diff options
author | Bruno Haible <bruno@clisp.org> | 2000-08-19 13:25:52 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2000-08-19 13:25:52 +0000 |
commit | 574127cfd57b4ecceaf4f1920baa7dac43f551e1 (patch) | |
tree | 45877d302aa94cce5c85d8011fb09203c5107f7b | |
parent | 2efcd453efed0c71793c171b568fa822a7232b75 (diff) | |
download | gperf-574127cfd57b4ecceaf4f1920baa7dac43f551e1.tar.gz |
Output command-line options with argument delimiters if necessary.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/options.cc | 45 |
2 files changed, 47 insertions, 1 deletions
@@ -1,5 +1,8 @@ 2000-08-19 Bruno Haible <bruno@linuix.math.u-bordeaux.fr> + * src/options.cc (Options::print_options): Escape the arguments which + contain special characters. + * tests/c-parse.gperf: Updated from gcc-2.95.2/gcc/c-parse.gperf. * tests/objc.gperf: New file, from gcc-2.95.2/gcc/objc/objc.gperf. * tests/chill.gperf: New file, from gcc-2.95.2/gcc/ch/gperf. diff --git a/src/options.cc b/src/options.cc index 85fe275..0d0da1b 100644 --- a/src/options.cc +++ b/src/options.cc @@ -229,7 +229,50 @@ Options::print_options (void) printf ("/* Command-line: "); for (i = 0; i < argument_count; i++) - printf ("%s ", argument_vector[i]); + { + const char *arg = argument_vector[i]; + + /* Escape arg if it contains shell metacharacters. */ + if (*arg == '-') + { + putchar (*arg); + arg++; + if (*arg >= 'A' && *arg <= 'Z' || *arg >= 'a' && *arg <= 'z') + { + putchar (*arg); + arg++; + } + } + if (strpbrk (arg, "\t\n !\"#$&'()*;<>?[\\]`{|}~") != NULL) + { + if (strchr (arg, '\'') != NULL) + { + putchar ('"'); + for (; *arg; arg++) + { + if (*arg == '\"' || *arg == '\\' || *arg == '$') + putchar ('\\'); + putchar (*arg); + } + putchar ('"'); + } + else + { + putchar ('\''); + for (; *arg; arg++) + { + if (*arg == '\\') + putchar ('\\'); + putchar (*arg); + } + putchar ('\''); + } + } + else + printf ("%s", arg); + + printf (" "); + } printf (" */"); } |