home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip21.zip / zip.h < prev    next >
C/C++ Source or Header  |  1996-04-03  |  14KB  |  379 lines

  1. /*
  2.  
  3.  Copyright (C) 1990-1996 Mark Adler, Richard B. Wales, Jean-loup Gailly,
  4.  Kai Uwe Rommel, Onno van der Linden and Igor Mandrichenko.
  5.  Permission is granted to any individual or institution to use, copy, or
  6.  redistribute this software so long as all of the original files are included,
  7.  that it is not sold for profit, and that this copyright notice is retained.
  8.  
  9. */
  10.  
  11. /*
  12.  *  zip.h by Mark Adler.
  13.  */
  14.  
  15. #ifndef __zip_h
  16. #define __zip_h 1
  17.  
  18. #define ZIP   /* for crypt.c:  include zip password functions, not unzip */
  19.  
  20. /* Set up portability */
  21. #include "tailor.h"
  22.  
  23. #define MIN_MATCH  3
  24. #define MAX_MATCH  258
  25. /* The minimum and maximum match lengths */
  26.  
  27. #ifndef WSIZE
  28. #  define WSIZE  (0x8000)
  29. #endif
  30. /* Maximum window size = 32K. If you are really short of memory, compile
  31.  * with a smaller WSIZE but this reduces the compression ratio for files
  32.  * of size > WSIZE. WSIZE must be a power of two in the current implementation.
  33.  */
  34.  
  35. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  36. /* Minimum amount of lookahead, except at the end of the input file.
  37.  * See deflate.c for comments about the MIN_MATCH+1.
  38.  */
  39.  
  40. #define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
  41. /* In order to simplify the code, particularly on 16 bit machines, match
  42.  * distances are limited to MAX_DIST instead of WSIZE.
  43.  */
  44.  
  45. /* Forget FILENAME_MAX (incorrectly = 14 on some System V) */
  46. #ifdef DOS
  47. #  define FNMAX 256
  48. #else
  49. #  define FNMAX 1024
  50. #endif
  51.  
  52. /* Types centralized here for easy modification */
  53. #define local static            /* More meaningful outside functions */
  54. typedef unsigned char uch;      /* unsigned 8-bit value */
  55. typedef unsigned short ush;     /* unsigned 16-bit value */
  56. typedef unsigned long ulg;      /* unsigned 32-bit value */
  57.  
  58.  
  59. /* Lengths of headers after signatures in bytes */
  60. #define LOCHEAD 26
  61. #define CENHEAD 42
  62. #define ENDHEAD 18
  63.  
  64. /* Structures for in-memory file information */
  65. struct zlist {
  66.   /* See central header in zipfile.c for what vem..off are */
  67.   ush vem, ver, flg, how;
  68.   ulg tim, crc, siz, len;
  69.   extent nam, ext, cext, com;   /* offset of ext must be >= LOCHEAD */
  70.   ush dsk, att, lflg;           /* offset of lflg must be >= LOCHEAD */
  71.   ulg atx, off;
  72.   char *name;                   /* File name in zip file */
  73.   char *extra;                  /* Extra field (set only if ext != 0) */
  74.   char *cextra;                 /* Extra in central (set only if cext != 0) */
  75.   char *comment;                /* Comment (set only if com != 0) */
  76.   char *zname;                  /* Name for new zip file header */
  77.   int mark;                     /* Marker for files to operate on */
  78.   int trash;                    /* Marker for files to delete */
  79.   int dosflag;                  /* Set to force MSDOS file attributes */
  80.   struct zlist far *nxt;        /* Pointer to next header in list */
  81. };
  82. struct flist {
  83.   char *name;                   /* Pointer to zero-delimited name */
  84.   char *zname;                  /* Name used for zip file headers */
  85.   int dosflag;                  /* Set to force MSDOS file attributes */
  86.   struct flist far * far *lst;  /* Pointer to link pointing here */
  87.   struct flist far *nxt;        /* Link to next name */
  88. };
  89. struct plist {
  90.   char *zname;                  /* Name used for zip file headers */
  91.   int select;                   /* Selection flag ('i' or 'x') */
  92. };
  93.  
  94. /* internal file attribute */
  95. #define UNKNOWN (-1)
  96. #define BINARY  0
  97. #define ASCII   1
  98. #define __EBCDIC 2
  99.  
  100. /* extra field definitions */
  101. #define EF_VMCMS     0x4704   /* VM/CMS Extra Field ID ("G")*/
  102. #define EF_MVS       0x470f   /* MVS Extra Field ID ("G")   */
  103. #define EF_IZUNIX    0x5855   /* UNIX Extra Field ID ("UX") */
  104. #define EF_OS2EA     0x0009   /* OS/2 Extra Field ID (extended attributes) */
  105. #define EF_ACL       0x4C41   /* ACL Extra Field ID (access control list, "AL") */
  106.  
  107. /* Definitions for extra field handling: */
  108. #define EB_HEADSIZE       4     /* length of a extra field block header */
  109. #define EB_ID             0     /* offset of block ID in header */
  110. #define EB_LEN            2     /* offset of data length field in header */
  111.  
  112. #define EB_UX_MINLEN      8     /* minimal "UX" field contains atime, mtime */
  113. #define EB_UX_ATIME       0     /* offset of atime in "UX" extra field data */
  114. #define EB_UX_MTIME       4     /* offset of mtime in "UX" extra field data */
  115.  
  116. #define EB_UX_FULLSIZE    12    /* full "UX" field (atime, mtime, uid, gid) */
  117. #define EB_UX_UID         8     /* byte offset of UID in "UX" field data */
  118. #define EB_UX_GID         10    /* byte offset of GID in "UX" field data */
  119.  
  120. /* ASCII definitions for line terminators in text files: */
  121. #define LF     10        /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  122. #define CR     13        /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  123. #define CTRLZ  26        /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
  124. /* Error return codes and PERR macro */
  125. #include "ziperr.h"
  126.  
  127.  
  128. /* Public globals */
  129. extern uch upper[256];          /* Country dependent case map table */
  130. extern uch lower[256];
  131. #ifdef EBCDIC
  132. extern const uch ascii[256];    /* EBCDIC <--> ASCII translation tables */
  133. extern const uch ebcdic[256];
  134. #endif /* EBCDIC */
  135. extern char errbuf[];           /* Handy place to build error messages */
  136. extern int recurse;             /* Recurse into directories encountered */
  137. extern int dispose;             /* Remove files after put in zip file */
  138. extern int pathput;             /* Store path with name */
  139.  
  140. #ifdef RISCOS
  141. extern int scanimage;           /* Scan through image files */
  142. #endif
  143.  
  144. #define BEST -1                 /* Use best method (deflation or store) */
  145. #define STORE 0                 /* Store method */
  146. #define DEFLATE 8               /* Deflation method*/
  147. extern int method;              /* Restriction on compression method */
  148.  
  149. extern int dosify;              /* Make new entries look like MSDOS */
  150. extern char *special;           /* Don't compress special suffixes */
  151. extern int verbose;             /* Report oddities in zip file structure */
  152. extern int fix;                 /* Fix the zip file */
  153. extern int adjust;              /* Adjust the unzipsfx'd zip file */
  154. extern int level;               /* Compression level */
  155. extern int translate_eol;       /* Translate end-of-line LF -> CR LF */
  156. #ifdef VMS
  157.    extern int vmsver;           /* Append VMS version number to file names */
  158.    extern int vms_native;       /* Store in VMS format */
  159. #endif /* VMS */
  160. #if defined(OS2) || defined(WIN32)
  161.    extern int use_longname_ea;   /* use the .LONGNAME EA as the file's name */
  162. #endif
  163. extern int hidden_files;        /* process hidden and system files */
  164. extern int volume_label;        /* add volume label */
  165. extern int dirnames;            /* include directory names */
  166. extern int linkput;             /* Store symbolic links as such */
  167. extern int noisy;               /* False for quiet operation */
  168. extern int extra_fields;        /* do not create extra fields */
  169. extern char *key;               /* Scramble password or NULL */
  170. extern char *tempath;           /* Path for temporary files */
  171. extern FILE *mesg;              /* Where informational output goes */
  172. extern char *zipfile;           /* New or existing zip archive (zip file) */
  173. extern ulg zipbeg;              /* Starting offset of zip structures */
  174. extern ulg cenbeg;              /* Starting offset of central directory */
  175. extern struct zlist far *zfiles;/* Pointer to list of files in zip file */
  176. extern extent zcount;           /* Number of files in zip file */
  177. extern extent zcomlen;          /* Length of zip file comment */
  178. extern char *zcomment;          /* Zip file comment (not zero-terminated) */
  179. extern struct zlist far **zsort;/* List of files sorted by name */
  180. extern ulg tempzn;              /* Count of bytes written to output zip file */
  181. extern struct flist far *found; /* List of names found */
  182. extern struct flist far * far *fnxt;    /* Where to put next in found list */
  183. extern extent fcount;           /* Count of names in found list */
  184.  
  185. extern struct plist *patterns;  /* List of patterns to be matched */
  186. extern int pcount;              /* number of patterns */
  187. extern int icount;              /* number of include only patterns */
  188.  
  189. /* Diagnostic functions */
  190. #ifdef DEBUG
  191. # ifdef MSDOS
  192. #  undef  stderr
  193. #  define stderr stdout
  194. # endif
  195. #  define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
  196. #  define Assert(cond,msg) {if(!(cond)) error(msg);}
  197. #  define Trace(x) fprintf x
  198. #  define Tracev(x) {if (verbose) fprintf x ;}
  199. #  define Tracevv(x) {if (verbose>1) fprintf x ;}
  200. #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
  201. #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
  202. #else
  203. #  define diag(where)
  204. #  define Assert(cond,msg)
  205. #  define Trace(x)
  206. #  define Tracev(x)
  207. #  define Tracevv(x)
  208. #  define Tracec(c,x)
  209. #  define Tracecv(c,x)
  210. #endif
  211.  
  212.  
  213. /* Public function prototypes */
  214.  
  215.         /* in zip.c, zipcloak.c, or zipsplit.c */
  216. #ifdef EBCDIC
  217. extern int aflag;
  218. #endif /* EBCDIC */
  219. #ifdef CMS_MVS
  220. extern int bflag;
  221. #endif /* CMS_MVS */
  222. void zipwarn  OF((char *, char *));
  223. void ziperr   OF((int c, char *h));
  224. #ifdef UTIL
  225. #  define error(msg)    ziperr(ZE_LOGIC, msg)
  226. #else
  227.    void error OF((char *h));
  228. #endif
  229.  
  230.         /* in zipup.c */
  231. #ifndef UTIL
  232.    int percent OF((ulg, ulg));
  233.    int zipup OF((struct zlist far *, FILE *));
  234.    int file_read OF((char *buf, unsigned size));
  235. #endif /* !UTIL */
  236.  
  237.         /* in zipfile.c */
  238. #ifndef UTIL
  239.    struct zlist far *zsearch OF((char *));
  240. #  ifdef USE_EF_UX_TIME
  241.      int get_ef_ux_ztime OF((struct zlist far *, ztimbuf *));
  242. #  endif /* USE_EF_UX_TIME */
  243.    int trash OF((void));
  244. #endif /* !UTIL */
  245. char *ziptyp OF((char *));
  246. int readzipfile OF((void));
  247. int putlocal OF((struct zlist far *, FILE *));
  248. int putextended OF((struct zlist far *, FILE *));
  249. int putcentral OF((struct zlist far *, FILE *));
  250. int putend OF((int, ulg, ulg, extent, char *, FILE *));
  251. int zipcopy OF((struct zlist far *, FILE *, FILE *));
  252.  
  253.         /* in fileio.c */
  254. #ifndef UTIL
  255.    char *getnam OF((char *));
  256.    struct flist far *fexpel OF((struct flist far *));
  257.    char *last OF((char *, int));
  258.    char *msname OF((char *));
  259.    int check_dup OF((void));
  260.    int filter OF((char *name));
  261.    int newname OF((char *n, int isdir));
  262.    time_t dos2unixtime OF((ulg dostime));
  263.    ulg dostime OF((int, int, int, int, int, int));
  264.    ulg unix2dostime OF((time_t *));
  265.    int issymlnk OF((ulg a));
  266. #  ifdef S_IFLNK
  267. #    define rdsymlnk(p,b,n) readlink(p,b,n)
  268. /*   extern int readlink OF((char *, char *, int)); */
  269. #  else /* !S_IFLNK */
  270. #    define rdsymlnk(p,b,n) (0)
  271. #  endif /* !S_IFLNK */
  272. #endif /* !UTIL */
  273.  
  274. int destroy OF((char *));
  275. int replace OF((char *, char *));
  276. int getfileattr OF((char *));
  277. int setfileattr OF((char *, int));
  278. char *tempname OF((char *));
  279. int fcopy OF((FILE *, FILE *, ulg));
  280.  
  281. #ifdef ZMEM
  282.    char *memset OF((char *, int, unsigned int));
  283.    char *memcpy OF((char *, char *, unsigned int));
  284.    int memcmp OF((char *, char *, unsigned int));
  285. #endif /* ZMEM */
  286.  
  287.         /* in system dependent fileio code (<system>.c) */
  288. #ifndef UTIL
  289. #  if defined(MSVMS) || defined(AMIGA) || defined(RISCOS) || defined(ATARI)
  290.      int wild OF((char *));
  291. #  endif
  292.    char *in2ex OF((char *));
  293.    char *ex2in OF((char *, int, int *));
  294.    int procname OF((char *));
  295.    void stamp OF((char *, ulg));
  296.    ulg filetime OF((char *, ulg *, long *, ztimbuf *));
  297. #if !(defined(VMS) && defined(VMS_PK_EXTRA))
  298.    int set_extra_field OF((struct zlist far *z, ztimbuf *z_utim));
  299. #else /* VMS && VMS_PK_EXTRA */
  300.    void vms_get_attributes (); /* (struct ioctx *ctx, struct zlist far *z,
  301.                                    ztimbuf *z_utim) */
  302. #endif /* ?(VMS && VMS_PK_EXTRA) */
  303.    int deletedir OF((char *));
  304.    void version_local OF((void));
  305. #ifdef MY_ZCALLOC
  306.      zvoid far *zcalloc OF((unsigned int, unsigned int));
  307.      zvoid zcfree       OF((zvoid far *));
  308. #endif /* MY_ZCALLOC */
  309. #endif /* !UTIL */
  310.  
  311.         /* in util.c */
  312. char *isshexp OF((char *));
  313. int   shmatch OF((char *, char *));
  314. #ifdef DOS
  315.    int dosmatch OF((char *, char *));
  316. #endif /* DOS */
  317. void init_upper    OF((void));
  318. int  namecmp       OF((char *string1, char *string2));
  319.  
  320. #ifdef EBCDIC
  321. char *strtoasc(char *str1, char *str2);
  322. char *strtoebc(char *str1, char *str2);
  323. #endif /* EBCDIC */
  324.  
  325. zvoid far **search OF((zvoid *, zvoid far **, extent,
  326.                        int (*)(const zvoid *, const zvoid far *)));
  327. void envargs       OF((int *Pargc, char ***Pargv, char *envstr, char *envstr2));
  328. void expand_args   OF((int *argcp, char ***argvp));
  329.  
  330. #ifndef USE_ZLIB
  331. #ifndef UTIL
  332.         /* in crc32.c */
  333. ulg  crc32         OF((ulg, const uch *, extent));
  334. #endif /* !UTIL */
  335.  
  336.         /* in crctab.c */
  337. ulg near *get_crc_table OF((void));
  338. #endif /* !USE_ZLIB */
  339.  
  340. #ifndef UTIL
  341.         /* in deflate.c */
  342. void lm_init OF((int pack_level, ush *flags));
  343. void lm_free OF((void));
  344. ulg  deflate OF((void));
  345.  
  346.         /* in trees.c */
  347. void ct_init     OF((ush *attr, int *method));
  348. int  ct_tally    OF((int dist, int lc));
  349. ulg  flush_block OF((char far *buf, ulg stored_len, int eof));
  350.  
  351.         /* in bits.c */
  352. void     bi_init     OF((FILE *zipfile));
  353. void     send_bits   OF((int value, int length));
  354. unsigned bi_reverse  OF((unsigned value, int length));
  355. void     bi_windup   OF((void));
  356. void     copy_block  OF((char *block, unsigned len, int header));
  357. int      seekable    OF((void));
  358. extern   int (*read_buf) OF((char *buf, unsigned size));
  359. ulg      memcompress OF((char *tgt, ulg tgtsize, char *src, ulg srcsize));
  360.  
  361. #endif /* !UTIL */
  362.  
  363. /*---------------------------------------------------------------------------
  364.     VMS-only functions:
  365.   ---------------------------------------------------------------------------*/
  366. #ifdef VMS
  367.    int    vms_stat        OF((char *file, stat_t *s));              /* vms.c */
  368.    void   vms_exit        OF((int e));                              /* vms.c */
  369. #ifndef UTIL
  370. #ifdef VMSCLI
  371.    ulg    vms_zip_cmdline OF((int *, char ***));                /* cmdline.c */
  372.    void   help            OF((void));                           /* cmdline.c */
  373. #endif /* VMSCLI */
  374. #endif /* !UTIL */
  375. #endif /* VMS */
  376.  
  377. #endif /* !__zip_h */
  378. /* end of zip.h */
  379.