Improve option sanity checking

Any two conflicting options are reported only if they both occur in
the command line.  Otherwise, options defined in the command line
silently override those set in the TAR_OPTIONS environment variable.

* src/common.h (option_source): New enum.
(option_locus): New struct.
* src/names.c (name_elt): New member: line.
(name_add_file): Initialize line.
(read_name_from_file): Keep track of input line number for diagnostic
purposes.
(handle_option): Take a pointer to struct name_elt as 2nd parameter;
pass locus info to more_options().
* src/tar.c (tar_args): New member: loc.
(option_class): New enum.
(optloc_save,optloc_lookup)
(option_set_in_cl,optloc_eq): New functions.
(set_use_compress_program_option): Take into account option location.
(set_old_files_option): New function.
(parse_opt): Keep track of option locations.
(more_options): Improve error reporting.
(parse_default_options): New function.
(decode_options): Parse TAR_OPTION and command line separately.
Options from the latter silently override those from the former.

* lib/prepargs.c: Remove.
* lib/prepargs.h: Remove.
* lib/Makefile.am: Update.
This commit is contained in:
Sergey Poznyakoff
2015-08-31 08:37:46 +03:00
parent c440a92627
commit ae23a57d70
6 changed files with 280 additions and 141 deletions

View File

@@ -777,7 +777,26 @@ const char *subcommand_string (enum subcommand c);
void set_exit_status (int val);
void request_stdin (const char *option);
void more_options (int argc, char **argv);
/* Where an option comes from: */
enum option_source
{
OPTS_ENVIRON, /* Environment variable TAR_OPTIONS */
OPTS_COMMAND_LINE, /* Command line */
OPTS_FILE /* File supplied by --files-from */
};
/* Option location */
struct option_locus
{
enum option_source source; /* Option origin */
char const *name; /* File or variable name */
size_t line; /* Number of input line if source is OPTS_FILE */
struct option_locus *prev; /* Previous occurrence of the option of same
class */
};
void more_options (int argc, char **argv, struct option_locus *loc);
/* Module update.c. */