From 97a2e16b931a1c0b2f4e41ff53502369e584e4ad Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 2 Dec 2024 23:29:45 -0600 Subject: [PATCH] Cleanup: Use parameters pointer and relocate output.to assignment. Relocate the `main->program.output.to` assignment to the top of the load settings functions. This should better allow for printing to be properly used, sooner. Setup the `parameters` as a pointer to `&main->program.parameters`. This should help made the code easier to read by reducing the size of the code needed. --- level_3/fake/c/main/common.c | 62 +++++++++++++++++++++------------------- level_3/fss_read/c/main/common.c | 8 +++--- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/level_3/fake/c/main/common.c b/level_3/fake/c/main/common.c index 4008f78..9220705 100644 --- a/level_3/fake/c/main/common.c +++ b/level_3/fake/c/main/common.c @@ -13,6 +13,8 @@ extern "C" { main->program.output.to.stream = F_type_output_d; main->program.output.to.flag = F_file_flag_create_d | F_file_flag_write_only_d | F_file_flag_append_d; + f_console_parameters_t * const parameters = &main->program.parameters; + { const uint16_t step_original = main->setting.state.step_small; fake_data_t data = fake_data_t_initialize; @@ -20,7 +22,7 @@ extern "C" { main->setting.state.step_small = 4; - f_console_parameter_process(arguments, &main->program.parameters, &main->setting.state, (void *) &data); + f_console_parameter_process(arguments, parameters, &main->setting.state, (void *) &data); main->setting.state.step_small = step_original; } @@ -47,19 +49,19 @@ extern "C" { return; } - if (main->program.parameters.array[f_console_standard_parameter_help_e].result & f_console_result_found_e) { + if (parameters->array[f_console_standard_parameter_help_e].result & f_console_result_found_e) { main->setting.flag |= fake_main_flag_help_d; return; } - if (main->program.parameters.array[f_console_standard_parameter_version_e].result & f_console_result_found_e) { + if (parameters->array[f_console_standard_parameter_version_e].result & f_console_result_found_e) { main->setting.flag |= fake_main_flag_version_d; return; } - if (main->program.parameters.array[f_console_standard_parameter_copyright_e].result & f_console_result_found_e) { + if (parameters->array[f_console_standard_parameter_copyright_e].result & f_console_result_found_e) { main->setting.flag |= fake_main_flag_copyright_d; return; @@ -99,9 +101,9 @@ extern "C" { for (; i < 3; ++i) { - if (main->program.parameters.array[enables[i]].result & f_console_result_found_e) { - if (main->program.parameters.array[disables[i]].result & f_console_result_found_e) { - if (main->program.parameters.array[enables[i]].location < main->program.parameters.array[disables[i]].location) { + if (parameters->array[enables[i]].result & f_console_result_found_e) { + if (parameters->array[disables[i]].result & f_console_result_found_e) { + if (parameters->array[enables[i]].location < parameters->array[disables[i]].location) { main->setting.flag &= ~flags[i]; } else { @@ -112,14 +114,14 @@ extern "C" { main->setting.flag |= flags[i]; } } - else if (main->program.parameters.array[disables[i]].result & f_console_result_found_e) { + else if (parameters->array[disables[i]].result & f_console_result_found_e) { main->setting.flag &= ~flags[i]; } } // for } { - const f_number_unsigned_t parameters[] = { + const f_number_unsigned_t params[] = { fake_parameter_build_e, fake_parameter_data_e, fake_parameter_documents_e, @@ -197,7 +199,7 @@ extern "C" { for (i = 0; i < 10; ++i) { - if ((main->program.parameters.array[parameters[i]].result & f_console_result_found_e) && !(main->program.parameters.array[parameters[i]].result & f_console_result_value_e)) { + if ((parameters->array[params[i]].result & f_console_result_found_e) && !(parameters->array[params[i]].result & f_console_result_value_e)) { main->setting.state.status = F_status_set_error(F_parameter); if (main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -207,14 +209,14 @@ extern "C" { return; } - if (main->program.parameters.array[parameters[i]].result & f_console_result_value_e) { - index = main->program.parameters.array[parameters[i]].values.array[main->program.parameters.array[parameters[i]].values.used - 1]; + if (parameters->array[params[i]].result & f_console_result_value_e) { + index = parameters->array[params[i]].values.array[parameters->array[params[i]].values.used - 1]; - if (main->program.parameters.arguments.array[index].used) { - if (parameters[i] == fake_parameter_process_e) { - for (j = 0; j < main->program.parameters.arguments.array[index].used; ++j) { + if (parameters->arguments.array[index].used) { + if (params[i] == fake_parameter_process_e) { + for (j = 0; j < parameters->arguments.array[index].used; ++j) { - main->setting.state.status = f_utf_is_word_dash_plus(main->program.parameters.arguments.array[index].string + j, main->program.parameters.arguments.array[index].used - j, F_false); + main->setting.state.status = f_utf_is_word_dash_plus(parameters->arguments.array[index].string + j, parameters->arguments.array[index].used - j, F_false); // @todo fix this to print an error about the actual invalid character so that it can be investigated. @@ -229,7 +231,7 @@ extern "C" { if (main->setting.state.status == F_false) { main->setting.state.status = F_status_set_error(F_parameter); - fake_print_error_parameter_not_word(&main->program.error, f_console_symbol_long_normal_s, names[i], main->program.parameters.arguments.array[index]); + fake_print_error_parameter_not_word(&main->program.error, f_console_symbol_long_normal_s, names[i], parameters->arguments.array[index]); return; } @@ -237,7 +239,7 @@ extern "C" { } if (cleanups[i]) { - main->setting.state.status = f_path_directory_cleanup(main->program.parameters.arguments.array[index], variable[i]); + main->setting.state.status = f_path_directory_cleanup(parameters->arguments.array[index], variable[i]); if (F_status_is_error(main->setting.state.status)) { if (main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -262,15 +264,15 @@ extern "C" { } } - variable[i]->string = main->program.parameters.arguments.array[index].string; - variable[i]->used = main->program.parameters.arguments.array[index].used; + variable[i]->string = parameters->arguments.array[index].string; + variable[i]->used = parameters->arguments.array[index].used; variable[i]->size = 0; } if (!variable[i]->used) { main->setting.state.status = F_status_set_error(F_parameter); - fake_print_error_parameter_not_empty(&main->program.error, f_console_symbol_long_normal_s, names[i], main->program.parameters.arguments.array[index]); + fake_print_error_parameter_not_empty(&main->program.error, f_console_symbol_long_normal_s, names[i], parameters->arguments.array[index]); return; } @@ -299,7 +301,7 @@ extern "C" { } { - const f_number_unsigned_t parameters[] = { + const f_number_unsigned_t params[] = { fake_parameter_define_e, fake_parameter_mode_e, }; @@ -318,7 +320,7 @@ extern "C" { for (i = 0; i < 2; ++i) { - if ((main->program.parameters.array[parameters[i]].result & f_console_result_found_e) && !(main->program.parameters.array[parameters[i]].result & f_console_result_value_e)) { + if ((parameters->array[params[i]].result & f_console_result_found_e) && !(parameters->array[params[i]].result & f_console_result_value_e)) { main->setting.state.status = F_status_set_error(F_parameter); if (main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -328,8 +330,8 @@ extern "C" { return; } - if (main->program.parameters.array[parameters[i]].result & f_console_result_value_e) { - main->setting.state.status = fll_program_parameter_additional_rip(main->program.parameters.arguments.array, main->program.parameters.array[parameters[i]].values, variable[i]); + if (parameters->array[params[i]].result & f_console_result_value_e) { + main->setting.state.status = fll_program_parameter_additional_rip(parameters->arguments.array, parameters->array[params[i]].values, variable[i]); if (F_status_is_error(main->setting.state.status)) { if (main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -341,12 +343,12 @@ extern "C" { return; } - if (parameters[i] == fake_parameter_mode_e) { - for (j = 0; j < main->program.parameters.arguments.array[i].used; ++j) { + if (params[i] == fake_parameter_mode_e) { + for (j = 0; j < parameters->arguments.array[i].used; ++j) { - width_max = main->program.parameters.arguments.array[i].used - j; + width_max = parameters->arguments.array[i].used - j; - main->setting.state.status = f_utf_is_word_dash_plus(main->program.parameters.arguments.array[i].string + j, width_max, F_false); + main->setting.state.status = f_utf_is_word_dash_plus(parameters->arguments.array[i].string + j, width_max, F_false); if (F_status_is_error(main->setting.state.status)) { @@ -361,7 +363,7 @@ extern "C" { if (main->setting.state.status == F_false) { main->setting.state.status = F_status_set_error(F_parameter); - fake_print_error_parameter_not_word(&main->program.error, f_console_symbol_long_normal_s, names[i], main->program.parameters.arguments.array[i]); + fake_print_error_parameter_not_word(&main->program.error, f_console_symbol_long_normal_s, names[i], parameters->arguments.array[i]); return; } diff --git a/level_3/fss_read/c/main/common.c b/level_3/fss_read/c/main/common.c index c8050e0..969c9f7 100644 --- a/level_3/fss_read/c/main/common.c +++ b/level_3/fss_read/c/main/common.c @@ -45,6 +45,10 @@ extern "C" { if (!main) return; + main->program.output.to.id = F_type_descriptor_output_d; + main->program.output.to.stream = F_type_output_d; + main->program.output.to.flag = F_file_flag_create_d | F_file_flag_write_only_d | F_file_flag_append_d; + f_console_parameters_t * const parameters = &main->program.parameters; main->setting.state.step_small = fss_read_allocation_console_d; @@ -75,10 +79,6 @@ extern "C" { return; } - main->program.output.to.id = F_type_descriptor_output_d; - main->program.output.to.stream = F_type_output_d; - main->program.output.to.flag = F_file_flag_create_d | F_file_flag_write_only_d | F_file_flag_append_d; - if (parameters->array[f_console_standard_parameter_help_e].result & f_console_result_found_e) { main->setting.flag |= fss_read_main_flag_help_d; } -- 1.8.3.1