From d7b74d5ede27d75fde96f7ca1df6ba12af1053a8 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 6 Mar 2012 22:55:12 -0600 Subject: [PATCH] Bugfix: -t -n (somename) should show total of (somename) not all objects This fixes an oversight or logic flaw where the total count was returned in all cases. When a specific object name is requested, the total count should be the total number of objects that match the given name. --- level_3/fss_basic_list_read/c/fss_basic_list_read.c | 17 +++++++++++++---- level_3/fss_basic_read/c/fss_basic_read.c | 21 +++++++++++++++------ level_3/fss_extended_read/c/fss_extended_read.c | 21 +++++++++++++++------ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index 6cf69b8..90df939 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -281,7 +281,7 @@ extern "C"{ } // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none){ fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; @@ -377,6 +377,7 @@ extern "C"{ } else { current = 0; + f_string_length total = f_string_length_initialize; f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; @@ -443,9 +444,13 @@ extern "C"{ } } else { if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->contents.array[current].used > 0){ - f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found){ + total++; + } else { + if (data->contents.array[current].used > 0){ + f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } } } } @@ -460,6 +465,10 @@ extern "C"{ } } } // for + + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none){ + fprintf(f_standard_output, f_string_length_printf "\n", total); + } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index eab6105..1891994 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -267,7 +267,7 @@ extern "C"{ } // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none){ fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; @@ -312,6 +312,7 @@ extern "C"{ } else { current = 0; + f_string_length total = f_string_length_initialize; f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; @@ -326,12 +327,16 @@ extern "C"{ if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->contents.array[current].used > 0){ - f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); - fprintf(f_standard_output, "\n"); + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found){ + total++; } else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); + if (data->contents.array[current].used > 0){ + f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); + fprintf(f_standard_output, "\n"); + } else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } } } @@ -345,6 +350,10 @@ extern "C"{ } } } // for + + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none){ + fprintf(f_standard_output, f_string_length_printf "\n", total); + } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 76eef84..c84783e 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -279,7 +279,7 @@ extern "C"{ } // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none){ fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; @@ -324,6 +324,7 @@ extern "C"{ } else { current = 0; + f_string_length total = f_string_length_initialize; f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; @@ -338,12 +339,16 @@ extern "C"{ if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->contents.array[current].used > select){ - f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); - fprintf(f_standard_output, "\n"); + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found){ + total++; } else { - // for all objects with no data, print a newline - fprintf(f_standard_output, "\n"); + if (data->contents.array[current].used > select){ + f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); + fprintf(f_standard_output, "\n"); + } else { + // for all objects with no data, print a newline + fprintf(f_standard_output, "\n"); + } } } @@ -357,6 +362,10 @@ extern "C"{ } } } // for + + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none){ + fprintf(f_standard_output, f_string_length_printf "\n", total); + } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object -- 1.8.3.1