OSDN Git Service

(struct option_map): Sort in alphabetical order.
authorkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Sep 1994 22:24:38 +0000 (22:24 +0000)
committerkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 29 Sep 1994 22:24:38 +0000 (22:24 +0000)
(translate_options): Ignore option once an error occurs.
Fix error with reversed 'a' and 'o'.
Give error if specified abbreviation is unambiguous.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@8165 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/gcc.c

index 977b703..99bca41 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -746,7 +746,7 @@ struct option_map
      a => argument required.
      o => argument optional.
      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;
 };
 
@@ -755,76 +755,74 @@ struct option_map
 
 struct option_map option_map[] =
  {
-   {"--profile-blocks", "-a", 0},
-   {"--target", "-b", "a"},
+   {"--all-warnings", "-Wall", 0},
+   {"--ansi", "-ansi", 0},
+   {"--assemble", "-S", 0},
+   {"--assert", "-A", "a"},
+   {"--comments", "-C", 0},
    {"--compile", "-c", 0},
+   {"--debug", "-g", "oj"},
+   {"--define-macro", "-D", "a"},
+   {"--dependencies", "-M", 0},
    {"--dump", "-d", "a"},
+   {"--dumpbase", "-dumpbase", "a"},
    {"--entry", "-e", 0},
-   {"--debug", "-g", "oj"},
-   {"--include", "-include", "a"},
+   {"--extra-warnings", "-W", 0},
+   {"--for-assembler", "-Wa", "a"},
+   {"--for-linker", "-Xlinker", "a"},
+   {"--force-link", "-u", "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-prefix", "-iprefix", "a"},
    {"--include-with-prefix", "-iwithprefix", "a"},
    {"--include-with-prefix-before", "-iwithprefixbefore", "a"},
    {"--include-with-prefix-after", "-iwithprefix", "a"},
-   {"--machine-", "-m", "*j"},
+   {"--language", "-x", "a"},
+   {"--library-directory", "-L", "a"},
    {"--machine", "-m", "aj"},
+   {"--machine-", "-m", "*j"},
+   {"--no-line-commands", "-P", 0},
+   {"--no-precompiled-includes", "-noprecomp", 0},
    {"--no-standard-includes", "-nostdinc", 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},
-   {"--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"},
-   {"--no-line-commands", "-P", 0},
-   {"--assemble", "-S", 0},
-   {"--undefine-macro", "-U", "a"},
-   {"--use-version", "-V", "a"},
-   {"--for-assembler", "-Wa", "a"},
-   {"--extra-warnings", "-W", 0},
-   {"--all-warnings", "-Wall", 0},
-   {"--warn-", "-W", "*j"},
-   {"--for-linker", "-Xlinker", "a"},
-
-   {"--ansi", "-ansi", 0},
-   {"--traditional", "-traditional", 0},
-   {"--traditional-cpp", "-traditional-cpp", 0},
-   {"--trigraphs", "-trigraphs", 0},
-   {"--pipe", "-pipe", 0},
-   {"--dumpbase", "-dumpbase", "a"},
+   {"--output", "-o", "a"},
    {"--pedantic", "-pedantic", 0},
    {"--pedantic-errors", "-pedantic-errors", 0},
-   {"--save-temps", "-save-temps", 0},
-   {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
+   {"--pipe", "-pipe", 0},
+   {"--prefix", "-B", "a"},
+   {"--preprocess", "-E", 0},
    {"--print-file-name", "-print-file-name=", "aj"},
-   {"--print-prog-name", "-print-prog-name=", "aj"},
+   {"--print-libgcc-file-name", "-print-libgcc-file-name", 0},
+   {"--print-missing-file-dependencies", "-MG", 0},
    {"--print-multi-lib", "-print-multi-lib", 0},
    {"--print-multi-directory", "-print-multi-directory", 0},
-   {"--static", "-static", 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-cpp", "-traditional-cpp", 0},
+   {"--trigraphs", "-trigraphs", 0},
+   {"--undefine-macro", "-U", "a"},
+   {"--use-version", "-V", "a"},
+   {"--user-dependencies", "-MM", 0},
+   {"--verbose", "-v", 0},
+   {"--version", "-dumpversion", 0},
+   {"--warn-", "-W", "*j"},
+   {"--write-dependencies", "-MD", 0},
+   {"--write-user-dependencies", "-MMD", 0},
    {"--", "-f", "*j"}
  };
 \f
@@ -837,7 +835,7 @@ translate_options (argcp, argvp)
      int *argcp;
      char ***argvp;
 {
-  int i, j;
+  int i, j, k;
   int argc = *argcp;
   char **argv = *argvp;
   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++)
            {
              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;
 
              if (arginfo == 0)
                arginfo = "";
-             if (complen > optlen)
-               complen = optlen;
+
              if (!strncmp (argv[i], option_map[j].name, complen))
                {
-                 int extra = strlen (argv[i]) > optlen;
                  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 (argv[i][optlen] == '=')
                        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".  */
                      else if (index (arginfo, '*') != 0)
                        arg = argv[i] + optlen;
+
                      /* Otherwise, extra text at end means mismatch.
                         Try other mappings.  */
                      else
                        continue;
                    }
+
                  else if (index (arginfo, '*') != 0)
-                   error ("Incomplete `%s' option", option_map[j].name);
+                   {
+                     error ("Incomplete `%s' option", option_map[j].name);
+                     break;
+                   }
 
                  /* Handle arguments.  */
-                 if (index (arginfo, 'o') != 0)
+                 if (index (arginfo, 'a') != 0)
                    {
                      if (arg == 0)
                        {
                          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];
                        }
                    }
                  else if (index (arginfo, '*') != 0)
                    ;
-                 else if (index (arginfo, 'a') == 0)
+                 else if (index (arginfo, 'o') == 0)
                    {
                      if (arg != 0)
                        error ("Extraneous argument to `%s' option",
@@ -922,6 +945,7 @@ translate_options (argcp, argvp)
            }
          i++;
        }
+
       /* Handle old-fashioned options--just copy them through,
         with their arguments.  */
       else if (argv[i][0] == '-')