From mboxrd@z Thu Jan 1 00:00:00 1970 From: Luc Van Oostenryck Subject: [PATCH 3/9] option: let handle_simple_switch() handle an array of flags Date: Wed, 8 Nov 2017 11:10:02 +0100 Message-ID: <20171108101008.43804-4-luc.vanoostenryck@gmail.com> References: <20171108101008.43804-1-luc.vanoostenryck@gmail.com> Return-path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:49019 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750832AbdKHKKY (ORCPT ); Wed, 8 Nov 2017 05:10:24 -0500 Received: by mail-wm0-f67.google.com with SMTP id p75so9264735wmg.3 for ; Wed, 08 Nov 2017 02:10:23 -0800 (PST) In-Reply-To: <20171108101008.43804-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck This was used to handle a single flag but we need something more compact when we need to handle several flags. So, adapt this helper so that it now takes an array of flags instead of a single flag. Signed-off-by: Luc Van Oostenryck --- lib.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib.c b/lib.c index 04f9de5a8..992fdb49a 100644 --- a/lib.c +++ b/lib.c @@ -483,7 +483,12 @@ char *match_option(char *arg, const char *prefix) return NULL; } -static int handle_simple_switch(const char *arg, const char *name, int *flag) +struct flag { + const char *name; + int *flag; +}; + +static int handle_simple_switch(const char *arg, const struct flag *flags) { int val = 1; @@ -493,9 +498,11 @@ static int handle_simple_switch(const char *arg, const char *name, int *flag) val = 0; } - if (strcmp(arg, name) == 0) { - *flag = val; - return 1; + for (; flags->name; flags++) { + if (strcmp(arg, flags->name) == 0) { + *flags->flag = val; + return 1; + } } // not handled @@ -513,10 +520,7 @@ static char **handle_switch_o(char *arg, char **next) return next; } -static const struct flag { - const char *name; - int *flag; -} warnings[] = { +static const struct flag warnings[] = { { "address", &Waddress }, { "address-space", &Waddress_space }, { "bitwise", &Wbitwise }, @@ -745,6 +749,11 @@ err: die("error: unknown flag \"-fdump-%s\"", arg); } +static struct flag fflags[] = { + { "mem-report", &fmem_report }, + { }, +}; + static char **handle_switch_f(char *arg, char **next) { char *opt; @@ -758,7 +767,7 @@ static char **handle_switch_f(char *arg, char **next) return handle_switch_fmemcpy_max_count(opt, next); /* handle switches w/ arguments above, boolean and only boolean below */ - if (handle_simple_switch(arg, "mem-report", &fmem_report)) + if (handle_simple_switch(arg, fflags)) return next; return next; -- 2.14.0