Xref: wupost comp.sys.mac.comm:5695 comp.sys.mac.misc:16422 alt.sources:3867 alt.sources.d:2363 Path: wupost!uunet!mcsun!hp4nl!cwi.nl From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.sys.mac.comm,comp.sys.mac.misc,alt.sources,alt.sources.d Subject: MAC archive unpacker, patch01 Message-ID: <4089@charon.cwi.nl> Date: 19 Aug 91 00:11:01 GMT Sender: news@cwi.nl Followup-To: comp.sys.mac.comm Organization: CWI, Amsterdam Lines: 771 #! /bin/sh #This sharchive updates the Mac archive unpacker I posted about a month ago in #alt.sources. Instructions: # Go to the directory where you unpacked teh previous sharchives (it # should have a subdirectory named 'macutil'), unpack this sharchive. # That will create two files: # macutil/unpack/patchlevel.h # and patch01 # If you have Larry Wall's patch utility enter the command: # patch -p now. I have found no occurrences where it #was not allowed, but just in case, it is conditional (see the makefile). This #version compiles and runs on: Alliant, Encore, Sun4, SGI, IBM 3090 and Cray YMP #(how is that for portability!). # #I think the next version will come out in 4 to 6 weeks. It will include a #debinhexer (similar to mcvert and xbin as found in the archives). But this #will allow niceties as: # cat /usr/spool/news/binaries/mac/* | hexbin | unpack #How is that for wetting your appetite? # #Still, if you have problems, notify me; it will help me to find bugs. #Especially, if you find PackIt, StuffIt or Compactor archives that the #program refuses to unpack, or where errors are reported. # #dik #-- #dik t. winter, cwi, amsterdam, nederland #dik@cwi.nl #--------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # macutil # patch01 # This archive created: Mon Aug 19 01:29:33 1991 export PATH; PATH=/bin:/usr/bin:$PATH if test ! -d 'macutil' then echo shar: "You are unpacking in the wrong place; see the instructions." echo shar: "I am continuing anyhow." echo shar: "creating directory 'macutil'" mkdir 'macutil' fi echo shar: "entering directory 'macutil'" cd 'macutil' if test ! -d 'unpack' then echo shar: "creating directory 'unpack'" mkdir 'unpack' fi echo shar: "entering directory 'unpack'" cd 'unpack' echo shar: "extracting 'patchlevel.h'" '(21 characters)' if test -f 'patchlevel.h' then echo shar: "will not over-write existing file 'patchlevel.h'" else sed 's/^X//' << \SHAR_EOF > 'patchlevel.h' X#define PATCHLEVEL 1 SHAR_EOF if test 21 -ne "`wc -c < 'patchlevel.h'`" then echo shar: "error transmitting 'patchlevel.h'" '(should have been 21 characters)' fi fi echo shar: "done with directory 'unpack'" cd .. echo shar: "done with directory 'macutil'" cd .. echo shar: "extracting 'patch01'" '(15710 characters)' if test -f 'patch01' then echo shar: "will not over-write existing file 'patch01'" else sed 's/^X//' << \SHAR_EOF > 'patch01' X*** macutil.old/makefile Sun Jul 14 03:15:48 1991 X--- macutil/makefile Mon Aug 19 01:23:36 1991 X*************** X*** 2,8 **** X BINDIR = /ufs/dik/bin X # remove -DBSD if you are not on a BSD system. X # add -DNOMKDIR if your system does not have the mkdir system call. X! CF = -DNODOT -DBSD X IF = X # If you want AUFS support use the following two lines: X #CF = -DNODOT -DBSD -DAUFS_SUPPORT X--- 2,9 ---- X BINDIR = /ufs/dik/bin X # remove -DBSD if you are not on a BSD system. X # add -DNOMKDIR if your system does not have the mkdir system call. X! # remove -DTYPES_H if your system does not have /usr/include/sys/types.h X! CF = -DNODOT -DBSD -DTYPES_H X IF = X # If you want AUFS support use the following two lines: X #CF = -DNODOT -DBSD -DAUFS_SUPPORT X*** macutil.old/unpack.1 Sun Jul 14 03:08:35 1991 X--- macutil/unpack.1 Mon Aug 19 01:19:13 1991 X*************** X*** 57,62 **** X--- 57,65 ---- X .B \-q X Ask the user for every file/folder whether it should be extracted X (implies -l) X+ .B \-V X+ Gives the patchlevel of the program. X+ Other options are ignored and the program quits immediately. X .SH BUGS X As this is a beta release, there may still be some problems. Archives X that are password protected, multi-file archives, and files archived X*** macutil.old/fileio/fileglob.h Sun Jul 14 03:08:26 1991 X--- macutil/fileio/fileglob.h Mon Aug 19 01:19:14 1991 X*************** X*** 1,12 **** X- #define TEXT 0 X- #define DATA 1 X- #define RSRC 2 X- #define FULL 3 X- #define MACB 4 X- #define FORK 5 X- #define AUFS 6 X- X extern int bytes_read, bytes_written; X extern char *out_buffer, *out_ptr; X! extern int mode; X X--- 1,4 ---- X extern int bytes_read, bytes_written; X extern char *out_buffer, *out_ptr; X! extern int filopt(); X X*** macutil.old/fileio/fileio.c Sun Jul 14 03:08:26 1991 X--- macutil/fileio/fileio.c Mon Aug 19 01:21:57 1991 X*************** X*** 1,3 **** X--- 1,6 ---- X+ #ifdef TYPES_H X+ #include X+ #endif /* TYPES_H */ X #include X #include X #include "../machdr/machdr.h" X*************** X*** 8,13 **** X--- 11,24 ---- X #include X #endif /* AUFS_SUPPORT */ X X+ #define TEXT 0 X+ #define DATA 1 X+ #define RSRC 2 X+ #define FULL 3 X+ #define MACB 4 X+ #define FORK 5 X+ #define AUFS 6 X+ X char *malloc(); X char *realloc(); X X*************** X*** 26,34 **** X #define RSRC_FORK 2 X #define DATA_FORK 3 X X! #ifdef BSD X char *sprintf(); X! #endif /* BSD */ X X char f_info[I_NAMELEN]; X char f_data[I_NAMELEN]; X--- 37,45 ---- X #define RSRC_FORK 2 X #define DATA_FORK 3 X X! #ifdef UNDEF /* Do not declare sprintf; not portable (but lint will complain) */ X char *sprintf(); X! #endif /* UNDEF */ X X char f_info[I_NAMELEN]; X char f_data[I_NAMELEN]; X*************** X*** 45,51 **** X #endif /* AUFS_SUPPORT */ X X int bytes_read, bytes_written; X! int mode; X char *out_buffer, *out_ptr; X X char *buffer = NULL; X--- 56,62 ---- X #endif /* AUFS_SUPPORT */ X X int bytes_read, bytes_written; X! static int mode = MACB; X char *out_buffer, *out_ptr; X X char *buffer = NULL; X*************** X*** 202,225 **** X } X wr_aufs_info(fp); X (void) fclose(fp); X! if(rsz != 0 || mode == FULL) { X! fp = fopen(f_rsrc_aufs, "w"); X! if(fp == NULL) { X! perror(f_rsrc_aufs); X! exit(1); X! } X! (void) fwrite(rbuffer, 1, (int)rsz, fp); X! (void) fclose(fp); X } X! if(dsz != 0 || mode == FULL) { X! fp = fopen(f_data, "w"); X! if(fp == NULL) { X! perror(f_data); X! exit(1); X! } X! (void) fwrite(dbuffer, 1, (int)dsz, fp); X! (void) fclose(fp); X } X break; X #endif /* AUFS_SUPPORT */ X } X--- 213,232 ---- X } X wr_aufs_info(fp); X (void) fclose(fp); X! fp = fopen(f_rsrc_aufs, "w"); X! if(fp == NULL) { X! perror(f_rsrc_aufs); X! exit(1); X } X! (void) fwrite(rbuffer, 1, (int)rsz, fp); X! (void) fclose(fp); X! fp = fopen(f_data, "w"); X! if(fp == NULL) { X! perror(f_data); X! exit(1); X } X+ (void) fwrite(dbuffer, 1, (int)dsz, fp); X+ (void) fclose(fp); X break; X #endif /* AUFS_SUPPORT */ X } X*************** X*** 236,242 **** X #endif /* MKDIR */ X X if (stat(name, &sbuf) == -1) { /* directory doesn't exist */ X! #ifndef NOMKDIR~ X if (mkdir(name, 0777) == -1) { X fprintf(stderr, "Can't create subdirectory %s\n", name); X exit(1); X--- 243,249 ---- X #endif /* MKDIR */ X X if (stat(name, &sbuf) == -1) { /* directory doesn't exist */ X! #ifndef NOMKDIR X if (mkdir(name, 0777) == -1) { X fprintf(stderr, "Can't create subdirectory %s\n", name); X exit(1); X*************** X*** 342,345 **** X--- 349,387 ---- X fwrite((char *) &theinfo, 1, sizeof theinfo, fp); X } X #endif /* AUFS_SUPPORT */ X+ X+ fileopt(c) X+ char c; X+ { X+ switch(c) { X+ case 'r': X+ mode = RSRC; X+ break; X+ case 'd': X+ mode = DATA; X+ break; X+ case 'u': X+ mode = TEXT; X+ break; X+ case 'f': X+ mode = FORK; X+ break; X+ case '3': X+ mode = FULL; X+ break; X+ case 'a': X+ #ifdef AUFS_SUPPORT X+ check_aufs(); X+ mode = AUFS; X+ break; X+ #else /* AUFS_SUPPORT */ X+ fprintf(stderr, "Sorry, AUFS is not supported. Recompile or "); X+ fprintf(stderr, "omit -a option.\n"); X+ exit(1); X+ #endif /* AUFS_SUPPORT */ X+ default: X+ return 0; X+ } X+ return 1; X+ } X X*** macutil.old/fileio/fileio.h Sun Jul 14 03:08:26 1991 X--- macutil/fileio/fileio.h Mon Aug 19 01:19:15 1991 X*************** X*** 4,6 **** X--- 4,7 ---- X void start_data(); X void end_file(); X void do_mkdir(); X+ X*** macutil.old/unpack/cpt_folder.c Sun Jul 14 03:08:33 1991 X--- macutil/unpack/cpt_folder.c Mon Aug 19 01:19:16 1991 X*************** X*** 1,5 **** X--- 1,6 ---- X #include "globals.h" X #include "cpt.h" X+ #include "../fileio/fileio.h" X X void cpt_uncompact(); X X*** macutil.old/unpack/cpt_rle_lzh.c Sun Jul 14 03:08:32 1991 X--- macutil/unpack/cpt_rle_lzh.c Mon Aug 19 01:19:17 1991 X*************** X*** 5,11 **** X X unsigned char getb(); X static void cpt_readHuff(); X! static int cpt_getbits(); X void cpt_outch(); X static int cpt_getbit(); X X--- 5,11 ---- X X unsigned char getb(); X static void cpt_readHuff(); X! static int cpt_get6bits(); X void cpt_outch(); X static int cpt_getbit(); X X*************** X*** 17,23 **** X X void cpt_rle_lzh() X { X! int i, block_count; X unsigned int bptr; X int Huffchar, LZlength, LZoffs; X X--- 17,23 ---- X X void cpt_rle_lzh() X { X! int block_count; X unsigned int bptr; X int Huffchar, LZlength, LZoffs; X X*************** X*** 38,49 **** X while(block_count < 0x1fff0 && cpt_outlength != 0) { X if(cpt_getbit()) { X Huffchar = gethuffbyte(cpt_Hufftree); X! cpt_outch(Huffchar); X block_count += 2; X } else { X LZlength = gethuffbyte(cpt_LZlength); X LZoffs = gethuffbyte(cpt_LZoffs); X! LZoffs = (LZoffs << 6) | cpt_getbits(6); X bptr = cpt_LZptr - LZoffs; X while(LZlength-- > 0) { X cpt_outch(cpt_LZbuff[bptr++ & (CIRCSIZE - 1)]); X--- 38,49 ---- X while(block_count < 0x1fff0 && cpt_outlength != 0) { X if(cpt_getbit()) { X Huffchar = gethuffbyte(cpt_Hufftree); X! cpt_outch((unsigned char)Huffchar); X block_count += 2; X } else { X LZlength = gethuffbyte(cpt_LZlength); X LZoffs = gethuffbyte(cpt_LZoffs); X! LZoffs = (LZoffs << 6) | cpt_get6bits(); X bptr = cpt_LZptr - LZoffs; X while(LZlength-- > 0) { X cpt_outch(cpt_LZbuff[bptr++ & (CIRCSIZE - 1)]); X*************** X*** 85,90 **** X--- 85,93 ---- X /* declarations from GenerateTrees */ X int codelen, lvlstart, next, parents; X /* int i, j already above */ X+ X+ /* for Compactor */ X+ int tree_MaxCount; X /* end declarations */ X X /* next paraphrased from ReadLengths with adaption for Compactor. */ X*************** X*** 95,100 **** X--- 98,104 ---- X } X i = 0; X tree_MaxLength = 0; X+ tree_MaxCount = 0; X tree_entries = 0; X while(treeBytes-- > 0) { /* adaption for Compactor */ X len = (*cpt_char) >> 4; X*************** X*** 101,106 **** X--- 105,113 ---- X if(len != 0) { /* only if length unequal zero */ X if(len > tree_MaxLength) { X tree_MaxLength = len; X+ tree_MaxCount = 1; X+ } else if(len == tree_MaxLength) { X+ tree_MaxCount++; X } X tree_entry[tree_entries].Value = i; X tree_entry[tree_entries++].BitLength = len; X*************** X*** 110,115 **** X--- 117,125 ---- X if(len != 0) { /* only if length unequal zero */ X if(len > tree_MaxLength) { X tree_MaxLength = len; X+ tree_MaxCount = 1; X+ } else if(len == tree_MaxLength) { X+ tree_MaxCount++; X } X tree_entry[tree_entries].Value = i; X tree_entry[tree_entries++].BitLength = len; X*************** X*** 117,122 **** X--- 127,138 ---- X i++; X } X X+ /* Compactor allows an odd trailing code in its Huffman tree! */ X+ if(tree_MaxCount & 1) { X+ tree_entry[tree_entries].Value = size; X+ tree_entry[tree_entries++].BitLength = tree_MaxLength; X+ } X+ X /* adaption from SortLengths */ X entry = &(tree_entry[0]); X entries = tree_entries; X*************** X*** 163,175 **** X Hufftree[0].flag = 0; X } X X! static int cpt_getbits(num) X! unsigned int num; X { X! int b = 0, i; X X! for(i = 0; i < num; i++) { X! b = (b << 1) | cpt_getbit(); X } X return b; X } X--- 179,196 ---- X Hufftree[0].flag = 0; X } X X! static int cpt_get6bits() X { X! int b = 0, cn; X X! b = (cpt_newbits >> 26) & 0x3f; X! cpt_bitsavail -= 6; X! cpt_newbits <<= 6; X! if(cpt_bitsavail < 16) { X! cn = (*cpt_char++ << 8); X! cn |= *cpt_char++; X! cpt_newbits |= (cn << (16 - cpt_bitsavail)); X! cpt_bitsavail += 16; X } X return b; X } X*** macutil.old/unpack/cpt_wrfile.c Sun Jul 14 03:08:34 1991 X--- macutil/unpack/cpt_wrfile.c Mon Aug 19 01:19:18 1991 X*************** X*** 83,89 **** X return; X } X cpt_savechar = ESC2; X! *out_ptr++ = ch; X cpt_outlength--; X } X } X--- 83,89 ---- X return; X } X cpt_savechar = ESC2; X! *out_ptr++ = cpt_savechar; X cpt_outlength--; X } X } X*** macutil.old/unpack/dehuffman.c Sun Jul 14 03:08:31 1991 X--- macutil/unpack/dehuffman.c Mon Aug 19 01:19:18 1991 X*************** X*** 38,44 **** X np = nodeptr++; X if(getbit() == 1) { X np->flag = 1; X! np->byte = getdecodebyte((node *)NULL); X } else { X np->flag = 0; X np->zero = read_sub_tree(); X--- 38,44 ---- X np = nodeptr++; X if(getbit() == 1) { X np->flag = 1; X! np->byte = getdecodebyte(); X } else { X np->flag = 0; X np->zero = read_sub_tree(); X*************** X*** 73,80 **** X return np->byte; X } X X! int getdecodebyte(nodelist) X! struct node *nodelist; X { X register int i, b; X X--- 73,84 ---- X return np->byte; X } X X! int getihuffbyte() X! { X! return gethuffbyte(nodelist); X! } X! X! int getdecodebyte() X { X register int i, b; X X*** macutil.old/unpack/makefile Sun Jul 14 03:23:40 1991 X--- macutil/unpack/makefile Mon Aug 19 01:19:19 1991 X*************** X*** 93,98 **** X--- 93,99 ---- X -rm -f unpack X X unpack.o: globals.h X+ unpack.o: patchlevel.h X unpack.o: ../fileio/fileglob.h X globals.o: globals.h X globals.o: ../machdr/machdr.h X*** macutil.old/unpack/pit.c Sun Jul 14 03:08:30 1991 X--- macutil/unpack/pit.c Mon Aug 19 01:19:19 1991 X*************** X*** 60,67 **** X 100.0 * bytes_read / bytes_written); X } X } X! crc = (gethuffbyte(decode) & BYTEMASK) | X! ((gethuffbyte(decode) & BYTEMASK) << 8); X if(crc != data_crc) { X fprintf(stderr, X "CRC error in file: need 0x%04x, got 0x%04x\n", X--- 60,67 ---- X 100.0 * bytes_read / bytes_written); X } X } X! crc = (getihuffbyte() & BYTEMASK) | X! ((getihuffbyte() & BYTEMASK) << 8); X if(crc != data_crc) { X fprintf(stderr, X "CRC error in file: need 0x%04x, got 0x%04x\n", X*** macutil.old/unpack/pit.h Sun Jul 14 03:08:35 1991 X--- macutil/unpack/pit.h Mon Aug 19 01:19:20 1991 X*************** X*** 16,22 **** X #define H_HDRCRC 92 X #define HDRBYTES 94 X X! struct pit_header { /* Packit file header (92 bytes) X unsigned char nlen; /* number of characters in packed file name */ X char name[63]; /* name of packed file */ X char type[4]; /* file type */ X--- 16,22 ---- X #define H_HDRCRC 92 X #define HDRBYTES 94 X X! struct pit_header { /* Packit file header (92 bytes) */ X unsigned char nlen; /* number of characters in packed file name */ X char name[63]; /* name of packed file */ X char type[4]; /* file type */ X*** macutil.old/unpack/pit_filehdr.c Sun Jul 14 03:08:32 1991 X--- macutil/unpack/pit_filehdr.c Mon Aug 19 01:19:21 1991 X*************** X*** 24,30 **** X X if(compr == DECODE) { X for(i = 0; i < HDRBYTES; i++) { X! hdr[i] = gethuffbyte(compr); X } X } else { X if(fread(hdr, 1, HDRBYTES, infp) != HDRBYTES) { X--- 24,30 ---- X X if(compr == DECODE) { X for(i = 0; i < HDRBYTES; i++) { X! hdr[i] = getihuffbyte(); X } X } else { X if(fread(hdr, 1, HDRBYTES, infp) != HDRBYTES) { X*** macutil.old/unpack/sit_folder.c Sun Jul 14 03:08:28 1991 X--- macutil/unpack/sit_folder.c Mon Aug 19 01:19:21 1991 X*************** X*** 1,5 **** X--- 1,6 ---- X #include "globals.h" X #include "sit.h" X+ #include "../fileio/fileio.h" X X void sit_skip(); X void sit_unstuff(); X*** macutil.old/unpack/unpack.c Sun Jul 14 03:08:29 1991 X--- macutil/unpack/unpack.c Mon Aug 19 01:19:22 1991 X*************** X*** 1,4 **** X--- 1,5 ---- X #include "globals.h" X+ #include "patchlevel.h" X #include "../fileio/fileglob.h" X X unsigned long get4(); X*************** X*** 17,67 **** X extern char *optarg; X int errflg; X X- mode = MACB; X errflg = 0; X X! while((c = getopt(argc, argv, "3adfilqruv")) != EOF) { X! switch(c) { X! case 'r': X! mode = RSRC; X! break; X! case 'd': X! mode = DATA; X! break; X! case 'u': X! mode = TEXT; X! break; X! case 'f': X! mode = FORK; X! break; X! case '3': X! mode = FULL; X! break; X! case 'a': X #ifdef AUFS_SUPPORT X! check_aufs(); X! mode = AUFS; X! break; X #else /* AUFS_SUPPORT */ X! fprintf(stderr, "Sorry, AUFS is not supported. Recompile or "); X! fprintf(stderr, "omit -a option.\n"); X! exit(1); X #endif /* AUFS_SUPPORT */ X! case 'l': X! list++; X! break; X! case 'q': X! query++; X! break; X! case 'v': X! verbose++; X! break; X! case 'i': X! info_only++; X! break; X! case '?': X! errflg++; X! break; X } X } X if(errflg) { X--- 18,53 ---- X extern char *optarg; X int errflg; X X errflg = 0; X X! while((c = getopt(argc, argv, "3Vadfilqruv")) != EOF) { X! if(!fileopt(c)) { X! switch(c) { X! case 'l': X! list++; X! break; X! case 'q': X! query++; X! break; X! case 'v': X! verbose++; X! break; X! case 'i': X! info_only++; X! break; X! case '?': X! errflg++; X! break; X! case 'V': X! fprintf(stderr, "Patchlevel %d", PATCHLEVEL); X #ifdef AUFS_SUPPORT X! fprintf(stderr, ", AUFS supported"); X #else /* AUFS_SUPPORT */ X! fprintf(stderr, ", AUFS not supported"); X #endif /* AUFS_SUPPORT */ X! fprintf(stderr, ".\n"); X! exit(0); X! } X } X } X if(errflg) { X*** macutil.old/unpack/util.c Sun Jul 14 03:08:30 1991 X--- macutil/unpack/util.c Mon Aug 19 01:19:22 1991 X*************** X*** 68,74 **** X printf("? "); X (void) fflush(stdout); X (void) read(2, temp, sizeof(temp)); X! temp[sizeof(temp)] = 0; X tp = temp; X while(*tp != 0) { X if(*tp == 'y' || *tp == 'Y') { X--- 68,74 ---- X printf("? "); X (void) fflush(stdout); X (void) read(2, temp, sizeof(temp)); X! temp[sizeof(temp) - 1] = 0; X tp = temp; X while(*tp != 0) { X if(*tp == 'y' || *tp == 'Y') { SHAR_EOF if test 15710 -ne "`wc -c < 'patch01'`" then echo shar: "error transmitting 'patch01'" '(should have been 15710 characters)' fi fi exit 0 # End of shell archive -- dik t. winter, cwi, amsterdam, nederland dik@cwi.nl