From 92cf944395d3e7dbf33ed795785886b78963bce3 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 29 Mar 2022 21:42:07 -0500 Subject: [PATCH] Update: Move the program data into the main. Move parameter initialization and deallocation for FLL program data into main.c. --- level_3/status_code/c/common.c | 7 ------- level_3/status_code/c/common.h | 19 ------------------- level_3/status_code/c/main.c | 6 ++++++ level_3/status_code/c/status_code.c | 30 ++---------------------------- 4 files changed, 8 insertions(+), 54 deletions(-) diff --git a/level_3/status_code/c/common.c b/level_3/status_code/c/common.c index 20208f3..e2ef3f3 100644 --- a/level_3/status_code/c/common.c +++ b/level_3/status_code/c/common.c @@ -29,13 +29,6 @@ extern "C" { const f_string_static_t status_code_long_number_s = macro_f_string_static_t_initialize(STATUS_CODE_long_number_s, 0, STATUS_CODE_long_number_s_length); #endif // _di_status_code_parameters_ -#ifndef _di_status_code_main_delete_ - f_status_t status_code_main_delete(fll_program_data_t * const main) { - - return fll_program_data_delete(main); - } -#endif // _di_status_code_main_delete_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/status_code/c/common.h b/level_3/status_code/c/common.h index 1898af5..0baba81 100644 --- a/level_3/status_code/c/common.h +++ b/level_3/status_code/c/common.h @@ -147,25 +147,6 @@ extern "C" { #define status_code_total_parameters_d 13 #endif // _di_status_code_parameters_ -/** - * Deallocate main. - * - * Be sure to call this after executing status_code_main(). - * - * @param main - * The main program data. - * - * @return - * F_none on success. - * - * Status codes (with error bit) are returned on any problem. - * - * @see status_code_main() - */ -#ifndef _di_status_code_main_delete_ - extern f_status_t status_code_main_delete(fll_program_data_t * const main); -#endif // _di_status_code_main_delete_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index bc349b7..38bddf5 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -5,6 +5,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); fll_program_data_t data = fll_program_data_t_initialize; + f_console_parameter_t parameters[] = status_code_console_parameter_t_initialize; + data.parameters.array = parameters; + data.parameters.used = status_code_total_parameters_d; + if (f_pipe_input_exists()) { data.process_pipe = F_true; } @@ -15,6 +19,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { fll_program_standard_setdown(&data.signal); + fll_program_data_delete(&data); + if (F_status_is_error(status)) return 1; return 0; diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 2290242..4648d95 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -43,10 +43,6 @@ extern "C" { f_status_t status = F_none; - f_console_parameter_t parameters[] = status_code_console_parameter_t_initialize; - main->parameters.array = parameters; - main->parameters.used = status_code_total_parameters_d; - { f_console_parameter_id_t ids[3] = { status_code_parameter_no_color_e, status_code_parameter_light_e, status_code_parameter_dark_e }; const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 3); @@ -73,11 +69,7 @@ extern "C" { fll_program_parameter_process_empty(&main->context, sets); } - if (F_status_is_error(status)) { - status_code_main_delete(main); - - return F_status_set_error(status); - } + if (F_status_is_error(status)) return F_status_set_error(status); } // Identify priority of verbosity related parameters. @@ -88,11 +80,7 @@ extern "C" { status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); - if (F_status_is_error(status)) { - status_code_main_delete(main); - - return status; - } + if (F_status_is_error(status)) return status; if (choice == status_code_parameter_verbosity_quiet_e) { main->output.verbosity = f_console_verbosity_quiet_e; @@ -123,16 +111,12 @@ extern "C" { if (main->parameters.array[status_code_parameter_help_e].result == f_console_result_found_e) { status_code_print_help(main->output.to, main->context); - status_code_main_delete(main); - return F_none; } if (main->parameters.array[status_code_parameter_version_e].result == f_console_result_found_e) { fll_program_print_version(main->output.to, status_code_program_version_s); - status_code_main_delete(main); - return F_none; } @@ -148,8 +132,6 @@ extern "C" { funlockfile(main->error.to.stream); - status_code_main_delete(main); - return F_status_set_error(status); } @@ -164,8 +146,6 @@ extern "C" { funlockfile(main->error.to.stream); - status_code_main_delete(main); - return F_status_set_error(status); } } @@ -180,16 +160,12 @@ extern "C" { funlockfile(main->error.to.stream); - status_code_main_delete(main); - return F_status_set_error(status); } if (main->parameters.remaining.used == 0 && !main->process_pipe) { fll_print_format("%[You failed to specify a status code.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s); - status_code_main_delete(main); - return F_status_set_error(F_parameter); } @@ -294,8 +270,6 @@ extern "C" { } } - status_code_main_delete(main); - return status; } #endif // _di_status_code_main_ -- 1.8.3.1