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

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC035:  Nulib - Archive Library Tools (Unix) 04/10
  4. Message-ID: <May.1.18.10.42.1991.23491@yoko.rutgers.edu>
  5. Date: 1 May 91 22:10:44 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Andy McFadden (fadden@cory.berkeley.edu)
  10. Posting-number: Volume 1, Source:35
  11. Archive-name: archive/unix/nulib/part04.10
  12. Architecture: UNIX
  13. Version-number: 3.03
  14.  
  15.  
  16. =nucomp.h
  17. -/*
  18. - * nucomp.h - declarations for nucomp.c
  19. - *
  20. - * NuLib v3.0  February 1991  Freeware (distribute, don't sell)
  21. - * By Andy McFadden (fadden@cory.berkeley.edu)
  22. - */
  23. -
  24. -#ifdef BSD43
  25. -# define NO_SETVBUF
  26. -#endif
  27. -
  28. -#include <ctype.h>
  29. -#include <string.h>
  30. -#ifdef UNIX        /* this is asking for trouble */
  31. -# include <sys/types.h>
  32. -#else
  33. -# ifdef IAPX286
  34. -#  include <sys/types.h>
  35. -# else
  36. -#  ifdef IAPX386
  37. -#   include <sys/types.h>
  38. -#  else
  39. -#   include <types.h>
  40. -#  endif
  41. -# endif
  42. -#endif
  43. -#include <fcntl.h>
  44. -
  45. -/*@H************************ < COMPRESS HEADER > ****************************
  46. -*   $@(#) compress.c,v 4.3 88/12/26 08:00:00 don Release ^                  *
  47. -*                                                                           *
  48. -*   compress : compress.h <global defines, etc>                             *
  49. -*                                                                           *
  50. -*   port by  : Donald J. Gloistein                                          *
  51. -*                                                                           *
  52. -*   Source, Documentation, Object Code:                                     *
  53. -*   released to Public Domain.  This code is based on code as documented    *
  54. -*   below in release notes.                                                 *
  55. -*                                                                           *
  56. -*---------------------------  Module Description  --------------------------*
  57. -*   THIS HEADER CONTAINS MUCH IMPLEMENTATION INFORMATION AND ASSUMPTIONS    *
  58. -*   PLEASE PRINT IT OUT AND READ IT BEFORE COMPILING CODE FOR YOURSELF      *
  59. -*                                                                           *
  60. -*   This header supports a number of compiler defines and predefines.       *
  61. -*   Rather than explain all of them, please print the header and read the   *
  62. -*   notes. Also the unix and xenix makefiles are commented for the          *
  63. -*   various options. There continues to have a lot of Dos specific info in  *
  64. -*   the header. This is to help on 16 bit Msdos machines to get their       *
  65. -*   compiler to work properly. I make no appology for that, as this port    *
  66. -*   began as a way to implement 16 bit compress on a segmented MsDos machine*
  67. -*                                                                           *
  68. -*   However, for Unix and Xenix, all you should have to define is -DXENIX   *
  69. -*   or -DUNIX and compile. There may be a problem with whether your library *
  70. -*   supports alloc() or malloc(), but there is a define for that, also.     *
  71. -*                                                                           *
  72. -*   This header can be maintained to keep up with the different compilers   *
  73. -*   and systems. As distributed in don Release, the files will compile with *
  74. -*   no changes under Microsoft version 5.1 C compiler, and Xenix C compiler *
  75. -*   which is the Microsoft version 4 ported. If you are going to bind the   *
  76. -*   code for use in MsDos and OS/2 machines, then you must uncomment the    *
  77. -*   #define BIND in this header. Otherwise, this distribution of source     *
  78. -*   detect Msdos and Xenix predefines from the compiler and adjust.         *
  79. -*                                                                           *
  80. -*--------------------------- Implementation Notes --------------------------*
  81. -*                                                                           *
  82. -*   compiled with : compress.fns                                            *
  83. -*
  84. -*   NOTE!!!  Defaults of this code now are completely Unix, even for the    *
  85. -*            msdos ports.  That means that the program works as a filter,   *
  86. -*            and will just sit there waiting for input from stdin if you    *
  87. -*            issue just the command name. You must use -h or -? to get the  *
  88. -*            full help screen now. Also, it will unlink (kill) as a default *
  89. -*            on successful compression and decompression. That means the    *
  90. -*            source file will be erased.                                    *
  91. -*            These defaults are changed with the FILTER and KEEPFLAG        *
  92. -*            defines.                                                       *
  93. -*                                                                           *
  94. -*   NOTE!!!  Compiler predefines were taken out of the compress.h header.   *
  95. -*            You must either specify them on compile or uncomment the       *
  96. -*            compiler define in this header. Compiling without doing these  *
  97. -*            will result in a program that does unspecified actions.        *
  98. -*   problems:                                                               *
  99. -*            The inpath and outpath is a bit kludged. It should work okay.  *
  100. -*            Let me know if you have problems, especially under Unix.       *
  101. -*                                                                           *
  102. -*   CAUTION: The bound version will run on Dos 2.x, but you must use the    *
  103. -*            name compress.exe.  If you rename the file, it will not run    *
  104. -*            The unbound version will run on Dos 2.x with the name changed  *
  105. -*            but due to the dos version, will not detect its own name.      *
  106. -*                                                                           *
  107. -*   CAUTION: Non MsDos users. You must modify the _MAX_PATH defines for     *
  108. -*            your operating system if it is different from the assumed      *
  109. -*            standard.                                                      *
  110. -*                                                                           *
  111. -*   CAUTION: I have used a number of defines to make it possible to compile *
  112. -*            properly under a number of bit sizes and adjust for the memory *
  113. -*            allocation scheme needed. If you do not use a dos system,      *
  114. -*            PLEASE pay attention to the defines for MAXSEG_64 and the one  *
  115. -*            called SMALLMODEL. The SMALLMODEL define is set in the header  *
  116. -*            but if you don't have a compiler that triggers the MAXSEG_64   *
  117. -*            define, you may end up with bad pointers. Becareful.           *
  118. -*                                                                           *
  119. -*   Header for files using version 4 compress routines define MAIN          *
  120. -*   in the file with defining instance of the global variables.             *
  121. -*   There are a number of compilers for MsDos and Unix/Xenix.               *
  122. -*   So the user must define the actions required.                           *
  123. -*                                                                           *
  124. -*                                                                           *
  125. -*   Defines:  This header file contains most of the system wide defines.    *
  126. -*             the purpose for this was to consolodate compiler differences  *
  127. -*             into one area that is easily changed.                         *
  128. -*                                                                           *
  129. -*   define MAXBITS= if you want a different maximum bits. 16 bits will now  *
  130. -*   run in about 400K of memory.                                            *
  131. -*   define BIND if you are going to use Microsoft bind.exe program on the   *
  132. -*   executable.                                                             *
  133. -*                                                                           *
  134. -*   define MSDOS if you are compiling under MsDos or PcDos and your compiler*
  135. -*   does not predefine it.                                                  *
  136. -*                                                                           *
  137. -*     Initials ---- Name ---------------------------------                  *
  138. -*      DjG          Donald J. Gloistein, current port to MsDos 16 bit       *
  139. -*                   Plus many others, see rev.hst file for full list        *
  140. -*      LvR          Lyle V. Rains, many thanks for improved implementation  *
  141. -*                   of the compression and decompression routines.          *
  142. -*************************************************************************@H*/
  143. -
  144. -#ifndef FALSE            /* let's get some sense to this */
  145. -#define FALSE 0
  146. -#define TRUE !FALSE
  147. -#endif
  148. -
  149. -#define NDEBUG
  150. -#define NPROTO
  151. -#define COMP40           /* take this out for a little more speed */
  152. -char *malloc();
  153. -#define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  154. -#define FREEIT(ptr)     free(ptr)
  155. -#define NOSIGNAL    /* what the hell is "SIGTYPE"? */
  156. -#define setbinary(fp)
  157. -#define FAR 
  158. -#define CONST
  159. -#define _MAX_DIR 64
  160. -
  161. -/* FILTER  if you want the program to operate as a unix type filter */
  162. -/*  if not defined TRUE, then issuing command without parameters will */
  163. -/*  print a usage and help information                              */
  164. -/*  Use -DFILTER=0 to deactivate filter operation                   */
  165. -#ifndef FILTER
  166. -#define FILTER  FALSE
  167. -#endif
  168. -
  169. -/* KEEPFLAG determines the default action on successful completion */
  170. -/* Unix convention is FALSE (erase input file)                     */
  171. -/* Use -DKEEPFLAG=1 to keep files as default or change here        */
  172. -/* if you don't set it before here and you are compiling the debug */
  173. -/* version, then files will be kept.                               */
  174. -
  175. -#ifndef KEEPFLAG
  176. -#define KEEPFLAG TRUE
  177. -#endif
  178. -
  179. -
  180. -
  181. -
  182. -/* the following tells the system that the maximum segment is 64k */
  183. -/* if your compiler is not one of these and has this limitation   */
  184. -/* Because of this, this code should compile with minimum porting */
  185. -/* in the COMPUSI.XEN module to most unix systems.                */
  186. -/* This is also used to keep array indexing to 16 bit integer     */
  187. -/* if not predefined in compiler implementation, you must define  */
  188. -/* it separately if applicable to your compiler/system            */
  189. -
  190. -#define MAXSEG_64K                                             
  191. -
  192. -/* put this in if you are compiling in small code */
  193. -/* model and your compiler does not predefine it  */
  194. -/* this is for CPU' with 64k segment limitation.  */
  195. -/* Use this define for small code, it is used by  */
  196. -/* the header to decide on value for NEARHEAP     */
  197. -/* #define SMALLMODEL */
  198. -
  199. -/* does your system use far pointers ? if you want it enabled keep this */
  200. -/* if you have segment limit and compile in larger than 13 bits         */
  201. -/* then you will have to use compact or large model if your compiler    */
  202. -/* does not support far pointer keyword.                                */
  203. -
  204. -#ifndef FAR
  205. -#define FAR
  206. -#endif
  207. -
  208. -/* What type does the alloc() function return, char or void? */
  209. -
  210. -#ifndef ALLOCTYPE
  211. -#define ALLOCTYPE char
  212. -#endif
  213. -
  214. -/* Does your run time library support the ANSI functions for:*/
  215. -
  216. -/* reverse string set search?  strrpbrk() if not:             */
  217. -#define NO_REVSEARCH 
  218. -
  219. -/* Does your library include strrchr()? If not define this:  */
  220. -/*#define NO_STRRCHR*//* unix/xenix module uses this function*/
  221. -
  222. -/* Does your library include strchr()? If not define this:   */
  223. -/*#define NO_STRCHR*//* dos module uses this function.       */
  224. -
  225. -/* definition for const key word if supported */
  226. -#ifndef CONST
  227. -#define CONST
  228. -#endif
  229. -
  230. -
  231. -/*  And now for some typedefs */
  232. -typedef unsigned short CODE;
  233. -typedef unsigned char UCHAR;
  234. -typedef unsigned int HASH;
  235. -typedef int FLAG;
  236. -
  237. -  /* 
  238. -   * You can define the value of MAXBITS to be anything betweeen MINBITS
  239. -   * and MAXMAXBITS.  This is will determine the maximum memory you will
  240. -   * use and how the tables will be handled.  I recommend you just leave
  241. -   * it at MAXMAXBITS, because you can define DFLTBITS in compiling the
  242. -   * module COMPRESS.C to set the default, and you can vary the number
  243. -   * of bits at runtime by using the -b switch.
  244. -   */
  245. -
  246. -   /*
  247. -   * The only reason to change MAXBITS is if you absolutely must have
  248. -   * faster performance. If you specify 14 bits, the tables will not
  249. -   * be split; at 13 bits, you can fit in the MSDOS small memory model
  250. -   * and allocate tables in near heap.
  251. -   * This value is available to other modules through the variable maxbits.
  252. -   */
  253. -
  254. -#define INITBITS    9
  255. -#define MINBITS     12
  256. -#define MAXMAXBITS  16
  257. -
  258. -#ifndef MAXBITS
  259. -#define MAXBITS    MAXMAXBITS
  260. -#endif
  261. -
  262. -#if (MAXBITS > MAXMAXBITS)
  263. -#undef MAXBITS
  264. -#define MAXBITS    MAXMAXBITS
  265. -#endif
  266. -
  267. -#if (MAXBITS < MINBITS)
  268. -#undef MAXBITS
  269. -#define MAXBITS  MINBITS
  270. -#endif
  271. -
  272. -  /* You should define DFLTBITS to be the default compression code
  273. -   * bit length you desire on your system.
  274. -   * (I define mine in the compiler command line in my Makefile.LvR)
  275. -   * (I leave mine alone and keep to the maximum. DjG)
  276. -   */
  277. -
  278. -#ifndef DFLTBITS
  279. -#define DFLTBITS MAXBITS
  280. -#endif
  281. -#if (DFLTBITS < MINBITS)
  282. -#undef DFLTBITS
  283. -#define DFLTBITS MINBITS
  284. -#endif
  285. -#if (DFLTBITS > MAXBITS)
  286. -#undef DFLTBITS
  287. -#define DFLTBITS MAXBITS
  288. -#endif
  289. -
  290. -/* correcting for different types of pointer arithmatic */
  291. -/* probably won't have to change it                     */
  292. -#define NULLPTR(type)   ((type FAR *) NULL)
  293. -
  294. -
  295. -/* in making this program portable the following allocation and          */
  296. -/* free functions are called, with the following parameters:             */
  297. -/*        ALLOCTYPE FAR *emalloc(unsigned int x, int y)                  */
  298. -/*                 void  efree(ALLOCTYPE FAR *ptr)                       */
  299. -/* you must define the allocation function and the free function         */
  300. -/* keep in mind that the casts must be correct for your compiler         */
  301. -/* NOTE these are the two functions to change for allocating pointers to */
  302. -/* far data space if you are not using Microsoft C v.5.1                 */
  303. -/* Consult your compiler manual and find the low level function that     */
  304. -/* returns a far pointer when compiled in the small model.               */
  305. -/* if your compiler does not support that, you will have to compile with */
  306. -/* a model that defaults to far pointers to data (compact or large model)*/
  307. -/* HERE ARE SOME SAMPLE PREDEFINED ONES                                  */
  308. -
  309. -
  310. -/* default allocation function, in segmented addressing, must return */
  311. -/* a far pointer or compile with far pointer data as default         */
  312. -#ifndef ALLOCATE
  313. -#include <malloc.h>
  314. -#define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  315. -#define FREEIT(ptr)     free((ptr))
  316. -#endif
  317. -
  318. -
  319. -# ifdef MAXSEG_64K
  320. -#   if  MAXBITS > 14
  321. -#       define SPLIT_HT   TRUE
  322. -#   else
  323. -#       define SPLIT_HT   0
  324. -#   endif
  325. -# else
  326. -#   define SPLIT_HT   0
  327. -# endif
  328. -
  329. -# ifdef MAXSEG_64K
  330. -#   if  MAXBITS > 15
  331. -#       define SPLIT_PFX   TRUE
  332. -#   else
  333. -#       define SPLIT_PFX   0
  334. -#   endif
  335. -# else
  336. -#   define SPLIT_PFX   0
  337. -# endif
  338. -
  339. -#ifndef BUFSIZ
  340. -#define BUFSIZ 512
  341. -#endif
  342. -
  343. -#ifdef NO_SETBUF
  344. -#define NO_SETVBUF
  345. -#endif
  346. -
  347. -/* NuLib: comment: this ought to use setbuffer() if available */
  348. -#ifdef NO_SETVBUF
  349. -#   ifndef NO_SETBUF
  350. -#       define setvbuf(fp,buf,mode,size) setbuf((fp),(buf))
  351. -#       define ZBUFSIZE BUFSIZ
  352. -#       define XBUFSIZE BUFSIZ
  353. -#   else
  354. -#       define setvbuf(fp,buf,mode,size)
  355. -#       define ZBUFSIZE (1)
  356. -#       define XBUFSIZE (1)
  357. -#   endif
  358. -#else
  359. -#   ifdef NEARHEAP
  360. -#       define XBUFSIZE    (0xC00)
  361. -#       define ZBUFSIZE    (0x1800)
  362. -#   else
  363. -#       define XBUFSIZE    (0x3000)      /* 12k bytes */
  364. -#       define ZBUFSIZE    (0x6000)      /* 24k bytes */
  365. -#   endif
  366. -#endif
  367. -
  368. -#define UNUSED      ((CODE)0)   /* Indicates hash table value unused    */
  369. -#define CLEAR       ((CODE)256) /* Code requesting table to be cleared  */
  370. -#define FIRSTFREE ((CODE)(CLEAR+1))/* First free code for token encoding */
  371. -#define MAXTOKLEN   512         /* Max chars in token; size of buffer   */
  372. -#define OK          0           /* Result codes from functions:         */
  373. -#define ERROR       1
  374. -#define NORMAL      0
  375. -
  376. -#define SIGNAL_ERROR -1         /*   signal function error              */
  377. -#define NOMEM       2           /*   Ran out of memory                  */
  378. -#define TOKTOOBIG   3           /*   Token longer than MAXTOKLEN chars  */
  379. -#define READERR     4           /*   I/O error on input                 */
  380. -#define WRITEERR    5           /*   I/O error on output                */
  381. -#define INFILEBAD   6           /*   Infile not in compressed format    */
  382. -#define CODEBAD     7           /*   Infile contained a bad token code  */
  383. -#define TABLEBAD    8           /*   The tables got corrupted (!)       */
  384. -#define NOSAVING    9           /*   no saving in file size             */
  385. -#define NOTOPENED  10           /*   output file couldn't be opened     */
  386. -#define YES         1
  387. -#define NO          0
  388. -
  389. -
  390. -#include "nucompfn.h"    /* This has to come late... needs typedefs above */
  391. -
  392. -/* defines opening mode for files */
  393. -/* and suffixes for compressed file */
  394. -
  395. -
  396. -#define WRITE_FILE_TYPE FWRITE_STR    /* NuLib: was "wb" */
  397. -#define READ_FILE_TYPE FREAD_STR    /* NuLib: was "rb" */
  398. -#define SUFFIX ".Z"
  399. -
  400. -/* Defines for third byte of header */
  401. -#define BIT_MASK    0x1f
  402. -#define BLOCK_MASK  0x80
  403. -/* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
  404. -   a fourth header byte (for expansion).
  405. -*/
  406. -
  407. -
  408. -#define CHECK_GAP 10000L     /* ratio check interval */
  409. -
  410. -#ifdef MAIN
  411. -UCHAR magic_header[] = { 0x1F,0x9D };  /* 1F 9D */
  412. -
  413. -char rcs_ident[] = "@(#) compress,v 4.3 88/12/26 08:00:00 don Release $";
  414. -
  415. -int overwrite = 0;          /* Do not overwrite unless given -f flag */
  416. -int maxbits = DFLTBITS;     /* user settable max # bits/code */
  417. -
  418. -int exit_stat = 0;
  419. -int keep = KEEPFLAG;            /* True = don't kill file */
  420. -int keep_error = FALSE;     /* True = keep output file even if error exist */
  421. -char *prog_name;
  422. -char ifname[_MAX_DIR];
  423. -char inpath[_MAX_DIR];
  424. -char ofname [_MAX_DIR];
  425. -char outpath[_MAX_DIR];
  426. -int is_list = FALSE;            /* flag for file parameters */
  427. -char endchar[1];
  428. -char xbuf[XBUFSIZE];
  429. -char zbuf[ZBUFSIZE];
  430. -char separator[] = "/";
  431. -
  432. -int nomagic = FALSE;  /* Use a 3-byte magic number header, unless old file */
  433. -int zcat_flg = TRUE;  /* Write output on stdout, suppress messages */
  434. -int quiet = TRUE;     /* don't tell me about compression */
  435. -/*
  436. - * block compression parameters -- after all codes are used up,
  437. - * and compression rate changes, start over.
  438. - */
  439. -int block_compress = BLOCK_MASK;
  440. -#ifdef COMP40
  441. -long int ratio = 0L;
  442. -long checkpoint = CHECK_GAP;
  443. -#endif
  444. -
  445. -/* force the overwrite */
  446. -int force = 0;
  447. -
  448. -#ifndef NDEBUG
  449. -int verbose = FALSE;
  450. -int debug = FALSE;
  451. -#endif /* !NDEBUG */
  452. -
  453. -int do_decomp = FALSE;
  454. -
  455. -#else               /* not defining instance */
  456. -
  457. -extern UCHAR magic_header[];
  458. -extern char rcs_ident[];
  459. -extern int overwrite;
  460. -extern int maxbits;
  461. -
  462. -
  463. -extern int exit_stat;
  464. -extern int keep;
  465. -extern int keep_error;
  466. -extern char *prog_name;
  467. -extern char inpath[];
  468. -extern char outpath[];
  469. -extern int is_list;
  470. -extern char endchar[];
  471. -extern char xbuf[];
  472. -extern char zbuf[];
  473. -extern char ifname[];
  474. -extern char ofname[];
  475. -extern char separator[];
  476. -extern int nomagic;
  477. -extern int zcat_flg;
  478. -extern int quiet;
  479. -extern int block_compress;
  480. -#ifdef COMP40
  481. -extern long int ratio;
  482. -extern long checkpoint;
  483. -#endif
  484. -extern int force;
  485. -
  486. -#ifndef NDEBUG
  487. -extern int verbose;
  488. -extern int debug;
  489. -#endif /* !NDEBUG */
  490. -
  491. -extern int do_decomp;
  492. -#endif
  493. -
  494. =nuview.c
  495. -/*
  496. - * nuview.c - prints the contents of a NuFX archive
  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 "NuMain"
  503. -#endif
  504. -
  505. -#include "nudefs.h"
  506. -#include <stdio.h>
  507. -#ifdef BSD43
  508. -# include <strings.h>
  509. -#else  /* SYSV, APW, MSC */
  510. -# include <string.h>
  511. -#endif
  512. -
  513. -#ifdef APW
  514. -# include <shell.h>
  515. -#endif
  516. -
  517. -#include "nuview.h"
  518. -#include "nuread.h"
  519. -#include "nuetc.h"
  520. -
  521. -
  522. -/*
  523. - * String definitions for NuView
  524. - */
  525. -/* unknown value msg */
  526. -char *unknownStr = "[ unknown ]";
  527. -
  528. -/* weekDay values */
  529. -char *WD[8] = { "[ null ]", "Sunday", "Monday", "Tuesday", "Wednesday",
  530. -        "Thursday", "Friday", "Saturday" };
  531. -
  532. -/* month values */
  533. -char *MO[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  534. -        "Aug", "Sep", "Oct", "Nov", "Dec" };
  535. -
  536. -/* thread_class */
  537. -/*#define TCn 4*/
  538. -char *TC[TCn] = { "Message_thread", "Control_thread", "Data_thread",
  539. -        "Filename_thread" };
  540. -
  541. -/*#define TKn 3  /* max #of thread_kinds in a thread_class */
  542. -char *TK[TCn][TKn] = {
  543. -        { "ASCII text", "ASCII text (predef size)", "<undef>" },
  544. -        { "Create directory", "<undef>", "<undef>" },
  545. -        { "File data_fork", "Disk image", "File resource_fork" },
  546. -        { "Generic filename", "<undef>", "<undef>" } };
  547. -
  548. -/* thread_format */
  549. -/*#define TFn 6*/
  550. -char *TF[TFn] = { "Uncompressed", "SQueezed (SQ/USQ)",
  551. -        "Dynamic LZW Type I (ShrinkIt)",
  552. -        "Dynamic LZW Type II (ShrinkIt)", "12-bit UNIX compress",
  553. -        "16-bit UNIX compress" };
  554. -
  555. -/* brief thread format */
  556. -/*#define BTFn 6*/
  557. -char *BTF[BTFn] = { "Uncompr", "SQueezed", "LZW/1", "LZW/2", "Unix/12",
  558. -        "Unix/16" };
  559. -
  560. -/* quick thread_format */
  561. -/*#define QTFn 6*/
  562. -char *QTF[QTFn] = { "unc", "squ", "shk", "sh2", "u12", "u16" };
  563. -
  564. -/* file_sys_id */
  565. -/*#define FIDn 14*/
  566. -char *FID[FIDn] = { "Reserved/unknown ($00)", "ProDOS/SOS", "DOS 3.3",
  567. -        "DOS 3.2", "Apple II Pascal", "Macintosh (MFS)",
  568. -        "Macintosh (HFS)", "LISA file system", "Apple CP/M",
  569. -        "Reserved ($09)", "MS-DOS", "High-Sierra", "ISO 9660",
  570. -        "AppleShare" };
  571. -
  572. -/* storage_type */
  573. -/*#define STn 14*/
  574. -char *ST[STn] = { "Standard file ($00)", "Standard file ($01)",
  575. -        "Standard file ($02)", "Standard file ($03)", "??? ($04)",
  576. -        "Extended file ($05)", "??? ($06)", "??? ($07)", "??? ($08)",
  577. -        "??? ($09)", "??? ($0a)", "??? ($0b)", "??? ($0c)",
  578. -        "Subdirectory ($0d)" };
  579. -
  580. -/* file type names */
  581. -char *FT[256] = {
  582. -    "NON", "BAD", "PCD", "PTX", "TXT", "PDA", "BIN", "CHR",
  583. -    "PIC", "BA3", "DA3", "WPD", "SOS", "$0D", "$0E", "DIR",
  584. -    "RPD", "RPI", "$12", "OUT", "$14", "RPT", "$16", "$17",
  585. -    "$18", "ADB", "AWP", "ASP", "$1C", "$1D", "$1E", "$1F",
  586. -    "$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27",
  587. -    "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F",
  588. -    "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37",
  589. -    "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F",
  590. -    "$40", "$41", "$42", "$43", "$44", "$45", "$46", "$47",
  591. -    "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F",
  592. -    "$50", "$51", "$52", "$53", "$54", "$55", "$56", "$57",
  593. -    "$58", "$59", "$5A", "$5B", "$5C", "$5D", "$5E", "$5F",
  594. -    "PRE", "$61", "$62", "$63", "$64", "$65", "$66", "$67",
  595. -    "$68", "$69", "$6A", "NIO", "$6C", "DVR", "$6E", "HDV",
  596. -    "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77",
  597. -    "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F",
  598. -    "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87",
  599. -    "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F",
  600. -    "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97",
  601. -    "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F",
  602. -    "WPF", "MAC", "HLP", "DAT", "$A4", "LEX", "$A6", "$A7",
  603. -    "$A8", "$A9", "$AA", "GSB", "ARC", "$AD", "$AE", "$AF",
  604. -    "SRC", "OBJ", "LIB", "S16", "RTL", "EXE", "STR", "TSF",
  605. -    "NDA", "CDA", "TOL", "DRV", "$BC", "FST", "$BE", "DOC",
  606. -    "PNT", "SCR", "ANI", "$C3", "$C4", "$C5", "$C6", "$C7",
  607. -    "FON", "FND", "ICN", "$CB", "$CC", "$CD", "$CE", "$CF",
  608. -    "$D0", "$D1", "$D2", "$D3", "$D4", "$D5", "$D6", "$D7",
  609. -    "$D8", "$D9", "$DA", "$DB", "$DC", "DDD", "$DE", "$DF",
  610. -    "LBR", "$E1", "ATI", "$E3", "$E4", "$E5", "$E6", "$E7",
  611. -    "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "$EE", "PAS",
  612. -    "CMD", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7",
  613. -    "$F8", "IMG", "INT", "IVR", "BAS", "VAR", "REL", "SYS" };
  614. -
  615. -
  616. -/*
  617. - * NuView program
  618. - */
  619. -
  620. -/* print date from Time structure */
  621. -char *PrintDate(tptr, brief)
  622. -Time *tptr;
  623. -int brief;
  624. -{
  625. -    static char buf[64];  /* holds final date string; must be static */
  626. -    char buf2[64];  /* space to hold string while building it */
  627. -
  628. -    /* check for validity */
  629. -    if ( (tptr->day > 30) || (tptr->month > 11) || (tptr->hour > 24) ||
  630. -    (tptr->minute > 59) ) {
  631. -    strcpy(buf, "   <invalid>   ");
  632. -    return (buf);
  633. -    }
  634. -
  635. -    if (!tptr->second && !tptr->minute && !tptr->hour && !tptr->day &&
  636. -        !tptr->month && !tptr->year && !tptr->weekDay && !tptr->extra) {
  637. -    strcpy(buf, "   [No Date]   ");
  638. -    return (buf);
  639. -    }
  640. -
  641. -    /* only print weekDay if one was stored and if we're in FULL mode */
  642. -    if (!brief && tptr->weekDay) {
  643. -    (void) sprintf(buf, "%s, ", WD[tptr->weekDay]);
  644. -    } else {
  645. -    buf[0] = '\0';
  646. -    }
  647. -    if (brief == 2) {    /* special case for ARCZOO format */
  648. -    (void) sprintf(buf2, "%.2d-%s-%.2d  %.2d:%.2d%c",
  649. -        (tptr->day)+1, MO[tptr->month], tptr->year,
  650. -        tptr->hour > 12 ? tptr->hour-12 : tptr->hour, tptr->minute,
  651. -        tptr->hour > 12 ? 'p' : 'a');
  652. -    } else {
  653. -    (void) sprintf(buf2, "%.2d-%s-%.2d  %.2d:%.2d",
  654. -        (tptr->day)+1, MO[tptr->month], tptr->year,
  655. -        tptr->hour, tptr->minute);
  656. -    }
  657. -    (void) strcat(buf, buf2);
  658. -    if (!brief) {  /* add seconds to long output */
  659. -    (void) sprintf(buf2, ":%.2d", tptr->second);
  660. -    (void) strcat(buf, buf2);
  661. -    }
  662. -    return (buf);
  663. -}
  664. -
  665. -
  666. -/*
  667. - * Dump contents of the threads (used by FULL view mode)
  668. - */
  669. -static void DumpThreads(RNodePtr)
  670. -RNode *RNodePtr;
  671. -{
  672. -    int i;
  673. -    fourbyt count = RNodePtr->RHptr->total_threads;
  674. -    static char ind[4] = "   ";  /* indentation */
  675. -    THblock *THptr;
  676. -    TNode *TNodePtr;
  677. -
  678. -    /* go through all threads, printing as we go */
  679. -    TNodePtr = RNodePtr->TNodePtr;
  680. -    for (i = 0; (fourbyt) i < count; i++) {
  681. -    if (TNodePtr == (TNode *) NULL) {
  682. -        fprintf(stderr, "WARNING: fewer threads than expected\n");
  683. -        return;
  684. -    }
  685. -    THptr = TNodePtr->THptr;
  686. -
  687. -    printf("%s --> Information for thread %d\n", ind, i);
  688. -    printf("%s thread_class: %s\n", ind, THptr->thread_class < TCn ?
  689. -        TC[THptr->thread_class] : unknownStr);
  690. -    printf("%s thread_format: %s\n", ind, THptr->thread_format < TFn ?
  691. -        TF[THptr->thread_format] : unknownStr);
  692. -    printf("%s thread_kind: %s ($%.2X)\n", ind,
  693. -        (THptr->thread_kind < TKn && THptr->thread_class < TCn) ?
  694. -        TK[THptr->thread_class][THptr->thread_kind] : unknownStr,
  695. -        THptr->thread_kind);
  696. -    printf("%s thread_crc: $%.4x\n", ind, THptr->thread_crc);
  697. -    printf("%s thread_eof: %lu   ", ind, THptr->thread_eof);
  698. -    printf("comp_thread_eof: %lu\n", THptr->comp_thread_eof);
  699. -    printf("%s * position within file: %ld\n", ind, TNodePtr->fileposn);
  700. -
  701. -    TNodePtr = TNodePtr->TNext;
  702. -    }
  703. -    /* after all info printed, show sum total of thread lengths */
  704. -    printf("%s * total thread_eof: %lu   ", ind, RNodePtr->unc_len);
  705. -    printf("total comp_thread_eof: %lu\n", RNodePtr->comp_len);
  706. -}
  707. -
  708. -
  709. -/*
  710. - * Scan contents of the threads for certain things (for PROSHK view mode)
  711. - * Returns 65535 as error code (-1 in an unsigned short).
  712. - * Places the format, compressed EOF, and uncompressed EOF in the location
  713. - * pointed to by the appropriate variables.
  714. - *
  715. - * This will probably fail if there are > 32767 threads.
  716. - */
  717. -static twobyt ScanThreads(RNodePtr, format, dataCEOF, dataEOF)
  718. -RNode *RNodePtr;
  719. -twobyt *format;  /* format of the data_fork thread */
  720. -long *dataCEOF;  /* length of the data_fork thread (compressed) */
  721. -long *dataEOF;  /* length of the data_fork thread (uncompressed) */
  722. -{
  723. -    int i;
  724. -    int count;
  725. -    THblock *THptr;
  726. -    TNode *TNodePtr;
  727. -
  728. -    count = (int) RNodePtr->RHptr->total_threads;
  729. -    *format = 65535;  /* default = error */
  730. -    *dataCEOF = 0L;
  731. -    *dataEOF = 0L;
  732. -    TNodePtr = RNodePtr->TNodePtr;
  733. -    for (i = 0; i < count; i++) {
  734. -    if (TNodePtr == (TNode *) NULL) {
  735. -        fprintf(stderr, "WARNING: fewer threads than expected\n");
  736. -        return (65535);
  737. -    }
  738. -    THptr = TNodePtr->THptr;
  739. -
  740. -    if (THptr->thread_class == 2) {  /* data thread? */
  741. -        *format = THptr->thread_format;
  742. -        *dataCEOF = THptr->comp_thread_eof;
  743. -        *dataEOF = THptr->thread_eof;
  744. -        return (THptr->thread_kind);
  745. -    }
  746. -    TNodePtr = TNodePtr->TNext;
  747. -    }
  748. -    return (65535);  /* no data thread found */
  749. -}
  750. -
  751. -
  752. -/*
  753. - * View archive contents
  754. - *
  755. - * Format types:
  756. - *    T: NAMEONLY - Brief output of filenames only (good for pipes)
  757. - *    V: PROSHK - ProDOS ShrinkIt format
  758. - *    A: ARCZOO - Format similar to ARC or ZOO
  759. - *    Z: FULL - Fully detailed output
  760. - */
  761. -void NuView(filename, options)
  762. -char *filename;
  763. -char *options;
  764. -{
  765. -    ListHdr *archive;
  766. -    MHblock *MHptr;
  767. -    RHblock *RHptr;
  768. -    RNode *RNodePtr;
  769. -    outtype prtform;
  770. -    int rec;
  771. -    char tmpbuf[80];  /* temporary buffer for sprintf + printf */
  772. -    twobyt format, datakind;  /* PROSHK */
  773. -    int percent;  /* PROSHK */
  774. -    long dataCEOF, dataEOF;  /* PROSHK */
  775. -    int total_files = 0, total_length = 0, total_complen = 0;    /* ARCZOO */
  776. -
  777. -#ifdef APW  /* kill "not used" messages */
  778. -    char *ptr;
  779. -#endif
  780. -    static char *procName = "NuView";
  781. -
  782. -    /* process options ourselves */
  783. -    switch (options[0]) {
  784. -    case 't':
  785. -    if (INDEX(options+1, 'v')) prtform = PROSHK;  /* -tv is same as -v */
  786. -    else if (INDEX(options+1, 'a')) prtform = ARCZOO;
  787. -    else if (INDEX(options+1, 'z')) prtform = FULL;
  788. -    else prtform = NAMEONLY;
  789. -    break;
  790. -    case 'v':
  791. -    prtform = PROSHK;
  792. -    break;
  793. -    default:
  794. -    fprintf(stderr, "%s internal error: unknown output format\n", prgName);
  795. -    Quit (-1);
  796. -    }
  797. -
  798. -    archive = NuRead(filename);
  799. -    MHptr = archive->MHptr;
  800. -
  801. -    /* Print master header info */
  802. -    if (prtform == NAMEONLY) {
  803. -    /* don't print any info from master header for NAMEONLY */
  804. -    } else if (prtform == PROSHK) {
  805. -#ifdef APW
  806. -    /* strip partial paths from APW filename (if any) */
  807. -    ptr = RINDEX(archive->arc_name, '/');
  808. -    printf(" %-15.15s ", ptr ? ptr+1 : archive->arc_name);
  809. -#else
  810. -    printf(" %-15.15s ", archive->arc_name);
  811. -#endif
  812. -    printf("Created:%s   ", PrintDate(&MHptr->arc_create_when, TRUE));
  813. -    printf("Mod:%s     ", PrintDate(&MHptr->arc_mod_when, TRUE));
  814. -    printf("Recs:%5lu\n\n", MHptr->total_records);
  815. -    printf(" Name                  Kind  Typ  Auxtyp Archived");
  816. -    printf("        Fmat Size  Un-Length\n");
  817. -    printf("-------------------------------------------------") ;
  818. -    printf("----------------------------\n");
  819. -    } else if (prtform == ARCZOO) {
  820. -    printf("Name                      Length    Stowage    SF   Size now");
  821. -    printf("  Date       Time  \n");
  822. -    printf("========================  ========  ========  ====  ========");
  823. -    printf("  =========  ======\n");
  824. -    } else if (prtform == FULL) {
  825. -    printf("Now processing archive '%s'\n", archive->arc_name);
  826. -    printf("---> Master header information:\n");
  827. -    printf("master ID: '%.6s'   ", MHptr->ID);
  828. -    printf("master_version: $%.4x   ", MHptr->master_version);
  829. -    printf("master_crc: $%.4X\n", MHptr->master_crc);
  830. -    printf("total_records: %lu    ", MHptr->total_records);
  831. -    if (MHptr->master_version >= 0x0001) {
  832. -        printf("master_eof: %lu\n", MHptr->master_eof);
  833. -    } else {
  834. -        printf("\n");
  835. -    }
  836. -    printf("created: %s   ", PrintDate(&MHptr->arc_create_when, FALSE));
  837. -    printf("mod: %s\n", PrintDate(&MHptr->arc_mod_when, FALSE));
  838. -    } else {
  839. -    printf("NuView internal error: undefined output format\n");
  840. -    Quit (-1);
  841. -    }
  842. -
  843. -    /* Print record info */
  844. -    RNodePtr = archive->RNodePtr;
  845. -    for (rec = 0; (fourbyt) rec < MHptr->total_records; rec++) {
  846. -    if (RNodePtr == (RNode *) NULL) {
  847. -        fprintf(stderr, "WARNING: fewer records than expected\n");
  848. -        return;
  849. -    }
  850. -    RHptr = RNodePtr->RHptr;
  851. -
  852. -    if (prtform == NAMEONLY) {
  853. -        printf("%.79s\n", RNodePtr->filename);  /* max 79 chars */
  854. -    } else if (prtform == PROSHK) {
  855. -        printf("%c", (RHptr->access == 0xE3L || RHptr->access == 0xC3L) ?
  856. -        ' ' : '+');
  857. -        printf("%-21.21s ", RNodePtr->filename);
  858. -        /* get info on data_fork thread */
  859. -        datakind = ScanThreads(RNodePtr, &format, &dataCEOF, &dataEOF);
  860. -        if (datakind == 65535) {  /* no data thread... */
  861. -        printf("????  ");
  862. -        printf("%s  ", RHptr->file_type < 256L ? FT[RHptr->file_type] :
  863. -            "???");
  864. -        printf("$%.4X  ", (twobyt) RHptr->extra_type);
  865. -        } else if (datakind == 1) {  /* disk */
  866. -        printf("Disk  ");
  867. -        printf("---  ");
  868. -        (void) sprintf(tmpbuf, "%dk", (twobyt) RHptr->extra_type / 2);
  869. -        printf("%-5s  ", tmpbuf);
  870. -        } else {  /* must be a file */
  871. -        printf("File  ");
  872. -        printf("%s  ", RHptr->file_type < 256L ? FT[RHptr->file_type] :
  873. -            "???");
  874. -        printf("$%.4X  ", (twobyt) RHptr->extra_type);
  875. -        }
  876. -        printf("%s  ", PrintDate(&RHptr->archive_when, TRUE));
  877. -        printf("%s  ", format < QTFn ? QTF[format] : "???");
  878. -
  879. -        /* figure out the percent size, and format it appropriately */
  880. -        /* Note RNodePtr->comp_len corresponds to dataCEOF, and */
  881. -        /*      RNodePtr->unc_len corresponds to dataEOF.       */
  882. -        if (!dataCEOF && !dataEOF) {
  883. -        printf("100%%  ");  /* file is 0 bytes long */
  884. -        } else if ((!dataEOF && dataCEOF) || (dataEOF && !dataCEOF)) {
  885. -        printf("---   ");  /* something weird happened */
  886. -        } else if (dataEOF < dataCEOF) {
  887. -        printf(">100%% ");  /* compression failed?!? */
  888. -        } else {  /* compute from sum of thread lengths (use only data?) */
  889. -        percent = (dataCEOF * 100) / dataEOF;
  890. -        (void) sprintf(tmpbuf, "%.2d%%", percent);
  891. -        printf("%-4s  ", tmpbuf);
  892. -        }
  893. -        if (!dataEOF && dataCEOF)  /* weird */
  894. -        printf("   ????\n");
  895. -        else
  896. -        printf("%7ld\n", dataEOF);    /* was 8ld */
  897. -    } else if (prtform == ARCZOO) {
  898. -        printf("%-24.24s  ", RNodePtr->filename);
  899. -        datakind = ScanThreads(RNodePtr, &format, &dataCEOF, &dataEOF);
  900. -        printf("%8ld  ", dataEOF);
  901. -        printf("%-8.8s  ", format < BTFn ? BTF[format] : "Unknown");
  902. -
  903. -        /* figure out the percent size, and format it appropriately */
  904. -        /* Note RNodePtr->comp_len corresponds to dataCEOF, and */
  905. -        /*      RNodePtr->unc_len corresponds to dataEOF.       */
  906. -        if (!dataCEOF && !dataEOF) {
  907. -        printf("  0%%  ");  /* file is 0 bytes long */
  908. -        } else if ((!dataEOF && dataCEOF) || (dataEOF && !dataCEOF)) {
  909. -        printf("---   ");  /* something weird happened */
  910. -        } else if (dataEOF < dataCEOF) {
  911. -        printf(" <0%%  ");  /* compression failed?!? */
  912. -        } else {  /* compute from sum of thread lengths (use only data?) */
  913. -        percent = 100 - ((dataCEOF * 100) / dataEOF);
  914. -        if (percent == 0 || percent == 100)
  915. -            (void) sprintf(tmpbuf, "%d%%", percent);
  916. -        else
  917. -            (void) sprintf(tmpbuf, "%.2d%%", percent);
  918. -        printf("%4s  ", tmpbuf);
  919. -        }
  920. -        printf("%8ld  ", dataCEOF);
  921. -        printf("%s\n", PrintDate(&RHptr->mod_when, 2));
  922. -
  923. -        total_files++;
  924. -        total_length += dataEOF;
  925. -        total_complen += dataCEOF;
  926. -    } else if (prtform == FULL) {
  927. -        printf("\n---> Information for record %d:\n", rec);
  928. -        printf("Filename: (%d) '%s'\n",
  929. -                RNodePtr->filename_length, RNodePtr->filename);
  930. -        printf("header ID: '%.4s'   ", RHptr->ID);
  931. -        printf("version_number: $%.4X   ", RHptr->version_number);
  932. -        printf("header_crc: $%.4X\n", RHptr->header_crc);
  933. -        printf("attrib_count: %u   ", RHptr->attrib_count);
  934. -        printf("total_threads: %u\n", RHptr->total_threads);
  935. -        printf("file_sys_id: %s   ", RHptr->file_sys_id < FIDn ?
  936. -        FID[RHptr->file_sys_id] : unknownStr);
  937. -        printf("sep: '%c'\n", RHptr->file_sys_info);
  938. -        if (RHptr->file_sys_id == 0x0001) {  /* ProDOS-specific */
  939. -        printf("access: %s ($%.8lX)   ", (RHptr->access == 0xE3L ||
  940. -        RHptr->access == 0xC3L) ? "Unlocked" : "Locked", RHptr->access);
  941. -        printf("file_type: %s ($%.8lX)\n", RHptr->file_type < 256L ?
  942. -            FT[RHptr->file_type] : "???", RHptr->file_type);
  943. -        } else {  /* all other filesystems */
  944. -        printf("access: $%.8lX   ", RHptr->access);
  945. -        printf("file_type: $%.8lX\n", RHptr->file_type);
  946. -        }
  947. -        printf("extra_type: $%.8lX   ", RHptr->extra_type);
  948. -        printf("storage_type: %s\n", RHptr->storage_type < STn ?
  949. -        ST[RHptr->storage_type] : unknownStr);
  950. -        printf("created: %s   ", PrintDate(&RHptr->create_when, FALSE));
  951. -        printf("mod: %s\n", PrintDate(&RHptr->mod_when, FALSE));
  952. -        printf("archived: %s\n", PrintDate(&RHptr->archive_when,
  953. -            FALSE));
  954. -        printf("GS/OS option_size: %.4x\n", RHptr->option_size);
  955. -        /* future expansion... */
  956. -    } else {
  957. -        printf("%s internal error: undefined output format\n", prgName);
  958. -        Quit (-1);
  959. -    }
  960. -
  961. -    /* Print thread info */
  962. -    if (prtform == FULL) DumpThreads(RNodePtr);
  963. -    RNodePtr = RNodePtr->RNext;  /* advance to next record */
  964. -#ifdef APW
  965. -    if (STOP()) Quit (1);  /* check for OA-period */
  966. -#endif
  967. -    }
  968. -
  969. -    /* end of archive processing */
  970. -    if (prtform == ARCZOO) {
  971. -    printf(
  972. -        "                     ===  ========            ====  ========\n");
  973. -    printf("Total                ");
  974. -    printf("%3d  ", total_files);
  975. -    printf("%8ld            ", total_length);
  976. -
  977. -    /* figure out the percent size, and format it appropriately */
  978. -    if (!total_complen && !total_length) {
  979. -        printf("  0%%  ");  /* file is 0 bytes long */
  980. -    } else if ((!total_length && total_complen) ||
  981. -                    (total_length && !total_complen)) {
  982. -        printf("---   ");  /* something weird happened */
  983. -    } else if (total_length < total_complen) {
  984. -        printf(" <0%%  ");  /* compression failed?!? */
  985. -    } else {  /* compute from sum of thread lengths (use only data?) */
  986. -        percent = 100 - ((total_complen * 100) / total_length);
  987. -        if (percent == 0 || percent == 100)
  988. -        (void) sprintf(tmpbuf, "%d%%", percent);
  989. -        else
  990. -        (void) sprintf(tmpbuf, "%.2d%%", percent);
  991. -        printf("%4s  ", tmpbuf);
  992. -    }
  993. -
  994. -    printf("%8ld\n", total_complen);
  995. -
  996. -    } else if (prtform == FULL) {
  997. -    printf("\n*** end of file position: %ld\n", archive->nextposn);
  998. -    }  /* else do nothing */
  999. -}
  1000. + END OF ARCHIVE
  1001.