From 5e465ac8bf961dcce7329237fb15c14abe9fa300 Mon Sep 17 00:00:00 2001 From: "Julian M. Kunkel" Date: Tue, 21 Jul 2020 13:54:50 +0100 Subject: [PATCH] Option: merge function to supported AIORI module reuse. --- src/option.c | 17 +++++++++++++++++ src/option.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/option.c b/src/option.c index 618360f..c44dc9b 100644 --- a/src/option.c +++ b/src/option.c @@ -7,6 +7,23 @@ #include + +/* merge two option lists and return the total size */ +option_help * option_merge(option_help * a, option_help * b){ + int count_a = 0; + for(option_help * i = a; i->type != 0; i++){ + count_a++; + } + int count = count_a + 1; // LAST_OPTION is one + for(option_help * i = b; i->type != 0; i++){ + count++; + } + option_help * h = malloc(sizeof(option_help) * count); + memcpy(h, a, sizeof(option_help) * count_a); + memcpy(h + count_a, b, sizeof(option_help) * (count - count_a)); + return h; +} + /* * Takes a string of the form 64, 8m, 128k, 4g, etc. and converts to bytes. */ diff --git a/src/option.h b/src/option.h index 5ca305f..0afa519 100644 --- a/src/option.h +++ b/src/option.h @@ -43,6 +43,7 @@ void option_print_current(option_help * args); //@return the number of parsed arguments int option_parse(int argc, char ** argv, options_all_t * args); int option_parse_str(char*val, options_all_t * opt_all); +option_help * option_merge(option_help * a, option_help * b); /* Parse a single line */ int option_parse_key_value(char * key, char * value, options_all_t * opt_all);