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
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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 }