Option: merge function to supported AIORI module reuse.

master
Julian M. Kunkel 2020-07-21 13:54:50 +01:00
parent 4258e14c11
commit 5e465ac8bf
2 changed files with 18 additions and 0 deletions

View File

@ -7,6 +7,23 @@
#include <option.h>
/* 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.
*/

View File

@ -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);