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