diff options
Diffstat (limited to 'tar.c')
-rw-r--r-- | tar.c | 133 |
1 files changed, 62 insertions, 71 deletions
@@ -108,9 +108,7 @@ typedef struct { | |||
108 | */ | 108 | */ |
109 | static int listFlag; | 109 | static int listFlag; |
110 | static int extractFlag; | 110 | static int extractFlag; |
111 | #ifdef BB_FEATURE_TAR_CREATE | ||
112 | static int createFlag; | 111 | static int createFlag; |
113 | #endif | ||
114 | static int verboseFlag; | 112 | static int verboseFlag; |
115 | static int tostdoutFlag; | 113 | static int tostdoutFlag; |
116 | 114 | ||
@@ -185,9 +183,7 @@ extern int tar_main (int argc, char **argv) | |||
185 | 183 | ||
186 | errorFlag = FALSE; | 184 | errorFlag = FALSE; |
187 | extractFlag = FALSE; | 185 | extractFlag = FALSE; |
188 | #ifdef BB_FEATURE_TAR_CREATE | ||
189 | createFlag = FALSE; | 186 | createFlag = FALSE; |
190 | #endif | ||
191 | listFlag = FALSE; | 187 | listFlag = FALSE; |
192 | verboseFlag = FALSE; | 188 | verboseFlag = FALSE; |
193 | tostdoutFlag = FALSE; | 189 | tostdoutFlag = FALSE; |
@@ -199,90 +195,85 @@ extern int tar_main (int argc, char **argv) | |||
199 | /* | 195 | /* |
200 | * Parse the options. | 196 | * Parse the options. |
201 | */ | 197 | */ |
202 | if (**argv == '-') { | 198 | if (**argv == '-') |
203 | options = (*argv++) + 1; | 199 | options = (*argv++) + 1; |
204 | argc--; | 200 | else |
205 | for (; *options; options++) { | 201 | options = (*argv++); |
206 | switch (*options) { | 202 | argc--; |
207 | case 'f': | ||
208 | if (tarName != NULL) { | ||
209 | fprintf (stderr, "Only one 'f' option allowed\n"); | ||
210 | |||
211 | exit (FALSE); | ||
212 | } | ||
213 | |||
214 | tarName = *argv++; | ||
215 | argc--; | ||
216 | |||
217 | break; | ||
218 | |||
219 | case 't': | ||
220 | listFlag = TRUE; | ||
221 | break; | ||
222 | |||
223 | case 'x': | ||
224 | extractFlag = TRUE; | ||
225 | break; | ||
226 | #ifdef BB_FEATURE_TAR_CREATE | ||
227 | case 'c': | ||
228 | createFlag = TRUE; | ||
229 | break; | ||
230 | #else | ||
231 | case 'c': | ||
232 | fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" ); | ||
233 | |||
234 | exit (FALSE); | ||
235 | #endif | ||
236 | |||
237 | case 'v': | ||
238 | verboseFlag = TRUE; | ||
239 | break; | ||
240 | |||
241 | case 'O': | ||
242 | tostdoutFlag = TRUE; | ||
243 | break; | ||
244 | |||
245 | case '-': | ||
246 | usage( tar_usage); | ||
247 | break; | ||
248 | 203 | ||
249 | default: | 204 | for (; *options; options++) { |
250 | fprintf (stderr, "Unknown tar flag '%c'\n" | 205 | switch (*options) { |
251 | "Try `tar --help' for more information\n", | 206 | case 'f': |
252 | *options); | 207 | if (tarName != NULL) { |
208 | fprintf (stderr, "Only one 'f' option allowed\n"); | ||
253 | 209 | ||
254 | exit (FALSE); | 210 | exit (FALSE); |
255 | } | 211 | } |
256 | } | ||
257 | } | ||
258 | 212 | ||
259 | /* | 213 | tarName = *argv++; |
260 | * Validate the options. | 214 | argc--; |
261 | */ | 215 | |
262 | if (extractFlag + listFlag | 216 | break; |
263 | #ifdef BB_FEATURE_TAR_CREATE | 217 | |
264 | + createFlag | 218 | case 't': |
265 | #endif | 219 | if (extractFlag == TRUE || createFlag == TRUE ) |
266 | != (TRUE+FALSE+FALSE)) { | 220 | goto flagError; |
267 | fprintf (stderr, | 221 | listFlag = TRUE; |
268 | "Exactly one of 'c', 'x' or 't' must be specified\n"); | 222 | break; |
269 | 223 | ||
270 | exit (FALSE); | 224 | case 'x': |
225 | if (listFlag == TRUE || createFlag == TRUE ) | ||
226 | goto flagError; | ||
227 | extractFlag = TRUE; | ||
228 | break; | ||
229 | case 'c': | ||
230 | if (extractFlag == TRUE || listFlag == TRUE) | ||
231 | goto flagError; | ||
232 | createFlag = TRUE; | ||
233 | break; | ||
234 | |||
235 | case 'v': | ||
236 | verboseFlag = TRUE; | ||
237 | break; | ||
238 | |||
239 | case 'O': | ||
240 | tostdoutFlag = TRUE; | ||
241 | break; | ||
242 | |||
243 | case '-': | ||
244 | usage( tar_usage); | ||
245 | break; | ||
246 | |||
247 | default: | ||
248 | fprintf (stderr, "Unknown tar flag '%c'\n" | ||
249 | "Try `tar --help' for more information\n", | ||
250 | *options); | ||
251 | exit (FALSE); | ||
252 | } | ||
271 | } | 253 | } |
272 | 254 | ||
273 | /* | 255 | /* |
274 | * Do the correct type of action supplying the rest of the | 256 | * Do the correct type of action supplying the rest of the |
275 | * command line arguments as the list of files to process. | 257 | * command line arguments as the list of files to process. |
276 | */ | 258 | */ |
277 | #ifdef BB_FEATURE_TAR_CREATE | 259 | if (createFlag==TRUE) { |
278 | if (createFlag==TRUE) | 260 | #ifndef BB_FEATURE_TAR_CREATE |
261 | fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" ); | ||
262 | exit (FALSE); | ||
263 | #else | ||
279 | writeTarFile (argc, argv); | 264 | writeTarFile (argc, argv); |
280 | else | ||
281 | #endif | 265 | #endif |
266 | } else { | ||
282 | readTarFile (argc, argv); | 267 | readTarFile (argc, argv); |
283 | if (errorFlag==TRUE) | 268 | } |
269 | if (errorFlag==TRUE) { | ||
284 | fprintf (stderr, "\n"); | 270 | fprintf (stderr, "\n"); |
271 | } | ||
285 | exit (!errorFlag); | 272 | exit (!errorFlag); |
273 | |||
274 | flagError: | ||
275 | fprintf (stderr, "Exactly one of 'c', 'x' or 't' must be specified\n"); | ||
276 | exit (FALSE); | ||
286 | } | 277 | } |
287 | 278 | ||
288 | 279 | ||