From 5437a456ed0bb24ad968634a4975e4f86e6840fb Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 6 May 2021 19:12:32 -0500 Subject: [PATCH] Bugfix: Fix problems revealed when working on FSS Extended List Read. Be sure to explicitly check data->objects.used is non-zero when counting total. The Basic List and Extended List Object names, when being selected (via the --select parameter), should be trimmed by default. This is because the Basic List nd Extended List standards define an Object name as beginning after on the first non-whitespace and ending at the last non-whitespace. Minor syntax cleanups such as replaced "if (X > 0)" with "if (X)". --- .../c/private-fss_basic_list_read.c | 31 +++++++++------------- level_3/fss_basic_read/c/private-fss_basic_read.c | 7 +++-- .../c/private-fss_extended_read.c | 10 ++++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c index 352d1c8..336cdea 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c @@ -426,7 +426,10 @@ extern "C" { f_status_t fss_basic_list_read_process_at(fss_basic_list_read_main_t * const main, fss_basic_list_read_data_t *data, bool names[]) { if (data->depths.array[0].value_at >= data->objects.used) { - if (names[data->depths.array[0].value_at] && (data->option & fss_basic_list_read_data_option_total)) { + if (!data->objects.used) { + fss_extended_list_read_print_zero(main); + } + else if (names[data->depths.array[0].value_at] && (data->option & fss_basic_list_read_data_option_total)) { fss_basic_list_read_print_zero(main); } @@ -438,7 +441,6 @@ extern "C" { f_array_lengths_t *delimits_content = fss_basic_list_read_delimit_content_is(0, data) ? &data->delimits_content : &except_none; f_array_length_t at = 0; - f_array_length_t line = 0; f_status_t status = F_none; for (f_array_length_t i = 0; i < data->objects.used; ++i) { @@ -447,6 +449,8 @@ extern "C" { if (at == data->depths.array[0].value_at) { if (data->option & fss_basic_list_read_data_option_line) { + f_array_length_t line = 0; + status = fss_basic_list_read_process_at_line(at, *delimits_object, *delimits_content, main, data, &line); if (status == F_success) return F_none; } @@ -586,27 +590,18 @@ extern "C" { f_array_lengths_t except_none = f_array_lengths_t_initialize; - if (data->depths.array[0].index_name > 0) { + if (data->depths.array[0].index_name) { f_array_length_t i = 0; memset(names, F_false, sizeof(bool) * data->objects.used); - if (data->option & fss_basic_list_read_data_option_trim) { - for (i = 0; i < data->objects.used; ++i) { + // This standard should always tread selected names as trimmed. + for (i = 0; i < data->objects.used; ++i) { - if (fl_string_dynamic_partial_compare_except_trim_dynamic(data->depths.array[0].value_name, data->buffer, data->objects.array[i], except_none, data->delimits_object) == F_equal_to) { - names[i] = F_true; - } - } // for - } - else { - for (i = 0; i < data->objects.used; ++i) { - - if (fl_string_dynamic_partial_compare_except_dynamic(data->depths.array[0].value_name, data->buffer, data->objects.array[i], except_none, data->delimits_object) == F_equal_to) { - names[i] = F_true; - } - } // for - } + if (fl_string_dynamic_partial_compare_except_trim_dynamic(data->depths.array[0].value_name, data->buffer, data->objects.array[i], except_none, data->delimits_object) == F_equal_to) { + names[i] = F_true; + } + } // for } else { memset(names, F_true, sizeof(bool) * data->objects.used); diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.c b/level_3/fss_basic_read/c/private-fss_basic_read.c index bced878..514a482 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.c +++ b/level_3/fss_basic_read/c/private-fss_basic_read.c @@ -370,7 +370,10 @@ extern "C" { f_status_t fss_basic_read_process_at(fss_basic_read_main_t * const main, fss_basic_read_data_t *data, bool names[]) { if (data->depths.array[0].value_at >= data->objects.used) { - if (names[data->depths.array[0].value_at] && (data->option & fss_basic_read_data_option_total)) { + if (!data->objects.used) { + fss_extended_list_read_print_zero(main); + } + else if (names[data->depths.array[0].value_at] && (data->option & fss_basic_read_data_option_total)) { fss_basic_read_print_zero(main); } @@ -482,7 +485,7 @@ extern "C" { f_array_lengths_t except_none = f_array_lengths_t_initialize; - if (data->depths.array[0].index_name > 0) { + if (data->depths.array[0].index_name) { f_array_length_t i = 0; memset(names, F_false, sizeof(bool) * data->objects.used); diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.c b/level_3/fss_extended_read/c/private-fss_extended_read.c index 07565a6..c7c46ee 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.c +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -466,7 +466,10 @@ extern "C" { f_status_t fss_extended_read_process_at(fss_extended_read_main_t * const main, fss_extended_read_data_t *data, bool names[]) { if (data->depths.array[0].value_at >= data->objects.used) { - if (names[data->depths.array[0].value_at] && (data->option & fss_extended_read_data_option_total)) { + if (!data->objects.used) { + fss_extended_list_read_print_zero(main); + } + else if (names[data->depths.array[0].value_at] && (data->option & fss_extended_read_data_option_total)) { fss_extended_read_print_zero(main); } @@ -489,9 +492,8 @@ extern "C" { f_array_lengths_t *delimits_content = fss_extended_read_delimit_content_is((data->option & fss_extended_read_data_option_select) ? data->select : 0, data) ? &data->delimits_content : &except_none; f_array_length_t at = 0; - f_array_length_t i = 0; - for (; i < data->objects.used; ++i) { + for (f_array_length_t i = 0; i < data->objects.used; ++i) { if (!names[i]) continue; @@ -580,7 +582,7 @@ extern "C" { f_array_lengths_t except_none = f_array_lengths_t_initialize; - if (data->depths.array[0].index_name > 0) { + if (data->depths.array[0].index_name) { f_array_length_t i = 0; memset(names, F_false, sizeof(bool) * data->objects.used); -- 1.8.3.1