#define BYTE_DUMP_character_incomplete_s "�"
#define BYTE_DUMP_character_unused_s "�"
+ #define BYTE_DUMP_format_raw_context_s "%[%r%]"
+
#define BYTE_DUMP_hexidecimal_s_length 11
#define BYTE_DUMP_duodecimal_s_length 10
#define BYTE_DUMP_octal_s_length 5
#define BYTE_DUMP_character_incomplete_s_length 3
#define BYTE_DUMP_character_unused_s_length 3
+ #define BYTE_DUMP_format_raw_context_s_length 6
+
extern const f_string_static_t byte_dump_hexidecimal_s;
extern const f_string_static_t byte_dump_duodecimal_s;
extern const f_string_static_t byte_dump_octal_s;
extern const f_string_static_t byte_dump_character_placeholder_s;
extern const f_string_static_t byte_dump_character_incomplete_s;
extern const f_string_static_t byte_dump_character_unused_s;
+
+ extern const f_string_static_t byte_dump_format_raw_context_s;
#endif // _di_byte_dump_s_
/**
+ * Paddings and an array containing the paddings for quick reference.
+ *
+ * The byte_dump_padding_s is an array with the following structure:
+ * - index 0: unicode.
+ * - index 1: hexidecimal.
+ * - index 2: duodecimal.
+ * - index 3: octal.
+ * - index 4: binary.
+ * - index 5: decimal.
+ */
+#ifndef _di_byte_dump_padding_s_
+ #define BYTE_DUMP_padding_3_s " "
+ #define BYTE_DUMP_padding_4_s " "
+ #define BYTE_DUMP_padding_5_s " "
+ #define BYTE_DUMP_padding_6_s " "
+ #define BYTE_DUMP_padding_8_s " "
+ #define BYTE_DUMP_padding_9_s " "
+
+ #define BYTE_DUMP_padding_3_s_length 3
+ #define BYTE_DUMP_padding_4_s_length 4
+ #define BYTE_DUMP_padding_5_s_length 5
+ #define BYTE_DUMP_padding_6_s_length 6
+ #define BYTE_DUMP_padding_8_s_length 8
+ #define BYTE_DUMP_padding_9_s_length 9
+
+ extern const f_string_static_t byte_dump_padding_3_s;
+ extern const f_string_static_t byte_dump_padding_4_s;
+ extern const f_string_static_t byte_dump_padding_5_s;
+ extern const f_string_static_t byte_dump_padding_6_s;
+ extern const f_string_static_t byte_dump_padding_8_s;
+ extern const f_string_static_t byte_dump_padding_9_s;
+
+ extern const f_string_static_t byte_dump_padding_s[];
+#endif // _di_byte_dump_padding_s_
+
+/**
* The main program parameters.
*/
#ifndef _di_byte_dump_parameter_d_
// Pad the buffer with spaces to hide any skipped bytes (skipped via --first).
while (offset_to_print && cell->column < main->setting.width) {
- if (main->setting.flag & byte_dump_main_flag_unicode_e) {
- f_print_terminated(" ", print->to);
- }
- else if (main->setting.mode == byte_dump_mode_hexidecimal_e) {
- f_print_terminated(" ", print->to);
- }
- else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
- f_print_terminated(" ", print->to);
- }
- else if (main->setting.mode == byte_dump_mode_octal_e) {
- f_print_terminated(" ", print->to);
- }
- else if (main->setting.mode == byte_dump_mode_binary_e) {
- f_print_terminated(" ", print->to);
- }
- else if (main->setting.mode == byte_dump_mode_decimal_e) {
- f_print_terminated(" ", print->to);
- }
+ f_print_dynamic_raw(byte_dump_padding_s[(main->setting.flag & byte_dump_main_flag_unicode_e) ? 0 : main->setting.mode], print->to);
--offset_to_print;
++cell->column;
if (cell->column < main->setting.width) {
- if (main->setting.flag & byte_dump_main_flag_unicode_e) {
+ if ((main->setting.flag & byte_dump_main_flag_unicode_e) || main->setting.mode == byte_dump_mode_binary_e) {
if (!(cell->column % 4)) {
f_print_dynamic_raw(f_string_space_s, print->to);
}
f_print_dynamic_raw(f_string_space_s, print->to);
}
}
- else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
- if (!(cell->column % 6)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_octal_e) {
- if (!(cell->column % 6)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_binary_e) {
- if (!(cell->column % 4)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_decimal_e) {
+ else if (main->setting.mode == byte_dump_mode_duodecimal_e || main->setting.mode == byte_dump_mode_octal_e || main->setting.mode == byte_dump_mode_decimal_e) {
if (!(cell->column % 6)) {
f_print_dynamic_raw(f_string_space_s, print->to);
}
else {
// Pad the sequence that are incomplete fragments of an already printed valid Unicode.
- f_print_terminated(" ", print->to);
+ f_print_dynamic_raw(byte_dump_padding_9_s, print->to);
}
}
else {
if (main->setting.mode == byte_dump_mode_hexidecimal_e) {
if (main->setting.flag & byte_dump_main_flag_unicode_e) {
- f_print_terminated(" ", print->to);
+ f_print_dynamic_raw(byte_dump_padding_6_s, print->to);
}
if (invalid[current]) {
}
else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
if (main->setting.flag & byte_dump_main_flag_unicode_e) {
- f_print_terminated(" ", print->to);
+ f_print_dynamic_raw(byte_dump_padding_5_s, print->to);
}
if (invalid[current]) {
}
else if (main->setting.mode == byte_dump_mode_octal_e) {
if (main->setting.flag & byte_dump_main_flag_unicode_e) {
- f_print_terminated(" ", print->to);
+ f_print_dynamic_raw(byte_dump_padding_5_s, print->to);
}
if (invalid[current]) {
}
else if (main->setting.mode == byte_dump_mode_decimal_e) {
if (main->setting.flag & byte_dump_main_flag_unicode_e) {
- f_print_terminated(" ", print->to);
+ f_print_dynamic_raw(byte_dump_padding_5_s, print->to);
}
if (invalid[current]) {
}
}
else {
- if (main->setting.flag & byte_dump_main_flag_unicode_e) {
+ if ((main->setting.flag & byte_dump_main_flag_unicode_e) || main->setting.mode == byte_dump_mode_binary_e) {
if (!(cell->column % 4)) {
f_print_dynamic_raw(f_string_space_s, print->to);
}
f_print_dynamic_raw(f_string_space_s, print->to);
}
}
- else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
- if (!(cell->column % 6)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_octal_e) {
- if (!(cell->column % 6)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_binary_e) {
- if (!(cell->column % 4)) {
- f_print_dynamic_raw(f_string_space_s, print->to);
- }
- }
- else if (main->setting.mode == byte_dump_mode_decimal_e) {
+ else if (main->setting.mode == byte_dump_mode_duodecimal_e || main->setting.mode == byte_dump_mode_octal_e || main->setting.mode == byte_dump_mode_decimal_e) {
if (!(cell->column % 6)) {
f_print_dynamic_raw(f_string_space_s, print->to);
}
if (main->setting.flag & byte_dump_main_flag_placeholder_e) {
for (; *offset && at < main->setting.width; --(*offset), ++at) {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
if (main->setting.flag & byte_dump_main_flag_wide_e) {
f_print_dynamic_raw(f_string_space_s, print->to);
for (; at < previous->bytes && at < main->setting.width; ++at) {
if (previous->invalid) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
}
else if (main->setting.flag & byte_dump_main_flag_classic_e) {
f_print_dynamic_raw(f_string_ascii_period_s, print->to);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
}
if (main->setting.flag & byte_dump_main_flag_wide_e) {
width_utf = macro_f_utf_byte_width_is(c);
if (invalid[i]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_incomplete_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_incomplete_s, print->set->error);
if (main->setting.flag & byte_dump_main_flag_wide_e) {
f_print_dynamic_raw(f_string_ascii_space_s, print->to);
// Print invalid placeholder for invalid UTF-8 widths.
if (invalid[i]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_incomplete_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_incomplete_s, print->set->error);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_incomplete_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_incomplete_s, print->set->warning);
}
}
else if (width_utf == 2) {
if (width_utf > 1 && at + 1 < main->setting.width) {
if (main->setting.flag & byte_dump_main_flag_placeholder_e) {
if (invalid[i]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
}
else if (main->setting.flag & byte_dump_main_flag_classic_e) {
f_print_dynamic_raw(f_string_ascii_period_s, print->to);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
}
}
else {
if (width_utf > 2 && at + 1 < main->setting.width) {
if (main->setting.flag & byte_dump_main_flag_placeholder_e) {
if (invalid[i]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
}
else if (main->setting.flag & byte_dump_main_flag_classic_e) {
f_print_dynamic_raw(f_string_ascii_period_s, print->to);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
}
}
else {
if (width_utf > 3 && at + 1 < main->setting.width) {
if (main->setting.flag & byte_dump_main_flag_placeholder_e) {
if (invalid[i]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
}
else if (main->setting.flag & byte_dump_main_flag_classic_e) {
f_print_dynamic_raw(f_string_ascii_period_s, print->to);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
}
}
else {
for (; at < main->setting.width; ++at) {
if (invalid[at]) {
- fl_print_format("%[%r%]", print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->error, byte_dump_character_placeholder_s, print->set->error);
}
else if (main->setting.flag & byte_dump_main_flag_classic_e) {
f_print_dynamic_raw(f_string_ascii_period_s, print->to);
}
else {
- fl_print_format("%[%r%]", print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
+ fl_print_format(byte_dump_format_raw_context_s.string, print->to, print->set->warning, byte_dump_character_placeholder_s, print->set->warning);
}
if (main->setting.flag & byte_dump_main_flag_wide_e) {