From 50ddbe2631b446920ed32cbb4a76c9a5f0d58fc6 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 16 Dec 2024 21:37:55 -0600 Subject: [PATCH] Progress: Continue fixing iki_read (and eki_read). This addresses some of the `--total` processing. It looks like I had not completed a lot of that code. Much of that is added back. I also noticed that I need to keep tabs on the `--select` parameter. I will need tests for this and I may have missed some logic cases. My first objective is to just get the 0.6.x runtime tests to work in 0.7.x. (Or, I need to fix the 0.6.x tests to be correct.) The expected next steps: - Review and address what is left for IKI Read that is incorrect. - For anything identified in the 0.6.x runtime tests that is invalid shall be fixed in 0.6.x. - Update the EKI Read with all of the changes from IKI Read. - Make a copy of the IKI Read runtime tests and see how EKI Read passes or fails. - Address unexpected failures. - Fix the tests for expected failures, which would be relating to having multiple Vocabularies/Objects. - Write all of the new runtime tests for EKI Read. - Make sure everything all passes. - I probably need to update the help and describe the order of operations for some parameters. --- level_3/iki_read/c/eki/process.c | 95 +++++++++++++++++++++--------------- level_3/iki_read/c/eki/process.h | 38 +++++++++------ level_3/iki_read/c/iki/process.c | 93 ++++++++++++++++++----------------- level_3/iki_read/c/iki/process.h | 14 +++--- level_3/iki_read/c/main/print/data.c | 17 +++++-- level_3/iki_read/c/main/print/data.h | 33 +++++++------ level_3/iki_read/c/main/process.c | 9 ++++ level_3/iki_read/c/main/process.h | 21 ++++++++ 8 files changed, 194 insertions(+), 126 deletions(-) diff --git a/level_3/iki_read/c/eki/process.c b/level_3/iki_read/c/eki/process.c index 006a7c2..3d66ae3 100644 --- a/level_3/iki_read/c/eki/process.c +++ b/level_3/iki_read/c/eki/process.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_iki_read_eki_process_buffer_line_ - void iki_read_eki_process_buffer_line(iki_read_main_t * const main, const f_number_unsigned_t index) { +#ifndef _di_iki_read_iki_process_buffer_at_ + void iki_read_eki_process_buffer_at(iki_read_main_t * const main, const f_number_unsigned_t index) { if (!main || F_status_is_error(main->setting.state.status)) return; @@ -207,7 +207,7 @@ extern "C" { main->setting.state.status = main->cache.expand.used ? F_okay : F_data_not; } -#endif // _di_iki_read_eki_process_buffer_line_ +#endif // _di_iki_read_iki_process_buffer_at_ #ifndef _di_iki_read_eki_process_buffer_ranges_ void iki_read_eki_process_buffer_ranges(iki_read_main_t * const main, f_range_t * const range_buffer) { @@ -223,7 +223,7 @@ extern "C" { if ((main->setting.flag & iki_read_main_flag_at_d) && (main->setting.flag & iki_read_main_flag_line_d)) { if ((main->setting.flag & iki_read_main_flag_object_d) && main->setting.line) { if (main->setting.flag & iki_read_main_flag_total_d) { - fll_print_format("0%r", main->program.output.to, f_string_eol_s); + iki_read_print_data_total(&main->program.output, 0); } main->setting.state.status = F_data_not; @@ -272,22 +272,14 @@ extern "C" { ++matches; } - if (main->setting.flag & iki_read_main_flag_line_d) { // @todo handle --at. - iki_read_eki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + if (main->setting.flag & (iki_read_main_flag_at_d | iki_read_main_flag_line_d)) { + iki_read_eki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } } else if (main->setting.flag & iki_read_main_flag_line_d) { - iki_read_eki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_eki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } else { f_file_stream_lock(main->program.output.to); @@ -307,21 +299,21 @@ extern "C" { if (main->setting.flag & iki_read_main_flag_line_d) { if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } - else if ((main->setting.flag & iki_read_main_flag_total_d)) { - iki_read_print_data_total( - &main->program.output, - (main->setting.flag & iki_read_main_flag_line_d) - ? main->setting.at < matches ? 1 : 0 - : matches - ); + else if (main->setting.flag & iki_read_main_flag_total_d) { + if (main->setting.flag & iki_read_main_flag_at_d) { + iki_read_print_data_total_expand(&main->program.output); + } + else { + iki_read_print_data_total(&main->program.output, matches); + } - main->setting.state.status = F_okay; + main->setting.state.status = matched ? F_okay : F_data_not; return; } @@ -336,20 +328,27 @@ extern "C" { if (main->setting.flag & iki_read_main_flag_at_d) { if (main->setting.at < data->variable.used) { if (main->setting.flag & iki_read_main_flag_line_d) { - iki_read_eki_process_buffer_line(main, main->setting.at); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_eki_process_buffer_at(main, main->setting.at); + iki_read_process_buffer_at_newline(main); if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } + else if (main->setting.flag & iki_read_main_flag_total_d) { + if (main->setting.flag & iki_read_main_flag_object_d) { + iki_read_print_data_total(&main->program.output, ((main->setting.flag & iki_read_main_flag_select_d) && main->setting.select) ? 0 : 1); + } + else { + iki_read_eki_process_buffer_at(main, main->setting.at); + iki_read_process_buffer_at_newline(main); + + iki_read_print_data_total_expand(&main->program.output); + } + } else { f_file_stream_lock(main->program.output.to); @@ -369,6 +368,10 @@ extern "C" { } } else { + if (main->setting.flag & iki_read_main_flag_total_d) { + iki_read_print_data_total(&main->program.output, 0); + } + main->setting.state.status = F_data_not; } } @@ -377,21 +380,33 @@ extern "C" { if (iki_read_signal_check(main)) return; - iki_read_eki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_eki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } // for if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } + else if (main->setting.flag & iki_read_main_flag_total_d) { + if (main->setting.flag & iki_read_main_flag_object_d) { + iki_read_print_data_total(&main->program.output, ((main->setting.flag & iki_read_main_flag_select_d) && main->setting.select) ? 0 : data->variable.used); + } + else { + for (i = 0; F_status_is_error_not(main->setting.state.status) && i < data->variable.used; ++i) { + + if (iki_read_signal_check(main)) return; + + iki_read_eki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); + } // for + + iki_read_print_data_total_expand(&main->program.output); + } + } else { f_file_stream_lock(main->program.output.to); diff --git a/level_3/iki_read/c/eki/process.h b/level_3/iki_read/c/eki/process.h index 492c837..56d8e15 100644 --- a/level_3/iki_read/c/eki/process.h +++ b/level_3/iki_read/c/eki/process.h @@ -17,33 +17,43 @@ extern "C" { #endif /** - * Print the given range at the given index for EKI read, for when printing a single Line in Content and Literal modes. + * Process the given range at the given index for EKI read. * - * This expects the caller to have the output locked appropriately. + * This expands all of the appropriate Variables so that post-expansion calculations may be performed. + * This is particularly useful for preparing to print a single Line in Content and Literal modes. * - * This detects and prints any applicable substitution matching the vocabulary at the given index. - * If there is no substitution, then this prints the given range at the given index. + * @param main + * The main program data. * - * @param print - * The output structure to print to. + * Must not be NULL. * * The setting.map_wrapss is expected to be defined as a valid pointer to an array. * The setting.map_replacess is expected to be defined as a valid pointer to an array. * - * This does not alter print.custom.setting.state.status. + * This alters setting.state.status: + * F_okay on success. + * F_data_not on success, but nothing done. + * + * F_interrupt (with error bit) on (exit) signal received. + * + * Errors (with error bit) from: f_string_dynamic_append_nulless(). + * Errors (with error bit) from: f_string_dynamic_partial_append_nulless(). + * + * Errors (with error bit) from: iki_read_process_wrap_append(). + * Errors (with error bit) from: iki_read_process_wrap_prepend(). * @param index * The index used to identify the desired range in variable, content, and ranges. * - * @see f_print_dynamic() - * @see f_print_dynamic_partial() + * @see f_string_dynamic_append_nulless() + * @see f_string_dynamic_partial_append_nulless() * * @see iki_read_identify_substitution() - * @see iki_read_print_data_wrap_append() - * @see iki_read_print_data_wrap_prepend() + * @see iki_read_process_wrap_append() + * @see iki_read_process_wrap_prepend() */ -#ifndef _di_iki_read_eki_process_buffer_line_ - extern void iki_read_eki_process_buffer_line(iki_read_main_t * const main, const f_number_unsigned_t index); -#endif // _di_iki_read_eki_process_buffer_line_ +#ifndef _di_iki_read_eki_process_buffer_at_ + extern void iki_read_eki_process_buffer_at(iki_read_main_t * const main, const f_number_unsigned_t index); +#endif // _di_iki_read_eki_process_buffer_at_ /** * Process a given buffer, printing the given range for EKI read. diff --git a/level_3/iki_read/c/iki/process.c b/level_3/iki_read/c/iki/process.c index 6d0b0a7..27e2adf 100644 --- a/level_3/iki_read/c/iki/process.c +++ b/level_3/iki_read/c/iki/process.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_iki_read_iki_process_buffer_line_ - void iki_read_iki_process_buffer_line(iki_read_main_t * const main, const f_number_unsigned_t index) { +#ifndef _di_iki_read_iki_process_buffer_at_ + void iki_read_iki_process_buffer_at(iki_read_main_t * const main, const f_number_unsigned_t index) { if (!main || F_status_is_error(main->setting.state.status)) return; @@ -179,7 +179,7 @@ extern "C" { main->setting.state.status = main->cache.expand.used == original ? F_data_not : F_okay; } -#endif // _di_iki_read_iki_process_buffer_line_ +#endif // _di_iki_read_iki_process_buffer_at_ #ifndef _di_iki_read_iki_process_buffer_ranges_ void iki_read_iki_process_buffer_ranges(iki_read_main_t * const main, f_range_t * const range_buffer) { @@ -195,7 +195,7 @@ extern "C" { if ((main->setting.flag & iki_read_main_flag_at_d) && (main->setting.flag & iki_read_main_flag_line_d)) { if ((main->setting.flag & iki_read_main_flag_object_d) && main->setting.line) { if (main->setting.flag & iki_read_main_flag_total_d) { - fll_print_format("0%r", main->program.output.to, f_string_eol_s); + iki_read_print_data_total(&main->program.output, 0); } main->setting.state.status = F_data_not; @@ -239,22 +239,14 @@ extern "C" { ++matches; } - if (main->setting.flag & iki_read_main_flag_line_d) { // @todo handle --at. - iki_read_iki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + if (main->setting.flag & (iki_read_main_flag_at_d | iki_read_main_flag_line_d)) { + iki_read_iki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } } else if (main->setting.flag & iki_read_main_flag_line_d) { - iki_read_iki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_iki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } else { f_file_stream_lock(main->program.output.to); @@ -273,25 +265,15 @@ extern "C" { if (main->setting.flag & iki_read_main_flag_line_d) { if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } else if (main->setting.flag & iki_read_main_flag_total_d) { - if (main->setting.flag & iki_read_main_flag_line_d) { - for (i = 0; F_status_is_error_not(main->setting.state.status) && i < data->variable.used; ++i) { - - if (iki_read_signal_check(main)) return; - - iki_read_iki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } - } // for + if (main->setting.flag & iki_read_main_flag_at_d) { + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_total(&main->program.output, matches); @@ -309,20 +291,27 @@ extern "C" { if (main->setting.flag & iki_read_main_flag_at_d) { if (main->setting.at < data->variable.used) { if (main->setting.flag & iki_read_main_flag_line_d) { - iki_read_iki_process_buffer_line(main, main->setting.at); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_iki_process_buffer_at(main, main->setting.at); + iki_read_process_buffer_at_newline(main); if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } + else if (main->setting.flag & iki_read_main_flag_total_d) { + if (main->setting.flag & iki_read_main_flag_object_d) { + iki_read_print_data_total(&main->program.output, ((main->setting.flag & iki_read_main_flag_select_d) && main->setting.select) ? 0 : 1); + } + else { + iki_read_iki_process_buffer_at(main, main->setting.at); + iki_read_process_buffer_at_newline(main); + + iki_read_print_data_total_expand(&main->program.output); + } + } else { f_file_stream_lock(main->program.output.to); @@ -340,6 +329,10 @@ extern "C" { } } else { + if (main->setting.flag & iki_read_main_flag_total_d) { + iki_read_print_data_total(&main->program.output, 0); + } + main->setting.state.status = F_data_not; } } @@ -348,21 +341,33 @@ extern "C" { if (iki_read_signal_check(main)) return; - iki_read_iki_process_buffer_line(main, i); - - // Ensure that a newline is always at the end. - if (main->setting.state.status == F_okay) { - main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); - } + iki_read_iki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); } // for if (main->setting.flag & iki_read_main_flag_total_d) { - iki_read_print_data_line_total(&main->program.output); + iki_read_print_data_total_expand(&main->program.output); } else { iki_read_print_data_line(&main->program.output); } } + else if (main->setting.flag & iki_read_main_flag_total_d) { + if (main->setting.flag & iki_read_main_flag_object_d) { + iki_read_print_data_total(&main->program.output, ((main->setting.flag & iki_read_main_flag_select_d) && main->setting.select) ? 0 : data->variable.used); + } + else { + for (i = 0; F_status_is_error_not(main->setting.state.status) && i < data->variable.used; ++i) { + + if (iki_read_signal_check(main)) return; + + iki_read_iki_process_buffer_at(main, i); + iki_read_process_buffer_at_newline(main); + } // for + + iki_read_print_data_total_expand(&main->program.output); + } + } else { f_file_stream_lock(main->program.output.to); diff --git a/level_3/iki_read/c/iki/process.h b/level_3/iki_read/c/iki/process.h index d84896b..47b7e58 100644 --- a/level_3/iki_read/c/iki/process.h +++ b/level_3/iki_read/c/iki/process.h @@ -17,12 +17,10 @@ extern "C" { #endif /** - * Process and print the given range at the given index for IKI read, for when printing a single Line in Content and Literal modes. + * Process the given range at the given index for IKI read. * - * This expects the caller to have the output locked appropriately.???? - * - * This detects and prints any applicable substitution matching the vocabulary at the given index. - * If there is no substitution, then this prints the given range at the given index. + * This expands all of the appropriate Variables so that post-expansion calculations may be performed. + * This is particularly useful for preparing to print a single Line in Content and Literal modes. * * @param main * The main program data. @@ -53,9 +51,9 @@ extern "C" { * @see iki_read_process_wrap_append() * @see iki_read_process_wrap_prepend() */ -#ifndef _di_iki_read_iki_process_buffer_line_ - extern void iki_read_iki_process_buffer_line(iki_read_main_t * const main, const f_number_unsigned_t index); -#endif // _di_iki_read_iki_process_buffer_line_ +#ifndef _di_iki_read_iki_process_buffer_at_ + extern void iki_read_iki_process_buffer_at(iki_read_main_t * const main, const f_number_unsigned_t index); +#endif // _di_iki_read_iki_process_buffer_at_ /** * Process a given buffer, printing the given range for IKI read. diff --git a/level_3/iki_read/c/main/print/data.c b/level_3/iki_read/c/main/print/data.c index 08e68b4..4d9c99a 100644 --- a/level_3/iki_read/c/main/print/data.c +++ b/level_3/iki_read/c/main/print/data.c @@ -51,8 +51,8 @@ extern "C" { } #endif // _di_iki_read_print_data_line_ -#ifndef _di_iki_read_print_data_line_total_ - void iki_read_print_data_line_total(fl_print_t * const print) { +#ifndef _di_iki_read_print_data_line_total_expand_ + void iki_read_print_data_total_expand(fl_print_t * const print) { if (!print || !print->custom) return; @@ -74,11 +74,18 @@ extern "C" { } // for } - iki_read_print_data_total(print, main->setting.line < total ? 1 : 0); + iki_read_print_data_total( + print, + (main->setting.flag & iki_read_main_flag_line_d) + ? main->setting.line < total ? 1 : 0 + : total + ); - main->setting.state.status = main->setting.line < total ? F_okay : F_data_not; + main->setting.state.status = (main->setting.flag & iki_read_main_flag_line_d) + ? main->setting.line < total ? F_okay : F_data_not + : total ? F_okay : F_data_not; } -#endif // _di_iki_read_print_data_line_total_ +#endif // _di_iki_read_print_data_line_total_expand_ #ifndef _di_iki_read_print_data_total_ void iki_read_print_data_total(fl_print_t * const print, const f_number_unsigned_t total) { diff --git a/level_3/iki_read/c/main/print/data.h b/level_3/iki_read/c/main/print/data.h index d2fd0b9..106b5d4 100644 --- a/level_3/iki_read/c/main/print/data.h +++ b/level_3/iki_read/c/main/print/data.h @@ -32,21 +32,6 @@ extern "C" { #endif // _di_iki_read_print_data_line_ /** - * Print the total from the data in the expand cache at the line. - * - * This requires that the expand cache is properly populated. - * The expand cache may be empty. - * - * @param print - * The output structure to print to. - * - * This does not alter print.custom.setting.state.status. - */ -#ifndef _di_iki_read_print_data_line_total_ - extern void iki_read_print_data_line_total(fl_print_t * const print); -#endif // _di_iki_read_print_data_line_total_ - -/** * Print the number that represents the total. * * @param print @@ -69,6 +54,24 @@ extern "C" { #endif // _di_iki_read_print_data_total_ /** + * Count and print the total from the data in the expand cache at the line. + * + * This requires that the expand cache is properly populated. + * The expand cache may be empty. + * + * This only checks if the flag iki_read_main_flag_line_d is set. + * Otherwise, the total lines from the expand cache is counted as-is. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + */ +#ifndef _di_iki_read_print_data_line_total_expand_ + extern void iki_read_print_data_total_expand(fl_print_t * const print); +#endif // _di_iki_read_print_data_line_total_expand_ + +/** * Print the append part of the wrap at the given index, if valid. * * This expects the caller to have the output locked appropriately. diff --git a/level_3/iki_read/c/main/process.c b/level_3/iki_read/c/main/process.c index f793cb0..c9f87a6 100644 --- a/level_3/iki_read/c/main/process.c +++ b/level_3/iki_read/c/main/process.c @@ -48,6 +48,15 @@ extern "C" { } #endif // _di_iki_read_process_buffer_ +#ifndef _di_iki_read_process_buffer_at_newline_ + void iki_read_process_buffer_at_newline(iki_read_main_t * const main) { + + if (!main || main->setting.state.status != F_okay) return; + + main->setting.state.status = f_string_dynamic_append(f_string_eol_s, &main->cache.expand); + } +#endif // _di_iki_read_process_buffer_at_newline_ + #ifndef _di_iki_read_process_line_ void iki_read_process_line(iki_read_main_t * const main, f_range_t * const range) { diff --git a/level_3/iki_read/c/main/process.h b/level_3/iki_read/c/main/process.h index 0306446..5080dca 100644 --- a/level_3/iki_read/c/main/process.h +++ b/level_3/iki_read/c/main/process.h @@ -46,6 +46,27 @@ extern "C" { #endif // _di_iki_read_process_buffer_ /** + * Append a new line at the end of the expand cache if the state status is F_okay. + * + * This is intended to be called immediately after iki_read_iki_process_buffer_at() and iki_read_eki_process_buffer_at() to handle the state status. + * + * @param main + * The main program data. + * + * Must not be NULL. + * + * This alters setting.state.status: + * Success from: f_string_dynamic_append() + * + * Errors (with error bit) from: f_string_dynamic_append(). + * + * @see f_string_dynamic_append() + */ +#ifndef _di_iki_read_process_buffer_at_newline_ + extern void iki_read_process_buffer_at_newline(iki_read_main_t * const main); +#endif // _di_iki_read_process_buffer_at_newline_ + +/** * Determine the range based on the --line parameter. * * If the --line parameter is not specified in the console arguments, then range is untouched. -- 1.8.3.1