]> Kevux Git Server - fll/commitdiff
Update: add support for repeated parameters
authorKevin Day <kevin@kevux.org>
Sat, 31 Mar 2012 16:45:35 +0000 (11:45 -0500)
committerKevin Day <kevin@kevux.org>
Sat, 31 Mar 2012 16:45:35 +0000 (11:45 -0500)
Thus, something like my_function -s 0 -s 1 would be able to process both -s 0 and -s 1.
Previously, only the last -s option would have been processed.

level_0/f_console/c/console.h
level_1/fl_console/c/console.c
level_3/firewall/c/firewall.c
level_3/fss_basic_list_read/c/fss_basic_list_read.c
level_3/fss_basic_read/c/fss_basic_read.c
level_3/fss_extended_read/c/fss_extended_read.c
level_3/fss_return_code/c/fss_return_code.c
level_3/return_code/c/return_code.c

index 96f33e6f567e438c9546bb6472b278c2b31d1804..b12210f306c6bd8ea5ae5dcabd8ee840424c2b40 100644 (file)
@@ -99,12 +99,12 @@ extern "C"{
     const f_bool    has_additional;
     const f_u_int   type;
     f_u_int         result;
-    f_string_length additional;
+    f_string_lengths additional;
     f_string_length length;
   } f_console_parameter;
 
   #define f_console_parameter_initialize(symbol_short, symbol_long, symbol_extra, symbol_other, has_additional, type_value, length) \
-    { symbol_short, symbol_long, symbol_extra, symbol_other, has_additional, type_value, f_console_result_none, 0, length }
+    { symbol_short, symbol_long, symbol_extra, symbol_other, has_additional, type_value, f_console_result_none, f_string_lengths_initialize, length }
 #endif // _di_f_console_parameter_
 
 #ifndef _di_f_console_identify_
index e89fc49cc0965f150cd43f981cade4a9cc4b6e66..69fdf30efd616581922701657bd96029514ebc8d 100644 (file)
@@ -65,6 +65,13 @@ extern "C"{
 
                       f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
                       if (f_macro_test_for_allocation_errors(allocation_status)) {
+                        f_string_length i = 0;
+
+                        while (i < total_parameters) {
+                          f_delete_string_lengths(status, parameters[i].additional);
+                          i++;
+                        } // while
+
                         f_delete_string_lengths(status, extra_initiator);
                         return allocation_status;
                       }
@@ -86,6 +93,13 @@ extern "C"{
 
                       f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
                       if (f_macro_test_for_allocation_errors(allocation_status)) {
+                        f_string_length i = 0;
+
+                        while (i < total_parameters) {
+                          f_delete_string_lengths(status, parameters[i].additional);
+                          i++;
+                        } // while
+
                         f_delete_string_lengths(status, extra_initiator);
                         return allocation_status;
                       }
@@ -116,7 +130,15 @@ extern "C"{
                       f_status allocation_status = f_status_initialize;
 
                       f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+
                       if (f_macro_test_for_allocation_errors(allocation_status)) {
+                        f_string_length i = 0;
+
+                        while (i < total_parameters) {
+                          f_delete_string_lengths(status, parameters[i].additional);
+                          i++;
+                        } // while
+
                         f_delete_string_lengths(status, extra_initiator);
                         return allocation_status;
                       }
@@ -137,7 +159,15 @@ extern "C"{
                       f_status allocation_status = f_status_initialize;
 
                       f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step);
+
                       if (f_macro_test_for_allocation_errors(allocation_status)) {
+                        f_string_length i = 0;
+
+                        while (i < total_parameters) {
+                          f_delete_string_lengths(status, parameters[i].additional);
+                          i++;
+                        } // while
+
                         f_delete_string_lengths(status, extra_initiator);
                         return allocation_status;
                       }
@@ -161,10 +191,29 @@ extern "C"{
           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_status_initialize;
+
+                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 (f_macro_test_for_allocation_errors(allocation_status)) {
+                  f_string_length i = 0;
+
+                  while (i < total_parameters) {
+                    f_delete_string_lengths(status, parameters[i].additional);
+                    i++;
+                  } // while
+
+                  f_delete_string_lengths(status, extra_initiator);
+                  return allocation_status;
+                }
+
                 parameters[parameter_counter].result = f_console_result_found;
 
                 // 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 = location;
+                parameters[parameter_counter].additional.array[parameters[parameter_counter].additional.used] = location;
+                parameters[parameter_counter].additional.used++;
 
                 found = f_true;
                 break;
@@ -175,8 +224,27 @@ extern "C"{
 
         if (!found) {
           if (extra_initiator.used > 0) {
-            parameters[extra_initiator.array[0]].result     = f_console_result_additional;
-            parameters[extra_initiator.array[0]].additional = location;
+            f_status allocation_status = f_status_initialize;
+
+            if (parameters[extra_initiator.array[0]].additional.used >= parameters[extra_initiator.array[0]].additional.size) {
+                f_resize_string_lengths(allocation_status, parameters[extra_initiator.array[0]].additional, parameters[extra_initiator.array[0]].additional.size + f_console_default_allocation_step);
+              }
+
+              if (f_macro_test_for_allocation_errors(allocation_status)) {
+                f_string_length i = 0;
+
+                while (i < total_parameters) {
+                  f_delete_string_lengths(status, parameters[i].additional);
+                  i++;
+                } // while
+
+                f_delete_string_lengths(status, extra_initiator);
+                return allocation_status;
+              }
+
+            parameters[extra_initiator.array[0]].result = f_console_result_additional;
+            parameters[extra_initiator.array[0]].additional.array[parameters[extra_initiator.array[0]].additional.used] = location;
+            parameters[extra_initiator.array[0]].additional.used++;
 
             extra_initiator.used--;
 
@@ -192,6 +260,13 @@ extern "C"{
               f_resize_string_lengths(allocation_status, (*remaining), remaining->size + f_console_default_allocation_step);
 
               if (f_macro_test_for_allocation_errors(allocation_status)) {
+                f_string_length i = 0;
+
+                while (i < total_parameters) {
+                  f_delete_string_lengths(status, parameters[i].additional);
+                  i++;
+                } // while
+
                 f_delete_string_lengths(status, extra_initiator);
                 return allocation_status;
               }
index 1e1708ea57c6f93857035c9ec460f7ed8454b6d7..b87179222e8ba5503b59d905042017f095fae983 100644 (file)
@@ -162,7 +162,7 @@ extern "C"{
 
       if (data->parameters[firewall_parameter_command_stop].result == f_console_result_found) {
         if (found_command) {
-          if (data->parameters[command].additional > data->parameters[firewall_parameter_command_stop].additional) {
+          if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_stop].additional.array[0]) {
             command = firewall_parameter_command_stop;
           }
         } else {
@@ -173,7 +173,7 @@ extern "C"{
 
       if (data->parameters[firewall_parameter_command_restart].result == f_console_result_found) {
         if (found_command) {
-          if (data->parameters[command].additional > data->parameters[firewall_parameter_command_restart].additional) {
+          if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_restart].additional.array[0]) {
             command = firewall_parameter_command_restart;
           }
         } else {
@@ -184,7 +184,7 @@ extern "C"{
 
       if (data->parameters[firewall_parameter_command_lock].result == f_console_result_found) {
         if (found_command) {
-          if (data->parameters[command].additional > data->parameters[firewall_parameter_command_lock].additional) {
+          if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_lock].additional.array[0]) {
             command = firewall_parameter_command_lock;
           }
         } else {
@@ -195,7 +195,7 @@ extern "C"{
 
       if (data->parameters[firewall_parameter_command_show].result == f_console_result_found) {
         if (found_command) {
-          if (data->parameters[command].additional > data->parameters[firewall_parameter_command_show].additional) {
+          if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_show].additional.array[0]) {
             command = firewall_parameter_command_show;
           }
         } else {
@@ -1629,7 +1629,13 @@ extern "C"{
 
 #ifndef _di_firewall_delete_data_
   f_return_status firewall_delete_data(firewall_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < firewall_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_fss_contents(status, data->contents);
     f_delete_fss_objects(status, data->objects);
index 9954a4a0761bda77298c286045219c00539ac05c..f3b076637ba006c7195e6f51537838482289ac39 100644 (file)
@@ -179,7 +179,7 @@ extern "C"{
       f_string_length original_size = data->file_position.total_elements;
 
       if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) {
-        target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_count].additional]);
+        target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_count].additional.array[0]]);
       }
 
       if (data->process_pipe) {
@@ -374,7 +374,7 @@ extern "C"{
                 if (data->contents.array[current].used > 0) {
                   f_string_length   counter  = data->contents.array[current].array[0].start;
                   f_string_length   position = 0;
-                  f_string_length   target   = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional]);
+                  f_string_length   target   = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
                   f_string_location range    = f_string_location_initialize;
 
                   // use an invalid range to communicate range not found
@@ -445,14 +445,14 @@ extern "C"{
         f_string_length argv_length = f_string_length_initialize;
 
         if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) {
-          argv_length = strlen(argv[data->parameters[fss_basic_list_read_parameter_name].additional]);
+          argv_length = strlen(argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]]);
 
           if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) {
             for (; current < data->objects.used; current++) {
               name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
 
               if (name_length == argv_length) {
-                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
 
                   if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) {
                     if (data->contents.array[current].used > 0) {
@@ -474,7 +474,7 @@ extern "C"{
                     if (data->contents.array[current].used > 0) {
                       f_string_length   counter  = data->contents.array[current].array[0].start;
                       f_string_length   position = 0;
-                      f_string_length   target   = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional]);
+                      f_string_length   target   = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
                       f_string_location range    = f_string_location_initialize;
 
                       // use an invalid range to communicate range not found
@@ -540,7 +540,7 @@ extern "C"{
                 name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1;
 
                 if (name_length == argv_length) {
-                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
                     if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) {
                       f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]);
                       fprintf(f_standard_output, "\n");
@@ -568,7 +568,13 @@ extern "C"{
 
 #ifndef _di_fss_basic_list_read_delete_data_
   f_return_status fss_basic_list_read_delete_data(fss_basic_list_read_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < fss_basic_list_read_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_fss_contents(status, data->contents);
     f_delete_fss_objects(status, data->objects);
index 73c069c6cdd48c350d397cd309fbe3069a2456ad..1b2e07a8e27c23fe19b568beaafbe40d7885a42c 100644 (file)
@@ -165,7 +165,7 @@ extern "C"{
       f_string_length original_size = data->file_position.total_elements;
 
       if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) {
-        target = (f_string_length) atoll(argv[data->parameters[fss_basic_read_parameter_count].additional]);
+        target = (f_string_length) atoll(argv[data->parameters[fss_basic_read_parameter_count].additional.array[0]]);
       }
 
       if (data->process_pipe) {
@@ -386,14 +386,14 @@ extern "C"{
         f_string_length argv_length = f_string_length_initialize;
 
         if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) {
-          argv_length = strlen(argv[data->parameters[fss_basic_read_parameter_name].additional]);
+          argv_length = strlen(argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]);
 
           if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) {
             for (; current < data->objects.used; current++) {
               name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
 
               if (name_length == argv_length) {
-                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
 
                   if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) {
                     if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) {
@@ -431,7 +431,7 @@ extern "C"{
                 name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1;
 
                 if (name_length == argv_length) {
-                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
                     if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) {
                       f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]);
                       fprintf(f_standard_output, "\n");
@@ -459,7 +459,13 @@ extern "C"{
 
 #ifndef _di_fss_basic_read_delete_data_
   f_return_status fss_basic_read_delete_data(fss_basic_read_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < fss_basic_read_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_fss_contents(status, data->contents);
     f_delete_fss_objects(status, data->objects);
index 7d4fbf4721800acb56956a0be8bd8613a6088e9e..af2782d854fbb9b3c15d89186826f8dc01dc5ea1 100644 (file)
@@ -173,11 +173,11 @@ extern "C"{
       f_string_length original_size = data->file_position.total_elements;
 
       if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) {
-        target = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_count].additional]);
+        target = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_count].additional.array[0]]);
       }
 
       if (data->parameters[fss_extended_read_parameter_select].result == f_console_result_additional) {
-        select = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_select].additional]);
+        select = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_select].additional.array[0]]);
       }
 
       if (data->process_pipe) {
@@ -393,14 +393,14 @@ extern "C"{
         f_string_length argv_length = f_string_length_initialize;
 
         if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional) {
-          argv_length = strlen(argv[data->parameters[fss_extended_read_parameter_name].additional]);
+          argv_length = strlen(argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]]);
 
           if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) {
             for (; current < data->objects.used; current++) {
               name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
 
               if (name_length == argv_length) {
-                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
 
                   if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) {
                     if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) {
@@ -438,7 +438,7 @@ extern "C"{
                 name_length = data->contents.array[current].array[select].stop - data->contents.array[current].array[select].start + 1;
 
                 if (name_length == argv_length) {
-                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[select].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to) {
+                  if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[select].start, argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
                     if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) {
                       f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]);
                       fprintf(f_standard_output, "\n");
@@ -466,7 +466,13 @@ extern "C"{
 
 #ifndef _di_fss_extended_read_delete_data_
   f_return_status fss_extended_read_delete_data(fss_extended_read_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < fss_extended_read_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_fss_contents(status, data->contents);
     f_delete_fss_objects(status, data->objects);
index b1ce7256686ec5e20d25a7ae71e8b74f008d94f6..99921918d144b114df0377dd930ba153803e434b 100644 (file)
@@ -228,7 +228,13 @@ extern "C"{
 
 #ifndef _di_fss_return_code_delete_data_
   f_return_status fss_return_code_delete_data(fss_return_code_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < fss_return_code_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_string_lengths(status, data->remaining);
     fll_delete_color_context(status, data->context);
index 0a7ee864a917e32739fa3d99655e141afbe8cf03..8ed9ca98ba947db0515ee409143e34067c964445 100644 (file)
@@ -228,7 +228,13 @@ extern "C"{
 
 #ifndef _di_return_code_delete_data_
   f_return_status return_code_delete_data(return_code_data *data) {
-    f_status status = f_status_initialize;
+    f_status        status = f_status_initialize;
+    f_string_length i      = 0;
+
+    while (i < return_code_total_parameters) {
+      f_delete_string_lengths(status, data->parameters[i].additional);
+      i++;
+    } // while
 
     f_delete_string_lengths(status, data->remaining);
     fll_delete_color_context(status, data->context);