aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-08-09 11:58:40 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-02 21:07:52 +0200
commit9e9ee8433d21912b87300a9c8957d4148e64b1c0 (patch)
treec8cfa3da994d08d16f1ea542af0d05f7bf0a0fc1
parentdaaeb83f8232d390802a724c327f13810f630e78 (diff)
downloadsparse-9e9ee8433d21912b87300a9c8957d4148e64b1c0.tar.gz
options: move helpers up
The helpers for parsing the options are often situated just above the first function using them. As result, these helpers can be found a bit everywhere in the code, it's messy and doesn't help to reuse these helpers. So, move all these helpers to the top. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--lib.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/lib.c b/lib.c
index c2777309..4868154f 100644
--- a/lib.c
+++ b/lib.c
@@ -364,6 +364,15 @@ void add_pre_buffer(const char *fmt, ...)
////////////////////////////////////////////////////////////////////////////////
// Helpers for option parsing
+static const char *match_option(const char *arg, const char *prefix)
+{
+ unsigned int n = strlen(prefix);
+ if (strncmp(arg, prefix, n) == 0)
+ return arg + n;
+ return NULL;
+}
+
+
struct val_map {
const char *name;
int val;
@@ -438,14 +447,6 @@ end:
}
-static const char *match_option(const char *arg, const char *prefix)
-{
- unsigned int n = strlen(prefix);
- if (strncmp(arg, prefix, n) == 0)
- return arg + n;
- return NULL;
-}
-
#define OPT_INVERSE 1
#define OPT_VAL 2
struct flag {
@@ -497,6 +498,41 @@ static int handle_switches(const char *ori, const char *opt, const struct flag *
return 0;
}
+static char **handle_onoff_switch(char *arg, char **next, const struct flag flags[])
+{
+ int flag = FLAG_ON;
+ char *p = arg + 1;
+ unsigned i;
+
+ // Prefixes "no" and "no-" mean to turn warning off.
+ if (p[0] == 'n' && p[1] == 'o') {
+ p += 2;
+ if (p[0] == '-')
+ p++;
+ flag = FLAG_FORCE_OFF;
+ }
+
+ for (i = 0; flags[i].name; i++) {
+ if (!strcmp(p,flags[i].name)) {
+ *flags[i].flag = flag;
+ return next;
+ }
+ }
+
+ // Unknown.
+ return NULL;
+}
+
+static void handle_onoff_switch_finalize(const struct flag flags[])
+{
+ unsigned i;
+
+ for (i = 0; flags[i].name; i++) {
+ if (*flags[i].flag == FLAG_FORCE_OFF)
+ *flags[i].flag = FLAG_OFF;
+ }
+}
+
static int handle_switch_setval(const char *arg, const char *opt, const struct flag *flag, int options)
{
*(flag->flag) = flag->mask;
@@ -529,31 +565,6 @@ 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 flags[])
-{
- int flag = FLAG_ON;
- char *p = arg + 1;
- unsigned i;
-
- // Prefixes "no" and "no-" mean to turn warning off.
- if (p[0] == 'n' && p[1] == 'o') {
- p += 2;
- if (p[0] == '-')
- p++;
- flag = FLAG_FORCE_OFF;
- }
-
- for (i = 0; flags[i].name; i++) {
- if (!strcmp(p,flags[i].name)) {
- *flags[i].flag = flag;
- return next;
- }
- }
-
- // Unknown.
- return NULL;
-}
-
////////////////////////////////////////////////////////////////////////////////
// Option parsing
@@ -858,16 +869,6 @@ static char **handle_switch_d(char *arg, char **next)
}
-static void handle_onoff_switch_finalize(const struct flag flags[])
-{
- unsigned i;
-
- for (i = 0; flags[i].name; i++) {
- if (*flags[i].flag == FLAG_FORCE_OFF)
- *flags[i].flag = FLAG_OFF;
- }
-}
-
static void handle_switch_W_finalize(void)
{
handle_onoff_switch_finalize(warnings);