diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-09-13 09:57:49 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-09-14 18:27:20 +0200 |
| commit | 443142fb7e0f62e7e4fde9edc23166e21a7cbbd4 (patch) | |
| tree | a36125e71ad9c1597160a918c538fcafb5097ad4 | |
| parent | dc54f0c9a44c084f894e346eea3ea626733052bb (diff) | |
| download | sparse-dev-443142fb7e0f62e7e4fde9edc23166e21a7cbbd4.tar.gz | |
option: add support for options with 'zero is infinity'
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>
| -rw-r--r-- | lib.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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; \ } |
