aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-02-21 21:54:32 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-11-15 02:25:59 +0100
commit13391893fd91d9fd39dc393e2b90106236783ba7 (patch)
tree57af7948d4d1e9b8a9ff7e158172f70fd691833b
parented7b9191f7a5850140604da890e61a4d6fc9fca6 (diff)
downloadsparse-13391893fd91d9fd39dc393e2b90106236783ba7.tar.gz
option: allow handle_switches() to set non-boolean values
The function handle_switches() was designated to set or clear simple boolean flags but some options, internally, are non-boolean. So, extend the function so that it can be used to set non-boolean values. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--lib.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 4b5bc7d4..3f36ed2d 100644
--- a/lib.c
+++ b/lib.c
@@ -418,11 +418,13 @@ static const char *match_option(const char *arg, const char *prefix)
}
#define OPT_INVERSE 1
+#define OPT_VAL 2
struct flag {
const char *name;
int *flag;
int (*fun)(const char *arg, const char *opt, const struct flag *, int options);
unsigned long mask;
+ int val;
};
static int handle_switches(const char *ori, const char *opt, const struct flag *flags)
@@ -453,6 +455,8 @@ static int handle_switches(const char *ori, const char *opt, const struct flag *
// boolean flag
if (opt[0] == '\0' && flags->flag) {
+ if (flags->mask & OPT_VAL)
+ val = flags->val;
if (flags->mask & OPT_INVERSE)
val = !val;
*flags->flag = val;