]> Kevux Git Server - fll/commitdiff
Update: Relocate several static stings into single location for Byte Dump program.
authorKevin Day <kevin@kevux.org>
Thu, 27 Jul 2023 02:31:05 +0000 (21:31 -0500)
committerKevin Day <kevin@kevux.org>
Thu, 27 Jul 2023 02:31:05 +0000 (21:31 -0500)
level_3/byte_dump/c/main/common/string.c
level_3/byte_dump/c/main/common/string.h
level_3/byte_dump/c/main/print/data.c
level_3/byte_dump/c/main/process.c

index ab6232ab1048fcbab3af34ec3e5a49d4af988c2c..2542d9cb69d7f550c1609408936872c558047d2f 100644 (file)
@@ -24,8 +24,28 @@ extern "C" {
   const f_string_static_t byte_dump_character_placeholder_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_character_placeholder_s, 0, BYTE_DUMP_character_placeholder_s_length);
   const f_string_static_t byte_dump_character_incomplete_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_character_incomplete_s, 0, BYTE_DUMP_character_incomplete_s_length);
   const f_string_static_t byte_dump_character_unused_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_character_unused_s, 0, BYTE_DUMP_character_unused_s_length);
+
+  const f_string_static_t byte_dump_format_raw_context_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_format_raw_context_s, 0, BYTE_DUMP_format_raw_context_s_length);
 #endif // _di_byte_dump_s_
 
+#ifndef _di_byte_dump_padding_s_
+  const f_string_static_t byte_dump_padding_3_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_3_s, 0, BYTE_DUMP_padding_3_s_length);
+  const f_string_static_t byte_dump_padding_4_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_4_s, 0, BYTE_DUMP_padding_4_s_length);
+  const f_string_static_t byte_dump_padding_5_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_5_s, 0, BYTE_DUMP_padding_5_s_length);
+  const f_string_static_t byte_dump_padding_6_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_6_s, 0, BYTE_DUMP_padding_6_s_length);
+  const f_string_static_t byte_dump_padding_8_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_8_s, 0, BYTE_DUMP_padding_8_s_length);
+  const f_string_static_t byte_dump_padding_9_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_padding_9_s, 0, BYTE_DUMP_padding_9_s_length);
+
+  const f_string_static_t byte_dump_padding_s[] = {
+    byte_dump_padding_9_s,
+    byte_dump_padding_3_s,
+    byte_dump_padding_4_s,
+    byte_dump_padding_4_s,
+    byte_dump_padding_9_s,
+    byte_dump_padding_4_s,
+  };
+#endif // _di_byte_dump_padding_s_
+
 #ifndef _di_byte_dump_parameter_d_
   const f_string_static_t byte_dump_short_binary_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_short_binary_s, 0, BYTE_DUMP_short_binary_s_length);
   const f_string_static_t byte_dump_short_decimal_s = macro_f_string_static_t_initialize_1(BYTE_DUMP_short_decimal_s, 0, BYTE_DUMP_short_decimal_s_length);
index 8029813094d9932968427250aa6023f77811c7fa..df467f3a58890882dfe514660aacd2695b4d2575 100644 (file)
@@ -74,6 +74,8 @@ extern "C" {
   #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
@@ -85,6 +87,8 @@ extern "C" {
   #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;
@@ -95,9 +99,47 @@ extern "C" {
   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_
index c4f6381349169cf4ef1fee489f17384895500fbb..916377112ef10c559163b6581096e373f5110332 100644 (file)
@@ -38,30 +38,13 @@ extern "C" {
         // 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);
               }
@@ -71,22 +54,7 @@ extern "C" {
                 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);
               }
@@ -138,13 +106,13 @@ extern "C" {
         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]) {
@@ -156,7 +124,7 @@ extern "C" {
         }
         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]) {
@@ -168,7 +136,7 @@ extern "C" {
         }
         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]) {
@@ -188,7 +156,7 @@ extern "C" {
         }
         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]) {
@@ -232,7 +200,7 @@ extern "C" {
       }
     }
     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);
         }
@@ -242,22 +210,7 @@ extern "C" {
           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);
         }
@@ -303,7 +256,7 @@ extern "C" {
         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);
@@ -336,13 +289,13 @@ extern "C" {
           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) {
@@ -377,7 +330,7 @@ extern "C" {
       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);
@@ -496,10 +449,10 @@ extern "C" {
 
           // 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) {
@@ -588,13 +541,13 @@ extern "C" {
       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 {
@@ -610,13 +563,13 @@ extern "C" {
         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 {
@@ -632,13 +585,13 @@ extern "C" {
           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 {
@@ -660,13 +613,13 @@ extern "C" {
       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) {
index b937e2e544f09dc5497150f41a5557d5bf493ff1..46f325a748829537c39a78234dcf7e5890fad7de 100644 (file)
@@ -241,24 +241,7 @@ extern "C" {
     if (cell.column && cell.column < main->setting.width) {
       while (cell.column < main->setting.width) {
 
-        if (main->setting.flag & byte_dump_main_flag_unicode_e) {
-          f_print_terminated("         ", main->program.output.to);
-        }
-        else if (main->setting.mode == byte_dump_mode_hexidecimal_e) {
-          f_print_terminated("   ", main->program.output.to);
-        }
-        else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
-          f_print_terminated("    ", main->program.output.to);
-        }
-        else if (main->setting.mode == byte_dump_mode_octal_e) {
-          f_print_terminated("    ", main->program.output.to);
-        }
-        else if (main->setting.mode == byte_dump_mode_binary_e) {
-          f_print_terminated("         ", main->program.output.to);
-        }
-        else if (main->setting.mode == byte_dump_mode_decimal_e) {
-          f_print_terminated("    ", main->program.output.to);
-        }
+        f_print_dynamic_raw(byte_dump_padding_s[(main->setting.flag & byte_dump_main_flag_unicode_e) ? 0 : main->setting.mode], main->program.output.to);
 
         ++cell.column;
 
@@ -273,22 +256,7 @@ extern "C" {
               f_print_dynamic_raw(f_string_space_s, main->program.output.to);
             }
           }
-          else if (main->setting.mode == byte_dump_mode_duodecimal_e) {
-            if (!(cell.column % 6)) {
-              f_print_dynamic_raw(f_string_space_s, main->program.output.to);
-            }
-          }
-          else if (main->setting.mode == byte_dump_mode_octal_e) {
-            if (!(cell.column % 6)) {
-              f_print_dynamic_raw(f_string_space_s, main->program.output.to);
-            }
-          }
-          else if (main->setting.mode == byte_dump_mode_binary_e) {
-            if (!(cell.column % 6)) {
-              f_print_dynamic_raw(f_string_space_s, main->program.output.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_binary_e || main->setting.mode == byte_dump_mode_decimal_e) {
             if (!(cell.column % 6)) {
               f_print_dynamic_raw(f_string_space_s, main->program.output.to);
             }