From: Kevin Day Date: Sun, 10 Nov 2019 04:31:20 +0000 (-0600) Subject: Feature: add support for duodecimal (base-12) X-Git-Tag: 0.5.0~398 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=02bcf733a5360b6aca877a87af950c13ca4e09e4;p=fll Feature: add support for duodecimal (base-12) Now that duodecimal has been added to the FLL project, make sure byte_dump can print in that format. There is no printf() code for base-12, so implement a custom print process. Fix some typoes in the "hexi" decimal spelling. --- diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index 4d2f88c..ec6b075 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -19,7 +19,8 @@ extern "C" { fll_program_print_help_option(data.context, byte_dump_short_binary, byte_dump_long_binary, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display binary representation."); fll_program_print_help_option(data.context, byte_dump_short_decimal, byte_dump_long_decimal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display decimal representation."); - fll_program_print_help_option(data.context, byte_dump_short_hexdecimal, byte_dump_long_hexidecimal, f_console_symbol_short_enable, f_console_symbol_long_enable, "Display hexadecimal representation."); + fll_program_print_help_option(data.context, byte_dump_short_duodecimal, byte_dump_long_duodecimal, f_console_symbol_short_enable, f_console_symbol_long_enable, "Display duodecimal representation."); + fll_program_print_help_option(data.context, byte_dump_short_hexidecimal, byte_dump_long_hexidecimal, f_console_symbol_short_enable, f_console_symbol_long_enable, "Display hexadecimal representation."); fll_program_print_help_option(data.context, byte_dump_short_octal, byte_dump_long_octal, f_console_symbol_short_enable, f_console_symbol_long_enable, " Display octal representation."); printf("%c", f_string_eol); @@ -85,10 +86,10 @@ extern "C" { // Identify priority of mode parameters. { - f_console_parameter_id ids[4] = { byte_dump_parameter_hexidecimal, byte_dump_parameter_octal, byte_dump_parameter_binary, byte_dump_parameter_decimal }; + f_console_parameter_id ids[5] = { byte_dump_parameter_hexidecimal, byte_dump_parameter_duodecimal, byte_dump_parameter_octal, byte_dump_parameter_binary, byte_dump_parameter_decimal }; f_console_parameter_id choice = byte_dump_parameter_hexidecimal; choices.id = ids; - choices.used = 4; + choices.used = 5; status = fl_console_parameter_prioritize(parameters, choices, &choice); @@ -100,6 +101,9 @@ extern "C" { if (choice == byte_dump_parameter_hexidecimal) { data->mode = byte_dump_mode_hexidecimal; } + else if (choice == byte_dump_parameter_duodecimal) { + data->mode = byte_dump_mode_duodecimal; + } else if (choice == byte_dump_parameter_octal) { data->mode = byte_dump_mode_octal; } @@ -258,6 +262,9 @@ extern "C" { if (data->mode == byte_dump_mode_hexidecimal) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Hexidecimal"); } + else if (data->mode == byte_dump_mode_duodecimal) { + fl_color_print(f_standard_output, data->context.title, data->context.reset, "Duodecimal"); + } else if (data->mode == byte_dump_mode_octal) { fl_color_print(f_standard_output, data->context.title, data->context.reset, "Octal"); } diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index 9d1024e..b8622fb 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -63,6 +63,7 @@ extern "C" { #ifndef _di_byte_dump_defines_ enum { byte_dump_mode_hexidecimal = 1, + byte_dump_mode_duodecimal, byte_dump_mode_octal, byte_dump_mode_binary, byte_dump_mode_decimal, @@ -117,7 +118,8 @@ extern "C" { #define byte_dump_short_binary "b" #define byte_dump_short_decimal "d" - #define byte_dump_short_hexdecimal "x" + #define byte_dump_short_duodecimal "D" + #define byte_dump_short_hexidecimal "x" #define byte_dump_short_octal "o" #define byte_dump_short_first "f" @@ -128,6 +130,7 @@ extern "C" { #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" @@ -151,6 +154,7 @@ extern "C" { byte_dump_parameter_binary, byte_dump_parameter_decimal, + byte_dump_parameter_duodecimal, byte_dump_parameter_hexidecimal, byte_dump_parameter_octal, @@ -175,7 +179,8 @@ extern "C" { f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_console_type_inverse), \ f_console_parameter_initialize(byte_dump_short_binary, byte_dump_long_binary, 0, 0, f_console_type_normal), \ f_console_parameter_initialize(byte_dump_short_decimal, byte_dump_long_decimal, 0, 0, f_console_type_normal), \ - f_console_parameter_initialize(byte_dump_short_hexdecimal, byte_dump_long_hexidecimal, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_duodecimal, byte_dump_long_duodecimal, 0, 0, f_console_type_normal), \ + f_console_parameter_initialize(byte_dump_short_hexidecimal, byte_dump_long_hexidecimal, 0, 0, f_console_type_normal), \ f_console_parameter_initialize(byte_dump_short_octal, byte_dump_long_octal, 0, 0, f_console_type_normal), \ f_console_parameter_initialize(byte_dump_short_first, byte_dump_long_first, 0, 1, f_console_type_normal), \ f_console_parameter_initialize(byte_dump_short_last, byte_dump_long_last, 0, 1, f_console_type_normal), \ @@ -187,7 +192,7 @@ extern "C" { f_console_parameter_initialize(0, byte_dump_long_classic, 0, 0, f_console_type_normal), \ } - #define byte_dump_total_parameters 17 + #define byte_dump_total_parameters 18 #endif // _di_byte_dump_defines_ #ifndef _di_byte_dump_data_ diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 8238de4..3131790 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -159,6 +159,9 @@ extern "C" { if (data.mode == byte_dump_mode_hexidecimal) { printf(" "); } + else if (data.mode == byte_dump_mode_duodecimal) { + printf(" "); + } else if (data.mode == byte_dump_mode_octal) { printf(" "); } @@ -175,6 +178,9 @@ extern "C" { if (data.mode == byte_dump_mode_hexidecimal && column % 8 == 0) { printf(" "); } + else if (data.mode == byte_dump_mode_duodecimal && column % 6 == 0) { + printf(" "); + } else if (data.mode == byte_dump_mode_octal && column % 6 == 0) { printf(" "); } @@ -255,6 +261,41 @@ extern "C" { printf(" %02x", (uint8_t) byte); } } + else if (data.mode == byte_dump_mode_duodecimal) { + if (invalid[character_current]) { + f_print_string_dynamic(f_standard_output, data.context.error); + } + + printf(" %01d", byte / 144); + + uint8_t current = (byte % 144) / 12; + + if (current == 11) { + printf("b"); + } + else if (current == 10) { + printf("a"); + } + else { + printf("%01d", current); + } + + current = (byte % 144) % 12; + + if (current == 11) { + printf("b"); + } + else if (current == 10) { + printf("a"); + } + else { + printf("%01d", current); + } + + if (invalid[character_current]) { + f_print_string_dynamic(f_standard_output, data.context.reset); + } + } else if (data.mode == byte_dump_mode_octal) { if (invalid[character_current]) { fl_color_print(f_standard_output, data.context.error, data.context.reset, " %03o", (uint8_t) byte); @@ -324,6 +365,9 @@ extern "C" { else if (data.mode == byte_dump_mode_hexidecimal && *column % 8 == 0) { printf(" "); } + else if (data.mode == byte_dump_mode_duodecimal && *column % 6 == 0) { + printf(" "); + } else if (data.mode == byte_dump_mode_octal && *column % 6 == 0) { printf(" "); }