[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/8] diagnostics: factor the list of warning names
From: |
Akim Demaille |
Subject: |
[PATCH 3/8] diagnostics: factor the list of warning names |
Date: |
Thu, 14 Feb 2013 15:11:07 +0100 |
* src/getargs.h, src/getargs.c (warnings_args, warnings_types): Make
them public.
* src/complain.h, src/complain.c (warnings_print_categories): Its
only use outside complain.c was removed in a recent commit, so
make it static.
Simplify its implementation.
Use warnings_args and warnings_types.
* src/muscle-tab.c (muscle_percent_define_check_values): Make it
silent.
---
src/complain.c | 44 +++++++++++++++-----------------------------
src/complain.h | 3 ---
src/getargs.c | 4 ++--
src/getargs.h | 8 ++++++++
src/muscle-tab.c | 2 +-
5 files changed, 26 insertions(+), 35 deletions(-)
diff --git a/src/complain.c b/src/complain.c
index f9b2fea..80731b7 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -38,35 +38,20 @@ warnings errors_flag;
err_status complaint_status = status_none;
static unsigned *indent_ptr = 0;
-void
-warnings_print_categories (warnings warn_flags)
+/** Display a "[-Wyacc]" like message on \a f. */
+
+static void
+warnings_print_categories (warnings warn_flags, FILE *f)
{
- if (! (warn_flags & silent))
- {
- char const *warn_names[] =
- {
- "midrule-values",
- "yacc",
- "conflicts-sr",
- "conflicts-rr",
- "deprecated",
- "precedence",
- "other"
- };
-
- bool any = false;
- int i;
- for (i = 0; i < ARRAY_CARDINALITY (warn_names); ++i)
- if (warn_flags & 1 << i)
- {
- bool err = warn_flags & errors_flag;
- fprintf (stderr, "%s-W", any ? ", " : " [");
- fprintf (stderr, "%s%s", err ? "error=" : "" , warn_names[i]);
- any = true;
- }
- if (any)
- fprintf (stderr, "]");
- }
+ /* Display only the first match, the second is "-Wall". */
+ int i;
+ for (i = 0; warnings_args[i]; ++i)
+ if (warn_flags & warnings_types[i])
+ {
+ bool err = warn_flags & errors_flag;
+ fprintf (f, " [-W%s%s]", err ? "error=" : "" , warnings_args[i]);
+ break;
+ }
}
/** Report an error message.
@@ -109,7 +94,8 @@ error_message (const location *loc, warnings flags, const
char *prefix,
fprintf (stderr, "%s: ", prefix);
vfprintf (stderr, message, args);
- warnings_print_categories (flags);
+ if (! (flags & silent))
+ warnings_print_categories (flags, stderr);
{
size_t l = strlen (message);
if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
diff --git a/src/complain.h b/src/complain.h
index 0110c6b..306d2e8 100644
--- a/src/complain.h
+++ b/src/complain.h
@@ -57,9 +57,6 @@ extern warnings warnings_flag;
/** What warnings are made errors. */
extern warnings errors_flag;
-/** Display a "[-Wyacc]" like message on stderr. */
-void warnings_print_categories (warnings warn_flags);
-
/** Make a complaint, with maybe a location. */
void complain (location const *loc, warnings flags, char const *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
diff --git a/src/getargs.c b/src/getargs.c
index fe6c1d4..7a637a2 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -240,7 +240,7 @@ ARGMATCH_VERIFY (trace_args, trace_types);
| --warnings's handling. |
`------------------------*/
-static const char * const warnings_args[] =
+const char * const warnings_args[] =
{
"none",
"midrule-values",
@@ -255,7 +255,7 @@ static const char * const warnings_args[] =
0
};
-static const int warnings_types[] =
+const int warnings_types[] =
{
Wnone,
Wmidrule_values,
diff --git a/src/getargs.h b/src/getargs.h
index c246f28..2fba265 100644
--- a/src/getargs.h
+++ b/src/getargs.h
@@ -121,6 +121,14 @@ enum feature
/** What additional features to use. */
extern int feature_flag;
+/*------------.
+| --warning. |
+`------------*/
+/* Null-terminated list. */
+extern const char * const warnings_args[];
+extern const int warnings_types[];
+
+
/** Process the command line arguments.
*
* \param argc size of \a argv
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 8212895..490dada 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -664,7 +664,7 @@ muscle_percent_define_check_values (char const * const
*values)
quote (*variablep), quote_n (1, value));
i += SUB_INDENT;
for (values = variablep + 1; *values; ++values)
- complain_indent (&loc, complaint | no_caret, &i,
+ complain_indent (&loc, complaint | no_caret | silent, &i,
_("accepted value: %s"), quote (*values));
}
else
--
1.8.1.3
- [PATCH 0/8] {master} revamp the handling of -W, Akim Demaille, 2013/02/14
- [PATCH 5/8] options: simplify the handling of -W, Akim Demaille, 2013/02/14
- [PATCH 8/8] getargs: minor simplification, Akim Demaille, 2013/02/14
- [PATCH 4/8] options: don't accept "error=" for -f and -r, Akim Demaille, 2013/02/14
- [PATCH 2/8] diagnostics: no longer pretty-print rules in error messages, carets suffice, Akim Demaille, 2013/02/14
- [PATCH 6/8] diagnostics: revamp the handling of -Werror, Akim Demaille, 2013/02/14
- [PATCH 7/8] style: more argument handling of -W into the diagnostics module, Akim Demaille, 2013/02/14
- [PATCH 3/8] diagnostics: factor the list of warning names,
Akim Demaille <=
- [PATCH 1/8] options: no longer document warnings when diagnosing an invalid -W, Akim Demaille, 2013/02/14
- Re: [PATCH 0/8] {master} revamp the handling of -W, Akim Demaille, 2013/02/16