From d72d912a64a5b89069f49d8fd432b55ca13f01f5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 23 Apr 2020 22:07:27 -0500 Subject: [PATCH] Update: Make classic mode more like hexdump The hexdump program prints periods more than what is currently done. Change this behavior to increase the use of non-colored periods. The -p/--placeholder parameter is still used, so the combination of --classic and -p will have closer results to hexdump. --- level_3/byte_dump/c/private-byte_dump.c | 49 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 5264301..3f30db1 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -442,17 +442,26 @@ extern "C" { if (*offset > 0) { - f_string placeholder = " "; - - if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { - placeholder = byte_dump_character_placeholder; + if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + while (*offset > 0 && j < data.width) { + printf("."); + (*offset)--; + j++; + } // while } + else { + f_string placeholder = " "; - while (*offset > 0 && j < data.width) { - fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", placeholder); - (*offset)--; - j++; - } // while + if (data.parameters[byte_dump_parameter_placeholder].result == f_console_result_found) { + placeholder = byte_dump_character_placeholder; + } + + while (*offset > 0 && j < data.width) { + fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", placeholder); + (*offset)--; + j++; + } // while + } } // Print placeholders for the remaining fragments of UTF-8 characters printed on previous lines. @@ -469,6 +478,9 @@ extern "C" { if (previous->invalid) { fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } + else if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } else { fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } @@ -610,7 +622,12 @@ extern "C" { } } else if (f_utf_character_is_whitespace(characters.string[i]) == f_true) { - fl_color_print2(f_standard_output, data.context.notable, data.context.warning, data.context.reset, "%s", byte_dump_sequence_space); + if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } + else { + fl_color_print2(f_standard_output, data.context.notable, data.context.warning, data.context.reset, "%s", byte_dump_sequence_space); + } } else if (f_utf_character_is_zero_width(characters.string[i]) == f_true) { if (data.presentation == byte_dump_presentation_classic) { @@ -732,6 +749,9 @@ extern "C" { if (invalid[i]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } + else if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } else { fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } @@ -747,6 +767,9 @@ extern "C" { if (invalid[i]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } + else if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } else { fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } @@ -762,6 +785,9 @@ extern "C" { if (invalid[i]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } + else if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } else { fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } @@ -782,6 +808,9 @@ extern "C" { if (invalid[j]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_placeholder); } + else if (data.parameters[byte_dump_parameter_classic].result == f_console_result_found) { + printf("."); + } else { fl_color_print(f_standard_output, data.context.warning, data.context.reset, "%s", byte_dump_character_placeholder); } -- 1.8.3.1