home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / disk / archive / nspark_1 / nspark-1.7.5 / main.c < prev    next >
C/C++ Source or Header  |  1994-12-12  |  4KB  |  207 lines

  1. /*                      
  2.  * main function
  3.  *
  4.  * $Header: main.c 1.10 93/08/20 $
  5.  * $Log:    main.c,v $
  6.  * Revision 1.10  93/08/20  12:39:28  arb
  7.  * Added support for ArcFS archive detection
  8.  *
  9.  * Revision 1.9  93/08/20  10:30:50  arb
  10.  * Added -C option for "convert filenames to lowercase"
  11.  *
  12.  * Revision 1.8  93/03/05  15:40:32  arb
  13.  * Added <stdlib.h> for RISCOS, needed for exit()
  14.  *
  15.  * Revision 1.7  92/12/09  09:43:03  duplain
  16.  * Changed "-a" option to "-T".
  17.  * 
  18.  * Revision 1.6  92/12/08  10:19:30  duplain
  19.  * Added -a option for "append filetype".
  20.  * 
  21.  * Revision 1.5  92/12/07  17:18:42  duplain
  22.  * reformatted source.
  23.  * 
  24.  * Revision 1.4  92/10/19  09:33:09  duplain
  25.  * Added -x as an alternative to -u.
  26.  * 
  27.  * Revision 1.3  92/10/01  11:21:39  duplain
  28.  * Added -R option.
  29.  * 
  30.  * Revision 1.2  92/09/30  10:27:29  duplain
  31.  * Added logfile option and processing.
  32.  * 
  33.  * Revision 1.1  92/09/29  18:02:20  duplain
  34.  * Initial revision
  35.  * 
  36.  */
  37.  
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #include "spark.h"
  41. #include "io.h"
  42. #include "error.h"
  43. #include "misc.h"
  44. #include "arc.h"
  45. #include "unarc.h"
  46. #ifdef RISCOS
  47. #include <stdlib.h>
  48. #endif
  49.  
  50. #ifdef UNIX
  51. static char rcsid[] = "$Header: main.c 1.10 93/08/20 $";
  52. #endif /* UNIX */
  53.  
  54. char *ourname;            /* program name */
  55. char *archive;            /* name of archive file */
  56. char *logfile = "settypes";    /* default name for log file */
  57. char **files;            /* optional file arguments */
  58.  
  59. unsigned char unarc = 0;    /* -u or -x */
  60. unsigned char quiet = 0;    /* -q */
  61. unsigned char verbose = 0;    /* -v */
  62. unsigned char testing = 0;    /* -t */
  63. unsigned char listing = 0;    /* -l */
  64. unsigned char force = 0;    /* -f */
  65. unsigned char stamp = 1;    /* -s */
  66. unsigned char retry = 0;    /* -R */
  67. unsigned char apptype = 0;    /* -T */ 
  68. unsigned char singlecase = 0;   /* -C */
  69. #ifdef DEBUGGING
  70. unsigned char debugging = 0;    /* -D */
  71. #endif /* DEBUGGING */
  72.  
  73. void usage P__((void));
  74. int do_unarc P__((void));
  75. int do_arc P__((void));
  76.  
  77. int
  78. main(argc, argv)
  79.     int argc;
  80.     char **argv;
  81. {
  82.     register i;
  83.  
  84. #ifdef DEBUGGING
  85.     /*
  86.      * check types are defined correctly for this machine (or compiler ???)
  87.      */
  88.     if (sizeof(Word) != 4) {
  89.     puts("Word size != 4");
  90.     exit(1);
  91.     } 
  92.     if (sizeof(Halfword) != 2) {
  93.     puts("Halfword size != 2");
  94.     exit(1);
  95.     }
  96.     if (sizeof(Byte) != 1) {
  97.     puts("Byte size != 1");
  98.     exit(1);
  99.     }
  100. #endif /* DEBUGGING */
  101.  
  102.     ourname = basename(*argv++);
  103.     argc--;
  104.  
  105.     /*
  106.      * parse args (can't use getopt() 'cos not all C libraries have it)
  107.      */
  108.     while(argc) {
  109.     int donext = 0;
  110.     char *arg = *argv;
  111.     if (*arg == '-') {
  112.         char c;
  113.         while (!donext && !isspace(c = *++arg) && c) {
  114.         switch(c) {
  115.         case 'u':
  116.         case 'x':
  117.             unarc = 1;
  118.             break;
  119.         case 't':
  120.             testing++;
  121.             unarc = 1;    /* implied */
  122.             break;
  123.         case 'l':
  124.             listing++;
  125.             unarc = 1;    /* implied */
  126.             break;
  127.         case 'q':
  128.             quiet = 1;
  129.             break;
  130.         case 'v':
  131.             verbose = 1;
  132.             break;
  133.         case 'f':
  134.             force = 1;
  135.             break;
  136.         case 's':
  137.             stamp = 0;
  138.             break;
  139.         case 'R':
  140.             retry = 1;
  141.             break;
  142.         case 'V':
  143.             printf("%s v%s - maintained by %s - PUBLIC DOMAIN\n", ourname, VERSION, MAINTAINER);
  144.             break;
  145.         case 'T':
  146.             apptype = 1;
  147.             break;
  148.         case 'C':
  149.             singlecase = 1;
  150.             break;
  151.         case 'L':
  152.             if (*++arg)
  153.             logfile = arg;
  154.             else
  155.             if (--argc)
  156.                 logfile = *++argv;
  157.             else
  158.                 usage();
  159.             donext++;
  160.             break;
  161. #ifdef DEBUGGING
  162.         case 'D':
  163.             debugging = 1;
  164.             break;
  165. #endif /* DEBUGGING */
  166.         default:
  167.             error("unknown option '%c'", c);
  168.             exit(1);
  169.         }
  170.         }
  171.         argv++;
  172.         argc--;
  173.     } else
  174.         break;
  175.     }
  176.  
  177.     if (!argc)
  178.     usage();
  179.         
  180.     archive = *argv++;
  181.     files = argv;
  182.  
  183.     if (unarc)
  184.     i = do_unarc();
  185.     else
  186.     i = do_arc();
  187.     exit(i);
  188. }
  189.  
  190.  
  191. /*
  192.  * display program usage and exit
  193.  */
  194. void
  195. usage()
  196. {
  197.     fprintf(stderr, "usage: %s [options] archive [file ... file]\n", ourname);
  198.     fprintf(stderr, "       where options are:\n");
  199.     fprintf(stderr, "       -u or -x unarchive           -t test archive integrity\n");
  200.     fprintf(stderr, "       -l list archive contents     -q quiet\n");
  201.     fprintf(stderr, "       -f force file overwrite      -s no filestamp\n");
  202.     fprintf(stderr, "       -v verbose                   -V display version number\n");
  203.     fprintf(stderr, "       -R retry if archive corrupt  -L<name> set logfile name\n");
  204.     fprintf(stderr, "       -T append filetype to name   -C create lowercase filenames\n");
  205.     exit(1);
  206. }
  207.