#include <getline.h>
#include <argp.h>
#include <argp-namefrob.h>
+#include <argp-fmtstream.h>
#include <signal.h>
#if ! defined SIGCHLD && defined SIGCLD
}
void
-tar_list_quoting_styles (FILE *fp, char *prefix)
+tar_list_quoting_styles (argp_fmtstream_t fs, char *prefix)
{
int i;
for (i = 0; quoting_style_args[i]; i++)
- fprintf (fp, "%s%s\n", prefix, quoting_style_args[i]);
+ argp_fmtstream_printf (fs, "%s%s\n", prefix, quoting_style_args[i]);
}
void
ATIME_PRESERVE_OPTION,
BACKUP_OPTION,
CHECKPOINT_OPTION,
- CHECK_LINKS_OPTION,
DELAY_DIRECTORY_RESTORE_OPTION,
DELETE_OPTION,
EXCLUDE_CACHES_OPTION,
SAME_OWNER_OPTION,
SHOW_DEFAULTS_OPTION,
SHOW_OMITTED_DIRS_OPTION,
- SHOW_STORED_NAMES_OPTION,
+ SHOW_TRANSFORMED_NAMES_OPTION,
STRIP_COMPONENTS_OPTION,
SUFFIX_OPTION,
TEST_LABEL_OPTION,
TOTALS_OPTION,
TO_COMMAND_OPTION,
+ TRANSFORM_OPTION,
UNQUOTE_OPTION,
USAGE_OPTION,
USE_COMPRESS_PROGRAM_OPTION,
N_("exclude patterns listed in FILE"), GRID+1 },
{"exclude-caches", EXCLUDE_CACHES_OPTION, 0, 0,
N_("exclude directories containing a cache tag"), GRID+1 },
- {"ignore-case", IGNORE_CASE_OPTION, 0, 0,
- N_("exclusion ignores case"), GRID+1 },
- {"anchored", ANCHORED_OPTION, 0, 0,
- N_("exclude patterns match file name start"), GRID+1 },
- {"no-anchored", NO_ANCHORED_OPTION, 0, 0,
- N_("exclude patterns match after any `/' (default)"), GRID+1 },
- {"no-ignore-case", NO_IGNORE_CASE_OPTION, 0, 0,
- N_("exclusion is case sensitive (default)"), GRID+1 },
- {"no-wildcards", NO_WILDCARDS_OPTION, 0, 0,
- N_("exclude patterns are plain strings"), GRID+1 },
- {"no-wildcards-match-slash", NO_WILDCARDS_MATCH_SLASH_OPTION, 0, 0,
- N_("exclude pattern wildcards do not match `/'"), GRID+1 },
{"no-recursion", NO_RECURSION_OPTION, 0, 0,
N_("avoid descending automatically in directories"), GRID+1 },
{"one-file-system", ONE_FILE_SYSTEM_OPTION, 0, 0,
N_("stay in local file system when creating archive"), GRID+1 },
- {NULL, 'l', 0, OPTION_HIDDEN, "", GRID+1 },
{"recursion", RECURSION_OPTION, 0, 0,
N_("recurse into directories (default)"), GRID+1 },
{"absolute-names", 'P', 0, 0,
N_("follow symlinks; archive and dump the files they point to"), GRID+1 },
{"starting-file", 'K', N_("MEMBER-NAME"), 0,
N_("begin at member MEMBER-NAME in the archive"), GRID+1 },
- {"strip-components", STRIP_COMPONENTS_OPTION, N_("NUMBER"), 0,
- N_("strip NUMBER leading components from file names"), GRID+1 },
{"newer", 'N', N_("DATE-OR-FILE"), 0,
N_("only store files newer than DATE-OR-FILE"), GRID+1 },
{"newer-mtime", NEWER_MTIME_OPTION, N_("DATE"), 0,
N_("backup before removal, choose version CONTROL"), GRID+1 },
{"suffix", SUFFIX_OPTION, N_("STRING"), 0,
N_("backup before removal, override usual suffix ('~' unless overridden by environment variable SIMPLE_BACKUP_SUFFIX)"), GRID+1 },
+#undef GRID
+
+#define GRID 92
+ {NULL, 0, NULL, 0,
+ N_("File name transformations:"), GRID },
+ {"strip-components", STRIP_COMPONENTS_OPTION, N_("NUMBER"), 0,
+ N_("strip NUMBER leading components from file names on extraction"),
+ GRID+1 },
+ {"transform", TRANSFORM_OPTION, N_("EXPRESSION"), 0,
+ N_("Use sed replace EXPRESSION to transform file names"), GRID+1 },
+#undef GRID
+
+#define GRID 95
+ {NULL, 0, NULL, 0,
+ N_("File name matching options (affect both exclude and include patterns):"),
+ GRID },
+ {"ignore-case", IGNORE_CASE_OPTION, 0, 0,
+ N_("ignore case"), GRID+1 },
+ {"anchored", ANCHORED_OPTION, 0, 0,
+ N_("patterns match file name start"), GRID+1 },
+ {"no-anchored", NO_ANCHORED_OPTION, 0, 0,
+ N_("patterns match after any `/' (default for exclusion)"), GRID+1 },
+ {"no-ignore-case", NO_IGNORE_CASE_OPTION, 0, 0,
+ N_("case sensitive matching (default)"), GRID+1 },
{"wildcards", WILDCARDS_OPTION, 0, 0,
- N_("exclude patterns use wildcards (default)"), GRID+1 },
+ N_("use wildcards (default for exclusion)"), GRID+1 },
+ {"no-wildcards", NO_WILDCARDS_OPTION, 0, 0,
+ N_("verbatim string matching"), GRID+1 },
+ {"no-wildcards-match-slash", NO_WILDCARDS_MATCH_SLASH_OPTION, 0, 0,
+ N_("wildcards do not match `/'"), GRID+1 },
{"wildcards-match-slash", WILDCARDS_MATCH_SLASH_OPTION, 0, 0,
- N_("exclude pattern wildcards match `/' (default)"), GRID+1 },
+ N_("wildcards match `/' (default for exclusion)"), GRID+1 },
#undef GRID
-
+
#define GRID 100
{NULL, 0, NULL, 0,
N_("Informative output:"), GRID },
{"verbose", 'v', 0, 0,
N_("verbosely list files processed"), GRID+1 },
- {"checkpoint", CHECKPOINT_OPTION, 0, 0,
- N_("display progress messages every 10th record"), GRID+1 },
- {"check-links", CHECK_LINKS_OPTION, 0, 0,
+ {"checkpoint", CHECKPOINT_OPTION, N_("[.]NUMBER"), OPTION_ARG_OPTIONAL,
+ N_("display progress messages every NUMBERth record (default 10)"),
+ GRID+1 },
+ {"check-links", 'l', 0, 0,
N_("print a message if not all links are dumped"), GRID+1 },
{"totals", TOTALS_OPTION, 0, 0,
N_("print total bytes written while creating archive"), GRID+1 },
N_("show tar defaults"), GRID+1 },
{"show-omitted-dirs", SHOW_OMITTED_DIRS_OPTION, 0, 0,
N_("when listing or extracting, list each directory that does not match search criteria"), GRID+1 },
- {"show-stored-names", SHOW_STORED_NAMES_OPTION, 0, 0,
- N_("when creating archive in verbose mode, list member names as stored in the archive"),
+ {"show-transformed-names", SHOW_TRANSFORMED_NAMES_OPTION, 0, 0,
+ N_("show file or archive names after transformation"),
GRID+1 },
+ {"show-stored-names", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
{"quoting-style", QUOTING_STYLE_OPTION, N_("STYLE"), 0,
N_("set name quoting style; see below for valid STYLE values"), GRID+1 },
{"quote-chars", QUOTE_CHARS_OPTION, N_("STRING"), 0,
{
"replace", "system", NULL
};
+
static enum atime_preserve const atime_preserve_types[] =
{
replace_atime_preserve, system_atime_preserve
};
+
+/* Make sure atime_preserve_types has as much entries as atime_preserve_args
+ (minus 1 for NULL guard) */
ARGMATCH_VERIFY (atime_preserve_args, atime_preserve_types);
+/* Wildcard matching settings */
+enum wildcards
+ {
+ default_wildcards, /* For exclusion == enable_wildcards,
+ for inclusion == disable_wildcards */
+ disable_wildcards,
+ enable_wildcards
+ };
-struct tar_args {
- char const *textual_date_option;
- int exclude_options;
- bool o_option;
- int pax_option;
- char const *backup_suffix_string;
- char const *version_control_string;
- int input_files;
+struct tar_args /* Variables used during option parsing */
+{
+ char const *textual_date_option; /* Keeps the argument to --newer-mtime
+ option if it represents a textual date */
+ enum wildcards wildcards; /* Wildcard settings (--wildcards/
+ --no-wildcards) */
+ int matching_flags; /* exclude_fnmatch options */
+ int include_anchored; /* Pattern anchoring options used for
+ file inclusion */
+ bool o_option; /* True if -o option was given */
+ bool pax_option; /* True if --pax-option was given */
+ char const *backup_suffix_string; /* --suffix option argument */
+ char const *version_control_string; /* --backup option argument */
+ bool input_files; /* True if some input files where given */
};
-static void
-show_default_settings (FILE *stream)
-{
- fprintf (stream,
- "--format=%s -f%s -b%d --quoting-style=%s --rmt-command=%s",
- archive_format_string (DEFAULT_ARCHIVE_FORMAT),
- DEFAULT_ARCHIVE, DEFAULT_BLOCKING,
- quoting_style_args[DEFAULT_QUOTING_STYLE],
- DEFAULT_RMT_COMMAND);
-#ifdef REMOTE_SHELL
- fprintf (stream, " --rsh-command=%s", REMOTE_SHELL);
-#endif
- fprintf (stream, "\n");
+#define MAKE_EXCL_OPTIONS(args) \
+ ((((args)->wildcards != disable_wildcards) ? EXCLUDE_WILDCARDS : 0) \
+ | (args)->matching_flags \
+ | recursion_option)
+
+#define MAKE_INCL_OPTIONS(args) \
+ ((((args)->wildcards == enable_wildcards) ? EXCLUDE_WILDCARDS : 0) \
+ | (args)->include_anchored \
+ | (args)->matching_flags \
+ | recursion_option)
+
+#ifdef REMOTE_SHELL
+# define DECL_SHOW_DEFAULT_SETTINGS(stream, printer) \
+{ \
+ printer (stream, \
+ "--format=%s -f%s -b%d --quoting-style=%s --rmt-command=%s", \
+ archive_format_string (DEFAULT_ARCHIVE_FORMAT), \
+ DEFAULT_ARCHIVE, DEFAULT_BLOCKING, \
+ quoting_style_args[DEFAULT_QUOTING_STYLE], \
+ DEFAULT_RMT_COMMAND); \
+ printer (stream, " --rsh-command=%s", REMOTE_SHELL); \
+ printer (stream, "\n"); \
+}
+#else
+# define DECL_SHOW_DEFAULT_SETTINGS(stream, printer) \
+{ \
+ printer (stream, \
+ "--format=%s -f%s -b%d --quoting-style=%s --rmt-command=%s", \
+ archive_format_string (DEFAULT_ARCHIVE_FORMAT), \
+ DEFAULT_ARCHIVE, DEFAULT_BLOCKING, \
+ quoting_style_args[DEFAULT_QUOTING_STYLE], \
+ DEFAULT_RMT_COMMAND); \
+ printer (stream, "\n"); \
}
+#endif
+
+static void
+show_default_settings (FILE *fp)
+ DECL_SHOW_DEFAULT_SETTINGS(fp, fprintf)
+
+static void
+show_default_settings_fs (argp_fmtstream_t fs)
+ DECL_SHOW_DEFAULT_SETTINGS(fs, argp_fmtstream_printf)
static void
set_subcommand_option (enum subcommand subcommand)
}
}
+\f
+static void
+tar_help (struct argp_state *state)
+{
+ argp_fmtstream_t fs;
+ state->flags |= ARGP_NO_EXIT;
+ argp_state_help (state, state->out_stream,
+ ARGP_HELP_STD_HELP & ~ARGP_HELP_BUG_ADDR);
+ /* FIXME: use struct uparams.rmargin (from argp-help.c) instead of 79 */
+ fs = argp_make_fmtstream (state->out_stream, 0, 79, 0);
+
+ argp_fmtstream_printf (fs, "\n%s\n\n",
+ _("Valid arguments for --quoting-style options are:"));
+ tar_list_quoting_styles (fs, " ");
+
+ argp_fmtstream_puts (fs, _("\n*This* tar defaults to:\n"));
+ show_default_settings_fs (fs);
+ argp_fmtstream_putc (fs, '\n');
+ argp_fmtstream_printf (fs, _("Report bugs to %s.\n"),
+ argp_program_bug_address);
+ argp_fmtstream_free (fs);
+}
\f
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
case ARGP_KEY_ARG:
/* File name or non-parsed option, because of ARGP_IN_ORDER */
- name_add (arg);
- args->input_files++;
+ name_add_name (arg, MAKE_INCL_OPTIONS (args));
+ args->input_files = true;
break;
case 'A':
break;
case 'C':
- name_add ("-C");
- name_add (arg);
+ name_add_dir (arg);
break;
case 'd':
case 'f':
if (archive_names == allocated_archive_names)
- {
- allocated_archive_names *= 2;
- archive_name_array =
- xrealloc (archive_name_array,
- sizeof (const char *) * allocated_archive_names);
- }
+ archive_name_array = x2nrealloc (archive_name_array,
+ &allocated_archive_names,
+ sizeof (archive_name_array[0]));
+
archive_name_array[archive_names++] = arg;
break;
addname (arg, 0);
break;
- case 'l':
- /* Historically equivalent to --one-file-system. This usage is
- incompatible with UNIX98 and POSIX specs and therefore is
- deprecated. The semantics of -l option will be changed in
- future versions. See TODO.
- */
- WARN ((0, 0,
- _("Semantics of -l option will change in the future releases.")));
- WARN ((0, 0,
- _("Please use --one-file-system option instead.")));
- /* FALL THROUGH */
case ONE_FILE_SYSTEM_OPTION:
/* When dumping directories, don't dump files/subdirectories
that are on other filesystems. */
one_file_system_option = true;
break;
+ case 'l':
+ check_links_option = 1;
+ break;
+
case 'L':
{
uintmax_t u;
case 'X':
if (add_exclude_file (add_exclude, excluded, arg,
- args->exclude_options | recursion_option, '\n')
+ MAKE_EXCL_OPTIONS (args), '\n')
!= 0)
{
int e = errno;
break;
case ANCHORED_OPTION:
- args->exclude_options |= EXCLUDE_ANCHORED;
+ args->matching_flags |= EXCLUDE_ANCHORED;
break;
case ATIME_PRESERVE_OPTION:
break;
case CHECKPOINT_OPTION:
- checkpoint_option = true;
+ if (arg)
+ {
+ char *p;
+
+ if (*arg == '.')
+ {
+ checkpoint_style = checkpoint_dot;
+ arg++;
+ }
+ checkpoint_option = strtoul (arg, &p, 0);
+ if (*p)
+ FATAL_ERROR ((0, 0,
+ _("--checkpoint value is not an integer")));
+ }
+ else
+ checkpoint_option = 10;
break;
case BACKUP_OPTION:
break;
case EXCLUDE_OPTION:
- add_exclude (excluded, arg, args->exclude_options | recursion_option);
+ add_exclude (excluded, arg, MAKE_EXCL_OPTIONS (args));
break;
case EXCLUDE_CACHES_OPTION:
break;
case IGNORE_CASE_OPTION:
- args->exclude_options |= FNM_CASEFOLD;
+ args->matching_flags |= FNM_CASEFOLD;
break;
case IGNORE_COMMAND_ERROR_OPTION:
break;
case NO_ANCHORED_OPTION:
- args->exclude_options &= ~ EXCLUDE_ANCHORED;
+ args->include_anchored = 0; /* Clear the default for comman line args */
+ args->matching_flags &= ~ EXCLUDE_ANCHORED;
break;
case NO_IGNORE_CASE_OPTION:
- args->exclude_options &= ~ FNM_CASEFOLD;
+ args->matching_flags &= ~ FNM_CASEFOLD;
break;
case NO_IGNORE_COMMAND_ERROR_OPTION:
break;
case NO_WILDCARDS_OPTION:
- args->exclude_options &= ~ EXCLUDE_WILDCARDS;
+ args->wildcards = disable_wildcards;
break;
case NO_WILDCARDS_MATCH_SLASH_OPTION:
- args->exclude_options |= FNM_FILE_NAME;
+ args->matching_flags |= FNM_FILE_NAME;
break;
case NULL_OPTION:
break;
case PAX_OPTION:
- args->pax_option++;
+ args->pax_option = true;
xheader_set_option (arg);
break;
break;
case PRESERVE_OPTION:
+ /* FIXME: What it is good for? */
same_permissions_option = true;
same_order_option = true;
break;
show_omitted_dirs_option = true;
break;
- case SHOW_STORED_NAMES_OPTION:
- show_stored_names_option = true;
+ case SHOW_TRANSFORMED_NAMES_OPTION:
+ show_transformed_names_option = true;
break;
case SUFFIX_OPTION:
totals_option = true;
break;
+ case TRANSFORM_OPTION:
+ set_transform_expr (arg);
+ break;
+
case USE_COMPRESS_PROGRAM_OPTION:
set_use_compress_program_option (arg);
break;
break;
case WILDCARDS_OPTION:
- args->exclude_options |= EXCLUDE_WILDCARDS;
+ args->wildcards = enable_wildcards;
break;
case WILDCARDS_MATCH_SLASH_OPTION:
- args->exclude_options &= ~ FNM_FILE_NAME;
- break;
-
- case CHECK_LINKS_OPTION:
- check_links_option = 1;
+ args->matching_flags &= ~ FNM_FILE_NAME;
break;
case NO_RECURSION_OPTION:
#endif /* not DENSITY_LETTER */
if (archive_names == allocated_archive_names)
- {
- allocated_archive_names *= 2;
- archive_name_array =
- xrealloc (archive_name_array,
- sizeof (const char *) * allocated_archive_names);
- }
+ archive_name_array = x2nrealloc (archive_name_array,
+ &allocated_archive_names,
+ sizeof (archive_name_array[0]));
archive_name_array[archive_names++] = xstrdup (buf);
}
break;
#endif /* not DEVICE_PREFIX */
case '?':
- state->flags |= ARGP_NO_EXIT;
- argp_state_help (state, state->out_stream,
- ARGP_HELP_STD_HELP & ~ARGP_HELP_BUG_ADDR);
- fprintf (state->out_stream, "\n%s\n\n",
- _("Valid arguments for --quoting-style options are:"));
- tar_list_quoting_styles (state->out_stream, " ");
-
- fprintf (state->out_stream, _("\n*This* tar defaults to:\n"));
- show_default_settings (state->out_stream);
- fprintf (state->out_stream, "\n");
- fprintf (state->out_stream, _("Report bugs to %s.\n"),
- argp_program_bug_address);
+ tar_help (state);
close_stdout ();
exit (0);
/* Set some default option values. */
args.textual_date_option = NULL;
- args.exclude_options = EXCLUDE_WILDCARDS;
- args.o_option = 0;
- args.pax_option = 0;
+ args.wildcards = default_wildcards;
+ args.matching_flags = 0;
+ args.include_anchored = EXCLUDE_ANCHORED;
+ args.o_option = false;
+ args.pax_option = false;
args.backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
args.version_control_string = 0;
- args.input_files = 0;
+ args.input_files = false;
subcommand_option = UNKNOWN_SUBCOMMAND;
archive_format = DEFAULT_FORMAT;
/* Handle operands after any "--" argument. */
for (; index < argc; index++)
{
- name_add (argv[index]);
- args.input_files++;
+ name_add_name (argv[index], MAKE_INCL_OPTIONS (&args));
+ args.input_files = true;
}
+ /* Warn about implicit use of the wildcards in command line arguments.
+ See TODO */
+ warn_regex_usage = args.wildcards == default_wildcards;
+
/* Derive option values and check option consistency. */
if (archive_format == DEFAULT_FORMAT)
{
/* --test-label is silent if the user has specified the label name to
compare against. */
- if (args.input_files == 0)
+ if (!args.input_files)
verbose_option++;
}
else if (utc_option)
switch (subcommand_option)
{
case CREATE_SUBCOMMAND:
- if (args.input_files == 0 && !files_from_option)
+ if (!args.input_files && !files_from_option)
USAGE_ERROR ((0, 0,
_("Cowardly refusing to create an empty archive")));
break;
signal (SIGCHLD, SIG_DFL);
#endif
- init_names ();
-
/* Decode options. */
decode_options (argc, argv);