home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume19 / unzip / part02 < prev    next >
Text File  |  1991-05-19  |  56KB  |  1,456 lines

  1. Newsgroups: comp.sources.misc
  2. From: David Kirschbaum <kirsch@usasoc.soc.mil>
  3. Subject:  v19i097:  unzip - Portable unzip v4.1, Part02/06
  4. Message-ID: <1991May20.012121.29183@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 5663abf4905d8ac21c5d4c91607a1baf
  6. Date: Mon, 20 May 1991 01:21:21 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: David Kirschbaum <kirsch@usasoc.soc.mil>
  10. Posting-number: Volume 19, Issue 97
  11. Archive-name: unzip/part02
  12. Supersedes: unzip-3.1: Volume 14, Issue 102-106
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  ./v41/VMS/fjndef.h ./v41/unzip.c.2 ./v41/unzip.h
  20. # Wrapped by kent@sparky on Sun May 19 19:40:39 1991
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 2 (of 6)."'
  24. if test -f './v41/VMS/fjndef.h' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'./v41/VMS/fjndef.h'\"
  26. else
  27.   echo shar: Extracting \"'./v41/VMS/fjndef.h'\" \(684 characters\)
  28.   sed "s/^X//" >'./v41/VMS/fjndef.h' <<'END_OF_FILE'
  29. X/* This header file was created by Joe Meadows, and is not copyrighted
  30. X   in any way. No guarantee is made as to the accuracy of the contents
  31. X   of this header file. This header file was last modified on Sep. 22th,
  32. X   1987. (Modified to include this statement) */
  33. X
  34. X#define FJN$M_ONLY_RU 1
  35. X#define FJN$M_RUJNL 2
  36. X#define FJN$M_BIJNL 4
  37. X#define FJN$M_AIJNL 8
  38. X#define FJN$M_ATJNL 16
  39. X#define FJN$M_NEVER_RU 32
  40. X#define FJN$M_JOURNAL_FILE 64
  41. X#define FJN$S_FJNDEF 1
  42. Xstruct fjndef  {
  43. X  unsigned fjn$v_only_ru : 1;
  44. X  unsigned fjn$v_rujnl : 1;
  45. X  unsigned fjn$v_bijnl : 1;
  46. X  unsigned fjn$v_aijnl : 1;
  47. X  unsigned fjn$v_atjnl : 1;
  48. X  unsigned fjn$v_never_ru : 1;
  49. X  unsigned fjn$v_journal_file:1;
  50. X} ;
  51. END_OF_FILE
  52.   if test 684 -ne `wc -c <'./v41/VMS/fjndef.h'`; then
  53.     echo shar: \"'./v41/VMS/fjndef.h'\" unpacked with wrong size!
  54.   fi
  55.   # end of './v41/VMS/fjndef.h'
  56. fi
  57. if test -f './v41/unzip.c.2' -a "${1}" != "-c" ; then 
  58.   echo shar: Will not clobber existing file \"'./v41/unzip.c.2'\"
  59. else
  60.   echo shar: Extracting \"'./v41/unzip.c.2'\" \(22093 characters\)
  61.   sed "s/^X//" >'./v41/unzip.c.2' <<'END_OF_FILE'
  62. X    less the end-of-central-directory record was on this disk, and we would
  63. X    not have gotten to this routine unless this is also the disk on which
  64. X    the central directory starts.  In practice, this had better be the ONLY
  65. X    disk in the archive, but maybe someday we'll add multi-disk support.
  66. X  ---------------------------------------------------------------------------*/
  67. X
  68. X    members_remaining = ecrec.total_entries_central_dir;
  69. X    while (members_remaining) {
  70. X        j = 0;
  71. X
  72. X        /*
  73. X         * Loop through files in central directory, storing offsets, file
  74. X         * attributes, and case-conversion flags until block size is reached.
  75. X         */
  76. X
  77. X        while (members_remaining && (j < DIR_BLKSIZ)) {
  78. X            --members_remaining;
  79. X
  80. X            if (readbuf(sig, 4) <= 0) {
  81. X                error_in_archive = 51;  /* 51:  unexpected EOF */
  82. X                members_remaining = 0;  /* ...so no more left to do */
  83. X                break;
  84. X            }
  85. X            if (strncmp(sig, CENTRAL_HDR_SIG, 4)) {  /* just to make sure */
  86. X                fprintf(stderr, CentSigMsg, j);  /* sig not found */
  87. X                fprintf(stderr, ReportMsg);   /* report to info-zip */
  88. X                error_in_archive = 3;   /* 3:  error in zipfile */
  89. X                members_remaining = 0;  /* ...so no more left to do */
  90. X                break;
  91. X            }
  92. X            /* (sets lcflag)-------v  */
  93. X            if ((error = process_central_file_header()) != 0) {
  94. X                error_in_archive = error;   /* only 51 (EOF) defined */
  95. X                members_remaining = 0;  /* ...so no more left to do */
  96. X                break;
  97. X            }
  98. X            if ((error = do_string(crec.filename_length, FILENAME)) != 0) {
  99. X                if (error > error_in_archive)
  100. X                    error_in_archive = error;
  101. X                if (error > 1) {  /* fatal:  no more left to do */
  102. X                    fprintf(stderr, FilNamMsg, filename, "central");
  103. X                    members_remaining = 0;
  104. X                    break;
  105. X                }
  106. X            }
  107. X            if ((error = do_string(crec.extra_field_length, SKIP)) != 0) {
  108. X                if (error > error_in_archive)
  109. X                    error_in_archive = error;
  110. X                if (error > 1) {  /* fatal */
  111. X                    fprintf(stderr, ExtFieldMsg, filename, "central");
  112. X                    members_remaining = 0;
  113. X                    break;
  114. X                }
  115. X            }
  116. X            if ((error = do_string(crec.file_comment_length, SKIP)) != 0) {
  117. X                if (error > error_in_archive)
  118. X                    error_in_archive = error;
  119. X                if (error > 1) {  /* fatal */
  120. X                    fprintf(stderr, "\n%s:  bad file comment length\n",
  121. X                            filename);
  122. X                    members_remaining = 0;
  123. X                    break;
  124. X                }
  125. X            }
  126. X            if (process_all_files) {
  127. X                if (crec.general_purpose_bit_flag & 1) {
  128. X                    fprintf(stderr, CryptMsg, filename);  /* encrypted: skip */
  129. X                    error_in_archive = 1;       /* 1:  warning error */
  130. X                } else {
  131. X                    ULONG tmp = ULONG_(crec.external_file_attributes);
  132. X
  133. X                    switch (hostnum) {
  134. X                        case UNIX_:
  135. X                          info[j].f_attr = tmp >> 16;
  136. X                          break;
  137. X                        case DOS_OS2_FAT_:
  138. X                          tmp = (!(tmp & 1)) << 1;   /* read-only bit */
  139. X                          info[j].f_attr = 0444 | tmp<<6 | tmp<<3 | tmp;
  140. X#ifdef UNIX
  141. X                          umask((int)(tmp = umask(0)));
  142. X                          info[j].f_attr &= ~tmp;
  143. X#endif
  144. X                          break;
  145. X                        case MAC_:
  146. X                          tmp &= 1;   /* read-only bit */
  147. X                          info[j].f_attr = tmp;
  148. X                          break;
  149. X                        default:
  150. X                          info[j].f_attr = 0666;
  151. X                          break;
  152. X                    }
  153. X                    info[j].lcflag = lcflag;
  154. X                    info[j++].offset = (longint)
  155. X                        ULONG_(crec.relative_offset_local_header);
  156. X                }
  157. X            } else {
  158. X                fnamev = fnv;   /* don't destroy permanent filename pointer */
  159. X                for (--fnamev; *++fnamev;)
  160. X                    if (match(filename, *fnamev)) {
  161. X                        if (crec.version_needed_to_extract[0] > UNZIP_VERSION) {
  162. X                            fprintf(stderr, "%s:  requires compatibility with\
  163. X version %u.%u to extract\n       (this handles %u.%u)--skipping.\n", filename,
  164. X                                crec.version_needed_to_extract[0] / 10,
  165. X                                crec.version_needed_to_extract[0] % 10,
  166. X                                UNZIP_VERSION / 10, UNZIP_VERSION % 10);
  167. X                            error_in_archive = 1;       /* 1:  warning error */
  168. X                        } else if (crec.general_purpose_bit_flag & 1) {
  169. X                            fprintf(stderr, CryptMsg, filename);  /* encrypt */
  170. X                            error_in_archive = 1;       /* 1:  warning error */
  171. X                        } else {
  172. X                            ULONG tmp = ULONG_(crec.external_file_attributes);
  173. X
  174. X                            switch (hostnum) {
  175. X                                case UNIX_:
  176. X                                  info[j].f_attr = tmp >> 16;
  177. X                                  break;
  178. X                                case DOS_OS2_FAT_:
  179. X                                  tmp = (!(tmp & 1)) << 1;  /* read-only bit */
  180. X                                  info[j].f_attr = 0444 | tmp<<6 | tmp<<3 | tmp;
  181. X#ifdef UNIX
  182. X                                  umask((int)(tmp = umask(0)));
  183. X                                  info[j].f_attr &= ~tmp;
  184. X#endif
  185. X                                  break;
  186. X                                case MAC_:
  187. X                                  tmp &= 1;   /* read-only bit */
  188. X                                  info[j].f_attr = tmp;
  189. X                                  break;
  190. X                                default:
  191. X                                  info[j].f_attr = 0666;
  192. X                                  break;
  193. X                            }
  194. X                            info[j].lcflag = lcflag;
  195. X                            info[j++].offset = (longint)
  196. X                                ULONG_(crec.relative_offset_local_header);
  197. X                        }
  198. X                        break;  /* found match for filename, so stop looping */
  199. X
  200. X                    }   /* end if (match), for-loop (fnamev) */
  201. X            }           /* end if (process_all_files) */
  202. X        }               /* end while-loop (adding files to current block) */
  203. X
  204. X        /* save position in central directory so can come back later */
  205. X        cd_bufstart = cur_zipfile_bufstart;
  206. X        cd_inptr = inptr;
  207. X        cd_incnt = incnt;
  208. X
  209. X        /*
  210. X         * Loop through files in block, extracting or testing each one.
  211. X         */
  212. X
  213. X        for (i = 0; i < j; ++i) {
  214. X            /*
  215. X             * if the target position is not within the current input buffer
  216. X             * (either haven't yet read far enough, or (maybe) skipping back-
  217. X             * ward) skip to the target position and reset readbuf().
  218. X             */
  219. X
  220. X            /* LSEEK(info[i].offset):  */
  221. X            inbuf_offset = info[i].offset % INBUFSIZ;
  222. X            bufstart = info[i].offset - inbuf_offset;
  223. X
  224. X            if (bufstart != cur_zipfile_bufstart) {
  225. X                cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  226. X                if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0) {
  227. X                    fprintf(stderr, OffsetMsg, filename, "lseek");
  228. X                    error_in_archive = 3;   /* 3:  error in zipfile, but */
  229. X                    continue;               /*  can still do next file   */
  230. X                }
  231. X                inptr = inbuf + inbuf_offset;
  232. X                incnt -= inbuf_offset;
  233. X            } else {
  234. X                incnt += (inptr-inbuf) - inbuf_offset;
  235. X                inptr = inbuf + inbuf_offset;
  236. X            }
  237. X            lcflag = info[i].lcflag;
  238. X            f_attr = info[i].f_attr;
  239. X
  240. X            /* should be in proper position now, so check for sig */
  241. X            if (readbuf(sig, 4) <= 0) {
  242. X                fprintf(stderr, OffsetMsg, filename, "EOF");  /* bad offset */
  243. X                error_in_archive = 3;   /* 3:  error in zipfile */
  244. X                continue;       /* but can still do next one */
  245. X            }
  246. X            if (strncmp(sig, LOCAL_HDR_SIG, 4)) {
  247. X                fprintf(stderr, OffsetMsg, filename,
  248. X                        "can't find local header sig");   /* bad offset */
  249. X                error_in_archive = 3;
  250. X                continue;
  251. X            }
  252. X            if ((error = process_local_file_header()) != 0) {
  253. X                fprintf(stderr, "\n%s:  bad local header\n", filename);
  254. X                error_in_archive = error;       /* only 51 (EOF) defined */
  255. X                continue;       /* can still do next one */
  256. X            }
  257. X            if ((error = do_string(lrec.filename_length, FILENAME)) != 0) {
  258. X                if (error > error_in_archive)
  259. X                    error_in_archive = error;
  260. X                if (error > 1) {
  261. X                    fprintf(stderr, FilNamMsg, filename, "local");
  262. X                    continue;   /* go on to next one */
  263. X                }
  264. X            }
  265. X            if ((error = do_string(lrec.extra_field_length, SKIP)) != 0) {
  266. X                if (error > error_in_archive)
  267. X                    error_in_archive = error;
  268. X                if (error > 1) {
  269. X                    fprintf(stderr, ExtFieldMsg, filename, "local");
  270. X                    continue;   /* go on */
  271. X                }
  272. X            }
  273. X            if ((error = extract_or_test_member()) != 0)
  274. X                if (error > error_in_archive)
  275. X                    error_in_archive = error;       /* ...and keep going */
  276. X
  277. X        }                       /* end for-loop (i:  files in current block) */
  278. X
  279. X        /*
  280. X         * Jump back to where we were in the central directory, then go and do
  281. X         * the next batch of files.
  282. X         */
  283. X
  284. X        cur_zipfile_bufstart = lseek(zipfd, cd_bufstart, SEEK_SET);
  285. X        read(zipfd, inbuf, INBUFSIZ);   /* were already there ==> no error */
  286. X        inptr = cd_inptr;
  287. X        incnt = cd_incnt;
  288. X
  289. X#ifdef TEST
  290. X        printf("\ncd_bufstart = %ld (%.8lXh)\n", cd_bufstart, cd_bufstart);
  291. X        printf("cur_zipfile_bufstart = %ld (%.8lXh)\n", cur_zipfile_bufstart,
  292. X          cur_zipfile_bufstart);
  293. X        printf("inptr-inbuf = %d\n", inptr-inbuf);
  294. X        printf("incnt = %d\n\n", incnt);
  295. X#endif
  296. X
  297. X    }           /* end while-loop (blocks of files in central directory) */
  298. X
  299. X/*---------------------------------------------------------------------------
  300. X    Double check that we're back at the end-of-central-directory record, and
  301. X    print quick summary of results, if we were just testing the archive.  We
  302. X    send the summary to stdout so that people doing the testing in the back-
  303. X    ground and redirecting to a file can just do a "tail" on the output file.
  304. X  ---------------------------------------------------------------------------*/
  305. X
  306. X    readbuf(sig, 4);
  307. X    if (strncmp(sig, END_CENTRAL_SIG, 4)) {     /* just to make sure again */
  308. X        fprintf(stderr, EndSigMsg);  /* didn't find end-of-central-dir sig */
  309. X        fprintf(stderr, ReportMsg);  /* report to info-zip */
  310. X        if (!error_in_archive)       /* don't overwrite stronger error */
  311. X            error_in_archive = 1;    /* 1:  warning error */
  312. X    }
  313. X    if (tflag && (quietflg == 1)) {
  314. X        if (error_in_archive)
  315. X            printf("At least one error was detected in the archive.\n");
  316. X        else if (process_all_files)
  317. X            printf("No errors detected.\n");
  318. X        else
  319. X            printf("No errors detected in the tested files.\n");
  320. X    }
  321. X    return (error_in_archive);
  322. X
  323. X}       /* end function extract_or_test_files() */
  324. X
  325. X
  326. X
  327. X
  328. X
  329. X/**************************************/
  330. X/*  Function extract_or_test_member() */
  331. X/**************************************/
  332. X
  333. Xint extract_or_test_member()
  334. X/* return PK-type error code */
  335. X{
  336. X    int error = 0;
  337. X    UWORD b;
  338. X
  339. X
  340. X
  341. X/*---------------------------------------------------------------------------
  342. X    Initialize variables, buffers, etc.
  343. X  ---------------------------------------------------------------------------*/
  344. X
  345. X    bits_left = 0;
  346. X    bitbuf = 0;
  347. X    outpos = 0L;
  348. X    outcnt = 0;
  349. X    outptr = outbuf;
  350. X    zipeof = 0;
  351. X    crc32val = 0xFFFFFFFFL;
  352. X
  353. X    memset(outbuf, 0, OUTBUFSIZ);
  354. X    if (aflag)                  /* if we have a scratchpad, clear it out */
  355. X        memset(outout, 0, OUTBUFSIZ);
  356. X
  357. X    if (tflag) {
  358. X        if (!quietflg) {
  359. X            fprintf(stdout, "  Testing: %-12s ", filename);
  360. X            fflush(stdout);
  361. X        }
  362. X    } else {
  363. X        if (cflag)              /* output to stdout (copy of it) */
  364. X#ifdef MACOS
  365. X            outfd = 1;
  366. X#else
  367. X            outfd = dup(1);
  368. X#endif
  369. X        else {
  370. X            if ((error = mapped_name()) > 1)  /* member name conversion error */
  371. X                return (2);     /* 2:  (weak) error in zipfile */
  372. X            if (create_output_file())   /* output to file:  read/write perms */
  373. X                return (50);    /* 50:  disk full */
  374. X        }
  375. X    }                           /* endif (!tflag) */
  376. X
  377. X/*---------------------------------------------------------------------------
  378. X    Unpack the file.
  379. X  ---------------------------------------------------------------------------*/
  380. X
  381. X    switch (lrec.compression_method) {
  382. X
  383. X    case STORED:
  384. X        if (!tflag && QCOND) {
  385. X            fprintf(stdout, " Extracting: %-12s ", filename);
  386. X            if (cflag)
  387. X                fprintf(stdout, "\n");
  388. X            fflush(stdout);
  389. X        }
  390. X        while (ReadByte(&b))
  391. X            OUTB(b);
  392. X        break;
  393. X
  394. X    case SHRUNK:
  395. X        if (!tflag && QCOND) {
  396. X            fprintf(stdout, "UnShrinking: %-12s ", filename);
  397. X            if (cflag)
  398. X                fprintf(stdout, "\n");
  399. X            fflush(stdout);
  400. X        }
  401. X        unShrink();
  402. X        break;
  403. X
  404. X    case REDUCED1:
  405. X    case REDUCED2:
  406. X    case REDUCED3:
  407. X    case REDUCED4:
  408. X        if (!tflag && QCOND) {
  409. X            fprintf(stdout, "  Expanding: %-12s ", filename);
  410. X            if (cflag)
  411. X                fprintf(stdout, "\n");
  412. X            fflush(stdout);
  413. X        }
  414. X        unReduce();
  415. X        break;
  416. X
  417. X    case IMPLODED:
  418. X        if (!tflag && QCOND) {
  419. X            fprintf(stdout, "  Exploding: %-12s ", filename);
  420. X            if (cflag)
  421. X                fprintf(stdout, "\n");
  422. X            fflush(stdout);
  423. X        }
  424. X        unImplode();
  425. X        break;
  426. X
  427. X    default:
  428. X        fprintf(stderr, "%s:  unknown compression method\n", filename);
  429. X        /* close and delete file before return?? */
  430. X        return (1);             /* 1:  warning error */
  431. X    }
  432. X
  433. X/*---------------------------------------------------------------------------
  434. X    Write the last partial buffer, if any; set the file date and time; and
  435. X    close the file (not necessarily in that order).  Then make sure CRC came
  436. X    out OK and print result.  [Note:  crc32val must be logical-ANDed with
  437. X    32 bits of 1's, or else machines whose longs are bigger than 32 bits will
  438. X    report bad CRCs (because of the upper bits being filled with 1's instead
  439. X    of 0's).]
  440. X  ---------------------------------------------------------------------------*/
  441. X
  442. X    if (FlushOutput())
  443. X        return (50);            /* 50:  disk full */
  444. X
  445. X    if (!tflag)
  446. X#if defined(VMS) || defined(MTS)/* VMS already set file time; MTS can't */
  447. X        close(outfd);
  448. X#else
  449. X        set_file_time_and_close();
  450. X#endif
  451. X
  452. X    if ((crc32val = ((~crc32val) & 0xFFFFFFFFL)) != ULONG_(lrec.crc32)) {
  453. X        /* if quietflg is set we haven't output the filename yet, do it */
  454. X        if (quietflg)
  455. X            printf("%-12s: ", filename);
  456. X        fprintf(stdout, " Bad CRC %08lx  (should be %08lx)\n", crc32val,
  457. X                ULONG_(lrec.crc32));
  458. X        return (1);             /* 1:  warning error */
  459. X    } else if (tflag) {
  460. X        if (!quietflg)
  461. X            fprintf(stdout, " OK\n");
  462. X    } else {
  463. X        if (QCOND)
  464. X            fprintf(stdout, "\n");
  465. X    }
  466. X
  467. X    return (error);
  468. X
  469. X}       /* end function extract_or_test_member() */
  470. X
  471. X
  472. X
  473. X
  474. X
  475. X/*******************************************/
  476. X/*  Function process_central_file_header() */
  477. X/*******************************************/
  478. X
  479. Xint process_central_file_header()
  480. X/* return PK-type error code */
  481. X{
  482. X#ifdef NOTINT16
  483. X    central_directory_byte_header byterec;
  484. X#endif
  485. X
  486. X
  487. X
  488. X/*---------------------------------------------------------------------------
  489. X    Read the next central directory entry and do any necessary machine-type
  490. X    conversions (byte ordering, structure padding compensation--in the latter
  491. X    case, copy the data from the array into which it was read (byterec) to
  492. X    the usable struct (crec)).
  493. X  ---------------------------------------------------------------------------*/
  494. X
  495. X#ifndef NOTINT16
  496. X    if (readbuf((char *) &crec, CREC_SIZE) <= 0)
  497. X        return (51);
  498. X
  499. X#else  /* NOTINT16 */
  500. X    if (readbuf((char *) byterec, CREC_SIZE) <= 0)
  501. X        return (51);            /* 51:  unexpected EOF */
  502. X
  503. X    crec.version_made_by[0] = byterec[C_VERSION_MADE_BY_0];
  504. X    crec.version_made_by[1] = byterec[C_VERSION_MADE_BY_1];
  505. X    crec.version_needed_to_extract[0] = byterec[C_VERSION_NEEDED_TO_EXTRACT_0];
  506. X    crec.version_needed_to_extract[1] = byterec[C_VERSION_NEEDED_TO_EXTRACT_1];
  507. X
  508. X    crec.general_purpose_bit_flag =
  509. X        makeword(&byterec[C_GENERAL_PURPOSE_BIT_FLAG]);
  510. X    crec.compression_method =
  511. X        makeword(&byterec[C_COMPRESSION_METHOD]);
  512. X    crec.last_mod_file_time =
  513. X        makeword(&byterec[C_LAST_MOD_FILE_TIME]);
  514. X    crec.last_mod_file_date =
  515. X        makeword(&byterec[C_LAST_MOD_FILE_DATE]);
  516. X    crec.crc32 =
  517. X        makelong(&byterec[C_CRC32]);
  518. X    crec.compressed_size =
  519. X        makelong(&byterec[C_COMPRESSED_SIZE]);
  520. X    crec.uncompressed_size =
  521. X        makelong(&byterec[C_UNCOMPRESSED_SIZE]);
  522. X    crec.filename_length =
  523. X        makeword(&byterec[C_FILENAME_LENGTH]);
  524. X    crec.extra_field_length =
  525. X        makeword(&byterec[C_EXTRA_FIELD_LENGTH]);
  526. X    crec.file_comment_length =
  527. X        makeword(&byterec[C_FILE_COMMENT_LENGTH]);
  528. X    crec.disk_number_start =
  529. X        makeword(&byterec[C_DISK_NUMBER_START]);
  530. X    crec.internal_file_attributes =
  531. X        makeword(&byterec[C_INTERNAL_FILE_ATTRIBUTES]);
  532. X    crec.external_file_attributes =
  533. X        makelong(&byterec[C_EXTERNAL_FILE_ATTRIBUTES]); /* LONG, not word! */
  534. X    crec.relative_offset_local_header =
  535. X        makelong(&byterec[C_RELATIVE_OFFSET_LOCAL_HEADER]);
  536. X#endif  /* NOTINT16 */
  537. X
  538. X    hostnum = min(crec.version_made_by[1], NUM_HOSTS);
  539. X/*  extnum = min( crec.version_needed_to_extract[1], NUM_HOSTS ); */
  540. X    methnum = min(crec.compression_method, NUM_METHODS);
  541. X
  542. X/*---------------------------------------------------------------------------
  543. X    Set flag for lowercase conversion of filename, depending on which OS the
  544. X    file is coming from.  This section could be ifdef'd if some people have
  545. X    come to love DOS uppercase filenames under Unix...but really, guys, get
  546. X    a life. :)  NOTE THAT ALL SYSTEM NAMES NOW HAVE TRAILING UNDERSCORES!!!
  547. X    This is to prevent interference with compiler command-line defines such
  548. X    as -DUNIX, for example, which are then used in "#ifdef UNIX" constructs.
  549. X  ---------------------------------------------------------------------------*/
  550. X
  551. X    lcflag = FALSE;
  552. X    if (!Uflag)                 /* as long as user hasn't specified
  553. X                                 * case-preservation */
  554. X        switch (hostnum) {
  555. X        case DOS_OS2_FAT_:
  556. X        case VMS_:
  557. X        case VM_CMS_:           /* all caps? */
  558. X        case CPM_:              /* like DOS, right? */
  559. X/*      case ATARI_:            ??? */
  560. X/*      case Z_SYSTEM_:         ??? */
  561. X/*      case TOPS20_:           (if we had such a thing...) */
  562. X
  563. X            lcflag = TRUE;      /* convert filename to lowercase */
  564. X            break;
  565. X
  566. X        default:                /* AMIGA_, UNIX_, (ATARI_), OS2_HPFS_, */
  567. X            break;              /*   MAC_, (Z_SYSTEM_):  no conversion */
  568. X        }
  569. X
  570. X    return (0);
  571. X
  572. X}       /* end function process_central_file_header() */
  573. X
  574. X
  575. X
  576. X
  577. X
  578. X/*****************************************/
  579. X/*  Function process_local_file_header() */
  580. X/*****************************************/
  581. X
  582. Xint process_local_file_header()
  583. X/* return PK-type error code */
  584. X{
  585. X#ifdef NOTINT16
  586. X    local_byte_header byterec;
  587. X#endif
  588. X
  589. X
  590. X
  591. X/*---------------------------------------------------------------------------
  592. X    Read the next local file header and do any necessary machine-type con-
  593. X    versions (byte ordering, structure padding compensation--in the latter
  594. X    case, copy the data from the array into which it was read (byterec) to
  595. X    the usable struct (lrec)).
  596. X  ---------------------------------------------------------------------------*/
  597. X
  598. X#ifndef NOTINT16
  599. X    if (readbuf((char *) &lrec, LREC_SIZE) <= 0)
  600. X        return (51);
  601. X
  602. X#else /* NOTINT16 */
  603. X    if (readbuf((char *) byterec, LREC_SIZE) <= 0)
  604. X        return (51);            /* 51:  unexpected EOF */
  605. X
  606. X    lrec.version_needed_to_extract[0] = byterec[L_VERSION_NEEDED_TO_EXTRACT_0];
  607. X    lrec.version_needed_to_extract[1] = byterec[L_VERSION_NEEDED_TO_EXTRACT_1];
  608. X
  609. X    lrec.general_purpose_bit_flag = makeword(&byterec[L_GENERAL_PURPOSE_BIT_FLAG]);
  610. X    lrec.compression_method = makeword(&byterec[L_COMPRESSION_METHOD]);
  611. X    lrec.last_mod_file_time = makeword(&byterec[L_LAST_MOD_FILE_TIME]);
  612. X    lrec.last_mod_file_date = makeword(&byterec[L_LAST_MOD_FILE_DATE]);
  613. X    lrec.crc32 = makelong(&byterec[L_CRC32]);
  614. X    lrec.compressed_size = makelong(&byterec[L_COMPRESSED_SIZE]);
  615. X    lrec.uncompressed_size = makelong(&byterec[L_UNCOMPRESSED_SIZE]);
  616. X    lrec.filename_length = makeword(&byterec[L_FILENAME_LENGTH]);
  617. X    lrec.extra_field_length = makeword(&byterec[L_EXTRA_FIELD_LENGTH]);
  618. X#endif  /* NOTINT16 */
  619. X
  620. X    csize = (longint) ULONG_(lrec.compressed_size);
  621. X    ucsize = (longint) ULONG_(lrec.uncompressed_size);
  622. X
  623. X    return (0);                 /* 0:  no error */
  624. X
  625. X}       /* end function process_local_file_header() */
  626. END_OF_FILE
  627.   if test 22093 -ne `wc -c <'./v41/unzip.c.2'`; then
  628.     echo shar: \"'./v41/unzip.c.2'\" unpacked with wrong size!
  629.   fi
  630.   # end of './v41/unzip.c.2'
  631. fi
  632. if test -f './v41/unzip.h' -a "${1}" != "-c" ; then 
  633.   echo shar: Will not clobber existing file \"'./v41/unzip.h'\"
  634. else
  635.   echo shar: Extracting \"'./v41/unzip.h'\" \(28924 characters\)
  636.   sed "s/^X//" >'./v41/unzip.h' <<'END_OF_FILE'
  637. X/*---------------------------------------------------------------------------
  638. X
  639. X  unzip.h
  640. X
  641. X  This header file is used by all of the unzip source files.  Its contents
  642. X  are divided into six more-or-less separate sections:  OS-dependent includes,
  643. X  (mostly) OS-independent defines, typedefs, function prototypes (or "proto-
  644. X  types," in the case of non-ANSI compilers), macros, and global-variable
  645. X  declarations.
  646. X
  647. X  ---------------------------------------------------------------------------*/
  648. X
  649. X
  650. X
  651. X/***************************/
  652. X/*  OS-Dependent Includes  */
  653. X/***************************/
  654. X
  655. X#include <stdio.h>       /* this is your standard header for all C compiles */
  656. X#include <ctype.h>
  657. X#include <errno.h>       /* used in mapped_name() */
  658. X#define DECLARE_ERRNO    /* everybody except MSC 6.0 */
  659. X#ifdef VMS               /* sigh...you just KNEW someone had to break this.  */
  660. X#  include <types.h>     /*  (placed up here instead of in VMS section below */
  661. X#  include <stat.h>      /*   because types.h is used in some other headers) */
  662. X#else  /* almost everybody */
  663. X#  if defined(THINK_C) || defined(MPW) /* for Macs */
  664. X#    include <stddef.h>
  665. X#  else
  666. X#    include <sys/types.h> /* off_t, time_t, dev_t, ... */
  667. X#    include <sys/stat.h>  /* Everybody seems to need this. */
  668. X#  endif
  669. X#endif                   /*   This include file defines
  670. X                          *     #define S_IREAD 0x0100  (owner may read)
  671. X                          *     #define S_IWRITE 0x0080 (owner may write)
  672. X                          *   as used in the creat() standard function.  Must
  673. X                          *   be included AFTER sys/types.h for most systems.
  674. X                          */
  675. X
  676. X
  677. X/*---------------------------------------------------------------------------
  678. X    Next, a word from our Unix (mostly) sponsors:
  679. X  ---------------------------------------------------------------------------*/
  680. X
  681. X#ifdef UNIX               /* On some systems sys/param.h partly duplicates   */
  682. X#  include <sys/param.h>  /*  the contents of sys/types.h, so you don't need */
  683. X                          /*  (and can't use) sys/types.h. (or param.h???)   */
  684. X#  ifndef BSIZE
  685. X#    define BSIZE   DEV_BSIZE   /* assume common for all Unix systems */
  686. X#  endif
  687. X
  688. X#  ifndef BSD
  689. X#    define NO_MKDIR            /* for mapped_name() */
  690. X#    include <time.h>
  691. X     struct tm *gmtime(), *localtime();
  692. X#  else   /* BSD */
  693. X#    include <sys/time.h>
  694. X#    include <sys/timeb.h>
  695. X#  endif
  696. X
  697. X#else   /* !UNIX */
  698. X#  define BSIZE   512           /* disk block size */
  699. X#endif
  700. X
  701. X#if defined(V7) || defined(BSD)
  702. X#  define strchr    index
  703. X#  define strrchr   rindex
  704. X#endif
  705. X
  706. X/*---------------------------------------------------------------------------
  707. X    And now, our MS-DOS and OS/2 corner:
  708. X  ---------------------------------------------------------------------------*/
  709. X
  710. X#ifdef __TURBOC__
  711. X#  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS2    */
  712. X#  include <sys/timeb.h>      /* for structure ftime                        */
  713. X#  include <mem.h>            /* for memcpy()                               */
  714. X#else                         /* NOT Turbo C...                             */
  715. X#  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
  716. X#    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
  717. X#      define MSC             /*   necessary (it is in 5.0; apparently not  */
  718. X#    endif                    /*   in 5.1 and 6.0)                          */
  719. X#    include <dos.h>          /* _dos_setftime()                            */
  720. X#  endif
  721. X#  ifdef OS2                  /* stuff for DOS and OS/2 family version */
  722. X#    ifndef MSC
  723. X#      define MSC
  724. X#    endif
  725. X#    include <os2.h>          /* DosQFileInfo(), DosSetFileInfo()? */
  726. X#  endif
  727. X#endif
  728. X
  729. X#ifdef MSC                    /* defined for all versions of MSC now         */
  730. X#  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
  731. X#  ifndef __STDC__            /* MSC 5.0 and 5.1 aren't truly ANSI-standard, */
  732. X#    define __STDC__          /*   but they understand prototypes...so       */
  733. X#  endif                      /*   they're close enough for our purposes     */
  734. X#  if defined(_MSC_VER) && (_MSC_VER >= 600)      /* new with 5.1 or 6.0 ... */
  735. X#    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
  736. X#  endif                      /*   library (or something)--incompatible with */
  737. X#endif                        /*   the usual "extern int errno" declaration  */
  738. X
  739. X#ifdef DOS_OS2                /* defined for both Turbo C, MSC */
  740. X#  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  741. X#endif
  742. X
  743. X/*---------------------------------------------------------------------------
  744. X    Followed by some VMS (mostly) stuff:
  745. X  ---------------------------------------------------------------------------*/
  746. X
  747. X#ifdef VMS
  748. X#  include <time.h>             /* the usual non-BSD time functions */
  749. X#  include <file.h>             /* same things as fcntl.h has */
  750. X#  define UNIX                  /* can share most of same code from now on */
  751. X#  define RETURN   return_VMS   /* VMS interprets return codes incorrectly */
  752. X#else
  753. X#  define RETURN   return       /* only used in main() */
  754. X#  ifdef V7
  755. X#    define O_RDONLY  0
  756. X#    define O_WRONLY  1
  757. X#    define O_RDWR    2
  758. X#  else
  759. X#    ifdef MTS
  760. X#      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  761. X#    else
  762. X#      include <fcntl.h>
  763. X#    endif
  764. X#  endif
  765. X#endif
  766. X/*
  767. X *   fcntl.h (above):   This include file defines
  768. X *                        #define O_BINARY 0x8000  (no cr-lf translation)
  769. X *                      as used in the open() standard function.
  770. X */
  771. X
  772. X/*---------------------------------------------------------------------------
  773. X    And some Mac stuff for good measure:
  774. X  ---------------------------------------------------------------------------*/
  775. X
  776. X#ifdef THINK_C
  777. X#  define MACOS
  778. X#  define NOTINT16
  779. X#  ifndef __STDC__            /* THINK_C isn't truly ANSI-standard, */
  780. X#    define __STDC__          /*   but it understands prototypes...so */
  781. X#  endif                      /*   it's close enough for our purposes */
  782. X#  include <time.h>
  783. X#  include <unix.h>
  784. X#  include "macstat.h"
  785. X#endif
  786. X#ifdef MPW                    /* not tested yet - should be easy enough tho */
  787. X#  define MACOS
  788. X#  define NOTINT16
  789. X#  include <time.h>
  790. X#  include <fcntl.h>
  791. X#  include "macstat.h"
  792. X#endif
  793. X
  794. X/*---------------------------------------------------------------------------
  795. X    And finally, some random extra stuff:
  796. X  ---------------------------------------------------------------------------*/
  797. X
  798. X#ifdef __STDC__
  799. X#  include <stdlib.h>      /* standard library prototypes, malloc(), etc. */
  800. X#  include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  801. X#else
  802. X   char *malloc();
  803. X   char *strchr(), *strrchr();
  804. X   long lseek();
  805. X#endif
  806. X
  807. X
  808. X
  809. X
  810. X
  811. X/*************/
  812. X/*  Defines  */
  813. X/*************/
  814. X
  815. X#define INBUFSIZ          BUFSIZ   /* same as stdio uses */
  816. X#define DIR_BLKSIZ        64       /* number of directory entries per block
  817. X                                    *  (should fit in 4096 bytes, usually) */
  818. X#define FILNAMSIZ         (1025)
  819. X#ifdef MTS
  820. X#  undef FILENAME_MAX              /* the MTS value is too low: use default */
  821. X#endif
  822. X#ifndef FILENAME_MAX               /* make sure FILENAME_MAX always exists  */
  823. X#  define FILENAME_MAX    (FILNAMSIZ - 1)
  824. X#endif
  825. X#ifdef ZIPINFO
  826. X#  define OUTBUFSIZ       BUFSIZ   /* zipinfo needs less than unzip does    */
  827. X#else
  828. X#  define OUTBUFSIZ       0x2000   /* unImplode needs power of 2, >= 0x2000 */
  829. X#endif
  830. X
  831. X#define ZSUFX             ".zip"
  832. X#define CENTRAL_HDR_SIG   "\120\113\001\002"   /* the infamous "PK" */
  833. X#define LOCAL_HDR_SIG     "\120\113\003\004"   /*  signature bytes  */
  834. X#define END_CENTRAL_SIG   "\120\113\005\006"
  835. X
  836. X#define SKIP              0    /* choice of activities for do_string() */
  837. X#define DISPLAY           1
  838. X#define FILENAME          2
  839. X
  840. X#define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
  841. X#define AMIGA_            1
  842. X#define VMS_              2    /* MAKE SURE THESE ARE NOT DEFINED ON     */
  843. X#define UNIX_             3    /* THE RESPECTIVE SYSTEMS!!  (Like, for   */
  844. X#define VM_CMS_           4    /* instance, "UNIX":  CFLAGS = -O -DUNIX) */
  845. X#define ATARI_            5
  846. X#define OS2_HPFS_         6
  847. X#define MAC_              7
  848. X#define Z_SYSTEM_         8
  849. X#define CPM_              9
  850. X/* #define TOPS20_   10  (we're going to need this soon...)  */
  851. X#define NUM_HOSTS         10   /* index of last system + 1 */
  852. X
  853. X#define STORED            0    /* compression methods */
  854. X#define SHRUNK            1
  855. X#define REDUCED1          2
  856. X#define REDUCED2          3
  857. X#define REDUCED3          4
  858. X#define REDUCED4          5
  859. X#define IMPLODED          6
  860. X#define NUM_METHODS       7    /* index of last method + 1 */
  861. X/* don't forget to update list_files() appropriately if NUM_METHODS changes */
  862. X
  863. X#ifndef MACOS
  864. X#  define TRUE            1    /* sort of obvious */
  865. X#  define FALSE           0
  866. X#endif
  867. X
  868. X#define UNZIP_VERSION   11     /* compatible with PKUNZIP 1.1 */
  869. X
  870. X#ifndef UNZIP_OS               /* not used yet, but will need for Zip  */
  871. X#  ifdef UNIX                  /* (could be defined in Makefile or...) */
  872. X#    define UNZIP_OS    UNIX_
  873. X#  endif
  874. X#  ifdef DOS_OS2
  875. X#    define UNZIP_OS    DOS_OS2_FAT_
  876. X#  endif
  877. X#  ifdef VMS
  878. X#    define UNZIP_OS    VMS_
  879. X#  endif
  880. X#  ifdef MTS
  881. X#    define UNZIP_OS    UNIX_
  882. X#  endif
  883. X#  ifdef MACOS
  884. X#    define UNZIP_OS    MAC_
  885. X#  endif
  886. X#  ifndef UNZIP_OS             /* still not defined:  default setting */
  887. X#    define UNZIP_OS    UNKNOWN
  888. X#  endif
  889. X#endif
  890. X
  891. X/*---------------------------------------------------------------------------
  892. X    Macros for accessing the ULONG header fields.  When NOTINT16 is *not*
  893. X    defined, these fields are allocated as arrays of char within the structs.
  894. X    This prevents 32-bit compilers from padding the structs so that ULONGs
  895. X    start on 4-byte boundaries (this will not work on machines that can ONLY
  896. X    access ULONGs if they start on 4-byte boundaries).  If NOTINT16 *is*
  897. X    defined, however, the original data are individually copied into working
  898. X    structs consisting of UWORDs and ULONGs (which may therefore be padded
  899. X    arbitrarily), so the ULONGs are accessed normally.
  900. X  ---------------------------------------------------------------------------*/
  901. X
  902. X#ifdef NOTINT16
  903. X#  define ULONG_(X)   X
  904. X#else
  905. X#  define ULONG_(X)   (*((ULONG *) (X)))
  906. X#endif
  907. X
  908. X/*---------------------------------------------------------------------------
  909. X    True sizes of the various headers, as defined by Phil Katz--so it is not
  910. X    likely that these will ever change.  But if they do, make sure both these
  911. X    defines AND the typedefs below get updated accordingly.
  912. X  ---------------------------------------------------------------------------*/
  913. X
  914. X#define LREC_SIZE     26    /* lengths of local file headers, central */
  915. X#define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  916. X#define ECREC_SIZE    18    /*  central-dir record, respectively      */
  917. X
  918. X
  919. X#define MAX_BITS      13                 /* used in unShrink() */
  920. X#define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  921. X
  922. X#define LF   10   /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
  923. X#define CR   13   /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
  924. X
  925. X#ifdef EBCDIC
  926. X#  define ascii_to_native(c)   ebcdic[(c)]
  927. X#endif
  928. X
  929. X#ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
  930. X#  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
  931. X#  define SEEK_CUR  1
  932. X#  define SEEK_END  2
  933. X#endif
  934. X
  935. X
  936. X
  937. X
  938. X
  939. X/**************/
  940. X/*  Typedefs  */
  941. X/**************/
  942. X
  943. Xtypedef unsigned char    byte;       /* code assumes UNSIGNED bytes */
  944. Xtypedef long             longint;
  945. Xtypedef unsigned short   UWORD;
  946. Xtypedef unsigned long    ULONG;
  947. Xtypedef char             boolean;
  948. X
  949. X/*---------------------------------------------------------------------------
  950. X    Zipfile layout declarations.  If these headers ever change, make sure the
  951. X    ??REC_SIZE defines (above) change with them!
  952. X  ---------------------------------------------------------------------------*/
  953. X
  954. X#ifdef NOTINT16
  955. X
  956. X   typedef byte   local_byte_header[ LREC_SIZE ];
  957. X#      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  958. X#      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  959. X#      define L_GENERAL_PURPOSE_BIT_FLAG        2
  960. X#      define L_COMPRESSION_METHOD              4
  961. X#      define L_LAST_MOD_FILE_TIME              6
  962. X#      define L_LAST_MOD_FILE_DATE              8
  963. X#      define L_CRC32                           10
  964. X#      define L_COMPRESSED_SIZE                 14
  965. X#      define L_UNCOMPRESSED_SIZE               18
  966. X#      define L_FILENAME_LENGTH                 22
  967. X#      define L_EXTRA_FIELD_LENGTH              24
  968. X
  969. X   typedef byte   central_directory_byte_header[ CREC_SIZE ];
  970. X#      define C_VERSION_MADE_BY_0               0
  971. X#      define C_VERSION_MADE_BY_1               1
  972. X#      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  973. X#      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  974. X#      define C_GENERAL_PURPOSE_BIT_FLAG        4
  975. X#      define C_COMPRESSION_METHOD              6
  976. X#      define C_LAST_MOD_FILE_TIME              8
  977. X#      define C_LAST_MOD_FILE_DATE              10
  978. X#      define C_CRC32                           12
  979. X#      define C_COMPRESSED_SIZE                 16
  980. X#      define C_UNCOMPRESSED_SIZE               20
  981. X#      define C_FILENAME_LENGTH                 24
  982. X#      define C_EXTRA_FIELD_LENGTH              26
  983. X#      define C_FILE_COMMENT_LENGTH             28
  984. X#      define C_DISK_NUMBER_START               30
  985. X#      define C_INTERNAL_FILE_ATTRIBUTES        32
  986. X#      define C_EXTERNAL_FILE_ATTRIBUTES        34
  987. X#      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  988. X
  989. X   typedef byte   end_central_byte_record[ ECREC_SIZE+4 ];
  990. X/*     define SIGNATURE                         0   space-holder only */
  991. X#      define NUMBER_THIS_DISK                  4
  992. X#      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  993. X#      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  994. X#      define TOTAL_ENTRIES_CENTRAL_DIR         10
  995. X#      define SIZE_CENTRAL_DIRECTORY            12
  996. X#      define OFFSET_START_CENTRAL_DIRECTORY    16
  997. X#      define ZIPFILE_COMMENT_LENGTH            20
  998. X
  999. X
  1000. X   typedef struct local_file_header {                 /* LOCAL */
  1001. X       byte version_needed_to_extract[2];
  1002. X       UWORD general_purpose_bit_flag;
  1003. X       UWORD compression_method;
  1004. X       UWORD last_mod_file_time;
  1005. X       UWORD last_mod_file_date;
  1006. X       ULONG crc32;
  1007. X       ULONG compressed_size;
  1008. X       ULONG uncompressed_size;
  1009. X       UWORD filename_length;
  1010. X       UWORD extra_field_length;
  1011. X   } local_file_header;
  1012. X
  1013. X   typedef struct central_directory_file_header {     /* CENTRAL */
  1014. X       byte version_made_by[2];
  1015. X       byte version_needed_to_extract[2];
  1016. X       UWORD general_purpose_bit_flag;
  1017. X       UWORD compression_method;
  1018. X       UWORD last_mod_file_time;
  1019. X       UWORD last_mod_file_date;
  1020. X       ULONG crc32;
  1021. X       ULONG compressed_size;
  1022. X       ULONG uncompressed_size;
  1023. X       UWORD filename_length;
  1024. X       UWORD extra_field_length;
  1025. X       UWORD file_comment_length;
  1026. X       UWORD disk_number_start;
  1027. X       UWORD internal_file_attributes;
  1028. X       ULONG external_file_attributes;
  1029. X       ULONG relative_offset_local_header;
  1030. X   } central_directory_file_header;
  1031. X
  1032. X   typedef struct end_central_dir_record {            /* END CENTRAL */
  1033. X       UWORD number_this_disk;
  1034. X       UWORD num_disk_with_start_central_dir;
  1035. X       UWORD num_entries_centrl_dir_ths_disk;
  1036. X       UWORD total_entries_central_dir;
  1037. X       ULONG size_central_directory;
  1038. X       ULONG offset_start_central_directory;
  1039. X       UWORD zipfile_comment_length;
  1040. X   } end_central_dir_record;
  1041. X
  1042. X
  1043. X#else   /* !NOTINT16:  read data directly into the structure we'll be using */
  1044. X
  1045. X
  1046. X   typedef struct local_file_header {                 /* LOCAL */
  1047. X       byte version_needed_to_extract[2];
  1048. X       UWORD general_purpose_bit_flag;
  1049. X       UWORD compression_method;
  1050. X       UWORD last_mod_file_time;
  1051. X       UWORD last_mod_file_date;
  1052. X       byte crc32[4];
  1053. X       byte compressed_size[4];
  1054. X       byte uncompressed_size[4];
  1055. X       UWORD filename_length;
  1056. X       UWORD extra_field_length;
  1057. X   } local_file_header;
  1058. X
  1059. X   typedef struct central_directory_file_header {     /* CENTRAL */
  1060. X       byte version_made_by[2];
  1061. X       byte version_needed_to_extract[2];
  1062. X       UWORD general_purpose_bit_flag;
  1063. X       UWORD compression_method;
  1064. X       UWORD last_mod_file_time;
  1065. X       UWORD last_mod_file_date;
  1066. X       byte crc32[4];
  1067. X       byte compressed_size[4];
  1068. X       byte uncompressed_size[4];
  1069. X       UWORD filename_length;
  1070. X       UWORD extra_field_length;
  1071. X       UWORD file_comment_length;
  1072. X       UWORD disk_number_start;
  1073. X       UWORD internal_file_attributes;
  1074. X       byte external_file_attributes[4];
  1075. X       byte relative_offset_local_header[4];
  1076. X   } central_directory_file_header;
  1077. X
  1078. X   typedef struct end_central_dir_record {            /* END CENTRAL */
  1079. X       byte _sig_[4];  /* space-holder only */
  1080. X       UWORD number_this_disk;
  1081. X       UWORD num_disk_with_start_central_dir;
  1082. X       UWORD num_entries_centrl_dir_ths_disk;
  1083. X       UWORD total_entries_central_dir;
  1084. X       byte size_central_directory[4];
  1085. X       byte offset_start_central_directory[4];
  1086. X       UWORD zipfile_comment_length;
  1087. X   } end_central_dir_record;
  1088. X
  1089. X#endif  /* !NOTINT16 */
  1090. X
  1091. X
  1092. X
  1093. X
  1094. X
  1095. X/*************************/
  1096. X/*  Function Prototypes  */
  1097. X/*************************/
  1098. X
  1099. X#ifndef __              /* This amusing little construct was swiped without  */
  1100. X#  ifdef __STDC__       /*  permission from the fine folks at Cray Research, */
  1101. X#    define __(X)   X   /*  Inc.  Should probably give them a call and see   */
  1102. X#  else                 /*  if they mind, but....  Then again, I can't think */
  1103. X#    define __(X)   ()  /*  of any other way to do this, so maybe it's an    */
  1104. X#  endif                /*  algorithm?  Whatever, thanks to CRI.  (Note:     */
  1105. X#endif                  /*  keep interior stuff parenthesized.)              */
  1106. X/*
  1107. X * Toad Hall Note:  Not to worry:  I've seen this somewhere else too,
  1108. X * so obviously it's been stolen more than once.
  1109. X * That makes it public domain, right?
  1110. X */
  1111. X
  1112. X/*---------------------------------------------------------------------------
  1113. X    Functions in nunzip.c:
  1114. X  ---------------------------------------------------------------------------*/
  1115. X
  1116. Xvoid   usage                         __( (void) );
  1117. Xint    process_zipfile               __( (void) );
  1118. Xint    find_end_central_dir          __( (void) );
  1119. Xint    process_end_central_dir       __( (void) );
  1120. Xint    list_files                    __( (void) );
  1121. Xint    extract_or_test_files         __( (void) );
  1122. Xint    extract_or_test_member        __( (void) );
  1123. Xint    process_central_file_header   __( (void) );
  1124. Xint    process_local_file_header     __( (void) );
  1125. X
  1126. X/*---------------------------------------------------------------------------
  1127. X    Functions in file_io.c:
  1128. X  ---------------------------------------------------------------------------*/
  1129. X
  1130. Xint    change_zipfile_attributes __( (int zip_error) );
  1131. Xint    open_input_file           __( (void) );
  1132. Xint    readbuf                   __( (char *buf, register unsigned size) );
  1133. Xint    create_output_file        __( (void) );
  1134. Xint    FillBitBuffer             __( (register int bits) );
  1135. Xint    ReadByte                  __( (UWORD *x) );
  1136. Xint    FlushOutput               __( (void) );
  1137. X/*
  1138. X * static int   WriteBuffer       __( (int fd, unsigned char *buf, int len) );
  1139. X * static int   dos2unix          __( (unsigned char *buf, int len) );
  1140. X */
  1141. Xvoid   set_file_time_and_close   __( (void) );
  1142. X
  1143. X/*---------------------------------------------------------------------------
  1144. X    Macintosh file_io functions:
  1145. X  ---------------------------------------------------------------------------*/
  1146. X
  1147. X#ifdef MACOS
  1148. Xvoid   macfstest                 __( (int vrefnum, int wd) );
  1149. X/*
  1150. X * static int   IsHFSDisk        __( (int wAppVRefNum) );
  1151. X */
  1152. Xint    mkdir                     __( (char *path, int mode) );
  1153. Xvoid   SetMacVol                 __( (char *pch, short wVRefNum) );
  1154. X#endif
  1155. X
  1156. X/*---------------------------------------------------------------------------
  1157. X    Uncompression functions (all internal compression routines, enclosed in
  1158. X    comments below, are prototyped in their respective files and are invisi-
  1159. X    ble to external functions):
  1160. X  ---------------------------------------------------------------------------*/
  1161. X
  1162. Xvoid   unImplode                __( (void) );                  /* unimplod.c */
  1163. X/*
  1164. X * static void   ReadLengths     __( (sf_tree *tree) );
  1165. X * static void   SortLengths     __( (sf_tree *tree) );
  1166. X * static void   GenerateTrees   __( (sf_tree *tree, sf_node *nodes) );
  1167. X * static void   LoadTree        __( (sf_tree *tree, int treesize, sf_node *nodes) );
  1168. X * static void   LoadTrees       __( (void) );
  1169. X * static void   ReadTree        __( (register sf_node *nodes, int *dest) );
  1170. X */
  1171. X
  1172. Xvoid   unReduce                 __( (void) );                  /* unreduce.c */
  1173. X/*
  1174. X * static void   LoadFollowers   __( (void) );
  1175. X */
  1176. X
  1177. Xvoid   unShrink                 __( (void) );                  /* unshrink.c */
  1178. X/*
  1179. X * static void   partial_clear   __( (void) );
  1180. X */
  1181. X
  1182. X/*---------------------------------------------------------------------------
  1183. X    Functions in match.c, mapname.c, and misc.c:
  1184. X  ---------------------------------------------------------------------------*/
  1185. X
  1186. Xint       match         __( (char *string, char *pattern) );      /* match.c */
  1187. X/*
  1188. X * static BOOLEAN   do_list      __( (register char *string, char *pattern) );
  1189. X * static void      list_parse   __( (char **patp, char *lowp, char *highp) );
  1190. X * static char      nextch       __( (char **patp) );
  1191. X */
  1192. X
  1193. Xint       mapped_name   __( (void) );                           /* mapname.c */
  1194. X
  1195. Xvoid      UpdateCRC     __( (register unsigned char *s, register int len) );
  1196. Xint       do_string     __( (unsigned int len, int option) );      /* misc.c */
  1197. XUWORD     makeword      __( (byte *b) );                           /* misc.c */
  1198. XULONG     makelong      __( (byte *sig) );                         /* misc.c */
  1199. Xvoid      return_VMS    __( (int zip_error) );                     /* misc.c */
  1200. X#ifdef ZMEM
  1201. X   char   *memset       __( (register char *buf, register char init, register unsigned int len) );
  1202. X   char   *memcpy       __( (register char *dst, register char *src, register unsigned int len) );
  1203. X#endif      /* These guys MUST be ifdef'd because their definition  */
  1204. X            /*  conflicts with the standard one.  Others (makeword, */
  1205. X            /*  makelong, return_VMS) don't matter.                 */
  1206. X
  1207. X
  1208. X
  1209. X
  1210. X
  1211. X/************/
  1212. X/*  Macros  */
  1213. X/************/
  1214. X
  1215. X#ifndef min    /* MSC defines this in stdlib.h */
  1216. X#  define min(a,b)   ((a) < (b) ? (a) : (b))
  1217. X#endif
  1218. X
  1219. X
  1220. X#define LSEEK(abs_offset) {longint request=(abs_offset), inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  1221. X   if(bufstart!=cur_zipfile_bufstart) {cur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
  1222. X   if((incnt=read(zipfd,inbuf,INBUFSIZ))<=0) return(51); inptr=inbuf+inbuf_offset; incnt-=inbuf_offset;\
  1223. X   }else {incnt+=(inptr-inbuf)-inbuf_offset; inptr=inbuf+inbuf_offset; }}
  1224. X
  1225. X/*
  1226. X *  Seek to the block boundary of the block which includes abs_offset,
  1227. X *  then read block into input buffer and set pointers appropriately.
  1228. X *  If block is already in the buffer, just set the pointers.  This macro
  1229. X *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
  1230. X *  A slightly modified version is embedded within extract_or_test_files
  1231. X *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  1232. X *
  1233. X *  macro LSEEK( abs_offset )
  1234. X *    {
  1235. X *      longint   request = abs_offset;
  1236. X *      longint   inbuf_offset = request % INBUFSIZ;
  1237. X *      longint   bufstart = request - inbuf_offset;
  1238. X *
  1239. X *      if (bufstart != cur_zipfile_bufstart) {
  1240. X *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  1241. X *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  1242. X *              return(51);
  1243. X *          inptr = inbuf + inbuf_offset;
  1244. X *          incnt -= inbuf_offset;
  1245. X *      } else {
  1246. X *          incnt += (inptr-inbuf) - inbuf_offset;
  1247. X *          inptr = inbuf + inbuf_offset;
  1248. X *      }
  1249. X *    }
  1250. X *
  1251. X */
  1252. X
  1253. X
  1254. X#define OUTB(intc) { *outptr++=intc; if (++outcnt==OUTBUFSIZ) FlushOutput(); }
  1255. X
  1256. X/*
  1257. X *  macro OUTB(intc)
  1258. X *  {
  1259. X *      *outptr++=intc;
  1260. X *      if (++outcnt==OUTBUFSIZ)
  1261. X *          FlushOutput();
  1262. X *  }
  1263. X *
  1264. X */
  1265. X
  1266. X
  1267. X#define READBIT(nbits,zdest) { if (nbits <= bits_left) { zdest = (int)(bitbuf & mask_bits[nbits]); bitbuf >>= nbits; bits_left -= nbits; } else zdest = FillBitBuffer(nbits);}
  1268. X
  1269. X/*
  1270. X * macro READBIT(nbits,zdest)
  1271. X *  {
  1272. X *      if (nbits <= bits_left) {
  1273. X *          zdest = (int)(bitbuf & mask_bits[nbits]);
  1274. X *          bitbuf >>= nbits;
  1275. X *          bits_left -= nbits;
  1276. X *      } else
  1277. X *          zdest = FillBitBuffer(nbits);
  1278. X *  }
  1279. X *
  1280. X */
  1281. X
  1282. X
  1283. X#define NUKE_CRs(buf,len) {register int i,j; for (i=j=0; j<len; (buf)[i++]=(buf)[j++]) if ((buf)[j]=='\r') ++j; len=i;}
  1284. X
  1285. X/*
  1286. X *  Remove all the ASCII carriage returns from buffer buf (length len),
  1287. X *  shortening as necessary (note that len gets modified in the process,
  1288. X *  so it CANNOT be an expression).  This macro is intended to be used
  1289. X *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  1290. X *  if-test gets performed one time too many, but it doesn't matter.
  1291. X *
  1292. X *  macro NUKE_CRs( buf, len )
  1293. X *    {
  1294. X *      register int   i, j;
  1295. X *
  1296. X *      for ( i = j = 0  ;  j < len  ;  (buf)[i++] = (buf)[j++] )
  1297. X *        if ( (buf)[j] == CR )
  1298. X *          ++j;
  1299. X *      len = i;
  1300. X *    }
  1301. X *
  1302. X */
  1303. X
  1304. X
  1305. X#define TOLOWER(str1,str2) {char *ps1,*ps2; ps1=(str1)-1; ps2=(str2); while(*++ps1) *ps2++=(isupper(*ps1))?tolower(*ps1):*ps1; *ps2='\0';}
  1306. X
  1307. X/*
  1308. X *  Copy the zero-terminated string in str1 into str2, converting any
  1309. X *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1310. X *  as well, of course.  str1 and str2 may be the same character array.
  1311. X *
  1312. X *  macro TOLOWER( str1, str2 )
  1313. X *    {
  1314. X *      register char   *ps1, *ps2;
  1315. X *
  1316. X *      ps1 = (str1) - 1;
  1317. X *      ps2 = (str2);
  1318. X *      while ( *++ps1 )
  1319. X *        *ps2++ = (isupper(*ps1)) ?  tolower(*ps1)  :  *ps1;
  1320. X *      *ps2='\0';
  1321. X *    }
  1322. X *
  1323. X *  NOTES:  This macro makes no assumptions about the characteristics of
  1324. X *    the tolower() function or macro (beyond its existence), nor does it
  1325. X *    make assumptions about the structure of the character set (i.e., it
  1326. X *    should work on EBCDIC machines, too).  The fact that either or both
  1327. X *    of isupper() and tolower() may be macros has been taken into account;
  1328. X *    watch out for "side effects" (in the C sense) when modifying this
  1329. X *    macro.
  1330. X */
  1331. X
  1332. X
  1333. X#ifndef ascii_to_native
  1334. X
  1335. X#  define ascii_to_native(c)   (c)
  1336. X#  define A_TO_N(str1)
  1337. X
  1338. X#else
  1339. X
  1340. X#  define NATIVE   /* Used in main() for '-a' and '-c'. */
  1341. X#  define A_TO_N(str1) { register unsigned char *ps1; for (ps1 = str1; *ps1; ps1++) *ps1 = (ascii_to_native(*ps1)); }
  1342. X
  1343. X/*
  1344. X *   Translate the zero-terminated string in str1 from ASCII to the native
  1345. X *   character set. The translation is performed in-place and uses the
  1346. X *   ascii_to_native macro to translate each character.
  1347. X *
  1348. X *   macro A_TO_N( str1 )
  1349. X *     {
  1350. X *     register unsigned char *ps1;
  1351. X *
  1352. X *     for ( ps1 = str1; *ps1; ps1++ )
  1353. X *       *ps1 = ( ascii_to_native( *ps1 ) );
  1354. X *     }
  1355. X *
  1356. X *   NOTE: Using the ascii_to_native macro means that is it the only part of
  1357. X *     unzip which knows which translation table (if any) is actually in use
  1358. X *     to produce the native character set. This makes adding new character
  1359. X *     set translation tables easy insofar as all that is needed is an
  1360. X *     appropriate ascii_to_native macro definition and the translation
  1361. X *     table itself. Currently, the only non-ASCII native character set
  1362. X *     implemented is EBCDIC but this may not always be so.
  1363. X */
  1364. X
  1365. X#endif
  1366. X
  1367. X
  1368. X
  1369. X
  1370. X
  1371. X/*************/
  1372. X/*  Globals  */
  1373. X/*************/
  1374. X
  1375. X   extern int       tflag;
  1376. X/* extern int       vflag;    (only used in unzip.c)  */
  1377. X   extern int       cflag;
  1378. X   extern int       aflag;
  1379. X   extern int       dflag;
  1380. X   extern int       Uflag;
  1381. X   extern int       V_flag;
  1382. X#ifdef MACOS
  1383. X   extern int       hfsflag;
  1384. X#endif
  1385. X   extern int       lcflag;
  1386. X   extern unsigned  f_attr;
  1387. X   extern longint   csize;
  1388. X   extern longint   ucsize;
  1389. X
  1390. X   extern short     prefix_of[];
  1391. X#ifdef MACOS
  1392. X   extern byte      *suffix_of;
  1393. X   extern byte      *stack;
  1394. X#else
  1395. X   extern byte      suffix_of[];
  1396. X   extern byte      stack[];
  1397. X#endif
  1398. X   extern ULONG     crc32val;
  1399. X   extern UWORD     mask_bits[];
  1400. X
  1401. X   extern byte      *inbuf;
  1402. X   extern byte      *inptr;
  1403. X   extern int       incnt;
  1404. X   extern UWORD     bitbuf;
  1405. X   extern int       bits_left;
  1406. X   extern boolean   zipeof;
  1407. X   extern int       zipfd;
  1408. X   extern char      zipfn[];
  1409. X   extern local_file_header   lrec;
  1410. X   extern struct stat         statbuf;
  1411. X   extern longint   cur_zipfile_bufstart;
  1412. X
  1413. X   extern byte      *outbuf;
  1414. X   extern byte      *outptr;
  1415. X   extern byte      *outout;
  1416. X   extern longint   outpos;
  1417. X   extern int       outcnt;
  1418. X   extern int       outfd;
  1419. X   extern char      filename[];
  1420. X
  1421. X#ifdef DECLARE_ERRNO
  1422. X   extern int       errno;
  1423. X#endif
  1424. X
  1425. X#ifdef EBCDIC
  1426. X   extern byte      ebcdic[];
  1427. X#endif
  1428. END_OF_FILE
  1429.   if test 28924 -ne `wc -c <'./v41/unzip.h'`; then
  1430.     echo shar: \"'./v41/unzip.h'\" unpacked with wrong size!
  1431.   fi
  1432.   # end of './v41/unzip.h'
  1433. fi
  1434. echo shar: End of archive 2 \(of 6\).
  1435. cp /dev/null ark2isdone
  1436. MISSING=""
  1437. for I in 1 2 3 4 5 6 ; do
  1438.     if test ! -f ark${I}isdone ; then
  1439.     MISSING="${MISSING} ${I}"
  1440.     fi
  1441. done
  1442. if test "${MISSING}" = "" ; then
  1443.     echo You have unpacked all 6 archives.
  1444.     rm -f ark[1-9]isdone
  1445. else
  1446.     echo You still must unpack the following archives:
  1447.     echo "        " ${MISSING}
  1448. fi
  1449. exit 0
  1450. exit 0 # Just in case...
  1451. -- 
  1452. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1453. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1454. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1455. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1456.