From: Kevin Day Date: Tue, 28 Jan 2025 04:31:23 +0000 (-0600) Subject: Update: Improve signal handling code. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=HEAD;p=fll Update: Improve signal handling code. 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. --- diff --git a/level_2/fll_program/c/program/print.c b/level_2/fll_program/c/program/print.c index 63e7228..0832ff5 100644 --- a/level_2/fll_program/c/program/print.c +++ b/level_2/fll_program/c/program/print.c @@ -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); diff --git a/level_3/byte_dump/c/main/byte_dump.c b/level_3/byte_dump/c/main/byte_dump.c index 1a312d4..bc094d3 100644 --- a/level_3/byte_dump/c/main/byte_dump.c +++ b/level_3/byte_dump/c/main/byte_dump.c @@ -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_ diff --git a/level_3/byte_dump/c/main/signal.c b/level_3/byte_dump/c/main/signal.c index 6e06493..d092802 100644 --- a/level_3/byte_dump/c/main/signal.c +++ b/level_3/byte_dump/c/main/signal.c @@ -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; diff --git a/level_3/example/c/main/example.c b/level_3/example/c/main/example.c index ee4994d..8bf8ad5 100644 --- a/level_3/example/c/main/example.c +++ b/level_3/example/c/main/example.c @@ -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); } } diff --git a/level_3/example/c/main/signal.c b/level_3/example/c/main/signal.c index 3ee3fab..7a3972b 100644 --- a/level_3/example/c/main/signal.c +++ b/level_3/example/c/main/signal.c @@ -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; diff --git a/level_3/fake/c/main/fake.c b/level_3/fake/c/main/fake.c index de88cb2..089e84f 100644 --- a/level_3/fake/c/main/fake.c +++ b/level_3/fake/c/main/fake.c @@ -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_ diff --git a/level_3/fake/c/main/signal.c b/level_3/fake/c/main/signal.c index d0c1fe4..f102697 100644 --- a/level_3/fake/c/main/signal.c +++ b/level_3/fake/c/main/signal.c @@ -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; diff --git a/level_3/firewall/c/main/firewall.c b/level_3/firewall/c/main/firewall.c index dd84c03..3956a1d 100644 --- a/level_3/firewall/c/main/firewall.c +++ b/level_3/firewall/c/main/firewall.c @@ -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; diff --git a/level_3/firewall/c/main/signal.c b/level_3/firewall/c/main/signal.c index 7711f74..6fd7cd3 100644 --- a/level_3/firewall/c/main/signal.c +++ b/level_3/firewall/c/main/signal.c @@ -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; diff --git a/level_3/fss_identify/c/main/fss_identify.c b/level_3/fss_identify/c/main/fss_identify.c index cb57051..c1a14da 100644 --- a/level_3/fss_identify/c/main/fss_identify.c +++ b/level_3/fss_identify/c/main/fss_identify.c @@ -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; diff --git a/level_3/fss_identify/c/main/signal.c b/level_3/fss_identify/c/main/signal.c index b633959..c548b79 100644 --- a/level_3/fss_identify/c/main/signal.c +++ b/level_3/fss_identify/c/main/signal.c @@ -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; diff --git a/level_3/fss_read/c/main/fss_read.c b/level_3/fss_read/c/main/fss_read.c index e97f1d6..f91cbaf 100644 --- a/level_3/fss_read/c/main/fss_read.c +++ b/level_3/fss_read/c/main/fss_read.c @@ -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_ diff --git a/level_3/fss_read/c/main/signal.c b/level_3/fss_read/c/main/signal.c index 8dc4ea2..fbab7c3 100644 --- a/level_3/fss_read/c/main/signal.c +++ b/level_3/fss_read/c/main/signal.c @@ -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; diff --git a/level_3/fss_write/c/main/fss_write.c b/level_3/fss_write/c/main/fss_write.c index 5370ac4..10344f3 100644 --- a/level_3/fss_write/c/main/fss_write.c +++ b/level_3/fss_write/c/main/fss_write.c @@ -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; diff --git a/level_3/fss_write/c/main/signal.c b/level_3/fss_write/c/main/signal.c index 37027ce..56a3955 100644 --- a/level_3/fss_write/c/main/signal.c +++ b/level_3/fss_write/c/main/signal.c @@ -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; diff --git a/level_3/iki_read/c/main/iki_read.c b/level_3/iki_read/c/main/iki_read.c index 08d81de..add8460 100644 --- a/level_3/iki_read/c/main/iki_read.c +++ b/level_3/iki_read/c/main/iki_read.c @@ -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_ diff --git a/level_3/iki_read/c/main/signal.c b/level_3/iki_read/c/main/signal.c index 36854ea..e79cc9e 100644 --- a/level_3/iki_read/c/main/signal.c +++ b/level_3/iki_read/c/main/signal.c @@ -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; diff --git a/level_3/iki_write/c/main/iki_write.c b/level_3/iki_write/c/main/iki_write.c index eb9ab45..0d0224d 100644 --- a/level_3/iki_write/c/main/iki_write.c +++ b/level_3/iki_write/c/main/iki_write.c @@ -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_ diff --git a/level_3/iki_write/c/main/signal.c b/level_3/iki_write/c/main/signal.c index 8bf9e38..10eeedc 100644 --- a/level_3/iki_write/c/main/signal.c +++ b/level_3/iki_write/c/main/signal.c @@ -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; diff --git a/level_3/status_code/c/main/signal.c b/level_3/status_code/c/main/signal.c index 3aaea4a..3be8e85 100644 --- a/level_3/status_code/c/main/signal.c +++ b/level_3/status_code/c/main/signal.c @@ -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; diff --git a/level_3/status_code/c/main/status_code.c b/level_3/status_code/c/main/status_code.c index aefd52c..118f19d 100644 --- a/level_3/status_code/c/main/status_code.c +++ b/level_3/status_code/c/main/status_code.c @@ -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); } } diff --git a/level_3/utf8/c/main/signal.c b/level_3/utf8/c/main/signal.c index 64f391d..ce5fa2b 100644 --- a/level_3/utf8/c/main/signal.c +++ b/level_3/utf8/c/main/signal.c @@ -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; diff --git a/level_3/utf8/c/main/utf8.c b/level_3/utf8/c/main/utf8.c index 90543b2..d70eb68 100644 --- a/level_3/utf8/c/main/utf8.c +++ b/level_3/utf8/c/main/utf8.c @@ -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;