home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip22.zip / zip.h < prev    next >
C/C++ Source or Header  |  1997-08-23  |  18KB  |  485 lines

  1. /*
  2.  
  3.  Copyright (C) 1990-1997 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. /* Structure carrying extended timestamp information */
  60. typedef struct iztimes {
  61.    time_t atime;                /* new access time */
  62.    time_t mtime;                /* new modification time */
  63.    time_t ctime;                /* new creation time (!= Unix st.ctime) */
  64. } iztimes;
  65.  
  66. /* Lengths of headers after signatures in bytes */
  67. #define LOCHEAD 26
  68. #define CENHEAD 42
  69. #define ENDHEAD 18
  70.  
  71. /* Structures for in-memory file information */
  72. struct zlist {
  73.   /* See central header in zipfile.c for what vem..off are */
  74.   ush vem, ver, flg, how;
  75.   ulg tim, crc, siz, len;
  76.   extent nam, ext, cext, com;   /* offset of ext must be >= LOCHEAD */
  77.   ush dsk, att, lflg;           /* offset of lflg must be >= LOCHEAD */
  78.   ulg atx, off;
  79.   char *name;                   /* File name in zip file */
  80.   char *extra;                  /* Extra field (set only if ext != 0) */
  81.   char *cextra;                 /* Extra in central (set only if cext != 0) */
  82.   char *comment;                /* Comment (set only if com != 0) */
  83.   char *iname;                  /* Internal file name after cleanup */
  84.   char *zname;                  /* External version of internal name */
  85.   int mark;                     /* Marker for files to operate on */
  86.   int trash;                    /* Marker for files to delete */
  87.   int dosflag;                  /* Set to force MSDOS file attributes */
  88.   struct zlist far *nxt;        /* Pointer to next header in list */
  89. };
  90. struct flist {
  91.   char *name;                   /* Raw internal file name */
  92.   char *iname;                  /* Internal file name after cleanup */
  93.   char *zname;                  /* External version of internal name */
  94.   int dosflag;                  /* Set to force MSDOS file attributes */
  95.   struct flist far *far *lst;   /* Pointer to link pointing here */
  96.   struct flist far *nxt;        /* Link to next name */
  97. };
  98. struct plist {
  99.   char *zname;                  /* External version of internal name */
  100.   int select;                   /* Selection flag ('i' or 'x') */
  101. };
  102.  
  103. /* internal file attribute */
  104. #define UNKNOWN (-1)
  105. #define BINARY  0
  106. #define ASCII   1
  107. #define __EBCDIC 2
  108.  
  109. /* extra field definitions */
  110. #define EF_VMCMS     0x4704   /* VM/CMS Extra Field ID ("G")*/
  111. #define EF_MVS       0x470f   /* MVS Extra Field ID ("G")   */
  112. #define EF_IZUNIX    0x5855   /* UNIX Extra Field ID ("UX") */
  113. #define EF_IZUNIX2   0x7855   /* Info-ZIP's new Unix ("Ux") */
  114. #define EF_TIME      0x5455   /* universal timestamp ("UT") */
  115. #define EF_OS2EA     0x0009   /* OS/2 Extra Field ID (extended attributes) */
  116. #define EF_ACL       0x4C41   /* ACL Extra Field ID (access control list, "AL") */
  117. #define EF_NTSD      0x4453   /* NT Security Descriptor Extra Field ID, ("SD") */
  118. #define EF_BEOS      0x6542   /* BeOS Extra Field ID ("Be") */
  119. #define EF_QDOS      0xfb4a   /* SMS/QDOS ("J\373") */
  120. #define EF_AOSVS     0x5356   /* AOS/VS ("VS") */
  121. #define EF_SPARK     0x4341   /* David Pilling's Acorn/SparkFS ("AC") */
  122.  
  123. /* Definitions for extra field handling: */
  124. #define EB_HEADSIZE       4     /* length of a extra field block header */
  125. #define EB_ID             0     /* offset of block ID in header */
  126. #define EB_LEN            2     /* offset of data length field in header */
  127.  
  128. #define EB_UX_MINLEN      8     /* minimal "UX" field contains atime, mtime */
  129. #define EB_UX_ATIME       0     /* offset of atime in "UX" extra field data */
  130. #define EB_UX_MTIME       4     /* offset of mtime in "UX" extra field data */
  131.  
  132. #define EB_UX_FULLSIZE    12    /* full "UX" field (atime, mtime, uid, gid) */
  133. #define EB_UX_UID         8     /* byte offset of UID in "UX" field data */
  134. #define EB_UX_GID         10    /* byte offset of GID in "UX" field data */
  135.  
  136. #define EB_UT_MINLEN      1     /* minimal UT field contains Flags byte */
  137. #define EB_UT_FLAGS       0     /* byte offset of Flags field */
  138. #define EB_UT_TIME1       1     /* byte offset of 1st time value */
  139. #define EB_UT_FL_MTIME    (1 << 0)      /* mtime present */
  140. #define EB_UT_FL_ATIME    (1 << 1)      /* atime present */
  141. #define EB_UT_FL_CTIME    (1 << 2)      /* ctime present */
  142. #define EB_UT_LEN(n)      (EB_UT_MINLEN + 4 * (n))
  143.  
  144. #define EB_UX2_MINLEN     4     /* minimal Ux field contains UID/GID */
  145. #define EB_UX2_UID        0     /* byte offset of UID in "Ux" field data */
  146. #define EB_UX2_GID        2     /* byte offset of GID in "Ux" field data */
  147. #define EB_UX2_VALID      (1 << 8)      /* UID/GID present */
  148.  
  149. /* ASCII definitions for line terminators in text files: */
  150. #define LF     10        /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  151. #define CR     13        /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  152. #define CTRLZ  26        /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
  153.  
  154. /* return codes of password fetches (negative: user abort; positive: error) */
  155. #define IZ_PW_ENTERED   0       /* got some PWD string, use/try it */
  156. #define IZ_PW_CANCEL    -1      /* no password available (for this entry) */
  157. #define IZ_PW_CANCELALL -2      /* no password, skip any further PWD request */
  158. #define IZ_PW_ERROR     5       /* = PK_MEM2 : failure (no mem, no tty, ...) */
  159. #define IZ_PW_SKIPVERIFY IZ_PW_CANCEL   /* skip encrypt. passwd verification */
  160.  
  161. /* mode flag values of password prompting function */
  162. #define ZP_PW_ENTER     0       /* request for encryption password */
  163. #define ZP_PW_VERIFY    1       /* request for reentering password */
  164.  
  165. /* Error return codes and PERR macro */
  166. #include "ziperr.h"
  167.  
  168. #if 0            /* Optimization: use the (const) result of crc32(0L,NULL,0) */
  169. #  define CRCVAL_INITIAL  crc32(0L, (uch *)NULL, 0)
  170. #else
  171. #  define CRCVAL_INITIAL  0L
  172. #endif
  173.  
  174.  
  175. /* Public globals */
  176. extern uch upper[256];          /* Country dependent case map table */
  177. extern uch lower[256];
  178. #ifdef EBCDIC
  179. extern ZCONST uch ascii[256];   /* EBCDIC <--> ASCII translation tables */
  180. extern ZCONST uch ebcdic[256];
  181. #endif /* EBCDIC */
  182. #ifdef IZ_ISO2OEM_ARRAY         /* ISO 8859-1 (Win CP 1252) --> OEM CP 850 */
  183. extern ZCONST uch Far iso2oem[128];
  184. #endif
  185. #ifdef IZ_OEM2ISO_ARRAY         /* OEM CP 850 --> ISO 8859-1 (Win CP 1252) */
  186. extern ZCONST uch Far oem2iso[128];
  187. #endif
  188. extern char errbuf[];           /* Handy place to build error messages */
  189. extern int recurse;             /* Recurse into directories encountered */
  190. extern int dispose;             /* Remove files after put in zip file */
  191. extern int pathput;             /* Store path with name */
  192.  
  193. #ifdef RISCOS
  194. extern int scanimage;           /* Scan through image files */
  195. #endif
  196.  
  197. #define BEST -1                 /* Use best method (deflation or store) */
  198. #define STORE 0                 /* Store method */
  199. #define DEFLATE 8               /* Deflation method*/
  200. extern int method;              /* Restriction on compression method */
  201.  
  202. extern int dosify;              /* Make new entries look like MSDOS */
  203. extern char *special;           /* Don't compress special suffixes */
  204. extern int verbose;             /* Report oddities in zip file structure */
  205. extern int fix;                 /* Fix the zip file */
  206. extern int adjust;              /* Adjust the unzipsfx'd zip file */
  207. extern int level;               /* Compression level */
  208. extern int translate_eol;       /* Translate end-of-line LF -> CR LF */
  209. #ifdef VMS
  210.    extern int vmsver;           /* Append VMS version number to file names */
  211.    extern int vms_native;       /* Store in VMS format */
  212. #endif /* VMS */
  213. #if defined(OS2) || defined(WIN32)
  214.    extern int use_longname_ea;   /* use the .LONGNAME EA as the file's name */
  215. #endif
  216. #if defined (QDOS) || defined(QLZIP)
  217. extern short qlflag;
  218. #endif
  219. extern int hidden_files;        /* process hidden and system files */
  220. extern int volume_label;        /* add volume label */
  221. extern int dirnames;            /* include directory names */
  222. extern int linkput;             /* Store symbolic links as such */
  223. extern int noisy;               /* False for quiet operation */
  224. extern int extra_fields;        /* do not create extra fields */
  225. #ifdef WIN32
  226.     extern int use_privileges;  /* use security privilege overrides */
  227. #endif
  228. extern char *key;               /* Scramble password or NULL */
  229. extern char *tempath;           /* Path for temporary files */
  230. extern FILE *mesg;              /* Where informational output goes */
  231. extern char *zipfile;           /* New or existing zip archive (zip file) */
  232. extern ulg zipbeg;              /* Starting offset of zip structures */
  233. extern ulg cenbeg;              /* Starting offset of central directory */
  234. extern struct zlist far *zfiles;/* Pointer to list of files in zip file */
  235. extern extent zcount;           /* Number of files in zip file */
  236. extern extent zcomlen;          /* Length of zip file comment */
  237. extern char *zcomment;          /* Zip file comment (not zero-terminated) */
  238. extern struct zlist far **zsort;/* List of files sorted by name */
  239. extern ulg tempzn;              /* Count of bytes written to output zip file */
  240. extern struct flist far *found; /* List of names found */
  241. extern struct flist far *far *fnxt;     /* Where to put next in found list */
  242. extern extent fcount;           /* Count of names in found list */
  243.  
  244. extern struct plist *patterns;  /* List of patterns to be matched */
  245. extern int pcount;              /* number of patterns */
  246. extern int icount;              /* number of include only patterns */
  247.  
  248. #ifdef WINDLL
  249. extern int zipstate;            /* flag "zipfile has been stat()'ed */
  250. #endif
  251.  
  252. /* Diagnostic functions */
  253. #ifdef DEBUG
  254. # ifdef MSDOS
  255. #  undef  stderr
  256. #  define stderr stdout
  257. # endif
  258. #  define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
  259. #  define Assert(cond,msg) {if(!(cond)) error(msg);}
  260. #  define Trace(x) fprintf x
  261. #  define Tracev(x) {if (verbose) fprintf x ;}
  262. #  define Tracevv(x) {if (verbose>1) fprintf x ;}
  263. #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
  264. #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
  265. #else
  266. #  define diag(where)
  267. #  define Assert(cond,msg)
  268. #  define Trace(x)
  269. #  define Tracev(x)
  270. #  define Tracevv(x)
  271. #  define Tracec(c,x)
  272. #  define Tracecv(c,x)
  273. #endif
  274.  
  275. #ifdef DEBUGNAMES
  276. #  define free(x) { int *v;Free(x); v=x;*v=0xdeadbeef;x=(void *)0xdeadbeef; }
  277. #endif
  278.  
  279. /* Public function prototypes */
  280.  
  281. #ifndef UTIL
  282. #ifdef USE_ZIPMAIN
  283. int zipmain OF((int, char **));
  284. #else
  285. int main OF((int, char **));
  286. #endif /* USE_ZIPMAIN */
  287. #endif
  288.  
  289. #ifdef EBCDIC
  290. extern int aflag;
  291. #endif /* EBCDIC */
  292. #ifdef CMS_MVS
  293. extern int bflag;
  294. #endif /* CMS_MVS */
  295. void zipwarn  OF((char *, char *));
  296. void ziperr   OF((int c, char *h));
  297. #ifdef UTIL
  298. #  define error(msg)    ziperr(ZE_LOGIC, msg)
  299. #else
  300.    void error OF((char *h));
  301. #  ifdef VMSCLI
  302.      void help OF((void));
  303. #  endif
  304.    int encr_passwd OF((int modeflag, char *pwbuf, int size, ZCONST char *zfn));
  305. #endif
  306.  
  307.         /* in zipup.c */
  308. #ifndef UTIL
  309.    int percent OF((ulg, ulg));
  310.    int zipup OF((struct zlist far *, FILE *));
  311.    int file_read OF((char *buf, unsigned size));
  312. #endif /* !UTIL */
  313.  
  314.         /* in zipfile.c */
  315. #ifndef UTIL
  316.    struct zlist far *zsearch OF((char *));
  317. #  ifdef USE_EF_UT_TIME
  318.      int get_ef_ut_ztime OF((struct zlist far *, iztimes *));
  319. #  endif /* USE_EF_UT_TIME */
  320.    int trash OF((void));
  321. #endif /* !UTIL */
  322. char *ziptyp OF((char *));
  323. int readzipfile OF((void));
  324. int putlocal OF((struct zlist far *, FILE *));
  325. int putextended OF((struct zlist far *, FILE *));
  326. int putcentral OF((struct zlist far *, FILE *));
  327. int putend OF((int, ulg, ulg, extent, char *, FILE *));
  328. int zipcopy OF((struct zlist far *, FILE *, FILE *));
  329.  
  330.         /* in fileio.c */
  331. #ifndef UTIL
  332.    char *getnam OF((char *, FILE *));
  333.    struct flist far *fexpel OF((struct flist far *));
  334.    char *last OF((char *, int));
  335.    char *msname OF((char *));
  336.    int check_dup OF((void));
  337.    int filter OF((char *name));
  338.    int newname OF((char *n, int isdir));
  339.    time_t dos2unixtime OF((ulg dostime));
  340.    ulg dostime OF((int, int, int, int, int, int));
  341.    ulg unix2dostime OF((time_t *));
  342.    int issymlnk OF((ulg a));
  343. #  ifdef S_IFLNK
  344. #    define rdsymlnk(p,b,n) readlink(p,b,n)
  345. /*   extern int readlink OF((char *, char *, int)); */
  346. #  else /* !S_IFLNK */
  347. #    define rdsymlnk(p,b,n) (0)
  348. #  endif /* !S_IFLNK */
  349. #endif /* !UTIL */
  350.  
  351. int destroy OF((char *));
  352. int replace OF((char *, char *));
  353. int getfileattr OF((char *));
  354. int setfileattr OF((char *, int));
  355. char *tempname OF((char *));
  356. int fcopy OF((FILE *, FILE *, ulg));
  357.  
  358. #ifdef ZMEM
  359.    char *memset OF((char *, int, unsigned int));
  360.    char *memcpy OF((char *, char *, unsigned int));
  361.    int memcmp OF((char *, char *, unsigned int));
  362. #endif /* ZMEM */
  363.  
  364.         /* in system dependent fileio code (<system>.c) */
  365. #ifndef UTIL
  366. #  ifdef PROCNAME
  367.      int wild OF((char *));
  368. #  endif
  369.    char *in2ex OF((char *));
  370.    char *ex2in OF((char *, int, int *));
  371.    int procname OF((char *));
  372.    void stamp OF((char *, ulg));
  373.    ulg filetime OF((char *, ulg *, long *, iztimes *));
  374. #if !(defined(VMS) && defined(VMS_PK_EXTRA))
  375.    int set_extra_field OF((struct zlist far *z, iztimes *z_utim));
  376. #else /* VMS && VMS_PK_EXTRA */
  377.    void vms_get_attributes (); /* (struct ioctx *ctx, struct zlist far *z,
  378.                                    iztimes *z_utim) */
  379. #endif /* ?(VMS && VMS_PK_EXTRA) */
  380.    int deletedir OF((char *));
  381. #ifdef MY_ZCALLOC
  382.      zvoid far *zcalloc OF((unsigned int, unsigned int));
  383.      zvoid zcfree       OF((zvoid far *));
  384. #endif /* MY_ZCALLOC */
  385. #endif /* !UTIL */
  386. void version_local OF((void));
  387.  
  388.         /* in util.c */
  389. #ifndef UTIL
  390. int   fseekable    OF((FILE *));
  391. char *isshexp      OF((char *));
  392. int   shmatch      OF((char *, char *));
  393. #if defined(DOS) || defined(WIN32)
  394.    int dosmatch    OF((char *, char *));
  395. #endif /* DOS || WIN32 */
  396. #endif /* !UTIL */
  397. void init_upper    OF((void));
  398. int  namecmp       OF((char *string1, char *string2));
  399.  
  400. #ifdef EBCDIC
  401. char *strtoasc     OF((char *str1, ZCONST char *str2);
  402. char *strtoebc     OF((char *str1, ZCONST char *str2));
  403. char *memtoasc     OF((char *mem1, ZCONST char *mem2, unsigned len));
  404. char *memtoebc     OF((char *mem1, ZCONST char *mem2, unsigned len));
  405. #endif /* EBCDIC */
  406. #ifdef IZ_ISO2OEM_ARRAY
  407. char *str_iso_to_oem    OF((char *dst, ZCONST char *src));
  408. #endif
  409. #ifdef IZ_OEM2ISO_ARRAY
  410. char *str_oem_to_iso    OF((char *dst, ZCONST char *src));
  411. #endif
  412.  
  413. zvoid far **search OF((zvoid *, zvoid far **, extent,
  414.                        int (*)(ZCONST zvoid *, ZCONST zvoid far *)));
  415. void envargs       OF((int *Pargc, char ***Pargv, char *envstr, char *envstr2));
  416. void expand_args   OF((int *argcp, char ***argvp));
  417.  
  418. #ifndef USE_ZLIB
  419. #ifndef UTIL
  420.         /* in crc32.c */
  421. ulg  crc32         OF((ulg, ZCONST uch *, extent));
  422. #endif /* !UTIL */
  423.  
  424.         /* in crctab.c */
  425. ulg near *get_crc_table OF((void));
  426. #ifdef DYNALLOC_CRCTAB
  427. void free_crc_table OF((void));
  428. #endif
  429. #endif /* !USE_ZLIB */
  430.  
  431. #ifndef UTIL
  432.         /* in deflate.c */
  433. void lm_init OF((int pack_level, ush *flags));
  434. void lm_free OF((void));
  435. ulg  deflate OF((void));
  436.  
  437.         /* in trees.c */
  438. void ct_init     OF((ush *attr, int *method));
  439. int  ct_tally    OF((int dist, int lc));
  440. ulg  flush_block OF((char far *buf, ulg stored_len, int eof));
  441.  
  442.         /* in bits.c */
  443. void     bi_init     OF((FILE *zipfile));
  444. void     send_bits   OF((int value, int length));
  445. unsigned bi_reverse  OF((unsigned value, int length));
  446. void     bi_windup   OF((void));
  447. void     copy_block  OF((char *block, unsigned len, int header));
  448. int      seekable    OF((void));
  449. extern   int (*read_buf) OF((char *buf, unsigned size));
  450. ulg      memcompress OF((char *tgt, ulg tgtsize, char *src, ulg srcsize));
  451.  
  452. #endif /* !UTIL */
  453.  
  454. /*---------------------------------------------------------------------------
  455.     VMS-only functions:
  456.   ---------------------------------------------------------------------------*/
  457. #ifdef VMS
  458.    int    vms_stat        OF((char *file, stat_t *s));              /* vms.c */
  459.    void   vms_exit        OF((int e));                              /* vms.c */
  460. #ifndef UTIL
  461. #ifdef VMSCLI
  462.    ulg    vms_zip_cmdline OF((int *, char ***));                /* cmdline.c */
  463.    void   VMSCLI_help     OF((void));                           /* cmdline.c */
  464. #endif /* VMSCLI */
  465. #endif /* !UTIL */
  466. #endif /* VMS */
  467.  
  468.  
  469. /*---------------------------------------------------------------------------
  470.     WIN32-only functions:
  471.   ---------------------------------------------------------------------------*/
  472. #ifdef WIN32
  473.    int    ZipIsWinNT         OF((void));                         /* win32.c */
  474. #endif /* WIN32 */
  475.  
  476. #if (defined(WINDLL) || defined(DLL_ZIPAPI))
  477. /*---------------------------------------------------------------------------
  478.     Prototypes for public Zip API (DLL) functions.
  479.   ---------------------------------------------------------------------------*/
  480. #include "api.h"
  481. #endif /* WINDLL || DLL_ZIPAPI */
  482.  
  483. #endif /* !__zip_h */
  484. /* end of zip.h */
  485.