From 866fa1c3c871d263746df7cdff1cb89a015d01c0 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 22 Apr 2020 20:40:50 -0500 Subject: [PATCH] Feature: implement support for the -T/--trim parameter Provide support for trimming the object names on input and output. After implementing this I suddenly remember that the standard might require that the whitespace before and after a valid object name are to be ignored. This may be removed in the future and fixed in the library. Additional investigation on how I want to handle this needs to happen first. The standard is originally designed around ASCII, which only ASCII whitespace is considered whitespace. This will probably have to be fixed to match the additional goals of the project in terms of whitespace handling. --- .../fss_basic_list_read/c/fss_basic_list_read.c | 11 ++- .../fss_basic_list_read/c/fss_basic_list_read.h | 7 +- .../c/private-fss_basic_list_read.c | 51 ++++++++--- .../c/private-fss_basic_list_read.h | 100 +++++++++++++++++++-- .../fss_basic_list_read/data/build/dependencies | 1 + level_3/fss_basic_list_read/data/build/settings | 2 +- level_3/fss_basic_read/c/fss_basic_read.c | 11 ++- level_3/fss_basic_read/c/fss_basic_read.h | 7 +- level_3/fss_basic_read/c/private-fss_basic_read.c | 51 ++++++++--- level_3/fss_basic_read/c/private-fss_basic_read.h | 100 +++++++++++++++++++-- level_3/fss_basic_read/data/build/dependencies | 1 + level_3/fss_basic_read/data/build/settings | 2 +- .../c/fss_extended_list_read.c | 11 ++- .../c/fss_extended_list_read.h | 7 +- .../c/private-fss_extended_list_read.c | 67 ++++++++------ .../c/private-fss_extended_list_read.h | 98 ++++++++++++++++++-- .../fss_extended_list_read/data/build/dependencies | 1 + level_3/fss_extended_list_read/data/build/settings | 2 +- level_3/fss_extended_read/c/fss_extended_read.c | 11 ++- level_3/fss_extended_read/c/fss_extended_read.h | 7 +- .../c/private-fss_extended_read.c | 51 ++++++++--- .../c/private-fss_extended_read.h | 100 +++++++++++++++++++-- level_3/fss_extended_read/data/build/dependencies | 1 + level_3/fss_extended_read/data/build/settings | 2 +- 24 files changed, 587 insertions(+), 115 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 64d8412..3a6fd7e 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 @@ -25,6 +25,7 @@ extern "C" { fll_program_print_help_option(data.context, fss_basic_list_read_short_object, fss_basic_list_read_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the object instead of the content."); fll_program_print_help_option(data.context, fss_basic_list_read_short_select, fss_basic_list_read_long_select, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select sub-content at this index."); fll_program_print_help_option(data.context, fss_basic_list_read_short_total, fss_basic_list_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of lines."); + fll_program_print_help_option(data.context, fss_basic_list_read_short_trim, fss_basic_list_read_long_trim, f_console_symbol_short_enable, f_console_symbol_long_enable, " Trim object names on select or print."); fll_program_print_help_usage(data.context, fss_basic_list_read_name, "filename(s)"); @@ -106,9 +107,15 @@ extern "C" { printf(" For parameters like "); fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_list_read_long_select); - printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid."); + printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid.%c", f_string_eol); - printf("%c%c", f_string_eol, f_string_eol); + printf("%c", f_string_eol); + + printf(" The parameter "); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_list_read_long_trim); + printf(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol); + + printf("%c", f_string_eol); return f_none; } diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.h b/level_3/fss_basic_list_read/c/fss_basic_list_read.h index 3a071e3..8da0d4d 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.h @@ -32,6 +32,7 @@ #include #include #include +#include #include // fll-2 includes @@ -65,6 +66,7 @@ extern "C" { #define fss_basic_list_read_short_object "o" #define fss_basic_list_read_short_select "s" #define fss_basic_list_read_short_total "t" + #define fss_basic_list_read_short_trim "T" #define fss_basic_list_read_long_at "at" #define fss_basic_list_read_long_depth "depth" @@ -74,6 +76,7 @@ extern "C" { #define fss_basic_list_read_long_object "object" #define fss_basic_list_read_long_select "select" #define fss_basic_list_read_long_total "total" + #define fss_basic_list_read_long_trim "trim" enum { fss_basic_list_read_parameter_help, @@ -90,6 +93,7 @@ extern "C" { fss_basic_list_read_parameter_object, fss_basic_list_read_parameter_select, fss_basic_list_read_parameter_total, + fss_basic_list_read_parameter_trim, }; #define f_console_parameter_initialize_fss_basic_list_read \ @@ -107,9 +111,10 @@ extern "C" { f_console_parameter_initialize(fss_basic_list_read_short_object, fss_basic_list_read_long_object, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_basic_list_read_short_select, fss_basic_list_read_long_select, 0, f_true, f_console_type_normal), \ f_console_parameter_initialize(fss_basic_list_read_short_total, fss_basic_list_read_long_total, 0, f_false, f_console_type_normal), \ + f_console_parameter_initialize(fss_basic_list_read_short_trim, fss_basic_list_read_long_trim, 0, f_false, f_console_type_normal), \ } - #define fss_basic_list_read_total_parameters 13 + #define fss_basic_list_read_total_parameters 14 #endif // _di_fss_basic_list_read_defines_ #ifndef _di_fss_basic_list_read_data_ 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 99fc9b1..b6da80c 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 @@ -111,7 +111,8 @@ extern "C" { depths->array[i].index_at = 0; depths->array[i].index_name = 0; depths->array[i].value_at = 0; - depths->array[i].value_name = f_string_eos; + + f_macro_string_dynamic_clear(depths->array[i].value_name); if (data.parameters[fss_basic_list_read_parameter_depth].additional.used == 0) { position_depth = 0; @@ -159,9 +160,15 @@ extern "C" { } depths->array[i].index_name = data.parameters[fss_basic_list_read_parameter_name].additional.array[position_name]; - depths->array[i].value_name = arguments.argv[depths->array[i].index_name]; - if (depths->array[i].value_name[0] == '\0') { + if (data.parameters[fss_basic_list_read_parameter_trim].result == f_console_result_found) { + fl_string_rip_trim(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + else { + fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + + if (depths->array[i].value_name.used == 0) { fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: The '"); fl_color_print(f_standard_error, data.context.notable, data.context.reset, "--%s", fss_basic_list_read_long_name); fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' must not be an empty string."); @@ -290,18 +297,30 @@ extern "C" { if (depths.array[0].index_name > 0) { memset(names, 0, sizeof(bool) * data->objects.used); - f_string_length argv_length = strlen(depths.array[0].value_name); f_string_length name_length = 0; - for (f_string_length i = 0; i < data->objects.used; i++) { - name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + if (data->parameters[fss_basic_list_read_parameter_trim].result == f_console_result_found) { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name, name_length, argv_length) == f_equal_to) { - names[i] = 1; + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare_trim(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } } - } - } // for + } // for + } + else { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } + } + } // for + } } else { memset(names, 1, sizeof(bool) * data->objects.used); @@ -341,6 +360,12 @@ extern "C" { return f_none; } + f_return_status (*print_object)(FILE *, const f_string_dynamic, const f_string_location) = &f_print_string_dynamic_partial; + + if (data->parameters[fss_basic_list_read_parameter_trim].result == f_console_result_found) { + print_object = &fl_print_trim_string_dynamic_partial; + } + if (depths.array[0].index_at > 0) { f_array_length at = 0; f_array_length i = 0; @@ -348,7 +373,7 @@ extern "C" { for (; i < data->objects.used; i++) { if (names[i]) { if (at == depths.array[0].value_at) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); break; } @@ -363,7 +388,7 @@ extern "C" { for (f_string_length i = 0; i < data->objects.used; i++) { if (names[i] == 0) continue; - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); } // for diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h index 1a4f945..d43513e 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h @@ -31,7 +31,7 @@ extern "C" { f_array_length index_name; f_number_unsigned value_at; - f_string value_name; + f_string_dynamic value_name; } fss_basic_list_read_depth; #define fss_basic_list_read_depth_initialize \ @@ -40,8 +40,21 @@ extern "C" { 0, \ 0, \ 0, \ - f_string_initialize, \ + f_string_dynamic_initialize, \ } + + #define macro_fss_basic_list_read_depth_clear(structure) \ + structure.depth = 0; \ + structure.index_at = 0; \ + structure.index_name = 0; \ + structure.value_at = 0; \ + f_macro_string_dynamic_clear(structure.value_name) + + #define macro_fss_basic_list_read_depth_delete(status, structure) f_macro_string_dynamic_delete(status, structure.value_name) + #define macro_fss_basic_list_read_depth_destroy(status, structure) f_macro_string_dynamic_destroy(status, structure.value_name) + + #define macro_fss_basic_list_read_depth_delete_simple(structure) f_macro_string_dynamic_delete_simple(structure.value_name) + #define macro_fss_basic_list_read_depth_destroy_simple(structure) f_macro_string_dynamic_destroy_simple(structure.value_name) #endif // _di_fss_basic_list_read_depth_ /** @@ -65,14 +78,83 @@ extern "C" { #define macro_fss_basic_list_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_basic_list_read_depth, length) - #define macro_fss_basic_list_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_basic_list_read_depth) - #define macro_fss_basic_list_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_basic_list_read_depth) - - #define macro_fss_basic_list_read_depths_delete_simple(depths) f_macro_memory_structure_delete_simple(depths, fss_basic_list_read_depth) - #define macro_fss_basic_list_read_depths_destroy_simple(depths) f_macro_memory_structure_destroy_simple(depths, fss_basic_list_read_depth) + #define macro_fss_basic_list_read_depths_delete(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_list_read_depth_delete(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_delete(depths, fss_basic_list_read_depth) + + #define macro_fss_basic_list_read_depths_destroy(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_list_read_depth_destroy(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_destroy(depths, fss_basic_list_read_depth) + + #define macro_fss_basic_list_read_depths_delete_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_list_read_depth_delete_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_delete_simple(depths, fss_basic_list_read_depth) + + #define macro_fss_basic_list_read_depths_destroy_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_list_read_depth_destroy_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_destroy_simple(depths, fss_basic_list_read_depth) + + #define macro_fss_basic_list_read_depths_resize(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_basic_list_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_resize((void **) & depths.array, sizeof(fss_basic_list_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_basic_list_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } - #define macro_fss_basic_list_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_basic_list_read_depth, new_length) - #define macro_fss_basic_list_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_basic_list_read_depth, new_length) + #define macro_fss_basic_list_read_depths_adjust(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_basic_list_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_adjust((void **) & depths.array, sizeof(fss_basic_list_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_basic_list_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } #endif // _di_fss_basic_list_read_depths_ /** diff --git a/level_3/fss_basic_list_read/data/build/dependencies b/level_3/fss_basic_list_read/data/build/dependencies index 2615941..73e0e63 100644 --- a/level_3/fss_basic_list_read/data/build/dependencies +++ b/level_3/fss_basic_list_read/data/build/dependencies @@ -11,6 +11,7 @@ fl_console fl_directory fl_file fl_fss +fl_print fl_status fl_string fll_execute diff --git a/level_3/fss_basic_list_read/data/build/settings b/level_3/fss_basic_list_read/data/build/settings index 762d226..792b21f 100644 --- a/level_3/fss_basic_list_read/data/build/settings +++ b/level_3/fss_basic_list_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_color -lfl_console -lf_conversion -lfl_directory -lfl_file -lfl_fss -lfl_print -lfl_status -lfl_string -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 build_libraries_fll-monolithic -lfll build_sources_library fss_basic_list_read.c private-fss_basic_list_read.c 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 28a4b21..c225d54 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -25,6 +25,7 @@ extern "C" { fll_program_print_help_option(data.context, fss_basic_read_short_object, fss_basic_read_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the object instead of the content."); fll_program_print_help_option(data.context, fss_basic_read_short_select, fss_basic_read_long_select, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select sub-content at this index."); fll_program_print_help_option(data.context, fss_basic_read_short_total, fss_basic_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of lines."); + fll_program_print_help_option(data.context, fss_basic_read_short_trim, fss_basic_read_long_trim, f_console_symbol_short_enable, f_console_symbol_long_enable, " Trim object names on select or print."); fll_program_print_help_usage(data.context, fss_basic_read_name, "filename(s)"); @@ -106,9 +107,15 @@ extern "C" { printf(" For parameters like "); fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_select); - printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid."); + printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid.%c", f_string_eol); - printf("%c%c", f_string_eol, f_string_eol); + printf("%c", f_string_eol); + + printf(" The parameter "); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_trim); + printf(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol); + + printf("%c", f_string_eol); return f_none; } 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 440ce77..ed7eac5 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -32,6 +32,7 @@ #include #include #include +#include #include // fll-2 includes @@ -65,6 +66,7 @@ extern "C" { #define fss_basic_read_short_object "o" #define fss_basic_read_short_select "s" #define fss_basic_read_short_total "t" + #define fss_basic_read_short_trim "T" #define fss_basic_read_long_at "at" #define fss_basic_read_long_depth "depth" @@ -74,6 +76,7 @@ extern "C" { #define fss_basic_read_long_object "object" #define fss_basic_read_long_select "select" #define fss_basic_read_long_total "total" + #define fss_basic_read_long_trim "trim" enum { fss_basic_read_parameter_help, @@ -90,6 +93,7 @@ extern "C" { fss_basic_read_parameter_object, fss_basic_read_parameter_select, fss_basic_read_parameter_total, + fss_basic_read_parameter_trim, }; #define f_console_parameter_initialize_fss_basic_read \ @@ -107,9 +111,10 @@ extern "C" { f_console_parameter_initialize(fss_basic_read_short_object, fss_basic_read_long_object, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_basic_read_short_select, fss_basic_read_long_select, 0, f_true, f_console_type_normal), \ f_console_parameter_initialize(fss_basic_read_short_total, fss_basic_read_long_total, 0, f_false, f_console_type_normal), \ + f_console_parameter_initialize(fss_basic_read_short_trim, fss_basic_read_long_trim, 0, f_false, f_console_type_normal), \ } - #define fss_basic_read_total_parameters 13 + #define fss_basic_read_total_parameters 14 #endif // _di_fss_basic_read_defines_ #ifndef _di_fss_basic_read_data_ 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 c06cdee..f0eb68c 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 @@ -111,7 +111,8 @@ extern "C" { depths->array[i].index_at = 0; depths->array[i].index_name = 0; depths->array[i].value_at = 0; - depths->array[i].value_name = f_string_eos; + + f_macro_string_dynamic_clear(depths->array[i].value_name); if (data.parameters[fss_basic_read_parameter_depth].additional.used == 0) { position_depth = 0; @@ -159,9 +160,15 @@ extern "C" { } depths->array[i].index_name = data.parameters[fss_basic_read_parameter_name].additional.array[position_name]; - depths->array[i].value_name = arguments.argv[depths->array[i].index_name]; - if (depths->array[i].value_name[0] == '\0') { + if (data.parameters[fss_basic_read_parameter_trim].result == f_console_result_found) { + fl_string_rip_trim(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + else { + fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + + if (depths->array[i].value_name.used == 0) { fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: The '"); fl_color_print(f_standard_error, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_name); fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' must not be an empty string."); @@ -290,18 +297,30 @@ extern "C" { if (depths.array[0].index_name > 0) { memset(names, 0, sizeof(bool) * data->objects.used); - f_string_length argv_length = strlen(depths.array[0].value_name); f_string_length name_length = 0; - for (f_string_length i = 0; i < data->objects.used; i++) { - name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + if (data->parameters[fss_basic_read_parameter_trim].result == f_console_result_found) { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name, name_length, argv_length) == f_equal_to) { - names[i] = 1; + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare_trim(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } } - } - } // for + } // for + } + else { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } + } + } // for + } } else { memset(names, 1, sizeof(bool) * data->objects.used); @@ -341,6 +360,12 @@ extern "C" { return f_none; } + f_return_status (*print_object)(FILE *, const f_string_dynamic, const f_string_location) = &f_print_string_dynamic_partial; + + if (data->parameters[fss_basic_read_parameter_trim].result == f_console_result_found) { + print_object = &fl_print_trim_string_dynamic_partial; + } + if (depths.array[0].index_at > 0) { f_array_length at = 0; f_array_length i = 0; @@ -348,7 +373,7 @@ extern "C" { for (; i < data->objects.used; i++) { if (names[i]) { if (at == depths.array[0].value_at) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); break; } @@ -363,7 +388,7 @@ extern "C" { for (f_array_length i = 0; i < data->objects.used; i++) { if (names[i] == 0) continue; - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); } // for 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 f9f2a28..5ab4ccb 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 @@ -31,7 +31,7 @@ extern "C" { f_array_length index_name; f_number_unsigned value_at; - f_string value_name; + f_string_dynamic value_name; } fss_basic_read_depth; #define fss_basic_read_depth_initialize \ @@ -40,8 +40,21 @@ extern "C" { 0, \ 0, \ 0, \ - f_string_initialize, \ + f_string_dynamic_initialize, \ } + + #define macro_fss_basic_read_depth_clear(structure) \ + structure.depth = 0; \ + structure.index_at = 0; \ + structure.index_name = 0; \ + structure.value_at = 0; \ + f_macro_string_dynamic_clear(structure.value_name) + + #define macro_fss_basic_read_depth_delete(status, structure) f_macro_string_dynamic_delete(status, structure.value_name) + #define macro_fss_basic_read_depth_destroy(status, structure) f_macro_string_dynamic_destroy(status, structure.value_name) + + #define macro_fss_basic_read_depth_delete_simple(structure) f_macro_string_dynamic_delete_simple(structure.value_name) + #define macro_fss_basic_read_depth_destroy_simple(structure) f_macro_string_dynamic_destroy_simple(structure.value_name) #endif // _di_fss_basic_read_depth_ /** @@ -65,14 +78,83 @@ extern "C" { #define macro_fss_basic_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_basic_read_depth, length) - #define macro_fss_basic_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_basic_read_depth) - #define macro_fss_basic_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_basic_read_depth) - - #define macro_fss_basic_read_depths_delete_simple(depths) f_macro_memory_structure_delete_simple(depths, fss_basic_read_depth) - #define macro_fss_basic_read_depths_destroy_simple(depths) f_macro_memory_structure_destroy_simple(depths, fss_basic_read_depth) + #define macro_fss_basic_read_depths_delete(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_read_depth_delete(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_delete(depths, fss_basic_read_depth) + + #define macro_fss_basic_read_depths_destroy(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_read_depth_destroy(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_destroy(depths, fss_basic_read_depth) + + #define macro_fss_basic_read_depths_delete_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_read_depth_delete_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_delete_simple(depths, fss_basic_read_depth) + + #define macro_fss_basic_read_depths_destroy_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_basic_read_depth_destroy_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_destroy_simple(depths, fss_basic_read_depth) + + #define macro_fss_basic_read_depths_resize(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_basic_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_resize((void **) & depths.array, sizeof(fss_basic_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_basic_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } - #define macro_fss_basic_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_basic_read_depth, new_length) - #define macro_fss_basic_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_basic_read_depth, new_length) + #define macro_fss_basic_read_depths_adjust(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_basic_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_adjust((void **) & depths.array, sizeof(fss_basic_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_basic_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } #endif // _di_fss_basic_read_depths_ /** diff --git a/level_3/fss_basic_read/data/build/dependencies b/level_3/fss_basic_read/data/build/dependencies index 2615941..73e0e63 100644 --- a/level_3/fss_basic_read/data/build/dependencies +++ b/level_3/fss_basic_read/data/build/dependencies @@ -11,6 +11,7 @@ fl_console fl_directory fl_file fl_fss +fl_print fl_status fl_string fll_execute diff --git a/level_3/fss_basic_read/data/build/settings b/level_3/fss_basic_read/data/build/settings index 4230baf..fa1a568 100644 --- a/level_3/fss_basic_read/data/build/settings +++ b/level_3/fss_basic_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_color -lfl_console -lf_conversion -lfl_directory -lfl_file -lfl_fss -lfl_print -lfl_status -lfl_string -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 build_libraries_fll-monolithic -lfll build_sources_library fss_basic_read.c private-fss_basic_read.c diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index 1f7b005..dd9909d 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -25,6 +25,7 @@ extern "C" { fll_program_print_help_option(data.context, fss_extended_list_read_short_object, fss_extended_list_read_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the object instead of the content."); fll_program_print_help_option(data.context, fss_extended_list_read_short_select, fss_extended_list_read_long_select, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select sub-content at this index."); fll_program_print_help_option(data.context, fss_extended_list_read_short_total, fss_extended_list_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of lines."); + fll_program_print_help_option(data.context, fss_extended_list_read_short_trim, fss_extended_list_read_long_trim, f_console_symbol_short_enable, f_console_symbol_long_enable, " Trim object names on select or print."); fll_program_print_help_usage(data.context, fss_extended_list_read_name, "filename(s)"); @@ -106,9 +107,15 @@ extern "C" { printf(" For parameters like "); fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_extended_list_read_long_select); - printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid."); + printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid.%c", f_string_eol); - printf("%c%c", f_string_eol, f_string_eol); + printf("%c", f_string_eol); + + printf(" The parameter "); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_extended_list_read_long_trim); + printf(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol); + + printf("%c", f_string_eol); return f_none; } diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.h b/level_3/fss_extended_list_read/c/fss_extended_list_read.h index 8f66cd1..cb1a423 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.h @@ -32,6 +32,7 @@ #include #include #include +#include #include // fll-2 includes @@ -65,6 +66,7 @@ extern "C" { #define fss_extended_list_read_short_object "o" #define fss_extended_list_read_short_select "s" #define fss_extended_list_read_short_total "t" + #define fss_extended_list_read_short_trim "T" #define fss_extended_list_read_long_at "at" #define fss_extended_list_read_long_depth "depth" @@ -74,6 +76,7 @@ extern "C" { #define fss_extended_list_read_long_object "object" #define fss_extended_list_read_long_select "select" #define fss_extended_list_read_long_total "total" + #define fss_extended_list_read_long_trim "trim" enum { fss_extended_list_read_parameter_help, @@ -90,6 +93,7 @@ extern "C" { fss_extended_list_read_parameter_object, fss_extended_list_read_parameter_select, fss_extended_list_read_parameter_total, + fss_extended_list_read_parameter_trim, }; #define f_console_parameter_initialize_fss_extended_list_read \ @@ -107,9 +111,10 @@ extern "C" { f_console_parameter_initialize(fss_extended_list_read_short_object, fss_extended_list_read_long_object, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_extended_list_read_short_select, fss_extended_list_read_long_select, 0, f_true, f_console_type_normal), \ f_console_parameter_initialize(fss_extended_list_read_short_total, fss_extended_list_read_long_total, 0, f_false, f_console_type_normal), \ + f_console_parameter_initialize(fss_extended_list_read_short_trim, fss_extended_list_read_long_trim, 0, f_false, f_console_type_normal), \ } - #define fss_extended_list_read_total_parameters 13 + #define fss_extended_list_read_total_parameters 14 #endif // _di_fss_extended_list_read_defines_ #ifndef _di_fss_extended_list_read_data_ diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c index 7f3b7bc..4cc033a 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c @@ -111,7 +111,8 @@ extern "C" { depths->array[i].index_at = 0; depths->array[i].index_name = 0; depths->array[i].value_at = 0; - depths->array[i].value_name = f_string_eos; + + f_macro_string_dynamic_clear(depths->array[i].value_name); if (data.parameters[fss_extended_list_read_parameter_depth].additional.used == 0) { position_depth = 0; @@ -159,9 +160,15 @@ extern "C" { } depths->array[i].index_name = data.parameters[fss_extended_list_read_parameter_name].additional.array[position_name]; - depths->array[i].value_name = arguments.argv[depths->array[i].index_name]; - if (depths->array[i].value_name[0] == '\0') { + if (data.parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) { + fl_string_rip_trim(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + else { + fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + + if (depths->array[i].value_name.used == 0) { fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: The '"); fl_color_print(f_standard_error, data.context.notable, data.context.reset, "--%s", fss_extended_list_read_long_name); fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' must not be an empty string."); @@ -316,18 +323,23 @@ extern "C" { if (depth_setting.index_name > 0) { memset(names, 0, sizeof(bool) * items->used); - f_string_length argv_length = strlen(depth_setting.value_name); - f_string_length name_length = 0; + f_string_location value_location = f_string_location_initialize; + value_location.stop = depth_setting.value_name.used - 1; - for (f_string_length i = 0; i < items->used; i++) { - name_length = (items->array[i].object.stop - items->array[i].object.start) + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + items->array[i].object.start, depth_setting.value_name, name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) { + for (f_string_length i = 0; i < items->used; i++) { + if (fl_string_dynamic_partial_compare_trim(data->buffer, depth_setting.value_name, items->array[i].object, value_location) == f_equal_to) { names[i] = 1; } - } - } // for + } // for + } + else { + for (f_string_length i = 0; i < items->used; i++) { + if (fl_string_dynamic_partial_compare(data->buffer, depth_setting.value_name, items->array[i].object, value_location) == f_equal_to) { + names[i] = 1; + } + } // for + } } else { memset(names, 1, sizeof(bool) * items->used); @@ -370,24 +382,29 @@ extern "C" { return f_none; } - else { - if (depth_setting.index_at > 0) { - if (depth_setting.value_at < items->used && names[depth_setting.value_at]) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, items->array[depth_setting.value_at].object); - fprintf(f_standard_output, "%c", f_string_eol); - } - return f_none; + f_return_status (*print_object)(FILE *, const f_string_dynamic, const f_string_location) = &f_print_string_dynamic_partial; + + if (data->parameters[fss_extended_list_read_parameter_trim].result == f_console_result_found) { + print_object = &fl_print_trim_string_dynamic_partial; + } + + if (depth_setting.index_at > 0) { + if (depth_setting.value_at < items->used && names[depth_setting.value_at]) { + print_object(f_standard_output, data->buffer, items->array[depth_setting.value_at].object); + fprintf(f_standard_output, "%c", f_string_eol); } - for (f_array_length i = 0; i < items->used; i++) { - if (names[i]) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, items->array[i].object); - fprintf(f_standard_output, "%c", f_string_eol); - } - } // for + return f_none; } + for (f_array_length i = 0; i < items->used; i++) { + if (names[i]) { + print_object(f_standard_output, data->buffer, items->array[i].object); + fprintf(f_standard_output, "%c", f_string_eol); + } + } // for + return f_none; } diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h index 4952acc..27d9e8f 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h @@ -31,7 +31,7 @@ extern "C" { f_array_length index_name; f_number_unsigned value_at; - f_string value_name; + f_string_dynamic value_name; } fss_extended_list_read_depth; #define fss_extended_list_read_depth_initialize \ @@ -40,8 +40,21 @@ extern "C" { 0, \ 0, \ 0, \ - f_string_initialize, \ + f_string_dynamic_initialize, \ } + + #define macro_fss_extended_list_read_depth_clear(structure) \ + structure.depth = 0; \ + structure.index_at = 0; \ + structure.index_name = 0; \ + structure.value_at = 0; \ + f_macro_string_dynamic_clear(structure.value_name) + + #define macro_fss_extended_list_read_depth_delete(status, structure) f_macro_string_dynamic_delete(status, structure.value_name) + #define macro_fss_extended_list_read_depth_destroy(status, structure) f_macro_string_dynamic_destroy(status, structure.value_name) + + #define macro_fss_extended_list_read_depth_delete_simple(structure) f_macro_string_dynamic_delete_simple(structure.value_name) + #define macro_fss_extended_list_read_depth_destroy_simple(structure) f_macro_string_dynamic_destroy_simple(structure.value_name) #endif // _di_fss_extended_list_read_depth_ /** @@ -65,14 +78,83 @@ extern "C" { #define macro_fss_extended_list_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_extended_list_read_depth, length) - #define macro_fss_extended_list_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_extended_list_read_depth) - #define macro_fss_extended_list_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_extended_list_read_depth) + #define macro_fss_extended_list_read_depths_delete(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_list_read_depth_delete(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_delete(depths, fss_extended_list_read_depth) + + #define macro_fss_extended_list_read_depths_destroy(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_list_read_depth_destroy(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_destroy(depths, fss_extended_list_read_depth) - #define macro_fss_extended_list_read_depths_delete_simple(depths) f_macro_memory_structure_delete_simple(depths, fss_extended_list_read_depth) - #define macro_fss_extended_list_read_depths_destroy_simple(depths) f_macro_memory_structure_destroy_simple(depths, fss_extended_list_read_depth) + #define macro_fss_extended_list_read_depths_delete_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_list_read_depth_delete_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_delete_simple(depths, fss_extended_list_read_depth) - #define macro_fss_extended_list_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_extended_list_read_depth, new_length) - #define macro_fss_extended_list_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_extended_list_read_depth, new_length) + #define macro_fss_extended_list_read_depths_destroy_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_list_read_depth_destroy_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_destroy_simple(depths, fss_extended_list_read_depth) + + #define macro_fss_extended_list_read_depths_resize(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_extended_list_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_resize((void **) & depths.array, sizeof(fss_extended_list_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_extended_list_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } + + #define macro_fss_extended_list_read_depths_adjust(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_extended_list_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_adjust((void **) & depths.array, sizeof(fss_extended_list_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_extended_list_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } #endif // _di_fss_extended_list_read_depths_ /** diff --git a/level_3/fss_extended_list_read/data/build/dependencies b/level_3/fss_extended_list_read/data/build/dependencies index 2615941..73e0e63 100644 --- a/level_3/fss_extended_list_read/data/build/dependencies +++ b/level_3/fss_extended_list_read/data/build/dependencies @@ -11,6 +11,7 @@ fl_console fl_directory fl_file fl_fss +fl_print fl_status fl_string fll_execute diff --git a/level_3/fss_extended_list_read/data/build/settings b/level_3/fss_extended_list_read/data/build/settings index cefe159..1dad99f 100644 --- a/level_3/fss_extended_list_read/data/build/settings +++ b/level_3/fss_extended_list_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_color -lfl_console -lf_conversion -lfl_directory -lfl_file -lfl_fss -lfl_print -lfl_status -lfl_string -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 build_libraries_fll-monolithic -lfll build_sources_library fss_extended_list_read.c private-fss_extended_list_read.c 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 b8dadd8..91a712a 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -25,6 +25,7 @@ extern "C" { fll_program_print_help_option(data.context, fss_extended_read_short_object, fss_extended_read_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the object instead of the content."); fll_program_print_help_option(data.context, fss_extended_read_short_select, fss_extended_read_long_select, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select sub-content at this index."); fll_program_print_help_option(data.context, fss_extended_read_short_total, fss_extended_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of lines."); + fll_program_print_help_option(data.context, fss_extended_read_short_trim, fss_extended_read_long_trim, f_console_symbol_short_enable, f_console_symbol_long_enable, " Trim object names on select or print."); fll_program_print_help_usage(data.context, fss_extended_read_name, "filename(s)"); @@ -106,9 +107,15 @@ extern "C" { printf(" For parameters like "); fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_extended_read_long_select); - printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid."); + printf(", if the standard doesn't support multiple content groups, then only a select of 0 would be valid.%c", f_string_eol); - printf("%c%c", f_string_eol, f_string_eol); + printf("%c", f_string_eol); + + printf(" The parameter "); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_extended_read_long_trim); + printf(" will remove leading and trailing whitespaces when selecting objects or when printing objects.%c", f_string_eol); + + printf("%c", f_string_eol); return f_none; } diff --git a/level_3/fss_extended_read/c/fss_extended_read.h b/level_3/fss_extended_read/c/fss_extended_read.h index 1123446..46c0208 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -32,6 +32,7 @@ #include #include #include +#include #include // fll-2 includes @@ -65,6 +66,7 @@ extern "C" { #define fss_extended_read_short_object "o" #define fss_extended_read_short_select "s" #define fss_extended_read_short_total "t" + #define fss_extended_read_short_trim "T" #define fss_extended_read_long_at "at" #define fss_extended_read_long_depth "depth" @@ -74,6 +76,7 @@ extern "C" { #define fss_extended_read_long_object "object" #define fss_extended_read_long_select "select" #define fss_extended_read_long_total "total" + #define fss_extended_read_long_trim "trim" enum { fss_extended_read_parameter_help, @@ -90,6 +93,7 @@ extern "C" { fss_extended_read_parameter_object, fss_extended_read_parameter_select, fss_extended_read_parameter_total, + fss_extended_read_parameter_trim, }; #define f_console_parameter_initialize_fss_extended_read \ @@ -107,9 +111,10 @@ extern "C" { f_console_parameter_initialize(fss_extended_read_short_object, fss_extended_read_long_object, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_extended_read_short_select, fss_extended_read_long_select, 0, f_true, f_console_type_normal), \ f_console_parameter_initialize(fss_extended_read_short_total, fss_extended_read_long_total, 0, f_false, f_console_type_normal), \ + f_console_parameter_initialize(fss_extended_read_short_trim, fss_extended_read_long_trim, 0, f_false, f_console_type_normal), \ } - #define fss_extended_read_total_parameters 13 + #define fss_extended_read_total_parameters 14 #endif // _di_fss_extended_read_defines_ #ifndef _di_fss_extended_read_data_ 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 7ba6354..31c0b8c 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 @@ -111,7 +111,8 @@ extern "C" { depths->array[i].index_at = 0; depths->array[i].index_name = 0; depths->array[i].value_at = 0; - depths->array[i].value_name = f_string_eos; + + f_macro_string_dynamic_clear(depths->array[i].value_name); if (data.parameters[fss_extended_read_parameter_depth].additional.used == 0) { position_depth = 0; @@ -159,9 +160,15 @@ extern "C" { } depths->array[i].index_name = data.parameters[fss_extended_read_parameter_name].additional.array[position_name]; - depths->array[i].value_name = arguments.argv[depths->array[i].index_name]; - if (depths->array[i].value_name[0] == '\0') { + if (data.parameters[fss_extended_read_parameter_trim].result == f_console_result_found) { + fl_string_rip_trim(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + else { + fl_string_rip(arguments.argv[depths->array[i].index_name], 0, strlen(arguments.argv[depths->array[i].index_name]), &depths->array[i].value_name); + } + + if (depths->array[i].value_name.used == 0) { fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: The '"); fl_color_print(f_standard_error, data.context.notable, data.context.reset, "--%s", fss_extended_read_long_name); fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' must not be an empty string."); @@ -285,18 +292,30 @@ extern "C" { if (depths.array[0].index_name > 0) { memset(names, 0, sizeof(bool) * data->objects.used); - f_string_length argv_length = strlen(depths.array[0].value_name); f_string_length name_length = 0; - for (f_string_length i = 0; i < data->objects.used; i++) { - name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + if (data->parameters[fss_extended_read_parameter_trim].result == f_console_result_found) { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name, name_length, argv_length) == f_equal_to) { - names[i] = 1; + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare_trim(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } } - } - } // for + } // for + } + else { + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = (data->objects.array[i].stop - data->objects.array[i].start) + 1; + + if (name_length == depths.array[0].value_name.used) { + if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name.string, name_length, depths.array[0].value_name.used) == f_equal_to) { + names[i] = 1; + } + } + } // for + } } else { memset(names, 1, sizeof(bool) * data->objects.used); @@ -336,6 +355,12 @@ extern "C" { return f_none; } + f_return_status (*print_object)(FILE *, const f_string_dynamic, const f_string_location) = &f_print_string_dynamic_partial; + + if (data->parameters[fss_extended_read_parameter_trim].result == f_console_result_found) { + print_object = &fl_print_trim_string_dynamic_partial; + } + if (depths.array[0].index_at > 0) { f_array_length at = 0; f_array_length i = 0; @@ -343,7 +368,7 @@ extern "C" { for (; i < data->objects.used; i++) { if (names[i]) { if (at == depths.array[0].value_at) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); break; } @@ -358,7 +383,7 @@ extern "C" { for (f_string_length i = 0; i < data->objects.used; i++) { if (names[i] == 0) continue; - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + print_object(f_standard_output, data->buffer, data->objects.array[i]); fprintf(f_standard_output, "%c", f_string_eol); } // for diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.h b/level_3/fss_extended_read/c/private-fss_extended_read.h index c48154c..c41837c 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.h +++ b/level_3/fss_extended_read/c/private-fss_extended_read.h @@ -31,7 +31,7 @@ extern "C" { f_array_length index_name; f_number_unsigned value_at; - f_string value_name; + f_string_dynamic value_name; } fss_extended_read_depth; #define fss_extended_read_depth_initialize \ @@ -40,8 +40,21 @@ extern "C" { 0, \ 0, \ 0, \ - f_string_initialize, \ + f_string_dynamic_initialize, \ } + + #define macro_fss_extended_read_depth_clear(structure) \ + structure.depth = 0; \ + structure.index_at = 0; \ + structure.index_name = 0; \ + structure.value_at = 0; \ + f_macro_string_dynamic_clear(structure.value_name) + + #define macro_fss_extended_read_depth_delete(status, structure) f_macro_string_dynamic_delete(status, structure.value_name) + #define macro_fss_extended_read_depth_destroy(status, structure) f_macro_string_dynamic_destroy(status, structure.value_name) + + #define macro_fss_extended_read_depth_delete_simple(structure) f_macro_string_dynamic_delete_simple(structure.value_name) + #define macro_fss_extended_read_depth_destroy_simple(structure) f_macro_string_dynamic_destroy_simple(structure.value_name) #endif // _di_fss_extended_read_depth_ /** @@ -65,14 +78,83 @@ extern "C" { #define macro_fss_extended_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_extended_read_depth, length) - #define macro_fss_extended_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_extended_read_depth) - #define macro_fss_extended_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_extended_read_depth) - - #define macro_fss_extended_read_depths_delete_simple(depths) f_macro_memory_structure_delete_simple(depths, fss_extended_read_depth) - #define macro_fss_extended_read_depths_destroy_simple(depths) f_macro_memory_structure_destroy_simple(depths, fss_extended_read_depth) + #define macro_fss_extended_read_depths_delete(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_read_depth_delete(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_delete(depths, fss_extended_read_depth) + + #define macro_fss_extended_read_depths_destroy(status, depths) \ + status = f_none; \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_read_depth_destroy(status, depths.array[depths.used]); \ + if (status != f_none) break; \ + } \ + if (status == f_none) f_macro_memory_structure_destroy(depths, fss_extended_read_depth) + + #define macro_fss_extended_read_depths_delete_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_read_depth_delete_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_delete_simple(depths, fss_extended_read_depth) + + #define macro_fss_extended_read_depths_destroy_simple(depths) \ + depths.used = depths.size; \ + while (depths.used > 0) { \ + depths.used--; \ + macro_fss_extended_read_depth_destroy_simple(depths.array[depths.used]); \ + } \ + if (depths.used == 0) f_macro_memory_structure_destroy_simple(depths, fss_extended_read_depth) + + #define macro_fss_extended_read_depths_resize(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_extended_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_resize((void **) & depths.array, sizeof(fss_extended_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_extended_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } - #define macro_fss_extended_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_extended_read_depth, new_length) - #define macro_fss_extended_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_extended_read_depth, new_length) + #define macro_fss_extended_read_depths_adjust(status, depths, new_length) \ + status = f_none; \ + if (new_length < depths.size) { \ + f_array_length i = depths.size - new_length; \ + for (; i < depths.size; i++) { \ + macro_fss_extended_read_depth_delete(status, depths.array[i]); \ + if (status != f_none) break; \ + } \ + } \ + if (status == f_none) status = f_memory_adjust((void **) & depths.array, sizeof(fss_extended_read_depth), depths.size, new_length); \ + if (status == f_none) { \ + if (new_length > depths.size) { \ + f_array_length i = depths.size; \ + for (; i < new_length; i++) { \ + memset(&depths.array[i], 0, sizeof(fss_extended_read_depth)); \ + } \ + } \ + depths.size = new_length; \ + if (depths.used > depths.size) depths.used = new_length; \ + } #endif // _di_fss_extended_read_depths_ /** diff --git a/level_3/fss_extended_read/data/build/dependencies b/level_3/fss_extended_read/data/build/dependencies index 2615941..73e0e63 100644 --- a/level_3/fss_extended_read/data/build/dependencies +++ b/level_3/fss_extended_read/data/build/dependencies @@ -11,6 +11,7 @@ fl_console fl_directory fl_file fl_fss +fl_print fl_status fl_string fll_execute diff --git a/level_3/fss_extended_read/data/build/settings b/level_3/fss_extended_read/data/build/settings index 6e19053..bf9b43c 100644 --- a/level_3/fss_extended_read/data/build/settings +++ b/level_3/fss_extended_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_file -lfll_fss -lfll_execute -lfl_color -lfl_console -lf_conversion -lfl_directory -lfl_file -lfl_fss -lfl_print -lfl_status -lfl_string -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 build_libraries_fll-monolithic -lfll build_sources_library fss_extended_read.c private-fss_extended_read.c -- 1.8.3.1