home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / aufstols.zoo / aufstools.4 < prev   
Text File  |  1991-02-26  |  34KB  |  1,186 lines

  1. #! /bin/sh
  2. # This is a shell archive.  Remove anything before this line, then unpack
  3. # it by saving it into a file and typing "sh file".  To overwrite existing
  4. # files, type "sh file -c".  You can also feed this as standard input via
  5. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  6. # will see the following message at the end:
  7. #        "End of archive 4 (of 4)."
  8. # Contents:  unstuffit/unsit.c
  9. # Wrapped by np@asun5 on Mon Dec  3 13:15:59 1990
  10. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  11. if test -f 'unstuffit/unsit.c' -a "${1}" != "-c" ; then 
  12.   echo shar: Will not clobber existing file \"'unstuffit/unsit.c'\"
  13. else
  14. echo shar: Extracting \"'unstuffit/unsit.c'\" \(31819 characters\)
  15. sed "s/^X//" >'unstuffit/unsit.c' <<'END_OF_FILE'
  16. X/* Modified Aug & Dec 90, Nigel Perry, Dept of Computing, Imperial College,
  17. X   London SW7 2BZ, np@doc.ic.ac.uk
  18. X
  19. X   If called by AUFSNAME (default unstuffit) will input/output to
  20. X   CAPS aufs disc.
  21. X
  22. X   Will now untiff multiple files.
  23. X
  24. X */
  25. X/*
  26. X           unsit - Macintosh StuffIt file extractor
  27. X
  28. X             Version 1.5f, for StuffIt 1.5
  29. X
  30. X                July 23, 1990
  31. X
  32. XThis program will unpack a Macintosh StuffIt file into separate files.
  33. XThe data fork of a StuffIt file contains both the data and resource
  34. Xforks of the packed files.  The program will unpack each Mac file into
  35. Xeither separate .data, .rsrc., and .info files that can be downloaded
  36. Xto a Mac using macput and MacTerminal over a tty line, or into a
  37. Xsingle MacBinary format file.  The MacBinary format is generally more
  38. Xconvenient for those with network connections and FTP capability.  The
  39. Xprogram is much like the "unpit" program for breaking apart Packit
  40. Xarchive files.
  41. X
  42. X            ***** IMPORTANT *****
  43. XTo extract StuffIt files that have been compressed with the Lempel-Ziv
  44. Xcompression method, unsit pipes the data through the "compress"
  45. Xprogram with the appropriate switches, rather than incorporate the
  46. Xuncompression routines within "unsit".  Therefore, it is necessary to
  47. Xhave the "compress" program on the system and in the search path to
  48. Xmake "unsit" work.  "Compress" is available from the comp.sources.unix
  49. Xarchives.
  50. X
  51. XThe program syntax is much like unpit and macput/macget, with some added
  52. Xoptions:
  53. X
  54. X    unsit [-rdulM] [-vqfm] stuffit-file.data
  55. X
  56. XOnly one of the flags r, d, u, l, or M should be specified.  The
  57. Xdefault mode is to create the three macput/MacTerminal compatible
  58. Xfile.  The -M flag will cause the output to be in MacBinary format (a
  59. Xsingle file).  This can be swapped (default = MacBinary, -M = macput)
  60. Xby changing the definitions of DEFAULT_MODE and OTHER_MODE below.  The
  61. X-r and -d flags will cause only the resource and data forks to be
  62. Xwritten.  The -u flag will cause only the data fork to be written and
  63. Xto have carriage return characters changed to Unix newline characters.
  64. XThe -l flag will make the program only list the files in the StuffIt
  65. Xfile.
  66. X
  67. XThe -v flag causes the program to list the names, sizes, type, and
  68. Xcreators of the files it is writing.  The -q flag causes it to list
  69. Xthe name, type and size of each file and wait for a 'y' or 'n' for
  70. Xeither writing that file or skipping it, respectively.  The -m flag is
  71. Xused when the input file in in the MacBinary format instead of just
  72. Xthe data fork.  It causes the program to skip the 128 byte MacBinary
  73. Xheader before looking for the StuffIt header.  It is not necessary to
  74. Xspecify the -m flag since the program now checks for MacBinary format
  75. Xinput files and handles them correctly
  76. X
  77. XVersion 1.5 of the unsit supports extracting files and folders as
  78. Ximplemented by StuffIt 1.5's "Hierarchy Maintained Folder" feature.
  79. XEach folder is extracted as a subdirectory on the Unix system with the
  80. Xfiles in the folder placed in the corresponding subdirectory.  The -f
  81. Xoption can be used to "flatten" out the hierarchy and unsit will store
  82. Xall the files in the current directory.  If the query option (-q) is
  83. Xused and a "n" response is given to a folder name, none of the files
  84. Xor folders in that folder will be extraced.
  85. X
  86. XSome of the program is borrowed from the macput.c/macget.c programs.
  87. XMany, many thanks to Raymond Lau, the author of StuffIt, for including
  88. Xinformation on the format of the StuffIt archives in the
  89. Xdocumentation.  Several changes and enhancements supplied by David
  90. XShanks (cde@atelabs.UUCP) have been incorporated into the program for
  91. Xdoing things like supporting System V and recognizing MacBinary files.
  92. XChristopher Bingham <kb@umnstat.stat.umn.edu> supplied some Macbinary
  93. Xpatches.  Code was also borrowed from the macbin program by Jim Budler
  94. Xfor convert macput format files to MacBinary.  I'm always glad to
  95. Xreceive advice, suggestions, or comments about the program so feel free
  96. Xto send whatever you think would be helpful
  97. X
  98. X
  99. X    Author: Allan G. Weber
  100. X        weber@sipi.usc.edu
  101. X        ...!usc!sipi!weber
  102. X    Date:   July 23, 1990
  103. X
  104. X*/
  105. X
  106. X#include <stdio.h>
  107. X#include <sys/types.h>
  108. X#include <sys/stat.h>
  109. X
  110. Xtypedef long OSType;
  111. X
  112. X#include "stuffit.h"
  113. X
  114. X/*
  115. X * Define the following if your Unix can only handle 14 character file names
  116. X * (e.g. Version 7 and System V).
  117. X */
  118. X/* #define SHORTNAMES */
  119. X
  120. X/*
  121. X * The following defines the name of the compress program that is used for the
  122. X * uncompression of Lempel-Ziv compressed files.  If the path is set up to
  123. X * include the right directory, this should work.
  124. X */
  125. X#define COMPRESS   "compress"
  126. X
  127. X#define IOBUFSIZ   4096
  128. X
  129. X#define MACBINHDRSIZE  128L
  130. X
  131. X#define INIT_CRC 0L
  132. Xextern unsigned short updcrc();
  133. X
  134. X#define INFOBYTES 128
  135. X
  136. X#define BYTEMASK 0xff
  137. X
  138. X#define S_SIGNATURE    0
  139. X#define S_NUMFILES     4
  140. X#define S_ARCLENGTH    6
  141. X#define S_SIGNATURE2  10
  142. X#define    S_VERSION     14
  143. X#define SITHDRSIZE    22
  144. X
  145. X#define F_COMPRMETHOD    0
  146. X#define F_COMPDMETHOD    1
  147. X#define F_FNAME          2
  148. X#define F_FTYPE         66
  149. X#define F_CREATOR       70
  150. X#define F_FNDRFLAGS     74
  151. X#define F_CREATIONDATE  76
  152. X#define F_MODDATE       80
  153. X#define F_RSRCLENGTH    84
  154. X#define F_DATALENGTH    88
  155. X#define F_COMPRLENGTH   92
  156. X#define F_COMPDLENGTH   96
  157. X#define F_RSRCCRC      100
  158. X#define F_DATACRC      102
  159. X#define F_HDRCRC       110
  160. X#define FILEHDRSIZE    112
  161. X
  162. X#define F_NAMELEN 63
  163. X#ifdef SHORTNAMES        /* short file names */
  164. X# define I_NAMELEN 15        /* 14 char file names + '\0' terminator */
  165. X#else
  166. X# define I_NAMELEN 69        /* 63 + strlen(".info") + 1 */
  167. X#endif
  168. X
  169. X/* The following are copied out of macput.c/macget.c */
  170. X#define I_NAMEOFF 1
  171. X/* 65 <-> 80 is the FInfo structure */
  172. X#define I_TYPEOFF 65
  173. X#define I_AUTHOFF 69
  174. X#define I_FLAGOFF 73
  175. X#define I_LOCKOFF 81
  176. X#define I_DLENOFF 83
  177. X#define I_RLENOFF 87
  178. X#define I_CTIMOFF 91
  179. X#define I_MTIMOFF 95
  180. X
  181. X#define INITED_BUG
  182. X#define INITED_OFF    I_FLAGOFF    /* offset to byte with Inited flag */
  183. X#define INITED_MASK    (~1)        /* mask to '&' with byte to reset it */
  184. X
  185. X#define TEXT 0
  186. X#define DATA 1
  187. X#define RSRC 2
  188. X#define MACPUT 3
  189. X#define DUMP 4
  190. X#define MACBINARY 5
  191. X
  192. X/* Swap the following definitions if you want the output to default to
  193. X   MacBinary, and the -M switch to create macput file (.data, .rsrc, .info) */
  194. X#define DEFAULT_MODE MACPUT
  195. X#define OTHER_MODE   MACBINARY
  196. X
  197. X/* #define ADDBIN */    /* add .bin to macbinary file names */
  198. X
  199. X#define NODECODE 0
  200. X#define DECODE   1
  201. X
  202. X#define H_ERROR -1
  203. X#define H_EOF    0
  204. X#define H_WRITE  1
  205. X#define H_SKIP   2
  206. X
  207. X/* if called by this name program works on aufs files */
  208. X#define AUFSNAME "unstuffit"
  209. X
  210. Xstruct node {
  211. X    int flag, byte;
  212. X    struct node *one, *zero;
  213. X} nodelist[512], *nodeptr, *read_tree();    /* 512 should be big enough */
  214. X
  215. Xstruct sitHdr sithdr;
  216. X
  217. Xchar f_info[I_NAMELEN];
  218. Xchar f_data[I_NAMELEN];
  219. Xchar f_rsrc[I_NAMELEN];
  220. X
  221. Xchar info[INFOBYTES];
  222. Xchar mname[F_NAMELEN+1];
  223. Xchar uname[F_NAMELEN+1];
  224. Xchar dname[F_NAMELEN+1];    /* directory name for aufs */
  225. Xchar iobuf[IOBUFSIZ];
  226. Xchar zbuf[128];            /* buffer of zeros to pad MacBinary forks */
  227. X
  228. Xint mode, txtmode, listonly, verbose, query, flatten;
  229. Xint bit, chkcrc, numfiles, depth;
  230. Xint aufs;            /* aufs flag */
  231. Xint debug = 0;
  232. XFILE *infp;
  233. X
  234. Xlong get4();
  235. Xshort get2();
  236. Xunsigned short write_file();
  237. X
  238. X/********************************************************************************/
  239. X/* added for aufs, nicked from various places... */
  240. X
  241. X/* following from mcvert program */
  242. X
  243. X/* Useful, though not particularly Mac related, values */
  244. Xtypedef unsigned char byte;     /* one byte, obviously */
  245. Xtypedef unsigned short word;    /* must be 2 bytes */
  246. Xtypedef unsigned long ulong;    /* 4 bytes */
  247. X
  248. X#define NAMELEN 63              /* maximum legal Mac file name length */
  249. X
  250. X/* Format of a bin file:
  251. XA bin file is composed of 128 byte blocks.  The first block is the
  252. Xinfo_header (see below).  Then comes the data fork, null padded to fill the
  253. Xlast block.  Then comes the resource fork, padded to fill the last block.  A
  254. Xproposal to follow with the text of the Get Info box has not been implemented,
  255. Xto the best of my knowledge.  Version, zero1 and zero2 are what the receiving
  256. Xprogram looks at to determine if a MacBinary transfer is being initiated.
  257. X*/ 
  258. Xtypedef struct {     /* info file header (128 bytes). Unfortunately, these
  259. X                        longs don't align to word boundaries */
  260. X            byte version;           /* there is only a version 0 at this time */
  261. X            byte nlen;              /* Length of filename. */
  262. X            byte name[NAMELEN];     /* Filename (only 1st nlen are significant)*/
  263. X            byte type[4];           /* File type. */
  264. X            byte auth[4];           /* File creator. */
  265. X            byte flags;             /* file flags: LkIvBnSyBzByChIt */
  266. X            byte zero1;             /* Locked, Invisible,Bundle, System */
  267. X                                    /* Bozo, Busy, Changed, Init */
  268. X            byte icon_vert[2];      /* Vertical icon position within window */
  269. X            byte icon_horiz[2];     /* Horizontal icon postion in window */
  270. X            byte window_id[2];      /* Window or folder ID. */
  271. X            byte protect;           /* = 1 for protected file, 0 otherwise */
  272. X            byte zero2;
  273. X            byte dflen[4];          /* Data Fork length (bytes) -   most sig.  */
  274. X            byte rflen[4];          /* Resource Fork length         byte first */
  275. X            byte cdate[4];          /* File's creation date. */
  276. X            byte mdate[4];          /* File's "last modified" date. */
  277. X            byte ilen[2];           /* GetInfo message length */
  278. X        byte flags2;            /* Finder flags, bits 0-7 */
  279. X        byte unused[14];       
  280. X        byte packlen[4];        /* length of total files when unpacked */
  281. X        byte headlen[2];        /* length of secondary header */
  282. X        byte uploadvers;        /* Version of MacBinary II that the uploading program is written for */
  283. X        byte readvers;          /* Minimum MacBinary II version needed to read this file */
  284. X            byte crc[2];            /* CRC of the previous 124 bytes */
  285. X        byte padding[2];        /* two trailing unused bytes */
  286. X            } info_header;
  287. X
  288. X/* end of mcvert stuff */
  289. X/* from CAP aufs documentation */
  290. X
  291. X#define FINFOLEN 32
  292. X#define MAXCLEN 199
  293. Xtypedef struct
  294. X{  /* byte fi_fndr[FINFOLEN]; */    /* finder info */
  295. X   /* what I think the above is... */
  296. X   ulong fndr_type, fndr_creator;
  297. X   word fndr_flags;
  298. X   ulong fndr_loc;
  299. X   word fndr_fldr;
  300. X   word fndr_icon;
  301. X   byte fndr_unused[8];
  302. X   word fndr_comment;
  303. X   ulong fndr_putaway;
  304. X   /* end of fi_fndr */
  305. X
  306. X   word fi_attr;            /* attributes */
  307. X#define FI_MAGIC1 255
  308. X   byte fi_magic1;        /* was: length of comment */
  309. X#define FI_VERSION 0x10        /* version major 1, minor 0 */
  310. X                /* if more than 8 versions then */
  311. X                /* something wrong anyway */
  312. X   byte fi_version;        /* version number */
  313. X#define FI_MAGIC 0xda
  314. X   byte fi_magic;        /* magic word check */
  315. X   byte fi_bitmap;        /* bitmap of included info */
  316. X#define FI_BM_SHORTFILENAME 0x1    /* is this included? */
  317. X#define FI_BM_MACINTOSHFILENAME 0x2 /* is this included? */
  318. X   byte fi_shortfilename[12+1];    /* possible short file name */
  319. X   byte fi_macfilename[32+1];    /* possible macintosh file name */
  320. X   byte fi_comln;        /* comment length */
  321. X   byte fi_comnt[MAXCLEN+1];    /* comment string */
  322. X} FileInfo;
  323. X
  324. XFileInfo fndr_info;
  325. X
  326. X/* end aufs */
  327. X/********************************************************************************/
  328. X
  329. Xmain(argc, argv)
  330. Xint argc;
  331. Xchar *argv[];
  332. X{
  333. X    int status;
  334. X    int c;
  335. X    extern int optind;
  336. X    extern char *optarg;
  337. X    int errflg;
  338. X    int macbin;
  339. X
  340. X    mode = DEFAULT_MODE;
  341. X    errflg = 0;
  342. X    macbin = 0;
  343. X    flatten = 0;
  344. X    numfiles = 0;
  345. X    depth = 0;
  346. X    aufs = strcmp(argv[0], AUFSNAME) == 0;
  347. X
  348. X    while ((c = getopt(argc, argv, "DMdflmqruvx")) != EOF)
  349. X    switch (c) {
  350. X      case 'r':        /* extract resource fork only */
  351. X        mode = RSRC;
  352. X        break;
  353. X      case 'd':        /* extract data fork only */
  354. X        mode = DATA;
  355. X        break;
  356. X      case 'u':        /* extract data fork as Unix text file */
  357. X        mode = TEXT;
  358. X        break;
  359. X      case 'l':        /* list contents of archive */
  360. X        listonly++;
  361. X        break;
  362. X      case 'q':        /* query user on each extraction */
  363. X        query++;
  364. X        break;
  365. X      case 'v':        /* verbose mode */
  366. X        verbose++;
  367. X        break;
  368. X      case 'x':        /* don't decode data, just dump to files*/
  369. X        mode = DUMP;
  370. X        break;
  371. X      case 'm':        /* input file is in Macbinary format */
  372. X        macbin = 1;
  373. X        break;
  374. X      case 'M':        /* output file in OTHER_MODE */
  375. X        mode = OTHER_MODE;
  376. X        break;
  377. X      case 'f':        /* don't create flat directory tree */
  378. X        flatten = 1;
  379. X        break;
  380. X      case 'D':        /* debugging mode */
  381. X        debug = 1;
  382. X        break;
  383. X      case '?':
  384. X        errflg++;
  385. X        break;
  386. X    }
  387. X    if (errflg) {
  388. X    usage();
  389. X    exit(1);
  390. X    }
  391. X
  392. X    /* -a incompatible with -M and -u */
  393. X    if(aufs && (mode == MACBINARY || mode == TEXT))
  394. X    {   fprintf(stderr, "Aufs mode cannot be combined with MacBinary (-M) or text (-t) mode\n");
  395. X    exit(1);
  396. X    }
  397. X
  398. X    if (optind == argc) {
  399. X    usage();
  400. X    exit(1);
  401. X    }
  402. X    else
  403. X    while(optind < argc)
  404. X        {   if ((infp = fopen(argv[optind], "r")) == NULL)
  405. X        {   fprintf(stderr,"Can't open input file \"%s\"\n",argv[optind]);
  406. X            exit(1);
  407. X        }
  408. X
  409. X        if (macbin) {
  410. X        if (fseek(infp, MACBINHDRSIZE, 0) == -1) {
  411. X            fprintf(stderr, "Can't skip over MacBinary header\n");
  412. X            exit(1);
  413. X        }
  414. X        }
  415. X
  416. X        if (readsithdr(&sithdr) == 0) {
  417. X        fprintf(stderr, "Can't read file header\n");
  418. X        exit(1);
  419. X        }
  420. X        if (debug) {
  421. X        printf("archive header (%d bytes):\n", SITHDRSIZE);
  422. X        printf("numFiles=%d, arcLength=%ld, version=%d\n",
  423. X               sithdr.numFiles, sithdr.arcLength, sithdr.version & 0xff);
  424. X        }
  425. X        status = extract("", 0);
  426. X        if(status < 0) exit(1);
  427. X
  428. X        optind++;
  429. X    }
  430. X
  431. X    exit(0);
  432. X}
  433. X
  434. Xusage()
  435. X{
  436. X    fprintf(stderr, "Usage: unsit/unstuffit [-rdulM] [-vqfm] filename\n");
  437. X}
  438. X
  439. X/*
  440. X  extract(parent, skip) - Extract all files from the current folder.
  441. X  char *parent;           name of parent folder
  442. X  int  skip;              1 to skip all files and folders in this one
  443. X                          0 to extract them
  444. X
  445. X  returns 1 if came an endFolder record
  446. X          0 if EOF
  447. X     -1 if error (bad fileHdr, bad file, etc.)
  448. X*/
  449. X
  450. Xextract(parent, skip)
  451. Xchar *parent;
  452. Xint skip;
  453. X{
  454. X    struct fileHdr filehdr;
  455. X    struct stat sbuf;
  456. X    int status, rstat, sstat, skipit;
  457. X    char name[256];
  458. X
  459. X    while (1) {
  460. X    rstat = readfilehdr(&filehdr, skip);
  461. X    if (rstat == H_ERROR || rstat == H_EOF) {
  462. X        status = rstat;
  463. X        break;
  464. X    }
  465. X    if (debug) {
  466. X        printf("file header (%d bytes):\n", FILEHDRSIZE);
  467. X        printf("compRMethod=%d, compDMethod=%d\n",
  468. X           filehdr.compRMethod, filehdr.compDMethod);
  469. X        printf("rsrcLength=%ld, dataLength=%ld\n",
  470. X           filehdr.rsrcLength, filehdr.dataLength);
  471. X        printf("compRLength=%ld, compDLength=%ld\n",
  472. X           filehdr.compRLength, filehdr.compDLength);
  473. X        printf("rsrcCRC=%d=0x%04x, dataCRC=%d=0x%04x\n",
  474. X           filehdr.rsrcCRC, filehdr.rsrcCRC,
  475. X           filehdr.dataCRC, filehdr.dataCRC);
  476. X    }
  477. X
  478. X    skipit = (rstat == H_SKIP) ? 1 : 0;
  479. X
  480. X    if (filehdr.compRMethod == endFolder && 
  481. X        filehdr.compDMethod == endFolder) {
  482. X        status = 1;        /* finished with this folder */
  483. X        break;
  484. X    }
  485. X    else if (filehdr.compRMethod == startFolder && 
  486. X         filehdr.compDMethod == startFolder) {
  487. X        if (!listonly && rstat == H_WRITE && !flatten) {
  488. X        sstat = stat(uname, &sbuf);
  489. X        if (sstat == -1) {    /* directory doesn't exist */
  490. X            if (mkdir(uname, 0777) == -1) {
  491. X            fprintf(stderr,
  492. X                "Can't create subdirectory %s\n", uname);
  493. X            return(-1);
  494. X            }
  495. X        }
  496. X        else {        /* something exists with this name */
  497. X            if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  498. X            fprintf(stderr, "Directory name %s already in use\n",
  499. X                uname);
  500. X            return(-1);
  501. X            }
  502. X        }
  503. X        if(aufs) /* create .finderinfo & .resource subdirectories */
  504. X        {   strcpy(dname, uname);
  505. X            strcat(dname, "/.finderinfo");
  506. X            sstat = stat(dname, &sbuf);
  507. X            if (sstat == -1) {    /* directory doesn't exist */
  508. X            if (mkdir(dname, 0777) == -1) {
  509. X                fprintf(stderr,
  510. X                    "Can't create subdirectory %s\n", dname);
  511. X                return(-1);
  512. X            }
  513. X            }
  514. X            else {        /* something exists with this name */
  515. X            if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  516. X                fprintf(stderr, "Directory name %s already in use\n",
  517. X                    dname);
  518. X                return(-1);
  519. X            }
  520. X            }
  521. X            strcpy(dname, uname);
  522. X            strcat(dname, "/.resource");
  523. X            sstat = stat(dname, &sbuf);
  524. X            if (sstat == -1) {    /* directory doesn't exist */
  525. X            if (mkdir(dname, 0777) == -1) {
  526. X                fprintf(stderr,
  527. X                    "Can't create subdirectory %s\n", dname);
  528. X                return(-1);
  529. X            }
  530. X            }
  531. X            else {        /* something exists with this name */
  532. X            if ((sbuf.st_mode & S_IFMT) != S_IFDIR) {
  533. X                fprintf(stderr, "Directory name %s already in use\n",
  534. X                    dname);
  535. X                return(-1);
  536. X            }
  537. X            }
  538. X        }
  539. X        if (chdir(uname) == -1) {
  540. X            fprintf(stderr, "Can't chdir to %s\n", uname);
  541. X            return(-1);
  542. X        }
  543. X        sprintf(name,"%s:%s", parent, uname);
  544. X        }
  545. X        depth++;
  546. X        status = extract(name, skipit);
  547. X        depth--;
  548. X        if (status != 1)
  549. X        break;        /* problem with folder */
  550. X        if (depth == 0)    /* count how many top-level files done */
  551. X        numfiles++;
  552. X        if (!flatten)
  553. X        chdir("..");
  554. X    }
  555. X    else {
  556. X        if ((status = extractfile(&filehdr, skipit)) != 1)
  557. X        break;
  558. X        if (depth == 0)    /* count how many top-level files done */
  559. X        numfiles++;
  560. X    }
  561. X    if (numfiles == sithdr.numFiles)
  562. X        break;
  563. X    }
  564. X    return(status);
  565. X}
  566. X
  567. Xextractfile(fh, skip)
  568. Xstruct fileHdr *fh;
  569. Xint skip;
  570. X{
  571. X    unsigned short crc;
  572. X    FILE *fp, *fp1;
  573. X    int n;
  574. X
  575. X    f_data[0] = f_rsrc[0] = f_info[0] = '\0'; /* assume no output files */
  576. X    /* figure out what file names to use and what to do */
  577. X    if (!listonly && !skip) {
  578. X    switch (mode) {
  579. X      case MACPUT:        /* do both rsrc and data forks */
  580. X        if(aufs)
  581. X        {   sprintf(f_data, "%.*s", I_NAMELEN - 1, uname);
  582. X        sprintf(f_rsrc, ".resource/%.*s", I_NAMELEN - 1, uname);
  583. X        sprintf(f_info, ".finderinfo/%.*s", I_NAMELEN - 1, uname);
  584. X        }
  585. X        else
  586. X        {   sprintf(f_data, "%.*s.data", I_NAMELEN - 6, uname);
  587. X        sprintf(f_rsrc, "%.*s.rsrc", I_NAMELEN - 6, uname);
  588. X        sprintf(f_info, "%.*s.info", I_NAMELEN - 6, uname);
  589. X        }
  590. X        break;
  591. X      case RSRC:        /* rsrc fork only */
  592. X        if(aufs)
  593. X        {   sprintf(f_rsrc, ".resource/%.*s", I_NAMELEN - 1, uname);
  594. X        sprintf(f_info, ".finderinfo/%.*s", I_NAMELEN - 1, uname);
  595. X        }
  596. X        else
  597. X        sprintf(f_rsrc, "%.*s.rsrc", I_NAMELEN - 6, uname);
  598. X        break;
  599. X      case DATA:        /* data fork only */
  600. X        if(aufs)
  601. X        {   sprintf(f_data, "%.*s", I_NAMELEN - 1, uname);
  602. X        sprintf(f_info, ".finderinfo/%.*s", I_NAMELEN - 1, uname);
  603. X        }
  604. X        else
  605. X            sprintf(f_data, "%.*s.data", I_NAMELEN - 6, uname);
  606. X        break;
  607. X      case TEXT:
  608. X        sprintf(f_data, "%.*s.text", I_NAMELEN - 6, uname);
  609. X        break;
  610. X      case DUMP:        /* for debugging, dump data as is */
  611. X        sprintf(f_data, "%.*s.ddump", I_NAMELEN - 7, uname);
  612. X        sprintf(f_rsrc, "%.*s.rdump", I_NAMELEN - 7, uname);
  613. X        fh->compRMethod = fh->compDMethod = noComp;
  614. X        break;
  615. X      case MACBINARY:    /* output file in MacBinary format */
  616. X        sprintf(f_data, "%.*s.data", I_NAMELEN - 6, uname);
  617. X        sprintf(f_rsrc, "%.*s.rsrc", I_NAMELEN - 6, uname);
  618. X#ifndef ADDBIN
  619. X        sprintf(f_info, "%.*s", I_NAMELEN - 1, uname);
  620. X#else
  621. X        sprintf(f_info, "%.*s.bin", I_NAMELEN - 5, uname);
  622. X#endif /*ADDBIN*/
  623. X        break;
  624. X    }
  625. X    }
  626. X
  627. X    fp = NULL;            /* so we can tell if a file is open */
  628. X    if (f_info[0] != '\0' && check_access(f_info) != -1) {
  629. X    fp = fopen(f_info, "w");
  630. X    if (fp == NULL) {
  631. X        perror(f_info);
  632. X        exit(1);
  633. X    }
  634. X    if(aufs) /* convert info structure */
  635. X    {   register info_header *pinfo;
  636. X    
  637. X        pinfo = (info_header *)info;
  638. X
  639. X        /* make the .finderinfo file */
  640. X        bzero(&fndr_info, sizeof(FileInfo));
  641. X        bcopy(pinfo->type, &fndr_info.fndr_type, 4);
  642. X        bcopy(pinfo->auth, &fndr_info.fndr_creator, 4);
  643. X        bcopy(&pinfo->flags, &fndr_info.fndr_flags, 2);
  644. X        fndr_info.fi_magic1 = FI_MAGIC1;
  645. X        fndr_info.fi_version = FI_VERSION;
  646. X        fndr_info.fi_magic = FI_MAGIC;
  647. X        fndr_info.fi_bitmap = FI_BM_MACINTOSHFILENAME;
  648. X        bcopy(pinfo->name, fndr_info.fi_macfilename, pinfo->nlen);
  649. X
  650. X        fwrite(&fndr_info, sizeof(FileInfo), 1, fp);
  651. X    }
  652. X    else
  653. X    {   if (mode == MACBINARY) { /* convert to MacBinary header */
  654. X        /* taken from the macbin program */
  655. X        if (info[74] & 0x40) info[81] = '\1'; /* protected */
  656. X        info[74] = '\0'; /* clear zero2 */
  657. X        info[82] = '\0'; /* force zero3 clear */
  658. X        }
  659. X        fwrite(info, 1, INFOBYTES, fp);
  660. X    }
  661. X    }
  662. X
  663. X    if (f_rsrc[0] != '\0') {
  664. X    txtmode = 0;
  665. X    crc = write_file(f_rsrc, fh->compRLength,
  666. X             fh->rsrcLength, fh->compRMethod);
  667. X    if (chkcrc && fh->rsrcCRC != crc) {
  668. X        fprintf(stderr,
  669. X            "CRC error on resource fork: need 0x%04x, got 0x%04x\n",
  670. X            fh->rsrcCRC, crc);
  671. X        return(-1);
  672. X    }
  673. X    }
  674. X    else {
  675. X    fseek(infp, (long) fh->compRLength, 1);
  676. X    }
  677. X    if (f_data[0] != '\0') {
  678. X    txtmode = (mode == TEXT);
  679. X    crc = write_file(f_data, fh->compDLength,
  680. X             fh->dataLength, fh->compDMethod);
  681. X    if (chkcrc && fh->dataCRC != crc) {
  682. X        fprintf(stderr,
  683. X            "CRC error on data fork: need 0x%04x, got 0x%04x\n",
  684. X            fh->dataCRC, crc);
  685. X        return(-1);
  686. X    }
  687. X    }
  688. X    else {
  689. X    fseek(infp, (long) fh->compDLength, 1);
  690. X    }
  691. X    if (fp != NULL) {
  692. X    /* if Macbinary output, copy the data and resource forks to the
  693. X       end of the info file, and pad each to multiples of 128 bytes. */
  694. X    if (mode == MACBINARY) {
  695. X        fp1 = fopen(f_data, "r"); /* re-open the file we just wrote */
  696. X        if (fp1 == NULL) {
  697. X        perror(f_data);
  698. X        exit(1);
  699. X        }
  700. X        while ((n = fread(iobuf, 1, IOBUFSIZ, fp1)) > 0)
  701. X        fwrite(iobuf, 1, n, fp); /* append it to the info file */
  702. X        /* pad out to multiple of 128 if in MacBinary format */
  703. X        n = fh->dataLength % 128;
  704. X        if (n > 0)
  705. X        outc(zbuf, 128 - n, fp);
  706. X        fclose(fp1);
  707. X        unlink(f_data);
  708. X        fp1 = fopen(f_rsrc, "r"); /* re-open the file we just wrote */
  709. X        if (fp1 == NULL) {
  710. X        perror(f_rsrc);
  711. X        exit(1);
  712. X        }
  713. X        while ((n = fread(iobuf, 1, IOBUFSIZ, fp1)) > 0)
  714. X        fwrite(iobuf, 1, n, fp); /* append it to the info file */
  715. X        /* pad out to multiple of 128 if in MacBinary format */
  716. X        n = fh->rsrcLength % 128;
  717. X        if (n > 0)
  718. X        outc(zbuf, 128 - n, fp);
  719. X        fclose(fp1);
  720. X        unlink(f_rsrc);
  721. X    }
  722. X    fclose(fp);
  723. X    }
  724. X    return(1);
  725. X}
  726. X
  727. Xreadsithdr(s)
  728. Xstruct sitHdr *s;
  729. X{
  730. X    char temp[FILEHDRSIZE];
  731. X    int count = 0;
  732. X
  733. X    for (;;) {
  734. X    if (fread(temp, 1, SITHDRSIZE, infp) != SITHDRSIZE) {
  735. X        fprintf(stderr, "Can't read file header\n");
  736. X        return(0);
  737. X    }
  738. X        
  739. X    if (strncmp(temp + S_SIGNATURE,  "SIT!", 4) == 0 &&
  740. X        strncmp(temp + S_SIGNATURE2, "rLau", 4) == 0) {
  741. X        s->numFiles = get2(temp + S_NUMFILES);
  742. X        s->arcLength = get4(temp + S_ARCLENGTH);
  743. X        return(1);
  744. X    }
  745. X    
  746. X    if (++count == 2) {
  747. X        fprintf(stderr, "Not a StuffIt file\n");
  748. X        return(0);
  749. X    }
  750. X    
  751. X    if (fread(&temp[SITHDRSIZE], 1, FILEHDRSIZE - SITHDRSIZE, infp) !=
  752. X        FILEHDRSIZE - SITHDRSIZE) {
  753. X        fprintf(stderr, "Can't read file header\n");
  754. X        return(0);
  755. X    }
  756. X    
  757. X    if (strncmp(temp + I_TYPEOFF, "SIT!", 4) == 0 &&
  758. X        strncmp(temp + I_AUTHOFF, "SIT!", 4) == 0) {    /* MacBinary format */
  759. X        fseek(infp, (long)(INFOBYTES-FILEHDRSIZE), 1);    /* Skip over header */
  760. X    }
  761. X    }
  762. X}
  763. X
  764. X/*
  765. X  readfilehdr - reads the file header for each file and the folder start
  766. X  and end records.
  767. X
  768. X  returns: H_ERROR = error
  769. X       H_EOF   = EOF
  770. X       H_WRITE = write file/folder
  771. X       H_SKIP  = skip file/folder
  772. X*/
  773. X
  774. Xreadfilehdr(f, skip)
  775. Xstruct fileHdr *f;
  776. Xint skip;
  777. X{
  778. X    unsigned short crc;
  779. X    int i, n, write_it, isfolder;
  780. X    char hdr[FILEHDRSIZE];
  781. X    char ch, *mp, *up;
  782. X    char *tp, temp[10];
  783. X
  784. X    for (i = 0; i < INFOBYTES; i++)
  785. X    info[i] = '\0';
  786. X
  787. X    /* read in the next file header, which could be folder start/end record */
  788. X    n = fread(hdr, 1, FILEHDRSIZE, infp);
  789. X    if (n == 0)            /* return 0 on EOF */
  790. X    return(H_EOF);
  791. X    else if (n != FILEHDRSIZE) {
  792. X    fprintf(stderr, "Can't read file header\n");
  793. X    return(H_ERROR);
  794. X    }
  795. X
  796. X    /* check the CRC for the file header */
  797. X    crc = INIT_CRC;
  798. X    crc = updcrc(crc, hdr, FILEHDRSIZE - 2);
  799. X    f->hdrCRC = get2(hdr + F_HDRCRC);
  800. X    if (f->hdrCRC != crc) {
  801. X    fprintf(stderr, "Header CRC mismatch: got 0x%04x, need 0x%04x\n",
  802. X        f->hdrCRC, crc);
  803. X    return(H_ERROR);
  804. X    }
  805. X
  806. X    /* grab the name of the file or folder */
  807. X    n = hdr[F_FNAME] & BYTEMASK;
  808. X    if (n > F_NAMELEN)
  809. X    n = F_NAMELEN;
  810. X    info[I_NAMEOFF] = n;
  811. X    copy(info + I_NAMEOFF + 1, hdr + F_FNAME + 1, n);
  812. X    strncpy(mname, hdr + F_FNAME + 1, n);
  813. X    mname[n] = '\0';
  814. X    /* copy to a string with no illegal Unix characters in the file name */
  815. X    mp = mname;
  816. X    up = uname;
  817. X    while ((ch = *mp++) != '\0') {
  818. X    if (ch <= ' ' || ch > '~' || index("/!()[]*<>?\\\"$\';&`", ch) != NULL)
  819. X        ch = '_';
  820. X    *up++ = ch;
  821. X    }
  822. X    *up = '\0';
  823. X
  824. X    /* get lots of other stuff from the header */
  825. X    f->compRMethod = hdr[F_COMPRMETHOD];
  826. X    f->compDMethod = hdr[F_COMPDMETHOD];
  827. X    f->rsrcLength = get4(hdr + F_RSRCLENGTH);
  828. X    f->dataLength = get4(hdr + F_DATALENGTH);
  829. X    f->compRLength = get4(hdr + F_COMPRLENGTH);
  830. X    f->compDLength = get4(hdr + F_COMPDLENGTH);
  831. X    f->rsrcCRC = get2(hdr + F_RSRCCRC);
  832. X    f->dataCRC = get2(hdr + F_DATACRC);
  833. X
  834. X    /* if it's an end folder record, don't need to do any more */
  835. X    if (f->compRMethod == endFolder && f->compDMethod == endFolder)
  836. X    return(H_WRITE);
  837. X
  838. X    /* prepare an info file in case its needed */
  839. X
  840. X    copy(info + I_TYPEOFF, hdr + F_FTYPE, 4);
  841. X    copy(info + I_AUTHOFF, hdr + F_CREATOR, 4);
  842. X    copy(info + I_FLAGOFF, hdr + F_FNDRFLAGS, 2);
  843. X#ifdef INITED_BUG
  844. X    info[INITED_OFF] &= INITED_MASK; /* reset init bit */
  845. X#endif
  846. X    copy(info + I_DLENOFF, hdr + F_DATALENGTH, 4);
  847. X    copy(info + I_RLENOFF, hdr + F_RSRCLENGTH, 4);
  848. X    copy(info + I_CTIMOFF, hdr + F_CREATIONDATE, 4);
  849. X    copy(info + I_MTIMOFF, hdr + F_MODDATE, 4);
  850. X
  851. X    isfolder = f->compRMethod == startFolder && f->compDMethod == startFolder;
  852. X    
  853. X    /* list the file name if verbose or listonly mode, also if query mode */
  854. X    if (skip)            /* skip = 1 if skipping all in this folder */
  855. X    write_it = 0;
  856. X    else {
  857. X    write_it = 1;
  858. X    if (listonly || verbose || query) {
  859. X        for (i = 0; i < depth; i++)
  860. X        putchar(' ');
  861. X        if (isfolder)
  862. X        printf("Folder: \"%s\"", uname);
  863. X        else
  864. X        printf("name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  865. X               uname, hdr + F_FTYPE, hdr + F_CREATOR,
  866. X               f->dataLength, f->rsrcLength);
  867. X        if (query) {    /* if querying, check with the boss */
  868. X        printf(" ? ");
  869. X        fgets(temp, sizeof(temp) - 1, stdin);
  870. X        tp = temp;
  871. X        write_it = 0;
  872. X        while (*tp != '\0') {
  873. X            if (*tp == 'y' || *tp == 'Y') {
  874. X            write_it = 1;
  875. X            break;
  876. X            }
  877. X            else
  878. X            tp++;
  879. X        }
  880. X        }
  881. X        else        /* otherwise, terminate the line */
  882. X        putchar('\n');
  883. X    }
  884. X    }
  885. X    return(write_it ? H_WRITE : H_SKIP);
  886. X}
  887. X
  888. Xcheck_access(fname)    /* return 0 if OK to write on file fname, -1 otherwise */
  889. Xchar *fname;
  890. X{
  891. X    char temp[10], *tp;
  892. X
  893. X    if (access(fname, 0) == -1) {
  894. X    return(0);
  895. X    }
  896. X    else {
  897. X    printf("%s exists.  Overwrite? ", fname);
  898. X    fgets(temp, sizeof(temp) - 1, stdin);
  899. X    tp = temp;
  900. X    while (*tp != '\0') {
  901. X        if (*tp == 'y' || *tp == 'Y') {
  902. X        return(0);
  903. X        }
  904. X        else
  905. X        tp++;
  906. X    }
  907. X    }
  908. X    return(-1);
  909. X}
  910. X
  911. Xunsigned short write_file(fname, ibytes, obytes, type)
  912. Xchar *fname;
  913. Xunsigned long ibytes, obytes;
  914. Xunsigned char type;
  915. X{
  916. X    unsigned short crc;
  917. X    int i, n, ch, lastch;
  918. X    FILE *outf;
  919. X    char temp[256];
  920. X
  921. X    crc = INIT_CRC;
  922. X    chkcrc = 1;            /* usually can check the CRC */
  923. X
  924. X    if (check_access(fname) == -1) {
  925. X    fseek(infp, ibytes, 1);
  926. X    chkcrc = 0;        /* inhibit crc check if file not written */
  927. X        return(-1);
  928. X    }
  929. X    
  930. X    switch (type) {
  931. X      case noComp:        /* no compression */
  932. X    outf = fopen(fname, "w");
  933. X    if (outf == NULL) {
  934. X        perror(fname);
  935. X        exit(1);
  936. X    }
  937. X    while (ibytes > 0) {
  938. X        n = (ibytes > IOBUFSIZ) ? IOBUFSIZ : ibytes;
  939. X        n = fread(iobuf, 1, n, infp);
  940. X        if (n == 0)
  941. X        break;
  942. X        crc = updcrc(crc, iobuf, n);
  943. X        outc(iobuf, n, outf);
  944. X        ibytes -= n;
  945. X    }
  946. X    fclose(outf);
  947. X    break;
  948. X      case rleComp:        /* run length encoding */
  949. X    outf = fopen(fname, "w");
  950. X    if (outf == NULL) {
  951. X        perror(fname);
  952. X        exit(1);
  953. X    }
  954. X    while (ibytes > 0) {
  955. X        ch = getc(infp) & 0xff;
  956. X        ibytes--;
  957. X        if (ch == 0x90) {    /* see if its the repeat marker */
  958. X        n = getc(infp) & 0xff; /* get the repeat count */
  959. X        ibytes--;
  960. X        if (n == 0) { /* 0x90 was really an 0x90 */
  961. X            iobuf[0] = 0x90;
  962. X            crc = updcrc(crc, iobuf, 1);
  963. X            outc(iobuf, 1, outf);
  964. X        }
  965. X        else {
  966. X            n--;
  967. X            for (i = 0; i < n; i++)
  968. X            iobuf[i] = lastch;
  969. X            crc = updcrc(crc, iobuf, n);
  970. X            outc(iobuf, n, outf);
  971. X        }
  972. X        }
  973. X        else {
  974. X        iobuf[0] = ch;
  975. X        crc = updcrc(crc, iobuf, 1);
  976. X        lastch = ch;
  977. X        outc(iobuf, 1, outf);
  978. X        }
  979. X    }
  980. X    fclose(outf);
  981. X    break;
  982. X      case lzwComp:        /* LZW compression */
  983. X    sprintf(temp, "%s%s", COMPRESS, " -d -c -n -b 14 ");
  984. X    if (txtmode) {
  985. X        strcat(temp, "| tr \'\\015\' \'\\012\' ");
  986. X        chkcrc = 0;        /* can't check CRC in this case */
  987. X    }
  988. X    strcat(temp, "> '");
  989. X    strcat(temp, fname);
  990. X    strcat(temp, "'");
  991. X    outf = popen(temp, "w");
  992. X    if (outf == NULL) {
  993. X        perror(fname);
  994. X        exit(1);
  995. X    }
  996. X    while (ibytes > 0) {
  997. X        n = (ibytes > IOBUFSIZ) ? IOBUFSIZ : ibytes;
  998. X        n = fread(iobuf, 1, n, infp);
  999. X        if (n == 0)
  1000. X        break;
  1001. X        fwrite(iobuf, 1, n, outf);
  1002. X        ibytes -= n;
  1003. X    }
  1004. X    pclose(outf);
  1005. X    if (chkcrc) {
  1006. X        outf = fopen(fname, "r"); /* read the file to get CRC value */
  1007. X        if (outf == NULL) {
  1008. X        perror(fname);
  1009. X        exit(1);
  1010. X        }
  1011. X        while (1) {
  1012. X        n = fread(iobuf, 1, IOBUFSIZ, outf);
  1013. X        if (n == 0)
  1014. X            break;
  1015. X        crc = updcrc(crc, iobuf, n);
  1016. X        }
  1017. X        fclose(outf);
  1018. X    }
  1019. X    break;
  1020. X      case hufComp:        /* Huffman compression */
  1021. X    outf = fopen(fname, "w");
  1022. X    if (outf == NULL) {
  1023. X        perror(fname);
  1024. X        exit(1);
  1025. X    }
  1026. X    nodeptr = nodelist;
  1027. X    bit = 0;        /* put us on a byte boundary */
  1028. X    read_tree();
  1029. X    while (obytes > 0) {
  1030. X        n = (obytes > IOBUFSIZ) ? IOBUFSIZ : obytes;
  1031. X        for (i = 0; i < n; i++)
  1032. X        iobuf[i] = gethuffbyte(DECODE);
  1033. X        crc = updcrc(crc, iobuf, n);
  1034. X        outc(iobuf, n, outf);
  1035. X        obytes -= n;
  1036. X    }
  1037. X    fclose(outf);
  1038. X    break;
  1039. X      default:
  1040. X    fprintf(stderr, "Unknown compression method\n");
  1041. X    chkcrc = 0;        /* inhibit crc check if file not written */
  1042. X    return(-1);
  1043. X    }
  1044. X
  1045. X    return(crc & 0xffff);
  1046. X}
  1047. X
  1048. Xoutc(p, n, fp)
  1049. Xchar *p;
  1050. Xint n;
  1051. XFILE *fp;
  1052. X{
  1053. X    register char *p1;
  1054. X    register int i;
  1055. X    if (txtmode) {
  1056. X    for (i = 0, p1 = p; i < n; i++, p1++)
  1057. X        if ((*p1 & BYTEMASK) == '\r')
  1058. X        *p1 = '\n';
  1059. X    }
  1060. X    fwrite(p, 1, n, fp);
  1061. X}
  1062. X
  1063. Xlong get4(bp)
  1064. Xchar *bp;
  1065. X{
  1066. X    register int i;
  1067. X    long value = 0;
  1068. X
  1069. X    for (i = 0; i < 4; i++) {
  1070. X    value <<= 8;
  1071. X    value |= (*bp & BYTEMASK);
  1072. X    bp++;
  1073. X    }
  1074. X    return(value);
  1075. X}
  1076. X
  1077. Xshort get2(bp)
  1078. Xchar *bp;
  1079. X{
  1080. X    register int i;
  1081. X    int value = 0;
  1082. X
  1083. X    for (i = 0; i < 2; i++) {
  1084. X    value <<= 8;
  1085. X    value |= (*bp & BYTEMASK);
  1086. X    bp++;
  1087. X    }
  1088. X    return(value);
  1089. X}
  1090. X
  1091. Xcopy(p1, p2, n)
  1092. Xchar *p1, *p2;
  1093. Xint n;
  1094. X{
  1095. X    while (n-- > 0)
  1096. X        *p1++ = *p2++;
  1097. X}
  1098. X
  1099. X/* This routine recursively reads the Huffman encoding table and builds
  1100. X   and decoding tree. */
  1101. X
  1102. Xstruct node *read_tree()
  1103. X{
  1104. X    struct node *np;
  1105. X    np = nodeptr++;
  1106. X    if (getbit() == 1) {
  1107. X        np->flag = 1;
  1108. X        np->byte = gethuffbyte(NODECODE);
  1109. X    }
  1110. X    else {
  1111. X        np->flag = 0;
  1112. X        np->zero = read_tree();
  1113. X        np->one  = read_tree();
  1114. X    }
  1115. X    return(np);
  1116. X}
  1117. X
  1118. X/* This routine returns the next bit in the input stream (MSB first) */
  1119. X
  1120. Xgetbit()
  1121. X{
  1122. X    static char b;
  1123. X    if (bit == 0) {
  1124. X        b = getc(infp) & 0xff;
  1125. X        bit = 8;
  1126. X    }
  1127. X    bit--;
  1128. X    return((b >> bit) & 1);
  1129. X}
  1130. X
  1131. X/* This routine returns the next 8 bits.  If decoding is on, it finds the
  1132. Xbyte in the decoding tree based on the bits from the input stream.  If
  1133. Xdecoding is not on, it either gets it directly from the input stream or
  1134. Xputs it together from 8 calls to getbit(), depending on whether or not we
  1135. Xare currently on a byte boundary
  1136. X*/
  1137. Xgethuffbyte(decode)
  1138. Xint decode;
  1139. X{
  1140. X    register struct node *np;
  1141. X    register int i, b;
  1142. X    if (decode == DECODE) {
  1143. X        np = nodelist;
  1144. X        while (np->flag == 0)
  1145. X            np = (getbit()) ? np->one : np->zero;
  1146. X        b = np->byte;
  1147. X    }
  1148. X    else {
  1149. X        if (bit == 0)    /* on byte boundary? */
  1150. X            b = getc(infp) & 0xff;
  1151. X        else {        /* no, put a byte together */
  1152. X            b = 0;
  1153. X            for (i = 8; i > 0; i--) {
  1154. X                b = (b << 1) + getbit();
  1155. X            }
  1156. X        }
  1157. X    }
  1158. X    return(b);
  1159. X}
  1160. END_OF_FILE
  1161. if test 31819 -ne `wc -c <'unstuffit/unsit.c'`; then
  1162.     echo shar: \"'unstuffit/unsit.c'\" unpacked with wrong size!
  1163. fi
  1164. # end of 'unstuffit/unsit.c'
  1165. fi
  1166. echo shar: End of archive 4 \(of 4\).
  1167. cp /dev/null ark4isdone
  1168. MISSING=""
  1169. for I in 1 2 3 4 ; do
  1170.     if test ! -f ark${I}isdone ; then
  1171.     MISSING="${MISSING} ${I}"
  1172.     fi
  1173. done
  1174. if test "${MISSING}" = "" ; then
  1175.     echo You have unpacked all 4 archives.
  1176.     rm -f ark[1-9]isdone
  1177. else
  1178.     echo You still need to unpack the following archives:
  1179.     echo "        " ${MISSING}
  1180. fi
  1181. ##  End of shell archive.
  1182. exit 0
  1183. --- end of part 4 ---
  1184.  
  1185.  
  1186.