From c75c33ae7648fe962e87a8cc6ac6bda2272ee078 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 14 Jun 2023 22:13:00 -0500 Subject: [PATCH] Progress: Fix issues in runtime tests for fss_read not relating to Embedded List and Payload. More runtime tests now pass. The Extended List tests still fail in some cases. I noticed that the Extended List line count is not handling the closing brace. The count is inaccurate. This is a bug in the 0.6.x branch and needs to be fixed there. The fix is in place for this branch but the tests currently fail because they generated expect files are incorrect in this case. There are other similar problems in different FSS read programs regarding --total and parameters like --at or --line that need to be fixed in the 0.6.x branch as well. The Embedded List and Payload need special handling and are not addressed here. Other things regarding fss_read not done: - The help printing needs to be updated for each program. - Any remaining todo and fixme. - The pipe input and output. There is likely a lot of room for improvement but I am going to ignore such things for now as my priorities are elsewhere. --- level_3/fss_read/c/basic/main.c | 2 +- level_3/fss_read/c/basic_list/main.c | 4 +- level_3/fss_read/c/embedded_list/main.c | 4 +- level_3/fss_read/c/embedded_list/print.c | 16 ++++ level_3/fss_read/c/embedded_list/print.h | 26 ++++++ level_3/fss_read/c/extended_list/main.c | 4 +- level_3/fss_read/c/extended_list/print.c | 6 +- level_3/fss_read/c/main/common.h | 4 +- level_3/fss_read/c/main/common/enumeration.h | 112 +++++++++++----------- level_3/fss_read/c/main/main.c | 29 ++++-- level_3/fss_read/c/main/process_normal.c | 135 ++++++++++----------------- level_3/fss_read/c/payload/main.c | 5 +- 12 files changed, 182 insertions(+), 165 deletions(-) diff --git a/level_3/fss_read/c/basic/main.c b/level_3/fss_read/c/basic/main.c index 4bb2865..77d1654 100644 --- a/level_3/fss_read/c/basic/main.c +++ b/level_3/fss_read/c/basic/main.c @@ -36,8 +36,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.print_at = &fss_read_print_at; data.callback.print_content = &fss_read_print_content; - data.callback.print_content_next = 0; data.callback.print_content_ignore = 0; + data.callback.print_content_next = 0; data.callback.print_object = &fss_read_print_object; data.callback.print_object_end = &fss_read_basic_print_object_end; data.callback.print_set_end = &fss_read_print_set_end; diff --git a/level_3/fss_read/c/basic_list/main.c b/level_3/fss_read/c/basic_list/main.c index 7c919f6..c8798c0 100644 --- a/level_3/fss_read/c/basic_list/main.c +++ b/level_3/fss_read/c/basic_list/main.c @@ -17,7 +17,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.flag |= fss_read_main_flag_object_as_line_e; + data.setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_basic_list_standard_s; @@ -35,8 +35,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.print_at = &fss_read_print_at; data.callback.print_content = &fss_read_print_content; - data.callback.print_content_next = 0; data.callback.print_content_ignore = &fss_read_print_content_ignore; + data.callback.print_content_next = 0; data.callback.print_object = &fss_read_print_object; data.callback.print_object_end = &fss_read_basic_list_print_object_end; data.callback.print_set_end = &fss_read_print_set_end_no_eol; diff --git a/level_3/fss_read/c/embedded_list/main.c b/level_3/fss_read/c/embedded_list/main.c index ca5972e..1bd71e2 100644 --- a/level_3/fss_read/c/embedded_list/main.c +++ b/level_3/fss_read/c/embedded_list/main.c @@ -17,7 +17,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.flag |= fss_read_main_flag_object_as_line_e; + data.setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_content_has_close_e | fss_read_main_flag_object_trim_e; data.setting.flag |= fss_read_main_flag_depth_multiple_e; data.setting.state.custom = (void *) &data; @@ -36,8 +36,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.print_at = &fss_read_print_at; data.callback.print_content = &fss_read_print_content; - data.callback.print_content_next = 0; data.callback.print_content_ignore = &fss_read_print_content_ignore; + data.callback.print_content_next = 0; data.callback.print_object = &fss_read_print_object; data.callback.print_object_end = &fss_read_embedded_list_print_object_end; data.callback.print_set_end = &fss_read_print_set_end; diff --git a/level_3/fss_read/c/embedded_list/print.c b/level_3/fss_read/c/embedded_list/print.c index da4b651..243b21a 100644 --- a/level_3/fss_read/c/embedded_list/print.c +++ b/level_3/fss_read/c/embedded_list/print.c @@ -62,6 +62,22 @@ extern "C" { } #endif // _di_fss_read_embedded_list_print_object_end_ +#ifndef _di_fss_read_embedded_list_print_set_end_ + f_status_t fss_read_embedded_list_print_set_end(fl_print_t * const print) { + + if (!print || !print->custom) return F_status_set_error(F_output_not); + + fss_read_main_t * const main = (fss_read_main_t *) print->custom; + + if ((main->setting.flag & fss_read_main_flag_object_e) && main->setting.flag & fss_read_main_flag_content_e) { + f_print_dynamic_raw(f_fss_embedded_list_close_s, print->to); + f_print_dynamic_raw(f_fss_embedded_list_close_end_s, print->to); + } + + return F_none; + } +#endif // _di_fss_read_embedded_list_print_set_end_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fss_read/c/embedded_list/print.h b/level_3/fss_read/c/embedded_list/print.h index f871663..6914be9 100644 --- a/level_3/fss_read/c/embedded_list/print.h +++ b/level_3/fss_read/c/embedded_list/print.h @@ -56,6 +56,32 @@ extern "C" { extern f_status_t fss_read_embedded_list_print_object_end(fl_print_t * const print); #endif // _di_fss_read_embedded_list_print_object_end_ +/** + * Print the end of an Object/Content set. + * + * This locks, uses, and unlocks the file stream. + * + * @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. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if a parameter is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see f_print_dynamic_raw() + */ +#ifndef _di_fss_read_embedded_list_print_set_end_ + extern f_status_t fss_read_embedded_list_print_set_end(fl_print_t * const print); +#endif // _di_fss_read_embedded_list_print_set_end_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fss_read/c/extended_list/main.c b/level_3/fss_read/c/extended_list/main.c index 7cf68bb..7ee67ed 100644 --- a/level_3/fss_read/c/extended_list/main.c +++ b/level_3/fss_read/c/extended_list/main.c @@ -17,7 +17,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.flag |= fss_read_main_flag_object_as_line_e; + data.setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_content_has_close_e | fss_read_main_flag_object_trim_e; data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_extended_list_standard_s; @@ -35,8 +35,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.print_at = &fss_read_print_at; data.callback.print_content = &fss_read_print_content; - data.callback.print_content_next = 0; data.callback.print_content_ignore = &fss_read_print_content_ignore; + data.callback.print_content_next = 0; data.callback.print_object = &fss_read_print_object; data.callback.print_object_end = &fss_read_extended_list_print_object_end; data.callback.print_set_end = &fss_read_extended_list_print_set_end; diff --git a/level_3/fss_read/c/extended_list/print.c b/level_3/fss_read/c/extended_list/print.c index 68ae81e..17e3f52 100644 --- a/level_3/fss_read/c/extended_list/print.c +++ b/level_3/fss_read/c/extended_list/print.c @@ -69,8 +69,10 @@ extern "C" { fss_read_main_t * const main = (fss_read_main_t *) print->custom; - // @todo - //fll_print_dynamic_raw((main->setting.flag & fss_read_main_flag_pipe_e) ? fss_read_pipe_content_end_s : f_string_eol_s, print->to); + if ((main->setting.flag & fss_read_main_flag_object_e) && main->setting.flag & fss_read_main_flag_content_e) { + f_print_dynamic_raw(f_fss_extended_list_close_s, print->to); + f_print_dynamic_raw(f_fss_extended_list_close_end_s, print->to); + } return F_none; } diff --git a/level_3/fss_read/c/main/common.h b/level_3/fss_read/c/main/common.h index a8f3234..0ac1cae 100644 --- a/level_3/fss_read/c/main/common.h +++ b/level_3/fss_read/c/main/common.h @@ -64,7 +64,7 @@ extern "C" { * Errors (with error bit) from: fll_program_parameter_process_context(). * Errors (with error bit) from: fll_program_parameter_process_verbosity(). * - * Errors (with error bit) from: fss_read_setting_load_depth(). @todo fss_read_depths_resize() is to be relocated to "callback". + * Errors (with error bit) from: fss_read_setting_load_depth(). * Errors (with error bit) from: fss_read_signal_check() * @param callback * (optional) Designate a function to call after performing the initial processing, but before printing help. @@ -77,7 +77,7 @@ extern "C" { * @see fll_program_parameter_process_context() * @see fll_program_parameter_process_verbosity() * - * @see fss_read_setting_load_depth() @todo fss_read_depths_resize() is to be relocated to "callback". + * @see fss_read_setting_load_depth() * @see fss_read_signal_check() */ #ifndef _di_fss_read_setting_load_ diff --git a/level_3/fss_read/c/main/common/enumeration.h b/level_3/fss_read/c/main/common/enumeration.h index bb55a99..b04ccc3 100644 --- a/level_3/fss_read/c/main/common/enumeration.h +++ b/level_3/fss_read/c/main/common/enumeration.h @@ -20,63 +20,67 @@ extern "C" { * Flags passed to the main function or program. * * fss_read_main_flag_*_e: - * - none: No flags set. - * - at: The object at the given position is being selected (Think of this as select a row for some Object). - * - columns: The total columns found and selected is printed instead of the Content. - * - content: The Content is to be printed. - * - content_multiple: Designate that multiple Content is allowed for an Object for this standard rather than a single Content per Object. - * - copyright: Print copyright. - * - delimit: How delimits are to be handled is designated. - * - depth: The depth is specified at least once. - * - depth_multiple: Designate that multiple depths are allowed within Content rather than being single depth Content. - * - empty: Empty Content will be printed (Objects that have no Content will have their empty Content printed). - * - help: Print help. - * - line: A specific Content at a given line is to be selected (Think of this as select a row for some Content). - * - line_single: Designate that only a single line for Content is allowed for an Object for this standard rather than allowing multiple lines per Content per Object. - * - name: A specific Object name has been requested. - * - object: The Object is to be printed. - * - object_as_line: The Object is counted as its own line for the purpose of -l/--line or any other similar behavior. - * - original: Enable original printing, where the quotes are printed and no delimits are applied. - * - pipe: Print using the special pipe format. - * - print_first: When set, print new line to message output on program begin after loading settings. - * - print_last: When set, print new line to message output on program end. - * - quote_content: Designate that the standard supports quotes on Content. - * - quote_object: Designate that the standard supports quotes on Objects. - * - select: A specific Content at a given position is to be selected (Think of this as select a column for some Content). - * - total: The total lines found and selected is printed instead of the Content. - * - trim: Empty space before and after Objects and Content will not be printed (They will be trimmed). - * - trim_object: Empty space before and after Objects (but not Content) will not be printed (They will be trimmed). - * - version: Print version. + * - none: No flags set. + * - at: The object at the given position is being selected (Think of this as select a row for some Object). + * - columns: The total columns found and selected is printed instead of the Content. + * - content: The Content is to be printed. + * - content_has_close: The Content has a closing character which needs to be counted and handled when processing both Object and Content, but is otherwise not processed or printed. + * - content_multiple: Designate that multiple Content is allowed for an Object for this standard rather than a single Content per Object. + * - copyright: Print copyright. + * - delimit: How delimits are to be handled is designated. + * - depth: The depth is specified at least once. + * - depth_multiple: Designate that multiple depths are allowed within Content rather than being single depth Content. + * - empty: Empty Content will be printed (Objects that have no Content will have their empty Content printed). + * - help: Print help. + * - line: A specific Content at a given line is to be selected (Think of this as select a row for some Content). + * - line_single: Designate that only a single line for Content is allowed for an Object for this standard rather than allowing multiple lines per Content per Object. + * - name: A specific Object name has been requested. + * - object: The Object is to be printed. + * - object_as_line: The Object is counted as its own line for the purpose of -l/--line or any other similar behavior. + * - object_trim: Empty space before an after Objects are ignored while processing without affecting printing behavior. + * - original: Enable original printing, where the quotes are printed and no delimits are applied. + * - pipe: Print using the special pipe format. + * - print_first: When set, print new line to message output on program begin after loading settings. + * - print_last: When set, print new line to message output on program end. + * - quote_content: Designate that the standard supports quotes on Content. + * - quote_object: Designate that the standard supports quotes on Objects. + * - select: A specific Content at a given position is to be selected (Think of this as select a column for some Content). + * - total: The total lines found and selected is printed instead of the Content. + * - trim: Empty space before and after Objects and Content will not be printed (They will be trimmed). + * - trim_object: Empty space before and after Objects (but not Content) will not be printed (They will be trimmed). + * - version: Print version. */ #ifndef _di_fss_read_main_flag_e_ enum { - fss_read_main_flag_none_e = 0x0, - fss_read_main_flag_at_e = 0x1, - fss_read_main_flag_columns_e = 0x2, - fss_read_main_flag_content_e = 0x4, - fss_read_main_flag_content_multiple_e = 0x8, - fss_read_main_flag_copyright_e = 0x10, - fss_read_main_flag_delimit_e = 0x20, - fss_read_main_flag_depth_e = 0x40, - fss_read_main_flag_depth_multiple_e = 0x80, - fss_read_main_flag_empty_e = 0x100, - fss_read_main_flag_help_e = 0x200, - fss_read_main_flag_line_e = 0x400, - fss_read_main_flag_line_single_e = 0x800, - fss_read_main_flag_name_e = 0x1000, - fss_read_main_flag_object_e = 0x2000, - fss_read_main_flag_object_as_line_e = 0x4000, - fss_read_main_flag_original_e = 0x8000, - fss_read_main_flag_pipe_e = 0x10000, - fss_read_main_flag_print_first_e = 0x20000, - fss_read_main_flag_print_last_e = 0x40000, - fss_read_main_flag_quote_content_e = 0x80000, - fss_read_main_flag_quote_object_e = 0x100000, - fss_read_main_flag_select_e = 0x200000, - fss_read_main_flag_total_e = 0x400000, - fss_read_main_flag_trim_e = 0x800000, - fss_read_main_flag_trim_object_e = 0x1000000, - fss_read_main_flag_version_e = 0x2000000, + fss_read_main_flag_none_e = 0x0, + fss_read_main_flag_at_e = 0x1, + fss_read_main_flag_columns_e = 0x2, + fss_read_main_flag_content_e = 0x4, + fss_read_main_flag_content_has_close_e = 0x8, + fss_read_main_flag_content_multiple_e = 0x10, + fss_read_main_flag_copyright_e = 0x20, + fss_read_main_flag_delimit_e = 0x40, + fss_read_main_flag_depth_e = 0x80, + fss_read_main_flag_depth_multiple_e = 0x100, + fss_read_main_flag_empty_e = 0x200, + fss_read_main_flag_help_e = 0x400, + fss_read_main_flag_line_e = 0x800, + fss_read_main_flag_line_single_e = 0x1000, + fss_read_main_flag_name_e = 0x2000, + fss_read_main_flag_object_e = 0x4000, + fss_read_main_flag_object_as_line_e = 0x8000, + fss_read_main_flag_object_trim_e = 0x10000, + fss_read_main_flag_original_e = 0x20000, + fss_read_main_flag_pipe_e = 0x40000, + fss_read_main_flag_print_first_e = 0x80000, + fss_read_main_flag_print_last_e = 0x100000, + fss_read_main_flag_quote_content_e = 0x200000, + fss_read_main_flag_quote_object_e = 0x400000, + fss_read_main_flag_select_e = 0x800000, + fss_read_main_flag_total_e = 0x1000000, + fss_read_main_flag_trim_e = 0x2000000, + fss_read_main_flag_trim_object_e = 0x4000000, + fss_read_main_flag_version_e = 0x8000000, }; // enum #endif // _di_fss_read_main_flag_e_ diff --git a/level_3/fss_read/c/main/main.c b/level_3/fss_read/c/main/main.c index 2b7053e..9f9a1bf 100644 --- a/level_3/fss_read/c/main/main.c +++ b/level_3/fss_read/c/main/main.c @@ -134,9 +134,11 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.standard = fss_read_basic_standard_s; // Remove flags not supported for this standard. + main->setting.flag -= main->setting.flag & fss_read_main_flag_content_has_close_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_content_multiple_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_depth_multiple_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_object_as_line_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_object_trim_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_trim_object_e; main->setting.flag |= fss_read_main_flag_line_single_e; @@ -158,8 +160,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.standard = fss_read_extended_standard_s; // Remove flags not supported for this standard. + main->setting.flag -= main->setting.flag & fss_read_main_flag_content_has_close_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_depth_multiple_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_object_as_line_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_object_trim_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_trim_object_e; main->setting.flag |= fss_read_main_flag_line_single_e | fss_read_main_flag_content_multiple_e; @@ -181,13 +185,14 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.standard = fss_read_basic_list_standard_s; // Remove flags not supported for this standard. - main->setting.flag -= main->setting.flag & fss_read_main_flag_line_single_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_content_has_close_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_content_multiple_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_depth_multiple_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_line_single_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_content_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_object_e; - main->setting.flag |= fss_read_main_flag_object_as_line_e; + main->setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; main->callback.process_help = &fss_read_basic_list_process_help; main->callback.process_load = &fss_read_basic_list_process_load; @@ -211,7 +216,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_content_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_object_e; - main->setting.flag |= fss_read_main_flag_object_as_line_e; + main->setting.flag |= fss_read_main_flag_content_has_close_e; + main->setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; main->callback.process_help = &fss_read_extended_list_process_help; main->callback.process_load = &fss_read_extended_list_process_load; @@ -219,7 +225,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->callback.print_content_next = 0; main->callback.print_object_end = &fss_read_extended_list_print_object_end; - main->callback.print_set_end = &fss_read_print_set_end; + main->callback.print_set_end = &fss_read_extended_list_print_set_end; } else if (f_compare_dynamic(argv[index], fss_read_format_code_short_0008_s) == F_equal_to || f_compare_dynamic(argv[index], fss_read_format_code_long_0008_s) == F_equal_to || @@ -229,12 +235,14 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.standard = fss_read_embedded_list_standard_s; // Remove flags not supported for this standard. + main->setting.flag -= main->setting.flag & fss_read_main_flag_content_has_close_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_line_single_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_content_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_object_e; - main->setting.flag |= fss_read_main_flag_content_multiple_e | fss_read_main_flag_depth_multiple_e; - main->setting.flag |= fss_read_main_flag_object_as_line_e; + main->setting.flag |= fss_read_main_flag_content_has_close_e | fss_read_main_flag_content_multiple_e; + main->setting.flag |= fss_read_main_flag_depth_multiple_e; + main->setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; main->callback.process_help = &fss_read_embedded_list_process_help; main->callback.process_load = &fss_read_embedded_list_process_load; @@ -242,7 +250,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->callback.print_content_next = 0; main->callback.print_object_end = &fss_read_embedded_list_print_object_end; - main->callback.print_set_end = &fss_read_print_set_end; + main->callback.print_set_end = &fss_read_embedded_list_print_set_end; } else if (f_compare_dynamic(argv[index], fss_read_format_code_short_000e_s) == F_equal_to || f_compare_dynamic(argv[index], fss_read_format_code_long_000e_s) == F_equal_to || @@ -252,13 +260,14 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->setting.standard = fss_read_payload_standard_s; // Remove flags not supported for this standard. - main->setting.flag -= main->setting.flag & fss_read_main_flag_line_single_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_content_has_close_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_content_multiple_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_depth_multiple_e; + main->setting.flag -= main->setting.flag & fss_read_main_flag_line_single_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_content_e; main->setting.flag -= main->setting.flag & fss_read_main_flag_quote_object_e; - main->setting.flag |= fss_read_main_flag_object_as_line_e; + main->setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; main->callback.process_help = &fss_read_payload_process_help; main->callback.process_load = &fss_read_payload_process_load; @@ -266,7 +275,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->callback.print_content_next = 0; main->callback.print_object_end = &fss_read_payload_print_object_end; - main->callback.print_set_end = &fss_read_print_set_end; + main->callback.print_set_end = &fss_read_print_set_end_no_eol; } else { if (main->setting.flag & fss_read_main_flag_help_e) { diff --git a/level_3/fss_read/c/main/process_normal.c b/level_3/fss_read/c/main/process_normal.c index a25f72e..b699b45 100644 --- a/level_3/fss_read/c/main/process_normal.c +++ b/level_3/fss_read/c/main/process_normal.c @@ -65,7 +65,12 @@ extern "C" { memset(names, F_true, sizeof(bool) * main->setting.objects.used); } - if (main->setting.flag & fss_read_main_flag_at_e) { + if (main->setting.flag & fss_read_main_flag_total_e) { + if (main->callback.process_total) { + main->callback.process_total(main, names); + } + } + else if (main->setting.flag & fss_read_main_flag_at_e) { if (main->callback.process_at) { main->callback.process_at(main, names, *delimits_object, *delimits_content); } @@ -75,11 +80,6 @@ extern "C" { main->callback.process_columns(main, names); } } - else if (main->setting.flag & fss_read_main_flag_total_e) { - if (main->callback.process_total) { - main->callback.process_total(main, names); - } - } else { f_array_length_t i = 0; @@ -134,10 +134,6 @@ extern "C" { // If the standard only has one line per Content, then any line value greater than 0 equates to no line to print. if ((main->setting.flag & fss_read_main_flag_line_e) && (main->setting.flag & fss_read_main_flag_line_single_e)) { if (main->setting.line) { - if (main->setting.flag & fss_read_main_flag_total_e) { - fss_read_print_number(&main->program.output, 0); - } - main->setting.state.status = F_none; return; @@ -158,34 +154,7 @@ extern "C" { // If using "--at" for standards that only support one line per Object, then the only valid line is line 0. if ((main->setting.flag & fss_read_main_flag_line_single_e) && !at) break; - if (main->setting.flag & fss_read_main_flag_total_e) { - f_array_length_t total = 0; - f_array_length_t j = 0; - f_array_length_t k = 0; - f_array_length_t l = 0; - - for (; j < main->setting.contents.array[i].used; ++j) { - - if (main->setting.contents.array[i].array[j].start > main->setting.contents.array[i].array[j].stop) continue; - - if (l < main->setting.comments.used) { - while (main->setting.comments.array[l].stop < k) ++l; - - if (k >= main->setting.comments.array[l].start && k <= main->setting.comments.array[l].stop) { - k = main->setting.comments.array[l++].stop; - - continue; - } - } - - total = 1; - - break; - } // for - - fss_read_print_number(&main->program.output, total); - } - else if (main->callback.process_at_line) { + if (main->callback.process_at_line) { f_array_length_t line = 0; main->callback.process_at_line(void_main, i, delimits_object, delimits_content, &line); @@ -194,49 +163,6 @@ extern "C" { else if (main->setting.flag & fss_read_main_flag_columns_e) { fss_read_print_number(&main->program.output, main->setting.contents.array[i].used); } - else if (main->setting.flag & fss_read_main_flag_total_e) { - if (main->setting.flag & fss_read_main_flag_line_single_e) { - fss_read_print_number(&main->program.output, main->setting.contents.array[i].used ? 1 : 0); - } - else { - f_array_length_t total = 0; - f_string_range_t range = f_string_range_t_initialize; - f_array_length_t j = 0; - f_array_length_t k = 0; - f_array_length_t l = 0; - - for (; j < main->setting.contents.array[i].used; ++j) { - - range.start = main->setting.contents.array[i].array[j].start; - range.stop = main->setting.contents.array[i].array[j].stop; - - // This content has no data, do not even check "include empty" because it cannot be counted as a line. - if (range.start > range.stop) continue; - - for (k = range.start; k <= range.stop; ++k) { - - if (l < main->setting.comments.used) { - while (main->setting.comments.array[l].stop < k) ++l; - - if (k >= main->setting.comments.array[l].start && k <= main->setting.comments.array[l].stop) { - k = main->setting.comments.array[l++].stop; - - continue; - } - } - - if (main->setting.buffer.string[k] == f_string_eol_s.string[0]) ++total; - } // for - } // for - - // If there are no newline characters but there is data, then this represents a single line. - if (main->setting.contents.array[i].used && !total) { - total = 1; - } - - fss_read_print_number(&main->program.output, total); - } - } else if (main->callback.print_at) { main->callback.print_at(&main->program.output, i, delimits_object, delimits_content); } @@ -274,12 +200,14 @@ extern "C" { main->callback.print_object(&main->program.output, at, delimits_object); } - if (main->callback.print_object_end) { // @todo need to handle object end only if content is not being printed or object end is not white space. + if (main->callback.print_object_end) { main->callback.print_object_end(&main->program.output); } if (!(main->setting.flag & fss_read_main_flag_content_e)) { - f_print_dynamic_raw(f_string_eol_s, main->program.output.to); + if (!(main->setting.flag & fss_read_main_flag_object_as_line_e)) { + f_print_dynamic_raw(f_string_eol_s, main->program.output.to); + } main->setting.state.status = F_success; @@ -358,7 +286,7 @@ extern "C" { while (main->setting.comments.array[k].stop < j) ++k; if (j >= main->setting.comments.array[k].start && j <= main->setting.comments.array[k].stop) { - j = main->setting.comments.array[k++].stop; + j = main->setting.comments.array[k++].stop + 1; if (j > main->setting.range.stop) break; } @@ -384,8 +312,7 @@ extern "C" { } // for // If Content does not end with a newline, it still must be treated as the last line. - if (*line == line_original) { - //if (main->setting.buffer.string[main->setting.range.stop] != f_string_eol_s.string[0]) { + if ((main->setting.flag & fss_read_main_flag_line_single_e) && *line == line_original) { ++(*line); if (*line == main->setting.line) { @@ -401,6 +328,22 @@ extern "C" { } } // for } + + // @fixme The fll_fss_*_read functions do not have a store of the set closing ranges but should. + // Simulate the ending by printing, but the original range should ideally be used (add new features to accomplish this). + if ((main->setting.flag & fss_read_main_flag_object_e) && (main->setting.flag & fss_read_main_flag_content_has_close_e)) { + if (*line == main->setting.line) { + if (main->callback.print_set_end) { + main->callback.print_set_end(&main->program.output); + } + + main->setting.state.status = F_success; + + return; + } + + ++(*line); + } } main->setting.state.status = F_none; @@ -466,7 +409,7 @@ extern "C" { memset(names, F_false, sizeof(bool) * main->setting.objects.used); - if (main->setting.flag & (fss_read_main_flag_trim_e | fss_read_main_flag_trim_object_e)) { + if (main->setting.flag & (fss_read_main_flag_trim_e | fss_read_main_flag_trim_object_e | fss_read_main_flag_object_trim_e)) { for (i = 0; i < main->setting.objects.used; ++i) { if (fss_read_signal_check(main)) return; @@ -511,6 +454,10 @@ extern "C" { if (!names[i]) continue; if (fss_read_signal_check(main)) return; + if (main->setting.flag & fss_read_main_flag_at_e) { + if (main->setting.depths.array[0].value_at != i) continue; + } + if (main->setting.select < main->setting.contents.array[i].used && main->setting.contents.array[i].array[main->setting.select].start <= main->setting.contents.array[i].array[main->setting.select].stop) { ++total; } @@ -522,6 +469,10 @@ extern "C" { if (!names[i]) continue; if (fss_read_signal_check(main)) return; + if (main->setting.flag & fss_read_main_flag_at_e) { + if (main->setting.depths.array[0].value_at != i) continue; + } + if (!(main->setting.flag & fss_read_main_flag_object_e) && (main->setting.flag & fss_read_main_flag_content_e)) { if (!(main->setting.contents.array[i].used || (main->setting.flag & fss_read_main_flag_empty_e))) continue; } @@ -559,6 +510,10 @@ extern "C" { if (!names[at]) continue; if (fss_read_signal_check(main)) return; + if (main->setting.flag & fss_read_main_flag_at_e) { + if (main->setting.depths.array[0].value_at != at) continue; + } + if (main->setting.flag & fss_read_main_flag_object_e) { ++total; } @@ -592,11 +547,15 @@ extern "C" { } // for // If Content does not end with a newline, it still must be treated as the last line. - if (i) { + if ((main->setting.flag & fss_read_main_flag_line_single_e) && i) { j = main->setting.contents.array[at].array[i - 1].stop; if (main->setting.buffer.string[j] != f_string_eol_s.string[0]) ++total; } + + if ((main->setting.flag & fss_read_main_flag_object_e) && (main->setting.flag & fss_read_main_flag_content_has_close_e)) { + ++total; + } } } // for diff --git a/level_3/fss_read/c/payload/main.c b/level_3/fss_read/c/payload/main.c index 05f7882..aa29134 100644 --- a/level_3/fss_read/c/payload/main.c +++ b/level_3/fss_read/c/payload/main.c @@ -17,7 +17,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.output.custom = (void *) &data; data.program.warning.custom = (void *) &data; - data.setting.flag |= fss_read_main_flag_object_as_line_e; + data.setting.flag |= fss_read_main_flag_object_as_line_e | fss_read_main_flag_object_trim_e; data.setting.state.custom = (void *) &data; data.setting.standard = fss_read_payload_standard_s; @@ -36,9 +36,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.print_at = &fss_read_print_at; data.callback.print_content = &fss_read_print_content; data.callback.print_content_ignore = &fss_read_print_content_ignore; + data.callback.print_content_next = 0; data.callback.print_object = &fss_read_print_object; data.callback.print_object_end = &fss_read_payload_print_object_end; - data.callback.print_set_end = &fss_read_print_set_end; + data.callback.print_set_end = &fss_read_print_set_end_no_eol; f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize; data.program.parameters.array = parameters; -- 1.8.3.1