[comp.sources.misc] arc that UnSquashes 1/2

ddl@husc6.UUCP (Dan Lanciani) (07/18/87)

[This was in alt.sources; however, it is definitely in demand.  ++bsa]

	Here is a version of unix ARC that can deal with Squashed
archive entries.  It does not (yet) make such entries.  This is a
quick hack for those who want to be able to unpack current pkarced
postings on their unix machine.  I made the changes in the most obvious
and simple way and did only minimal testing.  No flames please; a better
version will follow.  I would have posted changes only, but there are too
many versions floating around.  Combine parts 1 & 2 and unshar.


						Dan Lanciani
						ddl@harvard.*

#! /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 the files:
#	Makefile
#	arc.c
#	arc.h
#	arcadd.c
#	arccode.c
#	arccvt.c
#	arcdel.c
#	arcdir.c
#	arcdos.c
#	arcext.c
#	arcio.c
#	arclst.c
#	arclzw.c
#	arcm.h
#	arcmatch.c
#	arcmisc.c
#	arcpack.c
#	arcrun.c
#	arcs.h
#	arcsq.c
#	arcsvc.c
#	arctst.c
#	arcunp.c
#	arcusq.c
#	arcvax.c
#	squash.c
# This archive created: Wed Jul 15 19:55:51 1987
export PATH; PATH=/bin:$PATH
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
#
#	Makefile for Hack-attack 1.3
#	VAX 11/780 BSD4.2 "ARC" utility
#
CFLAGS = -O

OBJS = arc.o arcadd.o arccode.o arccvt.o arcdel.o arcdir.o \
arcdos.o arcext.o arcio.o arclst.o arclzw.o arcmatch.o arcpack.o arcrun.o \
arcsq.o arcsvc.o arctst.o arcunp.o arcusq.o arcvax.o arcmisc.o squash.o


SRCS = arc.c arcadd.c arccode.c arccvt.c arcdel.c arcdir.c \
arcdos.c arcext.c arcio.c arclst.c arclzw.c arcmatch.c arcpack.c arcrun.c \
arcs.c arcsq.c arcsvc.c arctst.c arcunp.c arcusq.c arcvax.c arcmisc.c squash.c

arc:		${OBJS}
	cc  -O -o arc ${OBJS}
arc.o:		arc.h
	cc -O -c arc.c
arcadd.o:	arc.h
	cc -O -c arcadd.c
arccode.o:	arc.h
	cc -O -c arccode.c
arccvt.o:	arc.h
	cc -O -c arccvt.c
arcdel.o:	arc.h
	cc -O -c arcdel.c
arcdir.o:	arc.h
	cc -O -c arcdir.c
arcdos.o:	arc.h
	cc -O -c arcdos.c
arcext.o:	arc.h
	cc -O -c arcext.c
arcio.o:	arc.h
	cc -O -c arcio.c
arclst.o:	arc.h
	cc -O -c arclst.c
arclzw.o:	arc.h
	cc -O -c arclzw.c
arcmatch.o:	arc.h
	cc -O -c arcmatch.c
arcmisc.o:	arc.h
	cc -O -c arcmisc.c
arcpack.o:	arc.h
	cc -O -c arcpack.c
arcrun.o:	arc.h
	cc -O -c arcrun.c
arcs.o:		arcm.h
	cc -O -c arcs.c
arcsq.o:	arc.h
	cc -O -c arcsq.c
arcsvc.o:	arc.h
	cc -O -c arcsvc.c
arctst.o:	arc.h
	cc -O -c arctst.c
arcunp.o:	arc.h
	cc -O -c arcunp.c
arcusq.o:	arc.h
	cc -O -c arcusq.c
arcvax.o:	arc.h
	cc -O -c arcvax.c
squash.o:	arc.h
	cc -O -c squash.c
arc.h:		arcm.h arcs.h
	touch arc.h
SHAR_EOF
fi # end of overwriting check
if test -f 'arc.c'
then
	echo shar: will not over-write existing file "'arc.c'"
else
cat << \SHAR_EOF > 'arc.c'
static char *RCSid = "$Header: arc.c,v 1.2 86/07/15 07:52:04 turner Exp $";

/*
 * $Log:	arc.c,v $
 * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
 * 	Bludgeoned into submission for VAX 11/780 BSD4.2
 *	(ugly code, but fewer core dumps)
 *
 * Revision 1.2  86/07/15  07:52:04  turner
 * first working version for the vax
 * 
 * Revision 1.1  86/06/26  14:59:15  turner
 * initial version
 * 
 * 
 */

/*  ARC - Archive utility

$define(tag,$$segment(@1,$$index(@1,=)+1))#
$define(version,Version $tag(
TED_VERSION DB =5.12), created on $tag(
TED_DATE DB =02/05/86) at $tag(
TED_TIME DB =22:22:01))#
$undefine(tag)#
    $version

(C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED

    By:  Thom Henderson

    Description:
         This program is a general archive utility, and is used to maintain
         an archive of files.  An "archive" is a single file that combines
         many files, reducing storage space and allowing multiple files to
         be handled as one.

    Instructions:
         Run this program with no arguments for complete instructions.

    Programming notes:
         ARC Version 2 differs from version 1 in that archive entries
         are automatically compressed when they are added to the archive,
         making a separate compression step unecessary.  The nature of the
         compression is indicated by the header version number placed in
         each archive entry, as follows:

         1 = Old style, no compression
         2 = New style, no compression
         3 = Compression of repeated characters only
         4 = Compression of repeated characters plus Huffman SQueezing
         5 = Lempel-Zev packing of repeated strings (old style)
         6 = Lempel-Zev packing of repeated strings (new style)
         7 = Lempel-Zev Williams packing with improved has function
         8 = Dynamic Lempel-Zev packing with adaptive reset

         Type 5, Lempel-Zev packing, was added as of version 4.0

         Type 6 is Lempel-Zev packing where runs of repeated characters
         have been collapsed, and was added as of version 4.1

         Type 7 is a variation of Lempel-Zev using a different hash
         function which yields speed improvements of 20-25%, and was
         added as of version 4.6

         Type 8 is a different implementation of Lempel-Zev, using a
         variable code size and an adaptive block reset, and was added
         as of version 5.0

         Verion 4.3 introduced a temporary file for holding the result
         of the first crunch pass, thus speeding up crunching.

         Version 4.4 introduced the ARCTEMP environment string, so that
         the temporary crunch file may be placed on a ramdisk.  Also
         added was the distinction bewteen Adding a file in all cases,
         and Updating a file only if the disk file is newer than the
         corresponding archive entry.

         The compression method to use is determined when the file is
         added, based on whichever method yields the smallest result.

    Language:
         Computer Innovations Optimizing C86
*/
#include <stdio.h>
#include "arc.h"

main(num,arg)                          /* system entry point */
INT num;                               /* number of arguments */
char *arg[];                           /* pointers to arguments */
{
    char opt = 0;                      /* selected action */
    char *a;                           /* option pointer */
    char *makefnam();                  /* filename fixup routine */
    char *upper();                     /* case conversion routine */
    char *index();                     /* string index utility */
    char *envfind();                   /* environment searcher */
    INT n;                             /* argument index */
    char *arctemp2;
    long getpid();

    warn = 1;
    note = 1;
    if(num<3)
    { /* printf("ARC - Archive utility, $version\n");
         printf("(C) COPYRIGHT 1985,86 by System Enhancement Associates;");
         printf(" ALL RIGHTS RESERVED\n\n");
         printf("Please refer all inquiries to:\n\n");
         printf("       System Enhancement Associates\n");
         printf("       21 New Street, Wayne NJ 07470\n\n");
         printf("You may copy and distribute this program freely,");
         printf(" provided that:\n");
         printf("    1)   No fee is charged for such copying and");
         printf(" distribution, and\n");
         printf("    2)   It is distributed ONLY in its original,");
         printf(" unmodified state.\n\n");
         printf("If you like this program, and find it of use, then your");
         printf(" contribution will\n");
         printf("be appreciated.  You may not use this product in a");
         printf(" commercial environment\n");
         printf("or a governmental organization without paying a license");
         printf(" fee of $35.  Site\n");
         printf("licenses and commercial distribution licenses are");
         printf(" available.  A program\n");
         printf("disk and printed documentation are available for $50.\n");
         printf("\nIf you fail to abide by the terms of this license, ");
         printf(" then your conscience\n");
         printf("will haunt you for the rest of your life.\n\n");            */
         printf("Usage: ARC {amufdxerplvtc}[bswn][g<password>]");
         printf(" <archive> [<filename> . . .]\n");
         printf("Where:   a   = add files to archive\n");
         printf("         m   = move files to archive\n");
         printf("         u   = update files in archive\n");
         printf("         f   = freshen files in archive\n");
         printf("         d   = delete files from archive\n");
         printf("         x,e = extract files from archive\n");
         printf("         r   = run files from archive\n");
         printf("         p   = copy files from archive to");
         printf(" standard output\n");
         printf("         l   = list files in archive\n");
         printf("         v   = verbose listing of files in archive\n");
         printf("         t   = test archive integrity\n");
         printf("         c   = convert entry to new packing method\n");
         printf("         b   = retain backup copy of archive\n");
         printf("         s   = suppress compression (store only)\n");
         printf("         w   = suppress warning messages\n");
         printf("         n   = suppress notes and comments\n");
         printf("         g   = Encrypt/decrypt archive entry\n\n");
/*       printf("\nPlease refer to the program documentation for");          */
/*       printf(" complete instructions.\n");                                */
         return 1;
    }

    /* see where temp files go */
    /* use process id to "enhance uniquity" of temp filenames */
    /* (avoids multi-user or background foolishness) */

    if(!(arctemp2 = envfind("ARCTEMP")))
         arctemp2 = envfind("TEMP");
    if (arctemp2) sprintf(arctemp,"%s.Arc%ld",arctemp2,getpid());
    else sprintf(arctemp,".Arc%ld",getpid());

#if MSDOS 
    /* avoid any case problems with arguments */

    for(n=1; n<num; n++)               /* for each argument */
         upper(arg[n]);                /* convert it to uppercase */
#endif
#if BSD | ST
    /* avoid any case problems with command options */

         upper(arg[1]);                /* convert it to uppercase */
#endif

    /* create archive names, supplying defaults */

#if MSDOS
    makefnam(arg[2],".ARC",arcname);
#endif
#if BSD | ST
    makefnam(arg[2],".arc",arcname);
#endif
/*  makefnam(".$$$$",arcname,newname); */
    sprintf(newname,"%s.ARC",arctemp);
    makefnam(".BAK",arcname,bakname);

    /* now scan the command and see what we are to do */

    for(a=arg[1]; *a; a++)             /* scan the option flags */
    {    if(index("AMUFDXEPLVTCR",*a)) /* if a known command */
         {    if(opt)                  /* do we have one yet? */
                   abort("Cannot mix %c and %c",opt,*a);
              opt = *a;                /* else remember it */
         }

         else if(*a=='B')              /* retain backup copy */
              keepbak = 1;

         else if(*a=='W')              /* suppress warnings */
              warn = 0;

         else if(*a=='N')              /* suppress notes and comments */
              note = 0;

         else if(*a=='G')              /* garble */
         {    password = a+1;
              while(*a)
                   a++;
              a--;
         }

         else if(*a=='S')              /* storage kludge */
              nocomp = 1;

         else if(*a=='K')              /* special kludge */
              kludge = 1;

         else if(*a=='-' || *a=='/')   /* UNIX and PC-DOS option markers */
              ;

         else abort("%c is an unknown command",*a);
    }

    if(!opt)
         abort("I have nothing to do!");

    /* act on whatever action command was given */

    switch(opt)                        /* action depends on command */
    {
    case 'A':                          /* Add */
    case 'M':                          /* Move */
    case 'U':                          /* Update */
    case 'F':                          /* Freshen */
         addarc(num-3,&arg[3],(opt=='M'),(opt=='U'),(opt=='F'));
         break;

    case 'D':                          /* Delete */
         delarc(num-3,&arg[3]);