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

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC037:  Nulib - Archive Library Tools (Unix) 06/10
  4. Message-ID: <May.1.18.12.37.1991.23513@yoko.rutgers.edu>
  5. Date: 1 May 91 22:12:38 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Andy McFadden (fadden@cory.berkeley.edu)
  10. Posting-number: Volume 1, Source:37
  11. Archive-name: archive/unix/nulib/part06.10
  12. Architecture: UNIX
  13. Version-number: 3.03
  14.  
  15.  
  16. =nupdel.c
  17. -/*
  18. - * nudel.c - operations which delete from a NuFX archive
  19. - * nuupd.c - update/freshen a NuFX archive
  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. -#ifdef BSD43
  32. -# include <strings.h>
  33. -#else  /* SYSV, APW, MSC */
  34. -# include <string.h>
  35. -#endif
  36. -
  37. -#ifdef UNIX
  38. -# include <errno.h>
  39. -#endif
  40. -#ifdef APW
  41. -# include <types.h>
  42. -# include <prodos.h> /* ? */
  43. -# include <shell.h>
  44. -# include <strings.h>  /* APW string ops */
  45. -#endif
  46. -#ifdef MSDOS
  47. -# include <io.h>
  48. -# include <sys/types.h>
  49. -# include <sys/stat.h>
  50. -# include <errno.h>
  51. -#endif
  52. -
  53. -#include "nuread.h"
  54. -#include "nuadd.h"  /* AddFile(), etc. */
  55. -#include "nupak.h"  /* uses PAKBUFSIZ */
  56. -#include "nupdel.h"
  57. -#include "nuetc.h"
  58. -
  59. -static BOOLEAN dofreshen;  /* do freshen instead of update? */
  60. -
  61. -/* delete routines */
  62. -
  63. -/*
  64. - * Rebuild an archive, excluding files marked as deleted.
  65. - * Does not use absolute position values; just seeks along.  The archive
  66. - * should be seeked just beyond the master header block.
  67. - */
  68. -static void RebuildArchive(arcfd, archive, tmpname, remaining)
  69. -int arcfd;
  70. -ListHdr *archive;
  71. -char *tmpname;
  72. -long remaining;
  73. -{
  74. -    int dstfd;    /* destination filename */
  75. -    onebyt *mptr;
  76. -    RNode *RNodePtr;
  77. -    TNode *TNodePtr;
  78. -    int rec, thread;
  79. -    long size;
  80. -    long master_eof;
  81. -#ifdef APW
  82. -    FileRec create_p;
  83. -#endif
  84. -    static char *procName = "RebuildArchive";
  85. -
  86. -    if (verbose) { printf("Building new archive file...");  fflush(stdout); }
  87. -
  88. -    ArcfiCreate(tmpname);    /* create file */
  89. -    master_eof = (long) MHsize;
  90. -
  91. -    if ((dstfd = open(tmpname, O_WRONLY | O_TRUNC | O_BINARY, WPERMS)) < 0)
  92. -    Fatal("Unable to open dest file", procName);
  93. -    if (lseek(dstfd, (long) MHsize, S_ABS) < 0)
  94. -    Fatal("Unable to lseek past dest mhblock", procName);
  95. -
  96. -    RNodePtr = archive->RNodePtr;
  97. -
  98. -    /* copy the surviving records to the destination file */
  99. -    for (rec = 0; rec < archive->MHptr->total_records; rec++) {
  100. -#ifdef APW
  101. -    if (STOP()) { printf("aborting.\n"); Quit(1); }
  102. -#endif
  103. -    size = (long) RNodePtr->RHptr->attrib_count;
  104. -    size += (long) RNodePtr->filename_length;
  105. -    TNodePtr = RNodePtr->TNodePtr;
  106. -    for (thread=0; thread < (int)RNodePtr->RHptr->total_threads; thread++){
  107. -        if (TNodePtr == (TNode *) NULL) {
  108. -        fprintf(stderr, "Internal error: Bad thread structure\n");
  109. -        Quit(-1);
  110. -        }
  111. -        size += (long) THsize;
  112. -        size += TNodePtr->THptr->comp_thread_eof;
  113. -        TNodePtr = TNodePtr->TNext;
  114. -    }
  115. -
  116. -    if (!RNodePtr->filename[0]) {
  117. -        if (lseek(arcfd, size, S_REL) < 0)
  118. -        Fatal("Unable to seek past deleted record", procName);
  119. -    } else {
  120. -        FCopy(arcfd, dstfd, size, pakbuf, FALSE);
  121. -        master_eof += size;
  122. -    }
  123. -
  124. -    RNodePtr = RNodePtr->RNext;  /* move on to next record */
  125. -    }
  126. -
  127. -    mptr = MakeMHblock(archive, remaining, master_eof);  /* build mheader */
  128. -    if (lseek(dstfd, 0L, S_ABS) < 0)
  129. -    Fatal("Unable to seek back in dest file", procName);
  130. -    if (write(dstfd, mptr, MHsize) < MHsize)
  131. -    Fatal("Unable to write master header", procName);
  132. -
  133. -    if (close(dstfd) < 0)
  134. -    Fatal("Unable to close archive", procName);
  135. -    if (verbose) printf("done.\n");
  136. -}
  137. -
  138. -
  139. -/*
  140. - * Delete files from archive
  141. - *
  142. - * Scan archive, deleting files which match the strings in "names".
  143. - */
  144. -static void Delete(filename, namecount, names)
  145. -char *filename;
  146. -int namecount;
  147. -char **names;
  148. -{
  149. -    ListHdr *archive;
  150. -    int arcfd;    /* archive file descriptor */
  151. -    int rec, idx;
  152. -    MHblock *MHptr;   /* Master Header block */
  153. -    RNode *RNodePtr;  /* Record Node */
  154. -    int len, *lentab;  /* hold strlen() of all names */
  155. -    char *pn;  /* archived pathname */
  156. -    long remaining;
  157. -    char *tmpname = (char *) Malloc(MAXFILENAME);
  158. -    static char *procName = "Delete";
  159. -
  160. -    archive = NuRead(filename);
  161. -    if ((arcfd = open(archive->arc_name, O_RDONLY | O_BINARY)) < 0)
  162. -    Fatal("Unable to open archive", procName);
  163. -
  164. -    lentab = (int *) Malloc( sizeof(int) * namecount ); /* calloc() is nicer */
  165. -    for (idx = 0; idx < namecount; idx++)  /* calc. once (for efficiency) */
  166. -    lentab[idx] = strlen(names[idx]);
  167. -
  168. -    MHptr = archive->MHptr;
  169. -    RNodePtr = archive->RNodePtr;
  170. -    remaining = MHptr->total_records;
  171. -
  172. -    /* main record read loop */
  173. -    for (rec = 0; rec < MHptr->total_records; rec++) {
  174. -
  175. -    pn = RNodePtr->filename;
  176. -    len = strlen(pn);
  177. -    if (RNodePtr->RHptr->version_number > MAXVERS)
  178. -        printf("WARNING: '%s' has unknown record version_number\n", pn);
  179. -
  180. -    for (idx = 0; idx < namecount; idx++) {  /* find file in archive */
  181. -        /* try to match argument with first few chars of stored filename */
  182. -        /* or the entire filename, depending on EXPAND flag */
  183. -        if ((len >= lentab[idx]) && doExpand ?
  184. -            (!strncasecmp(pn, names[idx], lentab[idx])) :
  185. -            (!strcasecmp(pn, names[idx])) ) {
  186. -
  187. -        if (verbose) printf("Marking '%s' as deleted.\n", pn);
  188. -        RNodePtr->filename[0] = '\0';  /* mark as deleted */
  189. -        remaining--;
  190. -        break;    /* out of filename matching for-loop */
  191. -        }
  192. -    }
  193. -
  194. -    RNodePtr = RNodePtr->RNext;  /* move on to next record */
  195. -    }
  196. -
  197. -    if (remaining == MHptr->total_records) {
  198. -    if (verbose) printf("No files selected; archive not modified\n");
  199. -    if (close(arcfd) < 0)
  200. -        Fatal("Source (archive) close failed", procName);
  201. -    Quit (0);
  202. -    }
  203. -    if (remaining == 0L) {
  204. -    printf("All files in archive marked for deletion...");    fflush(stdout);
  205. -    if (close(arcfd) < 0)
  206. -        Fatal("Source (archive) close failed", procName);
  207. -#ifdef APW
  208. -    if (STOP()) { printf("aborting.\n"); Quit (1); }
  209. -#endif
  210. -    printf(" deleteing archive file.\n");
  211. -
  212. -    if (unlink(archive->arc_name) < 0)
  213. -        Fatal("Unable to delete archive", procName);
  214. -    } else {
  215. -    tmpname = MakeTemp(tmpname);
  216. -#ifdef APW
  217. -    if (STOP()) { printf("aborting.\n"); Quit (1); }
  218. -#endif
  219. -    if (lseek(arcfd, (long) MHsize, S_ABS) < 0)
  220. -        Fatal("Unable to seek past master block", procName);
  221. -    RebuildArchive(arcfd, archive, tmpname, remaining);
  222. -
  223. -    if (close(arcfd) < 0)
  224. -        Fatal("Source (archive) close failed", procName);
  225. -    if (verbose) {
  226. -        printf("Deleteing old archive file...");
  227. -        fflush(stdout);
  228. -    }
  229. -    if (unlink(archive->arc_name) < 0)
  230. -        Fatal("Unable to delete original archive", procName);
  231. -    Rename(tmpname, archive->arc_name);
  232. -    if (verbose) printf("done.\n");
  233. -
  234. -    }
  235. -    free (tmpname);
  236. -    free (lentab);
  237. -}
  238. -
  239. -
  240. -/*
  241. - * Entry point for deleteing files from archive.
  242. - */
  243. -void NuDelete(filename, namecount, names, options)
  244. -char *filename;
  245. -int namecount;
  246. -char **names;
  247. -char *options;
  248. -{
  249. -    static char *procName = "NuDelete";
  250. -
  251. -    /* presently does nothing */
  252. -
  253. -    Delete(filename, namecount, names);
  254. -}
  255. -
  256. -
  257. -/**********  update routines  **********/
  258. -
  259. -/*
  260. - * Updates the archive.
  261. - *
  262. - * Evaluate the command line arguments and compare them with the files in
  263. - * the archive.  Put the most recent copy of the file in a new archive file.
  264. - * Essentially a combination of add and delete.
  265. - *
  266. - * This procedure is huge.  Someday I may clean this up a bit...
  267. - */
  268. -static void Update(archive, namecount, names)
  269. -ListHdr *archive;
  270. -int namecount;
  271. -char **names;
  272. -{
  273. -    int arcfd, dstfd;  /* archive file descriptor */
  274. -    static file_info *FIArray[MAXARGS];  /* entries malloc()ed by EvalArgs */
  275. -    unsigned int rec;
  276. -    int idx, thread;
  277. -    MHblock *MHptr;   /* Master Header block */
  278. -    RNode *RNodePtr;  /* Record Node */
  279. -    TNode *TNodePtr;   /* Thread block */
  280. -    char *pn;  /* archived pathname */
  281. -    BOOLEAN keeparc, gotone;
  282. -    char *tmpname = (char *) Malloc(MAXFILENAME);
  283. -    Time *atptr, *ftptr;
  284. -    long a_dt, f_dt;
  285. -    long size;
  286. -    fourbyt totalrecs, master_eof;
  287. -    onebyt *mptr;
  288. -    twobyt *twoptr;
  289. -    static char *procName = "Update";
  290. -
  291. -    if ((arcfd = open(archive->arc_name, O_RDONLY | O_BINARY)) < 0)
  292. -    Fatal("Unable to open archive", procName);
  293. -
  294. -    /* expand wildcards/subdirectories, and get info */
  295. -    namecount = EvalArgs(namecount, names, FIArray, TRUE);
  296. -    if (!namecount) {
  297. -    if (verbose) printf("No files selected; archive not modified.\n");
  298. -    Quit (0);
  299. -    }
  300. -
  301. -    /*
  302. -     * For each file in the archive, check for an *exact* match with the
  303. -     * store_names in FIArray (case independent).  If a match is found,
  304. -     * compare the dates, and copy/add the most recent file.  If no match
  305. -     * is found, copy the file.  After all archived files have been processed,
  306. -     * add all remaining files specified on the command line (unless the
  307. -     * F)reshen option is used, in which case this exits).
  308. -     */
  309. -
  310. -    MHptr = archive->MHptr;
  311. -    RNodePtr = archive->RNodePtr;
  312. -    gotone = FALSE;
  313. -
  314. -    /* mark files that will be replaced */
  315. -    for (rec = 0; rec < MHptr->total_records; rec++) {
  316. -#ifdef APW
  317. -    if (STOP()) { printf("aborting.\n"); Quit (1); }
  318. -#endif
  319. -    pn = RNodePtr->filename;
  320. -    if (RNodePtr->RHptr->version_number > MAXVERS)
  321. -        printf("WARNING: '%s' has unknown record version_number\n", pn);
  322. -
  323. -    for (idx = 0; idx < namecount; idx++) {  /* find file in archive */
  324. -        /* try to match argument with first few chars of stored filename */
  325. -        if (!strcasecmp(pn, FIArray[idx]->store_name)) {
  326. -        atptr = &RNodePtr->RHptr->mod_when;
  327. -        ftptr = &FIArray[idx]->mod_dt;
  328. -
  329. -        /* compare month/year [ I think it's best-case faster... ] */
  330. -        a_dt = (atptr->year * 12) + atptr->month;
  331. -        f_dt = (ftptr->year * 12) + ftptr->month;
  332. -        if (a_dt > f_dt)    /* archive is more recent? */
  333. -            keeparc = TRUE;
  334. -        else if (a_dt < f_dt)    /* file is more recent? */
  335. -            keeparc = FALSE;
  336. -        else {    /* year & month match, check rest */
  337. -            a_dt = (atptr->day * 86400L) + (atptr->hour * 3600) +
  338. -               (atptr->minute * 60) + (atptr->second);
  339. -            f_dt = (ftptr->day * 86400L) + (ftptr->hour * 3600) +
  340. -               (ftptr->minute * 60) + (ftptr->second);
  341. -            if (a_dt < f_dt)
  342. -            keeparc = FALSE;
  343. -            else  /* (a_dt >= f_dt) */
  344. -            keeparc = TRUE;
  345. -        }
  346. -
  347. -        if (!keeparc) {  /* not keeping; mark as being replaced */
  348. -#ifndef APW  /* APW uses actual filetype; other systems keep old */
  349. -            FIArray[idx]->fileType = RNodePtr->RHptr->file_type;
  350. -            FIArray[idx]->auxType = RNodePtr->RHptr->extra_type;
  351. -#endif
  352. -            RNodePtr->RHptr->version_number = 65535; /*can't do fname*/
  353. -            twoptr = (twobyt *) RNodePtr->filename;
  354. -            *twoptr = idx;  /* null filename -> problems */
  355. -            gotone = TRUE;
  356. -        }
  357. -        FIArray[idx]->marked = TRUE;  /* MARK as processed */
  358. -        }
  359. -    }
  360. -
  361. -    RNodePtr = RNodePtr->RNext;  /* move on to next record */
  362. -    }
  363. -
  364. -    totalrecs = MHptr->total_records;  /* none will be deleted */
  365. -    if (!dofreshen) {  /* add new files? */
  366. -    for (idx = 0; idx < namecount; idx++) {  /* handle unmatched args */
  367. -        if (!FIArray[idx]->marked) {
  368. -        gotone = TRUE;
  369. -        totalrecs++;  /* count new ones too */
  370. -        }
  371. -    }
  372. -    }
  373. -    if (!gotone) {
  374. -    if (verbose) printf("No files need updating; archive not modified\n");
  375. -    if (close(arcfd) < 0)
  376. -        Fatal("Source (archive) close failed", procName);
  377. -    Quit (0);
  378. -    }
  379. -
  380. -    /*
  381. -     * Rebuild archive file
  382. -     */
  383. -    if (verbose) printf("Building new archive file...\n");
  384. -    tmpname = MakeTemp(tmpname);
  385. -    ArcfiCreate(tmpname);
  386. -
  387. -    master_eof = (long) MHsize;
  388. -
  389. -    if (lseek(arcfd, (long) MHsize, S_ABS) < 0)
  390. -    Fatal("Bad archive seek", procName);
  391. -
  392. -    if ((dstfd = open(tmpname, O_RDWR | O_TRUNC | O_BINARY)) < 0)
  393. -    Fatal("Unable to open dest file", procName);
  394. -    if (lseek(dstfd, (long) MHsize, S_ABS) < 0)
  395. -    Fatal("Bad dest seek", procName);    /* leave space for later */
  396. -
  397. -    RNodePtr = archive->RNodePtr;
  398. -    for (rec = 0; rec < MHptr->total_records; rec++) {
  399. -    size = (long) RNodePtr->RHptr->attrib_count;
  400. -    size += (long) RNodePtr->filename_length;
  401. -    TNodePtr = RNodePtr->TNodePtr;
  402. -    for (thread=0; thread < (int)RNodePtr->RHptr->total_threads; thread++){
  403. -        if (TNodePtr == (TNode *) NULL) {
  404. -        fprintf(stderr, "Internal error: Bad thread structure\n");
  405. -        Quit (-1);
  406. -        }
  407. -        size += (long) THsize;
  408. -        size += TNodePtr->THptr->comp_thread_eof;
  409. -        TNodePtr = TNodePtr->TNext;
  410. -    }
  411. -    /* we now know the size; either copy the old or replace with new */
  412. -    if (RNodePtr->RHptr->version_number != 65535) { /* file not replaced */
  413. -/*        if (verbose) {
  414. - *        printf("Copying '%s'...", RNodePtr->filename);
  415. - *        fflush(stdout);
  416. - *        }
  417. - */
  418. -        FCopy(arcfd, dstfd, size, pakbuf, FALSE);
  419. -        master_eof += (fourbyt) size;
  420. -/*        if (verbose) printf("done.\n");
  421. - */
  422. -    } else {  /* file replaced; skip orig and add new */
  423. -        if (lseek(arcfd, size, S_REL) < 0)
  424. -        Fatal("Bad skip seek", procName);
  425. -        twoptr = (twobyt *) RNodePtr->filename;
  426. -        idx = *twoptr;
  427. -        if (verbose) printf("Replacing/");  /* +"Adding 'filename'..." */
  428. -        master_eof += AddFile(dstfd, FIArray[idx]);
  429. -    }
  430. -
  431. -    RNodePtr = RNodePtr->RNext;  /* move on to next record */
  432. -    }
  433. -
  434. -    if (!dofreshen) {
  435. -    for (idx = 0 ; idx < namecount; idx++) {
  436. -#ifdef APW
  437. -        if (STOP()) Quit(1);  /* check for OA-. */
  438. -#endif
  439. -        if (!FIArray[idx]->marked) {
  440. -        master_eof += AddFile(dstfd, FIArray[idx]);
  441. -        }
  442. -    }
  443. -    }
  444. -
  445. -    /* build master header */
  446. -    mptr = MakeMHblock(archive, totalrecs, master_eof);
  447. -    if (lseek(dstfd, 0L, S_ABS) < 0)
  448. -    Fatal("Bad lseek for master header", procName);
  449. -    if (write(dstfd, mptr, MHsize) < MHsize)
  450. -    Fatal("Unable to write master header", procName);
  451. -
  452. -    if (close(arcfd) < 0)
  453. -    Fatal("Source (old archive) close failed", procName);
  454. -    if (close(dstfd) < 0)
  455. -    Fatal("Destination (new archive) close failed", procName);
  456. -
  457. -    if (verbose) { printf("Deleteing old archive file...");  fflush(stdout); }
  458. -    if (unlink(archive->arc_name) < 0)
  459. -    Fatal("Unable to delete original archive", procName);
  460. -    Rename(tmpname, archive->arc_name);
  461. -    if (verbose) printf("done.\n");
  462. -
  463. -    free (tmpname);
  464. -}
  465. -
  466. -
  467. -/*
  468. - * Update files in archive
  469. - *
  470. - * This part just evaluates the options, sets parms, and calls Update().
  471. - */
  472. -void NuUpdate(filename, namecount, names, options)
  473. -char *filename;
  474. -int namecount;
  475. -char **names;
  476. -char *options;
  477. -{
  478. -    ListHdr *archive;
  479. -    static char *procName = "NuUpdate";
  480. -
  481. -    if (*options == 'f') dofreshen = TRUE;
  482. -    else dofreshen = FALSE;
  483. -
  484. -    /* change T subopt to convert FROM current system TO <subopt> */
  485. -    if (transfrom >= 0) {
  486. -    transto = transfrom;
  487. -    transfrom = -1;
  488. -    }
  489. -
  490. -    archive = NuRead(filename);
  491. -    Update(archive, namecount, names);
  492. -}
  493. -
  494. =nublu.c
  495. -/*
  496. - * nublu.c - operations on Binary II archives
  497. - *
  498. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  499. - * By Andy McFadden (fadden@cory.berkeley.edu)
  500. - */
  501. -#ifdef APW
  502. -segment "Compress"
  503. -#endif
  504. -
  505. -#ifndef NO_BLU                       /***********************************/
  506. -
  507. -#include "nudefs.h"
  508. -#include <stdio.h>
  509. -#include <fcntl.h>
  510. -
  511. -#ifdef UNIX
  512. -# include <errno.h>
  513. -# include <sys/types.h>
  514. -# include <sys/stat.h>
  515. -#endif
  516. -#ifdef APW
  517. -# include <prodos.h>
  518. -#endif
  519. -#ifdef MSDOS
  520. -# include <stdlib.h>
  521. -# include <io.h>
  522. -# include <string.h>
  523. -# include <sys/types.h>
  524. -# include <sys/stat.h>
  525. -#endif
  526. -
  527. -#include "nuview.h"  /* file types for BLU */
  528. -#include "nuadd.h"   /* need OptNum() */
  529. -#include "nupak.h"   /* need unpak_SQU */
  530. -#include "nuetc.h"
  531. -
  532. -/* Binary II extraction routines are adapted from:            */
  533. -/*************************************************************************
  534. - **                                    **
  535. - **  Name    :    unblu                            **
  536. - **  Author  :    Marcel J.E. Mol                     **
  537. - **  Date    :    10/05/88          (first release)            **
  538. - **  Version :    2.20                            **
  539. - **  Files   :    unblu.c     Main source file            **
  540. - **                                    **
  541. - **  ------------------------- Revision List -------------------------    **
  542. - **  Ver   Date       Name             Remarks            **
  543. - **  1.00  10/05/88   Marcel Mol         Raw copy of a basic program**
  544. - **  2.00  03/06/88   Marcel Mol         Rewrite after blu info    **
  545. - **                         was send to the net    **
  546. - **  2.10  18/06/88   Marcel Mol         Added filetype texts    **
  547. - **  2.20  23/09/88   Marcel Mol         Show mod and creation time **
  548. - **                                    **
  549. - ************************************************************************/
  550. -
  551. -
  552. -/*char * copyright = "@(#) unblu.c  2.1 18/06/88  (c) M.J.E. Mol";*/
  553. -#define BUFSIZE 128            /* Blu block length */
  554. -
  555. -/* global variables */
  556. -static char *progname;
  557. -static char *blufile;
  558. -static BOOLEAN extract = FALSE;  /* extract (as opposed to just listing) */
  559. -
  560. -
  561. -/*
  562. - * extract_file -- extract file fname from the archive fd. Fname
  563. - *           contains filelen bytes.
  564. - *
  565. - * If the first block has the .QQ magic numbers, go ahead and try to
  566. - * unsqueeze it.  Not the best way to go about it, but it works.
  567. - */
  568. -static void extract_file(fd, fname, filelen)
  569. -int fd;
  570. -char *fname;  /* 64 bytes */
  571. -long filelen;
  572. -{
  573. -    int ofd;
  574. -    int n, i;
  575. -    int j, len;
  576. -    onebyt buf[BUFSIZE];
  577. -    long full_len;
  578. -    int offset;
  579. -    static char *procName = "extract_file";
  580. -
  581. -    /*n = */ read(fd, buf, 70);  /* read first few bytes */
  582. -    lseek(fd, -70L, S_REL);  /* back up */
  583. -    if ((buf[0] == 0x76) && (buf[1] == 0xff)) {  /* is it squeezed? */
  584. -    i = 0;                /* get the original file name */
  585. -    while ((fname[i] = buf[4+i]) != '\0')
  586. -        i++;
  587. -    offset = 5+i;  /* how far into file is end of filename? */
  588. -    if (verbose) { printf("(as %s)...", fname);  fflush(stdout); }
  589. -    }
  590. -
  591. -    len = strlen(fname);
  592. -    for (j = 0; j < len; j++)
  593. -    fname[j] &= 0x7f;    /* clear hi bits */
  594. -
  595. -    if (Exists(fname)) {
  596. -    if (interact) {
  597. -        if (verbose) printf("file exists, overwite");
  598. -        else         printf("%s exists, overwite", fname);
  599. -        if (!AskYesNo()) {  /* return w/o overwriting */
  600. -        full_len = ( (filelen / 128L) +1 ) * 128L;
  601. -        lseek(fd, full_len, S_REL);
  602. -        return;
  603. -        }
  604. -    }
  605. -    if (verbose) { printf("overwriting..."); fflush(stdout); }
  606. -    if (unlink(fname) < 0)
  607. -        Fatal("Unable to remove existing file", procName);
  608. -    }
  609. -
  610. -    if ((ofd = open(fname, O_BINARY|O_CREAT|O_WRONLY|O_TRUNC, 0644)) < 0) {
  611. -    Fatal("Can't open destination file", "extract_file");
  612. -    }
  613. -
  614. -    if ((buf[0] == 0x76) && (buf[1] == 0xff)) {  /* is it squeezed? */
  615. -    if (verbose) { printf("unsqueezing...");  fflush(stdout); }
  616. -    full_len = ( (filelen / 128L) +1 ) * 128L;
  617. -    lseek(fd, (long) offset, S_REL);
  618. -    full_len -= offset;  /* send unpak_SQU everything past fname */
  619. -
  620. -    unpak_SQU(fd, ofd, full_len);  /* unsqueeze it */
  621. -
  622. -    } else {  /* extract uncompressed */
  623. -
  624. -    lastseen = '\0';  /* used by crlf() translator */
  625. -    while (filelen > 0L) {
  626. -        n = read(fd, buf, BUFSIZE);        /* Read 128 bytes */
  627. -        if (n != BUFSIZE) {
  628. -        fprintf(stderr, "Extract_BNY: %s file size broken\n", blufile);
  629. -        Quit(-1);
  630. -        }
  631. -        if (crlf(ofd, buf, (filelen >= BUFSIZE ? BUFSIZE : filelen)) !=
  632. -            (filelen >= BUFSIZE ? BUFSIZE : filelen))
  633. -        Fatal("Bad write", procName);
  634. -    
  635. -        filelen -= (long) BUFSIZE;
  636. -    }
  637. -    }
  638. -    close(ofd);                  /* Close destination file */
  639. -}
  640. -
  641. -
  642. -/*
  643. - * print_header -- print global information of the binary II file
  644. - */
  645. -static void print_header(buf)
  646. -onebyt *buf;
  647. -{
  648. -    long disk_blocks;
  649. -
  650. -    disk_blocks = buf[117] + (buf[118]<<8) + (buf[119]<<16) + (buf[120]<<24);
  651. -    printf("Listing %-40.40s  ", blufile);
  652. -    printf("Blocks used: %-5ld", disk_blocks);
  653. -    printf("Files: %d\n", buf[127]+1);
  654. -    printf("\nFilename       Type Blocks   Modified        ");
  655. -    printf("Created           Length  Subtype\n\n");
  656. -}
  657. -
  658. -
  659. -/*
  660. - * want -- return TRUE if name exists in array wantlist,
  661. - *       else return FALSE
  662. - */
  663. -static BOOLEAN want(name, wantlist)
  664. -char *name;
  665. -char **wantlist;
  666. -{
  667. -    while (*wantlist != NULL) {
  668. -    if (strcasecmp(name, *wantlist++) == NULL)
  669. -        return (TRUE);
  670. -    }
  671. -    return (FALSE);
  672. -
  673. -}
  674. -
  675. -
  676. -/*
  677. - * process_file -- retrieve or print file information of file given
  678. - *           in buf
  679. - */
  680. -static void process_file(fd, buf, count, wanted)
  681. -int  fd;
  682. -onebyt *buf;
  683. -int count;
  684. -char **wanted;
  685. -{
  686. -    int ftype, auxtype;
  687. -    int fnamelen;
  688. -    long filelen;
  689. -    char fname[64];
  690. -    char outbuf[16];  /* temp for sprintf */
  691. -    int nblocks, problocks;
  692. -    Time create_dt;
  693. -    Time mod_dt;
  694. -#ifdef APW
  695. -    FileRec frec;
  696. -#endif
  697. -#ifdef UNIX
  698. -    struct stat st;
  699. -#endif
  700. -#ifdef MSDOS
  701. -    struct stat st;
  702. -#endif
  703. -/* +PORT+ */
  704. -/*    int tf;
  705. - *    int dflags;
  706. - */
  707. -    static char *procName = "process_file";
  708. -
  709. -    /* Get file info */
  710. -    ftype =  buf[4];                /* File type */
  711. -    auxtype = (int) buf[5] + ((int)buf[6] << 8);
  712. -    fnamelen =    buf[23];            /* filename */
  713. -    strncpy(fname, &buf[24], fnamelen);
  714. -    fname[fnamelen] = '\0';
  715. -    /* dflags =  buf[125];             /* Data flags */
  716. -    /* tf =  buf[127];                /* Number of files to follow */
  717. -    filelen = (long) buf[20] + ((long) buf[21] << 8) +
  718. -        ((long) buf[22] << 16);    /* calculate file len */
  719. -    nblocks = (filelen + BUFSIZE-1) / BUFSIZE;    /* #of BNY blocks */
  720. -    problocks = buf[8] + ((int) buf[9] << 8);
  721. -
  722. -    mod_dt.second = 0;
  723. -    mod_dt.minute = buf[12] & 0x3f;
  724. -    mod_dt.hour   = buf[13] & 0x1f;
  725. -    mod_dt.day      = (buf[10] & 0x1f) -1;
  726. -    mod_dt.month  = (((buf[11] & 0x01) << 3) + (buf[10] >> 5)) -1;
  727. -    mod_dt.year   = buf[11] >> 1;
  728. -    mod_dt.weekDay= 0;
  729. -    create_dt.second = 0;
  730. -    create_dt.minute = buf[16] & 0x3f;
  731. -    create_dt.hour   = buf[17] & 0x1f;
  732. -    create_dt.day    = (buf[14] & 0x1f) -1;
  733. -    create_dt.month  = (((buf[15] & 0x01) << 3) + (buf[14] >> 5)) -1;
  734. -    create_dt.year   = buf[15] >> 1;
  735. -    create_dt.weekDay= 0;
  736. -
  737. -    if (!count || want(fname, wanted)) {
  738. -    if (!extract) { /* print file information ONLY */
  739. -        printf("%-15.15s %-3.3s ", fname, FT[ftype]);
  740. -        printf("%6d  ", problocks);
  741. -        printf("%-16.16s ", PrintDate(&mod_dt, TRUE));
  742. -        printf("%-16.16s ", PrintDate(&create_dt, TRUE));
  743. -        if (filelen < 0x100L)
  744. -        sprintf(outbuf, "$%.2lx", filelen);
  745. -        else if (filelen < 0x10000L)
  746. -        sprintf(outbuf, "$%.4lx", filelen);
  747. -        else sprintf(outbuf, "$%.6lx", filelen);
  748. -        printf("%7s    ", outbuf);
  749. -        printf("$%.4x\n", auxtype);
  750. -
  751. -/*        if (dflags == 0)
  752. - *        printf("stored");
  753. - *        else {
  754. - *        if (dflags & 128) {
  755. - *            printf("squeezed");
  756. - *        }
  757. - *        if (dflags & 64) {
  758. - *            printf("encrypted");
  759. - *        }
  760. - *        if (dflags & 1)
  761. - *            printf("packed");
  762. - *        }
  763. - *        putchar('\n');
  764. - */
  765. -        if (ftype != 15) {            /* If not a directory */
  766. -        lseek(fd, (long) BUFSIZE*nblocks, S_REL); /*Seek to next file*/
  767. -        }
  768. -
  769. -    } else {  /* extract is TRUE */
  770. -
  771. -        if (verbose) { printf("Extracting %s...", fname); fflush(stdout); }
  772. -#ifdef UNIX
  773. -        if (ftype != 15)
  774. -        extract_file(fd, fname, filelen);  /* note dates etc not set */
  775. -        else {
  776. -        /* if no directory exists, then make one */
  777. -        if (stat(fname, &st) < 0)
  778. -            if (errno == ENOENT) {
  779. -            sprintf(tmpNameBuf, "mkdir %s", fname);
  780. -            if (system(tmpNameBuf) != 0)  /* call UNIX mkdir */
  781. -                Fatal("Unable to create subdir", procName);
  782. -            } else {
  783. -            Fatal("Unable to create dir", procName);
  784. -            }
  785. -        }
  786. -#else
  787. -# ifdef APW
  788. -        /* create file/directory , with appropriate type/auxtype stuff */
  789. -        c2pstr(fname);
  790. -        frec.pathname = fname;
  791. -        frec.fAccess = 0x00e3;  /* unlocked */
  792. -        frec.fileType = ftype;
  793. -        frec.auxType = (unsigned long) auxtype;
  794. -        frec.storageType = (int) buf[7];
  795. -        frec.createDate = 0x0000;  /* set later */
  796. -        frec.createTime = 0x0000;
  797. -
  798. -        CREATE( &frec );
  799. -        ToolErrChk();
  800. -        p2cstr(fname);
  801. -
  802. -        extract_file(fd, fname, filelen);
  803. -
  804. -        /* set file attributes */
  805. -        c2pstr(fname);
  806. -        frec.fAccess = (word) buf[3];
  807. -        frec.modDate = (word) buf[10] + ((word)buf[11] << 8);
  808. -        frec.modTime = (word) buf[12] + ((word)buf[13] << 8);
  809. -        frec.createDate = (word) buf[14] + ((word)buf[15] << 8);
  810. -        frec.createTime = (word) buf[16] + ((word)buf[17] << 8);
  811. -        SET_FILE_INFO( &frec );
  812. -        ToolErrChk();
  813. -        p2cstr(fname);
  814. -# else
  815. -        if (ftype != 15)
  816. -        extract_file(fd, fname, filelen);
  817. -        else  /* +PORT+ */
  818. -        printf("[ need [other] subdir create for UnBNY ]\n");
  819. -# endif /* APW */
  820. -#endif /* UNIX */
  821. -        if (verbose) printf("done.\n");
  822. -    }
  823. -    } else if (ftype != 15) {    /* This file not wanted; if not a directory */
  824. -    lseek(fd, (long) BUFSIZE*nblocks, S_REL);       /* Seek to next file */
  825. -    }
  826. -}
  827. -
  828. -
  829. -/*
  830. - * unblu -- process a binary II file fd, and process the filenames
  831. - *        listed in wanted. If wanted is \0, all files are processed.
  832. - */
  833. -static void unblu(fd, count, wanted)
  834. -int fd;
  835. -int count;
  836. -char **wanted;
  837. -{
  838. -    onebyt buf[BUFSIZE];
  839. -    int  firstblock = 1;    /* First block needs special processing */
  840. -    int  tofollow = 1;        /* Files to follow in the archive */
  841. -    int  n;
  842. -
  843. -    while (tofollow && ((n = read(fd, buf, BUFSIZE)) > 0)) {
  844. -                        /* If there is a header block */
  845. -
  846. -    if (n != BUFSIZE) {
  847. -        fprintf(stderr, "UnBNY: %s file size is broken\n", blufile);
  848. -        Quit(-1);
  849. -    }
  850. -    if ((buf[0] != 10) || (buf[1] != 71) ||
  851. -        (buf[2] != 76) || (buf[18] != 2)) {
  852. -        fprintf(stderr,
  853. -        "UnBNY: %s not a Binary II file or bad record\n", blufile);
  854. -        Quit(-1);
  855. -    }
  856. -
  857. -    tofollow = buf[127];        /* How many files to follow */
  858. -    if (firstblock && !extract) {
  859. -        print_header(buf);
  860. -    }
  861. -    firstblock = 0;
  862. -    process_file(fd, buf, count, wanted);     /* process the file for it */
  863. -
  864. -    }
  865. -    if (firstblock && (n < 0))  /* length < 128 */
  866. -    fprintf(stderr, "UnBNY: Not a Binary II file");
  867. -}
  868. -
  869. -
  870. -/*
  871. - * Main entry point from CShrink
  872. - */
  873. -void NuBNY(filename, argc, argv, options)
  874. -char *filename;
  875. -int argc;
  876. -char **argv;
  877. -char *options;
  878. -{
  879. -    int  bfd;                /* File descriptor for blu file */
  880. -    char *optr;
  881. -
  882. -    /* process X subopt ourselves */
  883. -    if (INDEX(options+1, 'x')) extract = TRUE;
  884. -    else extract = FALSE;
  885. -
  886. -    blufile = filename;       /* Make it global */
  887. -    if ((bfd = open(filename, O_RDONLY | O_BINARY)) < 0)
  888. -    Fatal("Unable to open Binary II archive", "NuBNY");
  889. -
  890. -    unblu(bfd, argc, argv);         /* Process wanted files */
  891. -
  892. -    close(bfd);
  893. -    Quit(0);
  894. -}
  895. -
  896. -#endif /*NO_BLU*/                    /***********************************/
  897. -
  898. =nusq.c
  899. -/*
  900. - * nusq.c - Huffman squeeze/unsqueeze routines
  901. - *        Based on sq3/usq2 by Don Elton
  902. - *
  903. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  904. - * By Andy McFadden (fadden@cory.berkeley.edu)
  905. - */
  906. -#ifdef APW
  907. -segment "Compress"
  908. -#endif
  909. -
  910. -#include "nudefs.h"
  911. -#include <stdio.h>
  912. -#include <fcntl.h>
  913. -
  914. -#ifdef MSDOS     /* For file IO */
  915. -# include <io.h>
  916. -# include <sys/types.h>
  917. -# include <sys/stat.h>
  918. -# include <errno.h>
  919. -#endif
  920. -
  921. -#include "nuetc.h"
  922. -
  923. -/*
  924. - * usq.c - undo Huffman coding
  925. - * Adapated from code By Marcel J.E. Mol
  926. - *
  927. - * Squeezed file format:
  928. - *     2 bytes MAGIC
  929. - *     2 bytes dummy ???  (maybe CRC or checksum; not checked)
  930. - *     filename ended by \0
  931. - *
  932. - *     2 bytes node count
  933. - *     node count node values, each 2 bytes
  934. - *     squeezed data per byte
  935. - *
  936. - * NuFX SQueezed format includes only the node count, node values, and
  937. - *   the data.  The BLU routines are expected to strip off the MAGIC,
  938. - *   checksum, and filename before calling this.
  939. - */
  940. -
  941. -/*char *copyright = "@(#) usq.c  2.1 18/06/88  (c) M.J.E. Mol";*/
  942. -#define BUFSIZE 128
  943. -#define MAGIC    0xff76               /* Squeezed file magic */
  944. -#define DLE 0x90               /* repeat byte flag */
  945. -#define NOHIST 0               /* no relevant history */
  946. -#define INREP 1                /* sending a repeated value */
  947. -#define SPEOF 256               /* special endfile token */
  948. -#define NUMVALS 257               /* 256 data values plus SPEOF */
  949. -
  950. -/* global variable declarations */
  951. -char *sfn;                   /* squeezed file name */
  952. -struct nd {                   /* decoding tree */
  953. -    int child[2];               /* left, right */
  954. -} node[NUMVALS];               /* use large buffer */
  955. -int state;                   /* repeat unpacking state */
  956. -int bpos;                   /* last bit position read */
  957. -int curin;                   /* last byte value read */
  958. -int numnodes;                   /* number of nodes in decode tree */
  959. -
  960. -static unsigned char fromc;    /* for use in text translation */
  961. -static BOOLEAN trbool;        /* BOOLEAN version of transfrom */
  962. -
  963. -
  964. -/* Get an integer from the input stream */
  965. -static twobyt get_int(f)
  966. -FILE *f;
  967. -{
  968. -    twobyt val;
  969. -
  970. -    val = (twobyt)getc(f);
  971. -    val += (twobyt)getc(f) << 8;
  972. -    return (val);
  973. -}
  974. -
  975. -
  976. -static int getc_usq(f)                /* get byte from squeezed file */
  977. -FILE *f;                   /* file containing squeezed data */
  978. -{
  979. -    register short i;               /* tree index */
  980. -
  981. -    /* follow bit stream in tree to a leaf */
  982. -    for (i=0; (i <= 0x7fff) && (i>=0); )/* work down(up?) from root */
  983. -    {
  984. -     if (++bpos > 7) {
  985. -          if ((curin=getc(f)) == EOF)
  986. -           return(EOF);
  987. -          bpos = 0;
  988. -
  989. -          /* move a level deeper in tree */
  990. -          i = node[i].child[1 & curin];
  991. -     }
  992. -     else i = node[i].child[1 & (curin >>= 1)];
  993. -    }
  994. -
  995. -    /* decode fake node index to original data value */
  996. -    i = -(i + 1);
  997. -
  998. -    /* decode special endfile token to normal EOF */
  999. -    return ((i==SPEOF) ? EOF : i);
  1000. -}
  1001. -
  1002. -
  1003. -/*  putc-ncr -- decode non-repeat compression.    Bytes are passed one
  1004. - *        at a time in coded format, and are written out uncoded.
  1005. - *        The data is stored normally, except that runs of more
  1006. - *        than two characters are represented as:
  1007. - *
  1008. - *             <char> <DLE> <count>
  1009. - *
  1010. - *        With a special case that a count of zero indicates a DLE
  1011. - *        as data, not as a repeat marker.
  1012. - */
  1013. -static void putc_ncr(c, t)           /* put NCR coded bytes */
  1014. -unsigned char c;               /* next byte of stream */
  1015. -FILE *t;                   /* file to receive data */
  1016. -{
  1017. -    static int lastc;          /* last character seen */
  1018. -
  1019. -    /* if converting line terminators, do so now */
  1020. -    if (trbool && (c == fromc))
  1021. -#ifdef UNIX
  1022. -    c = 0x0a;
  1023. -#else
  1024. -# ifdef APW
  1025. -    c = 0x0d;
  1026. -# else
  1027. -    c = 0x0d;  /* No CRLF stuff in unSQueeze... sorry */
  1028. -# endif
  1029. -#endif
  1030. -
  1031. -    switch (state) {               /* action depends on our state */
  1032. -    case NOHIST:               /* no previous history */
  1033. -        if (c==DLE)            /* if starting a series */
  1034. -         state = INREP;        /* then remember it next time */
  1035. -        else putc(lastc=c, t);     /* else nothing unusual */
  1036. -        return;
  1037. -
  1038. -    case INREP:               /* in a repeat */
  1039. -        if (c)               /* if count is nonzero */
  1040. -        while (--c)           /* then repeatedly ... */
  1041. -            putc(lastc, t);    /* ... output the byte */
  1042. -        else putc(DLE, t);           /* else output DLE as data */
  1043. -        state = NOHIST;           /* back to no history */
  1044. -        return;
  1045. -
  1046. -    default:
  1047. -        fprintf(stderr, "%s: bad NCR unpacking state (%d)",
  1048. -                prgName, state);
  1049. -    }
  1050. -}
  1051. -
  1052. -
  1053. -static int init_usq(f)                /* initialize Huffman unsqueezing */
  1054. -FILE *f;                   /* file containing squeezed data */
  1055. -{
  1056. -    register int i;               /* node index */
  1057. -
  1058. -    switch (transfrom) {
  1059. -    case -1:  /* no translation */
  1060. -    trbool = 0;
  1061. -    break;
  1062. -    case 0:  /* from ProDOS */
  1063. -    trbool = 1;
  1064. -    fromc = 0x0d;
  1065. -    break;
  1066. -    case 1:  /* from UNIX */
  1067. -    trbool = 1;
  1068. -    fromc = 0x0a;
  1069. -    break;
  1070. -    case 2:  /* from MS-DOS... this needs fixing */
  1071. -    trbool = 1;
  1072. -    fromc = 0x0a;  /* just turn LFs into whatever... */
  1073. -    break;
  1074. -    default:  /* unknown */
  1075. -    fprintf(stderr, "%s: unknown translation type %d\n", prgName, trbool);
  1076. -    fprintf(stderr, "%s: assuming conversion from CR\n", prgName);
  1077. -    trbool = 1;  /* should just ignore flag, but other procs do this */
  1078. -    fromc = 0x0d;
  1079. -    break;
  1080. -    }
  1081. -
  1082. -    bpos = 99;                   /* force initial read */
  1083. -    numnodes = get_int(f);           /* get number of nodes */
  1084. -
  1085. -    if (numnodes<0 || numnodes>=NUMVALS) {
  1086. -     fprintf(stderr, "%s: usq: archived file has invalid decode tree\n",
  1087. -                            prgName);
  1088. -     return (-1);
  1089. -    }
  1090. -
  1091. -    /* initialize for possible empty tree (SPEOF only) */
  1092. -    node[0].child[0] = -(SPEOF + 1);
  1093. -    node[0].child[1] = -(SPEOF + 1);
  1094. -
  1095. -    for (i=0; i<numnodes; ++i) {    /* get decoding tree from file */
  1096. -     node[i].child[0] = get_int(f);
  1097. -     node[i].child[1] = get_int(f);
  1098. -    }
  1099. -
  1100. -    return (0);
  1101. -}
  1102. -
  1103. -
  1104. -/*
  1105. - * Unsqueeze a file
  1106. - */
  1107. -static int unsqueeze(sfp, dfp)
  1108. -FILE *sfp, *dfp;
  1109. -{
  1110. -    register int i;
  1111. -    register int c;            /* one char of stream */
  1112. -
  1113. -    state = NOHIST;               /* initial repeat unpacking state */
  1114. -
  1115. -    if (init_usq(sfp))               /* init unsqueeze algorithm */
  1116. -    return 1;
  1117. -    while ((c=getc_usq(sfp)) != EOF)   /* and unsqueeze file */
  1118. -     putc_ncr(c, dfp);
  1119. -
  1120. -    return (0);                   /* file is okay */
  1121. -}
  1122. -
  1123. -
  1124. -/*
  1125. - * main entrance to unsqueeze
  1126. - *
  1127. - * We reset the file posn to where it should be according to "length"; note
  1128. - * that "length" is not actually used by the unsqueeze routines.  We have
  1129. - * do to this because fdopen() sticks about 8K or so in a buffer...
  1130. - *
  1131. - * Note also that we dup() the file descriptors before starting.  This
  1132. - * is so that we can cleanly fclose() the file descriptors when we're done,
  1133. - * but still keep the file open.
  1134. - */
  1135. -void unpak_SQU(srcfd, dstfd, length)
  1136. -int srcfd, dstfd;
  1137. -long length;  /* #of bytes we're expected to read */
  1138. -{
  1139. -    FILE *srcfp, *dstfp;        /* File pointers for squ/dest file */
  1140. -    int srcfd2, dstfd2;
  1141. -    long finalposn;
  1142. -    static char *procName = "unpak_SQU";
  1143. -
  1144. -    finalposn = lseek(srcfd, 0L, S_REL) + length;  /* where we should end up */
  1145. -    srcfd2 = dup(srcfd);
  1146. -    dstfd2 = dup(dstfd);
  1147. -    if ((srcfp = fdopen(srcfd2, FREAD_STR)) == NULL)
  1148. -    Fatal("Can't fdopen() archive", procName);
  1149. -    if ((dstfp = fdopen(dstfd2, FWRITE_STR)) == NULL)
  1150. -    Fatal("Can't fdopen() dest file", procName);
  1151. -
  1152. -    unsqueeze(srcfp, dstfp);  /* unsqueeze the file */
  1153. -    fclose(srcfp);  /* (was fflush) (this isn't really necessary) */
  1154. -    fclose(dstfp);  /* (was fflush) This is *very* necessary */
  1155. -
  1156. -    if (lseek(srcfd, finalposn, S_ABS) < 0)  /* set file posn back */
  1157. -    Fatal("Can't reset final posn", procName);
  1158. -    /* note that this lets things continue even if unSQueezing failed */
  1159. -}
  1160. -
  1161. =apwerr.h
  1162. -/*
  1163. - * apwerr.h - text versions of APW and ProDOS 16 error codes
  1164. - *   ERROR() didn't cut it, and I'm trying to separate things from the shell.
  1165. - *
  1166. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  1167. - * By Andy McFadden (fadden@cory.berkeley.edu)
  1168. - */
  1169. -
  1170. -/* APW-specific UNIX-like errors */
  1171. -
  1172. -/*
  1173. - [ this is derived from: ]
  1174. - errno.h -- error return codes
  1175. -
  1176. - Copyright American Telephone & Telegraph
  1177. - Modified and used with permission, Apple Computer Inc.
  1178. - Copyright Apple Computer Inc. 1985, 1986, 1987
  1179. - All rights reserved.
  1180. -*/
  1181. -/* @(#)errno.h 2.1 */
  1182. -/* 3.0 SID # 1.3 */
  1183. -
  1184. -#define sys_nerr 35       /* err must be < Max APW Err */
  1185. -static char *sys_errlist[sys_nerr] = {
  1186. -    /* 0  (no err)  */    "[ call successful ]",
  1187. -    /* 1  EPERM     */    "permission denied",
  1188. -    /* 2  ENOENT    */    "no such file or directory",
  1189. -    /* 3  ENORSRC   */    "no such resource",
  1190. -    /* 4  EINTR     */    "interrupted system call",
  1191. -    /* 5  EIO        */    "I/O error",
  1192. -    /* 6  ENXIO     */    "no such device or address",
  1193. -    /* 7  E2BIG     */    "insufficient space for return argument",
  1194. -    /* 8  ENOEXEC   */    "exec format error",
  1195. -    /* 9  EBADF     */    "bad file number",
  1196. -    /* 10 ECHILD    */    "no children",
  1197. -    /* 11 EAGAIN    */    "no more processes",
  1198. -    /* 12 ENOMEM    */    "not enough memory",
  1199. -    /* 13 EACCES    */    "permission denied",
  1200. -    /* 14 EFAULT    */    "bad address",
  1201. -    /* 15 ENOTBLK   */    "block device required",
  1202. -    /* 16 EBUSY     */    "mount device busy",
  1203. -    /* 17 EEXIST    */    "file exists",
  1204. -    /* 18 EXDEV     */    "cross-device link",
  1205. -    /* 19 ENODEV    */    "no such device",
  1206. -    /* 20 ENOTDIR   */    "not a directory",
  1207. -    /* 21 EISDIR    */    "is a directory",
  1208. -    /* 22 EINVAL    */    "invalid argument",
  1209. -    /* 23 ENFILE    */    "file table overflow",
  1210. -    /* 24 EMFILE    */    "too many open files",
  1211. -    /* 25 ENOTTY    */    "not a typewriter (sorry)",
  1212. -    /* 26 ETXTBSY   */    "text file busy",
  1213. -    /* 27 EFBIG     */    "file too large",
  1214. -    /* 28 ENOSPC    */    "no space left on device",
  1215. -    /* 29 ESPIPE    */    "illegal seek",
  1216. -    /* 30 EROFS     */    "read only file system",
  1217. -    /* 31 EMLINK    */    "too many links",
  1218. -    /* 32 EPIPE     */    "broken pipe",
  1219. -    /* 33 EDOM        */    "math arg out of domain of func",
  1220. -    /* 34 ERANGE    */    "math result not representable"
  1221. -};
  1222. -
  1223. -
  1224. -/* ProDOS errors */
  1225. -
  1226. -/* [ This is derived from: ]
  1227. -/********************************************
  1228. -; File: ProDos.h
  1229. -;
  1230. -;
  1231. -; Copyright Apple Computer, Inc. 1986, 1987
  1232. -; All Rights Reserved
  1233. -;
  1234. -********************************************/
  1235. -
  1236. -#define MPErr 0x61    /* err must be < Max ProDOS Err # */
  1237. -static char *ProDOSErr[MPErr] = {
  1238. -    /* 00 (no error)        */ "[ ProDOS call successful ]",
  1239. -    /* 01 invalidCallNum    */ "invalid call number / (fatal) unclaimed intr",
  1240. -    /* 02            */ "",
  1241. -    /* 03            */ "",
  1242. -    /* 04            */ "(ProDOS 8 invalid parameter count)",
  1243. -    /* 05 badPBlockPtr        */ "call pointer out of bounds",
  1244. -    /* 06 pdosActiveErr     */ "ProDOS is active",
  1245. -    /* 07 pdosBusyErr        */ "ProDOS is busy",
  1246. -    /* 08            */ "",
  1247. -    /* 09            */ "",
  1248. -    /* 0a vcbUnusable        */ "(fatal) VCB is unusable",
  1249. -    /* 0b fcbUnusable        */ "(fatal) FCB is unusable",
  1250. -    /* 0c badBlockZero        */ "(fatal) block zero allocated illegally",
  1251. -    /* 0d shdwInterruptErr  */ "(fatal) interrupt occurred while I/O shadowing off",
  1252. -    /* 0e            */ "",
  1253. -    /* 0f            */ "",
  1254. -    /* 10 devNotFound        */ "device not found",
  1255. -    /* 11 badDevRefNum        */ "invalid device ref# / (fatal) wrong OS version",
  1256. -    /* 12            */ "",
  1257. -    /* 13            */ "",
  1258. -    /* 14            */ "",
  1259. -    /* 15            */ "",
  1260. -    /* 16            */ "",
  1261. -    /* 17            */ "",
  1262. -    /* 18            */ "",
  1263. -    /* 19            */ "",
  1264. -    /* 1a            */ "",
  1265. -    /* 1b            */ "",
  1266. -    /* 1c            */ "",
  1267. -    /* 1d            */ "",
  1268. -    /* 1e            */ "",
  1269. -    /* 1f            */ "",
  1270. -    /* 20 badReqCode        */ "invalid request code",
  1271. -    /* 21            */ "",
  1272. -    /* 22            */ "",
  1273. -    /* 23            */ "",
  1274. -    /* 24            */ "",
  1275. -    /* 25 intTableFull        */ "interrupt table full",
  1276. -    /* 26 invalidOperation  */ "invalid operation",
  1277. -    /* 27 ioError        */ "I/O error",
  1278. -    /* 28 noDevConnect        */ "no device connected",
  1279. -    /* 29            */ "",
  1280. -    /* 2a            */ "",
  1281. -    /* 2b writeProtectErr   */ "write protect error",
  1282. -    /* 2c            */ "",
  1283. -    /* 2d            */ "",
  1284. -    /* 2e diskSwitchErr     */ "disk switched error",
  1285. -    /* 2f            */ "device not online",
  1286. -    /* 30            */ "device-specific err $30",
  1287. -    /* 31            */ "device-specific err $31",
  1288. -    /* 32            */ "device-specific err $32",
  1289. -    /* 33            */ "device-specific err $33",
  1290. -    /* 34            */ "device-specific err $34",
  1291. -    /* 35            */ "device-specific err $35",
  1292. -    /* 36            */ "device-specific err $36",
  1293. -    /* 37            */ "device-specific err $37",
  1294. -    /* 38            */ "device-specific err $38",
  1295. -    /* 39            */ "device-specific err $39",
  1296. -    /* 3a            */ "device-specific err $3a",
  1297. -    /* 3b            */ "device-specific err $3b",
  1298. -    /* 3c            */ "device-specific err $3c",
  1299. -    /* 3d            */ "device-specific err $3d",
  1300. -    /* 3e            */ "device-specific err $3e",
  1301. -    /* 3f            */ "device-specific err $3f",
  1302. -    /* 40 badPathName        */ "invalid pathname syntax",
  1303. -    /* 41            */ "",
  1304. -    /* 42 fcbFullErr        */ "FCB full error (too many files open)",
  1305. -    /* 43 badFileRefNum     */ "invalid file reference number",
  1306. -    /* 44 pathNotFound        */ "path not found",
  1307. -    /* 45 volumeNotFound    */ "volume not found",
  1308. -    /* 46 fileNotFound        */ "file not found",
  1309. -    /* 47 dupFileName        */ "duplicate file name",
  1310. -    /* 48 volumeFullErr     */ "volume full error",
  1311. -    /* 49 dirFullErr        */ "directory full error",
  1312. -    /* 4a versionErr        */ "version error (incompatible file format)",
  1313. -    /* 4b badStoreType        */ "unsupported (or incorrect) storage type",
  1314. -    /* 4c eofEncountered    */ "end-of-file encountered",
  1315. -    /* 4d positionRangeErr  */ "position out of range",
  1316. -    /* 4e accessErr        */ "access not allowed",
  1317. -    /* 4f            */ "",
  1318. -    /* 50 fileOpenErr        */ "file already open",
  1319. -    /* 51 dirDamaged        */ "directory structure is damaged (file count?)",
  1320. -    /* 52 badVolType        */ "unsupported volume type",
  1321. -    /* 53 paramRangeErr     */ "parameter out of range",
  1322. -    /* 54 memoryFullErr     */ "out of memory",
  1323. -    /* 55 vcbFullErr        */ "VCB full error",
  1324. -    /* 56            */ "(ProDOS 8 bad buffer address)",
  1325. -    /* 57 dupVolumeErr        */ "duplicate volume error",
  1326. -    /* 58 notBlkDevErr        */ "not a block device",
  1327. -    /* 59 invalidLevel        */ "invalid level",
  1328. -
  1329. -    /* 5a            */ "block number out of range (bad vol bitmap?)",
  1330. -    /* 5b            */ "illegal pathname change",
  1331. -    /* 5c            */ "not an executable file",
  1332. -    /* 5d            */ "file system not available",
  1333. -    /* 5e            */ "cannot deallocate /RAM",
  1334. -    /* 5f            */ "return stack overflow",
  1335. -    /* 60            */ "data unavailable"
  1336. -};
  1337. + END OF ARCHIVE
  1338.