* support/cpp/output.h, support/cpp/opts-common.c,
[fw/sdcc] / support / cpp / opts-common.c
index dcbbe2c1e6e2486b06d2aedf966e23bb1031fc69..f442c5604ce3db416f26aa33d0d8efd5c408c458 100644 (file)
@@ -1,11 +1,11 @@
 /* Command line option handling.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -14,9 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -38,7 +37,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
    before having tested "-g".  This doesn't match, and as "-gen-decls"
    is less than "-gstabs", it will become the lower bound of the
    binary search range, and "-g" will never be seen.  To resolve this
-   issue, opts.sh makes "-gen-decls" point, via the back_chain member,
+   issue, 'optc-gen.awk' makes "-gen-decls" point, via the back_chain member,
    to "-g" so that failed searches that end between "-gen-decls" and
    the lexicographically subsequent switch know to go back and see if
    "-g" causes a match (which it does in this example).
@@ -66,9 +65,9 @@ find_opt (const char *input, int lang_mask)
       comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
 
       if (comp < 0)
-       mx = md;
+        mx = md;
       else
-       mn = md;
+        mn = md;
     }
 
   /* This is the switch that is the best match but for a different
@@ -83,22 +82,22 @@ find_opt (const char *input, int lang_mask)
       const struct cl_option *opt = &cl_options[mn];
 
       /* Is the input either an exact match or a prefix that takes a
-        joined argument?  */
+         joined argument?  */
       if (!strncmp (input, opt->opt_text + 1, opt->opt_len)
-         && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
-       {
-         /* If language is OK, return it.  */
-         if (opt->flags & lang_mask)
-           return mn;
-
-         /* If we haven't remembered a prior match, remember this
-            one.  Any prior match is necessarily better.  */
-         if (match_wrong_lang == cl_options_count)
-           match_wrong_lang = mn;
-       }
+          && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
+        {
+          /* If language is OK, return it.  */
+          if (opt->flags & lang_mask)
+            return mn;
+
+          /* If we haven't remembered a prior match, remember this
+             one.  Any prior match is necessarily better.  */
+          if (match_wrong_lang == cl_options_count)
+            match_wrong_lang = mn;
+        }
 
       /* Try the next possibility.  This is cl_options_count if there
-        are no more.  */
+         are no more.  */
       mn = opt->back_chain;
     }
   while (mn != cl_options_count);
@@ -120,8 +119,8 @@ cancel_option (int opt_idx, int next_opt_idx, int orig_next_opt_idx)
 
   if (cl_options [next_opt_idx].neg_index != orig_next_opt_idx)
     return cancel_option (opt_idx, cl_options [next_opt_idx].neg_index,
-                         orig_next_opt_idx);
-    
+                          orig_next_opt_idx);
+
   return false;
 }
 
@@ -131,8 +130,8 @@ void
 prune_options (int *argcp, char ***argvp)
 {
   int argc = *argcp;
-  int *options = xmalloc (argc * sizeof (*options));
-  char **argv = xmalloc (argc * sizeof (char *));
+  int *options = XNEWVEC (int, argc);
+  char **argv = XNEWVEC (char *, argc);
   int i, arg_count, need_prune = 0;
   const struct cl_option *option;
   size_t opt_index;
@@ -145,43 +144,43 @@ prune_options (int *argcp, char ***argvp)
 
       opt_index = find_opt (opt + 1, -1);
       if (opt_index == cl_options_count
-         && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
-         && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
-       {
-         char *dup;
-
-         /* Drop the "no-" from negative switches.  */
-         size_t len = strlen (opt) - 3;
-
-         dup = XNEWVEC (char, len + 1);
-         dup[0] = '-';
-         dup[1] = opt[1];
-         memcpy (dup + 2, opt + 5, len - 2 + 1);
-         opt = dup;
-         value = 0;
-         opt_index = find_opt (opt + 1, -1);
-         free (dup);
-       }
+          && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
+          && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
+        {
+          char *dup;
+
+          /* Drop the "no-" from negative switches.  */
+          size_t len = strlen (opt) - 3;
+
+          dup = XNEWVEC (char, len + 1);
+          dup[0] = '-';
+          dup[1] = opt[1];
+          memcpy (dup + 2, opt + 5, len - 2 + 1);
+          opt = dup;
+          value = 0;
+          opt_index = find_opt (opt + 1, -1);
+          free (dup);
+        }
 
       if (opt_index == cl_options_count)
-       {
+        {
 cont:
-         options [i] = 0;
-         continue;
-       }
+          options [i] = 0;
+          continue;
+        }
 
       option = &cl_options[opt_index];
       if (option->neg_index < 0)
-       goto cont;
+        goto cont;
 
       /* Skip joined switches.  */
       if ((option->flags & CL_JOINED))
-       goto cont;
+        goto cont;
 
       /* Reject negative form of switches that don't take negatives as
-        unrecognized.  */
+         unrecognized.  */
       if (!value && (option->flags & CL_REJECT_NEGATIVE))
-       goto cont;
+        goto cont;
 
       options [i] = (int) opt_index;
       need_prune |= options [i];
@@ -199,26 +198,26 @@ cont:
 
       opt_idx = options [i];
       if (opt_idx)
-       {
-         int next_opt_idx;
-         for (j = i + 1; j < argc; j++)
-           {
-             next_opt_idx = options [j];
-             if (next_opt_idx
-                 && cancel_option (opt_idx, next_opt_idx,
-                                   next_opt_idx))
-               break;
-           }
-       }
+        {
+          int next_opt_idx;
+          for (j = i + 1; j < argc; j++)
+            {
+              next_opt_idx = options [j];
+              if (next_opt_idx
+                  && cancel_option (opt_idx, next_opt_idx,
+                                    next_opt_idx))
+                break;
+            }
+        }
       else
-       goto keep;
+        goto keep;
 
       if (j == argc)
-       {
+        {
 keep:
-         argv [arg_count] = (*argvp) [i];
-         arg_count++;
-       }
+          argv [arg_count] = (*argvp) [i];
+          arg_count++;
+        }
     }
 
   if (arg_count != argc)