]> Kevux Git Server - fll/commitdiff
Update: Improve signal handling code. development
authorKevin Day <Kevin@kevux.org>
Tue, 28 Jan 2025 04:31:23 +0000 (22:31 -0600)
committerKevin Day <Kevin@kevux.org>
Tue, 28 Jan 2025 04:41:59 +0000 (22:41 -0600)
Add a new line before printing the standard "Received signal code" message to ensure that it is always reasonably separated from the output being interrupted.

Simplify the verbosity variable check to a less than because the verbosity list is an enumeration.

Move the `fll_program_print_signal_received()` calls to the main program to help ensure consistent printing at the end of the program.
- Note: I am not certain if I want this instead in the main() function or not and I opted not to do so for now.

Fix some cases where the manual signal checks are still being performed to use the function instead.

23 files changed:
level_2/fll_program/c/program/print.c
level_3/byte_dump/c/main/byte_dump.c
level_3/byte_dump/c/main/signal.c
level_3/example/c/main/example.c
level_3/example/c/main/signal.c
level_3/fake/c/main/fake.c
level_3/fake/c/main/signal.c
level_3/firewall/c/main/firewall.c
level_3/firewall/c/main/signal.c
level_3/fss_identify/c/main/fss_identify.c
level_3/fss_identify/c/main/signal.c
level_3/fss_read/c/main/fss_read.c
level_3/fss_read/c/main/signal.c
level_3/fss_write/c/main/fss_write.c
level_3/fss_write/c/main/signal.c
level_3/iki_read/c/main/iki_read.c
level_3/iki_read/c/main/signal.c
level_3/iki_write/c/main/iki_write.c
level_3/iki_write/c/main/signal.c
level_3/status_code/c/main/signal.c
level_3/status_code/c/main/status_code.c
level_3/utf8/c/main/signal.c
level_3/utf8/c/main/utf8.c

index 63e72288e5619b07ad9bbf27d71e5b05d5c82f37..0832ff5f37e5db1909486cc4e35a10f16f75e93a 100644 (file)
@@ -680,7 +680,7 @@ extern "C" {
       if (!print) return F_status_set_error(F_parameter);
     #endif // _di_level_2_parameter_checking_
 
-    if (print->verbosity != f_console_verbosity_verbose_e && print->verbosity != f_console_verbosity_debug_e) {
+    if (print->verbosity < f_console_verbosity_verbose_e) {
       return F_output_not;
     }
 
@@ -689,7 +689,7 @@ extern "C" {
     // Must flush and reset color because the interrupt may have interrupted the middle of a print function.
     f_file_stream_flush(print->to);
 
-    fl_print_format("%]%[Received signal code %]", print->to, print->set->reset, print->set->warning, print->set->warning);
+    fl_print_format("%]\n%[Received signal code %]", print->to, print->set->reset, print->set->warning, print->set->warning);
     fl_print_format(f_string_format_u_single_s.string, print->to, print->set->notable, signal, print->set->notable);
     fl_print_format(f_string_format_sentence_end_single_s.string, print->to, print->set->warning, print->set->warning, f_string_eol_s);
 
index 1a312d4b67493036773acfcb1e81b7ef7ba0390c..bc094d3cce5a2501cd43df9136837ecee4ce78cd 100644 (file)
@@ -22,6 +22,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -81,6 +85,10 @@ extern "C" {
 
       byte_dump_print_error_file_none(&main->program.error);
     }
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_byte_dump_main_
 
index 6e064931933b1d590c046b28fc3ea7488161c09b..d0928020e5eb7f6b13896b682d8cd078d65d1fe3 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % byte_dump_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index ee4994d521c44f426dea29cfe2074c389e5b4041..8bf8ad5e1bea25077efd20bf090b21cba3dcfab6 100644 (file)
@@ -22,10 +22,14 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
-    if (main->setting.state.status == F_status_set_error(F_interrupt)) {
+    if (main->program.signal_received) {
       fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
     }
   }
index 3ee3fab9b7b33a6ff0953a12197728097f86293b..7a3972b4f49886fdc2585666fab8c420ef1687cd 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % example_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index de88cb2cc9d080abe3adb79cf386e55de888c911..089e84f23e74db0bd28add0f4b0e82e7c479ed41 100644 (file)
@@ -22,6 +22,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -183,6 +187,10 @@ extern "C" {
     }
 
     fake_data_delete(&data);
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_fake_main_
 
index d0c1fe4c4c7b95c6b2d21c449dea5735d77c43b9..f102697a293942cee681107228ec470883dee99a 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % fake_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index dd84c03ffd34bc2b4881d63acc5529fac1f84102..3956a1d1a10d84f5bec5492c47d61569bfd8e330 100644 (file)
@@ -22,6 +22,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -34,6 +38,10 @@ extern "C" {
       firewall_print_error_operation_specified_not(&main->program.error);
     }
 
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
+
     if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_interrupt) return;
 
     main->setting.state.status = F_okay;
index 7711f7489e5787f20142d2f63ab2d6a9346d9361..6fd7cd3073b17f8fdf528fa9c2b63e32830a7d53 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % firewall_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index cb57051a6f5164f532940d17a6c30cd7754e39ae..c1a14da782e7a8fb1016002593ef3f2d43d7d27b 100644 (file)
@@ -22,6 +22,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -69,6 +73,10 @@ extern "C" {
       }
     }
 
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
+
     if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_interrupt) return;
 
     main->setting.state.status = F_okay;
index b633959fa4c8d01e2ea9b9861d3c98ef1336d891..c548b791ec0e436a1330fc797a8d79d63a7c693e 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % fss_identify_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index e97f1d613cda18bceb6ace5965c67e32a847a75a..f91cbafe40b8bd9023c9331824fcea53f4f6e04b 100644 (file)
@@ -72,6 +72,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -80,6 +84,10 @@ extern "C" {
         main->callback.process(void_main);
       }
     }
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_fss_read_main_
 
index 8dc4ea2568bc1a83e7bea386286fc61aff626674..fbab7c3f3cb5a74d26426a8a6ffc5f7e344f3540 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % fss_read_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index 5370ac476baa9b47f8027b3d84ca10e9f6ce9992..10344f31b4ed87967786921387c2d336d018bd0f 100644 (file)
@@ -31,6 +31,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -47,6 +51,10 @@ extern "C" {
         }
       }
     }
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_fss_write_main_
 
@@ -79,16 +87,7 @@ extern "C" {
     if (length) {
       for (f_number_unsigned_t i = 0; i < length; ++i) {
 
-        // @todo replace all signal checks with forked main process that independently checks and assigns main->program.signal_received.
-        if (!((++main->program.signal_check) % fss_write_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            return;
-          }
-
-          main->program.signal_check = 0;
-        }
+        if (fss_write_signal_check(main)) return;
 
         if (main->setting.objects.used) {
           main->setting.object = &main->setting.objects.array[i];
@@ -196,17 +195,7 @@ extern "C" {
 
     for (;;) {
 
-      if (!((++main->program.signal_check) % fss_write_signal_check_d)) {
-        if (fll_program_standard_signal_received(&main->program)) {
-          fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
-          main->setting.state.status = F_status_set_error(F_interrupt);
-
-          break;
-        }
-
-        main->program.signal_check = 0;
-      }
+      if (fss_write_signal_check(main)) break;
 
       if (range.start > range.stop) {
         if (status_pipe == F_okay_eof) break;
index 37027cea9054fa5e89873625b036000a689956ee..56a3955709752366d9794a8becbd0fc8531101c8 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % fss_write_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index 08d81de5c4a9b62fd838bafebe249eb72bcd186d..add8460be69bd24f48a72cb93973fcbac32f7a51 100644 (file)
@@ -24,6 +24,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -139,6 +143,10 @@ extern "C" {
         f_file_stream_close(&file);
       }
     }
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_iki_read_main_
 
index 36854ea50fc6b17146af4f7faa8c09303ccdea1b..e79cc9e7c7f41997085d1ecd4884ba670e788940 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % iki_read_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index eb9ab45faee1e840a427d3f72190bf3bb2f1ca75..0d0224d529cd5cb9a29ed5254eda102c9c6936b7 100644 (file)
@@ -24,6 +24,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -127,6 +131,10 @@ extern "C" {
         fll_print_dynamic_raw(f_string_eol_s, main->program.output.to);
       } // for
     }
+
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
   }
 #endif // _di_iki_write_main_
 
index 8bf9e3883dbac494248a088ce0afb8c0c14d1068..10eeedc1f7642a7bea5f017c9cfa3fcaeb0886b6 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % iki_write_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index 3aaea4afb0d6c1c25f393185962239e4e35e1fb4..3be8e85402a5e346a8c945cc38f3366b6754f3da 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % status_code_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index aefd52c960510c7ebb3f06a4953149b1f19172dc..118f19d3c734f6fbd1c7ffe3808b7c4ead4954f2 100644 (file)
@@ -36,6 +36,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -51,15 +55,7 @@ extern "C" {
 
         for (f_number_unsigned_t i = 0; i < main->program.parameters.remaining.used; ++i) {
 
-          if (!((++main->program.signal_check) % status_code_signal_check_d)) {
-            if (fll_program_standard_signal_received(&main->program)) {
-              main->setting.state.status = F_status_set_error(F_interrupt);
-
-              break;
-            }
-
-            main->program.signal_check = 0;
-          }
+          if (status_code_signal_check(main)) break;
 
           status = main->setting.state.status;
 
@@ -83,15 +79,7 @@ extern "C" {
 
         for (f_number_unsigned_t i = 0; i < main->program.parameters.remaining.used; ++i) {
 
-          if (!((++main->program.signal_check) % status_code_signal_check_d)) {
-            if (fll_program_standard_signal_received(&main->program)) {
-              main->setting.state.status = F_status_set_error(F_interrupt);
-
-              break;
-            }
-
-            main->program.signal_check = 0;
-          }
+          if (status_code_signal_check(main)) break;
 
           status = main->setting.state.status;
 
@@ -115,15 +103,7 @@ extern "C" {
 
         for (f_number_unsigned_t i = 0; i < main->program.parameters.remaining.used; ++i) {
 
-          if (!((++main->program.signal_check) % status_code_signal_check_d)) {
-            if (fll_program_standard_signal_received(&main->program)) {
-              main->setting.state.status = F_status_set_error(F_interrupt);
-
-              break;
-            }
-
-            main->program.signal_check = 0;
-          }
+          if (status_code_signal_check(main)) break;
 
           status = main->setting.state.status;
 
@@ -138,7 +118,7 @@ extern "C" {
       }
     }
 
-    if (main->setting.state.status == F_status_set_error(F_interrupt)) {
+    if (main->program.signal_received) {
       fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
     }
   }
index 64f391d7d9230ebabacd825199e04cf85041e724..ce5fa2b3149adf3d47c8470ba38d33b3045a3673 100644 (file)
@@ -12,8 +12,6 @@ extern "C" {
 
     if (!((++main->program.signal_check) % utf8_signal_check_d)) {
       if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) {
-        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
         main->setting.state.status = F_status_set_error(F_interrupt);
 
         return F_true;
@@ -32,8 +30,6 @@ extern "C" {
     if (!main) return F_false;
 
     if (main->program.signal_received) {
-      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
       main->setting.state.status = F_status_set_error(F_interrupt);
 
       return F_true;
index 90543b2f38f818f4f7153833fd40c4fdc7e7e9ff..d70eb688e2d5a0d805ca9e2338ae816fcddd546e 100644 (file)
@@ -22,6 +22,10 @@ extern "C" {
         fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s);
       }
 
+      if (main->program.signal_received) {
+        fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+      }
+
       return;
     }
 
@@ -143,6 +147,10 @@ extern "C" {
       }
     }
 
+    if (main->program.signal_received) {
+      fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
+    }
+
     if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_interrupt) return;
 
     main->setting.state.status = (main->setting.flag & utf8_main_flag_verify_d) ? valid : F_okay;