My son just woke up, I'll use this later. Unless someone beats
me :) (I can't check it works properly yet, I have to install
Autoconf 2.60 first. But it seems ok.)
Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
Implement --warnings/-W.
* src/getargs.c (report_argmatch, trace_argmatch): Remove,
replaced by...
(flags_argmatch, FLAGS_ARGMATCH): this new function and macro.
Adjust callers.
* src/getargs.h, src/getargs.c (warnings, warnings_flags)
(warnings_args, warnings_types): New.
(getargs, short_options, long_options): Accept -W/--warnings.
Sort the options by alphabetical order, upper case letter right
before its lower case.
Index: src/getargs.c
===================================================================
RCS file: /cvsroot/bison/bison/src/getargs.c,v
retrieving revision 1.75
diff -u -r1.75 getargs.c
--- src/getargs.c 9 Jul 2006 15:38:42 -0000 1.75
+++ src/getargs.c 9 Jul 2006 16:54:59 -0000
@@ -62,6 +62,7 @@
int report_flag = report_none;
int trace_flag = trace_none;
+int warnings_flag = warnings_none;
const char *skeleton = NULL;
const char *include = NULL;
@@ -69,6 +70,53 @@
extern char *program_name;
+/** Decode an option's set of keys.
+ *
+ * \param option option being decoded.
+ * \paran keys array of valid subarguments.
+ * \param values array of corresponding (int) values.
+ * \param flag the flags to update
+ * \param args colon separated list of effective subarguments to decode.
+ * If 0, then activate all the flags.
+ *
+ * The special value 0 resets the flags to 0.
+ */
+static int
+flags_argmatch (const char *option,
+ const char * const keys[], const int values[],
+ int *flags, char *args)
+{
+ if (args)
+ {
+ args = strtok (args, ",");
+ do
+ {
+ int value = XARGMATCH (option, args, keys, values);
+ if (value == 0)
+ *flags = 0;
+ else
+ *flags |= value;
+ }
+ while ((args = strtok (NULL, ",")));
+ }
+ else
+ *flags = ~0;
+}
+
+/** Decode a set of sub arguments.
+ *
+ * \param FlagName the flag familly to update.
+ * \param args the effective sub arguments to decode.
+ *
+ * \arg FlagName_args the list of keys.
+ * \arg FlagName_types the list of values.
+ * \arg FlagName_flag the flag to update.
+ */
+#define FLAGS_ARGMATCH(FlagName, Args) \
+ flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \
+ &FlagName ## _flag, Args)
+
+
/*----------------------.
| --report's handling. |
`----------------------*/
@@ -100,22 +148,6 @@
ARGMATCH_VERIFY (report_args, report_types);
-static void
-report_argmatch (char *args)
-{
- args = strtok (args, ",");
- do
- {
- int report = XARGMATCH ("--report", args,
- report_args, report_types);
- if (report == report_none)
- report_flag = report_none;
- else
- report_flag |= report;
- }
- while ((args = strtok (NULL, ",")));
-}
-
/*---------------------.
| --trace's handling. |
@@ -160,26 +192,31 @@
ARGMATCH_VERIFY (trace_args, trace_types);
-static void
-trace_argmatch (char *args)
+
+/*------------------------.
+| --warnings's handling. |
+`------------------------*/
+
+static const char * const warnings_args[] =
{
- if (args)
- {
- args = strtok (args, ",");
- do
- {
- int trace = XARGMATCH ("--trace", args,
- trace_args, trace_types);
- if (trace == trace_none)
- trace_flag = trace_none;
- else
- trace_flag |= trace;
- }
- while ((args = strtok (NULL, ",")));
- }
- else
- trace_flag = trace_all;
-}
+ /* In a series of synonyms, present the most meaningful first, so
+ that argmatch_valid be more readable. */
+ "none - no warnings",
+ "error - warnings are errors",
+ "yacc - incompatibilities with POSIX YACC",
+ "all - all of the above",
+ 0
+};
+
+static const int warnings_types[] =
+{
+ warnings_none,
+ warnings_error,
+ warnings_yacc,
+ warnings_all
+};
+
+ARGMATCH_VERIFY (warnings_args, warnings_types);
/*-------------------------------------------.
@@ -255,7 +292,7 @@
putc ('\n', stdout);
fputs (_("\
-Report bugs to <[email protected]>.\n"), stdout);
+Report bugs to <" PACKAGE_BUGREPORT ">.\n"), stdout);
}
exit (status);
@@ -293,7 +330,7 @@
`----------------------*/
/* Shorts options. */
-static char const short_options[] = "yvegdhr:ltknVo:b:p:S:T::";
+static char const short_options[] = "yvegdhr:ltknVo:b:p:S:T::W";
/* Values for long options that do not have single-letter equivalents. */
enum
@@ -305,9 +342,10 @@
static struct option const long_options[] =
{
/* Operation modes. */
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'V' },
- { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
+ { "help", no_argument, 0, 'h' },
+ { "version", no_argument, 0, 'V' },
+ { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
+ { "warnings", optional_argument, 0, 'W' },
/* Parser. */
{ "name-prefix", required_argument, 0, 'p' },
@@ -364,21 +402,10 @@
/* Certain long options cause getopt_long to return 0. */
break;
- case 'y':
- yacc_flag = true;
+ case 'b':
+ spec_file_prefix = AS_FILE_NAME (optarg);
break;
- case 'h':
- usage (EXIT_SUCCESS);
-
- case 'V':
- version ();
- exit (EXIT_SUCCESS);
-
- case PRINT_LOCALEDIR_OPTION:
- printf ("%s\n", LOCALEDIR);
- exit (EXIT_SUCCESS);
-
case 'g':
/* Here, the -g and --graph=FILE options are differentiated. */
graph_flag = true;
@@ -386,9 +413,8 @@
spec_graph_file = AS_FILE_NAME (optarg);
break;
- case 'v':
- report_flag |= report_states;
- break;
+ case 'h':
+ usage (EXIT_SUCCESS);
case 'S':
skeleton = AS_FILE_NAME (optarg);
@@ -405,46 +431,62 @@
spec_defines_file = AS_FILE_NAME (optarg);
break;
+ case 'k':
+ token_table_flag = true;
+ break;
+
case 'l':
no_lines_flag = true;
break;
- case LOCATIONS_OPTION:
- locations_flag = true;
+ case 'n':
+ no_parser_flag = true;
break;
- case 'k':
- token_table_flag = true;
+ case 'o':
+ spec_outfile = AS_FILE_NAME (optarg);
break;
- case 'n':
- no_parser_flag = true;
+ case 'p':
+ spec_name_prefix = optarg;
+ break;
+
+ case 'r':
+ FLAGS_ARGMATCH (report, optarg);
+ break;
+
+ case 'T':
+ FLAGS_ARGMATCH (trace, optarg);
break;
case 't':
debug_flag = true;
break;
- case 'o':
- spec_outfile = AS_FILE_NAME (optarg);
- break;
+ case 'V':
+ version ();
+ exit (EXIT_SUCCESS);
- case 'b':
- spec_file_prefix = AS_FILE_NAME (optarg);
+ case 'v':
+ report_flag |= report_states;
break;
- case 'p':
- spec_name_prefix = optarg;
+ case 'y':
+ yacc_flag = true;
break;
- case 'r':
- report_argmatch (optarg);
+ case 'W':
+ FLAGS_ARGMATCH (warnings, optarg);
break;
- case 'T':
- trace_argmatch (optarg);
+ case LOCATIONS_OPTION:
+ locations_flag = true;
break;
+ case PRINT_LOCALEDIR_OPTION:
+ printf ("%s\n", LOCALEDIR);
+ exit (EXIT_SUCCESS);
+
default:
usage (EXIT_FAILURE);
}
Index: src/getargs.h
===================================================================
RCS file: /cvsroot/bison/bison/src/getargs.h,v
retrieving revision 1.32
diff -u -r1.32 getargs.h
--- src/getargs.h 9 Jul 2006 15:38:42 -0000 1.32
+++ src/getargs.h 9 Jul 2006 16:54:59 -0000
@@ -59,7 +59,11 @@
extern bool nondeterministic_parser;
-/* --report. */
+
+/*-----------.
+| --report. |
+`-----------*/
+
enum report
{
report_none = 0,
@@ -72,7 +76,9 @@
/** What appears in the *.output file. */
extern int report_flag;
-/* --trace. */
+/*----------.
+| --trace. |
+`----------*/
enum trace
{
trace_none = 0, /**< No traces. */
@@ -92,6 +98,26 @@
/** What debug items bison displays during its run. */
extern int trace_flag;
+/*-------------.
+| --warnings. |
+`-------------*/
+
+enum warnings
+ {
+ warnings_none = 0, /**< Issue no warnings. */
+ warnings_error = 1 << 0, /**< Warnings are treated as errors.
*/
+ warnings_yacc = 1 << 1, /**< POSIXME. */
+ warnings_all = ~0 /**< All of the above. */
+ };
+/** What warnings are issued. */
+extern int warnings_flag;
+
+
+/** Process the command line arguments.
+ *
+ * \param argc size of \a argv
+ * \param argv list of arguments.
+ */
void getargs (int argc, char *argv[]);
#endif /* !GETARGS_H_ */