From b8db13653cf389f14b944d2cc03ec17b183ee74a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 8 Dec 2021 23:21:57 -0600 Subject: [PATCH] Bugfix: Performance is slow due to process signal checks. The cost of the system call for checking if a signal is received is more expensive than I have previously imagined. I also was not sure where I should handle the signals and I arbitrarily put them inside loops. Reduce the number of checks. Reduce the number of the system call to check the process signal using modulus math. The performance difference is most notable when using the byte_dump program. This focuses on solving the immediate performance bug. I still have not done any extensive performance investigations and I expect this to still have significant room for improvement. --- level_3/byte_dump/c/byte_dump.h | 2 + level_3/byte_dump/c/private-byte_dump.c | 10 +- level_3/fake/c/fake.c | 2 +- level_3/fake/c/fake.h | 6 + level_3/fake/c/private-build.c | 135 ++++++--------------- level_3/fake/c/private-fake.c | 26 ++-- level_3/fake/c/private-make.c | 29 +---- level_3/fake/c/private-skeleton.c | 32 ----- level_3/firewall/c/firewall.h | 2 + level_3/firewall/c/private-firewall.c | 44 +++---- .../fss_basic_list_read/c/fss_basic_list_read.h | 2 + .../fss_basic_list_write/c/fss_basic_list_write.h | 2 + level_3/fss_basic_read/c/fss_basic_read.h | 2 + level_3/fss_basic_write/c/fss_basic_write.h | 2 + .../c/fss_embedded_list_read.h | 2 + .../c/fss_embedded_list_write.h | 2 + .../c/fss_extended_list_read.h | 2 + .../c/fss_extended_list_write.h | 2 + level_3/fss_extended_read/c/fss_extended_read.c | 22 +++- level_3/fss_extended_read/c/fss_extended_read.h | 2 + .../c/private-fss_extended_read.c | 17 ++- level_3/fss_extended_write/c/fss_extended_write.c | 23 ++-- level_3/fss_extended_write/c/fss_extended_write.h | 2 + .../c/private-fss_extended_write.c | 10 +- level_3/fss_identify/c/fss_identify.c | 11 +- level_3/fss_identify/c/fss_identify.h | 2 + level_3/fss_identify/c/private-fss_identify.c | 11 +- level_3/fss_status_code/c/fss_status_code.c | 36 ++++-- level_3/fss_status_code/c/fss_status_code.h | 2 + level_3/iki_read/c/iki_read.c | 12 +- level_3/iki_read/c/iki_read.h | 2 + level_3/iki_read/c/private-iki_read.c | 12 +- level_3/iki_write/c/iki_write.c | 22 +++- level_3/iki_write/c/iki_write.h | 2 + level_3/status_code/c/status_code.c | 36 ++++-- level_3/status_code/c/status_code.h | 2 + level_3/utf8/c/private-utf8.c | 20 ++- level_3/utf8/c/private-utf8_binary.c | 18 +-- level_3/utf8/c/private-utf8_codepoint.c | 18 +-- level_3/utf8/c/utf8.c | 24 ++-- level_3/utf8/c/utf8.h | 2 + 41 files changed, 316 insertions(+), 296 deletions(-) diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index 0e43e6f..a22b372 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -95,6 +95,8 @@ extern "C" { #define byte_dump_option_wide_d 0x1 + #define byte_dump_signal_check_d 10000 + #define byte_dump_sequence_acknowledge_s "␆" #define byte_dump_sequence_acknowledge_negative_s "␕" #define byte_dump_sequence_backspace_s "␈" diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index e31e906..955b25a 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -57,10 +57,14 @@ extern "C" { memset(&invalid, 0, sizeof(char) * main->width); if (byte_get >= 0) { - for (;;) { + for (uint16_t signal_check = 0; ; ) { - if (byte_dump_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++signal_check) % byte_dump_signal_check_d)) { + if (byte_dump_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + signal_check = 0; } byte_get = getc(file.stream); diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index e4cb8ae..a38749a 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -336,7 +336,7 @@ extern "C" { if (status == F_child) { break; } - else if (F_status_set_fine(status) == F_interrupt || fake_signal_received(main)) { + else if (F_status_set_fine(status) == F_interrupt || !(i % fake_signal_check_short_d) && fake_signal_received(main)) { status = F_status_set_error(F_interrupt); break; } diff --git a/level_3/fake/c/fake.h b/level_3/fake/c/fake.h index ccca3e9..0b2d1a5 100644 --- a/level_3/fake/c/fake.h +++ b/level_3/fake/c/fake.h @@ -240,6 +240,10 @@ extern "C" { fake_operation_skeleton, }; + #define fake_signal_check_d 10000 + #define fake_signal_check_tiny_d 4 + #define fake_signal_check_short_d 16 + #define fake_operations_total_d 4 #define fake_operations_initialize { 0, 0, 0, 0 } @@ -396,6 +400,7 @@ extern "C" { f_signal_t signal; uint8_t operation; + uint16_t signal_check; mode_t umask; int child; @@ -468,6 +473,7 @@ extern "C" { 0, \ 0, \ 0, \ + 0, \ f_string_dynamics_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamics_t_initialize, \ diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index d1b22e0..48cd201 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -328,6 +328,11 @@ extern "C" { for (f_array_length_t i = 0; i < files.used; ++i) { + if (!(i % fake_signal_check_short_d) && fake_signal_received(main)) { + *status = F_status_set_error(F_interrupt); + break; + } + if (!files.array[i].used) continue; path_source.used = source.used; @@ -346,11 +351,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_directory_is(path_source.string); if (*status == F_true) { @@ -461,11 +461,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_file_copy(path_source.string, destination_file.string, mode, F_file_default_read_size_d, F_false); if (F_status_is_error(*status)) { @@ -550,12 +545,6 @@ extern "C" { if (!directorys[i]->used) continue; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return; - } - // @todo implement this in a common function and use across project for creating parent directories. for (f_array_length_t j = 0; j < directorys[i]->used; ++j) { @@ -788,48 +777,40 @@ extern "C" { int return_code = 0; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - macro_f_string_dynamic_t_delete_simple(path); - macro_f_string_dynamics_t_delete_simple(arguments); - } - else { - // child processes should receive all signals, without blocking. - f_signal_how_t signals = f_signal_how_t_initialize; - f_signal_set_empty(&signals.block); - f_signal_set_fill(&signals.block_not); + // Child processes should receive all signals, without blocking. + f_signal_how_t signals = f_signal_how_t_initialize; + f_signal_set_empty(&signals.block); + f_signal_set_fill(&signals.block_not); - fl_execute_parameter_t parameter = macro_fl_execute_parameter_t_initialize(FL_execute_parameter_option_path_d, 0, &data_build.environment, &signals, 0); + fl_execute_parameter_t parameter = macro_fl_execute_parameter_t_initialize(FL_execute_parameter_option_path_d, 0, &data_build.environment, &signals, 0); - *status = fll_execute_program(path.string, arguments, ¶meter, 0, (void *) &return_code); + *status = fll_execute_program(path.string, arguments, ¶meter, 0, (void *) &return_code); - macro_f_string_dynamics_t_delete_simple(arguments); + macro_f_string_dynamics_t_delete_simple(arguments); - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - } - else if (*status != F_child) { - if (F_status_is_error(*status)) { - if (F_status_set_fine(*status) == F_failure) { - if (main->error.verbosity != f_console_verbosity_quiet) { - flockfile(main->error.to.stream); + if (fake_signal_received(main)) { + *status = F_status_set_error(F_interrupt); + } + else if (*status != F_child) { + if (F_status_is_error(*status)) { + if (F_status_set_fine(*status) == F_failure) { + if (main->error.verbosity != f_console_verbosity_quiet) { + flockfile(main->error.to.stream); - fl_print_format("%c%[%SFailed to execute script: '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); - fl_print_format("%[%Q%]", main->error.to.stream, main->error.notable, path, main->error.notable); - fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); + fl_print_format("%c%[%SFailed to execute script: '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); + fl_print_format("%[%Q%]", main->error.to.stream, main->error.notable, path, main->error.notable); + fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); - funlockfile(main->error.to.stream); - } - } - else { - fll_error_print(main->error, F_status_set_fine(*status), "fll_execute_program", F_true); + funlockfile(main->error.to.stream); } } else { - fake_build_touch(main, file_stage, status); + fll_error_print(main->error, F_status_set_fine(*status), "fll_execute_program", F_true); } } + else { + fake_build_touch(main, file_stage, status); + } } macro_f_string_dynamic_t_delete_simple(path); @@ -1242,12 +1223,6 @@ extern "C" { parameter_file_path[parameter_file_path_length] = 0; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return 0; - } - *status = f_file_link(parameter_file_name_major, parameter_file_path); if (F_status_is_error_not(*status) && main->error.verbosity == f_console_verbosity_verbose) { @@ -1277,12 +1252,6 @@ extern "C" { parameter_file_path[parameter_file_path_length] = 0; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return 0; - } - *status = f_file_link(parameter_file_name_minor, parameter_file_path); if (F_status_is_error_not(*status) && main->error.verbosity == f_console_verbosity_verbose) { @@ -1311,12 +1280,6 @@ extern "C" { parameter_file_path[parameter_file_path_length] = 0; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return 0; - } - *status = f_file_link(parameter_file_name_micro, parameter_file_path); if (F_status_is_error_not(*status) && main->error.verbosity == f_console_verbosity_verbose) { @@ -1345,12 +1308,6 @@ extern "C" { parameter_file_path[parameter_file_path_length] = 0; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return 0; - } - *status = f_file_link(parameter_file_name_nano, parameter_file_path); if (F_status_is_error_not(*status) && main->error.verbosity == f_console_verbosity_verbose) { @@ -1448,11 +1405,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_file_name_directory(sources[i]->array[j].string, sources[i]->array[j].used, &source_path); if (F_status_is_error(*status)) { @@ -1629,10 +1581,7 @@ extern "C" { *status = fake_file_buffer(main, main->file_data_build_settings.string, &buffer); } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - } - else if (F_status_is_error_not(*status)) { + if (F_status_is_error_not(*status)) { f_string_range_t range = macro_f_string_range_t_initialize(buffer.used); f_fss_delimits_t delimits = f_fss_delimits_t_initialize; @@ -2171,7 +2120,7 @@ extern "C" { fll_error_print(main->error, F_status_set_fine(*status), function, F_true); } } - else if (!fake_signal_received(main)) { + else { const f_string_t settings_single_name[] = { fake_build_setting_name_build_compiler_s, fake_build_setting_name_build_indexer_s, @@ -2919,10 +2868,6 @@ extern "C" { *status = F_status_set_error(F_failure); } } - - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - } } #endif // _di_fake_build_load_setting_defaults_ @@ -2933,6 +2878,8 @@ extern "C" { if (fake_signal_received(main)) { *status = F_status_set_error(F_interrupt); + + return; } const f_string_t names[] = { @@ -3127,11 +3074,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_file_name_directory(sources[i]->array[j].string, sources[i]->array[j].used, &destination_path); if (F_status_is_error(*status)) { @@ -3161,11 +3103,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_directory_exists(destination_path.string); if (*status == F_false) { @@ -3675,15 +3612,15 @@ extern "C" { if (F_status_is_error(*status)) return; - f_mode_t mode = f_mode_t_initialize; - - macro_f_mode_t_set_default_umask(mode, main->umask); - if (fake_signal_received(main)) { *status = F_status_set_error(F_interrupt); return; } + f_mode_t mode = f_mode_t_initialize; + + macro_f_mode_t_set_default_umask(mode, main->umask); + *status = f_file_touch(file.string, mode.regular, F_false); if (F_status_is_error(*status)) { diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index d50cdd8..e505fca 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -34,12 +34,6 @@ extern "C" { fflush(main->output.to.stream); } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - - return 0; - } - int return_code = 0; if (program.used) { @@ -960,8 +954,12 @@ extern "C" { fake_main_t *main = (fake_main_t *) state_ptr->custom; - if (fake_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++main->signal_check) % fake_signal_check_d)) { + if (fake_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + main->signal_check = 0; } return F_interrupt_not; @@ -983,8 +981,12 @@ extern "C" { fake_main_t *main = (fake_main_t *) state_ptr->custom; - if (fake_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++main->signal_check) % fake_signal_check_d)) { + if (fake_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + main->signal_check = 0; } return F_interrupt_not; @@ -1033,10 +1035,6 @@ extern "C" { for (uint8_t i = 0; i < 3; ++i) { - if (fake_signal_received(main)) { - return F_status_set_error(F_interrupt); - } - if (parameters_value[i]->used) { memset(&directory_stat, 0, sizeof(struct stat)); diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 478a084..19774b3 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -286,7 +286,7 @@ extern "C" { for (f_array_length_t i = 0; i < list_objects.used; ++i) { - if (fake_signal_received(main)) { + if (!(i % fake_signal_check_short_d) && fake_signal_received(main)) { *status = F_status_set_error(F_interrupt); break; } @@ -653,10 +653,6 @@ extern "C" { } } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - } - if (F_status_is_error_not(*status) && data_make->setting_make.load_build) { f_string_static_t stub = f_string_static_t_initialize; @@ -697,14 +693,8 @@ extern "C" { f_string_map_multis_t define = f_string_map_multis_t_initialize; - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - } - else { - - // load the fakefile "settings" as if they are build "settings". - fake_build_load_setting_process(main, F_false, main->file_data_build_fakefile.string, data_make->buffer, settings.objects, settings.contents, &data_make->setting_build, status); - } + // load the fakefile "settings" as if they are build "settings". + fake_build_load_setting_process(main, F_false, main->file_data_build_fakefile.string, data_make->buffer, settings.objects, settings.contents, &data_make->setting_build, status); if (F_status_is_error_not(*status) && settings.objects.used) { const f_string_t settings_name[] = { @@ -766,11 +756,6 @@ extern "C" { break; } - if (fake_signal_received(main)) { - *status = F_status_set_error(F_interrupt); - break; - } - *status = f_environment_set(define.array[i].name.string, combined.string, F_true); if (F_status_is_error(*status)) { @@ -1129,12 +1114,6 @@ extern "C" { return status; } - if (fake_signal_received(main)) { - macro_fake_make_data_t_delete_simple(data_make); - - return F_status_set_error(F_interrupt); - } - status = f_path_current(F_true, &data_make.path.stack.array[0]); if (F_status_is_error(status)) { @@ -2183,7 +2162,7 @@ extern "C" { operation = 0; operation_name = 0; - if (fake_signal_received(main)) { + if (!(i % fake_signal_check_short_d) && fake_signal_received(main)) { *status = F_status_set_error(F_interrupt); break; } diff --git a/level_3/fake/c/private-skeleton.c b/level_3/fake/c/private-skeleton.c index 1a05d66..bddc0ff 100644 --- a/level_3/fake/c/private-skeleton.c +++ b/level_3/fake/c/private-skeleton.c @@ -45,10 +45,6 @@ extern "C" { for (uint8_t i = 0; i < 20; ++i) { - if (fake_signal_received(main)) { - return F_status_set_error(F_interrupt); - } - status = fake_skeleton_operate_directory_create(main, *parameters_value[i]); if (F_status_is_error(status)) { @@ -64,10 +60,6 @@ extern "C" { f_string_dynamic_t content = f_string_dynamic_t_initialize; if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - content.string = fake_make_skeleton_content_defines_s; content.used = fake_make_skeleton_content_defines_s_length; content.size = content.used; @@ -78,10 +70,6 @@ extern "C" { } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - content.string = fake_make_skeleton_content_dependencies_s; content.used = fake_make_skeleton_content_dependencies_s_length; content.size = content.used; @@ -92,26 +80,14 @@ extern "C" { } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - status = fake_skeleton_operate_file_create(main, file_data_build_process_post, F_true, content); } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - status = fake_skeleton_operate_file_create(main, file_data_build_process_pre, F_true, content); } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - content.string = fake_make_skeleton_content_settings_s; content.used = fake_make_skeleton_content_settings_s_length; content.size = content.used; @@ -122,18 +98,10 @@ extern "C" { } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - status = fake_skeleton_operate_file_create(main, main->file_documents_readme, F_false, content); } if (F_status_is_error_not(status)) { - if (fake_signal_received(main)) { - status = F_status_set_error(F_interrupt); - } - content.string = fake_make_skeleton_content_fakefile_s; content.used = fake_make_skeleton_content_fakefile_s_length; content.size = content.used; diff --git a/level_3/firewall/c/firewall.h b/level_3/firewall/c/firewall.h index 4e9a0f2..0d6eaa4 100644 --- a/level_3/firewall/c/firewall.h +++ b/level_3/firewall/c/firewall.h @@ -93,6 +93,8 @@ extern "C" { #endif // _di_firewall_default_allocation_step_ #ifndef _di_firewall_defines_ + #define firewall_signal_check_d 10000 + #define firewall_tool_s "tool" #define firewall_tool_iptables_s "iptables" #define firewall_tool_ip6tables_s "ip6tables" diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 7f94ce6..49f0a44 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -61,18 +61,20 @@ f_status_t firewall_perform_commands(firewall_main_t * const main, const firewal chain = firewall_chain_custom_id; } - for (; i < local.rule_objects.used; ++i) { + for (uint16_t signal_check = 0; i < local.rule_objects.used; ++i) { - status = firewall_signal_received(main); + if (!((++signal_check) % firewall_signal_check_d)) { + if (firewall_signal_received(main)) { + macro_f_string_dynamic_t_delete_simple(ip_list); + macro_f_string_dynamic_t_delete_simple(argument); + macro_f_string_dynamics_t_delete_simple(arguments); + macro_f_string_dynamic_t_delete_simple(device); + macro_f_string_dynamic_t_delete_simple(protocol); - if (status) { - macro_f_string_dynamic_t_delete_simple(ip_list); - macro_f_string_dynamic_t_delete_simple(argument); - macro_f_string_dynamics_t_delete_simple(arguments); - macro_f_string_dynamic_t_delete_simple(device); - macro_f_string_dynamic_t_delete_simple(protocol); + return F_status_set_error(F_interrupt); + } - return F_status_set_error(F_interrupt); + signal_check = 0; } length = macro_firewall_structure_size(local.rule_objects, i); @@ -336,18 +338,6 @@ f_status_t firewall_perform_commands(firewall_main_t * const main, const firewal for (r = repeat; r > 0; --r) { - status = firewall_signal_received(main); - - if (status) { - macro_f_string_dynamic_t_delete_simple(ip_list); - macro_f_string_dynamic_t_delete_simple(argument); - macro_f_string_dynamics_t_delete_simple(arguments); - macro_f_string_dynamic_t_delete_simple(device); - macro_f_string_dynamic_t_delete_simple(protocol); - - return F_status_set_error(F_interrupt); - } - // first add the program name f_string_dynamics_resize(0, &arguments); @@ -939,17 +929,17 @@ f_status_t firewall_create_custom_chains(firewall_main_t * const main, firewall_ reserved->has_stop = F_false; reserved->has_main = F_false; - while (i < local->chain_objects.used) { + for (uint16_t signal_check = 0; i < local->chain_objects.used; ) { new_chain = F_true; j = 0; - status = firewall_signal_received(main); - - if (status) { - macro_f_string_dynamics_t_delete_simple(arguments); + if (!((++signal_check) % firewall_signal_check_d)) { + if (firewall_signal_received(main)) { + macro_f_string_dynamics_t_delete_simple(arguments); - return F_status_set_error(F_interrupt); + return F_status_set_error(F_interrupt); + } } // skip globally reserved chain name: main diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.h b/level_3/fss_basic_list_read/c/fss_basic_list_read.h index bc18a6b..b6085b0 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.h @@ -73,6 +73,8 @@ extern "C" { #endif // _di_fss_basic_list_read_program_name_ #ifndef _di_fss_basic_list_read_defines_ + #define fss_basic_list_read_signal_check_d 10000 + #define fss_basic_list_pipe_content_end_s '\f' #define fss_basic_list_pipe_content_ignore_s '\v' #define fss_basic_list_pipe_content_start_s '\b' diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.h b/level_3/fss_basic_list_write/c/fss_basic_list_write.h index abd468b..bde9c24 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.h +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.h @@ -67,6 +67,8 @@ extern "C" { #endif // _di_fss_basic_list_write_program_name_ #ifndef _di_fss_basic_list_write_defines_ + #define fss_basic_list_write_signal_check_d 10000 + #define fss_basic_list_write_pipe_content_end_s '\f' #define fss_basic_list_write_pipe_content_ignore_s '\v' #define fss_basic_list_write_pipe_content_start_s '\b' diff --git a/level_3/fss_basic_read/c/fss_basic_read.h b/level_3/fss_basic_read/c/fss_basic_read.h index bdd1817..0177668 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -73,6 +73,8 @@ extern "C" { #endif // _di_fss_basic_read_program_name_ #ifndef _di_fss_basic_read_defines_ + #define fss_basic_read_signal_check_d 10000 + #define fss_basic_read_pipe_content_end_s '\f' #define fss_basic_read_pipe_content_ignore_s '\v' #define fss_basic_read_pipe_content_start_s '\b' diff --git a/level_3/fss_basic_write/c/fss_basic_write.h b/level_3/fss_basic_write/c/fss_basic_write.h index 69781c0..6b3f81b 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.h +++ b/level_3/fss_basic_write/c/fss_basic_write.h @@ -68,6 +68,8 @@ extern "C" { #endif // _di_fss_basic_write_program_name_ #ifndef _di_fss_basic_write_defines_ + #define fss_basic_write_signal_check_d 10000 + #define fss_basic_write_pipe_content_end_s '\f' #define fss_basic_write_pipe_content_ignore_s '\v' #define fss_basic_write_pipe_content_start_s '\b' diff --git a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h index ea252ff..c698046 100644 --- a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h +++ b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.h @@ -73,6 +73,8 @@ extern "C" { #endif // _di_fss_embedded_list_read_program_name_ #ifndef _di_fss_embedded_list_read_defines_ + #define fss_embedded_list_read_signal_check_d 10000 + #define fss_embedded_list_read_pipe_content_end_s '\f' #define fss_embedded_list_read_pipe_content_ignore_s '\v' #define fss_embedded_list_read_pipe_content_start_s '\b' diff --git a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.h b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.h index e9136c0..8dd1015 100644 --- a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.h +++ b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.h @@ -68,6 +68,8 @@ extern "C" { #endif // _di_fss_embedded_list_write_program_name_ #ifndef _di_fss_embedded_list_write_defines_ + #define fss_embedded_list_write_signal_check_d 10000 + #define fss_embedded_list_write_pipe_content_end_s '\f' #define fss_embedded_list_write_pipe_content_ignore_s '\v' #define fss_embedded_list_write_pipe_content_start_s '\b' diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.h b/level_3/fss_extended_list_read/c/fss_extended_list_read.h index 174621e..20503c3 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.h @@ -73,6 +73,8 @@ extern "C" { #endif // _di_fss_extended_list_read_program_name_ #ifndef _di_fss_extended_list_read_defines_ + #define fss_extended_list_read_signal_check_d 10000 + #define fss_extended_list_read_pipe_content_end '\f' #define fss_extended_list_read_pipe_content_ignore '\v' #define fss_extended_list_read_pipe_content_start '\b' diff --git a/level_3/fss_extended_list_write/c/fss_extended_list_write.h b/level_3/fss_extended_list_write/c/fss_extended_list_write.h index df0923b..f6d243d 100644 --- a/level_3/fss_extended_list_write/c/fss_extended_list_write.h +++ b/level_3/fss_extended_list_write/c/fss_extended_list_write.h @@ -68,6 +68,8 @@ extern "C" { #endif // _di_fss_extended_list_write_program_name_ #ifndef _di_fss_extended_list_write_defines_ + #define fss_extended_list_write_signal_check_d 10000 + #define fss_extended_list_write_pipe_content_end_s '\f' #define fss_extended_list_write_pipe_content_ignore_s '\v' #define fss_extended_list_write_pipe_content_start_s '\b' diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index ee14011..d5ccd59 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -346,15 +346,20 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[fss_extended_read_parameter_delimit].result == f_console_result_additional) { f_array_length_t location = 0; f_array_length_t length = 0; + uint16_t signal_check = 0; // Set the value to 0 to allow for detecting mode based on what is provided. data.delimit_mode = 0; for (f_array_length_t i = 0; i < main->parameters[fss_extended_read_parameter_delimit].values.used; ++i) { - if (fss_extended_read_signal_received(main)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % fss_extended_read_signal_check_d)) { + if (fss_extended_read_signal_received(main)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } location = main->parameters[fss_extended_read_parameter_delimit].values.array[i]; @@ -545,12 +550,17 @@ extern "C" { if (F_status_is_error_not(status) && main->remaining.used > 0) { f_file_t file = f_file_t_initialize; f_array_length_t size_file = 0; + uint16_t signal_check = 0; for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (fss_extended_read_signal_received(main)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % fss_extended_read_signal_check_d)) { + if (fss_extended_read_signal_received(main)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } data.files.array[data.files.used].range.start = data.buffer.used; diff --git a/level_3/fss_extended_read/c/fss_extended_read.h b/level_3/fss_extended_read/c/fss_extended_read.h index d29e425..5e24b55 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -73,6 +73,8 @@ extern "C" { #endif // _di_fss_extended_read_program_name_ #ifndef _di_fss_extended_read_defines_ + #define fss_extended_read_signal_check_d 10000 + #define fss_extended_read_pipe_content_end_s '\f' #define fss_extended_read_pipe_content_ignore_s '\v' #define fss_extended_read_pipe_content_start_s '\b' diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.c b/level_3/fss_extended_read/c/private-fss_extended_read.c index a8cce6c..1cca898 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.c +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -86,11 +86,16 @@ extern "C" { f_array_length_t position_depth = 0; f_array_length_t position_at = 0; f_array_length_t position_name = 0; + uint16_t signal_check = 0; for (f_array_length_t i = 0; i < data->depths.used; ++i) { - if (fss_extended_read_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++signal_check) % fss_extended_read_signal_check_d)) { + if (fss_extended_read_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + signal_check = 0; } data->depths.array[i].depth = 0; @@ -175,8 +180,12 @@ extern "C" { for (f_array_length_t j = i + 1; j < data->depths.used; ++j) { - if (fss_extended_read_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++signal_check) % fss_extended_read_signal_check_d)) { + if (fss_extended_read_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + signal_check = 0; } if (data->depths.array[i].depth == data->depths.array[j].depth) { diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index 12f69d5..dbc6a1e 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -446,12 +446,17 @@ extern "C" { if (main->parameters[fss_extended_write_parameter_partial].result == f_console_result_found) { if (main->parameters[fss_extended_write_parameter_object].result == f_console_result_additional) { contents.used = 0; + uint16_t signal_check = 0; for (f_array_length_t i = 0; i < main->parameters[fss_extended_write_parameter_object].values.used; ++i) { - if (fss_extended_write_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_extended_write_signal_check_d)) { + if (fss_extended_write_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } object.string = arguments->argv[main->parameters[fss_extended_write_parameter_object].values.array[i]]; @@ -506,11 +511,15 @@ extern "C" { f_array_length_t object_next = 0; f_array_length_t content_current = 0; - for (; i < main->parameters[fss_extended_write_parameter_object].values.used; ++i) { + for (uint16_t signal_check = 0; i < main->parameters[fss_extended_write_parameter_object].values.used; ++i) { - if (fss_extended_write_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_extended_write_signal_check_d)) { + if (fss_extended_write_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } object_current = main->parameters[fss_extended_write_parameter_object].locations.array[i]; diff --git a/level_3/fss_extended_write/c/fss_extended_write.h b/level_3/fss_extended_write/c/fss_extended_write.h index 20fc35c..3a711fc 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.h +++ b/level_3/fss_extended_write/c/fss_extended_write.h @@ -67,6 +67,8 @@ extern "C" { #endif // _di_fss_extended_write_program_name_ #ifndef _di_fss_extended_write_defines_ + #define fss_extended_write_signal_check_d 10000 + #define fss_extended_write_pipe_content_end_s '\f' #define fss_extended_write_pipe_content_ignore_s '\v' #define fss_extended_write_pipe_content_start_s '\b' diff --git a/level_3/fss_extended_write/c/private-fss_extended_write.c b/level_3/fss_extended_write/c/private-fss_extended_write.c index 85dc7f1..3f990fb 100644 --- a/level_3/fss_extended_write/c/private-fss_extended_write.c +++ b/level_3/fss_extended_write/c/private-fss_extended_write.c @@ -174,10 +174,14 @@ extern "C" { // 0x0 = start new object/content set, 0x1 = processing object, 0x2 = new individual content, 0x3 = processing content, 0x4 = end object/content set. uint8_t state = 0; - for (;;) { + for (uint16_t signal_check = 0; ; ) { - if (fss_extended_write_signal_received(main)) { - return F_status_set_error(F_interrupt); + if (!((++signal_check) % fss_extended_write_signal_check_d)) { + if (fss_extended_write_signal_received(main)) { + return F_status_set_error(F_interrupt); + } + + signal_check = 0; } if (range.start > range.stop) { diff --git a/level_3/fss_identify/c/fss_identify.c b/level_3/fss_identify/c/fss_identify.c index ba43591..3e28097 100644 --- a/level_3/fss_identify/c/fss_identify.c +++ b/level_3/fss_identify/c/fss_identify.c @@ -299,12 +299,17 @@ extern "C" { } if (F_status_is_error_not(status)) { + uint16_t signal_check = 0; for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (fss_identify_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_identify_signal_check_d)) { + if (fss_identify_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } if (main->parameters[fss_identify_parameter_line].result == f_console_result_additional) { diff --git a/level_3/fss_identify/c/fss_identify.h b/level_3/fss_identify/c/fss_identify.h index 6d137f8..7c62085 100644 --- a/level_3/fss_identify/c/fss_identify.h +++ b/level_3/fss_identify/c/fss_identify.h @@ -71,6 +71,8 @@ extern "C" { #endif // _di_fss_identify_program_name_ #ifndef _di_fss_identify_defines_ + #define fss_identify_signal_check_d 10000 + #define fss_identify_short_content_s "c" #define fss_identify_short_line_s "l" #define fss_identify_short_name_s "n" diff --git a/level_3/fss_identify/c/private-fss_identify.c b/level_3/fss_identify/c/private-fss_identify.c index 5e49cd0..9ab8393 100644 --- a/level_3/fss_identify/c/private-fss_identify.c +++ b/level_3/fss_identify/c/private-fss_identify.c @@ -10,6 +10,7 @@ extern "C" { f_status_t fss_identify_load_line(fss_identify_main_t * const main, const f_file_t file, const f_string_t name, f_string_static_t *buffer, f_string_range_t *range) { f_status_t status = F_none; + uint16_t signal_check = 0; buffer->used = 0; @@ -17,9 +18,13 @@ extern "C" { range->stop = 0; do { - if (fss_identify_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_identify_signal_check_d)) { + if (fss_identify_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } if (buffer->used + file.size_read > buffer->size) { diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c index 8f68a42..5f710d6 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -190,13 +190,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (fss_status_code_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_status_code_signal_check_d)) { + if (fss_status_code_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } status2 = fss_status_code_process_check(main, arguments->argv[main->remaining.array[i]]); @@ -215,13 +221,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (fss_status_code_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_status_code_signal_check_d)) { + if (fss_status_code_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } status2 = fss_status_code_process_number(main, arguments->argv[main->remaining.array[i]]); @@ -240,13 +252,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (fss_status_code_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % fss_status_code_signal_check_d)) { + if (fss_status_code_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } status2 = fss_status_code_process_normal(main, arguments->argv[main->remaining.array[i]]); diff --git a/level_3/fss_status_code/c/fss_status_code.h b/level_3/fss_status_code/c/fss_status_code.h index 4d65fa2..9cce55d 100644 --- a/level_3/fss_status_code/c/fss_status_code.h +++ b/level_3/fss_status_code/c/fss_status_code.h @@ -68,6 +68,8 @@ extern "C" { #endif // _di_fss_status_code_program_name_ #ifndef _di_fss_status_code_defines_ + #define fss_status_code_signal_check_d 10000 + #define fss_status_code_short_is_fine_s "f" #define fss_status_code_short_is_warning_s "w" #define fss_status_code_short_is_error_s "e" diff --git a/level_3/iki_read/c/iki_read.c b/level_3/iki_read/c/iki_read.c index 858f5c1..d3f9343 100644 --- a/level_3/iki_read/c/iki_read.c +++ b/level_3/iki_read/c/iki_read.c @@ -437,11 +437,15 @@ extern "C" { f_array_length_t total = 0; f_file_t file = f_file_t_initialize; - for (; i < main->remaining.used; ++i) { + for (uint16_t signal_check = 0; i < main->remaining.used; ++i) { - if (iki_read_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % iki_read_signal_check_d)) { + if (iki_read_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } macro_f_file_t_reset(file); diff --git a/level_3/iki_read/c/iki_read.h b/level_3/iki_read/c/iki_read.h index 6e74308..53c69f2 100644 --- a/level_3/iki_read/c/iki_read.h +++ b/level_3/iki_read/c/iki_read.h @@ -76,6 +76,8 @@ extern "C" { #endif // _di_iki_read_program_name_ #ifndef _di_iki_read_defines_ + #define iki_read_signal_check_d 10000 + enum { iki_read_mode_content = 1, iki_read_mode_literal, diff --git a/level_3/iki_read/c/private-iki_read.c b/level_3/iki_read/c/private-iki_read.c index ad889f5..276c98a 100644 --- a/level_3/iki_read/c/private-iki_read.c +++ b/level_3/iki_read/c/private-iki_read.c @@ -487,12 +487,16 @@ extern "C" { range.start = 0; - for (; i < main->parameters[iki_read_parameter_name].values.used; ++i) { + for (uint16_t signal_check = 0; i < main->parameters[iki_read_parameter_name].values.used; ++i) { - if (iki_read_signal_received(main)) { - macro_f_string_dynamic_t_delete_simple(name); + if (!((++signal_check) % iki_read_signal_check_d)) { + if (iki_read_signal_received(main)) { + macro_f_string_dynamic_t_delete_simple(name); + + return F_status_set_error(F_interrupt); + } - return F_status_set_error(F_interrupt); + signal_check = 0; } index = main->parameters[iki_read_parameter_name].values.array[i]; diff --git a/level_3/iki_write/c/iki_write.c b/level_3/iki_write/c/iki_write.c index fe3df0b..a906ce0 100644 --- a/level_3/iki_write/c/iki_write.c +++ b/level_3/iki_write/c/iki_write.c @@ -293,14 +293,19 @@ extern "C" { f_array_length_t previous = 0; f_string_range_t range = f_string_range_t_initialize; + uint16_t signal_check = 0; range.start = 0; for (f_status_t status_pipe = F_none; ; ) { - if (iki_write_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % iki_write_signal_check_d)) { + if (iki_write_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } if (status_pipe != F_none_eof) { @@ -413,12 +418,17 @@ extern "C" { if (F_status_is_error_not(status)) { f_string_static_t object = f_string_static_t_initialize; f_string_static_t content = f_string_static_t_initialize; + uint16_t signal_check = 0; for (f_array_length_t i = 0; i < main->parameters[iki_write_parameter_object].values.used; ++i) { - if (iki_write_signal_received(main)) { - status = F_status_set_error(F_interrupt); - break; + if (!((++signal_check) % iki_write_signal_check_d)) { + if (iki_write_signal_received(main)) { + status = F_status_set_error(F_interrupt); + break; + } + + signal_check = 0; } object.string = arguments->argv[main->parameters[iki_write_parameter_object].values.array[i]]; diff --git a/level_3/iki_write/c/iki_write.h b/level_3/iki_write/c/iki_write.h index 6037759..4b7dd65 100644 --- a/level_3/iki_write/c/iki_write.h +++ b/level_3/iki_write/c/iki_write.h @@ -76,6 +76,8 @@ extern "C" { #endif // _di_iki_write_program_name_ #ifndef _di_iki_write_defines_ + #define iki_write_signal_check_d 10000 + #define iki_write_short_file_s "f" #define iki_write_short_content_s "c" #define iki_write_short_double_s "d" diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 577225f..58ba6ad 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -197,13 +197,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (status_code_signal_received(main)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % status_code_signal_check_d)) { + if (status_code_signal_received(main)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } status2 = status_code_process_check(main, arguments->argv[main->remaining.array[i]]); @@ -222,13 +228,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (status_code_signal_received(main)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % status_code_signal_check_d)) { + if (status_code_signal_received(main)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } status2 = status_code_process_number(main, arguments->argv[main->remaining.array[i]]); @@ -247,13 +259,19 @@ extern "C" { } if (main->remaining.used > 0) { + uint16_t signal_check = 0; + flockfile(main->output.to.stream); for (f_array_length_t i = 0; i < main->remaining.used; ++i) { - if (status_code_signal_received(main)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % status_code_signal_check_d)) { + if (status_code_signal_received(main)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } status2 = status_code_process_normal(main, arguments->argv[main->remaining.array[i]]); diff --git a/level_3/status_code/c/status_code.h b/level_3/status_code/c/status_code.h index aebbb85..2c249e5 100644 --- a/level_3/status_code/c/status_code.h +++ b/level_3/status_code/c/status_code.h @@ -67,6 +67,8 @@ extern "C" { #endif // _di_status_code_program_name_ #ifndef _di_status_code_defines_ + #define status_code_signal_check_d 10000 + #define status_code_short_is_fine_s "f" #define status_code_short_is_warning_s "w" #define status_code_short_is_error_s "e" diff --git a/level_3/utf8/c/private-utf8.c b/level_3/utf8/c/private-utf8.c index 088944a..70d99d6 100644 --- a/level_3/utf8/c/private-utf8.c +++ b/level_3/utf8/c/private-utf8.c @@ -36,20 +36,18 @@ extern "C" { flockfile(data->file.stream); - while (*character.string && F_status_is_error_not(status)) { + for (uint16_t signal_check = 0; *character.string && F_status_is_error_not(status); ) { - status = utf8_signal_received(data); + if (!((++signal_check) % utf8_signal_check_d)) { + if (utf8_signal_received(data)) { + utf8_print_signal_received(data, status); - if (status) { - utf8_print_signal_received(data, status); - - status = F_status_set_error(F_signal); - break; - } - else { - status = F_none; + status = F_status_set_error(F_signal); + break; + } } + status = F_none; character.used = macro_f_utf_byte_width(*character.string); // Re-adjust used if buffer ended before the character is supposed to end. @@ -97,7 +95,7 @@ extern "C" { if (status == F_utf) { valid = F_false; } - } // while + } // for if (F_status_is_error_not(status) && !(data->mode & utf8_mode_from_binary_d)) { if (mode_codepoint != utf8_codepoint_mode_ready && mode_codepoint != utf8_codepoint_mode_end && mode_codepoint != utf8_codepoint_mode_bad_end) { diff --git a/level_3/utf8/c/private-utf8_binary.c b/level_3/utf8/c/private-utf8_binary.c index 4c43ebe..fc414ac 100644 --- a/level_3/utf8/c/private-utf8_binary.c +++ b/level_3/utf8/c/private-utf8_binary.c @@ -65,6 +65,7 @@ extern "C" { bool valid = F_true; bool next = F_true; uint8_t mode_codepoint = utf8_codepoint_mode_ready; + uint16_t signal_check = 0; f_array_length_t i = 0; f_array_length_t j = 0; @@ -79,18 +80,17 @@ extern "C" { for (i = 0; F_status_is_fine(status) && i < data->buffer.used; ) { - status = utf8_signal_received(data); + if (!((++signal_check) % utf8_signal_check_d)) { + if (utf8_signal_received(data)) { + utf8_print_signal_received(data, status); - if (status) { - utf8_print_signal_received(data, status); - - status = F_status_set_error(F_signal); - break; - } - else { - status = F_none; + status = F_status_set_error(F_signal); + break; + } } + status = F_none; + // Get the current width only when processing a new block. if (next) { character.used = macro_f_utf_byte_width(data->buffer.string[i]); diff --git a/level_3/utf8/c/private-utf8_codepoint.c b/level_3/utf8/c/private-utf8_codepoint.c index 2af6c7d..6c8bd7c 100644 --- a/level_3/utf8/c/private-utf8_codepoint.c +++ b/level_3/utf8/c/private-utf8_codepoint.c @@ -189,6 +189,7 @@ extern "C" { f_status_t status = F_none; bool valid = F_true; bool next = F_true; + uint16_t signal_check = 0; f_array_length_t i = 0; f_array_length_t j = 0; @@ -203,18 +204,17 @@ extern "C" { for (i = 0; F_status_is_fine(status) && i < data->buffer.used; ) { - status = utf8_signal_received(data); + if (!((++signal_check) % utf8_signal_check_d)) { + if (utf8_signal_received(data)) { + utf8_print_signal_received(data, status); - if (status) { - utf8_print_signal_received(data, status); - - status = F_status_set_error(F_signal); - break; - } - else { - status = F_none; + status = F_status_set_error(F_signal); + break; + } } + status = F_none; + // Get the current width only when processing a new block. if (next) { character.used = macro_f_utf_byte_width(data->buffer.string[i]); diff --git a/level_3/utf8/c/utf8.c b/level_3/utf8/c/utf8.c index c602411..7c521e8 100644 --- a/level_3/utf8/c/utf8.c +++ b/level_3/utf8/c/utf8.c @@ -372,11 +372,15 @@ extern "C" { f_file_t file = macro_f_file_t_initialize(0, -1, F_file_flag_read_only_d, 32768, F_file_default_write_size_d); - for (; i < main->parameters[utf8_parameter_from_file].values.used && status != F_signal; ++i) { + for (uint16_t signal_check = 0; i < main->parameters[utf8_parameter_from_file].values.used && status != F_signal; ++i) { - if (utf8_signal_received(&data)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % utf8_signal_check_d)) { + if (utf8_signal_received(&data)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } index = main->parameters[utf8_parameter_from_file].values.array[i]; @@ -418,11 +422,15 @@ extern "C" { f_array_length_t i = 0; f_array_length_t index = 0; - for (; F_status_is_error_not(status) && i < main->remaining.used; ++i) { + for (uint16_t signal_check = 0; F_status_is_error_not(status) && i < main->remaining.used; ++i) { - if (utf8_signal_received(&data)) { - status = F_status_set_error(F_signal); - break; + if (!((++signal_check) % utf8_signal_check_d)) { + if (utf8_signal_received(&data)) { + status = F_status_set_error(F_signal); + break; + } + + signal_check = 0; } index = main->remaining.array[i]; diff --git a/level_3/utf8/c/utf8.h b/level_3/utf8/c/utf8.h index 7339684..9829038 100644 --- a/level_3/utf8/c/utf8.h +++ b/level_3/utf8/c/utf8.h @@ -87,6 +87,8 @@ extern "C" { #endif // _di_utf8_default_allocation_step_ #ifndef _di_utf8_defines_ + #define utf8_signal_check_d 10000 + #define utf8_string_from_s "from" #define utf8_string_to_s "to" -- 1.8.3.1