From: Kevin Day Date: Wed, 4 Sep 2024 01:17:50 +0000 (-0500) Subject: Update: Simplify and centralize reporting for FSS read errors. X-Git-Tag: 0.7.0~78 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=5c297fd92b752e39fa0af557d1348774a4616f95;p=fll Update: Simplify and centralize reporting for FSS read errors. Use a single function to handle the common cases. This is an improvement upon commit a9b37a3f8fd99e45feff22779e8d375314cbb925. --- diff --git a/level_3/fss_read/c/basic/fss_read.c b/level_3/fss_read/c/basic/fss_read.c index 46ee251..5c183f1 100644 --- a/level_3/fss_read/c/basic/fss_read.c +++ b/level_3/fss_read/c/basic/fss_read.c @@ -24,31 +24,7 @@ extern "C" { fll_fss_basic_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.quotes_object, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; - - // Handle knownable errors with more user-friendly messages. - switch (F_status_set_fine(main->setting.state.status)) { - case F_end_not_eos: - case F_end_not_group_eos: - case F_end_not_group_stop: - case F_end_not_nest_eos: - case F_end_not_nest_stop: - case F_end_not_stop: - fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); - - break; - - default: - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_basic_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); - } + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_basic_read)); return; } diff --git a/level_3/fss_read/c/basic_list/fss_read.c b/level_3/fss_read/c/basic_list/fss_read.c index 4146b91..c00338f 100644 --- a/level_3/fss_read/c/basic_list/fss_read.c +++ b/level_3/fss_read/c/basic_list/fss_read.c @@ -24,31 +24,7 @@ extern "C" { fll_fss_basic_list_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; - - // Handle knownable errors with more user-friendly messages. - switch (F_status_set_fine(main->setting.state.status)) { - case F_end_not_eos: - case F_end_not_group_eos: - case F_end_not_group_stop: - case F_end_not_nest_eos: - case F_end_not_nest_stop: - case F_end_not_stop: - fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); - - break; - - default: - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_basic_list_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); - } + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_basic_list_read)); return; } diff --git a/level_3/fss_read/c/embedded_list/fss_read.c b/level_3/fss_read/c/embedded_list/fss_read.c index 32da9f2..bcbf9fa 100644 --- a/level_3/fss_read/c/embedded_list/fss_read.c +++ b/level_3/fss_read/c/embedded_list/fss_read.c @@ -33,31 +33,7 @@ extern "C" { } if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; - - // Handle knownable errors with more user-friendly messages. - switch (F_status_set_fine(main->setting.state.status)) { - case F_end_not_eos: - case F_end_not_group_eos: - case F_end_not_group_stop: - case F_end_not_nest_eos: - case F_end_not_nest_stop: - case F_end_not_stop: - fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); - - break; - - default: - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_embedded_list_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); - } + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_embedded_list_read)); return; } diff --git a/level_3/fss_read/c/extended/fss_read.c b/level_3/fss_read/c/extended/fss_read.c index 3313c3a..bead096 100644 --- a/level_3/fss_read/c/extended/fss_read.c +++ b/level_3/fss_read/c/extended/fss_read.c @@ -24,31 +24,7 @@ extern "C" { fll_fss_extended_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.quotes_object, &main->setting.quotes_content, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; - - // Handle knownable errors with more user-friendly messages. - switch (F_status_set_fine(main->setting.state.status)) { - case F_end_not_eos: - case F_end_not_group_eos: - case F_end_not_group_stop: - case F_end_not_nest_eos: - case F_end_not_nest_stop: - case F_end_not_stop: - fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); - - break; - - default: - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_extended_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); - } + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_extended_read)); return; } diff --git a/level_3/fss_read/c/extended_list/fss_read.c b/level_3/fss_read/c/extended_list/fss_read.c index 07dd060..affe47b 100644 --- a/level_3/fss_read/c/extended_list/fss_read.c +++ b/level_3/fss_read/c/extended_list/fss_read.c @@ -24,31 +24,7 @@ extern "C" { fll_fss_extended_list_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.closes, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; - - // Handle knownable errors with more user-friendly messages. - switch (F_status_set_fine(main->setting.state.status)) { - case F_end_not_eos: - case F_end_not_group_eos: - case F_end_not_group_stop: - case F_end_not_nest_eos: - case F_end_not_nest_stop: - case F_end_not_stop: - fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); - - break; - - default: - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_extended_list_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); - } + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_extended_list_read)); return; } diff --git a/level_3/fss_read/c/main/print/error.c b/level_3/fss_read/c/main/print/error.c index 44cd973..3fccd9c 100644 --- a/level_3/fss_read/c/main/print/error.c +++ b/level_3/fss_read/c/main/print/error.c @@ -46,6 +46,39 @@ extern "C" { } #endif // _di_fss_read_print_error_fss_end_early_ +#ifndef _di_fss_read_print_error_fss_read_ + f_status_t fss_read_print_error_fss_read(fl_print_t * const print, const f_string_t function) { + + if (!print || !print->custom) return F_status_set_error(F_output_not); + if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; + + fss_read_main_t * const main = (fss_read_main_t *) print->custom; + + switch (F_status_set_fine(main->setting.state.status)) { + case F_interrupt: + return F_output_not; + + case F_end_not_eos: + case F_end_not_group_eos: + case F_end_not_group_stop: + case F_end_not_nest_eos: + case F_end_not_nest_stop: + case F_end_not_stop: + return fss_read_print_error_fss_end_early(&main->program.error, fss_read_file_identify(main->setting.range.start, main->setting.files)); + } + + return fll_error_file_print( + &main->program.error, + F_status_set_fine(main->setting.state.status), + function, + fll_error_file_flag_fallback_e, + fss_read_file_identify(main->setting.range.start, main->setting.files), + f_file_operation_process_s, + fll_error_file_type_file_e + ); + } +#endif // _di_fss_read_print_error_fss_read_ + #ifndef _di_fss_read_print_error_parameter_requires_message_ f_status_t fss_read_print_error_parameter_requires_message(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name, const f_string_static_t message) { diff --git a/level_3/fss_read/c/main/print/error.h b/level_3/fss_read/c/main/print/error.h index f29707c..2eeb64c 100644 --- a/level_3/fss_read/c/main/print/error.h +++ b/level_3/fss_read/c/main/print/error.h @@ -93,6 +93,34 @@ extern "C" { #endif // _di_fss_read_print_error_fss_end_early_ /** + * Print FSS read error messages, handling known errors. + * + * This is intended to be called to handle errors from the various FSS read functions, such as fll_fss_basic_read(). + * + * @param print + * The output structure to print to. + * + * The print.custom is expected to be of type fss_read_main_t. + * + * This does not alter print.custom.setting.state.status. + * @param function + * (optional) The name of the function where the error happened. + * + * Set to NULL to disable. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if a parameter is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_fss_read_print_error_fss_read_ + extern f_status_t fss_read_print_error_fss_read(fl_print_t * const print, const f_string_t function); +#endif // _di_fss_read_print_error_fss_read_ + +/** * Print an error message about the parameter requires something that is explained by the message parameter. * * @param print diff --git a/level_3/fss_read/c/payload/fss_read.c b/level_3/fss_read/c/payload/fss_read.c index 0b461ac..2b2aec5 100644 --- a/level_3/fss_read/c/payload/fss_read.c +++ b/level_3/fss_read/c/payload/fss_read.c @@ -42,78 +42,72 @@ extern "C" { fll_fss_payload_read(main->setting.buffer, &main->setting.range, &main->setting.objects, &main->setting.contents, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; + switch (F_status_set_fine(main->setting.state.status)) { + case F_okay_stop: + case F_okay_eos: + if (main->setting.flag & fss_read_main_flag_payload_error_d) { + fss_read_payload_print_problem_payload_missing(&main->program.error); - if (main->setting.state.status == F_status_set_error(F_okay_stop) || main->setting.state.status == F_status_set_error(F_okay_eos)) { - if (main->setting.flag & fss_read_main_flag_payload_error_d) { - fss_read_payload_print_problem_payload_missing(&main->program.error); - - return; - } - - if (main->setting.flag & (fss_read_main_flag_payload_error_d | fss_read_main_flag_payload_warn_d)) { - if (main->program.warning.verbosity > f_console_verbosity_normal_e) { - fss_read_payload_print_problem_payload_missing(&main->program.warning); + break; } - main->setting.state.status = F_okay; - } - else if (main->setting.flag & fss_read_main_flag_payload_create_d) { - main->setting.state.status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer); + if (main->setting.flag & (fss_read_main_flag_payload_error_d | fss_read_main_flag_payload_warn_d)) { + if (main->program.warning.verbosity > f_console_verbosity_normal_e) { + fss_read_payload_print_problem_payload_missing(&main->program.warning); + } - if (F_status_is_error(main->setting.state.status)) { - fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append_assure)); + main->setting.state.status = F_okay; } - else { - main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_range_t), (void **) &main->setting.objects.array, &main->setting.objects.used, &main->setting.objects.size); - - if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_ranges_t), (void **) &main->setting.contents.array, &main->setting.contents.used, &main->setting.contents.size); - } + else if (main->setting.flag & fss_read_main_flag_payload_create_d) { + main->setting.state.status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer); if (F_status_is_error(main->setting.state.status)) { - fss_read_print_error(&main->program.error, macro_fss_read_f(f_memory_array_increase)); + fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append_assure)); } else { - main->setting.objects.array[main->setting.objects.used].start = main->setting.buffer.used; - - main->setting.state.status = f_string_dynamic_append(f_fss_payload_s, &main->setting.buffer); - - if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_s, &main->setting.buffer); - } + main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_range_t), (void **) &main->setting.objects.array, &main->setting.objects.used, &main->setting.objects.size); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_end_s, &main->setting.buffer); + main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_ranges_t), (void **) &main->setting.contents.array, &main->setting.contents.used, &main->setting.contents.size); } if (F_status_is_error(main->setting.state.status)) { - fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append)); + fss_read_print_error(&main->program.error, macro_fss_read_f(f_memory_array_increase)); } else { - main->setting.objects.array[main->setting.objects.used].stop = main->setting.objects.array[main->setting.objects.used].start + f_fss_payload_s.used - 1; - main->setting.contents.array[main->setting.contents.used++].used = 0; - ++main->setting.objects.used; + main->setting.objects.array[main->setting.objects.used].start = main->setting.buffer.used; + + main->setting.state.status = f_string_dynamic_append(f_fss_payload_s, &main->setting.buffer); + + if (F_status_is_error_not(main->setting.state.status)) { + main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_s, &main->setting.buffer); + } + + if (F_status_is_error_not(main->setting.state.status)) { + main->setting.state.status = f_string_dynamic_append(f_fss_payload_list_open_end_s, &main->setting.buffer); + } + + if (F_status_is_error(main->setting.state.status)) { + fss_read_print_error(&main->program.error, macro_fss_read_f(f_string_dynamic_append)); + } + else { + main->setting.objects.array[main->setting.objects.used].stop = main->setting.objects.array[main->setting.objects.used].start + f_fss_payload_s.used - 1; + main->setting.contents.array[main->setting.contents.used++].used = 0; + ++main->setting.objects.used; - main->setting.state.status = F_okay; + main->setting.state.status = F_okay; + } } } } + + break; + + default: + fss_read_print_error_fss_read(&main->program.error, macro_fss_read_f(fll_fss_payload_read)); } - } - else { - fll_error_file_print( - &main->program.error, - F_status_set_fine(main->setting.state.status), - macro_fss_read_f(fll_fss_payload_read), - fll_error_file_flag_fallback_e, - fss_read_file_identify(main->setting.range.start, main->setting.files), - f_file_operation_process_s, - fll_error_file_type_file_e - ); return; - } } if (main->setting.state.status == F_data_not_stop || main->setting.state.status == F_data_not_eos) {