]> Kevux Git Server - fll/commitdiff
Feature: add fss snatch functions for "snatching" content for a set of object names
authorKevin Day <thekevinday@gmail.com>
Tue, 5 May 2020 05:00:50 +0000 (00:00 -0500)
committerKevin Day <thekevinday@gmail.com>
Tue, 5 May 2020 05:00:50 +0000 (00:00 -0500)
These are intended to be used for simple purposes.
Directly implementing these in individual projects are recommended for more advanced usage.
I intend to expand on these "snatch" functions in the near future.

build/level_2/settings
build/monolithic/settings
level_2/fll_fss/c/fss.c [new file with mode: 0644]
level_2/fll_fss/c/fss.h [new file with mode: 0644]
level_2/fll_fss/data/build/settings

index ece6d6042c60167f32468d5a0e697d0e34843ce4..231da0986c62b2d0fc183710e55ee20ec2bd9f60 100644 (file)
@@ -12,9 +12,9 @@ build_linker ar
 build_libraries -lc
 build_libraries_fll -lfll_0 -lfll_1
 build_libraries_fll-level -lfll_0 -lfll_1
-build_sources_library execute.c file.c fss_basic.c fss_basic_list.c fss_extended.c fss_extended_list.c fss_status.c program.c status.c
+build_sources_library execute.c file.c fss.c fss_basic.c fss_basic_list.c fss_extended.c fss_extended_list.c fss_status.c program.c status.c
 build_sources_program 
-build_sources_headers execute.h file.h fss_basic.h fss_basic_list.h fss_extended.h fss_extended_list.h fss_status.h program.h status.h
+build_sources_headers execute.h file.h fss.h fss_basic.h fss_basic_list.h fss_extended.h fss_extended_list.h fss_status.h program.h status.h
 build_shared yes
 build_static yes
 
index c63cf4e89793c6d7d825ed530cdc9042bd86334e..14bc65b43128a0e8d293e15d44124574901f5872 100644 (file)
@@ -11,9 +11,9 @@ build_compiler gcc
 build_linker ar
 build_libraries -lc
 build_libraries_fll
-build_sources_library level_0/console.c level_0/conversion.c level_0/file.c level_0/memory.c level_0/pipe.c level_0/print.c level_0/utf.c level_0/private-utf.c level_1/color.c level_1/console.c level_1/directory.c level_1/file.c level_1/fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/print.c level_1/serialized.c level_1/private-serialized.c level_1/socket.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_2/execute.c level_2/file.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/program.c level_2/status.c
+build_sources_library level_0/console.c level_0/conversion.c level_0/file.c level_0/memory.c level_0/pipe.c level_0/print.c level_0/utf.c level_0/private-utf.c level_1/color.c level_1/console.c level_1/directory.c level_1/file.c level_1/fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/print.c level_1/serialized.c level_1/private-serialized.c level_1/socket.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_2/execute.c level_2/file.c level_2/fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/program.c level_2/status.c
 build_sources_program
-build_sources_headers level_0/color.h level_0/console.h level_0/conversion.h level_0/file.h level_0/fss.h level_0/memory.h level_0/path_fll.h level_0/path_filesystem.h level_0/pipe.h level_0/print.h level_0/serialized.h level_0/socket.h level_0/status.h level_0/string.h level_0/type.h level_0/type_array.h level_0/utf.h level_1/color.h level_1/console.h level_1/directory.h level_1/file.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_status.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_macro.h level_1/print.h level_1/serialized.h level_1/socket.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.h level_2/execute.h level_2/file.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/program.h level_2/status.h
+build_sources_headers level_0/color.h level_0/console.h level_0/conversion.h level_0/file.h level_0/fss.h level_0/memory.h level_0/path_fll.h level_0/path_filesystem.h level_0/pipe.h level_0/print.h level_0/serialized.h level_0/socket.h level_0/status.h level_0/string.h level_0/type.h level_0/type_array.h level_0/utf.h level_1/color.h level_1/console.h level_1/directory.h level_1/file.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_status.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_macro.h level_1/print.h level_1/serialized.h level_1/socket.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.h level_2/execute.h level_2/file.h level_2/fss.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/program.h level_2/status.h
 build_sources_bash
 build_sources_settings
 build_shared yes
diff --git a/level_2/fll_fss/c/fss.c b/level_2/fll_fss/c/fss.c
new file mode 100644 (file)
index 0000000..c33595e
--- /dev/null
@@ -0,0 +1,89 @@
+#include <level_2/fss.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_fll_fss_snatch_
+  f_return_status fll_fss_snatch(const f_string_dynamic buffer, const f_fss_objects objects, const f_fss_contents contents, const f_string names[], const f_string_length lengths[], f_string_dynamic *values[], const f_string_length size) {
+    #ifndef _di_level_2_parameter_checking_
+      if (size == 0) return f_status_set_error(f_invalid_parameter);
+    #endif // _di_level_2_parameter_checking_
+
+    if (buffer.used == 0) return f_no_data;
+    if (objects.used == 0) return f_no_data;
+    if (contents.used == 0) return f_no_data;
+
+    f_status status = f_none;
+    f_string_length length_object = 0;
+
+    f_array_length i = 0;
+    f_array_length j = 0;
+    f_array_length k = 0;
+
+    for (; i < objects.used; i++) {
+      length_object = (objects.array[i].stop - objects.array[i].start) + 1;
+
+      for (j = 0; j < size; j++) {
+        if (fl_string_compare_trim(buffer.string + objects.array[i].start, names[j], length_object, lengths[j]) == f_equal_to) {
+          if (values[j]->used == 0) {
+            for (k = 0; k < contents.array[i].used; k++) {
+              status = fl_string_dynamic_partial_append_nulless(buffer, contents.array[i].array[k], values[j]);
+
+              if (f_status_is_error(status)) break;
+            } // for
+
+            if (f_status_is_error(status)) break;
+          }
+        }
+      } // for
+
+      if (f_status_is_error(status)) break;
+    } // for
+
+    return status;
+  }
+#endif // _di_fll_fss_snatch_
+
+#ifndef _di_fll_fss_snatch_mash_
+  f_return_status fll_fss_snatch_mash(const f_string_dynamic buffer, const f_fss_objects objects, const f_fss_contents contents, const f_string names[], const f_string_length lengths[], f_string_dynamic *values[], const f_string_length size, const f_string glue, const f_string_length glue_length) {
+    #ifndef _di_level_2_parameter_checking_
+      if (size == 0) return f_status_set_error(f_invalid_parameter);
+    #endif // _di_level_2_parameter_checking_
+
+    if (buffer.used == 0) return f_no_data;
+    if (objects.used == 0) return f_no_data;
+    if (contents.used == 0) return f_no_data;
+
+    f_status status = f_none;
+    f_string_length length_object = 0;
+
+    f_array_length i = 0;
+    f_array_length j = 0;
+    f_array_length k = 0;
+
+    for (; i < objects.used; i++) {
+      length_object = (objects.array[i].stop - objects.array[i].start) + 1;
+
+      for (j = 0; j < size; j++) {
+        if (fl_string_compare_trim(buffer.string + objects.array[i].start, names[j], length_object, lengths[j]) == f_equal_to) {
+          for (k = 0; k < contents.array[i].used; k++) {
+            status = fl_string_dynamic_partial_mash_nulless(glue, glue_length, buffer, contents.array[i].array[k], values[j]);
+
+            if (f_status_is_error(status)) break;
+          } // for
+
+          if (f_status_is_error(status)) break;
+        }
+      } // for
+
+      if (f_status_is_error(status)) break;
+    } // for
+
+    return status;
+  }
+#endif // _di_fll_fss_snatch_mash_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_2/fll_fss/c/fss.h b/level_2/fll_fss/c/fss.h
new file mode 100644 (file)
index 0000000..4a90619
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * FLL - Level 2
+ *
+ * Project: FSS
+ * API Version: 0.5
+ * Licenses: lgplv2.1
+ *
+ * Provide common FSS functions.
+ *
+ * @todo add "snatch" functions to grab contents in separate sets instead of appending (such as for fss extended).
+ */
+#ifndef _FLL_fss_h
+#define _FLL_fss_h
+
+// fll-0 includes
+#include <level_0/status.h>
+#include <level_0/fss.h>
+#include <level_0/memory.h>
+#include <level_0/string.h>
+#include <level_0/type.h>
+#include <level_0/utf.h>
+
+// fll-1 includes
+#include <level_1/fss.h>
+#include <level_1/fss_macro.h>
+#include <level_1/fss_status.h>
+#include <level_1/string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Perform simple search through all objects against the given set, saving all values when matched.
+ *
+ * Only the first match for each name is snatched, all others are ignored.
+ *
+ * This will trim the object names when comparing (removing leading/trailing whitespace).
+ * This will strip NULL charactes when copying.
+ *
+ * This performs only a simple search algorithm that should be acceptable for small sets where performance is generally not a concern.
+ *
+ * @param buffer
+ *   The buffer to read from.
+ * @param objects
+ *   This object mappings to process.
+ * @param contents
+ *   This content mappings to process.
+ * @param names
+ *   An array of strings to "snatch" from the buffer.
+ * @param lengths
+ *   An array of lengths for each names string.
+ * @param values
+ *   An array of values where "snatched" content is stored.
+ *   Each of these must be of type f_string_dynamic.
+ * @param size
+ *   The total size of the names, lengths, and values arrays.
+ *
+ * @return
+ *   f_none on success.
+ *   f_no_data when there is no buffer, objects or contents to process.
+ *   f_error_reallocation (with error bit) on reallocation error.
+ *   f_invalid_parameter (with error bit) if a parameter is invalid.
+ */
+#ifndef _di_fll_fss_snatch_
+  extern f_return_status fll_fss_snatch(const f_string_dynamic buffer, const f_fss_objects objects, const f_fss_contents contents, const f_string names[], const f_string_length lengths[], f_string_dynamic *values[], const f_string_length size);
+#endif // _di_fll_fss_snatch_
+
+/**
+ * Perform simple search through all objects against the given set, saving all values when matched.
+ *
+ * This will append all duplicates using the provided glue.
+ * This will trim the object names when comparing (removing leading/trailing whitespace).
+ * This will strip NULL charactes when copying.
+ *
+ * This performs only a simple search algorithm that should be acceptable for small sets where performance is generally not a concern.
+ *
+ * @param buffer
+ *   The buffer to read from.
+ * @param objects
+ *   This object mappings to process.
+ * @param contents
+ *   This content mappings to process.
+ * @param names
+ *   An array of strings to "snatch" from the buffer.
+ *   Each of these must be of type f_string.
+ * @param lengths
+ *   An array of lengths for each names string.
+ *   Each of these must be of type f_string_length.
+ * @param values
+ *   An array of values where "snatched" content is stored.
+ *   Each of these must be of type f_string_dynamic.
+ * @param size
+ *   The total size of the names, lengths, and values arrays.
+ * @param glue
+ *   A string to append between each duplicate name found when "snatching".
+ * @param glue_length
+ *   The length of the glue string.
+ *
+ * @return
+ *   f_none on success.
+ *   f_no_data when there is no buffer, objects or contents to process.
+ *   f_error_reallocation (with error bit) on reallocation error.
+ *   f_invalid_parameter (with error bit) if a parameter is invalid.
+ */
+#ifndef _di_fll_fss_snatch_mash_
+  extern f_return_status fll_fss_snatch_mash(const f_string_dynamic buffer, const f_fss_objects objects, const f_fss_contents contents, const f_string names[], const f_string_length lengths[], f_string_dynamic *values[], const f_string_length size, const f_string glue, const f_string_length glue_length);
+#endif // _di_fll_fss_snatch_mash_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _FLL_fss_h
index fae4f812143dc0b712e6b3f2a748bb23d35eac61..1f4577fa5202bfa1bfe481d4d945f96839d377bc 100644 (file)
@@ -11,9 +11,9 @@ build_compiler gcc
 build_linker ar
 build_libraries -lc
 build_libraries_fll -lfl_string -lfl_status -lfl_fss -lf_file -lf_utf -lf_conversion -lf_memory
-build_sources_library fss_basic.c fss_basic_list.c fss_extended.c fss_extended_list.c fss_status.c
+build_sources_library fss.c fss_basic.c fss_basic_list.c fss_extended.c fss_extended_list.c fss_status.c
 build_sources_program
-build_sources_headers fss_basic.h fss_basic_list.h fss_extended.h fss_extended_list.h fss_status.h
+build_sources_headers fss.h fss_basic.h fss_basic_list.h fss_extended.h fss_extended_list.h fss_status.h
 build_sources_bash
 build_sources_settings
 build_shared yes