home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / mpackppc-wos / src / arcunpk.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  3KB  |  123 lines

  1. /* (C) Copyright 1993,1994 by Carnegie Mellon University
  2.  * All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without
  6.  * fee, provided that the above copyright notice appear in all copies
  7.  * and that both that copyright notice and this permission notice
  8.  * appear in supporting documentation, and that the name of Carnegie
  9.  * Mellon University not be used in advertising or publicity
  10.  * pertaining to distribution of the software without specific,
  11.  * written prior permission.  Carnegie Mellon University makes no
  12.  * representations about the suitability of this software for any
  13.  * purpose.  It is provided "as is" without express or implied
  14.  * warranty.
  15.  *
  16.  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
  17.  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  18.  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
  19.  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  21.  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  22.  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  */
  25. /* this is almost exactly the same as unixunpk.c */
  26. #include <stdio.h>
  27. #include "version.h"
  28. #include "part.h"
  29.  
  30. extern int optind;
  31. extern char *optarg;
  32.  
  33. extern int overwrite_files;
  34. extern int didchat;
  35. int quiet;
  36.  
  37. main(argc, argv)
  38. int argc;
  39. char **argv;
  40. {
  41.     int opt;
  42.     FILE *file;
  43.     int extractText = 0;
  44.  
  45.     while ((opt = getopt(argc, argv, "qftC:")) != EOF) {
  46.     switch (opt) {
  47.     case 'f':
  48.         overwrite_files = 1;
  49.         break;
  50.  
  51.     case 'q':
  52.         quiet = 1;
  53.         break;
  54.  
  55.     case 't':
  56.         extractText = 1;
  57.         break;
  58.  
  59.     case 'C':
  60.         if (chdir(optarg)) {
  61.         perror(optarg);
  62.         exit(1);
  63.         }
  64.         break;
  65.  
  66.     default:
  67.         usage();
  68.     }
  69.     }
  70.  
  71.     if (optind == argc) {
  72.     fprintf(stderr, "munpack: reading from standard input\n");
  73.     didchat = 0;
  74.     handleMessage(part_init(stdin), "text/plain", 0, extractText);
  75.     if (!didchat) {
  76.         fprintf(stdout,
  77.             "Did not find anything to unpack from standard input\n");
  78.     }
  79.     exit(0);
  80.     }
  81.  
  82.     while (argv[optind]) {
  83.     file = fopen(argv[optind], "r");
  84.     if (!file) {
  85.         perror(argv[optind]);
  86.     }
  87.     else {
  88.         didchat = 0;
  89.         handleMessage(part_init(file), "text/plain", 0, extractText);
  90.         fclose(file);
  91.         if (!didchat) {
  92.         fprintf(stdout,
  93.             "Did not find anything to unpack from %s\n",
  94.             argv[optind]);
  95.         }
  96.     }
  97.     optind++;
  98.     }
  99.     exit(0);
  100. }
  101.  
  102. usage() {
  103.     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
  104. #ifdef TEST_VERSION
  105.     fprintf(stderr, "*** Arc "TEST_VERSION".  Report problems to olly@mantis.co.uk ***\n");
  106. #endif
  107.     fprintf(stderr, "usage: munpack [-f] [-q] [-C directory] [files...]\n");
  108.     exit(1);
  109. }
  110.  
  111. warn(s)
  112. char *s;
  113. {
  114.     fprintf(stderr, "munpack: warning: %s\n", s);
  115. }
  116.  
  117. chat(s)
  118. char *s;
  119. {
  120.     didchat = 1;
  121.     if (!quiet) fprintf(stdout, "%s\n", s);
  122. }
  123.