From 474a9229f422b97db3a15db84debdca7559c01e7 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 5 May 2021 00:13:35 -0500 Subject: [PATCH] Update: Improvements and tweaks in FSS Basic Read. Add additional help information. Cleanup comments. In some cases the total printing is inverted by accident. The print_object function pointer doesn't really need to exist anymore. Add missing print for when both total and line parameters are specified. --- level_3/fss_basic_read/c/fss_basic_read.c | 15 ++++++++ level_3/fss_basic_read/c/fss_basic_read.h | 11 +++++- level_3/fss_basic_read/c/private-common.h | 20 +++++----- level_3/fss_basic_read/c/private-fss_basic_read.c | 46 ++++++++++++----------- level_3/fss_basic_read/c/private-fss_basic_read.h | 12 +++--- 5 files changed, 65 insertions(+), 39 deletions(-) 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 088d36a..a08253b 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -46,6 +46,11 @@ extern "C" { fprintf(output.stream, "%c", f_string_eol_s[0]); + fprintf(output.stream, " All numeric positions (indexes) start at 0 instead of one.%c", f_string_eol_s[0]); + fprintf(output.stream, " For example, a file of 17 lines would range from 0 to 16.%c", f_string_eol_s[0]); + + fprintf(output.stream, "%c", f_string_eol_s[0]); + fprintf(output.stream, " When using the "); f_color_print(output.stream, context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_depth); fprintf(output.stream, " option, an order of operations is enforced on the parameters.%c", f_string_eol_s[0]); @@ -178,6 +183,7 @@ extern "C" { #ifndef _di_fss_basic_read_main_ f_status_t fss_basic_read_main(f_console_arguments_t * const arguments, fss_basic_read_main_t *main) { + f_status_t status = F_none; { @@ -315,6 +321,15 @@ extern "C" { status = F_status_set_error(F_parameter); } + else if (main->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { + f_color_print(main->error.to.stream, main->context.set.error, "%sCannot specify the '", fll_error_print_error); + f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_pipe); + f_color_print(main->error.to.stream, main->context.set.error, "' parameter with the '"); + f_color_print(main->error.to.stream, main->context.set.notable, "%s%s", f_console_symbol_long_enable_s, fss_basic_read_long_line); + f_color_print(main->error.to.stream, main->context.set.error, "' parameter.%c", f_string_eol_s[0]); + + status = F_status_set_error(F_parameter); + } } if (F_status_is_error_not(status) && main->parameters[fss_basic_read_parameter_delimit].result == f_console_result_additional) { diff --git a/level_3/fss_basic_read/c/fss_basic_read.h b/level_3/fss_basic_read/c/fss_basic_read.h index c5bcb9b..1f65a66 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -146,8 +146,17 @@ extern "C" { #endif // _di_fss_basic_read_defines_ /** + * FSS Delimit Parameter data. * - * + * fss_basic_read_delimit_mode_*: + * - all: All delimits are to be aplied. + * - content: Content are to have delimits applied. + * - content_greater: Content at this number or higher are to have delimits applied. + * - content_greater_object: Objects and Content at this number or higher are to have delimits applied. + * - content_lesser: Content at this number or lower are to have delimits applied. + * - content_lesser_object: Objects and Content at this number or lower are to have delimits applied. + * - content_object: Objects and Content are to have delimits applied + * - object: Objects arre to have delimits applied. */ #ifndef _di_fss_basic_read_delimit_mode_ #define fss_basic_read_delimit_mode_name_none "none" diff --git a/level_3/fss_basic_read/c/private-common.h b/level_3/fss_basic_read/c/private-common.h index b5ccc78..6dd3dfd 100644 --- a/level_3/fss_basic_read/c/private-common.h +++ b/level_3/fss_basic_read/c/private-common.h @@ -15,13 +15,13 @@ extern "C" { /** * A structure of parameters applied at some depth. * - * depth: the depth number in which this is to be processed at. + * depth: The depth number in which this is to be processed at. * - * index_at: position of the "--at" parameter value in the argv list, when 0 there is no parameter. - * index_name: position of the "--name" parameter value in the argv list, when 0 there is no parameter. + * index_at: Position of the "--at" parameter value in the argv list, when 0 there is no parameter. + * index_name: Position of the "--name" parameter value in the argv list, when 0 there is no parameter. * - * value_at: the value of the "--at" parameter, already processed and ready to use, only when index_at > 0. - * value_name: the value of the "--name" parameter, already processed and ready to use, only when index_name > 0. + * value_at: The value of the "--at" parameter, already processed and ready to use, only when index_at > 0. + * value_name: The value of the "--name" parameter, already processed and ready to use, only when index_name > 0. */ #ifndef _di_fss_basic_read_depth_t_ typedef struct { @@ -54,9 +54,9 @@ extern "C" { /** * An array of depth parameters. * - * array: the array of depths. - * size: total amount of allocated space. - * used: total number of allocated spaces used. + * array: The array of depths. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. */ #ifndef _di_fss_basic_read_depths_t_ typedef struct { @@ -74,7 +74,8 @@ extern "C" { /** * A structure for designating where within the buffer a particular file exists, using a statically allocated array. * - * name: The name of the file representing the range. Set string to NULL to represent the STDIN pipe. + * name: The name of the file representing the range. Set string to NULL to represent the STDIN pipe. + * range: A range within the buffer representing the file. */ #ifndef _di_fss_basic_read_file_t_ typedef struct { @@ -138,7 +139,6 @@ extern "C" { * delimits: The positions within the buffer representing character delimits. */ #ifndef _di_fss_basic_read_data_t_ - #define fss_basic_read_data_option_at 0x1 #define fss_basic_read_data_option_content 0x2 #define fss_basic_read_data_option_empty 0x4 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 e5b654d..e68f58b 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 @@ -228,16 +228,14 @@ extern "C" { return; } - if (data->contents.array[at].used || (data->option & fss_basic_read_data_option_empty)) { - - f_status_t (*print_object)(FILE *, const f_string_static_t, const f_string_range_t, const f_array_lengths_t) = &f_print_except_dynamic_partial; - - if (data->option & fss_basic_read_data_option_trim) { - print_object = &fl_print_trim_except_dynamic_partial; - } - + if ((data->option & fss_basic_read_data_option_object) || (data->option & fss_basic_read_data_option_content) && (data->contents.array[at].used || (data->option & fss_basic_read_data_option_empty))) { if (data->option & fss_basic_read_data_option_object) { - print_object(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + if (data->option & fss_basic_read_data_option_trim) { + fl_print_trim_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + } + else { + f_print_except_dynamic_partial(main->output.stream, data->buffer, data->objects.array[at], delimits_object); + } if (data->option & fss_basic_read_data_option_content) { fss_basic_read_print_object_end(main); @@ -248,9 +246,7 @@ extern "C" { f_print_except_dynamic_partial(main->output.stream, data->buffer, data->contents.array[at].array[0], delimits_content); } - if ((data->option & fss_basic_read_data_option_object) || (data->option & fss_basic_read_data_option_content) && (data->contents.array[at].used || (data->option & fss_basic_read_data_option_empty))) { - fss_basic_read_print_set_end(main); - } + fss_basic_read_print_set_end(main); } } #endif // _di_fss_basic_read_print_at_ @@ -381,8 +377,13 @@ extern "C" { return F_none; } + // This standard only has one line per Content; therefore, any line value greater than 0 equates to no line to print. if (data->option & fss_basic_read_data_option_line) { if (data->line) { + if (data->option & fss_basic_read_data_option_total) { + fss_basic_read_print_zero(main); + } + return F_none; } } @@ -402,10 +403,10 @@ extern "C" { // This standard only supports one Content per Object so when using "--at", the only valid line is line 0. if (data->option & fss_basic_read_data_option_total) { if (data->line) { - fss_basic_read_print_one(main); + fss_basic_read_print_zero(main); } else { - fss_basic_read_print_zero(main); + fss_basic_read_print_one(main); } } else if (!data->line) { @@ -413,11 +414,11 @@ extern "C" { } } else if (data->option & fss_basic_read_data_option_total) { - if (!data->contents.array[i].used) { - fss_basic_read_print_zero(main); + if (data->contents.array[i].used) { + fss_basic_read_print_one(main); } else { - fss_basic_read_print_one(main); + fss_basic_read_print_zero(main); } } else { @@ -440,7 +441,7 @@ extern "C" { f_array_lengths_t except_none = f_array_lengths_t_initialize; f_array_lengths_t *delimits = fss_basic_read_delimit_object_is(0, data) ? &data->delimits : &except_none; - f_array_length_t line_current = 0; + f_array_length_t line = 0; for (f_array_length_t i = 0; i < data->contents.used; ++i) { @@ -448,24 +449,25 @@ extern "C" { if (!data->contents.array[i].used) { if (data->option & fss_basic_read_data_option_empty) { - if (line_current == data->line) { + if (line == data->line) { fss_basic_read_print_set_end(main); + break; } - ++line_current; + ++line; } continue; } - if (line_current == data->line) { + if (line == data->line) { fss_basic_read_print_at(main, data, i, *delimits, except_none); break; } - ++line_current; + ++line; } // for return F_none; diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.h b/level_3/fss_basic_read/c/private-fss_basic_read.h index 2051916..b8ebe5d 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.h +++ b/level_3/fss_basic_read/c/private-fss_basic_read.h @@ -85,7 +85,7 @@ extern "C" { * @param arguments * The console arguments passed to the program. * @param main - * The program specific main. + * The main data. * @param parameter * An ID representing the parameter. * @param name @@ -128,10 +128,10 @@ extern "C" { #endif // _di_fss_basic_read_print_at_ /** - * Print the end of an Object (which is essentially the start of a Content). + * Print the end of an Object (which is essentially the start of Content). * * @param main - * The program specific main. + * The main data. */ #ifndef _di_fss_basic_read_print_object_end_ extern void fss_basic_read_print_object_end(fss_basic_read_main_t * const main) f_attribute_visibility_internal; @@ -141,7 +141,7 @@ extern "C" { * Print the number one and a newline. * * @param main - * The program specific main. + * The main data. */ #ifndef _di_fss_basic_read_print_one_ extern void fss_basic_read_print_one(fss_basic_read_main_t * const main) f_attribute_visibility_internal; @@ -151,7 +151,7 @@ extern "C" { * Print the end of an Object/Content set. * * @param main - * The program specific main. + * The main data. */ #ifndef _di_fss_basic_read_print_set_end_ extern void fss_basic_read_print_set_end(fss_basic_read_main_t * const main) f_attribute_visibility_internal; @@ -161,7 +161,7 @@ extern "C" { * Print the number zero and a newline. * * @param main - * The program specific main. + * The main data. */ #ifndef _di_fss_basic_read_print_zero_ extern void fss_basic_read_print_zero(fss_basic_read_main_t * const main) f_attribute_visibility_internal; -- 1.8.3.1