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