diff --git a/cmd/camera.h b/cmd/camera.h index 7715b21..bbdb0fe 100644 --- a/cmd/camera.h +++ b/cmd/camera.h @@ -15,6 +15,8 @@ typedef struct camera_options_s { bool allow_dma; float high_res_factor; float low_res_factor; + + char options[4096]; } camera_options_t; typedef struct camera_s { diff --git a/cmd/main.c b/cmd/main.c index db98d5a..73cab67 100644 --- a/cmd/main.c +++ b/cmd/main.c @@ -65,11 +65,15 @@ option_t all_options[] = { DEFINE_OPTION_DEFAULT(camera, allow_dma, bool, "1"), DEFINE_OPTION(camera, high_res_factor, float), DEFINE_OPTION(camera, low_res_factor, float), + DEFINE_OPTION_PTR(camera, options, list), + DEFINE_OPTION(http, port, uint), DEFINE_OPTION(http, maxcons, uint), + DEFINE_OPTION_DEFAULT(log, debug, bool, "1"), DEFINE_OPTION_DEFAULT(log, verbose, bool, "1"), - DEFINE_OPTION_PTR(log, filter, string), + DEFINE_OPTION_PTR(log, filter, list), + {} }; diff --git a/opts/opts.c b/opts/opts.c index 6cb806c..7a811f0 100644 --- a/opts/opts.c +++ b/opts/opts.c @@ -5,13 +5,32 @@ #include #include +static int option_handler_print(option_t *option, char *data); +static int option_handler_set(option_t *option, char *data); + +#define OPTION_VALUE_LIST_SEP "," + static void print_help(option_t *options) { for (int i = 0; options[i].name; i++) { option_t *option = &options[i]; + printf("%40s\t", option->name); - if (option->value_string) { + if (option->value_list) { + char *string = option->value_list; + char *token; + int tokens = 0; + + while (token = strsep(&string, OPTION_VALUE_LIST_SEP)) { + if (tokens++ > 0) + printf("\n%40s\t", ""); + printf("%s", token); + } + + if (!tokens) + printf("(none)"); + } else if (option->value_string) { printf(option->format, option->value_string); } else { if (option->value_mapping) { @@ -60,7 +79,16 @@ static int parse_opt(option_t *options, const char *key) } int ret = 0; - if (option->value_string) { + if (option->value_list) { + char *ptr = option->value_list; + + if (*ptr) { + strcat(ptr, OPTION_VALUE_LIST_SEP); + ptr += strlen(ptr); + } + + ret = sscanf(value, option->format, ptr); + } else if (option->value_string) { ret = sscanf(value, option->format, option->value_string); } else if (option->value_mapping) { for (int j = 0; option->value_mapping[j].name; j++) { diff --git a/opts/opts.h b/opts/opts.h index db6b33e..70887c0 100644 --- a/opts/opts.h +++ b/opts/opts.h @@ -10,6 +10,7 @@ typedef struct option_value_s { typedef struct options_s { const char *name; char *value_string; + char *value_list; union { unsigned *value; unsigned *value_uint; @@ -35,6 +36,7 @@ typedef struct options_s { #define OPTION_FORMAT_bool "%d" #define OPTION_FORMAT_float "%f" #define OPTION_FORMAT_string "%s" +#define OPTION_FORMAT_list "%s" #define DEFINE_OPTION(_section, _name, _type) \ { \