A lot of content in lib.c have been added by just appending at the
bottom of what was already present. As consequence, things are now
not well organized at all, especially when related to the options.
So, reorganize things a little bit here:
*) move all helpers on top
*) keep things alphabetically sorted
*) move options parsing in a separate file
*) move predefine-related stuff in a separate file
Luc Van Oostenryck (15):
options: let handle_onoff_switch() use null terminated arrays
options: move -Wsparse-all's processing out of handle_onoff_switch()
options: move on top the definition of warning type enums
options: make Wsparse_error less special
options: handle_onoff_switch() can handle any flags, not only warnings
options: move helpers up
options: alphasort the handle_switch_[a-zA_Z]()
options: avoid spaces between function name and arguments list
options: move declaration of tabstop out of "token.h"
options: add a small helper: handle_switch_finalize()
options: move option parsing in a separate file
options: keep the options sorted
cleanup: move predefines in a separate file
cleanup: move parsing helpers to parse.c
cleanup: move hexval() to utils.c
Makefile | 2 +
lib.c | 1256 +--------------------------------------------------
lib.h | 119 +----
options.c | 998 ++++++++++++++++++++++++++++++++++++++++
options.h | 137 ++++++
parse.c | 38 ++
predefine.c | 225 +++++++++
token.h | 1 -
utils.c | 17 +
utils.h | 4 +
10 files changed, 1427 insertions(+), 1370 deletions(-)
create mode 100644 options.c
create mode 100644 options.h
create mode 100644 predefine.c
base-commit: fa15396204a796135f71b5aef6cbbe3ba1fc0eb3
--
2.27.0
Since handle_onoff_switch() can be used for other flags than the
warnings, the processing of -Wsparse-all should move elsewhere.
So move it into handle_switch_W().
Signed-off-by: Luc Van Oostenryck <[email protected]>
---
lib.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib.c b/lib.c
index 709dd5176112..5128a5b64e9e 100644
--- a/lib.c
+++ b/lib.c
@@ -535,14 +535,6 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn
char *p = arg + 1;
unsigned i;
- if (!strcmp(p, "sparse-all")) {
- for (i = 0; warnings[i].name; i++) {
- if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
- *warnings[i].flag = WARNING_ON;
- }
- return NULL;
- }
-
// Prefixes "no" and "no-" mean to turn warning off.
if (p[0] == 'n' && p[1] == 'o') {
p += 2;
@@ -798,6 +790,14 @@ static char **handle_switch_W(char *arg, char **next)
if (ret)
return ret;
+ if (!strcmp(arg, "Wsparse-all")) {
+ int i;
+ for (i = 0; warnings[i].name; i++) {
+ if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
+ *warnings[i].flag = WARNING_ON;
+ }
+ }
+
// Unknown.
return next;
}
--
2.27.0
-Wsparse-error should not be enabled with -Wsparse-all, this is
special cased in the condition in loop handling -Wsparse-all.
However, the condition already handle warnings forced to off.
So instead of explicitly checking for &Wsparse_error, it's enough
to force Wsparse_error off.
Signed-off-by: Luc Van Oostenryck <[email protected]>
---
lib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib.c b/lib.c
index 43d55a0648ee..9acdc60fc416 100644
--- a/lib.c
+++ b/lib.c
@@ -276,7 +276,6 @@ int Winit_cstring = 0;
int Wint_to_pointer_cast = 1;
int Wenum_mismatch = 1;
int Wexternal_function_has_definition = 1;
-int Wsparse_error = 0;
int Wmemcpy_max_count = 1;
int Wnewline_eof = 1;
int Wnon_pointer_null = 1;
@@ -296,6 +295,7 @@ int Wshadow = 0;
int Wshift_count_negative = 1;
int Wshift_count_overflow = 1;
int Wsizeof_bool = 0;
+int Wsparse_error = WARNING_FORCE_OFF;
int Wstrict_prototypes = 1;
int Wtautological_compare = 0;
int Wtransparent_union = 0;
@@ -793,7 +793,7 @@ static char **handle_switch_W(char *arg, char **next)
if (!strcmp(arg, "Wsparse-all")) {
int i;
for (i = 0; warnings[i].name; i++) {
- if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
+ if (*warnings[i].flag != WARNING_FORCE_OFF)
*warnings[i].flag = WARNING_ON;
}
}
--
2.27.0
So, use 'flag' instead of 'warning' for variable and function names.
Signed-off-by: Luc Van Oostenryck <[email protected]>
---
lib.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/lib.c b/lib.c
index 9acdc60fc416..c27773097127 100644
--- a/lib.c
+++ b/lib.c
@@ -250,10 +250,10 @@ void die(const char *fmt, ...)
static struct token *pre_buffer_begin = NULL;
static struct token *pre_buffer_end = NULL;
-enum warning_type {
- WARNING_OFF,
- WARNING_ON,
- WARNING_FORCE_OFF
+enum flag_type {
+ FLAG_OFF,
+ FLAG_ON,
+ FLAG_FORCE_OFF
};
int Waddress = 0;
@@ -295,7 +295,7 @@ int Wshadow = 0;
int Wshift_count_negative = 1;
int Wshift_count_overflow = 1;
int Wsizeof_bool = 0;
-int Wsparse_error = WARNING_FORCE_OFF;
+int Wsparse_error = FLAG_FORCE_OFF;
int Wstrict_prototypes = 1;
int Wtautological_compare = 0;
int Wtransparent_union = 0;
@@ -529,9 +529,9 @@ static int opt_##NAME(const char *arg, const char *opt, TYPE *ptr, int flag) \
OPT_NUMERIC(ullong, unsigned long long, strtoull)
OPT_NUMERIC(uint, unsigned int, strtoul)
-static char **handle_onoff_switch(char *arg, char **next, const struct flag warnings[])
+static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[])
{
- int flag = WARNING_ON;
+ int flag = FLAG_ON;
char *p = arg + 1;
unsigned i;
@@ -540,12 +540,12 @@ static char **handle_onoff_switch(char *arg, char **next, const struct flag warn
p += 2;
if (p[0] == '-')
p++;
- flag = WARNING_FORCE_OFF;
+ flag = FLAG_FORCE_OFF;
}
- for (i = 0; warnings[i].name; i++) {
- if (!strcmp(p,warnings[i].name)) {
- *warnings[i].flag = flag;
+ for (i = 0; flags[i].name; i++) {
+ if (!strcmp(p,flags[i].name)) {
+ *flags[i].flag = flag;
return next;
}
}
@@ -722,7 +722,7 @@ static char **handle_switch_o(char *arg, char **next)
}
static const struct flag pflags[] = {
- { "pedantic", &Wpedantic, NULL, OPT_VAL, WARNING_ON },
+ { "pedantic", &Wpedantic, NULL, OPT_VAL, FLAG_ON },
{ }
};
@@ -793,8 +793,8 @@ static char **handle_switch_W(char *arg, char **next)
if (!strcmp(arg, "Wsparse-all")) {
int i;
for (i = 0; warnings[i].name; i++) {
- if (*warnings[i].flag != WARNING_FORCE_OFF)
- *warnings[i].flag = WARNING_ON;
+ if (*warnings[i].flag != FLAG_FORCE_OFF)
+ *warnings[i].flag = FLAG_ON;
}
}
@@ -858,13 +858,13 @@ static char **handle_switch_d(char *arg, char **next)
}
-static void handle_onoff_switch_finalize(const struct flag warnings[])
+static void handle_onoff_switch_finalize(const struct flag flags[])
{
unsigned i;
- for (i = 0; warnings[i].name; i++) {
- if (*warnings[i].flag == WARNING_FORCE_OFF)
- *warnings[i].flag = WARNING_OFF;
+ for (i = 0; flags[i].name; i++) {
+ if (*flags[i].flag == FLAG_FORCE_OFF)
+ *flags[i].flag = FLAG_OFF;
}
}
--
2.27.0
Deepest apologies, I've sent this to the wrong ML.
-- Luc