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