From: Tokunori Ikegami Date: Sun, 30 Apr 2023 13:35:46 +0000 (+0900) Subject: util: Delete unused argconfig subopts type X-Git-Tag: v2.5~133 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a6244a5e026b6916dbb15d52dee7bf60b36d8340;p=users%2Fsagi%2Fnvme-cli.git util: Delete unused argconfig subopts type Signed-off-by: Tokunori Ikegami --- diff --git a/util/argconfig.c b/util/argconfig.c index 6b547b9b..630c3ea5 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -48,8 +48,6 @@ #define fallthrough do {} while (0) #endif -static char END_DEFAULT[] = "__end_default__"; - static const char *append_usage_str = ""; void argconfig_append_usage(const char *str) @@ -167,8 +165,6 @@ static int argconfig_parse_type(struct argconfig_commandline_options *s, struct void *value = (void *)(char *)s->default_value; char *endptr; int ret = 0; - char **opts = ((char **)value); - int remaining_space = CFG_MAX_SUBOPTS - 2; switch (s->config_type) { case CFG_STRING: @@ -229,18 +225,6 @@ static int argconfig_parse_type(struct argconfig_commandline_options *s, struct if (errno || optarg == endptr) ret = argconfig_error("float", option[index].name, optarg); break; - case CFG_SUBOPTS: - *opts = END_DEFAULT; - opts += 2; - ret = argconfig_parse_subopt_string(optarg, opts, remaining_space); - if (ret) { - if (ret == 2) - fprintf(stderr, "Error Parsing Sub-Options: Too many options!\n"); - else - fprintf(stderr, "Error Parsing Sub-Options\n"); - ret = -EINVAL; - } - break; case CFG_FLAG: *((bool *)value) = true; break; @@ -360,82 +344,6 @@ out: return ret; } -int argconfig_parse_subopt_string(char *string, char **options, - size_t max_options) -{ - char **o = options; - char *tmp; - size_t toklen; - - if (!string || !strlen(string)) { - *(o++) = NULL; - *(o++) = NULL; - return 0; - } - - tmp = calloc(strlen(string) + 2, 1); - if (!tmp) - return 1; - strcpy(tmp, string); - - toklen = strcspn(tmp, "="); - - if (!toklen) { - free(tmp); - return 1; - } - - *(o++) = tmp; - tmp[toklen] = 0; - tmp += toklen + 1; - - while (1) { - if (*tmp == '"' || *tmp == '\'' || *tmp == '[' || *tmp == '(' || - *tmp == '{') { - - tmp++; - toklen = strcspn(tmp, "\"'])}"); - - if (!toklen) - return 1; - - *(o++) = tmp; - tmp[toklen] = 0; - tmp += toklen + 1; - - toklen = strcspn(tmp, ";:,"); - tmp[toklen] = 0; - tmp += toklen + 1; - } else { - toklen = strcspn(tmp, ";:,"); - - if (!toklen) - return 1; - - *(o++) = tmp; - tmp[toklen] = 0; - tmp += toklen + 1; - } - - toklen = strcspn(tmp, "="); - - if (!toklen) - break; - - *(o++) = tmp; - tmp[toklen] = 0; - tmp += toklen + 1; - - if ((o - options) > (max_options - 2)) - return 2; - } - - *(o++) = NULL; - *(o++) = NULL; - - return 0; -} - int argconfig_parse_comma_sep_array(char *string, int *val, unsigned max_length) { diff --git a/util/argconfig.h b/util/argconfig.h index f0e39f4e..1a2828ff 100644 --- a/util/argconfig.h +++ b/util/argconfig.h @@ -53,7 +53,6 @@ enum argconfig_types { CFG_SHORT, CFG_POSITIVE, CFG_INCREMENT, - CFG_SUBOPTS, }; #define OPT_ARGS(n) \ @@ -107,15 +106,11 @@ struct argconfig_commandline_options { bool seen; }; -#define CFG_MAX_SUBOPTS 500 - void argconfig_append_usage(const char *str); void argconfig_print_help(const char *program_desc, struct argconfig_commandline_options *options); int argconfig_parse(int argc, char *argv[], const char *program_desc, struct argconfig_commandline_options *options); -int argconfig_parse_subopt_string(char *string, char **options, - size_t max_options); int argconfig_parse_comma_sep_array(char *string, int *ret, unsigned max_length); int argconfig_parse_comma_sep_array_short(char *string, unsigned short *ret,