home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / arc68k.arc / ARC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-27  |  8.3 KB  |  221 lines

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