From: Kevin Day Date: Sat, 1 May 2021 01:03:09 +0000 (-0500) Subject: Feature: Provide fll_program_parameter_process_empty(). X-Git-Tag: 0.5.4~78 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=3cfa9cf56765eb363ec923004d018f15cd78969f;p=fll Feature: Provide fll_program_parameter_process_empty(). This should further simplify the standard color processing code for when color codes are replaced with empty strings. --- diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index e7e102e..2b488b8 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -99,6 +99,7 @@ extern "C" { #ifndef _di_fll_program_parameter_process_ f_status_t fll_program_parameter_process(const f_console_arguments_t arguments, f_console_parameters_t parameters, const f_console_parameter_ids_t choices, const bool right, f_array_lengths_t *remaining, f_color_context_t *context) { + f_status_t status = F_none; status = f_console_parameter_process(arguments, parameters, remaining); @@ -132,6 +133,26 @@ extern "C" { } #endif // _di_fll_program_parameter_process_ +#ifndef _di_fll_program_parameter_process_empty_ + void fll_program_parameter_process_empty(f_color_context_t *context, f_color_set_t *sets[]) { + + context->set.warning = f_color_set_empty_s; + context->set.error = f_color_set_empty_s; + context->set.title = f_color_set_empty_s; + context->set.notable = f_color_set_empty_s; + context->set.important = f_color_set_empty_s; + context->set.standout = f_color_set_empty_s; + context->set.normal = f_color_set_empty_s; + context->set.normal_reset = f_color_set_empty_s; + + if (sets) { + for (f_array_length_t i = 0; sets[i]; ++i) { + *sets[i] = f_color_set_empty_s; + } + } + } +#endif // _di_fll_program_parameter_process_empty_ + #ifndef _di_fll_program_parameter_additional_append_ f_status_t fll_program_parameter_additional_append(const f_string_t *argv, const f_array_lengths_t values, f_string_dynamics_t *destination) { #ifndef _di_level_2_parameter_checking_ diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 14b0a27..c43da39 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -207,6 +207,21 @@ extern "C" { #endif // _di_fll_program_parameter_process_ /** + * Set the provided context to empty along with all additional color sets. + * + * This will allow for safe usage of the color context and color sets to be safely processed when colors are disabled. + * + * @param context + * The primary color context to assign. + * @param sets + * (optional) A NULL terminated array representing additional sets to assign as empty. + * Set to NULL to not use. + */ +#ifndef _di_fll_program_parameter_process_empty_ + extern void fll_program_parameter_process_empty(f_color_context_t *context, f_color_set_t *sets[]); +#endif // _di_fll_program_parameter_process_empty_ + +/** * Allocate new strings from all of the provided locations. * * These new strings are appended onto the destination. diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index cc618d3..47e8293 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -94,17 +94,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/control/c/control.c b/level_3/control/c/control.c index 0d1d11a..7c4ab1b 100644 --- a/level_3/control/c/control.c +++ b/level_3/control/c/control.c @@ -47,20 +47,9 @@ extern "C" { data->warning.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; - - data->warning.context = f_color_set_empty_s; - data->warning.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, &data->warning.context, &data->warning.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 8b59328..56970da 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -69,20 +69,9 @@ extern "C" { data->warning.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; - - data->warning.context = f_color_set_empty_s; - data->warning.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, &data->warning.context, &data->warning.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index 66ccaab..a92e16a 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -117,17 +117,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index b7390b5..d704f15 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -73,17 +73,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 9322ddb..2bcd2df 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 @@ -176,17 +176,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 cd96020..af0ee24 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 @@ -103,17 +103,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 3dfebc3..3c5b107 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -176,17 +176,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 476d731..4122211 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -101,17 +101,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c index 40956f2..03c2152 100644 --- a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c +++ b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c @@ -176,17 +176,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c index 61c7a07..0ae1045 100644 --- a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c +++ b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c @@ -109,17 +109,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index 25a5b26..8cf3136 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -176,17 +176,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/fss_extended_list_write/c/fss_extended_list_write.c b/level_3/fss_extended_list_write/c/fss_extended_list_write.c index d7f2f80..e5bdd09 100644 --- a/level_3/fss_extended_list_write/c/fss_extended_list_write.c +++ b/level_3/fss_extended_list_write/c/fss_extended_list_write.c @@ -109,17 +109,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 0f6d9fa..761ae1b 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -176,17 +176,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 e8555a9..9fa7856 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -101,17 +101,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 e5138ec..62e956f 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -51,17 +51,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/iki_read/c/iki_read.c b/level_3/iki_read/c/iki_read.c index 895f872..d2d92f4 100644 --- a/level_3/iki_read/c/iki_read.c +++ b/level_3/iki_read/c/iki_read.c @@ -106,17 +106,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) { diff --git a/level_3/iki_write/c/iki_write.c b/level_3/iki_write/c/iki_write.c index 94a128a..a353502 100644 --- a/level_3/iki_write/c/iki_write.c +++ b/level_3/iki_write/c/iki_write.c @@ -69,17 +69,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } 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 59daaea..7f641ea 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -51,17 +51,9 @@ extern "C" { data->error.notable = data->context.set.notable; } else { - data->context.set.warning = f_color_set_empty_s; - data->context.set.error = f_color_set_empty_s; - data->context.set.title = f_color_set_empty_s; - data->context.set.notable = f_color_set_empty_s; - data->context.set.important = f_color_set_empty_s; - data->context.set.standout = f_color_set_empty_s; - data->context.set.normal = f_color_set_empty_s; - data->context.set.normal_reset = f_color_set_empty_s; - - data->error.context = f_color_set_empty_s; - data->error.notable = f_color_set_empty_s; + f_color_set_t *sets[] = { &data->error.context, &data->error.notable, 0 }; + + fll_program_parameter_process_empty(&data->context, sets); } if (F_status_is_error(status)) {