From: Kevin Day Date: Tue, 9 Apr 2024 01:37:34 +0000 (-0500) Subject: Update: Better utilize functionality of C for extern types. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=1e7890184b73a194f632df8bfd17283d1b7f5a78;p=controller Update: Better utilize functionality of C for extern types. I am creating a string pointer and passing it through a structure to dynamically pass different progam names for each program. This is fine for many languages that are not C/C++. For C/C++, this can be done in a cleaner and more efficient way. The extern type can be declared in the main project and use that. Then, the final binary is the only case where the actual implementation of the extern variable must exist. That means each program (init and controller) will define their own program name string. No extra memory in the structure needs to be used. This is cleaner, simpler, and more maintainable. --- diff --git a/sources/c/controller/main.c b/sources/c/controller/main.c index 2d413c6..4483d44 100644 --- a/sources/c/controller/main.c +++ b/sources/c/controller/main.c @@ -15,9 +15,6 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.program_name = &controller_controller_program_name_s; - data.setting.program_name_long = &controller_controller_program_name_long_s; - f_console_parameter_t parameters[] = controller_console_parameter_t_initialize; data.program.parameters.array = parameters; diff --git a/sources/c/controller/string.c b/sources/c/controller/string.c index c7b2c2b..3bad69b 100644 --- a/sources/c/controller/string.c +++ b/sources/c/controller/string.c @@ -4,10 +4,10 @@ extern "C" { #endif -#ifndef _di_controller_controller_program_name_s_ - const f_string_static_t controller_controller_program_name_s = macro_f_string_static_t_initialize_1(CONTROLLER_controller_program_name_s, 0, CONTROLLER_controller_program_name_s_length); - const f_string_static_t controller_controller_program_name_long_s = macro_f_string_static_t_initialize_1(CONTROLLER_controller_program_name_long_s, 0, CONTROLLER_controller_program_name_long_s_length); -#endif // _di_controller_controller_program_name_s_ +#ifndef _di_controller_program_name_s_ + const f_string_static_t controller_program_name_s = macro_f_string_static_t_initialize_1(CONTROLLER_program_name_s, 0, CONTROLLER_program_name_s_length); + const f_string_static_t controller_program_name_long_s = macro_f_string_static_t_initialize_1(CONTROLLER_program_name_long_s, 0, CONTROLLER_program_name_long_s_length); +#endif // _di_controller_program_name_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/controller/string.h b/sources/c/controller/string.h index ab36bb1..2f7ed97 100644 --- a/sources/c/controller/string.h +++ b/sources/c/controller/string.h @@ -19,16 +19,13 @@ extern "C" { /** * The program name. */ -#ifndef _di_controller_controller_program_name_s_ - #define CONTROLLER_controller_program_name_s "controller" - #define CONTROLLER_controller_program_name_long_s "Controller" +#ifndef _di_controller_program_name_s_ + #define CONTROLLER_program_name_s "controller" + #define CONTROLLER_program_name_long_s "Controller" - #define CONTROLLER_controller_program_name_s_length 10 - #define CONTROLLER_controller_program_name_long_s_length 10 - - extern const f_string_static_t controller_controller_program_name_s; - extern const f_string_static_t controller_controller_program_name_long_s; -#endif // _di_controller_controller_program_name_s_ + #define CONTROLLER_program_name_s_length 10 + #define CONTROLLER_program_name_long_s_length 10 +#endif // _di_controller_program_name_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/init/main.c b/sources/c/init/main.c index fc670d3..1aff3da 100644 --- a/sources/c/init/main.c +++ b/sources/c/init/main.c @@ -15,9 +15,6 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.program_name = &controller_init_program_name_s; - data.setting.program_name_long = &controller_init_program_name_long_s; - f_console_parameter_t parameters[] = controller_console_parameter_t_initialize; data.program.parameters.array = parameters; diff --git a/sources/c/init/string.c b/sources/c/init/string.c index ff1fd9e..2884a04 100644 --- a/sources/c/init/string.c +++ b/sources/c/init/string.c @@ -4,10 +4,10 @@ extern "C" { #endif -#ifndef _di_controller_init_program_name_s_ - const f_string_static_t controller_init_program_name_s = macro_f_string_static_t_initialize_1(CONTROLLER_init_program_name_s, 0, CONTROLLER_init_program_name_s_length); - const f_string_static_t controller_init_program_name_long_s = macro_f_string_static_t_initialize_1(CONTROLLER_init_program_name_long_s, 0, CONTROLLER_init_program_name_long_s_length); -#endif // _di_controller_init_program_name_s_ +#ifndef _di_controller_program_name_s_ + const f_string_static_t controller_program_name_s = macro_f_string_static_t_initialize_1(CONTROLLER_program_name_s, 0, CONTROLLER_program_name_s_length); + const f_string_static_t controller_program_name_long_s = macro_f_string_static_t_initialize_1(CONTROLLER_program_name_long_s, 0, CONTROLLER_program_name_long_s_length); +#endif // _di_controller_program_name_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/init/string.h b/sources/c/init/string.h index 5f8e82d..c9dd068 100644 --- a/sources/c/init/string.h +++ b/sources/c/init/string.h @@ -19,16 +19,13 @@ extern "C" { /** * The program name. */ -#ifndef _di_controller_init_program_name_s_ - #define CONTROLLER_init_program_name_s "init" - #define CONTROLLER_init_program_name_long_s "Init" +#ifndef _di_controller_program_name_s_ + #define CONTROLLER_program_name_s "init" + #define CONTROLLER_program_name_long_s "Init" - #define CONTROLLER_init_program_name_s_length 4 - #define CONTROLLER_init_program_name_long_s_length 4 - - extern const f_string_static_t controller_init_program_name_s; - extern const f_string_static_t controller_init_program_name_long_s; -#endif // _di_controller_init_program_name_s_ + #define CONTROLLER_program_name_s_length 4 + #define CONTROLLER_program_name_long_s_length 4 +#endif // _di_controller_program_name_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/string.h b/sources/c/main/common/string.h index 5d2ea63..406c7b5 100644 --- a/sources/c/main/common/string.h +++ b/sources/c/main/common/string.h @@ -46,6 +46,16 @@ extern "C" { #endif // _di_controller_program_version_s_ /** + * The program name. + * + * The implementation for this is defined within the individual programs. + */ +#ifndef _di_controller_program_name_s_ + extern const f_string_static_t controller_program_name_s; + extern const f_string_static_t controller_program_name_long_s; +#endif // _di_controller_program_name_s_ + +/** * The main program parameters. */ #ifndef _di_controller_parameter_s_ diff --git a/sources/c/main/common/type.h b/sources/c/main/common/type.h index 5f59d74..a3d3c4b 100644 --- a/sources/c/main/common/type.h +++ b/sources/c/main/common/type.h @@ -42,9 +42,6 @@ extern "C" { * * status_signal: A status used eclusively by the threaded signal handler. * state: The state data used when processing the FSS data. - * - * program_name: The short program name. - * program_name_long: The long program name. */ #ifndef _di_controller_setting_t_ typedef struct { @@ -52,9 +49,6 @@ extern "C" { f_status_t status_signal; f_state_t state; - - const f_string_static_t *program_name; - const f_string_static_t *program_name_long; } controller_setting_t; #define controller_setting_t_initialize \ @@ -62,8 +56,6 @@ extern "C" { controller_main_flag_none_e, \ F_okay, \ f_state_t_initialize, \ - 0, \ - 0, \ } #endif // _di_controller_setting_t_ diff --git a/sources/c/main/print/message.c b/sources/c/main/print/message.c index 42f1e77..6a3ee16 100644 --- a/sources/c/main/print/message.c +++ b/sources/c/main/print/message.c @@ -13,7 +13,7 @@ extern "C" { f_file_stream_lock(print->to); - fll_program_print_help_header(print, *main->setting.program_name_long, controller_program_version_s); + fll_program_print_help_header(print, controller_program_name_long_s, controller_program_version_s); fll_program_print_help_option_standard(print); @@ -32,7 +32,7 @@ extern "C" { f_print_dynamic_raw(f_string_eol_s, print->to); - fll_program_print_help_usage(print, *main->setting.program_name, f_string_empty_s); + fll_program_print_help_usage(print, controller_program_name_s, f_string_empty_s); fl_print_format("%r When both the %[%r%r%] parameter and the", print->to, f_string_eol_s, print->set->notable, f_console_symbol_long_normal_s, controller_long_simulate_s, print->set->notable); fl_print_format(" %[%r%r%] parameter are specified, then additional information on each would be executed rule is printed but no simulation is performed.%r%r", print->to, print->set->notable, f_console_symbol_long_normal_s, controller_long_validate_s, print->set->notable, f_string_eol_s, f_string_eol_s);