Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!sun-barr!ames!xanth!nic.MR.NET!shamash!com50!midgard!syntel!dal From: dal@syntel.UUCP (Dale Schumacher) Newsgroups: comp.os.minix Subject: Compress 4.3 sources (part 1 of 2) Keywords: Compress Message-ID: <041789A8734@syntel.UUCP> Date: 17 May 89 07:37:32 GMT Reply-To: dal@syntel.UUCP (Dale Schumacher) Lines: 1199 X-Member-Of: STdNET (ST Developer's Network) # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # readme # makefile # compress.h # compress.fns # compusi.c # This archive created: 17-May-1989 1:35:28 ENOENV # By: ENOENV (ENOENV) cat << \SHAR_EOF > readme The enclosed files are the COMPRESS v4.3 file compression utility with modifications to compile on Minix-ST v1.1 with the ACK compiler. This version supports compression/decompression with up to 16 bits. It probably WON'T work (at least for >13 bit compression) under Minix-PC. Dale Schumacher bungia!midgard.mn.org!syntel!dal -or- dal@syntel.UUCP Notes on the port to MINIX-ST: The get_one() function fails because MINIX won't support the dubious practice of reading from fd=2 (aka stderr). Instead, "/dev/tty" is opened and read from directly. This may not be the best way to handle this problem, but it works. I took the example from the Minix distribution sources (compress.c,v 4.1 85/12/05 09:00:00 kent). The defaults for the version of compress which was supplied with the MINIX-ST 1.1 distribution are apparently quite different from those of current Unix implementations. I've added a compile-time switch to allow 'verbose' to be default TRUE. I've also taken advantange of the switch for making 'keep source' also default TRUE. The comments in the code imply that both of these options are typically defaulted to FALSE, but I've chosen to remain as close to the original compress as possible. Similarly, the default number of bits to use is 13, although up to 16 will work properly. In order to do 16-bit compression, you must "chmem =400000 compress". If you still get a "not enough memory to compress" error, bump the chmem value up a bit more. If you only want to use 13 bits maximum for compression, "chmem =65000" seems to be sufficient. Decompression takes far less space, so 16-bit decompression can be done even with the smaller chmem value. You may even be able to make the value smaller and still do decompression, but the initial value from the compiler of about 45000 is not large enough to compress with 13 bits. Just for peace-of-mind, I have verified that this compress can decompress files created with the original compress, and the original compress can decompress files created with this new compress, as long as you don't use more than 13 bits (of course). SHAR_EOF cat << \SHAR_EOF > makefile # # MAKE FILE FOR UNIX SYSTEMS (MINIX) # add what optimizion options your system supports # on some systems there may be no setvbuf() or the code may generate # errors if the large buffer is used for the stream, if so : # add -DNO_SETVBUF (this is done in compress.h under #ifdef UNIX -Dal) # and if your system doesn't support either setvbuf or setbuf # add -DNO_SETBUF # add -DALLOC if your system uses alloc() instead of malloc() # add -DNOSIGNAL for faster processing on a unix pc CFLAGS=-DMINIX -DUNIX -DNDEBUG OFLAGS= LIB= PROG=compress OBJ=compress.o compusi.o compapi.o BIN=/usr/bin $(PROG): $(OBJ) cc -o $(PROG) $(OFLAGS) $(OBJ) $(LIB) chmem =400000 $(PROG) install: cp $(PROG) $(BIN) ln $(BIN)/$(PROG) $(BIN)/uncompress ln $(BIN)/$(PROG) $(BIN)/zcat compapi.o: compress.h compress.o: compress.h compusi.o: compress.h SHAR_EOF cat << \SHAR_EOF > compress.h /*@H************************ < COMPRESS HEADER > **************************** * $@(#) compress.c,v 4.3 88/12/26 08:00:00 don Release ^ * * * * compress : compress.h * * * * 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 #ifdef UNIX #define NPROTO #define COMP40 /* take this out for a little more speed */ #ifdef ALLOC char *alloc(); #define ALLOCATE(x,y) alloc((unsigned int)x*y) #else char *malloc(); #define ALLOCATE(x,y) malloc((unsigned int)x*y) #endif #define FREEIT(ptr) free(ptr) #define setbinary(fp) #define NO_SETVBUF /* most don't support setvbuf() function */ #endif /* NOTE: This program will not work on the */ /* IBM/PC version of MINIX due to the small */ /* memory model restrictions. There is no */ /* such thing as a FAR pointer in MINIX-PC */ #ifdef MINIX /* Unix V7 clone for Atari ST */ #define strchr index #define strrchr rindex #define DFLTBITS 13 /* compatible with original MINIX compress, max=16 */ #ifndef KEEPFLAG #define KEEPFLAG 1 /* compatible with original MINIX compress */ /* may be redefined from the Makefile if desired */ #endif #ifndef VERBOSE #define VERBOSE TRUE /* compatible with original MINIX compress */ /* may be redefined from the Makefile if desired */ #endif #define NPROTO #define SIGTYPE int /* MINIX defines this as pointer to int */ /* for the return from a signal */ #endif /* Microsoft C compiler v 4.0-5.1 */ /* MSC is defined in makefile.msc */ #ifdef MSC #define FAR far #define MAXSEG_64K #define NO_REVSEARCH #define CONST const #define ALLOCTYPE void #ifdef M_I86SM #define SMALLMODEL /* compiled in small model */ #endif #define setbinary(fp) setmode(fileno((fp)), O_BINARY) #endif /* Mark Williams C for Atari ST (V3.0.5) */ /* MWC is defined in makefile.mwc */ #ifdef MWC #define MSDOS #define NOSIGNAL #define DFLTBITS 14 #define NPROTO /* #define MAXSEG_64K */ /* use this if your compiler has a problem with */ /* indexing arrays larger than 64k */ #define NO_SETVBUF #define NO_REVSEARCH #define ALLOCATE(x,y) lcalloc((unsigned long)(x),((unsigned long)(unsigned)(y))) #define FREEIT(ptr) free(ptr) #define setbinary(fp) ((fp)->_ff &= ~_FASCII) #endif /* Sozobon or Alcyon (4.14) C for Atari ST */ /* used with the dLibs standard library */ #ifdef ALCYON #define SOZOBON 1 #endif #ifdef SOZOBON #define MSDOS #define NOSIGNAL #define DFLTBITS 14 #define NPROTO /* #define MAXSEG_64K */ /* use this if your compiler has a problem with */ /* indexing arrays larger than 64k */ #define ALLOCATE(x,y) lalloc((unsigned long)(x) * ((unsigned long)(y))) #define FREEIT(ptr) free(ptr) #define setbinary(fp) ((fp)->_flag |= _IOBIN) #define FILTER FALSE #endif #ifdef __ZTC__ /* Zortech compiler */ #define setbinary(fp) ((fp)->_flag&=~_IOTRAN) #define NO_REVSEARCH #define CONST const #define MAXSEG_64K #endif #ifdef XENIX #define setbinary(fp) #define FAR far #define CONST #define SIGTYPE int /* xenix defines this as pointer to int */ /* for the return from a signal */ #ifdef M_I286 #define MAXSEG_64K #endif #define NO_SETVBUF /* evidently xenix chokes on the large buff*/ #endif /* really needs to be fine tuned */ #ifdef MCH_AMIGA #define CONST #define MAXSEG_64K /* Manx C compiler limitation */ #define NO_SETVBUF #endif #ifdef vms #define NO_SETVBUF #endif #ifdef __TURBOC__ #define MSDOS #define MAXSEG_64 #define NO_REVSEARCH #ifdef __SMALL__ #define SMALLMODEL #endif #define CONST const #define FAR far #define setbinary(fp) setmode(fileno((fp)), O_BINARY) #endif /* 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 TRUE #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 #ifdef NDEBUG #define KEEPFLAG FALSE #else #define KEEPFLAG TRUE #endif #endif /* Does your compiler support extended prototyping? */ /* Uncomment the following if your compiler does not.*/ /* support full prototyping, such as: */ /* char *emalloc(unsigned,int); */ /* if defined it will use the following: */ /* char *emalloc(); */ /* #define NPROTO */ /* putting the include files in one location */ #include #ifdef MINIX #define assert(x) extern char *index(), *rindex(), *strcat(), *strcpy(), *strncat(), *strncpy(); #else #include #include #endif #ifndef NOSIGNAL #include #endif #ifdef MWC #include #include #include #else #ifdef SOZOBON #include #include #include #include #include #else #include #include #endif #endif #ifdef M_XENIX #include #endif #ifdef MSC #include #include #include #include #include #endif #ifdef __TURBOC__ #include #include #include #include #endif #ifndef NOSIGNAL #ifndef SIGTYPE #define SIGTYPE void #endif #ifndef SIG_ERR #define SIG_ERR (SIGTYPE(*)())-1 #endif #endif /* This is for Microsoft C v5.1 to compile and be bound */ /* for use with os/2. Also if compiled just for os/2 */ /* The signal function is different between protected */ /* and real mode. */ /* #define BIND */ #ifdef INCL_DOSPROCESS #define ISOS2 TRUE #endif #ifdef BIND #define ISOS2 TRUE #endif /* The following is defined in MSC 5.1 stdlib.h Replace with appropriate values for your system. These values are used for MSDos system. */ #ifndef _MAX_PATH #define _MAX_PATH 144 /* max. length of full pathname */ #define _MAX_DRIVE 3 /* max. length of drive component */ #define _MAX_DIR 130 /* max. length of path component */ #define _MAX_FNAME 9 /* max. length of file name component */ #define _MAX_EXT 5 /* max. length of extension component */ #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 /* If you use compusi.dos and your computer supports the unix */ /* file links and the link code is set properly in the stat() */ /* then define the following: */ /* #define USE_LINKS */ /* Does your run time library support the ANSI functions for:*/ /* reverse string set search? strrpbrk() if so: */ /*#define NO_REVSEARCH*//* dos module uses this function. */ /* #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 /* THIS IS TO COMPILE A 13 BIT MODEL IN SMALL MEMORY AND NEAR HEAP */ /* AS SET UP IT WILL WORK WITH MICROSOFT C COMPILER */ #if (MAXBITS < 14) #ifdef SMALLMODEL #define NEARHEAP TRUE #undef FAR #define FAR #endif #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 */ #ifdef MSC #include #ifdef NEARHEAP #define ALLOCATE(x,y) malloc((size_t)((x)*(y))) #define FREEIT(ptr) free((ptr)) #else #define ALLOCATE(x,y) _fmalloc((size_t)((x)*(y))) #define FREEIT(ptr) _ffree((ptr)) #endif #endif #ifdef HUGE #include #define ALLOCATE(x,y) halloc((long)(x),(size_t)(y)) #define FREEIT(ptr) hfree(ptr) #endif #ifdef __TURBOC__ #include #ifdef NEARHEAP #define ALLOCATE(x,y) malloc((unsigned int)((x)*(y))) #define FREEIT(x) free(x) #else #define ALLOCATE(x,y) farmalloc((unsigned long)((x)*(y))) #define FREEIT(x) farfree(x) #endif #endif /* default allocation function, in segmented addressing, must return */ /* a far pointer or compile with far pointer data as default */ #ifndef ALLOCATE #include #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 #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: */ #ifdef vms #define ERROR 0x10000004 /* General unspecified error */ #define NORMAL 1 /* No error */ #define unlink(x) remove(x) #else # define NORMAL 0 # ifdef ERROR # if (ERROR == NORMAL) # define ERROR 1 /* force redefine if (ERROR == NORMAL) */ # endif # else # define ERROR 1 # endif #endif #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 "compress.fns" /* defines opening mode for files */ /* and suffixes for compressed file */ #ifdef MSDOS #define WRITE_FILE_TYPE "wb" #define READ_FILE_TYPE "rb" #define SUFFIX "Z" #else #ifdef vms #define SUFFIX "_Z" #define WRITE_FILE_TYPE "wb" #define READ_FILE_TYPE "rb" #else #define WRITE_FILE_TYPE "w" #define READ_FILE_TYPE "r" #define SUFFIX ".Z" #endif #endif /* The VERBOSE flag defines the default value of the verbose variable */ /* If it's not already defined, we set it to FALSE here since most */ /* systems set the default that way. -Dal */ #ifndef VERBOSE #define VERBOSE FALSE #endif /* 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 $"; #ifdef MWC long _stksize = 20000L; /* set MWC's stack to 20,000 */ #ifdef MWC_NAME /* if defined in makefile set _cmdname for */ char _cmdname[]=MWC_NAME; /* compress,zcat,uncomp check for desktop and */ #endif /* dumb shells */ #endif #ifdef SOZOBON long _STKSIZ = 20000L; /* set runtime stack to 20,000 bytes */ #ifndef CMDNAME #define CMDNAME "compress" #endif char _cmdname[]=CMDNAME; /* force command name */ #endif 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]; #ifdef MSDOS char separator[] = "\\"; #else char separator[] = "/"; #endif int nomagic = FALSE; /* Use a 3-byte magic number header, unless old file */ int zcat_flg = FALSE; /* Write output on stdout, suppress messages */ int quiet = !VERBOSE; /* 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 = VERBOSE; int debug = FALSE; #endif /* !NDEBUG */ #ifndef NOSIGNAL SIGTYPE (*bgnd_flag)(); #endif int do_decomp = FALSE; #else /* not defining instance */ extern UCHAR magic_header[]; extern char rcs_ident[]; #ifdef MWC extern long _stksize; #endif 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 */ #ifndef NOSIGNAL extern SIGTYPE (*bgnd_flag)(); #endif extern int do_decomp; #endif SHAR_EOF cat << \SHAR_EOF > compress.fns /* COMPRESS.FNS global function declarations */ /* this should be compatible with any type of declaration for external functions. See compress.h for explaination */ #ifdef NPROTO extern void Usage(); extern int check_error(); extern char *name_index(); extern char *get_program_name(); #ifdef NO_STRCHR extern char *strchr(); #endif #ifdef NO_STRRCHR extern char *strrchr(); #endif #ifdef NO_REVSEARCH extern char *strrpbrk(); #endif extern char get_one(); extern int is_z_name(); extern int cl_block(); extern int make_z_name(); extern void unmake_z_name(); extern void compress(); extern void putcode(); extern void decompress(); extern CODE getcode(); extern void writeerr(); extern void copystat(); #ifndef NOSIGNAL extern int foreground(); extern SIGTYPE onintr(); extern SIGTYPE oops(); #endif extern void prratio(); extern void version(); #ifdef NEARHEAP extern ALLOCTYPE *emalloc(); extern void efree(); #else extern ALLOCTYPE FAR *emalloc(); extern void efree(); #endif extern int alloc_tables(); extern void init_tables(); extern int nextcode(); #else extern void Usage(int); extern int check_error(void); extern char *name_index(char *); extern int cl_block(void); extern char *get_program_name(char *); extern char get_one(void); extern int is_z_name(char *); extern int make_z_name(char *); extern void unmake_z_name(char *); #ifdef NO_STRCHR extern char *strchr(char *,int); #endif #ifdef NO_STRRCHR extern char *strrchr(char *,int); #endif #ifdef NO_REVSEARCH extern char *strrpbrk(char *,char *); #endif extern void compress(void); extern void putcode(CODE,int); extern void decompress(void); extern CODE getcode(void); extern void writeerr(void); extern void copystat(char *,char *); #ifndef NOSIGNAL extern int foreground(void); extern SIGTYPE onintr(void); extern SIGTYPE oops(void); #endif extern void prratio(FILE *,long,long); extern void version(void); #ifdef NEARHEAP extern ALLOCTYPE *emalloc(unsigned int,int); extern void efree(ALLOCTYPE *); #else extern ALLOCTYPE FAR *emalloc(unsigned int,int); extern void efree(ALLOCTYPE FAR *); #endif extern int alloc_tables(CODE,HASH); extern void init_tables(void ); extern int nextcode(CODE *); #endif SHAR_EOF cat << \SHAR_EOF > compusi.c /*@H************************ < COMPRESS utility> **************************** * * * compress : compusi.uni * * * * port by : Donald J. Gloistein * * * * Source, Documentation, Object Code: * * released to Public Domain. This code is ported from compress v4.0 * * release joe. * * * *--------------------------- Module Description --------------------------* * Unix system dependent routines. These are specific to either the * * unix file structure or some unix only functions. * * * * Separated out for ease of writing the main module. * * * *--------------------------- Implementation Notes --------------------------* * * * compiled with : compress.h compress.fns * * linked with : compress.o compapi.o * * * * To use, copy or rename this file to compusi.c and recompile. * * Set the defines in compress.h to reflect the status of your compiler's * * runtime library, allocation type for malloc()'s, and memory models if * * applicable, and your library function call for malloc() and free(). * * * * problems: header has some hardcoded defines you may need to change * * for your compiler. Please read the header thoroughly. * * * *--------------------------- Author(s) -------------------------* * Initials ---- Name --------------------------------- * * DjG Donald J. Gloistein * * Plus many others, see rev.hst file for full list * * LvR Lyle V. Rains, thanks for the improved implementation * * of the compression and decompression routines. * *************************************************************************@H*/ #include #include "compress.h" /* contains the rest of the include file declarations */ /* For those who don't have it in libc.a */ #ifdef NO_STRRCHR char *strrchr(s,c) char *s; int c; { register int count; while (*s){ s++; count++; } s--; while (count--) if (*s == (char)c) return(s); else s--; return(NULL); } #endif char *get_program_name(ptr) char *ptr; { char *cp; if ((cp = strrchr(ptr, '/')) != NULL) cp++; else cp = ptr; if(strcmp(cp,"uncompress") == 0) { do_decomp = 1; } else if(strcmp(cp, "zcat") == 0) { keep = TRUE; zcat_flg = do_decomp = 1; } return (cp); } char *name_index(ptr) char *ptr; { char *p; p = strrchr(ptr,'/'); return ((p)? ++p: ptr); } int is_z_name(ptr) /* checks if it is already a z name */ char *ptr; { return (!(strcmp(ptr + strlen(ptr) -2,".Z"))); } int make_z_name(ptr) char *ptr; { #ifndef BSD4_2 if (strlen(name_index(ptr)) > 12 ) { fprintf(stderr,"%s: filename too long to add .Z\n",name_index(ptr)); return FALSE; } #endif strcat(ptr,".Z"); return TRUE; } void unmake_z_name(ptr) char *ptr; { register int len = strlen(ptr)-2; ptr[len] = '\0'; } #ifndef NOSIGNAL SIGTYPE onintr ( ) { if (!zcat_flg && !keep_error){ fclose(stdout); unlink ( ofname ); } exit ( ERROR ); } SIGTYPE oops ( ) /* wild pointer -- assume bad input */ { if ( do_decomp == 1 ) fprintf ( stderr, "%s: corrupt input: %s\n",prog_name,ifname); if (!zcat_flg && !keep_error){ fclose(stdout); unlink ( ofname ); } exit ( ERROR ); } #endif void copystat(ifname, ofname) char *ifname, *ofname; { struct stat statbuf; int mode; time_t timep[2]; fclose(stdout); if (stat(ifname, &statbuf)) { /* Get stat on input file */ perror(ifname); return; } if ((statbuf.st_mode & S_IFMT/*0170000*/) != S_IFREG/*0100000*/) { if(quiet) fprintf(stderr, "%s: ", ifname); fprintf(stderr, " -- not a regular file: unchanged"); exit_stat = 1; } else if (statbuf.st_nlink > 1) { if(quiet) fprintf(stderr, "%s: ", ifname); fprintf(stderr, " -- has %d other links: unchanged", statbuf.st_nlink - 1); exit_stat = ERROR; } else if (exit_stat == NOSAVING && (!force)) { /* No compression: remove file.Z */ if(!quiet) fprintf(stderr, " -- no savings -- file unchanged"); } else if (exit_stat == NOMEM){ if (!quiet) fprintf(stderr, " -- file unchanged"); if (!do_decomp) exit(ERROR); else return; /* otherwise will unlink outfile */ } else if (exit_stat == OK) { /* ***** Successful Compression ***** */ mode = statbuf.st_mode & 07777; if (chmod(ofname, mode)) /* Copy modes */ perror(ofname); chown(ofname,statbuf.st_uid,statbuf.st_gid); /* Copy Ownership */ timep[0] = statbuf.st_atime; timep[1] = statbuf.st_mtime; utime(ofname,timep); /* Update last accessed and modified times */ if (!keep){ fclose(stdin); if (unlink(ifname)) /* Remove input file */ perror(ifname); if(!quiet) fprintf(stderr, " -- replaced with %s", ofname); } else{ if(!quiet) fprintf(stderr, " -- compressed to %s", ofname); } return; /* Successful return */ } /* Unsuccessful return -- one of the tests failed */ fclose(stdout); if (unlink(ofname)) perror(ofname); } void version() { #ifdef XENIX #ifndef NDEBUG fprintf(stderr, "%s\nOptions: Xenix %s MAXBITS = %d\n", rcs_ident, "DEBUG",MAXBITS); #else fprintf(stderr, "%s\nOptions: Xenix MAXBITS = %d\n", rcs_ident,MAXBITS); #endif #else #ifndef NDEBUG fprintf(stderr, "%s\nOptions: Unix %s MAXBITS = %d\n", rcs_ident, "DEBUG",MAXBITS); #else fprintf(stderr, "%s\nOptions: Unix MAXBITS = %d\n", rcs_ident,MAXBITS); #endif #endif } ALLOCTYPE FAR *emalloc(x,y) unsigned int x; int y; { ALLOCTYPE FAR *p; p = (ALLOCTYPE FAR *)ALLOCATE(x,y); return(p); } void efree(ptr) ALLOCTYPE FAR *ptr; { FREEIT(ptr); } SHAR_EOF # End of shell archive exit 0 -- Dale Schumacher 399 Beacon Ave. (alias: Dalnefre') St. Paul, MN 55104-3527 ...bungia!midgard.mn.org!syntel!dal United States of America "I may be competitive, but I'm never ruthless"