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