From fc782eb55a6134a2097920293fab201b155234ef Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 3 Dec 2024 20:05:22 -0600 Subject: [PATCH] Update: Simplify code slightly aad remove redundant `fll_program_print_help_header()` call. Use the variable for `parameters` to simplify code. This simplifies the code at the cost of using a variable. Remove include that is not needed from the c files. Update the documentation comments to have `Properties: `. Remove redundant `fll_program_print_help_header()` call. --- level_3/iki_write/c/eki/eki_write.c | 1 - level_3/iki_write/c/iki/iki_write.c | 1 - level_3/iki_write/c/main/common.c | 58 +++++++++++++++++--------------- level_3/iki_write/c/main/common/type.h | 42 ++++++++++++----------- level_3/iki_write/c/main/print/message.c | 2 -- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/level_3/iki_write/c/eki/eki_write.c b/level_3/iki_write/c/eki/eki_write.c index eafe507..c2eb053 100644 --- a/level_3/iki_write/c/eki/eki_write.c +++ b/level_3/iki_write/c/eki/eki_write.c @@ -1,5 +1,4 @@ #include "eki_write.h" -#include "../main/iki_write.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/iki_write/c/iki/iki_write.c b/level_3/iki_write/c/iki/iki_write.c index 42626dd..4bd708c 100644 --- a/level_3/iki_write/c/iki/iki_write.c +++ b/level_3/iki_write/c/iki/iki_write.c @@ -1,5 +1,4 @@ #include "iki_write.h" -#include "../main/iki_write.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/iki_write/c/main/common.c b/level_3/iki_write/c/main/common.c index 2ef9099..3fe1028 100644 --- a/level_3/iki_write/c/main/common.c +++ b/level_3/iki_write/c/main/common.c @@ -9,9 +9,15 @@ 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 = iki_write_allocation_console_d; - f_console_parameter_process(arguments, &main->program.parameters, &main->setting.state, 0); + f_console_parameter_process(arguments, parameters, &main->setting.state, 0); main->setting.state.step_small = iki_write_allocation_small_d; @@ -37,10 +43,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 (callback) { callback(arguments, main); if (F_status_is_error(main->setting.state.status)) return; @@ -52,19 +54,19 @@ extern "C" { } } - 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 |= iki_write_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 |= iki_write_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 |= iki_write_main_flag_copyright_d; return; @@ -77,8 +79,8 @@ extern "C" { main->setting.flag &= ~iki_write_main_flag_pipe_d; } - if (main->program.parameters.array[iki_write_parameter_file_e].result & f_console_result_value_e && main->program.parameters.array[iki_write_parameter_file_e].values.used) { - if (main->program.parameters.array[iki_write_parameter_file_e].values.used > 1) { + if (parameters->array[iki_write_parameter_file_e].result & f_console_result_value_e && parameters->array[iki_write_parameter_file_e].values.used) { + if (parameters->array[iki_write_parameter_file_e].values.used > 1) { main->setting.state.status = F_status_set_error(F_parameter); fll_program_print_error_parameter_must_specify_once(&main->program.error, f_console_symbol_long_normal_s, iki_write_long_file_s); @@ -86,22 +88,22 @@ extern "C" { return; } - const f_number_unsigned_t index = main->program.parameters.array[iki_write_parameter_file_e].values.array[0]; + const f_number_unsigned_t index = parameters->array[iki_write_parameter_file_e].values.array[0]; main->program.output.to.id = -1; main->program.output.to.stream = 0; - main->setting.state.status = f_file_stream_open(main->program.parameters.arguments.array[index], f_string_empty_s, &main->program.output.to); + main->setting.state.status = f_file_stream_open(parameters->arguments.array[index], f_string_empty_s, &main->program.output.to); if (F_status_is_error(main->setting.state.status)) { - fll_error_file_print(&main->program.error, F_status_set_fine(main->setting.state.status), macro_iki_write_f(f_file_stream_open), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_open_s, fll_error_file_type_file_e); + fll_error_file_print(&main->program.error, F_status_set_fine(main->setting.state.status), macro_iki_write_f(f_file_stream_open), fll_error_file_flag_fallback_e, parameters->arguments.array[index], f_file_operation_open_s, fll_error_file_type_file_e); return; } main->setting.flag |= iki_write_main_flag_file_to_d; } - else if (main->program.parameters.array[iki_write_parameter_file_e].result & f_console_result_found_e) { + else if (parameters->array[iki_write_parameter_file_e].result & f_console_result_found_e) { main->setting.state.status = F_status_set_error(F_parameter); fll_program_print_error_parameter_missing_value(&main->program.error, f_console_symbol_long_normal_s, iki_write_long_file_s); @@ -117,7 +119,7 @@ extern "C" { return; } - if (main->program.parameters.array[iki_write_parameter_wrap_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_wrap_e].result & f_console_result_found_e) { main->setting.flag |= iki_write_main_flag_wrap_d; main->setting.state.flag |= f_iki_state_flag_force_wrap_e; } @@ -127,39 +129,39 @@ extern "C" { main->setting.quote = f_iki_syntax_quote_double_s; - if (main->program.parameters.array[iki_write_parameter_double_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_single_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_double_e].location < main->program.parameters.array[iki_write_parameter_single_e].location) { + if (parameters->array[iki_write_parameter_double_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_single_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_double_e].location < parameters->array[iki_write_parameter_single_e].location) { main->setting.quote = f_iki_syntax_quote_single_s; - if (main->program.parameters.array[iki_write_parameter_grave_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_single_e].location < main->program.parameters.array[iki_write_parameter_grave_e].location) { + if (parameters->array[iki_write_parameter_grave_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_single_e].location < parameters->array[iki_write_parameter_grave_e].location) { main->setting.quote = f_iki_syntax_quote_grave_s; } } } - else if (main->program.parameters.array[iki_write_parameter_grave_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_double_e].location < main->program.parameters.array[iki_write_parameter_grave_e].location) { + else if (parameters->array[iki_write_parameter_grave_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_double_e].location < parameters->array[iki_write_parameter_grave_e].location) { main->setting.quote = f_iki_syntax_quote_grave_s; } } } - else if (main->program.parameters.array[iki_write_parameter_grave_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_double_e].location < main->program.parameters.array[iki_write_parameter_grave_e].location) { + else if (parameters->array[iki_write_parameter_grave_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_double_e].location < parameters->array[iki_write_parameter_grave_e].location) { main->setting.quote = f_iki_syntax_quote_grave_s; } } } - else if (main->program.parameters.array[iki_write_parameter_single_e].result & f_console_result_found_e) { + else if (parameters->array[iki_write_parameter_single_e].result & f_console_result_found_e) { main->setting.quote = f_iki_syntax_quote_single_s; - if (main->program.parameters.array[iki_write_parameter_grave_e].result & f_console_result_found_e) { - if (main->program.parameters.array[iki_write_parameter_single_e].location < main->program.parameters.array[iki_write_parameter_grave_e].location) { + if (parameters->array[iki_write_parameter_grave_e].result & f_console_result_found_e) { + if (parameters->array[iki_write_parameter_single_e].location < parameters->array[iki_write_parameter_grave_e].location) { main->setting.quote = f_iki_syntax_quote_grave_s; } } } - else if (main->program.parameters.array[iki_write_parameter_grave_e].result & f_console_result_found_e) { + else if (parameters->array[iki_write_parameter_grave_e].result & f_console_result_found_e) { main->setting.quote = f_iki_syntax_quote_grave_s; } } diff --git a/level_3/iki_write/c/main/common/type.h b/level_3/iki_write/c/main/common/type.h index 296c68f..876cf4e 100644 --- a/level_3/iki_write/c/main/common/type.h +++ b/level_3/iki_write/c/main/common/type.h @@ -17,12 +17,13 @@ extern "C" { #endif /** - * The iki write main program cache. + * The IKI write main program cache. * - * buffer: A buffer used during processing the file. - * content: A buffer used to hold a Content during processing. - * iki: A buffer used for writing the IKI during processing. - * objects: A buffer used to hold Objects during processing. + * Properties: + * - buffer: A buffer used during processing the file. + * - content: A buffer used to hold a Content during processing. + * - iki: A buffer used for writing the IKI during processing. + * - objects: A buffer used to hold Objects during processing. */ #ifndef _di_iki_write_setting_t_ typedef struct { @@ -44,11 +45,12 @@ extern "C" { /** * The IKI write callbacks. * - * load_objects_content_pipe: Load the Objects and Content from the pipe. + * Properties: + * - load_objects_content_pipe: Load the Objects and Content from the pipe. * - * print_help: Print the main help message. + * - print_help: Print the main help message. * - * process_objects_content: Process an Objects and Content set. + * - process_objects_content: Process an Objects and Content set. */ #ifndef _di_iki_write_callback_t_ typedef struct { @@ -68,20 +70,21 @@ extern "C" { #endif // _di_iki_write_callback_t_ /** - * The iki write main program settings. + * The IKI write main program settings. * * This is passed to the program-specific main entry point to designate program settings. * These program settings are often processed from the program arguments (often called the command line arguments). * - * flag: Flags passed to the main function. + * Properties: + * - flag: Flags passed to the main function. * - * status_signal: A status used eclusively by the threaded signal handler. - * state: The state data used when processing the FSS data. + * - status_signal: A status used eclusively by the threaded signal handler. + * - state: The state data used when processing the FSS data. * - * quote: This holds the quote used during processing. + * - quote: This holds the quote used during processing. * - * contents: An array of content passed as values to the "--content" parameter and must match the length of objects. - * objectss: An array of an array of objects passed as values to the "--object" parameter. + * - contents: An array of content passed as values to the "--content" parameter and must match the length of objects. + * - objectss: An array of an array of objects passed as values to the "--object" parameter. */ #ifndef _di_iki_write_setting_t_ typedef struct { @@ -110,10 +113,11 @@ extern "C" { /** * The main program data as a single structure. * - * cache: The cache data. - * callback: The callbacks. - * program: The main program data. - * setting: The settings data. + * Properties: + * - cache: The cache data. + * - callback: The callbacks. + * - program: The main program data. + * - setting: The settings data. */ #ifndef _di_iki_write_main_t_ typedef struct { diff --git a/level_3/iki_write/c/main/print/message.c b/level_3/iki_write/c/main/print/message.c index 161d546..97a399b 100644 --- a/level_3/iki_write/c/main/print/message.c +++ b/level_3/iki_write/c/main/print/message.c @@ -9,8 +9,6 @@ extern "C" { if (!print) return; - fll_program_print_help_header(print, iki_write_program_name_long_s, iki_write_program_version_s); - fll_program_print_help_option(print, f_console_standard_short_help_s, f_console_standard_long_help_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Print this help message."); fll_program_print_help_option(print, f_console_standard_short_dark_s, f_console_standard_long_dark_s, f_console_symbol_short_inverse_s, f_console_symbol_long_inverse_s, " Output using colors that show up better on dark backgrounds."); fll_program_print_help_option(print, f_console_standard_short_light_s, f_console_standard_long_light_s, f_console_symbol_short_inverse_s, f_console_symbol_long_inverse_s, " Output using colors that show up better on light backgrounds."); -- 1.8.3.1