summaryrefslogtreecommitdiff
path: root/test-parse-options.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2009-05-07 19:45:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-05-09 07:29:47 (GMT)
commite0319ff5ed2b7927302389181449dcd029a26622 (patch)
tree5185c782d22d57ce359f0493bc26aa5ac5215c77 /test-parse-options.c
parent2f4b97f91071f5060bf2da482cf8b0d70486d808 (diff)
downloadgit-e0319ff5ed2b7927302389181449dcd029a26622.zip
git-e0319ff5ed2b7927302389181449dcd029a26622.tar.gz
git-e0319ff5ed2b7927302389181449dcd029a26622.tar.bz2
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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'test-parse-options.c')
-rw-r--r--test-parse-options.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/test-parse-options.c b/test-parse-options.c
index eddc026..d46eac2 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),