Debian Codegraph @

unixunpk.c

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