From 6e6b971f3b67ecc79c119547349c69c5e48f0104 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 13 Jun 2023 21:28:03 -0500 Subject: [PATCH] Progress: Continue working on fss_read. Focus on the Basic and Extended standards. Begin working on Basic List standard. There is already a function fss_read_process_at_line(). Cannibalize that function and turn it into a standard at line normal processor function. Update documentation comments, clarifying the "at" parameter. --- 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 | 3 +- level_3/fss_read/c/extended/main.c | 2 +- level_3/fss_read/c/extended_list/main.c | 4 +- level_3/fss_read/c/main/common.c | 27 ++- level_3/fss_read/c/main/common.h | 8 +- level_3/fss_read/c/main/common/enumeration.h | 24 +-- level_3/fss_read/c/main/common/type.h | 4 +- level_3/fss_read/c/main/fss_read.c | 99 ---------- level_3/fss_read/c/main/fss_read.h | 38 ---- level_3/fss_read/c/main/main.c | 11 +- level_3/fss_read/c/main/print/data.h | 12 +- level_3/fss_read/c/main/process_normal.c | 286 ++++++++++++++++++--------- level_3/fss_read/c/main/process_normal.h | 44 +++-- level_3/fss_read/c/payload/main.c | 4 +- 16 files changed, 291 insertions(+), 281 deletions(-) diff --git a/level_3/fss_read/c/basic/main.c b/level_3/fss_read/c/basic/main.c index ecd2a53..4bb2865 100644 --- a/level_3/fss_read/c/basic/main.c +++ b/level_3/fss_read/c/basic/main.c @@ -28,8 +28,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_basic_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total; diff --git a/level_3/fss_read/c/basic_list/main.c b/level_3/fss_read/c/basic_list/main.c index a2fac6f..7c919f6 100644 --- a/level_3/fss_read/c/basic_list/main.c +++ b/level_3/fss_read/c/basic_list/main.c @@ -17,6 +17,8 @@ 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.state.custom = (void *) &data; data.setting.standard = fss_read_basic_list_standard_s; @@ -25,8 +27,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_basic_list_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total_multiple; diff --git a/level_3/fss_read/c/embedded_list/main.c b/level_3/fss_read/c/embedded_list/main.c index 089e154..ca5972e 100644 --- a/level_3/fss_read/c/embedded_list/main.c +++ b/level_3/fss_read/c/embedded_list/main.c @@ -17,6 +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_depth_multiple_e; data.setting.state.custom = (void *) &data; @@ -27,8 +28,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_embedded_list_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total_multiple; diff --git a/level_3/fss_read/c/extended/main.c b/level_3/fss_read/c/extended/main.c index 673b2c1..ade999d 100644 --- a/level_3/fss_read/c/extended/main.c +++ b/level_3/fss_read/c/extended/main.c @@ -28,8 +28,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_extended_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total; diff --git a/level_3/fss_read/c/extended_list/main.c b/level_3/fss_read/c/extended_list/main.c index 270ca22..7cf68bb 100644 --- a/level_3/fss_read/c/extended_list/main.c +++ b/level_3/fss_read/c/extended_list/main.c @@ -17,6 +17,8 @@ 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.state.custom = (void *) &data; data.setting.standard = fss_read_extended_list_standard_s; @@ -25,8 +27,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_extended_list_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total_multiple; diff --git a/level_3/fss_read/c/main/common.c b/level_3/fss_read/c/main/common.c index 72b979f..7f50795 100644 --- a/level_3/fss_read/c/main/common.c +++ b/level_3/fss_read/c/main/common.c @@ -7,14 +7,33 @@ extern "C" { #ifndef _di_fss_read_ensure_quotes_length_ void fss_read_ensure_quotes_length(fss_read_main_t * const main) { - if (main->setting.quotes_object.size < main->setting.objects.used) { - main->setting.state.status = f_uint8s_increase_by(main->setting.objects.used - main->setting.quotes_object.size, &main->setting.quotes_object); + f_array_length_t i = 0; + f_array_length_t j = 0; + + if (main->setting.quotes_object.used < main->setting.objects.used) { + main->setting.state.status = f_uint8s_resize(main->setting.objects.used, &main->setting.quotes_object); if (F_status_is_error(main->setting.state.status)) return; + + for (i = main->setting.quotes_object.used; i < main->setting.objects.used; ++i) { + main->setting.quotes_object.array[i] = 0; + } // for } - if (main->setting.quotes_content.size < main->setting.contents.used) { - main->setting.state.status = f_uint8ss_increase_by(main->setting.contents.used - main->setting.quotes_content.size, &main->setting.quotes_content); + if (main->setting.quotes_content.used < main->setting.contents.used) { + main->setting.state.status = f_uint8ss_resize(main->setting.contents.used, &main->setting.quotes_content); if (F_status_is_error(main->setting.state.status)) return; + + for (i = main->setting.quotes_content.used; i < main->setting.contents.used; ++i) { + + main->setting.state.status = f_uint8s_resize(main->setting.contents.array[i].used, &main->setting.quotes_content.array[i]); + if (F_status_is_error(main->setting.state.status)) return; + + main->setting.quotes_content.array[i].used = 0; + + for (j = 0; j < main->setting.contents.array[i].used; ++j) { + main->setting.quotes_content.array[i].array[j] = 0; + } // for + } // for } main->setting.state.status = F_none; diff --git a/level_3/fss_read/c/main/common.h b/level_3/fss_read/c/main/common.h index 6469691..a8f3234 100644 --- a/level_3/fss_read/c/main/common.h +++ b/level_3/fss_read/c/main/common.h @@ -25,11 +25,11 @@ extern "C" { * This alters main.setting.state.status: * F_none on success. * - * Errors (with error bit) from: f_uint8s_increase_by(). - * Errors (with error bit) from: f_uint8ss_increase_by(). + * Errors (with error bit) from: f_uint8s_resize(). + * Errors (with error bit) from: f_uint8ss_resize(). * - * @see f_uint8s_increase_by() - * @see f_uint8ss_increase_by() + * @see f_uint8s_resize() + * @see f_uint8ss_resize() */ #ifndef _di_fss_read_ensure_quotes_length_ extern void fss_read_ensure_quotes_length(fss_read_main_t * const main); diff --git a/level_3/fss_read/c/main/common/enumeration.h b/level_3/fss_read/c/main/common/enumeration.h index 7fee9bd..bb55a99 100644 --- a/level_3/fss_read/c/main/common/enumeration.h +++ b/level_3/fss_read/c/main/common/enumeration.h @@ -35,6 +35,7 @@ extern "C" { * - 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. @@ -64,17 +65,18 @@ extern "C" { 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_original_e = 0x4000, - fss_read_main_flag_pipe_e = 0x8000, - fss_read_main_flag_print_first_e = 0x10000, - fss_read_main_flag_print_last_e = 0x20000, - fss_read_main_flag_quote_content_e = 0x40000, - fss_read_main_flag_quote_object_e = 0x80000, - fss_read_main_flag_select_e = 0x100000, - fss_read_main_flag_total_e = 0x200000, - fss_read_main_flag_trim_e = 0x400000, - fss_read_main_flag_trim_object_e = 0x800000, - fss_read_main_flag_version_e = 0x1000000, + 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, }; // enum #endif // _di_fss_read_main_flag_e_ diff --git a/level_3/fss_read/c/main/common/type.h b/level_3/fss_read/c/main/common/type.h index b574f42..30cbe5b 100644 --- a/level_3/fss_read/c/main/common/type.h +++ b/level_3/fss_read/c/main/common/type.h @@ -124,8 +124,8 @@ extern "C" { * process_normal: Process normally (data from parameters and files). * * process_at: Process at parameter, usually called by the process_normal() callback. + * process_at_line: Process line parameter for some Object index position, usually called by the process_normal() callback. * process_columns: Process columns parameter, usually called by the process_normal() callback. - * process_line: Process line parameter, usually called by the process_normal() callback. * process_load: Process loading of FSS data from buffer (not to be confused with loading settings), usually called by the process_normal() callback. * process_name: Process name parameter, usually called by the process_normal() callback. * process_total: Process total parameter, usually called by the process_normal() callback. @@ -145,8 +145,8 @@ extern "C" { void (*process_normal)(void * const main); void (*process_at)(void * const main, const bool names[], const f_fss_delimits_t delimits_object, const f_fss_delimits_t delimits_content); + void (*process_at_line)(void * const void_main, const f_array_length_t at, const f_array_lengths_t delimits_object, const f_array_lengths_t delimits_content, f_number_unsigned_t * const line); void (*process_columns)(void * const main, const bool names[]); - void (*process_line)(void * const main, const bool names[]); void (*process_load)(void * const main); void (*process_name)(void * const main, bool names[]); void (*process_total)(void * const main, const bool names[]); diff --git a/level_3/fss_read/c/main/fss_read.c b/level_3/fss_read/c/main/fss_read.c index 3f1b58e..19bbe73 100644 --- a/level_3/fss_read/c/main/fss_read.c +++ b/level_3/fss_read/c/main/fss_read.c @@ -101,105 +101,6 @@ extern "C" { } #endif // _di_fss_read_main_ -#ifndef _di_fss_read_process_at_line_ - void fss_read_process_at_line(fss_read_main_t * const main, const f_array_length_t at, const f_array_lengths_t delimits_object, const f_array_lengths_t delimits_content, f_array_length_t * const line) { - - if (!main || !line) return; - - if (main->setting.flag & fss_read_main_flag_object_e) { - if (*line == main->setting.line) { - if (main->setting.flag & fss_read_main_flag_total_e) { - fss_read_print_number(&main->program.output, 1); - } - else { - if (main->callback.print_object) { - main->callback.print_object(&main->program.output, at, delimits_object); - } - - if (main->callback.print_object_end) { - main->callback.print_object_end(&main->program.output); - } - } - - main->setting.state.status = F_success; - - return; - } - - ++(*line); - } - - // There is only a single Content column for this standard. - if (main->setting.flag & fss_read_main_flag_content_e) { - if (!main->setting.contents.array[at].used) { - main->setting.state.status = F_none; - - return; - } - - f_string_range_t range = main->setting.contents.array[at].array[0]; - - // This content has no data, do not even check "include empty" because it cannot be counted as a line. - if (range.start > range.stop) { - main->setting.state.status = F_none; - - return; - } - - for (f_array_length_t i = range.start; i <= range.stop; ++i) { - - if (fss_read_signal_check(main)) return; - - if (main->setting.buffer.string[i] == f_string_eol_s.string[0]) { - if (*line == main->setting.line) { - range.stop = i; - - if (main->setting.flag & fss_read_main_flag_total_e) { - fss_read_print_number(&main->program.output, 1); - } - else { - fss_read_print_content(&main->program.output, range, main->setting.quotes_content.array[at].array[0], delimits_content); - } - - main->setting.state.status = F_success; - - return; - } - - range.start = i + 1; - - if (i <= range.stop) { - ++(*line); - } - } - } // for - - // If Content does not end with a newline, it still must be treated as the last line. - if (main->setting.buffer.string[range.stop] != f_string_eol_s.string[0]) { - ++(*line); - - if (*line == main->setting.line) { - if (main->setting.flag & fss_read_main_flag_total_e) { - fss_read_print_number(&main->program.output, 1); - } - else { - range.stop = main->setting.contents.array[at].array[0].stop; - - fss_read_print_content(&main->program.output, range, main->setting.quotes_content.array[at].array[0], delimits_content); - f_print_dynamic_raw(f_string_eol_s, main->program.output.to); - } - - main->setting.state.status = F_success; - - return; - } - } - } - - main->setting.state.status = F_none; - } -#endif // _di_fss_read_process_at_line_ - #ifndef _di_fss_read_file_identify_ f_string_static_t fss_read_file_identify(const f_array_length_t at, const fss_read_files_t files) { diff --git a/level_3/fss_read/c/main/fss_read.h b/level_3/fss_read/c/main/fss_read.h index 0f57c42..388bbd4 100644 --- a/level_3/fss_read/c/main/fss_read.h +++ b/level_3/fss_read/c/main/fss_read.h @@ -135,44 +135,6 @@ extern "C" { #endif // _di_fss_read_main_ /** - * Process based on at parameter for a specific line. - * - * @param main - * The program and settings data. - * - * Must not be NULL. - * Must be of type fss_read_main_t. - * - * This alters main.setting.state.status: - * F_none on success. - * - * F_parameter (with error bit) if main is NULL or setting is NULL. - * - * Errors (with error bit) from: f_string_dynamic_append_assure(). - * - * Errors (with error bit) from: fss_read_signal_check(). - * @param at - * The "at" position to be printed. - * @param delimits_object - * The delimits array representing a delimited Object. - * This represents the positions within the current Object at the "at" position. - * @param delimits_content - * The delimits array representing a delimited Content. - * This represents the positions within the current Content at the "at" position. - * @param line - * The current line being processed. - * This will be incremented as necessary. - * - * Must not be NULL. - * - * @return - * F_none on success. - */ -#ifndef _di_fss_read_process_at_line_ - extern void fss_read_process_at_line(fss_read_main_t * const main, const f_array_length_t at, const f_array_lengths_t delimits_object, const f_array_lengths_t delimits_content, f_array_length_t * const line); -#endif // _di_fss_read_process_at_line_ - -/** * Get the name of the file the given position represents within the buffer. * * @param at diff --git a/level_3/fss_read/c/main/main.c b/level_3/fss_read/c/main/main.c index a9e647d..2b7053e 100644 --- a/level_3/fss_read/c/main/main.c +++ b/level_3/fss_read/c/main/main.c @@ -103,8 +103,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { main->callback.process_normal = &fss_read_process_normal; main->callback.process_at = &fss_read_process_normal_at; + main->callback.process_at_line = &fss_read_process_normal_at_line; main->callback.process_columns = &fss_read_process_normal_columns; - main->callback.process_line = &fss_read_process_normal_line; main->callback.process_load = 0; main->callback.process_name = &fss_read_process_normal_name; main->callback.process_total = 0; @@ -136,6 +136,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { // Remove flags not supported for this standard. 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_trim_object_e; main->setting.flag |= fss_read_main_flag_line_single_e; @@ -158,6 +159,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { // Remove flags not supported for this standard. 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_trim_object_e; main->setting.flag |= fss_read_main_flag_line_single_e | fss_read_main_flag_content_multiple_e; @@ -185,6 +187,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->callback.process_help = &fss_read_basic_list_process_help; main->callback.process_load = &fss_read_basic_list_process_load; main->callback.process_total = &fss_read_process_normal_total_multiple; @@ -207,6 +211,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->callback.process_help = &fss_read_extended_list_process_help; main->callback.process_load = &fss_read_extended_list_process_load; main->callback.process_total = &fss_read_process_normal_total_multiple; @@ -228,6 +234,7 @@ 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_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->callback.process_help = &fss_read_embedded_list_process_help; main->callback.process_load = &fss_read_embedded_list_process_load; @@ -251,6 +258,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->callback.process_help = &fss_read_payload_process_help; main->callback.process_load = &fss_read_payload_process_load; main->callback.process_total = &fss_read_process_normal_total_multiple; diff --git a/level_3/fss_read/c/main/print/data.h b/level_3/fss_read/c/main/print/data.h index 0ee9be8..479f303 100644 --- a/level_3/fss_read/c/main/print/data.h +++ b/level_3/fss_read/c/main/print/data.h @@ -17,7 +17,7 @@ extern "C" { #endif /** - * Process printing the buffer according to "at" position and given delimits. + * Process printing the buffer according to an Object index position and given delimits. * * This locks, uses, and unlocks the file stream. * @@ -30,7 +30,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param at - * The "at" position to be printed. + * The Object index to be printed. * @param delimits_object * The delimits array representing a delimited Object. * This represents the positions within the current Object at the "at" position. @@ -145,7 +145,7 @@ extern "C" { #endif // _di_fss_read_print_number_ /** - * Print the Object at the given position. + * Print the Object at the given Object index position. * * This locks, uses, and unlocks the file stream. * @@ -158,7 +158,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param at - * The "at" position to be printed. + * The Object index to be printed. * @param delimits * The delimits array representing a delimited Object. * This represents the positions within the current Object at the "at" position. @@ -181,7 +181,7 @@ extern "C" { #endif // _di_fss_read_print_object_ /** - * Print the Object at the given position. + * Print the Object at the given Object index position. * * This locks, uses, and unlocks the file stream. * @@ -192,7 +192,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param at - * The "at" position to be printed. + * The Object index position to be printed. * @param delimits * The delimits array representing a delimited Object. * This represents the positions within the current Object at the "at" position. diff --git a/level_3/fss_read/c/main/process_normal.c b/level_3/fss_read/c/main/process_normal.c index f701014..a25f72e 100644 --- a/level_3/fss_read/c/main/process_normal.c +++ b/level_3/fss_read/c/main/process_normal.c @@ -69,44 +69,47 @@ extern "C" { if (main->callback.process_at) { main->callback.process_at(main, names, *delimits_object, *delimits_content); } - - return; } - - if (main->setting.flag & fss_read_main_flag_columns_e) { + else if (main->setting.flag & fss_read_main_flag_columns_e) { if (main->callback.process_columns) { main->callback.process_columns(main, names); } - - return; } - - if (main->setting.flag & fss_read_main_flag_total_e) { + else if (main->setting.flag & fss_read_main_flag_total_e) { if (main->callback.process_total) { main->callback.process_total(main, names); } - - return; } + else { + f_array_length_t i = 0; - if (main->setting.flag & fss_read_main_flag_line_e) { - if (main->callback.process_line) { - main->callback.process_line(main, names); - } + if (main->setting.flag & fss_read_main_flag_line_e) { + if (main->callback.process_at_line) { + f_number_unsigned_t line = 0; - return; - } + for (; i < main->setting.contents.used && main->setting.state.status != F_success; ++i) { - if (main->callback.print_at) { - for (f_array_length_t i = 0; i < main->setting.contents.used; ++i) { + if (!names[i]) continue; + if (fss_read_signal_check(main)) return; - if (!names[i]) continue; - if (fss_read_signal_check(main)) return; + main->callback.process_at_line(void_main, i, *delimits_object, *delimits_content, &line); + if (F_status_is_error(main->setting.state.status)) return; + } // for + } + } + else if (main->callback.print_at) { + for (; i < main->setting.contents.used; ++i) { - main->callback.print_at(&main->program.output, i, *delimits_object, *delimits_content); - } // for + if (!names[i]) continue; + if (fss_read_signal_check(main)) return; + + main->callback.print_at(&main->program.output, i, *delimits_object, *delimits_content); + } // for + } } + if (F_status_is_error(main->setting.state.status)) return; + main->setting.state.status = F_none; } #endif // _di_fss_read_process_normal_ @@ -129,7 +132,7 @@ 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 | fss_read_main_flag_line_single_e) == (fss_read_main_flag_line_e | fss_read_main_flag_line_single_e)) { + 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); @@ -142,13 +145,7 @@ extern "C" { } f_array_length_t i = 0; - f_array_length_t j = 0; - f_array_length_t k = 0; - f_array_length_t l = 0; f_array_length_t at = 0; - f_array_length_t line = 0; - f_array_length_t total = 0; - f_string_range_t range = f_string_range_t_initialize; for (; i < main->setting.objects.used; ++i) { @@ -161,13 +158,13 @@ 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; - line = 0; - if (main->setting.flag & fss_read_main_flag_total_e) { - total = 0; - l = 0; + 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 = 0; j < main->setting.contents.array[i].used; ++j) { + 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; @@ -188,8 +185,10 @@ extern "C" { fss_read_print_number(&main->program.output, total); } - else { - fss_read_process_at_line(main, i, delimits_object, delimits_content, &line); + else 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); } } else if (main->setting.flag & fss_read_main_flag_columns_e) { @@ -200,10 +199,13 @@ extern "C" { fss_read_print_number(&main->program.output, main->setting.contents.array[i].used ? 1 : 0); } else { - total = 0; - l = 0; + 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 = 0; j < main->setting.contents.array[i].used; ++j) { + 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; @@ -239,6 +241,8 @@ extern "C" { main->callback.print_at(&main->program.output, i, delimits_object, delimits_content); } + if (F_status_is_error(main->setting.state.status)) return; + main->setting.state.status = F_none; return; @@ -247,6 +251,8 @@ extern "C" { ++at; } // for + if (F_status_is_error(main->setting.state.status)) return; + if (main->setting.flag & fss_read_main_flag_total_e) { fss_read_print_number(&main->program.output, 0); } @@ -255,6 +261,152 @@ extern "C" { } #endif // _di_fss_read_process_normal_at_ +#ifndef _di_fss_read_process_normal_at_line_ + void fss_read_process_normal_at_line(void * const void_main, const f_array_length_t at, const f_array_lengths_t delimits_object, const f_array_lengths_t delimits_content, f_number_unsigned_t * const line) { + + if (!void_main || !line) return; + + fss_read_main_t * const main = (fss_read_main_t *) void_main; + + if (main->setting.flag & fss_read_main_flag_object_e) { + if (*line == main->setting.line) { + if (main->callback.print_object) { + 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. + 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); + + main->setting.state.status = F_success; + + return; + } + } + + if ((main->setting.flag & fss_read_main_flag_object_as_line_e) || !(main->setting.flag & fss_read_main_flag_content_e)) { + ++(*line); + } + } + + if (main->setting.flag & fss_read_main_flag_content_e) { + if (!main->setting.contents.array[at].used) { + + // Must process/count line when both Object and Content share the same line but Content is empty. + if ((main->setting.flag & fss_read_main_flag_object_e) && !(main->setting.flag & fss_read_main_flag_object_as_line_e) && (main->setting.flag & fss_read_main_flag_line_single_e)) { + if (*line == main->setting.line) { + f_print_dynamic_raw(f_string_eol_s, main->program.output.to); + + main->setting.state.status = F_success; + + return; + } + + ++(*line); + } + + main->setting.state.status = F_none; + + return; + } + + f_array_length_t i = 0; + + if (main->setting.flag & fss_read_main_flag_line_single_e) { + if (*line == main->setting.line) { + while (main->setting.contents.array[at].used) { + + fss_read_print_content(&main->program.output, main->setting.contents.array[at].array[i], main->setting.quotes_content.array[at].array[i], delimits_content); + + if (++i >= main->setting.contents.array[at].used) break; + + if (main->callback.print_content_next) { + main->callback.print_content_next(&main->program.output); + } + } // while + + f_print_dynamic_raw(f_string_eol_s, main->program.output.to); + + main->setting.state.status = F_success; + + return; + } + + ++(*line); + } + else { + f_array_length_t line_original = 0; + f_array_length_t j = 0; + f_array_length_t k = 0; + + for (; i < main->setting.contents.array[at].used; ++i) { + + if (fss_read_signal_check(main)) return; + + line_original = *line; + main->setting.range = main->setting.contents.array[at].array[i]; + k = 0; + + for (j = main->setting.range.start; j <= main->setting.range.stop; ++j) { + + if (fss_read_signal_check(main)) return; + + if (k < main->setting.comments.used) { + 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; + + if (j > main->setting.range.stop) break; + } + } + + if (main->setting.buffer.string[j] == f_string_eol_s.string[0]) { + if (*line == main->setting.line) { + main->setting.range.stop = j; + + fss_read_print_content(&main->program.output, main->setting.range, main->setting.quotes_content.array[at].array[i], delimits_content); + + main->setting.state.status = F_success; + + return; + } + + main->setting.range.start = j + 1; + + if (j <= main->setting.range.stop) { + ++(*line); + } + } + } // 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]) { + ++(*line); + + if (*line == main->setting.line) { + main->setting.range.stop = main->setting.contents.array[at].array[i].stop; + + fss_read_print_content(&main->program.output, main->setting.range, main->setting.quotes_content.array[at].array[i], delimits_content); + f_print_dynamic_raw(f_string_eol_s, main->program.output.to); + + main->setting.state.status = F_success; + + return; + } + } + } // for + } + } + + main->setting.state.status = F_none; + } +#endif // _di_fss_read_process_normal_at_line_ + #ifndef _di_fss_read_process_normal_columns_ void fss_read_process_normal_columns(void * const void_main, const bool names[]) { @@ -302,62 +454,6 @@ extern "C" { } #endif // _di_fss_read_process_normal_columns_ -#ifndef _di_fss_read_process_normal_line_ - void fss_read_process_normal_line(void * const void_main, const bool names[]) { - - if (!void_main) return; - - fss_read_main_t * const main = (fss_read_main_t *) void_main; - - f_array_length_t line = 0; - - for (f_array_length_t i = 0; i < main->setting.contents.used; ++i) { - - if (!names[i]) continue; - if (fss_read_signal_check(main)) return; - - 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) { - if (main->setting.flag & fss_read_main_flag_empty_e) { - if (line == main->setting.line) { - if (main->callback.print_set_end) { - main->callback.print_set_end(&main->program.output); - } - - break; - } - - ++line; - } - - continue; - } - } - - if (line == main->setting.line) { - if (main->callback.print_at) { - main->callback.print_at( - &main->program.output, - i, - !(main->setting.flag & fss_read_main_flag_original_e) && fss_read_delimit_object_is(main, 0) - ? main->setting.delimits_object - : fss_read_except_none_c, - !(main->setting.flag & fss_read_main_flag_original_e) && fss_read_delimit_content_is(main, 0) - ? main->setting.delimits_content - : fss_read_except_none_c - ); - } - - break; - } - - ++line; - } // for - - main->setting.state.status = F_none; - } -#endif // _di_fss_read_process_normal_line_ - #ifndef _di_fss_read_process_normal_name_ void fss_read_process_normal_name(void * const void_main, bool names[]) { diff --git a/level_3/fss_read/c/main/process_normal.h b/level_3/fss_read/c/main/process_normal.h index 911301a..d42d4ad 100644 --- a/level_3/fss_read/c/main/process_normal.h +++ b/level_3/fss_read/c/main/process_normal.h @@ -29,8 +29,8 @@ extern "C" { * F_none on success. * * Errors (with error bit) from: main.callback.process_at(). + * Errors (with error bit) from: main.callback.process_at_line(). * Errors (with error bit) from: main.callback.process_columns(). - * Errors (with error bit) from: main.callback.process_line(). * Errors (with error bit) from: main.callback.process_load(). * Errors (with error bit) from: main.callback.process_name(). * Errors (with error bit) from: main.callback.print_at(). @@ -77,7 +77,7 @@ extern "C" { #endif // _di_fss_read_process_normal_at_ /** - * Process buffer according to "columns" parameter rules. + * Process for the given Object index position for processing and ultimately printing a specific line. * * @param main * The program and settings data. @@ -85,22 +85,37 @@ extern "C" { * Must not be NULL. * Must be of type fss_read_main_t. * + * This alters main.setting.range. + * * This alters main.setting.state.status: - * F_none on success. + * F_none on success but line not yet found. + * F_success on success and line is found and printed. + * + * F_parameter (with error bit) if main is NULL or setting is NULL. + * + * Errors (with error bit) from: f_string_dynamic_append_assure(). * * Errors (with error bit) from: fss_read_signal_check(). - * @param names - * An array of booleans representing if the name at a given index is enabled. - * (If TRUE, then the name is to be used and if FALSE, then the name is not to be used.) + * @param at + * The Object index position to be processed. + * @param delimits_object + * The delimits array representing a delimited Object. + * This represents the positions within the current Object at the "at" position. + * @param delimits_content + * The delimits array representing a delimited Content. + * This represents the positions within the current Content at the "at" position. + * @param line + * The current line being processed. + * This will be incremented as necessary. * - * @see fss_read_signal_check() + * Must not be NULL. */ -#ifndef _di_fss_read_process_normal_columns_ - extern void fss_read_process_normal_columns(void * const main, const bool names[]); -#endif // _di_fss_read_process_normal_columns_ +#ifndef _di_fss_read_process_normal_at_line_ + extern void fss_read_process_normal_at_line(void * const main, const f_array_length_t at, const f_array_lengths_t delimits_object, const f_array_lengths_t delimits_content, f_number_unsigned_t * const line); +#endif // _di_fss_read_process_normal_at_line_ /** - * Process buffer according to "line" parameter rules. + * Process buffer according to "columns" parameter rules. * * @param main * The program and settings data. @@ -117,11 +132,10 @@ extern "C" { * (If TRUE, then the name is to be used and if FALSE, then the name is not to be used.) * * @see fss_read_signal_check() - * @see main.callback.print_set_end() */ -#ifndef _di_fss_read_process_normal_line_ - extern void fss_read_process_normal_line(void * const main, const bool names[]); -#endif // _di_fss_read_process_normal_line_ +#ifndef _di_fss_read_process_normal_columns_ + extern void fss_read_process_normal_columns(void * const main, const bool names[]); +#endif // _di_fss_read_process_normal_columns_ /** * Process buffer according to "name" parameter rules. diff --git a/level_3/fss_read/c/payload/main.c b/level_3/fss_read/c/payload/main.c index 60ab238..05f7882 100644 --- a/level_3/fss_read/c/payload/main.c +++ b/level_3/fss_read/c/payload/main.c @@ -17,6 +17,8 @@ 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.state.custom = (void *) &data; data.setting.standard = fss_read_payload_standard_s; @@ -25,8 +27,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.callback.process_normal = &fss_read_process_normal; data.callback.process_at = &fss_read_process_normal_at; + data.callback.process_at_line = &fss_read_process_normal_at_line; data.callback.process_columns = &fss_read_process_normal_columns; - data.callback.process_line = &fss_read_process_normal_line; data.callback.process_load = &fss_read_payload_process_load; data.callback.process_name = &fss_read_process_normal_name; data.callback.process_total = &fss_read_process_normal_total; -- 1.8.3.1