X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=parse-options.c;h=fd08bb425c241a0861588ec0aedd15041095a95f;hb=1e2bba92d21d9c72d4a6816c3a98a22779856f9e;hp=ae88885d4da573c85dbfbeea3061f3b026223710;hpb=19792b27da51bc52cfd08c7a17473b8a1f26d8a3;p=git.git diff --git a/parse-options.c b/parse-options.c index ae88885d4..fd08bb425 100644 --- a/parse-options.c +++ b/parse-options.c @@ -5,12 +5,6 @@ #define OPT_SHORT 1 #define OPT_UNSET 2 -static inline const char *skip_prefix(const char *str, const char *prefix) -{ - size_t len = strlen(prefix); - return strncmp(str, prefix, len) ? NULL : str + len; -} - static int opterror(const struct option *opt, const char *reason, int flags) { if (flags & OPT_SHORT) @@ -28,7 +22,7 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, p->opt = NULL; } else if (p->argc == 1 && (opt->flags & PARSE_OPT_LASTARG_DEFAULT)) { *arg = (const char *)opt->defval; - } else if (p->argc) { + } else if (p->argc > 1) { p->argc--; *arg = *++p->argv; } else @@ -220,7 +214,7 @@ is_abbreviated: return -2; } -void check_typos(const char *arg, const struct option *options) +static void check_typos(const char *arg, const struct option *options) { if (strlen(arg) < 3) return; @@ -489,3 +483,15 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg, *(unsigned long *)(opt->value) = approxidate(arg); return 0; } + +/* + * This should really be OPTION_FILENAME type as a part of + * parse_options that take prefix to do this while parsing. + */ +extern const char *parse_options_fix_filename(const char *prefix, const char *file) +{ + if (!file || !prefix || is_absolute_path(file) || !strcmp("-", file)) + return file; + return prefix_filename(prefix, strlen(prefix), file); +} +