diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-22 15:13:38 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-09-22 15:13:38 +0000 |
| commit | 4ea5a7cc18a7fac943bedd99f61aaa8ffa94ed7a (patch) | |
| tree | c6bd6a4927d6716953bafc82f8b27ad4d2874c99 | |
| parent | eaf1194e42116fb2ae22ad4dd6dbb848537bc17e (diff) | |
| download | busybox-w32-4ea5a7cc18a7fac943bedd99f61aaa8ffa94ed7a.tar.gz busybox-w32-4ea5a7cc18a7fac943bedd99f61aaa8ffa94ed7a.tar.bz2 busybox-w32-4ea5a7cc18a7fac943bedd99f61aaa8ffa94ed7a.zip | |
gzip: getopt_ulflags'isation
git-svn-id: svn://busybox.net/trunk/busybox@16187 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | archival/gzip.c | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 7c18154ff..05f6cb582 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
| @@ -1122,44 +1122,36 @@ typedef struct dirent dir_type; | |||
| 1122 | /* ======================================================================== */ | 1122 | /* ======================================================================== */ |
| 1123 | int gzip_main(int argc, char **argv) | 1123 | int gzip_main(int argc, char **argv) |
| 1124 | { | 1124 | { |
| 1125 | enum { | ||
| 1126 | OPT_tostdout = 0x1, | ||
| 1127 | OPT_force = 0x2, | ||
| 1128 | }; | ||
| 1129 | |||
| 1130 | unsigned long opt; | ||
| 1125 | int result; | 1131 | int result; |
| 1126 | int inFileNum; | 1132 | int inFileNum; |
| 1127 | int outFileNum; | 1133 | int outFileNum; |
| 1128 | struct stat statBuf; | 1134 | struct stat statBuf; |
| 1129 | char *delFileName; | 1135 | char *delFileName; |
| 1130 | int tostdout = 0; | 1136 | |
| 1131 | int force = 0; | 1137 | opt = bb_getopt_ulflags(argc, argv, "cf123456789q" USE_GUNZIP("d")); |
| 1132 | int opt; | 1138 | //if (opt & 0x1) // -c |
| 1133 | 1139 | //if (opt & 0x2) // -f | |
| 1134 | while ((opt = getopt(argc, argv, "cf123456789dq")) != -1) { | 1140 | /* Ignore 1-9 (compression level) options */ |
| 1135 | switch (opt) { | 1141 | //if (opt & 0x4) // -1 |
| 1136 | case 'c': | 1142 | //if (opt & 0x8) // -2 |
| 1137 | tostdout = 1; | 1143 | //if (opt & 0x10) // -3 |
| 1138 | break; | 1144 | //if (opt & 0x20) // -4 |
| 1139 | case 'f': | 1145 | //if (opt & 0x40) // -5 |
| 1140 | force = 1; | 1146 | //if (opt & 0x80) // -6 |
| 1141 | break; | 1147 | //if (opt & 0x100) // -7 |
| 1142 | /* Ignore 1-9 (compression level) options */ | 1148 | //if (opt & 0x200) // -8 |
| 1143 | case '1': | 1149 | //if (opt & 0x400) // -9 |
| 1144 | case '2': | 1150 | //if (opt & 0x800) // -q |
| 1145 | case '3': | 1151 | if (ENABLE_GUNZIP && (opt & 0x1000)) { // -d |
| 1146 | case '4': | 1152 | /* FIXME: bb_getopt_ulflags should not depend on optind */ |
| 1147 | case '5': | 1153 | optind = 1; |
| 1148 | case '6': | 1154 | return gunzip_main(argc, argv); |
| 1149 | case '7': | ||
| 1150 | case '8': | ||
| 1151 | case '9': | ||
| 1152 | break; | ||
| 1153 | case 'q': | ||
| 1154 | break; | ||
| 1155 | #ifdef CONFIG_GUNZIP | ||
| 1156 | case 'd': | ||
| 1157 | optind = 1; | ||
| 1158 | return gunzip_main(argc, argv); | ||
| 1159 | #endif | ||
| 1160 | default: | ||
| 1161 | bb_show_usage(); | ||
| 1162 | } | ||
| 1163 | } | 1155 | } |
| 1164 | 1156 | ||
| 1165 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 1157 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
| @@ -1211,7 +1203,7 @@ int gzip_main(int argc, char **argv) | |||
| 1211 | bb_perror_msg_and_die("%s", argv[i]); | 1203 | bb_perror_msg_and_die("%s", argv[i]); |
| 1212 | time_stamp = statBuf.st_ctime; | 1204 | time_stamp = statBuf.st_ctime; |
| 1213 | 1205 | ||
| 1214 | if (!tostdout) { | 1206 | if (!(opt & OPT_tostdout)) { |
| 1215 | path = xasprintf("%s.gz", argv[i]); | 1207 | path = xasprintf("%s.gz", argv[i]); |
| 1216 | 1208 | ||
| 1217 | /* Open output file */ | 1209 | /* Open output file */ |
| @@ -1233,7 +1225,7 @@ int gzip_main(int argc, char **argv) | |||
| 1233 | outFileNum = STDOUT_FILENO; | 1225 | outFileNum = STDOUT_FILENO; |
| 1234 | } | 1226 | } |
| 1235 | 1227 | ||
| 1236 | if (path == NULL && isatty(outFileNum) && force == 0) { | 1228 | if (path == NULL && isatty(outFileNum) && !(opt & OPT_force)) { |
| 1237 | bb_error_msg | 1229 | bb_error_msg |
| 1238 | ("compressed data not written to a terminal. Use -f to force compression."); | 1230 | ("compressed data not written to a terminal. Use -f to force compression."); |
| 1239 | free(path); | 1231 | free(path); |
