From 0ce865b134f8ccd60f6e584744144b0978a9fdf2 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 14 Oct 2007 11:05:12 +0200 Subject: Add shortcuts for very often used options. It helps with consistency of the help strings, for example. Signed-off-by: Pierre Habouzit Signed-off-by: Shawn O. Pearce --- parse-options.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'parse-options.c') diff --git a/parse-options.c b/parse-options.c index c751ebf601..12a9f9ea68 100644 --- a/parse-options.c +++ b/parse-options.c @@ -254,3 +254,24 @@ void usage_with_options(const char * const *usagestr, exit(129); } + +/*----- some often used options -----*/ +#include "cache.h" +int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) +{ + int v; + + if (!arg) { + v = unset ? 0 : DEFAULT_ABBREV; + } else { + v = strtol(arg, (char **)&arg, 10); + if (*arg) + return opterror(opt, "expects a numerical value", 0); + if (v && v < MINIMUM_ABBREV) + v = MINIMUM_ABBREV; + else if (v > 40) + v = 40; + } + *(int *)(opt->value) = v; + return 0; +} -- cgit v1.2.3