home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 157.lha / Arc_Src / arc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-27  |  7.5 KB  |  206 lines

  1. /*  ARC - Archive utility
  2.  
  3. System V Version 1.0 based upon:
  4.     Version 5.12, created on 02/05/86 at 22:22:01
  5.  
  6. Port to System V, by Mike Stump
  7. Please send all bug fixes, comments, etc...  to:
  8. uucp: {sdcrdcf, ihnp4, hplabs, ttidca, psivax, csustan}!csun!aeusemrs
  9.  
  10. Machines known to work on:
  11.     3B5 System V, Version 2 Release 2.0
  12.  
  13. (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  14.  
  15.     By:  Thom Henderson
  16.  
  17.     Description:
  18.          This program is a general archive utility, and is used to maintain
  19.          an archive of files.  An "archive" is a single file that combines
  20.          many files, reducing storage space and allowing multiple files to
  21.          be handled as one.
  22.  
  23.     Instructions:
  24.          Run this program with no arguments for complete instructions.
  25.  
  26.     Programming notes:
  27.          ARC Version 2 differs from version 1 in that archive entries
  28.          are automatically compressed when they are added to the archive,
  29.          making a separate compression step unecessary.  The nature of the
  30.          compression is indicated by the header version number placed in
  31.          each archive entry, as follows:
  32.  
  33.          1 = Old style, no compression
  34.          2 = New style, no compression
  35.          3 = Compression of repeated characters only
  36.          4 = Compression of repeated characters plus Huffman SQueezing
  37.          5 = Lempel-Zev packing of repeated strings (old style)
  38.          6 = Lempel-Zev packing of repeated strings (new style)
  39.          7 = Lempel-Zev Williams packing with improved has function
  40.          8 = Dynamic Lempel-Zev packing with adaptive reset
  41.  
  42.          Type 5, Lempel-Zev packing, was added as of version 4.0
  43.  
  44.          Type 6 is Lempel-Zev packing where runs of repeated characters
  45.          have been collapsed, and was added as of version 4.1
  46.  
  47.          Type 7 is a variation of Lempel-Zev using a different hash
  48.          function which yields speed improvements of 20-25%, and was
  49.          added as of version 4.6
  50.  
  51.          Type 8 is a different implementation of Lempel-Zev, using a
  52.          variable code size and an adaptive block reset, and was added
  53.          as of version 5.0
  54.  
  55.          Verion 4.3 introduced a temporary file for holding the result
  56.          of the first crunch pass, thus speeding up crunching.
  57.  
  58.          Version 4.4 introduced the ARCTEMP environment string, so that
  59.          the temporary crunch file may be placed on a ramdisk.  Also
  60.          added was the distinction bewteen Adding a file in all cases,
  61.          and Updating a file only if the disk file is newer than the
  62.          corresponding archive entry.
  63.  
  64.          The compression method to use is determined when the file is
  65.          added, based on whichever method yields the smallest result.
  66.  
  67. */
  68. #include "arc.h"
  69.  
  70. main(num,arg)                          /* system entry point */
  71. int num;                               /* number of arguments */
  72. char **arg;                            /* pointers to arguments */
  73. {
  74.     char opt = 0;                      /* selected action */
  75.     char *a;                           /* option pointer */
  76.     char *makefnam();                  /* filename fixup routine */
  77.     char *upper();                     /* case conversion routine */
  78.     char *index();                     /* string index utility */
  79.     char *envfind();                   /* environment searcher */
  80.     INT n;                             /* argument index */
  81.     char *arctemp2;
  82.     long getpid();
  83.  
  84.     warn = 1;
  85.     note = 1;
  86.     if(num<3)
  87.     {    printf("arc - Archive Utility, 5.12\n");
  88.          printf("Usage: arc {amufdxeplvtc}[bswn][g<password>]");
  89.          printf(" <archive> [<filename> . . .]\n");
  90.          printf("Where:   a   = add files to archive\n");
  91.          printf("         m   = move files to archive\n");
  92.          printf("         u   = update files in archive\n");
  93.          printf("         f   = freshen files in archive\n");
  94.          printf("         d   = delete files from archive\n");
  95.          printf("         x,e = extract files from archive\n");
  96.          printf("         p   = copy files from archive to");
  97.          printf(" standard output\n");
  98.          printf("         l   = list files in archive\n");
  99.          printf("         v   = verbose listing of files in archive\n");
  100.          printf("         t   = test archive integrity\n");
  101.          printf("         c   = convert entry to new packing method\n");
  102.          printf("         b   = retain backup copy of archive\n");
  103.          printf("         s   = suppress compression (store only)\n");
  104.          printf("         w   = suppress warning messages\n");
  105.          printf("         n   = suppress notes and comments\n");
  106.          printf("         g   = Encrypt/decrypt archive entry\n\n");
  107.          return 1;
  108.     }
  109.  
  110.     /* see where temp files go */
  111.     /* use process id to "enhance uniquity" of temp filenames */
  112.     /* (avoids multi-user or background foolishness) */
  113.  
  114.     if(!(arctemp2 = envfind("ARCTEMP")))
  115.          arctemp2 = envfind("TEMP");
  116.     if (arctemp2) sprintf(arctemp,"%s.Arc%ld",arctemp2,getpid());
  117.     else sprintf(arctemp,".Arc%ld",getpid());
  118.  
  119.     /* avoid any case problems with command options */
  120.          upper(arg[1]);                /* convert it to uppercase */
  121.  
  122.     /* create archive names, supplying defaults */
  123.  
  124.     makefnam(arg[2],".arc",arcname);
  125.     sprintf(newname,"%s.arc",arctemp);
  126.     makefnam(".bak",arcname,bakname);
  127.  
  128.     /* now scan the command and see what we are to do */
  129.  
  130.     for(a=arg[1]; *a; a++)             /* scan the option flags */
  131.     {    if(index("AMUFDXEPLVTC",*a)) /* if a known command */
  132.          {    if(opt)                  /* do we have one yet? */
  133.                    abort("Cannot mix %c and %c",opt,*a);
  134.               opt = *a;                /* else remember it */
  135.          }
  136.  
  137.          else if(*a=='B')              /* retain backup copy */
  138.               keepbak = 1;
  139.  
  140.          else if(*a=='W')              /* suppress warnings */
  141.               warn = 0;
  142.  
  143.          else if(*a=='N')              /* suppress notes and comments */
  144.               note = 0;
  145.  
  146.          else if(*a=='G')              /* garble */
  147.          {    password = a+1;
  148.               while(*a)
  149.                    a++;
  150.               a--;
  151.          }
  152.  
  153.          else if(*a=='S')              /* storage kludge */
  154.               nocomp = 1;
  155.  
  156.          else if (*a=='-')   /* UNIX option marker */
  157.               ;
  158.  
  159.          else abort("%c is an unknown command",*a);
  160.     }
  161.  
  162.     if(!opt)
  163.          abort("I have nothing to do!");
  164.  
  165.     /* act on whatever action command was given */
  166.  
  167.     switch(opt)                        /* action depends on command */
  168.     {
  169.     case 'A':                          /* Add */
  170.     case 'M':                          /* Move */
  171.     case 'U':                          /* Update */
  172.     case 'F':                          /* Freshen */
  173.          addarc(num-3,&arg[3],(opt=='M'),(opt=='U'),(opt=='F'));
  174.          break;
  175.  
  176.     case 'D':                          /* Delete */
  177.          delarc(num-3,&arg[3]);
  178.          break;
  179.  
  180.     case 'E':                          /* Extract */
  181.     case 'X':                          /* eXtract */
  182.     case 'P':                          /* Print */
  183.          extarc(num-3,&arg[3],(opt=='P'));
  184.          break;
  185.  
  186.     case 'V':                          /* Verbose list */
  187.          bose = 1;
  188.     case 'L':                          /* List */
  189.          lstarc(num-3,&arg[3]);
  190.          break;
  191.  
  192.     case 'T':                          /* Test */
  193.          tstarc();
  194.          break;
  195.  
  196.     case 'C':                          /* Convert */
  197.          cvtarc(num-3,&arg[3]);
  198.          break;
  199.  
  200.     default:
  201.          abort("I don't know how to do %c yet!",opt);
  202.     }
  203.  
  204.     return nerrs;
  205. }
  206.