From 05c24138c0ad8f15a557274f21956fed206fec23 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 19 Nov 2022 17:42:24 -0600 Subject: [PATCH] Bugfix: The level_0 console should use private functions. The level_0 f_console_identify function should not be directly called by another function in this project. Create a private function and call that function. This is the standard practice for this project This improves hackability. --- build/level_0/settings | 4 +-- build/monolithic/settings | 4 +-- build/stand_alone/fake.settings | 2 +- build/stand_alone/utf8.settings | 2 +- level_0/f_console/c/console.c | 45 ++------------------------ level_0/f_console/c/console.h | 2 +- level_0/f_console/c/private-console.c | 60 +++++++++++++++++++++++++++++++++++ level_0/f_console/c/private-console.h | 44 +++++++++++++++++++++++++ level_0/f_console/data/build/settings | 4 +-- 9 files changed, 116 insertions(+), 51 deletions(-) create mode 100644 level_0/f_console/c/private-console.c create mode 100644 level_0/f_console/c/private-console.h diff --git a/build/level_0/settings b/build/level_0/settings index c14518c..82abd52 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -22,7 +22,7 @@ build_libraries -lc -lcap build_sources_library account.c private-account.c build_sources_library capability.c build_sources_library color.c private-color.c color/common.c -build_sources_library console.c console/common.c +build_sources_library console.c console/common.c private-console.c build_sources_library control_group.c control_group/common.c build_sources_library conversion.c private-conversion.c conversion/common.c build_sources_library directory.c directory/common.c private-directory.c @@ -51,7 +51,7 @@ build_sources_library-level thread.c private-thread.c thread/attribute.c thread/ build_sources_headers account.h account/common.h build_sources_headers capability.h capability/common.h build_sources_headers color.h color/common.h -build_sources_headers console.h console/common.h +build_sources_headers console.h console/common.h private-console.h build_sources_headers control_group.h control_group/common.h build_sources_headers conversion.h conversion/common.h build_sources_headers directory.h directory/common.h directory/type.h diff --git a/build/monolithic/settings b/build/monolithic/settings index da7949e..4176f8f 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -22,7 +22,7 @@ build_libraries -lc -lcap build_sources_library level_0/account.c level_0/private-account.c build_sources_library level_0/capability.c build_sources_library level_0/color.c level_0/private-color.c level_0/color/common.c -build_sources_library level_0/console.c level_0/console/common.c +build_sources_library level_0/console.c level_0/console/common.c level_0/private-console.c build_sources_library level_0/control_group.c level_0/control_group/common.c build_sources_library level_0/conversion.c level_0/private-conversion.c level_0/conversion/common.c build_sources_library level_0/directory.c level_0/directory/common.c level_0/private-directory.c @@ -75,7 +75,7 @@ build_sources_library-monolithic level_0/thread.c level_0/private-thread.c level build_sources_headers level_0/account.h level_0/account/common.h build_sources_headers level_0/capability.h level_0/capability/common.h build_sources_headers level_0/color.h level_0/color/common.h -build_sources_headers level_0/console.h level_0/console/common.h +build_sources_headers level_0/console.h level_0/console/common.h level_0/private-console.h build_sources_headers level_0/control_group.h level_0/control_group/common.h build_sources_headers level_0/conversion.h level_0/conversion/common.h build_sources_headers level_0/directory.h level_0/directory/common.h level_0/directory/type.h diff --git a/build/stand_alone/fake.settings b/build/stand_alone/fake.settings index 2463aca..3e7aef8 100644 --- a/build/stand_alone/fake.settings +++ b/build/stand_alone/fake.settings @@ -26,7 +26,7 @@ build_libraries -lc -lcap build_sources_program fll/level_0/account.c fll/level_0/private-account.c build_sources_program fll/level_0/capability.c build_sources_program fll/level_0/color.c fll/level_0/private-color.c fll/level_0/color/common.c -build_sources_program fll/level_0/console.c fll/level_0/console/common.c +build_sources_program fll/level_0/console.c fll/level_0/console/common.c fll/level_0/private-console.c build_sources_program fll/level_0/control_group.c fll/level_0/control_group/common.c build_sources_program fll/level_0/conversion.c fll/level_0/private-conversion.c fll/level_0/conversion/common.c build_sources_program fll/level_0/directory.c fll/level_0/directory/common.c fll/level_0/private-directory.c diff --git a/build/stand_alone/utf8.settings b/build/stand_alone/utf8.settings index 02873ff..b2daeb5 100644 --- a/build/stand_alone/utf8.settings +++ b/build/stand_alone/utf8.settings @@ -24,7 +24,7 @@ build_language c build_libraries -lc -lcap build_sources_program fll/level_0/color.c fll/level_0/private-color.c fll/level_0/color/common.c -build_sources_program fll/level_0/console.c fll/level_0/console/common.c +build_sources_program fll/level_0/console.c fll/level_0/console/common.c fll/level_0/private-console.c build_sources_program fll/level_0/conversion.c fll/level_0/private-conversion.c fll/level_0/conversion/common.c build_sources_program fll/level_0/file.c fll/level_0/private-file.c fll/level_0/file/common.c build_sources_program fll/level_0/memory.c fll/level_0/private-memory.c fll/level_0/memory/structure.c diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index dbaf73e..7c18b5c 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -1,4 +1,5 @@ #include "console.h" +#include "private-console.h" #ifdef __cplusplus extern "C" { @@ -69,47 +70,7 @@ extern "C" { if (!result) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_f - if (!input) { - *result = f_console_none_e; - - return F_data_not; - } - - const f_array_length_t length = strnlen(input, 3); - - if (!length) { - *result = f_console_none_e; - - return F_data_not; - } - - if (input[0] == f_console_symbol_short_enable_s.string[0]) { - if (length > 1) { - if (input[1] == f_console_symbol_short_enable_s.string[0]) { - if (length > 2) { - *result = f_console_long_enable_e; - } - else *result = f_console_empty_long_enable_e; - } - else *result = f_console_short_enable_e; - } - else *result = f_console_empty_short_enable_e; - } - else if (input[0] == f_console_symbol_short_disable_s.string[0]) { - if (length > 1) { - if (input[1] == f_console_symbol_short_disable_s.string[0]) { - if (length > 2) { - *result = f_console_long_disable_e; - } - else *result = f_console_empty_long_disable_e; - } - else *result = f_console_short_disable_e; - } - else *result = f_console_empty_short_disable_e; - } - else *result = f_console_none_e; - - return F_none; + return private_f_console_identify(input, result); } #endif // _di_f_console_identify_ @@ -279,7 +240,7 @@ extern "C" { continue; } - f_console_identify(arguments.argv[location], &result); + private_f_console_identify(arguments.argv[location], &result); // Process the current parameter. if (result == f_console_short_enable_e || result == f_console_short_disable_e) { diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 4f6df8b..5a29d78 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -49,7 +49,7 @@ extern "C" { * @see f_string_maps_increase_by() */ #ifndef _di_f_console_environment_process_ - extern f_status_t f_console_environment_process(const f_console_arguments_t arguments, f_string_maps_t * const environment); + extern f_status_t f_console_environment_process(const f_console_arguments_t arguments, f_string_maps_t * const environment) F_attribute_visibility_internal_d; #endif // _di_f_console_environment_process_ /** diff --git a/level_0/f_console/c/private-console.c b/level_0/f_console/c/private-console.c new file mode 100644 index 0000000..fa421ab --- /dev/null +++ b/level_0/f_console/c/private-console.c @@ -0,0 +1,60 @@ +#include "console.h" +#include "private-console.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_) + f_status_t private_f_console_identify(const f_string_t input, f_console_id_t * const result) { + #ifndef _di_level_0_parameter_checking_ + if (!result) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_f + + if (!input) { + *result = f_console_none_e; + + return F_data_not; + } + + const f_array_length_t length = strnlen(input, 3); + + if (!length) { + *result = f_console_none_e; + + return F_data_not; + } + + if (input[0] == f_console_symbol_short_enable_s.string[0]) { + if (length > 1) { + if (input[1] == f_console_symbol_short_enable_s.string[0]) { + if (length > 2) { + *result = f_console_long_enable_e; + } + else *result = f_console_empty_long_enable_e; + } + else *result = f_console_short_enable_e; + } + else *result = f_console_empty_short_enable_e; + } + else if (input[0] == f_console_symbol_short_disable_s.string[0]) { + if (length > 1) { + if (input[1] == f_console_symbol_short_disable_s.string[0]) { + if (length > 2) { + *result = f_console_long_disable_e; + } + else *result = f_console_empty_long_disable_e; + } + else *result = f_console_short_disable_e; + } + else *result = f_console_empty_short_disable_e; + } + else *result = f_console_none_e; + + return F_none; + } +#endif // !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_console/c/private-console.h b/level_0/f_console/c/private-console.h new file mode 100644 index 0000000..c69b568 --- /dev/null +++ b/level_0/f_console/c/private-console.h @@ -0,0 +1,44 @@ +/** + * FLL - Level 0 + * + * Project: Console + * API Version: 0.6 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_console_h +#define _PRIVATE_F_console_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation of f_console_identify(). + * + * Intended to be shared to each of the different implementation variations. + * + * @param input + * The input parameter to process. + * @param result + * The flag with the console type bits determined by this function. + * + * @return + * F_none on success. + * F_data_not the input string is empty. + * + * + * @see f_console_identify() + * @see f_console_parameter_process() + */ +#if !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_) + extern f_status_t private_f_console_identify(const f_string_t input, f_console_id_t * const result) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_console_h diff --git a/level_0/f_console/data/build/settings b/level_0/f_console/data/build/settings index 7b78e9c..4182dbb 100644 --- a/level_0/f_console/data/build/settings +++ b/level_0/f_console/data/build/settings @@ -20,9 +20,9 @@ build_language c build_libraries -lc build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_utf -build_sources_library console.c console/common.c +build_sources_library console.c console/common.c private-console.c -build_sources_headers console.h console/common.h +build_sources_headers console.h console/common.h private-console.h build_script yes build_shared yes -- 1.8.3.1