@matheusbsbs / matheus-bagliano / commits / 1f4a711a05
Fork 0

parse-options.c: introduce OPT_DATE

There are quite a few places that will need to call approxidate(), when they'll adopt the parse-options system, so this patch adds the function parse_opt_approxidate_cb(), used by OPT_DATE. Signed-off-by: Michele Ballabio <barra_cuda@katamail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michele Ballabio committed Mar 24, 2008 at 15:02 UTC 1f4a711a05e00db81da552dd990f6ddff4ffb63e
2 files changed +11
parse-options.c
+7
@@ -409,3 +409,10 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
409 *(int *)(opt->value) = v;
410 return 0;
411 }
412 +
413 +int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
414 + int unset)
415 +{
416 + *(unsigned long *)(opt->value) = approxidate(arg);
417 + return 0;
418 +}
parse-options.h
+4
@@ -94,6 +94,9 @@ struct option {
94 #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) }
95 #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) }
96 #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) }
97 +#define OPT_DATE(s, l, v, h) \
98 + { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \
99 + parse_opt_approxidate_cb }
100 #define OPT_CALLBACK(s, l, v, a, h, f) \
101 { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
102
@@ -110,6 +113,7 @@ extern NORETURN void usage_with_options(const char * const *usagestr,
113
114 /*----- some often used options -----*/
115 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
116 +extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
117
118 #define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
119 #define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")