]> Kevux Git Server - fll/commitdiff
Update: use fl_console_parameter_to_number_unsigned() instead of atoll()
authorKevin Day <thekevinday@gmail.com>
Sun, 17 Nov 2019 01:15:57 +0000 (19:15 -0600)
committerKevin Day <thekevinday@gmail.com>
Sun, 17 Nov 2019 01:43:22 +0000 (19:43 -0600)
This includes minor source code changes.

level_3/byte_dump/c/byte_dump.c
level_3/byte_dump/c/byte_dump.h

index e9334f9393b230ebebbc2d94a8257a1764ddf6dd..3759a89f3145ce38edd2bfc14d10bd4d1201278e 100644 (file)
@@ -152,15 +152,25 @@ extern "C" {
     }
     else if (data->remaining.used > 0 || data->process_pipe) {
       if (data->parameters[byte_dump_parameter_width].result == f_console_result_found) {
-        fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Width option was specified but no width was given.");
+        fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+        fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_width);
+        fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' was specified, but no value was given.");
 
         byte_dump_delete_data(data);
         return f_status_set_error(status);
       }
       else if (data->parameters[byte_dump_parameter_width].result == f_console_result_additional) {
-        uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_width].additional.array[0]]);
-        if (number < 1 || number >= 0xfb) {
-          fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Width option can only be a number between 0 and 251.");
+        f_number_unsigned number = 0;
+        status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[byte_dump_parameter_width].additional.array[data->parameters[byte_dump_parameter_width].additional.used - 1]], &number);
+
+        if (f_status_is_error(status) || number < 1 || number >= 0xfb) {
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_width);
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "' value can only be a number between ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "0");
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, " and ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "251");
+          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, ".");
 
           byte_dump_delete_data(data);
           return f_status_set_error(status);
@@ -170,15 +180,25 @@ extern "C" {
       }
 
       if (data->parameters[byte_dump_parameter_first].result == f_console_result_found) {
-        fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "First option was specified but no number was given.");
+        fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+        fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_first);
+        fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' was specified, but no value was given.");
 
         byte_dump_delete_data(data);
         return f_status_set_error(status);
       }
       else if (data->parameters[byte_dump_parameter_first].result == f_console_result_additional) {
-        uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_first].additional.array[0]]);
-        if (number < 1 || number >= 0xffffffffffffffff) {
-          fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "First option can only be a number between 0 and 18446744073709551615.");
+        f_number_unsigned number = 0;
+        status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[byte_dump_parameter_first].additional.array[data->parameters[byte_dump_parameter_first].additional.used - 1]], &number);
+
+        if (f_status_is_error(status) || number > f_type_number_size_unsigned) {
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_first);
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "' value can only be a number (inclusively) between ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "0");
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, " and ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%llu", f_type_number_size_unsigned);
+          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, ".");
 
           byte_dump_delete_data(data);
           return f_status_set_error(status);
@@ -188,15 +208,25 @@ extern "C" {
       }
 
       if (data->parameters[byte_dump_parameter_last].result == f_console_result_found) {
-        fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Last option was specified but no number was given.");
+        fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+        fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_last);
+        fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' was specified, but no value was given.");
 
         byte_dump_delete_data(data);
         return f_status_set_error(status);
       }
       else if (data->parameters[byte_dump_parameter_last].result == f_console_result_additional) {
-        uint64_t number = atoll(arguments.argv[data->parameters[byte_dump_parameter_last].additional.array[0]]);
-        if (number < 1 || number >= 0xffffffffffffffff) {
-          fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Last option can only be a number between 0 and 18446744073709551615.");
+        f_number_unsigned number = 0;
+        status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[byte_dump_parameter_last].additional.array[data->parameters[byte_dump_parameter_last].additional.used - 1]], &number);
+
+        if (f_status_is_error(status) || number > f_type_number_size_unsigned) {
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_last);
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "' value can only be a number (inclusively) between ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "0");
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, " and ");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "%llu", f_type_number_size_unsigned);
+          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, ".");
 
           byte_dump_delete_data(data);
           return f_status_set_error(status);
@@ -206,11 +236,11 @@ extern "C" {
       }
 
       if (data->first > data->last) {
-          fl_color_print(f_standard_output, data->context.error, data->context.reset, "First option (");
-          fl_color_print(f_standard_output, data->context.notable, data->context.reset, "%d", data->first);
-          fl_color_print(f_standard_output, data->context.error, data->context.reset, ") cannot be greater than Last option (");
-          fl_color_print(f_standard_output, data->context.notable, data->context.reset, "%d", data->last);
-          fl_color_print_line(f_standard_output, data->context.error, data->context.reset, ").");
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_first);
+          fl_color_print(f_standard_error, data->context.error, data->context.reset, "' value cannot be greater than the parameter '");
+          fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", byte_dump_long_last);
+          fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' value.");
 
           byte_dump_delete_data(data);
           return f_status_set_error(status);
index b8622fb890902a035794f59ea23fc2ed5197e68b..db2ab96fa1dc6deaf86c3f4be446aa01a97ecbe8 100644 (file)
@@ -56,7 +56,7 @@ extern "C" {
 #endif // _di_byte_dump_name_
 
 #ifndef _di_byte_dump_default_allocation_step_
-  // provide a UTF-8 friendly allocation step.
+  // Set to at least 4 to provide a UTF-8 friendly allocation step.
   #define byte_dump_default_allocation_step 4
 #endif // _di_byte_dump_default_allocation_step_
 
@@ -128,22 +128,22 @@ extern "C" {
   #define byte_dump_short_width       "w"
   #define byte_dump_short_placeholder "p"
 
-  #define byte_dump_long_binary       "binary"
-  #define byte_dump_long_decimal      "decimal"
-  #define byte_dump_long_duodecimal   "duodecimal"
-  #define byte_dump_long_hexidecimal  "hexidecimal"
-  #define byte_dump_long_octal        "octal"
+  #define byte_dump_long_binary      "binary"
+  #define byte_dump_long_decimal     "decimal"
+  #define byte_dump_long_duodecimal  "duodecimal"
+  #define byte_dump_long_hexidecimal "hexidecimal"
+  #define byte_dump_long_octal       "octal"
 
-  #define byte_dump_long_first        "first"       // first offset byte size.
-  #define byte_dump_long_last         "last"        // last offset byte size.
-  #define byte_dump_long_width        "width"       // number of characters to display per row.
+  #define byte_dump_long_first "first" // first offset byte size.
+  #define byte_dump_long_last  "last"  // last offset byte size.
+  #define byte_dump_long_width "width" // number of characters to display per row.
 
-  #define byte_dump_long_text         "text"        // display text
-  #define byte_dump_long_placeholder  "placeholder" // display (colored) placeholders to signify codes that are UTF-8 fragments.
+  #define byte_dump_long_text        "text"        // display text
+  #define byte_dump_long_placeholder "placeholder" // display (colored) placeholders to signify codes that are UTF-8 fragments.
 
-  #define byte_dump_long_normal       "normal"      // use normal presentation, displaying UTF-8 sequence codes for ASCII special codes.
-  #define byte_dump_long_simple       "simple"      // use simple presentation, displaying spaces for ASCII special codes instead of UTF-8 sequence codes.
-  #define byte_dump_long_classic      "classic"     // use classic presentation, displaying periods for ASCII special codes instead of UTF-8 sequence codes.
+  #define byte_dump_long_normal  "normal"  // use normal presentation, displaying UTF-8 sequence codes for ASCII special codes.
+  #define byte_dump_long_simple  "simple"  // use simple presentation, displaying spaces for ASCII special codes instead of UTF-8 sequence codes.
+  #define byte_dump_long_classic "classic" // use classic presentation, displaying periods for ASCII special codes instead of UTF-8 sequence codes.
 
   enum {
     byte_dump_parameter_help,