| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
} |