From fa1cb89cfa0d25e7a037543c27835a5f17723dd4 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 10 Aug 2022 23:06:20 -0500 Subject: [PATCH] Progress: Begin breaking out internal parameters to allow for better caller control in programs. Starting with utf8, start the process of breaking out the parameter settings into a variable that the caller can customize. This should improve extensibility such that the caller can provide their own initializers. Other incidental changes are made. --- level_3/byte_dump/c/byte_dump.c | 3 +- level_3/byte_dump/c/main.c | 4 +- level_3/control/c/main.c | 4 +- level_3/control/c/private-control.c | 3 +- .../controller/c/controller/private-controller.c | 21 +- level_3/controller/c/main.c | 4 +- level_3/fake/c/main.c | 4 +- level_3/fake/c/private-fake.c | 3 +- level_3/fake/c/private-make-operate.c | 5 +- level_3/fake/c/private-make-operate_process_type.c | 8 +- level_3/fake/c/private-skeleton.c | 6 +- level_3/firewall/c/main.c | 4 +- level_3/firewall/c/private-firewall.c | 9 +- .../fss_basic_list_read/c/fss_basic_list_read.c | 12 +- level_3/fss_basic_list_read/c/main.c | 4 +- .../fss_basic_list_write/c/fss_basic_list_write.c | 5 +- level_3/fss_basic_list_write/c/main.c | 4 +- level_3/fss_basic_read/c/fss_basic_read.c | 9 +- level_3/fss_basic_read/c/main.c | 4 +- level_3/fss_basic_write/c/fss_basic_write.c | 5 +- level_3/fss_basic_write/c/main.c | 4 +- .../c/fss_embedded_list_read.c | 12 +- level_3/fss_embedded_list_read/c/main.c | 4 +- .../c/fss_embedded_list_write.c | 5 +- level_3/fss_embedded_list_write/c/main.c | 4 +- .../c/fss_extended_list_read.c | 9 +- level_3/fss_extended_list_read/c/main.c | 4 +- .../c/fss_extended_list_write.c | 5 +- level_3/fss_extended_list_write/c/main.c | 4 +- level_3/fss_extended_read/c/fss_extended_read.c | 9 +- level_3/fss_extended_read/c/main.c | 4 +- level_3/fss_extended_write/c/fss_extended_write.c | 5 +- level_3/fss_extended_write/c/main.c | 4 +- level_3/fss_identify/c/fss_identify.c | 3 +- level_3/fss_identify/c/main.c | 4 +- level_3/fss_payload_read/c/fss_payload_read.c | 9 +- level_3/fss_payload_read/c/main.c | 4 +- level_3/fss_payload_write/c/fss_payload_write.c | 5 +- level_3/fss_payload_write/c/main.c | 4 +- level_3/fss_status_code/c/main.c | 4 +- level_3/iki_read/c/iki_read.c | 12 +- level_3/iki_read/c/main.c | 4 +- level_3/iki_write/c/iki_write.c | 5 +- level_3/iki_write/c/main.c | 4 +- level_3/status_code/c/main.c | 4 +- level_3/utf8/c/common.h | 72 +++- level_3/utf8/c/main.c | 27 +- level_3/utf8/c/private-common.c | 4 - level_3/utf8/c/private-common.h | 14 +- level_3/utf8/c/private-utf8_bytesequence.c | 8 +- level_3/utf8/c/private-utf8_codepoint.c | 4 +- level_3/utf8/c/utf8.c | 423 ++++++++++----------- level_3/utf8/c/utf8.h | 57 ++- 53 files changed, 485 insertions(+), 380 deletions(-) diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index d67a8d5..427bc34 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -498,7 +498,8 @@ extern "C" { status = byte_dump_file(&data, data.argv[main->parameters.remaining.array[counter]], file); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_interrupt) { diff --git a/level_3/byte_dump/c/main.c b/level_3/byte_dump/c/main.c index 62c3db4..586e425 100644 --- a/level_3/byte_dump/c/main.c +++ b/level_3/byte_dump/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = byte_dump_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/control/c/main.c b/level_3/control/c/main.c index c475e01..fa54ef2 100644 --- a/level_3/control/c/main.c +++ b/level_3/control/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = control_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/control/c/private-control.c b/level_3/control/c/private-control.c index ce8f28e..87ceae8 100644 --- a/level_3/control/c/private-control.c +++ b/level_3/control/c/private-control.c @@ -642,7 +642,8 @@ extern "C" { status = f_file_stream_read(file, &data->cache.large); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_read", F_true, data->cache.small, f_file_operation_read_s, fll_error_file_type_file_e); diff --git a/level_3/controller/c/controller/private-controller.c b/level_3/controller/c/controller/private-controller.c index d9d8857..e739ddd 100644 --- a/level_3/controller/c/controller/private-controller.c +++ b/level_3/controller/c/controller/private-controller.c @@ -94,7 +94,8 @@ extern "C" { if (F_status_is_error(status)) { if (!required && F_status_set_fine(status) == F_file_found_not) { - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); return F_file_found_not; } @@ -113,7 +114,8 @@ extern "C" { } } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error_not(status)) { struct stat stat_file; @@ -175,7 +177,8 @@ extern "C" { fll_print_format("%i%r", file.stream, pid, f_string_eol_s); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) return status; @@ -202,7 +205,11 @@ extern "C" { status = f_file_stream_read(pid_file, &pid_buffer); if (F_status_is_error_not(status)) { - status = f_file_stream_close(F_true, &pid_file); + status = f_file_stream_flush(&pid_file); + } + + if (F_status_is_error_not(status)) { + status = f_file_stream_close(&pid_file); } if (F_status_is_error_not(status)) { @@ -255,7 +262,11 @@ extern "C" { status = f_file_stream_read(pid_file, &pid_buffer); if (F_status_is_error_not(status)) { - status = f_file_stream_close(F_true, &pid_file); + status = f_file_stream_flush(&pid_file); + } + + if (F_status_is_error_not(status)) { + status = f_file_stream_close(&pid_file); } if (F_status_is_error_not(status)) { diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c index b4b8570..2de5fd9 100644 --- a/level_3/controller/c/main.c +++ b/level_3/controller/c/main.c @@ -16,7 +16,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.pid = getpid(); - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); f_file_umask_get(&data.umask); @@ -45,7 +45,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { controller_main_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); // When the child process exits, it must return the code to the parent so the parent knows how to handle the exit. if (status == F_child) { diff --git a/level_3/fake/c/main.c b/level_3/fake/c/main.c index dff0537..1b4ad4f 100644 --- a/level_3/fake/c/main.c +++ b/level_3/fake/c/main.c @@ -27,7 +27,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); f_file_umask_get(&data.umask); @@ -35,7 +35,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (status == F_child) { exit(data.child); diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 55fcb53..e2f10c1 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -131,7 +131,8 @@ extern "C" { name_function = "f_file_read"; status = f_file_read(file, buffer); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } } else if (status == F_false) { diff --git a/level_3/fake/c/private-make-operate.c b/level_3/fake/c/private-make-operate.c index 07b847b..f1ac0c4 100644 --- a/level_3/fake/c/private-make-operate.c +++ b/level_3/fake/c/private-make-operate.c @@ -115,7 +115,7 @@ extern "C" { data_make.error.context = data->main->context.set.warning; data_make.error.notable = data->main->context.set.notable; data_make.error.to.stream = F_type_warning_d; - data_make.error.to.id = F_type_descriptor_warning_d; + data_make.error.to.id = F_type_descriptor_output_d; data_make.error.set = &data->main->context.set; } else { @@ -152,7 +152,8 @@ extern "C" { } } - f_file_stream_close(F_true, &data_make.path.top); + f_file_stream_flush(&data_make.path.top); + f_file_stream_close(&data_make.path.top); f_array_lengths_resize(0, §ion_stack); fake_make_data_delete(&data_make); diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index 71b3b6d..a2a60d8 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -509,7 +509,7 @@ extern "C" { data_make->error.context = data_make->main->context.set.warning; data_make->error.notable = data_make->main->context.set.notable; data_make->error.to.stream = F_type_warning_d; - data_make->error.to.id = F_type_descriptor_warning_d; + data_make->error.to.id = F_type_descriptor_output_d; data_make->error.set = &data_make->main->context.set; } else { @@ -1964,7 +1964,8 @@ extern "C" { else { status = F_none; - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } } @@ -2025,7 +2026,8 @@ extern "C" { } // for } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } if (F_status_is_error(status)) return F_status_set_error(F_failure); diff --git a/level_3/fake/c/private-skeleton.c b/level_3/fake/c/private-skeleton.c index 9b2844a..edd32a7 100644 --- a/level_3/fake/c/private-skeleton.c +++ b/level_3/fake/c/private-skeleton.c @@ -274,7 +274,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(data->main->error, F_status_set_fine(status), "f_file_write", F_true, path, fake_common_file_populate_pre_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); return status; } @@ -283,7 +284,8 @@ extern "C" { fll_print_format("File '%Q' pre-populated.%r", data->main->output.to.stream, path, f_string_eol_s); } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } } else if (F_status_is_error(status)) { diff --git a/level_3/firewall/c/main.c b/level_3/firewall/c/main.c index 92b05d5..cb52c88 100644 --- a/level_3/firewall/c/main.c +++ b/level_3/firewall/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = firewall_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (status == F_child) { exit(data.child); diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index e9450ce..c52005f 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -578,12 +578,14 @@ f_status_t firewall_perform_commands(firewall_data_t * const data, firewall_loca firewall_print_error_on_unhandled(data->main->error, "f_file_open", F_status_set_fine(status)); } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } else { status = f_file_read(file, &local_buffer); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (data->main->error.verbosity != f_console_verbosity_quiet_e) { @@ -1158,7 +1160,8 @@ f_status_t firewall_buffer_rules(firewall_data_t * const data, const f_string_st status = f_file_read(file, &local->buffer); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (data->main->error.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index cb11510..edd2188 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -564,7 +564,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -590,7 +591,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_increase_by", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -610,7 +612,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { @@ -638,7 +641,8 @@ extern "C" { } } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); } if (F_status_is_error_not(status)) { diff --git a/level_3/fss_basic_list_read/c/main.c b/level_3/fss_basic_list_read/c/main.c index 3a68d31..0ded01b 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_basic_list_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index 71b29bb..6a91c6f 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -514,9 +514,8 @@ extern "C" { } if (main->parameters.array[fss_basic_list_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_basic_list_write/c/main.c b/level_3/fss_basic_list_write/c/main.c index 52566fe..5135c63 100644 --- a/level_3/fss_basic_list_write/c/main.c +++ b/level_3/fss_basic_list_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_basic_list_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 23cbb19..7bbce28 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -571,7 +571,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -597,7 +598,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -617,7 +619,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index 2703e70..cdddcca 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_basic_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index b1d95be..5f05c50 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -505,9 +505,8 @@ extern "C" { } if (main->parameters.array[fss_basic_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_basic_write/c/main.c b/level_3/fss_basic_write/c/main.c index 9a91620..059d3fa 100644 --- a/level_3/fss_basic_write/c/main.c +++ b/level_3/fss_basic_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_basic_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c index a416fce..2762431 100644 --- a/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c +++ b/level_3/fss_embedded_list_read/c/fss_embedded_list_read.c @@ -457,7 +457,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -468,7 +469,8 @@ extern "C" { fll_print_format("%r%r", main->output.to.stream, f_string_ascii_0_s, f_string_eol_s); } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); continue; } @@ -492,7 +494,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -512,7 +515,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/fss_embedded_list_read/c/main.c b/level_3/fss_embedded_list_read/c/main.c index 9ae2ea4..66a29c5 100644 --- a/level_3/fss_embedded_list_read/c/main.c +++ b/level_3/fss_embedded_list_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_embedded_list_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c index 0ecb591..67d5f89 100644 --- a/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c +++ b/level_3/fss_embedded_list_write/c/fss_embedded_list_write.c @@ -520,9 +520,8 @@ extern "C" { } if (main->parameters.array[fss_embedded_list_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_embedded_list_write/c/main.c b/level_3/fss_embedded_list_write/c/main.c index fa25afc..257b8a2 100644 --- a/level_3/fss_embedded_list_write/c/main.c +++ b/level_3/fss_embedded_list_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_embedded_list_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index 2247565..aa23486 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -571,7 +571,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -597,7 +598,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -617,7 +619,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/fss_extended_list_read/c/main.c b/level_3/fss_extended_list_read/c/main.c index 2a6234b..fa5f77e 100644 --- a/level_3/fss_extended_list_read/c/main.c +++ b/level_3/fss_extended_list_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_extended_list_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_extended_list_write/c/fss_extended_list_write.c b/level_3/fss_extended_list_write/c/fss_extended_list_write.c index fd90cdf..4606275 100644 --- a/level_3/fss_extended_list_write/c/fss_extended_list_write.c +++ b/level_3/fss_extended_list_write/c/fss_extended_list_write.c @@ -519,9 +519,8 @@ extern "C" { } if (main->parameters.array[fss_extended_list_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_extended_list_write/c/main.c b/level_3/fss_extended_list_write/c/main.c index 3a959ab..4628094 100644 --- a/level_3/fss_extended_list_write/c/main.c +++ b/level_3/fss_extended_list_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_extended_list_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; 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 a6773c9..27d029a 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -570,7 +570,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -596,7 +597,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -616,7 +618,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index 93a1894..ca65430 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_extended_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; 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 f999582..12f2f30 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -574,9 +574,8 @@ extern "C" { } if (main->parameters.array[fss_extended_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_extended_write/c/main.c b/level_3/fss_extended_write/c/main.c index 952c449..cd8acc4 100644 --- a/level_3/fss_extended_write/c/main.c +++ b/level_3/fss_extended_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_extended_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_identify/c/fss_identify.c b/level_3/fss_identify/c/fss_identify.c index 162c02a..f2b1d29 100644 --- a/level_3/fss_identify/c/fss_identify.c +++ b/level_3/fss_identify/c/fss_identify.c @@ -319,7 +319,8 @@ extern "C" { } } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) break; } // for diff --git a/level_3/fss_identify/c/main.c b/level_3/fss_identify/c/main.c index d2b2197..a8274e2 100644 --- a/level_3/fss_identify/c/main.c +++ b/level_3/fss_identify/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_identify_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_payload_read/c/fss_payload_read.c b/level_3/fss_payload_read/c/fss_payload_read.c index c0ffa4d..c2a9e21 100644 --- a/level_3/fss_payload_read/c/fss_payload_read.c +++ b/level_3/fss_payload_read/c/fss_payload_read.c @@ -602,7 +602,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_read_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -628,7 +629,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -648,7 +650,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/fss_payload_read/c/main.c b/level_3/fss_payload_read/c/main.c index fe6246c..b908e0e 100644 --- a/level_3/fss_payload_read/c/main.c +++ b/level_3/fss_payload_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_payload_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_payload_write/c/fss_payload_write.c b/level_3/fss_payload_write/c/fss_payload_write.c index 04701d9..1534628 100644 --- a/level_3/fss_payload_write/c/fss_payload_write.c +++ b/level_3/fss_payload_write/c/fss_payload_write.c @@ -518,9 +518,8 @@ extern "C" { } if (main->parameters.array[fss_payload_write_parameter_file_e].result == f_console_result_additional_e) { - if (output.id != -1) { - f_file_stream_close(F_true, &output); - } + f_file_stream_flush(&output); + f_file_stream_close(&output); } // Ensure a newline is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/fss_payload_write/c/main.c b/level_3/fss_payload_write/c/main.c index cbb903c..56c7ca2 100644 --- a/level_3/fss_payload_write/c/main.c +++ b/level_3/fss_payload_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_payload_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c index 4014fa9..387dd27 100644 --- a/level_3/fss_status_code/c/main.c +++ b/level_3/fss_status_code/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = fss_status_code_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status) || status == F_false) return 1; diff --git a/level_3/iki_read/c/iki_read.c b/level_3/iki_read/c/iki_read.c index 3da7f43..ad8981c 100644 --- a/level_3/iki_read/c/iki_read.c +++ b/level_3/iki_read/c/iki_read.c @@ -464,14 +464,16 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_file_size_by_id", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } // Skip past empty files. if (!size_file) { - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); continue; } @@ -492,7 +494,8 @@ extern "C" { if (F_status_is_error(status)) { fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, data.argv[main->parameters.remaining.array[i]], f_file_operation_process_s, fll_error_file_type_file_e); - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); break; } @@ -512,7 +515,8 @@ extern "C" { if (F_status_is_error(status)) break; } // for - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_interrupt) { diff --git a/level_3/iki_read/c/main.c b/level_3/iki_read/c/main.c index 9ed1acf..edff724 100644 --- a/level_3/iki_read/c/main.c +++ b/level_3/iki_read/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = iki_read_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/iki_write/c/iki_write.c b/level_3/iki_write/c/iki_write.c index 24de7bf..e50f74d 100644 --- a/level_3/iki_write/c/iki_write.c +++ b/level_3/iki_write/c/iki_write.c @@ -455,9 +455,8 @@ extern "C" { } if (main->parameters.array[iki_write_parameter_file_e].result == f_console_result_additional_e) { - if (file.id != -1) { - f_file_stream_close(F_true, &file); - } + f_file_stream_flush(&file); + f_file_stream_close(&file); } // Ensure a new line is always put at the end of the program execution, unless in quiet mode. diff --git a/level_3/iki_write/c/main.c b/level_3/iki_write/c/main.c index b35e86c..4b140dc 100644 --- a/level_3/iki_write/c/main.c +++ b/level_3/iki_write/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = iki_write_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index 6fd7860..9326cb7 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -13,13 +13,13 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.process_pipe = F_true; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); const f_status_t status = status_code_main(&data, &arguments); fll_program_data_delete(&data); - fll_program_standard_setdown(&data.signal); + fll_program_standard_set_down(&data.signal); if (F_status_is_error(status)) return 1; diff --git a/level_3/utf8/c/common.h b/level_3/utf8/c/common.h index 5541281..c7672dc 100644 --- a/level_3/utf8/c/common.h +++ b/level_3/utf8/c/common.h @@ -298,24 +298,76 @@ extern "C" { /** * Modes used to designate how to the input and output are to be processed. * - * utf8_mode_from_*: + * utf8_mode_*_e: + * - none: No modes in use. + * + * utf8_mode_from_*_e: * - bytesequence: The input format is bytesequence. * - codepoint: The input format is codepoint (U+XXXX or U+XXXXXX). * - * utf8_mode_to_*: + * utf8_mode_to_*_e: * - bytesequence: The outout format is bytesequence. * - codepoint: The outout format is codepoint (U+XXXX or U+XXXXXX). * - combining: The outout format is whether or not character is combining (may be used with "width"). * - width: The outout format is how wide the character is (may be used with "combining"). */ -#ifndef _di_utf8_modes_ - #define utf8_mode_from_bytesequence_d 0x1 - #define utf8_mode_from_codepoint_d 0x2 - #define utf8_mode_to_bytesequence_d 0x4 - #define utf8_mode_to_codepoint_d 0x8 - #define utf8_mode_to_combining_d 0x10 - #define utf8_mode_to_width_d 0x20 -#endif // _di_utf8_modes_ +#ifndef _di_utf8_modes_e_ + enum { + utf8_mode_none_e = 0x0, + utf8_mode_from_bytesequence_e = 0x1, + utf8_mode_from_codepoint_d = 0x2, + utf8_mode_to_bytesequence_d = 0x4, + utf8_mode_to_codepoint_d = 0x8, + utf8_mode_to_combining_d = 0x10, + utf8_mode_to_width_d = 0x20, + }; +#endif // _di_utf8_modes_e_ + +/** + * The UTF-8 main program settings. + * + * This is passed to the program-specific main entry point to designate program settings. + * These program settings are often processed from the program arguments (often called the command line arguments). + * + * mode: The input/output mode (see utf8_modes_e). + */ +#ifndef _di_utf8_main_setting_t_ + typedef struct { + uint8_t mode; + } utf8_main_setting_t; + + #define utf8_main_setting_t_initialize \ + { \ + utf8_mode_from_bytesequence_d | utf8_mode_to_codepoint_d, \ + } +#endif // _di_utf8_main_setting_t_ + +/* + f_color_set_t valid; + f_color_set_t valid_not; + + f_string_static_t append; + f_string_static_t prepend; + + f_string_dynamic_t buffer; + f_string_dynamic_t text; + } utf8_data_t; + + #define utf8_data_t_initialize \ + { \ + 0, \ + 0, \ + 0, \ + f_file_t_initialize, \ + utf8_mode_from_bytesequence_d | utf8_mode_to_codepoint_d, \ + f_color_set_t_initialize, \ + f_color_set_t_initialize, \ + f_string_static_t_initialize, \ + f_string_static_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + } + */ #ifdef __cplusplus } // extern "C" diff --git a/level_3/utf8/c/main.c b/level_3/utf8/c/main.c index 0dc25a5..2f51d63 100644 --- a/level_3/utf8/c/main.c +++ b/level_3/utf8/c/main.c @@ -3,25 +3,38 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); + fll_program_data_t data = fll_program_data_t_initialize; + utf8_main_setting_t setting = utf8_main_setting_t_initialize; f_console_parameter_t parameters[] = utf8_console_parameter_t_initialize; data.parameters.array = parameters; data.parameters.used = utf8_total_parameters_d; if (f_pipe_input_exists()) { - data.process_pipe = F_true; + data.pipe |= fll_program_data_pipe_input_e; } - fll_program_standard_setup(&data.signal); + fll_program_standard_set_up(&data.signal); - const f_status_t status = utf8_main(&data, &arguments); + f_status_t status = utf8_main_setting_load(arguments, data, &setting); - fll_program_data_delete(&data); + if (F_status_is_error_not(status)) { + status = utf8_main(&data, &setting); + } + + if (data.message.stream != data.output.stream) { + f_file_stream_flush(&data->output); + f_file_stream_close(&data->output); + } + + utf8_main_setting_unload(data, &setting); - fll_program_standard_setdown(&data.signal); + utf8_main_setting_delete(&setting); + + fll_program_data_delete(&data); - if (F_status_is_error(status)) return 1; + fll_program_standard_set_down(&data.signal); - return 0; + return F_status_is_error(status) ? 1 : 0; } diff --git a/level_3/utf8/c/private-common.c b/level_3/utf8/c/private-common.c index e8bbe72..f6bc326 100644 --- a/level_3/utf8/c/private-common.c +++ b/level_3/utf8/c/private-common.c @@ -9,10 +9,6 @@ extern "C" { #ifndef _di_utf8_data_delete_ void utf8_data_delete(utf8_data_t *data) { - if (data->file.stream != data->main->output.to.stream) { - f_file_stream_close(F_true, &data->file); - } - f_string_dynamic_resize(0, &data->buffer); f_string_dynamic_resize(0, &data->text); } diff --git a/level_3/utf8/c/private-common.h b/level_3/utf8/c/private-common.h index ebf495f..40fc9cb 100644 --- a/level_3/utf8/c/private-common.h +++ b/level_3/utf8/c/private-common.h @@ -48,10 +48,12 @@ extern "C" { /** * The program data. * - * argv: The argument structure in the progam data parameters for simplifying syntax. + * main: The main program data. + * setting: The main program settings. + * argv: The argument structure in the progam data parameters for simplifying syntax. + * * main: The main program data. * file: The output file for writing the processed data to (may potentially default to "output"). - * mode: The input/output mode (see utf8_modes). * valid: Designate the output context set for valid characters. * valid_not: Designate the output context set for invalid characters. * append: A string to append. A value of NULL results in not appending. @@ -62,10 +64,10 @@ extern "C" { #ifndef _di_utf8_data_t_ typedef struct { fll_program_data_t *main; + utf8_main_setting_t *setting; f_string_static_t *argv; - f_file_t file; - uint8_t mode; + //f_file_t file; f_color_set_t valid; f_color_set_t valid_not; @@ -81,8 +83,8 @@ extern "C" { { \ 0, \ 0, \ - f_file_t_initialize, \ - utf8_mode_from_bytesequence_d | utf8_mode_to_codepoint_d, \ + 0, \ + //f_file_t_initialize, \ f_color_set_t_initialize, \ f_color_set_t_initialize, \ f_string_static_t_initialize, \ diff --git a/level_3/utf8/c/private-utf8_bytesequence.c b/level_3/utf8/c/private-utf8_bytesequence.c index 7e2ce44..dd18133 100644 --- a/level_3/utf8/c/private-utf8_bytesequence.c +++ b/level_3/utf8/c/private-utf8_bytesequence.c @@ -52,9 +52,7 @@ extern "C" { } } - if (valid_not || F_status_is_error(status)) { - return F_utf_not; - } + if (valid_not || F_status_is_error(status)) return F_utf_not; return F_none; } @@ -154,9 +152,7 @@ extern "C" { data->buffer.used = 0; - if (F_status_is_error(status) || status == F_interrupt) { - return status; - } + if (F_status_is_error(status) || status == F_interrupt) return status; return valid; } diff --git a/level_3/utf8/c/private-utf8_codepoint.c b/level_3/utf8/c/private-utf8_codepoint.c index 8389de9..f96c43d 100644 --- a/level_3/utf8/c/private-utf8_codepoint.c +++ b/level_3/utf8/c/private-utf8_codepoint.c @@ -440,9 +440,7 @@ extern "C" { data->buffer.used = 0; - if (F_status_is_error(status) || status == F_interrupt) { - return status; - } + if (F_status_is_error(status) || status == F_interrupt) return status; return valid; } diff --git a/level_3/utf8/c/utf8.c b/level_3/utf8/c/utf8.c index 7606f1e..eef2f33 100644 --- a/level_3/utf8/c/utf8.c +++ b/level_3/utf8/c/utf8.c @@ -68,235 +68,25 @@ extern "C" { #endif // _di_utf8_print_help_ #ifndef _di_utf8_main_ - f_status_t utf8_main(fll_program_data_t * const main, const f_console_arguments_t *arguments) { + f_status_t utf8_main(fll_program_data_t * const main, utf8_main_setting_t * const setting) { - f_status_t status = F_none; - - utf8_data_t data = utf8_data_t_initialize; - data.main = main; - - // Identify priority of color parameters. - { - f_console_parameter_id_t ids[3] = { utf8_parameter_no_color_e, utf8_parameter_light_e, utf8_parameter_dark_e }; - const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 3); - - status = fll_program_parameter_process(*arguments, &main->parameters, choices, F_true, &main->context); - - main->output.set = &main->context.set; - main->error.set = &main->context.set; - main->warning.set = &main->context.set; - - if (main->context.set.error.before) { - main->output.context = f_color_set_empty_s; - main->output.notable = main->context.set.notable; - - main->error.context = main->context.set.error; - main->error.notable = main->context.set.notable; - - main->warning.context = main->context.set.warning; - main->warning.notable = main->context.set.notable; - } - else { - f_color_set_t *sets[] = { &main->output.context, &main->output.notable, &main->error.context, &main->error.notable, &main->warning.context, &main->warning.notable, 0 }; - - fll_program_parameter_process_empty(&main->context, sets); - } - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process", F_true); - - utf8_data_delete(&data); - - return F_status_set_error(status); - } - } - - // Identify priority of verbosity related parameters. - { - f_console_parameter_id_t ids[5] = { utf8_parameter_verbosity_quiet_e, utf8_parameter_verbosity_error_e, utf8_parameter_verbosity_normal_e, utf8_parameter_verbosity_verbose_e, utf8_parameter_verbosity_debug_e }; - f_console_parameter_id_t choice = 0; - const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 5); - - status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - - utf8_data_delete(&data); - - return status; - } - - if (choice == utf8_parameter_verbosity_quiet_e) { - main->output.verbosity = f_console_verbosity_quiet_e; - main->error.verbosity = f_console_verbosity_quiet_e; - main->warning.verbosity = f_console_verbosity_quiet_e; - } - else if (choice == utf8_parameter_verbosity_error_e) { - main->output.verbosity = f_console_verbosity_error_e; - main->error.verbosity = f_console_verbosity_error_e; - main->warning.verbosity = f_console_verbosity_error_e; - } - else if (choice == utf8_parameter_verbosity_normal_e) { - main->output.verbosity = f_console_verbosity_normal_e; - main->error.verbosity = f_console_verbosity_normal_e; - main->warning.verbosity = f_console_verbosity_normal_e; - } - else if (choice == utf8_parameter_verbosity_verbose_e) { - main->output.verbosity = f_console_verbosity_verbose_e; - main->error.verbosity = f_console_verbosity_verbose_e; - main->warning.verbosity = f_console_verbosity_verbose_e; - } - else if (choice == utf8_parameter_verbosity_debug_e) { - main->output.verbosity = f_console_verbosity_debug_e; - main->error.verbosity = f_console_verbosity_debug_e; - main->warning.verbosity = f_console_verbosity_debug_e; - } - } - - // Identify and prioritize from mode parameters. - { - f_console_parameter_id_t ids[2] = { utf8_parameter_from_bytesequence_e, utf8_parameter_from_codepoint_e }; - f_console_parameter_id_t choice = 0; - const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 2); - - status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - - utf8_data_delete(&data); - - return status; - } - - if (choice == utf8_parameter_from_bytesequence_e) { - if (data.mode & utf8_mode_from_codepoint_d) { - data.mode -= utf8_mode_from_codepoint_d; - } - - data.mode |= utf8_mode_from_bytesequence_d; - } - else if (choice == utf8_parameter_from_codepoint_e) { - if (data.mode & utf8_mode_from_bytesequence_d) { - data.mode -= utf8_mode_from_bytesequence_d; - } - - data.mode |= utf8_mode_from_codepoint_d; - } - } - - // Identify and prioritize to mode parameters. - { - f_console_parameter_id_t ids[5] = { utf8_parameter_to_bytesequence_e, utf8_parameter_to_codepoint_e, utf8_parameter_to_combining_e, utf8_parameter_to_width_e }; - f_console_parameter_id_t choice = 0; - const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 5); - - status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); - - utf8_data_delete(&data); - - return status; - } - - if (choice == utf8_parameter_verbosity_quiet_e) { - main->output.verbosity = f_console_verbosity_quiet_e; - main->error.verbosity = f_console_verbosity_quiet_e; - main->warning.verbosity = f_console_verbosity_quiet_e; - } - else if (choice == utf8_parameter_verbosity_error_e) { - main->output.verbosity = f_console_verbosity_error_e; - main->error.verbosity = f_console_verbosity_error_e; - main->warning.verbosity = f_console_verbosity_error_e; - } - else if (choice == utf8_parameter_verbosity_normal_e) { - main->output.verbosity = f_console_verbosity_normal_e; - main->error.verbosity = f_console_verbosity_normal_e; - main->warning.verbosity = f_console_verbosity_normal_e; - } - else if (choice == utf8_parameter_verbosity_verbose_e) { - main->output.verbosity = f_console_verbosity_verbose_e; - main->error.verbosity = f_console_verbosity_verbose_e; - main->warning.verbosity = f_console_verbosity_verbose_e; - } - else if (choice == utf8_parameter_verbosity_debug_e) { - main->output.verbosity = f_console_verbosity_debug_e; - main->error.verbosity = f_console_verbosity_debug_e; - main->warning.verbosity = f_console_verbosity_debug_e; - } - - if (choice == utf8_parameter_to_bytesequence_e) { - if (data.mode & utf8_mode_to_codepoint_d) { - data.mode -= utf8_mode_to_codepoint_d; - } - - if (data.mode & utf8_mode_to_combining_d) { - data.mode -= utf8_mode_to_combining_d; - } - - if (data.mode & utf8_mode_to_width_d) { - data.mode -= utf8_mode_to_width_d; - } - - data.mode |= utf8_mode_to_bytesequence_d; - } - else if (choice == utf8_parameter_to_codepoint_e) { - if (data.mode & utf8_mode_to_bytesequence_d) { - data.mode -= utf8_mode_to_bytesequence_d; - } - - if (data.mode & utf8_mode_to_combining_d) { - data.mode -= utf8_mode_to_combining_d; - } - - if (data.mode & utf8_mode_to_width_d) { - data.mode -= utf8_mode_to_width_d; - } - - data.mode |= utf8_mode_to_codepoint_d; + if (!main || !setting) { + if (main->error.verbosity != f_console_verbosity_quiet_e) { + fll_error_print(main->error, F_status_set_fine(status), "utf8_main", F_true); + fll_print_dynamic_raw(f_string_eol_s, main->message.to.stream); } - else if (choice == utf8_parameter_to_combining_e) { - if (data.mode & utf8_mode_to_bytesequence_d) { - data.mode -= utf8_mode_to_bytesequence_d; - } - - if (data.mode & utf8_mode_to_codepoint_d) { - data.mode -= utf8_mode_to_codepoint_d; - } - - // --to_width may be specified with --to_combining. - if (main->parameters.array[utf8_parameter_to_width_e].result == f_console_result_found_e) { - data.mode |= utf8_mode_to_width_d; - } - - data.mode |= utf8_mode_to_combining_d; - } - else if (choice == utf8_parameter_to_width_e) { - if (data.mode & utf8_mode_to_bytesequence_d) { - data.mode -= utf8_mode_to_bytesequence_d; - } - - if (data.mode & utf8_mode_to_codepoint_d) { - data.mode -= utf8_mode_to_codepoint_d; - } - - // --to_width may be specified with --to_combining. - if (main->parameters.array[utf8_parameter_to_combining_e].result == f_console_result_found_e) { - data.mode |= utf8_mode_to_combining_d; - } - data.mode |= utf8_mode_to_width_d; - } + return F_status_set_error(F_paremeter); } + utf8_data_t data = utf8_data_t_initialize; + data.main = main; + data.setting = setting; data.argv = main->parameters.arguments.array; - status = F_none; + f_status_t status = F_none; if (main->parameters.array[utf8_parameter_help_e].result == f_console_result_found_e) { - utf8_print_help(main->output.to, main->context); + utf8_print_help(main->message.to, main->context); utf8_data_delete(&data); @@ -304,7 +94,7 @@ extern "C" { } if (main->parameters.array[utf8_parameter_version_e].result == f_console_result_found_e) { - fll_program_print_version(main->output.to, utf8_program_version_s); + fll_program_print_version(main->message.to, utf8_program_version_s); utf8_data_delete(&data); @@ -375,7 +165,7 @@ extern "C" { status = F_status_set_error(F_parameter); } else { - data.file = main->output.to; + data.file = main->message.to; } } @@ -396,7 +186,7 @@ extern "C" { } } - data.valid_not = main->output.set->error; + data.valid_not = main->message.set->error; } if (F_status_is_error_not(status)) { @@ -459,7 +249,8 @@ extern "C" { status = utf8_process_file_codepoint(&data, file); } - f_file_stream_close(F_true, &file); + f_file_stream_flush(&file); + f_file_stream_close(&file); if (main->parameters.array[utf8_parameter_verify_e].result == f_console_result_found_e) { if (status == F_false) { @@ -501,28 +292,196 @@ extern "C" { } } - if (main->output.verbosity != f_console_verbosity_quiet_e && main->parameters.array[utf8_parameter_verify_e].result == f_console_result_none_e) { + if (main->message.verbosity != f_console_verbosity_quiet_e && main->parameters.array[utf8_parameter_verify_e].result == f_console_result_none_e) { if (status == F_interrupt) { fflush(data.file.stream); - if (data.file.stream != main->output.to.stream) { - fflush(main->output.to.stream); + if (data.file.stream != main->message.to.stream) { + fflush(main->message.to.stream); } } - fll_print_dynamic_raw(f_string_eol_s, main->output.to.stream); + fll_print_dynamic_raw(f_string_eol_s, main->message.to.stream); } utf8_data_delete(&data); - if (F_status_is_error(status) || status == F_interrupt) { - return status; - } + if (F_status_is_error(status) || status == F_interrupt) return status; return valid; } #endif // _di_utf8_main_ +#ifndef _di_utf8_main_setting_delete_ + f_status_t utf8_main_setting_delete(utf8_main_setting_t * const setting) { + + return F_none; + } +#endif // _di_utf8_main_setting_delete_ + +#ifndef _di_utf8_main_setting_load_ + f_status_t utf8_main_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, utf8_main_setting_t * const setting) { + + f_status_t status = F_none; + + // Identify priority of color parameters. + { + f_console_parameter_id_t ids[3] = { utf8_parameter_no_color_e, utf8_parameter_light_e, utf8_parameter_dark_e }; + const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 3); + + status = fll_program_parameter_process(arguments, choices, F_true, main); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process", F_true); + + return status; + } + } + + { + const verbosity[5] = { utf8_parameter_verbosity_quiet_e, utf8_parameter_verbosity_error_e, f_console_verbosity_normal_e, utf8_parameter_verbosity_verbose_e, utf8_parameter_verbosity_debug_e }; + f_console_parameter_id_t ids[5] = { utf8_parameter_verbosity_quiet_e, utf8_parameter_verbosity_error_e, utf8_parameter_verbosity_normal_e, utf8_parameter_verbosity_verbose_e, utf8_parameter_verbosity_debug_e }; + const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 5); + + status = fll_program_parameter_process_verbosity(choices, F_true, verbosity, main); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process_verbosity", F_true); + + return status; + } + } + + // Identify and prioritize from mode parameters. + { + f_console_parameter_id_t ids[2] = { utf8_parameter_from_bytesequence_e, utf8_parameter_from_codepoint_e }; + f_console_parameter_id_t choice = 0; + const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 2); + + status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); + + return status; + } + + if (choice == utf8_parameter_from_bytesequence_e) { + if (data.mode & utf8_mode_from_codepoint_d) { + data.mode -= utf8_mode_from_codepoint_d; + } + + data.mode |= utf8_mode_from_bytesequence_d; + } + else if (choice == utf8_parameter_from_codepoint_e) { + if (data.mode & utf8_mode_from_bytesequence_d) { + data.mode -= utf8_mode_from_bytesequence_d; + } + + data.mode |= utf8_mode_from_codepoint_d; + } + } + + // Identify and prioritize to mode parameters. + { + f_console_parameter_id_t ids[5] = { utf8_parameter_to_bytesequence_e, utf8_parameter_to_codepoint_e, utf8_parameter_to_combining_e, utf8_parameter_to_width_e }; + f_console_parameter_id_t choice = 0; + const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 5); + + status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_console_parameter_prioritize_right", F_true); + + return status; + } + + if (choice == utf8_parameter_to_bytesequence_e) { + if (data.mode & utf8_mode_to_codepoint_d) { + data.mode -= utf8_mode_to_codepoint_d; + } + + if (data.mode & utf8_mode_to_combining_d) { + data.mode -= utf8_mode_to_combining_d; + } + + if (data.mode & utf8_mode_to_width_d) { + data.mode -= utf8_mode_to_width_d; + } + + data.mode |= utf8_mode_to_bytesequence_d; + } + else if (choice == utf8_parameter_to_codepoint_e) { + if (data.mode & utf8_mode_to_bytesequence_d) { + data.mode -= utf8_mode_to_bytesequence_d; + } + + if (data.mode & utf8_mode_to_combining_d) { + data.mode -= utf8_mode_to_combining_d; + } + + if (data.mode & utf8_mode_to_width_d) { + data.mode -= utf8_mode_to_width_d; + } + + data.mode |= utf8_mode_to_codepoint_d; + } + else if (choice == utf8_parameter_to_combining_e) { + if (data.mode & utf8_mode_to_bytesequence_d) { + data.mode -= utf8_mode_to_bytesequence_d; + } + + if (data.mode & utf8_mode_to_codepoint_d) { + data.mode -= utf8_mode_to_codepoint_d; + } + + // --to_width may be specified with --to_combining. + if (main->parameters.array[utf8_parameter_to_width_e].result == f_console_result_found_e) { + data.mode |= utf8_mode_to_width_d; + } + + data.mode |= utf8_mode_to_combining_d; + } + else if (choice == utf8_parameter_to_width_e) { + if (data.mode & utf8_mode_to_bytesequence_d) { + data.mode -= utf8_mode_to_bytesequence_d; + } + + if (data.mode & utf8_mode_to_codepoint_d) { + data.mode -= utf8_mode_to_codepoint_d; + } + + // --to_width may be specified with --to_combining. + if (main->parameters.array[utf8_parameter_to_combining_e].result == f_console_result_found_e) { + data.mode |= utf8_mode_to_combining_d; + } + + data.mode |= utf8_mode_to_width_d; + } + } + + return F_none; + } +#endif // _di_utf8_main_setting_load_ + +#ifndef _di_utf8_main_setting_unload_ + f_status_t utf8_main_setting_unload(fll_program_data_t * const main, utf8_main_setting_t * const setting) { + + if (data->file.stream) { + if (data->file.stream != main->message.stream && data->file.stream != main->output.stream && data->file.stream != main->error.stream && data->file.stream != main->warning.stream && data->file.stream != main->debug.stream) { + f_file_stream_flush(&data->file); + f_file_stream_close(&data->file); + } + } + else if (data->file.id != -1) { + if (data->file.id != main->message.id && data->file.id != main->output.id && data->file.id != main->error.id && data->file.id != main->warning.id && data->file.id != main->debug.id) { + f_file_flush(&data->file); + f_file_close(&data->file); + } + } + } +#endif // _di_utf8_main_setting_unload_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/utf8/c/utf8.h b/level_3/utf8/c/utf8.h index fa13572..9d1697f 100644 --- a/level_3/utf8/c/utf8.h +++ b/level_3/utf8/c/utf8.h @@ -89,8 +89,8 @@ extern "C" { * * @param main * The main program data. - * @param arguments - * The parameters passed to the process. + * @param setting + * The main program setting data. * * @return * F_none on success. @@ -98,12 +98,61 @@ extern "C" { * F_false on success when performing verification and verify failed. * F_interrupt on (exit) signal received. * - * Status codes (with error bit) are returned on any problem. + * F_parameter (with error bit) If main is NULL or setting is NULL. */ #ifndef _di_utf8_main_ - extern f_status_t utf8_main(fll_program_data_t * const main, const f_console_arguments_t *arguments); + extern f_status_t utf8_main(fll_program_data_t * const main, utf8_main_setting_t * const setting); #endif // _di_utf8_main_ +/** + * Delete the program main setting data. + * + * @param setting + * The program main setting data. + * + * @return + * F_none on success. + */ +#ifndef _di_utf8_main_setting_delete_ + extern f_status_t utf8_main_setting_delete(utf8_main_setting_t * const setting); +#endif // _di_utf8_main_setting_delete_ + +/** + * Perform the standard program setting load process. + * + * @param arguments + * The parameters passed to the process (often referred to as command line arguments). + * @param main + * The main program data. + * @param setting + * The main program setting data. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: fll_program_parameter_process(). + * + * @see fll_program_parameter_process() + */ +#ifndef _di_utf8_main_setting_load_ + extern f_status_t utf8_main_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, utf8_main_setting_t * const setting); +#endif // _di_utf8_main_setting_load_ + +/** + * Perform the standard program setting unload process. + * + * @param main + * The main program data. + * @param setting + * The main program setting data. + * + * @return + * F_none on success. + */ +#ifndef _di_utf8_main_setting_unload_ + extern f_status_t utf8_main_setting_unload(fll_program_data_t * const main, utf8_main_setting_t * const setting); +#endif // _di_utf8_main_setting_unload_ + #ifdef __cplusplus } // extern "C" #endif -- 1.8.3.1