]> Kevux Git Server - control/commitdiff
Refactor: Change bit-wise enumerations into defines.
authorKevin Day <Kevin@kevux.org>
Wed, 31 Jul 2024 02:45:29 +0000 (21:45 -0500)
committerKevin Day <Kevin@kevux.org>
Wed, 31 Jul 2024 02:45:29 +0000 (21:45 -0500)
I did some reviewing of how the enumerations used for flags are used.
These generally are not being used as a type.
An enumeration slightly increases the resulting binary size.
Enumeration values might be limited to just type of int.

This seems like an easy (small) optimization to just use defines rather than enumerations for flags and other bit-wise numbers.

sources/c/program/control/control/main.c
sources/c/program/control/main/common.c
sources/c/program/control/main/common/define.h
sources/c/program/control/main/common/enumeration.h
sources/c/program/control/main/common/type.h
sources/c/program/control/main/packet.c
sources/c/program/control/main/process.c

index 32edbac67e4af27dcf3021d5bf6748121df33e45..20509b4e7ae82111763b61934db0f3cccf37c39f 100644 (file)
@@ -4,11 +4,11 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   control_t data = control_t_initialize;
 
-  data.program.debug.flag |= control_print_flag_debug_e | control_print_flag_out_e;
-  data.program.error.flag |= control_print_flag_error_e | control_print_flag_out_e;
-  data.program.output.flag |= control_print_flag_out_e;
-  data.program.message.flag |= control_print_flag_message_e | control_print_flag_out_e;
-  data.program.warning.flag |= control_print_flag_warning_e | control_print_flag_out_e;
+  data.program.debug.flag |= control_print_flag_debug_d | control_print_flag_out_d;
+  data.program.error.flag |= control_print_flag_error_d | control_print_flag_out_d;
+  data.program.output.flag |= control_print_flag_out_d;
+  data.program.message.flag |= control_print_flag_message_d | control_print_flag_out_d;
+  data.program.warning.flag |= control_print_flag_warning_d | control_print_flag_out_d;
   data.program.error.custom = (void *) &data;
   data.program.debug.custom = (void *) &data;
   data.program.message.custom = (void *) &data;
index aab7c088383a06184e109a7ff3468cdd5b1f7b21..fe65a9ddfd3f5819ece06a3a5d753bc8231669c7 100644 (file)
@@ -38,7 +38,7 @@ extern "C" {
     }
 
     if (main->program.parameters.array[f_console_standard_parameter_help_e].result & f_console_result_found_e) {
-      main->setting.flag |= control_main_flag_help_e;
+      main->setting.flag |= control_main_flag_help_d;
 
       return;
     }
@@ -50,13 +50,13 @@ extern "C" {
     }
 
     if (main->program.parameters.array[f_console_standard_parameter_copyright_e].result & f_console_result_found_e) {
-      main->setting.flag |= control_main_flag_copyright_e;
+      main->setting.flag |= control_main_flag_copyright_d;
 
       return;
     }
 
     if (main->program.parameters.array[control_parameter_return_e].result & f_console_result_found_e) {
-      main->setting.flag |= control_main_flag_return_e;
+      main->setting.flag |= control_main_flag_return_d;
 
       return;
     }
@@ -64,10 +64,10 @@ extern "C" {
     f_number_unsigned_t index = 0;
 
     if (main->program.pipe & fll_program_data_pipe_input_e) {
-      main->setting.flag |= control_main_flag_pipe_e;
+      main->setting.flag |= control_main_flag_pipe_d;
     }
     else {
-      main->setting.flag &= ~control_main_flag_pipe_e;
+      main->setting.flag &= ~control_main_flag_pipe_d;
     }
 
     // The settings path is statically allocated.
index 1a8c2e05049306f2cdb76e4880367e505466e0c4..38a17111a0bf256b7eb2ffaf08029b74e1ebac12 100644 (file)
@@ -45,6 +45,29 @@ extern "C" {
 #endif // _di_control_default_d_
 
 /**
+ * Flags passed to the main function or program.
+ *
+ * control_main_flag_*_d:
+ *   - none:                   No flags set.
+ *   - copyright:              Print copyright.
+ *   - header:                 Enable printing of headers.
+ *   - help:                   Print help.
+ *   - pipe:                   Use the input pipe.
+ *   - return:                 Print a message about the response packet.
+ *   - version:                Print version.
+ *   - version_copyright_help: A helper flag representing version, copyright, and help flag bits being set.
+ */
+#ifndef _di_control_main_flag_d_
+  #define control_main_flag_none_d                   0x0
+  #define control_main_flag_copyright_d              0x1
+  #define control_main_flag_help_d                   0x2
+  #define control_main_flag_pipe_d                   0x4
+  #define control_main_flag_return_d                 0x8
+  #define control_main_flag_version_e                0x10
+  #define control_main_flag_version_copyright_help_d 0x13
+#endif // _di_control_main_flag_d_
+
+/**
  * A codes repesent different flags associated with a packet.
  *
  * control_packet_flag_*_d:
@@ -57,6 +80,29 @@ extern "C" {
 #endif // _di_control_packet_flag_d_
 
 /**
+ * Flags for fine-tuned print control.
+ *
+ * control_print_flag_*_d:
+ *   - none:    No flags set.
+ *   - debug:   Stream is for debug printing.
+ *   - error:   Stream is for error printing.
+ *   - in:      Stream is a source file.
+ *   - message: Stream is for message printing.
+ *   - out:     Stream is a destination file.
+ *   - warning: Stream is for warning printing.
+ */
+#ifndef _di_control_print_flag_d_
+  #define control_print_flag_none_d    0x0
+  #define control_print_flag_debug_d   0x1
+  #define control_print_flag_error_d   0x2
+  #define control_print_flag_file_d    0x4
+  #define control_print_flag_in_d      0x8
+  #define control_print_flag_out_d     0x10
+  #define control_print_flag_message_d 0x20
+  #define control_print_flag_warning_d 0x40
+#endif // _di_control_print_flag_d_
+
+/**
  * The program signal defines.
  *
  * control_signal_*_d:
index 8fa82863c926514b37d765a27d7e6a3220c86640..eb86b554d9f62e88ea68543175cc06a84386b608 100644 (file)
@@ -55,31 +55,6 @@ extern "C" {
 #endif // _di_control_action_type_e_
 
 /**
- * Flags passed to the main function or program.
- *
- * control_main_flag_*_e:
- *   - none:                   No flags set.
- *   - copyright:              Print copyright.
- *   - header:                 Enable printing of headers.
- *   - help:                   Print help.
- *   - pipe:                   Use the input pipe.
- *   - return:                 Print a message about the response packet.
- *   - version:                Print version.
- *   - version_copyright_help: A helper flag representing version, copyright, and help flag bits being set.
- */
-#ifndef _di_control_main_flag_e_
-  enum {
-    control_main_flag_none_e                   = 0x0,
-    control_main_flag_copyright_e              = 0x1,
-    control_main_flag_help_e                   = 0x2,
-    control_main_flag_pipe_e                   = 0x4,
-    control_main_flag_return_e                 = 0x8,
-    control_main_flag_version_e                = 0x10,
-    control_main_flag_version_copyright_help_e = 0x13,
-  }; // enum
-#endif // _di_control_main_flag_e_
-
-/**
  * Supported payload types.
  *
  * control_payload_type_*_e:
@@ -119,31 +94,6 @@ extern "C" {
   #define control_parameter_total_d (f_console_parameter_state_type_total_d + 4)
 #endif // _di_control_parameter_e_
 
-/**
- * Flags for fine-tuned print control.
- *
- * control_print_flag_*_e:
- *   - none:    No flags set.
- *   - debug:   Stream is for debug printing.
- *   - error:   Stream is for error printing.
- *   - in:      Stream is a source file.
- *   - message: Stream is for message printing.
- *   - out:     Stream is a destination file.
- *   - warning: Stream is for warning printing.
- */
-#ifndef _di_control_print_flag_e_
-  enum {
-    control_print_flag_none_e    = 0x0,
-    control_print_flag_debug_e   = 0x1,
-    control_print_flag_error_e   = 0x2,
-    control_print_flag_file_e    = 0x4,
-    control_print_flag_in_e      = 0x8,
-    control_print_flag_out_e     = 0x10,
-    control_print_flag_message_e = 0x20,
-    control_print_flag_warning_e = 0x40,
-  }; // enum
-#endif // _di_control_print_flag_e_
-
 #ifdef __cplusplus
 } // extern "C"
 #endif
index c42d46781f1a2d4cc7cb63dff5e10b638c6b9b86..973b971d38fc4db4b55721e92ddb8b9ea1a3d0ab 100644 (file)
@@ -136,7 +136,7 @@ extern "C" {
 
   #define control_setting_t_initialize \
     { \
-      control_main_flag_none_e, \
+      control_main_flag_none_d, \
       0, \
       0, \
       F_okay, \
index 92c2afcde1d56a3c4511558e3d522a9d9a6ea0df..69f7cef58507b3beef9e25f8bfda353ce81d7c1e 100644 (file)
@@ -505,7 +505,7 @@ extern "C" {
       }
     }
 
-    if (main->setting.flag & control_main_flag_return_e) {
+    if (main->setting.flag & control_main_flag_return_d) {
       control_print_message_packet_response_return(&main->program.output, header, string_status);
     }
     else if (header->type == control_payload_type_error_e) {
index 30dc2e3c9987a7f1a70ed3c5c58b20578a6e33c5..e6ce0b02bb4b1dbc1dd733ce9af39ac67b5904a1 100644 (file)
@@ -11,21 +11,21 @@ extern "C" {
 
     main->setting.state.status = F_okay;
 
-    if (main->setting.flag & control_main_flag_version_copyright_help_e) {
-      if (main->setting.flag & control_main_flag_help_e) {
+    if (main->setting.flag & control_main_flag_version_copyright_help_d) {
+      if (main->setting.flag & control_main_flag_help_d) {
         control_print_message_help(&main->program.message);
       }
       else if (main->setting.flag & control_main_flag_version_e) {
         fll_program_print_version(&main->program.message, control_program_version_s);
       }
-      else if (main->setting.flag & control_main_flag_copyright_e) {
+      else if (main->setting.flag & control_main_flag_copyright_d) {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
       return;
     }
 
-    if (main->setting.flag & control_main_flag_pipe_e) {
+    if (main->setting.flag & control_main_flag_pipe_d) {
       control_print_error_pipe_supported_not(&main->program.error);
 
       main->setting.state.status = F_status_set_error(F_support_not);