From 2f4b97f91071f5060bf2da482cf8b0d70486d808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 7 May 2009 21:44:17 +0200 Subject: parseopt: add OPT_NEGBIT Add OPTION_NEGBIT and OPT_NEGBIT, mirroring OPTION_BIT and OPT_BIT. OPT_NEGBIT can be used together with OPT_BIT to define two options that cancel each other out. Note: this patch removes the reminder from the test script because it adds a test for --no-or4 and there already was one for --or4. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- test-parse-options.c | 1 + 1 file changed, 1 insertion(+) (limited to 'test-parse-options.c') diff --git a/test-parse-options.c b/test-parse-options.c index 61d2c39814..eddc0267a2 100644 --- a/test-parse-options.c +++ b/test-parse-options.c @@ -29,6 +29,7 @@ int main(int argc, const char **argv) OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"), OPT_BIT('4', "or4", &boolean, "bitwise-or boolean with ...0100", 4), + OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4), OPT_GROUP(""), OPT_INTEGER('i', "integer", &integer, "get a integer"), OPT_INTEGER('j', NULL, &integer, "get a integer, too"), -- cgit v1.2.3 From e0319ff5ed2b7927302389181449dcd029a26622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 7 May 2009 21:45:08 +0200 Subject: parseopt: add OPT_NUMBER_CALLBACK Add a way to recognize numerical options. The number is passed to a callback function as a string. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- test-parse-options.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test-parse-options.c') diff --git a/test-parse-options.c b/test-parse-options.c index eddc0267a2..d46eac21b1 100644 --- a/test-parse-options.c +++ b/test-parse-options.c @@ -19,6 +19,12 @@ int length_callback(const struct option *opt, const char *arg, int unset) return 0; } +int number_callback(const struct option *opt, const char *arg, int unset) +{ + *(int *)opt->value = strtol(arg, NULL, 10); + return 0; +} + int main(int argc, const char **argv) { const char *usage[] = { @@ -46,6 +52,8 @@ int main(int argc, const char **argv) "set string to default", (unsigned long)"default"), OPT_GROUP("Magic arguments"), OPT_ARGUMENT("quux", "means --quux"), + OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", + number_callback), OPT_GROUP("Standard options"), OPT__ABBREV(&abbrev), OPT__VERBOSE(&verbose), -- cgit v1.2.3 From 51a9949eda7421a2dd9cb45b2110d6571ba09bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 7 May 2009 21:45:42 +0200 Subject: parseopt: add PARSE_OPT_NODASH Add support for options that don't start with a dash. Initially, they don't accept arguments and can only be short options, i.e. consist of a single character. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- test-parse-options.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test-parse-options.c') diff --git a/test-parse-options.c b/test-parse-options.c index d46eac21b1..e0669dcb41 100644 --- a/test-parse-options.c +++ b/test-parse-options.c @@ -54,6 +54,8 @@ int main(int argc, const char **argv) OPT_ARGUMENT("quux", "means --quux"), OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", number_callback), + { OPTION_BOOLEAN, '+', NULL, &boolean, NULL, "same as -b", + PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH }, OPT_GROUP("Standard options"), OPT__ABBREV(&abbrev), OPT__VERBOSE(&verbose), -- cgit v1.2.3