home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / unzip50 / part08 < prev    next >
Encoding:
Text File  |  1992-08-22  |  58.9 KB  |  1,527 lines

  1. Newsgroups: comp.sources.misc
  2. From: zip-bugs@cs.ucla.edu (Info-ZIP group)
  3. Subject:  v31i111:  unzip50 - Info-ZIP portable UnZip, version 5.0, Part08/14
  4. Message-ID: <1992Aug24.025609.24832@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9b7db4696753d88ac9695a11405b9708
  6. Date: Mon, 24 Aug 1992 02:56:09 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: zip-bugs@cs.ucla.edu (Info-ZIP group)
  10. Posting-number: Volume 31, Issue 111
  11. Archive-name: unzip50/part08
  12. Supersedes: unzip: Volume 29, Issue 31-42
  13. Environment: UNIX, VMS, OS/2, MS-DOS, MACINTOSH, WIN-NT, LINUX, MINIX, COHERENT AMIGA?, !ATARI, symlink, SGI, DEC, Cray, Convex, Amdahl, Sun
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  funzip.c unzip.c.A zipinfo.doc
  22. # Wrapped by kent@sparky on Sun Aug 23 21:09:34 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 8 (of 14)."'
  26. if test -f 'funzip.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'funzip.c'\"
  28. else
  29.   echo shar: Extracting \"'funzip.c'\" \(11324 characters\)
  30.   sed "s/^X//" >'funzip.c' <<'END_OF_FILE'
  31. X/* funzip.c -- Not copyrighted 1992 by Mark Adler
  32. X   version 1.3, 16 August 1992 */
  33. X
  34. X
  35. X/* You can do whatever you like with this source file, though I would
  36. X   prefer that if you modify it and redistribute it that you include
  37. X   comments to that effect with your name and the date.  Thank you.
  38. X
  39. X   History:
  40. X   vers    date          who           what
  41. X   ----  ---------  --------------  ------------------------------------
  42. X    1.0  13 Aug 92  M. Adler        really simple unzip filter.
  43. X    1.1  13 Aug 92  M. Adler        cleaned up somewhat, give help if
  44. X                                    stdin not redirected, warn if more
  45. X                                    zip file entries after the first.
  46. X    1.2  15 Aug 92  M. Adler        added check of lengths for stored
  47. X                                    entries, added more help.
  48. X    1.3  16 Aug 92  M. Adler        removed redundant #define's, added
  49. X                                    decryption.
  50. X
  51. X */
  52. X
  53. X
  54. X/*
  55. X
  56. X   All funzip does is take a zip file from stdin and decompress the
  57. X   first entry to stdout.  The entry has to be either deflated or
  58. X   stored.  If the entry is encrypted, then the decryption password
  59. X   must be supplied on the command line as the first argument.
  60. X
  61. X   funzip needs to be linked with inflate.o compiled from the unzip
  62. X   source.  If decryption is desired, then it needs to be compiled
  63. X   with -DCRYPT and linked also with crypt.o.
  64. X
  65. X */
  66. X
  67. X#include "unzip.h"
  68. X
  69. X/* enforce binary i/o if recognized */
  70. X#ifdef __STDC__
  71. X#  define FOPR "rb"
  72. X#  define FOPW "w+b"
  73. X#else
  74. X#  define FOPR "r"
  75. X#  define FOPW "w+"
  76. X#endif
  77. X
  78. X/* PKZIP header definitions */
  79. X#define LOCSIG 0x04034b50L      /* four byte lead-in (lsb first) */
  80. X#define LOCFLG 6                /* offset of bit flag */
  81. X#define  CRPFLG 1               /*  bit for encrypted entry */
  82. X#define  EXTFLG 8               /*  bit for extended local header */
  83. X#define LOCHOW 8                /* offset of compression method */
  84. X#define LOCTIM 10               /* file mod time (for decryption) */
  85. X#define LOCCRC 14               /* offset of crc */
  86. X#define LOCSIZ 18               /* offset of compressed size */
  87. X#define LOCLEN 22               /* offset of uncompressed length */
  88. X#define LOCFIL 26               /* offset of file name field length */
  89. X#define LOCEXT 28               /* offset of extra field length */
  90. X#define LOCHDR 30               /* size of local header, including sig */
  91. X#define EXTHDR 16               /* size of extended local header, inc sig */
  92. X
  93. X/* Macros for getting two byte and four byte header values */
  94. X#define SH(p) ((UWORD)(byte)((p)[0]) | ((UWORD)(byte)((p)[1]) << 8))
  95. X#define LG(p) ((ULONG)(SH(p)) | ((ULONG)(SH((p)+2)) << 16))
  96. X
  97. X/* Function prototypes */
  98. XULONG updcrc OF((byte *, int));
  99. Xint inflate_entry OF((void));
  100. Xvoid err OF((int, char *));
  101. Xvoid main OF((int, char **));
  102. X
  103. X/* Globals */
  104. XFILE *in, *out;                 /* input and output files */
  105. Xunion work area;                /* inflate sliding window */
  106. Xbyte *outbuf;                   /* malloc'ed output buffer */
  107. Xbyte *outptr;                   /* points to next byte in output buffer */
  108. Xint outcnt;                     /* bytes in output buffer */
  109. XULONG outsiz;                   /* total bytes written to out */
  110. Xint decrypt;                    /* flag to turn on decryption */
  111. Xchar *key;                      /* not used--needed to link crypt.c */
  112. X
  113. X/* Masks for inflate.c */
  114. XUWORD mask_bits[] = {
  115. X    0x0000,
  116. X    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  117. X    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  118. X};
  119. X
  120. X
  121. X/* Table of CRC-32's of all single byte values (made by makecrc.c) */
  122. XULONG crc_32_tab[] = {
  123. X  0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
  124. X  0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
  125. X  0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
  126. X  0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
  127. X  0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
  128. X  0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
  129. X  0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
  130. X  0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
  131. X  0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
  132. X  0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
  133. X  0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
  134. X  0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
  135. X  0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
  136. X  0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
  137. X  0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
  138. X  0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
  139. X  0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
  140. X  0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
  141. X  0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
  142. X  0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
  143. X  0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
  144. X  0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
  145. X  0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
  146. X  0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
  147. X  0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
  148. X  0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
  149. X  0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
  150. X  0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
  151. X  0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
  152. X  0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
  153. X  0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
  154. X  0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
  155. X  0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
  156. X  0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
  157. X  0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
  158. X  0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
  159. X  0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
  160. X  0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
  161. X  0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
  162. X  0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
  163. X  0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
  164. X  0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
  165. X  0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
  166. X  0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
  167. X  0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
  168. X  0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
  169. X  0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
  170. X  0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
  171. X  0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
  172. X  0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
  173. X  0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
  174. X  0x2d02ef8dL
  175. X};
  176. X
  177. X
  178. XULONG updcrc(s, n)
  179. Xbyte *s;                /* pointer to bytes to pump through */
  180. Xint n;                  /* number of bytes in s[] */
  181. X/* Run a set of bytes through the crc shift register.  If s is a NULL
  182. X   pointer, then initialize the crc shift register contents instead.
  183. X   Return the current crc in either case. */
  184. X{
  185. X  register ULONG c;       /* temporary variable */
  186. X
  187. X  static ULONG crc = 0xffffffffL; /* shift register contents */
  188. X
  189. X  if (s == NULL)
  190. X    c = 0xffffffffL;
  191. X  else
  192. X  {
  193. X    c = crc;
  194. X    while (n--)
  195. X      c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
  196. X  }
  197. X  crc = c;
  198. X  return c ^ 0xffffffffL;       /* (instead of ~c for 64-bit machines) */
  199. X}
  200. X
  201. X
  202. Xvoid err(n, m)
  203. Xint n;
  204. Xchar *m;
  205. X/* Exit on error with a message and a code */
  206. X{
  207. X  fprintf(stderr, "funzip error: %s\n", m);
  208. X  exit(n);
  209. X}
  210. X
  211. X
  212. Xint ReadByte(b)
  213. XUWORD *b;
  214. X/* Used by inflate.c to get a byte (archaism from unzip) */
  215. X{
  216. X  register int c = getc(in);
  217. X
  218. X  if (c == EOF)
  219. X    return 0;
  220. X#ifdef CRYPT
  221. X  if (decrypt)
  222. X    update_keys(c ^= decrypt_byte());
  223. X#endif /* CRYPT */
  224. X  *b = (UWORD)c;
  225. X  return 8;
  226. X}
  227. X
  228. X
  229. Xint FlushOutput()
  230. X/* Empty output buffer */
  231. X{
  232. X  if (outcnt)
  233. X  {
  234. X    updcrc(outbuf, outcnt);
  235. X    if (fwrite(outbuf, 1, outcnt, out) != outcnt)
  236. X      err(9, "out of space on stdout");
  237. X    outsiz += outcnt;
  238. X    outptr = outbuf;
  239. X    outcnt = 0;
  240. X  }
  241. X  return 0;
  242. X}
  243. X
  244. X
  245. Xvoid main(argc, argv)
  246. Xint argc;
  247. Xchar **argv;
  248. X/* Given a zip file on stdin, decompress the first entry to stdout. */
  249. X{
  250. X  byte h[LOCHDR];               /* first local header */
  251. X
  252. X  /* if stdin not redirected, give the user help */
  253. X  if (isatty(0))
  254. X  {
  255. X    fprintf(stderr,
  256. X#ifdef CRYPT
  257. X      "usage: funzip [password] < infile.zip > outfile\n");
  258. X#else /* !CRYPT */
  259. X      "usage: funzip < infile.zip > outfile\n");
  260. X#endif /* ?CRYPT */
  261. X    fprintf(stderr,
  262. X      "       extracts to stdout the first zip entry of stdin.\n");
  263. X    exit(3);
  264. X  }
  265. X
  266. X  /* prepare to be a binary filter */
  267. X  if ((outbuf = (byte *)malloc(OUTBUFSIZ)) == NULL)
  268. X    err(1, "out of memory");
  269. X  if ((in = fdopen(0, FOPR)) == NULL)
  270. X    err(2, "cannot find stdin");
  271. X  if ((out = fdopen(1, FOPW)) == NULL)
  272. X    err(2, "cannot write to stdout");
  273. X
  274. X  /* read local header, check validity, and skip name and extra fields */
  275. X  if (fread((char *)h, 1, LOCHDR, in) != LOCHDR || LG(h) != LOCSIG)
  276. X    err(3, "input not a zip file or empty");
  277. X  if (SH(h + LOCHOW) != STORED && SH(h + LOCHOW) != DEFLATED)
  278. X    err(3, "first entry not deflated or stored--can't funzip");
  279. X  fseek(in, (long)(SH(h + LOCFIL)) + (long)(SH(h + LOCEXT)), 1);
  280. X
  281. X  /* if entry encrypted, decrypt and validate encryption header */
  282. X  if ((decrypt = h[LOCFLG] & CRPFLG) != 0)
  283. X#ifdef CRYPT
  284. X  {
  285. X    UWORD i, e;
  286. X
  287. X    if (argc < 2)
  288. X      err(3, "need password on command line for encrypted entry");
  289. X    init_keys(argv[1]);
  290. X    for (i = 0; i < 10; i++)
  291. X      ReadByte(&e);
  292. X    ReadByte(&e);
  293. X    ReadByte(&i);
  294. X    e += i << 8;
  295. X    if (e != (h[LOCFLG] & EXTFLG ? SH(h + LOCTIM) : SH(h + LOCCRC + 2)))
  296. X      err(3, "incorrect password for first entry");
  297. X  }
  298. X#else /* !CRYPT */
  299. X    err(3, "cannot decrypt entry (need to recompile funzip with crypt.c)");
  300. X#endif /* ?CRYPT */
  301. X
  302. X  /* prepare output buffer and crc */
  303. X  outptr = outbuf;
  304. X  outcnt = 0;
  305. X  outsiz = 0L;
  306. X  updcrc(NULL, 0);
  307. X
  308. X  /* decompress */
  309. X  if (h[LOCHOW])
  310. X  {                             /* deflated entry */
  311. X    if (inflate_entry())
  312. X      err(4, "invalid compressed data or out of memory");
  313. X  }
  314. X  else
  315. X  {                             /* stored entry */
  316. X    register ULONG n;
  317. X
  318. X    n = LG(h + LOCLEN);
  319. X    if (n != LG(h + LOCSIZ))
  320. X      err(4, "invalid compressed data--length mismatch");
  321. X    while (n--)
  322. X      OUTB(getc(in));
  323. X  }
  324. X  FlushOutput();
  325. X  fflush(out);
  326. X
  327. X  /* if extended header, get it */
  328. X  if ((h[LOCFLG] & EXTFLG) &&
  329. X      fread((char *)h + LOCCRC - 4, 1, EXTHDR, in) != EXTHDR)
  330. X    err(3, "zip file ended prematurely");
  331. X
  332. X  /* validate decompression */
  333. X  if (LG(h + LOCCRC) != updcrc(outbuf, 0))
  334. X    err(4, "invalid compressed data--crc error");
  335. X  if (LG(h + LOCLEN) != outsiz)
  336. X    err(4, "invalid compressed data--length error");
  337. X
  338. X  /* check if there are more entries */
  339. X  if (fread((char *)h, 1, 4, in) == 4 && LG(h) == LOCSIG)
  340. X    fprintf(stderr,
  341. X      "funzip warning: zip file has more than one entry--rest ignored\n");
  342. X}
  343. END_OF_FILE
  344.   if test 11324 -ne `wc -c <'funzip.c'`; then
  345.     echo shar: \"'funzip.c'\" unpacked with wrong size!
  346.   fi
  347.   # end of 'funzip.c'
  348. fi
  349. if test -f 'unzip.c.A' -a "${1}" != "-c" ; then 
  350.   echo shar: Will not clobber existing file \"'unzip.c.A'\"
  351. else
  352.   echo shar: Extracting \"'unzip.c.A'\" \(29228 characters\)
  353.   sed "s/^X//" >'unzip.c.A' <<'END_OF_FILE'
  354. X/*---------------------------------------------------------------------------
  355. X
  356. X  unzip.c
  357. X
  358. X  UnZip - a zipfile extraction utility.  See below for make instructions, or
  359. X  read the comments in Makefile and the various Contents files for more de-
  360. X  tailed explanations.  To report a bug, send a *complete* description to
  361. X  zip-bugs@cs.ucla.edu; include machine type, operating system and version,
  362. X  compiler and version, and reasonably detailed error messages or problem
  363. X  report.  To join Info-ZIP, send a message to info-zip-request@cs.ucla.edu.
  364. X
  365. X  UnZip 5.x is a greatly expanded and partially rewritten successor to 4.x,
  366. X  which in turn was almost a complete rewrite of version 3.x.  For a detailed
  367. X  revision history, see UnzpHist.zip at Info-ZIP headquarters (below).  For a 
  368. X  (partial) list of the many (near infinite) contributors, see "CONTRIBS" in
  369. X  the UnZip source distribution.
  370. X
  371. X  ---------------------------------------------------------------------------
  372. X
  373. X  To compile (partial instructions):
  374. X
  375. X     under Unix (cc):  make <system name>
  376. X       (type "make list" for a list of valid names, or read Makefile for 
  377. X       details.  "make unzip" works for most systems.  If you have a NEW
  378. X       system, not covered by any of the existing targets, send FULL infor-
  379. X       mation--hardware, OS, versions, etc.--to zip-bugs@cs.ucla.edu)
  380. X
  381. X     under MS-DOS (MSC, Turbo C, or Borland C++):  use the makefiles or
  382. X       project files in the MSDOS sub-archive; edit or otherwise modify
  383. X       as appropriate.  For MSC, use NMAKE.
  384. X
  385. X     under MS Windows 3.x:  get wunz12sr.{zip | zoo | whatever} and use
  386. X       the included makefile
  387. X
  388. X     under OS/2 (MSC, gcc, IBM C Set/2, Watcom C):  make -f makefile.os2
  389. X       (from OS2 sub-archive; for MSC, use NMAKE)
  390. X
  391. X     under VMS (VAX C or GNU C):  @make_unzip_vaxc  or  @make_unzip_gcc
  392. X       (from VMS sub-archive; can also use MMS or MAKE/VMS; see VMS.notes)
  393. X
  394. X     under Macintosh OS:  Double click on unzip.make.  Press <Command>-M.
  395. X       (from MAC sub-archive)
  396. X
  397. X     under Windows NT:  use makefile.nt (from NT sub-archive)
  398. X
  399. X     under AmigaDOS:  try one of the makefiles in the AMIGA sub-archive;
  400. X       may need some work yet...
  401. X
  402. X     under Atari TOS:  needs considerable work yet...
  403. X
  404. X  ---------------------------------------------------------------------------
  405. X
  406. X  Version:  unzip50.{tar.Z | zip | zoo} for Unix, VMS, OS/2, MS-DOS, Windows,
  407. X              Windows NT, Macintosh and Amiga.  Decryption requires sources
  408. X              in zcrypt19.zip, and Windows (not NT) support requires sources
  409. X              in wunz12sr.zip.  See accompanying file "Where" in the main
  410. X              source distribution for ftp, uucp and mail-server sites.
  411. X  Copyrights:  see accompanying file "COPYING" in UnZip source distribution.
  412. X
  413. X  ---------------------------------------------------------------------------*/
  414. X
  415. X
  416. X
  417. X
  418. X
  419. X#include "unzip.h"               /* includes, defines, and macros */
  420. X#ifdef MSWIN
  421. X#  include "wizunzip.h"          /* see History.500 for version history */
  422. X#endif
  423. X
  424. X#define VERSION  "v5.0 of 21 August 1992"
  425. X/* #define VERSION  "v5.0p BETA of 8-21-92" */   /* internal beta level */
  426. X#define PAKFIX   /* temporary(?) solution to PAK-created zipfiles */
  427. X
  428. X
  429. X
  430. X
  431. X
  432. X/**********************/
  433. X/*  Global Variables  */
  434. X/**********************/
  435. X
  436. Xint aflag=0;          /* -a: do ASCII to EBCDIC translation, or CR-LF  */
  437. X                      /*     to CR or LF conversion of extracted files */
  438. X/* int bflag=0; RESERVED for -b: extract as binary */
  439. Xint cflag=0;          /* -c: output to stdout */
  440. Xint fflag=0;          /* -f: "freshen" (extract only newer files) */
  441. Xint jflag=0;          /* -j: junk pathnames */
  442. Xint overwrite_none=0; /* -n: never overwrite files (no prompting) */
  443. Xint overwrite_all=0;  /* -o: OK to overwrite files without prompting */
  444. Xint force_flag=0;     /* (shares -o for now): force to override errors, etc. */
  445. Xint quietflg=0;       /* -q: produce a lot less output */
  446. X#ifdef DOS_OS2
  447. X   int sflag=1;       /* -s: allow spaces (blanks) in filenames */
  448. X#endif /* DOS_OS2 */
  449. Xint tflag=0;          /* -t: test */
  450. Xint uflag=0;          /* -u: "update" (extract only newer & brand-new files) */
  451. Xstatic int U_flag=0;  /* -U: leave filenames in upper or mixed case */
  452. Xstatic int vflag=0;   /* -v: view directory (only used in unzip.c) */
  453. Xint V_flag=0;         /* -V: don't strip VMS version numbers */
  454. X#ifdef VMS
  455. X   int secinf=0;      /* -X: keep owner/protection */
  456. X#endif /* VMS */
  457. Xint zflag=0;          /* -z: display only the archive comment */
  458. Xint process_all_files=0;
  459. X
  460. Xlongint csize;        /* used by list_files(), ReadByte(): must be signed */
  461. Xlongint ucsize;       /* used by list_files(), unReduce(), explode() */
  462. X
  463. Xchar *fnames[2] = {"*", NULL};   /* default filenames vector */
  464. Xchar **fnv = fnames;
  465. Xchar sig[5];
  466. Xchar answerbuf[10];
  467. X
  468. Xmin_info info[DIR_BLKSIZ], *pInfo=info;
  469. X
  470. X#ifdef OS2
  471. X   int longname;              /* used in extract.c, mapname.c and file_io.c */
  472. X   char longfilename[FILNAMSIZ];
  473. X#endif /* OS2 */
  474. X
  475. X#ifdef CRYPT
  476. X   char *key = (char *)NULL;  /* password with which to decrypt data, or NULL */
  477. X#endif /* CRYPT */
  478. X
  479. X/*---------------------------------------------------------------------------
  480. X    unShrink/unReduce/explode/inflate working storage and globals:
  481. X  ---------------------------------------------------------------------------*/
  482. X
  483. Xunion work area;              /* see unzip.h for the definition of work */
  484. XULONG crc32val;
  485. X
  486. XUWORD mask_bits[] = {
  487. X    0x0000,
  488. X    0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  489. X    0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  490. X};
  491. X
  492. X/*---------------------------------------------------------------------------
  493. X    Input file variables:
  494. X  ---------------------------------------------------------------------------*/
  495. X
  496. Xbyte *inbuf, *inptr;     /* input buffer (any size is legal) and pointer */
  497. Xint incnt;
  498. X
  499. XULONG bitbuf;
  500. Xint bits_left;
  501. Xboolean zipeof;
  502. X
  503. Xint zipfd;               /* zipfile file handle */
  504. X#ifdef MSWIN
  505. X   char *zipfn;
  506. X#else
  507. X   char zipfn[FILNAMSIZ];
  508. X#endif
  509. X
  510. Xchar local_hdr_sig[5] = "\120";    /* remaining signature bytes come later   */
  511. Xchar central_hdr_sig[5] = "\120";  /*  (must initialize at runtime so unzip  */
  512. Xchar end_central_sig[5] = "\120";  /*  executable won't look like a zipfile) */
  513. X/* char extd_local_sig[5] = "\120";  NOT USED YET */
  514. X
  515. Xcdir_file_hdr crec;      /* used in unzip.c, extract.c, misc.c */
  516. Xlocal_file_hdr lrec;     /* used in unzip.c, extract.c */
  517. Xecdir_rec ecrec;         /* used in unzip.c, extract.c */
  518. Xstruct stat statbuf;     /* used by main(), mapped_name(), check_for_newer() */
  519. X
  520. Xlongint extra_bytes = 0;        /* used in unzip.c, misc.c */
  521. Xlongint cur_zipfile_bufstart;   /* extract_or_test_files, readbuf, ReadByte */
  522. X  
  523. X#ifdef MACOS
  524. X   short  gnVRefNum;
  525. X   long  glDirID;
  526. X   OSType  gostCreator;
  527. X   OSType  gostType;
  528. X   boolean  fMacZipped;
  529. X   boolean  macflag;
  530. X   CursHandle  rghCursor[4];    /* status cursors */
  531. X   short  giCursor = 0;
  532. X#endif
  533. X
  534. X/*---------------------------------------------------------------------------
  535. X    Output stream variables:
  536. X  ---------------------------------------------------------------------------*/
  537. X
  538. Xbyte *outbuf;                   /* buffer for rle look-back */
  539. Xbyte *outptr;
  540. X#ifdef MSWIN
  541. X   byte __far *outout;
  542. X   char *filename;
  543. X#else /* !MSWIN */
  544. X   byte *outout;                /* scratch pad for ASCII-native trans */
  545. X   char filename[FILNAMSIZ];
  546. X#endif /* ?MSWIN */
  547. Xbyte *extra_field = (byte *)NULL;  /* used by VMS, Mac and OS/2 versions */
  548. Xlongint outpos;                 /* absolute position in outfile */
  549. Xint outcnt;                     /* current position in outbuf */
  550. Xint outfd;
  551. Xint mem_mode = 0;
  552. Xint disk_full;
  553. X
  554. X/*---------------------------------------------------------------------------
  555. X    unzip.c static global variables (visible only within this file):
  556. X  ---------------------------------------------------------------------------*/
  557. X
  558. Xstatic byte *hold;
  559. Xstatic char unkn[10];
  560. Xstatic longint ziplen;
  561. Xstatic UWORD methnum;
  562. X
  563. X/*---------------------------------------------------------------------------
  564. X    unzip.c repeated error messages (we use all of these at least twice)
  565. X  ---------------------------------------------------------------------------*/
  566. X
  567. Xchar *EndSigMsg = "\nwarning:\
  568. X  didn't find end-of-central-dir signature at end of central dir.\n";
  569. Xchar *CentSigMsg =
  570. X  "error:  expected central file header signature not found (file #%u).\n";
  571. Xchar *SeekMsg =
  572. X  "error:  attempt to seek before beginning of zipfile\n%s";
  573. X
  574. X#ifdef VMS
  575. Xchar *ReportMsg = "\
  576. X  (please check that you have transferred or created the zipfile in the\n\
  577. X  appropriate BINARY mode--this includes ftp, Kermit, AND unzip'd zipfiles)\n";
  578. X#else /* !VMS */
  579. Xchar *ReportMsg = "\
  580. X  (please check that you have transferred or created the zipfile in the\n\
  581. X  appropriate BINARY mode and that you have compiled unzip properly)\n";
  582. X#endif /* ?VMS */
  583. X
  584. X
  585. X#ifdef MSWIN
  586. X/* MS Windows Setup  and Take-Down functions bracket calls to 
  587. X * process_zipfile().
  588. X * These functions allocate and free the necessary buffers, set and clear
  589. X * any global variables so that  process_zipfile()  can be called multiple
  590. X * times in the same session of WizUnzip. You'll recognize some of the 
  591. X * code from main() in SetUpToProcessZipFile().
  592. X */
  593. XHANDLE hOutBuf;
  594. XHANDLE hOutOut;   /* added 04/03/92 for version 1.1 */
  595. XHANDLE hInBuf;
  596. XHANDLE hZipFN;
  597. XHANDLE hFileName;
  598. X
  599. XBOOL FSetUpToProcessZipFile(int ncflag, int ntflag, int nvflag, int nUflag, 
  600. X       int nzflag, int ndflag, int noflag, int naflag, int argc,
  601. X       LPSTR lpszZipFN, PSTR *FNV)
  602. X{
  603. X    /* clear all global flags -- need to or not. */
  604. X
  605. X    tflag = vflag=cflag=aflag=U_flag=quietflg=zflag = 0;
  606. X    overwrite_all=overwrite_none=0;
  607. X    fnv = &fnames[0];       /* assign default file name vector */
  608. X
  609. X    cflag = ncflag ; overwrite_all = noflag;
  610. X    tflag = ntflag ; vflag = nvflag; zflag = nzflag; U_flag = nUflag;
  611. X    aflag = naflag;
  612. X    sflag = 1;
  613. X
  614. X    local_hdr_sig[0] = central_hdr_sig[0] = end_central_sig[0] = '\120';
  615. X    local_hdr_sig[1] = central_hdr_sig[1] = end_central_sig[1] = '\0';
  616. X
  617. X    if (!(hZipFN = LocalAlloc(LMEM_MOVEABLE, FILNAMSIZ)))
  618. X        return FALSE;
  619. X
  620. X    zipfn = (char *)LocalLock(hZipFN);
  621. X    lstrcpy(zipfn, lpszZipFN);
  622. X    if (stat(zipfn, &statbuf) || (statbuf.st_mode & S_IFMT) == S_IFDIR)
  623. X        strcat(zipfn, ZSUFX);
  624. X
  625. X    if (stat(zipfn, &statbuf)) {  /* try again */
  626. X        fprintf(stderr, "error:  can't find zipfile [ %s ]\n", zipfn);
  627. X        return TRUE;              /* 9:  file not found */
  628. X    } else
  629. X        ziplen = statbuf.st_size;
  630. X
  631. X    if (argc != 0) {
  632. X        fnv = FNV;
  633. X        process_all_files = FALSE;
  634. X    } else
  635. X        process_all_files = TRUE;       /* for speed */
  636. X
  637. X/*---------------------------------------------------------------------------
  638. X    Okey dokey, we have everything we need to get started.  Let's roll.
  639. X  ---------------------------------------------------------------------------*/
  640. X
  641. X    if (hInBuf = LocalAlloc(LMEM_MOVEABLE, INBUFSIZ+4)) {  /* 4 extra: hold[] */
  642. X        inbuf = (byte *) LocalLock(hInBuf);
  643. X        WinAssert(inbuf);
  644. X    }
  645. X    if (hOutBuf = LocalAlloc(LMEM_MOVEABLE, OUTBUFSIZ+1)) {  /* extra: ASCIIZ */
  646. X        outbuf = (byte *)LocalLock(hOutBuf);
  647. X        WinAssert(outbuf);
  648. X        if (aflag) {   /* if LF => CR,LF translation */
  649. X            if (hOutOut = GlobalAlloc(GMEM_MOVEABLE,OUTBUFSIZ)) {
  650. X                outout = (byte _far *)GlobalLock(hOutOut);
  651. X                WinAssert(outout);
  652. X            }
  653. X        } else    /* no translation; just re-use output buffer */
  654. X            outout = (byte _far *)outbuf;  /*  point to outbuf */
  655. X    }
  656. X    if ( hFileName = LocalAlloc(LMEM_MOVEABLE, FILNAMSIZ)) {
  657. X        filename = (char *)LocalLock(hFileName);
  658. X        WinAssert(filename);
  659. X    }
  660. X
  661. X    if ((inbuf == NULL) || (outbuf == NULL) || (outout == NULL) ||
  662. X        (zipfn == NULL) || (filename == NULL))
  663. X        return FALSE;
  664. X
  665. X    hold = &inbuf[INBUFSIZ];   /* to check for boundary-spanning signatures */
  666. X
  667. X    return TRUE;    /* set up was OK */
  668. X}
  669. X
  670. Xvoid TakeDownFromProcessZipFile(void)
  671. X{
  672. X    if (inbuf) {
  673. X        LocalUnlock(hInBuf);
  674. X        inbuf = NULL;
  675. X    }
  676. X    if (hInBuf)
  677. X        hInBuf = LocalFree(hInBuf);
  678. X
  679. X    if (outbuf) {
  680. X        LocalUnlock(hOutBuf);
  681. X        outbuf = NULL;
  682. X    }
  683. X    if (hOutBuf)
  684. X        hOutBuf = LocalFree(hOutBuf);
  685. X
  686. X    if (aflag && outout)    /* if doing LF => CR,LF translation */
  687. X        GlobalUnlock(hOutOut);
  688. X    outout = NULL;          /* free now, translation or not     */
  689. X    if (hOutOut)
  690. X        hOutOut = GlobalFree(hOutOut);  /* mark buffer as freed */
  691. X
  692. X    if (zipfn) {
  693. X        LocalUnlock(hZipFN);
  694. X        zipfn = NULL;
  695. X    }
  696. X    if (hZipFN)
  697. X        hZipFN = LocalFree(hZipFN);
  698. X
  699. X    if (filename) {
  700. X        LocalUnlock(hFileName);
  701. X        filename = NULL;
  702. X    }
  703. X    if (hFileName)
  704. X        hFileName = LocalFree(hFileName);
  705. X}
  706. X
  707. X#else /* !MSWIN */
  708. X
  709. X/******************/
  710. X/*  Main program  */
  711. X/******************/
  712. X
  713. Xint main(argc, argv)   /* return PK-type error code (except under VMS) */
  714. X    int argc;
  715. X    char *argv[];
  716. X{
  717. X    char *s;
  718. X    int c, error=FALSE, negative=0;
  719. X
  720. X
  721. X/*---------------------------------------------------------------------------
  722. X    Macintosh initialization code.
  723. X  ---------------------------------------------------------------------------*/
  724. X
  725. X#ifdef MACOS
  726. X#ifdef THINK_C
  727. X#   include <console.h>
  728. X    static char *argstr[30], args[30*64];
  729. X    Point p;
  730. X    SFTypeList sfT;
  731. X    EventRecord theEvent;
  732. X    short eMask;
  733. X    SFReply fileRep;
  734. X#endif /* THINK_C */
  735. X    int a;
  736. X
  737. X    for (a = 0;  a < 4;  ++a)
  738. X        rghCursor[a] = GetCursor(a+128);
  739. X    giCursor = 0;
  740. X
  741. X    area.Slide = (byte *)calloc(8193, sizeof(short)+sizeof(char)+sizeof(char));
  742. X    area.shrink.Prefix_of = (short *)area.Slide;
  743. X    area.shrink.Suffix_of = area.Slide + (sizeof(short)*(HSIZE+1));
  744. X    area.shrink.Stack = area.Slide + (sizeof(short) + sizeof(char))*(HSIZE+1);
  745. X
  746. X#ifdef THINK_C   
  747. X    for (a = 0;  a < 30;  ++a)
  748. X        argstr[a] = &args[a*64];
  749. Xstart:
  750. X    tflag=vflag=cflag=aflag=jflag=U_flag=quietflg=fflag=uflag=zflag = 0;
  751. X    local_hdr_sig[1] = central_hdr_sig[1] = end_central_sig[1] = '\0';
  752. X/*  extd_local_sig[1] = '\0';  */
  753. X    error = FALSE;
  754. X
  755. X    argc = ccommand(&argv);
  756. X    SetPt(&p, 40, 40);
  757. X
  758. X    SFGetFile(p, "\pSpecify ZIP file:", 0L, -1, sfT, 0L, &fileRep);
  759. X    if (fileRep.good) {
  760. X        macfstest(fileRep.vRefNum);
  761. X        ResolveMacVol(fileRep.vRefNum, &gnVRefNum, &glDirID, NULL);
  762. X        for (a = 1;  a < argc;  ++a)
  763. X            if (argv[a][0] == '-')
  764. X                BlockMove(argv[a], argstr[a], (strlen(argv[a]) > 63) ? 64 :
  765. X                   strlen(argv[a])+1);
  766. X            else
  767. X                break;
  768. X        PtoCstr((char *)fileRep.fName);
  769. X        strcpy(argstr[a], (char *)fileRep.fName);
  770. X        for (;  a < argc;  ++a)
  771. X            BlockMove(argv[a], argstr[a+1], (strlen(argv[a]) > 63) ? 64 :
  772. X               strlen(argv[a])+1);
  773. X        ++argc;
  774. X        argv = argstr;
  775. X
  776. X        if (hfsflag == FALSE)  /* can't support directories:  junk pathnames */
  777. X            jflag = 1;
  778. X    }
  779. X#endif /* THINK_C */
  780. X#endif /* MACOS */
  781. X
  782. X/*---------------------------------------------------------------------------
  783. X    Set signal handler for restoring echo, warn of zipfile corruption, etc.
  784. X  ---------------------------------------------------------------------------*/
  785. X
  786. X    signal(SIGINT, handler);
  787. X    signal(SIGTERM, handler);
  788. X#ifdef SIGBUS
  789. X    signal(SIGBUS, handler);
  790. X#endif
  791. X#ifdef SIGSEGV
  792. X    signal(SIGSEGV, handler);
  793. X#endif
  794. X
  795. X/*---------------------------------------------------------------------------
  796. X    Debugging info for checking on structure padding:
  797. X  ---------------------------------------------------------------------------*/
  798. X
  799. X#ifdef DEBUG_STRUC
  800. X    printf("local_file_hdr size: %X\n",
  801. X           sizeof(local_file_hdr));
  802. X    printf("local_byte_hdr size: %X\n",
  803. X           sizeof(local_byte_hdr));
  804. X    printf("actual size of local headers: %X\n", LREC_SIZE);
  805. X
  806. X    printf("central directory header size: %X\n",
  807. X           sizeof(cdir_file_hdr));
  808. X    printf("central directory byte header size: %X\n",
  809. X           sizeof(cdir_byte_hdr));
  810. X    printf("actual size of central dir headers: %X\n", CREC_SIZE);
  811. X
  812. X    printf("end central dir record size: %X\n",
  813. X           sizeof(ecdir_rec));
  814. X    printf("end central dir byte record size: %X\n",
  815. X           sizeof(ec_byte_rec));
  816. X    printf("actual size of end-central-dir record: %X\n", ECREC_SIZE);
  817. X#endif /* DEBUG_STRUC */
  818. X
  819. X/*---------------------------------------------------------------------------
  820. X    Put environment-variable options into the queue, then rip through any
  821. X    command-line options lurking about...
  822. X  ---------------------------------------------------------------------------*/
  823. X
  824. X    envargs(&argc, &argv, ENV_UNZIP);
  825. X
  826. X    while (--argc > 0 && (*++argv)[0] == '-') {
  827. X        s = argv[0] + 1;
  828. X        while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
  829. X            switch (c) {
  830. X                case ('-'):
  831. X                    ++negative;
  832. X                    break;
  833. X                case ('a'):
  834. X                    if (negative)
  835. X                        aflag = FALSE, negative = 0;
  836. X                    else
  837. X                        aflag = TRUE;
  838. X                    break;
  839. X#if 0
  840. X                case ('b'):    /* force binary mode */
  841. X                    if (negative)
  842. X                        bflag = FALSE, negative = 0;
  843. X                    else
  844. X                        bflag = TRUE;
  845. X                    break;
  846. X#endif
  847. X                case ('c'):
  848. X                    if (negative) {
  849. X                        cflag = FALSE, negative = 0;
  850. X#ifdef NATIVE
  851. X                        aflag = FALSE;
  852. X#endif
  853. X                    } else {
  854. X                        cflag = TRUE;
  855. X#ifdef NATIVE
  856. X                        aflag = TRUE;  /* so you can read it on the screen */
  857. X#endif
  858. X                    }
  859. X                    break;
  860. X                case ('d'):    /* re-create directory structure (default) */
  861. X                    if (negative)
  862. X                        jflag = TRUE, negative = 0;
  863. X                    break;
  864. X                case ('e'):    /* just ignore -e, -x options (extract) */
  865. X                    break;
  866. X                case ('f'):    /* "freshen" (extract only newer files) */
  867. X                    if (negative)
  868. X                        fflag = uflag = FALSE, negative = 0;
  869. X                    else
  870. X                        fflag = uflag = TRUE;
  871. X                    break;
  872. X                case ('j'):    /* junk pathnames/directory structure */
  873. X                    if (negative)
  874. X                        jflag = FALSE, negative = 0;
  875. X                    else
  876. X                        jflag = TRUE;
  877. X                    break;
  878. X                case ('l'):
  879. X                    if (negative) {
  880. X                        vflag = MAX(vflag-negative,0);
  881. X                        negative = 0;
  882. X                    } else
  883. X                        ++vflag;
  884. X                    break;
  885. X                case ('n'):    /* don't overwrite any files */
  886. X                    if (negative)
  887. X                        overwrite_none = FALSE, negative = 0;
  888. X                    else
  889. X                        overwrite_none = TRUE;
  890. X                    break;
  891. X                case ('o'):    /* OK to overwrite files without prompting */
  892. X                    if (negative) {
  893. X                        overwrite_all = MAX(overwrite_all-negative,0);
  894. X                        force_flag = MAX(force_flag-negative,0);
  895. X                        negative = 0;
  896. X                    } else {
  897. X                        ++overwrite_all;
  898. X                        ++force_flag;  /* (share -o for now) force to cont. */
  899. X                    }
  900. X                    break;
  901. X                case ('p'):    /* pipes:  stdout, no tranlation, no messages */
  902. X                    if (negative) {
  903. X                        cflag = FALSE;
  904. X                        quietflg = MAX(quietflg-999,0);
  905. X                        negative = 0;
  906. X                    } else {
  907. X                        cflag = TRUE;
  908. X                        quietflg += 999;
  909. X                    }
  910. X                    break;
  911. X                case ('q'):    /* quiet:  fewer comments/messages */
  912. X                    if (negative) {
  913. X                        quietflg = MAX(quietflg-negative,0);
  914. X                        negative = 0;
  915. X                    } else
  916. X                        ++quietflg;
  917. X                    break;
  918. X#ifdef DOS_OS2
  919. X                case ('s'):    /* spaces in filenames:  allow by default */
  920. X                    if (negative)
  921. X                        sflag = TRUE, negative = 0;
  922. X                    else
  923. X                        sflag = FALSE;
  924. X                    break;
  925. X#endif
  926. X                case ('t'):
  927. X                    if (negative)
  928. X                        tflag = FALSE, negative = 0;
  929. X                    else
  930. X                        tflag = TRUE;
  931. X                    break;
  932. X                case ('U'):    /* Uppercase (don't convert to all-lower) */
  933. X                    if (negative)
  934. X                        U_flag = FALSE, negative = 0;
  935. X                    else
  936. X                        U_flag = TRUE;
  937. X                    break;
  938. X                case ('u'):    /* update (extract only new and newer files) */
  939. X                    if (negative)
  940. X                        uflag = FALSE, negative = 0;
  941. X                    else
  942. X                        uflag = TRUE;
  943. X                    break;
  944. X                case ('V'):    /* Version (retain VMS/DEC-20 file versions) */
  945. X                    if (negative)
  946. X                        V_flag = FALSE, negative = 0;
  947. X                    else
  948. X                        V_flag = TRUE;
  949. X                    break;
  950. X                case ('v'):    /* verbose */
  951. X                    if (negative) {
  952. X                        vflag = MAX(vflag-negative,0);
  953. X                        negative = 0;
  954. X                    } else if (vflag)
  955. X                        ++vflag;
  956. X                    else
  957. X                        vflag = 2;
  958. X                    break;
  959. X#ifdef VMS
  960. X                case ('X'):   /* restore owner/protection info (need privs?) */
  961. X                    if (negative)
  962. X                        secinf = FALSE, negative = 0;
  963. X                    else
  964. X                        secinf = TRUE;
  965. X                    break;
  966. X#endif /* VMS */
  967. X                case ('x'):    /* extract:  default */
  968. X                    break;
  969. X                case ('z'):    /* display only the archive comment */
  970. X                    if (negative) {
  971. X                        zflag = MAX(zflag-negative,0);
  972. X                        negative = 0;
  973. X                    } else
  974. X                        ++zflag;
  975. X                    break;
  976. X                default:
  977. X                    error = TRUE;
  978. X                    break;
  979. X
  980. X            } /* end switch */
  981. X        } /* end while (not end of argument string) */
  982. X    } /* end while (not done with switches) */
  983. X
  984. X/*---------------------------------------------------------------------------
  985. X    Make sure we aren't trying to do too many things here.  [This seems like
  986. X    kind of a brute-force way to do things; but aside from that, isn't the
  987. X    -a option useful when listing the directory (i.e., for reading zipfile
  988. X    comments)?  It's a modifier, not an action in and of itself, so perhaps
  989. X    it should not be included in the test--certainly, in the case of zipfile
  990. X    testing, it can just be ignored.]
  991. X  ---------------------------------------------------------------------------*/
  992. X
  993. X    if ((aflag && tflag) || (aflag && vflag) || (cflag && tflag) ||
  994. X        (cflag && uflag) || (cflag && vflag) || (tflag && uflag) ||
  995. X        (tflag && vflag) || (uflag && vflag) || (fflag && overwrite_none)) {
  996. X        fprintf(stderr, "error:\
  997. X  -at, -av, -ct, -cu, -cv, -fn, -tu, -tv, -uv combinations not allowed\n");
  998. X        error = TRUE;
  999. X    }
  1000. X    if (quietflg && zflag)
  1001. X        quietflg = 0;
  1002. X    if (overwrite_all && overwrite_none) {
  1003. X        fprintf(stderr, "caution:  both -n and -o specified; ignoring -o\n");
  1004. X        overwrite_all = FALSE;
  1005. X    }
  1006. X    if ((argc-- == 0) || error)
  1007. X        RETURN(usage(error));
  1008. X
  1009. X/*---------------------------------------------------------------------------
  1010. X    Now get the zipfile name from the command line and see if it exists as a
  1011. X    regular (non-directory) file.  If not, append the ".zip" suffix.  We don't
  1012. X    immediately check to see if this results in a good name, but we will do so
  1013. X    later.  In the meantime, see if there are any member filespecs on the com-
  1014. X    mand line, and if so, set the filename pointer to point at them.
  1015. X  ---------------------------------------------------------------------------*/
  1016. X
  1017. X    strcpy(zipfn, *argv++);
  1018. X    if (stat(zipfn, &statbuf) || (statbuf.st_mode & S_IFMT) == S_IFDIR)
  1019. X        strcat(zipfn, ZSUFX);
  1020. X#if (defined(UNIX) && !defined(VMS)) /* Unix executables have no extension-- */
  1021. X    else if (statbuf.st_mode & S_IXUSR)  /* might find zip, not zip.zip; etc */
  1022. X        fprintf(stderr, "\nnote:  file [ %s ] may be an executable\n\n", zipfn);
  1023. X#endif /* UNIX && !VMS */
  1024. X
  1025. X    if (stat(zipfn, &statbuf)) {/* try again */
  1026. X        fprintf(stderr, "error:  can't find zipfile [ %s ]\n", zipfn);
  1027. X        RETURN(9);              /* 9:  file not found */
  1028. X    } else
  1029. X        ziplen = statbuf.st_size;
  1030. X
  1031. X    if (argc != 0) {
  1032. X        fnv = argv;
  1033. X        process_all_files = FALSE;
  1034. X    } else
  1035. X        process_all_files = TRUE;       /* for speed */
  1036. X
  1037. X/*---------------------------------------------------------------------------
  1038. X    Okey dokey, we have everything we need to get started.  Let's roll.
  1039. X  ---------------------------------------------------------------------------*/
  1040. X
  1041. X    inbuf = (byte *) malloc(INBUFSIZ + 4);     /* 4 extra for hold[] (below) */
  1042. X    outbuf = (byte *) malloc(OUTBUFSIZ + 1);   /* 1 extra for string termin. */
  1043. X#ifndef DOS_OS2
  1044. X    if (aflag)                  /* if need an ascebc scratch, */
  1045. X        outout = (byte *) malloc(OUTBUFSIZ);
  1046. X    else                        /*  allocate it... */
  1047. X#endif /* !DOS_OS2 */
  1048. X        outout = outbuf;        /*  else just point to outbuf */
  1049. X
  1050. X    if ((inbuf == (byte *)NULL) || (outbuf == (byte *)NULL) ||
  1051. X        (outout == (byte *)NULL)) {
  1052. X        fprintf(stderr, "error:  can't allocate unzip buffers\n");
  1053. X        RETURN(4);              /* 4-8:  insufficient memory */
  1054. X    }
  1055. X    hold = &inbuf[INBUFSIZ];    /* to check for boundary-spanning signatures */
  1056. X
  1057. X    RETURN(process_zipfile());  /* keep passing errors back... */
  1058. X
  1059. X} /* end main() */
  1060. X
  1061. X
  1062. X
  1063. X
  1064. X
  1065. X/**********************/
  1066. X/*  Function usage()  */
  1067. X/**********************/
  1068. X
  1069. Xint usage(error)   /* return PK-type error code */
  1070. X    int error;
  1071. X{
  1072. X#ifdef NATIVE
  1073. X#ifdef EBCDIC
  1074. X    char *astring = "-a  convert ASCII to EBCDIC";
  1075. X#else /* !EBCDIC */
  1076. X    char *astring = "-a  convert ASCII to native chars";
  1077. X#endif /* ?EBCDIC */
  1078. X/*  char *astring = "-a  convert ASCII to " NATIVE;  (ANSI C concatenation)  */
  1079. X    char *loc_str = "";
  1080. X#else /* !NATIVE */
  1081. X#ifdef DOS_OS2
  1082. X    char *astring = "-a  convert text (LF => CR LF)";
  1083. X    char *loc_str = "-s  spaces in filenames => _";
  1084. X#else /* !DOS_OS2 */
  1085. X#ifdef MACOS
  1086. X    char *astring = "-a  convert text (CR LF => CR)";
  1087. X    char *loc_str = "";
  1088. X#else /* !MACOS:  UNIX, VMS */
  1089. X    char *astring = "-a  convert text (CR LF => LF)";
  1090. X#ifdef VMS
  1091. X    char *loc_str = "-X  restore owner/protection info";
  1092. X#else /* !VMS */
  1093. X    char *loc_str = "";
  1094. X#endif /* ?VMS */
  1095. X#endif /* ?MACOS */
  1096. X#endif /* ?DOS_OS2 */
  1097. X#endif /* ?NATIVE */
  1098. X    FILE *usagefp;
  1099. X
  1100. X
  1101. X/*---------------------------------------------------------------------------
  1102. X    If user requested usage, send it to stdout; else send to stderr.
  1103. X  ---------------------------------------------------------------------------*/
  1104. X
  1105. X    if (error)
  1106. X        usagefp = (FILE *) stderr;
  1107. X    else
  1108. X        usagefp = (FILE *) stdout;
  1109. X
  1110. X    fprintf(usagefp, "\
  1111. XUnZip:  Zipfile Extract %s;  (c) 1989 S.H.Smith and others\n\
  1112. XVersions 3.0 and later by Info-ZIP.  Bug reports ONLY to zip-bugs@cs.ucla.edu\
  1113. X\n\n", VERSION);
  1114. X
  1115. X    fprintf(usagefp, "\
  1116. XUsage: unzip [ -options[modifiers] ] file[.zip] [filespec...]\n\
  1117. X  -x  extract files (default)                -l  list files (short format)\n\
  1118. X  -c  extract files to stdout/screen (CRT)   -v  list files (verbose format)\n\
  1119. X  -f  freshen existing files, create none    -p  extract to pipe, no messages\n\
  1120. X  -u  update files, create if necessary      -t  test archive integrity\n\
  1121. X                                             -z  display archive comment\n\
  1122. Xmodifiers:\n\
  1123. X  -n  never overwrite existing files         %s\n", loc_str);
  1124. X    fprintf(usagefp, "\
  1125. X  -o  overwrite files WITHOUT prompting      %s\n\
  1126. X  -j  junk paths (don't make directories)    -U  don't make names lowercase\n\
  1127. X  -q  quiet mode (-qq => quieter)            -V  retain VMS version numbers\
  1128. X\n\n\
  1129. XExamples: (See manual for more information)\n\
  1130. X  unzip data1 Readme   => extracts file Readme from zipfile data1.zip\n\
  1131. X  unzip -p foo | more  => send contents of foo.zip via pipe into program more\n\
  1132. X  unzip -fo foo        => quietly replace existing files if archive files newer\
  1133. X\n", astring);
  1134. X
  1135. X#ifdef VMS
  1136. X    fprintf(usagefp, "\
  1137. X  unzip \"-V\" foo \"Bar\" => must quote uppercase options and filenames in VMS\
  1138. X\n");
  1139. X#endif
  1140. X
  1141. X    if (error)
  1142. X        return 10;    /* 10:  bad or illegal parameters specified */
  1143. X    else
  1144. X        return 0;     /* just wanted usage screen: no error */
  1145. X
  1146. X} /* end function usage() */
  1147. X
  1148. X#endif /* ?MSWIN */
  1149. X
  1150. X
  1151. X
  1152. END_OF_FILE
  1153.  if test 29228 -ne `wc -c <'unzip.c.A'`; then
  1154.     echo shar: \"'unzip.c.A'\" unpacked with wrong size!
  1155.  elif test -f 'unzip.c.B'; then
  1156.     echo shar: Combining  \"'unzip.c'\" \(60418 characters\)
  1157.     cat 'unzip.c.A' 'unzip.c.B' > 'unzip.c'
  1158.     if test 60418 -ne `wc -c <'unzip.c'`; then
  1159.       echo shar: \"'unzip.c'\" combined with wrong size!
  1160.     else
  1161.       rm unzip.c.A unzip.c.B
  1162.     fi
  1163.   fi
  1164.   # end of 'unzip.c.A'
  1165. fi
  1166. if test -f 'zipinfo.doc' -a "${1}" != "-c" ; then 
  1167.   echo shar: Will not clobber existing file \"'zipinfo.doc'\"
  1168. else
  1169.   echo shar: Extracting \"'zipinfo.doc'\" \(15236 characters\)
  1170.   sed "s/^X//" >'zipinfo.doc' <<'END_OF_FILE'
  1171. X
  1172. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1173. X
  1174. XNAME
  1175. X     zipinfo - list detailed information about a ZIP archive file
  1176. X
  1177. XSYNOPSIS
  1178. X     zipinfo [-1smlvht] file[.zip] [filespec ...]
  1179. X
  1180. XARGUMENTS
  1181. X     file[.zip]  Path of the ZIP archive.  The suffix ``.zip'' is
  1182. X                 applied  if  the  file specified does not exist.
  1183. X                 Note that self-extracting  ZIP  files  are  sup-
  1184. X                 ported;  just  specify the ``.exe'' suffix your-
  1185. X                 self.
  1186. X
  1187. X     [filespec]  An optional list of archive members to  be  pro-
  1188. X                 cessed.  Expressions may be used to match multi-
  1189. X                 ple members; be sure to quote  expressions  that
  1190. X                 contain   characters  interpreted  by  the  Unix
  1191. X                 shell. See PATTERN  MATCHING  (below)  for  more
  1192. X                 details.
  1193. X
  1194. XOPTIONS
  1195. X     -1  list filenames only, one per line (useful for pipes)
  1196. X     -s  list zipfile  info  in  short  Unix  ``ls  -l''  format:
  1197. X         default
  1198. X     -m  list zipfile info in medium Unix ``ls -l'' format
  1199. X     -l  list zipfile info in long Unix ``ls -l'' format
  1200. X     -v  list zipfile information in verbose, multi-page format
  1201. X     -h  list header line
  1202. X     -t  list totals for files listed or for all files
  1203. X
  1204. XPATTERN MATCHING
  1205. X     All archive members are listed unless a filespec is provided
  1206. X     to specify a subset of the archive members.  The filespec is
  1207. X     similar to an egrep expression, and may contain:
  1208. X
  1209. X     *      matches a sequence of 0 or more characters
  1210. X     ?      matches exactly 1 character
  1211. X     \nnn   matches the character having octal code nnn
  1212. X     [...]  matches any single character found inside the  brack-
  1213. X            ets; ranges are specified by a beginning character, a
  1214. X            hyphen, and an ending character.  If  an  exclamation
  1215. X            point  or  a  carat  (`!'  or  `^')  follows the left
  1216. X            bracket, then the range of characters matched is com-
  1217. X            plemented  with  respect  to  the ASCII character set
  1218. X            (that is, anything except the characters  inside  the
  1219. X            brackets is considered a match).
  1220. X
  1221. XDESCRIPTION
  1222. X     ZipInfo lists technical information  about  a  ZIP  archive,
  1223. X     including  information  file  access permissions, encryption
  1224. X     status, type of compression, version and operating system of
  1225. X     compressing program, and the like.  The default option is to
  1226. X
  1227. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 1
  1228. X
  1229. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1230. X
  1231. X     list files in the following format:
  1232. X
  1233. X-rw-rwl---  1.5 unx    2802 t- defX 11-Aug-91 13:48 perms.2660
  1234. X
  1235. X     The last three fields are clearly the modification date  and
  1236. X     time of the file, and its name.  The case of the filename is
  1237. X     respected; thus files  which  come  from  MS-DOS  PKZIP  are
  1238. X     always  capitalized.   If  the file was zipped with a stored
  1239. X     directory name, that  is  also  displayed  as  part  of  the
  1240. X     filename.
  1241. X
  1242. X     The second and third  fields  indicate  that  the  file  was
  1243. X     zipped  under Unix with version 1.5 of Zip (a beta version).
  1244. X     Since it comes from Unix, the file permissions at the begin-
  1245. X     ning   of   the  line  are  printed  in  Unix  format.   The
  1246. X     uncompressed file-size (2802 in this example) is the  fourth
  1247. X     field.
  1248. X
  1249. X     The fifth field consists of two characters, either of  which
  1250. X     may  take  on  several  values.   The first character may be
  1251. X     either `t' or `b', indicating that Zip believes the file  to
  1252. X     be  text  or  binary,  respectively;  but  if  the  file  is
  1253. X     encrypted, ZipInfo notes this fact by capitalizing the char-
  1254. X     acter  (`T'  or `B').  The second character may also take on
  1255. X     four values, depending on whether there is an extended local
  1256. X     header  and/or  an  ``extra field'' associated with the file
  1257. X     (explained in PKWare's APPNOTE.TXT).  If neither exists, the
  1258. X     character  will  be  a hyphen (`-'); if there is an extended
  1259. X     local header but no extra field, `l'; if the  reverse,  `x';
  1260. X     and  if  both  exist, `X'.  Thus the file in this example is
  1261. X     (apparently) a text file, is not encrypted, and has  neither
  1262. X     an  extra field nor an extended local header associated with
  1263. X     it.  The example below, on the other hand, is  an  encrypted
  1264. X     binary file with an extra field:
  1265. X
  1266. XRWD,R,R     0.9 vms     168 Bx shrk  9-Aug-91 19:15 perms.0644
  1267. X
  1268. X     Extra fields are used by PKWare for  authenticity  verifica-
  1269. X     tion(?)  and  possibly other purposes, and by Info-ZIP's Zip
  1270. X     1.6 and later to store OS/2, Macintosh and VMS  file  attri-
  1271. X     butes.  This example presumably falls into the latter class,
  1272. X     then.  Note that the file attributes are listed in VMS  for-
  1273. X     mat.   Other  possibilities  for  the  host operating system
  1274. X     include OS/2 with High Performance File System  (HPFS),  DOS
  1275. X     or  OS/2  with  File Allocation Table (FAT) file system, and
  1276. X     Macintosh, denoted as follows:
  1277. X
  1278. Xarc,,rw,    1.0 os2    5358 Tl i4:3  4-Dec-91 11:33 longfilename.hpfs
  1279. Xarc,hid,rdo,sys dos    4096 b- i4:2 14-Jul-91 12:58 EA DATA. SF
  1280. X--w-------  1.0 mac   17357 bx i8:2  4-May-92 04:02 unzip.macr
  1281. X
  1282. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 2
  1283. X
  1284. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1285. X
  1286. X     File attributes in the first two cases are  indicated  in  a
  1287. X     DOS-like  format,  where  the  file  may or may not have its
  1288. X     archive bit set; may be hidden or not; may be read-write  or
  1289. X     read-only;  and  may be a system file or not.  If the attri-
  1290. X     butes are too long,  the  version  number  of  the  encoding
  1291. X     software is omitted.  (The information is still available in
  1292. X     the verbose listing, however.)  Interpretation of  Macintosh
  1293. X     file attributes needs some work yet.
  1294. X
  1295. X     Finally, the sixth field indicates  the  compression  method
  1296. X     and  possible  sub-method used.  There are six methods known
  1297. X     at present:  storing (no compression), reducing,  shrinking,
  1298. X     imploding,  tokenizing,  and  deflating.  In addition, there
  1299. X     are four levels of reducing (1 through  4);  four  types  of
  1300. X     imploding  (4K or 8K sliding dictionary, and 2 or 3 Shannon-
  1301. X     Fano trees); and three levels of  deflating  (fast,  normal,
  1302. X     maximum  compression).  ZipInfo represents these methods and
  1303. X     their sub-methods as follows:  ``stor''; ``re:1,'' ``re:2,''
  1304. X     etc.;  ``shrk'';  ``i4:2,''  ``i8:3,''  etc.;  ``tokn''; and
  1305. X     ``defF,'' ``defN,'' and ``defX.''
  1306. X
  1307. X     The medium and long listings are  almost  identical  to  the
  1308. X     short  format except that they add information on the file's
  1309. X     compression.   The  medium  format  indicates   the   file's
  1310. X     compression factor as a percentage:
  1311. X
  1312. X-rw-rwl---  1.5 unx    2802 t- 81% defX 11-Aug-91 13:48 perms.2660
  1313. X
  1314. X     In this example, the file has been compressed by more than a
  1315. X     factor of five; the compressed data are only 19% of the ori-
  1316. X     ginal size.  The long format  gives  the  compressed  file's
  1317. X     size in bytes, instead:
  1318. X
  1319. X-rw-rwl---  1.5 unx    2802 t-     538 defX 11-Aug-91 13:48 perms.2660
  1320. X
  1321. X     In addition to individual file information, a  default  zip-
  1322. X     file listing also includes header and trailer lines:
  1323. X
  1324. XArchive:  OS2.zip   5453 bytes   5 files
  1325. X,,rw,       1.0 os2     730 b- i4:3 26-Jun-92 23:40 Contents
  1326. X,,rw,       1.0 os2    3710 b- i4:3 26-Jun-92 23:33 makefile.os2
  1327. X,,rw,       1.0 os2    8753 b- i8:3 26-Jun-92 15:29 os2unzip.c
  1328. X,,rw,       1.0 os2      98 b- stor 21-Aug-91 15:34 unzip.def
  1329. X,,rw,       1.0 os2      95 b- stor 21-Aug-91 17:51 zipinfo.def
  1330. X5 files, 13386 bytes uncompressed, 4951 bytes compressed:  63%
  1331. X
  1332. X     The header line gives the name of  the  archive,  its  total
  1333. X     size,  and  the total number of files; the trailer gives the
  1334. X     number of files listed, their total uncompressed  size,  and
  1335. X     their  total  compressed  size  (not  including any of Zip's
  1336. X     internal overhead).  If, however, one or more filespecs  are
  1337. X     provided, the header and trailer lines are not listed.  This
  1338. X
  1339. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 3
  1340. X
  1341. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1342. X
  1343. X     behavior is also similar to that of Unix's ``ls -l''; it may
  1344. X     be  overridden  by  specifying  the -h and -t options expli-
  1345. X     citly.  In such a case  the  listing  format  must  also  be
  1346. X     specified  explicitly,  since  -h  or  -t  (or  both) in the
  1347. X     absence of other options implies that  ONLY  the  header  or
  1348. X     trailer  line (or both) is listed.  See the EXAMPLES section
  1349. X     below for a semi-intelligible translation of this nonsense.
  1350. X
  1351. X     The verbose listing is self-explanatory.  It also lists file
  1352. X     comments  and the zipfile comment, if any, and the number of
  1353. X     bytes of OS/2 extended attributes  stored.   Note  that  the
  1354. X     latter  number will in general NOT match the number given by
  1355. X     OS/2's ``dir'' command; OS/2 always reports  the  number  of
  1356. X     bytes  required  in  16-bit  format,  whereas ZipInfo always
  1357. X     reports the 32-bit storage.
  1358. X
  1359. XENVIRONMENT OPTIONS
  1360. X     Modifying ZipInfo's default behavior via options  placed  in
  1361. X     an environment variable can be a bit complicated to explain,
  1362. X     due to ZipInfo's attempts to handle various defaults  in  an
  1363. X     intuitive,  yet  Unix-like,  manner.  Nevertheless, there is
  1364. X     some underlying logic.  In brief, there are three ``priority
  1365. X     levels''  of  options:   the  default  options;  environment
  1366. X     options, which can override or  add  to  the  defaults;  and
  1367. X     explicit  options  given  by the user, which can override or
  1368. X     add to either of the above.
  1369. X
  1370. X     The default listing  format,  as  noted  above,  corresponds
  1371. X     roughly  to  the "zipinfo -hst" command (except when indivi-
  1372. X     dual zipfile members are specified).  A user who prefers the
  1373. X     long-listing  format  (-l)  can  make  use  of  the  ZIPINFO
  1374. X     environment variable to change this default:
  1375. X
  1376. X           setenv ZIPINFO -l            Unix C shell
  1377. X
  1378. X           ZIPINFO=-l; export ZIPINFO   Unix Bourne shell
  1379. X
  1380. X           set ZIPINFO=-l               OS/2 or MS-DOS
  1381. X
  1382. X           define ZIPINFO_OPTS "-l"     VMS (quotes for LOWERCASE)
  1383. X
  1384. X     If,  in  addition,  the  user  dislikes  the  trailer  line,
  1385. X     ZipInfo's concept of ``negative options''  may  be  used  to
  1386. X     override  the default inclusion of the line.  This is accom-
  1387. X     plished by preceding the undesired option with one  or  more
  1388. X     minuses:   e.g., ``-l-t'' or ``--tl'', in this example.  The
  1389. X     first hyphen is the regular switch character,  but  the  one
  1390. X     before the `t' is a minus sign.  The dual use of hyphens may
  1391. X     seem  a  little  awkward,  but  it's  reasonably   intuitive
  1392. X     nonetheless:   simply  ignore  the  first hyphen and go from
  1393. X     there.  It is also consistent with the behavior of the  Unix
  1394. X     command nice(1).
  1395. X
  1396. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 4
  1397. X
  1398. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1399. X
  1400. XEXAMPLES
  1401. X     To get a basic, short-format listing of  the  complete  con-
  1402. X     tents of a ZIP archive ``storage.zip,'' with both header and
  1403. X     totals lines, use only the archive name as  an  argument  to
  1404. X     zipinfo:
  1405. X
  1406. X           zipinfo storage
  1407. X
  1408. X     To produce  a  basic,  long-format  listing  (not  verbose),
  1409. X     including header and totals lines, use -l:
  1410. X
  1411. X           zipinfo -l storage
  1412. X
  1413. X     To list the complete contents of the archive without  header
  1414. X     and  totals  lines,  either  negate the -h and -t options or
  1415. X     else specify the contents explicitly:
  1416. X
  1417. X           zipinfo --h-t storage
  1418. X
  1419. X           zipinfo storage \*
  1420. X
  1421. X     (where the backslash is required only  if  the  shell  would
  1422. X     otherwise  expand the `*' wildcard, as in Unix when globbing
  1423. X     is turned on--double quotes around the asterisk  would  have
  1424. X     worked  as  well).   To turn off the totals line by default,
  1425. X     use the environment variable (C shell is assumed here):
  1426. X
  1427. X           setenv ZIPINFO --t
  1428. X
  1429. X           zipinfo storage
  1430. X
  1431. X     To get the full, short-format listing of the  first  example
  1432. X     again,  given that the environment variable is set as in the
  1433. X     previous example, it is necessary to specify the  -s  option
  1434. X     explicitly,  since the -t option by itself implies that ONLY
  1435. X     the footer line is to be printed:
  1436. X
  1437. X           setenv ZIPINFO --t
  1438. X
  1439. X           zipinfo -t storage           [only totals line]
  1440. X
  1441. X           zipinfo -st storage          [full listing]
  1442. X
  1443. X     The -s option, like -m and -l, includes headers and  footers
  1444. X     by  default, unless otherwise specified.  Since the environ-
  1445. X     ment variable specified no footers and  that  has  a  higher
  1446. X     precedence  than  the default behavior of -s, an explicit -t
  1447. X     option was necessary to produce the full  listing.   Nothing
  1448. X     was  indicated  about  the header, however, so the -s option
  1449. X     was sufficient.  Note that both the -h and -t options,  when
  1450. X     used  by themselves or with each other, override any default
  1451. X     listing of member files; only the header and/or  footer  are
  1452. X
  1453. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 5
  1454. X
  1455. XZIPINFO(1)               USER COMMANDS                 ZIPINFO(1)
  1456. X
  1457. X     printed.   This  behavior  will  be more useful when ZipInfo
  1458. X     accepts wildcards for the zipfile name; one may then summar-
  1459. X     ize the contents of all zipfiles with a single command.
  1460. X
  1461. X     To list information on a single file within the archive,  in
  1462. X     medium format, specify the filename explicitly:
  1463. X
  1464. X           zipinfo -m storage unshrink.c
  1465. X
  1466. X     The specification of any member file, as  in  this  example,
  1467. X     will  override the default header and totals lines; only the
  1468. X     single line of information about the requested file will  be
  1469. X     printed.   This  is  intuitively  what one would expect when
  1470. X     requesting information about a single  file.   For  multiple
  1471. X     files,  it  is often useful to know the total compressed and
  1472. X     uncompressed size; in such cases -t may be specified  expli-
  1473. X     citly:
  1474. X
  1475. X           zipinfo -mt storage "*.[ch] Mak\*
  1476. X
  1477. X     Finally, to get maximal information about the  ZIP  archive,
  1478. X     use the verbose option.  It is usually wise to pipe the out-
  1479. X     put into a filter such as more(1):
  1480. X
  1481. X           zipinfo -v storage | more
  1482. X
  1483. XTIPS
  1484. X     The author finds it convenient to set up an alias ``ii'' for
  1485. X     ZipInfo  on systems which allow aliases, or else to set up a
  1486. X     batch  file  ``ii.bat''  or  to  rename  the  executable  to
  1487. X     ``ii.exe'' on systems such as MS-DOS which have no provision
  1488. X     for aliases.  The ``ii'' usage parallels the  common  ``ll''
  1489. X     alias  for long listings in Unix, and the similarity between
  1490. X     the outputs of the two commands was intentional.
  1491. X
  1492. XSEE ALSO
  1493. X     funzip(1),  unzip(1),   zip(1),   zipcloak(1),   zipnote(1),
  1494. X     zipsplit(1)
  1495. X
  1496. XAUTHOR
  1497. X     Greg Roelofs (also known as Cave Newt).  ZipInfo  is  partly
  1498. X     based  on  S. H. Smith's unzip and contains pattern-matching
  1499. X     code by  J.  Kercheval,  but  mostly  it  was  written  from
  1500. X     scratch.  The OS/2 extra-field code is by Kai Uwe Rommel.
  1501. X
  1502. XInfo-ZIP          Last change: 19 Aug 92 (v1.0)                 6
  1503. X
  1504. END_OF_FILE
  1505.   if test 15236 -ne `wc -c <'zipinfo.doc'`; then
  1506.     echo shar: \"'zipinfo.doc'\" unpacked with wrong size!
  1507.   fi
  1508.   # end of 'zipinfo.doc'
  1509. fi
  1510. echo shar: End of archive 8 \(of 14\).
  1511. cp /dev/null ark8isdone
  1512. MISSING=""
  1513. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
  1514.     if test ! -f ark${I}isdone ; then
  1515.     MISSING="${MISSING} ${I}"
  1516.     fi
  1517. done
  1518. if test "${MISSING}" = "" ; then
  1519.     echo You have unpacked all 14 archives.
  1520.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1521. else
  1522.     echo You still must unpack the following archives:
  1523.     echo "        " ${MISSING}
  1524. fi
  1525. exit 0
  1526. exit 0 # Just in case...
  1527.