diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | doc/interface.md | 9 | ||||
-rw-r--r-- | simple-opt.h | 11 |
3 files changed, 13 insertions, 9 deletions
@@ -5,7 +5,7 @@ simple-opt simple, flexible, and portable version of command line option parsing for programs written in C. it is designed to be (hopefully) intuitive while also being (hopefully) more powerful than traditional getopt or similar. it has no -dependencies outside the standard library and is C99 compatible. +dependencies outside the standard library. what follows is a simple example usage. refer to [interface.md](doc/interface.md) for more detail. diff --git a/doc/interface.md b/doc/interface.md index 86937f8..da07986 100644 --- a/doc/interface.md +++ b/doc/interface.md @@ -53,9 +53,12 @@ the fields which are set by `simple_opt_parse` are: union { bool val_bool; - int val_int; - unsigned val_unsigned; - char val_string[SIMPLE_OPT_ARG_MAX_WIDTH]; + long val_int; + unsigned long val_unsigned; + double val_double; + char val_char; + char val_string[SIMPLE_OPT_OPT_ARG_MAX_WIDTH]; + int val_string_set_idx; }; ``` diff --git a/simple-opt.h b/simple-opt.h index ada6233..736d8e0 100644 --- a/simple-opt.h +++ b/simple-opt.h @@ -5,6 +5,7 @@ #include <stdbool.h> #include <string.h> #include <stdio.h> +#include <stdint.h> #include <ctype.h> #include <errno.h> @@ -105,7 +106,7 @@ static void simple_opt_print_usage(FILE *f, unsigned width, char *usage_name, static bool sub_simple_opt_parse(struct simple_opt *o, char *s) { - int i, j; + unsigned i, j; char *str, *cp; bool match; @@ -410,11 +411,11 @@ opt_copy_and_return: goto end; } -static int sub_simple_opt_wrap_print(FILE *f, unsigned width, int col, - int line_start, const char *s) +static int sub_simple_opt_wrap_print(FILE *f, unsigned width, unsigned col, + unsigned line_start, const char *s) { bool add_newline = false, first_word = true, first_line = true;; - int i, j, word_start, word_end; + unsigned i, j, word_start, word_end; if (width != 0 && line_start >= width) { line_start = 0; @@ -510,7 +511,7 @@ static void simple_opt_print_usage(FILE *f, unsigned width, char *usage_name, char *usage_options, char *usage_summary, struct simple_opt *options) { char print_buffer[SIMPLE_OPT_USAGE_PRINT_BUFFER_WIDTH]; - int i, j, col, print_buffer_offset, desc_line_start; + unsigned i, j, col, print_buffer_offset, desc_line_start; /* calculate the required line_start for printing descriptions (leaving * space for the widest existing long-option) */ |