From: Kevin Day Date: Sun, 17 Nov 2019 01:15:57 +0000 (-0600) Subject: Update: use fl_console_parameter_to_number_unsigned() instead of atoll() X-Git-Tag: 0.5.0~379 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=3fd0ada848bb746ba497de102964d93c22653081;p=fll Update: use fl_console_parameter_to_number_unsigned() instead of atoll() This includes minor source code changes. --- diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index e9334f9..3759a89 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -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); diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index b8622fb..db2ab96 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -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,