home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / unix / arcunx11 / arc.sh1 / arc.c next >
Encoding:
C/C++ Source or Header  |  1987-04-01  |  8.0 KB  |  227 lines

  1. /*
  2.  *    arc.c    1.1
  3.  *
  4.  *    Author: Thom Henderson
  5.  *    Original System V port: Mike Stump
  6.  *    Enhancements, Bug fixes, and cleanup: Chris Seaman
  7.  *    Date: Fri Mar 20 09:57:02 1987
  8.  *    Last Mod.    3/21/87
  9.  *
  10.  */
  11.  
  12. #ifndef    lint
  13. static char    sccsid[] = "@(#)arc.c    1.1";
  14. #endif    /* lint */
  15.  
  16.  
  17. /*
  18.  * ARC - Archive utility
  19.  * 
  20.  * Version 5.12, created on 02/05/86 at 22:22:01
  21.  * 
  22.  * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  23.  * 
  24.  *     Description:
  25.  *          This program is a general archive utility, and is used to maintain
  26.  *          an archive of files.  An "archive" is a single file that combines
  27.  *          many files, reducing storage space and allowing multiple files to
  28.  *          be handled as one.
  29.  * 
  30.  *     Instructions:
  31.  *          Run this program with no arguments for complete instructions.
  32.  * 
  33.  *     Programming notes:
  34.  *          ARC Version 2 differs from version 1 in that archive entries
  35.  *          are automatically compressed when they are added to the archive,
  36.  *          making a separate compression step unecessary.  The nature of the
  37.  *          compression is indicated by the header version number placed in
  38.  *          each archive entry, as follows:
  39.  * 
  40.  *          1 = Old style, no compression
  41.  *          2 = New style, no compression
  42.  *          3 = Compression of repeated characters only
  43.  *          4 = Compression of repeated characters plus Huffman SQueezing
  44.  *          5 = Lempel-Zev packing of repeated strings (old style)
  45.  *          6 = Lempel-Zev packing of repeated strings (new style)
  46.  *          7 = Lempel-Zev Williams packing with improved has function
  47.  *          8 = Dynamic Lempel-Zev packing with adaptive reset
  48.  * 
  49.  *          Type 5, Lempel-Zev packing, was added as of version 4.0
  50.  * 
  51.  *          Type 6 is Lempel-Zev packing where runs of repeated characters
  52.  *          have been collapsed, and was added as of version 4.1
  53.  * 
  54.  *          Type 7 is a variation of Lempel-Zev using a different hash
  55.  *          function which yields speed improvements of 20-25%, and was
  56.  *          added as of version 4.6
  57.  * 
  58.  *          Type 8 is a different implementation of Lempel-Zev, using a
  59.  *          variable code size and an adaptive block reset, and was added
  60.  *          as of version 5.0
  61.  * 
  62.  *          Verion 4.3 introduced a temporary file for holding the result
  63.  *          of the first crunch pass, thus speeding up crunching.
  64.  * 
  65.  *        { Version 4.4 introduced the ARCTEMP environment string, so that }
  66.  *        { the temporary crunch file may be placed on a ramdisk.  Also    }
  67.  *        { added was the distinction bewteen Adding a file in all cases,  }
  68.  *        { and Updating a file only if the disk file is newer than the    }
  69.  *        { corresponding archive entry.                                   }
  70.  *           (NOT USED IN THIS RELEASE OF THE SYSTEM V VERSION)
  71.  * 
  72.  *          The compression method to use is determined when the file is
  73.  *          added, based on whichever method yields the smallest result.
  74.  * 
  75.  */
  76. #include "arc.h"
  77.  
  78. main(argc,argv)                        /* system entry point */
  79. int argc;                              /* number of arguments */
  80. char *argv[];                          /* pointers to arguments */
  81. {
  82.     char opt = 0;                      /* selected action */
  83.     char *a;                           /* option pointer */
  84.     char *upper();                     /* case conversion routine */
  85.     INT n;                             /* argument index */
  86.     INT dups = 0;                      /* duplicate argument counter */
  87.     INT onintr();                      /* funtion to call when SIGNAL caught */
  88.  
  89.     /* Basic signal trapping */
  90.     signal(SIGHUP,SIG_IGN);
  91.     signal(SIGINT,onintr);
  92.     if (signal(SIGQUIT,SIG_IGN) != SIG_IGN) signal(SIGQUIT,onintr);
  93.  
  94.     warn = 1;
  95.     note = 1;
  96.  
  97.     if (argc<3)
  98.     {
  99.         printf("%s - Archive Utility, 5.12\n",argv[0]);
  100.         printf("System V Version 1.1, 3/21/87\n\n");
  101.         printf("Usage: %s [-]{amufdxeplvtc}[biswn][g<password>]",argv[0]);
  102.         printf(" <archive> [<filename> ... ]\n");
  103.         printf("Where:   a   = add files to archive\n");
  104.         printf("         m   = move files to archive\n");
  105.         printf("         u   = update files in archive\n");
  106.         printf("         f   = freshen files in archive\n");
  107.         printf("         d   = delete files from archive\n");
  108.         printf("         x,e = extract files from archive\n");
  109.         printf("         p   = copy files from archive to standard output\n");
  110.         printf("         l   = list files in archive\n");
  111.         printf("         v   = verbose listing of files in archive\n");
  112.         printf("         t   = test archive integrity\n");
  113.         printf("         c   = convert entry to new packing method\n\n");
  114.         printf("         b   = retain backup copy of archive\n");
  115.         printf("         i   = maintain IBM(TM) PC compatible archive\n");
  116.         printf("         s   = suppress compression (store only)\n");
  117.         printf("         w   = suppress warning messages\n");
  118.         printf("         n   = suppress notes and comments\n");
  119.         printf("         g   = Encrypt/decrypt archive entry\n\n");
  120.         exit(1);
  121.     }
  122.  
  123.     /* avoid any case problems with command options */
  124.     upper(argv[1]);                /* convert it to uppercase */
  125.  
  126.     /* parse the option argument */
  127.  
  128.     for (a=argv[1]; *a; a++)
  129.     {
  130.         switch(*a)
  131.         {
  132.         case 'A':                       /* if a known command */
  133.         case 'M':
  134.         case 'U':
  135.         case 'F':
  136.         case 'D':
  137.         case 'X':
  138.         case 'E':
  139.         case 'P':
  140.         case 'L':
  141.         case 'V':
  142.         case 'T':
  143.         case 'C':
  144.             if (opt)                    /* do we have one yet? */
  145.                 abort("Cannot mix %c and %c",opt,*a);
  146.             else
  147.                 opt = *a;               /* else remember it */
  148.             break;
  149.         case 'B':                       /* retain backup copy */
  150.             keepbak = 1;
  151.             break;
  152.         case 'I':                       /* IBM compatibility */
  153.             ibmpc = 1;
  154.             break;
  155.         case 'W':                       /* suppress warnings */
  156.             warn = 0;
  157.             break;
  158.         case 'N':                       /* suppress notes and comments */
  159.             note = 0;
  160.             break;
  161.         case 'G':                       /* garble */
  162.             password = a+1;
  163.             while (*a)
  164.                 a++;
  165.             a--;
  166.             break;
  167.         case 'S':                       /* storage kludge */
  168.             nocomp = 1;
  169.             break;
  170.         case '-':                       /* UNIX option marker */
  171.             break;
  172.         default:
  173.             abort("%c is an unknown command",*a);
  174.         }
  175.     }
  176.  
  177.     /* get out if no option made it through */
  178.     if (!opt)
  179.         abort("I don't know what to do!");
  180.  
  181.     /* create archive names (arctemp, arcname, newname, bakname) */
  182.     makenames(argv[2]);
  183.  
  184.     /* strip off used args */
  185.     argc -=3;
  186.     argv +=3;
  187.  
  188.     /* if file args, sort them */
  189.     if (argc)
  190.     {
  191.         dups = sortarg(argc,argv);
  192.         argc -= dups;
  193.     }
  194.  
  195.     /* act on whatever action command was given */
  196.  
  197.     switch(opt)                        /* action depends on command */
  198.     {
  199.     case 'A':                          /* Add */
  200.     case 'M':                          /* Move */
  201.     case 'U':                          /* Update */
  202.     case 'F':                          /* Freshen */
  203.         addarc(argc,argv,(opt=='M'),(opt=='U'),(opt=='F'));
  204.         break;
  205.     case 'D':                          /* Delete */
  206.         delarc(argc,argv);
  207.         break;
  208.     case 'E':                          /* Extract */
  209.     case 'X':                          /* eXtract */
  210.     case 'P':                          /* Print */
  211.         extarc(argc,argv,(opt=='P'));
  212.         break;
  213.     case 'V':                          /* Verbose list */
  214.         bose = 1;
  215.     case 'L':                          /* List */
  216.         lstarc(argc,argv);
  217.         break;
  218.     case 'T':                          /* Test */
  219.         tstarc();
  220.         break;
  221.     case 'C':                          /* Convert */
  222.         cvtarc(argc,argv);
  223.     }
  224.  
  225.     exit(nerrs);
  226. }
  227.