]> Kevux Git Server - fll/commitdiff
Bugfix: The level_0 console should use private functions.
authorKevin Day <thekevinday@gmail.com>
Sat, 19 Nov 2022 23:42:24 +0000 (17:42 -0600)
committerKevin Day <thekevinday@gmail.com>
Sat, 19 Nov 2022 23:42:24 +0000 (17:42 -0600)
The level_0 f_console_identify function should not be directly called by another function in this project.
Create a private function and call that function.

This is the standard practice for this project
This improves hackability.

build/level_0/settings
build/monolithic/settings
build/stand_alone/fake.settings
build/stand_alone/utf8.settings
level_0/f_console/c/console.c
level_0/f_console/c/console.h
level_0/f_console/c/private-console.c [new file with mode: 0644]
level_0/f_console/c/private-console.h [new file with mode: 0644]
level_0/f_console/data/build/settings

index c14518c6fc2548e94b45422eee3c7798d846bb2a..82abd52cc6fad3e7c0d6a687a781a265b16f2635 100644 (file)
@@ -22,7 +22,7 @@ build_libraries -lc -lcap
 build_sources_library account.c private-account.c
 build_sources_library capability.c
 build_sources_library color.c private-color.c color/common.c
-build_sources_library console.c console/common.c
+build_sources_library console.c console/common.c private-console.c
 build_sources_library control_group.c control_group/common.c
 build_sources_library conversion.c private-conversion.c conversion/common.c
 build_sources_library directory.c directory/common.c private-directory.c
@@ -51,7 +51,7 @@ build_sources_library-level thread.c private-thread.c thread/attribute.c thread/
 build_sources_headers account.h account/common.h
 build_sources_headers capability.h capability/common.h
 build_sources_headers color.h color/common.h
-build_sources_headers console.h console/common.h
+build_sources_headers console.h console/common.h private-console.h
 build_sources_headers control_group.h control_group/common.h
 build_sources_headers conversion.h conversion/common.h
 build_sources_headers directory.h directory/common.h directory/type.h
index da7949ea32ba7a9ac118da23277558f1c71abc60..4176f8f004285ef4a902b0cc606a1530e8d1a172 100644 (file)
@@ -22,7 +22,7 @@ build_libraries -lc -lcap
 build_sources_library level_0/account.c level_0/private-account.c
 build_sources_library level_0/capability.c
 build_sources_library level_0/color.c level_0/private-color.c level_0/color/common.c
-build_sources_library level_0/console.c level_0/console/common.c
+build_sources_library level_0/console.c level_0/console/common.c level_0/private-console.c
 build_sources_library level_0/control_group.c level_0/control_group/common.c
 build_sources_library level_0/conversion.c level_0/private-conversion.c level_0/conversion/common.c
 build_sources_library level_0/directory.c level_0/directory/common.c level_0/private-directory.c
@@ -75,7 +75,7 @@ build_sources_library-monolithic level_0/thread.c level_0/private-thread.c level
 build_sources_headers level_0/account.h level_0/account/common.h
 build_sources_headers level_0/capability.h level_0/capability/common.h
 build_sources_headers level_0/color.h level_0/color/common.h
-build_sources_headers level_0/console.h level_0/console/common.h
+build_sources_headers level_0/console.h level_0/console/common.h level_0/private-console.h
 build_sources_headers level_0/control_group.h level_0/control_group/common.h
 build_sources_headers level_0/conversion.h level_0/conversion/common.h
 build_sources_headers level_0/directory.h level_0/directory/common.h level_0/directory/type.h
index 2463aca447b6b999b20c90211d106fc722f223f7..3e7aef886d45a6740277ab8d065a16cbc6381276 100644 (file)
@@ -26,7 +26,7 @@ build_libraries -lc -lcap
 build_sources_program fll/level_0/account.c fll/level_0/private-account.c
 build_sources_program fll/level_0/capability.c
 build_sources_program fll/level_0/color.c fll/level_0/private-color.c fll/level_0/color/common.c
-build_sources_program fll/level_0/console.c fll/level_0/console/common.c
+build_sources_program fll/level_0/console.c fll/level_0/console/common.c fll/level_0/private-console.c
 build_sources_program fll/level_0/control_group.c fll/level_0/control_group/common.c
 build_sources_program fll/level_0/conversion.c fll/level_0/private-conversion.c fll/level_0/conversion/common.c
 build_sources_program fll/level_0/directory.c fll/level_0/directory/common.c fll/level_0/private-directory.c
index 02873ffec7ec6c261ba118a68de809259c3109a6..b2daeb5e96569123a411262a2ce7ad7c6471681e 100644 (file)
@@ -24,7 +24,7 @@ build_language c
 build_libraries -lc -lcap
 
 build_sources_program fll/level_0/color.c fll/level_0/private-color.c fll/level_0/color/common.c
-build_sources_program fll/level_0/console.c fll/level_0/console/common.c
+build_sources_program fll/level_0/console.c fll/level_0/console/common.c fll/level_0/private-console.c
 build_sources_program fll/level_0/conversion.c fll/level_0/private-conversion.c fll/level_0/conversion/common.c
 build_sources_program fll/level_0/file.c fll/level_0/private-file.c fll/level_0/file/common.c
 build_sources_program fll/level_0/memory.c fll/level_0/private-memory.c fll/level_0/memory/structure.c
index dbaf73e30d8ea6aa2740f642e8cbee32789aee69..7c18b5c9d0131a0613ecf2878f11fe9c8c7ab5e1 100644 (file)
@@ -1,4 +1,5 @@
 #include "console.h"
+#include "private-console.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -69,47 +70,7 @@ extern "C" {
       if (!result) return F_status_set_error(F_parameter);
     #endif // _di_level_0_parameter_checking_f
 
-    if (!input) {
-      *result = f_console_none_e;
-
-      return F_data_not;
-    }
-
-    const f_array_length_t length = strnlen(input, 3);
-
-    if (!length) {
-      *result = f_console_none_e;
-
-      return F_data_not;
-    }
-
-    if (input[0] == f_console_symbol_short_enable_s.string[0]) {
-      if (length > 1) {
-        if (input[1] == f_console_symbol_short_enable_s.string[0]) {
-          if (length > 2) {
-            *result = f_console_long_enable_e;
-          }
-          else *result = f_console_empty_long_enable_e;
-        }
-        else *result = f_console_short_enable_e;
-      }
-      else *result = f_console_empty_short_enable_e;
-    }
-    else if (input[0] == f_console_symbol_short_disable_s.string[0]) {
-      if (length > 1) {
-        if (input[1] == f_console_symbol_short_disable_s.string[0]) {
-          if (length > 2) {
-            *result = f_console_long_disable_e;
-          }
-          else *result = f_console_empty_long_disable_e;
-        }
-        else *result = f_console_short_disable_e;
-      }
-      else *result = f_console_empty_short_disable_e;
-    }
-    else *result = f_console_none_e;
-
-    return F_none;
+    return private_f_console_identify(input, result);
   }
 #endif // _di_f_console_identify_
 
@@ -279,7 +240,7 @@ extern "C" {
         continue;
       }
 
-      f_console_identify(arguments.argv[location], &result);
+      private_f_console_identify(arguments.argv[location], &result);
 
       // Process the current parameter.
       if (result == f_console_short_enable_e || result == f_console_short_disable_e) {
index 4f6df8b7a7513617cad0ce65b64addd5efaf8e9f..5a29d78b19eba4607a3fa3581e6812bc2bbea39c 100644 (file)
@@ -49,7 +49,7 @@ extern "C" {
  * @see f_string_maps_increase_by()
  */
 #ifndef _di_f_console_environment_process_
-  extern f_status_t f_console_environment_process(const f_console_arguments_t arguments, f_string_maps_t * const environment);
+  extern f_status_t f_console_environment_process(const f_console_arguments_t arguments, f_string_maps_t * const environment) F_attribute_visibility_internal_d;
 #endif // _di_f_console_environment_process_
 
 /**
diff --git a/level_0/f_console/c/private-console.c b/level_0/f_console/c/private-console.c
new file mode 100644 (file)
index 0000000..fa421ab
--- /dev/null
@@ -0,0 +1,60 @@
+#include "console.h"
+#include "private-console.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_)
+  f_status_t private_f_console_identify(const f_string_t input, f_console_id_t * const result) {
+    #ifndef _di_level_0_parameter_checking_
+      if (!result) return F_status_set_error(F_parameter);
+    #endif // _di_level_0_parameter_checking_f
+
+    if (!input) {
+      *result = f_console_none_e;
+
+      return F_data_not;
+    }
+
+    const f_array_length_t length = strnlen(input, 3);
+
+    if (!length) {
+      *result = f_console_none_e;
+
+      return F_data_not;
+    }
+
+    if (input[0] == f_console_symbol_short_enable_s.string[0]) {
+      if (length > 1) {
+        if (input[1] == f_console_symbol_short_enable_s.string[0]) {
+          if (length > 2) {
+            *result = f_console_long_enable_e;
+          }
+          else *result = f_console_empty_long_enable_e;
+        }
+        else *result = f_console_short_enable_e;
+      }
+      else *result = f_console_empty_short_enable_e;
+    }
+    else if (input[0] == f_console_symbol_short_disable_s.string[0]) {
+      if (length > 1) {
+        if (input[1] == f_console_symbol_short_disable_s.string[0]) {
+          if (length > 2) {
+            *result = f_console_long_disable_e;
+          }
+          else *result = f_console_empty_long_disable_e;
+        }
+        else *result = f_console_short_disable_e;
+      }
+      else *result = f_console_empty_short_disable_e;
+    }
+    else *result = f_console_none_e;
+
+    return F_none;
+  }
+#endif // !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/level_0/f_console/c/private-console.h b/level_0/f_console/c/private-console.h
new file mode 100644 (file)
index 0000000..c69b568
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * FLL - Level 0
+ *
+ * Project: Console
+ * API Version: 0.6
+ * Licenses: lgpl-2.1-or-later
+ *
+ * These are provided for internal reduction in redundant code.
+ * These should not be exposed/used outside of this project.
+ */
+#ifndef _PRIVATE_F_console_h
+#define _PRIVATE_F_console_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Private implementation of f_console_identify().
+ *
+ * Intended to be shared to each of the different implementation variations.
+ *
+ * @param input
+ *   The input parameter to process.
+ * @param result
+ *   The flag with the console type bits determined by this function.
+ *
+ * @return
+ *   F_none on success.
+ *   F_data_not the input string is empty.
+ *
+ *
+ * @see f_console_identify()
+ * @see f_console_parameter_process()
+ */
+#if !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_)
+  extern f_status_t private_f_console_identify(const f_string_t input, f_console_id_t * const result) F_attribute_visibility_internal_d;
+#endif // !defined(_di_f_console_identify_) || !defined(_di_f_console_parameter_process_)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _PRIVATE_F_console_h
index 7b78e9ce83c62ab666ba3289e744439c1b18a1ff..4182dbb2e0a98149532d0e42f144dc9b315a327a 100644 (file)
@@ -20,9 +20,9 @@ build_language c
 build_libraries -lc
 build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_utf
 
-build_sources_library console.c console/common.c
+build_sources_library console.c console/common.c private-console.c
 
-build_sources_headers console.h console/common.h
+build_sources_headers console.h console/common.h private-console.h
 
 build_script yes
 build_shared yes