home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / vmsnet / sources / 328 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  47.3 KB

  1. Path: sparky!uunet!stanford.edu!agate!dog.ee.lbl.gov!network.ucsd.edu!mvb.saic.com!vmsnet-sources
  2. From: goathunter@wkuvx1.bitnet
  3. Newsgroups: vmsnet.sources
  4. Subject: Zip v1.9 & UnZip v5.0, part 11/22
  5. Message-ID: <8009648@MVB.SAIC.COM>
  6. Date: Tue, 01 Sep 1992 22:51:38 GMT
  7. Organization: Western Kentucky University, Bowling Green, KY
  8. Lines: 1332
  9. Approved: Mark.Berryman@Mvb.Saic.Com
  10.  
  11. Submitted-by: goathunter@wkuvx1.bitnet
  12. Posting-number: Volume 3, Issue 133
  13. Archive-name: zip_unzip/part11
  14.  
  15. -+-+-+-+-+-+-+-+ START OF PART 11 -+-+-+-+-+-+-+-+
  16. X                if ((ascii_to_native(*inptr) == 'P')  &&
  17. X                     !strncmp((char *)inptr, end_central_sig, 4)) `7B
  18. X                    incnt -= inptr - inbuf;
  19. X                    return 0;   /* found it! */
  20. X                `7D               /* ...otherwise fall through & fail */
  21. X
  22. X/*--------------------------------------------------------------------------
  23. V-
  24. X    Zipfile is longer than INBUFSIZ:  may need to loop.  Start with short
  25. X    block at end of zipfile (if not TOO short).
  26. X  --------------------------------------------------------------------------
  27. V-*/
  28. X
  29. X    `7D else `7B
  30. X        if ((tail_len = ziplen % INBUFSIZ) > ECREC_SIZE) `7B
  31. X            cur_zipfile_bufstart = lseek(zipfd, ziplen-tail_len, SEEK_SET);
  32. X            if ((incnt = read(zipfd,(char *)inbuf,(unsigned int)tail_len)) !
  33. V=
  34. X                 (int)tail_len)
  35. X                goto fail;      /* shut up; it's expedient. */
  36. X
  37. X            /* 'P' must be at least 22 bytes from end of zipfile */
  38. X            for (inptr = inbuf+(int)tail_len-22;  inptr >= inbuf;  --inptr)
  39. X                if ((ascii_to_native(*inptr) == 'P')  &&
  40. X                     !strncmp((char *)inptr, end_central_sig, 4)) `7B
  41. X                    incnt -= inptr - inbuf;
  42. X                    return 0;   /* found it */
  43. X                `7D               /* ...otherwise search next block */
  44. X            strncpy((char *)hold, (char *)inbuf, 3);    /* sig may span bloc
  45. Vk
  46. X                                                           boundary */
  47. X        `7D else `7B
  48. X            cur_zipfile_bufstart = ziplen - tail_len;
  49. X        `7D
  50. X
  51. X    /*----------------------------------------------------------------------
  52. V-
  53. X        Loop through blocks of zipfile data, starting at the end and going
  54. X        toward the beginning.  Need only check last 65557 bytes of zipfile:
  55. X        comment may be up to 65535 bytes long, end-of-central-directory rec-
  56. X        ord is 18 bytes (shouldn't hardcode this number, but what the hell:
  57. X        already did so above (22=18+4)), and sig itself is 4 bytes.
  58. X      ----------------------------------------------------------------------
  59. V-*/
  60. X
  61. X        numblks = (int)
  62. X                  ((MIN(ziplen,65557L) - tail_len + (INBUFSIZ-1)) / INBUFSIZ
  63. V);
  64. X        /*          =amount to search=   ==done==   ==rounding==    =blksiz=
  65. V */
  66. X
  67. X        for (i = 1;  i <= numblks;  ++i) `7B
  68. X            cur_zipfile_bufstart -= INBUFSIZ;
  69. X            lseek(zipfd, cur_zipfile_bufstart, SEEK_SET);
  70. X            if ((incnt = read(zipfd,(char *)inbuf,INBUFSIZ)) != INBUFSIZ)
  71. X                break;          /* fall through and fail */
  72. X
  73. X            for (inptr = inbuf+INBUFSIZ-1;  inptr >= inbuf;  --inptr)
  74. X                if ((ascii_to_native(*inptr) == 'P')  &&
  75. X                     !strncmp((char *)inptr, end_central_sig, 4)) `7B
  76. X                    incnt -= inptr - inbuf;
  77. X                    return 0;   /* found it */
  78. X                `7D
  79. X            strncpy((char *)hold, (char *)inbuf, 3);    /* sig may span bloc
  80. Vk
  81. X                                                           boundary */
  82. X        `7D
  83. X
  84. X    `7D /* end if (ziplen > INBUFSIZ) */
  85. X
  86. X/*--------------------------------------------------------------------------
  87. V-
  88. X    Searched through whole region where signature should be without finding
  89. X    it.  Print informational message and die a horrible death.
  90. X  --------------------------------------------------------------------------
  91. V-*/
  92. X
  93. Xfail:
  94. X#ifdef MSWIN
  95. X    MessageBeep(1);
  96. X#endif
  97. X
  98. X    fprintf(stderr, "\nFile:  %s\n\n\
  99. X     End-of-central-directory signature not found.  Either this file is not\
  100. Vn\
  101. X     a zipfile, or it constitutes one disk of a multi-part archive.  In the\
  102. Vn\
  103. X     latter case the central directory and zipfile comment will be found on\
  104. Vn\
  105. X     the last disk(s) of this archive.\n", zipfn);
  106. X    return 1;
  107. X
  108. X`7D /* end function find_end_central_dir() */
  109. X
  110. X
  111. X
  112. X
  113. X
  114. X/***************************************/
  115. X/*  Function process_end_central_dir() */
  116. X/***************************************/
  117. X
  118. Xint process_end_central_dir()    /* return PK-type error code */
  119. X`7B
  120. X    ec_byte_rec byterec;
  121. X    int error=0;
  122. X
  123. X
  124. X/*--------------------------------------------------------------------------
  125. V-
  126. X    Read the end-of-central-directory record and do any necessary machine-
  127. X    type conversions (byte ordering, structure padding compensation) by
  128. X    reading data into character array, then copying to struct.
  129. X  --------------------------------------------------------------------------
  130. V-*/
  131. X
  132. X    if (readbuf((char *) byterec, ECREC_SIZE+4) <= 0)
  133. X        return 51;
  134. X
  135. X    ecrec.number_this_disk =
  136. X        makeword(&byterec`5BNUMBER_THIS_DISK`5D);
  137. X    ecrec.num_disk_with_start_central_dir =
  138. X        makeword(&byterec`5BNUM_DISK_WITH_START_CENTRAL_DIR`5D);
  139. X    ecrec.num_entries_centrl_dir_ths_disk =
  140. X        makeword(&byterec`5BNUM_ENTRIES_CENTRL_DIR_THS_DISK`5D);
  141. X    ecrec.total_entries_central_dir =
  142. X        makeword(&byterec`5BTOTAL_ENTRIES_CENTRAL_DIR`5D);
  143. X    ecrec.size_central_directory =
  144. X        makelong(&byterec`5BSIZE_CENTRAL_DIRECTORY`5D);
  145. X    ecrec.offset_start_central_directory =
  146. X        makelong(&byterec`5BOFFSET_START_CENTRAL_DIRECTORY`5D);
  147. X    ecrec.zipfile_comment_length =
  148. X        makeword(&byterec`5BZIPFILE_COMMENT_LENGTH`5D);
  149. X
  150. X/*--------------------------------------------------------------------------
  151. V-
  152. X    Get the zipfile comment, if any, and print it out.  (Comment may be up
  153. X    to 64KB long.  May the fleas of a thousand camels infest the armpits of
  154. X    anyone who actually takes advantage of this fact.)  Then position the
  155. X    file pointer to the beginning of the central directory and fill buffer.
  156. X  --------------------------------------------------------------------------
  157. V-*/
  158. X
  159. X#ifdef MSWIN
  160. X    cchComment = ecrec.zipfile_comment_length; /* save for comment button */
  161. X    if (ecrec.zipfile_comment_length && zflag) `7B
  162. X#else /* !MSWIN */
  163. X    if (ecrec.zipfile_comment_length && !quietflg) `7B
  164. X        if (!zflag)
  165. X          printf("`5B%s`5D comment:\n", zipfn);
  166. X#endif /* ?MSWIN */
  167. X        if (do_string(ecrec.zipfile_comment_length,DISPLAY)) `7B
  168. X            fprintf(stderr, "\ncaution:  zipfile comment truncated\n");
  169. X            error = 1;          /* 1:  warning error */
  170. X        `7D
  171. X    `7D
  172. X
  173. X    return error;
  174. X
  175. X`7D /* end function process_end_central_dir() */
  176. X
  177. X
  178. X
  179. X
  180. X
  181. X/* also referenced in UpdateListBox() in updatelb.c (Windows version) */
  182. Xchar *Headers`5B`5D`5B2`5D = `7B
  183. X    `7B" Length    Date    Time    Name",
  184. X     " ------    ----    ----    ----"`7D,
  185. X    `7B" Length  Method   Size  Ratio   Date    Time   CRC-32     Name",
  186. X     " ------  ------   ----  -----   ----    ----   ------     ----"`7D
  187. X`7D;
  188. X
  189. X/*************************/
  190. X/* Function list_files() */
  191. X/*************************/
  192. X
  193. Xint list_files()    /* return PK-type error code */
  194. X`7B
  195. X    char **fnamev;
  196. X    int do_this_file=FALSE, ratio, error, error_in_archive=0;
  197. X    int which_hdr=(vflag>1), date_format;
  198. X    UWORD j, yr, mo, dy, hh, mm, members=0;
  199. X    ULONG tot_csize=0L, tot_ucsize=0L;
  200. X#ifdef OS2
  201. X    ULONG tot_easize=0L, tot_eafiles=0L, ea_size;
  202. X#endif
  203. X#ifdef MSWIN
  204. X    PSTR psLBEntry;  /* list box entry */
  205. X#endif
  206. X    min_info info;
  207. X    static char *method`5BNUM_METHODS+1`5D =
  208. X        `7B"Stored", "Shrunk", "Reduce1", "Reduce2", "Reduce3", "Reduce4",
  209. X         "Implode", "Token", "Deflate", unkn`7D;
  210. X
  211. X
  212. X
  213. X/*--------------------------------------------------------------------------
  214. V-
  215. X    Unlike extract_or_test_files(), this routine confines itself to the cen-
  216. X    tral directory.  Thus its structure is somewhat simpler, since we can do
  217. X    just a single loop through the entire directory, listing files as we go.
  218. X
  219. X    So to start off, print the heading line and then begin main loop through
  220. X    the central directory.  The results will look vaguely like the following
  221. V:
  222. X
  223. X  Length  Method   Size  Ratio   Date    Time   CRC-32     Name ("`5E" ==> c
  224. Vase
  225. X  ------  ------   ----  -----   ----    ----   ------     ----   conversion
  226. V)
  227. X   44004  Implode  13041  71%  11-02-89  19:34  8b4207f7   Makefile.UNIX
  228. X    3438  Shrunk    2209  36%  09-15-90  14:07  a2394fd8  `5Edos-file.ext
  229. X  --------------------------------------------------------------------------
  230. V-*/
  231. X
  232. X    pInfo = &info;
  233. X    date_format = dateformat();
  234. X
  235. X#ifndef MSWIN
  236. X    if (quietflg < 2)
  237. X        if (U_flag)
  238. X            printf("%s\n%s\n", Headers`5Bwhich_hdr`5D`5B0`5D, Headers`5Bwhic
  239. Vh_hdr`5D`5B1`5D);
  240. X        else
  241. X            printf("%s (\"`5E\" ==> case\n%s   conversion)\n",`20
  242. X              Headers`5Bwhich_hdr`5D`5B0`5D, Headers`5Bwhich_hdr`5D`5B1`5D);
  243. X#endif /* !MSWIN */
  244. X
  245. X    for (j = 0; j < ecrec.total_entries_central_dir; ++j) `7B
  246. X
  247. X        if (readbuf(sig, 4) <= 0)
  248. X            return 51;          /* 51:  unexpected EOF */
  249. X        if (strncmp(sig, central_hdr_sig, 4)) `7B  /* just to make sure */
  250. X            fprintf(stderr, CentSigMsg, j);  /* sig not found */
  251. X            fprintf(stderr, ReportMsg);   /* check binary transfers */
  252. X            return 3;           /* 3:  error in zipfile */
  253. X        `7D
  254. X        if ((error = process_cdir_file_hdr()) != 0)  /* (sets pInfo->lcflag)
  255. V */
  256. X            return error;       /* only 51 (EOF) defined */
  257. X
  258. X        /*
  259. X         * We could DISPLAY the filename instead of storing (and possibly tr
  260. Vun-
  261. X         * cating, in the case of a very long name) and printing it, but tha
  262. Vt
  263. X         * has the disadvantage of not allowing case conversion--and it's ni
  264. Vce
  265. X         * to be able to see in the listing precisely how you have to type e
  266. Vach
  267. X         * filename in order for unzip to consider it a match.  Speaking of
  268. X         * which, if member names were specified on the command line, check
  269. V in
  270. X         * with match() to see if the current file is one of them, and make
  271. V a
  272. X         * note of it if it is.
  273. X         */
  274. X
  275. X        if ((error = do_string(crec.filename_length, FILENAME)) != 0) `7B
  276. X            error_in_archive = error;  /*             `5E--(uses pInfo->lcfl
  277. Vag) */
  278. X            if (error > 1)      /* fatal:  can't continue */
  279. X                return error;
  280. X        `7D
  281. X        if (extra_field != (byte *)NULL)
  282. X            free(extra_field);
  283. X        extra_field = (byte *)NULL;
  284. X        if ((error = do_string(crec.extra_field_length, EXTRA_FIELD)) != 0)
  285. V `7B
  286. X            error_in_archive = error; `20
  287. X            if (error > 1)      /* fatal:  can't continue */
  288. X                return error;
  289. X        `7D
  290. X        if (!process_all_files) `7B   /* check if specified on command line
  291. V */
  292. X            do_this_file = FALSE;
  293. X            fnamev = fnv;       /* don't destroy permanent filename ptr */
  294. X            for (--fnamev; *++fnamev;)
  295. X                if (match(filename, *fnamev)) `7B
  296. X                    do_this_file = TRUE;
  297. X                    break;      /* found match, so stop looping */
  298. X                `7D
  299. X        `7D
  300. X        /*
  301. X         * If current file was specified on command line, or if no names wer
  302. Ve
  303. X         * specified, do the listing for this file.  Otherwise, get rid of t
  304. Vhe
  305. X         * file comment and go back for the next file.
  306. X         */
  307. X
  308. X        if (process_all_files `7C`7C do_this_file) `7B
  309. X
  310. X            yr = (((crec.last_mod_file_date >> 9) & 0x7f) + 80) % (unsigned)
  311. V100;
  312. X            mo = (crec.last_mod_file_date >> 5) & 0x0f;
  313. X            dy = crec.last_mod_file_date & 0x1f;
  314. X
  315. X            /* twist date so it displays according to national convention */
  316. X            switch (date_format) `7B
  317. X                case DF_YMD:
  318. X                    hh = mo; mo = yr; yr = dy; dy = hh; break;
  319. X                case DF_DMY:
  320. X                    hh = mo; mo = dy; dy = hh;
  321. X            `7D
  322. X            hh = (crec.last_mod_file_time >> 11) & 0x1f;
  323. X            mm = (crec.last_mod_file_time >> 5) & 0x3f;
  324. X
  325. X            csize = (longint) crec.compressed_size;
  326. X            ucsize = (longint) crec.uncompressed_size;
  327. X            if (crec.general_purpose_bit_flag & 1)
  328. X                csize -= 12;    /* if encrypted, don't count encrypt hdr */
  329. X
  330. X            ratio = (ucsize == 0) ? 0 :   /* .zip can have 0-length members
  331. V */
  332. X                ((ucsize > 2000000L) ?    /* risk signed overflow if mult. *
  333. V/
  334. X                (int) ((ucsize-csize) / (ucsize/1000L)) + 5 :   /* big */
  335. X                (int) ((1000L*(ucsize-csize)) / ucsize) + 5);   /* small */
  336. X
  337. X#if 0       /* GRR/Euro:  add this?  define p above */
  338. X#if (defined(DOS_OS2) `7C`7C (defined(UNIX) && !defined(VMS)))
  339. X            for (p = filename;  *p;  ++p)
  340. X                if (!isprint(*p))
  341. X                    *p = '?';  /* change non-printable chars to '?' */
  342. X#endif /* DOS_OS2 `7C`7C UNIX */
  343. X#endif /* 0 */
  344. X
  345. X#ifdef MSWIN
  346. X#ifdef NEED_EARLY_REDRAW
  347. X            /* turn on listbox redrawing just before adding last line */
  348. X            if (j == (ecrec.total_entries_central_dir-1))
  349. X                (void)SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
  350. X#endif /* NEED_EARLY_REDRAW */
  351. X            psLBEntry =
  352. X              (PSTR)LocalAlloc(LMEM_FIXED, FILNAMSIZ+LONG_FORM_FNAME_INX);
  353. X            switch (which_hdr) `7B
  354. X                case 0:   /* short form */
  355. X                    OemToAnsi(filename, filename);  /* translate to ANSI */
  356. X                    wsprintf(psLBEntry, "%7ld  %02u-%02u-%02u  %02u:%02u  %c
  357. V%s",
  358. X                      (long)ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'`5E'
  359. V:' '),
  360. X                      (LPSTR)filename);
  361. X                    SendMessage(hWndList, LB_ADDSTRING, 0,
  362. X                      (LONG)(LPSTR)psLBEntry);
  363. X                    break;
  364. X                case 1:   /* verbose */
  365. X                    OemToAnsi(filename, filename);  /* translate to ANSI */
  366. X                    wsprintf(psLBEntry,`20
  367. X                 "%7ld  %-7s%7ld %3d%%  %02u-%02u-%02u  %02u:%02u  %08lx  %c
  368. V%s",
  369. X                      (long)ucsize, (LPSTR)method`5Bmethnum`5D, (long)csize,
  370. X                      ratio/10, mo, dy, yr, hh, mm, (unsigned long)crec.crc3
  371. V2,
  372. X                      (pInfo->lcflag?'`5E':' '), (LPSTR)filename);
  373. X                    SendMessage(hWndList, LB_ADDSTRING, 0,
  374. X                      (LONG)(LPSTR)psLBEntry);
  375. X            `7D
  376. X            LocalFree((HANDLE)psLBEntry);
  377. X#else /* !MSWIN */
  378. X            switch (which_hdr) `7B
  379. X                case 0:   /* short form */
  380. X                    printf("%7ld  %02u-%02u-%02u  %02u:%02u  %c%s\n",
  381. X                      ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'`5E':' '),
  382. X                      filename);
  383. X                    break;
  384. X                case 1:   /* verbose */
  385. X                    printf(
  386. X              "%7ld  %-7s%7ld %3d%%  %02u-%02u-%02u  %02u:%02u  %08lx  %c%s\
  387. Vn",
  388. X                      ucsize, method`5Bmethnum`5D, csize, ratio/10, mo, dy,
  389. V yr,
  390. X                      hh, mm, crec.crc32, (pInfo->lcflag?'`5E':' '), filenam
  391. Ve);
  392. X            `7D
  393. X#endif /* ?MSWIN */
  394. X
  395. X            error = do_string(crec.file_comment_length, (QCOND? DISPLAY:SKIP
  396. V));
  397. X            if (error) `7B
  398. X                error_in_archive = error;  /* might be just warning */
  399. X                if (error > 1)  /* fatal */
  400. X                    return error;
  401. X            `7D
  402. X            tot_ucsize += (ULONG) ucsize;
  403. X            tot_csize += (ULONG) csize;
  404. X            ++members;
  405. X#ifdef OS2
  406. X            if ((ea_size = SizeOfEAs(extra_field)) != 0) `7B
  407. X                tot_easize += ea_size;
  408. X                tot_eafiles++;
  409. X            `7D
  410. X#endif
  411. X        `7D else `7B        /* not listing this file */
  412. X            SKIP_(crec.file_comment_length)
  413. X        `7D
  414. X    `7D                   /* end for-loop (j: files in central directory) */
  415. X
  416. X/*--------------------------------------------------------------------------
  417. V-
  418. X    Print footer line and totals (compressed size, uncompressed size, number
  419. X    of members in zipfile).
  420. X  --------------------------------------------------------------------------
  421. V-*/
  422. X
  423. X    ratio = (tot_ucsize == 0) ?`20
  424. X        0 : ((tot_ucsize > 4000000L) ?   /* risk unsigned overflow if mult.
  425. V */
  426. X        (int) ((tot_ucsize - tot_csize) / (tot_ucsize/1000L)) + 5 :
  427. X        (int) ((tot_ucsize - tot_csize) * 1000L / tot_ucsize) + 5);
  428. X
  429. X    if (quietflg < 2) `7B
  430. X#ifdef MSWIN
  431. X        /* Display just the totals since the dashed lines get displayed
  432. X         * in UpdateListBox(). Get just enough space to display total.
  433. X         */
  434. X        switch (which_hdr) `7B
  435. X            case 0:         /* short */
  436. X                wsprintf(lpumb->szTotalsLine, "%7lu                    %-7u"
  437. V,`20
  438. X                  (ULONG)tot_ucsize, members);
  439. X                break;
  440. X            case 1:         /* verbose */
  441. X                wsprintf(lpumb->szTotalsLine,`20
  442. X                  "%7lu         %7lu %3d%%                              %-7u
  443. V",`20
  444. X                  (ULONG)tot_ucsize, (ULONG)tot_csize, ratio / 10, members);
  445. X                break;
  446. X        `7D
  447. X#else /* !MSWIN */
  448. X        switch (which_hdr) `7B
  449. X        case 0:         /* short */
  450. X            printf("%s\n%7lu                    %-7u\n",
  451. X                   " ------                    -------",
  452. X                   tot_ucsize, members);
  453. X            break;
  454. X        case 1:         /* verbose */
  455. X            printf(
  456. X              "%s\n%7lu         %7lu %3d%%                              %-7u
  457. V\n",
  458. X              " ------          ------  ---                              ---
  459. V----",
  460. X              tot_ucsize, tot_csize, ratio / 10, members);
  461. X        `7D
  462. X#endif /* ?MSWIN */
  463. X#ifdef OS2
  464. X        if (tot_eafiles && tot_easize)
  465. X            printf("\n%ld file%s %ld bytes of EA's attached.\n", tot_eafiles
  466. V,`20
  467. X              tot_eafiles == 1 ? " has" : "s have a total of", tot_easize);
  468. X#endif
  469. X    `7D
  470. X/*--------------------------------------------------------------------------
  471. V-
  472. X    Double check that we're back at the end-of-central-directory record.
  473. X  --------------------------------------------------------------------------
  474. V-*/
  475. X
  476. X    readbuf(sig, 4);
  477. X    if (strncmp(sig, end_central_sig, 4)) `7B     /* just to make sure again
  478. V */
  479. X        fprintf(stderr, EndSigMsg);  /* didn't find end-of-central-dir sig *
  480. V/
  481. X/*      fprintf(stderr, ReportMsg);   */
  482. X        error_in_archive = 1;        /* 1:  warning error */
  483. X    `7D
  484. X    return error_in_archive;
  485. X
  486. X`7D /* end function list_files() */
  487. X
  488. X
  489. X
  490. X
  491. X
  492. X/**************************************/
  493. X/*  Function process_cdir_file_hdr()  */
  494. X/**************************************/
  495. X
  496. Xint process_cdir_file_hdr()    /* return PK-type error code */
  497. X`7B
  498. X    cdir_byte_hdr byterec;
  499. X
  500. X
  501. X/*--------------------------------------------------------------------------
  502. V-
  503. X    Read the next central directory entry and do any necessary machine-type
  504. X    conversions (byte ordering, structure padding compensation--do so by
  505. X    copying the data from the array into which it was read (byterec) to the
  506. X    usable struct (crec)).
  507. X  --------------------------------------------------------------------------
  508. V-*/
  509. X
  510. X    if (readbuf((char *) byterec, CREC_SIZE) <= 0)
  511. X        return 51;   /* 51:  unexpected EOF */
  512. X
  513. X    crec.version_made_by`5B0`5D = byterec`5BC_VERSION_MADE_BY_0`5D;
  514. X    crec.version_made_by`5B1`5D = byterec`5BC_VERSION_MADE_BY_1`5D;
  515. X    crec.version_needed_to_extract`5B0`5D = byterec`5BC_VERSION_NEEDED_TO_EX
  516. VTRACT_0`5D;
  517. X    crec.version_needed_to_extract`5B1`5D = byterec`5BC_VERSION_NEEDED_TO_EX
  518. VTRACT_1`5D;
  519. X
  520. X    crec.general_purpose_bit_flag =
  521. X        makeword(&byterec`5BC_GENERAL_PURPOSE_BIT_FLAG`5D);
  522. X    crec.compression_method =
  523. X        makeword(&byterec`5BC_COMPRESSION_METHOD`5D);
  524. X    crec.last_mod_file_time =
  525. X        makeword(&byterec`5BC_LAST_MOD_FILE_TIME`5D);
  526. X    crec.last_mod_file_date =
  527. X        makeword(&byterec`5BC_LAST_MOD_FILE_DATE`5D);
  528. X    crec.crc32 =
  529. X        makelong(&byterec`5BC_CRC32`5D);
  530. X    crec.compressed_size =
  531. X        makelong(&byterec`5BC_COMPRESSED_SIZE`5D);
  532. X    crec.uncompressed_size =
  533. X        makelong(&byterec`5BC_UNCOMPRESSED_SIZE`5D);
  534. X    crec.filename_length =
  535. X        makeword(&byterec`5BC_FILENAME_LENGTH`5D);
  536. X    crec.extra_field_length =
  537. X        makeword(&byterec`5BC_EXTRA_FIELD_LENGTH`5D);
  538. X    crec.file_comment_length =
  539. X        makeword(&byterec`5BC_FILE_COMMENT_LENGTH`5D);
  540. X    crec.disk_number_start =
  541. X        makeword(&byterec`5BC_DISK_NUMBER_START`5D);
  542. X    crec.internal_file_attributes =
  543. X        makeword(&byterec`5BC_INTERNAL_FILE_ATTRIBUTES`5D);
  544. X    crec.external_file_attributes =
  545. X        makelong(&byterec`5BC_EXTERNAL_FILE_ATTRIBUTES`5D);  /* LONG, not wo
  546. Vrd! */
  547. X    crec.relative_offset_local_header =
  548. X        makelong(&byterec`5BC_RELATIVE_OFFSET_LOCAL_HEADER`5D);
  549. X
  550. X    pInfo->hostnum = MIN(crec.version_made_by`5B1`5D, NUM_HOSTS);
  551. X/*  extnum = MIN(crec.version_needed_to_extract`5B1`5D, NUM_HOSTS); */
  552. X    methnum = MIN(crec.compression_method, NUM_METHODS);
  553. X    if (methnum == NUM_METHODS)
  554. X        sprintf(unkn, "Unk:%03d", crec.compression_method);
  555. X
  556. X/*--------------------------------------------------------------------------
  557. V-
  558. X    Set flag for lowercase conversion of filename, depending on which OS the
  559. X    file is coming from.  This section could be ifdef'd if some people have
  560. X    come to love DOS uppercase filenames under Unix...but really, guys, get
  561. X    a life. :)  NOTE THAT ALL SYSTEM NAMES NOW HAVE TRAILING UNDERSCORES!!!
  562. X    This is to prevent interference with compiler command-line defines such
  563. X    as -DUNIX, for example, which are then used in "#ifdef UNIX" constructs.
  564. X  --------------------------------------------------------------------------
  565. V-*/
  566. X
  567. X    pInfo->lcflag = 0;
  568. X    if (!U_flag)   /* as long as user hasn't specified case-preservation */
  569. X        switch (pInfo->hostnum) `7B
  570. X            case DOS_OS2_FAT_:
  571. X        /*  case VMS_:              VMS Zip converts filenames to lowercase
  572. V */
  573. X            case VM_CMS_:           /* all caps? */
  574. X            case CPM_:              /* like DOS, right? */
  575. X        /*  case ATARI_:            ? */
  576. X        /*  case Z_SYSTEM_:         ? */
  577. X        /*  case TOPS20_:           (if we had such a thing...) */
  578. X                pInfo->lcflag = 1;  /* convert filename to lowercase */
  579. X                break;
  580. X
  581. X            default:                /* AMIGA_, UNIX_, (ATARI_), OS2_HPFS_, *
  582. V/
  583. X                break;              /*   MAC_, (Z_SYSTEM_):  no conversion *
  584. V/
  585. X        `7D
  586. X
  587. X    return 0;
  588. X
  589. X`7D /* end function process_cdir_file_hdr() */
  590. X
  591. X
  592. X
  593. X
  594. X
  595. X/***************************************/
  596. X/*  Function process_local_file_hdr()  */
  597. X/***************************************/
  598. X
  599. Xint process_local_file_hdr()    /* return PK-type error code */
  600. X`7B
  601. X    local_byte_hdr byterec;
  602. X
  603. X
  604. X/*--------------------------------------------------------------------------
  605. V-
  606. X    Read the next local file header and do any necessary machine-type con-
  607. X    versions (byte ordering, structure padding compensation--do so by copy-
  608. X    ing the data from the array into which it was read (byterec) to the
  609. X    usable struct (lrec)).
  610. X  --------------------------------------------------------------------------
  611. V-*/
  612. X
  613. X    if (readbuf((char *) byterec, LREC_SIZE) <= 0)
  614. X        return 51;   /* 51:  unexpected EOF */
  615. X
  616. X    lrec.version_needed_to_extract`5B0`5D = byterec`5BL_VERSION_NEEDED_TO_EX
  617. VTRACT_0`5D;
  618. X    lrec.version_needed_to_extract`5B1`5D = byterec`5BL_VERSION_NEEDED_TO_EX
  619. VTRACT_1`5D;
  620. X
  621. X    lrec.general_purpose_bit_flag = makeword(&byterec`5BL_GENERAL_PURPOSE_BI
  622. VT_FLAG`5D);
  623. X    lrec.compression_method = makeword(&byterec`5BL_COMPRESSION_METHOD`5D);
  624. X    lrec.last_mod_file_time = makeword(&byterec`5BL_LAST_MOD_FILE_TIME`5D);
  625. X    lrec.last_mod_file_date = makeword(&byterec`5BL_LAST_MOD_FILE_DATE`5D);
  626. X    lrec.crc32 = makelong(&byterec`5BL_CRC32`5D);
  627. X    lrec.compressed_size = makelong(&byterec`5BL_COMPRESSED_SIZE`5D);
  628. X    lrec.uncompressed_size = makelong(&byterec`5BL_UNCOMPRESSED_SIZE`5D);
  629. X    lrec.filename_length = makeword(&byterec`5BL_FILENAME_LENGTH`5D);
  630. X    lrec.extra_field_length = makeword(&byterec`5BL_EXTRA_FIELD_LENGTH`5D);
  631. X
  632. X    csize = (longint) lrec.compressed_size;
  633. X    ucsize = (longint) lrec.uncompressed_size;
  634. X
  635. X    if ((lrec.general_purpose_bit_flag & 8) != 0) `7B
  636. X        /* Can't trust local header, use central directory: */
  637. X      lrec.crc32 = pInfo->crc;
  638. X        lrec.compressed_size = pInfo->compr_size;
  639. X        csize = (longint) lrec.compressed_size;
  640. X    `7D
  641. X
  642. X    return 0;                 /* 0:  no error */
  643. X
  644. X`7D /* end function process_local_file_hdr() */
  645. $ CALL UNPACK [.UNZIP50]UNZIP.C;1 157894339
  646. $ create 'f'
  647. X
  648. XUNZIP(1)                 USER COMMANDS                   UNZIP(1)
  649. X
  650. XNAME
  651. X     unzip - list/test/extract from a ZIP archive file
  652. X
  653. XSYNOPSIS
  654. X     unzip `5B -cflptuvxz`5BajnoqUV`5D `5D file`5B.zip`5D `5Bfilespec ...`5D
  655. X
  656. XARGUMENTS
  657. X     file`5B.zip`5D  Path of the ZIP archive.  The suffix `60`60.zip'' is
  658. X                 applied  if  the  file specified does not exist.
  659. X                 Note that self-extracting  ZIP  files  are  sup-
  660. X                 ported;  just  specify the `60`60.exe'' suffix your-
  661. X                 self.
  662. X
  663. X     `5Bfilespec`5D  An optional list of archive members to  be  pro-
  664. X                 cessed.  Expressions may be used to match multi-
  665. X                 ple members; be sure to quote  expressions  that
  666. X                 contain  characters interpreted by the operating
  667. X                 system.  See  DESCRIPTION   (below)   for   more
  668. X                 details.
  669. X
  670. XOPTIONS
  671. X     -c  extract files to stdout/screen (`60`60CRT'')
  672. X     -f  freshen existing files (replace if newer); create none
  673. X     -l  list archive files (short format)
  674. X     -p  extract files to pipe; no informational messages
  675. X     -t  test archive files
  676. X     -u  update existing files; create new ones if needed
  677. X     -v  list archive files (verbose format)
  678. X     -x  extract files in archive (default)
  679. X     -z  display only the archive comment
  680. X
  681. XMODIFIERS
  682. X     -a  convert to MS-DOS textfile format (CR  LF),  Mac  format
  683. X         (CR),  Unix/VMS  format  (LF),  OR from ASCII to EBCDIC,
  684. X         depending on your system (only use for TEXT files!)
  685. X     -j  junk paths (don't recreate  archive's  directory  struc-
  686. X         ture)
  687. X     -n  never overwrite existing files; don't prompt
  688. X     -o  OK to overwrite files without prompting
  689. X     -q  perform operations quietly (-qq => even quieter)
  690. X     -s  `5BOS/2,  MS-DOS`5D  allow  spaces   in   filenames   (e.g.,
  691. X         `60`60EA DATA. SF'')
  692. X     -U  leave filenames uppercase if created under MS-DOS,  VMS,
  693. X         etc.
  694. X     -V  retain (VMS) file version numbers
  695. X     -X  `5BVMS`5D  restore  owner/protection   info   (may   require
  696. X         privileges)
  697. X
  698. XDESCRIPTION
  699. X     UnZip will list, test, or extract from a ZIP  archive,  com-
  700. X     monly  found on MSDOS systems.  Archive member extraction is
  701. X     implied by the absence of the -c,  -p,  -t,  -l,  -v  or  -z
  702. X
  703. XInfo-ZIP          Last change: 21 Aug 92 (v5.0)                 1
  704. X
  705. XUNZIP(1)                 USER COMMANDS                   UNZIP(1)
  706. X
  707. X     options.    All  archive  members  are  processed  unless  a
  708. X     filespec is provided to specify  a  subset  of  the  archive
  709. X     members.   The  filespec  is similar to an egrep expression,
  710. X     and may contain:
  711. X
  712. X     *      matches a sequence of 0 or more characters
  713. X     ?      matches exactly 1 character
  714. X     \nnn   matches the character having octal code nnn
  715. X     `5B...`5D  matches any single character found inside the  brack-
  716. X            ets; ranges are specified by a beginning character, a
  717. X            hyphen, and an ending character.  If  an  exclamation
  718. X            point  or  a  carat  (`60!'  or  `60`5E')  follows the left
  719. X            bracket, then the range of characters matched is com-
  720. X            plemented  with  respect  to  the ASCII character set
  721. X            (that is, anything except the characters  inside  the
  722. X            brackets is considered a match).
  723. X
  724. XENVIRONMENT OPTIONS
  725. X     UnZip's default behavior may be modified via options  placed
  726. X     in  an  environment  variable.   This  can  be done with any
  727. X     option, but it is probably most useful with the -q,  -o,  or
  728. X     -n modifiers:  in order to make UnZip quieter by default, or
  729. X     to make it always overwrite or never overwrite files  as  it
  730. X     extracts them.  For example, to make UnZip act as quietly as
  731. X     possible, only reporting errors, one would use  one  of  the
  732. X     following commands:
  733. X
  734. X           setenv UNZIP -qq           Unix C shell
  735. X
  736. X           UNZIP=-qq; export UNZIP    Unix Bourne shell
  737. X
  738. X           set UNZIP=-qq              OS/2 or MS-DOS
  739. X
  740. X           define UNZIP_OPTS "-qq"    VMS (quotes for LOWERCASE)
  741. X
  742. X     Environment options are, in effect, considered  to  be  just
  743. X     like  any  other  command-line options, except that they are
  744. X     effectively the first options on the command line.  To over-
  745. X     ride  an  environment option, one may use the `60`60minus opera-
  746. X     tor'' to remove it.  For instance, to override  one  of  the
  747. X     quiet-flags in the example above, use the command
  748. X
  749. X           unzip --q`5Bother options`5D zipfile
  750. X
  751. X     The first hyphen is the normal  switch  character,  and  the
  752. X     second  is  a  minus sign, acting on the q option.  Thus the
  753. X     effect here is to cancel a single quantum of quietness.   To
  754. X     cancel both quiet flags, two (or more) minuses may be used:
  755. X
  756. X           unzip -x--q zipfile
  757. X
  758. XInfo-ZIP          Last change: 21 Aug 92 (v5.0)                 2
  759. X
  760. XUNZIP(1)                 USER COMMANDS                   UNZIP(1)
  761. X
  762. X     or
  763. X
  764. X           unzip ---qx zipfile
  765. X
  766. X     (the two are equivalent).  This may seem awkward or  confus-
  767. X     ing,  but it is reasonably intuitive:  just ignore the first
  768. X     hyphen and go from there.  It is also  consistent  with  the
  769. X     behavior of Unix nice(1).
  770. X
  771. XEXAMPLES
  772. X     To  use  UnZip  to  extract  all  members  of  the   archive
  773. X     letters.zip, creating any directories as necessary:
  774. X
  775. X           unzip letters
  776. X
  777. X     To extract all members of letters.zip to the current  direc-
  778. X     tory:
  779. X
  780. X           unzip -j letters
  781. X
  782. X     To test letters.zip, printing only a summary  message  indi-
  783. X     cating whether the archive is OK or not:
  784. X
  785. X           unzip -tq letters
  786. X
  787. X     To extract to standard output  all  members  of  letters.zip
  788. X     whose  names  end  in `60`60.tex'', converting to the local end-
  789. X     of-line convention and piping the output into more(1):
  790. X
  791. X           unzip -ca letters \*.tex `7C more
  792. X
  793. X     (The backslash before the asterisk is only required  if  the
  794. X     shell  expands  wildcards,  as  in Unix; double quotes could
  795. X     have been used instead, as in the source example below.)  To
  796. X     extract  the  binary  file paper1.dvi to standard output and
  797. X     pipe it to a printing program:
  798. X
  799. X           unzip -p articles paper1.dvi `7C dvips
  800. X
  801. X     To extract all FORTRAN and C source  files--*.f,  *.c,  *.h,
  802. X     Makefile  (the  double quotes are necessary only in Unix and
  803. X     only if globbing is turned on):
  804. X
  805. X           unzip source.zip "*.`5Bfch`5D" Makefile
  806. X
  807. X     To extract only newer versions of the files already  in  the
  808. X     current  directory,  without  querying (NOTE:  be careful of
  809. X     unzipping in one timezone a zipfile created in  another--ZIP
  810. X     archives  contain  no  timezone information, and a `60`60newer''
  811. X     file from an eastern timezone may, in fact, be older):
  812. X
  813. XInfo-ZIP          Last change: 21 Aug 92 (v5.0)                 3
  814. X
  815. XUNZIP(1)                 USER COMMANDS                   UNZIP(1)
  816. X
  817. X           unzip -fo sources
  818. X
  819. X     To extract newer  versions  of  the  files  already  in  the
  820. X     current  directory and to create any files not already there
  821. X     (same caveat as previous example):
  822. X
  823. X           unzip -uo sources
  824. X
  825. X     In the last five examples, assume that UNZIP  or  UNZIP_OPTS
  826. X     is set to -q.  To do a singly quiet listing:
  827. X
  828. X           unzip -l file
  829. X
  830. X     To do a doubly quiet listing:
  831. X
  832. X           unzip -ql file
  833. X
  834. X     To do a standard listing:
  835. X
  836. X           unzip --ql file
  837. X
  838. X     or
  839. X
  840. X           unzip -l-q file
  841. X
  842. X     or
  843. X
  844. X           unzip -l--q file
  845. X
  846. X     (extra minuses don't hurt).
  847. X
  848. XTIPS
  849. X     The current maintainer, being a lazy  sort,  finds  it  very
  850. X     useful to define an alias `60`60tt'' for `60`60unzip -tq''.  One may
  851. X     then simply type `60`60tt zipfile'' to test the  archive,  some-
  852. X     thing  which  one  ought  make  a habit of doing.  With luck
  853. X     UnZip will report `60`60No  errors  detected  in  zipfile.zip,''
  854. X     after which one may breathe a sigh of relief.
  855. X
  856. XSEE ALSO
  857. X     funzip(1),  zip(1),  zipcloak(1),  zipinfo(1),   zipnote(1),
  858. X     zipsplit(1)
  859. X
  860. XAUTHORS
  861. X     Samuel H. Smith, Carl Mascott, David P. Kirschbaum, Greg  R.
  862. X     Roelofs,  Mark  Adler,  Kai  Uwe  Rommel, Igor Mandrichenko,
  863. X     Johnny Lee, Jean-loup Gailly; Glenn  Andrews,  Joel  Aycock,
  864. X     Allan  Bjorklund,  James  Birdsall,  Wim Bonner, John Cowan,
  865. X     Frank da Cruz, Bill Davidsen, Arjan de Vet, James Dugal, Jim
  866. X     Dumser,  Mark  Edwards, David Feinleib, Mike Freeman, Hunter
  867. X     Goatley, Robert Heath, Dave  Heiland,  Larry  Jones,  Kjetil
  868. X     J`7Bob  Kemp, J. Kercheval, Alvin Koh, Bo Kullmar, Johnny Lee,
  869. X
  870. XInfo-ZIP          Last change: 21 Aug 92 (v5.0)                 4
  871. X
  872. XUNZIP(1)                 USER COMMANDS                   UNZIP(1)
  873. X
  874. X     Warner Losh, Fulvio Marino, Gene McManus, Joe Meadows,  Mike
  875. X     O'Carroll,  Humberto  Ortiz-Zuazaga,  Piet W. Plomp, Antonio
  876. X     Querubin Jr., Steve Salisbury,  Georg  Sassen,  Jon  Saxton,
  877. X     Hugh Schmidt, Martin Schulz, Charles Scripter, Chris Seaman,
  878. X     Richard Seay, Alex Sergejew, Cliff Stanford,  Onno  van  der
  879. X     Linden, Jim Van Zandt, Antoine Verheijen, Paul Wells.
  880. X
  881. XVERSIONS
  882. X     v1.2  15 Mar 89  Samuel H. Smith
  883. X     v2.0   9 Sep 89  Samuel H. Smith
  884. X     v2.x  fall 1989  many Usenet contributors
  885. X     v3.0   1 May 90  Info-ZIP (DPK, consolidator)
  886. X     v3.1  15 Aug 90  Info-ZIP (DPK, consolidator)
  887. X     v4.0   1 Dec 90  Info-ZIP (GRR, maintainer)
  888. X     v4.1  12 May 91  Info-ZIP
  889. X     v4.2  20 Mar 92  Info-ZIP (zip-bugs subgroup; GRR, maint.)
  890. X     v5.0  21 Aug 92  Info-ZIP (zip-bugs subgroup; GRR, maint.)
  891. X
  892. XInfo-ZIP          Last change: 21 Aug 92 (v5.0)                 5
  893. X
  894. $ CALL UNPACK [.UNZIP50]UNZIP.DOC;1 1762853046
  895. $ create 'f'
  896. X/*--------------------------------------------------------------------------
  897. V-
  898. X
  899. X  unzip.h
  900. X
  901. X  This header file is used by all of the unzip source files.  Its contents
  902. X  are divided into seven more-or-less separate sections:  predefined macros,
  903. X  OS-dependent includes, (mostly) OS-independent defines, typedefs, function
  904. V`20
  905. X  prototypes (or "prototypes," in the case of non-ANSI compilers), macros,`2
  906. V0
  907. X  and global-variable declarations.
  908. X
  909. X  --------------------------------------------------------------------------
  910. V-*/
  911. X
  912. X
  913. X
  914. X/*****************************************/
  915. X/*  Predefined, Machine-specific Macros  */
  916. X/*****************************************/
  917. X
  918. X#if (defined(__GO32__) && defined(unix))   /* DOS extender */
  919. X#  undef unix
  920. X#endif
  921. X
  922. X#if (defined(unix) && !defined(UNIX))
  923. X#  define UNIX
  924. X#endif /* unix && !UNIX */
  925. X
  926. X/* Much of the following is swiped from zip's tailor.h: */
  927. X
  928. X/* define MSDOS for Turbo C (unless OS/2) and Power C as well as Microsoft C
  929. V */
  930. X#ifdef __POWERC
  931. X#  define __TURBOC__
  932. X#  define MSDOS
  933. X#endif /* __POWERC */
  934. X#if (defined(__TURBOC__) && defined(__MSDOS__) && !defined(MSDOS))
  935. X#  define MSDOS
  936. X#endif
  937. X
  938. X/* use prototypes and ANSI libraries if __STDC__, or Microsoft or Borland C,
  939. X * or Silicon Graphics, or Convex, or IBM C Set/2, or GNU gcc under emx, or
  940. X * or Watcom C, or Macintosh, or Windows NT.
  941. X */
  942. X#if (__STDC__ `7C`7C defined(MSDOS) `7C`7C defined(sgi) `7C`7C defined(CONVE
  943. VX))
  944. X#  ifndef PROTO
  945. X#    define PROTO
  946. X#  endif
  947. X#  define MODERN
  948. X#endif
  949. X#if (defined(__IBMC__) `7C`7C defined(__EMX__) `7C`7C defined(__WATCOMC__))
  950. X#  ifndef PROTO
  951. X#    define PROTO
  952. X#  endif
  953. X#  define MODERN
  954. X#endif
  955. X#if (defined(THINK_C) `7C`7C defined(MPW) `7C`7C defined(WIN32))
  956. X#  ifndef PROTO
  957. X#    define PROTO
  958. X#  endif
  959. X#  define MODERN
  960. X#endif
  961. X
  962. X/* turn off prototypes if requested */
  963. X#if (defined(NOPROTO) && defined(PROTO))
  964. X#  undef PROTO
  965. X#endif
  966. X
  967. X/* used to remove arguments in function prototypes for non-ANSI C */
  968. X#ifdef PROTO
  969. X#  define OF(a) a
  970. X#else /* !PROTO */
  971. X#  define OF(a) ()
  972. X#endif /* ?PROTO */
  973. X
  974. X#if (defined(ultrix) `7C`7C defined(bsd4_2) `7C`7C defined(sun) `7C`7C defin
  975. Ved(pyr))
  976. X#  if (!defined(BSD) && !defined(__SYSTEM_FIVE) && !defined(SYSV))
  977. X#    define BSD
  978. X#  endif /* !BSD && !__SYSTEM_FIVE && !SYSV */
  979. X#endif /* ultrix `7C`7C bsd4_2 `7C`7C sun `7C`7C pyr */
  980. X
  981. X#if (defined(CONVEX) `7C`7C defined(CRAY) `7C`7C defined(__SYSTEM_FIVE))
  982. X#  ifndef TERMIO
  983. X#    define TERMIO
  984. X#  endif /* !TERMIO */
  985. X#endif /* CONVEX `7C`7C CRAY `7C`7C __SYSTEM_FIVE */
  986. X
  987. X#ifdef pyr  /* Pyramid */
  988. X#  ifndef ZMEM
  989. X#    define ZMEM
  990. X#  endif /* !ZMEM */
  991. X#endif /* pyr */
  992. X
  993. X#ifdef CRAY
  994. X#  ifdef ZMEM
  995. X#    undef ZMEM
  996. X#  endif /* ZMEM */
  997. X#endif /* CRAY */
  998. X
  999. X/* the i386 test below is to catch SCO Unix (which has redefinition
  1000. X * warnings if param.h is included), but it probably doesn't hurt if
  1001. X * other 386 Unixes get nailed, too...except now that 386BSD and BSDI
  1002. X * exist.  Sigh.  <sys/param.h> is mostly included for "BSD", I think.
  1003. X * `5BAn alternate fix for SCO Unix is below.`5D
  1004. X */
  1005. X#if (defined(MINIX) `7C`7C (defined(i386) && defined(unix)))
  1006. X#  define NO_PARAM_H
  1007. X#endif /* MINIX `7C`7C (i386 && unix) */
  1008. X
  1009. X
  1010. X
  1011. X
  1012. X
  1013. X/***************************/
  1014. X/*  OS-Dependent Includes  */
  1015. X/***************************/
  1016. X
  1017. X#ifndef MINIX            /* Minix needs it after all the other includes (?)
  1018. V */
  1019. X#  include <stdio.h>
  1020. X#endif
  1021. X#include <ctype.h>       /* skip for VMS, to use tolower() function? */
  1022. X#include <errno.h>       /* used in mapname() */
  1023. X#ifndef NO_ERRNO
  1024. X#  define DECLARE_ERRNO  /* everybody except MSC 6.0, SCO cc, Watcom C/386 *
  1025. V/
  1026. X#endif /* !NO_ERRNO */
  1027. X#ifdef VMS
  1028. X#  include <types.h>     /* (placed up here instead of in VMS section below
  1029. V */
  1030. X#  include <stat.h>      /* because types.h is used in some other headers) *
  1031. V/
  1032. X#else /* !VMS */
  1033. X#  if !defined(THINK_C) && !defined(MPW)
  1034. X#    include <sys/types.h>                 /* off_t, time_t, dev_t, ... */
  1035. X#    include <sys/stat.h>
  1036. X#  endif /* !THINK_C && !MPW */
  1037. X#endif /* ?VMS */
  1038. X
  1039. X#ifdef MODERN
  1040. X#  if (!defined(M_XENIX) && !(defined(__GNUC__) && defined(sun)))
  1041. X#    include <stddef.h>
  1042. X#  endif
  1043. X#  if (!defined(__GNUC__) && !defined(apollo))   /* both define __STDC__ */
  1044. X#    include <stdlib.h>    /* standard library prototypes, malloc(), etc. */
  1045. X#  else
  1046. X#    ifdef __EMX__
  1047. X#      include <stdlib.h>  /* emx IS gcc but has stdlib.h */
  1048. X#    endif
  1049. X#  endif
  1050. X#  include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  1051. X   typedef size_t extent;
  1052. X   typedef void voidp;
  1053. X#else /* !MODERN */
  1054. X   char *malloc();
  1055. X   char *strchr(), *strrchr();
  1056. X   long lseek();
  1057. X   typedef unsigned int extent;
  1058. X#  define void int
  1059. X   typedef char voidp;
  1060. X#endif /* ?MODERN */
  1061. X
  1062. X/* this include must be down here for SysV.4, for some reason... */
  1063. X#include <signal.h>      /* used in unzip.c, file_io.c */
  1064. X
  1065. X
  1066. X
  1067. X/*--------------------------------------------------------------------------
  1068. V-
  1069. X    Next, a word from our Unix (mostly) sponsors:
  1070. X  --------------------------------------------------------------------------
  1071. V-*/
  1072. X
  1073. X#ifdef UNIX
  1074. X#  ifdef AMIGA
  1075. X#    include <libraries/dos.h>
  1076. X#  else /* !AMIGA */
  1077. X#    ifndef NO_PARAM_H
  1078. X#if 0  /* `5BGRR: this is an alternate fix for SCO's redefinition bug`5D */
  1079. X#      ifdef NGROUPS_MAX
  1080. X#        undef NGROUPS_MAX     /* SCO bug:  defined again in <param.h> */
  1081. X#      endif /* NGROUPS_MAX */
  1082. X#endif /* 0 */
  1083. X#      include <sys/param.h>   /* conflict with <sys/types.h>, some systems?
  1084. V */
  1085. X#    endif /* !NO_PARAM_H */
  1086. X#  endif /* ?AMIGA */
  1087. X
  1088. X#  ifndef BSIZE
  1089. X#    ifdef MINIX
  1090. X#      define BSIZE   1024
  1091. X#    else /* !MINIX */
  1092. X#      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
  1093. X#    endif /* ?MINIX */
  1094. X#  endif
  1095. X
  1096. X#  ifndef BSD
  1097. X#    if (!defined(AMIGA) && !defined(MINIX))
  1098. X#      define NO_MKDIR           /* for mapname() */
  1099. X#    endif /* !AMIGA && !MINIX */
  1100. X#    include <time.h>
  1101. X     struct tm *gmtime(), *localtime();
  1102. X#  else   /* BSD */
  1103. X#    include <sys/time.h>
  1104. X#    include <sys/timeb.h>
  1105. X#    ifdef _AIX
  1106. X#      include <time.h>
  1107. X#    endif
  1108. X#  endif
  1109. X
  1110. X#else   /* !UNIX */
  1111. X#  define BSIZE   512               /* disk block size */
  1112. X#endif /* ?UNIX */
  1113. X
  1114. X#if (defined(V7) `7C`7C defined(BSD))
  1115. X#  define strchr    index
  1116. X#  define strrchr   rindex
  1117. X#endif
  1118. X
  1119. X/*--------------------------------------------------------------------------
  1120. V-
  1121. X    And now, our MS-DOS and OS/2 corner:
  1122. X  --------------------------------------------------------------------------
  1123. V-*/
  1124. X
  1125. X#ifdef __TURBOC__
  1126. X#  define DOS_OS2
  1127. X#  include <sys/timeb.h>      /* for structure ftime
  1128. V                        */
  1129. X#  ifndef __BORLANDC__        /* there appears to be a bug (?) in Borland's
  1130. V */
  1131. X#    include <mem.h>          /*   MEM.H related to __STDC__ and far poin-
  1132. V  */
  1133. X#  endif                      /*   ters. (dpk)  `5Bmem.h included for memcpy
  1134. V`5D */
  1135. X#  include <dos.h>            /* for REGS macro (at least for Turbo C 2.0)
  1136. V  */
  1137. X#else                         /* NOT Turbo C (or Power C)...
  1138. V                */
  1139. X#  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's
  1140. V   */
  1141. X#    ifndef MSC               /*   Microsoft's compiler and fake the ID, if
  1142. V */
  1143. X#      define MSC             /*   necessary (it is in 5.0; apparently not
  1144. V  */
  1145. X#    endif                    /*   in 5.1 and 6.0)
  1146. V                          */
  1147. X#    include <dos.h>          /* for _dos_setftime()
  1148. V                        */
  1149. X#  endif
  1150. X#endif
  1151. X
  1152. X#if (defined(__IBMC__) && defined(__OS2__))
  1153. X#  define DOS_OS2
  1154. X#  define S_IFMT 0xF000
  1155. X#  define timezone _timezone
  1156. X#endif
  1157. X
  1158. X#ifdef __WATCOMC__
  1159. X#  define DOS_OS2
  1160. X#  define __32BIT__
  1161. X#  ifdef DECLARE_ERRNO
  1162. X#    undef DECLARE_ERRNO
  1163. X#  endif
  1164. X#  undef far
  1165. X#  define far
  1166. X#endif
  1167. X
  1168. X#ifdef __EMX__
  1169. X#  define DOS_OS2
  1170. X#  define __32BIT__
  1171. X#  define far
  1172. X#endif /* __EMX__ */
  1173. X
  1174. X#ifdef MSC                    /* defined for all versions of MSC now
  1175. V         */
  1176. X#  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2
  1177. V    */
  1178. X#  if (defined(_MSC_VER) && (_MSC_VER >= 600))    /* new with 5.1 or 6.0 ...
  1179. V */
  1180. X#    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link
  1181. V   */
  1182. X#  endif                      /*   library (or something)--incompatible with
  1183. V */
  1184. X#endif                        /*   the usual "extern int errno" declaration
  1185. V  */
  1186. X
  1187. X#ifdef DOS_OS2                /* defined for all MS-DOS and OS/2 compilers
  1188. V   */
  1189. X#  include <io.h>             /* lseek(), open(), setftime(), dup(), creat()
  1190. V */
  1191. X#  include <time.h>           /* localtime() */
  1192. X#endif
  1193. X
  1194. X#ifdef OS2                    /* defined for all OS/2 compilers */
  1195. X#  ifdef isupper
  1196. X#    undef isupper
  1197. X#  endif
  1198. X#  ifdef tolower
  1199. X#    undef tolower
  1200. X#  endif
  1201. X#  define isupper(x)   IsUpperNLS((unsigned char)(x))
  1202. X#  define tolower(x)   ToLowerNLS((unsigned char)(x))
  1203. X#endif
  1204. X
  1205. X#ifdef WIN32
  1206. X#  include <io.h>             /* read(), open(), etc. */
  1207. X#  include <time.h>
  1208. X#  include <memory.h>
  1209. X#  include <direct.h>         /* mkdir() */
  1210. X#  ifdef FILE_IO_C
  1211. X#    include <fcntl.h>
  1212. X#    include <conio.h>
  1213. X#    include <sys\types.h>
  1214. X#    include <sys\utime.h>
  1215. X#    include <windows.h>
  1216. X#    define DOS_OS2
  1217. X#    define getch() getchar()
  1218. X#  endif
  1219. X#endif
  1220. X
  1221. X/*--------------------------------------------------------------------------
  1222. V-
  1223. X    Followed by some VMS (mostly) stuff:
  1224. X  --------------------------------------------------------------------------
  1225. V-*/
  1226. X
  1227. X#ifdef VMS
  1228. X#  include <time.h>               /* the usual non-BSD time functions */
  1229. X#  include <file.h>               /* same things as fcntl.h has */
  1230. X#  include <rms.h>
  1231. X#  define _MAX_PATH NAM$C_MAXRSS  /* to define FILNAMSIZ below */
  1232. X#  define UNIX                    /* can share most of same code from now on
  1233. V */
  1234. X#  define RETURN    return_VMS    /* VMS interprets return codes incorrectly
  1235. V */
  1236. X#else /* !VMS */
  1237. X#  ifndef THINK_C
  1238. X#    define RETURN  return        /* only used in main() */
  1239. X#  else
  1240. X#    define RETURN(v) `7B int n;\
  1241. X                        n = (v);\
  1242. X                        fprintf(stderr, "\npress <return> to continue ");\
  1243. X                        while (getc(stdin) != '\n');\
  1244. X                        putc('\n', stderr);\
  1245. X                        InitCursor();\
  1246. X                        goto start;\
  1247. X                      `7D
  1248. X#  endif
  1249. X#  ifdef V7
  1250. X#    define O_RDONLY  0
  1251. X#    define O_WRONLY  1
  1252. X#    define O_RDWR    2
  1253. X#  else /* !V7 */
  1254. X#    ifdef MTS
  1255. X#      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  1256. X#      include <timeb.h>
  1257. X#      include <time.h>
  1258. X#    else /* !MTS */
  1259. X#      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
  1260. X#        include <sys/fcntl.h>
  1261. X#        define SHORT_NAMES
  1262. X#        define tzset  settz
  1263. X#      else /* !COHERENT */
  1264. X#        include <fcntl.h>      /* O_BINARY for open() w/o CR/LF translation
  1265. V */
  1266. X#      endif /* ?COHERENT */
  1267. X#    endif /* ?MTS */
  1268. X#  endif /* ?V7 */
  1269. X#endif /* ?VMS */
  1270. X
  1271. X#if (defined(MSDOS) `7C`7C defined(VMS))
  1272. X#  define DOS_VMS
  1273. X#endif
  1274. X
  1275. X/*--------------------------------------------------------------------------
  1276. V-
  1277. X    And some Mac stuff for good measure:
  1278. X  --------------------------------------------------------------------------
  1279. V-*/
  1280. X
  1281. X#ifdef THINK_C
  1282. X#  define MACOS
  1283. X#  ifndef __STDC__            /* if Think C hasn't defined __STDC__ ... */
  1284. X#    define __STDC__ 1        /*   make sure it's defined: it needs it */
  1285. X#  else /* __STDC__ defined */
  1286. X#    if !__STDC__             /* sometimes __STDC__ is defined as 0; */
  1287. X#      undef __STDC__         /*   it needs to be 1 or required header */
  1288. X#      define __STDC__ 1      /*   files are not properly included. */
  1289. X#    endif /* !__STDC__ */
  1290. X#  endif /* ?defined(__STDC__) */
  1291. X#endif /* THINK_C */
  1292. X
  1293. X#ifdef MPW
  1294. X#  define MACOS
  1295. X#  include <Errors.h>
  1296. X#  include <Files.h>
  1297. X#  include <Memory.h>
  1298. X#  include <Quickdraw.h>
  1299. X#  include <ToolUtils.h>
  1300. X#  define CtoPstr c2pstr
  1301. X#  define PtoCstr p2cstr
  1302. X#  ifdef CR
  1303. X#    undef  CR
  1304. X#  endif
  1305. X#endif /* MPW */
  1306. X
  1307. X#ifdef MACOS
  1308. X#  define open(x,y) macopen(x,y, gnVRefNum, glDirID)
  1309. X#  define close macclose
  1310. X#  define read macread
  1311. X#  define write macwrite
  1312. X#  define lseek maclseek
  1313. X#  define creat(x,y) maccreat(x, gnVRefNum, glDirID, gostCreator, gostType)
  1314. X#  define stat(x,y) macstat(x,y,gnVRefNum, glDirID)
  1315. X
  1316. X#  ifndef isascii
  1317. X#    define isascii(c) ((unsigned char)(c) <= 0x3F)
  1318. X#  endif
  1319. X
  1320. X#  include "macstat.h"
  1321. X
  1322. Xtypedef struct _ZipExtraHdr `7B
  1323. X    unsigned short header;    /*    2 bytes */
  1324. X    unsigned short data;      /*    2 bytes */
  1325. X`7D ZIP_EXTRA_HEADER;
  1326. X
  1327. Xtypedef struct _MacInfoMin `7B
  1328. X    unsigned short header;    /*    2 bytes */
  1329. X    unsigned short data;      /*    2 bytes */
  1330. X    unsigned long signature;  /*    4 bytes */
  1331. X    FInfo finfo;              /*   16 bytes */
  1332. X    unsigned long lCrDat;     /*    4 bytes */
  1333. X    unsigned long lMdDat;     /*    4 bytes */
  1334. X    unsigned long flags ;     /*    4 bytes */
  1335. X    unsigned long lDirID;     /*    4 bytes */
  1336. X                              /*------------*/
  1337. X`7D MACINFOMIN;                 /* = 40 bytes for size of data */
  1338. X
  1339. Xtypedef struct _MacInfo `7B
  1340. X    unsigned short header;    /*    2 bytes */
  1341. X    unsigned short data;      /*    2 bytes */
  1342. +-+-+-+-+-+-+-+-  END  OF PART 11 +-+-+-+-+-+-+-+-
  1343.