home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / unz50p1 / unzip.h < prev    next >
C/C++ Source or Header  |  1993-01-11  |  43KB  |  1,244 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h
  4.  
  5.   This header file is used by all of the unzip source files.  Its contents
  6.   are divided into seven more-or-less separate sections:  predefined macros,
  7.   OS-dependent includes, (mostly) OS-independent defines, typedefs, function 
  8.   prototypes (or "prototypes," in the case of non-ANSI compilers), macros, 
  9.   and global-variable declarations.
  10.  
  11.   ---------------------------------------------------------------------------*/
  12.  
  13.  
  14.  
  15. /*****************************************/
  16. /*  Predefined, Machine-specific Macros  */
  17. /*****************************************/
  18.  
  19. #if (defined(__GO32__) && defined(unix))   /* DOS extender */
  20. #  undef unix
  21. #endif
  22.  
  23. #if defined(unix) || defined(__convexc__) || defined(M_XENIX)
  24. #  ifndef UNIX
  25. #    define UNIX
  26. #  endif /* !UNIX */
  27. #endif /* unix || __convexc__ || M_XENIX */
  28.  
  29. /* Much of the following is swiped from zip's tailor.h: */
  30.  
  31. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  32. #ifdef __POWERC
  33. #  define __TURBOC__
  34. #  define MSDOS
  35. #endif /* __POWERC */
  36. #if (defined(__TURBOC__) && defined(__MSDOS__) && !defined(MSDOS))
  37. #  define MSDOS
  38. #endif
  39.  
  40. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C,
  41.  * or Silicon Graphics, or Convex, or IBM C Set/2, or GNU gcc under emx, or
  42.  * or Watcom C, or Macintosh, or Windows NT.
  43.  */
  44. #if (__STDC__ || defined(MSDOS) || defined(sgi) || defined(CONVEX))
  45. #  ifndef PROTO
  46. #    define PROTO
  47. #  endif
  48. #  define MODERN
  49. #endif
  50. #if (defined(__IBMC__) || defined(__EMX__) || defined(__WATCOMC__))
  51. #  ifndef PROTO
  52. #    define PROTO
  53. #  endif
  54. #  define MODERN
  55. #endif
  56. #if (defined(THINK_C) || defined(MPW) || defined(WIN32))
  57. #  ifndef PROTO
  58. #    define PROTO
  59. #  endif
  60. #  define MODERN
  61. #endif
  62.  
  63. /* turn off prototypes if requested */
  64. #if (defined(NOPROTO) && defined(PROTO))
  65. #  undef PROTO
  66. #endif
  67.  
  68. /* used to remove arguments in function prototypes for non-ANSI C */
  69. #ifdef PROTO
  70. #  define OF(a) a
  71. #else /* !PROTO */
  72. #  define OF(a) ()
  73. #endif /* ?PROTO */
  74.  
  75. #if (defined(ultrix) || defined(bsd4_2) || defined(sun) || defined(pyr))
  76. #  if (!defined(BSD) && !defined(__SYSTEM_FIVE) && !defined(SYSV))
  77. #    define BSD
  78. #  endif /* !BSD && !__SYSTEM_FIVE && !SYSV */
  79. #endif /* ultrix || bsd4_2 || sun || pyr */
  80.  
  81. #if (defined(CONVEX) || defined(CRAY) || defined(__SYSTEM_FIVE))
  82. #  ifndef TERMIO
  83. #    define TERMIO
  84. #  endif /* !TERMIO */
  85. #endif /* CONVEX || CRAY || __SYSTEM_FIVE */
  86.  
  87. #ifdef pyr  /* Pyramid */
  88. #  ifndef ZMEM
  89. #    define ZMEM
  90. #  endif /* !ZMEM */
  91. #endif /* pyr */
  92.  
  93. #ifdef CRAY
  94. #  ifdef ZMEM
  95. #    undef ZMEM
  96. #  endif /* ZMEM */
  97. #endif /* CRAY */
  98.  
  99. /* the i386 test below is to catch SCO Unix (which has redefinition
  100.  * warnings if param.h is included), but it probably doesn't hurt if
  101.  * other 386 Unixes get nailed, too...except now that 386BSD and BSDI
  102.  * exist.  Sigh.  <sys/param.h> is mostly included for "BSD", I think.
  103.  * [An alternate fix for SCO Unix is below.]
  104.  */
  105. #if (defined(MINIX) || (defined(i386) && defined(unix)))
  106. #  define NO_PARAM_H
  107. #endif /* MINIX || (i386 && unix) */
  108.  
  109.  
  110.  
  111.  
  112.  
  113. /***************************/
  114. /*  OS-Dependent Includes  */
  115. /***************************/
  116.  
  117. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  118. #  include <stdio.h>
  119. #endif
  120. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  121. #include <errno.h>       /* used in mapname() */
  122. #ifndef NO_ERRNO
  123. #  define DECLARE_ERRNO  /* everybody except MSC 6.0, SCO cc, Watcom C/386 */
  124. #endif /* !NO_ERRNO */
  125. #ifdef VMS
  126. #  include <types.h>     /* (placed up here instead of in VMS section below */
  127. #  include <stat.h>      /* because types.h is used in some other headers) */
  128. #else /* !VMS */
  129. #  if !defined(THINK_C) && !defined(MPW)
  130. #    include <sys/types.h>                 /* off_t, time_t, dev_t, ... */
  131. #    include <sys/stat.h>
  132. #  endif /* !THINK_C && !MPW */
  133. #endif /* ?VMS */
  134.  
  135. #ifdef MODERN
  136. #  if (!defined(M_XENIX) && !(defined(__GNUC__) && defined(sun)))
  137. #    include <stddef.h>
  138. #  endif
  139. #  if (!defined(__GNUC__) && !defined(apollo))   /* both define __STDC__ */
  140. #    include <stdlib.h>    /* standard library prototypes, malloc(), etc. */
  141. #  else
  142. #    ifdef __EMX__
  143. #      include <stdlib.h>  /* emx IS gcc but has stdlib.h */
  144. #    endif
  145. #  endif
  146. #  include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  147.    typedef size_t extent;
  148.    typedef void voidp;
  149. #else /* !MODERN */
  150.    char *malloc();
  151.    char *strchr(), *strrchr();
  152.    long lseek();
  153.    typedef unsigned int extent;
  154. #  define void int
  155.    typedef char voidp;
  156. #endif /* ?MODERN */
  157.  
  158. /* this include must be down here for SysV.4, for some reason... */
  159. #include <signal.h>      /* used in unzip.c, file_io.c */
  160.  
  161.  
  162.  
  163. /*---------------------------------------------------------------------------
  164.     Next, a word from our Unix (mostly) sponsors:
  165.   ---------------------------------------------------------------------------*/
  166.  
  167. #ifdef UNIX
  168. #  ifdef AMIGA
  169. #    include <libraries/dos.h>
  170. #  else /* !AMIGA */
  171. #    ifndef NO_PARAM_H
  172. #if 0  /* [GRR: this is an alternate fix for SCO's redefinition bug] */
  173. #      ifdef NGROUPS_MAX
  174. #        undef NGROUPS_MAX     /* SCO bug:  defined again in <param.h> */
  175. #      endif /* NGROUPS_MAX */
  176. #endif /* 0 */
  177. #      include <sys/param.h>   /* conflict with <sys/types.h>, some systems? */
  178. #    endif /* !NO_PARAM_H */
  179. #  endif /* ?AMIGA */
  180.  
  181. #  ifndef BSIZE
  182. #    ifdef MINIX
  183. #      define BSIZE   1024
  184. #    else /* !MINIX */
  185. #      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
  186. #    endif /* ?MINIX */
  187. #  endif
  188.  
  189. #  ifndef BSD
  190. #    if (!defined(AMIGA) && !defined(MINIX))
  191. #      define NO_MKDIR           /* for mapname() */
  192. #    endif /* !AMIGA && !MINIX */
  193. #    include <time.h>
  194.      struct tm *gmtime(), *localtime();
  195. #  else   /* BSD */
  196. #    include <sys/time.h>
  197. #    include <sys/timeb.h>
  198. #    ifdef _AIX
  199. #      include <time.h>
  200. #    endif
  201. #  endif
  202.  
  203. #else   /* !UNIX */
  204. #  define BSIZE   512               /* disk block size */
  205. #endif /* ?UNIX */
  206.  
  207. #if (defined(V7) || defined(BSD))
  208. #  define strchr    index
  209. #  define strrchr   rindex
  210. #endif
  211.  
  212. /*---------------------------------------------------------------------------
  213.     And now, our MS-DOS and OS/2 corner:
  214.   ---------------------------------------------------------------------------*/
  215.  
  216. #ifdef __TURBOC__
  217. #  define DOS_OS2
  218. #  include <sys/timeb.h>      /* for structure ftime                        */
  219. #  ifndef __BORLANDC__        /* there appears to be a bug (?) in Borland's */
  220. #    include <mem.h>          /*   MEM.H related to __STDC__ and far poin-  */
  221. #  endif                      /*   ters. (dpk)  [mem.h included for memcpy] */
  222. #  include <dos.h>            /* for REGS macro (at least for Turbo C 2.0)  */
  223. #else                         /* NOT Turbo C (or Power C)...                */
  224. #  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
  225. #    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
  226. #      define MSC             /*   necessary (it is in 5.0; apparently not  */
  227. #    endif                    /*   in 5.1 and 6.0)                          */
  228. #    include <dos.h>          /* for _dos_setftime()                        */
  229. #  endif
  230. #endif
  231.  
  232. #if (defined(__IBMC__) && defined(__OS2__))
  233. #  define DOS_OS2
  234. #  define S_IFMT 0xF000
  235. #  define timezone _timezone
  236. #endif
  237.  
  238. #ifdef __WATCOMC__
  239. #  define DOS_OS2
  240. #  define __32BIT__
  241. #  ifdef DECLARE_ERRNO
  242. #    undef DECLARE_ERRNO
  243. #  endif
  244. #  undef far
  245. #  define far
  246. #endif
  247.  
  248. #ifdef __EMX__
  249. #  define DOS_OS2
  250. #  define __32BIT__
  251. #  define far
  252. #endif /* __EMX__ */
  253.  
  254. #ifdef MSC                    /* defined for all versions of MSC now         */
  255. #  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
  256. #  if (defined(_MSC_VER) && (_MSC_VER >= 600))    /* new with 5.1 or 6.0 ... */
  257. #    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
  258. #  endif                      /*   library (or something)--incompatible with */
  259. #endif                        /*   the usual "extern int errno" declaration  */
  260.  
  261. #ifdef DOS_OS2                /* defined for all MS-DOS and OS/2 compilers   */
  262. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  263. #  include <time.h>           /* localtime() */
  264. #endif
  265.  
  266. #ifdef OS2                    /* defined for all OS/2 compilers */
  267. #  ifdef isupper
  268. #    undef isupper
  269. #  endif
  270. #  ifdef tolower
  271. #    undef tolower
  272. #  endif
  273. #  define isupper(x)   IsUpperNLS((unsigned char)(x))
  274. #  define tolower(x)   ToLowerNLS((unsigned char)(x))
  275. #endif
  276.  
  277. #ifdef WIN32
  278. #  include <io.h>             /* read(), open(), etc. */
  279. #  include <time.h>
  280. #  include <memory.h>
  281. #  include <direct.h>         /* mkdir() */
  282. #  ifdef FILE_IO_C
  283. #    include <fcntl.h>
  284. #    include <conio.h>
  285. #    include <sys\types.h>
  286. #    include <sys\utime.h>
  287. #    include <windows.h>
  288. #    define DOS_OS2
  289. #    define getch() getchar()
  290. #  endif
  291. #endif
  292.  
  293. /*---------------------------------------------------------------------------
  294.     Followed by some VMS (mostly) stuff:
  295.   ---------------------------------------------------------------------------*/
  296.  
  297. #ifdef VMS
  298. #  include <time.h>               /* the usual non-BSD time functions */
  299. #  include <file.h>               /* same things as fcntl.h has */
  300. #  include <rms.h>
  301. #  define _MAX_PATH NAM$C_MAXRSS  /* to define FILNAMSIZ below */
  302. #  define UNIX                    /* can share most of same code from now on */
  303. #  define RETURN    return_VMS    /* VMS interprets return codes incorrectly */
  304. #else /* !VMS */
  305. #  ifndef THINK_C
  306. #    define RETURN  return        /* only used in main() */
  307. #  else
  308. #    define RETURN(v) { int n;\
  309.                         n = (v);\
  310.                         fprintf(stderr, "\npress <return> to continue ");\
  311.                         while (getc(stdin) != '\n');\
  312.                         putc('\n', stderr);\
  313.                         InitCursor();\
  314.                         goto start;\
  315.                       }
  316. #  endif
  317. #  ifdef V7
  318. #    define O_RDONLY  0
  319. #    define O_WRONLY  1
  320. #    define O_RDWR    2
  321. #  else /* !V7 */
  322. #    ifdef MTS
  323. #      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  324. #      include <timeb.h>
  325. #      include <time.h>
  326. #    else /* !MTS */
  327. #      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
  328. #        include <sys/fcntl.h>
  329. #        define SHORT_NAMES
  330. #        define tzset  settz
  331. #      else /* !COHERENT */
  332. #        include <fcntl.h>      /* O_BINARY for open() w/o CR/LF translation */
  333. #      endif /* ?COHERENT */
  334. #    endif /* ?MTS */
  335. #  endif /* ?V7 */
  336. #endif /* ?VMS */
  337.  
  338. #if (defined(MSDOS) || defined(VMS))
  339. #  define DOS_VMS
  340. #endif
  341.  
  342. /*---------------------------------------------------------------------------
  343.     And some Mac stuff for good measure:
  344.   ---------------------------------------------------------------------------*/
  345.  
  346. #ifdef THINK_C
  347. #  define MACOS
  348. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  349. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  350. #  else /* __STDC__ defined */
  351. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  352. #      undef __STDC__         /*   it needs to be 1 or required header */
  353. #      define __STDC__ 1      /*   files are not properly included. */
  354. #    endif /* !__STDC__ */
  355. #  endif /* ?defined(__STDC__) */
  356. #endif /* THINK_C */
  357.  
  358. #ifdef MPW
  359. #  define MACOS
  360. #  include <Errors.h>
  361. #  include <Files.h>
  362. #  include <Memory.h>
  363. #  include <Quickdraw.h>
  364. #  include <ToolUtils.h>
  365. #  define CtoPstr c2pstr
  366. #  define PtoCstr p2cstr
  367. #  ifdef CR
  368. #    undef  CR
  369. #  endif
  370. #endif /* MPW */
  371.  
  372. #ifdef MACOS
  373. #  define open(x,y) macopen(x,y, gnVRefNum, glDirID)
  374. #  define close macclose
  375. #  define read macread
  376. #  define write macwrite
  377. #  define lseek maclseek
  378. #  define creat(x,y) maccreat(x, gnVRefNum, glDirID, gostCreator, gostType)
  379. #  define stat(x,y) macstat(x,y,gnVRefNum, glDirID)
  380.  
  381. #  ifndef isascii
  382. #    define isascii(c) ((unsigned char)(c) <= 0x3F)
  383. #  endif
  384.  
  385. #  include "macstat.h"
  386.  
  387. typedef struct _ZipExtraHdr {
  388.     unsigned short header;    /*    2 bytes */
  389.     unsigned short data;      /*    2 bytes */
  390. } ZIP_EXTRA_HEADER;
  391.  
  392. typedef struct _MacInfoMin {
  393.     unsigned short header;    /*    2 bytes */
  394.     unsigned short data;      /*    2 bytes */
  395.     unsigned long signature;  /*    4 bytes */
  396.     FInfo finfo;              /*   16 bytes */
  397.     unsigned long lCrDat;     /*    4 bytes */
  398.     unsigned long lMdDat;     /*    4 bytes */
  399.     unsigned long flags ;     /*    4 bytes */
  400.     unsigned long lDirID;     /*    4 bytes */
  401.                               /*------------*/
  402. } MACINFOMIN;                 /* = 40 bytes for size of data */
  403.  
  404. typedef struct _MacInfo {
  405.     unsigned short header;    /*    2 bytes */
  406.     unsigned short data;      /*    2 bytes */
  407.     unsigned long signature;  /*    4 bytes */
  408.     FInfo finfo;              /*   16 bytes */
  409.     unsigned long lCrDat;     /*    4 bytes */
  410.     unsigned long lMdDat;     /*    4 bytes */
  411.     unsigned long flags ;     /*    4 bytes */
  412.     unsigned long lDirID;     /*    4 bytes */
  413.     char rguchVolName[28];    /*   28 bytes */
  414.                               /*------------*/
  415. } MACINFO;                    /* = 68 bytes for size of data */
  416. #endif /* MACOS */
  417.  
  418. /*---------------------------------------------------------------------------
  419.     And finally, some random extra stuff:
  420.   ---------------------------------------------------------------------------*/
  421.  
  422. #ifdef MINIX
  423. #  include <stdio.h>
  424. #endif
  425.  
  426. #ifdef SHORT_NAMES         /* Mark Williams C, ...? */
  427. #  define extract_or_test_files    xtr_or_tst_files
  428. #  define extract_or_test_member   xtr_or_tst_member
  429. #endif
  430.  
  431. #ifdef MTS
  432. #  include <unix.h>          /* Some important non-ANSI routines */
  433. #  define mkdir(s,n) (-1)    /* No "make directory" capability */
  434. #  define EBCDIC             /* Set EBCDIC conversion on */
  435. #endif
  436.  
  437.  
  438.  
  439.  
  440.  
  441. /*************/
  442. /*  Defines  */
  443. /*************/
  444.  
  445. #ifndef WSIZE
  446. #  define WSIZE 0x8000       /* window size--must be a power of two, and */
  447. #endif /* !WSIZE */          /*  at least 32K for zip's deflate method */
  448.  
  449. #define DIR_BLKSIZ    64     /* number of directory entries per block
  450.                               *  (should fit in 4096 bytes, usually) */
  451. #ifndef INBUFSIZ
  452. #  define INBUFSIZ    2048   /* works for MS-DOS small model */
  453. #endif /* !INBUFSIZ */
  454.  
  455. /*
  456.  * If <limits.h> exists on most systems, should include that, since it may
  457.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  458.  * _POSIX_PATH_MAX.
  459.  */
  460. #ifdef DOS_OS2
  461. #  include <limits.h>
  462. #endif /* DOS_OS2 */
  463.  
  464. #ifdef _MAX_PATH
  465. #  define FILNAMSIZ       (_MAX_PATH)
  466. #else /* !_MAX_PATH */
  467. #  define FILNAMSIZ       1025
  468. #endif /* ?_MAX_PATH */
  469.  
  470. #ifndef PATH_MAX
  471. #  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems */
  472. #    define PATH_MAX      MAXPATHLEN
  473. #  else
  474. #    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
  475. #      define PATH_MAX    FILENAME_MAX
  476. #    else
  477. #      define PATH_MAX    (FILNAMSIZ - 1)
  478. #    endif
  479. #  endif /* ?MAXPATHLEN */
  480. #endif /* !PATH_MAX */
  481.  
  482. #define OUTBUFSIZ         INBUFSIZ
  483.  
  484. #define ZSUFX             ".zip"
  485. #define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  486. #define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
  487. #define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for */
  488. #define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
  489.  
  490. #define SKIP              0    /* choice of activities for do_string() */
  491. #define DISPLAY           1
  492. #define FILENAME          2
  493. #define EXTRA_FIELD       3
  494.  
  495. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  496. #define EXISTS_AND_OLDER  0
  497. #define EXISTS_AND_NEWER  1
  498.  
  499. #define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
  500. #define AMIGA_            1
  501. #define VMS_              2    /* make sure these are not defined on */
  502. #define UNIX_             3    /*  the respective systems!!  (like, for */
  503. #define VM_CMS_           4    /*  instance, "VMS", or "UNIX":  CFLAGS = */
  504. #define ATARI_            5    /*  -O -DUNIX) */
  505. #define OS2_HPFS_         6
  506. #define MAC_              7
  507. #define Z_SYSTEM_         8
  508. #define CPM_              9
  509. /* #define TOPS20_   10?  (TOPS20_ is to be defined in PKZIP 2.0...)  */
  510. #define NUM_HOSTS         10   /* index of last system + 1 */
  511.  
  512. #define STORED            0    /* compression methods */
  513. #define SHRUNK            1
  514. #define REDUCED1          2
  515. #define REDUCED2          3
  516. #define REDUCED3          4
  517. #define REDUCED4          5
  518. #define IMPLODED          6
  519. #define TOKENIZED         7
  520. #define DEFLATED          8
  521. #define NUM_METHODS       9    /* index of last method + 1 */
  522. /* don't forget to update list_files() appropriately if NUM_METHODS changes */
  523.  
  524. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  525. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  526. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  527.  
  528. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  529. #define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
  530.  
  531. /*---------------------------------------------------------------------------
  532.     True sizes of the various headers, as defined by PKWare--so it is not
  533.     likely that these will ever change.  But if they do, make sure both these
  534.     defines AND the typedefs below get updated accordingly.
  535.   ---------------------------------------------------------------------------*/
  536. #define LREC_SIZE     26    /* lengths of local file headers, central */
  537. #define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  538. #define ECREC_SIZE    18    /*  central-dir record, respectively      */
  539.  
  540. #define MAX_BITS      13                 /* used in unShrink() */
  541. #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  542.  
  543. #define LF      10    /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
  544. #define CR      13    /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
  545. #define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
  546.  
  547. #ifdef EBCDIC
  548. #  define ascii_to_native(c)   ebcdic[(c)]
  549. #  define NATIVE    "EBCDIC"
  550. #endif
  551.  
  552. #if MPW
  553. #  define FFLUSH    putc('\n',stderr);
  554. #else /* !MPW */
  555. #  define FFLUSH    fflush(stderr);
  556. #endif /* ?MPW */
  557.  
  558. #ifdef VMS
  559. #  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
  560. #  define ENV_ZIPINFO   "ZIPINFO_OPTS"
  561. #else /* !VMS */
  562. #  define ENV_UNZIP     "UNZIP"
  563. #  define ENV_ZIPINFO   "ZIPINFO"
  564. #endif /* ?VMS */
  565.  
  566. #ifdef CRYPT
  567. #  define PWLEN         80
  568. #  define DECRYPT(b)    (update_keys(t=((b)&0xff)^decrypt_byte()),t)
  569. #endif /* CRYPT */
  570.  
  571. #ifdef QQ  /* Newtware version */
  572. #  define QCOND   (!quietflg)   /* for no file comments with -vq or -vqq */
  573. #else      /* (original) Bill Davidsen version  */
  574. #  define QCOND   (which_hdr)   /* no way to kill file comments with -v, -l */
  575. #endif
  576.  
  577. #ifndef TRUE
  578. #  define TRUE      1   /* sort of obvious */
  579. #endif
  580. #ifndef FALSE
  581. #  define FALSE     0
  582. #endif
  583.  
  584. #ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
  585. #  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
  586. #  define SEEK_CUR  1
  587. #  define SEEK_END  2
  588. #endif
  589.  
  590. #ifndef S_IRUSR
  591. #  define S_IRWXU       00700       /* read, write, execute: owner */
  592. #  define S_IRUSR       00400       /* read permission: owner */
  593. #  define S_IWUSR       00200       /* write permission: owner */
  594. #  define S_IXUSR       00100       /* execute permission: owner */
  595. #  define S_IRWXG       00070       /* read, write, execute: group */
  596. #  define S_IRGRP       00040       /* read permission: group */
  597. #  define S_IWGRP       00020       /* write permission: group */
  598. #  define S_IXGRP       00010       /* execute permission: group */
  599. #  define S_IRWXO       00007       /* read, write, execute: other */
  600. #  define S_IROTH       00004       /* read permission: other */
  601. #  define S_IWOTH       00002       /* write permission: other */
  602. #  define S_IXOTH       00001       /* execute permission: other */
  603. #endif /* !S_IRUSR */
  604.  
  605. #ifdef ZIPINFO      /* these are individually checked because SysV doesn't */
  606. #  ifndef S_IFBLK   /*  have some of them, Microsoft C others, etc. */
  607. #    define   S_IFBLK     0060000     /* block special */
  608. #  endif
  609. #  ifndef S_IFIFO  /* in Borland C, not MSC */
  610. #    define   S_IFIFO     0010000     /* fifo */
  611. #  endif
  612. #  ifndef S_IFLNK  /* in BSD, not SysV */
  613. #    define   S_IFLNK     0120000     /* symbolic link */
  614. #  endif
  615. #  ifndef S_IFSOCK  /* in BSD, not SysV */
  616. #    define   S_IFSOCK    0140000     /* socket */
  617. #  endif
  618. #  ifndef S_ISUID
  619. #    define S_ISUID       04000       /* set user id on execution */
  620. #  endif
  621. #  ifndef S_ISGID
  622. #    define S_ISGID       02000       /* set group id on execution */
  623. #  endif
  624. #  ifndef S_ISVTX
  625. #    define S_ISVTX       01000       /* directory permissions control */
  626. #  endif
  627. #  ifndef S_ENFMT
  628. #    define S_ENFMT       S_ISGID     /* record locking enforcement flag */
  629. #  endif
  630. #endif /* ZIPINFO */
  631.  
  632.  
  633.  
  634.  
  635.  
  636. /**************/
  637. /*  Typedefs  */
  638. /**************/
  639.  
  640. #ifndef _BULL_SOURCE                /* Bull has it defined somewhere already */
  641.    typedef unsigned char  byte;     /* code assumes UNSIGNED bytes */
  642. #endif /* !_BULL_SOURCE */
  643.  
  644. typedef char              boolean;
  645. typedef long              longint;
  646. typedef unsigned short    UWORD;
  647. typedef unsigned long     ULONG;
  648. typedef unsigned char     uch;
  649. typedef unsigned short    ush;
  650. typedef unsigned long     ulg;
  651.  
  652. typedef struct min_info {
  653.     unsigned unix_attr;
  654.     unsigned dos_attr;
  655.     int hostnum;
  656.     longint offset;
  657.     ULONG compr_size;        /* compressed size (needed if extended header) */
  658.     ULONG crc;               /* crc (needed if extended header) */
  659.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  660.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  661.     unsigned text : 1;       /* file is text or binary */
  662.     unsigned lcflag : 1;     /* convert filename to lowercase */
  663. } min_info;
  664.  
  665. typedef struct VMStimbuf {
  666.     char *revdate;           /* (both correspond to Unix modtime/st_mtime) */
  667.     char *credate;
  668. } VMStimbuf;
  669.  
  670. /*---------------------------------------------------------------------------
  671.     Zipfile layout declarations.  If these headers ever change, make sure the
  672.     xxREC_SIZE defines (above) change with them!
  673.   ---------------------------------------------------------------------------*/
  674.  
  675.    typedef byte   local_byte_hdr[ LREC_SIZE ];
  676. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  677. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  678. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  679. #      define L_COMPRESSION_METHOD              4
  680. #      define L_LAST_MOD_FILE_TIME              6
  681. #      define L_LAST_MOD_FILE_DATE              8
  682. #      define L_CRC32                           10
  683. #      define L_COMPRESSED_SIZE                 14
  684. #      define L_UNCOMPRESSED_SIZE               18
  685. #      define L_FILENAME_LENGTH                 22
  686. #      define L_EXTRA_FIELD_LENGTH              24
  687.  
  688.    typedef byte   cdir_byte_hdr[ CREC_SIZE ];
  689. #      define C_VERSION_MADE_BY_0               0
  690. #      define C_VERSION_MADE_BY_1               1
  691. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  692. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  693. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  694. #      define C_COMPRESSION_METHOD              6
  695. #      define C_LAST_MOD_FILE_TIME              8
  696. #      define C_LAST_MOD_FILE_DATE              10
  697. #      define C_CRC32                           12
  698. #      define C_COMPRESSED_SIZE                 16
  699. #      define C_UNCOMPRESSED_SIZE               20
  700. #      define C_FILENAME_LENGTH                 24
  701. #      define C_EXTRA_FIELD_LENGTH              26
  702. #      define C_FILE_COMMENT_LENGTH             28
  703. #      define C_DISK_NUMBER_START               30
  704. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  705. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  706. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  707.  
  708.    typedef byte   ec_byte_rec[ ECREC_SIZE+4 ];
  709. /*     define SIGNATURE                         0   space-holder only */
  710. #      define NUMBER_THIS_DISK                  4
  711. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  712. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  713. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  714. #      define SIZE_CENTRAL_DIRECTORY            12
  715. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  716. #      define ZIPFILE_COMMENT_LENGTH            20
  717.  
  718.  
  719.    typedef struct local_file_header {                 /* LOCAL */
  720.        byte version_needed_to_extract[2];
  721.        UWORD general_purpose_bit_flag;
  722.        UWORD compression_method;
  723.        UWORD last_mod_file_time;
  724.        UWORD last_mod_file_date;
  725.        ULONG crc32;
  726.        ULONG compressed_size;
  727.        ULONG uncompressed_size;
  728.        UWORD filename_length;
  729.        UWORD extra_field_length;
  730.    } local_file_hdr;
  731.  
  732.    typedef struct central_directory_file_header {     /* CENTRAL */
  733.        byte version_made_by[2];
  734.        byte version_needed_to_extract[2];
  735.        UWORD general_purpose_bit_flag;
  736.        UWORD compression_method;
  737.        UWORD last_mod_file_time;
  738.        UWORD last_mod_file_date;
  739.        ULONG crc32;
  740.        ULONG compressed_size;
  741.        ULONG uncompressed_size;
  742.        UWORD filename_length;
  743.        UWORD extra_field_length;
  744.        UWORD file_comment_length;
  745.        UWORD disk_number_start;
  746.        UWORD internal_file_attributes;
  747.        ULONG external_file_attributes;
  748.        ULONG relative_offset_local_header;
  749.    } cdir_file_hdr;
  750.  
  751.    typedef struct end_central_dir_record {            /* END CENTRAL */
  752.        UWORD number_this_disk;
  753.        UWORD num_disk_with_start_central_dir;
  754.        UWORD num_entries_centrl_dir_ths_disk;
  755.        UWORD total_entries_central_dir;
  756.        ULONG size_central_directory;
  757.        ULONG offset_start_central_directory;
  758.        UWORD zipfile_comment_length;
  759.    } ecdir_rec;
  760.  
  761.  
  762.  
  763.  
  764.  
  765. /*************************/
  766. /*  Function Prototypes  */
  767. /*************************/
  768.  
  769. #ifndef __
  770. #  define __   OF
  771. #endif
  772.  
  773. /*---------------------------------------------------------------------------
  774.     Functions in unzip.c and/or zipinfo.c:
  775.   ---------------------------------------------------------------------------*/
  776.  
  777. int    usage                     __((int error));
  778. int    process_zipfile           __((void));
  779. int    find_end_central_dir      __((void));
  780. int    process_end_central_dir   __((void));
  781. int    list_files                __((void));                      /* unzip.c */
  782. int    process_cdir_file_hdr     __((void));                      /* unzip.c */
  783. int    process_local_file_hdr    __((void));                      /* unzip.c */
  784. int    process_central_dir       __((void));
  785. int    long_info                 __((void));                    /* zipinfo.c */
  786. int    short_info                __((void));                    /* zipinfo.c */
  787. char   *zipinfo_time             __((UWORD *datez, UWORD *timez));
  788.  
  789. /*---------------------------------------------------------------------------
  790.     Functions in extract.c:
  791.   ---------------------------------------------------------------------------*/
  792.  
  793. int    extract_or_test_files     __((void));
  794. /* static int   store_info               __((void)); */
  795. /* static int   extract_or_test_member   __((void)); */
  796. int    memextract                __((byte *, ULONG, byte *, ULONG));
  797. int    FlushMemory               __((void));
  798. int    ReadMemoryByte            __((UWORD *x));
  799.  
  800. /*---------------------------------------------------------------------------
  801.     Decompression functions:
  802.   ---------------------------------------------------------------------------*/
  803.  
  804. int    explode                   __((void));                    /* explode.c */
  805.  
  806. int    inflate                   __((void));                    /* inflate.c */
  807.  
  808. void   unReduce                  __((void));                   /* unreduce.c */
  809. /* static void  LoadFollowers    __((void));                    * unreduce.c */
  810.  
  811. void   unShrink                  __((void));                   /* unshrink.c */
  812. /* static void  partial_clear    __((void));                    * unshrink.c */
  813.  
  814. /*---------------------------------------------------------------------------
  815.     Functions in file_io.c and crypt.c:
  816.   ---------------------------------------------------------------------------*/
  817.  
  818. int    open_input_file           __((void));                    /* file_io.c */
  819. int    readbuf                   __((char *buf, register unsigned len));
  820. int    create_output_file        __((void));             /* file_io.c, vms.c */
  821. int    FillBitBuffer             __((void));                    /* file_io.c */
  822. int    ReadByte                  __((UWORD *x));                /* file_io.c */
  823. int    FlushOutput               __((void));             /* file_io.c, vms.c */
  824. /* static int   dos2unix         __((unsigned char *, int));     * file_io.c */
  825. void   set_file_time_and_close   __((void));                    /* file_io.c */
  826. void   handler                   __((int signal));              /* file_io.c */
  827. int    echo                      __((int opt));                 /* file_io.c */
  828. void   echoff                    __((int f));                   /* file_io.c */
  829. void   echon                     __((void));                    /* file_io.c */
  830. char   *getp                     __((char *, char *, int));     /* file_io.c */
  831.  
  832. int    decrypt_byte              __((void));                      /* crypt.c */
  833. void   update_keys               __((int));                       /* crypt.c */
  834. void   init_keys                 __((char *));                    /* crypt.c */
  835.  
  836. /*---------------------------------------------------------------------------
  837.     Macintosh file_io functions:
  838.   ---------------------------------------------------------------------------*/
  839.  
  840. #ifdef MACOS
  841. /* static int   IsHFSDisk        __((int)); */
  842.    void     macfstest            __((int));
  843.    int      macmkdir             __((char *, short, long));
  844.    void     ResolveMacVol        __((short, short *, long *, StringPtr));
  845.    short    macopen              __((char *, short, short, long));
  846.    short    maccreat             __((char *, short, long, OSType, OSType));
  847.    short    macread              __((short, char *, unsigned));
  848.    short    macwrite             __((short, char *, unsigned));
  849.    short    macclose             __((short));
  850.    long     maclseek             __((short, long, short));
  851. #endif
  852.  
  853. /*---------------------------------------------------------------------------
  854.     OS/2 file_io functions:
  855.   ---------------------------------------------------------------------------*/
  856.  
  857. void     ChangeNameForFAT  __((char *name));                   /* os2unzip.c */
  858. int      IsFileNameValid   __((char *name));                   /* os2unzip.c */
  859. int      GetCountryInfo    __((void));                         /* os2unzip.c */
  860. long     GetFileTime       __((char *name));                   /* os2unzip.c */
  861. void     SetPathInfo __((char *path, UWORD moddate, UWORD modtime, int flags));
  862. int      SetLongNameEA     __((char *name, char *longname));   /* os2unzip.c */
  863. int      IsEA              __((void *extra_field));            /* os2unzip.c */
  864. ULONG    SizeOfEAs         __((void *extra_field));            /* os2unzip.c */
  865. void     SetEAs            __((char *path, void *eablock));    /* os2unzip.c */
  866. int      IsUpperNLS        __((int nChr));                     /* os2unzip.c */
  867. int      ToLowerNLS        __((int nChr));                     /* os2unzip.c */
  868.  
  869. /*---------------------------------------------------------------------------
  870.     VMS file_io functions:
  871.   ---------------------------------------------------------------------------*/
  872.  
  873. int      check_format      __((void));                              /* vms.c */
  874. int      find_vms_attrs    __((void));                              /* vms.c */
  875. int      CloseOutputFile   __((void));                              /* vms.c */
  876. /* static byte *extract_block __((struct extra_block *, int *, byte *, int));*/
  877. /* static int  _flush_blocks  __((int final_flag));                  * vms.c */
  878. /* static int  _flush_records __((int final_flag));                  * vms.c */
  879. /* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c */
  880. /* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c */
  881. /* static void message        __((int string, char *status));        * vms.c */
  882.  
  883. int      VMSmunch          __((char *, int, char *));          /* VMSmunch.c */
  884.  
  885. /*---------------------------------------------------------------------------
  886.     Functions in match.c, mapname.c, misc.c, etc.:
  887.   ---------------------------------------------------------------------------*/
  888.  
  889. int      match             __((char *string, char *pattern));     /* match.c */
  890.  
  891. int      mapname           __((int create_dirs));               /* mapname.c */
  892.  
  893. void     UpdateCRC         __((register unsigned char *s, register int len));
  894. int      do_string         __((unsigned int len, int option));     /* misc.c */
  895. time_t   dos_to_unix_time  __((unsigned ddate, unsigned dtime));   /* misc.c */
  896. int      check_for_newer   __((char *filename));                   /* misc.c */
  897. int      dateformat        __((void));                             /* misc.c */
  898. UWORD    makeword          __((byte *b));                          /* misc.c */
  899. ULONG    makelong          __((byte *sig));                        /* misc.c */
  900. void     return_VMS        __((int zip_error));                    /* misc.c */
  901.  
  902. void     envargs           __((int *, char ***, char *));       /* envargs.c */
  903.  
  904. #ifdef AMIGA
  905.    int   utime             __((char *file, time_t timep[]));      /* utime.c */
  906. #endif /* AMIGA */
  907.  
  908. #ifdef ZMEM   /* these MUST be ifdef'd because of conflicts with the std def */
  909.    char  *memset           __((register char *buf, register char init,
  910.                                register unsigned int len));        /* misc.c */
  911.    char  *memcpy           __((register char *dst, register char *src,
  912.                                register unsigned int len));        /* misc.c */
  913. #endif /* ZMEM */
  914.  
  915.  
  916.  
  917.  
  918.  
  919. /************/
  920. /*  Macros  */
  921. /************/
  922.  
  923. #ifndef MAX
  924. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  925. #endif
  926.  
  927. #ifndef MIN
  928. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  929. #endif
  930.  
  931.  
  932. #define LSEEK(abs_offset) {longint request=(abs_offset)+extra_bytes,\
  933.    inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  934.    if(request<0) {fprintf(stderr, SeekMsg, ReportMsg); return(3);}\
  935.    else if(bufstart!=cur_zipfile_bufstart)\
  936.    {cur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
  937.    if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  938.    inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;} else\
  939.    {incnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;}}
  940.  
  941. /*
  942.  *  Seek to the block boundary of the block which includes abs_offset,
  943.  *  then read block into input buffer and set pointers appropriately.
  944.  *  If block is already in the buffer, just set the pointers.  This macro
  945.  *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
  946.  *  A slightly modified version is embedded within extract_or_test_files
  947.  *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  948.  *
  949.  *  macro LSEEK(abs_offset)
  950.  *      ULONG   abs_offset;
  951.  *  {
  952.  *      longint   request = abs_offset + extra_bytes;
  953.  *      longint   inbuf_offset = request % INBUFSIZ;
  954.  *      longint   bufstart = request - inbuf_offset;
  955.  *
  956.  *      if (request < 0) {
  957.  *          fprintf(stderr, SeekMsg, ReportMsg);
  958.  *          return(3);             /-* 3:  severe error in zipfile *-/
  959.  *      } else if (bufstart != cur_zipfile_bufstart) {
  960.  *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  961.  *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  962.  *              return(51);        /-* 51:  unexpected EOF *-/
  963.  *          inptr = inbuf + (int)inbuf_offset;
  964.  *          incnt -= (int)inbuf_offset;
  965.  *      } else {
  966.  *          incnt += (inptr-inbuf) - (int)inbuf_offset;
  967.  *          inptr = inbuf + (int)inbuf_offset;
  968.  *      }
  969.  *  }
  970.  *
  971.  */
  972.  
  973.  
  974. #define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  975.   {error_in_archive=error; if(error>1) return error;}
  976.  
  977. /*
  978.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  979.  *  and unzip.c in several functions.
  980.  *
  981.  *  macro SKIP_(length)
  982.  *      UWORD   length;
  983.  *  {
  984.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  985.  *          error_in_archive = error;   /-* might be warning *-/
  986.  *          if (error > 1)              /-* fatal *-/
  987.  *              return (error);
  988.  *      }
  989.  *  }
  990.  *
  991.  */
  992.  
  993.  
  994. #define OUTB(intc) {*outptr++=(byte)(intc); if (++outcnt==OUTBUFSIZ)\
  995.   FlushOutput();}
  996.  
  997. /*
  998.  *  macro OUTB(intc)
  999.  *  {
  1000.  *      *outptr++ = (byte)(intc);
  1001.  *      if (++outcnt == OUTBUFSIZ)
  1002.  *          FlushOutput();
  1003.  *  }
  1004.  *
  1005.  */
  1006.  
  1007.  
  1008. #define READBIT(nbits,zdest) {if(nbits>bits_left) FillBitBuffer();\
  1009.   zdest=(int)((UWORD)bitbuf&mask_bits[nbits]);bitbuf>>=nbits;bits_left-=nbits;}
  1010.  
  1011. /*
  1012.  * macro READBIT(nbits,zdest)
  1013.  *  {
  1014.  *      if (nbits > bits_left)
  1015.  *          FillBitBuffer();
  1016.  *      zdest = (int)((UWORD)bitbuf & mask_bits[nbits]);
  1017.  *      bitbuf >>= nbits;
  1018.  *      bits_left -= nbits;
  1019.  *  }
  1020.  *
  1021.  */
  1022.  
  1023.  
  1024. #define PEEKBIT(nbits) (nbits>bits_left? (FillBitBuffer(),\
  1025.   (UWORD)bitbuf & mask_bits[nbits]) : (UWORD)bitbuf & mask_bits[nbits])
  1026.  
  1027.  
  1028. #define NUKE_CRs(buf,len) {register int i,j; for (i=j=0; j<len;\
  1029.   (buf)[i++]=(buf)[j++]) if ((buf)[j]=='\r') ++j; len=i;}
  1030.  
  1031. /*
  1032.  *  Remove all the ASCII carriage returns from buffer buf (length len),
  1033.  *  shortening as necessary (note that len gets modified in the process,
  1034.  *  so it CANNOT be an expression).  This macro is intended to be used
  1035.  *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  1036.  *  if-test gets performed one time too many, but it doesn't matter.
  1037.  *
  1038.  *  macro NUKE_CRs(buf,len)
  1039.  *  {
  1040.  *      register int   i, j;
  1041.  *
  1042.  *      for (i = j = 0;  j < len;  (buf)[i++] = (buf)[j++])
  1043.  *          if ((buf)[j] == CR)
  1044.  *              ++j;
  1045.  *      len = i;
  1046.  *  }
  1047.  *
  1048.  */
  1049.  
  1050.  
  1051. #define TOLOWER(str1,str2) {char *ps1,*ps2; ps1=(str1)-1; ps2=(str2);\
  1052.   while(*++ps1) *ps2++=(char)(isupper((int)(*ps1))?tolower((int)(*ps1)):*ps1);\
  1053.   *ps2='\0';}
  1054.  
  1055. /*
  1056.  *  Copy the zero-terminated string in str1 into str2, converting any
  1057.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1058.  *  as well, of course.  str1 and str2 may be the same character array.
  1059.  *
  1060.  *  macro TOLOWER( str1, str2 )
  1061.  *  {
  1062.  *      char  *ps1, *ps2;
  1063.  *
  1064.  *      ps1 = (str1) - 1;
  1065.  *      ps2 = (str2);
  1066.  *      while (*++ps1)
  1067.  *          *ps2++ = (char)(isupper((int)(*ps1))? tolower((int)(*ps1)) : *ps1);
  1068.  *      *ps2='\0';
  1069.  *  }
  1070.  *
  1071.  *  NOTES:  This macro makes no assumptions about the characteristics of
  1072.  *    the tolower() function or macro (beyond its existence), nor does it
  1073.  *    make assumptions about the structure of the character set (i.e., it
  1074.  *    should work on EBCDIC machines, too).  The fact that either or both
  1075.  *    of isupper() and tolower() may be macros has been taken into account;
  1076.  *    watch out for "side effects" (in the C sense) when modifying this
  1077.  *    macro.
  1078.  */
  1079.  
  1080.  
  1081. #ifndef ascii_to_native
  1082. #  define ascii_to_native(c)   (c)
  1083. #  define A_TO_N(str1)
  1084. #else
  1085. #  ifndef NATIVE
  1086. #    define NATIVE     "native chars"
  1087. #  endif
  1088. #  define A_TO_N(str1) {register unsigned char *ps1;\
  1089.      for (ps1=str1; *ps1; ps1++) *ps1=ascii_to_native(*ps1);}
  1090. #endif
  1091.  
  1092. /*
  1093.  *  Translate the zero-terminated string in str1 from ASCII to the native
  1094.  *  character set. The translation is performed in-place and uses the
  1095.  *  ascii_to_native macro to translate each character.
  1096.  *
  1097.  *  macro A_TO_N( str1 )
  1098.  *  {
  1099.  *      register unsigned char *ps1;
  1100.  *
  1101.  *      for (ps1 = str1;  *ps1;  ++ps1)
  1102.  *          *ps1 = ascii_to_native(*ps1);
  1103.  *  }
  1104.  *
  1105.  *  NOTE:  Using the ascii_to_native macro means that is it the only part of
  1106.  *    unzip which knows which translation table (if any) is actually in use
  1107.  *    to produce the native character set.  This makes adding new character
  1108.  *    set translation tables easy, insofar as all that is needed is an
  1109.  *    appropriate ascii_to_native macro definition and the translation
  1110.  *    table itself.  Currently, the only non-ASCII native character set
  1111.  *    implemented is EBCDIC, but this may not always be so.
  1112.  */
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118. /*************/
  1119. /*  Globals  */
  1120. /*************/
  1121.  
  1122.    extern int       aflag;
  1123. /* extern int       bflag;   reserved */
  1124.    extern int       cflag;
  1125.    extern int       fflag;
  1126.    extern int       jflag;
  1127.    extern int       overwrite_none;
  1128.    extern int       overwrite_all;
  1129.    extern int       force_flag;
  1130.    extern int       quietflg;
  1131. #ifdef DOS_OS2
  1132.    extern int       sflag;
  1133. #endif
  1134.    extern int       tflag;
  1135.    extern int       uflag;
  1136.    extern int       V_flag;
  1137. #ifdef VMS
  1138.    extern int       secinf;
  1139. #endif
  1140. #ifdef MACOS
  1141.    extern int       hfsflag;
  1142. #endif
  1143.    extern int       process_all_files;
  1144.    extern longint   csize;
  1145.    extern longint   ucsize;
  1146.    extern char      *fnames[];
  1147.    extern char      **fnv;
  1148.    extern char      sig[];
  1149.    extern char      answerbuf[];
  1150.    extern min_info  *pInfo;
  1151.    extern char      *key;
  1152.    extern ULONG     keys[];
  1153.  
  1154. #ifdef MACOS
  1155.    union work {
  1156.      struct {
  1157.        short *Prefix_of;        /* (8193 * sizeof(short)) */
  1158.        byte *Suffix_of;
  1159.        byte *Stack;
  1160.      } shrink;
  1161.      byte *Slide;
  1162.    };
  1163. #else
  1164.    union work {
  1165.      struct {
  1166.        short Prefix_of[HSIZE + 2];      /* (8194 * sizeof(short)) */
  1167.        byte Suffix_of[HSIZE + 2];       /* also s-f length_nodes (smaller) */
  1168.        byte Stack[HSIZE + 2];           /* also s-f distance_nodes (smaller) */
  1169.      } shrink;
  1170.      byte Slide[WSIZE];
  1171.    };
  1172. #endif
  1173.    extern union work area;
  1174.  
  1175. #  define prefix_of area.shrink.Prefix_of
  1176. #  define suffix_of area.shrink.Suffix_of
  1177. #  define stack area.shrink.Stack
  1178. #  define slide area.Slide
  1179.  
  1180.    extern ULONG     crc32val;
  1181.    extern UWORD     mask_bits[];
  1182.  
  1183.    extern byte      *inbuf;
  1184.    extern byte      *inptr;
  1185.    extern int       incnt;
  1186.    extern ULONG     bitbuf;
  1187.    extern int       bits_left;
  1188.    extern boolean   zipeof;
  1189.    extern int       zipfd;
  1190. #ifdef MSWIN
  1191.    extern char      *zipfn;
  1192. #else
  1193.    extern char      zipfn[];
  1194. #endif
  1195.    extern longint   extra_bytes;
  1196.    extern longint   cur_zipfile_bufstart;
  1197.    extern byte      *extra_field;
  1198.    extern char      local_hdr_sig[];
  1199.    extern char      central_hdr_sig[];
  1200.    extern char      end_central_sig[];
  1201.    extern local_file_hdr  lrec;
  1202.    extern cdir_file_hdr   crec;
  1203.    extern ecdir_rec       ecrec;
  1204.    extern struct stat     statbuf;
  1205.  
  1206.    extern byte      *outbuf;
  1207.    extern byte      *outptr;
  1208. #ifdef MSWIN
  1209.    extern byte __far *outout;
  1210.    extern char     *filename;
  1211. #else
  1212.    extern byte      *outout;
  1213.    extern char      filename[];
  1214. #endif
  1215.    extern longint   outpos;
  1216.    extern int       outcnt;
  1217.    extern int       outfd;
  1218.    extern int       mem_mode;
  1219.    extern int       disk_full;
  1220.  
  1221.    extern char      *EndSigMsg;
  1222.    extern char      *CentSigMsg;
  1223.    extern char      *SeekMsg;
  1224.    extern char      *ReportMsg;
  1225.  
  1226. #ifdef DECLARE_ERRNO
  1227.    extern int       errno;
  1228. #endif
  1229.  
  1230. #ifdef EBCDIC
  1231.    extern byte      ebcdic[];
  1232. #endif
  1233.  
  1234. #ifdef MACOS
  1235.    extern short     gnVRefNum;
  1236.    extern long      glDirID;
  1237.    extern OSType    gostCreator;
  1238.    extern OSType    gostType;
  1239.    extern boolean   fMacZipped;
  1240.    extern boolean   macflag;
  1241.    extern short     giCursor;
  1242.    extern CursHandle rghCursor[];
  1243. #endif
  1244.