home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZIP19P1.ZIP / zip.h < prev    next >
C/C++ Source or Header  |  1993-01-23  |  11KB  |  325 lines

  1. /*
  2.  
  3.  Copyright (C) 1990-1992 Mark Adler, Richard B. Wales, Jean-loup Gailly,
  4.  Kai Uwe Rommel 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.  unmodified, that it is not sold for profit, and that this copyright notice
  8.  is retained.
  9.  
  10. */
  11.  
  12. /*
  13.  *  zip.h by Mark Adler.
  14.  */
  15.  
  16.  
  17. /* Set up portability */
  18. #include "tailor.h"
  19.  
  20. #define MIN_MATCH  3
  21. #define MAX_MATCH  258
  22. /* The minimum and maximum match lengths */
  23.  
  24. #ifndef WSIZE
  25. #  define WSIZE  ((unsigned)32768)
  26. #endif
  27. /* Maximum window size = 32K. If you are really short of memory, compile
  28.  * with a smaller WSIZE but this reduces the compression ratio for files
  29.  * of size > WSIZE. WSIZE must be a power of two in the current implementation.
  30.  */
  31.  
  32. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  33. /* Minimum amount of lookahead, except at the end of the input file.
  34.  * See deflate.c for comments about the MIN_MATCH+1.
  35.  */
  36.  
  37. #define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
  38. /* In order to simplify the code, particularly on 16 bit machines, match
  39.  * distances are limited to MAX_DIST instead of WSIZE.
  40.  */
  41.  
  42. /* Define malloc() and string functions */
  43. #ifdef MODERN
  44. #  include <string.h>
  45. #else /* !MODERN */
  46.    voidp *malloc();
  47.    char *getenv();
  48.    long atol();
  49.    char *strcpy();
  50.    char *strcat();
  51.    char *strchr();
  52.    char *strrchr();
  53. #  ifndef ZMEM
  54.      char *memset();
  55.      char *memcpy();
  56. #  endif /* !ZMEM */
  57. #endif /* ?MODERN */
  58.  
  59.  
  60. /* Define fseek() commands */
  61. #ifndef SEEK_SET
  62. #  define SEEK_SET 0
  63. #endif /* !SEEK_SET */
  64.  
  65. #ifndef SEEK_CUR
  66. #  define SEEK_CUR 1
  67. #endif /* !SEEK_CUR */
  68.  
  69.  
  70. /* Forget FILENAME_MAX (incorrectly = 14 on some System V) */
  71. #ifdef MSDOS
  72. #  define FNMAX 256
  73. #else /* !MSDOS */
  74. #  define FNMAX 1024
  75. #endif /* ?MSDOS */
  76.  
  77.  
  78. /* For setting stdout to binary */
  79. #ifdef MSDOS
  80. #  include <io.h>
  81. #  include <fcntl.h>
  82. #endif /* MSDOS */
  83.  
  84.  
  85. /* Types centralized here for easy modification */
  86. #define local static            /* More meaningful outside functions */
  87. typedef unsigned char uch;      /* unsigned 8-bit value */
  88. typedef unsigned short ush;     /* unsigned 16-bit value */
  89. typedef unsigned long ulg;      /* unsigned 32-bit value */
  90.  
  91.  
  92. /* Lengths of headers after signatures in bytes */
  93. #define LOCHEAD 26
  94. #define CENHEAD 42
  95. #define ENDHEAD 18
  96.  
  97.  
  98. /* Structures for in-memory file information */
  99. struct zlist {
  100.   /* See central header in zipfile.c for what vem..off are */
  101.   ush vem, ver, flg, how;
  102.   ulg tim, crc, siz, len;
  103.   extent nam, ext, cext, com;   /* offset of ext must be >= LOCHEAD */
  104.   ush dsk, att, lflg;           /* offset of lflg must be >= LOCHEAD */
  105.   ulg atx, off;
  106.   char *name;                   /* File name in zip file */
  107.   char *extra;                  /* Extra field (set only if ext != 0) */
  108.   char *cextra;                 /* Extra in central (set only if cext != 0) */
  109.   char *comment;                /* Comment (set only if com != 0) */
  110.   char *zname;                  /* Name for new zip file header */
  111.   int mark;                     /* Marker for files to operate on */
  112.   int trash;                    /* Marker for files to delete */
  113.   int dosflag;                  /* Set to force MSDOS file attributes */
  114.   struct zlist far *nxt;        /* Pointer to next header in list */
  115. };
  116. struct flist {
  117.   char *name;                   /* Pointer to zero-delimited name */
  118.   char *zname;                  /* Name used for zip file headers */
  119.   int dosflag;                  /* Set to force MSDOS file attributes */
  120.   struct flist far * far *lst;  /* Pointer to link pointing here */
  121.   struct flist far *nxt;        /* Link to next name */
  122. };
  123.  
  124. /* internal file attribute */
  125. #define UNKNOWN (-1)
  126. #define BINARY  0
  127. #define ASCII   1
  128.  
  129. /* Error return codes and PERR macro */
  130. #include "ziperr.h"
  131.  
  132.  
  133. /* Public globals */
  134. extern uch upper[256];          /* Country dependent case map table */
  135. extern uch lower[256];
  136. extern char errbuf[];           /* Handy place to build error messages */
  137. extern int recurse;             /* Recurse into directories encountered */
  138. extern int pathput;             /* Store path with name */
  139.  
  140. #define BEST -1                 /* Use best method (deflation or store) */
  141. #define STORE 0                 /* Store method */
  142. #define DEFLATE 8               /* Deflation method*/
  143. extern int method;              /* Restriction on compression method */
  144.  
  145. extern int dosify;              /* Make new entries look like MSDOS */
  146. extern char *special;           /* Don't compress special suffixes */
  147. extern int verbose;             /* Report oddities in zip file structure */
  148. extern int level;               /* Compression level */
  149. extern int translate_eol;       /* Translate end-of-line LF -> CR LF */
  150. #ifdef VMS
  151.    extern int vmsver;           /* Append VMS version number to file names */
  152.    extern int vms_native;       /* Store in VMS formait */
  153. #endif /* VMS */
  154. #ifdef OS2
  155.    extern int use_longname_ea;   /* use the .LONGNAME EA as the file's name */
  156. #endif /* OS2 */
  157. extern int linkput;             /* Store symbolic links as such */
  158. extern int noisy;               /* False for quiet operation */
  159. extern char *key;               /* Scramble password or NULL */
  160. extern char *tempath;           /* Path for temporary files */
  161. extern FILE *mesg;              /* Where informational output goes */
  162. extern char *zipfile;           /* New or existing zip archive (zip file) */
  163. extern ulg zipbeg;              /* Starting offset of zip structures */
  164. extern ulg cenbeg;              /* Starting offset of central directory */
  165. extern struct zlist far *zfiles;/* Pointer to list of files in zip file */
  166. extern extent zcount;           /* Number of files in zip file */
  167. extern extent zcomlen;          /* Length of zip file comment */
  168. extern char *zcomment;          /* Zip file comment (not zero-terminated) */
  169. extern struct zlist far **zsort;/* List of files sorted by name */
  170. extern ulg tempzn;              /* Count of bytes written to output zip file */
  171. extern struct flist far *found; /* List of names found */
  172. extern struct flist far * far *fnxt;    /* Where to put next in found list */
  173. extern extent fcount;           /* Count of names in found list */
  174.  
  175.  
  176. /* Diagnostic functions */
  177. #ifdef DEBUG
  178. # ifdef MSDOS
  179. #  undef  stderr
  180. #  define stderr stdout
  181. # endif
  182. #  define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
  183. #  define Assert(cond,msg) {if(!(cond)) error(msg);}
  184. #  define Trace(x) fprintf x
  185. #  define Tracev(x) {if (verbose) fprintf x ;}
  186. #  define Tracevv(x) {if (verbose>1) fprintf x ;}
  187. #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
  188. #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
  189. #else
  190. #  define diag(where)
  191. #  define Assert(cond,msg)
  192. #  define Trace(x)
  193. #  define Tracev(x)
  194. #  define Tracevv(x)
  195. #  define Tracec(c,x)
  196. #  define Tracecv(c,x)
  197. #endif
  198.  
  199.  
  200. /* Public function prototypes */
  201.  
  202.         /* in zip.c, zipcloak.c, or zipsplit.c */
  203. void warn  OF((char *, char *));
  204. void err   OF((int c, char *h));
  205. void error OF((char *h));
  206.  
  207.         /* in zipup.c */
  208. int zipcopy OF((struct zlist far *, FILE *, FILE *));
  209. #ifndef UTIL
  210.    int percent OF((long, long));
  211.    int zipup OF((struct zlist far *, FILE *));
  212.    int file_read OF((char *buf, unsigned size));
  213. #endif /* !UTIL */
  214.  
  215.         /* in zipfile.c */
  216. #ifndef UTIL
  217.    struct zlist far *zsearch OF((char *));
  218.    int trash OF((void));
  219. #endif /* !UTIL */
  220. char *ziptyp OF((char *));
  221. int readzipfile OF((void));
  222. int putlocal OF((struct zlist far *, FILE *));
  223. int putextended OF((struct zlist far *, FILE *));
  224. int putcentral OF((struct zlist far *, FILE *));
  225. int putend OF((int, ulg, ulg, extent, char *, FILE *));
  226.  
  227.         /* in fileio.c */
  228. #ifndef UTIL
  229. #  ifdef MSDOS
  230.      int wild OF((char *));
  231. #  endif /* MSDOS */
  232. #  ifdef VMS
  233.      int wild OF((char *));
  234. #  endif /* VMS */
  235.    char *getnam OF((char *));
  236.    struct flist far *fexpel OF((struct flist far *));
  237.    char *in2ex OF((char *));
  238.    int exclude OF((void));
  239.    int procname OF((char *));
  240.    void stamp OF((char *, ulg));
  241.    ulg dostime OF((int, int, int, int, int, int));
  242.    ulg filetime OF((char *, ulg *, long *));
  243.    int issymlnk OF((ulg a));
  244. #  ifdef S_IFLNK
  245. #    define rdsymlnk(p,b,n) readlink(p,b,n)
  246.      extern int readlink OF((char *, char *, int));
  247. #  else /* !S_IFLNK */
  248. #    define rdsymlnk(p,b,n) (0)
  249. #  endif /* !S_IFLNK */
  250.    int deletedir OF((char *));
  251. #endif /* !UTIL */
  252. int destroy OF((char *));
  253. int replace OF((char *, char *));
  254. int getfileattr OF((char *));
  255. int setfileattr OF((char *, int));
  256. char *tempname OF((char *));
  257. int fcopy OF((FILE *, FILE *, ulg));
  258. #ifdef CRYPT
  259. #  ifndef MSVMS
  260.      void echoff OF((int));
  261.      void echon OF((void));
  262. #  endif /* !MSVMS */
  263.    char *getp OF((char *, char *, int));
  264. #endif /* !CRYPT */
  265. #ifdef ZMEM
  266.    char *memset OF((char *, int, unsigned int));
  267.    char *memcpy OF((char *, char *, unsigned int));
  268.    int memcmp OF((char *, char *, unsigned int));
  269. #endif /* ZMEM */
  270.  
  271.         /* in crypt.c */
  272. #ifndef CRYPT
  273. #  define zfwrite fwrite
  274. #  define zputc putc
  275. #else /* CRYPT */
  276.    void crypthead OF((char *, ulg, FILE *));
  277. #  ifdef UTIL
  278.      int zipcloak OF ((struct zlist far *, FILE *, FILE *, char *));
  279.      int zipbare OF ((struct zlist far *, FILE *, FILE *, char *));
  280. #  else /* !UTIL */
  281.      unsigned zfwrite OF((voidp *, extent, extent, FILE *));
  282.      int zencode OF((int c));
  283.      extern char *key;
  284. #    define zputc(c,f) (putc(key!=NULL? zencode(c) : (c),(f)))
  285. #  endif /* ?UTIL */
  286. #endif /* ?CRYPT */
  287.  
  288.         /* in util.c */
  289. char *isshexp OF((char *));
  290. int   shmatch OF((char *, char *));
  291. #ifdef MSDOS
  292.    int dosmatch OF((char *, char *));
  293. #endif /* MSDOS */
  294. void     init_upper OF((void));
  295. int      namecmp    OF((char *string1, char *string2));
  296. voidp far **search  OF((voidp *, voidp far **, extent,
  297.                        int (*)(voidp *, voidp far *)));
  298. ulg crc32 OF((ulg, int));
  299. ulg updcrc OF((char *, extent));
  300.  
  301. #ifndef UTIL
  302.         /* in deflate.c */
  303. void lm_init OF((int pack_level, ush *flags));
  304. ulg  deflate OF((void));
  305.  
  306.         /* in trees.c */
  307. void ct_init     OF((ush *attr, int *method));
  308. int  ct_tally    OF((int dist, int lc));
  309. ulg  flush_block OF((char far *buf, ulg stored_len, int eof));
  310.  
  311.         /* in bits.c */
  312. void     bi_init    OF((FILE *zipfile));
  313. void     send_bits  OF((int value, int length));
  314. unsigned bi_reverse OF((unsigned value, int length));
  315. void     bi_windup  OF((void));
  316. void     copy_block OF((char far *buf, unsigned len, int header));
  317. int      seekable   OF((void));
  318. extern   int (*read_buf) OF((char *buf, unsigned size));
  319. ulg     memcompress OF((char *tgt, ulg tgtsize, char *src, ulg srcsize));
  320.  
  321. #endif /* !UTIL */
  322.  
  323.  
  324. /* end of zip.h */
  325.