- while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) {
- switch (opt) {
-
- /* One and only one of these is required */
- case 'c':
- untar_funct_required |= untar_create;
- break;
- case 't':
- untar_funct_required |= untar_list;
- extract_function |= extract_list | extract_unconditional;
- break;
- case 'x':
- untar_funct_required |= untar_extract;
- extract_function |=
- (extract_all_to_fs | extract_unconditional |
- extract_create_leading_dirs);
- break;
-
- /* These are optional */
- /* Exclude or Include files listed in <filename> */
-#ifdef CONFIG_FEATURE_TAR_EXCLUDE
- case 'X':
- append_file_list_to_list(optarg, &exclude_list,
- &exclude_list_count);
- break;
-#endif
- case 'T':
- /* by default a list is an include list */
- append_file_list_to_list(optarg, &include_list,
- &include_list_count);
- break;
+ /* Initialise default values */
+ tar_handle = init_handle();
+ tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
+
+ bb_opt_complementaly = "c~tx:t~cx:x~ct:X*";
+ opt = bb_getopt_ulflags(argc, argv, tar_options,
+ NULL, /* T: arg is ignored by default
+ a list is an include list */
+ &(tar_handle->reject),
+ &base_dir, /* Change to dir <optarg> */
+ &tar_filename); /* archive filename */
+ /* Check one and only one context option was given */
+ if(opt & 0x80000000UL)
+ bb_show_usage();
+ ctx_flag = opt & (CTX_CREATE | CTX_TEST | CTX_EXTRACT);
+ if(ctx_flag & CTX_TEST) {
+ if ((tar_handle->action_header == header_list) ||
+ (tar_handle->action_header == header_verbose_list)) {
+ tar_handle->action_header = header_verbose_list;
+ } else {
+ tar_handle->action_header = header_list;
+ }
+ }
+ if(ctx_flag & CTX_EXTRACT) {
+ if (tar_handle->action_data != data_extract_to_stdout)
+ tar_handle->action_data = data_extract_all;
+ }
+ if(opt & TAR_OPT_2STDOUT) {
+ /* To stdout */
+ tar_handle->action_data = data_extract_to_stdout;
+ }
+ if(opt & TAR_OPT_VERBOSE) {
+ if ((tar_handle->action_header == header_list) ||
+ (tar_handle->action_header == header_verbose_list))
+ {
+ tar_handle->action_header = header_verbose_list;
+ } else {
+ tar_handle->action_header = header_list;
+ }
+ }
+ if (opt & TAR_OPT_KEEP_OLD) {
+ tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
+ }