From: Kevin Day Date: Sat, 25 Apr 2020 17:46:36 +0000 (-0500) Subject: Update: redesign byte_dump --last to be inclusive X-Git-Tag: 0.5.0~333 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=9355b758983e5589e9137752ca38b257f4e016fe;p=fll Update: redesign byte_dump --last to be inclusive The --last parameter should be inclusive for consistency with the rest of the project, namely FSS. By redesigning the --last to internally be represented as a relative offset, the behavior can be simplified. Doing this also adds support for potential future designs where a --length parameter may be provided that is a relative size parameter instead of an absolute one like --last. --- diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 65a723e..d4d3332 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -26,7 +26,7 @@ extern "C" { printf("%c", f_string_eol); fll_program_print_help_option(data.context, byte_dump_short_first, byte_dump_long_first, f_console_symbol_short_enable, f_console_symbol_long_enable, " Start reading at this byte offset."); - fll_program_print_help_option(data.context, byte_dump_short_last, byte_dump_long_last, f_console_symbol_short_enable, f_console_symbol_long_enable, " Stop reading at this byte offset."); + fll_program_print_help_option(data.context, byte_dump_short_last, byte_dump_long_last, f_console_symbol_short_enable, f_console_symbol_long_enable, " Stop reading at this (inclusive) byte offset."); fll_program_print_help_option(data.context, byte_dump_short_width, byte_dump_long_width, f_console_symbol_short_enable, f_console_symbol_long_enable, " Set number of columns of Bytes to display."); printf("%c", f_string_eol); @@ -224,11 +224,11 @@ extern "C" { 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 < 1 || number > f_type_number_size_unsigned) { + if (f_status_is_error(status) || number < 0 || 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, "1"); + 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, "."); @@ -251,6 +251,9 @@ extern "C" { byte_dump_delete_data(data); return f_status_set_error(status); } + + // store last position as a relative offset from first instead of an absolute position. + data->last = (data->last - data->first) + 1; } if (data->process_pipe) { diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 3b5eb04..400fbf6 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -9,7 +9,7 @@ extern "C" { f_return_status byte_dump_file(const byte_dump_data data, const f_string file_name, f_file file) { f_status status = f_none; - uint64_t position = data.first; + uint64_t position = 0; uint8_t size = 0; uint8_t byte = 0; uint8_t offset = 0;