Merge branch 'nd/switch-and-restore'
[gitweb.git] / parse-options-cb.c
index 4b95d04a37c028322c6fbf7d3f1b59e0d541fdb3..1240a8514e040954cbc7f091e7053b5c76ac6627 100644 (file)
@@ -16,6 +16,9 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
        if (!arg) {
                v = unset ? 0 : DEFAULT_ABBREV;
        } else {
+               if (!*arg)
+                       return error(_("option `%s' expects a numerical value"),
+                                    opt->long_name);
                v = strtol(arg, (char **)&arg, 10);
                if (*arg)
                        return error(_("option `%s' expects a numerical value"),
@@ -156,6 +159,23 @@ int parse_opt_tertiary(const struct option *opt, const char *arg, int unset)
        return 0;
 }
 
+struct option *parse_options_dup(const struct option *o)
+{
+       struct option *opts;
+       int nr = 0;
+
+       while (o && o->type != OPTION_END) {
+               nr++;
+               o++;
+       }
+
+       ALLOC_ARRAY(opts, nr + 1);
+       memcpy(opts, o - nr, sizeof(*o) * nr);
+       memset(opts + nr, 0, sizeof(*opts));
+       opts[nr].type = OPTION_END;
+       return opts;
+}
+
 struct option *parse_options_concat(struct option *a, struct option *b)
 {
        struct option *ret;