home *** CD-ROM | disk | FTP | other *** search
- From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
- Newsgroups: comp.sources.apple2
- Subject: v001SRC035: Nulib - Archive Library Tools (Unix) 04/10
- Message-ID: <May.1.18.10.42.1991.23491@yoko.rutgers.edu>
- Date: 1 May 91 22:10:44 GMT
- Approved: jac@paul.rutgers.edu
-
-
- Submitted-by: Andy McFadden (fadden@cory.berkeley.edu)
- Posting-number: Volume 1, Source:35
- Archive-name: archive/unix/nulib/part04.10
- Architecture: UNIX
- Version-number: 3.03
-
-
- =nucomp.h
- -/*
- - * nucomp.h - declarations for nucomp.c
- - *
- - * NuLib v3.0 February 1991 Freeware (distribute, don't sell)
- - * By Andy McFadden (fadden@cory.berkeley.edu)
- - */
- -
- -#ifdef BSD43
- -# define NO_SETVBUF
- -#endif
- -
- -#include <ctype.h>
- -#include <string.h>
- -#ifdef UNIX /* this is asking for trouble */
- -# include <sys/types.h>
- -#else
- -# ifdef IAPX286
- -# include <sys/types.h>
- -# else
- -# ifdef IAPX386
- -# include <sys/types.h>
- -# else
- -# include <types.h>
- -# endif
- -# endif
- -#endif
- -#include <fcntl.h>
- -
- -/*@H************************ < COMPRESS HEADER > ****************************
- -* $@(#) compress.c,v 4.3 88/12/26 08:00:00 don Release ^ *
- -* *
- -* compress : compress.h <global defines, etc> *
- -* *
- -* port by : Donald J. Gloistein *
- -* *
- -* Source, Documentation, Object Code: *
- -* released to Public Domain. This code is based on code as documented *
- -* below in release notes. *
- -* *
- -*--------------------------- Module Description --------------------------*
- -* THIS HEADER CONTAINS MUCH IMPLEMENTATION INFORMATION AND ASSUMPTIONS *
- -* PLEASE PRINT IT OUT AND READ IT BEFORE COMPILING CODE FOR YOURSELF *
- -* *
- -* This header supports a number of compiler defines and predefines. *
- -* Rather than explain all of them, please print the header and read the *
- -* notes. Also the unix and xenix makefiles are commented for the *
- -* various options. There continues to have a lot of Dos specific info in *
- -* the header. This is to help on 16 bit Msdos machines to get their *
- -* compiler to work properly. I make no appology for that, as this port *
- -* began as a way to implement 16 bit compress on a segmented MsDos machine*
- -* *
- -* However, for Unix and Xenix, all you should have to define is -DXENIX *
- -* or -DUNIX and compile. There may be a problem with whether your library *
- -* supports alloc() or malloc(), but there is a define for that, also. *
- -* *
- -* This header can be maintained to keep up with the different compilers *
- -* and systems. As distributed in don Release, the files will compile with *
- -* no changes under Microsoft version 5.1 C compiler, and Xenix C compiler *
- -* which is the Microsoft version 4 ported. If you are going to bind the *
- -* code for use in MsDos and OS/2 machines, then you must uncomment the *
- -* #define BIND in this header. Otherwise, this distribution of source *
- -* detect Msdos and Xenix predefines from the compiler and adjust. *
- -* *
- -*--------------------------- Implementation Notes --------------------------*
- -* *
- -* compiled with : compress.fns *
- -*
- -* NOTE!!! Defaults of this code now are completely Unix, even for the *
- -* msdos ports. That means that the program works as a filter, *
- -* and will just sit there waiting for input from stdin if you *
- -* issue just the command name. You must use -h or -? to get the *
- -* full help screen now. Also, it will unlink (kill) as a default *
- -* on successful compression and decompression. That means the *
- -* source file will be erased. *
- -* These defaults are changed with the FILTER and KEEPFLAG *
- -* defines. *
- -* *
- -* NOTE!!! Compiler predefines were taken out of the compress.h header. *
- -* You must either specify them on compile or uncomment the *
- -* compiler define in this header. Compiling without doing these *
- -* will result in a program that does unspecified actions. *
- -* problems: *
- -* The inpath and outpath is a bit kludged. It should work okay. *
- -* Let me know if you have problems, especially under Unix. *
- -* *
- -* CAUTION: The bound version will run on Dos 2.x, but you must use the *
- -* name compress.exe. If you rename the file, it will not run *
- -* The unbound version will run on Dos 2.x with the name changed *
- -* but due to the dos version, will not detect its own name. *
- -* *
- -* CAUTION: Non MsDos users. You must modify the _MAX_PATH defines for *
- -* your operating system if it is different from the assumed *
- -* standard. *
- -* *
- -* CAUTION: I have used a number of defines to make it possible to compile *
- -* properly under a number of bit sizes and adjust for the memory *
- -* allocation scheme needed. If you do not use a dos system, *
- -* PLEASE pay attention to the defines for MAXSEG_64 and the one *
- -* called SMALLMODEL. The SMALLMODEL define is set in the header *
- -* but if you don't have a compiler that triggers the MAXSEG_64 *
- -* define, you may end up with bad pointers. Becareful. *
- -* *
- -* Header for files using version 4 compress routines define MAIN *
- -* in the file with defining instance of the global variables. *
- -* There are a number of compilers for MsDos and Unix/Xenix. *
- -* So the user must define the actions required. *
- -* *
- -* *
- -* Defines: This header file contains most of the system wide defines. *
- -* the purpose for this was to consolodate compiler differences *
- -* into one area that is easily changed. *
- -* *
- -* define MAXBITS= if you want a different maximum bits. 16 bits will now *
- -* run in about 400K of memory. *
- -* define BIND if you are going to use Microsoft bind.exe program on the *
- -* executable. *
- -* *
- -* define MSDOS if you are compiling under MsDos or PcDos and your compiler*
- -* does not predefine it. *
- -* *
- -* Initials ---- Name --------------------------------- *
- -* DjG Donald J. Gloistein, current port to MsDos 16 bit *
- -* Plus many others, see rev.hst file for full list *
- -* LvR Lyle V. Rains, many thanks for improved implementation *
- -* of the compression and decompression routines. *
- -*************************************************************************@H*/
- -
- -#ifndef FALSE /* let's get some sense to this */
- -#define FALSE 0
- -#define TRUE !FALSE
- -#endif
- -
- -#define NDEBUG
- -#define NPROTO
- -#define COMP40 /* take this out for a little more speed */
- -char *malloc();
- -#define ALLOCATE(x,y) malloc((unsigned int)x*y)
- -#define FREEIT(ptr) free(ptr)
- -#define NOSIGNAL /* what the hell is "SIGTYPE"? */
- -#define setbinary(fp)
- -#define FAR
- -#define CONST
- -#define _MAX_DIR 64
- -
- -/* FILTER if you want the program to operate as a unix type filter */
- -/* if not defined TRUE, then issuing command without parameters will */
- -/* print a usage and help information */
- -/* Use -DFILTER=0 to deactivate filter operation */
- -#ifndef FILTER
- -#define FILTER FALSE
- -#endif
- -
- -/* KEEPFLAG determines the default action on successful completion */
- -/* Unix convention is FALSE (erase input file) */
- -/* Use -DKEEPFLAG=1 to keep files as default or change here */
- -/* if you don't set it before here and you are compiling the debug */
- -/* version, then files will be kept. */
- -
- -#ifndef KEEPFLAG
- -#define KEEPFLAG TRUE
- -#endif
- -
- -
- -
- -
- -/* the following tells the system that the maximum segment is 64k */
- -/* if your compiler is not one of these and has this limitation */
- -/* Because of this, this code should compile with minimum porting */
- -/* in the COMPUSI.XEN module to most unix systems. */
- -/* This is also used to keep array indexing to 16 bit integer */
- -/* if not predefined in compiler implementation, you must define */
- -/* it separately if applicable to your compiler/system */
- -
- -#define MAXSEG_64K
- -
- -/* put this in if you are compiling in small code */
- -/* model and your compiler does not predefine it */
- -/* this is for CPU' with 64k segment limitation. */
- -/* Use this define for small code, it is used by */
- -/* the header to decide on value for NEARHEAP */
- -/* #define SMALLMODEL */
- -
- -/* does your system use far pointers ? if you want it enabled keep this */
- -/* if you have segment limit and compile in larger than 13 bits */
- -/* then you will have to use compact or large model if your compiler */
- -/* does not support far pointer keyword. */
- -
- -#ifndef FAR
- -#define FAR
- -#endif
- -
- -/* What type does the alloc() function return, char or void? */
- -
- -#ifndef ALLOCTYPE
- -#define ALLOCTYPE char
- -#endif
- -
- -/* Does your run time library support the ANSI functions for:*/
- -
- -/* reverse string set search? strrpbrk() if not: */
- -#define NO_REVSEARCH
- -
- -/* Does your library include strrchr()? If not define this: */
- -/*#define NO_STRRCHR*//* unix/xenix module uses this function*/
- -
- -/* Does your library include strchr()? If not define this: */
- -/*#define NO_STRCHR*//* dos module uses this function. */
- -
- -/* definition for const key word if supported */
- -#ifndef CONST
- -#define CONST
- -#endif
- -
- -
- -/* And now for some typedefs */
- -typedef unsigned short CODE;
- -typedef unsigned char UCHAR;
- -typedef unsigned int HASH;
- -typedef int FLAG;
- -
- - /*
- - * You can define the value of MAXBITS to be anything betweeen MINBITS
- - * and MAXMAXBITS. This is will determine the maximum memory you will
- - * use and how the tables will be handled. I recommend you just leave
- - * it at MAXMAXBITS, because you can define DFLTBITS in compiling the
- - * module COMPRESS.C to set the default, and you can vary the number
- - * of bits at runtime by using the -b switch.
- - */
- -
- - /*
- - * The only reason to change MAXBITS is if you absolutely must have
- - * faster performance. If you specify 14 bits, the tables will not
- - * be split; at 13 bits, you can fit in the MSDOS small memory model
- - * and allocate tables in near heap.
- - * This value is available to other modules through the variable maxbits.
- - */
- -
- -#define INITBITS 9
- -#define MINBITS 12
- -#define MAXMAXBITS 16
- -
- -#ifndef MAXBITS
- -#define MAXBITS MAXMAXBITS
- -#endif
- -
- -#if (MAXBITS > MAXMAXBITS)
- -#undef MAXBITS
- -#define MAXBITS MAXMAXBITS
- -#endif
- -
- -#if (MAXBITS < MINBITS)
- -#undef MAXBITS
- -#define MAXBITS MINBITS
- -#endif
- -
- - /* You should define DFLTBITS to be the default compression code
- - * bit length you desire on your system.
- - * (I define mine in the compiler command line in my Makefile.LvR)
- - * (I leave mine alone and keep to the maximum. DjG)
- - */
- -
- -#ifndef DFLTBITS
- -#define DFLTBITS MAXBITS
- -#endif
- -#if (DFLTBITS < MINBITS)
- -#undef DFLTBITS
- -#define DFLTBITS MINBITS
- -#endif
- -#if (DFLTBITS > MAXBITS)
- -#undef DFLTBITS
- -#define DFLTBITS MAXBITS
- -#endif
- -
- -/* correcting for different types of pointer arithmatic */
- -/* probably won't have to change it */
- -#define NULLPTR(type) ((type FAR *) NULL)
- -
- -
- -/* in making this program portable the following allocation and */
- -/* free functions are called, with the following parameters: */
- -/* ALLOCTYPE FAR *emalloc(unsigned int x, int y) */
- -/* void efree(ALLOCTYPE FAR *ptr) */
- -/* you must define the allocation function and the free function */
- -/* keep in mind that the casts must be correct for your compiler */
- -/* NOTE these are the two functions to change for allocating pointers to */
- -/* far data space if you are not using Microsoft C v.5.1 */
- -/* Consult your compiler manual and find the low level function that */
- -/* returns a far pointer when compiled in the small model. */
- -/* if your compiler does not support that, you will have to compile with */
- -/* a model that defaults to far pointers to data (compact or large model)*/
- -/* HERE ARE SOME SAMPLE PREDEFINED ONES */
- -
- -
- -/* default allocation function, in segmented addressing, must return */
- -/* a far pointer or compile with far pointer data as default */
- -#ifndef ALLOCATE
- -#include <malloc.h>
- -#define ALLOCATE(x,y) malloc((unsigned int)x*y)
- -#define FREEIT(ptr) free((ptr))
- -#endif
- -
- -
- -# ifdef MAXSEG_64K
- -# if MAXBITS > 14
- -# define SPLIT_HT TRUE
- -# else
- -# define SPLIT_HT 0
- -# endif
- -# else
- -# define SPLIT_HT 0
- -# endif
- -
- -# ifdef MAXSEG_64K
- -# if MAXBITS > 15
- -# define SPLIT_PFX TRUE
- -# else
- -# define SPLIT_PFX 0
- -# endif
- -# else
- -# define SPLIT_PFX 0
- -# endif
- -
- -#ifndef BUFSIZ
- -#define BUFSIZ 512
- -#endif
- -
- -#ifdef NO_SETBUF
- -#define NO_SETVBUF
- -#endif
- -
- -/* NuLib: comment: this ought to use setbuffer() if available */
- -#ifdef NO_SETVBUF
- -# ifndef NO_SETBUF
- -# define setvbuf(fp,buf,mode,size) setbuf((fp),(buf))
- -# define ZBUFSIZE BUFSIZ
- -# define XBUFSIZE BUFSIZ
- -# else
- -# define setvbuf(fp,buf,mode,size)
- -# define ZBUFSIZE (1)
- -# define XBUFSIZE (1)
- -# endif
- -#else
- -# ifdef NEARHEAP
- -# define XBUFSIZE (0xC00)
- -# define ZBUFSIZE (0x1800)
- -# else
- -# define XBUFSIZE (0x3000) /* 12k bytes */
- -# define ZBUFSIZE (0x6000) /* 24k bytes */
- -# endif
- -#endif
- -
- -#define UNUSED ((CODE)0) /* Indicates hash table value unused */
- -#define CLEAR ((CODE)256) /* Code requesting table to be cleared */
- -#define FIRSTFREE ((CODE)(CLEAR+1))/* First free code for token encoding */
- -#define MAXTOKLEN 512 /* Max chars in token; size of buffer */
- -#define OK 0 /* Result codes from functions: */
- -#define ERROR 1
- -#define NORMAL 0
- -
- -#define SIGNAL_ERROR -1 /* signal function error */
- -#define NOMEM 2 /* Ran out of memory */
- -#define TOKTOOBIG 3 /* Token longer than MAXTOKLEN chars */
- -#define READERR 4 /* I/O error on input */
- -#define WRITEERR 5 /* I/O error on output */
- -#define INFILEBAD 6 /* Infile not in compressed format */
- -#define CODEBAD 7 /* Infile contained a bad token code */
- -#define TABLEBAD 8 /* The tables got corrupted (!) */
- -#define NOSAVING 9 /* no saving in file size */
- -#define NOTOPENED 10 /* output file couldn't be opened */
- -#define YES 1
- -#define NO 0
- -
- -
- -#include "nucompfn.h" /* This has to come late... needs typedefs above */
- -
- -/* defines opening mode for files */
- -/* and suffixes for compressed file */
- -
- -
- -#define WRITE_FILE_TYPE FWRITE_STR /* NuLib: was "wb" */
- -#define READ_FILE_TYPE FREAD_STR /* NuLib: was "rb" */
- -#define SUFFIX ".Z"
- -
- -/* Defines for third byte of header */
- -#define BIT_MASK 0x1f
- -#define BLOCK_MASK 0x80
- -/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
- - a fourth header byte (for expansion).
- -*/
- -
- -
- -#define CHECK_GAP 10000L /* ratio check interval */
- -
- -#ifdef MAIN
- -UCHAR magic_header[] = { 0x1F,0x9D }; /* 1F 9D */
- -
- -char rcs_ident[] = "@(#) compress,v 4.3 88/12/26 08:00:00 don Release $";
- -
- -int overwrite = 0; /* Do not overwrite unless given -f flag */
- -int maxbits = DFLTBITS; /* user settable max # bits/code */
- -
- -int exit_stat = 0;
- -int keep = KEEPFLAG; /* True = don't kill file */
- -int keep_error = FALSE; /* True = keep output file even if error exist */
- -char *prog_name;
- -char ifname[_MAX_DIR];
- -char inpath[_MAX_DIR];
- -char ofname [_MAX_DIR];
- -char outpath[_MAX_DIR];
- -int is_list = FALSE; /* flag for file parameters */
- -char endchar[1];
- -char xbuf[XBUFSIZE];
- -char zbuf[ZBUFSIZE];
- -char separator[] = "/";
- -
- -int nomagic = FALSE; /* Use a 3-byte magic number header, unless old file */
- -int zcat_flg = TRUE; /* Write output on stdout, suppress messages */
- -int quiet = TRUE; /* don't tell me about compression */
- -/*
- - * block compression parameters -- after all codes are used up,
- - * and compression rate changes, start over.
- - */
- -int block_compress = BLOCK_MASK;
- -#ifdef COMP40
- -long int ratio = 0L;
- -long checkpoint = CHECK_GAP;
- -#endif
- -
- -/* force the overwrite */
- -int force = 0;
- -
- -#ifndef NDEBUG
- -int verbose = FALSE;
- -int debug = FALSE;
- -#endif /* !NDEBUG */
- -
- -int do_decomp = FALSE;
- -
- -#else /* not defining instance */
- -
- -extern UCHAR magic_header[];
- -extern char rcs_ident[];
- -extern int overwrite;
- -extern int maxbits;
- -
- -
- -extern int exit_stat;
- -extern int keep;
- -extern int keep_error;
- -extern char *prog_name;
- -extern char inpath[];
- -extern char outpath[];
- -extern int is_list;
- -extern char endchar[];
- -extern char xbuf[];
- -extern char zbuf[];
- -extern char ifname[];
- -extern char ofname[];
- -extern char separator[];
- -extern int nomagic;
- -extern int zcat_flg;
- -extern int quiet;
- -extern int block_compress;
- -#ifdef COMP40
- -extern long int ratio;
- -extern long checkpoint;
- -#endif
- -extern int force;
- -
- -#ifndef NDEBUG
- -extern int verbose;
- -extern int debug;
- -#endif /* !NDEBUG */
- -
- -extern int do_decomp;
- -#endif
- -
- =nuview.c
- -/*
- - * nuview.c - prints the contents of a NuFX archive
- - *
- - * NuLib v3.0 February 1991 Freeware (distribute, don't sell)
- - * By Andy McFadden (fadden@cory.berkeley.edu)
- - */
- -#ifdef APW
- -segment "NuMain"
- -#endif
- -
- -#include "nudefs.h"
- -#include <stdio.h>
- -#ifdef BSD43
- -# include <strings.h>
- -#else /* SYSV, APW, MSC */
- -# include <string.h>
- -#endif
- -
- -#ifdef APW
- -# include <shell.h>
- -#endif
- -
- -#include "nuview.h"
- -#include "nuread.h"
- -#include "nuetc.h"
- -
- -
- -/*
- - * String definitions for NuView
- - */
- -/* unknown value msg */
- -char *unknownStr = "[ unknown ]";
- -
- -/* weekDay values */
- -char *WD[8] = { "[ null ]", "Sunday", "Monday", "Tuesday", "Wednesday",
- - "Thursday", "Friday", "Saturday" };
- -
- -/* month values */
- -char *MO[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
- - "Aug", "Sep", "Oct", "Nov", "Dec" };
- -
- -/* thread_class */
- -/*#define TCn 4*/
- -char *TC[TCn] = { "Message_thread", "Control_thread", "Data_thread",
- - "Filename_thread" };
- -
- -/*#define TKn 3 /* max #of thread_kinds in a thread_class */
- -char *TK[TCn][TKn] = {
- - { "ASCII text", "ASCII text (predef size)", "<undef>" },
- - { "Create directory", "<undef>", "<undef>" },
- - { "File data_fork", "Disk image", "File resource_fork" },
- - { "Generic filename", "<undef>", "<undef>" } };
- -
- -/* thread_format */
- -/*#define TFn 6*/
- -char *TF[TFn] = { "Uncompressed", "SQueezed (SQ/USQ)",
- - "Dynamic LZW Type I (ShrinkIt)",
- - "Dynamic LZW Type II (ShrinkIt)", "12-bit UNIX compress",
- - "16-bit UNIX compress" };
- -
- -/* brief thread format */
- -/*#define BTFn 6*/
- -char *BTF[BTFn] = { "Uncompr", "SQueezed", "LZW/1", "LZW/2", "Unix/12",
- - "Unix/16" };
- -
- -/* quick thread_format */
- -/*#define QTFn 6*/
- -char *QTF[QTFn] = { "unc", "squ", "shk", "sh2", "u12", "u16" };
- -
- -/* file_sys_id */
- -/*#define FIDn 14*/
- -char *FID[FIDn] = { "Reserved/unknown ($00)", "ProDOS/SOS", "DOS 3.3",
- - "DOS 3.2", "Apple II Pascal", "Macintosh (MFS)",
- - "Macintosh (HFS)", "LISA file system", "Apple CP/M",
- - "Reserved ($09)", "MS-DOS", "High-Sierra", "ISO 9660",
- - "AppleShare" };
- -
- -/* storage_type */
- -/*#define STn 14*/
- -char *ST[STn] = { "Standard file ($00)", "Standard file ($01)",
- - "Standard file ($02)", "Standard file ($03)", "??? ($04)",
- - "Extended file ($05)", "??? ($06)", "??? ($07)", "??? ($08)",
- - "??? ($09)", "??? ($0a)", "??? ($0b)", "??? ($0c)",
- - "Subdirectory ($0d)" };
- -
- -/* file type names */
- -char *FT[256] = {
- - "NON", "BAD", "PCD", "PTX", "TXT", "PDA", "BIN", "CHR",
- - "PIC", "BA3", "DA3", "WPD", "SOS", "$0D", "$0E", "DIR",
- - "RPD", "RPI", "$12", "OUT", "$14", "RPT", "$16", "$17",
- - "$18", "ADB", "AWP", "ASP", "$1C", "$1D", "$1E", "$1F",
- - "$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27",
- - "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F",
- - "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37",
- - "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F",
- - "$40", "$41", "$42", "$43", "$44", "$45", "$46", "$47",
- - "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F",
- - "$50", "$51", "$52", "$53", "$54", "$55", "$56", "$57",
- - "$58", "$59", "$5A", "$5B", "$5C", "$5D", "$5E", "$5F",
- - "PRE", "$61", "$62", "$63", "$64", "$65", "$66", "$67",
- - "$68", "$69", "$6A", "NIO", "$6C", "DVR", "$6E", "HDV",
- - "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77",
- - "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F",
- - "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87",
- - "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F",
- - "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97",
- - "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F",
- - "WPF", "MAC", "HLP", "DAT", "$A4", "LEX", "$A6", "$A7",
- - "$A8", "$A9", "$AA", "GSB", "ARC", "$AD", "$AE", "$AF",
- - "SRC", "OBJ", "LIB", "S16", "RTL", "EXE", "STR", "TSF",
- - "NDA", "CDA", "TOL", "DRV", "$BC", "FST", "$BE", "DOC",
- - "PNT", "SCR", "ANI", "$C3", "$C4", "$C5", "$C6", "$C7",
- - "FON", "FND", "ICN", "$CB", "$CC", "$CD", "$CE", "$CF",
- - "$D0", "$D1", "$D2", "$D3", "$D4", "$D5", "$D6", "$D7",
- - "$D8", "$D9", "$DA", "$DB", "$DC", "DDD", "$DE", "$DF",
- - "LBR", "$E1", "ATI", "$E3", "$E4", "$E5", "$E6", "$E7",
- - "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "$EE", "PAS",
- - "CMD", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7",
- - "$F8", "IMG", "INT", "IVR", "BAS", "VAR", "REL", "SYS" };
- -
- -
- -/*
- - * NuView program
- - */
- -
- -/* print date from Time structure */
- -char *PrintDate(tptr, brief)
- -Time *tptr;
- -int brief;
- -{
- - static char buf[64]; /* holds final date string; must be static */
- - char buf2[64]; /* space to hold string while building it */
- -
- - /* check for validity */
- - if ( (tptr->day > 30) || (tptr->month > 11) || (tptr->hour > 24) ||
- - (tptr->minute > 59) ) {
- - strcpy(buf, " <invalid> ");
- - return (buf);
- - }
- -
- - if (!tptr->second && !tptr->minute && !tptr->hour && !tptr->day &&
- - !tptr->month && !tptr->year && !tptr->weekDay && !tptr->extra) {
- - strcpy(buf, " [No Date] ");
- - return (buf);
- - }
- -
- - /* only print weekDay if one was stored and if we're in FULL mode */
- - if (!brief && tptr->weekDay) {
- - (void) sprintf(buf, "%s, ", WD[tptr->weekDay]);
- - } else {
- - buf[0] = '\0';
- - }
- - if (brief == 2) { /* special case for ARCZOO format */
- - (void) sprintf(buf2, "%.2d-%s-%.2d %.2d:%.2d%c",
- - (tptr->day)+1, MO[tptr->month], tptr->year,
- - tptr->hour > 12 ? tptr->hour-12 : tptr->hour, tptr->minute,
- - tptr->hour > 12 ? 'p' : 'a');
- - } else {
- - (void) sprintf(buf2, "%.2d-%s-%.2d %.2d:%.2d",
- - (tptr->day)+1, MO[tptr->month], tptr->year,
- - tptr->hour, tptr->minute);
- - }
- - (void) strcat(buf, buf2);
- - if (!brief) { /* add seconds to long output */
- - (void) sprintf(buf2, ":%.2d", tptr->second);
- - (void) strcat(buf, buf2);
- - }
- - return (buf);
- -}
- -
- -
- -/*
- - * Dump contents of the threads (used by FULL view mode)
- - */
- -static void DumpThreads(RNodePtr)
- -RNode *RNodePtr;
- -{
- - int i;
- - fourbyt count = RNodePtr->RHptr->total_threads;
- - static char ind[4] = " "; /* indentation */
- - THblock *THptr;
- - TNode *TNodePtr;
- -
- - /* go through all threads, printing as we go */
- - TNodePtr = RNodePtr->TNodePtr;
- - for (i = 0; (fourbyt) i < count; i++) {
- - if (TNodePtr == (TNode *) NULL) {
- - fprintf(stderr, "WARNING: fewer threads than expected\n");
- - return;
- - }
- - THptr = TNodePtr->THptr;
- -
- - printf("%s --> Information for thread %d\n", ind, i);
- - printf("%s thread_class: %s\n", ind, THptr->thread_class < TCn ?
- - TC[THptr->thread_class] : unknownStr);
- - printf("%s thread_format: %s\n", ind, THptr->thread_format < TFn ?
- - TF[THptr->thread_format] : unknownStr);
- - printf("%s thread_kind: %s ($%.2X)\n", ind,
- - (THptr->thread_kind < TKn && THptr->thread_class < TCn) ?
- - TK[THptr->thread_class][THptr->thread_kind] : unknownStr,
- - THptr->thread_kind);
- - printf("%s thread_crc: $%.4x\n", ind, THptr->thread_crc);
- - printf("%s thread_eof: %lu ", ind, THptr->thread_eof);
- - printf("comp_thread_eof: %lu\n", THptr->comp_thread_eof);
- - printf("%s * position within file: %ld\n", ind, TNodePtr->fileposn);
- -
- - TNodePtr = TNodePtr->TNext;
- - }
- - /* after all info printed, show sum total of thread lengths */
- - printf("%s * total thread_eof: %lu ", ind, RNodePtr->unc_len);
- - printf("total comp_thread_eof: %lu\n", RNodePtr->comp_len);
- -}
- -
- -
- -/*
- - * Scan contents of the threads for certain things (for PROSHK view mode)
- - * Returns 65535 as error code (-1 in an unsigned short).
- - * Places the format, compressed EOF, and uncompressed EOF in the location
- - * pointed to by the appropriate variables.
- - *
- - * This will probably fail if there are > 32767 threads.
- - */
- -static twobyt ScanThreads(RNodePtr, format, dataCEOF, dataEOF)
- -RNode *RNodePtr;
- -twobyt *format; /* format of the data_fork thread */
- -long *dataCEOF; /* length of the data_fork thread (compressed) */
- -long *dataEOF; /* length of the data_fork thread (uncompressed) */
- -{
- - int i;
- - int count;
- - THblock *THptr;
- - TNode *TNodePtr;
- -
- - count = (int) RNodePtr->RHptr->total_threads;
- - *format = 65535; /* default = error */
- - *dataCEOF = 0L;
- - *dataEOF = 0L;
- - TNodePtr = RNodePtr->TNodePtr;
- - for (i = 0; i < count; i++) {
- - if (TNodePtr == (TNode *) NULL) {
- - fprintf(stderr, "WARNING: fewer threads than expected\n");
- - return (65535);
- - }
- - THptr = TNodePtr->THptr;
- -
- - if (THptr->thread_class == 2) { /* data thread? */
- - *format = THptr->thread_format;
- - *dataCEOF = THptr->comp_thread_eof;
- - *dataEOF = THptr->thread_eof;
- - return (THptr->thread_kind);
- - }
- - TNodePtr = TNodePtr->TNext;
- - }
- - return (65535); /* no data thread found */
- -}
- -
- -
- -/*
- - * View archive contents
- - *
- - * Format types:
- - * T: NAMEONLY - Brief output of filenames only (good for pipes)
- - * V: PROSHK - ProDOS ShrinkIt format
- - * A: ARCZOO - Format similar to ARC or ZOO
- - * Z: FULL - Fully detailed output
- - */
- -void NuView(filename, options)
- -char *filename;
- -char *options;
- -{
- - ListHdr *archive;
- - MHblock *MHptr;
- - RHblock *RHptr;
- - RNode *RNodePtr;
- - outtype prtform;
- - int rec;
- - char tmpbuf[80]; /* temporary buffer for sprintf + printf */
- - twobyt format, datakind; /* PROSHK */
- - int percent; /* PROSHK */
- - long dataCEOF, dataEOF; /* PROSHK */
- - int total_files = 0, total_length = 0, total_complen = 0; /* ARCZOO */
- -
- -#ifdef APW /* kill "not used" messages */
- - char *ptr;
- -#endif
- - static char *procName = "NuView";
- -
- - /* process options ourselves */
- - switch (options[0]) {
- - case 't':
- - if (INDEX(options+1, 'v')) prtform = PROSHK; /* -tv is same as -v */
- - else if (INDEX(options+1, 'a')) prtform = ARCZOO;
- - else if (INDEX(options+1, 'z')) prtform = FULL;
- - else prtform = NAMEONLY;
- - break;
- - case 'v':
- - prtform = PROSHK;
- - break;
- - default:
- - fprintf(stderr, "%s internal error: unknown output format\n", prgName);
- - Quit (-1);
- - }
- -
- - archive = NuRead(filename);
- - MHptr = archive->MHptr;
- -
- - /* Print master header info */
- - if (prtform == NAMEONLY) {
- - /* don't print any info from master header for NAMEONLY */
- - } else if (prtform == PROSHK) {
- -#ifdef APW
- - /* strip partial paths from APW filename (if any) */
- - ptr = RINDEX(archive->arc_name, '/');
- - printf(" %-15.15s ", ptr ? ptr+1 : archive->arc_name);
- -#else
- - printf(" %-15.15s ", archive->arc_name);
- -#endif
- - printf("Created:%s ", PrintDate(&MHptr->arc_create_when, TRUE));
- - printf("Mod:%s ", PrintDate(&MHptr->arc_mod_when, TRUE));
- - printf("Recs:%5lu\n\n", MHptr->total_records);
- - printf(" Name Kind Typ Auxtyp Archived");
- - printf(" Fmat Size Un-Length\n");
- - printf("-------------------------------------------------") ;
- - printf("----------------------------\n");
- - } else if (prtform == ARCZOO) {
- - printf("Name Length Stowage SF Size now");
- - printf(" Date Time \n");
- - printf("======================== ======== ======== ==== ========");
- - printf(" ========= ======\n");
- - } else if (prtform == FULL) {
- - printf("Now processing archive '%s'\n", archive->arc_name);
- - printf("---> Master header information:\n");
- - printf("master ID: '%.6s' ", MHptr->ID);
- - printf("master_version: $%.4x ", MHptr->master_version);
- - printf("master_crc: $%.4X\n", MHptr->master_crc);
- - printf("total_records: %lu ", MHptr->total_records);
- - if (MHptr->master_version >= 0x0001) {
- - printf("master_eof: %lu\n", MHptr->master_eof);
- - } else {
- - printf("\n");
- - }
- - printf("created: %s ", PrintDate(&MHptr->arc_create_when, FALSE));
- - printf("mod: %s\n", PrintDate(&MHptr->arc_mod_when, FALSE));
- - } else {
- - printf("NuView internal error: undefined output format\n");
- - Quit (-1);
- - }
- -
- - /* Print record info */
- - RNodePtr = archive->RNodePtr;
- - for (rec = 0; (fourbyt) rec < MHptr->total_records; rec++) {
- - if (RNodePtr == (RNode *) NULL) {
- - fprintf(stderr, "WARNING: fewer records than expected\n");
- - return;
- - }
- - RHptr = RNodePtr->RHptr;
- -
- - if (prtform == NAMEONLY) {
- - printf("%.79s\n", RNodePtr->filename); /* max 79 chars */
- - } else if (prtform == PROSHK) {
- - printf("%c", (RHptr->access == 0xE3L || RHptr->access == 0xC3L) ?
- - ' ' : '+');
- - printf("%-21.21s ", RNodePtr->filename);
- - /* get info on data_fork thread */
- - datakind = ScanThreads(RNodePtr, &format, &dataCEOF, &dataEOF);
- - if (datakind == 65535) { /* no data thread... */
- - printf("???? ");
- - printf("%s ", RHptr->file_type < 256L ? FT[RHptr->file_type] :
- - "???");
- - printf("$%.4X ", (twobyt) RHptr->extra_type);
- - } else if (datakind == 1) { /* disk */
- - printf("Disk ");
- - printf("--- ");
- - (void) sprintf(tmpbuf, "%dk", (twobyt) RHptr->extra_type / 2);
- - printf("%-5s ", tmpbuf);
- - } else { /* must be a file */
- - printf("File ");
- - printf("%s ", RHptr->file_type < 256L ? FT[RHptr->file_type] :
- - "???");
- - printf("$%.4X ", (twobyt) RHptr->extra_type);
- - }
- - printf("%s ", PrintDate(&RHptr->archive_when, TRUE));
- - printf("%s ", format < QTFn ? QTF[format] : "???");
- -
- - /* figure out the percent size, and format it appropriately */
- - /* Note RNodePtr->comp_len corresponds to dataCEOF, and */
- - /* RNodePtr->unc_len corresponds to dataEOF. */
- - if (!dataCEOF && !dataEOF) {
- - printf("100%% "); /* file is 0 bytes long */
- - } else if ((!dataEOF && dataCEOF) || (dataEOF && !dataCEOF)) {
- - printf("--- "); /* something weird happened */
- - } else if (dataEOF < dataCEOF) {
- - printf(">100%% "); /* compression failed?!? */
- - } else { /* compute from sum of thread lengths (use only data?) */
- - percent = (dataCEOF * 100) / dataEOF;
- - (void) sprintf(tmpbuf, "%.2d%%", percent);
- - printf("%-4s ", tmpbuf);
- - }
- - if (!dataEOF && dataCEOF) /* weird */
- - printf(" ????\n");
- - else
- - printf("%7ld\n", dataEOF); /* was 8ld */
- - } else if (prtform == ARCZOO) {
- - printf("%-24.24s ", RNodePtr->filename);
- - datakind = ScanThreads(RNodePtr, &format, &dataCEOF, &dataEOF);
- - printf("%8ld ", dataEOF);
- - printf("%-8.8s ", format < BTFn ? BTF[format] : "Unknown");
- -
- - /* figure out the percent size, and format it appropriately */
- - /* Note RNodePtr->comp_len corresponds to dataCEOF, and */
- - /* RNodePtr->unc_len corresponds to dataEOF. */
- - if (!dataCEOF && !dataEOF) {
- - printf(" 0%% "); /* file is 0 bytes long */
- - } else if ((!dataEOF && dataCEOF) || (dataEOF && !dataCEOF)) {
- - printf("--- "); /* something weird happened */
- - } else if (dataEOF < dataCEOF) {
- - printf(" <0%% "); /* compression failed?!? */
- - } else { /* compute from sum of thread lengths (use only data?) */
- - percent = 100 - ((dataCEOF * 100) / dataEOF);
- - if (percent == 0 || percent == 100)
- - (void) sprintf(tmpbuf, "%d%%", percent);
- - else
- - (void) sprintf(tmpbuf, "%.2d%%", percent);
- - printf("%4s ", tmpbuf);
- - }
- - printf("%8ld ", dataCEOF);
- - printf("%s\n", PrintDate(&RHptr->mod_when, 2));
- -
- - total_files++;
- - total_length += dataEOF;
- - total_complen += dataCEOF;
- - } else if (prtform == FULL) {
- - printf("\n---> Information for record %d:\n", rec);
- - printf("Filename: (%d) '%s'\n",
- - RNodePtr->filename_length, RNodePtr->filename);
- - printf("header ID: '%.4s' ", RHptr->ID);
- - printf("version_number: $%.4X ", RHptr->version_number);
- - printf("header_crc: $%.4X\n", RHptr->header_crc);
- - printf("attrib_count: %u ", RHptr->attrib_count);
- - printf("total_threads: %u\n", RHptr->total_threads);
- - printf("file_sys_id: %s ", RHptr->file_sys_id < FIDn ?
- - FID[RHptr->file_sys_id] : unknownStr);
- - printf("sep: '%c'\n", RHptr->file_sys_info);
- - if (RHptr->file_sys_id == 0x0001) { /* ProDOS-specific */
- - printf("access: %s ($%.8lX) ", (RHptr->access == 0xE3L ||
- - RHptr->access == 0xC3L) ? "Unlocked" : "Locked", RHptr->access);
- - printf("file_type: %s ($%.8lX)\n", RHptr->file_type < 256L ?
- - FT[RHptr->file_type] : "???", RHptr->file_type);
- - } else { /* all other filesystems */
- - printf("access: $%.8lX ", RHptr->access);
- - printf("file_type: $%.8lX\n", RHptr->file_type);
- - }
- - printf("extra_type: $%.8lX ", RHptr->extra_type);
- - printf("storage_type: %s\n", RHptr->storage_type < STn ?
- - ST[RHptr->storage_type] : unknownStr);
- - printf("created: %s ", PrintDate(&RHptr->create_when, FALSE));
- - printf("mod: %s\n", PrintDate(&RHptr->mod_when, FALSE));
- - printf("archived: %s\n", PrintDate(&RHptr->archive_when,
- - FALSE));
- - printf("GS/OS option_size: %.4x\n", RHptr->option_size);
- - /* future expansion... */
- - } else {
- - printf("%s internal error: undefined output format\n", prgName);
- - Quit (-1);
- - }
- -
- - /* Print thread info */
- - if (prtform == FULL) DumpThreads(RNodePtr);
- - RNodePtr = RNodePtr->RNext; /* advance to next record */
- -#ifdef APW
- - if (STOP()) Quit (1); /* check for OA-period */
- -#endif
- - }
- -
- - /* end of archive processing */
- - if (prtform == ARCZOO) {
- - printf(
- - " === ======== ==== ========\n");
- - printf("Total ");
- - printf("%3d ", total_files);
- - printf("%8ld ", total_length);
- -
- - /* figure out the percent size, and format it appropriately */
- - if (!total_complen && !total_length) {
- - printf(" 0%% "); /* file is 0 bytes long */
- - } else if ((!total_length && total_complen) ||
- - (total_length && !total_complen)) {
- - printf("--- "); /* something weird happened */
- - } else if (total_length < total_complen) {
- - printf(" <0%% "); /* compression failed?!? */
- - } else { /* compute from sum of thread lengths (use only data?) */
- - percent = 100 - ((total_complen * 100) / total_length);
- - if (percent == 0 || percent == 100)
- - (void) sprintf(tmpbuf, "%d%%", percent);
- - else
- - (void) sprintf(tmpbuf, "%.2d%%", percent);
- - printf("%4s ", tmpbuf);
- - }
- -
- - printf("%8ld\n", total_complen);
- -
- - } else if (prtform == FULL) {
- - printf("\n*** end of file position: %ld\n", archive->nextposn);
- - } /* else do nothing */
- -}
- + END OF ARCHIVE
-