]> Kevux Git Server - fll/commitdiff
Feature: implement support for the -T/--trim parameter
authorKevin Day <thekevinday@gmail.com>
Thu, 23 Apr 2020 01:40:50 +0000 (20:40 -0500)
committerKevin Day <thekevinday@gmail.com>
Thu, 23 Apr 2020 01:40:50 +0000 (20:40 -0500)
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.

24 files changed:
level_3/fss_basic_list_read/c/fss_basic_list_read.c
level_3/fss_basic_list_read/c/fss_basic_list_read.h
level_3/fss_basic_list_read/c/private-fss_basic_list_read.c
level_3/fss_basic_list_read/c/private-fss_basic_list_read.h
level_3/fss_basic_list_read/data/build/dependencies
level_3/fss_basic_list_read/data/build/settings
level_3/fss_basic_read/c/fss_basic_read.c
level_3/fss_basic_read/c/fss_basic_read.h
level_3/fss_basic_read/c/private-fss_basic_read.c
level_3/fss_basic_read/c/private-fss_basic_read.h
level_3/fss_basic_read/data/build/dependencies
level_3/fss_basic_read/data/build/settings
level_3/fss_extended_list_read/c/fss_extended_list_read.c
level_3/fss_extended_list_read/c/fss_extended_list_read.h
level_3/fss_extended_list_read/c/private-fss_extended_list_read.c
level_3/fss_extended_list_read/c/private-fss_extended_list_read.h
level_3/fss_extended_list_read/data/build/dependencies
level_3/fss_extended_list_read/data/build/settings
level_3/fss_extended_read/c/fss_extended_read.c
level_3/fss_extended_read/c/fss_extended_read.h
level_3/fss_extended_read/c/private-fss_extended_read.c
level_3/fss_extended_read/c/private-fss_extended_read.h
level_3/fss_extended_read/data/build/dependencies
level_3/fss_extended_read/data/build/settings

index 64d8412494c68a21a7920cc7abbb8e725077fa86..3a6fd7ecca5149961c19dbc5cf295d7a39f0fb54 100644 (file)
@@ -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;
   }
index 3a071e32b46d684e4a0c0107b8b9db62be74e50b..8da0d4dd6adb5329eac8f89eefdcfac67e76a300 100644 (file)
@@ -32,6 +32,7 @@
 #include <level_1/console.h>
 #include <level_1/directory.h>
 #include <level_1/file.h>
+#include <level_1/print.h>
 #include <level_1/string.h>
 
 // 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_
index 99fc9b1089f648fbe5904b70db964a56f9b74d55..b6da80c63e95f49c56c924776a84f22118ac8a62 100644 (file)
@@ -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
 
index 1a4f9458c37bc584ede719111683a5546d7a888a..d43513e846ae5a1910c16e7edadc19a587bdf5af 100644 (file)
@@ -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_
 
 /**
index 2615941d1f68ae815943e32b1669a870e537ac31..73e0e634de9da679ab256cb99a68a7f2afd6f974 100644 (file)
@@ -11,6 +11,7 @@ fl_console
 fl_directory
 fl_file
 fl_fss
+fl_print
 fl_status
 fl_string
 fll_execute
index 762d22658ef3450fbaf1fec5cd8f79b28b7e0f5a..792b21f37a8fe9afb9cd9cc41c9d655985e1d34f 100644 (file)
@@ -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
index 28a4b21fc0b00ba3d06b651260b25331035f066d..c225d54a55cf67159d01bef4a6f06df3ad3613af 100644 (file)
@@ -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;
   }
index 440ce7782c862199b95f6bc340570d87c6bec016..ed7eac5a78409c542e7ab1595730340091728283 100644 (file)
@@ -32,6 +32,7 @@
 #include <level_1/console.h>
 #include <level_1/directory.h>
 #include <level_1/file.h>
+#include <level_1/print.h>
 #include <level_1/string.h>
 
 // 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_
index c06cdeebb9353a34393b8962ad3f9e627b79dab5..f0eb68c2f77b4a69247f4ae85d68a947266f9a05 100644 (file)
@@ -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
 
index f9f2a28787c5dcb3e298c255d789a06b22acd272..5ab4ccb01cac34f19ac167710f1983dca595c7d5 100644 (file)
@@ -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_
 
 /**
index 2615941d1f68ae815943e32b1669a870e537ac31..73e0e634de9da679ab256cb99a68a7f2afd6f974 100644 (file)
@@ -11,6 +11,7 @@ fl_console
 fl_directory
 fl_file
 fl_fss
+fl_print
 fl_status
 fl_string
 fll_execute
index 4230baffdaf2383d07de283d20c58fe59699b9b1..fa1a568c81b94ea7da720e48f3c8f8038d5cb957 100644 (file)
@@ -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
index 1f7b005a1f75c9227d92900e346c34b52e3e381d..dd9909dc3d823e4c08d056acb17af75ddc28f904 100644 (file)
@@ -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;
   }
index 8f66cd1b19a09498cec79d6c6ef362e70ff72e8e..cb1a423e6bb2024a8584b5da70e58abe4751daff 100644 (file)
@@ -32,6 +32,7 @@
 #include <level_1/console.h>
 #include <level_1/directory.h>
 #include <level_1/file.h>
+#include <level_1/print.h>
 #include <level_1/string.h>
 
 // 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_
index 7f3b7bc909b1826ca89d3d7983134fd475b4296d..4cc033ab1dc2eeef20c17a5681ac8769e7a81d35 100644 (file)
@@ -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;
     }
 
index 4952acc6d9dc3927f260272d725222e9c3cbd99b..27d9e8f191dc604f247253c97eb7ec7f6bebb4bf 100644 (file)
@@ -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_
 
 /**
index 2615941d1f68ae815943e32b1669a870e537ac31..73e0e634de9da679ab256cb99a68a7f2afd6f974 100644 (file)
@@ -11,6 +11,7 @@ fl_console
 fl_directory
 fl_file
 fl_fss
+fl_print
 fl_status
 fl_string
 fll_execute
index cefe159756db211082bfe72ed3ad11bd02805d41..1dad99f467e5e65ad68b88a8fe7c8cc7ede4fcb3 100644 (file)
@@ -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
index b8dadd8272642e6329e15a252e34c6cf5f112015..91a712a1624f9aaaeb076399930eac883720ad1c 100644 (file)
@@ -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;
   }
index 11234466e8bab4c11714e4e691c8b702cc42d622..46c02085f763671d19952f96836a0f2bfde686a0 100644 (file)
@@ -32,6 +32,7 @@
 #include <level_1/console.h>
 #include <level_1/directory.h>
 #include <level_1/file.h>
+#include <level_1/print.h>
 #include <level_1/string.h>
 
 // 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_
index 7ba6354589057b52d43f808fded25c3196acba01..31c0b8c5921cf2dad9d646e14a64bc8b5fefa75d 100644 (file)
@@ -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
 
index c48154c46a3e81b5509ffa0f928b9b0d48f79280..c41837ce20ddf69a8898c46c00877e48066083f7 100644 (file)
@@ -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_
 
 /**
index 2615941d1f68ae815943e32b1669a870e537ac31..73e0e634de9da679ab256cb99a68a7f2afd6f974 100644 (file)
@@ -11,6 +11,7 @@ fl_console
 fl_directory
 fl_file
 fl_fss
+fl_print
 fl_status
 fl_string
 fll_execute
index 6e190536a96fcb4a4c27f5c779d7a9070c0e5876..bf9b43c3f2112f39d70b1a19cd66c78208422143 100644 (file)
@@ -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