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