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