linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 3/9] option: let handle_simple_switch() handle an array of flags
Date: Wed,  8 Nov 2017 11:10:02 +0100	[thread overview]
Message-ID: <20171108101008.43804-4-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20171108101008.43804-1-luc.vanoostenryck@gmail.com>

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 <luc.vanoostenryck@gmail.com>
---
 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


  parent reply	other threads:[~2017-11-08 10:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 10:09 [PATCH 0/9] option parsing improvements Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 1/9] option: add helper to parse/match command line options Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 2/9] option: rename 'struct warning' to 'struct flag' Luc Van Oostenryck
2017-11-08 10:10 ` Luc Van Oostenryck [this message]
2017-11-08 10:10 ` [PATCH 4/9] option: extract OPTION_NUMERIC() from handle_switch_fmemcpy_max_count() Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 5/9] option: add support for options with 'zero is infinity' Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 6/9] option: add support for '-<some-option>=unlimited' Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 7/9] option: use OPTION_NUMERIC() for handle_switch_fmemcpy_max_count() Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 8/9] option: constify match_option() Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 9/9] option: handle switches by table Luc Van Oostenryck
2017-11-09 18:42   ` Christopher Li
2017-11-09 21:02     ` Luc Van Oostenryck
  -- strict thread matches above, loose matches on Subject: below --
2017-09-15  7:32 [PATCH 0/9] Simplify the parsion of options Luc Van Oostenryck
2017-09-15  7:32 ` [PATCH 3/9] option: let handle_simple_switch() handle an array of flags Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171108101008.43804-4-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).