]> Kevux Git Server - fll/commitdiff
Update: add UTF-8 support to fl_console
authorKevin Day <thekevinday@gmail.com>
Thu, 29 Aug 2019 00:48:28 +0000 (19:48 -0500)
committerKevin Day <thekevinday@gmail.com>
Thu, 29 Aug 2019 00:48:28 +0000 (19:48 -0500)
Also remove unnecessary looping.

level_0/f_console/c/console.h
level_1/fl_console/c/console.c
level_1/fl_console/c/console.h
level_1/fl_console/data/build/dependencies
level_1/fl_console/data/build/settings

index 138bcf796ae1b563be05516e5f18466c79c2dc69..7dcd80d94da07782a3ccd3cc0b8bbef9da5e7322 100644 (file)
@@ -85,7 +85,8 @@ extern "C" {
 #endif // _di_f_console_max_size_
 
 #ifndef _di_f_console_default_allocation_step_
-  #define f_console_default_allocation_step f_memory_default_allocation_step
+  // provide a UTF-8 friendly allocation step.
+  #define f_console_default_allocation_step 4
 #endif // _di_f_console_default_allocation_step_
 
 #ifndef _di_f_console_types_
@@ -94,7 +95,7 @@ extern "C" {
   /**
    * none: parameter not found.
    * found: parameter found.
-   * additional: parameter found, extra data exists (such as '-f filename', filename would be the extra data).
+   * additional: parameter found, extra data exists (such as '-f filename', 'filename' would be the extra data).
    */
   enum {
     f_console_result_none,
@@ -146,8 +147,8 @@ extern "C" {
    * perform checks against short & long options to see if the string is one of them (normal).
    */
   #define f_console_is_enable(result, string, short_option, long_option, max_length) \
-          ((result == f_console_short_enable && strncmp(string, short_option, 1) == 0) || \
-          (result == f_console_long_enable && strncmp(string, long_option,  max_length) == 0))
+          ((result == f_console_short_enable && strncmp(string, short_option, max_length) == 0) || \
+          (result == f_console_long_enable && strncmp(string, long_option, max_length) == 0))
 #endif // _di_f_console_is_enable_
 
 #ifndef _di_f_console_is_disable_
@@ -155,8 +156,8 @@ extern "C" {
    * perform checks against short & long options to see if the string is one of them (inverse).
    */
   #define f_console_is_disable(result, string, short_option, long_option, max_length) \
-          ((result == f_console_short_disable && strncmp(string, short_option, 1) == 0) || \
-          (result == f_console_long_disable && strncmp(string, long_option,  max_length) == 0))
+          ((result == f_console_short_disable && strncmp(string, short_option, max_length) == 0) || \
+          (result == f_console_long_disable && strncmp(string, long_option, max_length) == 0))
 #endif // _di_f_console_is_disable_
 
 #ifndef _di_f_console_is_extra_enable_
index 0936b933870b01fc5432be31f1585c8b40837286..e82069e33a4d43b57d12740df0c4ddbc7c5a7682 100644 (file)
@@ -22,7 +22,6 @@ extern "C" {
 
     f_string_lengths extra_initiator = f_string_lengths_initialize;
 
-
     // loop through and read all parameters
     while (location < argc) {
       f_console_identify(argv[location], &result);
@@ -49,140 +48,141 @@ extern "C" {
 
       // Now handle the normal commands
       if (argv[location][0] == f_console_symbol_enable) {
-        while (sub_location < string_length) {
+        if (sub_location < string_length) {
           for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
-            if (parameters[parameter_counter].type == f_console_type_normal) {
-              if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
-                if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
-                  parameters[parameter_counter].result = f_console_result_found;
-
-                  if (parameters[parameter_counter].has_additional) {
-                    if (extra_initiator.used >= extra_initiator.size) {
-                      f_status allocation_status = f_none;
-
-                      f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
-                      if (f_error_is_error(allocation_status)) {
-                        f_delete_string_lengths(status, extra_initiator);
-                        return f_error_set_error(allocation_status);
-                      }
-                    }
+            if (parameters[parameter_counter].type != f_console_type_normal) {
+              continue;
+            }
+
+            if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
+              if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
+                parameters[parameter_counter].result = f_console_result_found;
 
-                    extra_initiator.array[extra_initiator.used] = parameter_counter;
-                    extra_initiator.used++;
+                if (parameters[parameter_counter].has_additional) {
+                  if (extra_initiator.used >= extra_initiator.size) {
+                    f_status allocation_status = f_none;
+
+                    f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+                    if (f_error_is_error(allocation_status)) {
+                      f_delete_string_lengths(status, extra_initiator);
+                      return f_error_set_error(allocation_status);
+                    }
                   }
+
+                  extra_initiator.array[extra_initiator.used] = parameter_counter;
+                  extra_initiator.used++;
                 }
               }
+            }
 
-              if (parameters[parameter_counter].symbol_extra != 0) {
-                if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
-                  parameters[parameter_counter].result = f_console_result_found;
+            if (parameters[parameter_counter].symbol_extra != 0) {
+              if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
+                parameters[parameter_counter].result = f_console_result_found;
 
-                  if (parameters[parameter_counter].has_additional) {
-                    if (extra_initiator.used >= extra_initiator.size) {
-                      f_status allocation_status = f_none;
+                if (parameters[parameter_counter].has_additional) {
+                  if (extra_initiator.used >= extra_initiator.size) {
+                    f_status allocation_status = f_none;
 
-                      f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+                    f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
 
-                      if (f_error_is_error(allocation_status)) {
-                        f_delete_string_lengths(status, extra_initiator);
-                        return f_error_set_error(allocation_status);
-                      }
+                    if (f_error_is_error(allocation_status)) {
+                      f_delete_string_lengths(status, extra_initiator);
+                      return f_error_set_error(allocation_status);
                     }
-
-                    extra_initiator.array[extra_initiator.used] = parameter_counter;
-                    extra_initiator.used++;
                   }
+
+                  extra_initiator.array[extra_initiator.used] = parameter_counter;
+                  extra_initiator.used++;
                 }
               }
             }
           } // for
-
-          sub_location += increments;
-        } // while
-
-      // now handle the inverse commands
+        }
       }
+      // now handle the inverse commands
       else if (argv[location][0] == f_console_symbol_disable) {
-        while (sub_location < string_length) {
+        if (sub_location < string_length) {
           for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
-            if (parameters[parameter_counter].type == f_console_type_inverse) {
-              if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
-                if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
-                  parameters[parameter_counter].result = f_console_result_found;
+            if (parameters[parameter_counter].type != f_console_type_inverse) {
+              continue;
+            }
 
-                  if (parameters[parameter_counter].has_additional) {
-                    if (extra_initiator.used >= extra_initiator.size) {
-                      f_status allocation_status = f_none;
+            if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) {
+              if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) {
+                parameters[parameter_counter].result = f_console_result_found;
 
-                      f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+                if (parameters[parameter_counter].has_additional) {
+                  if (extra_initiator.used >= extra_initiator.size) {
+                    f_status allocation_status = f_none;
 
-                      if (f_error_is_error(allocation_status)) {
-                        f_delete_string_lengths(status, extra_initiator);
-                        return f_error_set_error(allocation_status);
-                      }
-                    }
+                    f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
 
-                    extra_initiator.array[extra_initiator.used] = parameter_counter;
-                    extra_initiator.used++;
+                    if (f_error_is_error(allocation_status)) {
+                      f_delete_string_lengths(status, extra_initiator);
+                      return f_error_set_error(allocation_status);
+                    }
                   }
+
+                  extra_initiator.array[extra_initiator.used] = parameter_counter;
+                  extra_initiator.used++;
                 }
               }
+            }
 
-              if (parameters[parameter_counter].symbol_extra != 0) {
-                if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
-                  parameters[parameter_counter].result = f_console_result_found;
+            if (parameters[parameter_counter].symbol_extra != 0) {
+              if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) {
+                parameters[parameter_counter].result = f_console_result_found;
 
-                  if (parameters[parameter_counter].has_additional) {
-                    if (extra_initiator.used >= extra_initiator.size) {
-                      f_status allocation_status = f_none;
+                if (parameters[parameter_counter].has_additional) {
+                  if (extra_initiator.used >= extra_initiator.size) {
+                    f_status allocation_status = f_none;
 
-                      f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+                    f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
 
-                      if (f_error_is_error(allocation_status)) {
-                        f_delete_string_lengths(status, extra_initiator);
-                        return f_error_set_error(allocation_status);
-                      }
+                    if (f_error_is_error(allocation_status)) {
+                      f_delete_string_lengths(status, extra_initiator);
+                      return f_error_set_error(allocation_status);
                     }
-
-                    extra_initiator.array[extra_initiator.used] = parameter_counter;
-                    extra_initiator.used++;
                   }
+
+                  extra_initiator.array[extra_initiator.used] = parameter_counter;
+                  extra_initiator.used++;
                 }
               }
             }
           } // for
-
-          sub_location += increments;
-        } // while
+        }
       }
       else {
         // use found to determine if the remaining parameter should be populated
         found = f_false;
 
         for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) {
-          if (parameters[parameter_counter].type == f_console_type_other) {
-            if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0) {
-              if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0) {
-                f_status allocation_status = f_none;
+          if (parameters[parameter_counter].type != f_console_type_other) {
+            continue;
+          }
 
-                if (parameters[parameter_counter].additional.used >= parameters[parameter_counter].additional.size) {
-                  f_resize_string_lengths(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step);
-                }
+          if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0) {
+            if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0) {
+              f_status allocation_status = f_none;
 
-                if (f_error_is_error(allocation_status)) {
-                  f_delete_string_lengths(status, extra_initiator);
-                  return f_error_set_error(allocation_status);
-                }
+              if (parameters[parameter_counter].additional.used >= parameters[parameter_counter].additional.size) {
+                f_resize_string_lengths(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step);
+              }
 
-                parameters[parameter_counter].result = f_console_result_found;
+              if (f_error_is_error(allocation_status)) {
+                f_delete_string_lengths(status, extra_initiator);
+                return f_error_set_error(allocation_status);
+              }
 
-                // when "other" is supplied, the extra will be recycled to represent the location of the "other" such that ordering can be determined by the caller
-                parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
-                parameters[parameter_counter].additional.used++;
+              parameters[parameter_counter].result = f_console_result_found;
 
-                found = f_true;
-                break;
-              }
+              // when "other" is supplied, the extra will be recycled to represent the location of the "other" such that ordering can be determined by the caller
+              parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
+              parameters[parameter_counter].additional.used++;
+
+              found = f_true;
+              break;
             }
           }
         } // for
index 31a5d4d23d8e2689630cc9cff51dfe091ffc5cfb..f33f900060dd3a2d42f8f96a08672ea6074cd2c6 100644 (file)
 extern "C" {
 #endif
 
+/**
+ * Process console parameters.
+ *
+ * @param argc
+ *   The number of parameters passed to the process.
+ * @param argv
+ *   The parameters passed to the process.
+ * @param parameters
+ *   The console parameters to look for.
+ * @param total_parameters
+ *   The used size of the parameters array.
+ *
+ * @return
+ *   f_none on success.
+ *   f_no_data if no "extra" parameters were found.
+ *   f_invalid_parameter (with error bit) if a parameter is invalid.
+ *   f_reallocation_error (with error bit) on memory reallocation error.
+ */
 #ifndef _di_fl_process_parameters_
-  /**
-   * Process console parameters.
-   */
   extern f_return_status fl_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length total_parameters, f_string_lengths *remaining);
 #endif // _di_fl_process_parameters_
 
index 8acdfae0b074d55d2d97b4d54c0a22908ddd5494..a355d97dbe250fa8c02e5d9c3d18d4cb99f35a49 100644 (file)
@@ -3,3 +3,4 @@ f_errors
 f_strings
 f_console
 f_memory
+f_utf
index 4b515f509dec55df11bf555fd0461a3312ce8561..600b1af3069aef62e14cc692e3489e51a6a93c7a 100644 (file)
@@ -10,9 +10,9 @@ version_micro 0
 build_compiler gcc
 build_linker ar
 build_libraries -lc
-build_libraries_fll -lf_memory -lf_console
+build_libraries_fll -lf_memory -lf_console -lf_utf
 build_sources_library console.c
-build_sources_program 
+build_sources_program
 build_sources_headers console.h
 build_sources_bash
 build_sources_settings