From 77bd13c264a2d91d5151af60bc1e76783c2f2d3e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 31 Jul 2024 22:07:08 -0500 Subject: [PATCH] Cleanup: Use a pointer to make the code more readable in fake_build_load_setting_process(). --- level_3/fake/c/main/build/load.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/level_3/fake/c/main/build/load.c b/level_3/fake/c/main/build/load.c index 127c3b6..22234e4 100644 --- a/level_3/fake/c/main/build/load.c +++ b/level_3/fake/c/main/build/load.c @@ -1125,6 +1125,8 @@ extern "C" { 5, // version_target }; + f_string_dynamic_t *single_source = 0; + for (i = 0; i < 42; ++i) { // Assign the default for literal and path types. @@ -1142,11 +1144,13 @@ extern "C" { if (!settings_single_source[i]->used) continue; + single_source = &settings_single_source[i]->array[settings_single_source[i]->used - 1]; + if (settings_single_type[i] == 1) { - if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_common_setting_bool_yes_s) == F_equal_to) { + if (f_compare_dynamic_trim(*single_source, fake_common_setting_bool_yes_s) == F_equal_to) { *settings_single_bool[i] = F_true; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_common_setting_bool_no_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_common_setting_bool_no_s) == F_equal_to) { *settings_single_bool[i] = F_false; } else { @@ -1156,13 +1160,13 @@ extern "C" { } } else if (settings_single_type[i] == 4) { - if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_language_bash_s) == F_equal_to) { + if (f_compare_dynamic_trim(*single_source, fake_build_language_bash_s) == F_equal_to) { *settings_single_language[i] = fake_build_language_bash_e; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_language_c_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_build_language_c_s) == F_equal_to) { *settings_single_language[i] = fake_build_language_c_e; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_language_cpp_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_build_language_cpp_s) == F_equal_to) { *settings_single_language[i] = fake_build_language_cpp_e; } else { @@ -1172,16 +1176,16 @@ extern "C" { } } else if (settings_single_type[i] == 5) { - if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_version_major_s) == F_equal_to) { + if (f_compare_dynamic_trim(*single_source, fake_build_version_major_s) == F_equal_to) { *settings_single_version[i] = fake_build_version_major_e; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_version_minor_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_build_version_minor_s) == F_equal_to) { *settings_single_version[i] = fake_build_version_minor_e; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_version_micro_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_build_version_micro_s) == F_equal_to) { *settings_single_version[i] = fake_build_version_micro_e; } - else if (f_compare_dynamic_trim(settings_single_source[i]->array[settings_single_source[i]->used - 1], fake_build_version_nano_s) == F_equal_to) { + else if (f_compare_dynamic_trim(*single_source, fake_build_version_nano_s) == F_equal_to) { *settings_single_version[i] = fake_build_version_nano_e; } else { @@ -1196,7 +1200,7 @@ extern "C" { settings_single_destination[i]->used = 0; if (settings_single_type[i] == 2) { - main->setting.state.status = f_path_directory_cleanup(settings_single_source[i]->array[settings_single_source[i]->used - 1], settings_single_destination[i]); + main->setting.state.status = f_path_directory_cleanup(*single_source, settings_single_destination[i]); if (F_status_is_error(main->setting.state.status)) { fake_print_error(&main->program.error, macro_fake_f(f_path_directory_cleanup)); @@ -1205,7 +1209,7 @@ extern "C" { } } else { - main->setting.state.status = f_memory_array_increase_by(settings_single_source[i]->array[settings_single_source[i]->used - 1].used + 1, sizeof(f_char_t), (void **) &settings_single_destination[i]->string, &settings_single_destination[i]->used, &settings_single_destination[i]->size); + main->setting.state.status = f_memory_array_increase_by(single_source->used + 1, sizeof(f_char_t), (void **) &settings_single_destination[i]->string, &settings_single_destination[i]->used, &settings_single_destination[i]->size); if (F_status_is_error(main->setting.state.status)) { fake_print_error(&main->program.error, macro_fake_f(f_memory_array_increase_by)); @@ -1217,13 +1221,13 @@ extern "C" { if (settings_single_type[i] == 6) { main->setting.state.status = F_okay; - for (j = 0; j < settings_single_source[i]->array[settings_single_source[i]->used - 1].used; ++j) { + for (j = 0; j < single_source->used; ++j) { - if (settings_single_source[i]->array[settings_single_source[i]->used - 1].string[j] == f_string_ascii_slash_forward_s.string[0] || settings_single_source[i]->array[settings_single_source[i]->used - 1].string[j] == f_string_ascii_slash_backward_s.string[0]) { + if (single_source->string[j] == f_string_ascii_slash_forward_s.string[0] || single_source->string[j] == f_string_ascii_slash_backward_s.string[0]) { main->setting.state.status = F_warning; // Prevent the slash from being copied. - settings_single_source[i]->array[settings_single_source[i]->used - 1].string[j] = 0; + single_source->string[j] = 0; } } // for @@ -1232,7 +1236,7 @@ extern "C" { } } - main->setting.state.status = f_string_dynamic_append_nulless(settings_single_source[i]->array[settings_single_source[i]->used - 1], settings_single_destination[i]); + main->setting.state.status = f_string_dynamic_append_nulless(*single_source, settings_single_destination[i]); if (F_status_is_error(main->setting.state.status)) { fake_print_error(&main->program.error, macro_fake_f(f_string_dynamic_append_nulless)); -- 1.8.3.1