home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip511.zip / unzip.h < prev    next >
C/C++ Source or Header  |  1994-07-31  |  60KB  |  1,791 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 "forward declarations," in the case of non-ANSI compilers),
  9.   macros, and global-variable declarations.
  10.  
  11.   ---------------------------------------------------------------------------*/
  12.  
  13.  
  14.  
  15. #ifndef __unzip_h   /* prevent multiple inclusions */
  16. #define __unzip_h
  17.  
  18. /*****************************************/
  19. /*  Predefined, Machine-specific Macros  */
  20. /*****************************************/
  21.  
  22. #if defined(__GO32__) && defined(unix)   /* MS-DOS extender:  NOT Unix */
  23. #  undef unix
  24. #endif
  25. #if (defined(__convex__) && !defined(__convexc__))
  26. #  define __convexc__
  27. #endif
  28.  
  29. #if defined(unix) || defined(M_XENIX) || defined(COHERENT) || defined(__hpux)
  30. #  ifndef UNIX
  31. #    define UNIX
  32. #  endif
  33. #endif /* unix || M_XENIX || COHERENT || __hpux */
  34. #if defined(__convexc__) || defined(MINIX)
  35. #  ifndef UNIX
  36. #    define UNIX
  37. #  endif
  38. #endif /* __convexc__ || MINIX */
  39.  
  40. #ifdef __COMPILER_KCC__
  41. #  include <c-env.h>
  42. #  ifdef SYS_T20
  43. #    define TOPS20
  44. #  endif
  45. #endif /* __COMPILER_KCC__ */
  46.  
  47. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  48. #ifdef __POWERC
  49. #  define __TURBOC__
  50. #  define MSDOS
  51. #endif /* __POWERC */
  52. #if defined(__MSDOS__) && (!defined(MSDOS))   /* just to make sure */
  53. #  define MSDOS
  54. #endif
  55.  
  56. #if defined(linux) && (!defined(LINUX))
  57. #  define LINUX
  58. #endif
  59.  
  60. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C, or
  61.  * Silicon Graphics, or Convex?, or IBM C Set/2, or GNU gcc/emx, or Watcom C,
  62.  * or Macintosh, or Windows NT, or Sequent, or Atari.
  63.  */
  64. #if defined(__STDC__) || defined(MSDOS) || defined(sgi)
  65. #  ifndef PROTO
  66. #    define PROTO
  67. #  endif
  68. #  define MODERN
  69. #endif
  70. #if defined(__IBMC__) || defined(__EMX__) || defined(__WATCOMC__)
  71. #  ifndef PROTO
  72. #    define PROTO
  73. #  endif
  74. #  define MODERN
  75. #endif
  76. #if defined(THINK_C) || defined(MPW) || defined(WIN32) || defined(_SEQUENT_)
  77. #  ifndef PTX   /* Sequent running Dynix/ptx:  non-modern compiler */
  78. #    ifndef PROTO
  79. #      define PROTO
  80. #    endif
  81. #    define MODERN
  82. #  endif
  83. #endif
  84. #if defined(ATARI_ST) || defined(__BORLANDC__)  /* || defined(__convexc__) */
  85. #  ifndef PROTO
  86. #    define PROTO
  87. #  endif
  88. #  define MODERN
  89. #endif
  90.  
  91. /* turn off prototypes if requested */
  92. #if defined(NOPROTO) && defined(PROTO)
  93. #  undef PROTO
  94. #endif
  95.  
  96. /* used to remove arguments in function prototypes for non-ANSI C */
  97. #ifdef PROTO
  98. #  define OF(a) a
  99. #else
  100. #  define OF(a) ()
  101. #endif
  102.  
  103. /* bad or (occasionally?) missing stddef.h: */
  104. #if defined(M_XENIX) || defined(DNIX)
  105. #  define NO_STDDEF_H
  106. #endif
  107.  
  108. #if defined(apollo)          /* defines __STDC__ */
  109. #    define NO_STDLIB_H
  110. #endif /* apollo */
  111.  
  112. #ifdef DNIX
  113. #  define SYSV
  114. #  define SHORT_NAMES         /* 14-char limitation on path components */
  115. /* #  define FILENAME_MAX  14 */
  116. #  define FILENAME_MAX  NAME_MAX    /* GRR:  experiment */
  117. #endif
  118.  
  119. #if (defined(__SYSTEM_FIVE) || defined(M_SYSV) || defined(M_SYS5))
  120. #  ifndef SYSV
  121. #    define SYSV
  122. #  endif
  123. #endif /* __SYSTEM_FIVE || M_SYSV || M_SYS5 */
  124.  
  125. #if (defined(ultrix) || defined(bsd4_2) || defined(sun) || defined(pyr))
  126. #  if (!defined(BSD) && !defined(SYSV))
  127. #    define BSD
  128. #  endif
  129. #endif /* ultrix || bsd4_2 || sun || pyr */
  130. #if defined(__convexc__)
  131. #  if (!defined(BSD) && !defined(SYSV))
  132. #    define BSD
  133. #  endif
  134. #endif /* __convexc__ */
  135.  
  136. #ifdef pyr  /* Pyramid */
  137. #  ifdef BSD
  138. #    define pyr_bsd
  139. #    define USE_STRINGS_H    /* instead of more common string.h */
  140. #  endif
  141. #  define ZMEM            /* should ZMEM only be for BSD universe...? */
  142. #  define DECLARE_ERRNO   /*  (AT&T memcpy was claimed to be very slow) */
  143. #endif /* pyr */
  144.  
  145. #if (defined(CRAY) && defined(ZMEM))
  146. #  undef ZMEM
  147. #endif
  148.  
  149. /* stat() bug for Borland, Watcom, VAX C (also GNU?), and Atari ST MiNT on
  150.  * TOS filesystems:  returns 0 for wildcards!  (returns 0xffffffff on Minix
  151.  * filesystem or U: drive under Atari MiNT) */
  152. #if (defined(__TURBOC__) || defined(__WATCOMC__) || defined(VMS))
  153. #  define WILD_STAT_BUG
  154. #endif
  155. #if (defined(__MINT__))
  156. #  define WILD_STAT_BUG
  157. #endif
  158.  
  159. #ifdef WILD_STAT_BUG
  160. #  define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
  161. #else
  162. #  define SSTAT stat
  163. #endif
  164.  
  165. #define STRNICMP zstrnicmp
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172. /***************************/
  173. /*  OS-Dependent Includes  */
  174. /***************************/
  175.  
  176. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  177. #  include <stdio.h>
  178. #endif
  179. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  180. #include <errno.h>       /* used in mapname() */
  181. #ifdef USE_STRINGS_H
  182. #  include <strings.h>   /* strcpy, strcmp, memcpy, index/rindex, etc. */
  183. #else
  184. #  include <string.h>    /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
  185. #endif
  186. #ifdef MODERN
  187. #  include <limits.h>    /* GRR:  EXPERIMENTAL!  (can be deleted) */
  188. #endif
  189.  
  190. #ifdef EFT
  191. #  define LONGINT off_t  /* Amdahl UTS nonsense ("extended file types") */
  192. #else
  193. #  define LONGINT long
  194. #endif
  195.  
  196. #ifdef MODERN
  197. #  ifndef NO_STDDEF_H
  198. #    include <stddef.h>
  199. #  endif
  200. #  ifndef NO_STDLIB_H
  201. #    include <stdlib.h>    /* standard library prototypes, malloc(), etc. */
  202. #  endif
  203.    typedef size_t extent;
  204.    typedef void voidp;
  205. #else /* !MODERN */
  206.    LONGINT lseek();
  207. #  ifdef VAXC              /* not fully modern, but does have stdlib.h */
  208. #    include <stdlib.h>
  209. #  else
  210.      char *malloc();
  211. #  endif
  212.    typedef unsigned int extent;
  213.    typedef char voidp;
  214. #  define void int
  215. #endif /* ?MODERN */
  216.  
  217. /* this include must be down here for SysV.4, for some reason... */
  218. #include <signal.h>      /* used in unzip.c, file_io.c */
  219.  
  220. /*---------------------------------------------------------------------------
  221.     Amiga section:
  222.   ---------------------------------------------------------------------------*/
  223.  
  224. #ifdef AMIGA
  225. #  include "amiga/amiga.h"
  226. #  ifndef AZTEC_C
  227. #    include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  228. #    include <sys/stat.h>
  229. #  endif
  230. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  231. #  define DATE_FORMAT   DF_MDY
  232. #  define lenEOL        1
  233. #  define PutNativeEOL  *q++ = native(LF);
  234. /* #  define USE_FWRITE   if write() returns 16-bit int */
  235. #  define PIPE_ERROR (errno == 9999)    /* always false */
  236. #endif
  237.  
  238. /*---------------------------------------------------------------------------
  239.     Atari ST section:
  240.   ---------------------------------------------------------------------------*/
  241.  
  242. #if (defined(ATARI_ST) || defined(__MINT__))    /* comments by [cjh] */
  243. #  ifdef __TURBOC__
  244. #    include <ext.h>   /* stat() */
  245. #    include <tos.h>   /* OS-specific functions (Fdup) */
  246. #  endif
  247. #  include <time.h>
  248. #  ifndef __MINT__
  249. #    define dup     Fdup
  250. #    define mkdir   Dcreate
  251. #    define DIR_END '\\'
  252. #  else
  253. #    include <sys/types.h>     /* didn't we include this already? */
  254. #    include <sys/stat.h>
  255. #    include <fcntl.h>         /* O_BINARY */
  256. #    include <unistd.h>        /* dup proto & unix system calls live here */
  257. #    include <time.h>
  258. #    include <stdio.h>         /* didn't we include this already? */
  259. #    define dup dup
  260. #    define mkdir mkdir
  261. #    define DIR_END '/'        /* much sexier than DOS filenames... */
  262. #    define timezone _timezone /* oops */
  263. #    define DIRENT
  264. #    define SYMLINKS
  265. #    ifdef S_ISLNK             /* WARNING:  horrible kludge!!!! */
  266. #      undef S_ISLNK           /* MiNTlibs & POSIX don't define S_ISLNK */
  267. #      define S_ISLNK(a) (((a) & 0xa000) == 0xa000)
  268. #    endif
  269. #    ifdef SHORT_NAMES         /* library will truncate weird names on TOS fs */
  270. #      undef SHORT_NAMES
  271. #    endif
  272. #    ifndef ZMEM
  273. #      define ZMEM             /* we have bcopy, etc., ifndef __STRICT_ANSI__ */
  274. #    endif
  275. #  endif /* __MINT__ */
  276. #  ifndef S_IFMT
  277. #    define S_IFMT     (S_IFCHR | S_IFREG | S_IFDIR)
  278. #  endif
  279. #  define DATE_FORMAT  DF_MDY
  280. #  ifndef lenEOL
  281. #    define lenEOL 2           /* DOS convention; MiNT doesn't really care */
  282. #  endif
  283. #  ifndef PutNativeEOL
  284. #    define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  285. #  endif
  286. #  define EXE_EXTENSION  ".tos"  /* or .ttp instead?? */
  287. #endif
  288.  
  289. /*---------------------------------------------------------------------------
  290.     Human68k/X68000 section:
  291.   ---------------------------------------------------------------------------*/
  292.  
  293. #ifdef __human68k__    /* DO NOT DEFINE DOS_OS2 HERE!  If Human68k is so much */
  294. #  include <time.h>    /*  like MS-DOS and/or OS/2, create DOS_HUM_OS2 macro. */
  295. #  include <fcntl.h>
  296. #  include <io.h>
  297. #  include <conio.h>
  298. #  include <jctype.h>
  299. #  include <sys/stat.h>
  300. #  define DATE_FORMAT  DF_YMD    /* Japanese standard */
  301.       /* GRR:  these EOL macros are guesses */
  302. #  define lenEOL        2
  303. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  304. #  define EXE_EXTENSION ".exe"   /* just a guess... */
  305. #endif
  306.  
  307. /*---------------------------------------------------------------------------
  308.     Mac section:
  309.   ---------------------------------------------------------------------------*/
  310.  
  311. #ifdef THINK_C
  312. #  define MACOS
  313. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  314. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  315. #  else
  316. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  317. #      undef __STDC__         /*   it needs to be 1 or required header */
  318. #      define __STDC__ 1      /*   files are not properly included. */
  319. #    endif /* !__STDC__ */
  320. #  endif
  321. #  define CREATOR  'KAHL'
  322. #  define MAIN     unzip
  323. #endif /* THINK_C */
  324.  
  325. #ifdef MPW
  326. #  define MACOS
  327. #  include <Errors.h>
  328. #  include <Files.h>
  329. #  include <Memory.h>
  330. #  include <Quickdraw.h>
  331. #  include <ToolUtils.h>
  332. #  ifdef fileno
  333. #    undef fileno
  334. #  endif
  335. #  ifdef MCH_MACINTOSH
  336. #    define CREATOR     'Manx'
  337. #  else
  338. #    define CREATOR     'MPS '
  339. #  endif
  340. #endif /* MPW */
  341.  
  342. #ifdef MACOS
  343. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  344. #  define fileno(x)     ((x) == stdout ? 1 : (short)(x))
  345. #  define open(x,y)     macopen((x), (y), gnVRefNum, glDirID)
  346. #  define fopen(x,y)    macfopen((x), (y), gnVRefNum, glDirID)
  347. #  define close         macclose
  348. #  define fclose(x)     macclose(fileno((x)))
  349. #  define read          macread
  350. #  define write         macwrite
  351. #  define lseek         maclseek
  352. #  define creat(x,y)    maccreat((x), gnVRefNum, glDirID, gostCreator, gostType)
  353. #  define stat(x,y)     macstat((x), (y), gnVRefNum, glDirID)
  354. #  define dup
  355. #  ifndef MCH_MACINTOSH
  356. #    define NO_STRNICMP
  357. #  endif
  358. #  define DIR_END ':'
  359. #  define DATE_FORMAT   DF_MDY
  360. #  define lenEOL        1
  361. #  define PutNativeEOL  *q++ = native(CR);
  362. #  define MALLOC_WORK
  363.  
  364. #  ifdef THINK_C
  365. #    define fgets       wfgets
  366. #    define fflush(f)
  367. #    define fprintf     wfprintf
  368. #    define fputs(s,f)  wfprintf((f), "%s", (s))
  369. #    define printf      wprintf
  370. #    ifdef putc
  371. #      undef putc
  372. #    endif
  373. #    define putc(c,f)   wfprintf((f), "%c", (c))
  374. #    define getenv      macgetenv
  375. #  endif
  376.  
  377. #  ifndef isascii
  378. #    define isascii(c)  ((unsigned char)(c) <= 0x3F)
  379. #  endif
  380.  
  381. #  include "macstat.h"
  382. #  include "macdir.h"
  383.  
  384. #  ifdef CR
  385. #    undef  CR
  386. #  endif
  387.  
  388. typedef struct _ZipExtraHdr {
  389.     unsigned short header;    /*    2 bytes */
  390.     unsigned short data;      /*    2 bytes */
  391. } ZIP_EXTRA_HEADER;
  392.  
  393. typedef struct _MacInfoMin {
  394.     unsigned short header;    /*    2 bytes */
  395.     unsigned short data;      /*    2 bytes */
  396.     unsigned long signature;  /*    4 bytes */
  397.     FInfo finfo;              /*   16 bytes */
  398.     unsigned long lCrDat;     /*    4 bytes */
  399.     unsigned long lMdDat;     /*    4 bytes */
  400.     unsigned long flags ;     /*    4 bytes */
  401.     unsigned long lDirID;     /*    4 bytes */
  402.                               /*------------*/
  403. } MACINFOMIN;                 /* = 40 bytes for size of data */
  404.  
  405. typedef struct _MacInfo {
  406.     unsigned short header;    /*    2 bytes */
  407.     unsigned short data;      /*    2 bytes */
  408.     unsigned long signature;  /*    4 bytes */
  409.     FInfo finfo;              /*   16 bytes */
  410.     unsigned long lCrDat;     /*    4 bytes */
  411.     unsigned long lMdDat;     /*    4 bytes */
  412.     unsigned long flags ;     /*    4 bytes */
  413.     unsigned long lDirID;     /*    4 bytes */
  414.     char rguchVolName[28];    /*   28 bytes */
  415.                               /*------------*/
  416. } MACINFO;                    /* = 68 bytes for size of data */
  417. #endif /* MACOS */
  418.  
  419. /*---------------------------------------------------------------------------
  420.     MS-DOS and OS/2 section:
  421.   ---------------------------------------------------------------------------*/
  422.  
  423. #ifdef MSDOS
  424. #  include <dos.h>           /* for REGS macro (TC) or _dos_setftime (MSC) */
  425. #  ifdef __TURBOC__          /* includes Power C */
  426. #    include <sys/timeb.h>   /* for structure ftime */
  427. #    ifndef __BORLANDC__     /* there appears to be a bug (?) in Borland's */
  428. #      include <mem.h>       /*  MEM.H related to __STDC__ and far poin-   */
  429. #    endif                   /*  ters. (dpk)  [mem.h included for memcpy]  */
  430. #  endif
  431. #endif /* MSDOS */
  432.  
  433. #ifdef __IBMC__
  434. #  define S_IFMT 0xF000
  435. #  define timezone _timezone
  436. #  define PIPE_ERROR (errno == EERRSET || errno == EOS2ERR)
  437. #endif
  438.  
  439. #ifdef __WATCOMC__
  440. #  define __32BIT__
  441. #  undef far
  442. #  define far
  443. #  undef near
  444. #  define near
  445. #  define PIPE_ERROR (errno == -1)
  446. #endif
  447.  
  448. #ifdef __EMX__
  449. #  ifndef __32BIT__
  450. #    define __32BIT__
  451. #  endif
  452. #  define far
  453. #endif
  454.  
  455. #ifdef __GO32__              /* note: MS-DOS compiler, not OS/2 */
  456. #  ifndef __32BIT__
  457. #    define __32BIT__
  458. #  endif
  459. #  include <sys/timeb.h>     /* for structure ftime */
  460.    int setmode(int, int);    /* not in djgpp's include files */
  461. #endif
  462.  
  463. #if defined(_MSC_VER) && (!defined(MSC))
  464. #  define MSC                /* for old versions, MSC must be set explicitly */
  465. #endif
  466.  
  467. #if 0  /* GRR 930907:  MSC 5.1 does declare errno but doesn't define _MSC_VER */
  468. #ifdef MSC
  469. #  ifndef _MSC_VER           /* new with 5.1 or 6.0 ... */
  470. #    define DECLARE_ERRNO    /* not declared in errno.h in 5.0 or earlier? */
  471. #  endif
  472. #endif
  473. #endif /* 0 */
  474.  
  475. #if defined(MSDOS) || defined(OS2)
  476. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  477. #  include <sys/stat.h>
  478. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  479. #  include <time.h>           /* localtime() */
  480. #  include <fcntl.h>          /* O_BINARY for open() w/o CR/LF translation */
  481. #  define DIR_END '\\'
  482. #  if (defined(M_I86CM) || defined(M_I86LM))
  483. #    define MED_MEM
  484. #  endif
  485. #  if (defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__))
  486. #    define MED_MEM
  487. #  endif
  488. #  ifndef __32BIT__
  489. #    ifndef MED_MEM
  490. #      define SMALL_MEM
  491. #    endif
  492. /* #    define USE_FWRITE   write() *can* write up to 65534 bytes after all */
  493. #  endif
  494. #  define DATE_FORMAT   dateformat()
  495. #  define lenEOL        2
  496. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  497. #endif
  498.  
  499. #ifdef OS2                    /* defined for all OS/2 compilers */
  500. #  ifdef MSDOS
  501. #    undef MSDOS
  502. #  endif
  503. #  ifdef isupper
  504. #    undef isupper
  505. #  endif
  506. #  ifdef tolower
  507. #    undef tolower
  508. #  endif
  509. #  define isupper(x)   IsUpperNLS((unsigned char)(x))
  510. #  define tolower(x)   ToLowerNLS((unsigned char)(x))
  511. #endif
  512.  
  513. #ifdef MSDOS
  514. #  define EXE_EXTENSION ".exe"  /* OS/2 has GetLoadPath() function instead */
  515. #endif
  516.  
  517. #if defined(MSWIN) && defined(FILE_IO_C)
  518. #  include "wizunzip.h"
  519. #endif
  520.  
  521. /*---------------------------------------------------------------------------
  522.     MTS section (piggybacks UNIX, I think):
  523.   ---------------------------------------------------------------------------*/
  524.  
  525. #ifdef MTS
  526. #  include <sys/types.h>    /* off_t, time_t, dev_t, ... */
  527. #  include <sys/stat.h>
  528. #  include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  529. #  include <timeb.h>
  530. #  include <time.h>
  531. #  include <unix.h>         /* some important non-ANSI routines */
  532. #  define mkdir(s,n) (-1)   /* no "make directory" capability */
  533. #  define EBCDIC            /* set EBCDIC conversion on */
  534. #  define NO_STRNICMP       /* unzip's is as good the one in MTS */
  535. #  define USE_FWRITE
  536. #  define close_outfile()  fclose(outfile)   /* can't set time on files */
  537. #  define umask(n)            /* Don't have umask() on MTS */
  538. #  define FOPWT         "w"   /* Open file for writing in TEXT mode */
  539. #  define DATE_FORMAT   DF_MDY
  540. #  define lenEOL        1
  541. #  define PutNativeEOL  *q++ = native(LF);
  542. #endif
  543.  
  544. /*---------------------------------------------------------------------------
  545.     NT section:
  546.   ---------------------------------------------------------------------------*/
  547.  
  548. #ifdef WIN32  /* NT */
  549. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  550. #  include <sys/stat.h>
  551. #  include <io.h>               /* read(), open(), etc. */
  552. #  include <time.h>
  553. #  include <memory.h>
  554. #  include <direct.h>           /* mkdir() */
  555. #  include <fcntl.h>
  556. #  if defined(FILE_IO_C)
  557. #    include <conio.h>
  558. #    include <sys\types.h>
  559. #    include <sys\utime.h>
  560. #    include <windows.h>
  561. #  endif
  562. #  define DATE_FORMAT   DF_MDY
  563. #  define lenEOL        2
  564. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  565. #  define NT
  566. #  if (defined(_MSC_VER) && !defined(MSC))
  567. #    define MSC
  568. #  endif
  569. #endif
  570.  
  571. /*---------------------------------------------------------------------------
  572.     TOPS-20 section:
  573.   ---------------------------------------------------------------------------*/
  574.  
  575. #ifdef TOPS20
  576. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  577. #  include <sys/stat.h>
  578. #  include <sys/param.h>
  579. #  include <sys/time.h>
  580. #  include <sys/timeb.h>
  581. /* #  include <utime.h>            GRR: not used, I suspect... */
  582. #  include <sys/file.h>
  583. #  include <timex.h>
  584. #  include <monsym.h>           /* get amazing monsym() macro */
  585.    extern int open(), close(), read();
  586.    extern int stat(), unlink(), jsys(), fcntl();
  587.    extern long lseek(), dup(), creat();
  588. #  define strchr    index       /* GRR: necessary? */
  589. #  define strrchr   rindex
  590. #  define REALLY_SHORT_SYMS
  591. #  define NO_MKDIR
  592. #  define DIR_BEG  '<'
  593. #  define DIR_END  '>'
  594. #  define DIR_EXT  ".directory"
  595. #  define DATE_FORMAT  DF_MDY
  596. #  define EXE_EXTENSION ".exe"  /* just a guess... */
  597. #endif /* TOPS20 */
  598.  
  599. /*---------------------------------------------------------------------------
  600.     Unix section:
  601.   ---------------------------------------------------------------------------*/
  602.  
  603. #ifdef UNIX
  604. #  include <sys/types.h>       /* off_t, time_t, dev_t, ... */
  605. #  include <sys/stat.h>
  606.  
  607. #  ifndef COHERENT
  608. #    include <fcntl.h>         /* O_BINARY for open() w/o CR/LF translation */
  609. #  else /* COHERENT */
  610. #    ifdef _I386
  611. #      include <fcntl.h>       /* Coherent 4.0.x, Mark Williams C */
  612. #    else
  613. #      include <sys/fcntl.h>   /* Coherent 3.10, Mark Williams C */
  614. #    endif
  615. #    define SHORT_SYMS
  616. #    ifndef __COHERENT__       /* Coherent 4.2 has tzset() */
  617. #      define tzset  settz
  618. #    endif
  619. #  endif /* ?COHERENT */
  620.  
  621. #  ifndef NO_PARAM_H
  622. #    ifdef NGROUPS_MAX
  623. #      undef NGROUPS_MAX       /* SCO bug:  defined again in <sys/param.h> */
  624. #    endif
  625. #    ifdef BSD
  626. #      define TEMP_BSD         /* may be defined again in <sys/param.h> */
  627. #      undef BSD
  628. #    endif
  629. #    include <sys/param.h>     /* conflict with <sys/types.h>, some systems? */
  630. #    ifdef TEMP_BSD
  631. #      undef TEMP_BSD
  632. #      ifndef BSD
  633. #        define BSD
  634. #      endif
  635. #    endif
  636. #  endif /* !NO_PARAM_H */
  637.  
  638. #  ifdef __osf__
  639. #    define DIRENT
  640. #    ifdef BSD
  641. #      undef BSD
  642. #    endif
  643. #  endif /* __osf__ */
  644.  
  645. #  ifdef BSD
  646. #    include <sys/time.h>
  647. #    include <sys/timeb.h>
  648. #    ifdef _AIX
  649. #      include <time.h>
  650. #    endif
  651. #  else
  652. #    include <time.h>
  653.      struct tm *gmtime(), *localtime();
  654. #  endif
  655.  
  656. #  if defined(BSD4_4) || defined(LINUX) || (defined(SYSV) && defined(MODERN))
  657. #    include <unistd.h>        /* this includes utime.h, at least on SGIs */
  658. #  endif
  659.  
  660. #  if defined(BSD4_4) || defined(_POSIX_SOURCE) || defined(sgi) || defined(_AIX)
  661. #    include <utime.h>   /* NeXT, at least, does NOT define utimbuf in here */
  662. #  else
  663.      struct utimbuf {
  664.          time_t actime;        /* new access time */
  665.          time_t modtime;       /* new modification time */
  666.      };
  667. #  endif /* ?(BSD4_4 || _POSIX_SOURCE || sgi || _AIX) */
  668.  
  669. #  if (defined(V7) || defined(pyr_bsd))
  670. #    define strchr   index
  671. #    define strrchr  rindex
  672. #  endif
  673. #  ifdef V7
  674. #    define O_RDONLY 0
  675. #    define O_WRONLY 1
  676. #    define O_RDWR   2
  677. #  endif
  678.  
  679. #  ifdef MINIX
  680. #    include <stdio.h>
  681. #  endif
  682. #  define DATE_FORMAT   DF_MDY
  683. #  define lenEOL        1
  684. #  define PutNativeEOL  *q++ = native(LF);
  685. #endif /* UNIX */
  686.  
  687. /*---------------------------------------------------------------------------
  688.     VMS section:
  689.   ---------------------------------------------------------------------------*/
  690.  
  691. #ifdef VMS
  692. #  include <types.h>              /* GRR:  experimenting... */
  693. #  include <stat.h>
  694. #  include <time.h>               /* the usual non-BSD time functions */
  695. #  include <file.h>               /* same things as fcntl.h has */
  696. #  include <unixio.h>
  697. #  include <rms.h>
  698. #  define _MAX_PATH NAM$C_MAXRSS  /* to define FILNAMSIZ below */
  699. #  define RETURN    return_VMS    /* VMS interprets return codes incorrectly */
  700. #  define DIR_BEG  '['
  701. #  define DIR_END  ']'
  702. #  define DIR_EXT  ".dir"
  703. #  define DATE_FORMAT  DF_MDY
  704. #  define lenEOL        1
  705. #  define PutNativeEOL  *q++ = native(LF);
  706. #endif /* VMS */
  707.  
  708.  
  709.  
  710.  
  711.  
  712. /*************/
  713. /*  Defines  */
  714. /*************/
  715.  
  716. #define UNZIP
  717. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  718. #define VMS_UNZIP_VERSION 42   /* if OS-needed-to-extract is VMS:  can do */
  719.  
  720. #if defined(MSDOS) || defined(NT) || defined(OS2)
  721. #  define DOS_NT_OS2
  722. #endif
  723.  
  724. #if defined(MSDOS) || defined(OS2)
  725. #  define DOS_OS2
  726. #endif
  727.  
  728. #if defined(MSDOS) || defined(OS2) || defined(ATARI_ST)
  729. #  define DOS_OS2_TOS
  730. #endif
  731.  
  732. #if defined(MSDOS) || defined(ATARI_ST)
  733. #  define DOS_TOS
  734. #endif
  735.  
  736. #if defined(MSDOS) || defined(TOPS20) || defined(VMS)
  737. #  define DOS_T20_VMS
  738. #endif
  739.  
  740. #if defined(TOPS20) || defined(VMS)
  741. #  define T20_VMS
  742. #endif
  743.  
  744. /* clean up with a few defaults */
  745. #ifndef DIR_END
  746. #  define DIR_END '/'       /* last char before program name (or filename) */
  747. #endif
  748. #ifndef RETURN
  749. #  define RETURN  return    /* only used in main() */
  750. #endif
  751. #ifndef PRINTF
  752. #  define PRINTF  printf
  753. #endif
  754. #ifndef FPRINTF
  755. #  define FPRINTF fprintf
  756. #endif
  757.  
  758. #define DIR_BLKSIZ  64      /* number of directory entries per block
  759.                              *  (should fit in 4096 bytes, usually) */
  760. #ifndef WSIZE
  761. #  define WSIZE     0x8000  /* window size--must be a power of two, and */
  762. #endif                      /*  at least 32K for zip's deflate method */
  763.  
  764. #ifndef INBUFSIZ
  765. #  if (defined(MEDIUM_MEM) || defined(SMALL_MEM))
  766. #    define INBUFSIZ  2048  /* works for MS-DOS small model */
  767. #  else
  768. #    define INBUFSIZ  8192  /* larger buffers for real OSes */
  769. #  endif
  770. #endif
  771.  
  772. /* GRR:  NT defines MSDOS?? */
  773. #if (!defined(MSDOS) && !defined(__IBMC__)) || defined(NT)
  774. #  define near
  775. #  define far
  776. #endif
  777. #if defined(__GO32__) || defined(__EMX__)
  778. #  define near
  779. #  define far
  780. #endif
  781.  
  782. /* Logic for case of small memory, length of EOL > 1:  if OUTBUFSIZ == 2048,
  783.  * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
  784.  * and transbuf 1040 bytes.  Have room for 32 extra EOL chars; 1008/32 == 31.5
  785.  * chars/line, smaller than estimated 35-70 characters per line for C source
  786.  * and normal text.  Hence difference is sufficient for most "average" files.
  787.  * (Argument scales for larger OUTBUFSIZ.)
  788.  */
  789. #ifdef SMALL_MEM          /* i.e., 16-bit OS's:  MS-DOS, OS/2 1.x, etc. */
  790. #  ifndef Far
  791. #    define Far far  /* __far only works for MSC 6.00, not 6.0a or Borland */
  792. #  endif
  793. #  define OUTBUFSIZ INBUFSIZ
  794. #  if (lenEOL == 1)
  795. #    define RAWBUFSIZ (OUTBUFSIZ>>1)
  796. #  else
  797. #    define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
  798. #  endif
  799. #  define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
  800. #else
  801. #  define LoadFarString(x)       x
  802. #  define LoadFarStringSmall(x)  x
  803. #  define LoadFarStringSmall2(x) x
  804. #  ifdef MED_MEM
  805. #    define OUTBUFSIZ 0xFF80     /* can't malloc arrays of 0xFFE8 or more */
  806. #    define TRANSBUFSIZ 0xFF80
  807. #  else
  808. #    define OUTBUFSIZ (lenEOL*WSIZE)  /* more efficient text conversion */
  809. #    define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
  810. #    define NEW_UNSHRINK
  811. #  endif
  812. #  define RAWBUFSIZ OUTBUFSIZ
  813. #endif /* ?SMALL_MEM */
  814.  
  815. #ifndef Far
  816. #  define Far   /* GRR:  should combine this with near/far above */
  817. #endif
  818.  
  819. #ifndef MAIN
  820. #  define MAIN  main
  821. #endif
  822.  
  823. #if (defined(SFX) && !defined(NO_ZIPINFO))
  824. #  define NO_ZIPINFO
  825. #endif
  826.  
  827. #ifndef O_BINARY
  828. #  define O_BINARY  0
  829. #endif
  830.  
  831. #ifndef PIPE_ERROR
  832. #  define PIPE_ERROR (errno == EPIPE)
  833. #endif
  834.  
  835. /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
  836. #ifdef VMS
  837. #  define FOPR  "r","ctx=stm"
  838. #  define FOPM  "r+","ctx=stm","rfm=fix","mrs=512"
  839. #  define FOPW  "w","ctx=stm","rfm=fix","mrs=512"
  840. #else /* !VMS */
  841. #  if defined(MODERN) || defined(AMIGA)
  842. #    define FOPR "rb"
  843. #    define FOPM "r+b"
  844. #    ifdef TOPS20          /* TOPS-20 MODERN?  You kidding? */
  845. #      define FOPW "w8"
  846. #    else
  847. #      define FOPW "wb"
  848. #    endif
  849. #  else /* !MODERN */
  850. #    define FOPR "r"
  851. #    define FOPM "r+"
  852. #    define FOPW "w"
  853. #  endif /* ?MODERN */
  854. #endif /* VMS */
  855.  
  856. /*
  857.  * If <limits.h> exists on most systems, should include that, since it may
  858.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  859.  * _POSIX_PATH_MAX.
  860.  */
  861. #ifdef DOS_OS2_TOS
  862. #  include <limits.h>
  863. #endif
  864.  
  865. #ifndef PATH_MAX
  866. #  ifdef MAXPATHLEN
  867. #    define PATH_MAX      MAXPATHLEN    /* in <sys/param.h> on some systems */
  868. #  else
  869. #    ifdef _MAX_PATH
  870. #      define PATH_MAX    _MAX_PATH
  871. #    else
  872. #      if FILENAME_MAX > 255
  873. #        define PATH_MAX  FILENAME_MAX  /* used like PATH_MAX on some systems */
  874. #      else
  875. #        define PATH_MAX  1024
  876. #      endif
  877. #    endif /* ?_MAX_PATH */
  878. #  endif /* ?MAXPATHLEN */
  879. #endif /* !PATH_MAX */
  880.  
  881. #define FILNAMSIZ  (PATH_MAX+1)
  882.  
  883. #ifdef SHORT_SYMS                   /* Mark Williams C, ...? */
  884. #  define extract_or_test_files     xtr_or_tst_files
  885. #  define extract_or_test_member    xtr_or_tst_member
  886. #endif
  887.  
  888. #ifdef REALLY_SHORT_SYMS            /* TOPS-20 linker:  first 6 chars */
  889. #  define process_cdir_file_hdr     XXpcdfh
  890. #  define process_local_file_hdr    XXplfh
  891. #  define extract_or_test_files     XXxotf  /* necessary? */
  892. #  define extract_or_test_member    XXxotm  /* necessary? */
  893. #  define check_for_newer           XXcfn
  894. #  define overwrite_all             XXoa
  895. #  define process_all_files         XXpaf
  896. #  define extra_field               XXef
  897. #  define explode_lit8              XXel8
  898. #  define explode_lit4              XXel4
  899. #  define explode_nolit8            XXnl8
  900. #  define explode_nolit4            XXnl4
  901. #  define cpdist8                   XXcpdist8
  902. #  define inflate_codes             XXic
  903. #  define inflate_stored            XXis
  904. #  define inflate_fixed             XXif
  905. #  define inflate_dynamic           XXid
  906. #  define inflate_block             XXib
  907. #  define maxcodemax                XXmax
  908. #endif
  909.  
  910. #define ZSUFX             ".zip"
  911. #define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  912. #define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
  913. #define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for */
  914. #define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
  915.  
  916. #define SKIP              0    /* choice of activities for do_string() */
  917. #define DISPLAY           1
  918. #define FILENAME          2
  919. #define EXTRA_FIELD       3
  920.  
  921. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  922. #define EXISTS_AND_OLDER  0
  923. #define EXISTS_AND_NEWER  1
  924.  
  925. #define ROOT              0    /* checkdir() extract-to path:  called once */
  926. #define INIT              1    /* allocate buildpath:  called once per member */
  927. #define APPEND_DIR        2    /* append a dir comp.:  many times per member */
  928. #define APPEND_NAME       3    /* append actual filename:  once per member */
  929. #define GETPATH           4    /* retrieve the complete path and free it */
  930. #define END               5    /* free root path prior to exiting program */
  931.  
  932. /* version_made_by codes (central dir):  make sure these */
  933. /*  are not defined on their respective systems!! */
  934. #define FS_FAT_           0    /* filesystem used by MS-DOS, OS/2, NT */
  935. #define AMIGA_            1
  936. #define VMS_              2
  937. #define UNIX_             3
  938. #define VM_CMS_           4
  939. #define ATARI_            5    /* what if it's a minix filesystem? [cjh] */
  940. #define FS_HPFS_          6    /* filesystem used by OS/2, NT */
  941. #define MAC_              7
  942. #define Z_SYSTEM_         8
  943. #define CPM_              9
  944. #define TOPS20_           10
  945. #define FS_NTFS_          11   /* filesystem used by Windows NT */
  946. #define QDOS_MAYBE_       12   /* a bit premature, but somebody once started */
  947. #define ACORN_            13   /* Archimedes Acorn RISCOS */
  948. #define NUM_HOSTS         14   /* index of last system + 1 */
  949.  
  950. #define STORED            0    /* compression methods */
  951. #define SHRUNK            1
  952. #define REDUCED1          2
  953. #define REDUCED2          3
  954. #define REDUCED3          4
  955. #define REDUCED4          5
  956. #define IMPLODED          6
  957. #define TOKENIZED         7
  958. #define DEFLATED          8
  959. #define NUM_METHODS       9    /* index of last method + 1 */
  960. /* don't forget to update list_files() appropriately if NUM_METHODS changes */
  961.  
  962. #define PK_OK             0    /* no error */
  963. #define PK_COOL           0    /* no error */
  964. #define PK_GNARLY         0    /* no error */
  965. #define PK_WARN           1    /* warning error */
  966. #define PK_ERR            2    /* error in zipfile */
  967. #define PK_BADERR         3    /* severe error in zipfile */
  968. #define PK_MEM            4    /* insufficient memory */
  969. #define PK_MEM2           5    /* insufficient memory */
  970. #define PK_MEM3           6    /* insufficient memory */
  971. #define PK_MEM4           7    /* insufficient memory */
  972. #define PK_MEM5           8    /* insufficient memory */
  973. #define PK_NOZIP          9    /* zipfile not found */
  974. #define PK_PARAM          10   /* bad or illegal parameters specified */
  975. #define PK_FIND           11   /* no files found */
  976. #define PK_DISK           50   /* disk full */
  977. #define PK_EOF            51   /* unexpected EOF */
  978.  
  979. #define IZ_DIR            76   /* potential zipfile is a directory */
  980. #define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  981. #define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  982.  
  983. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  984. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  985. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  986.  
  987. /*---------------------------------------------------------------------------
  988.     True sizes of the various headers, as defined by PKWARE--so it is not
  989.     likely that these will ever change.  But if they do, make sure both these
  990.     defines AND the typedefs below get updated accordingly.
  991.   ---------------------------------------------------------------------------*/
  992. #define LREC_SIZE     26    /* lengths of local file headers, central */
  993. #define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  994. #define ECREC_SIZE    18    /*  central-dir record, respectively      */
  995.  
  996. #define MAX_BITS      13                 /* used in old unshrink() */
  997. #define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  998.  
  999. #define LF      10    /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  1000. #define CR      13    /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  1001. #define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
  1002.  
  1003. #ifdef EBCDIC
  1004. #  define native(c)   ebcdic[(c)]
  1005. #  define NATIVE      "EBCDIC"
  1006. #endif
  1007.  
  1008. #ifdef MPW
  1009. #  define FFLUSH(f)   putc('\n',f)
  1010. #else
  1011. #  define FFLUSH      fflush
  1012. #endif
  1013.  
  1014. #ifdef ZMEM     /* GRR:  THIS IS AN EXPERIMENT... (seems to work) */
  1015. #  undef ZMEM
  1016. #  define memcpy(dest,src,len)   bcopy(src,dest,len)
  1017. #  define memzero                bzero
  1018. #else
  1019. #  define memzero(dest,len)      memset(dest,0,len)
  1020. #endif
  1021.  
  1022. #ifdef VMS
  1023. #  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
  1024. #  define ENV_ZIPINFO   "ZIPINFO_OPTS"
  1025. #else /* !VMS */
  1026. #  define ENV_UNZIP     "UNZIP"
  1027. #  define ENV_ZIPINFO   "ZIPINFO"
  1028. #endif /* ?VMS */
  1029. #define ENV_UNZIP2      "UNZIPOPT"        /* alternate name for zip compat. */
  1030. #define ENV_ZIPINFO2    "ZIPINFOOPT"
  1031.  
  1032. #if !defined(QQ) && !defined(NOQQ)
  1033. #  define QQ
  1034. #endif
  1035.  
  1036. #ifdef QQ                         /* Newtware version:  no file */
  1037. #  define QCOND     (!qflag)      /*  comments with -vq or -vqq */
  1038. #else                             /* Bill Davidsen version:  no way to */
  1039. #  define QCOND     (which_hdr)   /*  kill file comments when listing */
  1040. #endif
  1041.  
  1042. #ifdef OLD_QQ
  1043. #  define QCOND2    (qflag < 2)
  1044. #else
  1045. #  define QCOND2    (!qflag)
  1046. #endif
  1047.  
  1048. #ifndef TRUE
  1049. #  define TRUE      1   /* sort of obvious */
  1050. #endif
  1051. #ifndef FALSE
  1052. #  define FALSE     0
  1053. #endif
  1054.  
  1055. #ifndef SEEK_SET
  1056. #  define SEEK_SET  0
  1057. #  define SEEK_CUR  1
  1058. #  define SEEK_END  2
  1059. #endif
  1060.  
  1061. #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
  1062. #  define SYMLINKS
  1063. #  ifndef S_ISLNK
  1064. #    define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)
  1065. #  endif
  1066. #endif /* UNIX && S_IFLNK && !MTS */
  1067.  
  1068. #ifndef S_ISDIR
  1069. #  define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)
  1070. #endif
  1071.  
  1072. #ifndef IS_VOLID
  1073. #  define IS_VOLID(m)  ((m) & 0x08)
  1074. #endif
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080. /**************/
  1081. /*  Typedefs  */
  1082. /**************/
  1083.  
  1084. typedef char              boolean;
  1085. typedef unsigned char     uch;  /* code assumes unsigned bytes; these type-  */
  1086. typedef unsigned short    ush;  /*  defs replace byte/UWORD/ULONG (which are */
  1087. typedef unsigned long     ulg;  /*  predefined on some systems) & match zip  */
  1088.  
  1089. typedef struct min_info {
  1090.     long offset;
  1091.     ulg compr_size;          /* compressed size (needed if extended header) */
  1092.     ulg crc;                 /* crc (needed if extended header) */
  1093.     int hostnum;
  1094.     unsigned file_attr;      /* local flavor, as used by creat(), chmod()... */
  1095.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  1096.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  1097.     unsigned textfile : 1;   /* file is text (according to zip) */
  1098.     unsigned textmode : 1;   /* file is to be extracted as text */
  1099.     unsigned lcflag : 1;     /* convert filename to lowercase */
  1100.     unsigned vollabel : 1;   /* "file" is an MS-DOS volume (disk) label */
  1101. } min_info;
  1102.  
  1103. typedef struct VMStimbuf {
  1104.     char *revdate;           /* (both correspond to Unix modtime/st_mtime) */
  1105.     char *credate;
  1106. } VMStimbuf;
  1107.  
  1108. /*---------------------------------------------------------------------------
  1109.     Zipfile work area declarations.
  1110.   ---------------------------------------------------------------------------*/
  1111.  
  1112. #ifdef MALLOC_WORK
  1113.  
  1114.    union work {
  1115.      struct {
  1116.        short *Prefix_of;            /* (8193 * sizeof(short)) */
  1117.        uch *Suffix_of;
  1118.        uch *Stack;
  1119.      } shrink;                      /* unshrink() */
  1120.      uch *Slide;                    /* explode(), inflate(), unreduce() */
  1121.    };
  1122. #  define prefix_of  area.shrink.Prefix_of
  1123. #  define suffix_of  area.shrink.Suffix_of
  1124. #  define stack      area.shrink.Stack
  1125.  
  1126. #else /* !MALLOC_WORK */
  1127.  
  1128. #  ifdef NEW_UNSHRINK   /* weird segmentation violations if union NODE array */
  1129.      union work {
  1130.        uch Stack[8192];             /* unshrink() */
  1131.        uch Slide[WSIZE];            /* explode(), inflate(), unreduce() */
  1132.      };
  1133. #    define stack  area.Stack
  1134. #  else
  1135.      union work {
  1136.        struct {
  1137.          short Prefix_of[HSIZE];    /* (8192 * sizeof(short)) */
  1138.          uch Suffix_of[HSIZE];
  1139.          uch Stack[HSIZE];
  1140.        } shrink;
  1141.        uch Slide[WSIZE];            /* explode(), inflate(), unreduce() */
  1142.      };
  1143. #    define prefix_of  area.shrink.Prefix_of
  1144. #    define suffix_of  area.shrink.Suffix_of
  1145. #    define stack      area.shrink.Stack
  1146. #  endif /* ?NEW_UNSHRINK */
  1147.  
  1148. #endif /* ?MALLOC_WORK */
  1149.  
  1150. #define slide  area.Slide
  1151.  
  1152. /*---------------------------------------------------------------------------
  1153.     Zipfile layout declarations.  If these headers ever change, make sure the
  1154.     xxREC_SIZE defines (above) change with them!
  1155.   ---------------------------------------------------------------------------*/
  1156.  
  1157.    typedef uch   local_byte_hdr[ LREC_SIZE ];
  1158. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  1159. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  1160. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  1161. #      define L_COMPRESSION_METHOD              4
  1162. #      define L_LAST_MOD_FILE_TIME              6
  1163. #      define L_LAST_MOD_FILE_DATE              8
  1164. #      define L_CRC32                           10
  1165. #      define L_COMPRESSED_SIZE                 14
  1166. #      define L_UNCOMPRESSED_SIZE               18
  1167. #      define L_FILENAME_LENGTH                 22
  1168. #      define L_EXTRA_FIELD_LENGTH              24
  1169.  
  1170.    typedef uch   cdir_byte_hdr[ CREC_SIZE ];
  1171. #      define C_VERSION_MADE_BY_0               0
  1172. #      define C_VERSION_MADE_BY_1               1
  1173. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  1174. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  1175. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  1176. #      define C_COMPRESSION_METHOD              6
  1177. #      define C_LAST_MOD_FILE_TIME              8
  1178. #      define C_LAST_MOD_FILE_DATE              10
  1179. #      define C_CRC32                           12
  1180. #      define C_COMPRESSED_SIZE                 16
  1181. #      define C_UNCOMPRESSED_SIZE               20
  1182. #      define C_FILENAME_LENGTH                 24
  1183. #      define C_EXTRA_FIELD_LENGTH              26
  1184. #      define C_FILE_COMMENT_LENGTH             28
  1185. #      define C_DISK_NUMBER_START               30
  1186. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  1187. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  1188. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  1189.  
  1190.    typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
  1191. /*     define SIGNATURE                         0   space-holder only */
  1192. #      define NUMBER_THIS_DISK                  4
  1193. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  1194. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  1195. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  1196. #      define SIZE_CENTRAL_DIRECTORY            12
  1197. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  1198. #      define ZIPFILE_COMMENT_LENGTH            20
  1199.  
  1200.  
  1201.    typedef struct local_file_header {                 /* LOCAL */
  1202.        uch version_needed_to_extract[2];
  1203.        ush general_purpose_bit_flag;
  1204.        ush compression_method;
  1205.        ush last_mod_file_time;
  1206.        ush last_mod_file_date;
  1207.        ulg crc32;
  1208.        ulg csize;
  1209.        ulg ucsize;
  1210.        ush filename_length;
  1211.        ush extra_field_length;
  1212.    } local_file_hdr;
  1213.  
  1214.    typedef struct central_directory_file_header {     /* CENTRAL */
  1215.        uch version_made_by[2];
  1216.        uch version_needed_to_extract[2];
  1217.        ush general_purpose_bit_flag;
  1218.        ush compression_method;
  1219.        ush last_mod_file_time;
  1220.        ush last_mod_file_date;
  1221.        ulg crc32;
  1222.        ulg csize;
  1223.        ulg ucsize;
  1224.        ush filename_length;
  1225.        ush extra_field_length;
  1226.        ush file_comment_length;
  1227.        ush disk_number_start;
  1228.        ush internal_file_attributes;
  1229.        ulg external_file_attributes;
  1230.        ulg relative_offset_local_header;
  1231.    } cdir_file_hdr;
  1232.  
  1233.    typedef struct end_central_dir_record {            /* END CENTRAL */
  1234.        ush number_this_disk;
  1235.        ush num_disk_with_start_central_dir;
  1236.        ush num_entries_centrl_dir_ths_disk;
  1237.        ush total_entries_central_dir;
  1238.        ulg size_central_directory;
  1239.        ulg offset_start_central_directory;
  1240.        ush zipfile_comment_length;
  1241.    } ecdir_rec;
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247. /*************************/
  1248. /*  Function Prototypes  */
  1249. /*************************/
  1250.  
  1251. #ifndef __
  1252. #  define __   OF
  1253. #endif
  1254.  
  1255. /*---------------------------------------------------------------------------
  1256.     Functions in unzip.c (main initialization/driver routines):
  1257.   ---------------------------------------------------------------------------*/
  1258.  
  1259. int    uz_opts                   __((int *pargc, char ***pargv));
  1260. int    usage                     __((int error));
  1261. int    process_zipfiles          __((void));
  1262. int    do_seekable               __((int lastchance));
  1263. int    uz_end_central            __((void));
  1264. int    process_cdir_file_hdr     __((void));
  1265. int    process_local_file_hdr    __((void));
  1266.  
  1267. /*---------------------------------------------------------------------------
  1268.     Functions in zipinfo.c (zipfile-listing routines):
  1269.   ---------------------------------------------------------------------------*/
  1270.  
  1271. int    zi_opts                   __((int *pargc, char ***pargv));
  1272. int    zi_end_central            __((void));
  1273. int    zipinfo                   __((void));
  1274. /* static int    zi_long         __((void)); */
  1275. /* static int    zi_short        __((void)); */
  1276. /* static char  *zi_time         __((ush *datez, ush *timez)); */
  1277. ulg    SizeOfEAs                 __((void *extra_field));  /* also in os2.c? */
  1278. int    list_files                __((void));
  1279. /* static int    ratio           __((ulg uc, ulg c)); */
  1280.  
  1281. /*---------------------------------------------------------------------------
  1282.     Functions in file_io.c:
  1283.   ---------------------------------------------------------------------------*/
  1284.  
  1285. int      open_input_file    __((void));
  1286. int      open_outfile       __((void));                        /* also vms.c */
  1287. unsigned readbuf            __((char *buf, register unsigned len));
  1288. int      FillBitBuffer      __((void));
  1289. int      readbyte           __((void));
  1290. #ifdef FUNZIP
  1291.    int   flush              __((ulg size));
  1292. #else
  1293.    int   flush              __((uch *buf, ulg size, int unshrink));
  1294. #endif
  1295. void     handler            __((int signal));
  1296. time_t   dos_to_unix_time   __((unsigned ddate, unsigned dtime));
  1297. int      check_for_newer    __((char *filename));       /* also os2.c, vms.c */
  1298. int      find_ecrec         __((long searchlen));
  1299. int      get_cdir_ent       __((void));
  1300. int      do_string          __((unsigned int len, int option));
  1301. ush      makeword           __((uch *b));
  1302. ulg      makelong           __((uch *sig));
  1303. int      zstrnicmp __((register char *s1, register char *s2, register int n));
  1304.  
  1305. #ifdef ZMEM   /* MUST be ifdef'd because of conflicts with the standard def. */
  1306.    char *memset __((register char *, register char, register unsigned int));
  1307.    char *memcpy __((register char *, register char *, register unsigned int));
  1308. #endif
  1309.  
  1310. #ifdef SMALL_MEM
  1311.    char *LoadFarString         __((char Far *sz));
  1312.    char *LoadFarStringSmall    __((char Far *sz));
  1313.    char *LoadFarStringSmall2   __((char Far *sz));
  1314.    char Far * Far zfstrcpy     __((char Far *s1, const char Far *s2));
  1315. #endif
  1316.  
  1317.  
  1318. /*---------------------------------------------------------------------------
  1319.     Functions in extract.c:
  1320.   ---------------------------------------------------------------------------*/
  1321.  
  1322. int    extract_or_test_files     __((void));
  1323. /* static int   store_info               __((void)); */
  1324. /* static int   extract_or_test_member   __((void)); */
  1325. int    memextract                __((uch *, ulg, uch *, ulg));
  1326. int    FlushMemory               __((void));
  1327. int    ReadMemoryByte            __((ush *x));
  1328.  
  1329. /*---------------------------------------------------------------------------
  1330.     Decompression functions:
  1331.   ---------------------------------------------------------------------------*/
  1332.  
  1333. int    explode                   __((void));                    /* explode.c */
  1334. int    inflate                   __((void));                    /* inflate.c */
  1335. int    inflate_free              __((void));                    /* inflate.c */
  1336. void   unreduce                  __((void));                   /* unreduce.c */
  1337. /* static void  LoadFollowers    __((void));                    * unreduce.c */
  1338. int    unshrink                  __((void));                   /* unshrink.c */
  1339. /* static void  partial_clear    __((void));                    * unshrink.c */
  1340.  
  1341. /*---------------------------------------------------------------------------
  1342.     Human68K-only functions:
  1343.   ---------------------------------------------------------------------------*/
  1344.  
  1345. #ifdef __human68k__
  1346.    void     InitTwentyOne        __((void));
  1347. #endif
  1348.  
  1349. /*---------------------------------------------------------------------------
  1350.     Macintosh-only functions:
  1351.   ---------------------------------------------------------------------------*/
  1352.  
  1353. #ifdef MACOS
  1354.    int      macmkdir             __((char *, short, long));
  1355.    short    macopen              __((char *, short, short, long));
  1356.    FILE    *macfopen             __((char *, char *, short, long));
  1357.    short    maccreat             __((char *, short, long, OSType, OSType));
  1358.    short    macread              __((short, char *, unsigned));
  1359.    long     macwrite             __((short, char *, unsigned));
  1360.    short    macclose             __((short));
  1361.    long     maclseek             __((short, long, short));
  1362.    char    *macgetenv            __((char *));
  1363.    char    *wfgets               __((char *, int, FILE *));
  1364.    void     wfprintf             __((FILE *, char *, ...));
  1365.    void     wprintf              __((char *, ...));
  1366. #endif
  1367.  
  1368. /*---------------------------------------------------------------------------
  1369.     MSDOS-only functions:
  1370.   ---------------------------------------------------------------------------*/
  1371.  
  1372. #if (defined(__GO32__) || (defined(MSDOS) && defined(__EMX__)))
  1373.    unsigned _dos_getcountryinfo(void *);                          /* msdos.c */
  1374.    void _dos_setftime(int, unsigned short, unsigned short);       /* msdos.c */
  1375.    void _dos_setfileattr(char *, int);                            /* msdos.c */
  1376.    unsigned _dos_creat(char *, unsigned, int *);                  /* msdos.c */
  1377.    void _dos_getdrive(unsigned *);                                /* msdos.c */
  1378.    unsigned _dos_close(int);                                      /* msdos.c */
  1379. #endif
  1380.  
  1381. /*---------------------------------------------------------------------------
  1382.     OS/2-only functions:
  1383.   ---------------------------------------------------------------------------*/
  1384.  
  1385. #ifdef OS2  /* GetFileTime conflicts with something in NT header files */
  1386.    int   GetCountryInfo   __((void));                               /* os2.c */
  1387.    long  GetFileTime      __((char *name));                         /* os2.c */
  1388.    void  SetPathInfo      __((char *path, ush moddate, ush modtime, int flags));
  1389.    int   IsEA             __((void *extra_field));                  /* os2.c */
  1390.    void  SetEAs           __((char *path, void *eablock));          /* os2.c */
  1391.    ulg   SizeOfEAs        __((void *extra_field));                  /* os2.c */
  1392. /* static int   IsFileNameValid __((char *name));                      os2.c */
  1393. /* static void  map2fat         __((char *pathcomp, char **pEndFAT));  os2.c */
  1394. /* static int   SetLongNameEA   __((char *name, char *longname));      os2.c */
  1395. /* static void  InitNLS         __((void));                            os2.c */
  1396.    int   IsUpperNLS       __((int nChr));                           /* os2.c */
  1397.    int   ToLowerNLS       __((int nChr));                           /* os2.c */
  1398.    void  DebugMalloc      __((void));                               /* os2.c */
  1399. #endif
  1400.  
  1401. /*---------------------------------------------------------------------------
  1402.     TOPS20-only functions:
  1403.   ---------------------------------------------------------------------------*/
  1404.  
  1405. #ifdef TOPS20
  1406.    int upper               __((char *s));                        /* tops20.c */
  1407.    int enquote             __((char *s));                        /* tops20.c */
  1408.    int dequote             __((char *s));                        /* tops20.c */
  1409.    int fnlegal             __(());  /* error if prototyped(?) */ /* tops20.c */
  1410. #endif
  1411.  
  1412. /*---------------------------------------------------------------------------
  1413.     VMS-only functions:
  1414.   ---------------------------------------------------------------------------*/
  1415.  
  1416. #ifdef VMS
  1417.    int    check_format        __((void));                           /* vms.c */
  1418.    int    find_vms_attrs      __((void));                           /* vms.c */
  1419.    int    CloseOutputFile     __((void));                           /* vms.c */
  1420. /* static uch *extract_block  __((struct extra_block *, int *, uch *, int)); */
  1421. /* static int  _flush_blocks  __((int final_flag));                  * vms.c */
  1422. /* static int  _flush_records __((int final_flag));                  * vms.c */
  1423. /* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c */
  1424. /* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c */
  1425. /* static void message        __((int string, char *status));        * vms.c */
  1426.    void   return_VMS          __((int zip_error));                  /* vms.c */
  1427. #ifdef VMSCLI
  1428.    ulg    vms_unzip_cmdline   __((int *, char ***));            /* cmdline.c */
  1429. #endif
  1430. #endif
  1431.  
  1432. /*---------------------------------------------------------------------------
  1433.     Miscellaneous/shared functions:
  1434.   ---------------------------------------------------------------------------*/
  1435.  
  1436. int      match           __((char *s, char *p, int ic));          /* match.c */
  1437. int      iswild          __((char *p));                           /* match.c */
  1438.  
  1439. void     envargs         __((int *, char ***, char *, char *)); /* envargs.c */
  1440. void     mksargs         __((int *, char ***));                 /* envargs.c */
  1441.  
  1442. int      dateformat      __((void));
  1443. void     version         __((void));                                /* local */
  1444. int      mapattr         __((void));                                /* local */
  1445. int      mapname         __((int renamed));                         /* local */
  1446. int      checkdir        __((char *pathcomp, int flag));            /* local */
  1447. char    *do_wild         __((char *wildzipfn));                     /* local */
  1448. char    *GetLoadPath     __((void));                                /* local */
  1449. #ifndef MTS /* macro in MTS */
  1450.    void  close_outfile   __((void));                                /* local */
  1451. #endif
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457. /************/
  1458. /*  Macros  */
  1459. /************/
  1460.  
  1461. #ifndef MAX
  1462. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  1463. #endif
  1464. #ifndef MIN
  1465. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  1466. #endif
  1467.  
  1468. #ifdef DEBUG
  1469. #  define Trace(x)   fprintf x
  1470. #else
  1471. #  define Trace(x)
  1472. #endif
  1473.  
  1474. #if defined(UNIX) || defined(T20_VMS)   /* generally old systems */
  1475. #  define ToLower(x)   ((char)(isupper((int)x)? tolower((int)x) : x))
  1476. #else
  1477. #  define ToLower      tolower          /* assumed "smart"; used in match() */
  1478. #endif
  1479.  
  1480.  
  1481. #define LSEEK(abs_offset) {LONGINT request=(abs_offset)+extra_bytes,\
  1482.    inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  1483.    if(request<0) {FPRINTF(stderr, LoadFarStringSmall(SeekMsg), LoadFarString(ReportMsg)); return(3);}\
  1484.    else if(bufstart!=cur_zipfile_bufstart)\
  1485.    {cur_zipfile_bufstart=lseek(zipfd,(LONGINT)bufstart,SEEK_SET);\
  1486.    if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  1487.    inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;} else\
  1488.    {incnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;}}
  1489.  
  1490. /*
  1491.  *  Seek to the block boundary of the block which includes abs_offset,
  1492.  *  then read block into input buffer and set pointers appropriately.
  1493.  *  If block is already in the buffer, just set the pointers.  This macro
  1494.  *  is used by process_end_central_dir (unzip.c) and do_string (file_io.c).
  1495.  *  A slightly modified version is embedded within extract_or_test_files
  1496.  *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  1497.  *
  1498.  *  macro LSEEK(abs_offset)
  1499.  *      ulg abs_offset;
  1500.  *  {
  1501.  *      LONGINT   request = abs_offset + extra_bytes;
  1502.  *      LONGINT   inbuf_offset = request % INBUFSIZ;
  1503.  *      LONGINT   bufstart = request - inbuf_offset;
  1504.  *
  1505.  *      if (request < 0) {
  1506.  *          FPRINTF(stderr, LoadFarStringSmall(SeekMsg),
  1507.  *            LoadFarString(ReportMsg));
  1508.  *          return(3);             /-* 3:  severe error in zipfile *-/
  1509.  *      } else if (bufstart != cur_zipfile_bufstart) {
  1510.  *          cur_zipfile_bufstart = lseek(zipfd, (LONGINT)bufstart, SEEK_SET);
  1511.  *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  1512.  *              return(51);        /-* 51:  unexpected EOF *-/
  1513.  *          inptr = inbuf + (int)inbuf_offset;
  1514.  *          incnt -= (int)inbuf_offset;
  1515.  *      } else {
  1516.  *          incnt += (inptr-inbuf) - (int)inbuf_offset;
  1517.  *          inptr = inbuf + (int)inbuf_offset;
  1518.  *      }
  1519.  *  }
  1520.  *
  1521.  */
  1522.  
  1523.  
  1524. #define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  1525.   {error_in_archive=error; if(error>1) return error;}
  1526.  
  1527. /*
  1528.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  1529.  *  and unzip.c in several functions.
  1530.  *
  1531.  *  macro SKIP_(length)
  1532.  *      ush length;
  1533.  *  {
  1534.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  1535.  *          error_in_archive = error;   /-* might be warning *-/
  1536.  *          if (error > 1)              /-* fatal *-/
  1537.  *              return (error);
  1538.  *      }
  1539.  *  }
  1540.  *
  1541.  */
  1542.  
  1543.  
  1544. #ifdef FUNZIP
  1545. #  define FLUSH    flush
  1546. #  define NEXTBYTE getc(in)   /* redefined in crypt.h if full version */
  1547. #else
  1548. #  define FLUSH(w) if (mem_mode) outcnt=(w); else flush(slide,(ulg)w,0)
  1549. #  define NEXTBYTE (csize-- <= 0 ? EOF : (--incnt >= 0 ? *inptr++ : readbyte()))
  1550. #endif
  1551.  
  1552.  
  1553. #define READBITS(nbits,zdest) {if(nbits>bits_left) {int temp; zipeof=1;\
  1554.   while (bits_left<=8*(sizeof(bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
  1555.   bitbuf|=(ulg)temp<<bits_left; bits_left+=8; zipeof=0;}}\
  1556.   zdest=(int)((ush)bitbuf&mask_bits[nbits]);bitbuf>>=nbits;bits_left-=nbits;}
  1557.  
  1558. /*
  1559.  * macro READBITS(nbits,zdest)    * only used by unreduce and unshrink *
  1560.  *  {
  1561.  *      if (nbits > bits_left) {  * fill bitbuf, which is 8*sizeof(ulg) bits *
  1562.  *          int temp;
  1563.  *
  1564.  *          zipeof = 1;
  1565.  *          while (bits_left <= 8*(sizeof(bitbuf)-1) &&
  1566.  *                 (temp = NEXTBYTE) != EOF) {
  1567.  *              bitbuf |= (ulg)temp << bits_left;
  1568.  *              bits_left += 8;
  1569.  *              zipeof = 0;
  1570.  *          }
  1571.  *      }
  1572.  *      zdest = (int)((ush)bitbuf & mask_bits[nbits]);
  1573.  *      bitbuf >>= nbits;
  1574.  *      bits_left -= nbits;
  1575.  *  }
  1576.  *
  1577.  */
  1578.  
  1579.  
  1580. /* GRR:  should change name to STRLOWER and use StringLower if possible */
  1581.  
  1582. /*
  1583.  *  Copy the zero-terminated string in str1 into str2, converting any
  1584.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1585.  *  as well, of course.  str1 and str2 may be the same character array.
  1586.  */
  1587. #ifdef __human68k__
  1588. #  define TOLOWER(str1, str2) \
  1589.    { \
  1590.        char *p=(str1), *q=(str2); \
  1591.        uch c; \
  1592.        while ((c = *p++) != '\0') { \
  1593.            if (iskanji(c)) { \
  1594.                if (*p == '\0') \
  1595.                    break; \
  1596.                *q++ = c; \
  1597.                *q++ = *p++; \
  1598.            } else \
  1599.                *q++ = isupper(c) ? tolower(c) : c; \
  1600.        } \
  1601.        *q = '\0'; \
  1602.    }
  1603. #else
  1604. #  define TOLOWER(str1, str2) \
  1605.    { \
  1606.        char  *p, *q; \
  1607.        p = (str1) - 1; \
  1608.        q = (str2); \
  1609.        while (*++p) \
  1610.            *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
  1611.        *q = '\0'; \
  1612.    }
  1613. #endif
  1614. /*
  1615.  *  NOTES:  This macro makes no assumptions about the characteristics of
  1616.  *    the tolower() function or macro (beyond its existence), nor does it
  1617.  *    make assumptions about the structure of the character set (i.e., it
  1618.  *    should work on EBCDIC machines, too).  The fact that either or both
  1619.  *    of isupper() and tolower() may be macros has been taken into account;
  1620.  *    watch out for "side effects" (in the C sense) when modifying this
  1621.  *    macro.
  1622.  */
  1623.  
  1624.  
  1625. #ifndef native
  1626. #  define native(c)   (c)
  1627. #  define A_TO_N(str1)
  1628. #else
  1629. #  ifndef NATIVE
  1630. #    define NATIVE     "native chars"
  1631. #  endif
  1632. #  define A_TO_N(str1) {register unsigned char *p;\
  1633.      for (p=str1; *p; p++) *p=native(*p);}
  1634. #endif
  1635.  
  1636. /*
  1637.  *  Translate the zero-terminated string in str1 from ASCII to the native
  1638.  *  character set. The translation is performed in-place and uses the
  1639.  *  "native" macro to translate each character.
  1640.  *
  1641.  *  macro A_TO_N( str1 )
  1642.  *  {
  1643.  *      register unsigned char *p;
  1644.  *
  1645.  *      for (p = str1;  *p;  ++p)
  1646.  *          *p = native(*p);
  1647.  *  }
  1648.  *
  1649.  *  NOTE:  Using the "native" macro means that is it the only part of unzip
  1650.  *    which knows which translation table (if any) is actually in use to
  1651.  *    produce the native character set.  This makes adding new character set
  1652.  *    translation tables easy, insofar as all that is needed is an appropriate
  1653.  *    "native" macro definition and the translation table itself.  Currently,
  1654.  *    the only non-ASCII native character set implemented is EBCDIC, but this
  1655.  *    may not always be so.
  1656.  */
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662. /*************/
  1663. /*  Globals  */
  1664. /*************/
  1665.  
  1666.    extern int       zipinfo_mode;
  1667.    extern int       aflag;
  1668.    extern int       cflag;
  1669.    extern int       C_flag;
  1670.    extern int       fflag;
  1671.    extern int       hflag;
  1672.    extern int       jflag;
  1673.    extern int       lflag;
  1674.    extern int       L_flag;
  1675.    extern int       overwrite_none;
  1676.    extern int       overwrite_all;
  1677.    extern int       force_flag;
  1678.    extern int       qflag;
  1679. #ifdef DOS_NT_OS2
  1680.    extern int       sflag;
  1681.    extern int       volflag;
  1682. #endif
  1683.    extern int       tflag;
  1684.    extern int       T_flag;
  1685.    extern int       uflag;
  1686.    extern int       vflag;
  1687.    extern int       V_flag;
  1688. #ifdef VMS
  1689.    extern int       secinf;
  1690. #endif
  1691.    extern int       zflag;
  1692. #ifdef MACOS
  1693.    extern int       HFSFlag;
  1694. #endif
  1695.    extern int       filespecs;
  1696.    extern int       xfilespecs;
  1697.    extern int       process_all_files;
  1698.    extern int       create_dirs;
  1699.    extern LONGINT   real_ecrec_offset;
  1700.    extern LONGINT   expect_ecrec_offset;
  1701.    extern long      csize;
  1702.    extern long      ucsize;
  1703.    extern long      used_csize;
  1704.    extern char      **pfnames;
  1705.    extern char      **pxnames;
  1706.    extern char near sig[];
  1707.    extern char near answerbuf[];
  1708.    extern min_info  *pInfo;
  1709.  
  1710.    extern union work area;
  1711.  
  1712. #ifdef FUNZIP
  1713.    extern ulg near  crc_32_tab[];
  1714. #else
  1715.    extern ulg       *crc_32_tab;
  1716. #endif
  1717.    extern ulg       crc32val;
  1718.    extern ush near  mask_bits[];
  1719.  
  1720.    extern uch       *inbuf;
  1721.    extern uch       *inptr;
  1722.    extern int       incnt;
  1723.    extern ulg       bitbuf;
  1724.    extern int       bits_left;
  1725.    extern boolean   zipeof;
  1726.    extern char      *zipfn;
  1727.    extern int       zipfd;
  1728.    extern LONGINT   ziplen;
  1729.    extern LONGINT   cur_zipfile_bufstart;
  1730.    extern LONGINT   extra_bytes;
  1731.    extern uch       *extra_field;
  1732.    extern uch       *hold;
  1733.    extern char near local_hdr_sig[];
  1734.    extern char near central_hdr_sig[];
  1735.    extern char near end_central_sig[];
  1736.    extern local_file_hdr  lrec;
  1737.    extern cdir_file_hdr   crec;
  1738.    extern ecdir_rec       ecrec;
  1739.    extern struct stat     statbuf;
  1740.  
  1741.    extern int       mem_mode;
  1742.    extern int       disk_full;
  1743.    extern int       newfile;
  1744. #ifdef SYMLINKS
  1745.    extern int       symlnk;
  1746. #endif
  1747. #ifdef FUNZIP
  1748.    extern FILE      *in;
  1749. #endif
  1750.    extern FILE      *outfile;
  1751.    extern uch       *outbuf;
  1752.    extern uch       *outbuf2;
  1753.    extern uch       *outptr;
  1754.    extern ulg       outcnt;
  1755. #ifdef MSWIN
  1756.    extern char      *filename;
  1757. #else
  1758.    extern char near filename[];
  1759. #endif
  1760.  
  1761. #ifdef DECLARE_ERRNO
  1762.    extern int       errno;
  1763. #endif
  1764.  
  1765. #ifdef EBCDIC
  1766.    extern uch       ebcdic[];
  1767. #endif
  1768.  
  1769. #ifdef MACOS
  1770.    extern short     gnVRefNum;
  1771.    extern long      glDirID;
  1772.    extern OSType    gostCreator;
  1773.    extern OSType    gostType;
  1774.    extern boolean   fMacZipped;
  1775.    extern boolean   macflag;
  1776.    extern short     giCursor;
  1777.    extern CursHandle rghCursor[];
  1778. #endif
  1779.  
  1780.    extern char Far  CentSigMsg[];
  1781.    extern char Far  EndSigMsg[];
  1782.    extern char Far  SeekMsg[];
  1783.    extern char Far  ReportMsg[];
  1784.    extern char Far  FilenameNotMatched[];
  1785.    extern char Far  ExclFilenameNotMatched[];
  1786. #ifndef SFX
  1787.    extern char Far  CompiledWith[];
  1788. #endif
  1789.  
  1790. #endif /* !__unzip_h */
  1791.