From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 5/9] option: add support for options with 'zero is infinity'
Date: Fri, 15 Sep 2017 09:32:19 +0200 [thread overview]
Message-ID: <20170915073223.7568-6-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170915073223.7568-1-luc.vanoostenryck@gmail.com>
For some options with a numerical value, it is sometimes desirable,
to easily specify we want the maximum possible value.
This patch allow to interpret '=0' as meaning the maximum value.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
lib.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib.c b/lib.c
index 5fda4b029..6352b4e93 100644
--- a/lib.c
+++ b/lib.c
@@ -509,8 +509,11 @@ static int handle_simple_switch(const char *arg, const struct flag *flags)
return 0;
}
+
+#define OPTNUM_ZERO_IS_INF 1
+
#define OPT_NUMERIC(NAME, TYPE, FUNCTION) \
-static int opt_##NAME(char *arg, const char *name, TYPE *ptr) \
+static int opt_##NAME(char *arg, const char *name, TYPE *ptr, int flag) \
{ \
char *opt; \
char *end; \
@@ -523,6 +526,8 @@ static int opt_##NAME(char *arg, const char *name, TYPE *ptr) \
if (*end != '\0' || end == opt) { \
die("error: missing argument to \"%s\"", name); \
} \
+ if ((flag & OPTNUM_ZERO_IS_INF) && val == 0) \
+ val = ~val; \
*ptr = val; \
return 1; \
}
--
2.14.0
next prev parent reply other threads:[~2017-09-15 7:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-15 7:32 [PATCH 0/9] Simplify the parsion of options Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 1/9] option: add helper to parse/match command line options Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 2/9] option: rename 'struct warning' to 'struct flag' Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 3/9] option: let handle_simple_switch() handle an array of flags Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 4/9] option: extract OPTION_NUMERIC() from handle_switch_fmemcpy_max_count() Luc Van Oostenryck
2017-09-15 7:32 ` Luc Van Oostenryck [this message]
2017-09-15 7:32 ` [PATCH 6/9] option: add support for '-<some-option>=unlimited' Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 7/9] option: use OPTION_NUMERIC() for handle_switch_fmemcpy_max_count() Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 8/9] option: constify match_option() Luc Van Oostenryck
2017-09-15 7:32 ` [PATCH 9/9] option: handle switches by table Luc Van Oostenryck
-- strict thread matches above, loose matches on Subject: below --
2017-11-08 10:09 [PATCH 0/9] option parsing improvements Luc Van Oostenryck
2017-11-08 10:10 ` [PATCH 5/9] option: add support for options with 'zero is infinity' 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=20170915073223.7568-6-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.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).