diff options
author | katherine <shmibs@shmibbles.me> | 2018-03-19 13:48:25 -0700 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2018-03-19 13:48:25 -0700 |
commit | 9231b162706b991fd39f452ab4e9e728c8a933b7 (patch) | |
tree | 6d08def5d95604aad462b0dcceed127b4f17aa24 /doc | |
parent | 2323f6ef4510f7c7017b35f908876c19c696f330 (diff) | |
download | simple-opt-9231b162706b991fd39f452ab4e9e728c8a933b7.tar.gz |
add double, char, and string_set
also clean up integer parsing and usage printing
Diffstat (limited to 'doc')
-rw-r--r-- | doc/example.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/doc/example.c b/doc/example.c index fee399b..08a9d7f 100644 --- a/doc/example.c +++ b/doc/example.c @@ -2,20 +2,32 @@ int main(int argc, char **argv) { + const char *set[] = { "choice_a", "choice_b", NULL }; + /* array containing all options and their types / attributes */ struct simple_opt options[] = { { SIMPLE_OPT_FLAG, 'h', "help", false, "print this help message and exit" }, + { SIMPLE_OPT_BOOL, 'b', "bool", false, + "(optionally) takes a boolean arg!" }, { SIMPLE_OPT_INT, '\0', "int", true, - "this thing needs an integer!" }, + "requires an integer. has no short_name!" }, { SIMPLE_OPT_UNSIGNED, 'u', "uns", true, "this one has a custom_arg_string. normally it would say" " \"UNSIGNED\" rather than \"NON-NEG-INT\"", "NON-NEG-INT" }, + { SIMPLE_OPT_DOUBLE, 'd', "double", true, + "a floating point number" }, { SIMPLE_OPT_STRING, 's', NULL, true, - "this one doesn't have a long opt version" }, - { SIMPLE_OPT_BOOL, 'b', "bool", false, - "(optionally) takes a boolean arg!" }, + "this one doesn't have a long_name version" }, + { SIMPLE_OPT_STRING_SET, '\0', "set-choice", true, + "a choice of one string from a NULL-terminated array." + " note that, in order to maintain redability, the description" + " indentation does not accomodate the full width of an" + " overly-wide custom_arg_string like (choice_a|choice_b)", + "(choice_a|choice_b)", set }, + { SIMPLE_OPT_CHAR, 'c', "char", false, + "(optionally) takes a character argument" }, { SIMPLE_OPT_END }, }; @@ -82,22 +94,34 @@ int main(int argc, char **argv) if (options[i].arg_is_stored) { switch (options[i].type) { + case SIMPLE_OPT_BOOL: + printf(", val: %s", options[i].val_bool ? "true" : "false"); + break; + case SIMPLE_OPT_INT: - printf(", val: %d", options[i].val_int); + printf(", val: %ld", options[i].val_int); break; case SIMPLE_OPT_UNSIGNED: - printf(", val: %u", options[i].val_unsigned); + printf(", val: %lu", options[i].val_unsigned); + break; + + case SIMPLE_OPT_DOUBLE: + printf(", val: %lf", options[i].val_double); + break; + + case SIMPLE_OPT_CHAR: + printf(", val: %c", options[i].val_char); break; case SIMPLE_OPT_STRING: printf(", val: %s", options[i].val_string); break; - case SIMPLE_OPT_BOOL: - printf(", val: %s", options[i].val_bool ? "true" : "false"); + case SIMPLE_OPT_STRING_SET: + printf(", val: %s", set[options[i].val_string_set_idx]); break; - + default: break; } |