Debian Codegraph @

unixunpk.c

raw symbols ◀ ▶
Source reconstructed at patch state 3 of 4 — not the installed (fully patched) source.
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 printf("Replacement: '%c'\n", replacement_char);
64 break;
65
66 case 'C':
67 if (chdir(optarg)) {
68 perror(optarg);
69 exit(1);
70 }
71 break;
72
73 default:
74 usage();
75 }
76 }
77
78 if (optind == argc) {
79 fprintf(stderr, "munpack: reading from standard input\n");
80 didchat = 0;
81 handleMessage(part_init(stdin), "text/plain", 0, extractText);
82 if (!didchat) {
83 fprintf(stdout,
84 "Did not find anything to unpack from standard input\n");
85 }
86 exit(0);
87 }
88
89 while (argv[optind]) {
90 file = fopen(argv[optind], "r");
91 if (!file) {
92 perror(argv[optind]);
93 exit(1);
94 }
95 else {
96 didchat = 0;
97 handleMessage(part_init(file), "text/plain", 0, extractText);
98 fclose(file);
99 if (!didchat) {
100 fprintf(stdout,
101 "Did not find anything to unpack from %s\n",
102 argv[optind]);
103 }
104 }
105 optind++;
106 }
107 exit(0);
108 }
109
110 void usage(void) {
111 fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
112 fprintf(stderr, "usage: munpack [-f] [-q] [-t] [-r character] [-C directory] [files...]\n");
113 exit(1);
114 }
115
116 void warn(char *s)
117 {
118 fprintf(stderr, "munpack: warning: %s\n", s);
119 }
120
121 void chat(char *s)
122 {
123 didchat = 1;
124 if (!quiet) fprintf(stdout, "%s\n", s);
125 }