/* $VER: ar archive.h V0.1 (31.01.98)
 *
 * This file is part of ar, a portable archive maintanance
 * utility for normal and BSD-style archives.
 * Copyright (c) 1999  Frank Wille
 *
 * ar is freeware and part of the portable and retargetable ANSI C
 * compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
 * ar may be freely redistributed as long as no modifications are
 * made and nothing is charged for it. Non-commercial usage is allowed
 * without any restrictions.
 * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
 * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
 *
 *
 * v0.1  (31.01.99) phx
 *       First working version, which only supports 'q' (quick append)
 *       and 't' (table of contents), reads and writes normals and
 *       BSD-style archives. Symbol table will not be created!
 * v0.0  (29.01.99) phx
 *       File created.
 */

#include <time.h>
#include "lists.h"


#define ARMAG     "!<arch>\n"   /* ar "magic id" */
#define SARMAG    8             /* strlen(ARMAG) */
#define AR_EFMT1  "#1/"         /* extended format #1, long names (BSD-ar) */ 
#define ARFMAG    "`\n"
#define MAXARNAME 255           /* max. size for file names */

struct ArHeader {
  char ar_name[16];             /* name */
  char ar_time[12];             /* modification time */
  char ar_uid[6];               /* user id */
  char ar_gid[6];               /* group id */
  char ar_mode[8];              /* octal file permissions */
  char ar_size[10];             /* size in bytes */
  char ar_fmag[2];              /* consistency check */
};


struct ArObject {
  struct node n;
  char *name;
  uint8 *data;
  uint32 size;
  time_t time;
  uint16 uid;
  uint16 gid;
  uint16 mode;
};


struct Archive {
  struct list l;
  char *name;
  uint32 entries;
  struct ArObject *symbol_tab;
  struct ArObject *long_names;
};


/* functions */
extern struct Archive *ar_create(char *);
extern struct Archive *ar_read(char *);
extern struct Archive *ar_readorcreate(char *,uint32);
extern struct ArObject *ar_newmemb(char *);
extern void ar_write(struct Archive *,uint32);
