home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / mpackppc-wos / src / unixunpk.c < prev    next >
C/C++ Source or Header  |  1998-04-27  |  3KB  |  119 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. #include <stdio.h>
  26. #include "version.h"
  27. #include "part.h"
  28.  
  29. extern int optind;
  30. extern char *optarg;
  31.  
  32. extern int overwrite_files;
  33. extern int didchat;
  34. int quiet;
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.     int opt;
  41.     FILE *file;
  42.     int extractText = 0;
  43.     
  44.     while ((opt = getopt(argc, argv, "qftC:")) != EOF) {
  45.     switch (opt) {
  46.     case 'f':
  47.         overwrite_files = 1;
  48.         break;
  49.  
  50.     case 'q':
  51.         quiet = 1;
  52.         break;
  53.  
  54.     case 't':
  55.         extractText = 1;
  56.         break;
  57.  
  58.     case 'C':
  59.         if (chdir(optarg)) {
  60.         perror(optarg);
  61.         exit(1);
  62.         }
  63.         break;
  64.  
  65.     default:
  66.         usage();
  67.     }
  68.     }
  69.  
  70.     if (optind == argc) {
  71.     fprintf(stderr, "munpack: reading from standard input\n");
  72.     didchat = 0;
  73.     handleMessage(part_init(stdin), "text/plain", 0, extractText);
  74.     if (!didchat) {
  75.         fprintf(stdout,
  76.             "Did not find anything to unpack from standard input\n");
  77.     }
  78.     exit(0);
  79.     }
  80.  
  81.     while (argv[optind]) {
  82.     file = fopen(argv[optind], "r");
  83.     if (!file) {
  84.         perror(argv[optind]);
  85.     }
  86.     else {
  87.         didchat = 0;
  88.         handleMessage(part_init(file), "text/plain", 0, extractText);
  89.         fclose(file);
  90.         if (!didchat) {
  91.         fprintf(stdout, 
  92.             "Did not find anything to unpack from %s\n",
  93.             argv[optind]);
  94.         }
  95.     }
  96.     optind++;
  97.     }
  98.     exit(0);
  99. }
  100.  
  101. usage() {
  102.     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
  103.     fprintf(stderr, "usage: munpack [-f] [-q] [-C directory] [files...]\n");
  104.     exit(1);
  105. }
  106.  
  107. warn(s)
  108. char *s;
  109. {
  110.     fprintf(stderr, "munpack: warning: %s\n", s);
  111. }
  112.  
  113. chat(s)
  114. char *s;
  115. {
  116.     didchat = 1;
  117.     if (!quiet) fprintf(stdout, "%s\n", s);
  118. }
  119.