home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip532.zip / unzip.h < prev    next >
C/C++ Source or Header  |  1997-10-18  |  18KB  |  569 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   unzip.h (new)
  4.  
  5.   This header file contains the public macros and typedefs required by
  6.   both the UnZip sources and by any application using the UnZip API.  If
  7.   UNZIP_INTERNAL is defined, it includes unzpriv.h (containing includes,
  8.   prototypes and extern variables used by the actual UnZip sources).
  9.  
  10.   ---------------------------------------------------------------------------*/
  11.  
  12.  
  13. #ifndef __unzip_h   /* prevent multiple inclusions */
  14. #define __unzip_h
  15.  
  16.  
  17. /*---------------------------------------------------------------------------
  18.     Predefined, machine-specific macros.
  19.   ---------------------------------------------------------------------------*/
  20.  
  21. #ifdef POCKET_UNZIP             /* WinCE port */
  22. #  include "wince/punzip.h"     /* must appear before windows.h */
  23. #endif
  24.  
  25. #ifdef WINDLL
  26. #  include <windows.h>
  27. #endif
  28.  
  29. #ifdef __GO32__                 /* MS-DOS extender:  NOT Unix */
  30. #  ifdef unix
  31. #    undef unix
  32. #  endif
  33. #  ifdef __unix
  34. #    undef __unix
  35. #  endif
  36. #  ifdef __unix__
  37. #    undef __unix__
  38. #  endif
  39. #endif
  40.  
  41. #if ((defined(__convex__) || defined(__convexc__)) && !defined(CONVEX))
  42. #  define CONVEX
  43. #endif
  44.  
  45. #if (defined(unix) || defined(__unix) || defined(__unix__))
  46. #  ifndef UNIX
  47. #    define UNIX
  48. #  endif
  49. #endif /* unix || __unix || __unix__ */
  50. #if (defined(M_XENIX) || defined(COHERENT) || defined(__hpux))
  51. #  ifndef UNIX
  52. #    define UNIX
  53. #  endif
  54. #endif /* M_XENIX || COHERENT || __hpux */
  55. #if (defined(CONVEX) || defined(MINIX) || defined(_AIX) || defined(__QNX__))
  56. #  ifndef UNIX
  57. #    define UNIX
  58. #  endif
  59. #endif /* CONVEX || MINIX || _AIX || __QNX__ */
  60.  
  61. #if (defined(VM_CMS) || defined(MVS))
  62. #  define CMS_MVS
  63. #endif
  64.  
  65. #if (defined(__OS2__) && !defined(OS2))
  66. #  define OS2
  67. #endif
  68.  
  69. #if (defined(__TANDEM) && !defined(TANDEM))
  70. #  define TANDEM
  71. #endif
  72.  
  73. #if (defined(__VMS) && !defined(VMS))
  74. #  define VMS
  75. #endif
  76.  
  77. #if (defined(__WIN32__) && !defined(WIN32))
  78. #  define WIN32
  79. #endif
  80.  
  81. #ifdef __COMPILER_KCC__
  82. #  include <c-env.h>
  83. #  ifdef SYS_T20
  84. #    define TOPS20
  85. #  endif
  86. #endif /* __COMPILER_KCC__ */
  87.  
  88. /* Borland C does not define __TURBOC__ if compiling for a 32-bit platform */
  89. #ifdef __BORLANDC__
  90. #  ifndef __TURBOC__
  91. #    define __TURBOC__
  92. #  endif
  93. #  if (!defined(__MSDOS__) && !defined(OS2) && !defined(WIN32))
  94. #    define __MSDOS__
  95. #  endif
  96. #endif
  97.  
  98. /* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C */
  99. #ifdef __POWERC
  100. #  define __TURBOC__
  101. #  define MSDOS
  102. #endif /* __POWERC */
  103.  
  104. #if (defined(__MSDOS__) && !defined(MSDOS))   /* just to make sure */
  105. #  define MSDOS
  106. #endif
  107.  
  108. #if (defined(linux) && !defined(LINUX))
  109. #  define LINUX
  110. #endif
  111.  
  112. #ifdef __riscos
  113. #  define RISCOS
  114. #endif
  115.  
  116. #if (defined(THINK_C) || defined(MPW))
  117. #  define MACOS
  118. #endif
  119. #if (defined(__MWERKS__) && defined(macintosh))
  120. #  define MACOS
  121. #endif
  122.  
  123. /* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C, or
  124.  * Silicon Graphics, or Convex?, or IBM C Set/2, or GNU gcc/emx, or Watcom C,
  125.  * or Macintosh, or Windows NT, or Sequent, or Atari or IBM RS/6000.
  126.  */
  127. #if (defined(__STDC__) || defined(MSDOS) || defined(WIN32) || defined(__EMX__))
  128. #  ifndef PROTO
  129. #    define PROTO
  130. #  endif
  131. #  ifndef MODERN
  132. #    define MODERN
  133. #  endif
  134. #endif
  135. #if (defined(__IBMC__) || defined(__BORLANDC__) || defined(__WATCOMC__))
  136. #  ifndef PROTO
  137. #    define PROTO
  138. #  endif
  139. #  ifndef MODERN
  140. #    define MODERN
  141. #  endif
  142. #endif
  143. #if (defined(MACOS) || defined(ATARI_ST) || defined(RISCOS))
  144. #  ifndef PROTO
  145. #    define PROTO
  146. #  endif
  147. #  ifndef MODERN
  148. #    define MODERN
  149. #  endif
  150. #endif
  151. /* Sequent running Dynix/ptx:  non-modern compiler */
  152. #if (defined(_AIX) || defined(sgi) || (defined(_SEQUENT_) && !defined(PTX)))
  153. #  ifndef PROTO
  154. #    define PROTO
  155. #  endif
  156. #  ifndef MODERN
  157. #    define MODERN
  158. #  endif
  159. #endif
  160. #if (defined(CMS_MVS) || defined(__BEOS__))  /* || defined(CONVEX) */
  161. #  ifndef PROTO
  162. #    define PROTO
  163. #  endif
  164. #  ifndef MODERN
  165. #    define MODERN
  166. #  endif
  167. #endif
  168. #if defined(__BEOS__) && defined(__GNUC__)  /* brain damage for our GCC port */
  169. #  define __USE_FIXED_PROTOTYPES__
  170. #endif
  171.  
  172. /* turn off prototypes if requested */
  173. #if (defined(NOPROTO) && defined(PROTO))
  174. #  undef PROTO
  175. #endif
  176.  
  177. /* used to remove arguments in function prototypes for non-ANSI C */
  178. #ifdef PROTO
  179. #  define OF(a) a
  180. #else
  181. #  define OF(a) ()
  182. #endif
  183.  
  184. /* enable the "const" keyword only if MODERN and if not otherwise instructed */
  185. #ifdef MODERN
  186. #  if (!defined(ZCONST) && (defined(USE_CONST) || !defined(NO_CONST)))
  187. #    define ZCONST const
  188. #  endif
  189. #endif
  190.  
  191. #ifndef ZCONST
  192. #  define ZCONST
  193. #endif
  194.  
  195. /* bad or (occasionally?) missing stddef.h: */
  196. #if (defined(M_XENIX) || defined(DNIX))
  197. #  define NO_STDDEF_H
  198. #endif
  199.  
  200. #if (defined(M_XENIX) && !defined(M_UNIX))   /* SCO Xenix only, not SCO Unix */
  201. #  define SCO_XENIX
  202. #  define NO_LIMITS_H        /* no limits.h, but MODERN defined */
  203. #  define NO_UID_GID         /* no uid_t/gid_t */
  204. #  define size_t int
  205. #endif
  206.  
  207. #ifdef realix   /* Modcomp Real/IX, real-time SysV.3 variant */
  208. #  define SYSV
  209. #  define NO_UID_GID         /* no uid_t/gid_t */
  210. #endif
  211.  
  212. #if (defined(_AIX) && !defined(_ALL_SOURCE))
  213. #  define _ALL_SOURCE
  214. #endif
  215.  
  216. #if defined(apollo)          /* defines __STDC__ */
  217. #    define NO_STDLIB_H
  218. #endif
  219.  
  220. #ifdef DNIX
  221. #  define SYSV
  222. #  define SHORT_NAMES         /* 14-char limitation on path components */
  223. /* #  define FILENAME_MAX  14 */
  224. #  define FILENAME_MAX  NAME_MAX    /* GRR:  experiment */
  225. #endif
  226.  
  227. #if (defined(SYSTEM_FIVE) || defined(__SYSTEM_FIVE))
  228. #  ifndef SYSV
  229. #    define SYSV
  230. #  endif
  231. #endif /* SYSTEM_FIVE || __SYSTEM_FIVE */
  232. #if (defined(M_SYSV) || defined(M_SYS5))
  233. #  ifndef SYSV
  234. #    define SYSV
  235. #  endif
  236. #endif /* M_SYSV || M_SYS5 */
  237. /* __SVR4 and __svr4__ catch Solaris on at least some combos of compiler+OS */
  238. #if (defined(__SVR4) || defined(__svr4__) || defined(sgi) || defined(__hpux))
  239. #  ifndef SYSV
  240. #    define SYSV
  241. #  endif
  242. #endif /* __SVR4 || __svr4__ || sgi || __hpux */
  243. #if (defined(LINUX) || defined(__QNX__))
  244. #  ifndef SYSV
  245. #    define SYSV
  246. #  endif
  247. #endif /* LINUX || __QNX__ */
  248.  
  249. #if (defined(ultrix) || defined(__ultrix) || defined(bsd4_2))
  250. #  if (!defined(BSD) && !defined(SYSV))
  251. #    define BSD
  252. #  endif
  253. #endif /* ultrix || __ultrix || bsd4_2 */
  254. #if (defined(sun) || defined(pyr) || defined(CONVEX))
  255. #  if (!defined(BSD) && !defined(SYSV))
  256. #    define BSD
  257. #  endif
  258. #endif /* sun || pyr || CONVEX */
  259.  
  260. #ifdef pyr  /* Pyramid:  has BSD and AT&T "universes" */
  261. #  ifdef BSD
  262. #    define pyr_bsd
  263. #    define USE_STRINGS_H  /* instead of more common string.h */
  264. #    define ZMEM           /* ZMEM now uses bcopy/bzero: not in AT&T universe */
  265. #  endif                   /* (AT&T memcpy claimed to be very slow, though) */
  266. #  define DECLARE_ERRNO
  267. #endif /* pyr */
  268.  
  269. /* stat() bug for Borland, VAX C (also GNU?), and Atari ST MiNT on TOS
  270.  * filesystems:  returns 0 for wildcards!  (returns 0xffffffff on Minix
  271.  * filesystem or `U:' drive under Atari MiNT.)  Watcom C was previously
  272.  * included on this list; it would be good to know what version the problem
  273.  * was fixed at, if it did exist.  Watcom 10.6 has a separate stat() problem:
  274.  * it fails on "." when the current directory is a root.  This is covered by
  275.  * giving it a separate definition of SSTAT in OS-specific header files. */
  276. #if (defined(__TURBOC__) || defined(VMS) || defined(__MINT__))
  277. #  define WILD_STAT_BUG
  278. #endif
  279.  
  280. #ifdef WILD_STAT_BUG
  281. #  define SSTAT(path,pbuf) (iswild(path) || stat(path,pbuf))
  282. #else
  283. #  define SSTAT stat
  284. #endif
  285.  
  286. #ifdef REGULUS  /* returns the inode number on success(!)...argh argh argh */
  287. #  define stat(p,s) zstat(p,s)
  288. #endif
  289.  
  290. #define STRNICMP zstrnicmp
  291.  
  292. #define UzpMatch match
  293.  
  294.  
  295. /*---------------------------------------------------------------------------
  296.     OS-dependent includes
  297.   ---------------------------------------------------------------------------*/
  298.  
  299. #ifdef EFT
  300. #  define LONGINT off_t  /* Amdahl UTS nonsense ("extended file types") */
  301. #else
  302. #  define LONGINT long
  303. #endif
  304.  
  305. #ifdef MODERN
  306. #  ifndef NO_STDDEF_H
  307. #    include <stddef.h>
  308. #  endif
  309. #  ifndef NO_STDLIB_H
  310. #    include <stdlib.h>  /* standard library prototypes, malloc(), etc. */
  311. #  endif
  312.    typedef size_t extent;
  313.    typedef void zvoid;
  314. #else /* !MODERN */
  315. #  ifndef AOS_VS         /* mostly modern? */
  316. #    ifndef CMS_MVS
  317.        LONGINT lseek();
  318. #    endif
  319. #    ifdef VAXC          /* not fully modern, but does have stdlib.h and void */
  320. #      include <stdlib.h>
  321. #    else
  322.        char *malloc();
  323. #      define void int
  324. #    endif /* ?VAXC */
  325. #  endif /* !AOS_VS */
  326.    typedef unsigned int extent;
  327.    typedef char zvoid;
  328. #endif /* ?MODERN */
  329.  
  330.  
  331. /*---------------------------------------------------------------------------
  332.     Grab system-dependent definition of EXPENTRY for prototypes below.
  333.   ---------------------------------------------------------------------------*/
  334.  
  335. #if 0
  336. #if (defined(OS2) && !defined(FUNZIP))
  337. #  ifdef UNZIP_INTERNAL
  338. #    define INCL_NOPM
  339. #    define INCL_DOSNLS
  340. #    define INCL_DOSPROCESS
  341. #    define INCL_DOSDEVICES
  342. #    define INCL_DOSDEVIOCTL
  343. #    define INCL_DOSERRORS
  344. #    define INCL_DOSMISC
  345. #    ifdef OS2DLL
  346. #      define INCL_REXXSAA
  347. #      include <rexxsaa.h>
  348. #    endif
  349. #  endif /* UNZIP_INTERNAL */
  350. #  include <os2.h>
  351. #  define UZ_EXP EXPENTRY
  352. #endif /* OS2 && !FUNZIP */
  353. #endif /* 0 */
  354.  
  355. #if (defined(OS2) && !defined(FUNZIP))
  356. #  if defined(__IBMC__) || defined(__WATCOMC__)
  357. #    define UZ_EXP  _System    /* compiler keyword */
  358. #  else
  359. #    define UZ_EXP
  360. #  endif
  361. #endif /* OS2 && !FUNZIP */
  362.  
  363. #if (defined(WINDLL) || defined(USE_UNZIP_LIB))
  364. #  ifndef EXPENTRY
  365. #    define UZ_EXP WINAPI
  366. #  else
  367. #    define UZ_EXP EXPENTRY
  368. #  endif
  369. #endif
  370.  
  371. #ifndef UZ_EXP
  372. #  define UZ_EXP
  373. #endif
  374.  
  375.  
  376. /*---------------------------------------------------------------------------
  377.     Public typedefs.
  378.   ---------------------------------------------------------------------------*/
  379.  
  380. typedef unsigned char   uch;    /* code assumes unsigned bytes; these type-  */
  381. typedef unsigned short  ush;    /*  defs replace byte/UWORD/ULONG (which are */
  382. typedef unsigned long   ulg;    /*  predefined on some systems) & match zip  */
  383.  
  384. /* InputFn is not yet used and is likely to change: */
  385. #ifdef PROTO
  386.    typedef int   (UZ_EXP MsgFn)     (zvoid *pG, uch *buf, ulg size, int flag);
  387.    typedef int   (UZ_EXP InputFn)   (zvoid *pG, uch *buf, int *size, int flag);
  388.    typedef void  (UZ_EXP PauseFn)   (zvoid *pG, ZCONST char *prompt, int flag);
  389.    typedef int   (UZ_EXP PasswdFn)  (zvoid *pG, int *rcnt, char *pwbuf,
  390.                                      int size, ZCONST char *zfn,
  391.                                      ZCONST char *efn);
  392. #ifdef WINDLL
  393.    typedef int   (WINAPI ReplaceFn) (char *);
  394.    typedef void  (WINAPI SoundFn)   (void);
  395. #endif
  396. #else /* !PROTO */
  397.    typedef int   (UZ_EXP MsgFn)     ();
  398.    typedef int   (UZ_EXP InputFn)   ();
  399.    typedef void  (UZ_EXP PauseFn)   ();
  400.    typedef int   (UZ_EXP PasswdFn)  ();
  401. #ifdef WINDLL
  402.    typedef int   (WINAPI ReplaceFn) ();
  403.    typedef void  (WINAPI SoundFn)   ();
  404. #endif
  405. #endif /* ?PROTO */
  406.  
  407. typedef struct _UzpBuffer {    /* rxstr */
  408.     ulg   strlength;           /* length of string */
  409.     char  *strptr;             /* pointer to string */
  410. } UzpBuffer;
  411.  
  412. typedef struct _UzpInit {
  413.     ulg structlen;             /* length of the struct being passed */
  414.  
  415.     /* GRR: can we assume that each of these is a 32-bit pointer?  if not,
  416.      * does it matter? add "far" keyword to make sure? */
  417.     MsgFn *msgfn;
  418.     InputFn *inputfn;
  419.     PauseFn *pausefn;
  420.  
  421.     void (* UZ_EXP userfn)();  /* user init function to be called after */
  422.                                /*  globals constructed and initialized */
  423.  
  424.     /* pointer to program's environment area or something? */
  425.     /* hooks for performance testing? */
  426.     /* hooks for extra unzip -v output? (detect CPU or other hardware?) */
  427.     /* anything else?  let me (Greg) know... */
  428. } UzpInit;
  429.  
  430. /* intended to be a private struct: */
  431. typedef struct _ver {
  432.     uch major;              /* e.g., integer 5 */
  433.     uch minor;              /* e.g., 2 */
  434.     uch patchlevel;         /* e.g., 0 */
  435.     uch not_used;
  436. } _version_type;
  437.  
  438. typedef struct _UzpVer {
  439.     ulg structlen;          /* length of the struct being passed */
  440.     ulg flag;               /* bit 0: is_beta   bit 1: uses_zlib */
  441.     char *betalevel;        /* e.g., "g BETA" or "" */
  442.     char *date;             /* e.g., "4 Sep 95" (beta) or "4 September 1995" */
  443.     char *zlib_version;     /* e.g., "0.95" or NULL */
  444.     _version_type unzip;
  445.     _version_type zipinfo;
  446.     _version_type os2dll;
  447.     _version_type windll;
  448. } UzpVer;
  449.  
  450. /* for Visual BASIC access to Windows DLLs: */
  451. typedef struct _UzpVer2 {
  452.     ulg structlen;          /* length of the struct being passed */
  453.     ulg flag;               /* bit 0: is_beta   bit 1: uses_zlib */
  454.     char betalevel[10];     /* e.g., "g BETA" or "" */
  455.     char date[20];          /* e.g., "4 Sep 95" (beta) or "4 September 1995" */
  456.     char zlib_version[10];  /* e.g., "0.95" or NULL */
  457.     _version_type unzip;
  458.     _version_type zipinfo;
  459.     _version_type os2dll;
  460.     _version_type windll;
  461. } UzpVer2;
  462.  
  463. typedef struct central_directory_file_header { /* CENTRAL */
  464.     uch version_made_by[2];
  465.     uch version_needed_to_extract[2];
  466.     ush general_purpose_bit_flag;
  467.     ush compression_method;
  468.     ush last_mod_file_time;
  469.     ush last_mod_file_date;
  470.     ulg crc32;
  471.     ulg csize;
  472.     ulg ucsize;
  473.     ush filename_length;
  474.     ush extra_field_length;
  475.     ush file_comment_length;
  476.     ush disk_number_start;
  477.     ush internal_file_attributes;
  478.     ulg external_file_attributes;
  479.     ulg relative_offset_local_header;
  480. } cdir_file_hdr;
  481.  
  482.  
  483. #define UZPINIT_LEN   sizeof(UzpInit)
  484. #define UZPVER_LEN    sizeof(UzpVer)
  485. #define cbList(func)  int (* UZ_EXP func)(char *filename, cdir_file_hdr *crec)
  486.  
  487.  
  488. /*---------------------------------------------------------------------------
  489.     Return (and exit) values of the public UnZip API functions.
  490.   ---------------------------------------------------------------------------*/
  491.  
  492. /* external return codes */
  493. #define PK_OK              0   /* no error */
  494. #define PK_COOL            0   /* no error */
  495. #define PK_GNARLY          0   /* no error */
  496. #define PK_WARN            1   /* warning error */
  497. #define PK_ERR             2   /* error in zipfile */
  498. #define PK_BADERR          3   /* severe error in zipfile */
  499. #define PK_MEM             4   /* insufficient memory (during initialization) */
  500. #define PK_MEM2            5   /* insufficient memory (password failure) */
  501. #define PK_MEM3            6   /* insufficient memory (file decompression) */
  502. #define PK_MEM4            7   /* insufficient memory (memory decompression) */
  503. #define PK_MEM5            8   /* insufficient memory (not yet used) */
  504. #define PK_NOZIP           9   /* zipfile not found */
  505. #define PK_PARAM          10   /* bad or illegal parameters specified */
  506. #define PK_FIND           11   /* no files found */
  507. #define PK_DISK           50   /* disk full */
  508. #define PK_EOF            51   /* unexpected EOF */
  509.  
  510. #define IZ_CTRLC          80   /* user hit ^C to terminate */
  511. #define IZ_UNSUP          81   /* no files found: all unsup. compr/encrypt. */
  512. #define IZ_BADPWD         82   /* no files found: all had bad password */
  513.  
  514. /* internal and DLL-only return codes */
  515. #define IZ_DIR            76   /* potential zipfile is a directory */
  516. #define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  517. #define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  518. #define IZ_EF_TRUNC       79   /* local extra field truncated (PKZIP'd) */
  519.  
  520. /* return codes of password fetches (negative = user abort; positive = error) */
  521. #define IZ_PW_ENTERED      0   /* got some password string; use/try it */
  522. #define IZ_PW_CANCEL      -1   /* no password available (for this entry) */
  523. #define IZ_PW_CANCELALL   -2   /* no password, skip any further pwd. request */
  524. #define IZ_PW_ERROR        5   /* = PK_MEM2 : failure (no mem, no tty, ...) */
  525.  
  526.  
  527. /*---------------------------------------------------------------------------
  528.     Prototypes for public UnZip API (DLL) functions.
  529.   ---------------------------------------------------------------------------*/
  530.  
  531. int      UZ_EXP UzpMain            OF((int argc, char **argv));
  532. int      UZ_EXP UzpAltMain         OF((int argc, char **argv, UzpInit *init));
  533. UzpVer * UZ_EXP UzpVersion         OF((void));
  534. int      UZ_EXP UzpUnzipToMemory   OF((char *zip, char *file,
  535.                                        UzpBuffer *retstr));
  536. int      UZ_EXP UzpFileTree        OF((char *name, cbList(callBack),
  537.                                        char *cpInclude[], char *cpExclude[]));
  538.  
  539. #ifdef WINDLL
  540.    void  UZ_EXP UzpNoPrinting      OF((int));   /* turns all messages on/off */
  541. #endif
  542. void     UZ_EXP UzpVersion2        OF((UzpVer2 *version));
  543. int      UZ_EXP UzpGrep            OF((char *archive, char *file,
  544.                                        char *pattern, int cmd, int SkipBin));
  545. int      UZ_EXP UzpValidate        OF((char *archive, int AllCodes));
  546.  
  547.  
  548. /* default I/O functions (can be swapped out via UzpAltMain() entry point): */
  549.  
  550. int      UZ_EXP UzpMessagePrnt   OF((zvoid *pG, uch *buf, ulg size, int flag));
  551. int      UZ_EXP UzpMessageNull   OF((zvoid *pG, uch *buf, ulg size, int flag));
  552. int      UZ_EXP UzpInput         OF((zvoid *pG, uch *buf, int *size, int flag));
  553. void     UZ_EXP UzpMorePause     OF((zvoid *pG, ZCONST char *prompt, int flag));
  554. int      UZ_EXP UzpPassword      OF((zvoid *pG, int *rcnt, char *pwbuf,
  555.                                      int size, ZCONST char *zfn,
  556.                                      ZCONST char *efn));
  557.  
  558.  
  559. /*---------------------------------------------------------------------------
  560.     Remaining private stuff for UnZip compilation.
  561.   ---------------------------------------------------------------------------*/
  562.  
  563. #ifdef UNZIP_INTERNAL
  564. #  include "unzpriv.h"
  565. #endif
  566.  
  567.  
  568. #endif /* !__unzip_h */
  569.