From 000a35996e0cc875caf5533098710255670c4ffc Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 8 Sep 2019 17:44:10 -0500 Subject: [PATCH] Cleanup: Utilize f_console_parameter_ids to simplify parameters for fll_program_process_parameters() Althought not ideal, the ids must be in an explicit order of no_color, light, and dark. This has been added to the functional documentation. --- level_2/fll_program/c/program.c | 13 ++++--------- level_2/fll_program/c/program.h | 11 ++++------- level_3/bit_dump/c/bit_dump.c | 5 ++++- level_3/firewall/c/firewall.c | 5 ++++- level_3/fss_basic_list_read/c/fss_basic_list_read.c | 5 ++++- level_3/fss_basic_list_write/c/fss_basic_list_write.c | 5 ++++- level_3/fss_basic_read/c/fss_basic_read.c | 5 ++++- level_3/fss_basic_write/c/fss_basic_write.c | 5 ++++- level_3/fss_extended_read/c/fss_extended_read.c | 5 ++++- level_3/fss_extended_write/c/fss_extended_write.c | 5 ++++- level_3/fss_status_code/c/fss_status_code.c | 5 ++++- level_3/init/c/init.c | 5 ++++- level_3/status_code/c/status_code.c | 5 ++++- 13 files changed, 52 insertions(+), 27 deletions(-) diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 175af26..ceca97b 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -79,23 +79,18 @@ extern "C" { #endif // _di_fll_program_print_version_ #ifndef _di_fll_program_process_parameters_ - f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context) { + f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_console_parameter_ids choices, f_string_lengths *remaining, fl_color_context *context) { f_status status = f_none; f_status allocation_status = f_none; status = fl_console_parameter_process(arguments, parameters, remaining); - f_console_parameter_ids choices = f_console_parameter_ids_initialize; - f_console_parameter_id decision = parameter_dark; - f_console_parameter_id ids[3] = { parameter_no_color, parameter_light, parameter_dark}; - - choices.id = ids; - choices.used = 3; + f_console_parameter_id decision = choices.id[2]; fl_console_parameter_prioritize(parameters, choices, &decision); // load colors unless told not to. - if (decision != parameter_no_color) { + if (decision != choices.id[0]) { fl_macro_color_context_new(allocation_status, (*context)); if (f_status_is_error(allocation_status)) { @@ -103,7 +98,7 @@ extern "C" { return allocation_status; } - fl_color_load_context(context, decision == parameter_light); + fl_color_load_context(context, decision == choices.id[1]); } if (f_status_is_error(status)) { diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 923aa7c..da45dd1 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -124,12 +124,9 @@ extern "C" { * The parameters passed to the process. * @param parameters * The console parameters to look for. - * @param parameter_no_color - * The parameter in the parameters array representing the no-color option. - * @param parameter_light - * The parameter in the parameters array representing the light-color option. - * @param parameter_dark - * The parameter in the parameters array representing the dark-color option. + * @param choices + * A set of the color options: no-color option, light-color option, dark-color option. + * This must have its used size set to 3 and the ids are expected to be in this order: no_color, light, and dark. * @param remaining * A list of remaining parameters not associated with anything. * @param context @@ -142,7 +139,7 @@ extern "C" { * f_reallocation_error (with error bit) on memory reallocation error. */ #ifndef _di_fll_program_process_parameters_ - extern f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context); + extern f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameters parameters, const f_console_parameter_ids choices, f_string_lengths *remaining, fl_color_context *context); #endif // _di_fll_program_process_parameters_ #ifdef __cplusplus diff --git a/level_3/bit_dump/c/bit_dump.c b/level_3/bit_dump/c/bit_dump.c index c3362ae..5cedaa9 100644 --- a/level_3/bit_dump/c/bit_dump.c +++ b/level_3/bit_dump/c/bit_dump.c @@ -44,7 +44,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, bit_dump_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 7d9fa5b..4c4dc65 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -60,7 +60,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, firewall_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index 26e75f3..5e44f23 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -37,7 +37,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_basic_list_read_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index 4cca4dc..99e790d 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -32,7 +32,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_basic_list_write_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 611467a..fe7b1f7 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -35,7 +35,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_basic_read_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index 3c28a6d..20d368f 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -32,7 +32,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_basic_write_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 6ce66f2..87aeeb6 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -36,7 +36,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_extended_read_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index fcf36ed..b343982 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -33,7 +33,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_extended_write_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c index 796e04c..43e7490 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -33,7 +33,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, fss_status_code_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/init/c/init.c b/level_3/init/c/init.c index b841893..b161905 100644 --- a/level_3/init/c/init.c +++ b/level_3/init/c/init.c @@ -54,7 +54,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, init_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, init_parameter_no_color, init_parameter_light, init_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { init_parameter_no_color, init_parameter_light, init_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 634cba0..8e8fc70 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -33,7 +33,10 @@ extern "C" { { f_console_parameters parameters = { data->parameters, status_code_total_parameters }; - status = fll_program_process_parameters(arguments, parameters, status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark, &data->remaining, &data->context); + f_console_parameter_id ids[3] = { status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark }; + f_console_parameter_ids choices = { ids, 3 }; + + status = fll_program_process_parameters(arguments, parameters, choices, &data->remaining, &data->context); } if (f_status_is_error(status)) { -- 1.8.3.1