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.
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);
// 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);
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;
}
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");
}
#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,
#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"
#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"
byte_dump_parameter_binary,
byte_dump_parameter_decimal,
+ byte_dump_parameter_duodecimal,
byte_dump_parameter_hexidecimal,
byte_dump_parameter_octal,
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), \
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_
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(" ");
}
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(" ");
}
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);
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(" ");
}