Fix option handling, -i or -t must be given, if both ignore the -t.

Use bb_getopt_ulflags.
This commit is contained in:
Glenn L McGrath 2004-02-25 09:30:06 +00:00
parent d8746cdc40
commit 10b781345f

View File

@ -31,56 +31,61 @@
#include "unarchive.h" #include "unarchive.h"
#include "busybox.h" #include "busybox.h"
#define CPIO_OPT_EXTRACT 0x01
#define CPIO_OPT_TEST 0x02
#define CPIO_OPT_UNCONDITIONAL 0x04
#define CPIO_OPT_VERBOSE 0x08
#define CPIO_OPT_FILE 0x10
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
#define CPIO_OPT_PRESERVE_MTIME 0x40
extern int cpio_main(int argc, char **argv) extern int cpio_main(int argc, char **argv)
{ {
archive_handle_t *archive_handle; archive_handle_t *archive_handle;
int opt; char *cpio_filename = NULL;
unsigned long opt;
/* Initialise */ /* Initialise */
archive_handle = init_handle(); archive_handle = init_handle();
archive_handle->src_fd = fileno(stdin); archive_handle->src_fd = fileno(stdin);
archive_handle->seek = seek_by_char; archive_handle->seek = seek_by_char;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) { opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename);
switch (opt) {
case 'i': /* extract */ /* One of either extract or test options must be given */
archive_handle->action_data = data_extract_all; if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
break; bb_show_usage();
case 'd': /* create _leading_ directories */ }
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
break; if (opt & CPIO_OPT_TEST) {
#if 0 /* if both extract and test option are given, ignore extract option */
case 'm': /* preserve modification time */ if (opt & CPIO_OPT_EXTRACT) {
archive_handle->flags |= ARCHIVE_PRESERVE_DATE; opt &= ~CPIO_OPT_EXTRACT;
break; }
#endif archive_handle->action_header = header_list;
case 'v': /* verbosly list files */ }
if (archive_handle->action_header == header_list) { if (opt & CPIO_OPT_EXTRACT) {
archive_handle->action_header = header_verbose_list; archive_handle->action_data = data_extract_all;
} else { }
archive_handle->action_header = header_list; if (opt & CPIO_OPT_UNCONDITIONAL) {
} archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
break; archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
case 'u': /* unconditional */ }
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL; if (opt & CPIO_OPT_VERBOSE) {
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER; if (archive_handle->action_header == header_list) {
break; archive_handle->action_header = header_verbose_list;
case 't': /* list files */ } else {
if (archive_handle->action_header == header_list) { archive_handle->action_header = header_list;
archive_handle->action_header = header_verbose_list;
} else {
archive_handle->action_header = header_list;
}
break;
case 'F':
archive_handle->src_fd = bb_xopen(optarg, O_RDONLY);
archive_handle->seek = seek_by_jump;
break;
default:
bb_show_usage();
} }
} }
if (cpio_filename) { /* CPIO_OPT_FILE */
archive_handle->src_fd = bb_xopen(cpio_filename, O_RDONLY);
archive_handle->seek = seek_by_jump;
}
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
}
while (optind < argc) { while (optind < argc) {
archive_handle->filter = filter_accept_list; archive_handle->filter = filter_accept_list;