From edd313ef1268d709011d0a7c77d6aac1d6065727 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 3 Mar 2023 00:00:52 -0600 Subject: [PATCH] Progress: Continue program related work, focusing on utf8 and status_code. Do more clean up in regards to utf8. Update the first and last line printing logic. Update the file structure. Do the same for status_code. I did not get to working on the first and last line printing logic. --- build/stand_alone/utf8.settings | 3 +- level_3/status_code/c/fss/print.c | 6 +- level_3/status_code/c/fss/print.h | 10 +- level_3/status_code/c/fss/status_code.h | 9 +- .../c/main/{common-print.c => common/print.c} | 2 +- .../c/main/{common-print.h => common/print.h} | 0 .../c/main/{common-string.c => common/string.c} | 2 +- .../c/main/{common-string.h => common/string.h} | 0 .../c/main/{common-type.c => common/type.c} | 2 +- .../c/main/{common-type.h => common/type.h} | 40 +- level_3/status_code/c/main/convert.c | 42 ++ level_3/status_code/c/main/convert.h | 47 ++ level_3/status_code/c/main/print-error.c | 0 level_3/status_code/c/main/print-error.h | 0 level_3/status_code/c/main/print.c | 99 +++- level_3/status_code/c/main/print.h | 136 +++++- level_3/status_code/c/main/private-status_code.c | 146 ------ level_3/status_code/c/main/process.c | 147 ++++++ .../c/main/{private-status_code.h => process.h} | 40 +- level_3/status_code/c/main/status_code.c | 35 +- level_3/status_code/c/main/status_code.h | 9 +- level_3/status_code/data/build/settings | 4 +- level_3/utf8/c/main/bytesequence.c | 8 +- level_3/utf8/c/main/bytesequence.h | 4 +- level_3/utf8/c/main/codepoint.c | 22 +- level_3/utf8/c/main/codepoint.h | 8 +- level_3/utf8/c/main/common.c | 44 +- .../utf8/c/main/{common-print.c => common/print.c} | 2 +- .../utf8/c/main/{common-print.h => common/print.h} | 0 .../c/main/{common-string.c => common/string.c} | 2 +- .../c/main/{common-string.h => common/string.h} | 0 .../utf8/c/main/{common-type.c => common/type.c} | 2 +- .../utf8/c/main/{common-type.h => common/type.h} | 12 +- level_3/utf8/c/main/print-data.c | 321 +++++++++++++ level_3/utf8/c/main/print-data.h | 292 +++++++++++ level_3/utf8/c/main/print-error.c | 156 ++++++ level_3/utf8/c/main/print-error.h | 221 +++++++++ level_3/utf8/c/main/print.c | 535 +-------------------- level_3/utf8/c/main/print.h | 528 +------------------- level_3/utf8/c/main/private-common.c | 10 - level_3/utf8/c/main/private-common.h | 19 - level_3/utf8/c/main/process.c | 1 - level_3/utf8/c/main/utf8.c | 26 +- level_3/utf8/c/main/utf8.h | 8 +- level_3/utf8/data/build/settings | 4 +- 45 files changed, 1628 insertions(+), 1376 deletions(-) rename level_3/status_code/c/main/{common-print.c => common/print.c} (92%) rename level_3/status_code/c/main/{common-print.h => common/print.h} (100%) rename level_3/status_code/c/main/{common-string.c => common/string.c} (99%) rename level_3/status_code/c/main/{common-string.h => common/string.h} (100%) rename level_3/status_code/c/main/{common-type.c => common/type.c} (74%) rename level_3/status_code/c/main/{common-type.h => common/type.h} (86%) create mode 100644 level_3/status_code/c/main/convert.c create mode 100644 level_3/status_code/c/main/convert.h create mode 100644 level_3/status_code/c/main/print-error.c create mode 100644 level_3/status_code/c/main/print-error.h delete mode 100644 level_3/status_code/c/main/private-status_code.c create mode 100644 level_3/status_code/c/main/process.c rename level_3/status_code/c/main/{private-status_code.h => process.h} (68%) rename level_3/utf8/c/main/{common-print.c => common/print.c} (96%) rename level_3/utf8/c/main/{common-print.h => common/print.h} (100%) rename level_3/utf8/c/main/{common-string.c => common/string.c} (99%) rename level_3/utf8/c/main/{common-string.h => common/string.h} (100%) rename level_3/utf8/c/main/{common-type.c => common/type.c} (79%) rename level_3/utf8/c/main/{common-type.h => common/type.h} (96%) create mode 100644 level_3/utf8/c/main/print-data.c create mode 100644 level_3/utf8/c/main/print-data.h create mode 100644 level_3/utf8/c/main/print-error.c create mode 100644 level_3/utf8/c/main/print-error.h delete mode 100644 level_3/utf8/c/main/private-common.c delete mode 100644 level_3/utf8/c/main/private-common.h diff --git a/build/stand_alone/utf8.settings b/build/stand_alone/utf8.settings index ebd860f..5287836 100644 --- a/build/stand_alone/utf8.settings +++ b/build/stand_alone/utf8.settings @@ -47,8 +47,7 @@ build_sources_program fll/level_2/error.c fll/level_2/error/common.c fll/level_2 build_sources_program fll/level_2/print.c build_sources_program fll/level_2/program.c fll/level_2/program/common.c fll/level_2/program/print.c fll/level_2/private-program.c -build_sources_program program/utf8/common.c program/utf8/bytesequence.c program/utf8/codepoint.c program/utf8/print.c program/utf8/process.c program/utf8/utf8.c - +build_sources_program program/utf8/main/common.c program/utf8/main/common/print.c program/utf8/main/common/string.c program/utf8/main/common/type.c program/utf8/main/bytesequence.c program/utf8/main/codepoint.c program/utf8/main/print.c program/utf8/main/print-error.c program/utf8/main/print-data.c program/utf8/main/process.c program/utf8/main/utf8.c build_sources_program program/utf8/main.c build_sources_documentation man diff --git a/level_3/status_code/c/fss/print.c b/level_3/status_code/c/fss/print.c index f70e49c..82af1fe 100644 --- a/level_3/status_code/c/fss/print.c +++ b/level_3/status_code/c/fss/print.c @@ -7,7 +7,9 @@ extern "C" { #endif #ifndef _di_status_code_fss_print_help_detail_ - void status_code_fss_print_help_detail(void * const setting, const fl_print_t print) { + f_status_t status_code_fss_print_help_detail(void * const setting, const fl_print_t print) { + + if (!setting) return F_status_set_error(F_output_not); fl_print_format(" The FLL programs use a %[16-bit unsigned integer%] to represent the return status of programs and functions.%r%r", print.to, print.set->notable, print.set->notable, f_string_eol_s, f_string_eol_s); @@ -24,6 +26,8 @@ extern "C" { fl_print_format(" Each code will be printed on its own line.%r", print.to, f_string_eol_s); fl_print_format(" Errors regarding each code may be printed on its own line.%r", print.to, f_string_eol_s); + + return F_none; } #endif // _di_status_code_fss_print_help_detail_ diff --git a/level_3/status_code/c/fss/print.h b/level_3/status_code/c/fss/print.h index 7efd9a6..e017c11 100644 --- a/level_3/status_code/c/fss/print.h +++ b/level_3/status_code/c/fss/print.h @@ -26,10 +26,18 @@ extern "C" { * @param print * The output structure to print to. * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fl_print_format() + * * @see status_code_print_help() */ #ifndef _di_status_code_fss_print_help_detail_ - extern void status_code_fss_print_help_detail(void * const setting, const fl_print_t print); + extern f_status_t status_code_fss_print_help_detail(void * const setting, const fl_print_t print); #endif // _di_status_code_fss_print_help_detail_ #ifdef __cplusplus diff --git a/level_3/status_code/c/fss/status_code.h b/level_3/status_code/c/fss/status_code.h index 58f508c..d49be4e 100644 --- a/level_3/status_code/c/fss/status_code.h +++ b/level_3/status_code/c/fss/status_code.h @@ -42,12 +42,15 @@ #include // Status Code includes. -#include -#include -#include +#include +#include +#include #include #include +#include #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/level_3/status_code/c/main/common-print.c b/level_3/status_code/c/main/common/print.c similarity index 92% rename from level_3/status_code/c/main/common-print.c rename to level_3/status_code/c/main/common/print.c index 25ec837..4497281 100644 --- a/level_3/status_code/c/main/common-print.c +++ b/level_3/status_code/c/main/common/print.c @@ -1,4 +1,4 @@ -#include "status_code.h" +#include "../status_code.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/status_code/c/main/common-print.h b/level_3/status_code/c/main/common/print.h similarity index 100% rename from level_3/status_code/c/main/common-print.h rename to level_3/status_code/c/main/common/print.h diff --git a/level_3/status_code/c/main/common-string.c b/level_3/status_code/c/main/common/string.c similarity index 99% rename from level_3/status_code/c/main/common-string.c rename to level_3/status_code/c/main/common/string.c index d7dfb12..704559d 100644 --- a/level_3/status_code/c/main/common-string.c +++ b/level_3/status_code/c/main/common/string.c @@ -1,4 +1,4 @@ -#include "status_code.h" +#include "../status_code.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/status_code/c/main/common-string.h b/level_3/status_code/c/main/common/string.h similarity index 100% rename from level_3/status_code/c/main/common-string.h rename to level_3/status_code/c/main/common/string.h diff --git a/level_3/status_code/c/main/common-type.c b/level_3/status_code/c/main/common/type.c similarity index 74% rename from level_3/status_code/c/main/common-type.c rename to level_3/status_code/c/main/common/type.c index 4740201..4c41666 100644 --- a/level_3/status_code/c/main/common-type.c +++ b/level_3/status_code/c/main/common/type.c @@ -1,4 +1,4 @@ -#include "status_code.h" +#include "../status_code.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/status_code/c/main/common-type.h b/level_3/status_code/c/main/common/type.h similarity index 86% rename from level_3/status_code/c/main/common-type.h rename to level_3/status_code/c/main/common/type.h index 2e27586..5f7778d 100644 --- a/level_3/status_code/c/main/common-type.h +++ b/level_3/status_code/c/main/common/type.h @@ -36,26 +36,28 @@ extern "C" { * When number mode is not specified, then mode is "string" mode (there is no flag for "string" mode). * * status_code_main_flag_*_e: - * - none: No flags set. - * - copyright: Print copyright. - * - error: Check if status is "error". - * - fine: Check if status is "fine". - * - help: Print help. - * - number: Operate in number mode. - * - version: Print version. - * - warning: Check if status is "warning". + * - none: No flags set. + * - copyright: Print copyright. + * - error: Check if status is "error". + * - fine: Check if status is "fine". + * - help: Print help. + * - number: Operate in number mode. + * - print_first: When set, the first character printing logic is to be processed (this is usually automatic). + * - version: Print version. + * - warning: Check if status is "warning". */ #ifndef _di_status_code_main_flag_e_ enum { - status_code_main_flag_none_e = 0x0, - status_code_main_flag_copyright_e = 0x1, - status_code_main_flag_error_e = 0x2, - status_code_main_flag_fine_e = 0x4, - status_code_main_flag_help_e = 0x8, - status_code_main_flag_number_e = 0x10, - status_code_main_flag_version_e = 0x20, - status_code_main_flag_warning_e = 0x40, - }; + status_code_main_flag_none_e = 0x0, + status_code_main_flag_copyright_e = 0x1, + status_code_main_flag_error_e = 0x2, + status_code_main_flag_fine_e = 0x4, + status_code_main_flag_help_e = 0x8, + status_code_main_flag_number_e = 0x10, + status_code_main_flag_print_first_e = 0x20, + status_code_main_flag_version_e = 0x40, + status_code_main_flag_warning_e = 0x80, + }; // enum #endif // _di_status_code_main_flag_e_ /** @@ -139,12 +141,12 @@ extern "C" { f_status_t (*status_string_from)(const f_string_static_t name, f_status_t * const code); f_status_t (*status_string_to)(const f_status_t code, f_string_static_t * const name); - void (*status_string_help_detail)(void * const setting, const fl_print_t print); + f_status_t (*status_string_help_detail)(void * const setting, const fl_print_t print); } status_code_setting_t; #define status_code_setting_t_initialize \ { \ - status_code_main_flag_none_e, \ + status_code_main_flag_print_first_e, \ f_state_t_initialize, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ diff --git a/level_3/status_code/c/main/convert.c b/level_3/status_code/c/main/convert.c new file mode 100644 index 0000000..0706086 --- /dev/null +++ b/level_3/status_code/c/main/convert.c @@ -0,0 +1,42 @@ +#include "status_code.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_status_code_convert_number_ + void status_code_convert_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number) { + + if (!main || !setting) return; + + setting->state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, number); + + if (*number > F_status_size_max_with_bits_d) { + status_code_print_line_first_data(setting, main->message); + + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_out_of_range_s); + + setting->state.status = F_status_set_error(F_number_overflow); + + return; + } + + if (F_status_is_error(setting->state.status)) { + status_code_print_line_first_data(setting, main->message); + + if (F_status_set_fine(setting->state.status) == F_number_negative) { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_out_of_range_s); + } + else { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_invalid_number_s); + } + } + else { + setting->state.status = F_none; + } + } +#endif // _di_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/status_code/c/main/convert.h b/level_3/status_code/c/main/convert.h new file mode 100644 index 0000000..b11219b --- /dev/null +++ b/level_3/status_code/c/main/convert.h @@ -0,0 +1,47 @@ +/** + * FLL - Level 3 + * + * Project: Status Code + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + */ +#ifndef _PRIVATE_status_code_convert_h +#define _PRIVATE_status_code_convert_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convert the value string to the number, reporting any errors. + * + * @param main + * The main program data. + * @param value + * The parameter value to process. + * @param number + * The converted number. + * Will not be updated on error. + * + * This alters setting.state.status: + * F_none on success. + * F_data_not if string starts wth a null (length is 0). + * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. + * F_number (with error bit) if parameter is not a number. + * F_number_negative (with error bit) on negative value. + * F_number_overflow (with error bit) on integer overflow. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: fl_console_parameter_to_number_unsigned(). + * + * @see fl_console_parameter_to_number_unsigned() + */ +#ifndef _di_status_code_convert_number_ + extern void status_code_convert_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number); +#endif // _di_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_status_code_convert_h diff --git a/level_3/status_code/c/main/print-error.c b/level_3/status_code/c/main/print-error.c new file mode 100644 index 0000000..e69de29 diff --git a/level_3/status_code/c/main/print-error.h b/level_3/status_code/c/main/print-error.h new file mode 100644 index 0000000..e69de29 diff --git a/level_3/status_code/c/main/print.c b/level_3/status_code/c/main/print.c index eab0e34..abf1ce0 100644 --- a/level_3/status_code/c/main/print.c +++ b/level_3/status_code/c/main/print.c @@ -1,13 +1,37 @@ #include "status_code.h" -#include "print.h" #ifdef __cplusplus extern "C" { #endif +#ifndef _di_status_code_print_code_ + f_status_t status_code_print_code(status_code_setting_t * const setting, const fl_print_t print, const uint16_t code) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; + + fll_print_format("%ui%r", print.to, code, f_string_eol_s); + + return F_none; + } +#endif // _di_status_code_print_code_ + +#ifndef _di_status_code_print_context_value_ + f_status_t status_code_print_context_value(status_code_setting_t * const setting, const fl_print_t print, const f_color_set_t context, const f_string_static_t value) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; + + fll_print_format("%[%Q%]%r", print.to, context, value, context, f_string_eol_s); + + return F_none; + } +#endif // _di_status_code_print_context_value_ + #ifndef _di_status_code_print_error_ f_status_t status_code_print_error(status_code_setting_t * const setting, const fl_print_t print, const f_string_t function) { + if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; status_code_print_line_first_locked(setting, print); @@ -20,6 +44,7 @@ extern "C" { #ifndef _di_status_code_print_error_cannot_error_warning_number_ f_status_t status_code_print_error_cannot_error_warning_number(status_code_setting_t * const setting, const fl_print_t print) { + if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; f_file_stream_lock(print.to); @@ -41,6 +66,7 @@ extern "C" { #ifndef _di_status_code_print_error_no_status_codes_ f_status_t status_code_print_error_no_status_codes(status_code_setting_t * const setting, const fl_print_t print) { + if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; fll_print_format("%[No status code is specified.%]%r", print.to, print.context, print.context, f_string_eol_s); @@ -52,6 +78,7 @@ extern "C" { #ifndef _di_status_code_print_error_invalid_callback_ f_status_t status_code_print_error_invalid_callback(status_code_setting_t * const setting, const fl_print_t print, const f_string_t name) { + if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; f_file_stream_lock(print.to); @@ -69,6 +96,8 @@ extern "C" { #ifndef _di_status_code_print_help_ f_status_t status_code_print_help(status_code_setting_t * const setting, const fl_print_t print) { + if (!setting) return F_status_set_error(F_output_not); + f_file_stream_lock(print.to); f_print_dynamic_raw(setting->line_first, print.to); @@ -101,8 +130,8 @@ extern "C" { status_code_program_help_parameters_s ); - if (setting->state.status_string_help_detail) { - setting->state.status_string_help_detail(setting, print); + if (setting->status_string_help_detail) { + setting->status_string_help_detail(setting, print); } f_print_dynamic_raw(setting->line_last, print.to); @@ -115,7 +144,9 @@ extern "C" { #endif // _di_status_code_print_help_ #ifndef _di_status_code_print_help_detail_ - void status_code_print_help_detail(void * const void_setting, const fl_print_t print) { + f_status_t status_code_print_help_detail(void * const void_setting, const fl_print_t print) { + + if (!void_setting) return F_status_set_error(F_output_not); fl_print_format(" The FLL programs use a %[16-bit unsigned integer%] to represent the return status of programs and functions.%r%r", print.to, print.set->notable, print.set->notable, f_string_eol_s, f_string_eol_s); @@ -130,19 +161,41 @@ extern "C" { fl_print_format(" Each code will be printed on its own line.%r", print.to, print.set->notable, print.set->notable, f_string_eol_s); fl_print_format(" Errors regarding each code may be printed on its own line.%r", print.to, f_string_eol_s); + + return F_none; } #endif // _di_status_code_print_help_detail_ +#ifndef _di_status_code_print_line_first_data_ + f_status_t status_code_print_line_first_data(status_code_setting_t * const setting, const fl_print_t print) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; + + if (setting->flag & status_code_main_flag_print_first_e) { + fll_print_dynamic_raw(setting->line_first, print.to); + + setting->flag -= status_code_main_flag_print_first_e; + } + + return F_none; + } +#endif // _di_status_code_print_line_first_data_ + #ifndef _di_status_code_print_line_first_locked_ f_status_t status_code_print_line_first_locked(status_code_setting_t * const setting, const fl_print_t print) { - if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + if (setting->flag & status_code_main_flag_print_first_e) { + fll_print_dynamic_raw(setting->line_first, print.to); - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; + setting->flag -= status_code_main_flag_print_first_e; + } + else { + fll_print_dynamic_raw(f_string_eol_s, print.to); } - - f_print_dynamic_raw(setting->line_first, print.to); return F_none; } @@ -151,13 +204,17 @@ extern "C" { #ifndef _di_status_code_print_line_first_unlocked_ f_status_t status_code_print_line_first_unlocked(status_code_setting_t * const setting, const fl_print_t print) { - if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - } + if (setting->flag & status_code_main_flag_print_first_e) { + fll_print_dynamic_raw(setting->line_first, print.to); - fll_print_dynamic_raw(setting->line_first, print.to); + setting->flag -= status_code_main_flag_print_first_e; + } + else { + fll_print_dynamic_raw(f_string_eol_s, print.to); + } return F_none; } @@ -166,11 +223,8 @@ extern "C" { #ifndef _di_status_code_print_line_last_locked_ f_status_t status_code_print_line_last_locked(status_code_setting_t * const setting, const fl_print_t print) { - if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; - - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - } + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; fll_print_dynamic_raw(setting->line_last, print.to); @@ -181,11 +235,8 @@ extern "C" { #ifndef _di_status_code_print_line_last_unlocked_ f_status_t status_code_print_line_last_unlocked(status_code_setting_t * const setting, const fl_print_t print) { - if (!setting || print.verbosity < f_console_verbosity_error_e) return F_output_not; - - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - } + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; f_print_dynamic_raw(setting->line_last, print.to); diff --git a/level_3/status_code/c/main/print.h b/level_3/status_code/c/main/print.h index b584240..a746aa8 100644 --- a/level_3/status_code/c/main/print.h +++ b/level_3/status_code/c/main/print.h @@ -13,6 +13,56 @@ extern "C" { #endif /** + * Print generic code. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param code + * The code to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_format() + */ +#ifndef _di_status_code_print_code_ + f_status_t status_code_print_code(status_code_setting_t * const setting, const fl_print_t print, const uint16_t code); +#endif // _di_status_code_print_code_ + +/** + * Print generic context wrapped value. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param context + * The context string to wrap the variable with. + * @param value + * The value string. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_format() + */ +#ifndef _di_status_code_print_context_value_ + f_status_t status_code_print_context_value(status_code_setting_t * const setting, const fl_print_t print, const f_color_set_t context, const f_string_static_t value); +#endif // _di_status_code_print_context_value_ + +/** * Print generic error message regarding a function failing in some way. * * @param setting @@ -26,7 +76,11 @@ extern "C" { * F_none on success. * F_output_not on success, but no printing is performed. * + * F_output_not (with error bit) if setting is NULL. + * * @see fll_error_print() + * + * @see status_code_print_line_first_locked() */ #ifndef _di_status_code_print_error_ extern f_status_t status_code_print_error(status_code_setting_t * const setting, const fl_print_t print, const f_string_t function); @@ -45,6 +99,12 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() */ #ifndef _di_status_code_print_error_cannot_error_warning_number_ extern f_status_t status_code_print_error_cannot_error_warning_number(status_code_setting_t * const setting, const fl_print_t print); @@ -63,6 +123,10 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_format() */ #ifndef _di_status_code_print_error_no_status_codes_ extern f_status_t status_code_print_error_no_status_codes(status_code_setting_t * const setting, const fl_print_t print); @@ -84,6 +148,12 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() */ #ifndef _di_status_code_print_error_invalid_callback_ extern f_status_t status_code_print_error_invalid_callback(status_code_setting_t * const setting, const fl_print_t print, const f_string_t name); @@ -102,6 +172,19 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_flush() + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see f_print_dynamic_raw() + * @see fl_print_format() + * + * @see fll_program_print_help_header() + * @see fll_program_print_help_option() + * @see fll_program_print_help_option_standard() + * @see fll_program_print_help_usage() */ #ifndef _di_status_code_print_help_ extern f_status_t status_code_print_help(status_code_setting_t * const setting, const fl_print_t print); @@ -121,13 +204,48 @@ extern "C" { * @param print * The output structure to print to. * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fl_print_format() + * * @see status_code_print_help() */ #ifndef _di_status_code_print_help_detail_ - extern void status_code_print_help_detail(void * const setting, const fl_print_t print); + extern f_status_t status_code_print_help_detail(void * const setting, const fl_print_t print); #endif // _di_status_code_print_help_detail_ /** + * Print first new line, if applicable, otherwise nothing. + * + * This is generally intended to be used before data prints. + * This should probably be printed to setting.message while data goes to setting.output. + * + * This ensures a first line is printed if the data is the first output to be performed. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_dynamic_raw() + */ +#ifndef _di_status_code_print_line_first_data_ + extern f_status_t status_code_print_line_first_data(status_code_setting_t * const setting, const fl_print_t print); +#endif // _di_status_code_print_line_first_data_ + +/** * Print first new line, unless verbosity says otherwise. * * This is generally either the first line in the program or the first line printed before an error message. @@ -144,6 +262,10 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_dynamic_raw() */ #ifndef _di_status_code_print_line_first_locked_ extern f_status_t status_code_print_line_first_locked(status_code_setting_t * const setting, const fl_print_t print); @@ -166,6 +288,10 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_dynamic_raw() */ #ifndef _di_status_code_print_line_first_unlocked_ extern f_status_t status_code_print_line_first_unlocked(status_code_setting_t * const setting, const fl_print_t print); @@ -188,6 +314,10 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_dynamic_raw() */ #ifndef _di_status_code_print_line_last_locked_ extern f_status_t status_code_print_line_last_locked(status_code_setting_t * const setting, const fl_print_t print); @@ -209,6 +339,10 @@ extern "C" { * @return * F_none on success. * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_print_dynamic_raw() */ #ifndef _di_status_code_print_line_last_unlocked_ extern f_status_t status_code_print_line_last_unlocked(status_code_setting_t * const setting, const fl_print_t print); diff --git a/level_3/status_code/c/main/private-status_code.c b/level_3/status_code/c/main/private-status_code.c deleted file mode 100644 index 8613610..0000000 --- a/level_3/status_code/c/main/private-status_code.c +++ /dev/null @@ -1,146 +0,0 @@ -#include "status_code.h" -#include "private-status_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_status_code_process_check_ - f_status_t status_code_process_check(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { - - f_number_unsigned_t number = 0; - - { - f_status_t status = status_code_convert_number(main, setting, value, &number); - if (F_status_is_error(status)) return status; - } - - if ((setting->flag & status_code_main_flag_error_e) && F_status_is_error(number) || (setting->flag & status_code_main_flag_warning_e) && F_status_is_warning(number) || (setting->flag & status_code_main_flag_fine_e) && F_status_is_fine(number)) { - f_print_dynamic_raw(f_status_true_s, main->output.to); - } - else { - f_print_dynamic_raw(f_status_false_s, main->output.to); - } - - f_print_dynamic_raw(f_string_eol_s, main->output.to); - - return F_none; - } -#endif // _di_status_code_process_check_ - -#ifndef _di_status_code_process_number_ - f_status_t status_code_process_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { - - f_status_t status = F_none; - - { - f_number_unsigned_t number = 0; - - status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, &number); - - if (status == F_none) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_invalid_name_s, main->context.set.error, f_string_eol_s); - - return F_status_set_error(F_parameter); - } - - if (status == F_data_not || F_status_set_fine(status) == F_parameter) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_invalid_main_s, main->context.set.error, f_string_eol_s); - - return status; - } - } - - f_status_t code = F_none; - - status = setting->status_string_from(value, &code); - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_unknown_name_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_failed_to_convert_s, main->context.set.error, f_string_eol_s); - } - - return status; - } - - if (status == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_unknown_code_s, main->context.set.error, f_string_eol_s); - - return F_none; - } - - if (setting->flag & status_code_main_flag_error_e) { - code = F_status_set_error(code); - } - - if (setting->flag & status_code_main_flag_warning_e) { - code = F_status_set_warning(code); - } - - fl_print_format("%ui%r", main->output.to, code, f_string_eol_s); - - return F_none; - } -#endif // _di_status_code_process_number_ - -#ifndef _di_status_code_process_normal_ - f_status_t status_code_process_normal(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { - - f_number_unsigned_t number = 0; - - f_status_t status = status_code_convert_number(main, setting, value, &number); - if (F_status_is_error(status)) return status; - - f_string_static_t name = f_string_static_t_initialize; - - status = setting->status_string_to((f_status_t) number, &name); - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_unknown_code_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_failed_to_convert_s, main->context.set.error, f_string_eol_s); - } - - return status; - } - - fl_print_format("%Q%r", main->output.to, name, f_string_eol_s); - - return F_none; - } -#endif // _di_status_code_process_normal_ - -#ifndef _di_status_code_convert_number_ - f_status_t status_code_convert_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number) { - - const f_status_t status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, number); - - if (*number > F_status_size_max_with_bits_d) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_out_of_range_s, main->context.set.error, f_string_eol_s); - - return F_status_set_error(F_number_overflow); - } - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_number_negative) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_out_of_range_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, status_code_invalid_number_s, main->context.set.error, f_string_eol_s); - } - - return status; - } - - return F_none; - } -#endif // _di_status_code_convert_number_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/status_code/c/main/process.c b/level_3/status_code/c/main/process.c new file mode 100644 index 0000000..1ee810e --- /dev/null +++ b/level_3/status_code/c/main/process.c @@ -0,0 +1,147 @@ +#include "status_code.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_status_code_process_check_ + void status_code_process_check(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { + + if (!main || !setting) return; + + f_number_unsigned_t number = 0; + + { + status_code_convert_number(main, setting, value, &number); + if (F_status_is_error(setting->state.status)) return; + } + + f_file_stream_lock(main->output.to); + + status_code_print_line_first_unlocked(setting, main->output); + + if ((setting->flag & status_code_main_flag_error_e) && F_status_is_error(number) || (setting->flag & status_code_main_flag_warning_e) && F_status_is_warning(number) || (setting->flag & status_code_main_flag_fine_e) && F_status_is_fine(number)) { + f_print_dynamic_raw(f_status_true_s, main->output.to); + } + else { + f_print_dynamic_raw(f_status_false_s, main->output.to); + } + + f_print_dynamic_raw(f_string_eol_s, main->output.to); + + f_file_stream_unlock(main->output.to); + + setting->state.status = F_none; + } +#endif // _di_status_code_process_check_ + +#ifndef _di_status_code_process_number_ + void status_code_process_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { + + if (!main || !setting) return; + + { + f_number_unsigned_t number = 0; + + setting->state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, &number); + + if (setting->state.status == F_none) { + status_code_print_line_first_data(setting, main->message); + + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_invalid_name_s); + + setting->state.status = F_status_set_error(F_parameter); + + return; + } + + if (setting->state.status == F_data_not || F_status_set_fine(setting->state.status) == F_parameter) { + status_code_print_line_first_data(setting, main->message); + + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_invalid_main_s); + + return; + } + } + + f_status_t code = F_none; + + setting->state.status = setting->status_string_from(value, &code); + + if (F_status_is_error(setting->state.status)) { + status_code_print_line_first_data(setting, main->message); + + if (F_status_set_fine(setting->state.status) == F_data) { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_unknown_name_s); + } + else { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_failed_to_convert_s); + } + + return; + } + + if (setting->state.status == F_data) { + status_code_print_line_first_data(setting, main->message); + + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_unknown_code_s); + + setting->state.status = F_none; + + return; + } + + if (setting->flag & status_code_main_flag_error_e) { + code = F_status_set_error(code); + } + + if (setting->flag & status_code_main_flag_warning_e) { + code = F_status_set_warning(code); + } + + status_code_print_line_first_data(setting, main->message); + + status_code_print_code(setting, main->output, code); + + setting->state.status = F_none; + } +#endif // _di_status_code_process_number_ + +#ifndef _di_status_code_process_normal_ + void status_code_process_normal(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) { + + if (!main || !setting) return; + + f_string_static_t name = f_string_static_t_initialize; + + { + f_number_unsigned_t number = 0; + + status_code_convert_number(main, setting, value, &number); + if (F_status_is_error(setting->state.status)) return; + + setting->state.status = setting->status_string_to((f_status_t) number, &name); + } + + status_code_print_line_first_data(setting, main->message); + + if (F_status_is_error(setting->state.status)) { + if (F_status_set_fine(setting->state.status) == F_data) { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_unknown_code_s); + } + else { + status_code_print_context_value(setting, main->output, main->context.set.error, status_code_failed_to_convert_s); + } + + return; + } + + status_code_print_context_value(setting, main->output, f_color_set_empty_s, name); + + setting->state.status = F_none; + } +#endif // _di_status_code_process_normal_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/status_code/c/main/private-status_code.h b/level_3/status_code/c/main/process.h similarity index 68% rename from level_3/status_code/c/main/private-status_code.h rename to level_3/status_code/c/main/process.h index bfd3a18..daf2f9e 100644 --- a/level_3/status_code/c/main/private-status_code.h +++ b/level_3/status_code/c/main/process.h @@ -5,8 +5,8 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later */ -#ifndef _PRIVATE_status_code_h -#define _PRIVATE_status_code_h +#ifndef _PRIVATE_status_code_process_h +#define _PRIVATE_status_code_process_h #ifdef __cplusplus extern "C" { @@ -34,7 +34,7 @@ extern "C" { * @see fss_status_code_convert_number() */ #ifndef _di_status_code_process_check_ - extern void status_code_process_check(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; + extern void status_code_process_check(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value); #endif // _di_status_code_process_check_ /** @@ -58,7 +58,7 @@ extern "C" { * @see fll_status_string_from() */ #ifndef _di_status_code_process_number_ - extern void status_code_process_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; + extern void status_code_process_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value); #endif // _di_status_code_process_number_ /** @@ -87,39 +87,11 @@ extern "C" { * @see fss_status_code_convert_number() */ #ifndef _di_status_code_process_normal_ - extern void status_code_process_normal(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; + extern void status_code_process_normal(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value); #endif // _di_status_code_process_normal_ -/** - * Convert the value string to the number, reporting any errors. - * - * @param main - * The main program data. - * @param value - * The parameter value to process. - * @param number - * The converted number. - * Will not be updated on error. - * - * This alters setting.state.status: - * F_none on success. - * F_data_not if string starts wth a null (length is 0). - * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. - * F_number (with error bit) if parameter is not a number. - * F_number_negative (with error bit) on negative value. - * F_number_overflow (with error bit) on integer overflow. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: fl_console_parameter_to_number_unsigned(). - * - * @see fl_console_parameter_to_number_unsigned() - */ -#ifndef _di_status_code_convert_number_ - extern void status_code_convert_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number) F_attribute_visibility_internal_d; -#endif // _di_status_code_convert_number_ - #ifdef __cplusplus } // extern "C" #endif -#endif // _PRIVATE_status_code_h +#endif // _PRIVATE_status_code_process_h diff --git a/level_3/status_code/c/main/status_code.c b/level_3/status_code/c/main/status_code.c index 8d3e864..e49f984 100644 --- a/level_3/status_code/c/main/status_code.c +++ b/level_3/status_code/c/main/status_code.c @@ -1,5 +1,4 @@ #include "status_code.h" -#include "private-status_code.h" #ifdef __cplusplus extern "C" { @@ -16,13 +15,13 @@ extern "C" { return; } - if (!setting->state.status_string_from || !setting->state.status_string_to) { + if (!setting->status_string_from || !setting->status_string_to) { - if (!setting->state.status_string_from) { + if (!setting->status_string_from) { status_code_print_error_invalid_callback(setting, main->error, macro_status_code_f(status_string_from)); } - if (!setting->state.status_string_to) { + if (!setting->status_string_to) { status_code_print_error_invalid_callback(setting, main->error, macro_status_code_f(status_string_to)); } @@ -51,7 +50,7 @@ extern "C" { return; } - f_status_t status2 = F_none; + f_status_t status = F_none; if (setting->flag & status_code_main_flag_number_e) { if (main->pipe & fll_program_data_pipe_input_e) { @@ -77,17 +76,19 @@ extern "C" { main->signal_check = 0; } - status2 = status_code_process_number(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); + status = setting->state.status; - if (F_status_is_error(status2) && setting->state.status == F_none) { - setting->state.status = status2; + status_code_process_number(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); + + if (F_status_is_error_not(setting->state.status)) { + setting->state.status = status; } } // for f_file_stream_unlock(main->output.to); } } - else if (setting->flag & status_code_main_flag_error_e || setting->flag & status_code_main_flag_warning_e || setting->flag & status_code_main_flag_fine_e) { + else if ((setting->flag & status_code_main_flag_error_e) || (setting->flag & status_code_main_flag_warning_e) || (setting->flag & status_code_main_flag_fine_e)) { if (main->pipe & fll_program_data_pipe_input_e) { // @todo call status_code_process_check() here for all main from pipe that is space separated. } @@ -111,10 +112,12 @@ extern "C" { main->signal_check = 0; } - status2 = status_code_process_check(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); + status = setting->state.status; + + status_code_process_check(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); - if (F_status_is_error(status2) && setting->state.status == F_none) { - setting->state.status = status2; + if (F_status_is_error_not(setting->state.status)) { + setting->state.status = status; } } // for @@ -145,10 +148,12 @@ extern "C" { main->signal_check = 0; } - status2 = status_code_process_normal(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); + status = setting->state.status; + + status_code_process_normal(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); - if (F_status_is_error(status2) && setting->state.status == F_none) { - setting->state.status = status2; + if (F_status_is_error_not(setting->state.status)) { + setting->state.status = status; } } // for diff --git a/level_3/status_code/c/main/status_code.h b/level_3/status_code/c/main/status_code.h index 250c522..4271006 100644 --- a/level_3/status_code/c/main/status_code.h +++ b/level_3/status_code/c/main/status_code.h @@ -42,11 +42,14 @@ #include // Status Code includes. -#include -#include -#include +#include +#include +#include #include +#include #include +#include +#include #ifdef __cplusplus extern "C" { diff --git a/level_3/status_code/data/build/settings b/level_3/status_code/data/build/settings index 64e8a65..784ee63 100644 --- a/level_3/status_code/data/build/settings +++ b/level_3/status_code/data/build/settings @@ -25,10 +25,10 @@ build_libraries-individual -lfll_error -lfll_print -lfll_program -lfll_status_st build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll -build_sources_library main/status_code.c main/common.c main/common-print.c main/common-string.c main/common-type.c main/print.c main/private-status_code.c +build_sources_library main/status_code.c main/common.c main/common/print.c main/common/string.c main/common/type.c main/convert.c main/print.c main/print-error.c main/process.c build_sources_library fss/status_code.c fss/common.c -build_sources_headers main/status_code.h main/common.h main/common-print.h main/common-string.h main/common-type.h main/print.h +build_sources_headers main/status_code.h main/common.h main/common/print.h main/common/string.h main/common/type.h main/convert.h main/print.h main/print-error.h main/process.h build_sources_headers fss/status_code.h fss/common.h build_sources_documentation man diff --git a/level_3/utf8/c/main/bytesequence.c b/level_3/utf8/c/main/bytesequence.c index 74e9d9b..d2747fc 100644 --- a/level_3/utf8/c/main/bytesequence.c +++ b/level_3/utf8/c/main/bytesequence.c @@ -26,7 +26,7 @@ extern "C" { if (setting->state.status == F_failure || setting->state.status == F_utf_not || setting->state.status == F_complete_not_utf || setting->state.status == F_utf_fragment || setting->state.status == F_valid_not) { valid_not = F_true; - utf8_print_character_invalid(setting, main->output, sequence); + utf8_print_data_character_invalid(setting, main->output, sequence); } else { setting->state.status = F_status_set_error(setting->state.status); @@ -38,13 +38,13 @@ extern "C" { } else if (!(setting->flag & utf8_main_flag_verify_e)) { if (setting->mode & utf8_mode_to_bytesequence_e) { - utf8_print_bytesequence(setting, main->output, sequence); + utf8_print_data_bytesequence(setting, main->output, sequence); } else if (setting->mode & utf8_mode_to_codepoint_e) { - utf8_print_codepoint(setting, main->output, codepoint); + utf8_print_data_codepoint(setting, main->output, codepoint); } else { - utf8_print_combining_or_width(setting, main->output, sequence); + utf8_print_data_combining_or_width(setting, main->output, sequence); } } diff --git a/level_3/utf8/c/main/bytesequence.h b/level_3/utf8/c/main/bytesequence.h index 857187c..194ded0 100644 --- a/level_3/utf8/c/main/bytesequence.h +++ b/level_3/utf8/c/main/bytesequence.h @@ -34,7 +34,7 @@ extern "C" { * Errors (with error bit) from: f_utf_unicode_to() */ #ifndef _di_utf8_convert_bytesequence_ - extern void utf8_convert_bytesequence(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t sequence) F_attribute_visibility_internal_d; + extern void utf8_convert_bytesequence(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t sequence); #endif // _di_utf8_convert_bytesequence_ /** @@ -61,7 +61,7 @@ extern "C" { * @see utf8_detect_codepoint() */ #ifndef _di_utf8_process_file_bytesequence_ - extern void utf8_process_file_bytesequence(fll_program_data_t * const main, utf8_setting_t * const setting, const f_file_t file) F_attribute_visibility_internal_d; + extern void utf8_process_file_bytesequence(fll_program_data_t * const main, utf8_setting_t * const setting, const f_file_t file); #endif // _di_utf8_process_file_bytesequence_ #ifdef __cplusplus diff --git a/level_3/utf8/c/main/codepoint.c b/level_3/utf8/c/main/codepoint.c index 97a6688..dde1724 100644 --- a/level_3/utf8/c/main/codepoint.c +++ b/level_3/utf8/c/main/codepoint.c @@ -35,7 +35,7 @@ extern "C" { if (setting->state.status == F_failure || setting->state.status == F_utf_not || setting->state.status == F_complete_not_utf || setting->state.status == F_utf_fragment || setting->state.status == F_valid_not) { valid_not = F_true; - utf8_print_character_invalid(setting, main->output, unicode); + utf8_print_data_character_invalid(setting, main->output, unicode); } else { setting->state.status = F_status_set_error(setting->state.status); @@ -47,7 +47,7 @@ extern "C" { } else if (!(setting->flag & utf8_main_flag_verify_e)) { if (setting->mode & utf8_mode_to_codepoint_e) { - utf8_print_codepoint(setting, main->output, codepoint); + utf8_print_data_codepoint(setting, main->output, codepoint); } else { f_char_t byte[4] = { 0, 0, 0, 0 }; @@ -60,19 +60,19 @@ extern "C" { utf8_print_error_encode(setting, main->error, codepoint); } else { - utf8_print_combining_or_width_invalid(setting, main->output); + utf8_print_data_combining_or_width_invalid(setting, main->output); } } else if (setting->mode & utf8_mode_to_bytesequence_e) { setting->state.status = F_none; unicode.used = macro_f_utf_byte_width(unicode.string[0]); - utf8_print_bytesequence(setting, main->output, unicode); + utf8_print_data_bytesequence(setting, main->output, unicode); } else { setting->state.status = F_none; - utf8_print_combining_or_width(setting, main->output, unicode); + utf8_print_data_combining_or_width(setting, main->output, unicode); } } } @@ -80,7 +80,7 @@ extern "C" { else if (*mode == utf8_codepoint_mode_bad_end_e) { setting->state.status = F_none; - utf8_print_character_invalid(setting, main->output, unicode); + utf8_print_data_character_invalid(setting, main->output, unicode); } else { setting->state.status = F_none; @@ -134,7 +134,7 @@ extern "C" { if (setting->state.status == F_number || setting->state.status == F_utf_not || setting->state.status == F_complete_not_utf || setting->state.status == F_utf_fragment || setting->state.status == F_number_decimal || setting->state.status == F_number_negative || setting->state.status == F_number_positive || setting->state.status == F_number_overflow) { valid_not = F_true; - utf8_print_character_invalid(setting, main->output, hex); + utf8_print_data_character_invalid(setting, main->output, hex); } else { setting->state.status = F_status_set_error(setting->state.status); @@ -154,20 +154,20 @@ extern "C" { } if (setting->mode & utf8_mode_to_bytesequence_e) { - utf8_print_raw_bytesequence(setting, main->output, raw, width); + utf8_print_data_raw_bytesequence(setting, main->output, raw, width); } else if (setting->mode & utf8_mode_to_codepoint_e) { - utf8_print_raw_codepoint(setting, main->output, setting->text); + utf8_print_data_raw_codepoint(setting, main->output, setting->text); } else { - utf8_print_raw_combining_or_width(setting, main->output, width); + utf8_print_data_raw_combining_or_width(setting, main->output, width); } } } else if (*mode == utf8_codepoint_mode_bad_end_e) { setting->state.status = F_none; - utf8_print_character_invalid(setting, main->output, hex); + utf8_print_data_character_invalid(setting, main->output, hex); } else { setting->state.status = F_none; diff --git a/level_3/utf8/c/main/codepoint.h b/level_3/utf8/c/main/codepoint.h index c8e7c7b..45fa9fe 100644 --- a/level_3/utf8/c/main/codepoint.h +++ b/level_3/utf8/c/main/codepoint.h @@ -37,7 +37,7 @@ extern "C" { * @see f_utf_unicode_to() */ #ifndef _di_utf8_convert_codepoint_ - extern void utf8_convert_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t unicode, uint8_t *mode) F_attribute_visibility_internal_d; + extern void utf8_convert_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t unicode, uint8_t *mode); #endif // _di_utf8_convert_codepoint_ /** @@ -65,7 +65,7 @@ extern "C" { * @see fl_conversion_dynamic_to_unsigned_detect() */ #ifndef _di_utf8_convert_raw_ - extern void utf8_convert_raw(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t hex, uint8_t *mode) F_attribute_visibility_internal_d; + extern void utf8_convert_raw(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t hex, uint8_t *mode); #endif // _di_utf8_convert_raw_ /** @@ -88,7 +88,7 @@ extern "C" { * Errors (with error bit) from: f_utf_is_whitespace() */ #ifndef _di_utf8_detect_codepoint_ - extern void utf8_detect_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t unicode, uint8_t *mode) F_attribute_visibility_internal_d; + extern void utf8_detect_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_string_static_t unicode, uint8_t *mode); #endif // _di_utf8_detect_codepoint_ /** @@ -115,7 +115,7 @@ extern "C" { * @see utf8_detect_codepoint() */ #ifndef _di_utf8_process_file_codepoint_ - extern void utf8_process_file_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_file_t file) F_attribute_visibility_internal_d; + extern void utf8_process_file_codepoint(fll_program_data_t * const main, utf8_setting_t * const setting, const f_file_t file); #endif // _di_utf8_process_file_codepoint_ #ifdef __cplusplus diff --git a/level_3/utf8/c/main/common.c b/level_3/utf8/c/main/common.c index 22e2c78..5e55a3f 100644 --- a/level_3/utf8/c/main/common.c +++ b/level_3/utf8/c/main/common.c @@ -25,11 +25,10 @@ extern "C" { if (!main || !setting) return; - setting->flag = 0; - f_console_parameter_process(arguments, &main->parameters, &setting->state, 0); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_console_parameter_process)); return; @@ -50,6 +49,7 @@ extern "C" { setting->state.status = fll_program_parameter_process_context(choices, modes, F_true, main); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(fll_program_parameter_process_context)); return; @@ -81,6 +81,7 @@ extern "C" { setting->state.status = fll_program_parameter_process_verbosity(choices, verbosity, F_true, main); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(fll_program_parameter_process_verbosity)); return; @@ -96,6 +97,7 @@ extern "C" { setting->state.status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_console_parameter_prioritize_right)); return; @@ -121,6 +123,7 @@ extern "C" { setting->state.status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_console_parameter_prioritize_right)); return; @@ -198,6 +201,7 @@ extern "C" { setting->state.status = f_string_dynamics_increase_by(1, &setting->path_files_to); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_string_dynamics_increase_by)); return; @@ -208,6 +212,7 @@ extern "C" { setting->state.status = f_string_dynamic_append_nulless(main->parameters.arguments.array[main->parameters.array[utf8_parameter_to_file_e].values.array[0]], &setting->path_files_to.array[0]); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_string_dynamic_append_nulless)); return; @@ -226,7 +231,7 @@ extern "C" { setting->flag |= utf8_main_flag_file_to_e; } else { - utf8_print_line_first_locked(setting, main->error); + utf8_print_line_first(setting, main->message); utf8_print_error_parameter_file_name_empty(setting, main->error, main->parameters.array[utf8_parameter_to_file_e].values.array[0]); setting->state.status = F_status_set_error(F_parameter); @@ -237,7 +242,7 @@ extern "C" { else if (main->parameters.array[utf8_parameter_to_file_e].result & f_console_result_found_e) { setting->state.status = F_status_set_error(F_parameter); - utf8_print_line_first_locked(setting, main->error); + utf8_print_line_first(setting, main->message); fll_program_print_error_parameter_missing_value(main->error, f_console_symbol_long_normal_s, utf8_long_to_file_s); return; @@ -253,6 +258,7 @@ extern "C" { setting->state.status = f_string_dynamics_increase_by(main->parameters.array[utf8_parameter_from_file_e].values.used, &setting->path_files_from); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_string_dynamics_increase_by)); return; @@ -271,7 +277,7 @@ extern "C" { setting->state.status = f_string_dynamic_append_nulless(main->parameters.arguments.array[index], &setting->path_files_from.array[i]); if (F_status_is_error(setting->state.status)) { - utf8_print_line_first_locked(setting, main->error); + utf8_print_line_first(setting, main->message); fll_error_print(main->error, F_status_set_fine(setting->state.status), macro_utf8_f(f_string_dynamic_append_nulless), fll_error_file_flag_fallback_e); break; @@ -302,7 +308,7 @@ extern "C" { else if (main->parameters.array[utf8_parameter_from_file_e].result & f_console_result_found_e) { setting->state.status = F_status_set_error(F_parameter); - utf8_print_line_first_locked(setting, main->error); + utf8_print_line_first(setting, main->message); fll_program_print_error_parameter_missing_value(main->error, f_console_symbol_long_normal_s, utf8_long_from_file_s); return; @@ -317,6 +323,7 @@ extern "C" { setting->state.status = f_string_dynamics_increase_by(main->parameters.remaining.used, &setting->remaining); if (F_status_is_error(setting->state.status)) { + utf8_print_line_first(setting, main->message); utf8_print_error(setting, main->error, macro_utf8_f(f_string_dynamics_increase_by)); return; @@ -336,7 +343,7 @@ extern "C" { if (!(main->parameters.array[utf8_parameter_from_file_e].result & f_console_result_found_e) && !((main->pipe & fll_program_data_pipe_input_e) || main->parameters.remaining.used)) { setting->state.status = F_status_set_error(F_parameter); - utf8_print_line_first_locked(setting, main->error); + utf8_print_line_first(setting, main->message); utf8_print_error_no_from(setting, main->error); return; @@ -353,10 +360,27 @@ extern "C" { } if (main->parameters.array[utf8_parameter_headers_e].result & f_console_result_found_e) { - setting->flag |= utf8_main_flag_header_e; + if (main->parameters.array[utf8_parameter_separate_e].result & f_console_result_found_e) { + if (main->parameters.array[utf8_parameter_headers_e].location < main->parameters.array[utf8_parameter_separate_e].location) { + setting->flag |= utf8_main_flag_separate_e; + } + else if (main->parameters.array[utf8_parameter_headers_e].location == main->parameters.array[utf8_parameter_separate_e].location) { + if (main->parameters.array[utf8_parameter_headers_e].location_sub < main->parameters.array[utf8_parameter_separate_e].location_sub) { + setting->flag |= utf8_main_flag_separate_e; + } + else { + setting->flag |= utf8_main_flag_header_e; + } + } + else { + setting->flag |= utf8_main_flag_header_e; + } + } + else { + setting->flag |= utf8_main_flag_header_e; + } } - - if (main->parameters.array[utf8_parameter_separate_e].result & f_console_result_found_e) { + else if (main->parameters.array[utf8_parameter_separate_e].result & f_console_result_found_e) { setting->flag |= utf8_main_flag_separate_e; } diff --git a/level_3/utf8/c/main/common-print.c b/level_3/utf8/c/main/common/print.c similarity index 96% rename from level_3/utf8/c/main/common-print.c rename to level_3/utf8/c/main/common/print.c index fc7a94d..9a49594 100644 --- a/level_3/utf8/c/main/common-print.c +++ b/level_3/utf8/c/main/common/print.c @@ -1,4 +1,4 @@ -#include "utf8.h" +#include "../utf8.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/utf8/c/main/common-print.h b/level_3/utf8/c/main/common/print.h similarity index 100% rename from level_3/utf8/c/main/common-print.h rename to level_3/utf8/c/main/common/print.h diff --git a/level_3/utf8/c/main/common-string.c b/level_3/utf8/c/main/common/string.c similarity index 99% rename from level_3/utf8/c/main/common-string.c rename to level_3/utf8/c/main/common/string.c index b63bc5a..471174d 100644 --- a/level_3/utf8/c/main/common-string.c +++ b/level_3/utf8/c/main/common/string.c @@ -1,4 +1,4 @@ -#include "utf8.h" +#include "../utf8.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/utf8/c/main/common-string.h b/level_3/utf8/c/main/common/string.h similarity index 100% rename from level_3/utf8/c/main/common-string.h rename to level_3/utf8/c/main/common/string.h diff --git a/level_3/utf8/c/main/common-type.c b/level_3/utf8/c/main/common/type.c similarity index 79% rename from level_3/utf8/c/main/common-type.c rename to level_3/utf8/c/main/common/type.c index f0f663a..d0e8414 100644 --- a/level_3/utf8/c/main/common-type.c +++ b/level_3/utf8/c/main/common/type.c @@ -1,4 +1,4 @@ -#include "utf8.h" +#include "../utf8.h" #ifdef __cplusplus extern "C" { diff --git a/level_3/utf8/c/main/common-type.h b/level_3/utf8/c/main/common/type.h similarity index 96% rename from level_3/utf8/c/main/common-type.h rename to level_3/utf8/c/main/common/type.h index 8d618e0..72297ed 100644 --- a/level_3/utf8/c/main/common-type.h +++ b/level_3/utf8/c/main/common/type.h @@ -69,6 +69,7 @@ extern "C" { * - header: Enable printing of headers. * - help: Print help. * - pipe: Use the input pipe. + * - print_first: When set, the first character printing logic is to be processed (this is usually automatic). * - separate: Enable printing of separators. * - strip_invalid: Using strip invalid character mode. * - verify: Using verify mode. @@ -83,10 +84,11 @@ extern "C" { utf8_main_flag_header_e = 0x8, utf8_main_flag_help_e = 0x10, utf8_main_flag_pipe_e = 0x20, - utf8_main_flag_separate_e = 0x40, - utf8_main_flag_strip_invalid_e = 0x80, - utf8_main_flag_verify_e = 0x100, - utf8_main_flag_version_e = 0x200, + utf8_main_flag_print_first_e = 0x40, + utf8_main_flag_separate_e = 0x80, + utf8_main_flag_strip_invalid_e = 0x100, + utf8_main_flag_verify_e = 0x200, + utf8_main_flag_version_e = 0x400, }; // enum #endif // _di_utf8_main_flag_e_ @@ -246,7 +248,7 @@ extern "C" { #define utf8_setting_t_initialize \ { \ utf8_mode_from_bytesequence_e | utf8_mode_to_codepoint_e, \ - utf8_main_flag_none_e, \ + utf8_main_flag_print_first_e, \ f_state_t_initialize, \ f_color_set_t_initialize, \ f_color_set_t_initialize, \ diff --git a/level_3/utf8/c/main/print-data.c b/level_3/utf8/c/main/print-data.c new file mode 100644 index 0000000..13de283 --- /dev/null +++ b/level_3/utf8/c/main/print-data.c @@ -0,0 +1,321 @@ +#include "utf8.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_utf8_print_data_bytesequence_ + f_status_t utf8_print_data_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { + + if (!setting) return F_output_not; + + fl_print_format("%r%r%r", print.to, setting->prepend, sequence, setting->append); + + return F_none; + } +#endif // _di_utf8_print_data_bytesequence_ + +#ifndef _di_utf8_print_data_character_invalid_ + f_status_t utf8_print_data_character_invalid(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid) { + + if (!setting) return F_output_not; + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + if (!invalid.used) return F_output_not; + + if ((setting->mode & utf8_mode_to_combining_e) || (setting->mode & utf8_mode_to_width_e)) { + utf8_print_data_combining_or_width(setting, print, invalid); + } + else if (setting->mode & utf8_mode_to_bytesequence_e) { + fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, invalid, setting->valid_not, setting->append); + } + else if (setting->mode & utf8_mode_from_codepoint_e) { + fl_print_format("%r%[%Q%]%r", print.to, setting->prepend, setting->valid_not, invalid, setting->valid_not, setting->append); + } + else { + fl_print_format("%r%[0x", print.to, setting->prepend, setting->valid_not); + + for (uint8_t i = 0; i < invalid.used; ++i) { + fl_print_format("%02_uii", print.to, (uint8_t) invalid.string[i]); + } // for + + fl_print_format("%]%r", print.to, setting->valid_not, setting->append); + } + + return F_none; + } +#endif // _di_utf8_print_data_character_invalid_ + +#ifndef _di_utf8_print_data_codepoint_ + f_status_t utf8_print_data_codepoint(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint) { + + if (!setting) return F_output_not; + + if (codepoint < 0x10000) { + fl_print_format("%rU+%04_U%r", print.to, setting->prepend, codepoint, setting->append); + } + else if (codepoint < 0x100000) { + fl_print_format("%rU+%05_U%r", print.to, setting->prepend, codepoint, setting->append); + } + else { + fl_print_format("%rU+%06_U%r", print.to, setting->prepend, codepoint, setting->append); + } + + return F_none; + } +#endif // _di_utf8_print_data_codepoint_ + +#ifndef _di_utf8_print_data_combining_or_width_ + f_status_t utf8_print_data_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { + + if (!setting) return F_output_not; + + if (setting->mode & utf8_mode_to_combining_e) { + f_status_t status = f_utf_is_combining(sequence.string, sequence.used); + + if (status == F_true) { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_combining_is_s, setting->append); + } + else if (status == F_false) { + status = f_utf_is_private(sequence.string, sequence.used); + + if (status == F_true) { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_unknown_s, setting->append); + } + else if (setting->mode & utf8_mode_to_width_e) { + utf8_print_data_width(setting, print, sequence); + } + else { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_combining_not_s, setting->append); + } + } + else { + utf8_print_data_combining_or_width_invalid(setting, print); + } + } + else if (setting->mode & utf8_mode_to_width_e) { + utf8_print_data_width(setting, print, sequence); + } + + return F_none; + } +#endif // _di_utf8_print_data_combining_or_width_ + +#ifndef _di_utf8_print_data_combining_or_width_invalid_ + f_status_t utf8_print_data_combining_or_width_invalid(utf8_setting_t * const setting, const fl_print_t print) { + + if (!setting) return F_output_not; + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, utf8_string_unknown_s, setting->valid_not, setting->append); + + return F_none; + } +#endif // _di_utf8_print_data_combining_or_width_invalid_ + +#ifndef _di_utf8_print_data_raw_bytesequence_ + f_status_t utf8_print_data_raw_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_utf_char_t raw, const uint8_t width) { + + if (!setting) return F_status_set_error(F_output_not); + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + f_string_static_t character = macro_f_string_static_t_initialize(0, 0, width); + + f_char_t byte[character.used + 1]; + character.string = byte; + byte[character.used] = 0; + + if (raw) { + if (width == 1) { + byte[0] = macro_f_utf_char_t_to_char_4_be(raw); + } + else if (width == 2) { + byte[0] = macro_f_utf_char_t_to_char_3_be(raw); + byte[1] = macro_f_utf_char_t_to_char_4_be(raw); + } + else if (width == 3) { + byte[0] = macro_f_utf_char_t_to_char_2_be(raw); + byte[1] = macro_f_utf_char_t_to_char_3_be(raw); + byte[2] = macro_f_utf_char_t_to_char_4_be(raw); + } + else { + byte[0] = macro_f_utf_char_t_to_char_1_be(raw); + byte[1] = macro_f_utf_char_t_to_char_2_be(raw); + byte[2] = macro_f_utf_char_t_to_char_3_be(raw); + byte[3] = macro_f_utf_char_t_to_char_4_be(raw); + } + } + else { + memset(byte, 0, sizeof(f_char_t) * width); + } + + fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, character, setting->valid_not, setting->append); + + return F_none; + } +#endif // _di_utf8_print_data_raw_bytesequence_ + +#ifndef _di_utf8_print_data_raw_codepoint_ + f_status_t utf8_print_data_raw_codepoint(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t raw) { + + if (!setting) return F_status_set_error(F_output_not); + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, raw, setting->valid_not, setting->append); + + return F_none; + } +#endif // _di_utf8_print_data_raw_codepoint_ + +#ifndef _di_utf8_print_data_raw_combining_or_width_ + f_status_t utf8_print_data_raw_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const uint8_t width) { + + if (!setting) return F_status_set_error(F_output_not); + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + if (setting->mode & utf8_mode_to_combining_e) { + utf8_print_data_combining_or_width_invalid(setting, print); + } + else if (setting->mode & utf8_mode_to_width_e) { + const f_string_static_t *character = 0; + + switch (width) { + case 1: + character = &utf8_string_width_1_s; + break; + + case 2: + character = &utf8_string_width_2_s; + break; + + case 3: + character = &utf8_string_width_3_s; + break; + + case 4: + character = &utf8_string_width_4_s; + break; + + default: + character = &utf8_string_width_0_s; + } + + fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, *character, setting->valid_not, setting->append); + } + + return F_none; + } +#endif // _di_utf8_print_data_raw_combining_or_width_ + +#ifndef _di_utf8_print_data_section_header_file_ + f_status_t utf8_print_data_section_header_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t name, const f_array_length_t index) { + + if (!setting) return F_status_set_error(F_output_not); + if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; + if (setting->flag & utf8_main_flag_verify_e) return F_output_not; + + f_file_stream_lock(print.to); + + if (!setting->line_first.used || index) { + f_print_dynamic_raw(f_string_eol_s, print.to); + } + + if (setting->flag & utf8_main_flag_header_e) { + fl_print_format("%[File%] ", print.to, print.set->title, print.set->title); + + if (setting->flag & utf8_main_flag_file_to_e) { + fl_print_format("%[%Q%]: %Q.%r", print.to, print.set->notable, name, print.set->notable, setting->path_files_to.array[0], f_string_eol_s); + } + else { + fl_print_format("%[%Q%]:%r", print.to, print.set->notable, name, print.set->notable, f_string_eol_s); + } + } + + f_file_stream_unlock(print.to); + + return F_none; + } +#endif // _di_utf8_print_data_section_header_file_ + +#ifndef _di_utf8_print_data_section_header_parameter_ + f_status_t utf8_print_data_section_header_parameter(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index) { + + if (!setting) return F_status_set_error(F_output_not); + if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; + if (setting->flag & utf8_main_flag_verify_e) return F_output_not; + + f_file_stream_lock(print.to); + + if (setting->flag & utf8_main_flag_header_e) { + if ((setting->flag & (utf8_main_flag_pipe_e | utf8_main_flag_file_from_e)) || index) { + f_print_dynamic_raw(f_string_eol_s, print.to); + } + + fl_print_format("%[Parameter%] ", print.to, print.set->title, print.set->title); + fl_print_format("%[%ul%]:%r", print.to, print.set->notable, index, print.set->notable, f_string_eol_s); + } + else { + if ((setting->flag & (utf8_main_flag_pipe_e | utf8_main_flag_file_from_e)) || index) { + f_print_dynamic_raw(f_string_eol_s, print.to); + } + } + + f_file_stream_unlock(print.to); + + return F_none; + } +#endif // _di_utf8_print_data_section_header_parameter_ + +#ifndef _di_utf8_print_data_section_header_pipe_ + f_status_t utf8_print_data_section_header_pipe(utf8_setting_t * const setting, const fl_print_t print) { + + if (!setting) return F_status_set_error(F_output_not); + if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; + if (setting->flag & utf8_main_flag_verify_e) return F_output_not; + + if (setting->flag & utf8_main_flag_header_e) { + fll_print_format("%[Pipe%]:%r", print.to, print.set->title, print.set->title, f_string_eol_s); + } + + return F_none; + } +#endif // _di_utf8_print_data_section_header_pipe_ + +#ifndef _di_utf8_print_data_width_ + f_status_t utf8_print_data_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + f_status_t status = f_utf_is_wide(sequence.string, sequence.used); + + if (status == F_true) { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_2_s, setting->append); + + return F_output_not; + } + + if (status == F_false) { + status = f_utf_is_graph(sequence.string, sequence.used); + + if (status == F_true) { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_1_s, setting->append); + + return F_output_not; + } + + if (status == F_false) { + fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_0_s, setting->append); + + return F_output_not; + } + } + + utf8_print_data_combining_or_width_invalid(setting, print); + + return F_none; + } +#endif // _di_utf8_print_data_width_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/utf8/c/main/print-data.h b/level_3/utf8/c/main/print-data.h new file mode 100644 index 0000000..c8e0663 --- /dev/null +++ b/level_3/utf8/c/main/print-data.h @@ -0,0 +1,292 @@ +/** + * FLL - Level 3 + * + * Project: UTF8 + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + */ +#ifndef _utf8_print_data_h +#define _utf8_print_data_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Print the byte sequence character (such as '豸'). + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param sequence + * A byte sequences representing a single character to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_bytesequence_ + extern f_status_t utf8_print_data_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); +#endif // _di_utf8_print_data_bytesequence_ + +/** + * Print an invalid character either as a Unicode codeblock or as a byte sequence. + * + * This handles whether or not the invalid character should be printed or not based on program parameters. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param invalid + * The byte sequence string or unicode codepoint string representing a single character to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see utf8_print_combining_or_width() + */ +#ifndef _di_utf8_print_data_character_invalid_ + extern f_status_t utf8_print_data_character_invalid(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid); +#endif // _di_utf8_print_data_character_invalid_ + +/** + * Print the codepoint number as a codepoint string (such as U+8C78). + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param codepoint + * The codepoint to print. + * This is the code that represents a single character. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_codepoint_ + extern f_status_t utf8_print_data_codepoint(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint); +#endif // _di_utf8_print_data_codepoint_ + +/** + * Print the width or combining state of the given character. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param sequence + * A byte sequences representing a single character to print. + * + * @see utf8_print_width() + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_combining_or_width_ + extern f_status_t utf8_print_data_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); +#endif // _di_utf8_print_data_combining_or_width_ + +/** + * Print an error regarding the width or combining state of a some character. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_combining_or_width_invalid_ + extern f_status_t utf8_print_data_combining_or_width_invalid(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_data_combining_or_width_invalid_ + +/** + * Print the raw character data (binary / byte sequence). + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param raw + * The raw string in integer format. + * @param width + * The width the raw character represents (a value inclusively from 1 to 4). + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_raw_bytesequence_ + extern f_status_t utf8_print_data_raw_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_utf_char_t raw, const uint8_t width); +#endif // _di_utf8_print_data_raw_bytesequence_ + +/** + * Print the raw character data (codepoint). + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param raw + * The raw string already in codepoint format. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_raw_codepoint_ + extern f_status_t utf8_print_data_raw_codepoint(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t raw); +#endif // _di_utf8_print_data_raw_codepoint_ + +/** + * Print the width or combining state of the for a raw character. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param width + * The pre-calculated width. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see utf8_print_data_width() + */ +#ifndef _di_utf8_print_data_raw_combining_or_width_ + extern f_status_t utf8_print_data_raw_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const uint8_t width); +#endif // _di_utf8_print_data_raw_combining_or_width_ + +/** + * Print the input file section header. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param name + * The name of the file. + * @param index + * The index position of the file. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_section_header_file_ + extern f_status_t utf8_print_data_section_header_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t name, const f_array_length_t index); +#endif // _di_utf8_print_data_section_header_file_ + +/** + * Print the input parameter section header. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param index + * The index position of the parameter. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_section_header_parameter_ + extern f_status_t utf8_print_data_section_header_parameter(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index); +#endif // _di_utf8_print_data_section_header_parameter_ + +/** + * Print the input pipe section header. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_section_header_pipe_ + extern f_status_t utf8_print_data_section_header_pipe(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_data_section_header_pipe_ + +/** + * Print the width of the given character. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param sequence + * A byte sequences representing a single character whose width is to be printed. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_utf8_print_data_width_ + extern f_status_t utf8_print_data_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); +#endif // _di_utf8_print_data_width_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _utf8_print_data_h diff --git a/level_3/utf8/c/main/print-error.c b/level_3/utf8/c/main/print-error.c new file mode 100644 index 0000000..17fd254 --- /dev/null +++ b/level_3/utf8/c/main/print-error.c @@ -0,0 +1,156 @@ +#include "utf8.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_utf8_print_error_ + f_status_t utf8_print_error(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fll_error_print(print, F_status_set_fine(setting->state.status), function, fll_error_file_flag_fallback_e); + + return F_none; + } +#endif // _di_utf8_print_error_ + +#ifndef _di_utf8_print_error_decode_ + f_status_t utf8_print_error_decode(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + fl_print_format("%[%QFailed to decode character code '%]", print.to, print.set->error, print.prefix, print.set->error); + + if (invalid.used) { + fl_print_format("%[0x", print.to, print.set->notable); + + for (uint8_t i = 0; i < invalid.used; ++i) { + fl_print_format("%02_uii", print.to, (uint8_t) invalid.string[i]); + } // for + + fl_print_format("%]", print.to, print.set->notable); + } + + if (F_status_set_fine(setting->state.status) == F_utf_not) { + fl_print_format("%[', not a valid UTF-8 character sequence.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + else if (F_status_set_fine(setting->state.status) == F_complete_not_utf) { + fl_print_format("%[', invalid UTF-8 (truncated).%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + else if (F_status_set_fine(setting->state.status) == F_utf_fragment) { + fl_print_format("%[', invalid UTF-8 fragment.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + else { + fl_print_format("%[', error status code%] ", print.to, print.set->error, print.set->error, f_string_eol_s); + fl_print_format("%[%ui%]", print.to, print.set->notable, F_status_set_fine(setting->state.status), print.set->notable); + fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + + return F_none; + } +#endif // _di_utf8_print_error_decode_ + +#ifndef _di_utf8_print_error_encode_ + f_status_t utf8_print_error_encode(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; + + fl_print_format("%[%QFailed to encode Unicode codepoint '%]", print.to, print.set->error, print.prefix, print.set->error); + fl_print_format("%[U+%_U%]", print.to, print.set->notable, codepoint, print.set->notable); + + if (F_status_set_fine(setting->state.status) == F_utf_not) { + fl_print_format("%[', not a valid Unicode codepoint.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + else { + fl_print_format("%[', error status code%] ", print.to, print.set->error, print.set->error, f_string_eol_s); + fl_print_format("%[%ui%]", print.to, print.set->notable, F_status_set_fine(setting->state.status), print.set->notable); + fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + } + + return F_none; + } +#endif // _di_utf8_print_error_encode_ + +#ifndef _di_utf8_print_error_file_ + f_status_t utf8_print_error_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fll_error_file_print(print, F_status_set_fine(setting->state.status), function, fll_error_file_flag_fallback_e, name, operation, type); + + return F_none; + } +#endif // _di_utf8_print_error_file_ + +#ifndef _di_utf8_print_error_no_from_ + f_status_t utf8_print_error_no_from(utf8_setting_t * const setting, const fl_print_t print) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + fll_print_format("%[%QNo from sources are specified, please pipe data, designate a file, or add parameters.%]%r", print.to, print.set->error, print.prefix, print.set->error, f_string_eol_s); + + return F_none; + } +#endif // _di_utf8_print_error_no_from_ + +#ifndef _di_utf8_print_error_parameter_file_name_empty_ + f_status_t utf8_print_error_parameter_file_name_empty(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print.to); + + fl_print_format("%[%QNo file specified at parameter index%] ", print.to, print.set->error, print.prefix, print.set->error); + fl_print_format("%[%ul%]", print.to, print.set->notable, index, print.set->notable); + fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + + f_file_stream_unlock(print.to); + + return F_none; + } +#endif // _di_utf8_print_error_parameter_file_name_empty_ + +#ifndef _di_utf8_print_error_parameter_file_not_found_ + f_status_t utf8_print_error_parameter_file_not_found(utf8_setting_t * const setting, const fl_print_t print, const bool from, const f_string_static_t name) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print.to); + + fl_print_format("%[%QFailed to find the %r file '%]", print.to, print.set->error, print.prefix, from ? utf8_string_from_s : utf8_string_to_s, print.set->error); + fl_print_format("%[%Q%]", print.to, print.set->notable, name, print.set->notable); + fl_print_format("%['.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); + + f_file_stream_unlock(print.to); + + return F_none; + } +#endif // _di_utf8_print_error_parameter_file_not_found_ + +#ifndef _di_utf8_print_error_parameter_file_to_too_many_ + f_status_t utf8_print_error_parameter_file_to_too_many(utf8_setting_t * const setting, const fl_print_t print) { + + if (!setting) return F_status_set_error(F_output_not); + if (print.verbosity < f_console_verbosity_error_e) return F_output_not; + + utf8_print_line_first(setting, print); + + fll_print_format("%[%QToo many '%r' files specified, there may only be one '%r' file.%]%r", print.to, print.set->error, print.prefix, utf8_string_to_s, utf8_string_to_s, print.set->error, f_string_eol_s); + + return F_none; + } +#endif // _di_utf8_print_error_parameter_file_to_too_many_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/utf8/c/main/print-error.h b/level_3/utf8/c/main/print-error.h new file mode 100644 index 0000000..34ac5dc --- /dev/null +++ b/level_3/utf8/c/main/print-error.h @@ -0,0 +1,221 @@ +/** + * FLL - Level 3 + * + * Project: UTF8 + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + */ +#ifndef _utf8_print_error_h +#define _utf8_print_error_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Print generic error message regarding a function failing in some way. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_print() + */ +#ifndef _di_utf8_print_error_ + extern f_status_t utf8_print_error(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function); +#endif // _di_utf8_print_error_ + +/** + * Print error message when attempt to decode the character failed. + * + * @param main + * The main program data. + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param invalid + * The byte sequence string or unicode codepoint string representing a single character to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fl_print_format() + */ +#ifndef _di_utf8_print_error_decode_ + extern f_status_t utf8_print_error_decode(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid); +#endif // _di_utf8_print_error_decode_ + +/** + * Print error message when attempt to encode the character failed. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates the how and where to print. + * @param codepoint + * The codepoint that is invalid. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fl_print_format() + */ +#ifndef _di_utf8_print_error_encode_ + extern f_status_t utf8_print_error_encode(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint); +#endif // _di_utf8_print_error_encode_ + +/** + * Print file related error or warning messages. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param function + * The name of the function where the error happened. + * Set to 0 to disable. + * @param name + * The name of the file or directory. + * @param operation + * The operation that fails, such as 'create' or 'access'. + * @param type + * A valid file type code from the fll_error_file_type enum. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_utf8_print_error_file_ + extern f_status_t utf8_print_error_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type); +#endif // _di_utf8_print_error_file_ + +/** + * Print error message for when no sources are provided. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_utf8_print_error_no_from_ + extern f_status_t utf8_print_error_no_from(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_error_no_from_ + +/** + * Print error message for when the file parameter is an empty string. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param index + * The index within the argv[] array where the empty string is found. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + */ +#ifndef _di_utf8_print_error_parameter_file_name_empty_ + extern f_status_t utf8_print_error_parameter_file_name_empty(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index); +#endif // _di_utf8_print_error_parameter_file_name_empty_ + +/** + * Print error message for when no sources are provided in the main program parameters. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * @param from + * If TRUE, then this is a from file (source file). + * If FALSE, then this is a to file (destination file). + * @param name + * The file path name. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + */ +#ifndef _di_utf8_print_error_parameter_file_not_found_ + extern f_status_t utf8_print_error_parameter_file_not_found(utf8_setting_t * const setting, const fl_print_t print, const bool from, const f_string_static_t name); +#endif // _di_utf8_print_error_parameter_file_not_found_ + +/** + * Print error message for when too many 'to' destinations are specified. + * + * @param setting + * The main program settings. + * + * This does not alter setting.state.status. + * @param print + * Designates how printing is to be performed. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_print_format() + * + * @see utf8_print_line_first() + */ +#ifndef _di_utf8_print_error_parameter_file_to_too_many_ + extern f_status_t utf8_print_error_parameter_file_to_too_many(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_error_parameter_file_to_too_many_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _utf8_print_error_h diff --git a/level_3/utf8/c/main/print.c b/level_3/utf8/c/main/print.c index e980832..e6c2e13 100644 --- a/level_3/utf8/c/main/print.c +++ b/level_3/utf8/c/main/print.c @@ -4,270 +4,6 @@ extern "C" { #endif -#ifndef _di_utf8_print_error_ - f_status_t utf8_print_error(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - utf8_print_line_first_locked(setting, print); - fll_error_print(print, F_status_set_fine(setting->state.status), function, fll_error_file_flag_fallback_e); - - return F_none; - } -#endif // _di_utf8_print_error_ - -#ifndef _di_utf8_print_error_decode_ - f_status_t utf8_print_error_decode(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - - utf8_print_line_first_unlocked(setting, print); - - fl_print_format("%[%QFailed to decode character code '%]", print.to, print.set->error, print.prefix, print.set->error); - - if (invalid.used) { - fl_print_format("%[0x", print.to, print.set->notable); - - for (uint8_t i = 0; i < invalid.used; ++i) { - fl_print_format("%02_uii", print.to, (uint8_t) invalid.string[i]); - } // for - - fl_print_format("%]", print.to, print.set->notable); - } - - if (F_status_set_fine(setting->state.status) == F_utf_not) { - fl_print_format("%[', not a valid UTF-8 character sequence.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - else if (F_status_set_fine(setting->state.status) == F_complete_not_utf) { - fl_print_format("%[', invalid UTF-8 (truncated).%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - else if (F_status_set_fine(setting->state.status) == F_utf_fragment) { - fl_print_format("%[', invalid UTF-8 fragment.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - else { - fl_print_format("%[', error status code%] ", print.to, print.set->error, print.set->error, f_string_eol_s); - fl_print_format("%[%ui%]", print.to, print.set->notable, F_status_set_fine(setting->state.status), print.set->notable); - fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - - return F_none; - } -#endif // _di_utf8_print_error_decode_ - -#ifndef _di_utf8_print_error_encode_ - f_status_t utf8_print_error_encode(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - utf8_print_line_first_unlocked(setting, print); - - fl_print_format("%[%QFailed to encode Unicode codepoint '%]", print.to, print.set->error, print.prefix, print.set->error); - fl_print_format("%[U+%_U%]", print.to, print.set->notable, codepoint, print.set->notable); - - if (F_status_set_fine(setting->state.status) == F_utf_not) { - fl_print_format("%[', not a valid Unicode codepoint.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - else { - fl_print_format("%[', error status code%] ", print.to, print.set->error, print.set->error, f_string_eol_s); - fl_print_format("%[%ui%]", print.to, print.set->notable, F_status_set_fine(setting->state.status), print.set->notable); - fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - } - - return F_none; - } -#endif // _di_utf8_print_error_encode_ - -#ifndef _di_utf8_print_error_file_ - f_status_t utf8_print_error_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - utf8_print_line_first_locked(setting, print); - fll_error_file_print(print, F_status_set_fine(setting->state.status), function, fll_error_file_flag_fallback_e, name, operation, type); - - return F_none; - } -#endif // _di_utf8_print_error_file_ - -#ifndef _di_utf8_print_error_no_from_ - f_status_t utf8_print_error_no_from(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - fll_print_format("%[%QNo from sources are specified, please pipe data, designate a file, or add parameters.%]%r", print.to, print.set->error, print.prefix, print.set->error, f_string_eol_s); - - return F_none; - } -#endif // _di_utf8_print_error_no_from_ - -#ifndef _di_utf8_print_error_parameter_file_name_empty_ - f_status_t utf8_print_error_parameter_file_name_empty(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - f_file_stream_lock(print.to); - - utf8_print_line_first_unlocked(setting, print); - - fl_print_format("%[%QNo file specified at parameter index%] ", print.to, print.set->error, print.prefix, print.set->error); - fl_print_format("%[%ul%]", print.to, print.set->notable, index, print.set->notable); - fl_print_format("%[.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_utf8_print_error_parameter_file_name_empty_ - -#ifndef _di_utf8_print_error_parameter_file_not_found_ - f_status_t utf8_print_error_parameter_file_not_found(utf8_setting_t * const setting, const fl_print_t print, const bool from, const f_string_static_t name) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - f_file_stream_lock(print.to); - - utf8_print_line_first_unlocked(setting, print); - - fl_print_format("%[%QFailed to find the %r file '%]", print.to, print.set->error, print.prefix, from ? utf8_string_from_s : utf8_string_to_s, print.set->error); - fl_print_format("%[%Q%]", print.to, print.set->notable, name, print.set->notable); - fl_print_format("%['.%]%r", print.to, print.set->error, print.set->error, f_string_eol_s); - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_utf8_print_error_parameter_file_not_found_ - -#ifndef _di_utf8_print_error_parameter_file_to_too_many_ - f_status_t utf8_print_error_parameter_file_to_too_many(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - utf8_print_line_first_locked(setting, print); - - fll_print_format("%[%QToo many '%r' files specified, there may only be one '%r' file.%]%r", print.to, print.set->error, print.prefix, utf8_string_to_s, utf8_string_to_s, print.set->error, f_string_eol_s); - - return F_none; - } -#endif // _di_utf8_print_error_parameter_file_to_too_many_ - -#ifndef _di_utf8_print_bytesequence_ - f_status_t utf8_print_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { - - if (!setting) return F_output_not; - - fl_print_format("%r%r%r", print.to, setting->prepend, sequence, setting->append); - - return F_none; - } -#endif // _di_utf8_print_bytesequence_ - -#ifndef _di_utf8_print_character_invalid_ - f_status_t utf8_print_character_invalid(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid) { - - if (!setting) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - if (!invalid.used) return F_output_not; - - if ((setting->mode & utf8_mode_to_combining_e) || (setting->mode & utf8_mode_to_width_e)) { - utf8_print_combining_or_width(setting, print, invalid); - } - else if (setting->mode & utf8_mode_to_bytesequence_e) { - fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, invalid, setting->valid_not, setting->append); - } - else if (setting->mode & utf8_mode_from_codepoint_e) { - fl_print_format("%r%[%Q%]%r", print.to, setting->prepend, setting->valid_not, invalid, setting->valid_not, setting->append); - } - else { - fl_print_format("%r%[0x", print.to, setting->prepend, setting->valid_not); - - for (uint8_t i = 0; i < invalid.used; ++i) { - fl_print_format("%02_uii", print.to, (uint8_t) invalid.string[i]); - } // for - - fl_print_format("%]%r", print.to, setting->valid_not, setting->append); - } - - return F_none; - } -#endif // _di_utf8_print_character_invalid_ - -#ifndef _di_utf8_print_codepoint_ - f_status_t utf8_print_codepoint(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint) { - - if (!setting) return F_output_not; - - if (codepoint < 0x10000) { - fl_print_format("%rU+%04_U%r", print.to, setting->prepend, codepoint, setting->append); - } - else if (codepoint < 0x100000) { - fl_print_format("%rU+%05_U%r", print.to, setting->prepend, codepoint, setting->append); - } - else { - fl_print_format("%rU+%06_U%r", print.to, setting->prepend, codepoint, setting->append); - } - - return F_none; - } -#endif // _di_utf8_print_codepoint_ - -#ifndef _di_utf8_print_combining_or_width_ - f_status_t utf8_print_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { - - if (!setting) return F_output_not; - - if (setting->mode & utf8_mode_to_combining_e) { - f_status_t status = f_utf_is_combining(sequence.string, sequence.used); - - if (status == F_true) { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_combining_is_s, setting->append); - } - else if (status == F_false) { - status = f_utf_is_private(sequence.string, sequence.used); - - if (status == F_true) { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_unknown_s, setting->append); - } - else if (setting->mode & utf8_mode_to_width_e) { - utf8_print_width(setting, print, sequence); - } - else { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_combining_not_s, setting->append); - } - } - else { - utf8_print_combining_or_width_invalid(setting, print); - } - } - else if (setting->mode & utf8_mode_to_width_e) { - utf8_print_width(setting, print, sequence); - } - - return F_none; - } -#endif // _di_utf8_print_combining_or_width_ - -#ifndef _di_utf8_print_combining_or_width_invalid_ - f_status_t utf8_print_combining_or_width_invalid(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - - fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, utf8_string_unknown_s, setting->valid_not, setting->append); - - return F_none; - } -#endif // _di_utf8_print_combining_or_width_invalid_ - #ifndef _di_utf8_print_help_ f_status_t utf8_print_help(utf8_setting_t * const setting, const fl_print_t print) { @@ -327,42 +63,24 @@ extern "C" { } #endif // _di_utf8_print_help_ -#ifndef _di_utf8_print_line_first_locked_ - f_status_t utf8_print_line_first_locked(utf8_setting_t * const setting, const fl_print_t print) { +#ifndef _di_utf8_print_line_first_ + f_status_t utf8_print_line_first(utf8_setting_t * const setting, const fl_print_t print) { if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - if (setting->flag & (utf8_main_flag_verify_e | utf8_main_flag_file_to_e)) return F_output_not; - } - - f_print_dynamic_raw(setting->line_first, print.to); + if (setting->flag & utf8_main_flag_print_first_e) { + fll_print_dynamic_raw(setting->line_first, print.to); - return F_none; - } -#endif // _di_utf8_print_line_first_locked_ - -#ifndef _di_utf8_print_line_first_unlocked_ - f_status_t utf8_print_line_first_unlocked(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - if (setting->flag & (utf8_main_flag_verify_e | utf8_main_flag_file_to_e)) return F_output_not; + setting->flag -= utf8_main_flag_print_first_e; } - fll_print_dynamic_raw(setting->line_first, print.to); - return F_none; } -#endif // _di_utf8_print_line_first_unlocked_ +#endif // _di_utf8_print_line_first_ -#ifndef _di_utf8_print_line_last_locked_ - f_status_t utf8_print_line_last_locked(utf8_setting_t * const setting, const fl_print_t print) { +#ifndef _di_utf8_print_line_last_ + f_status_t utf8_print_line_last(utf8_setting_t * const setting, const fl_print_t print) { if (!setting) return F_status_set_error(F_output_not); if (print.verbosity < f_console_verbosity_error_e) return F_output_not; @@ -374,244 +92,9 @@ extern "C" { fll_print_dynamic_raw(setting->line_last, print.to); - // Two lines are printed because the normal final end of line is never printed by design. - // If this is an error or the header flag is set, then the normal end of line is printed by design so do not print this second new line. - if (F_status_is_error_not(setting->state.status) && !(setting->flag & utf8_main_flag_header_e)) { - fll_print_dynamic_raw(setting->line_last, print.to); - } - - return F_none; - } -#endif // _di_utf8_print_line_last_locked_ - -#ifndef _di_utf8_print_line_last_unlocked_ - f_status_t utf8_print_line_last_unlocked(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - if (F_status_is_error_not(setting->state.status)) { - if (print.verbosity < f_console_verbosity_normal_e) return F_output_not; - if (setting->flag & (utf8_main_flag_verify_e | utf8_main_flag_file_to_e)) return F_output_not; - } - - f_print_dynamic_raw(setting->line_last, print.to); - - return F_none; - } -#endif // _di_utf8_print_line_last_unlocked_ - -#ifndef _di_utf8_print_raw_bytesequence_ - f_status_t utf8_print_raw_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_utf_char_t raw, const uint8_t width) { - - if (!setting) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - - f_string_static_t character = macro_f_string_static_t_initialize(0, 0, width); - - f_char_t byte[character.used + 1]; - character.string = byte; - byte[character.used] = 0; - - if (raw) { - if (width == 1) { - byte[0] = macro_f_utf_char_t_to_char_4_be(raw); - } - else if (width == 2) { - byte[0] = macro_f_utf_char_t_to_char_3_be(raw); - byte[1] = macro_f_utf_char_t_to_char_4_be(raw); - } - else if (width == 3) { - byte[0] = macro_f_utf_char_t_to_char_2_be(raw); - byte[1] = macro_f_utf_char_t_to_char_3_be(raw); - byte[2] = macro_f_utf_char_t_to_char_4_be(raw); - } - else { - byte[0] = macro_f_utf_char_t_to_char_1_be(raw); - byte[1] = macro_f_utf_char_t_to_char_2_be(raw); - byte[2] = macro_f_utf_char_t_to_char_3_be(raw); - byte[3] = macro_f_utf_char_t_to_char_4_be(raw); - } - } - else { - memset(byte, 0, sizeof(f_char_t) * width); - } - - fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, character, setting->valid_not, setting->append); - - return F_none; - } -#endif // _di_utf8_print_raw_bytesequence_ - -#ifndef _di_utf8_print_raw_codepoint_ - f_status_t utf8_print_raw_codepoint(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t raw) { - - if (!setting) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - - fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, raw, setting->valid_not, setting->append); - - return F_none; - } -#endif // _di_utf8_print_raw_codepoint_ - -#ifndef _di_utf8_print_raw_combining_or_width_ - f_status_t utf8_print_raw_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const uint8_t width) { - - if (!setting) return F_output_not; - if (setting->flag & (utf8_main_flag_strip_invalid_e | utf8_main_flag_verify_e)) return F_output_not; - - if (setting->mode & utf8_mode_to_combining_e) { - utf8_print_combining_or_width_invalid(setting, print); - } - else if (setting->mode & utf8_mode_to_width_e) { - const f_string_static_t *character = 0; - - switch (width) { - case 1: - character = &utf8_string_width_1_s; - break; - - case 2: - character = &utf8_string_width_2_s; - break; - - case 3: - character = &utf8_string_width_3_s; - break; - - case 4: - character = &utf8_string_width_4_s; - break; - - default: - character = &utf8_string_width_0_s; - } - - fl_print_format("%r%[%r%]%r", print.to, setting->prepend, setting->valid_not, *character, setting->valid_not, setting->append); - } - - return F_none; - } -#endif // _di_utf8_print_raw_combining_or_width_ - -#ifndef _di_utf8_print_section_header_file_ - f_status_t utf8_print_section_header_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t name, const f_array_length_t index) { - - if (!setting) return F_output_not; - if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; - if (setting->flag & utf8_main_flag_verify_e) return F_output_not; - - f_file_stream_lock(print.to); - - - if ((setting->flag & utf8_main_flag_pipe_e) || index) { - f_print_dynamic_raw(f_string_eol_s, print.to); - } - else { - f_print_dynamic_raw(setting->line_first, print.to); - } - - if (setting->flag & utf8_main_flag_header_e) { - fl_print_format("%[File%] ", print.to, print.set->title, print.set->title); - - if (setting->flag & utf8_main_flag_file_to_e) { - fl_print_format("%[%Q%]: %Q.%r", print.to, print.set->notable, name, print.set->notable, setting->path_files_to.array[0], f_string_eol_s); - } - else { - fl_print_format("%[%Q%]:%r", print.to, print.set->notable, name, print.set->notable, f_string_eol_s); - } - } - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_utf8_print_section_header_file_ - -#ifndef _di_utf8_print_section_header_parameter_ - f_status_t utf8_print_section_header_parameter(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index) { - - if (!setting) return F_output_not; - if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; - if (setting->flag & utf8_main_flag_verify_e) return F_output_not; - - f_file_stream_lock(print.to); - - if ((setting->flag & utf8_main_flag_pipe_e) || (setting->flag & utf8_main_flag_file_from_e) || index) { - f_print_dynamic_raw(f_string_eol_s, print.to); - } - else { - f_print_dynamic_raw(setting->line_first, print.to); - } - - if (setting->flag & utf8_main_flag_header_e) { - fl_print_format("%[Parameter%] ", print.to, print.set->title, print.set->title); - fl_print_format("%[%ul%]:%r", print.to, print.set->notable, index, print.set->notable, f_string_eol_s); - } - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_utf8_print_section_header_parameter_ - -#ifndef _di_utf8_print_section_header_pipe_ - f_status_t utf8_print_section_header_pipe(utf8_setting_t * const setting, const fl_print_t print) { - - if (!setting) return F_output_not; - if (!(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) return F_output_not; - if (setting->flag & utf8_main_flag_verify_e) return F_output_not; - - f_file_stream_lock(print.to); - - f_print_dynamic_raw(setting->line_first, print.to); - - if (setting->flag & utf8_main_flag_header_e) { - fl_print_format("%[Pipe%]:%r", print.to, print.set->title, print.set->title, f_string_eol_s); - } - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_utf8_print_section_header_pipe_ - -#ifndef _di_utf8_print_width_ - f_status_t utf8_print_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence) { - - if (!setting) return F_status_set_error(F_output_not); - if (print.verbosity < f_console_verbosity_error_e) return F_output_not; - - f_status_t status = f_utf_is_wide(sequence.string, sequence.used); - - if (status == F_true) { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_2_s, setting->append); - - return F_output_not; - } - - if (status == F_false) { - status = f_utf_is_graph(sequence.string, sequence.used); - - if (status == F_true) { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_1_s, setting->append); - - return F_output_not; - } - - if (status == F_false) { - fl_print_format("%r%r%r", print.to, setting->prepend, utf8_string_width_0_s, setting->append); - - return F_output_not; - } - } - - utf8_print_combining_or_width_invalid(setting, print); - return F_none; } -#endif // _di_utf8_print_width_ +#endif // _di_utf8_print_line_last_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/utf8/c/main/print.h b/level_3/utf8/c/main/print.h index 6613f56..b0af6e3 100644 --- a/level_3/utf8/c/main/print.h +++ b/level_3/utf8/c/main/print.h @@ -13,305 +13,6 @@ extern "C" { #endif /** - * Print generic error message regarding a function failing in some way. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - * - * @see fll_error_print() - */ -#ifndef _di_utf8_print_error_ - extern f_status_t utf8_print_error(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function); -#endif // _di_utf8_print_error_ - -/** - * Print error message when attempt to decode the character failed. - * - * @param main - * The main program data. - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param invalid - * The byte sequence string or unicode codepoint string representing a single character to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_decode_ - extern f_status_t utf8_print_error_decode(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid); -#endif // _di_utf8_print_error_decode_ - -/** - * Print error message when attempt to encode the character failed. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param codepoint - * The codepoint that is invalid. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_encode_ - extern f_status_t utf8_print_error_encode(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint); -#endif // _di_utf8_print_error_encode_ - -/** - * Print file related error or warning messages. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param function - * The name of the function where the error happened. - * Set to 0 to disable. - * @param name - * The name of the file or directory. - * @param operation - * The operation that fails, such as 'create' or 'access'. - * @param type - * A valid file type code from the fll_error_file_type enum. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - * - * @see fll_error_file_print() - */ -#ifndef _di_utf8_print_error_file_ - extern f_status_t utf8_print_error_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type); -#endif // _di_utf8_print_error_file_ - -/** - * Print error message for when no sources are provided. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_no_from_ - extern f_status_t utf8_print_error_no_from(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_error_no_from_ - -/** - * Print error message for when the file parameter is an empty string. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param index - * The index within the argv[] array where the empty string is found. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_parameter_file_name_empty_ - extern f_status_t utf8_print_error_parameter_file_name_empty(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index); -#endif // _di_utf8_print_error_parameter_file_name_empty_ - -/** - * Print error message for when no sources are provided in the main program parameters. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param from - * If TRUE, then this is a from file (source file). - * If FALSE, then this is a to file (destination file). - * @param name - * The file path name. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_parameter_file_not_found_ - extern f_status_t utf8_print_error_parameter_file_not_found(utf8_setting_t * const setting, const fl_print_t print, const bool from, const f_string_static_t name); -#endif // _di_utf8_print_error_parameter_file_not_found_ - -/** - * Print error message for when too many 'to' destinations are specified. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_error_parameter_file_to_too_many_ - extern f_status_t utf8_print_error_parameter_file_to_too_many(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_error_parameter_file_to_too_many_ - -/** - * Print the byte sequence character (such as '豸'). - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param sequence - * A byte sequences representing a single character to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_bytesequence_ - extern f_status_t utf8_print_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); -#endif // _di_utf8_print_bytesequence_ - -/** - * Print an invalid character either as a Unicode codeblock or as a byte sequence. - * - * This handles whether or not the invalid character should be printed or not based on program parameters. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param invalid - * The byte sequence string or unicode codepoint string representing a single character to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - * - * @see utf8_print_combining_or_width() - */ -#ifndef _di_utf8_print_character_invalid_ - extern f_status_t utf8_print_character_invalid(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t invalid); -#endif // _di_utf8_print_character_invalid_ - -/** - * Print the codepoint number as a codepoint string (such as U+8C78). - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param codepoint - * The codepoint to print. - * This is the code that represents a single character. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_codepoint_ - extern f_status_t utf8_print_codepoint(utf8_setting_t * const setting, const fl_print_t print, const uint32_t codepoint); -#endif // _di_utf8_print_codepoint_ - -/** - * Print the width or combining state of the given character. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * @param sequence - * A byte sequences representing a single character to print. - * - * @see utf8_print_width() - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_combining_or_width_ - extern f_status_t utf8_print_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); -#endif // _di_utf8_print_combining_or_width_ - -/** - * Print an error regarding the width or combining state of a some character. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates how printing is to be performed. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_combining_or_width_invalid_ - extern f_status_t utf8_print_combining_or_width_invalid(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_combining_or_width_invalid_ - -/** * Print help. * * @param setting @@ -326,6 +27,17 @@ extern "C" { * F_output_not on success, but no printing is performed. * * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_flush() + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see f_print_dynamic_raw() + * @see fl_print_format() + * + * @see fll_program_print_help_header() + * @see fll_program_print_help_option() + * @see fll_program_print_help_option_standard() + * @see fll_program_print_help_usage() */ #ifndef _di_utf8_print_help_ extern f_status_t utf8_print_help(utf8_setting_t * const setting, const fl_print_t print); @@ -350,34 +62,12 @@ extern "C" { * F_output_not on success, but no printing is performed. * * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_line_first_locked_ - extern f_status_t utf8_print_line_first_locked(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_line_first_locked_ - -/** - * Print first new line, unless verbosity says otherwise. - * - * This is generally either the first line in the program or the first line printed before an error message. - * - * This function neither locks nor unlocks the input stream. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. + * @see fll_print_dynamic_raw() */ -#ifndef _di_utf8_print_line_first_unlocked_ - extern f_status_t utf8_print_line_first_unlocked(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_line_first_unlocked_ +#ifndef _di_utf8_print_line_first_ + extern f_status_t utf8_print_line_first(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_line_first_ /** * Print last new line when the main is complete, unless verbosity says otherwise. @@ -398,192 +88,12 @@ extern "C" { * F_output_not on success, but no printing is performed. * * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_line_last_locked_ - extern f_status_t utf8_print_line_last_locked(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_line_last_locked_ - -/** - * Print last new line when the main is complete, unless verbosity says otherwise. - * - * This is generally the very last line printed in the program. - * - * This function neither locks nor unlocks the input stream. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_line_last_unlocked_ - extern f_status_t utf8_print_line_last_unlocked(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_line_last_unlocked_ - -/** - * Print the raw character data (binary / byte sequence). - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param raw - * The raw string in integer format. - * @param width - * The width the raw character represents (a value inclusively from 1 to 4). - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_raw_bytesequence_ - extern f_status_t utf8_print_raw_bytesequence(utf8_setting_t * const setting, const fl_print_t print, const f_utf_char_t raw, const uint8_t width); -#endif // _di_utf8_print_raw_bytesequence_ - -/** - * Print the raw character data (codepoint). * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param raw - * The raw string already in codepoint format. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_raw_codepoint_ - extern f_status_t utf8_print_raw_codepoint(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t raw); -#endif // _di_utf8_print_raw_codepoint_ - -/** - * Print the width or combining state of the for a raw character. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param width - * The pre-calculated width. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - * - * @see utf8_print_width() - */ -#ifndef _di_utf8_print_raw_combining_or_width_ - extern f_status_t utf8_print_raw_combining_or_width(utf8_setting_t * const setting, const fl_print_t print, const uint8_t width); -#endif // _di_utf8_print_raw_combining_or_width_ - -/** - * Print the input file section header. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param name - * The name of the file. - * @param index - * The index position of the file. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_section_header_file_ - extern f_status_t utf8_print_section_header_file(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t name, const f_array_length_t index); -#endif // _di_utf8_print_section_header_file_ - -/** - * Print the input parameter section header. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param index - * The index position of the parameter. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_section_header_parameter_ - extern f_status_t utf8_print_section_header_parameter(utf8_setting_t * const setting, const fl_print_t print, const f_array_length_t index); -#endif // _di_utf8_print_section_header_parameter_ - -/** - * Print the input pipe section header. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. - */ -#ifndef _di_utf8_print_section_header_pipe_ - extern f_status_t utf8_print_section_header_pipe(utf8_setting_t * const setting, const fl_print_t print); -#endif // _di_utf8_print_section_header_pipe_ - -/** - * Print the width of the given character. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * Designates the how and where to print. - * @param sequence - * A byte sequences representing a single character whose width is to be printed. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - * - * F_output_not (with error bit) if setting is NULL. + * @see fll_print_dynamic_raw() */ -#ifndef _di_utf8_print_width_ - extern f_status_t utf8_print_width(utf8_setting_t * const setting, const fl_print_t print, const f_string_static_t sequence); -#endif // _di_utf8_print_width_ +#ifndef _di_utf8_print_line_last_ + extern f_status_t utf8_print_line_last(utf8_setting_t * const setting, const fl_print_t print); +#endif // _di_utf8_print_line_last_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/utf8/c/main/private-common.c b/level_3/utf8/c/main/private-common.c deleted file mode 100644 index c289854..0000000 --- a/level_3/utf8/c/main/private-common.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "utf8.h" -#include "private-common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/utf8/c/main/private-common.h b/level_3/utf8/c/main/private-common.h deleted file mode 100644 index 5bf1965..0000000 --- a/level_3/utf8/c/main/private-common.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: UTF8 - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _PRIVATE_common_h -#define _PRIVATE_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_common_h diff --git a/level_3/utf8/c/main/process.c b/level_3/utf8/c/main/process.c index b4cc7d6..7135aa7 100644 --- a/level_3/utf8/c/main/process.c +++ b/level_3/utf8/c/main/process.c @@ -47,7 +47,6 @@ extern "C" { utf8_detect_codepoint(main, setting, text, &mode_codepoint); if (F_status_is_error(setting->state.status)) { - utf8_print_line_first_locked(setting, main->error); fll_error_print(main->error, F_status_set_fine(setting->state.status), macro_utf8_f(utf8_detect_codepoint), fll_error_file_flag_fallback_e); break; diff --git a/level_3/utf8/c/main/utf8.c b/level_3/utf8/c/main/utf8.c index 06ca2c9..a6cb03f 100644 --- a/level_3/utf8/c/main/utf8.c +++ b/level_3/utf8/c/main/utf8.c @@ -10,7 +10,7 @@ extern "C" { if (!main || !setting) return; if (F_status_is_error(setting->state.status)) { - utf8_print_line_last_locked(setting, main->error); + utf8_print_line_last(setting, main->message); return; } @@ -35,16 +35,14 @@ extern "C" { return; } - if (!(setting->flag & utf8_main_flag_header_e)) { - utf8_print_line_first_locked(setting, main->message); - } + utf8_print_line_first(setting, main->message); f_status_t valid = F_true; if (main->pipe & fll_program_data_pipe_input_e) { const f_file_t file = macro_f_file_t_initialize(F_type_input_d, F_type_descriptor_input_d, F_file_flag_read_only_d, 32768, F_file_default_write_size_d); - utf8_print_section_header_pipe(setting, main->output); + utf8_print_data_section_header_pipe(setting, main->output); if (setting->mode & utf8_mode_from_bytesequence_e) { utf8_process_file_bytesequence(main, setting, file); @@ -85,7 +83,7 @@ extern "C" { main->signal_check = 0; } - utf8_print_section_header_file(setting, main->output, setting->path_files_from.array[i], i); + utf8_print_data_section_header_file(setting, main->output, setting->path_files_from.array[i], i); setting->state.status = f_file_stream_open(setting->path_files_from.array[i], f_string_empty_s, &file); @@ -151,7 +149,7 @@ extern "C" { main->signal_check = 0; } - utf8_print_section_header_parameter(setting, main->output, main->parameters.remaining.array[i]); + utf8_print_data_section_header_parameter(setting, main->output, i); utf8_process_text(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); @@ -163,15 +161,17 @@ extern "C" { } // for } - if (F_status_is_error(setting->state.status)) { - if (F_status_set_fine(setting->state.status) == F_interrupt) return; - - utf8_print_line_last_locked(setting, main->error); + if (F_status_set_fine(setting->state.status) == F_interrupt) return; - return; + // Two lines are printed because the normal final end of line is never printed by design. + // If this is an error or the header flag is set, then the normal end of line is printed by design so do not print this second new line. + if (F_status_is_error_not(setting->state.status) && main->message.verbosity > f_console_verbosity_error_e && !(setting->flag & (utf8_main_flag_header_e | utf8_main_flag_separate_e))) { + fll_print_dynamic_raw(f_string_eol_s, main->message.to); } - utf8_print_line_last_locked(setting, main->message); + utf8_print_line_last(setting, main->message); + + if (F_status_is_error(setting->state.status)) return; if (setting->flag & utf8_main_flag_verify_e) { setting->state.status = valid; diff --git a/level_3/utf8/c/main/utf8.h b/level_3/utf8/c/main/utf8.h index 1f379f2..3fedc27 100644 --- a/level_3/utf8/c/main/utf8.h +++ b/level_3/utf8/c/main/utf8.h @@ -55,13 +55,15 @@ #include // UTF-8 includes. -#include -#include -#include +#include +#include +#include #include #include #include #include +#include +#include #include #ifdef __cplusplus diff --git a/level_3/utf8/data/build/settings b/level_3/utf8/data/build/settings index fc11590..4c9dd60 100644 --- a/level_3/utf8/data/build/settings +++ b/level_3/utf8/data/build/settings @@ -22,11 +22,11 @@ build_libraries-individual -lfll_error -lfll_print -lfll_program -lfl_conversion build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll -build_sources_library main/common.c main/common-print.c main/common-string.c main/common-type.c main/bytesequence.c main/codepoint.c main/print.c main/process.c main/utf8.c +build_sources_library main/common.c main/common/print.c main/common/string.c main/common/type.c main/bytesequence.c main/codepoint.c main/print.c main/print-error.c main/print-data.c main/process.c main/utf8.c build_sources_program main/main.c -build_sources_headers main/common.h main/common-print.h main/common-string.h main/common-type.h main/bytesequence.h main/codepoint.h main/print.h main/process.h main/utf8.h +build_sources_headers main/common.h main/common/print.h main/common/string.h main/common/type.h main/bytesequence.h main/codepoint.h main/print.h main/print-error.h main/print-data.h main/process.h main/utf8.h build_sources_documentation man -- 1.8.3.1