]> Kevux Git Server - fll/commitdiff
Update: Add 3 presentation modes to byte_dump: normal, simple, and classic
authorKevin Day <thekevinday@gmail.com>
Tue, 10 Sep 2019 00:44:12 +0000 (19:44 -0500)
committerKevin Day <thekevinday@gmail.com>
Tue, 10 Sep 2019 00:44:12 +0000 (19:44 -0500)
Normal presentation will replace ASCII control or whitespace character with the UTF-8 characters that represent this with a picture character.
Simple presentation will use a single space to represent any given ASCII control or whitespace character.
Classic presentation will do what the "hexdump" tool traditionally does and use a single period to represent an ASCII control or whitespace character.

level_3/byte_dump/c/byte_dump.c
level_3/byte_dump/c/byte_dump.h
level_3/byte_dump/c/private-byte_dump.c

index 734fb127a33c8e0d57723eea6f8f61669a661e6c..f4763c6782af93c815efdcc818c8eba96dbbb8a8 100644 (file)
@@ -33,6 +33,12 @@ extern "C" {
     fll_program_print_help_option(data.context, byte_dump_short_text, byte_dump_long_text, f_console_symbol_short_enable, f_console_symbol_long_enable, "       Include a column of text when displaying the bytes.");
     fll_program_print_help_option(data.context, byte_dump_short_placeholder, byte_dump_long_placeholder, f_console_symbol_short_enable, f_console_symbol_long_enable, "Use a placeholder character instead of a space for placeholders.");
 
+    printf("%c", f_string_eol);
+
+    fll_program_print_help_option_long(data.context, byte_dump_long_normal, f_console_symbol_long_enable, "Display UTF-8 symbols for ASCII control codes.");
+    fll_program_print_help_option_long(data.context, byte_dump_long_simple, f_console_symbol_long_enable, "Display spaces for ASCII control codes.");
+    fll_program_print_help_option_long(data.context, byte_dump_long_classic, f_console_symbol_long_enable, "Display periods for ASCII control codes.");
+
     fll_program_print_help_usage(data.context, byte_dump_name, "filename(s)");
 
     printf("  When using the ");
@@ -59,6 +65,7 @@ extern "C" {
   f_return_status byte_dump_main(const f_console_arguments arguments, byte_dump_data *data) {
     f_status status = f_none;
 
+    // Identify priority of color parameters.
     {
       f_console_parameters parameters = { data->parameters, byte_dump_total_parameters };
       f_console_parameter_ids choices = f_console_parameter_ids_initialize;
@@ -76,6 +83,7 @@ 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 choice = byte_dump_parameter_hexidecimal;
@@ -102,6 +110,31 @@ extern "C" {
           data->mode = byte_dump_mode_decimal;
         }
       }
+
+      // Identify priority of presentation parameters.
+      {
+        f_console_parameter_id ids[3] = { byte_dump_parameter_normal, byte_dump_parameter_simple, byte_dump_parameter_classic };
+        f_console_parameter_id choice = byte_dump_parameter_normal;
+        choices.id = ids;
+        choices.used = 3;
+
+        status = fl_console_parameter_prioritize(parameters, choices, &choice);
+
+        if (f_status_is_error(status)) {
+          byte_dump_delete_data(data);
+          return f_status_set_error(status);
+        }
+
+        if (choice == byte_dump_parameter_normal) {
+          data->presentation = byte_dump_presentation_normal;
+        }
+        else if (choice == byte_dump_parameter_simple) {
+          data->presentation = byte_dump_presentation_simple;
+        }
+        else if (choice == byte_dump_parameter_classic) {
+          data->presentation = byte_dump_presentation_classic;
+        }
+      }
     }
 
     status = f_none;
index a08b08b2ae0c1714ef645b49ba5768069a9fa4ba..d98f10481043180f7f3e65a75a8fedb8317d0520 100644 (file)
@@ -68,6 +68,12 @@ extern "C" {
     byte_dump_mode_decimal,
   };
 
+  enum {
+    byte_dump_presentation_normal,
+    byte_dump_presentation_simple,
+    byte_dump_presentation_classic,
+  };
+
   #define byte_dump_sequence_acknowledge               "␆"
   #define byte_dump_sequence_backspace                 "␈"
   #define byte_dump_sequence_bell                      "␇"
@@ -133,6 +139,10 @@ extern "C" {
   #define byte_dump_long_text         "text"        // display text
   #define byte_dump_long_placeholder  "placeholder" // display (colored) placeholders to signify codes that are UTF-8 fragments.
 
+  #define byte_dump_long_normal       "normal"      // use normal presentation, displaying UTF-8 sequence codes for ASCII special codes.
+  #define byte_dump_long_simple       "simple"      // use simple presentation, displaying spaces for ASCII special codes instead of UTF-8 sequence codes.
+  #define byte_dump_long_classic      "classic"     // use classic presentation, displaying periods for ASCII special codes instead of UTF-8 sequence codes.
+
   enum {
     byte_dump_parameter_help,
     byte_dump_parameter_light,
@@ -151,6 +161,10 @@ extern "C" {
 
     byte_dump_parameter_text,
     byte_dump_parameter_placeholder,
+
+    byte_dump_parameter_normal,
+    byte_dump_parameter_simple,
+    byte_dump_parameter_classic,
   };
 
   #define byte_dump_console_parameter_initialize \
@@ -169,9 +183,12 @@ extern "C" {
       f_console_parameter_initialize(byte_dump_short_width, byte_dump_long_width, 0, 1, f_console_type_normal), \
       f_console_parameter_initialize(byte_dump_short_text, byte_dump_long_text, 0, 0, f_console_type_normal), \
       f_console_parameter_initialize(byte_dump_short_placeholder, byte_dump_long_placeholder, 0, 0, f_console_type_normal), \
+      f_console_parameter_initialize(0, byte_dump_long_normal, 0, 0, f_console_type_normal), \
+      f_console_parameter_initialize(0, byte_dump_long_simple, 0, 0, f_console_type_normal), \
+      f_console_parameter_initialize(0, byte_dump_long_classic, 0, 0, f_console_type_normal), \
     }
 
-  #define byte_dump_total_parameters 14
+  #define byte_dump_total_parameters 17
 #endif // _di_byte_dump_defines_
 
 #ifndef _di_byte_dump_data_
@@ -185,6 +202,7 @@ extern "C" {
     uint64_t last;
     uint8_t  width;
     uint8_t  mode;
+    uint8_t  presentation;
 
     fl_color_context context;
   } byte_dump_data;
@@ -198,6 +216,7 @@ extern "C" {
       0, \
       8, \
       byte_dump_mode_hexidecimal, \
+      byte_dump_presentation_normal, \
       fl_color_context_initialize, \
     }
 #endif // _di_byte_dump_data_
index 8dfb181647a31c3cd6dad5a162eac451b87252d5..3140f746356744f4d2292847e2ee86f982de6d46 100644 (file)
     uint8_t j = 0;
     uint8_t output = 0;
     uint8_t width_utf = 0;
+    f_bool printed = f_false;
 
     fl_color_print(f_standard_output, data.context.notable, data.context.reset, "  %s ", byte_dump_character_wall);
 
       if (invalid[i]) {
         fl_color_print(f_standard_output, data.context.error, data.context.reset, "%s", byte_dump_character_incomplete);
       }
-      else if (output == 0) {
-        printf("%s", byte_dump_sequence_null);
-      }
-      else if (output == 1) {
-        printf("%s", byte_dump_sequence_start_of_header);
-      }
-      else if (output == 2) {
-        printf("%s", byte_dump_sequence_start_of_text);
-      }
-      else if (output == 3) {
-        printf("%s", byte_dump_sequence_end_of_text);
-      }
-      else if (output == 4) {
-        printf("%s", byte_dump_sequence_end_of_transmission);
-      }
-      else if (output == 5) {
-        printf("%s", byte_dump_sequence_end_of_enquiry);
-      }
-      else if (output == 6) {
-        printf("%s", byte_dump_sequence_acknowledge);
-      }
-      else if (output == 7) {
-        printf("%s", byte_dump_sequence_bell);
-      }
-      else if (output == 8) {
-        printf("%s", byte_dump_sequence_backspace);
-      }
-      else if (output == 9) {
-        printf("%s", byte_dump_sequence_tab);
-      }
-      else if (output == 10) {
-        printf("%s", byte_dump_sequence_new_line);
-      }
-      else if (output == 11) {
-        printf("%s", byte_dump_sequence_tab_vertical);
-      }
-      else if (output == 12) {
-        printf("%s", byte_dump_sequence_form_feed);
-      }
-      else if (output == 13) {
-        printf("%s", byte_dump_sequence_carriage_return);
-      }
-      else if (output == 14) {
-        printf("%s", byte_dump_sequence_shift_out);
-      }
-      else if (output == 15) {
-        printf("%s", byte_dump_sequence_shift_in);
-      }
-      else if (output == 16) {
-        printf("%s", byte_dump_sequence_data_link_escape);
-      }
-      else if (output == 17) {
-        printf("%s", byte_dump_sequence_device_control_1);
-      }
-      else if (output == 18) {
-        printf("%s", byte_dump_sequence_device_control_2);
-      }
-      else if (output == 19) {
-        printf("%s", byte_dump_sequence_device_control_3);
-      }
-      else if (output == 20) {
-        printf("%s", byte_dump_sequence_device_control_4);
-      }
-      else if (output == 21) {
-        printf("%s", byte_dump_sequence_negative_acknowledge);
-      }
-      else if (output == 22) {
-        printf("%s", byte_dump_sequence_synchronous_idle);
-      }
-      else if (output == 23) {
-        printf("%s", byte_dump_sequence_end_of_transmission_block);
-      }
-      else if (output == 24) {
-        printf("%s", byte_dump_sequence_cancel);
-      }
-      else if (output == 25) {
-        printf("%s", byte_dump_sequence_end_of_medium);
-      }
-      else if (output == 26) {
-        printf("%s", byte_dump_sequence_substitute);
-      }
-      else if (output == 27) {
-        printf("%s", byte_dump_sequence_escape);
-      }
-      else if (output == 28) {
-        printf("%s", byte_dump_sequence_file_separator);
-      }
-      else if (output == 29) {
-        printf("%s", byte_dump_sequence_group_separator);
-      }
-      else if (output == 30) {
-        printf("%s", byte_dump_sequence_record_separator);
-      }
-      else if (output == 31) {
-        printf("%s", byte_dump_sequence_unit_separator);
-      }
-      else if (output == 32) {
-        printf("%s", byte_dump_sequence_space);
-      }
-      else if (output == 127) {
-        printf("%s", byte_dump_sequence_delete);
+      else if (output >= 0 && output <= 32 || output == 127) {
+        if (data.presentation == byte_dump_presentation_normal) {
+          if (output == 0) {
+            printf("%s", byte_dump_sequence_null);
+          }
+          else if (output == 1) {
+            printf("%s", byte_dump_sequence_start_of_header);
+          }
+          else if (output == 2) {
+            printf("%s", byte_dump_sequence_start_of_text);
+          }
+          else if (output == 3) {
+            printf("%s", byte_dump_sequence_end_of_text);
+          }
+          else if (output == 4) {
+            printf("%s", byte_dump_sequence_end_of_transmission);
+          }
+          else if (output == 5) {
+            printf("%s", byte_dump_sequence_end_of_enquiry);
+          }
+          else if (output == 6) {
+            printf("%s", byte_dump_sequence_acknowledge);
+          }
+          else if (output == 7) {
+            printf("%s", byte_dump_sequence_bell);
+          }
+          else if (output == 8) {
+            printf("%s", byte_dump_sequence_backspace);
+          }
+          else if (output == 9) {
+            printf("%s", byte_dump_sequence_tab);
+          }
+          else if (output == 10) {
+            printf("%s", byte_dump_sequence_new_line);
+          }
+          else if (output == 11) {
+            printf("%s", byte_dump_sequence_tab_vertical);
+          }
+          else if (output == 12) {
+            printf("%s", byte_dump_sequence_form_feed);
+          }
+          else if (output == 13) {
+            printf("%s", byte_dump_sequence_carriage_return);
+          }
+          else if (output == 14) {
+            printf("%s", byte_dump_sequence_shift_out);
+          }
+          else if (output == 15) {
+            printf("%s", byte_dump_sequence_shift_in);
+          }
+          else if (output == 16) {
+            printf("%s", byte_dump_sequence_data_link_escape);
+          }
+          else if (output == 17) {
+            printf("%s", byte_dump_sequence_device_control_1);
+          }
+          else if (output == 18) {
+            printf("%s", byte_dump_sequence_device_control_2);
+          }
+          else if (output == 19) {
+            printf("%s", byte_dump_sequence_device_control_3);
+          }
+          else if (output == 20) {
+            printf("%s", byte_dump_sequence_device_control_4);
+          }
+          else if (output == 21) {
+            printf("%s", byte_dump_sequence_negative_acknowledge);
+          }
+          else if (output == 22) {
+            printf("%s", byte_dump_sequence_synchronous_idle);
+          }
+          else if (output == 23) {
+            printf("%s", byte_dump_sequence_end_of_transmission_block);
+          }
+          else if (output == 24) {
+            printf("%s", byte_dump_sequence_cancel);
+          }
+          else if (output == 25) {
+            printf("%s", byte_dump_sequence_end_of_medium);
+          }
+          else if (output == 26) {
+            printf("%s", byte_dump_sequence_substitute);
+          }
+          else if (output == 27) {
+            printf("%s", byte_dump_sequence_escape);
+          }
+          else if (output == 28) {
+            printf("%s", byte_dump_sequence_file_separator);
+          }
+          else if (output == 29) {
+            printf("%s", byte_dump_sequence_group_separator);
+          }
+          else if (output == 30) {
+            printf("%s", byte_dump_sequence_record_separator);
+          }
+          else if (output == 31) {
+            printf("%s", byte_dump_sequence_unit_separator);
+          }
+          else if (output == 32) {
+            printf("%s", byte_dump_sequence_space);
+          }
+          else if (output == 127) {
+            printf("%s", byte_dump_sequence_delete);
+          }
+        }
+        else if (data.presentation == byte_dump_presentation_simple) {
+          printf(" ");
+        }
+        else if (data.presentation == byte_dump_presentation_classic) {
+          printf(".");
+        }
       }
       else if (f_utf_is_whitespace_character(characters.string[i]) == f_true) {
         printf("%s", byte_dump_sequence_space);