Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:45:00 UTC

view on githubraw file Latest commit 351d1cc0 on 2008-03-12 20:38:49 UTC
ec6cf3b09d Ed H*0001 /* (C) Copyright 1993,1994 by Carnegie Mellon University
                0002  * All Rights Reserved.
                0003  *
                0004  * Permission to use, copy, modify, distribute, and sell this software
                0005  * and its documentation for any purpose is hereby granted without
                0006  * fee, provided that the above copyright notice appear in all copies
                0007  * and that both that copyright notice and this permission notice
                0008  * appear in supporting documentation, and that the name of Carnegie
                0009  * Mellon University not be used in advertising or publicity
                0010  * pertaining to distribution of the software without specific,
                0011  * written prior permission.  Carnegie Mellon University makes no
                0012  * representations about the suitability of this software for any
                0013  * purpose.  It is provided "as is" without express or implied
                0014  * warranty.
                0015  *
                0016  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
                0017  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
                0018  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
                0019  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                0020  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
                0021  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                0022  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                0023  * SOFTWARE.
                0024  */
                0025 #include <stdio.h>
e768bd1221 Jean*0026 #include <stdlib.h>
351d1cc027 Jean*0027 #ifdef HAVE_GETOPT_H
e768bd1221 Jean*0028 #include <getopt.h>
351d1cc027 Jean*0029 #endif
e768bd1221 Jean*0030 #include <unistd.h>
ec6cf3b09d Ed H*0031 #include "version.h"
                0032 #include "part.h"
                0033 
                0034 extern int overwrite_files;
                0035 extern int didchat;
                0036 int quiet;
                0037 
                0038 void usage(void);
e768bd1221 Jean*0039 int handleMessage(struct part *inpart, char *defaultContentType,
                0040           int inAppleDouble, int extractText);
ec6cf3b09d Ed H*0041 
                0042 int main(int argc, char **argv)
                0043 {
                0044     int opt;
                0045     FILE *file;
                0046     int extractText = 0;
                0047     
                0048     while ((opt = getopt(argc, argv, "qftC:")) != EOF) {
                0049     switch (opt) {
                0050     case 'f':
                0051         overwrite_files = 1;
                0052         break;
                0053 
                0054     case 'q':
                0055         quiet = 1;
                0056         break;
                0057 
                0058     case 't':
                0059         extractText = 1;
                0060         break;
                0061 
                0062     case 'C':
                0063         if (chdir(optarg)) {
                0064         perror(optarg);
                0065         exit(1);
                0066         }
                0067         break;
                0068 
                0069     default:
                0070         usage();
                0071     }
                0072     }
                0073 
                0074     if (optind == argc) {
                0075     fprintf(stderr, "munpack: reading from standard input\n");
                0076     didchat = 0;
                0077     handleMessage(part_init(stdin), "text/plain", 0, extractText);
                0078     if (!didchat) {
                0079         fprintf(stdout,
                0080             "Did not find anything to unpack from standard input\n");
                0081     }
                0082     exit(0);
                0083     }
                0084 
                0085     while (argv[optind]) {
                0086     file = fopen(argv[optind], "r");
                0087     if (!file) {
                0088         perror(argv[optind]);
                0089     }
                0090     else {
                0091         didchat = 0;
                0092         handleMessage(part_init(file), "text/plain", 0, extractText);
                0093         fclose(file);
                0094         if (!didchat) {
                0095         fprintf(stdout, 
                0096             "Did not find anything to unpack from %s\n",
                0097             argv[optind]);
                0098         }
                0099     }
                0100     optind++;
                0101     }
                0102     exit(0);
                0103 }
                0104 
                0105 void usage(void) {
                0106     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
e768bd1221 Jean*0107     fprintf(stderr, "usage: munpack [-f] [-q] [-t] [-C directory] [files...]\n");
ec6cf3b09d Ed H*0108     exit(1);
                0109 }
                0110 
                0111 void warn(char *s)
                0112 {
                0113     fprintf(stderr, "munpack: warning: %s\n", s);
                0114 }
                0115 
                0116 void chat(char *s)
                0117 {
                0118     didchat = 1;
                0119     if (!quiet) fprintf(stdout, "%s\n", s);
                0120 }