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