home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / unix / macutil2.sha / macutil / macunpack / macunpack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-05  |  4.1 KB  |  202 lines

  1. #include "macunpack.h"
  2. #include "globals.h"
  3. #include "../util/patchlevel.h"
  4. #include "../fileio/wrfile.h"
  5. #include "../fileio/wrfileopt.h"
  6. #include "../fileio/kind.h"
  7. #include "../util/util.h"
  8.  
  9. #define LOCALOPT    "ilvqVH"
  10.  
  11. extern char *strcat();
  12. #ifdef STF
  13. extern void stf();
  14. #endif /* STF */
  15. #ifdef PIT
  16. extern void pit();
  17. #endif /* PIT */
  18. #ifdef SIT
  19. extern void sit();
  20. #endif /* SIT */
  21. #ifdef CPT
  22. extern void cpt();
  23. #endif /* CPT */
  24. void macbinary();
  25.  
  26. static void usage();
  27.  
  28. static char options[128];
  29.  
  30. int main(argc, argv)
  31. int argc;
  32. char *argv[];
  33. {
  34.     int c;
  35.     extern int optind;
  36.     extern char *optarg;
  37.     int errflg;
  38.  
  39.     set_wrfileopt(0);
  40.     (void)strcat(options, get_wrfileopt());
  41.     (void)strcat(options, LOCALOPT);
  42.     errflg = 0;
  43.  
  44.     while((c = getopt(argc, argv, options)) != EOF) {
  45. #ifdef SCAN
  46.     if(c == 'S') {
  47.         no_dd++;
  48.     }
  49. #endif /* SCAN */
  50.     if(!wrfileopt((char)c)) {
  51.         switch(c) {
  52.         case 'l':
  53.         list++;
  54.         break;
  55.         case 'q':
  56.         query++;
  57.         break;
  58.         case 'v':
  59.         verbose++;
  60.         break;
  61.         case 'i':
  62.         info_only++;
  63.         break;
  64.         case '?':
  65.         errflg++;
  66.         break;
  67.         case 'H':
  68.         give_wrfileopt();
  69.         (void)fprintf(stderr, "Macunpack specific options:\n");
  70.         (void)fprintf(stderr,
  71.             "-i:\tgive information only, do not unpack\n");
  72.         (void)fprintf(stderr, "-l:\tgive listing\n");
  73.         (void)fprintf(stderr, "-v:\tgive verbose listing\n");
  74.         (void)fprintf(stderr,
  75.             "-q:\tquery for every file/folder before unpacking\n");
  76.         (void)fprintf(stderr,
  77.             "-V:\tgive information about this version\n");
  78.         (void)fprintf(stderr, "-H:\tthis message\n");
  79.         (void)fprintf(stderr, "Default is silent unpacking\n");
  80.         exit(0);
  81.         case 'V':
  82.         (void)fprintf(stderr, "Version %s, ", VERSION);
  83.         (void)fprintf(stderr, "patchlevel %d", PATCHLEVEL);
  84.         (void)fprintf(stderr, "%s.\n", get_mina());
  85.         (void)fprintf(stderr, "Archive/file types recognized:\n");
  86. #ifdef BIN
  87.         (void)fprintf(stderr,
  88.             "\tBinHex 5.0, MacBinary 1.0 and UMCP (with caveat)\n");
  89. #endif /* BIN */
  90. #ifdef JDW
  91.         (void)fprintf(stderr, "\tCompress It\n");
  92. #endif /* JDW */
  93. #ifdef STF
  94.         (void)fprintf(stderr, "\tShrinkToFit\n");
  95. #endif /* STF */
  96. #ifdef LZC
  97.         (void)fprintf(stderr, "\tMacCompress\n");
  98. #endif /* LZC */
  99. #ifdef ASQ
  100.         (void)fprintf(stderr, "\tAutoSqueeze\n");
  101. #endif /* ASQ */
  102. #ifdef ARC
  103.         (void)fprintf(stderr, "\tArcMac\n");
  104. #endif /* ARC */
  105. #ifdef PIT
  106.         (void)fprintf(stderr, "\tPackIt\n");
  107. #endif /* PIT */
  108. #ifdef SIT
  109.         (void)fprintf(stderr, "\tStuffIt and StuffIt Deluxe\n");
  110. #endif /* SIT */
  111. #ifdef DIA
  112.         (void)fprintf(stderr, "\tDiamond\n");
  113. #endif /* DIA */
  114. #ifdef CPT
  115.         (void)fprintf(stderr, "\tCompactor\n");
  116. #endif /* CPT */
  117. #ifdef ZMA
  118.         (void)fprintf(stderr, "\tZoom\n");
  119. #endif /* ZMA */
  120. #ifdef LZH
  121.         (void)fprintf(stderr, "\tMacLHa\n");
  122. #endif /* LZH */
  123. #ifdef DD
  124.         (void)fprintf(stderr, "\tDiskDoubler\n");
  125. #endif /* DD */
  126.         exit(0);
  127.         }
  128.     }
  129.     }
  130.     if(errflg) {
  131.     usage();
  132.     exit(1);
  133.     }
  134.  
  135.     if(optind == argc) {
  136.     infp = stdin;
  137.     } else {
  138.     if((infp = fopen(argv[optind], "r")) == NULL) {
  139.         (void)fprintf(stderr,"Can't open input file \"%s\"\n",argv[optind]);
  140.         exit(1);
  141.     }
  142. #ifdef SCAN
  143.     do_idf(argv[optind], UNIX_NAME);
  144. #endif /* SCAN */
  145.     }
  146.  
  147.     if(info_only || verbose || query) {
  148.     list++;
  149.     }
  150.     c = getc(infp);
  151.     (void)ungetc(c, infp);
  152.     switch(c) {
  153.     case 0:
  154.     macbinary();
  155.     break;
  156. #ifdef STF
  157.     case 'R':
  158.     if(verbose) {
  159.         (void)fprintf(stderr, "This is a \"ShrinkToFit\" packed file.\n");
  160.     }
  161.     stf(~(unsigned long)1);
  162.     break;
  163. #endif /* STF */
  164. #ifdef PIT
  165.     case 'P':
  166.     if(verbose) {
  167.         (void)fprintf(stderr, "This is a \"PackIt\" archive.\n");
  168.     }
  169.     pit();
  170.     break;
  171. #endif /* PIT */
  172. #ifdef SIT
  173.     case 'S':
  174.     if(verbose) {
  175.         (void)fprintf(stderr, "This is a \"StuffIt\" archive.\n");
  176.     }
  177.     sit();
  178.     break;
  179. #endif /* SIT */
  180. #ifdef CPT
  181.     case 1:
  182.     if(verbose) {
  183.         (void)fprintf(stderr, "This is a \"Compactor\" archive.\n");
  184.     }
  185.     cpt();
  186.     break;
  187. #endif /* CPT */
  188.     default:
  189.     (void)fprintf(stderr, "Unrecognized archive type\n");
  190.     exit(1);
  191.     }
  192.     exit(0);
  193.     /* NOTREACHED */
  194. }
  195.  
  196. static void usage()
  197. {
  198.     (void)fprintf(stderr, "Usage: macunpack [-%s] [filename]\n", options);
  199.     (void)fprintf(stderr, "Use \"macunpack -H\" for help.\n");
  200. }
  201.  
  202.