(struct option_map): Sort in alphabetical order.

(translate_options): Ignore option once an error occurs.
Fix error with reversed 'a' and 'o'.
Give error if specified abbreviation is unambiguous.

From-SVN: r8165
This commit is contained in:
Richard Kenner 1994-09-29 18:24:38 -04:00
parent 7ee055f4ae
commit 92bd6bdc13

160
gcc/gcc.c
View File

@ -746,7 +746,7 @@ struct option_map
a => argument required. a => argument required.
o => argument optional. o => argument optional.
j => join argument to equivalent, making one word. j => join argument to equivalent, making one word.
* => allow other text after NAME as an argument. */ * => require other text after NAME as an argument. */
char *arg_info; char *arg_info;
}; };
@ -755,76 +755,74 @@ struct option_map
struct option_map option_map[] = struct option_map option_map[] =
{ {
{"--profile-blocks", "-a", 0}, {"--all-warnings", "-Wall", 0},
{"--target", "-b", "a"}, {"--ansi", "-ansi", 0},
{"--assemble", "-S", 0},
{"--assert", "-A", "a"},
{"--comments", "-C", 0},
{"--compile", "-c", 0}, {"--compile", "-c", 0},
{"--dump", "-d", "a"},
{"--entry", "-e", 0},
{"--debug", "-g", "oj"}, {"--debug", "-g", "oj"},
{"--include", "-include", "a"}, {"--define-macro", "-D", "a"},
{"--dependencies", "-M", 0},
{"--dump", "-d", "a"},
{"--dumpbase", "-dumpbase", "a"},
{"--entry", "-e", 0},
{"--extra-warnings", "-W", 0},
{"--for-assembler", "-Wa", "a"},
{"--for-linker", "-Xlinker", "a"},
{"--force-link", "-u", "a"},
{"--imacros", "-imacros", "a"}, {"--imacros", "-imacros", "a"},
{"--include-prefix", "-iprefix", "a"}, {"--include", "-include", "a"},
{"--include-barrier", "-I-", 0},
{"--include-directory", "-I", "a"},
{"--include-directory-after", "-idirafter", "a"}, {"--include-directory-after", "-idirafter", "a"},
{"--include-prefix", "-iprefix", "a"},
{"--include-with-prefix", "-iwithprefix", "a"}, {"--include-with-prefix", "-iwithprefix", "a"},
{"--include-with-prefix-before", "-iwithprefixbefore", "a"}, {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
{"--include-with-prefix-after", "-iwithprefix", "a"}, {"--include-with-prefix-after", "-iwithprefix", "a"},
{"--machine-", "-m", "*j"}, {"--language", "-x", "a"},
{"--library-directory", "-L", "a"},
{"--machine", "-m", "aj"}, {"--machine", "-m", "aj"},
{"--machine-", "-m", "*j"},
{"--no-line-commands", "-P", 0},
{"--no-precompiled-includes", "-noprecomp", 0},
{"--no-standard-includes", "-nostdinc", 0}, {"--no-standard-includes", "-nostdinc", 0},
{"--no-standard-libraries", "-nostdlib", 0}, {"--no-standard-libraries", "-nostdlib", 0},
{"--no-precompiled-includes", "-noprecomp", 0},
{"--output", "-o", "a"},
{"--profile", "-p", 0},
{"--quiet", "-q", 0},
{"--silent", "-q", 0},
{"--force-link", "-u", "a"},
{"--verbose", "-v", 0},
{"--version", "-dumpversion", 0},
{"--no-warnings", "-w", 0}, {"--no-warnings", "-w", 0},
{"--language", "-x", "a"},
{"--assert", "-A", "a"},
{"--prefix", "-B", "a"},
{"--comments", "-C", 0},
{"--define-macro", "-D", "a"},
{"--preprocess", "-E", 0},
{"--trace-includes", "-H", 0},
{"--include-directory", "-I", "a"},
{"--include-barrier", "-I-", 0},
{"--library-directory", "-L", "a"},
{"--dependencies", "-M", 0},
{"--user-dependencies", "-MM", 0},
{"--write-dependencies", "-MD", 0},
{"--write-user-dependencies", "-MMD", 0},
{"--print-missing-file-dependencies", "-MG", 0},
{"--optimize", "-O", "oj"}, {"--optimize", "-O", "oj"},
{"--no-line-commands", "-P", 0}, {"--output", "-o", "a"},
{"--assemble", "-S", 0}, {"--pedantic", "-pedantic", 0},
{"--undefine-macro", "-U", "a"}, {"--pedantic-errors", "-pedantic-errors", 0},
{"--use-version", "-V", "a"}, {"--pipe", "-pipe", 0},
{"--for-assembler", "-Wa", "a"}, {"--prefix", "-B", "a"},
{"--extra-warnings", "-W", 0}, {"--preprocess", "-E", 0},
{"--all-warnings", "-Wall", 0}, {"--print-file-name", "-print-file-name=", "aj"},
{"--warn-", "-W", "*j"}, {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
{"--for-linker", "-Xlinker", "a"}, {"--print-missing-file-dependencies", "-MG", 0},
{"--print-multi-lib", "-print-multi-lib", 0},
{"--ansi", "-ansi", 0}, {"--print-multi-directory", "-print-multi-directory", 0},
{"--print-prog-name", "-print-prog-name=", "aj"},
{"--profile", "-p", 0},
{"--profile-blocks", "-a", 0},
{"--quiet", "-q", 0},
{"--save-temps", "-save-temps", 0},
{"--shared", "-shared", 0},
{"--silent", "-q", 0},
{"--static", "-static", 0},
{"--symbolic", "-symbolic", 0},
{"--target", "-b", "a"},
{"--trace-includes", "-H", 0},
{"--traditional", "-traditional", 0}, {"--traditional", "-traditional", 0},
{"--traditional-cpp", "-traditional-cpp", 0}, {"--traditional-cpp", "-traditional-cpp", 0},
{"--trigraphs", "-trigraphs", 0}, {"--trigraphs", "-trigraphs", 0},
{"--pipe", "-pipe", 0}, {"--undefine-macro", "-U", "a"},
{"--dumpbase", "-dumpbase", "a"}, {"--use-version", "-V", "a"},
{"--pedantic", "-pedantic", 0}, {"--user-dependencies", "-MM", 0},
{"--pedantic-errors", "-pedantic-errors", 0}, {"--verbose", "-v", 0},
{"--save-temps", "-save-temps", 0}, {"--version", "-dumpversion", 0},
{"--print-libgcc-file-name", "-print-libgcc-file-name", 0}, {"--warn-", "-W", "*j"},
{"--print-file-name", "-print-file-name=", "aj"}, {"--write-dependencies", "-MD", 0},
{"--print-prog-name", "-print-prog-name=", "aj"}, {"--write-user-dependencies", "-MMD", 0},
{"--print-multi-lib", "-print-multi-lib", 0},
{"--print-multi-directory", "-print-multi-directory", 0},
{"--static", "-static", 0},
{"--shared", "-shared", 0},
{"--symbolic", "-symbolic", 0},
{"--", "-f", "*j"} {"--", "-f", "*j"}
}; };
@ -837,7 +835,7 @@ translate_options (argcp, argvp)
int *argcp; int *argcp;
char ***argvp; char ***argvp;
{ {
int i, j; int i, j, k;
int argc = *argcp; int argc = *argcp;
char **argv = *argvp; char **argv = *argvp;
char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *)); char **newv = (char **) xmalloc ((argc + 2) * 2 * sizeof (char *));
@ -855,49 +853,74 @@ translate_options (argcp, argvp)
for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++) for (j = 0; j < sizeof (option_map) / sizeof (option_map[0]); j++)
{ {
int optlen = strlen (option_map[j].name); int optlen = strlen (option_map[j].name);
int complen = strlen (argv[i]); int arglen = strlen (argv[i]);
int complen = arglen > optlen ? optlen : arglen;
char *arginfo = option_map[j].arg_info; char *arginfo = option_map[j].arg_info;
if (arginfo == 0) if (arginfo == 0)
arginfo = ""; arginfo = "";
if (complen > optlen)
complen = optlen;
if (!strncmp (argv[i], option_map[j].name, complen)) if (!strncmp (argv[i], option_map[j].name, complen))
{ {
int extra = strlen (argv[i]) > optlen;
char *arg = 0; char *arg = 0;
if (extra) if (arglen < optlen)
{
for (k = j + 1;
k < sizeof (option_map) / sizeof (option_map[0]);
k++)
if (strlen (option_map[k].name) >= arglen
&& !strncmp (argv[i], option_map[k].name, arglen))
{
error ("Ambiguous abbreviation %s", argv[i]);
break;
}
if (k != sizeof (option_map) / sizeof (option_map[0]))
break;
}
if (arglen > optlen)
{ {
/* If the option has an argument, accept that. */ /* If the option has an argument, accept that. */
if (argv[i][optlen] == '=') if (argv[i][optlen] == '=')
arg = argv[i] + optlen + 1; arg = argv[i] + optlen + 1;
/* If this mapping allows extra text at end of name,
/* If this mapping requires extra text at end of name,
accept that as "argument". */ accept that as "argument". */
else if (index (arginfo, '*') != 0) else if (index (arginfo, '*') != 0)
arg = argv[i] + optlen; arg = argv[i] + optlen;
/* Otherwise, extra text at end means mismatch. /* Otherwise, extra text at end means mismatch.
Try other mappings. */ Try other mappings. */
else else
continue; continue;
} }
else if (index (arginfo, '*') != 0) else if (index (arginfo, '*') != 0)
error ("Incomplete `%s' option", option_map[j].name); {
error ("Incomplete `%s' option", option_map[j].name);
break;
}
/* Handle arguments. */ /* Handle arguments. */
if (index (arginfo, 'o') != 0) if (index (arginfo, 'a') != 0)
{ {
if (arg == 0) if (arg == 0)
{ {
if (i + 1 == argc) if (i + 1 == argc)
error ("Missing argument to `%s' option", {
option_map[j].name); error ("Missing argument to `%s' option",
option_map[j].name);
break;
}
arg = argv[++i]; arg = argv[++i];
} }
} }
else if (index (arginfo, '*') != 0) else if (index (arginfo, '*') != 0)
; ;
else if (index (arginfo, 'a') == 0) else if (index (arginfo, 'o') == 0)
{ {
if (arg != 0) if (arg != 0)
error ("Extraneous argument to `%s' option", error ("Extraneous argument to `%s' option",
@ -922,6 +945,7 @@ translate_options (argcp, argvp)
} }
i++; i++;
} }
/* Handle old-fashioned options--just copy them through, /* Handle old-fashioned options--just copy them through,
with their arguments. */ with their arguments. */
else if (argv[i][0] == '-') else if (argv[i][0] == '-')