From: Sven Verdoolaege Date: Sat, 13 Nov 2010 14:24:31 +0000 (+0100) Subject: isl_arg_parse: support ISL_ARG_SINGLE_DASH flag X-Git-Tag: isl-0.05~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=635ac93275adc2acbe3f98b7ab331e9c191e6481;p=platform%2Fupstream%2Fisl.git isl_arg_parse: support ISL_ARG_SINGLE_DASH flag Signed-off-by: Sven Verdoolaege --- diff --git a/include/isl/arg.h b/include/isl/arg.h index d64b3db..7d85c01 100644 --- a/include/isl/arg.h +++ b/include/isl/arg.h @@ -50,6 +50,7 @@ struct isl_arg { const char *argument_name; size_t offset; const char *help_msg; +#define ISL_ARG_SINGLE_DASH (1 << 0) unsigned flags; union { struct { diff --git a/isl_arg.c b/isl_arg.c index eef54a6..a69f4bb 100644 --- a/isl_arg.c +++ b/isl_arg.c @@ -153,11 +153,16 @@ static int print_arg_help(struct isl_arg *decl, const char *prefix, int no) return 4; } - if (decl->short_name) + if (decl->short_name) { printf(" -%c, --", decl->short_name); - else + len += 8; + } else if (decl->flags & ISL_ARG_SINGLE_DASH) { + printf(" -"); + len += 3; + } else { printf(" --"); - len += 8; + len += 8; + } if (prefix) { printf("%s-", prefix); @@ -528,6 +533,15 @@ static int match_long_name(struct isl_arg *decl, return 0; } +static const char *skip_dash_dash(struct isl_arg *decl, const char *arg) +{ + if (!strncmp(arg, "--", 2)) + return arg + 2; + if ((decl->flags & ISL_ARG_SINGLE_DASH) && arg[0] == '-') + return arg + 1; + return NULL; +} + static const char *skip_name(struct isl_arg *decl, const char *arg, const char *prefix, int need_argument, int *has_argument) { @@ -545,10 +559,10 @@ static const char *skip_name(struct isl_arg *decl, const char *arg, if (!decl->long_name) return NULL; - if (strncmp(arg, "--", 2)) + name = skip_dash_dash(decl, arg); + if (!name) return NULL; - name = arg + 2; equal = strchr(name, '='); if (need_argument && !equal) return NULL; @@ -680,9 +694,9 @@ static int parse_bool_option(struct isl_arg *decl, const char *arg, if (!decl->long_name) return 0; - if (strncmp(arg, "--", 2)) + arg = skip_dash_dash(decl, arg); + if (!arg) return 0; - arg += 2; if (prefix) { size_t prefix_len = strlen(prefix);