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

  1. Newsgroups: comp.sources.misc
  2. From: David Kirschbaum <kirsch@usasoc.soc.mil>
  3. Subject:  v19i098:  unzip - Portable unzip v4.1, Part03/06
  4. Message-ID: <1991May20.012153.29243@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 776f1ed8bfd32b5a8bcabe5d505d2190
  6. Date: Mon, 20 May 1991 01:21:53 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: David Kirschbaum <kirsch@usasoc.soc.mil>
  10. Posting-number: Volume 19, Issue 98
  11. Archive-name: unzip/part03
  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/file_io.c ./v41/misc.c ./v41/unimplod.c
  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 3 (of 6)."'
  24. if test -f './v41/file_io.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'./v41/file_io.c'\"
  26. else
  27.   echo shar: Extracting \"'./v41/file_io.c'\" \(23959 characters\)
  28.   sed "s/^X//" >'./v41/file_io.c' <<'END_OF_FILE'
  29. X/*---------------------------------------------------------------------------
  30. X
  31. X  file_io.c
  32. X
  33. X  This file contains routines for doing direct input/output, file-related
  34. X  sorts of things.
  35. X
  36. X  ---------------------------------------------------------------------------*/
  37. X
  38. X
  39. X#include "unzip.h"
  40. X
  41. X
  42. X/************************************/
  43. X/*  File_IO Includes, Defines, etc. */
  44. X/************************************/
  45. X
  46. X#ifdef VMS
  47. X#include <rms.h>                /* RMS prototypes, error codes, etc. */
  48. X#include <ssdef.h>              /* system services error codes */
  49. X#include <descrip.h>            /* "descriptor" format stuff */
  50. X#endif
  51. X
  52. Xstatic int WriteBuffer __((int fd, unsigned char *buf, int len));
  53. Xstatic int dos2unix __((unsigned char *buf, int len));
  54. X
  55. Xint CR_flag = 0;        /* when last char of buffer == CR (for dos2unix()) */
  56. X
  57. X
  58. X
  59. X
  60. X
  61. X/*******************************/
  62. X/*  Function open_input_file() */
  63. X/*******************************/
  64. X
  65. Xint open_input_file()
  66. X{                               /* return non-0 if open failed */
  67. X    /*
  68. X     *  open the zipfile for reading and in BINARY mode to prevent cr/lf
  69. X     *  translation, which would corrupt the bitstreams
  70. X     */
  71. X
  72. X#ifndef UNIX
  73. X    zipfd = open(zipfn, O_RDONLY | O_BINARY);
  74. X#else
  75. X    zipfd = open(zipfn, O_RDONLY);
  76. X#endif
  77. X    if (zipfd < 1) {
  78. X        fprintf(stderr, "error:  can't open zipfile [ %s ]\n", zipfn);
  79. X        return (1);
  80. X    }
  81. X    return 0;
  82. X}
  83. X
  84. X
  85. X
  86. X
  87. X
  88. X/************************/
  89. X/*  Function readbuf()  */
  90. X/************************/
  91. X
  92. Xint readbuf(buf, size)
  93. Xchar *buf;
  94. Xregister unsigned size;
  95. X{                               /* return number of bytes read into buf */
  96. X    register int count;
  97. X    int n;
  98. X
  99. X    n = size;
  100. X    while (size) {
  101. X        if (incnt == 0) {
  102. X            if ((incnt = read(zipfd, inbuf, INBUFSIZ)) <= 0)
  103. X                return (n-size);
  104. X            /* buffer ALWAYS starts on a block boundary:  */
  105. X            cur_zipfile_bufstart += INBUFSIZ;
  106. X            inptr = inbuf;
  107. X        }
  108. X        count = min(size, incnt);
  109. X        memcpy(buf, inptr, count);
  110. X        buf += count;
  111. X        inptr += count;
  112. X        incnt -= count;
  113. X        size -= count;
  114. X    }
  115. X    return (n);
  116. X}
  117. X
  118. X
  119. X
  120. X
  121. X
  122. X#ifdef VMS
  123. X
  124. X/**********************************/
  125. X/*  Function create_output_file() */
  126. X/**********************************/
  127. X
  128. Xint create_output_file()
  129. X{                               /* return non-0 if sys$create failed */
  130. X    /*
  131. X     * VMS VERSION (generic version is below)
  132. X     *
  133. X     * Create the output file and set its date/time using VMS Record Management
  134. X     * Services From Hell.  Then reopen for appending with normal Unix/C-type
  135. X     * I/O functions.  This is the EASY way to set the file date/time under VMS.
  136. X     */
  137. X    int ierr, yr, mo, dy, hh, mm, ss;
  138. X    char timbuf[24];            /* length = first entry in "stupid" + 1 */
  139. X    struct FAB fileblk;
  140. X    struct XABDAT dattim;
  141. X    static char *month[] =
  142. X    {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
  143. X     "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
  144. X/*  fixed-length string descriptor (why not just a pointer to timbuf? sigh.) */
  145. X    struct dsc$descriptor stupid =
  146. X    {23, DSC$K_DTYPE_T, DSC$K_CLASS_S, timbuf};
  147. X
  148. X
  149. X
  150. X/*---------------------------------------------------------------------------
  151. X    First initialize the necessary RMS and date/time variables.  "FAB" stands
  152. X    for "file attribute block," "XAB" for "extended attribute block."  Files
  153. X    under VMS are usually in "variable-length records" format with "carriage-
  154. X    return carriage control" (at least for text files).  Unfortunately, some-
  155. X    where along the line extra "carriage returns" (i.e., line feed characters)
  156. X    get stuck in files which are opened in the variable format.  This may be
  157. X    a VMS problem, an RMS problem, or a Unix/C I/O problem, but every 8192
  158. X    characters of text file is followed by a spurious LF, and more often than
  159. X    that for binary files.  So we use the stream-LF format instead (which is
  160. X    what the Unix/C I/O routines do by default).  EDT complains about such
  161. X    files but goes ahead and edits them; TPU (Adam, Eve) and vi don't seem
  162. X    to care at all.
  163. X  ---------------------------------------------------------------------------*/
  164. X
  165. X    yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + 1980; /* dissect date */
  166. X    mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  167. X    dy = (lrec.last_mod_file_date & 0x1f);
  168. X    hh = (lrec.last_mod_file_time >> 11) & 0x1f;        /* dissect time */
  169. X    mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  170. X    ss = (lrec.last_mod_file_time & 0x1f) * 2;
  171. X
  172. X    fileblk = cc$rms_fab;               /* fill FAB with default values */
  173. X    fileblk.fab$l_fna = filename;       /* l_fna, b_fns are the only re- */
  174. X    fileblk.fab$b_fns = strlen(filename); /*  quired user-supplied fields */
  175. X    fileblk.fab$b_rfm = FAB$C_STMLF;    /* stream-LF record format */
  176. X    fileblk.fab$b_rat = FAB$M_CR;       /* carriage-return carriage ctrl */
  177. X    /*                      ^^^^ *NOT* V_CR!!!     */
  178. X    fileblk.fab$l_xab = &dattim;        /* chain XAB to FAB */
  179. X    dattim = cc$rms_xabdat;             /* fill XAB with default values */
  180. X
  181. X    CR_flag = 0;                /* Hack to get CR at end of buffer working
  182. X                                   (dos2unix) */
  183. X
  184. X/*---------------------------------------------------------------------------
  185. X    Next convert date into an ASCII string, then use a VMS service to con-
  186. X    vert the string into internal time format.  Obviously this is a bit of a
  187. X    kludge, but I have absolutely NO intention of figuring out how to convert
  188. X    MS-DOS time into tenths of microseconds elapsed since freaking 17 Novem-
  189. X    ber 1858!!  Particularly since DEC doesn't even have a native 64-bit data
  190. X    type.  Bleah.
  191. X  ---------------------------------------------------------------------------*/
  192. X
  193. X    sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", dy, month[mo], yr,
  194. X            hh, mm, ss);
  195. X
  196. X/*  "xab$q_cdt" is the XAB field which holds the file's creation date/time */
  197. X    sys$bintim(&stupid, &dattim.xab$q_cdt);
  198. X
  199. X/*---------------------------------------------------------------------------
  200. X    Next create the file under RMS.  If sys$create chokes with an error of
  201. X    RMS$_SYN (syntax error), it's probably because a Unix-style directory was
  202. X    specified, so try to create the file again using the regular creat() func-
  203. X    tion (date/time won't be set properly in this case, obviously).
  204. X  ---------------------------------------------------------------------------*/
  205. X
  206. X    if ((ierr = sys$create(&fileblk)) != RMS$_NORMAL)
  207. X        if (ierr == RMS$_SYN) { /* try Unix/C create:  0 = default perms */
  208. X            outfd = creat(filename, 0, "rfm=stmlf", "rat=cr");
  209. X            if (outfd < 1) {
  210. X                fprintf(stderr, "Can't create output file:  %s\n", filename);
  211. X                return (1);
  212. X            } else {
  213. X                return (0);
  214. X            }
  215. X        } else {                /* probably access violation */
  216. X            fprintf(stderr, "Can't create output file:  %s\n", filename);
  217. X            return (1);
  218. X        }
  219. X
  220. X/*---------------------------------------------------------------------------
  221. X    Finally, close the file under RMS and reopen with Unix/C open() function.
  222. X  ---------------------------------------------------------------------------*/
  223. X
  224. X    sys$close(&fileblk);
  225. X    outfd = open(filename, O_RDWR);
  226. X
  227. X    return (0);
  228. X}
  229. X
  230. X
  231. X
  232. X
  233. X
  234. X#else                           /* !VMS */
  235. X
  236. X/**********************************/
  237. X/*  Function create_output_file() */
  238. X/**********************************/
  239. X
  240. Xint create_output_file()
  241. X{                               /* return non-0 if creat failed */
  242. X    /*
  243. X     * GENERIC VERSION (special VMS version is above)
  244. X     *
  245. X     * Create the output file with default permissions.
  246. X     */
  247. X    extern int do_all;
  248. X    char answerbuf[10];
  249. X    UWORD holder;
  250. X
  251. X
  252. X
  253. X    CR_flag = 0;                /* Hack to get CR at end of buffer working. */
  254. X
  255. X    /*
  256. X     * check if the file exists, unless do_all
  257. X     */
  258. X    if (!do_all) {
  259. X        outfd = open(filename, 0);
  260. X        if (outfd >= 0) {       /* first close it, before you forget! */
  261. X            close(outfd);
  262. X
  263. X            /* ask the user before blowing it away */
  264. X            fprintf(stderr, "replace %s, y-yes, n-no, a-all: ", filename);
  265. X            fgets(answerbuf, 9, stdin);
  266. X
  267. X            switch (answerbuf[0]) {
  268. X            case 'y':
  269. X            case 'Y':
  270. X                break;
  271. X            case 'a':
  272. X            case 'A':
  273. X                do_all = 1;
  274. X                break;
  275. X            case 'n':
  276. X            case 'N':
  277. X            default:
  278. X                while (ReadByte(&holder));
  279. X                return 1;       /* it's done! */
  280. X            }
  281. X        }
  282. X    }
  283. X#ifndef UNIX
  284. X    outfd = creat(filename, (S_IWRITE | S_IREAD) & f_attr);
  285. X#else
  286. X    {
  287. X      int mask;
  288. X      mask = umask(0);
  289. X      outfd = creat(filename, 0777 & f_attr);
  290. X      umask(mask);
  291. X    }
  292. X#endif
  293. X
  294. X    if (outfd < 1) {
  295. X        fprintf(stderr, "Can't create output: %s\n", filename);
  296. X        return 1;
  297. X    }
  298. X    /*
  299. X     * close the newly created file and reopen it in BINARY mode to
  300. X     * disable all CR/LF translations
  301. X     */
  302. X#ifndef UNIX
  303. X#ifdef THINK_C
  304. X    /*
  305. X     * THINKC's stdio routines have the horrible habit of
  306. X     * making any file you open look like generic files
  307. X     * this code tells the OS that it's a text file
  308. X     */
  309. X    if (aflag) {
  310. X        fileParam pb;
  311. X        OSErr err;
  312. X
  313. X        CtoPstr(filename);
  314. X        pb.ioNamePtr = filename;
  315. X        pb.ioVRefNum = 0;
  316. X        pb.ioFVersNum = 0;
  317. X        pb.ioFDirIndex = 0;
  318. X        err = PBGetFInfo(&pb,0);
  319. X        if (err == noErr) {
  320. X            pb.ioFlFndrInfo.fdCreator = '????';
  321. X            pb.ioFlFndrInfo.fdType = 'TEXT';
  322. X            err = PBSetFInfo(&pb, 0);
  323. X        }
  324. X        PtoCstr(filename);
  325. X    }
  326. X#endif
  327. X    if (!aflag) {
  328. X        close(outfd);
  329. X        outfd = open(filename, O_RDWR | O_BINARY);
  330. X    }
  331. X#endif
  332. X    return 0;
  333. X}
  334. X
  335. X#endif                          /* !VMS */
  336. X
  337. X
  338. X
  339. X
  340. X
  341. X/*****************************/
  342. X/*  Function FillBitBuffer() */
  343. X/*****************************/
  344. X
  345. Xint FillBitBuffer(bits)
  346. Xregister int bits;
  347. X{
  348. X    /*
  349. X     * Get the bits that are left and read the next UWORD.  This
  350. X     * function is only used by the READBIT macro (which is used
  351. X     * by all of the uncompression routines).
  352. X     */
  353. X    register int result = bitbuf;
  354. X    UWORD temp;
  355. X    int sbits = bits_left;
  356. X
  357. X
  358. X    bits -= bits_left;
  359. X
  360. X    /* read next UWORD of input */
  361. X    bits_left = ReadByte(&bitbuf);
  362. X    bits_left += ReadByte(&temp);
  363. X
  364. X    bitbuf |= (temp << 8);
  365. X    if (bits_left == 0)
  366. X        zipeof = 1;
  367. X
  368. X    /* get the remaining bits */
  369. X    result = result | (int) ((bitbuf & mask_bits[bits]) << sbits);
  370. X    bitbuf >>= bits;
  371. X    bits_left -= bits;
  372. X    return result;
  373. X}
  374. X
  375. X
  376. X
  377. X
  378. X
  379. X/************************/
  380. X/*  Function ReadByte() */
  381. X/************************/
  382. X
  383. Xint ReadByte(x)
  384. XUWORD *x;
  385. X{
  386. X    /*
  387. X     * read a byte; return 8 if byte available, 0 if not
  388. X     */
  389. X
  390. X
  391. X    if (csize-- <= 0)
  392. X        return 0;
  393. X
  394. X    if (incnt == 0) {
  395. X        if ((incnt = read(zipfd, inbuf, INBUFSIZ)) <= 0)
  396. X            return 0;
  397. X        /* buffer ALWAYS starts on a block boundary:  */
  398. X        cur_zipfile_bufstart += INBUFSIZ;
  399. X        inptr = inbuf;
  400. X    }
  401. X    *x = *inptr++;
  402. X    --incnt;
  403. X    return 8;
  404. X}
  405. X
  406. X
  407. X
  408. X#ifdef FLUSH_AND_WRITE
  409. X/***************************/
  410. X/*  Function FlushOutput() */
  411. X/***************************/
  412. X
  413. Xint FlushOutput()
  414. X{                               /* return PK-type error code */
  415. X    /* flush contents of output buffer */
  416. X    /*
  417. X     * This combined version doesn't work, and I sure can't see why not...
  418. X     * probably something stupid, but how much can you screw up in 6 lines???
  419. X     * [optimization problem??]
  420. X     */
  421. X    int len;
  422. X
  423. X
  424. X    if (outcnt) {
  425. X        UpdateCRC(outbuf, outcnt);
  426. X
  427. X        if (!tflag) {
  428. X            if (aflag)
  429. X                len = dos2unix(outbuf, outcnt);
  430. X            if (write(outfd, outout, len) != len) {
  431. X                fprintf(stderr, "Fatal write error.\n");
  432. X                return (50);    /* 50:  disk full */
  433. X            }
  434. X        }
  435. X        outpos += outcnt;
  436. X        outcnt = 0;
  437. X        outptr = outbuf;
  438. X    }
  439. X    return (0);                 /* 0:  no error */
  440. X}
  441. X
  442. X#else                           /* separate flush and write routines */
  443. X/***************************/
  444. X/*  Function FlushOutput() */
  445. X/***************************/
  446. X
  447. Xint FlushOutput()
  448. X{                               /* return PK-type error code */
  449. X    /* flush contents of output buffer */
  450. X    if (outcnt) {
  451. X        UpdateCRC(outbuf, outcnt);
  452. X
  453. X        if (!tflag && WriteBuffer(outfd, outbuf, outcnt))
  454. X            return (50);        /* 50:  disk full */
  455. X
  456. X        outpos += outcnt;
  457. X        outcnt = 0;
  458. X        outptr = outbuf;
  459. X    }
  460. X    return (0);                 /* 0:  no error */
  461. X}
  462. X
  463. X/***************************/
  464. X/*  Function WriteBuffer() */
  465. X/***************************/
  466. X
  467. Xstatic int WriteBuffer(fd, buf, len)    /* return 0 if successful, 1 if not */
  468. Xint fd;
  469. Xunsigned char *buf;
  470. Xint len;
  471. X{
  472. X    if (aflag)
  473. X        len = dos2unix(buf, len);
  474. X    if (write(fd, outout, len) != len) {
  475. X#ifdef DOS_OS2
  476. X        if (!cflag) {           /* ^Z treated as EOF, removed with -c */
  477. X#endif
  478. X            fprintf(stderr, "Fatal write error.\n");
  479. X            return (1);         /* FAILED */
  480. X#ifdef DOS_OS2
  481. X        }
  482. X#endif
  483. X    }
  484. X    return (0);
  485. X}
  486. X
  487. X#endif
  488. X
  489. X
  490. X
  491. X
  492. X/************************/
  493. X/*  Function dos2unix() */
  494. X/************************/
  495. X
  496. Xstatic int dos2unix(buf, len)
  497. Xunsigned char *buf;
  498. Xint len;
  499. X{
  500. X    int new_len;
  501. X    int i;
  502. X    unsigned char *walker;
  503. X
  504. X    new_len = len;
  505. X    walker = outout;
  506. X#ifdef MACOS
  507. X    /*
  508. X     * Mac wants to strip LFs instead CRs from CRLF pairs
  509. X     */
  510. X    if (CR_flag && *buf == LF) {
  511. X        buf++;
  512. X        new_len--;
  513. X        len--;
  514. X        CR_flag = buf[len] == CR;
  515. X    }
  516. X    else
  517. X        CR_flag = buf[len - 1] == CR;
  518. X    for (i = 0; i < len; i += 1) {
  519. X        *walker++ = ascii_to_native(*buf);
  520. X        if (*buf == LF) walker[-1] = CR;
  521. X        if (*buf++ == CR && *buf == LF) {
  522. X            new_len--;
  523. X            buf++;
  524. X            i++;
  525. X        }
  526. X    }
  527. X#else
  528. X    if (CR_flag && *buf != LF)
  529. X        *walker++ = ascii_to_native(CR);
  530. X    CR_flag = buf[len - 1] == CR;
  531. X    for (i = 0; i < len; i += 1) {
  532. X        *walker++ = ascii_to_native(*buf);
  533. X        if (*buf++ == CR && *buf == LF) {
  534. X            new_len--;
  535. X            walker[-1] = ascii_to_native(*buf++);
  536. X            i++;
  537. X        }
  538. X    }
  539. X    /*
  540. X     * If the last character is a CR, then "ignore it" for now...
  541. X     */
  542. X    if (walker[-1] == ascii_to_native(CR))
  543. X        new_len--;
  544. X#endif
  545. X    return new_len;
  546. X}
  547. X
  548. X
  549. X
  550. X
  551. X
  552. X#ifdef DOS_OS2
  553. X
  554. X/***************************************/
  555. X/*  Function set_file_time_and_close() */
  556. X/***************************************/
  557. X
  558. Xvoid set_file_time_and_close()
  559. X /*
  560. X  * MS-DOS AND OS/2 VERSION (Mac, Unix versions are below)
  561. X  *
  562. X  * Set the output file date/time stamp according to information from the
  563. X  * zipfile directory record for this member, then close the file.  This
  564. X  * is optional and can be deleted if your compiler does not easily support
  565. X  * setftime().
  566. X  */
  567. X{
  568. X/*---------------------------------------------------------------------------
  569. X    Allocate local variables needed by OS/2 and Turbo C.  [OK, OK, so it's
  570. X    a bogus comment...but this routine was getting way too cluttered and
  571. X    needed some visual separators.  Bleah.]
  572. X  ---------------------------------------------------------------------------*/
  573. X
  574. X#ifdef OS2              /* (assuming only MSC or MSC-compatible compilers
  575. X                         * for this part) */
  576. X
  577. X    union {
  578. X        FDATE fd;               /* system file date record */
  579. X        UWORD zdate;            /* date word */
  580. X    } ud;
  581. X
  582. X    union {
  583. X        FTIME ft;               /* system file time record */
  584. X        UWORD ztime;            /* time word */
  585. X    } ut;
  586. X
  587. X    FILESTATUS fs;
  588. X
  589. X#else                           /* !OS2 */
  590. X#ifdef __TURBOC__
  591. X
  592. X    union {
  593. X        struct ftime ft;        /* system file time record */
  594. X        struct {
  595. X            UWORD ztime;        /* date and time words */
  596. X            UWORD zdate;        /* .. same format as in .ZIP file */
  597. X        } zt;
  598. X    } td;
  599. X
  600. X#endif                          /* __TURBOC__ */
  601. X#endif                          /* !OS2 */
  602. X
  603. X    /*
  604. X     * Do not attempt to set the time stamp on standard output
  605. X     */
  606. X    if (cflag) {
  607. X        close(outfd);
  608. X        return;
  609. X    }
  610. X
  611. X
  612. X/*---------------------------------------------------------------------------
  613. X    Copy and/or convert time and date variables, if necessary; then set the
  614. X    file time/date.
  615. X  ---------------------------------------------------------------------------*/
  616. X
  617. X#ifdef OS2
  618. X
  619. X    DosQFileInfo(outfd, 1, &fs, sizeof(fs));
  620. X    ud.zdate = lrec.last_mod_file_date;
  621. X    fs.fdateLastWrite = ud.fd;
  622. X    ut.ztime = lrec.last_mod_file_time;
  623. X    fs.ftimeLastWrite = ut.ft;
  624. X    DosSetFileInfo(outfd, 1, &fs, sizeof(fs));
  625. X
  626. X#else                           /* !OS2 */
  627. X#ifdef __TURBOC__
  628. X
  629. X    td.zt.ztime = lrec.last_mod_file_time;
  630. X    td.zt.zdate = lrec.last_mod_file_date;
  631. X    setftime(outfd, &td.ft);
  632. X
  633. X#else                           /* !__TURBOC__:  MSC MS-DOS */
  634. X
  635. X    _dos_setftime(outfd, lrec.last_mod_file_date, lrec.last_mod_file_time);
  636. X
  637. X#endif                          /* !__TURBOC__ */
  638. X#endif                          /* !OS2 */
  639. X
  640. X/*---------------------------------------------------------------------------
  641. X    And finally we can close the file...at least everybody agrees on how to
  642. X    do *this*.  I think...
  643. X  ---------------------------------------------------------------------------*/
  644. X
  645. X    close(outfd);
  646. X}
  647. X
  648. X
  649. X
  650. X
  651. X
  652. X#else                           /* !DOS_OS2 ... */
  653. X#ifndef VMS                     /* && !VMS (already done) ... */
  654. X#ifndef MTS                     /* && !MTS (can't do):  Mac or UNIX */
  655. X#ifdef MACOS                    /* Mac first */
  656. X
  657. X/***************************************/
  658. X/*  Function set_file_time_and_close() */
  659. X/***************************************/
  660. X
  661. Xvoid set_file_time_and_close()
  662. X /*
  663. X  * MAC VERSION
  664. X  *
  665. X  * First close the output file, then set its date/time stamp according
  666. X  * to information from the zipfile directory record for this file.  [So
  667. X  * technically this should be called "close_file_and_set_time()", but
  668. X  * this way we can use the same prototype for either case, without extra
  669. X  * #ifdefs.  So there.]
  670. X  */
  671. X{
  672. X    long m_time;
  673. X    DateTimeRec dtr;
  674. X    ParamBlockRec pbr;
  675. X    OSErr err;
  676. X
  677. X    if (outfd != 1)
  678. X    {
  679. X        close(outfd);
  680. X
  681. X        /*
  682. X         * Macintosh bases all file modification times on the number of seconds
  683. X         * elapsed since Jan 1, 1904, 00:00:00.  Therefore, to maintain
  684. X         * compatibility with MS-DOS archives, which date from Jan 1, 1980,
  685. X         * with NO relation to GMT, the following conversions must be made:
  686. X         *      the Year (yr) must be incremented by 1980;
  687. X         *      and converted to seconds using the Mac routine Date2Secs(),
  688. X         *      almost similar in complexity to the Unix version :-)
  689. X         *                                     J. Lee
  690. X         */
  691. X
  692. X        dtr.year = (((lrec.last_mod_file_date >> 9) & 0x7f) + 1980); /* dissect date */
  693. X        dtr.month = ((lrec.last_mod_file_date >> 5) & 0x0f);
  694. X        dtr.day = (lrec.last_mod_file_date & 0x1f);
  695. X
  696. X        dtr.hour = ((lrec.last_mod_file_time >> 11) & 0x1f);      /* dissect time */
  697. X        dtr.minute = ((lrec.last_mod_file_time >> 5) & 0x3f);
  698. X        dtr.second = ((lrec.last_mod_file_time & 0x1f) * 2);
  699. X        Date2Secs(&dtr, &m_time);
  700. X        CtoPstr(filename);
  701. X        pbr.fileParam.ioNamePtr = filename;
  702. X        pbr.fileParam.ioVRefNum = pbr.fileParam.ioFVersNum = pbr.fileParam.ioFDirIndex = 0;
  703. X        err = PBGetFInfo(&pbr, 0L);
  704. X        pbr.fileParam.ioFlMdDat = pbr.fileParam.ioFlCrDat = m_time;
  705. X        if (err == noErr) {
  706. X            err = PBSetFInfo(&pbr, 0L);
  707. X        }
  708. X        if (err != noErr) {
  709. X            printf("Error, can't set the time for %s\n",filename);
  710. X        }
  711. X
  712. X        /* set read-only perms if needed */
  713. X        if (err != noErr && f_attr != 0) {
  714. X            err = SetFLock(filename, 0);
  715. X        }
  716. X        PtoCstr(filename);
  717. X    }
  718. X}
  719. X
  720. X
  721. X
  722. X
  723. X
  724. X#else                           /* !MACOS:  only one left is UNIX */
  725. X
  726. X/***************************************/
  727. X/*  Function set_file_time_and_close() */
  728. X/***************************************/
  729. X
  730. Xvoid set_file_time_and_close()
  731. X /*
  732. X  * UNIX VERSION (MS-DOS & OS/2, Mac versions are above)
  733. X  *
  734. X  * First close the output file, then set its date/time stamp according
  735. X  * to information from the zipfile directory record for this file.  [So
  736. X  * technically this should be called "close_file_and_set_time()", but
  737. X  * this way we can use the same prototype for either case, without extra
  738. X  * #ifdefs.  So there.]
  739. X  */
  740. X{
  741. X    long m_time;
  742. X    int yr, mo, dy, hh, mm, ss, leap, days = 0;
  743. X    struct utimbuf {
  744. X      time_t atime;             /* New access time */
  745. X      time_t mtime;             /* New modification time */
  746. X    } tp;
  747. X#ifdef BSD
  748. X    static struct timeb tbp;
  749. X#else
  750. X    extern long timezone;
  751. X#endif
  752. X
  753. X
  754. X    close(outfd);
  755. X
  756. X    if (cflag)                  /* can't set time on stdout */
  757. X        return;
  758. X
  759. X    /*
  760. X     * These date conversions look a little weird, so I'll explain.
  761. X     * UNIX bases all file modification times on the number of seconds
  762. X     * elapsed since Jan 1, 1970, 00:00:00 GMT.  Therefore, to maintain
  763. X     * compatibility with MS-DOS archives, which date from Jan 1, 1980,
  764. X     * with NO relation to GMT, the following conversions must be made:
  765. X     *      the Year (yr) must be incremented by 10;
  766. X     *      the Date (dy) must be decremented by 1;
  767. X     *      and the whole mess must be adjusted by TWO factors:
  768. X     *          relationship to GMT (ie.,Pacific Time adds 8 hrs.),
  769. X     *          and whether or not it is Daylight Savings Time.
  770. X     * Also, the usual conversions must take place to account for leap years,
  771. X     * etc.
  772. X     *                                     C. Seaman
  773. X     */
  774. X
  775. X    yr = (((lrec.last_mod_file_date >> 9) & 0x7f) + 10); /* dissect date */
  776. X    mo = ((lrec.last_mod_file_date >> 5) & 0x0f);
  777. X    dy = ((lrec.last_mod_file_date & 0x1f) - 1);
  778. X
  779. X    hh = ((lrec.last_mod_file_time >> 11) & 0x1f);      /* dissect time */
  780. X    mm = ((lrec.last_mod_file_time >> 5) & 0x3f);
  781. X    ss = ((lrec.last_mod_file_time & 0x1f) * 2);
  782. X
  783. X    /* leap = # of leap years from 1970 up to but not including
  784. X       the current year */
  785. X
  786. X    leap = ((yr + 1969) / 4);   /* Leap year base factor */
  787. X
  788. X    /* How many days from 1970 to this year? */
  789. X    days = (yr * 365) + (leap - 492);
  790. X
  791. X    switch (mo) {               /* calculate expired days this year */
  792. X    case 12:
  793. X        days += 30;
  794. X    case 11:
  795. X        days += 31;
  796. X    case 10:
  797. X        days += 30;
  798. X    case 9:
  799. X        days += 31;
  800. X    case 8:
  801. X        days += 31;
  802. X    case 7:
  803. X        days += 30;
  804. X    case 6:
  805. X        days += 31;
  806. X    case 5:
  807. X        days += 30;
  808. X    case 4:
  809. X        days += 31;
  810. X    case 3:
  811. X        days += 28;             /* account for leap years (2000 IS one) */
  812. X        if (((yr + 1970) % 4 == 0) && (yr + 1970) != 2100)  /* OK thru 2199 */
  813. X            ++days;
  814. X    case 2:
  815. X        days += 31;
  816. X    }
  817. X
  818. X    /* convert date & time to seconds relative to 00:00:00, 01/01/1970 */
  819. X    m_time = ((days + dy) * 86400) + (hh * 3600) + (mm * 60) + ss;
  820. X
  821. X#ifdef BSD
  822. X   ftime(&tbp);
  823. X   m_time += tbp.timezone * 60L;
  824. X#else                                   /* !BSD */
  825. X    tzset();                            /* Set `timezone'. */
  826. X    m_time += timezone;                 /* account for timezone differences */
  827. X#endif
  828. X
  829. X    if (localtime(&m_time)->tm_isdst)
  830. X        m_time -= 60L * 60L;            /* Adjust for daylight savings time */
  831. X
  832. X    /* set the time stamp on the file */
  833. X    
  834. X    tp.mtime = m_time;                  /* Set modification time */
  835. X    tp.atime = m_time;                  /* Set access time */
  836. X
  837. X    if (utime(filename, &tp))
  838. X        fprintf(stderr, "Error, can't set the time for %s\n",filename);
  839. X}
  840. X
  841. X#endif                          /* ?MACOS */
  842. X#endif                          /* ?MTS */
  843. X#endif                          /* ?VMS */
  844. X#endif                          /* ?DOS_OS2 */
  845. END_OF_FILE
  846.   if test 23959 -ne `wc -c <'./v41/file_io.c'`; then
  847.     echo shar: \"'./v41/file_io.c'\" unpacked with wrong size!
  848.   fi
  849.   # end of './v41/file_io.c'
  850. fi
  851. if test -f './v41/misc.c' -a "${1}" != "-c" ; then 
  852.   echo shar: Will not clobber existing file \"'./v41/misc.c'\"
  853. else
  854.   echo shar: Extracting \"'./v41/misc.c'\" \(17338 characters\)
  855.   sed "s/^X//" >'./v41/misc.c' <<'END_OF_FILE'
  856. X/*---------------------------------------------------------------------------
  857. X
  858. X  misc.c
  859. X
  860. X  This file contains a number of useful but not particularly closely related
  861. X  functions; their main claim to fame is that they don't change much, so
  862. X  this file should rarely need to be recompiled.  The CRC-32 stuff is from
  863. X  crc32.c; do_string() is from nunzip.c; a_to_e() is from ascebc.c; makeword/
  864. X  makelong() are from unzip.c; and memset() and memcpy() are from zmemset.c
  865. X  and zmemcpy.c, respectively.  Lumped together here to cut down on the size
  866. X  of unzip.c and the number of associated files floating around.
  867. X
  868. X  ---------------------------------------------------------------------------
  869. X
  870. X  Contributions by C. Mascott, Allan Bjorklund, Bill Davidsen, Bo Kullmar,
  871. X  Warner Losh, Greg Roelofs, Larry Jones, Mark Edwards, Antoine Verheijen,
  872. X  and probably many others.
  873. X
  874. X  ---------------------------------------------------------------------------
  875. X
  876. X  Copyright, applying to UpdateCRC() and crc_32_tab[]:
  877. X
  878. X     COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or code
  879. X     or tables extracted from it, as desired without restriction.
  880. X
  881. X  ---------------------------------------------------------------------------*/
  882. X
  883. X
  884. X#include "unzip.h"
  885. X
  886. X
  887. X
  888. X/**************************/
  889. X/*  Function UpdateCRC()  */
  890. X/**************************/
  891. X
  892. X /*--------------------------------------------------------------------
  893. X
  894. X   First, the polynomial itself and its table of feedback terms.  The
  895. X   polynomial is
  896. X   X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
  897. X
  898. X   Note that we take it "backwards" and put the highest-order term in
  899. X   the lowest-order bit.  The X^32 term is "implied"; the LSB is the
  900. X   X^31 term, etc.  The X^0 term (usually shown as "+1") results in
  901. X   the MSB being 1.
  902. X
  903. X   Note that the usual hardware shift register implementation, which
  904. X   is what we're using (we're merely optimizing it by doing eight-bit
  905. X   chunks at a time) shifts bits into the lowest-order term.  In our
  906. X   implementation, that means shifting towards the right.  Why do we
  907. X   do it this way?  Because the calculated CRC must be transmitted in
  908. X   order from highest-order term to lowest-order term.  UARTs transmit
  909. X   characters in order from LSB to MSB.  By storing the CRC this way,
  910. X   we hand it to the UART in the order low-byte to high-byte; the UART
  911. X   sends each low-bit to hight-bit; and the result is transmission bit
  912. X   by bit from highest- to lowest-order term without requiring any bit
  913. X   shuffling on our part.  Reception works similarly.
  914. X
  915. X   The feedback terms table consists of 256, 32-bit entries.  Notes:
  916. X
  917. X       The table can be generated at runtime if desired; code to do so
  918. X       is shown later.  It might not be obvious, but the feedback
  919. X       terms simply represent the results of eight shift/xor opera-
  920. X       tions for all combinations of data and CRC register values.
  921. X
  922. X       The values must be right-shifted by eight bits by the "updcrc"
  923. X       logic; the shift must be unsigned (bring in zeroes).  On some
  924. X       hardware you could probably optimize the shift in assembler by
  925. X       using byte-swap instructions.
  926. X       polynomial $edb88320
  927. X
  928. X   --------------------------------------------------------------------*/
  929. X
  930. XULONG crc_32_tab[] =
  931. X{
  932. X    0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
  933. X    0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
  934. X    0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
  935. X    0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
  936. X    0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
  937. X    0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
  938. X    0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
  939. X    0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
  940. X    0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
  941. X    0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
  942. X    0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
  943. X    0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
  944. X    0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
  945. X    0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
  946. X    0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
  947. X    0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
  948. X    0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
  949. X    0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
  950. X    0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
  951. X    0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
  952. X    0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
  953. X    0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
  954. X    0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
  955. X    0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
  956. X    0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
  957. X    0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
  958. X    0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
  959. X    0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
  960. X    0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
  961. X    0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
  962. X    0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
  963. X    0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
  964. X    0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
  965. X    0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
  966. X    0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
  967. X    0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
  968. X    0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
  969. X    0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
  970. X    0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
  971. X    0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
  972. X    0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
  973. X    0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
  974. X    0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
  975. X    0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
  976. X    0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
  977. X    0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
  978. X    0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
  979. X    0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
  980. X    0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
  981. X    0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
  982. X    0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
  983. X    0x2d02ef8dL
  984. X};
  985. X
  986. X
  987. Xvoid UpdateCRC(s, len)
  988. Xregister byte *s;
  989. Xregister int len;
  990. X /* update running CRC calculation with contents of a buffer */
  991. X{
  992. X    register ULONG crcval = crc32val;
  993. X
  994. X
  995. X    while (len--)
  996. X        crcval = crc_32_tab[((byte) crcval ^ (*s++)) & 0xff] ^ (crcval >> 8);
  997. X    crc32val = crcval;
  998. X}
  999. X
  1000. X
  1001. X
  1002. X
  1003. X
  1004. X/**************************/
  1005. X/*  Function do_string()  */
  1006. X/**************************/
  1007. X
  1008. Xint do_string(len, option)      /* return PK-type error code */
  1009. Xunsigned int len;               /* without prototype, UWORD converted to this */
  1010. Xint option;
  1011. X{
  1012. X    int block_length, error = 0;
  1013. X    UWORD comment_bytes_left, extra_len;
  1014. X
  1015. X
  1016. X
  1017. X/*---------------------------------------------------------------------------
  1018. X    This function processes arbitrary-length (well, usually) strings.  Three
  1019. X    options are allowed:  SKIP, wherein the string is skipped pretty logical,
  1020. X    eh?); DISPLAY, wherein the string is printed to standard output after un-
  1021. X    dergoing any necessary or unnecessary character conversions; and FILENAME,
  1022. X    wherein the string is put into the filename[] array after undergoing ap-
  1023. X    propriate conversions (including case-conversion, if that is indicated:
  1024. X    see the global variable lcflag).  The latter option should be OK, since
  1025. X    filename is now dimensioned at FILENAME_MAX (1024).
  1026. X
  1027. X    The string, by the way, is assumed to start at the current file-pointer
  1028. X    position; its length is given by len.  So start off by checking length
  1029. X    of string:  if zero, we're already set.
  1030. X  ---------------------------------------------------------------------------*/
  1031. X
  1032. X    if (!len)
  1033. X        return (0);             /* 0:  no error */
  1034. X
  1035. X    switch (option) {
  1036. X
  1037. X    /*
  1038. X     * First case:  print string on standard output.  First set loop vari-
  1039. X     * ables, then loop through the comment in chunks of OUTBUFSIZ bytes,
  1040. X     * converting formats and printing as we go.  The second half of the
  1041. X     * loop conditional was added because the file might be truncated, in
  1042. X     * which case comment_bytes_left will remain at some non-zero value for
  1043. X     * all time.  outbuf is used as a scratch buffer because it is avail-
  1044. X     * able (we should be either before or in between any file processing).
  1045. X     * [The typecast in front of the min() macro was added because of the
  1046. X     * new promotion rules under ANSI C; readbuf() wants an int, but min()
  1047. X     * returns a signed long, if I understand things correctly.  The proto-
  1048. X     * type should handle it, but just in case...]
  1049. X     */
  1050. X
  1051. X    case DISPLAY:
  1052. X        comment_bytes_left = len;
  1053. X        block_length = OUTBUFSIZ;    /* for the while statement, first time */
  1054. X        while (comment_bytes_left > 0 && block_length > 0) {
  1055. X            if ((block_length = readbuf((char *) outbuf,
  1056. X                         (int) min(OUTBUFSIZ, comment_bytes_left))) <= 0)
  1057. X                return (51);    /* 51:  unexpected EOF */
  1058. X            comment_bytes_left -= block_length;
  1059. X            NUKE_CRs(outbuf, block_length);     /* (modifies block_length) */
  1060. X
  1061. X            /*  this is why we allocated an extra byte for outbuf: */
  1062. X            outbuf[block_length] = '\0';        /* terminate w/zero:  ASCIIZ */
  1063. X
  1064. X            A_TO_N(outbuf);     /* translate string to native */
  1065. X
  1066. X            printf("%s", outbuf);
  1067. X        }
  1068. X        printf("\n", outbuf);   /* assume no newline at end */
  1069. X        break;
  1070. X
  1071. X    /*
  1072. X     * Second case:  read string into filename[] array.  The filename should
  1073. X     * never ever be longer than FILNAMSIZ (1024), but for now we'll check,
  1074. X     * just to be sure.
  1075. X     */
  1076. X
  1077. X    case FILENAME:
  1078. X        extra_len = 0;
  1079. X        if (len >= FILNAMSIZ) {
  1080. X            fprintf(stderr, "warning:  filename too long--truncating.\n");
  1081. X            error = 1;          /* 1:  warning error */
  1082. X            extra_len = len - FILNAMSIZ + 1;
  1083. X            len = FILNAMSIZ - 1;
  1084. X        }
  1085. X        if (readbuf(filename, len) <= 0)
  1086. X            return (51);        /* 51:  unexpected EOF */
  1087. X        filename[len] = '\0';   /* terminate w/zero:  ASCIIZ */
  1088. X
  1089. X        A_TO_N(filename);       /* translate string to native */
  1090. X
  1091. X        if (lcflag)
  1092. X            TOLOWER(filename, filename);        /* replace with lowercase fn. */
  1093. X
  1094. X        if (!extra_len)         /* we're done here */
  1095. X            break;
  1096. X
  1097. X        /*
  1098. X         * We truncated the filename, so print what's left and then fall
  1099. X         * through to the SKIP routine.
  1100. X         */
  1101. X        fprintf(stderr, "[ %s ]\n", filename);
  1102. X        len = extra_len;
  1103. X        /*  FALL THROUGH...  */
  1104. X
  1105. X    /*
  1106. X     * Third case:  skip string, adjusting readbuf's internal variables
  1107. X     * as necessary (and possibly skipping to and reading a new block of
  1108. X     * data).
  1109. X     */
  1110. X
  1111. X    case SKIP:
  1112. X        LSEEK(cur_zipfile_bufstart + (inptr-inbuf) + len)
  1113. X        break;
  1114. X
  1115. X    }                           /* end switch (option) */
  1116. X
  1117. X    return (error);
  1118. X
  1119. X}                               /* end function do_string() */
  1120. X
  1121. X
  1122. X
  1123. X
  1124. X
  1125. X#ifdef EBCDIC
  1126. X
  1127. X/*
  1128. X * This is the MTS ASCII->EBCDIC translation table. It provides a 1-1
  1129. X * translation from ISO 8859/1 8-bit ASCII to IBM Code Page 37 EBCDIC.
  1130. X */
  1131. X
  1132. Xunsigned char ebcdic[] =
  1133. X{
  1134. X    0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, 0x16, 0x05, 0x25, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  1135. X    0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f,
  1136. X    0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61,
  1137. X    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f,
  1138. X    0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
  1139. X    0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xba, 0xe0, 0xbb, 0xb0, 0x6d,
  1140. X    0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
  1141. X    0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07,
  1142. X    0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x06, 0x17, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x1b,
  1143. X    0x30, 0x31, 0x1a, 0x33, 0x34, 0x35, 0x36, 0x08, 0x38, 0x39, 0x3a, 0x3b, 0x04, 0x14, 0x3e, 0xff,
  1144. X    0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, 0xbd, 0xb4, 0x9a, 0x8a, 0x5f, 0xca, 0xaf, 0xbc,
  1145. X    0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab,
  1146. X    0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77,
  1147. X    0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xad, 0xae, 0x59,
  1148. X    0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57,
  1149. X    0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf
  1150. X};
  1151. X
  1152. X#endif                          /* EBCDIC */
  1153. X
  1154. X
  1155. X
  1156. X
  1157. X
  1158. X#ifdef NOTINT16
  1159. X
  1160. X/*************************/
  1161. X/*  Function makeword()  */
  1162. X/*************************/
  1163. X
  1164. XUWORD makeword(b)
  1165. Xbyte *b;
  1166. X /*
  1167. X  * Convert Intel style 'short' integer to non-Intel non-16-bit
  1168. X  * host format.  This routine also takes care of byte-ordering.
  1169. X  */
  1170. X{
  1171. X/*
  1172. X    return  ( ((UWORD)(b[1]) << 8)  |  (UWORD)(b[0]) );
  1173. X */
  1174. X    return ((b[1] << 8) | b[0]);
  1175. X}
  1176. X
  1177. X
  1178. X
  1179. X
  1180. X
  1181. X/*************************/
  1182. X/*  Function makelong()  */
  1183. X/*************************/
  1184. X
  1185. XULONG makelong(sig)
  1186. Xbyte *sig;
  1187. X /*
  1188. X  * Convert intel style 'long' variable to non-Intel non-16-bit
  1189. X  * host format.  This routine also takes care of byte-ordering.
  1190. X  */
  1191. X{
  1192. X    return (((ULONG) sig[3]) << 24)
  1193. X        + (((ULONG) sig[2]) << 16)
  1194. X        + (((ULONG) sig[1]) << 8)
  1195. X        + ((ULONG) sig[0]);
  1196. X}
  1197. X
  1198. X#endif                          /* !NOTINT16 */
  1199. X
  1200. X
  1201. X
  1202. X
  1203. X
  1204. X#ifdef VMS
  1205. X
  1206. X/***************************/
  1207. X/*  Function return_VMS()  */
  1208. X/***************************/
  1209. X
  1210. Xvoid return_VMS(zip_error)
  1211. Xint zip_error;
  1212. X{
  1213. X/*---------------------------------------------------------------------------
  1214. X    Do our own, explicit processing of error codes and print message, since
  1215. X    VMS misinterprets return codes as rather obnoxious system errors ("access
  1216. X    violation," for example).
  1217. X  ---------------------------------------------------------------------------*/
  1218. X
  1219. X#ifndef NO_RETURN_CODES         /* can compile without messages if want */
  1220. X    switch (zip_error) {
  1221. X
  1222. X    case 0:
  1223. X        break;                  /* life is fine... */
  1224. X    case 1:
  1225. X        fprintf(stderr, "\n[return-code 1:  warning error \
  1226. X(e.g., failed CRC or unknown compression method)]\n");
  1227. X        break;
  1228. X    case 2:
  1229. X    case 3:
  1230. X        fprintf(stderr, "\n[return-code %d:  error in zipfile \
  1231. X(e.g., can't find local file header sig)]\n",
  1232. X                zip_error);
  1233. X        break;
  1234. X    case 4:
  1235. X    case 5:
  1236. X    case 6:
  1237. X    case 7:
  1238. X    case 8:
  1239. X        fprintf(stderr, "\n[return-code %d:  insufficient memory]\n",
  1240. X                zip_error);
  1241. X        break;
  1242. X    case 9:
  1243. X        fprintf(stderr, "\n[return-code 9:  zipfile not found]\n");
  1244. X        break;
  1245. X    case 10:                    /* this is the one that gives "access violation," I think */
  1246. X        fprintf(stderr, "\n[return-code 10:  bad or illegal parameters \
  1247. Xspecified on command line]\n");
  1248. X        break;
  1249. X    case 11:                    /* I'm not sure this one is implemented, but maybe soon? */
  1250. X        fprintf(stderr, "\n[return-code 11:  no files found to \
  1251. Xextract/view/etc.]\n");
  1252. X        break;
  1253. X    case 50:
  1254. X        fprintf(stderr, "\n[return-code 50:  disk full \
  1255. X(or otherwise unable to open output file)]\n");
  1256. X        break;
  1257. X    case 51:
  1258. X        fprintf(stderr, "\n[return-code 51:  unexpected EOF in zipfile \
  1259. X(i.e., truncated)]\n");
  1260. X        break;
  1261. X    default:
  1262. X        fprintf(stderr, "\n[return-code %d:  unknown return-code \
  1263. X(who put this one in?  Wasn't me...)]\n",
  1264. X                zip_error);
  1265. X        break;
  1266. X    }
  1267. X#endif                          /* NO_RETURN_CODES */
  1268. X
  1269. X    exit(0);                    /* everything okey-dokey as far as VMS concerned */
  1270. X}
  1271. X
  1272. X#endif                          /* VMS */
  1273. X
  1274. X
  1275. X
  1276. X
  1277. X
  1278. X#ifdef ZMEM                     /* memset, memcpy for systems without them */
  1279. X
  1280. X/************************/
  1281. X/*  Function zmemset()  */
  1282. X/************************/
  1283. X
  1284. Xchar *memset(buf, init, len)
  1285. Xregister char *buf, init;       /* buffer loc and initializer */
  1286. Xregister unsigned int len;      /* length of the buffer */
  1287. X{
  1288. X    char *start;
  1289. X
  1290. X    start = buf;
  1291. X    while (len--)
  1292. X        *(buf++) = init;
  1293. X    return (start);
  1294. X}
  1295. X
  1296. X
  1297. X
  1298. X
  1299. X
  1300. X/************************/
  1301. X/*  Function zmemcpy()  */
  1302. X/************************/
  1303. X
  1304. Xchar *memcpy(dst, src, len)
  1305. Xregister char *dst, *src;
  1306. Xregister unsigned int len;
  1307. X{
  1308. X    char *start;
  1309. X
  1310. X    start = dst;
  1311. X    while (len-- > 0)
  1312. X        *dst++ = *src++;
  1313. X    return (start);
  1314. X}
  1315. X
  1316. X#endif                          /* ZMEM */
  1317. END_OF_FILE
  1318.   if test 17338 -ne `wc -c <'./v41/misc.c'`; then
  1319.     echo shar: \"'./v41/misc.c'\" unpacked with wrong size!
  1320.   fi
  1321.   # end of './v41/misc.c'
  1322. fi
  1323. if test -f './v41/unimplod.c' -a "${1}" != "-c" ; then 
  1324.   echo shar: Will not clobber existing file \"'./v41/unimplod.c'\"
  1325. else
  1326.   echo shar: Extracting \"'./v41/unimplod.c'\" \(9186 characters\)
  1327.   sed "s/^X//" >'./v41/unimplod.c' <<'END_OF_FILE'
  1328. X/*---------------------------------------------------------------------------
  1329. X
  1330. X  unimplod.c
  1331. X
  1332. X  The Imploding algorithm is actually a combination of two distinct algor-
  1333. X  ithms.  The first algorithm compresses repeated byte sequences using a
  1334. X  sliding dictionary.  The second algorithm is used to compress the encoding
  1335. X  of the sliding dictionary ouput, using multiple Shannon-Fano trees.
  1336. X
  1337. X  ---------------------------------------------------------------------------*/
  1338. X
  1339. X
  1340. X#include "unzip.h"
  1341. X
  1342. X
  1343. X/***********************/
  1344. X/*  UnImplode Defines */
  1345. X/***********************/
  1346. X
  1347. X#define LITVALS     256
  1348. X#define DISTVALS    64
  1349. X#define LENVALS     64
  1350. X#define MAXSF       LITVALS
  1351. X
  1352. X
  1353. X
  1354. X/************************/
  1355. X/*  UnImplode Typedefs */
  1356. X/************************/
  1357. X
  1358. Xtypedef struct sf_entry {
  1359. X    byte Value;
  1360. X    byte BitLength;
  1361. X} sf_entry;
  1362. X
  1363. Xtypedef struct sf_tree {        /* a shannon-fano "tree" (table) */
  1364. X    sf_entry entry[MAXSF];
  1365. X    int entries;
  1366. X    int MaxLength;
  1367. X} sf_tree;
  1368. X
  1369. Xtypedef struct sf_node {        /* node in a true shannon-fano tree */
  1370. X    UWORD left;                 /* 0 means leaf node */
  1371. X    UWORD right;                /*   or value if leaf node */
  1372. X} sf_node;
  1373. X
  1374. X
  1375. X
  1376. X/********************************/
  1377. X/*  UnImplode Global Variables */
  1378. X/********************************/
  1379. X
  1380. X/* s-f storage is shared with that used by other comp. methods */
  1381. X
  1382. Xsf_tree lit_tree;
  1383. Xsf_tree length_tree;
  1384. Xsf_tree distance_tree;
  1385. Xsf_node *lit_nodes = (sf_node *) prefix_of;     /* 2*LITVALS nodes */
  1386. X#ifdef MACOS
  1387. Xsf_node *length_nodes ;  /* 2*LENVALS nodes */
  1388. Xsf_node *distance_nodes ;    /* 2*DISTVALS nodes */
  1389. X#else
  1390. Xsf_node *length_nodes = (sf_node *) suffix_of;  /* 2*LENVALS nodes */
  1391. Xsf_node *distance_nodes = (sf_node *) stack;    /* 2*DISTVALS nodes */
  1392. X#endif
  1393. Xboolean lit_tree_present;
  1394. Xboolean eightK_dictionary;
  1395. Xint minimum_match_length;
  1396. Xint dict_bits;
  1397. X
  1398. X
  1399. X
  1400. X/*****************************************/
  1401. X/*  UnImplode Local Function Prototypes */
  1402. X/*****************************************/
  1403. X
  1404. Xstatic void LoadTrees __((void));
  1405. Xstatic void LoadTree __((sf_tree * tree, int treesize, sf_node * nodes));
  1406. Xstatic void ReadLengths __((sf_tree * tree));
  1407. Xstatic void SortLengths __((sf_tree * tree));
  1408. Xstatic void GenerateTrees __((sf_tree * tree, sf_node * nodes));
  1409. Xstatic void ReadTree __((register sf_node * nodes, int *dest));
  1410. X
  1411. X
  1412. X
  1413. X
  1414. X
  1415. X/**************************/
  1416. X/*  Function unImplode() */
  1417. X/**************************/
  1418. X
  1419. Xvoid unImplode()
  1420. X /* expand imploded data */
  1421. X{
  1422. X    register int srcix;
  1423. X    register int Length;
  1424. X    register int limit;
  1425. X    int lout;
  1426. X    int Distance;
  1427. X
  1428. X    LoadTrees();
  1429. X
  1430. X#ifdef DEBUG
  1431. X    printf("\n");
  1432. X#endif
  1433. X    while ((!zipeof) && ((outpos + outcnt) < ucsize)) {
  1434. X        READBIT(1, lout);
  1435. X
  1436. X        if (lout != 0) {        /* encoded data is literal data */
  1437. X            if (lit_tree_present) {     /* use Literal Shannon-Fano tree */
  1438. X                ReadTree(lit_nodes, &lout);
  1439. X#ifdef DEBUG
  1440. X                printf("lit=%d\n", lout);
  1441. X#endif
  1442. X            } else
  1443. X                READBIT(8, lout);
  1444. X
  1445. X            OUTB(lout);
  1446. X        } else {                /* encoded data is sliding dictionary match */
  1447. X            READBIT(dict_bits, Distance);
  1448. X
  1449. X            ReadTree(distance_nodes, &lout);
  1450. X#ifdef DEBUG
  1451. X            printf("d=%5d (%2d,%3d)", (lout << dict_bits) | Distance, lout,
  1452. X                   Distance);
  1453. X#endif
  1454. X            Distance |= (lout << dict_bits);
  1455. X            /* using the Distance Shannon-Fano tree, read and decode the
  1456. X               upper 6 bits of the Distance value */
  1457. X
  1458. X            ReadTree(length_nodes, &lout);
  1459. X            Length = lout;
  1460. X#ifdef DEBUG
  1461. X            printf("\tl=%3d\n", Length);
  1462. X#endif
  1463. X            /* using the Length Shannon-Fano tree, read and decode the
  1464. X               Length value */
  1465. X
  1466. X            if (Length == 63) {
  1467. X                READBIT(8, lout);
  1468. X                Length += lout;
  1469. X            }
  1470. X            Length += minimum_match_length;
  1471. X
  1472. X            /* move backwards Distance+1 bytes in the output stream, and copy
  1473. X              Length characters from this position to the output stream.
  1474. X              (if this position is before the start of the output stream,
  1475. X              then assume that all the data before the start of the output
  1476. X              stream is filled with zeros.  Requires initializing outbuf
  1477. X              for each file.) */
  1478. X
  1479. X            srcix = (outcnt - (Distance + 1)) & (OUTBUFSIZ - 1);
  1480. X            limit = OUTBUFSIZ - Length;
  1481. X            if ((srcix <= limit) && (outcnt < limit)) {
  1482. X                outcnt += Length;
  1483. X                while (Length--)
  1484. X                    *outptr++ = outbuf[srcix++];
  1485. X            } else {
  1486. X                while (Length--) {
  1487. X                    OUTB(outbuf[srcix++]);
  1488. X                    srcix &= OUTBUFSIZ - 1;
  1489. X                }
  1490. X            }
  1491. X        }
  1492. X    }
  1493. X}
  1494. X
  1495. X
  1496. X
  1497. X
  1498. X
  1499. X/**************************/
  1500. X/*  Function LoadTrees() */
  1501. X/**************************/
  1502. X
  1503. Xstatic void LoadTrees()
  1504. X{
  1505. X    eightK_dictionary = (lrec.general_purpose_bit_flag & 0x02) != 0;    /* bit 1 */
  1506. X    lit_tree_present = (lrec.general_purpose_bit_flag & 0x04) != 0;     /* bit 2 */
  1507. X
  1508. X    if (eightK_dictionary)
  1509. X        dict_bits = 7;
  1510. X    else
  1511. X        dict_bits = 6;
  1512. X
  1513. X    if (lit_tree_present) {
  1514. X        minimum_match_length = 3;
  1515. X        LoadTree(&lit_tree, 256, lit_nodes);
  1516. X    } else
  1517. X        minimum_match_length = 2;
  1518. X
  1519. X    LoadTree(&length_tree, 64, length_nodes);
  1520. X    LoadTree(&distance_tree, 64, distance_nodes);
  1521. X}
  1522. X
  1523. X
  1524. X
  1525. X
  1526. X
  1527. X/*************************/
  1528. X/*  Function LoadTree() */
  1529. X/*************************/
  1530. X
  1531. Xstatic void LoadTree(tree, treesize, nodes)
  1532. Xsf_tree *tree;
  1533. Xint treesize;
  1534. Xsf_node *nodes;
  1535. X /* allocate and load a shannon-fano tree from the compressed file */
  1536. X{
  1537. X    tree->entries = treesize;
  1538. X    ReadLengths(tree);
  1539. X    SortLengths(tree);
  1540. X    GenerateTrees(tree, nodes);
  1541. X}
  1542. X
  1543. X
  1544. X
  1545. X
  1546. X
  1547. X/****************************/
  1548. X/*  Function ReadLengths() */
  1549. X/****************************/
  1550. X
  1551. Xstatic void ReadLengths(tree)
  1552. Xsf_tree *tree;
  1553. X{
  1554. X    int treeBytes;
  1555. X    int i;
  1556. X    int num, len;
  1557. X
  1558. X    /* get number of bytes in compressed tree */
  1559. X    READBIT(8, treeBytes);
  1560. X    treeBytes++;
  1561. X    i = 0;
  1562. X
  1563. X    tree->MaxLength = 0;
  1564. X
  1565. X/* High 4 bits: Number of values at this bit length + 1. (1 - 16)
  1566. X * Low  4 bits: Bit Length needed to represent value + 1. (1 - 16)
  1567. X */
  1568. X    while (treeBytes > 0) {
  1569. X        READBIT(4, len);
  1570. X        len++;
  1571. X        READBIT(4, num);
  1572. X        num++;
  1573. X
  1574. X        while (num > 0) {
  1575. X            if (len > tree->MaxLength)
  1576. X                tree->MaxLength = len;
  1577. X            tree->entry[i].BitLength = len;
  1578. X            tree->entry[i].Value = i;
  1579. X            i++;
  1580. X            num--;
  1581. X        }
  1582. X
  1583. X        treeBytes--;
  1584. X    }
  1585. X}
  1586. X
  1587. X
  1588. X
  1589. X
  1590. X
  1591. X/****************************/
  1592. X/*  Function SortLengths() */
  1593. X/****************************/
  1594. X
  1595. Xstatic void SortLengths(tree)
  1596. Xsf_tree *tree;
  1597. X /* Sort the Bit Lengths in ascending order, while retaining the order
  1598. X   of the original lengths stored in the file */
  1599. X{
  1600. X    register sf_entry *ejm1;    /* entry[j - 1] */
  1601. X    register int j;
  1602. X    register sf_entry *entry;
  1603. X    register int i;
  1604. X    sf_entry tmp;
  1605. X    int entries;
  1606. X    unsigned a, b;
  1607. X
  1608. X    entry = &tree->entry[0];
  1609. X    entries = tree->entries;
  1610. X
  1611. X    for (i = 0; ++i < entries;) {
  1612. X        tmp = entry[i];
  1613. X        b = tmp.BitLength;
  1614. X        j = i;
  1615. X        while ((j > 0)
  1616. X               && ((a = (ejm1 = &entry[j - 1])->BitLength) >= b)) {
  1617. X            if ((a == b) && (ejm1->Value <= tmp.Value))
  1618. X                break;
  1619. X            *(ejm1 + 1) = *ejm1;/* entry[j] = entry[j - 1] */
  1620. X            --j;
  1621. X        }
  1622. X        entry[j] = tmp;
  1623. X    }
  1624. X}
  1625. X
  1626. X
  1627. X
  1628. X
  1629. X
  1630. X/******************************/
  1631. X/*  Function GenerateTrees() */
  1632. X/******************************/
  1633. X
  1634. Xstatic void GenerateTrees(tree, nodes)
  1635. Xsf_tree *tree;
  1636. Xsf_node *nodes;
  1637. X /* Generate the Shannon-Fano trees */
  1638. X{
  1639. X    int codelen, i, j, lvlstart, next, parents;
  1640. X
  1641. X    i = tree->entries - 1;      /* either 255 or 63 */
  1642. X    lvlstart = next = 1;
  1643. X
  1644. X    /* believe it or not, there may be a 1-bit code */
  1645. X
  1646. X    for (codelen = tree->MaxLength; codelen >= 1; --codelen) {
  1647. X
  1648. X        /* create leaf nodes at level <codelen> */
  1649. X
  1650. X        while ((i >= 0) && (tree->entry[i].BitLength == codelen)) {
  1651. X            nodes[next].left = 0;
  1652. X            nodes[next].right = tree->entry[i].Value;
  1653. X            ++next;
  1654. X            --i;
  1655. X        }
  1656. X
  1657. X        /* create parent nodes for all nodes at level <codelen>,
  1658. X           but don't create the root node here */
  1659. X
  1660. X        parents = next;
  1661. X        if (codelen > 1) {
  1662. X            for (j = lvlstart; j <= parents - 2; j += 2) {
  1663. X                nodes[next].left = j;
  1664. X                nodes[next].right = j + 1;
  1665. X                ++next;
  1666. X            }
  1667. X        }
  1668. X        lvlstart = parents;
  1669. X    }
  1670. X
  1671. X    /* create root node */
  1672. X
  1673. X    nodes[0].left = next - 2;
  1674. X    nodes[0].right = next - 1;
  1675. X}
  1676. X
  1677. X
  1678. X
  1679. X
  1680. X
  1681. X/************************/
  1682. X/*  Function ReadTree() */
  1683. X/************************/
  1684. X
  1685. X#ifndef ASM
  1686. X
  1687. Xstatic void ReadTree(nodes, dest)
  1688. Xregister sf_node *nodes;
  1689. Xint *dest;
  1690. X /* read next byte using a shannon-fano tree */
  1691. X{
  1692. X    register int cur;
  1693. X    register int left;
  1694. X    UWORD b;
  1695. X
  1696. X    for (cur = 0;;) {
  1697. X        if ((left = nodes[cur].left) == 0) {
  1698. X            *dest = nodes[cur].right;
  1699. X            return;
  1700. X        }
  1701. X        READBIT(1, b);
  1702. X        cur = (b ? nodes[cur].right : left);
  1703. X    }
  1704. X}
  1705. X
  1706. X#endif                          /* !ASM */
  1707. END_OF_FILE
  1708.   if test 9186 -ne `wc -c <'./v41/unimplod.c'`; then
  1709.     echo shar: \"'./v41/unimplod.c'\" unpacked with wrong size!
  1710.   fi
  1711.   # end of './v41/unimplod.c'
  1712. fi
  1713. echo shar: End of archive 3 \(of 6\).
  1714. cp /dev/null ark3isdone
  1715. MISSING=""
  1716. for I in 1 2 3 4 5 6 ; do
  1717.     if test ! -f ark${I}isdone ; then
  1718.     MISSING="${MISSING} ${I}"
  1719.     fi
  1720. done
  1721. if test "${MISSING}" = "" ; then
  1722.     echo You have unpacked all 6 archives.
  1723.     rm -f ark[1-9]isdone
  1724. else
  1725.     echo You still must unpack the following archives:
  1726.     echo "        " ${MISSING}
  1727. fi
  1728. exit 0
  1729. exit 0 # Just in case...
  1730. -- 
  1731. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1732. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1733. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1734. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1735.