parse-options: avoid magic return codes
[gitweb.git] / parse-options.h
index f1f246387cae57748a04efa139da7a1d4b8951be..4e49185027a049e073c6991ffda7f2ae2a6c487e 100644 (file)
@@ -49,8 +49,8 @@ struct option;
 typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
 
 struct parse_opt_ctx_t;
-typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
-                               const struct option *opt, int unset);
+typedef enum parse_opt_result parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
+                                             const struct option *opt, int unset);
 
 /*
  * `type`::
@@ -222,12 +222,12 @@ const char *optname(const struct option *opt, int flags);
 
 /*----- incremental advanced APIs -----*/
 
-enum {
-       PARSE_OPT_COMPLETE = -2,
-       PARSE_OPT_HELP = -1,
-       PARSE_OPT_DONE,
+enum parse_opt_result {
+       PARSE_OPT_COMPLETE = -3,
+       PARSE_OPT_HELP = -2,
+       PARSE_OPT_ERROR = -1,   /* must be the same as error() */
+       PARSE_OPT_DONE = 0,     /* fixed so that "return 0" works */
        PARSE_OPT_NON_OPTION,
-       PARSE_OPT_ERROR,
        PARSE_OPT_UNKNOWN
 };