From e2efbbe64e1cea3942e9ffc5c60f9e3f60975180 Mon Sep 17 00:00:00 2001 From: katherine Date: Mon, 19 Mar 2018 20:38:34 -0700 Subject: update documentation for new functionality added SIMPLE_OPT_CHAR, SIMPLE_OPT_DOUBLE, and SIMPLE_OPT_STRING_SET types --- src/simple-opt.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/simple-opt.h b/src/simple-opt.h index e6f329d..d250e73 100644 --- a/src/simple-opt.h +++ b/src/simple-opt.h @@ -53,8 +53,8 @@ struct simple_opt { /* optional, a custom string describing the arg, used for usage printing */ const char *custom_arg_string; - /* for type SIMPLE_OPT_STRING_SET, a NULL-terminated array of string - * possibilities against which an option's argument is matched */ + /* required for type SIMPLE_OPT_STRING_SET, a NULL-terminated array of + * string possibilities against which an option's argument is matched */ const char **string_set; /* values assigned upon successful option parse */ @@ -261,7 +261,9 @@ static struct simple_opt_result simple_opt_parse(int argc, char **argv, for (i = 0; options[i].type != SIMPLE_OPT_END; i++) { if ( (options[i].short_name == '\0' && options[i].long_name == NULL) || (options[i].type == SIMPLE_OPT_FLAG && - options[i].arg_is_required) ) { + options[i].arg_is_required) + || (options[i].type == SIMPLE_OPT_STRING_SET && + options[i].string_set == NULL) ) { r.result_type = SIMPLE_OPT_RESULT_MALFORMED_OPTION_STRUCT; goto end; } @@ -568,13 +570,13 @@ static void simple_opt_print_usage(FILE *f, unsigned width, char *usage_name, } } - /* 5 for leading " -X ", 1 for trailing " " */ - if (desc_line_start < j + 5 + 1) - desc_line_start = j + 5 + 1; + /* 5 for leading " -X ", 2 for trailing " " */ + if (desc_line_start < j + 5 + 2) + desc_line_start = j + 5 + 2; } /* check for space for long_name printing */ - if (desc_line_start - 5 - 1 >= SIMPLE_OPT_USAGE_PRINT_BUFFER_WIDTH) { + if (desc_line_start - 5 - 2 >= SIMPLE_OPT_USAGE_PRINT_BUFFER_WIDTH) { fprintf(f, "simple-opt internal err: usage print buffer too small\n"); return; } -- cgit v1.2.3