home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip52.zip / unzpriv.h < prev    next >
C/C++ Source or Header  |  1996-04-27  |  67KB  |  1,868 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzpriv.h
  4.  
  5.   This header file contains private (internal) macros, typedefs, prototypes
  6.   and global-variable declarations used by all of the UnZip source files.
  7.   In a prior life it was part of the main unzip.h header, but now it is only
  8.   included by that header if UNZIP_INTERNAL is defined.
  9.  
  10.   ---------------------------------------------------------------------------*/
  11.  
  12.  
  13.  
  14. #ifndef __unzpriv_h   /* prevent multiple inclusions */
  15. #define __unzpriv_h
  16.  
  17. /* First thing: Signal all following code that we compile UnZip utilities! */
  18. #ifndef UNZIP
  19. #  define UNZIP
  20. #endif
  21.  
  22. /* GRR 960204:  MORE defined here in preparation for removal altogether */
  23. #ifndef MORE
  24. #  define MORE
  25. #endif
  26.  
  27. /* GRR 960218:  testing a new feature...definitely *not* ready for primetime */
  28. #if (defined(TIMESTAMP) && !defined(UNIX))
  29. #  undef TIMESTAMP
  30. #endif
  31.  
  32. /* fUnZip should never need to be reentrant */
  33. #ifdef FUNZIP
  34. #  ifdef REENTRANT
  35. #    undef REENTRANT
  36. #  endif
  37. #  ifdef DLL
  38. #    undef DLL
  39. #  endif
  40. #endif
  41.  
  42. #if (defined(DLL) && !defined(REENTRANT))
  43. #  define REENTRANT
  44. #endif
  45.  
  46. #ifndef DYNAMIC_CRC_TABLE
  47. #  define DYNAMIC_CRC_TABLE
  48. #endif
  49.  
  50. #if (defined(DYNAMIC_CRC_TABLE) && !defined(REENTRANT))
  51. #  ifndef DYNALLOC_CRCTAB
  52. #    define DYNALLOC_CRCTAB
  53. #  endif
  54. #endif
  55.  
  56. #ifndef MINIX            /* Minix needs it after all the other includes (?) */
  57. #  include <stdio.h>
  58. #endif
  59. #include <ctype.h>       /* skip for VMS, to use tolower() function? */
  60. #include <errno.h>       /* used in mapname() */
  61. #ifdef USE_STRINGS_H
  62. #  include <strings.h>   /* strcpy, strcmp, memcpy, index/rindex, etc. */
  63. #else
  64. #  include <string.h>    /* strcpy, strcmp, memcpy, strchr/strrchr, etc. */
  65. #endif
  66. #if (defined(MODERN) && !defined(NO_LIMITS_H))
  67. #  include <limits.h>    /* GRR:  EXPERIMENTAL!  (can be deleted) */
  68. #endif
  69.  
  70. /* this include must be down here for SysV.4, for some reason... */
  71. #include <signal.h>      /* used in unzip.c, fileio.c */
  72.  
  73.  
  74. /*---------------------------------------------------------------------------
  75.     API (DLL) section:
  76.   ---------------------------------------------------------------------------*/
  77.  
  78. #ifdef DLL
  79. #  define MAIN  UzpMain   /* was UzpUnzip */
  80. #  ifdef OS2API
  81. #    undef Info
  82. #    define REDIRECTC(c)             varputchar(__G__ c)
  83. #    define REDIRECTPRINT(buf,size)  varmessage(__G__ buf, size)
  84. #    define FINISH_REDIRECT()        finish_REXX_redirect(__G)
  85. #  else
  86. #    define REDIRECTC(c)
  87. #    define REDIRECTPRINT(buf,size)  0
  88. #    define FINISH_REDIRECT()
  89. #  endif
  90. #endif
  91.  
  92. /*---------------------------------------------------------------------------
  93.     Acorn RISCOS section:
  94.   ---------------------------------------------------------------------------*/
  95.  
  96. #ifdef RISCOS
  97. #  include "acorn/riscos.h"
  98. #endif
  99.  
  100. /*---------------------------------------------------------------------------
  101.     Amiga section:
  102.   ---------------------------------------------------------------------------*/
  103.  
  104. #ifdef AMIGA
  105. #  include "amiga/amiga.h"
  106. #endif
  107.  
  108. /*---------------------------------------------------------------------------
  109.     AOS/VS section (somewhat similar to Unix, apparently):
  110.   ---------------------------------------------------------------------------*/
  111.  
  112. #ifdef AOS_VS
  113. #  ifdef FILEIO_C
  114. #    include "aosvs/aosvs.h"
  115. #  endif
  116. #endif
  117.  
  118. /*---------------------------------------------------------------------------
  119.     Atari ST section:
  120.   ---------------------------------------------------------------------------*/
  121.  
  122. #ifdef ATARI
  123. #  include <time.h>
  124. #  include <stat.h>
  125. #  include <fcntl.h>
  126. #  include <limits.h>
  127. #  define SYMLINKS
  128. #  define EXE_EXTENSION  ".tos"
  129. #  define DATE_FORMAT    DF_MDY
  130. #  define DIR_END        '/'
  131. #  define INT_SPRINTF
  132. #  define timezone      _timezone
  133. #  define lenEOL        2
  134. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  135. #  undef SHORT_NAMES
  136. #endif
  137.  
  138. /*---------------------------------------------------------------------------
  139.     Human68k/X68000 section:
  140.   ---------------------------------------------------------------------------*/
  141.  
  142. #ifdef __human68k__    /* DO NOT DEFINE DOS_OS2 HERE!  If Human68k is so much */
  143. #  include <time.h>    /*  like MS-DOS and/or OS/2, create DOS_H68_OS2 macro. */
  144. #  include <fcntl.h>
  145. #  include <io.h>
  146. #  include <conio.h>
  147. #  include <jctype.h>
  148. #  include <sys/stat.h>
  149. #  define DATE_FORMAT   DF_YMD   /* Japanese standard */
  150.       /* GRR:  these EOL macros are guesses */
  151. #  define lenEOL        2
  152. #  define PutNativeEOL  {*q++ = native(CR); *q++ = native(LF);}
  153. #  define EXE_EXTENSION ".exe"   /* just a guess... */
  154. #endif
  155.  
  156. /*---------------------------------------------------------------------------
  157.     Mac section:
  158.   ---------------------------------------------------------------------------*/
  159.  
  160. #ifdef THINK_C
  161. #  define MACOS
  162. #  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  163. #    define __STDC__ 1        /*   make sure it's defined: it needs it */
  164. #  else
  165. #    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  166. #      undef __STDC__         /*   it needs to be 1 or required header */
  167. #      define __STDC__ 1      /*   files are not properly included. */
  168. #    endif /* !__STDC__ */
  169. #  endif
  170. #  define CREATOR  'KAHL'
  171. #  define MAIN     _dummy_main
  172. #endif /* THINK_C */
  173.  
  174. #ifdef MPW
  175. #  define MACOS
  176. #  include <Errors.h>
  177. #  include <Files.h>
  178. #  include <Memory.h>
  179. #  include <Quickdraw.h>
  180. #  include <ToolUtils.h>
  181. #  ifdef fileno
  182. #    undef fileno
  183. #  endif
  184. #  ifdef MCH_MACINTOSH
  185. #    define CREATOR     'Manx'
  186. #  else
  187. #    define CREATOR     'MPS '
  188. #  endif
  189. #endif /* MPW */
  190.  
  191. #ifdef MACOS
  192. #  include <fcntl.h>            /* O_BINARY for open() w/o CR/LF translation */
  193. #  define fileno(x)     ((x) == stdout ? 1 : ((x) == stderr ? 2 : (short)(x)))
  194. #  define open(x,y)     macopen((x), (y), G.gnVRefNum, G.glDirID)
  195. #  define fopen(x,y)    macfopen((x), (y), G.gnVRefNum, G.glDirID)
  196. #  define close         macclose
  197. #  define fclose(x)     macclose(fileno((x)))
  198. #  define read          macread
  199. #  define write         macwrite
  200. #  define lseek         maclseek
  201. #  define creat(x,y)    maccreat((x), G.gnVRefNum, G.glDirID, G.gostCreator, G.gostType)
  202. #  define stat(x,y)     macstat((x), (y), G.gnVRefNum, G.glDirID)
  203. #  define dup
  204. #  ifndef MCH_MACINTOSH
  205. #    define NO_STRNICMP
  206. #  endif
  207. #  define DIR_END ':'
  208. #  define DATE_FORMAT   DF_MDY
  209. #  define lenEOL        1
  210. #  define PutNativeEOL  *q++ = native(CR);
  211. #  define MALLOC_WORK
  212. #  define INT_SPRINTF
  213.  
  214. #  ifdef THINK_C
  215. #    define fgets       wfgets
  216. #    define fflush(f)
  217. #    define fprintf     wfprintf
  218. #    define fputs(s,f)  wfprintf((f), "%s", (s))
  219. #    define isatty(f)   (((f) >= 0) || ((f) <= 2))
  220. #    define printf      wprintf
  221. #    ifdef putc
  222. #      undef putc
  223. #    endif
  224. #    define putc(c,f)   wfprintf((f), "%c", (c))
  225. #    define getenv      macgetenv
  226. #  endif
  227.  
  228. #  ifndef isascii
  229. #    define isascii(c)  ((unsigned char)(c) <= 0x3F)
  230. #  endif
  231.  
  232. #  include "macstat.h"
  233. #  include "macdir.h"
  234.  
  235. #  ifdef CR
  236. #    undef  CR
  237. #  endif
  238.  
  239. typedef struct _ZipExtraHdr {
  240.     ush header;               /*    2 bytes */
  241.     ush data;                 /*    2 bytes */
  242. } ZIP_EXTRA_HEADER;
  243.  
  244. typedef struct _MacInfoMin {
  245.     ush header;               /*    2 bytes */
  246.     ush data;                 /*    2 bytes */
  247.     ulg signature;            /*    4 bytes */
  248.     FInfo finfo;              /*   16 bytes */
  249.     ulg lCrDat;               /*    4 bytes */
  250.     ulg lMdDat;               /*    4 bytes */
  251.     ulg flags ;               /*    4 bytes */
  252.     ulg lDirID;               /*    4 bytes */
  253.                               /*------------*/
  254. } MACINFOMIN;                 /* = 40 bytes for size of data */
  255.  
  256. typedef struct _MacInfo {
  257.     ush header;               /*    2 bytes */
  258.     ush data;                 /*    2 bytes */
  259.     ulg signature;            /*    4 bytes */
  260.     FInfo finfo;              /*   16 bytes */
  261.     ulg lCrDat;               /*    4 bytes */
  262.     ulg lMdDat;               /*    4 bytes */
  263.     ulg flags ;               /*    4 bytes */
  264.     ulg lDirID;               /*    4 bytes */
  265.     char rguchVolName[28];    /*   28 bytes */
  266.                               /*------------*/
  267. } MACINFO;                    /* = 68 bytes for size of data */
  268. #endif /* MACOS */
  269.  
  270. /*---------------------------------------------------------------------------
  271.     MS-DOS and OS/2 section:
  272.   ---------------------------------------------------------------------------*/
  273.  
  274. #ifdef WIZUNZIP
  275. #  define MSWIN
  276. #  ifdef MORE
  277. #    undef MORE
  278. #  endif
  279. #endif
  280.  
  281. #if (defined(_MSC_VER) || (defined(M_I86) && !defined(__WATCOMC__)))
  282. #  ifndef MSC
  283. #    define MSC               /* This should work for older MSC, too!  */
  284. #  endif
  285. #endif
  286.  
  287. #ifdef MSWIN
  288. #  include "wingui\wizunzip.h"
  289. #endif
  290.  
  291. #if (defined(MSDOS) || defined(OS2))
  292. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  293. #  include <sys/stat.h>
  294. #  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  295. #  include <time.h>           /* localtime() */
  296. #  include <fcntl.h>          /* O_BINARY for open() w/o CR/LF translation */
  297.  
  298. #  ifdef OS2                  /* defined for all OS/2 compilers */
  299. #    include "os2/os2cfg.h"
  300. #  else
  301. #    include "msdos/doscfg.h"
  302. #  endif
  303.  
  304. #  ifdef __GO32__
  305. #    define DIR_END '/'
  306. #  else
  307. #    define DIR_END '\\'
  308. #  endif
  309. #  ifndef WIN32
  310. #    define DATE_FORMAT   dateformat()
  311. #  endif
  312. #  define lenEOL          2
  313. #  define PutNativeEOL    {*q++ = native(CR); *q++ = native(LF);}
  314. #  define USE_EF_UX_TIME
  315. #endif /* MSDOS || OS2 */
  316.  
  317. /*---------------------------------------------------------------------------
  318.     MTS section (piggybacks UNIX, I think):
  319.   ---------------------------------------------------------------------------*/
  320.  
  321. #ifdef MTS
  322. #  include <sys/types.h>      /* off_t, time_t, dev_t, ... */
  323. #  include <sys/stat.h>
  324. #  include <sys/file.h>       /* MTS uses this instead of fcntl.h */
  325. #  include <timeb.h>
  326. #  include <time.h>
  327. #  include <unix.h>           /* some important non-ANSI routines */
  328. #  define mkdir(s,n) (-1)     /* no "make directory" capability */
  329. #  define EBCDIC              /* set EBCDIC conversion on */
  330. #  define NO_STRNICMP         /* unzip's is as good the one in MTS */
  331. #  define USE_FWRITE
  332. #  define close_outfile()  fclose(G.outfile)   /* can't set time on files */
  333. #  define umask(n)            /* don't have umask() on MTS */
  334. #  define FOPWT         "w"   /* open file for writing in TEXT mode */
  335. #  define DATE_FORMAT   DF_MDY
  336. #  define lenEOL        1
  337. #  define PutNativeEOL  *q++ = native(LF);
  338. #endif /* MTS */
  339.  
  340. /*---------------------------------------------------------------------------
  341.     Win32 section:
  342.   ---------------------------------------------------------------------------*/
  343.  
  344. #ifdef WIN32  /* NT and Win95 */
  345. #  include "win32/w32cfg.h"
  346. #endif
  347.  
  348. /*---------------------------------------------------------------------------
  349.     TOPS-20 section:
  350.   ---------------------------------------------------------------------------*/
  351.  
  352. #ifdef TOPS20
  353. #  include <sys/types.h>        /* off_t, time_t, dev_t, ... */
  354. #  include <sys/stat.h>
  355. #  include <sys/param.h>
  356. #  include <sys/time.h>
  357. #  include <sys/timeb.h>
  358. #  include <sys/file.h>
  359. #  include <timex.h>
  360. #  include <monsym.h>           /* get amazing monsym() macro */
  361.    extern int open(), close(), read();
  362.    extern int stat(), unlink(), jsys(), fcntl();
  363.    extern long lseek(), dup(), creat();
  364. #  define strchr    index       /* GRR: necessary? */
  365. #  define strrchr   rindex
  366. #  define REALLY_SHORT_SYMS
  367. #  define NO_MKDIR
  368. #  define DIR_BEG       '<'
  369. #  define DIR_END       '>'
  370. #  define DIR_EXT       ".directory"
  371. #  define DATE_FORMAT   DF_MDY
  372. #  define EXE_EXTENSION ".exe"  /* just a guess... */
  373. #endif /* TOPS20 */
  374.  
  375. /*---------------------------------------------------------------------------
  376.     Unix section:
  377.   ---------------------------------------------------------------------------*/
  378.  
  379. #ifdef UNIX
  380. #  include <sys/types.h>       /* off_t, time_t, dev_t, ... */
  381. #  include <sys/stat.h>
  382.  
  383. #  ifndef COHERENT
  384. #    include <fcntl.h>         /* O_BINARY for open() w/o CR/LF translation */
  385. #  else /* COHERENT */
  386. #    ifdef _I386
  387. #      include <fcntl.h>       /* Coherent 4.0.x, Mark Williams C */
  388. #    else
  389. #      include <sys/fcntl.h>   /* Coherent 3.10, Mark Williams C */
  390. #    endif
  391. #    define SHORT_SYMS
  392. #    ifndef __COHERENT__       /* Coherent 4.2 has tzset() */
  393. #      define tzset  settz
  394. #    endif
  395. #  endif /* ?COHERENT */
  396.  
  397. #  ifndef NO_PARAM_H
  398. #    ifdef NGROUPS_MAX
  399. #      undef NGROUPS_MAX       /* SCO bug:  defined again in <sys/param.h> */
  400. #    endif
  401. #    ifdef BSD
  402. #      define TEMP_BSD         /* may be defined again in <sys/param.h> */
  403. #      undef BSD
  404. #    endif
  405. #    include <sys/param.h>     /* conflict with <sys/types.h>, some systems? */
  406. #    ifdef TEMP_BSD
  407. #      undef TEMP_BSD
  408. #      ifndef BSD
  409. #        define BSD
  410. #      endif
  411. #    endif
  412. #  endif /* !NO_PARAM_H */
  413.  
  414. #  ifdef __osf__
  415. #    define DIRENT
  416. #    ifdef BSD
  417. #      undef BSD
  418. #    endif
  419. #  endif /* __osf__ */
  420.  
  421. #  ifdef BSD
  422. #    include <sys/time.h>
  423. #    include <sys/timeb.h>
  424. #    ifdef _AIX
  425. #      include <time.h>
  426. #    endif
  427. #  else
  428. #    include <time.h>
  429.      struct tm *gmtime(), *localtime();
  430. #  endif
  431.  
  432. #  if (defined(BSD4_4) || (defined(SYSV) && defined(MODERN)))
  433. #    include <unistd.h>        /* this includes utime.h on SGIs */
  434. #    ifdef BSD4_4
  435. #      include <utime.h>
  436. #    endif
  437. #  endif
  438.  
  439. #  if (defined(V7) || defined(pyr_bsd))
  440. #    define strchr   index
  441. #    define strrchr  rindex
  442. #  endif
  443. #  ifdef V7
  444. #    define O_RDONLY 0
  445. #    define O_WRONLY 1
  446. #    define O_RDWR   2
  447. #  endif
  448.  
  449. #  ifdef MINIX
  450. #    include <stdio.h>
  451. #  endif
  452. #  define DATE_FORMAT   DF_MDY    /* GRR:  customize with locale.h somehow? */
  453. #  define lenEOL        1
  454. #  define PutNativeEOL  *q++ = native(LF);
  455. #  define SCREENLINES   screenlines()
  456. #  define USE_EF_UX_TIME
  457. #endif /* UNIX */
  458.  
  459. /*---------------------------------------------------------------------------
  460.     VM/CMS and MVS section:
  461.   ---------------------------------------------------------------------------*/
  462.  
  463. #ifdef CMS_MVS
  464. #  include "vmmvs.h"
  465. #endif
  466.  
  467. /*---------------------------------------------------------------------------
  468.     VMS section:
  469.   ---------------------------------------------------------------------------*/
  470.  
  471. #ifdef VMS
  472. #  include <types.h>                    /* GRR:  experimenting... */
  473. #  include <stat.h>
  474. #  include <time.h>                     /* the usual non-BSD time functions */
  475. #  include <file.h>                     /* same things as fcntl.h has */
  476. #  include <unixio.h>
  477. #  include <rms.h>
  478. #  define _MAX_PATH (NAM$C_MAXRSS+1)    /* to define FILNAMSIZ below */
  479. #  ifdef RETURN_CODES  /* VMS interprets standard PK return codes incorrectly */
  480. #    define RETURN(ret) return_VMS(__G__ (ret))   /* verbose version */
  481. #    define EXIT(ret)   return_VMS(__G__ (ret))
  482. #  else
  483. #    define RETURN      return_VMS                /* quiet version */
  484. #    define EXIT        return_VMS
  485. #  endif
  486. #  define DIR_BEG       '['
  487. #  define DIR_END       ']'
  488. #  define DIR_EXT       ".dir"
  489. #  define DATE_FORMAT   DF_MDY
  490. #  define lenEOL        1
  491. #  define PutNativeEOL  *q++ = native(LF);
  492. #  define SCREENLINES   screenlines()
  493. #  if ((!defined(__VMS_VER)) || (__VMS_VER < 70000000))
  494. #    define NO_GMTIME           /* gmtime() of earlier VMS C RTLs is broken */
  495. #  else
  496. #    if (!defined(NO_EF_UX_TIME) && !defined(USE_EF_UX_TIME))
  497. #      define USE_EF_UX_TIME
  498. #    endif
  499. #  endif
  500. #endif /* VMS */
  501.  
  502.  
  503.  
  504.  
  505.  
  506. /*************/
  507. /*  Defines  */
  508. /*************/
  509.  
  510. #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  511. #define VMS_UNZIP_VERSION 42   /* if OS-needed-to-extract is VMS:  can do */
  512.  
  513. #if (defined(MSDOS) || defined(OS2))
  514. #  define DOS_OS2
  515. #endif
  516.  
  517. #if (defined(DOS_OS2) || defined(WIN32))
  518. #  define DOS_OS2_W32
  519. #  define DOS_W32_OS2          /* historical:  don't use */
  520. #endif
  521.  
  522. #if (defined(DOS_OS2_W32) || defined(__human68k__))
  523. #  define DOS_H68_OS2_W32
  524. #endif
  525.  
  526. #if (defined(TOPS20) || defined(VMS))
  527. #  define T20_VMS
  528. #endif
  529.  
  530. #if (defined(MSDOS) || defined(T20_VMS))
  531. #  define DOS_T20_VMS
  532. #endif
  533.  
  534. /* clean up with a few defaults */
  535. #ifndef DIR_END
  536. #  define DIR_END '/'       /* last char before program name (or filename) */
  537. #endif
  538. #ifndef DATE_FORMAT
  539. #  define DATE_FORMAT   DF_MDY  /* defaults to US convention */
  540. #endif
  541. #ifndef RETURN
  542. #  define RETURN  return        /* only used in main() */
  543. #endif
  544. #ifndef EXIT
  545. #  define EXIT    exit
  546. #endif
  547.  
  548. /* OS-specific exceptions to the "ANSI <--> INT_SPRINTF" rule */
  549.  
  550. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  551. #  if (defined(SYSV) || defined(CONVEX) || defined(NeXT) || defined(BSD4_4))
  552. #    define INT_SPRINTF      /* sprintf() returns int:  SysVish/Posix */
  553. #  endif
  554. #  if (defined(DOS_OS2_W32) || defined(VMS) || defined(AMIGA) || defined(_AIX))
  555. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
  556. #  endif
  557. #  if (defined(ultrix) || defined(__ultrix)) /* Ultrix 4.3 and newer */
  558. #    if (defined(POSIX) || defined(__POSIX))
  559. #      define INT_SPRINTF    /* sprintf() returns int:  ANSI/Posix */
  560. #    endif
  561. #    ifdef __GNUC__
  562. #      define PCHAR_SPRINTF  /* undetermined actual return value */
  563. #    endif
  564. #  endif
  565. #  if (defined(__osf__) || defined(CMS_MVS))
  566. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI/Posix */
  567. #  endif
  568. #  if defined(sun)
  569. #    define PCHAR_SPRINTF    /* sprintf() returns char *:  SunOS cc *and* gcc */
  570. #  endif
  571. #endif
  572.  
  573. /* defaults that we hope will take care of most machines in the future */
  574.  
  575. #if (!defined(PCHAR_SPRINTF) && !defined(INT_SPRINTF))
  576. #  ifdef __STDC__
  577. #    define INT_SPRINTF      /* sprintf() returns int:  ANSI */
  578. #  endif
  579. #  ifndef INT_SPRINTF
  580. #    define PCHAR_SPRINTF    /* sprintf() returns char *:  BSDish */
  581. #  endif
  582. #endif
  583.  
  584. #define MSG_STDERR(f)  (f & 1)        /* bit 0:  0 = stdout, 1 = stderr */
  585. #define MSG_INFO(f)    ((f & 6) == 0) /* bits 1 and 2:  0 = info */
  586. #define MSG_WARN(f)    ((f & 6) == 2) /* bits 1 and 2:  1 = warning */
  587. #define MSG_ERROR(f)   ((f & 6) == 4) /* bits 1 and 2:  2 = error */
  588. #define MSG_FATAL(f)   ((f & 6) == 6) /* bits 1 and 2:  (3 = fatal error) */
  589. #define MSG_ZFN(f)     (f & 0x0008)   /* bit 3:  1 = print zipfile name */
  590. #define MSG_FN(f)      (f & 0x0010)   /* bit 4:  1 = print filename */
  591. #define MSG_LNEWLN(f)  (f & 0x0020)   /* bit 5:  1 = leading newline if !SOL */
  592. #define MSG_TNEWLN(f)  (f & 0x0040)   /* bit 6:  1 = trailing newline if !SOL */
  593. #define MSG_MNEWLN(f)  (f & 0x0080)   /* bit 7:  1 = trailing newline if MPW */
  594. /* the following are subject to change */
  595. #define MSG_NO_WGUI(f) (f & 0x0100)   /* bit 8:  1 = skip if Windows GUI */
  596. #define MSG_NO_AGUI(f) (f & 0x0200)   /* bit 9:  1 = skip if Acorn GUI */
  597. #define MSG_NO_DLL2(f) (f & 0x0400)   /* bit 10:  1 = skip if OS/2 DLL */
  598. #define MSG_NO_NDLL(f) (f & 0x0800)   /* bit 11:  1 = skip if WIN32 DLL */
  599. #define MSG_NO_WDLL(f) (f & 0x1000)   /* bit 12:  1 = skip if Windows DLL */
  600.  
  601. #if (defined(MORE) && !defined(SCREENLINES))
  602. #  ifdef DOS_OS2_W32
  603. #    define SCREENLINES 25  /* can be (should be) a function instead */
  604. #  else
  605. #    define SCREENLINES 24  /* VT-100s are assumed to be minimal hardware */
  606. #  endif
  607. #endif
  608.  
  609. #define DIR_BLKSIZ  64      /* number of directory entries per block
  610.                              *  (should fit in 4096 bytes, usually) */
  611. #ifndef WSIZE
  612. #  define WSIZE     0x8000  /* window size--must be a power of two, and */
  613. #endif                      /*  at least 32K for zip's deflate method */
  614.  
  615. #ifndef INBUFSIZ
  616. #  if (defined(MED_MEM) || defined(SMALL_MEM))
  617. #    define INBUFSIZ  2048  /* works for MS-DOS small model */
  618. #  else
  619. #    define INBUFSIZ  8192  /* larger buffers for real OSes */
  620. #  endif
  621. #endif
  622.  
  623. #ifndef __16BIT__
  624. #  define nearmalloc  malloc
  625. #  define nearfree    free
  626. #  ifndef __IBMC__
  627. #    define near
  628. #    define far
  629. #  endif
  630. #endif
  631.  
  632. #if (defined(USE_ZLIB) && !defined(USE_OWN_CRCTAB))
  633. #  ifdef DYNALLOC_CRCTAB
  634. #    undef DYNALLOC_CRCTAB
  635. #  endif
  636. #endif
  637.  
  638. #if (defined(USE_ZLIB) && defined(ASM_CRC))
  639. #  undef ASM_CRC
  640. #endif
  641.  
  642. /* Logic for case of small memory, length of EOL > 1:  if OUTBUFSIZ == 2048,
  643.  * OUTBUFSIZ>>1 == 1024 and OUTBUFSIZ>>7 == 16; therefore rawbuf is 1008 bytes
  644.  * and transbuf 1040 bytes.  Have room for 32 extra EOL chars; 1008/32 == 31.5
  645.  * chars/line, smaller than estimated 35-70 characters per line for C source
  646.  * and normal text.  Hence difference is sufficient for most "average" files.
  647.  * (Argument scales for larger OUTBUFSIZ.)
  648.  */
  649. #ifdef SMALL_MEM          /* i.e., 16-bit OSes:  MS-DOS, OS/2 1.x, etc. */
  650. #  define LoadFarString(x)       fLoadFarString(__G__ (x))
  651. #  define LoadFarStringSmall(x)  fLoadFarStringSmall(__G__ (x))
  652. #  define LoadFarStringSmall2(x) fLoadFarStringSmall2(__G__ (x))
  653. #  if (defined(_MSC_VER) && (_MSC_VER >= 600))
  654. #    define zfstrcpy(dest, src)  _fstrcpy((dest), (src))
  655. #  endif
  656. #  ifndef Far
  657. #    define Far far  /* __far only works for MSC 6.00, not 6.0a or Borland */
  658. #  endif
  659. #  define OUTBUFSIZ INBUFSIZ
  660. #  if (lenEOL == 1)
  661. #    define RAWBUFSIZ (OUTBUFSIZ>>1)
  662. #  else
  663. #    define RAWBUFSIZ ((OUTBUFSIZ>>1) - (OUTBUFSIZ>>7))
  664. #  endif
  665. #  define TRANSBUFSIZ (OUTBUFSIZ-RAWBUFSIZ)
  666.    typedef short  shrint;            /* short/int or "shrink int" (unshrink) */
  667. #else
  668. #  define zfstrcpy(dest, src)    strcpy((dest), (src))
  669. #  define LoadFarString(x)       x
  670. #  define LoadFarStringSmall(x)  x
  671. #  define LoadFarStringSmall2(x) x
  672. #  ifdef MED_MEM
  673. #    define OUTBUFSIZ 0xFF80         /* can't malloc arrays of 0xFFE8 or more */
  674. #    define TRANSBUFSIZ 0xFF80
  675.      typedef short  shrint;
  676. #  else
  677. #    define OUTBUFSIZ (lenEOL*WSIZE) /* more efficient text conversion */
  678. #    define TRANSBUFSIZ (lenEOL*OUTBUFSIZ)
  679.      typedef int  shrint;            /* for efficiency/speed, we hope... */
  680. #  endif
  681. #  define RAWBUFSIZ OUTBUFSIZ
  682. #endif /* ?SMALL_MEM */
  683.  
  684. #ifndef Far
  685. #  define Far
  686. #endif
  687.  
  688. #ifndef MAIN
  689. #  define MAIN  main
  690. #endif
  691.  
  692. #if (defined(SFX) && !defined(NO_ZIPINFO))
  693. #  define NO_ZIPINFO
  694. #endif
  695.  
  696. #if (!defined(COPYRIGHT_CLEAN) && !defined(USE_SMITH_CODE))
  697. #  define COPYRIGHT_CLEAN
  698. #endif
  699.  
  700. #ifndef O_BINARY
  701. #  define O_BINARY  0
  702. #endif
  703.  
  704. #ifndef PIPE_ERROR
  705. #  define PIPE_ERROR (errno == EPIPE)
  706. #endif
  707.  
  708. /* File operations--use "b" for binary if allowed or fixed length 512 on VMS */
  709. #ifdef VMS
  710. #  define FOPR  "r","ctx=stm"
  711. #  define FOPM  "r+","ctx=stm","rfm=fix","mrs=512"
  712. #  define FOPW  "w","ctx=stm","rfm=fix","mrs=512"
  713. #endif /* VMS */
  714.  
  715. #ifdef CMS_MVS
  716. #  define FOPW "wb,recfm=f"
  717. #  ifdef MVS
  718. #    define FOPWT "w,lrecl=133"
  719. #  else
  720. #    define FOPWT "w"
  721. #  endif
  722. #endif /* CMS_MVS */
  723.  
  724. #ifdef TOPS20          /* TOPS-20 MODERN?  You kidding? */
  725. #  define FOPW "w8"
  726. #endif /* TOPS20 */
  727.  
  728. /* Defaults when nothing special has been defined previously. */
  729. #ifdef MODERN
  730. #  ifndef FOPR
  731. #    define FOPR "rb"
  732. #  endif
  733. #  ifndef FOPM
  734. #    define FOPM "r+b"
  735. #  endif
  736. #  ifndef FOPW
  737. #    define FOPW "wb"
  738. #  endif
  739. #  ifndef FOPWT
  740. #    define FOPWT "wt"
  741. #  endif
  742. #else /* !MODERN */
  743. #  ifndef FOPR
  744. #    define FOPR "r"
  745. #  endif
  746. #  ifndef FOPM
  747. #    define FOPM "r+"
  748. #  endif
  749. #  ifndef FOPW
  750. #    define FOPW "w"
  751. #  endif
  752. #  ifndef FOPWT
  753. #    define FOPWT "w"
  754. #  endif
  755. #endif /* ?MODERN */
  756.  
  757. /*
  758.  * If <limits.h> exists on most systems, should include that, since it may
  759.  * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  760.  * _POSIX_PATH_MAX.
  761.  */
  762. #ifdef DOS_OS2
  763. #  include <limits.h>
  764. #endif
  765.  
  766. #ifndef PATH_MAX
  767. #  ifdef MAXPATHLEN
  768. #    define PATH_MAX      MAXPATHLEN    /* in <sys/param.h> on some systems */
  769. #  else
  770. #    ifdef _MAX_PATH
  771. #      define PATH_MAX    _MAX_PATH
  772. #    else
  773. #      if FILENAME_MAX > 255
  774. #        define PATH_MAX  FILENAME_MAX  /* used like PATH_MAX on some systems */
  775. #      else
  776. #        define PATH_MAX  1024
  777. #      endif
  778. #    endif /* ?_MAX_PATH */
  779. #  endif /* ?MAXPATHLEN */
  780. #endif /* !PATH_MAX */
  781.  
  782. #define FILNAMSIZ  PATH_MAX
  783.  
  784. #ifdef SHORT_SYMS                   /* Mark Williams C, ...? */
  785. #  define extract_or_test_files     xtr_or_tst_files
  786. #  define extract_or_test_member    xtr_or_tst_member
  787. #endif
  788.  
  789. #ifdef REALLY_SHORT_SYMS            /* TOPS-20 linker:  first 6 chars */
  790. #  define process_cdir_file_hdr     XXpcdfh
  791. #  define process_local_file_hdr    XXplfh
  792. #  define extract_or_test_files     XXxotf  /* necessary? */
  793. #  define extract_or_test_member    XXxotm  /* necessary? */
  794. #  define check_for_newer           XXcfn
  795. #  define overwrite_all             XXoa
  796. #  define process_all_files         XXpaf
  797. #  define extra_field               XXef
  798. #  define explode_lit8              XXel8
  799. #  define explode_lit4              XXel4
  800. #  define explode_nolit8            XXnl8
  801. #  define explode_nolit4            XXnl4
  802. #  define cpdist8                   XXcpdist8
  803. #  define inflate_codes             XXic
  804. #  define inflate_stored            XXis
  805. #  define inflate_fixed             XXif
  806. #  define inflate_dynamic           XXid
  807. #  define inflate_block             XXib
  808. #  define maxcodemax                XXmax
  809. #endif
  810.  
  811. #ifdef RISCOS
  812. #  define ZSUFX           "/zip"
  813. #else
  814. #  define ZSUFX           ".zip"
  815. #endif
  816.  
  817. #define CENTRAL_HDR_SIG   "\001\002"   /* the infamous "PK" signature bytes, */
  818. #define LOCAL_HDR_SIG     "\003\004"   /*  sans "PK" (so unzip executable not */
  819. #define END_CENTRAL_SIG   "\005\006"   /*  mistaken for zipfile itself) */
  820. #define EXTD_LOCAL_SIG    "\007\010"   /* [ASCII "\113" == EBCDIC "\080" ??] */
  821.  
  822. #define SKIP              0    /* choice of activities for do_string() */
  823. #define DISPLAY           1
  824. #define DS_FN             2
  825. #define EXTRA_FIELD       3
  826. #define DS_EF             3
  827. #ifdef AMIGA
  828. #  define FILENOTE        4
  829. #endif
  830.  
  831. #define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  832. #define EXISTS_AND_OLDER  0
  833. #define EXISTS_AND_NEWER  1
  834.  
  835. #define ROOT              0    /* checkdir() extract-to path:  called once */
  836. #define INIT              1    /* allocate buildpath:  called once per member */
  837. #define APPEND_DIR        2    /* append a dir comp.:  many times per member */
  838. #define APPEND_NAME       3    /* append actual filename:  once per member */
  839. #define GETPATH           4    /* retrieve the complete path and free it */
  840. #define END               5    /* free root path prior to exiting program */
  841.  
  842. /* version_made_by codes (central dir):  make sure these */
  843. /*  are not defined on their respective systems!! */
  844. #define FS_FAT_           0    /* filesystem used by MS-DOS, OS/2, Win32 */
  845. #define AMIGA_            1
  846. #define VMS_              2
  847. #define UNIX_             3
  848. #define VM_CMS_           4
  849. #define ATARI_            5    /* what if it's a minix filesystem? [cjh] */
  850. #define FS_HPFS_          6    /* filesystem used by OS/2, NT */
  851. #define MAC_              7
  852. #define Z_SYSTEM_         8
  853. #define CPM_              9
  854. #define TOPS20_           10
  855. #define FS_NTFS_          11   /* filesystem used by Windows NT */
  856. #define QDOS_MAYBE_       12   /* a bit premature, but somebody once started */
  857. #define ACORN_            13   /* Archimedes Acorn RISC OS */
  858. #define FS_VFAT_          14   /* filesystem used by Windows 95 */
  859. #define MVS_              15
  860. #define BEBOX_            16
  861. #define NUM_HOSTS         17   /* index of last system + 1 */
  862.  
  863. #define STORED            0    /* compression methods */
  864. #define SHRUNK            1
  865. #define REDUCED1          2
  866. #define REDUCED2          3
  867. #define REDUCED3          4
  868. #define REDUCED4          5
  869. #define IMPLODED          6
  870. #define TOKENIZED         7
  871. #define DEFLATED          8
  872. #define NUM_METHODS       9    /* index of last method + 1 */
  873. /* don't forget to update list_files() appropriately if NUM_METHODS changes */
  874.  
  875. #define PK_OK             0    /* no error */
  876. #define PK_COOL           0    /* no error */
  877. #define PK_GNARLY         0    /* no error */
  878. #define PK_WARN           1    /* warning error */
  879. #define PK_ERR            2    /* error in zipfile */
  880. #define PK_BADERR         3    /* severe error in zipfile */
  881. #define PK_MEM            4    /* insufficient memory */
  882. #define PK_MEM2           5    /* insufficient memory */
  883. #define PK_MEM3           6    /* insufficient memory */
  884. #define PK_MEM4           7    /* insufficient memory */
  885. #define PK_MEM5           8    /* insufficient memory */
  886. #define PK_NOZIP          9    /* zipfile not found */
  887. #define PK_PARAM          10   /* bad or illegal parameters specified */
  888. #define PK_FIND           11   /* no files found */
  889. #define PK_DISK           50   /* disk full */
  890. #define PK_EOF            51   /* unexpected EOF */
  891.  
  892. #define IZ_DIR            76   /* potential zipfile is a directory */
  893. #define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  894. #define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  895. #define IZ_EF_TRUNC       79   /* local extra field truncated (PKZIP'd) */
  896.  
  897. #define DF_MDY            0    /* date format 10/26/91 (USA only) */
  898. #define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  899. #define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  900.  
  901. /* extra-field ID values, little-endian: */
  902. #define EF_AV        0x0007    /* PKWARE's authenticity verification ID */
  903. #define EF_OS2       0x0009    /* OS/2 extended attributes ID */
  904. #define EF_PKVMS     0x000c    /* PKWARE's VMS ID */
  905. #define EF_ASIUNIX   0x756e    /* ASi/PKWARE's Unix ID ("nu") */
  906. #define EF_IZVMS     0x4d49    /* Info-ZIP's VMS ID ("IM") */
  907. #define EF_IZUNIX    0x5855    /* Info-ZIP's Unix ID ("UX") */
  908. #define EF_VMCMS     0x4704    /* VM/CMS Extra Field ID ("\004G") */
  909. #define EF_MVS       0x470f    /* MVS Extra Field ID ("\017G") */
  910. #define EF_SPARK     0x4341    /* David Pilling's Acorn/SparkFS ID ("AC") */
  911. #define EF_MD5       0x4b46    /* Fred Kantor's MD5 ID ("FK") */
  912. #define EF_ACL       0x4C41    /* OS/2 ACL ID */
  913.  
  914. #define EB_HEADSIZE       4    /* length of extra field block header */
  915. #define EB_ID             0    /* offset of block ID in header */
  916. #define EB_LEN            2    /* offset of data length field in header */
  917.  
  918. #define EB_UX_MINLEN      8    /* minimal "UX" field contains atime, mtime */
  919. #define EB_UX_FULLSIZE    12   /* full "UX" field (atime, mtime, uid, gid) */
  920. #define EB_UX_ATIME       0    /* offset of atime in "UX" extra field data */
  921. #define EB_UX_MTIME       4    /* offset of mtime in "UX" extra field data */
  922. #define EB_UX_UID         8    /* byte offset of UID in "UX" field data */
  923. #define EB_UX_GID         10   /* byte offset of GID in "UX" field data */
  924.  
  925. /*---------------------------------------------------------------------------
  926.     True sizes of the various headers, as defined by PKWARE--so it is not
  927.     likely that these will ever change.  But if they do, make sure both these
  928.     defines AND the typedefs below get updated accordingly.
  929.   ---------------------------------------------------------------------------*/
  930. #define LREC_SIZE   26   /* lengths of local file headers, central */
  931. #define CREC_SIZE   42   /*  directory headers, and the end-of-    */
  932. #define ECREC_SIZE  18   /*  central-dir record, respectively      */
  933.  
  934. #define MAX_BITS    13                 /* used in unshrink() */
  935. #define HSIZE       (1 << MAX_BITS)    /* size of global work area */
  936.  
  937. #define LF     10        /* '\n' on ASCII machines; must be 10 due to EBCDIC */
  938. #define CR     13        /* '\r' on ASCII machines; must be 13 due to EBCDIC */
  939. #define CTRLZ  26        /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
  940.  
  941. #ifdef EBCDIC
  942. #  define native(c) ebcdic[(c)]
  943. #  define NATIVE    "EBCDIC"
  944. #endif
  945.  
  946. #if (defined(CRAY) && defined(ZMEM))
  947. #  undef ZMEM
  948. #endif
  949.  
  950. #ifdef ZMEM
  951. #  undef ZMEM
  952. #  define memcpy(dest,src,len)   bcopy(src,dest,len)
  953. #  define memzero                bzero
  954. #else
  955. #  define memzero(dest,len)      memset(dest,0,len)
  956. #endif
  957.  
  958. #ifdef VMS
  959. #  define ENV_UNZIP       "UNZIP_OPTS"     /* names of environment variables */
  960. #  define ENV_ZIPINFO     "ZIPINFO_OPTS"
  961. #else /* !VMS */
  962. #  ifdef RISCOS
  963. #    define ENV_UNZIP     "Unzip$Options"
  964. #    define ENV_ZIPINFO   "Zipinfo$Options"
  965. #  else /* !RISCOS */
  966. #    define ENV_UNZIP     "UNZIP"          /* the standard names */
  967. #    define ENV_ZIPINFO   "ZIPINFO"
  968. #  endif /* ?RISCOS */
  969. #endif /* ?VMS */
  970. #define ENV_UNZIP2        "UNZIPOPT"     /* alternate names, for zip compat. */
  971. #define ENV_ZIPINFO2      "ZIPINFOOPT"
  972.  
  973. #if (!defined(QQ) && !defined(NOQQ))
  974. #  define QQ
  975. #endif
  976.  
  977. #ifdef QQ                         /* Newtware version:  no file */
  978. #  define QCOND     (!G.qflag)   /*  comments with -vq or -vqq */
  979. #else                             /* Bill Davidsen version:  no way to */
  980. #  define QCOND     (which_hdr)   /*  kill file comments when listing */
  981. #endif
  982.  
  983. #ifdef OLD_QQ
  984. #  define QCOND2    (G.qflag < 2)
  985. #else
  986. #  define QCOND2    (!G.qflag)
  987. #endif
  988.  
  989. #ifndef TRUE
  990. #  define TRUE      1   /* sort of obvious */
  991. #endif
  992. #ifndef FALSE
  993. #  define FALSE     0
  994. #endif
  995.  
  996. #ifndef SEEK_SET
  997. #  define SEEK_SET  0
  998. #  define SEEK_CUR  1
  999. #  define SEEK_END  2
  1000. #endif
  1001.  
  1002. #if (defined(UNIX) && defined(S_IFLNK) && !defined(MTS))
  1003. #  define SYMLINKS
  1004. #  ifndef S_ISLNK
  1005. #    define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)
  1006. #  endif
  1007. #endif /* UNIX && S_IFLNK && !MTS */
  1008.  
  1009. #ifndef S_ISDIR
  1010. #  ifdef CMS_MVS
  1011. #    define S_ISDIR(m)  (FALSE)
  1012. #  else
  1013. #    define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)
  1014. # endif
  1015. #endif
  1016.  
  1017. #ifndef IS_VOLID
  1018. #  define IS_VOLID(m)  ((m) & 0x08)
  1019. #endif
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025. /**************/
  1026. /*  Typedefs  */
  1027. /**************/
  1028.  
  1029. #ifdef NO_UID_GID
  1030. #  ifdef UID_USHORT
  1031.      typedef unsigned short  uid_t;    /* TI SysV.3 */
  1032.      typedef unsigned short  gid_t;
  1033. #  else
  1034.      typedef unsigned int    uid_t;    /* SCO Xenix */
  1035.      typedef unsigned int    gid_t;
  1036. #  endif
  1037. #endif
  1038.  
  1039. #if (defined(WIN32) || defined(sgi) || defined(BSD4_4) || defined(ATARI))
  1040.    typedef struct utimbuf ztimbuf;
  1041. #else
  1042.    typedef struct ztimbuf {
  1043.        time_t actime;        /* new access time */
  1044.        time_t modtime;       /* new modification time */
  1045.    } ztimbuf;
  1046. #endif
  1047.  
  1048. typedef struct min_info {
  1049.     long offset;
  1050.     ulg compr_size;          /* compressed size (needed if extended header) */
  1051.     ulg crc;                 /* crc (needed if extended header) */
  1052.     int hostnum;
  1053.     unsigned file_attr;      /* local flavor, as used by creat(), chmod()... */
  1054.     unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  1055.     unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  1056.     unsigned textfile : 1;   /* file is text (according to zip) */
  1057.     unsigned textmode : 1;   /* file is to be extracted as text */
  1058.     unsigned lcflag : 1;     /* convert filename to lowercase */
  1059.     unsigned vollabel : 1;   /* "file" is an MS-DOS volume (disk) label */
  1060. } min_info;
  1061.  
  1062. typedef struct VMStimbuf {
  1063.     char *revdate;    /* (both roughly correspond to Unix modtime/st_mtime) */
  1064.     char *credate;
  1065. } VMStimbuf;
  1066.  
  1067. /*---------------------------------------------------------------------------
  1068.     Zipfile work area declarations.
  1069.   ---------------------------------------------------------------------------*/
  1070.  
  1071. #ifdef MALLOC_WORK
  1072.    union work {
  1073.      struct {                 /* unshrink(): */
  1074.        shrint *Parent;          /* (8193 * sizeof(short)) */
  1075.        uch *value;
  1076.        uch *Stack;
  1077.      } shrink;
  1078.      uch *Slide;              /* explode(), inflate(), unreduce() */
  1079.    };
  1080. #else /* !MALLOC_WORK */
  1081.    union work {
  1082.      struct {                 /* unshrink(): */
  1083.        shrint Parent[HSIZE];    /* (8192 * sizeof(short)) == 16KB minimum */
  1084.        uch value[HSIZE];        /* 8KB */
  1085.        uch Stack[HSIZE];        /* 8KB */
  1086.      } shrink;                  /* total = 32KB minimum; 80KB on Cray/Alpha */
  1087.      uch Slide[WSIZE];        /* explode(), inflate(), unreduce() */
  1088.    };
  1089. #endif /* ?MALLOC_WORK */
  1090.  
  1091. #define slide  G.area.Slide
  1092.  
  1093. #ifdef DLL
  1094. #  define redirSlide G.redirect_pointer
  1095. #else
  1096. #  define redirSlide G.area.Slide
  1097. #endif
  1098.  
  1099. /*---------------------------------------------------------------------------
  1100.     Zipfile layout declarations.  If these headers ever change, make sure the
  1101.     xxREC_SIZE defines (above) change with them!
  1102.   ---------------------------------------------------------------------------*/
  1103.  
  1104.    typedef uch   local_byte_hdr[ LREC_SIZE ];
  1105. #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  1106. #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  1107. #      define L_GENERAL_PURPOSE_BIT_FLAG        2
  1108. #      define L_COMPRESSION_METHOD              4
  1109. #      define L_LAST_MOD_FILE_TIME              6
  1110. #      define L_LAST_MOD_FILE_DATE              8
  1111. #      define L_CRC32                           10
  1112. #      define L_COMPRESSED_SIZE                 14
  1113. #      define L_UNCOMPRESSED_SIZE               18
  1114. #      define L_FILENAME_LENGTH                 22
  1115. #      define L_EXTRA_FIELD_LENGTH              24
  1116.  
  1117.    typedef uch   cdir_byte_hdr[ CREC_SIZE ];
  1118. #      define C_VERSION_MADE_BY_0               0
  1119. #      define C_VERSION_MADE_BY_1               1
  1120. #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  1121. #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  1122. #      define C_GENERAL_PURPOSE_BIT_FLAG        4
  1123. #      define C_COMPRESSION_METHOD              6
  1124. #      define C_LAST_MOD_FILE_TIME              8
  1125. #      define C_LAST_MOD_FILE_DATE              10
  1126. #      define C_CRC32                           12
  1127. #      define C_COMPRESSED_SIZE                 16
  1128. #      define C_UNCOMPRESSED_SIZE               20
  1129. #      define C_FILENAME_LENGTH                 24
  1130. #      define C_EXTRA_FIELD_LENGTH              26
  1131. #      define C_FILE_COMMENT_LENGTH             28
  1132. #      define C_DISK_NUMBER_START               30
  1133. #      define C_INTERNAL_FILE_ATTRIBUTES        32
  1134. #      define C_EXTERNAL_FILE_ATTRIBUTES        34
  1135. #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  1136.  
  1137.    typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
  1138. /*     define SIGNATURE                         0   space-holder only */
  1139. #      define NUMBER_THIS_DISK                  4
  1140. #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  1141. #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  1142. #      define TOTAL_ENTRIES_CENTRAL_DIR         10
  1143. #      define SIZE_CENTRAL_DIRECTORY            12
  1144. #      define OFFSET_START_CENTRAL_DIRECTORY    16
  1145. #      define ZIPFILE_COMMENT_LENGTH            20
  1146.  
  1147.  
  1148.    typedef struct local_file_header {                 /* LOCAL */
  1149.        uch version_needed_to_extract[2];
  1150.        ush general_purpose_bit_flag;
  1151.        ush compression_method;
  1152.        ush last_mod_file_time;
  1153.        ush last_mod_file_date;
  1154.        ulg crc32;
  1155.        ulg csize;
  1156.        ulg ucsize;
  1157.        ush filename_length;
  1158.        ush extra_field_length;
  1159.    } local_file_hdr;
  1160.  
  1161. #if 0
  1162.    typedef struct central_directory_file_header {     /* CENTRAL */
  1163.        uch version_made_by[2];
  1164.        uch version_needed_to_extract[2];
  1165.        ush general_purpose_bit_flag;
  1166.        ush compression_method;
  1167.        ush last_mod_file_time;
  1168.        ush last_mod_file_date;
  1169.        ulg crc32;
  1170.        ulg csize;
  1171.        ulg ucsize;
  1172.        ush filename_length;
  1173.        ush extra_field_length;
  1174.        ush file_comment_length;
  1175.        ush disk_number_start;
  1176.        ush internal_file_attributes;
  1177.        ulg external_file_attributes;
  1178.        ulg relative_offset_local_header;
  1179.    } cdir_file_hdr;
  1180. #endif /* 0 */
  1181.  
  1182.    typedef struct end_central_dir_record {            /* END CENTRAL */
  1183.        ush number_this_disk;
  1184.        ush num_disk_start_cdir;
  1185.        ush num_entries_centrl_dir_ths_disk;
  1186.        ush total_entries_central_dir;
  1187.        ulg size_central_directory;
  1188.        ulg offset_start_central_directory;
  1189.        ush zipfile_comment_length;
  1190.    } ecdir_rec;
  1191.  
  1192.  
  1193. /* Huffman code lookup table entry--this entry is four bytes for machines
  1194.    that have 16-bit pointers (e.g. PC's in the small or medium model).
  1195.    Valid extra bits are 0..13.  e == 15 is EOB (end of block), e == 16
  1196.    means that v is a literal, 16 < e < 32 means that v is a pointer to
  1197.    the next table, which codes e - 16 bits, and lastly e == 99 indicates
  1198.    an unused code.  If a code with e == 99 is looked up, this implies an
  1199.    error in the data. */
  1200.  
  1201. struct huft {
  1202.     uch e;                /* number of extra bits or operation */
  1203.     uch b;                /* number of bits in this code or subcode */
  1204.     union {
  1205.         ush n;            /* literal, length base, or distance base */
  1206.         struct huft *t;   /* pointer to next level of table */
  1207.     } v;
  1208. };
  1209.  
  1210.  
  1211. typedef struct _APIDocStruct {
  1212.     char *compare;
  1213.     char *function;
  1214.     char *syntax;
  1215.     char *purpose;
  1216. } APIDocStruct;
  1217.  
  1218.  
  1219.  
  1220.  
  1221. /*************/
  1222. /*  Globals  */
  1223. /*************/
  1224.  
  1225. #if (defined(OS2) && !defined(FUNZIP))
  1226. #  include "os2/os2.h"
  1227. #endif
  1228.  
  1229. /*
  1230.     no longer supported (though code is available separately)
  1231.  
  1232.     #if (defined(WINDLL) && !defined(FUNZIP))
  1233.     #  include "win16dll/windll.h"
  1234.     #endif
  1235.  */
  1236.  
  1237. #include "globals.h"
  1238.  
  1239.  
  1240.  
  1241. /*************************/
  1242. /*  Function Prototypes  */
  1243. /*************************/
  1244.  
  1245. /*---------------------------------------------------------------------------
  1246.     Functions in unzip.c (initialization routines):
  1247.   ---------------------------------------------------------------------------*/
  1248.  
  1249. /* int main                      OF((int argc, char **argv));  */
  1250. int    unzip                     OF((__GPRO__ int argc, char **argv));
  1251. int    uz_opts                   OF((__GPRO__ int *pargc, char ***pargv));
  1252. int    usage                     OF((__GPRO__ int error));
  1253.  
  1254. /*---------------------------------------------------------------------------
  1255.     Functions in process.c (main driver routines):
  1256.   ---------------------------------------------------------------------------*/
  1257.  
  1258. int      process_zipfiles        OF((__GPRO));
  1259. /* static int    do_seekable     OF((__GPRO__ int lastchance)); */
  1260. /* static int    find_ecrec      OF((__GPRO__ long searchlen)); */
  1261. int      uz_end_central          OF((__GPRO));
  1262. int      process_cdir_file_hdr   OF((__GPRO));
  1263. int      get_cdir_ent            OF((__GPRO));
  1264. int      process_local_file_hdr  OF((__GPRO));
  1265. unsigned ef_scan_for_izux        OF((uch *ef_buf, unsigned ef_len,
  1266.                                      ztimbuf *z_utim, ush *z_uidgid));
  1267.  
  1268. /*---------------------------------------------------------------------------
  1269.     Functions in zipinfo.c (`zipinfo-style' listing routines):
  1270.   ---------------------------------------------------------------------------*/
  1271.  
  1272. int      zi_opts                 OF((__GPRO__ int *pargc, char ***pargv));
  1273. int      zi_end_central          OF((__GPRO));
  1274. int      zipinfo                 OF((__GPRO));
  1275. /* static int      zi_long       OF((__GPRO__ ulg endprev)); */
  1276. /* static int      zi_short      OF((__GPRO)); */
  1277. /* static char    *zi_time       OF((__GPRO__
  1278.                                      const ush *datez, const ush *timez,
  1279.                                      const time_t *modtimez, char *d_t_str)); */
  1280.  
  1281. /*---------------------------------------------------------------------------
  1282.     Functions in list.c (generic zipfile-listing routines):
  1283.   ---------------------------------------------------------------------------*/
  1284.  
  1285. int      list_files              OF((__GPRO));
  1286. int      ratio                   OF((ulg uc, ulg c));
  1287. void     fnprint                 OF((__GPRO));
  1288.  
  1289. /*---------------------------------------------------------------------------
  1290.     Functions in fileio.c:
  1291.   ---------------------------------------------------------------------------*/
  1292.  
  1293. int      open_input_file      OF((__GPRO));
  1294. int      open_outfile         OF((__GPRO));                    /* also vms.c */
  1295. void     undefer_input        OF((__GPRO));
  1296. void     defer_leftover_input OF((__GPRO));
  1297. unsigned readbuf              OF((__GPRO__ char *buf, register unsigned len));
  1298. int      readbyte             OF((__GPRO));
  1299. int      fillinbuf            OF((__GPRO));
  1300. #ifdef FUNZIP
  1301.    int   flush                OF((__GPRO__ ulg size));  /* actually funzip.c */
  1302. #else
  1303.    int   flush                OF((__GPRO__ uch *buf, ulg size, int unshrink));
  1304. #endif
  1305. /* static int  disk_error     OF((__GPRO)); */
  1306. void     handler              OF((int signal));
  1307. time_t   dos_to_unix_time     OF((unsigned ddate, unsigned dtime));
  1308. int      check_for_newer      OF((__GPRO__ char *filename)); /* os2,vmcms,vms */
  1309. int      do_string            OF((__GPRO__ unsigned int len, int option));
  1310. ush      makeword             OF((uch *b));
  1311. ulg      makelong             OF((uch *sig));
  1312. int      zstrnicmp            OF((register const char *s1,
  1313.                                   register const char *s2,
  1314.                                   register unsigned n));
  1315. #ifdef REGULUS
  1316.    int zstat                  OF((char *p, struct stat *s));
  1317. #endif
  1318. #ifdef ZMEM   /* MUST be ifdef'd because of conflicts with the standard def. */
  1319.    zvoid *memset OF((register zvoid *, register int, register unsigned int));
  1320.    zvoid *memcpy OF((register zvoid *, register const zvoid *,
  1321.                      register unsigned int));
  1322. #endif
  1323. #ifdef SMALL_MEM
  1324.    char *fLoadFarString       OF((__GPRO__ const char Far *sz));
  1325.    char *fLoadFarStringSmall  OF((__GPRO__ const char Far *sz));
  1326.    char *fLoadFarStringSmall2 OF((__GPRO__ const char Far *sz));
  1327.    #ifndef zfstrcpy
  1328.      char Far * Far zfstrcpy  OF((char Far *s1, const char Far *s2));
  1329.    #endif
  1330. #endif
  1331.  
  1332.  
  1333. /*---------------------------------------------------------------------------
  1334.     Functions in extract.c:
  1335.   ---------------------------------------------------------------------------*/
  1336.  
  1337. int    extract_or_test_files     OF((__GPRO));
  1338. /* static int   store_info               OF((void)); */
  1339. /* static int   extract_or_test_member   OF((__GPRO)); */
  1340. /* static int   TestExtraField           OF((__GPRO__ uch *ef,
  1341.                                              unsigned ef_len)); */
  1342. /* static int   test_OS2                 OF((__GPRO__ uch *eb,
  1343.                                              unsigned eb_size)); */
  1344. int    memextract                OF((__GPRO__ uch *tgt, ulg tgtsize,
  1345.                                      uch *src, ulg srcsize));
  1346. int    memflush                  OF((__GPRO__ uch *rawbuf, ulg size));
  1347. char  *fnfilter                  OF((char *raw, uch *space));
  1348.  
  1349. /*---------------------------------------------------------------------------
  1350.     Decompression functions:
  1351.   ---------------------------------------------------------------------------*/
  1352.  
  1353. int    explode                   OF((__GPRO));                  /* explode.c */
  1354. int    huft_free                 OF((struct huft *t));          /* inflate.c */
  1355. int    huft_build                OF((__GPRO__ unsigned *b, unsigned n,
  1356.                                      unsigned s, ush *d, ush *e,
  1357.                                      struct huft **t, int *m));
  1358. #ifdef USE_ZLIB
  1359.    int    UZinflate              OF((__GPRO));                  /* inflate.c */
  1360. #  define inflate_free(x)        inflateEnd(&((struct Globals *)(&G))->dstrm)
  1361. #else
  1362.    int    inflate                OF((__GPRO));                  /* inflate.c */
  1363.    int    inflate_free           OF((__GPRO));                  /* inflate.c */
  1364. #endif /* ?USE_ZLIB */
  1365. void   unreduce                  OF((__GPRO));                 /* unreduce.c */
  1366. /* static void  LoadFollowers    OF((__GPRO__ f_array *follower, uch *Slen));
  1367.                                                                 * unreduce.c */
  1368. int    unshrink                  OF((__GPRO));                 /* unshrink.c */
  1369. /* static void  partial_clear    OF((__GPRO));                  * unshrink.c */
  1370.  
  1371. /*---------------------------------------------------------------------------
  1372.     Internal API functions (only included in DLL versions):
  1373.   ---------------------------------------------------------------------------*/
  1374.  
  1375. #ifdef DLL
  1376.    void     setFileNotFound       OF((__GPRO));                     /* api.c */
  1377.    int      unzipToMemory         OF((__GPRO__ char *zip, char *file,
  1378.                                       UzpBuffer *retstr));          /* api.c */
  1379.    int      redirect_outfile      OF((__GPRO));                     /* api.c */
  1380.    int      writeToMemory         OF((__GPRO__ uch *rawbuf, ulg size));
  1381.                                                                     /* api.c */
  1382.    /* this obsolescent entry point kept for compatibility: */
  1383.    int      UzpUnzip              OF((int argc, char **argv));/* use UzpMain */
  1384. #ifdef OS2API
  1385.    int      varmessage            OF((__GPRO__ uch *buf, ulg size));
  1386.                                                                 /* rexxapi.c */
  1387.    int      varputchar            OF((__GPRO__ int c));         /* rexxapi.c */
  1388.    int      finish_REXX_redirect  OF((__GPRO));                 /* rexxapi.c */
  1389. #endif
  1390. #ifdef API_DOC
  1391.    void     APIhelp               OF((__GPRO__ int argc, char **argv));
  1392. #endif                                                          /* apihelp.c */
  1393. /*
  1394.     no longer supported (though code is available separately)
  1395.  
  1396.     #ifdef WINDLL
  1397.        int      WINDLLMAIN            OF((struct ScFileList *pGZipFileList,
  1398.                                           int argc, char **argv));
  1399.     #endif
  1400.  */
  1401. #endif /* DLL */
  1402.  
  1403. /*---------------------------------------------------------------------------
  1404.     Acorn RISCOS-only functions:
  1405.   ---------------------------------------------------------------------------*/
  1406.  
  1407. #ifdef RISCOS
  1408.    int   isRISCOSexfield     OF((void *extra_field));             /* acorn.c */
  1409.    void  setRISCOSexfield    OF((char *path, void *extra_field)); /* acorn.c */
  1410.    void  printRISCOSexfield  OF((int isdir, void *extra_field));  /* acorn.c */
  1411. #endif
  1412.  
  1413. /*---------------------------------------------------------------------------
  1414.     Human68K-only functions:
  1415.   ---------------------------------------------------------------------------*/
  1416.  
  1417. #ifdef __human68k__
  1418.    void  InitTwentyOne       OF((void));
  1419. #endif
  1420.  
  1421. /*---------------------------------------------------------------------------
  1422.     Macintosh-only functions:
  1423.   ---------------------------------------------------------------------------*/
  1424.  
  1425. #ifdef MACOS
  1426.    int     macmkdir   OF((char *, short, long));                    /* mac.c */
  1427.    short   macopen    OF((char *, short, short, long));             /* mac.c */
  1428.    FILE   *macfopen   OF((char *, char *, short, long));            /* mac.c */
  1429.    short   maccreat   OF((char *, short, long, OSType, OSType));    /* mac.c */
  1430.    short   macread    OF((short, char *, unsigned));                /* mac.c */
  1431.    long    macwrite   OF((short, char *, unsigned));                /* mac.c */
  1432.    short   macclose   OF((short));                                  /* mac.c */
  1433.    long    maclseek   OF((short, long, short));                     /* mac.c */
  1434.    char   *macgetenv  OF((char *));                                 /* mac.c */
  1435.    char   *wfgets     OF((char *, int, FILE *));                    /* mac.c */
  1436.    void    wfprintf   OF((FILE *, char *, ...));                    /* mac.c */
  1437.    void    wprintf    OF((char *, ...));                            /* mac.c */
  1438. #endif
  1439.  
  1440. /*---------------------------------------------------------------------------
  1441.     MSDOS-only functions:
  1442.   ---------------------------------------------------------------------------*/
  1443.  
  1444. #if (defined(__GO32__) || (defined(MSDOS) && defined(__EMX__)))
  1445.    unsigned _dos_getcountryinfo(void *);                          /* msdos.c */
  1446. #if (!defined(__DJGPP__) || (__DJGPP__ < 2))
  1447.    void _dos_setftime(int, unsigned short, unsigned short);       /* msdos.c */
  1448.    void _dos_setfileattr(char *, int);                            /* msdos.c */
  1449.    unsigned _dos_creat(char *, unsigned, int *);                  /* msdos.c */
  1450.    void _dos_getdrive(unsigned *);                                /* msdos.c */
  1451.    unsigned _dos_close(int);                                      /* msdos.c */
  1452. #endif /* !__DJGPP__ || (__DJGPP__ < 2) */
  1453. #endif
  1454.  
  1455. /*---------------------------------------------------------------------------
  1456.     OS/2-only functions:
  1457.   ---------------------------------------------------------------------------*/
  1458.  
  1459. #ifdef OS2  /* GetFileTime conflicts with something in Win32 header files */
  1460. #  if (defined(REENTRANT) && defined(USETHREADID))
  1461.    ulg   GetThreadId      OF((void));
  1462. #  endif
  1463.    int   GetCountryInfo   OF((void));                               /* os2.c */
  1464.    long  GetFileTime      OF((char *name));                         /* os2.c */
  1465. /* static void  SetPathInfo  OF((char *path, ush moddate, ush modtime,
  1466.                                  int flags));                          os2.c */
  1467. /* static int   SetEAs       OF((__GPRO__ char *path, void *eablock)); os2.c */
  1468. /* static int   IsFileNameValid OF((char *name));                      os2.c */
  1469. /* static void  map2fat         OF((char *pathcomp, char **pEndFAT));  os2.c */
  1470. /* static int   SetLongNameEA   OF((char *name, char *longname));      os2.c */
  1471. /* static void  InitNLS         OF((void));                            os2.c */
  1472.    int   IsUpperNLS       OF((int nChr));                           /* os2.c */
  1473.    int   ToLowerNLS       OF((int nChr));                           /* os2.c */
  1474.    void  DebugMalloc      OF((void));                               /* os2.c */
  1475. #endif
  1476.  
  1477. /*---------------------------------------------------------------------------
  1478.     TOPS20-only functions:
  1479.   ---------------------------------------------------------------------------*/
  1480.  
  1481. #ifdef TOPS20
  1482.    int upper               OF((char *s));                        /* tops20.c */
  1483.    int enquote             OF((char *s));                        /* tops20.c */
  1484.    int dequote             OF((char *s));                        /* tops20.c */
  1485.    int fnlegal             OF(());  /* error if prototyped(?) */ /* tops20.c */
  1486. #endif
  1487.  
  1488. /*---------------------------------------------------------------------------
  1489.     VM/CMS- and MVS-only functions:
  1490.   ---------------------------------------------------------------------------*/
  1491.  
  1492. #ifdef CMS_MVS
  1493.    FILE  *vmmvs_open_infile  OF((__GPRO));                        /* vmmvs.c */
  1494.    extent getVMMVSexfield    OF((char *type, uch *ef_block, unsigned datalen));
  1495. #endif
  1496.  
  1497. /*---------------------------------------------------------------------------
  1498.     VMS-only functions:
  1499.   ---------------------------------------------------------------------------*/
  1500.  
  1501. #ifdef VMS
  1502.    int    check_format        OF((__GPRO));                         /* vms.c */
  1503.    int    find_vms_attrs      OF((__GPRO));                         /* vms.c */
  1504. /* int    open_outfile        OF((__GPRO));           * (see fileio.c) vms.c */
  1505. /* int    flush               OF((__GPRO__ uch *rawbuf, unsigned size,
  1506.                                   int final_flag));   * (see fileio.c) vms.c */
  1507. #ifdef RETURN_CODES
  1508.    void   return_VMS          OF((__GPRO__ int zip_error));         /* vms.c */
  1509. #else
  1510.    void   return_VMS          OF((int zip_error));                  /* vms.c */
  1511. #endif
  1512. #ifdef VMSCLI
  1513.    ulg    vms_unzip_cmdline   OF((int *, char ***));            /* cmdline.c */
  1514. #endif
  1515. #endif
  1516.  
  1517. /*---------------------------------------------------------------------------
  1518.     Miscellaneous/shared functions:
  1519.   ---------------------------------------------------------------------------*/
  1520.  
  1521. struct Globals *globalsCtor  OF((void));                        /* globals.c */
  1522.  
  1523. void     envargs         OF((__GPRO__ int *Pargc, char ***Pargv,
  1524.                              char *envstr, char *envstr2));     /* envargs.c */
  1525. void     mksargs         OF((int *argcp, char ***argvp));       /* envargs.c */
  1526.  
  1527. int      match           OF((char *s, char *p, int ic));          /* match.c */
  1528. int      iswild          OF((char *p));                           /* match.c */
  1529.  
  1530. #ifndef USE_ZLIB
  1531.    ulg near *get_crc_table  OF((void));                /* funzip.c, crctab.c */
  1532.    ulg      crc32           OF((ulg crc, const uch *buf,
  1533.                                 extent len));       /* AS source, or crc32.c */
  1534. #endif /* !USE_ZLIB */
  1535.  
  1536. int      dateformat      OF((void));              /* currently, only msdos.c */
  1537. void     version         OF((__GPRO));                              /* local */
  1538. int      mapattr         OF((__GPRO));                              /* local */
  1539. int      mapname         OF((__GPRO__ int renamed));                /* local */
  1540. int      checkdir        OF((__GPRO__ char *pathcomp, int flag));   /* local */
  1541. char    *do_wild         OF((__GPRO__ char *wildzipfn));            /* local */
  1542. char    *GetLoadPath     OF((__GPRO));                              /* local */
  1543. #if (defined(MORE) && (defined(UNIX) || defined(VMS)))
  1544.    int screenlines       OF((void));                                /* local */
  1545. #endif
  1546. #ifndef MTS /* macro in MTS */
  1547.    void  close_outfile   OF((__GPRO));                              /* local */
  1548. #endif
  1549. #ifdef SYSTEM_SPECIFIC_CTOR
  1550.    void  SYSTEM_SPECIFIC_CTOR   OF((__GPRO));                       /* local */
  1551. #endif
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557. /************/
  1558. /*  Macros  */
  1559. /************/
  1560.  
  1561. #ifndef MAX
  1562. #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  1563. #endif
  1564. #ifndef MIN
  1565. #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  1566. #endif
  1567.  
  1568. #ifdef DEBUG
  1569. #  define Trace(x)   fprintf x
  1570. #else
  1571. #  define Trace(x)
  1572. #endif
  1573.  
  1574. #ifdef DEBUG_TIME
  1575. #  define TTrace(x)  fprintf x
  1576. #else
  1577. #  define TTrace(x)
  1578. #endif
  1579.  
  1580. #ifdef NO_DEBUG_IN_MACROS
  1581. #  define MTrace(x)
  1582. #else
  1583. #  define MTrace(x)  Trace(x)
  1584. #endif
  1585.  
  1586. #if (defined(UNIX) || defined(T20_VMS)) /* generally old systems */
  1587. #  define ToLower(x)   ((char)(isupper((int)x)? tolower((int)x) : x))
  1588. #else
  1589. #  define ToLower      tolower          /* assumed "smart"; used in match() */
  1590. #endif
  1591.  
  1592. #ifdef USE_STRM_INPUT
  1593.    /* ``Replace'' the unbuffered UNIX style I/O function with similar
  1594.     * standard C functions from <stdio.h>.
  1595.     */
  1596. #  define read(fd,buf,n) fread((buf),1,(n),(FILE *)(fd))
  1597. #  define lseek(fd,o,w) fseek((FILE *)(fd),(o),(w))
  1598. #  define close(fd) fclose((FILE *)(fd))
  1599. #endif /* USE_STRM_INPUT */
  1600.  
  1601. /* The return value of the Info() "macro function" is never checked in
  1602.  * UnZip. Otherwise, to get the same behaviour as for (*G.message)(), the
  1603.  * Info() definition for "FUNZIP" would have to be corrected:
  1604.  * #define Info(buf,flag,sprf_arg) \
  1605.  *      (fprintf((flag)&1? stderr : stdout, \
  1606.  *               (char *)(sprintf sprf_arg, (buf))) == EOF)
  1607.  */
  1608. #ifndef Info   /* may already have been defined for redirection */
  1609. #  ifdef FUNZIP
  1610. #    define Info(buf,flag,sprf_arg) \
  1611.      fprintf((flag)&1? stderr : stdout, (char *)(sprintf sprf_arg, (buf)))
  1612. #  else
  1613. #    ifdef INT_SPRINTF  /* optimized version for "int sprintf()" flavour */
  1614. #      define Info(buf,flag,sprf_arg) \
  1615.        (*G.message)((zvoid *)&G, (uch *)(buf), (ulg)sprintf sprf_arg, (flag))
  1616. #    else          /* generic version, does not use sprintf() return value */
  1617. #      define Info(buf,flag,sprf_arg) \
  1618.        (*G.message)((zvoid *)&G, (uch *)(buf), \
  1619.                      (ulg)(sprintf sprf_arg, strlen((char *)(buf))), (flag))
  1620. #    endif
  1621. #  endif
  1622. #endif /* !Info */
  1623.  
  1624. #ifndef FUNZIP   /* used only in inflate.c */
  1625. #  define MESSAGE(str,len,flag)  (*G.message)((zvoid *)&G,(str),(len),(flag))
  1626. #endif
  1627.  
  1628. #if 0            /* Optimization: use the (const) result of crc32(0L,NULL,0) */
  1629. #  define CRCVAL_INITIAL  crc32(0L, NULL, 0)
  1630. #else
  1631. #  define CRCVAL_INITIAL  0L
  1632. #endif
  1633.  
  1634. /*
  1635.  *  Seek to the block boundary of the block which includes abs_offset,
  1636.  *  then read block into input buffer and set pointers appropriately.
  1637.  *  If block is already in the buffer, just set the pointers.  This macro
  1638.  *  is used by uz_end_central (process.c), zi_end_central (zipinfo.c) and
  1639.  *  do_string (fileio.c).  A slightly modified version is embedded within
  1640.  *  extract_or_test_files (extract.c).  readbyte() and readbuf() (fileio.c)
  1641.  *  are compatible.  NOTE THAT abs_offset is intended to be the "proper off-
  1642.  *  set" (i.e., if there were no extra bytes prepended); cur_zipfile_bufstart
  1643.  *  contains the corrected offset.
  1644.  *
  1645.  *  Since ZLSEEK is never used during decompression, it is safe to use the
  1646.  *  slide[] buffer for the error message.
  1647.  *
  1648.  *  The awkward "%cbs_offset" construct is provided for the obnoxious Solaris
  1649.  *  compiler, which wants to do macro substitution inside strings.
  1650.  */
  1651.  
  1652. #ifndef ZLSEEK
  1653. #  ifdef USE_STRM_INPUT
  1654. #    define _ZLS_RELOAD(abs_offset) {\
  1655.          MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
  1656.            'a', (abs_offset), G.extra_bytes));\
  1657.          fseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
  1658.          G.cur_zipfile_bufstart = ftell(G.zipfd);\
  1659.          MTrace((stderr,\
  1660.            "       request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
  1661.            request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
  1662.          MTrace((stderr, "       bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
  1663.            bufstart, G.cur_zipfile_bufstart));\
  1664.          if ((G.incnt = fread((char *)G.inbuf,1,INBUFSIZ,G.zipfd)) <= 0)\
  1665.              return(PK_EOF);\
  1666.          G.inptr = G.inbuf + (int)inbuf_offset;\
  1667.          G.incnt -= (int)inbuf_offset;\
  1668.      }
  1669. #  else /* !USE_STRM_INPUT */
  1670. #    define _ZLS_RELOAD(abs_offset) {\
  1671.          MTrace((stderr, "ZLSEEK: %cbs_offset = %ld, G.extra_bytes = %ld\n",\
  1672.            'a', (abs_offset), G.extra_bytes));\
  1673.          G.cur_zipfile_bufstart = lseek(G.zipfd,(LONGINT)bufstart,SEEK_SET);\
  1674.          MTrace((stderr,\
  1675.            "       request = %ld, (abs+extra) = %ld, inbuf_offset = %ld\n",\
  1676.            request, ((abs_offset)+G.extra_bytes), inbuf_offset));\
  1677.          MTrace((stderr, "       bufstart = %ld, cur_zipfile_bufstart = %ld\n",\
  1678.            bufstart, G.cur_zipfile_bufstart));\
  1679.          if ((G.incnt = read(G.zipfd,(char *)G.inbuf,INBUFSIZ)) <= 0)\
  1680.              return(PK_EOF);\
  1681.          G.inptr = G.inbuf + (int)inbuf_offset;\
  1682.          G.incnt -= (int)inbuf_offset;\
  1683.      }
  1684. #  endif /* ?USE_STRM_INPUT */
  1685.  
  1686. #  define ZLSEEK(abs_offset) {\
  1687.        LONGINT request = (abs_offset) + G.extra_bytes;\
  1688.        LONGINT inbuf_offset = request % INBUFSIZ;\
  1689.        LONGINT bufstart = request - inbuf_offset;\
  1690. \
  1691.        if (request < 0) {\
  1692.            Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),\
  1693.              LoadFarString(ReportMsg)));\
  1694.            return(PK_BADERR);\
  1695.        } else if (bufstart != G.cur_zipfile_bufstart)\
  1696.            _ZLS_RELOAD(abs_offset)\
  1697.        else {\
  1698.            G.incnt += (G.inptr-G.inbuf) - (int)inbuf_offset;\
  1699.            G.inptr = G.inbuf + (int)inbuf_offset;\
  1700.        }\
  1701.    }
  1702. #endif /* !ZLSEEK */
  1703.  
  1704. #define SKIP_(length) if(length&&((error=do_string(__G__ length,SKIP))!=0))\
  1705.   {error_in_archive=error; if(error>1) return error;}
  1706.  
  1707. /*
  1708.  *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  1709.  *  and unzip.c in several functions.
  1710.  *
  1711.  *  macro SKIP_(length)
  1712.  *      ush length;
  1713.  *  {
  1714.  *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  1715.  *          error_in_archive = error;   /-* might be warning *-/
  1716.  *          if (error > 1)              /-* fatal *-/
  1717.  *              return (error);
  1718.  *      }
  1719.  *  }
  1720.  *
  1721.  */
  1722.  
  1723.  
  1724. #ifdef FUNZIP
  1725. #  define FLUSH(w)  flush(__G__ (ulg)(w))
  1726. #  define NEXTBYTE  getc(G.in)   /* redefined in crypt.h if full version */
  1727. #else
  1728. #  define FLUSH(w)  if (G.mem_mode) memflush(__G__ redirSlide,(ulg)(w)); \
  1729.      else flush(__G__ redirSlide,(ulg)(w),0)
  1730. #  define NEXTBYTE  (--G.incnt >= 0 ? (int)(*G.inptr++) : readbyte(__G))
  1731. #endif
  1732.  
  1733.  
  1734. #define READBITS(nbits,zdest) {if(nbits>G.bits_left) {int temp; G.zipeof=1;\
  1735.   while (G.bits_left<=8*(sizeof(G.bitbuf)-1) && (temp=NEXTBYTE)!=EOF) {\
  1736.   G.bitbuf|=(ulg)temp<<G.bits_left; G.bits_left+=8; G.zipeof=0;}}\
  1737.   zdest=(shrint)((ush)G.bitbuf&mask_bits[nbits]);G.bitbuf>>=nbits;\
  1738.   G.bits_left-=nbits;}
  1739.  
  1740. /*
  1741.  * macro READBITS(nbits,zdest)    * only used by unreduce and unshrink *
  1742.  *  {
  1743.  *      if (nbits > G.bits_left) {  * fill G.bitbuf, 8*sizeof(ulg) bits *
  1744.  *          int temp;
  1745.  *
  1746.  *          G.zipeof = 1;
  1747.  *          while (G.bits_left <= 8*(sizeof(G.bitbuf)-1) &&
  1748.  *                 (temp = NEXTBYTE) != EOF) {
  1749.  *              G.bitbuf |= (ulg)temp << G.bits_left;
  1750.  *              G.bits_left += 8;
  1751.  *              G.zipeof = 0;
  1752.  *          }
  1753.  *      }
  1754.  *      zdest = (shrint)((ush)G.bitbuf & mask_bits[nbits]);
  1755.  *      G.bitbuf >>= nbits;
  1756.  *      G.bits_left -= nbits;
  1757.  *  }
  1758.  *
  1759.  */
  1760.  
  1761.  
  1762. /* GRR:  should change name to STRLOWER and use StringLower if possible */
  1763.  
  1764. /*
  1765.  *  Copy the zero-terminated string in str1 into str2, converting any
  1766.  *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1767.  *  as well, of course.  str1 and str2 may be the same character array.
  1768.  */
  1769. #ifdef __human68k__
  1770. #  define TOLOWER(str1, str2) \
  1771.    { \
  1772.        char *p=(str1), *q=(str2); \
  1773.        uch c; \
  1774.        while ((c = *p++) != '\0') { \
  1775.            if (iskanji(c)) { \
  1776.                if (*p == '\0') \
  1777.                    break; \
  1778.                *q++ = c; \
  1779.                *q++ = *p++; \
  1780.            } else \
  1781.                *q++ = isupper(c) ? tolower(c) : c; \
  1782.        } \
  1783.        *q = '\0'; \
  1784.    }
  1785. #else
  1786. #  define TOLOWER(str1, str2) \
  1787.    { \
  1788.        char  *p, *q; \
  1789.        p = (str1) - 1; \
  1790.        q = (str2); \
  1791.        while (*++p) \
  1792.            *q++ = (char)(isupper((int)(*p))? tolower((int)(*p)) : *p); \
  1793.        *q = '\0'; \
  1794.    }
  1795. #endif
  1796. /*
  1797.  *  NOTES:  This macro makes no assumptions about the characteristics of
  1798.  *    the tolower() function or macro (beyond its existence), nor does it
  1799.  *    make assumptions about the structure of the character set (i.e., it
  1800.  *    should work on EBCDIC machines, too).  The fact that either or both
  1801.  *    of isupper() and tolower() may be macros has been taken into account;
  1802.  *    watch out for "side effects" (in the C sense) when modifying this
  1803.  *    macro.
  1804.  */
  1805.  
  1806.  
  1807. #ifndef native
  1808. #  define native(c)   (c)
  1809. #  define A_TO_N(str1)
  1810. #else
  1811. #  ifndef NATIVE
  1812. #    define NATIVE     "native chars"
  1813. #  endif
  1814. #  define A_TO_N(str1) {register uch *p;\
  1815.      for (p=str1; *p; p++) *p=native(*p);}
  1816. #endif
  1817. /*
  1818.  *  Translate the zero-terminated string in str1 from ASCII to the native
  1819.  *  character set. The translation is performed in-place and uses the
  1820.  *  "native" macro to translate each character.
  1821.  *
  1822.  *  NOTE:  Using the "native" macro means that is it the only part of unzip
  1823.  *    which knows which translation table (if any) is actually in use to
  1824.  *    produce the native character set.  This makes adding new character set
  1825.  *    translation tables easy, insofar as all that is needed is an appropriate
  1826.  *    "native" macro definition and the translation table itself.  Currently,
  1827.  *    the only non-ASCII native character set implemented is EBCDIC, but this
  1828.  *    may not always be so.
  1829.  */
  1830.  
  1831.  
  1832.  
  1833.  
  1834. /**********************/
  1835. /*  Global constants  */
  1836. /**********************/
  1837.  
  1838.    extern ush near  mask_bits[];
  1839.    extern char     *fnames[2];
  1840.  
  1841. #ifdef EBCDIC
  1842.    extern const uch ebcdic[];
  1843. #endif
  1844.  
  1845.    extern char Far  CentSigMsg[];
  1846.    extern char Far  EndSigMsg[];
  1847.    extern char Far  SeekMsg[];
  1848.    extern char Far  FilenameNotMatched[];
  1849.    extern char Far  ExclFilenameNotMatched[];
  1850.    extern char Far  ReportMsg[];
  1851.  
  1852. #ifndef SFX
  1853.    extern char Far  CompiledWith[];
  1854. #endif /* !SFX */
  1855.  
  1856.  
  1857.  
  1858. /***********************************/
  1859. /*  Global (shared?) RTL variables */
  1860. /***********************************/
  1861.  
  1862. #ifdef DECLARE_ERRNO
  1863.    extern int       errno;
  1864. #endif
  1865.  
  1866.  
  1867. #endif /* !__unzpriv_h */
  1868.