home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 54 < prev    next >
Encoding:
Internet Message Format  |  1991-05-02  |  49.1 KB

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC036:  Nulib - Archive Library Tools (Unix) 05/10
  4. Message-ID: <May.1.18.11.35.1991.23506@yoko.rutgers.edu>
  5. Date: 1 May 91 22:11:37 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Andy McFadden (fadden@cory.berkeley.edu)
  10. Posting-number: Volume 1, Source:36
  11. Archive-name: archive/unix/nulib/part05.10
  12. Architecture: UNIX
  13. Version-number: 3.03
  14.  
  15.  
  16. =nuetc.c
  17. -/*
  18. - * nuetc.c - extra stuff; most is #ifdefed to death (mostly time routines
  19. - *           and file stuff that are highly system dependent)
  20. - *
  21. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  22. - * By Andy McFadden (fadden@cory.berkeley.edu)
  23. - */
  24. -#ifdef APW
  25. -segment "NuMain"
  26. -#endif
  27. -
  28. -#include "nudefs.h"
  29. -#include <stdio.h>
  30. -#include <fcntl.h>
  31. -#include <errno.h>      /* errno declarations */
  32. -#include <ctype.h>      /* for tolower(), isupper() */
  33. -
  34. -#ifdef UNIX
  35. -# include <time.h>      /* need localtime() */
  36. -# include <sys/types.h>   /* defn of time_t */
  37. -# include <sys/stat.h>
  38. -#endif
  39. -#ifdef APW
  40. -# include <stdlib.h>       /* exit(), etc. */
  41. -# include <types.h>       /* has _toolErr in it */
  42. -# include <prodos.h>
  43. -# include "apwerr.h"       /* APW/ProDOS error codes */
  44. -#endif
  45. -#ifdef MSDOS
  46. -# include <process.h>
  47. -# include <stdlib.h>
  48. -# include <io.h>
  49. -# include <sys/types.h>
  50. -# include <sys/stat.h>
  51. -# include <time.h>
  52. -#endif
  53. -
  54. -#include "nuetc.h"
  55. -/* note "nuread.h" is not included... none of the routines here assume */
  56. -/* any knowledge of NuFX archives.                                     */
  57. -
  58. -#ifndef MSDOS
  59. -extern char *malloc(); /* all systems ... except DOS : RBH */
  60. -#endif  /* +PORT+ */
  61. -
  62. -extern void free();
  63. -extern char *getenv();
  64. -#ifdef APW
  65. -extern Time ReadTimeHex();  /* should be TimeRec, from misctool.h */
  66. -#endif
  67. -
  68. -/* This is a generally available TEMPORARY filename buffer */
  69. -char tmpNameBuf[MAXFILENAME];
  70. -
  71. -
  72. -/******************** general misc routines ********************/
  73. -
  74. -/*
  75. - * Fatal error handler
  76. - */
  77. -void Fatal(deathstr, procName)
  78. -char *deathstr, *procName;
  79. -{
  80. -    fflush(stdout);
  81. -    fprintf(stderr, "\n%s: fatal error: %s\n--- ", prgName, deathstr);
  82. -    perror(procName);
  83. -    Quit (-1);
  84. -}
  85. -
  86. -
  87. -/*
  88. - * Quit can be used to perform cleanup operations before exiting.
  89. - */
  90. -void Quit(val)
  91. -int val;
  92. -{
  93. -    exit(val);
  94. -}
  95. -
  96. -
  97. -/*
  98. - * Safe malloc()... checks return value
  99. - */
  100. -char *Malloc(size)
  101. -int size;
  102. -{
  103. -    char *ptr = (char *) malloc(size);
  104. -
  105. -    if (ptr != (char *) NULL) {
  106. -    return(ptr);
  107. -    } else {
  108. -       /* 8910.31 - RBH: report byte size that failed */
  109. -       printf("Malloc: memory alloc error [%u : bytes]\n", size);
  110. -#ifdef MSDOS
  111. -       printf("(Largest Available Block: %u)\n", _memmax());
  112. -#endif
  113. -    Quit (-1);
  114. -    }
  115. -}
  116. -
  117. -/******************** UNIX compatibility routines ********************/
  118. -
  119. -#ifdef UNIX
  120. -/*
  121. - * Convert expanded date to a number of seconds for UNIX systems.
  122. - *
  123. - * Remember that *atime follows the NuFX docs for time values, which
  124. - * don't necessarily match those in UNIX manual pages.
  125. - * Adapted from _Advanced UNIX Programming_ by Marc J. Rochkind.
  126. - *
  127. - * Returns 0 if date/time is invalid.
  128. - */
  129. -long timecvt(atime)
  130. -Time *atime;
  131. -{
  132. -    long tm;
  133. -    int days;
  134. -    BOOLEAN isleapyear;
  135. -    int tzone;
  136. -    char *getenv(), *tz;
  137. -
  138. -    if ((tz = getenv("TZ")) == NULL)
  139. -    tzone = 8;  /* pacific std time */
  140. -    else
  141. -    tzone = atoi(&tz[3]);
  142. -
  143. -    isleapyear = (atime->year != 0) && (atime->year%4 == 0);  /* 2000 isn't */
  144. -    if (atime->year < 70)
  145. -    atime->year += 100;  /* years after 2000 */
  146. -    days = (atime->year - 70) * 365L;
  147. -    days += ((atime->year - 69L) / 4);  /* previous years' leap days */
  148. -
  149. -    switch (atime->month +1) {  /* month is 0-11 */
  150. -    case 12:
  151. -    days += 30;  /* Nov */
  152. -    case 11:
  153. -    days += 31;  /* Oct */
  154. -    case 10:
  155. -    days += 30;  /* Sep */
  156. -    case 9:
  157. -    days += 31;  /* Aug */
  158. -    case 8:
  159. -    days += 31;  /* Jul */
  160. -    case 7:
  161. -    days += 30;  /* Jun */
  162. -    case 6:
  163. -    days += 31;  /* May */
  164. -    case 5:
  165. -    days += 30;  /* Apr */
  166. -    case 4:
  167. -    days += 31;  /* Mar */
  168. -    case 3:
  169. -    days += (isleapyear ? 29 : 28);  /* Feb */
  170. -    case 2:
  171. -    days += 31;  /* Jan */
  172. -    case 1:
  173. -    break;
  174. -    default:
  175. -    /*printf("Invalid month\n");*/
  176. -    return (0L);
  177. -    }
  178. -
  179. -    if (atime->day > 31) {
  180. -    /*printf("Invalid day\n");*/
  181. -    return (0L);
  182. -    }
  183. -    tm = (days + atime->day) * 24L * 60L * 60L;
  184. -
  185. -    if (atime->hour > 23) {
  186. -    /*printf("Invalid hour\n");*/
  187. -    return (0L);
  188. -    }
  189. -    atime->hour += tzone;  /* correct for time zone */
  190. -    tm += atime->hour * 60L * 60L;
  191. -
  192. -    if (atime->minute > 59) {
  193. -    /*printf("Invalid minute\n");*/
  194. -    return (0L);
  195. -    }
  196. -    tm += atime->minute * 60L;
  197. -
  198. -    if (atime->second > 59) {
  199. -    /*printf("Invalid second\n");*/
  200. -    return (0L);
  201. -    }
  202. -    tm += atime->second;
  203. -
  204. -    if (localtime(&tm)->tm_isdst)  /* was that day in dst? */
  205. -    tm -= 60L * 60L;  /* adjust for daylight savings */
  206. -    return (tm);
  207. -}
  208. -#endif /* UNIX */
  209. -
  210. -/******************** APW compatibility routines ********************/
  211. -
  212. -#ifdef APW
  213. -/*
  214. - * Normally a C library function to print out a description of the most
  215. - * recent system (non-toolbox, non-ProDOS) error.  Exists under UNIX and
  216. - * MS C 5.1, so I'm assuming it exists most everywhere else...
  217. - */
  218. -void perror(errstr)
  219. -char *errstr;
  220. -{
  221. -    fflush(stdout);
  222. -    if ( (errno > 0) && (errno < sys_nerr) ) {    /* known APW error? */
  223. -    fprintf(stderr, "%s: %s\n", errstr, sys_errlist[errno]);
  224. -    } else {
  225. -    fprintf(stderr, "%s: ", errstr);
  226. -    fflush(stderr);
  227. -    ERROR( errno );
  228. -    }
  229. -    Quit (-1);
  230. -}
  231. -
  232. -
  233. -/* Check for //gs toolbox errors; all are fatal */
  234. -void ToolErrChk()
  235. -{
  236. -    int err = _toolErr;
  237. -
  238. -    if (err) {
  239. -    if (err < MPErr) {  /* was a ProDOS error? */
  240. -        fprintf(stderr, "Error: $%.2x %s\n", (char) err,
  241. -        ProDOSErr[err]);
  242. -    } else {
  243. -        fprintf(stderr, "Tool err ($%.4x): ", err);
  244. -        fflush(stderr);
  245. -        ERROR( err );
  246. -    }
  247. -    Quit (-1);
  248. -    }
  249. -}
  250. -
  251. -#endif /* APW */
  252. -
  253. -/******************** miscellaneous string routines ********************/
  254. -
  255. -/*
  256. - * Compare strings, ignoring case (may be in standard C lib; stricmp()?)
  257. - */
  258. -int strcasecmp(str1, str2)
  259. -register char *str1, *str2;
  260. -{
  261. -    register char one, two;
  262. -    register int val;
  263. -
  264. -    for ( ; *str1 && *str2; str1++, str2++) {
  265. -    one = (isupper(*str1) ? tolower(*str1) : *str1);
  266. -    two = (isupper(*str2) ? tolower(*str2) : *str2);
  267. -    if (val = two - one)
  268. -        return (val);
  269. -    }
  270. -    if (!(*str1) && !(*str2))  /* both zero -> equivalent */
  271. -    return (0);
  272. -    else {  /* one is shorter; return result */
  273. -    one = (isupper(*str1) ? tolower(*str1) : *str1);
  274. -    two = (isupper(*str2) ? tolower(*str2) : *str2);
  275. -    return (two - one);
  276. -    }
  277. -}
  278. -
  279. -int strncasecmp(str1, str2, num)
  280. -register char *str1, *str2;
  281. -int num;
  282. -{
  283. -    register int i;
  284. -    register char one, two;
  285. -    register int val;  /* keep going 'til no more registers... */
  286. -
  287. -    for (i = 0; (i < num) && (*str1) && (*str2); i++, str1++, str2++) {
  288. -    one = (isupper(*str1) ? tolower(*str1) : *str1);
  289. -    two = (isupper(*str2) ? tolower(*str2) : *str2);
  290. -    if (val = two - one)
  291. -        return (val);
  292. -    }
  293. -    if (i == num)  /* first num characters are equal, so return zero */
  294. -    return (0);
  295. -    else {  /* one ended early; return result */
  296. -    one = (isupper(*str1) ? tolower(*str1) : *str1);
  297. -    two = (isupper(*str2) ? tolower(*str2) : *str2);
  298. -    return (two - one);
  299. -    }
  300. -}
  301. -
  302. -/******************* file-related routines ********************/
  303. -
  304. -/*
  305. - * Do operating system-dependent CREATE stuff
  306. - *
  307. - * Creates a NuFX archive file, with type info where necessary.
  308. - * Does not leave file open.
  309. - */
  310. -void ArcfiCreate(filename)
  311. -char *filename;
  312. -{
  313. -    static char *procName = "ArcfiCreate";
  314. -#ifdef UNIX
  315. -    int fd;
  316. -
  317. -    if ((fd = open(filename, O_CREAT|O_RDWR, WPERMS)) < 0)
  318. -    Fatal("Unable to create file", procName);
  319. -    close(fd);
  320. -#else
  321. -# ifdef APW
  322. -    FileRec create_p;
  323. -
  324. -    c2pstr(filename);
  325. -    create_p.pathname = filename;
  326. -    create_p.fAccess = 0x00e3;
  327. -    create_p.fileType = 0x00e0;  /* LBR */
  328. -    create_p.auxType = 0x8002;     /* SHK */
  329. -    create_p.storageType = 0x0001;
  330. -    create_p.createDate = 0x0000;  /* let ProDOS fill in the blanks */
  331. -    create_p.createTime = 0x0000;
  332. -    CREATE( &create_p );
  333. -    ToolErrChk();
  334. -    p2cstr(filename);
  335. -# endif /* APW */
  336. -# ifdef MSDOS
  337. -    int fd;
  338. -
  339. -    if ((fd = open(filename, O_CREAT|O_RDWR, WPERMS)) < 0)
  340. -    Fatal("Unable to create file", procName);
  341. -    close(fd);
  342. -# endif /* MSDOS */
  343. -
  344. -# ifndef APW
  345. -# ifndef MSDOS
  346. -    int fd;
  347. -
  348. -    if ((fd = open(filename, O_CREAT|O_RDWR, WPERMS)) < 0)
  349. -    Fatal("Unable to create file", procName);
  350. -    close(fd);
  351. -# endif /* none2 */
  352. -# endif /* none1 */
  353. -#endif /* UNIX */
  354. -}
  355. -
  356. -
  357. -/*
  358. - * Determine if a file already exists.
  359. - */
  360. -BOOLEAN Exists(filename)
  361. -char *filename;
  362. -{
  363. -    static char *procName = "Exists";
  364. -#ifdef UNIX
  365. -    struct stat sm;
  366. -
  367. -    if (stat(filename, &sm) < 0) {
  368. -    if (errno == ENOENT)  /* if doesn't exist, then okay */
  369. -        return (FALSE);
  370. -    else  /* some other problem killed stat(), probably serious */
  371. -        fprintf(stderr, "Unable to stat() '%s'\n", filename);
  372. -        Fatal("Bad stat()", procName); /*serious prob*/
  373. -    } else  /* successful call - file exists */
  374. -    return (TRUE);
  375. -#else
  376. -# ifdef APW
  377. -    FileRec info_p;  /* check if file exists, is dir */
  378. -    int err;
  379. -
  380. -    c2pstr(filename);
  381. -    info_p.pathname = filename;
  382. -    GET_FILE_INFO( &info_p );
  383. -    err = _toolErr;
  384. -    p2cstr(filename);
  385. -    if (err == pathNotFound || err == fileNotFound)
  386. -    return (FALSE);
  387. -    else if (!err)
  388. -    return (TRUE);
  389. -    else {
  390. -    _toolErr = err;
  391. -    ToolErrChk();
  392. -    return (TRUE);
  393. -    }
  394. -# endif /* APW */
  395. -# ifdef MSDOS
  396. -    struct stat sm;
  397. -
  398. -    if (stat(filename, &sm) < 0) {
  399. -       if (errno == ENOENT)  /* if doesn't exist, then okay */
  400. -           return (FALSE);
  401. -       else  /* some other problem killed stat(), probably serious */
  402. -           fprintf(stderr, "Unable to stat() '%s'\n", filename);
  403. -           Fatal("Bad stat()", procName); /*serious prob*/
  404. -    } else  /* successful call - file exists */
  405. -       return (TRUE);
  406. -# endif /* MSDOS */
  407. -
  408. -# ifndef APW
  409. -# ifndef MSDOS
  410. -    printf("Need [other] Exists()\n");  /* +PORT+ */
  411. -    return (FALSE);
  412. -# endif /* none2 */
  413. -# endif /* none1 */
  414. -#endif /* UNIX */
  415. -}
  416. -
  417. -
  418. -/*
  419. - * Generate a temporary file name (system dependent).
  420. - * Assumes space is allocated for buffer.
  421. - */
  422. -char *MakeTemp(buffer)
  423. -char *buffer;
  424. -{
  425. -    static char *procName = "MakeTemp";
  426. -#ifdef UNIX
  427. -    extern char *mktemp();
  428. -
  429. -    strcpy(buffer, "nulb.tmpXXXXXX");
  430. -    return (mktemp(buffer));
  431. -#else
  432. -# ifdef APW
  433. -    int idx = 0;
  434. -
  435. -    do {
  436. -        sprintf(buffer, "nulb.tmp%d", idx++);
  437. -    } while (Exists(buffer));
  438. -    return (buffer);
  439. -# endif /* APW */
  440. -# ifdef MSDOS
  441. -    extern char *mktemp();
  442. -
  443. -    strcpy(buffer, "nulbXXXX.tmp");
  444. -    return (mktemp(buffer));
  445. -# endif /* MSDOS */
  446. -
  447. -# ifndef APW
  448. -# ifndef MSDOS
  449. -    strcpy(buffer, "nulb.tmp");  /* +PORT+ */
  450. -    return (buffer);
  451. -# endif /* none2 */
  452. -# endif /* none1 */
  453. -#endif /* UNIX */
  454. -}
  455. -
  456. -#ifdef NO_RENAME
  457. -/*
  458. - * This is a replacement for the library call, in case somebody's C library
  459. - * doesn't have it.
  460. - */
  461. -int rename(fromname, toname)
  462. -{
  463. -    if (link(fromname, toname) < 0)
  464. -    return (-1);
  465. -    if (unlink(fromname) < 0)
  466. -    return (-1);
  467. -}
  468. -#endif
  469. -
  470. -
  471. -/*
  472. - * Rename a file.
  473. - */
  474. -void Rename(fromname, toname)
  475. -char *fromname, *toname;
  476. -{
  477. -    static char *procName = "Rename";
  478. -#ifdef UNIX
  479. -    if (Exists(toname)) {
  480. -    fprintf(stderr, "\n%s: WARNING: Unable to rename '%s' as '%s'\n",
  481. -        prgName, fromname, toname);
  482. -    fflush(stderr);
  483. -    }
  484. -# ifdef AOSVS                    /* BAK 04/30/90 */
  485. -    printf("Work on AOS/VS rename command\n");    /* BAK 04/30/90 */
  486. -# else                        /* BAK 04/30/90 */
  487. -    else {
  488. -    if (rename(fromname, toname) < 0) {  /* this should "never" fail */
  489. -        fprintf(stderr,
  490. -        "\n%s: WARNING: Unable to rename '%s' as '%s'\n",
  491. -        prgName, fromname, toname);
  492. -        Fatal("Bad rename()", procName); /*serious prob*/
  493. -    }
  494. -    }
  495. -# endif
  496. -#else
  497. -# ifdef APW
  498. -    PathNameRec cpath_p;
  499. -
  500. -    if (Exists(toname)) {
  501. -    fprintf(stderr, "\n%s: WARNING: Unable to rename '%s' as '%s'\n",
  502. -        prgName, fromname, toname);
  503. -    fflush(stderr);
  504. -    return;
  505. -    }
  506. -
  507. -    cpath_p.pathname = fromname;
  508. -    cpath_p.newPathname = toname;
  509. -    c2pstr(fromname);
  510. -    c2pstr(toname);
  511. -    CHANGE_PATH( &cpath_p );
  512. -    ToolErrChk();
  513. -    p2cstr(fromname);
  514. -    p2cstr(toname);
  515. -# endif /* APW */
  516. -# ifdef MSDOS
  517. -    if (Exists(toname)) {
  518. -    fprintf(stderr, "\n%s: WARNING: Unable to rename '%s' as '%s'\n",
  519. -        prgName, fromname, toname);
  520. -    fflush(stderr);
  521. -    return;
  522. -    }
  523. -    printf("Work on MSDOS rename command\n");
  524. -# endif /* MSDOS */
  525. -
  526. -# ifndef APW
  527. -# ifndef MSDOS
  528. -    if (Exists(toname)) {
  529. -    fprintf(stderr, "\n%s: WARNING: Unable to rename '%s' as '%s'\n",
  530. -        prgName, fromname, toname);
  531. -    fflush(stderr);
  532. -    return;
  533. -    }
  534. -    printf("Need [other] rename command\n");  /* +PORT+ */
  535. -# endif /* none2 */
  536. -# endif /* none1 */
  537. -#endif /*UNIX*/
  538. -}
  539. -
  540. -/******************** date/time routines ********************/
  541. -
  542. -/*
  543. - * Expand date/time from file-sys dependent format to eight byte NuFX format.
  544. - * tptr is filesys format, TimePtr is NuFX format
  545. - */
  546. -void ExpandTime(tptr, TimePtr)       /* (BSD) UNIX version */
  547. -onebyt *tptr;  /* usually points to a time_t (long) */
  548. -Time *TimePtr;
  549. -{
  550. -#ifdef UNIX
  551. -    time_t *tp = (time_t *) tptr;
  552. -    struct tm *unixt;
  553. -
  554. -    unixt = localtime(tp);  /* expand time_t into components */
  555. -    TimePtr->second = unixt->tm_sec;
  556. -    TimePtr->minute = unixt->tm_min;
  557. -    TimePtr->hour = unixt->tm_hour;
  558. -    TimePtr->year = unixt->tm_year;
  559. -    TimePtr->day = unixt->tm_mday -1;  /* want 0-xx, not 1-xx */
  560. -    TimePtr->month = unixt->tm_mon;
  561. -    TimePtr->extra = 0;
  562. -    TimePtr->weekDay = unixt->tm_wday +1;  /* Sunday = 1, not 0 like UNIX */
  563. -#else
  564. -# ifdef APW                /* APW version */
  565. -    twobyt date, time;
  566. -
  567. -    date = (twobyt)tptr[0] + ((twobyt)tptr[1] << 8);
  568. -    time = (twobyt)tptr[2] + ((twobyt)tptr[3] << 8);
  569. -    TimePtr->second = 0;  /* not stored in ProDOS file info */
  570. -    TimePtr->minute = (char) time;  /* truncated to char */
  571. -    TimePtr->hour = time >> 8;
  572. -    TimePtr->year = date >> 9;
  573. -    TimePtr->day = (date & 0x1f) - 1;
  574. -    TimePtr->month = ((date & 0x01e0) >> 5) - 1;
  575. -    TimePtr->extra = 0;
  576. -    TimePtr->weekDay = 0;
  577. -# endif /* APW */
  578. -# ifdef MSDOS
  579. -    struct tm *newtime;
  580. -    time_t *tp = (time_t *) tptr;
  581. -
  582. -    newtime = localtime (tp);
  583. -    TimePtr->second = (onebyt)newtime->tm_sec;
  584. -    TimePtr->minute = (onebyt)newtime->tm_min;
  585. -    TimePtr->hour   = (onebyt)newtime->tm_hour;
  586. -    TimePtr->year   = (onebyt)newtime->tm_year;
  587. -    TimePtr->day    = (onebyt)newtime->tm_mday - 1;
  588. -    TimePtr->month  = (onebyt)newtime->tm_mon;
  589. -    TimePtr->extra  = 0;
  590. -    TimePtr->weekDay= (onebyt)newtime->tm_wday + 1;
  591. -# endif /* MSDOS */
  592. -
  593. -# ifndef APW
  594. -# ifndef MSDOS
  595. -    printf("Need [other] time-expander\n");  /* +PORT+ */
  596. -    TimePtr->second = 0;
  597. -    TimePtr->minute = 0;
  598. -    TimePtr->hour = 0;
  599. -    TimePtr->year = 0;
  600. -    TimePtr->day = 0;
  601. -    TimePtr->month = 0;
  602. -    TimePtr->extra = 0;
  603. -    TimePtr->weekDay = 0;
  604. -# endif /* none1 */
  605. -# endif /* none2 */
  606. -#endif /* UNIX */
  607. -}
  608. -
  609. -
  610. -/*
  611. - * Get current time, put in struct
  612. - */
  613. -Time *GetTime()
  614. -{
  615. -    static Time t;
  616. -#ifdef UNIX
  617. -    struct tm *unixt;
  618. -    time_t now = time(NULL);
  619. -
  620. -    unixt = localtime(&now);
  621. -    t.second = unixt->tm_sec;
  622. -    t.minute = unixt->tm_min;
  623. -    t.hour = unixt->tm_hour;
  624. -    t.year = unixt->tm_year;
  625. -    t.day = unixt->tm_mday -1;    /* want 0-xx, not 1-xx */
  626. -    t.month = unixt->tm_mon;
  627. -    t.extra = 0;
  628. -    t.weekDay = unixt->tm_wday +1;  /* Sunday = 1, not 0 like UNIX */
  629. -    /* return (&t) */
  630. -#else
  631. -# ifdef APW
  632. -    t = ReadTimeHex(t);
  633. -    /* return (&t) */
  634. -# endif /* APW */
  635. -# ifdef MSDOS
  636. -    struct tm *pctime;
  637. -    time_t now = time(NULL);
  638. -
  639. -    pctime = localtime(&now);
  640. -    t.second = (onebyt)pctime->tm_sec;
  641. -    t.minute = (onebyt)pctime->tm_min;
  642. -    t.hour   = (onebyt)pctime->tm_hour;
  643. -    t.year   = (onebyt)pctime->tm_year;
  644. -    t.day    = (onebyt)pctime->tm_mday -1; /* want 0-xx, not 1-xx */
  645. -    t.month  = (onebyt)pctime->tm_mon;
  646. -    t.extra  = 0;
  647. -    t.weekDay= (onebyt)pctime->tm_wday +1;  /* Sunday = 1, not 0 */
  648. -    /* return (&t) */
  649. -# endif /* MSDOS */
  650. -
  651. -# ifndef APW
  652. -# ifndef MSDOS
  653. -    printf("\nNeed [other] GetTime\n");  /* +PORT+ */
  654. -    t->second = 0;
  655. -    t->minute = 0;
  656. -    t->hour = 0;
  657. -    t->year = 0;
  658. -    t->day = 0;
  659. -    t->month = 0;
  660. -    t->filler = 0;
  661. -    t->weekDay = 0;
  662. -    /* return (&t) */
  663. -# endif /* none1 */
  664. -# endif /* none2 */
  665. -#endif /* UNIX */
  666. -    return (&t);
  667. -}
  668. -
  669. -
  670. -/*
  671. - * Convert a NuFX Time struct to a compact system-dependent format
  672. - *
  673. - * This is used to set a file's date when extracting.  Most systems don't
  674. - * dedicate 8 bytes to storing the date; this reduces it to the format
  675. - * used by a "set_file_date" command.
  676. - */
  677. -long ReduceTime(tptr)
  678. -Time *tptr;
  679. -{
  680. -#ifdef UNIX
  681. -    long t = timecvt(tptr);
  682. -
  683. -    return (t ? t : time(NULL));    /* if stored time is invalid, */
  684. -                    /* return current time */
  685. -#else
  686. -# ifdef APW
  687. -    twobyt date, time;
  688. -    long val;
  689. -
  690. -    date = ((twobyt)tptr->year << 9) | ((((twobyt)tptr->month)+1) << 5) |
  691. -       (((twobyt)tptr->day)+1);
  692. -    time = ((twobyt)tptr->hour << 8) | ((twobyt)tptr->minute);
  693. -
  694. -    val = (long) date + ((long) time << 16);
  695. -    return (val);
  696. -# endif /* APW */
  697. -# ifdef MSDOS
  698. -    return (time(NULL)); /* not sure what to do, return current : RBH */
  699. -# endif /* MSDOS */
  700. -
  701. -#ifndef APW
  702. -#ifndef MSDOS
  703. -    printf("Need [other] ReduceTime\n");  /* +PORT+ */
  704. -# endif /* none2 */
  705. -# endif /* none1 */
  706. -#endif /* UNIX */
  707. -}
  708. -
  709. =numain.c
  710. -/*
  711. - * numain.c - shell-based front end for NuLib
  712. - *
  713. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  714. - * By Andy McFadden (fadden@cory.berkeley.edu)
  715. - */
  716. -#ifdef APW
  717. -segment "main"
  718. -#endif
  719. -
  720. -static char *header =
  721. - "NuLib v3.03  February 1991  Freeware   Copyright 1989-91 By Andy McFadden";
  722. -
  723. -#include "nudefs.h"    /* system-dependent defines */
  724. -#include <stdio.h>    /* standard I/O library */
  725. -#include <errno.h>
  726. -#include <fcntl.h>
  727. -#include <ctype.h>    /* C type stuff, like tolower() */
  728. -#ifdef BSD43
  729. -# include <strings.h>
  730. -#else  /* SYSV, APW, MSC */
  731. -# include <string.h>    /* string stuff */
  732. -#endif
  733. -
  734. -#ifdef APW
  735. -# include <stdlib.h>
  736. -# include <types.h>
  737. -# include <strings.h>
  738. -# include <shell.h>
  739. -#endif
  740. -
  741. -#include "nuread.h"    /* structs for archive info, archive read routines */
  742. -#include "nuview.h"    /* archive listing functions */
  743. -#include "nuadd.h"    /* archive operations (add, create, move) */
  744. -#include "nuext.h"    /* archive operations (extract) */
  745. -#include "nupdel.h"    /* archive operations (delete, update, freshen) */
  746. -#include "nublu.h"    /* Binary II archive operations */
  747. -#include "nupak.h"    /* need PAKBUFSIZ */    
  748. -#include "nuetc.h"    /* Malloc(), Fatal(), etc. */
  749. -
  750. -extern char *getenv();  /* +PORT+ */
  751. -
  752. -#define Whoops(str) printf("WARNING: typedef %s may be set incorrectly\n",str);
  753. -#define ENVAR    "NULIBOPT"  /* environment variable with options in it */
  754. -
  755. -/*
  756. - * global to entire program
  757. - */
  758. -int HiLo;        /* byte ordering; FALSE on low-first (65816) */
  759. -int verbose;        /* print verbose? */
  760. -int interact;        /* interactive overwrite mode? */
  761. -int dopack;        /* do we want to pack/unpack? */
  762. -int doExpand;        /* do we want to expand archive filenames? */
  763. -int doSubdir;        /* process subdirectories at all? */
  764. -int doMessages;        /* do comments instead of data */
  765. -int transfrom;    /* how to do CR<->LF translation (from what?)  (-1 = off) */
  766. -int transto;    /* translate to ? */
  767. -int packMethod;        /* how to pack a file */
  768. -fourbyt defFileType;    /* default file type */
  769. -fourbyt defAuxType;    /* default aux type */
  770. -onebyt *pakbuf;  /* used by compression routines; created once to reduce */
  771. -         /* overhead involved in malloc()ing a 64K buffer */
  772. -char *prgName = "NuLib";    /* for error messages; don't like argv[0] */
  773. -                /* besides, the name changes every 3 weeks */
  774. -
  775. -/*
  776. - * Print simple usage info
  777. - */
  778. -static void Usage(argv0)
  779. -char *argv0;
  780. -{
  781. -    printf("\nUsage: %s option[suboptions] archive-name [filespec]\n", argv0);
  782. -    printf("\nType \"%s h\" for help.\n", argv0);
  783. -}
  784. -
  785. -
  786. -/*
  787. - * Print usage info
  788. - */
  789. -static void Help(argv0, options)
  790. -char *argv0, *options;
  791. -{
  792. -    if (INDEX(options+1, 'n')) {  /* using 'n' suboption? */
  793. -    printf("%s\n", header);
  794. -    printf("\nCompression methods:\n");
  795. -    printf("  #  Name                        Abbr  Pack?  Unpack?\n");
  796. -    printf("  0: Uncompressed                unc     Y      Y\n");
  797. -    printf("  1: SQueezed (sq/usq)           squ     N      Y\n");
  798. -    printf("  2: Dynamic LZW-I (ShrinkIt)    shk     Y      Y\n");
  799. -    printf("  3: Dynamic LZW-II (ShrinkIt)   sh2     N      N\n");
  800. -    printf("  4: UNIX 12-bit compress        u12     Y      Y\n");
  801. -    printf("  5: UNIX 16-bit compress        u16     Y      Y\n");
  802. -    printf("The default is #2\n");
  803. -    printf("\nText conversion methods (during extraction):\n");
  804. -    printf("  0: Convert from CR to this system (ProDOS files)\n");
  805. -    printf("  1: Convert from LF to this system (UNIX files)\n");
  806. -    printf("  2: Convert from CRLF to this system (MS-DOS files)\n");
  807. -
  808. -    } else if (INDEX(options+1, 'w')) {  /* print author info */
  809. -
  810. -    printf("%s\n", header);
  811. -    printf(
  812. -       "Internet: fadden@cory.berkeley.edu   Usenet: ...!ucbvax!cory!fadden\n");
  813. -    printf("\nShrinkIt and NuFX standard by Andy Nicholas.\n");
  814. -    printf(
  815. -  "ShrinkIt LZW compression by Kent Dickey.  LZW/II (a modified version of\n");
  816. -    printf("  Kent's algorithm) by Andy Nicholas.\n");
  817. -    printf("\nUNIX compress code adapted from COMPRESS v4.3.\n");
  818. -    printf(
  819. -"\nBinary II unpack and unsqueeze C code adapted from unblu.c and usq.c by\n");
  820. -    printf("  Marcel J.E. Mol (usq.c based on usq2/sq3 by Don Elton).\n");
  821. -    printf("\nMS-DOS port by Robert B. Hess and Bruce Kahn.\n");
  822. -    printf(
  823. -"\nThis program is Freeware.  Please distribute as widely as possible, but\n");
  824. -    printf(
  825. -      "  don't sell it.  Source code is available via e-mail upon request.\n");
  826. -    printf(
  827. -       "\nUsers without Usenet/Internet access may send mail to me at:\n");
  828. -    printf("  1474 Saskatchewan Drive\n");
  829. -    printf("  Sunnyvale, CA 94087\n");
  830. -
  831. -    } else if (INDEX(options+1, 's')) {  /* suboption info */
  832. -    printf("%s\n", header);
  833. -    printf("\nUsual meaning of suboptions:\n");
  834. -    printf("  c  - compression type, followed by a number\n");
  835. -    printf(
  836. -        "  f  - file/aux type to add, followed by file/aux type spec\n");
  837. -    printf("  i  - interactive; prompt before overwriting file\n");
  838. -    printf("  m  - messages (add/extract comments instead of data)\n");
  839. -    printf("  r  - don't recursively descend subdirectories\n");
  840. -    printf("  s  - storage type (store as compressed w/o compressing), ");
  841. -    printf("followed by number\n");
  842. -    printf(
  843. -       "  t  - text translation (CR<->LF), followed by conversion mode\n");
  844. -    printf("  u  - store as uncompressed (same as c0)\n");
  845. -    printf("  v  - verbose mode\n");
  846. -#ifndef NO_BLU
  847. -    printf("  x  - extract during Binary II operations\n");
  848. -#endif
  849. -    printf("  +  - match partial pathnames for extract and delete\n");
  850. -    printf("\nTable of contents suboptions:\n");
  851. -    printf("  v  - verbose output (same as V option)\n");
  852. -    printf("  a  - ARC/ZOO style format\n");
  853. -    printf("  z  - full output, prints all aspects of archive\n");
  854. -
  855. -    printf("\nSample shell variable command (csh):\n");
  856. -    printf(
  857. -      "  setenv NULIBOPT=verbose,interactive,type=SRC,aux=000a,compress=5\n");
  858. -    printf("  (default is non-verbose, non-interactive, type=NON, ");
  859. -    printf(  "aux=0000, compress=2)\n");
  860. -    
  861. -    } else {  /* default help screen */
  862. -
  863. -    printf("%s\n", header);
  864. -    printf(
  865. -         "\nUsage: %s option[suboptions] archive-name [filespec]\n", argv0);
  866. -    printf("Option must be one of:\n");
  867. -    printf("  a[vucsrf]   add to archive\n");
  868. -#ifndef NO_BLU
  869. -    printf("  b[xvti]     Binary II archive operations\n");
  870. -#endif
  871. -    printf(
  872. -       "  c[vucsrf]   create archive (add, but suppress 'create' message)\n");
  873. -    printf("  d[v+]       delete file from archive\n");
  874. -    printf("  f[vucsrf]   freshen files in archive\n");
  875. -    printf("  h[snw]      show help screen (subopt/numbers/who's who)\n");
  876. -    printf("  i[v]        verify archive integrity\n");
  877. -    printf("  m[vucsrf]   move files to archive (add, delete original)\n");
  878. -    printf("  p[vmt+]     print archived file to stdout\n");
  879. -    printf("  t[vaz]      display table of contents\n");
  880. -    printf("  u[vucsrf]   update files in archive\n");
  881. -    printf("  v           verbose listing (ProDOS 8 ShrinkIt format)\n");
  882. -    printf("  x,e[vumti+] extract from archive\n");
  883. -    }
  884. -}
  885. -
  886. -
  887. -/*
  888. - * Check machine dependencies
  889. - */
  890. -static void CheckMach()
  891. -{
  892. -    onebyt one;
  893. -    onebyt *oneptr;
  894. -    twobyt two;
  895. -    fourbyt four;
  896. -
  897. -#ifdef UNIX
  898. -# ifdef APW
  899. -    ^^ "ERROR: You have both APW and UNIX defined" ^^
  900. -# endif
  901. -# ifdef MSDOS
  902. -    ^^ "ERROR: You have both MSDOS and UNIX defined" ^^
  903. -# endif
  904. -#endif /*UNIX*/
  905. -#ifdef APW
  906. -# ifdef MSDOS
  907. -    ^^ "ERROR: You have both APW and MSDOS defined" ^^
  908. -# endif
  909. -#endif
  910. -
  911. -    /* some compilers complain about (unsigned) -1 , so I'm doing it this */
  912. -    /* way to keep everybody quiet.                      */
  913. -
  914. -    one = 0x100;
  915. -    if (one)
  916. -    Whoops("onebyt");  /* one > 1 */
  917. -    two = 0x10000;
  918. -    if (two)
  919. -    Whoops("twobyt");  /* two > 2 */
  920. -    two = 0x1000;
  921. -    if (!two)
  922. -    Whoops("twobyt");  /* two < 2 */
  923. -    four = 0xffffffff;
  924. -    four++;
  925. -    if (four)
  926. -    Whoops("fourbyt");  /* four > 4 */
  927. -    four = 0x10000;
  928. -    if (!four)
  929. -    Whoops("fourbyt");  /* four < 4 */
  930. -
  931. -    /* check byte ordering */
  932. -    two = 0x1122;
  933. -    oneptr = (onebyt *) &two;
  934. -    if (*oneptr == 0x11)
  935. -    HiLo = TRUE;
  936. -    else if (*oneptr == 0x22)
  937. -    HiLo = FALSE;
  938. -    else {
  939. -    printf("WARNING: Unable to determine a value for HiLo\n");
  940. -    HiLo = FALSE;
  941. -    }
  942. -
  943. -    /* check some other stuff... compilers may (should?) give warnings here */
  944. -    if (ATTSIZE < MHsize)
  945. -    printf("WARNING: ATTSIZE must be >= than MHsize\n");
  946. -    if (RECBUFSIZ < ATTSIZE)
  947. -    printf("WARNING: RECBUFSIZ should be larger than ATTSIZE\n");
  948. -    if (MHsize != 48 || THsize != 16)
  949. -    printf("WARNING: Bad MHsize or THsize\n");
  950. -    if (sizeof(Time) != 8)
  951. -    printf("WARNING: struct Time not 8 bytes\n");
  952. -}
  953. -
  954. -
  955. -/*
  956. - * Check to see if string 2 is in string 1.
  957. - *
  958. - * Returns the position of string 2 within string 1; -1 if not found.
  959. - */
  960. -static int strc(host, sub)
  961. -char *host, *sub;
  962. -{
  963. -    int hlen = strlen(host);
  964. -    int slen = strlen(sub);
  965. -    int i;
  966. -
  967. -    if (slen > hlen)  /* substring longer than host string */
  968. -    return (-1);
  969. -
  970. -    /* generic linear search... */
  971. -    for (i = 0; i <= (hlen - slen); i++)
  972. -    if ((*(host+i) == *sub) && (!strncmp(host+i, sub, slen)))
  973. -        return (i);
  974. -    
  975. -    return (-1);
  976. -}
  977. -
  978. -
  979. -/*
  980. - * Yank a number from a character string.
  981. - */
  982. -int OptNum(ptr)
  983. -char *ptr;
  984. -{
  985. -    int val = 0;
  986. -
  987. -    while (*ptr && isdigit(*ptr)) {
  988. -    val *= 10;
  989. -    val += (*ptr - '0');
  990. -    ptr++;
  991. -    }
  992. -    return (val);
  993. -}
  994. -
  995. -
  996. -/*
  997. - * Set default values for globals.
  998. - *
  999. - * Should be of form "NULIBOPT=..."
  1000. - *   verbose        : default to verbose output
  1001. - *   interactive    : default to interactive mode when overwriting
  1002. - *   type=xxx        : set storage type to ProDOS type "xxx"
  1003. - *   aux=xxxx        : set aux storage type to 4-byte hex number "xxxx"
  1004. - */
  1005. -void GetDefaults(options)
  1006. -char *options;
  1007. -{
  1008. -    char *envptr;
  1009. -    int off, idx, pt;
  1010. -    int len = strlen(options);
  1011. -    char type[5];
  1012. -
  1013. -    /* set program default values */
  1014. -    verbose = FALSE;    /* silent mode */
  1015. -    interact = FALSE;    /* don't ask questions */
  1016. -    doSubdir = TRUE;    /* process subdirectories unless told not to */
  1017. -    dopack = TRUE;    /* don't pack unless told to */
  1018. -    doExpand = FALSE;    /* don't expand archived filenames */
  1019. -    doMessages = FALSE;    /* do comments instead of data */
  1020. -    packMethod = 0x0002;/* ShrinkIt LZW */
  1021. -    transfrom = -1;    /* no text translation */
  1022. -    transto = -1;
  1023. -    defFileType = (fourbyt) 0;    /* NON */
  1024. -    defAuxType = (fourbyt) 0;    /* $0000 */
  1025. -
  1026. -    /* read from global envir var */
  1027. -    if (envptr = getenv(ENVAR)) {
  1028. -    if (strc(envptr, "verbose") >= 0) {
  1029. -        verbose = TRUE;
  1030. -    }
  1031. -    if (strc(envptr, "interactive") >= 0) {
  1032. -        interact = TRUE;
  1033. -    }
  1034. -    if ((off = strc(envptr, "compress=")) >= 0) {
  1035. -        off += 9;
  1036. -        if (off+1 > strlen(envptr)) {
  1037. -        fprintf(stderr, "Error with 'compress=n' in NULIBOPT var\n");
  1038. -        Quit (-1);
  1039. -        }
  1040. -        packMethod = atoi(envptr+off);
  1041. -    }
  1042. -    if ((off = strc(envptr, "type=")) >= 0) {
  1043. -        off += 5;
  1044. -        if (off+3 > strlen(envptr)) {
  1045. -        fprintf(stderr, "Error with 'type=xxx' in NULIBOPT var\n");
  1046. -        Quit (-1);
  1047. -        }
  1048. -        strncpy(type, envptr+off, 3);
  1049. -        type[3] = '\0';
  1050. -        for (idx = 0; idx < 256; idx++)  /* scan for file type */
  1051. -        if (!strcasecmp(FT[idx], type)) {
  1052. -            defFileType = (fourbyt) idx;
  1053. -            break;  /* out of for */
  1054. -        }
  1055. -    }
  1056. -    if ((off = strc(envptr, "aux=")) >= 0) {
  1057. -        off += 4;
  1058. -        if (off+4 > strlen(envptr)) {
  1059. -        fprintf(stderr, "Error with 'aux=$xxxx' in NULIBOPT var\n");
  1060. -        Quit (-1);
  1061. -        }
  1062. -        strncpy(type, envptr+off, 4);
  1063. -        type[4] = '\0';
  1064. -        sscanf(type, "%x", &defAuxType);
  1065. -    }
  1066. -    }
  1067. -
  1068. -    /* handle command line suboption string */
  1069. -    for (pt = 1; pt < len; pt++) {  /* skip option char */
  1070. -    switch(options[pt]) {
  1071. -    case '+':    /* expand */
  1072. -        doExpand = TRUE;
  1073. -        break;
  1074. -    case 'a':    /* ARC/ZOO output format */
  1075. -        /* do nothing */
  1076. -        break;
  1077. -    case 'c':    /* compress method */
  1078. -        packMethod = OptNum(&options[pt+1]);
  1079. -        while (pt < len && isdigit(options[pt+1]))  /* advance to next */
  1080. -        pt++;
  1081. -        dopack = TRUE;
  1082. -        break;
  1083. -    case 'f':    /* filetype specified */
  1084. -        strncpy(type, &options[pt+1], 3);
  1085. -        type[3] = '\0';
  1086. -        for (idx = 0; idx < 256; idx++)  /* scan for file type */
  1087. -        if (!strcasecmp(FT[idx], type)) {
  1088. -            defFileType = (fourbyt) idx;
  1089. -            break;  /* out of for */
  1090. -        }
  1091. -
  1092. -        pt += strlen(type);
  1093. -        if (options[pt+1] == '/') {  /* auxtype specification */
  1094. -        pt++;
  1095. -        strncpy(type, &options[pt+1], 4);
  1096. -        type[4] = '\0';
  1097. -        sscanf(type, "%lx", &defAuxType);
  1098. -        pt += strlen(type);
  1099. -        }
  1100. -        break;
  1101. -    case 'i':    /* interactive overwrites */
  1102. -        interact = TRUE;
  1103. -        break;
  1104. -    case 'm':    /* do messages instead of data */
  1105. -        doMessages = TRUE;
  1106. -        break;
  1107. -    case 'n':    /* help with numbers */
  1108. -        /* do nothing */
  1109. -        break;
  1110. -    case 'r':    /* don't recursively descend subdir */
  1111. -        doSubdir = FALSE;
  1112. -        break;
  1113. -    case 's':    /* store method */
  1114. -        packMethod = OptNum(&options[pt+1]);
  1115. -        while (pt < len && isdigit(options[pt+1]))  /* advance to next */
  1116. -        pt++;
  1117. -        dopack = FALSE;
  1118. -        break;
  1119. -    case 't':    /* how to translate text? */
  1120. -        transfrom = OptNum(&options[pt+1]);
  1121. -        while (pt < len && isdigit(options[pt+1]))
  1122. -        pt++;
  1123. -        break;
  1124. -    case 'u':    /* don't use compression */
  1125. -        dopack = FALSE;  /* this doesn't matter, but FALSE may be faster */
  1126. -        packMethod = 0x0000;  /* archive w/o compression */
  1127. -        break;
  1128. -    case 'v':    /* verbose mode */
  1129. -        verbose = TRUE;
  1130. -        break;
  1131. -    case 'w':    /* help on people */
  1132. -        /* do nothing */
  1133. -        break;
  1134. -    case 'x':    /* extract BLU files */
  1135. -        /* do nothing */
  1136. -        break;
  1137. -    case 'z':    /* in view files */
  1138. -        /* do nothing */
  1139. -        break;
  1140. -    default:    /* unknown */
  1141. -        fprintf(stderr, "%s: unknown subopt '%c'\n", prgName, options[pt]);
  1142. -        break;  /* do nothing */
  1143. -    }
  1144. -    }  /* for */
  1145. -}
  1146. -
  1147. -
  1148. -#ifdef APW
  1149. -/*
  1150. - * Expand a ProDOS filename using APW wildcard calls (even if the file doesn't
  1151. - * exist).
  1152. - *
  1153. - * Returns a pointer to a buffer holding the filename.
  1154. - */
  1155. -char *ExpandFilename(filename)
  1156. -char *filename;
  1157. -{
  1158. -    char *ptr;
  1159. -
  1160. -    c2pstr(filename);
  1161. -    if (!(*filename)) {
  1162. -    printf("Internal error: can't expand null filename\n");
  1163. -    Quit (-1);
  1164. -    }
  1165. -
  1166. -    INIT_WILDCARD(filename, 0);
  1167. -    ToolErrChk();
  1168. -    p2cstr(filename);
  1169. -
  1170. -    NEXT_WILDCARD(tmpNameBuf);
  1171. -    p2cstr(tmpNameBuf);
  1172. -    if (strlen(tmpNameBuf))  /* found it */
  1173. -    return(tmpNameBuf);
  1174. -    else {
  1175. -    /* file does not exist; expand path */
  1176. -    strcpy(tmpNameBuf, filename);
  1177. -    ptr = RINDEX(tmpNameBuf, '/');    /* remove filename */
  1178. -    if (!ptr)  /* filename only */
  1179. -        return (filename);
  1180. -
  1181. -    *ptr = '\0';
  1182. -    if (!strlen(tmpNameBuf)) {  /* something weird... */
  1183. -        printf("Unable to expand '%s'\n", filename);
  1184. -        Quit (-1);
  1185. -    }
  1186. -
  1187. -    c2pstr(tmpNameBuf);
  1188. -    INIT_WILDCARD(tmpNameBuf, 0);
  1189. -    ToolErrChk();
  1190. -
  1191. -    NEXT_WILDCARD(tmpNameBuf);
  1192. -    p2cstr(tmpNameBuf);
  1193. -    if (!strlen(tmpNameBuf))  {
  1194. -        printf("Unable to fully expand '%s'\n", filename);
  1195. -        Quit (-1);
  1196. -    }
  1197. -
  1198. -    strcat(tmpNameBuf, RINDEX(filename, '/'));
  1199. -    return (tmpNameBuf);
  1200. -    }
  1201. -}
  1202. -#endif /* APW */
  1203. -
  1204. -
  1205. -/*
  1206. - * Parse args, call functions.
  1207. - */
  1208. -main(argc, argv)
  1209. -int argc;
  1210. -char **argv;
  1211. -{
  1212. -    char *filename;  /* hold expanded archive file name */
  1213. -    int idx;
  1214. -
  1215. -    filename = (char *) Malloc(MAXFILENAME);
  1216. -    CheckMach();  /* check compiler options, and set HiLo */
  1217. -
  1218. -    if (argc < 2) {  /* no arguments supplied */
  1219. -    Usage(argv[0]);
  1220. -    Quit (0);
  1221. -    }
  1222. -
  1223. -    if (argv[1][0] == '-') {  /* skip initial dashes */
  1224. -    argv[1]++;
  1225. -    }
  1226. -    for (idx = 0; argv[1][idx]; idx++)    /* conv opts to lower case */
  1227. -    if (isupper(argv[1][idx]))
  1228. -        argv[1][idx] = tolower(argv[1][idx]);
  1229. -
  1230. -    if (argc < 3) {  /* no archive file specified; show help screen */
  1231. -    if (argv[1][0] == 'h')  /* could be HS, HN, or HW */
  1232. -        Help(argv[0], argv[1]);
  1233. -    else            /* not 'H' option; show generic help scrn */
  1234. -        Help(argv[0], "h");
  1235. -    Quit (0);
  1236. -    }
  1237. -
  1238. -#ifdef APW
  1239. -    strcpy(filename, ExpandFilename(argv[2]));
  1240. -#else
  1241. -    strcpy(filename, argv[2]);
  1242. -#endif
  1243. -    GetDefaults(argv[1]);  /* get defaults, process suboption string */
  1244. -
  1245. -    pakbuf = (onebyt *) Malloc(PAKBUFSIZ);  /* allocate global pack buf */
  1246. -    switch (argv[1][0]) {
  1247. -    case 'a':  /* add */
  1248. -    case 'c':  /* create */
  1249. -    case 'm':  /* move */
  1250. -    NuAdd(filename, argc-3, argv+3, argv[1]);  /* NuAdd will read */
  1251. -    break;
  1252. -#ifndef NO_BLU
  1253. -    case 'b':  /* Binary II operations */
  1254. -    NuBNY(filename, argc-3, argv+3, argv[1]);
  1255. -    break;
  1256. -#endif
  1257. -    case 'd':  /* delete */
  1258. -    NuDelete(filename, argc-3, argv+3, argv[1]);
  1259. -    break;
  1260. -    case 'f':  /* freshen */
  1261. -    case 'u':  /* update */
  1262. -    NuUpdate(filename, argc-3, argv+3, argv[1]);
  1263. -    break;
  1264. -    case 'i':  /* verify integrity */
  1265. -    NuTest(filename, argv[1]);
  1266. -    break;
  1267. -    case 't':  /* table of contents */
  1268. -    case 'v':  /* verbose output */
  1269. -    NuView(filename, argv[1]);
  1270. -    break;
  1271. -    case 'e':  /* extract */
  1272. -    case 'x':
  1273. -    case 'p':
  1274. -    NuExtract(filename, argc-3, argv+3, argv[1]);
  1275. -    break;
  1276. -    default:   /* need help */
  1277. -    fprintf(stderr, "%s: unknown option '%c'\n", argv[0], argv[1][0]);
  1278. -    break;
  1279. -    }
  1280. -
  1281. -    free (filename);
  1282. -    free (pakbuf);
  1283. -    Quit (0);
  1284. -}
  1285. -
  1286. =nupak.c
  1287. -/*
  1288. - * nupak.c - interface to the compression routines
  1289. - *
  1290. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  1291. - * By Andy McFadden (fadden@cory.berkeley.edu)
  1292. - */
  1293. -#ifdef APW
  1294. -segment "Compress"
  1295. -#endif
  1296. -
  1297. -#include "nudefs.h"
  1298. -#include <stdio.h>
  1299. -/*#include <fcntl.h>*/    /* "nucomp.h" includes <fcntl.h> for us */
  1300. -#include "nuread.h"    /* need THblock */
  1301. -#include "nucomp.h"    /* includes "nucompfn.h" + "types.h" */
  1302. -
  1303. -#ifdef MSDOS  /* for file I/O */
  1304. -# include <io.h>
  1305. -# include <sys/types.h>
  1306. -# include <sys/stat.h>
  1307. -# include <errno.h>
  1308. -#endif
  1309. -
  1310. -#include "nupak.h"
  1311. -#include "nuetc.h"
  1312. -
  1313. -#define CONVSIZ    1024
  1314. -
  1315. -long packedSize;  /* global - size of file after packing */
  1316. -onebyt lastseen;  /* used in crlf(); must be set by caller */
  1317. -
  1318. -
  1319. -/*
  1320. - * Make a little spinning thing.
  1321. - *
  1322. - * This just lets the user know that the whole thing hasn't stalled on him.
  1323. - * Prints a character, then backspaces so that the next thing will overwrite
  1324. - * it.
  1325. - *
  1326. - * Currently called by FCopy(), unpak_SHK(), pak_SHK()
  1327. - */
  1328. -void Spin()
  1329. -{
  1330. -    static char *sp = "/-\\|";
  1331. -    static int posn = 0;
  1332. -
  1333. -    posn++;
  1334. -    if ((posn < 0) || (posn > 3))
  1335. -    posn = 0;
  1336. -    putchar(sp[posn]);
  1337. -    putchar('\b');
  1338. -    fflush(stdout);
  1339. -}
  1340. -
  1341. -
  1342. -/*
  1343. - * Convert the end-of-line terminator between systems.
  1344. - *
  1345. - * Compile-time defines determine the value that things are translated to;
  1346. - * the value of "translate" determines what they are translated from.  This
  1347. - * will write the contents of the buffer to the passed file descriptor,
  1348. - * altering bytes as necessary.  Max buffer size is 64K.  Note that the
  1349. - * syntax is the same as for write();
  1350. - *
  1351. - * This would have been a lot easier without IBM...  lastseen is the last
  1352. - * character seen (used only in CRLF translations).  This needs to be set
  1353. - * by the caller (FCopy(), extract_files()).
  1354. - *
  1355. - * The putc_ncr() procedure in nusq.c does its own processing; this was
  1356. - * somewhat unavoidable.
  1357. - *
  1358. - * BUGS: This proc will have to be re-written.  It would be nice to be
  1359. - * able to pack files with a CRLF translation, not just unpack... but you
  1360. - * can't just do buffer writes for that.  It'll take some work, and will
  1361. - * probably appear in the next version.
  1362. - */
  1363. -unsigned int crlf(dstfd, buffer, length)
  1364. -int dstfd;
  1365. -onebyt *buffer;
  1366. -unsigned int length;
  1367. -{
  1368. -    register BOOLEAN doconv;
  1369. -    register onebyt *bptr = buffer;
  1370. -    register unsigned int idx;
  1371. -    static char *procName = "crlf";
  1372. -    unsigned int partial;   /* size for partial read/write */
  1373. -    onebyt tobuf[2048];
  1374. -    onebyt *toptr;
  1375. -    int conv;
  1376. -    unsigned int origlength = length;
  1377. -
  1378. -    if ((transfrom == -1) && (transto == -1)) {  /* no translation necessary */
  1379. -    return (write(dstfd, buffer, length));
  1380. -    }
  1381. -    if (transfrom < -1 || transfrom > 2) {
  1382. -    fprintf(stderr, "%s: unknown translation type %d\n",
  1383. -                            prgName, transfrom);
  1384. -    fprintf(stderr, "%s: assuming conversion 0 (from CR)\n", prgName);
  1385. -    transfrom = 0;
  1386. -    }
  1387. -    if (transto < -1 || transto > 2) {
  1388. -    fprintf(stderr, "%s: unknown translation type %d\n",
  1389. -                            prgName, transto);
  1390. -    fprintf(stderr, "%s: assuming conversion 0 (to CR)\n", prgName);
  1391. -    transto = 0;
  1392. -    }
  1393. -
  1394. -    /* macro defs for system-dependent actions */
  1395. -#ifdef UNIX
  1396. -# define DEFCONVFROM    if (*bptr == 0x0a)  /* LF */ \
  1397. -                doconv = TRUE
  1398. -#  define DEFCONVTO    *(toptr++) = 0x0a
  1399. -#else
  1400. -# ifdef APW
  1401. -#  define DEFCONVFROM    if (*bptr == 0x0d)  /* CR */ \
  1402. -                doconv = TRUE
  1403. -#  define DEFCONVTO    *(toptr++) = 0x0d
  1404. -# endif
  1405. -# ifdef MSDOS
  1406. -#  define DEFCONVFROM    if ((*bptr == 0x0a) && (lastseen == 0x0d)) { \
  1407. -                doconv = TRUE; \
  1408. -                toptr--;  /*already put CR; back up over it*/ \
  1409. -            } \
  1410. -            lastseen = *bptr
  1411. -#  define DEFCONVTO    *(toptr++) = 0x0d; \
  1412. -            *(toptr++) = 0x0a
  1413. -# endif
  1414. -# ifndef APW
  1415. -# ifndef MSDOS
  1416. -#  define DEFCONVFROM    if (*bptr == 0x0a)  /* LF */ \
  1417. -                doconv = TRUE
  1418. -# endif /* none2 */
  1419. -# endif /* none1 */
  1420. -#endif /* UNIX */
  1421. -
  1422. -    while (length != 0) {
  1423. -    if (length > CONVSIZ) {
  1424. -        partial = CONVSIZ;
  1425. -        length -= CONVSIZ;
  1426. -    } else {
  1427. -        partial = length;
  1428. -        length = 0;
  1429. -    }
  1430. -
  1431. -    /* uses an explicit flag rather than "continue" for clarity... */
  1432. -    toptr = tobuf;
  1433. -    for (idx = partial; idx > 0; idx--, bptr++) {
  1434. -        doconv = FALSE;
  1435. -        switch (transfrom) {
  1436. -        case -1:  /* convert from current system's terminator */
  1437. -        DEFCONVFROM;
  1438. -        break;
  1439. -        case 0:
  1440. -        if (*bptr == 0x0d)  /* CR */
  1441. -            doconv = TRUE;
  1442. -        break;
  1443. -        case 1:
  1444. -        if (*bptr == 0x0a)  /* LF */
  1445. -            doconv = TRUE;
  1446. -        break;
  1447. -        case 2:
  1448. -        if ((*bptr == 0x0a) && (lastseen == 0x0d)) {
  1449. -            doconv = TRUE;
  1450. -            toptr--;  /*already outputed CR; back up over it*/
  1451. -        }
  1452. -        lastseen = *bptr;
  1453. -        break;
  1454. -        }
  1455. -
  1456. -
  1457. -        if (doconv) {
  1458. -        switch (transto) {
  1459. -        case -1:  /* convert to current system's terminator */
  1460. -            DEFCONVTO;
  1461. -            break;
  1462. -        case 0:
  1463. -            *(toptr++) = 0x0d;
  1464. -            break;
  1465. -        case 1:
  1466. -            *(toptr++) = 0x0a;
  1467. -            break;
  1468. -        case 2:
  1469. -            *(toptr++) = 0x0d;
  1470. -            *(toptr++) = 0x0a;
  1471. -            break;
  1472. -        }
  1473. -        } else {
  1474. -        *(toptr++) = *bptr;
  1475. -        }
  1476. -    } /* for loop */
  1477. -            
  1478. -    if (write(dstfd, tobuf, (toptr-tobuf)) != (toptr-tobuf))
  1479. -        Fatal("Dest write failed", procName);
  1480. -    }  /* while loop */
  1481. -    return (origlength);
  1482. -}
  1483. -
  1484. -
  1485. -/*
  1486. - * Read a file, and place in another file at current posn.  We can't read more
  1487. - * than PAKBUFSIZ at a time, so for some files it will have to be broken down
  1488. - * into pieces.  Note PAKBUFSIZ is expected to be an int (defined in nupak.h),
  1489. - * and can't be any larger than read() can handle (64K... unsigned 16-bit int).
  1490. - *
  1491. - * The transl option is present for NuUpdate and NuDelete, which have to
  1492. - * copy old records to a new archive w/o performing translation.
  1493. - */
  1494. -void FCopy(srcfd, dstfd, length, copybuf, transl)
  1495. -int srcfd;    /* source file descriptor (must be open & seek()ed) */
  1496. -int dstfd;    /* destination file descriptor (must be open & seek()ed) */
  1497. -fourbyt length; /* number of bytes to copy */
  1498. -onebyt *copybuf;
  1499. -BOOLEAN transl;  /* maybe do text translation? */
  1500. -{
  1501. -    unsigned int partial;   /* size for partial read/write */
  1502. -    static char *procName = "FCopy";
  1503. -
  1504. -    if (transl) lastseen = '\0';
  1505. -    while (length != 0L) {
  1506. -    if (length > (long) PAKBUFSIZ) {
  1507. -        partial = (unsigned int) PAKBUFSIZ;
  1508. -        length -= (long) PAKBUFSIZ;
  1509. -        if (verbose) Spin();
  1510. -    } else {
  1511. -        partial = (unsigned int) length;
  1512. -        length = 0L;
  1513. -    }
  1514. -
  1515. -    if (read(srcfd, copybuf, partial) != partial)
  1516. -        Fatal("Source read failed", procName);
  1517. -    if (transl) {  /* do text translation if user wants it */
  1518. -        if (crlf(dstfd, copybuf, partial) != partial)
  1519. -        Fatal("Dest write failed (c)", procName);
  1520. -    } else {  /* NEVER do translation */
  1521. -        if (write(dstfd, copybuf, partial) != partial)
  1522. -        Fatal("Dest write failed (w)", procName);
  1523. -    }
  1524. -    }
  1525. -}
  1526. -
  1527. -
  1528. -/*
  1529. - * Add a range of bytes from one file into another, packing them.
  1530. - *
  1531. - * Set up stuff, then call the appropriate pack routine.  Returns the actual
  1532. - * algorithm used (thread_format), since the compression algorithm could
  1533. - * fail, storing the file in uncompressed format instead.  The packed length
  1534. - * is stored in a global variable.
  1535. - *
  1536. - * Since we're only using version 0 records, we don't need to propagate the
  1537. - * thread_crc.
  1538. - *
  1539. - * Compression routines must do the following:
  1540. - * - compress data from one file descriptor to another, given two seeked
  1541. - *   file descriptors and a length value.  They may not rely on EOF conditions
  1542. - *   for either file.
  1543. - * - return the packing method actually used.  If they cope with failure
  1544. - *   by starting over with something different, the successful method should
  1545. - *   be returned.  Failure may be handled in the switch statement below.
  1546. - */
  1547. -twobyt PackFile(srcfd, dstfd, thread_eof, thread_format, buffer)
  1548. -int srcfd;    /* source file descriptor (must be open & seek()ed) */
  1549. -int dstfd;    /* destination file descriptor (must be open & seek()ed) */
  1550. -fourbyt thread_eof; /* size of input */
  1551. -int thread_format; /* how to pack the bytes */
  1552. -onebyt *buffer; /* alloc in main prog so we don't have to each time */
  1553. -{
  1554. -    long length = (long) thread_eof;
  1555. -    twobyt retval = thread_format;  /* default = successful pack */
  1556. -    long srcposn, dstposn;
  1557. -    static char *procName = "PackFile";
  1558. -
  1559. -    switch (thread_format) {
  1560. -    case 0x0000:  /* uncompressed */
  1561. -    if (verbose) { printf("storing...", thread_format);  fflush(stdout); }
  1562. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1563. -    packedSize = length;
  1564. -    break;
  1565. -
  1566. -    case 0x0001:  /* SQUeeze */
  1567. -    if (verbose) {
  1568. -        printf("[can't squeeze; storing]...");
  1569. -        fflush(stdout);
  1570. -    } else {
  1571. -        printf("WARNING: can't squeeze; files stored uncompressed\n");
  1572. -    }
  1573. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1574. -    packedSize = length;
  1575. -    retval = 0x0000;  /* uncompressed */
  1576. -    break;
  1577. -
  1578. -    case 0x0002:  /* LZW (ShrinkIt) */
  1579. -    if (verbose) { printf("shrinking...");  fflush(stdout); }
  1580. -    /* packedSize set by pak_SHK */
  1581. -    retval = pak_SHK(srcfd, dstfd, length, buffer);
  1582. -    break;
  1583. -    case 0x0003:  /* LZW II (ShrinkIt) */
  1584. -    if (verbose) {
  1585. -        printf("[can't do LZW II; storing]...");
  1586. -        fflush(stdout);
  1587. -    } else {
  1588. -        printf("WARNING: can't do LZW II; files stored uncompressed\n");
  1589. -    }
  1590. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1591. -    packedSize = length;
  1592. -    retval = 0x0000;  /* uncompressed */
  1593. -    break;
  1594. -    case 0x0004:  /* UNIX 12-bit compress */
  1595. -#ifdef NO_UCOMP
  1596. -    if (verbose) {
  1597. -        printf("[can't do 12-bit UNIX compress; storing]...");
  1598. -        fflush(stdout);
  1599. -    } else {
  1600. -        printf(
  1601. -        "WARNING: can't do 12-bit compress; files stored uncompressed\n");
  1602. -    }
  1603. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1604. -    packedSize = length;
  1605. -    retval = 0x0000;  /* uncompressed */
  1606. -#else
  1607. -    maxbits = 12;    /* global compress parameter */
  1608. -    if (verbose) { printf("compressing...");  fflush(stdout); }
  1609. -    /* packedSize set by compress() */
  1610. -    if (u_compress(srcfd, dstfd, length) == OK)
  1611. -        retval = 0x0004;
  1612. -    else
  1613. -        retval = 0x0004;    /* FIX this */
  1614. -#endif
  1615. -    break;
  1616. -
  1617. -    case 0x0005:  /* UNIX 16-bit compress */
  1618. -#ifdef NO_UCOMP
  1619. -    if (verbose) {
  1620. -        printf("[can't do 16-bit UNIX compress; storing]...");
  1621. -        fflush(stdout);
  1622. -    } else {
  1623. -        printf(
  1624. -        "WARNING: can't do 16-bit compress; files stored uncompressed\n");
  1625. -    }
  1626. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1627. -    packedSize = length;
  1628. -    retval = 0x0000;  /* uncompressed */
  1629. -#else
  1630. -    maxbits = 16;    /* global compress parameter */
  1631. -    if (verbose) { printf("compressing...");  fflush(stdout); }
  1632. -    /* packedSize set by compress() */
  1633. -    srcposn = lseek(srcfd, 0L, S_REL);    /* save posn */
  1634. -    dstposn = lseek(dstfd, 0L, S_REL);
  1635. -    if (u_compress(srcfd, dstfd, length) == OK) {
  1636. -        /* compress succeeded */
  1637. -        retval = 0x0005;
  1638. -    } else {
  1639. -        /* compression failed */
  1640. -        if (verbose) { printf("storing..."); fflush(stdout); }
  1641. -        lseek(srcfd, srcposn, S_ABS);    /* reposn files */
  1642. -        lseek(dstfd, dstposn, S_ABS);
  1643. -        FCopy(srcfd, dstfd, length, buffer, TRUE);
  1644. -        packedSize = length;
  1645. -        retval = 0x0000;
  1646. -    }
  1647. -#endif
  1648. -    break;
  1649. -
  1650. -    default:
  1651. -    fprintf(stderr, "\nUnknown compression method %d\n", thread_format);
  1652. -    fprintf(stderr, "Aborting.\n");
  1653. -    Quit(-1);
  1654. -    }
  1655. -
  1656. -    return (retval);
  1657. -}
  1658. -
  1659. -
  1660. -/*
  1661. - * Extract a range of bytes from one file into another, unpacking them.
  1662. - *
  1663. - * (hacked to unpack disks, also.  Forces the thread_eof to be the total
  1664. - *  size of the disk, since ShrinkIt doesn't really define it, esp for DOS 3.3
  1665. - *  disks).
  1666. - *
  1667. - * Set up stuff, then call the appropriate unpack routine.  Leaves the srcfd
  1668. - * positioned past the data to be unpacked; the calling routine should not
  1669. - * have to do any seeks.
  1670. - *
  1671. - * Returns TRUE if able to unpack, FALSE if not able to.  Note that srcfd
  1672. - * WILL be seeked even if the compression method is not handled.
  1673. - *
  1674. - * New uncompression routines should have the following characteristics:
  1675. - * - they should be able to uncompress a range of bytes from one file
  1676. - *   to another given two seeked file descriptors and a length parameter.
  1677. - * - they should return TRUE if they succeed and FALSE otherwise.  Special
  1678. - *   condition codes can be handled in the switch statement below.
  1679. - */
  1680. -int UnpackFile(srcfd, dstfd, THptr, thread_format, buffer)
  1681. -int srcfd;    /* source file descriptor (must be open & lseek()ed) */
  1682. -int dstfd;    /* destination file descriptor (must be open & lseek()ed) */
  1683. -THblock *THptr;    /* pointer to thread structure */
  1684. -int thread_format; /* how to unpack the bytes (NOT THptr->thread_format) */
  1685. -onebyt *buffer;
  1686. -{
  1687. -    long length;
  1688. -    fourbyt thread_eof,        /* #of bytes to output */
  1689. -        comp_thread_eof;    /* #of bytes in source */
  1690. -    twobyt thread_crc;
  1691. -    BOOLEAN retval = TRUE;  /* default to success */
  1692. -    static char *procName = "UnpackFile";
  1693. -
  1694. -    thread_eof = THptr->thread_eof;
  1695. -    comp_thread_eof = THptr->comp_thread_eof;
  1696. -    thread_crc = THptr->thread_crc;    /* never used? */
  1697. -    length = (long) comp_thread_eof;    /* type checking goes easier */
  1698. -
  1699. -    switch (thread_format) {
  1700. -    case 0x0000:  /* uncompressed */
  1701. -    if (verbose) { printf("extracting...", thread_format); fflush(stdout);}
  1702. -    FCopy(srcfd, dstfd, length, buffer, TRUE);
  1703. -    break;
  1704. -
  1705. -    case 0x0001:  /* unSQUeeze */
  1706. -#ifdef NO_BLU
  1707. -    if (verbose) {
  1708. -        printf("[can't unsqueeze - aborting]...");
  1709. -        fflush(stdout);
  1710. -    } else {
  1711. -        printf("ERROR: can't unsqueeze; 'squ' files not extracted\n");
  1712. -    }
  1713. -    lseek(srcfd, length, S_REL);  /* set file posn */
  1714. -    retval = FALSE;
  1715. -#else
  1716. -    if (verbose) { printf("unsqueezing..."); fflush(stdout); }
  1717. -    unpak_SQU(srcfd, dstfd, length);  /* thread_eof not needed */
  1718. -#endif
  1719. -    break;
  1720. -
  1721. -    case 0x0002:  /* LZW (ShrinkIt) */
  1722. -    if (verbose) { printf("unshrinking (I)..."); fflush(stdout); }
  1723. -    unpak_SHK(srcfd, dstfd, comp_thread_eof, thread_eof, buffer, FALSE);
  1724. -    break;
  1725. -
  1726. -    case 0x0003:  /* LZW II (ShrinkIt) */
  1727. -#ifdef TRY_II
  1728. -    if (verbose) { printf("unshrinking (II)..."); fflush(stdout); }
  1729. -    unpak_SHK(srcfd, dstfd, comp_thread_eof, thread_eof, buffer, TRUE);
  1730. -#else
  1731. -    if (verbose) {
  1732. -        printf("[can't unshrink type II - aborting]...");
  1733. -        fflush(stdout);
  1734. -    } else {
  1735. -        printf(
  1736. -        "ERROR: can't unshrink type II; 'sh2' files not extracted\n");
  1737. -    }
  1738. -    lseek(srcfd, length, S_REL);  /* set file posn */
  1739. -    retval = FALSE;
  1740. -#endif
  1741. -    break;
  1742. -
  1743. -    case 0x0004:  /* 12-bit UNIX compress */
  1744. -#ifdef NO_UCOMP
  1745. -    if (verbose) {
  1746. -        printf("[can't undo 12-bit UNIX compress - aborting]...");
  1747. -        fflush(stdout);
  1748. -    } else {
  1749. -        printf(
  1750. -    "ERROR: can't undo 12-bit UNIX compress; 'u12' files not extracted\n");
  1751. -    }
  1752. -    lseek(srcfd, length, S_REL);  /* set file posn */
  1753. -    retval = FALSE;
  1754. -#else
  1755. -    if (verbose) { printf("uncompressing..."); fflush(stdout); }
  1756. -    if (u_decompress(srcfd, dstfd, (long) comp_thread_eof) != OK)
  1757. -        retval = FALSE;
  1758. -#endif
  1759. -    break;
  1760. -
  1761. -    case 0x0005:  /* 16-bit UNIX compress */
  1762. -#ifdef NO_UCOMP
  1763. -    if (verbose) {
  1764. -        printf("[can't undo 16-bit UNIX compress - aborting]...");
  1765. -        fflush(stdout);
  1766. -    } else {
  1767. -        printf(
  1768. -    "ERROR: can't undo 16-bit UNIX compress; 'u16' files not extracted\n");
  1769. -    }
  1770. -    lseek(srcfd, length, S_REL);  /* set file posn */
  1771. -    retval = FALSE;
  1772. -#else
  1773. -    if (verbose) { printf("uncompressing..."); fflush(stdout); }
  1774. -    if (u_decompress(srcfd, dstfd, (long) comp_thread_eof) != OK)
  1775. -        retval = FALSE;
  1776. -#endif
  1777. -    break;
  1778. -
  1779. -    default:
  1780. -    fprintf(stderr, "Unknown uncompression method %d\n", thread_format);
  1781. -    lseek(srcfd, length, S_REL);  /* set file posn */
  1782. -    retval = FALSE;
  1783. -    break;
  1784. -    }
  1785. -
  1786. -    return (retval);
  1787. -}
  1788. -
  1789. + END OF ARCHIVE
  1790.