X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/58697c6d89f2db69aa2321fe92fc388f87bf2a3c..76bf5102423b4d1597b214f77764075f55b5eb7b:/src/getargs.c

diff --git a/src/getargs.c b/src/getargs.c
index 34cb5874..d7e43850 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -1,7 +1,7 @@
 /* Parse command line arguments for Bison.
 
    Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -47,17 +47,13 @@
 #include "muscle_tab.h"
 #include "uniqstr.h"
 
-bool debug_flag;
 bool defines_flag;
 bool graph_flag;
 bool xml_flag;
-bool locations_flag;
 bool no_lines_flag;
 bool token_table_flag;
 bool yacc_flag;	/* for -y */
 
-bool error_verbose = false;
-
 bool nondeterministic_parser = false;
 bool glr_parser = false;
 
@@ -72,9 +68,9 @@ static struct bison_language const valid_languages[] = {
   { "", "", "", "", false }
 };
 
-static int skeleton_prio = 2;
+int skeleton_prio = default_prio;
 const char *skeleton = NULL;
-static int language_prio = 2;
+int language_prio = default_prio;
 struct bison_language const *language = &valid_languages[0];
 const char *include = NULL;
 
@@ -87,10 +83,12 @@ char *program_name;
  *  \param keys     array of valid subarguments.
  *  \param values   array of corresponding (int) values.
  *  \param flags    the flags to update
- *  \param args     colon separated list of effective subarguments to decode.
+ *  \param args     comma separated list of effective subarguments to decode.
  *                  If 0, then activate all the flags.
  *
- *  The special value 0 resets the flags to 0.
+ *  If VALUE != 0 then KEY sets flags and no-KEY clears them.
+ *  If VALUE == 0 then KEY clears all flags and no-KEY sets all flags.
+ *  Thus no-none = all and no-all = none.
  */
 static void
 flags_argmatch (const char *option,
@@ -102,11 +100,18 @@ flags_argmatch (const char *option,
       args = strtok (args, ",");
       while (args)
 	{
-	  int value = XARGMATCH (option, args, keys, values);
+	  int no = strncmp (args, "no-", 3) == 0 ? 3 : 0;
+	  int value = XARGMATCH (option, args + no, keys, values);
 	  if (value == 0)
-	    *flags = 0;
+	    if (no)
+	      *flags = ~0;
+	    else
+	      *flags = 0;
 	  else
-	    *flags |= value;
+	    if (no)
+	      *flags &= ~value;
+	    else
+	      *flags |= value;
 	  args = strtok (NULL, ",");
 	}
     }
@@ -176,6 +181,7 @@ static const char * const trace_args[] =
   "grammar    - reading, reducing the grammar",
   "resource   - memory consumption (where available)",
   "sets       - grammar sets: firsts, nullable etc.",
+  "muscles    - m4 definitions passed to the skeleton",
   "tools      - m4 invocation",
   "m4         - m4 traces",
   "skeleton   - skeleton postprocessing",
@@ -194,6 +200,7 @@ static const int trace_types[] =
   trace_grammar,
   trace_resource,
   trace_sets,
+  trace_muscles,
   trace_tools,
   trace_m4,
   trace_skeleton,
@@ -246,6 +253,11 @@ usage (int status)
 	     program_name);
   else
     {
+      /* For ../build-aux/cross-options.pl to work, use the format:
+		^  -S, --long[=ARGS] (whitespace)
+	 A --long option is required.
+	 Otherwise, add exceptions to ../build-aux/cross-options.pl.  */
+
       printf (_("Usage: %s [OPTION]... FILE\n"), program_name);
       fputs (_("\
 Generate LALR(1) and GLR parsers.\n\
@@ -361,7 +373,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
 `--------------------------------------*/
 
 void
-skeleton_arg (char const *arg, int prio, location const *loc)
+skeleton_arg (char const *arg, int prio, location loc)
 {
   if (prio < skeleton_prio)
     {
@@ -372,15 +384,12 @@ skeleton_arg (char const *arg, int prio, location const *loc)
     {
       char const *msg =
 	_("multiple skeleton declarations are invalid");
-      if (loc)
-	complain_at (*loc, msg);
-      else
-	complain (msg);
+      complain_at (loc, msg);
     }
 }
 
 void
-language_argmatch (char const *arg, int prio, location const *loc)
+language_argmatch (char const *arg, int prio, location loc)
 {
   char const *msg;
 
@@ -401,10 +410,7 @@ language_argmatch (char const *arg, int prio, location const *loc)
   else
     return;
 
-  if (loc)
-    complain_at (*loc, msg, arg);
-  else
-    complain (msg, arg);
+  complain_at (loc, msg, arg);
 }
 
 /*----------------------.
@@ -503,7 +509,7 @@ static struct option const long_options[] =
 /* Build a location for the current command line argument. */
 static
 location
-command_line_location()
+command_line_location (void)
 {
   location res;
   /* "<command line>" is used in GCC's messages about -D. */
@@ -535,9 +541,8 @@ getargs (int argc, char *argv[])
           char* value = strchr (optarg, '=');
           if (value)
             *value++ = 0;
-          else
-            value = "";
-          muscle_percent_define_insert (name, command_line_location (), value);
+          muscle_percent_define_insert (name, command_line_location (),
+                                        value ? value : "");
         }
 	break;
 
@@ -546,11 +551,13 @@ getargs (int argc, char *argv[])
 	break;
 
       case 'L':
-	language_argmatch (optarg, 0, NULL);
+	language_argmatch (optarg, command_line_prio,
+			   command_line_location ());
 	break;
 
       case 'S':
-	skeleton_arg (AS_FILE_NAME (optarg), 0, NULL);
+	skeleton_arg (AS_FILE_NAME (optarg), command_line_prio,
+		      command_line_location ());
 	break;
 
       case 'T':
@@ -609,7 +616,7 @@ getargs (int argc, char *argv[])
 	break;
 
       case 't':
-	debug_flag = true;
+        muscle_percent_define_insert ("debug", command_line_location (), "");
 	break;
 
       case 'v':
@@ -627,7 +634,8 @@ getargs (int argc, char *argv[])
 	break;
 
       case LOCATIONS_OPTION:
-	locations_flag = true;
+        muscle_percent_define_ensure ("locations",
+                                      command_line_location (), true);
 	break;
 
       case PRINT_LOCALEDIR_OPTION: