From: Kevin Day Date: Sun, 1 Aug 2021 04:24:53 +0000 (-0500) Subject: Progress: Continue print development. X-Git-Tag: 0.5.5~22 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=649432d206f8d6b364039c2a04d7d120961e96f1;p=fll Progress: Continue print development. I've noticed that the performance can be quite poor in the custom fprintf functions. Investigating this seems to be for several reasons: 1) No serious optimization developed into the logic as of yet. 2) The libc functions have serious optimization. 3) GCC/Clang are not properly identifying the register for unoptimized compilation. 4) I believe the libc functions are also parsing the data in a loop. Some very basic optimizations are implemented: 1) Utilize "-O2" in every config by default to encourage the compiler to properly detect and set register (huge performance gained). 2) Use libc functions like strnlen() and fwrite() more often (more work to do in this regard). 3) Use grouping in the if..then.. logic to reduce the number of comparisons. Fix bug where the number '11' is not being converted due to a typo. Fix bug where an uppercase 'E' is printed when it should be a lower case 'e'. There is no "end of enquiry". Replace "end of enquiry" with "enquiry" because there is no "end of enquiry". Organize print sequences and add (and utilize) a control sequence character map to avoid multiple if..then.. logic. Re-organize the format flags, changing some entirely. I decided not to so closely follow fprintf() functions and instead make things a little more consistent. For example, "ul" and "ull" exist but the signed opposite is "l" and "ll". This could instead be "ul" and "ull" as unsigned version of "il" and "ill". Most of the FLL project is explicit about byte sizes, and so do the same with the format flags. There is still a lot more work to do, but this is starting to stabilize a little. --- diff --git a/level_0/f_account/data/build/settings b/level_0/f_account/data/build/settings index 9ec3018..08735e8 100644 --- a/level_0/f_account/data/build/settings +++ b/level_0/f_account/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_capability/data/build/settings b/level_0/f_capability/data/build/settings index ae4b71f..50e9ca8 100644 --- a/level_0/f_capability/data/build/settings +++ b/level_0/f_capability/data/build/settings @@ -50,7 +50,7 @@ defines_all -D_libcap_legacy_only_ defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_color/data/build/settings b/level_0/f_color/data/build/settings index cc9002f..0887f70 100644 --- a/level_0/f_color/data/build/settings +++ b/level_0/f_color/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_console/data/build/settings b/level_0/f_console/data/build/settings index 3809628..41989c5 100644 --- a/level_0/f_console/data/build/settings +++ b/level_0/f_console/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_control_group/data/build/settings b/level_0/f_control_group/data/build/settings index 1dc5746..02ee113 100644 --- a/level_0/f_control_group/data/build/settings +++ b/level_0/f_control_group/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_conversion/c/private-conversion.c b/level_0/f_conversion/c/private-conversion.c index 4a17d78..41d9b09 100644 --- a/level_0/f_conversion/c/private-conversion.c +++ b/level_0/f_conversion/c/private-conversion.c @@ -8,6 +8,7 @@ extern "C" { #if !defined(_di_f_conversion_number_signed_to_file_) || !defined(_di_f_conversion_number_unsigned_to_file_) f_status_t private_f_conversion_digit_to_file(const f_number_unsigned_t number, const f_conversion_data_t data, const uint8_t negative, FILE *output) { + // @fixme this has a performance problems. int digits = 0; if (number) { @@ -179,7 +180,7 @@ extern "C" { c = data.flag & f_conversion_data_flag_base_upper ? f_string_ascii_A_s[0] : f_string_ascii_a_s[0]; break; - case 101: + case 11: c = data.flag & f_conversion_data_flag_base_upper ? f_string_ascii_B_s[0] : f_string_ascii_b_s[0]; break; @@ -192,7 +193,7 @@ extern "C" { break; case 14: - c = data.flag & f_conversion_data_flag_base_upper ? f_string_ascii_E_s[0] : f_string_ascii_E_s[0]; + c = data.flag & f_conversion_data_flag_base_upper ? f_string_ascii_E_s[0] : f_string_ascii_e_s[0]; break; case 15: diff --git a/level_0/f_conversion/data/build/settings b/level_0/f_conversion/data/build/settings index 707959a..7a2e38b 100644 --- a/level_0/f_conversion/data/build/settings +++ b/level_0/f_conversion/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_directory/data/build/settings b/level_0/f_directory/data/build/settings index 578f4eb..13cacbd 100644 --- a/level_0/f_directory/data/build/settings +++ b/level_0/f_directory/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_environment/data/build/settings b/level_0/f_environment/data/build/settings index 7347515..4d34303 100644 --- a/level_0/f_environment/data/build/settings +++ b/level_0/f_environment/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_execute/data/build/settings b/level_0/f_execute/data/build/settings index 068ff96..caa5191 100644 --- a/level_0/f_execute/data/build/settings +++ b/level_0/f_execute/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_file/data/build/settings b/level_0/f_file/data/build/settings index 5b628a4..3ea5b4d 100644 --- a/level_0/f_file/data/build/settings +++ b/level_0/f_file/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_fss/data/build/settings b/level_0/f_fss/data/build/settings index f5a0649..1fa9376 100644 --- a/level_0/f_fss/data/build/settings +++ b/level_0/f_fss/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_iki/data/build/settings b/level_0/f_iki/data/build/settings index e745d7d..2ddd3aa 100644 --- a/level_0/f_iki/data/build/settings +++ b/level_0/f_iki/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_limit/data/build/settings b/level_0/f_limit/data/build/settings index 8f997a5..669d4c0 100644 --- a/level_0/f_limit/data/build/settings +++ b/level_0/f_limit/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_memory/data/build/settings b/level_0/f_memory/data/build/settings index 264b34f..0160e72 100644 --- a/level_0/f_memory/data/build/settings +++ b/level_0/f_memory/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_path/data/build/settings b/level_0/f_path/data/build/settings index 03c0a45..429cda0 100644 --- a/level_0/f_path/data/build/settings +++ b/level_0/f_path/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_pipe/data/build/settings b/level_0/f_pipe/data/build/settings index 33727cc..b1828cc 100644 --- a/level_0/f_pipe/data/build/settings +++ b/level_0/f_pipe/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_print/c/print-common.c b/level_0/f_print/c/print-common.c index c80ec9a..9df9f1f 100644 --- a/level_0/f_print/c/print-common.c +++ b/level_0/f_print/c/print-common.c @@ -7,6 +7,7 @@ extern "C" { #ifndef _di_f_print_sequences_ const f_string_t f_print_sequence_acknowledge_s = f_print_sequence_acknowledge; + const f_string_t f_print_sequence_acknowledge_negative_s = f_print_sequence_acknowledge_negative; const f_string_t f_print_sequence_backspace_s = f_print_sequence_backspace; const f_string_t f_print_sequence_bell_s = f_print_sequence_bell; const f_string_t f_print_sequence_cancel_s = f_print_sequence_cancel; @@ -17,33 +18,67 @@ extern "C" { const f_string_t f_print_sequence_device_control_2_s = f_print_sequence_device_control_2; const f_string_t f_print_sequence_device_control_3_s = f_print_sequence_device_control_3; const f_string_t f_print_sequence_device_control_4_s = f_print_sequence_device_control_4; - const f_string_t f_print_sequence_end_of_enquiry_s = f_print_sequence_end_of_enquiry; const f_string_t f_print_sequence_end_of_medium_s = f_print_sequence_end_of_medium; const f_string_t f_print_sequence_end_of_text_s = f_print_sequence_end_of_text; const f_string_t f_print_sequence_end_of_transmission_s = f_print_sequence_end_of_transmission; const f_string_t f_print_sequence_end_of_transmission_block_s = f_print_sequence_end_of_transmission_block; + const f_string_t f_print_sequence_enquiry_s = f_print_sequence_enquiry; const f_string_t f_print_sequence_escape_s = f_print_sequence_escape; - const f_string_t f_print_sequence_file_separator_s = f_print_sequence_file_separator; const f_string_t f_print_sequence_form_feed_s = f_print_sequence_form_feed; - const f_string_t f_print_sequence_group_separator_s = f_print_sequence_group_separator; const f_string_t f_print_sequence_line_feed_s = f_print_sequence_line_feed; - const f_string_t f_print_sequence_negative_acknowledge_s = f_print_sequence_negative_acknowledge; - const f_string_t f_print_sequence_new_line_s = f_print_sequence_new_line; const f_string_t f_print_sequence_null_s = f_print_sequence_null; - const f_string_t f_print_sequence_record_separator_s = f_print_sequence_record_separator; + const f_string_t f_print_sequence_separator_file_s = f_print_sequence_separator_file; + const f_string_t f_print_sequence_separator_group_s = f_print_sequence_separator_group; + const f_string_t f_print_sequence_separator_record_s = f_print_sequence_separator_record; + const f_string_t f_print_sequence_separator_unit_s = f_print_sequence_separator_unit; const f_string_t f_print_sequence_shift_in_s = f_print_sequence_shift_in; const f_string_t f_print_sequence_shift_out_s = f_print_sequence_shift_out; - const f_string_t f_print_sequence_space_s = f_print_sequence_space; const f_string_t f_print_sequence_start_of_header_s = f_print_sequence_start_of_header; const f_string_t f_print_sequence_start_of_text_s = f_print_sequence_start_of_text; const f_string_t f_print_sequence_substitute_s = f_print_sequence_substitute; const f_string_t f_print_sequence_synchronous_idle_s = f_print_sequence_synchronous_idle; const f_string_t f_print_sequence_tab_s = f_print_sequence_tab; const f_string_t f_print_sequence_tab_vertical_s = f_print_sequence_tab_vertical; - const f_string_t f_print_sequence_unit_separator_s = f_print_sequence_unit_separator; const f_string_t f_print_sequence_unknown_s = f_print_sequence_unknown; #endif // _di_f_print_sequences_ +#ifndef _di_f_print_sequences_set_control_ + const char f_print_sequence_set_control_s[32][3] = { + f_print_sequence_null, + f_print_sequence_start_of_header, + f_print_sequence_start_of_text, + f_print_sequence_end_of_text, + f_print_sequence_end_of_transmission, + f_print_sequence_enquiry, + f_print_sequence_acknowledge, + f_print_sequence_bell, + f_print_sequence_backspace, + f_print_sequence_tab, + f_print_sequence_line_feed, + f_print_sequence_tab_vertical, + f_print_sequence_form_feed, + f_print_sequence_carriage_return, + f_print_sequence_shift_out, + f_print_sequence_shift_in, + f_print_sequence_data_link_escape, + f_print_sequence_device_control_1, + f_print_sequence_device_control_2, + f_print_sequence_device_control_3, + f_print_sequence_device_control_4, + f_print_sequence_acknowledge_negative, + f_print_sequence_synchronous_idle, + f_print_sequence_end_of_transmission_block, + f_print_sequence_cancel, + f_print_sequence_end_of_medium, + f_print_sequence_substitute, + f_print_sequence_escape, + f_print_sequence_separator_file, + f_print_sequence_separator_group, + f_print_sequence_separator_record, + f_print_sequence_separator_unit, + }; +#endif // _di_f_print_sequences_set_control_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_print/c/print-common.h b/level_0/f_print/c/print-common.h index 96108c3..49ff407 100644 --- a/level_0/f_print/c/print-common.h +++ b/level_0/f_print/c/print-common.h @@ -37,6 +37,7 @@ extern "C" { */ #ifndef _di_f_print_sequences_ #define f_print_sequence_acknowledge "␆" + #define f_print_sequence_acknowledge_negative "␕" #define f_print_sequence_backspace "␈" #define f_print_sequence_bell "␇" #define f_print_sequence_cancel "␘" @@ -47,33 +48,31 @@ extern "C" { #define f_print_sequence_device_control_2 "␒" #define f_print_sequence_device_control_3 "␓" #define f_print_sequence_device_control_4 "␔" - #define f_print_sequence_end_of_enquiry "␅" #define f_print_sequence_end_of_medium "␙" #define f_print_sequence_end_of_text "␃" #define f_print_sequence_end_of_transmission "␄" #define f_print_sequence_end_of_transmission_block "␗" + #define f_print_sequence_enquiry "␅" #define f_print_sequence_escape "␛" - #define f_print_sequence_file_separator "␜" #define f_print_sequence_form_feed "␌" - #define f_print_sequence_group_separator "␝" #define f_print_sequence_line_feed "␊" - #define f_print_sequence_negative_acknowledge "␕" - #define f_print_sequence_new_line "␤" #define f_print_sequence_null "␀" - #define f_print_sequence_record_separator "␞" + #define f_print_sequence_separator_file "␜" + #define f_print_sequence_separator_group "␝" + #define f_print_sequence_separator_record "␞" + #define f_print_sequence_separator_unit "␟" #define f_print_sequence_shift_in "␏" #define f_print_sequence_shift_out "␎" - #define f_print_sequence_space "␠" #define f_print_sequence_start_of_header "␁" #define f_print_sequence_start_of_text "␂" #define f_print_sequence_substitute "␚" #define f_print_sequence_synchronous_idle "␖" #define f_print_sequence_tab "␉" #define f_print_sequence_tab_vertical "␋" - #define f_print_sequence_unit_separator "␟" #define f_print_sequence_unknown "�" extern const f_string_t f_print_sequence_acknowledge_s; + extern const f_string_t f_print_sequence_acknowledge_negative_s; extern const f_string_t f_print_sequence_backspace_s; extern const f_string_t f_print_sequence_bell_s; extern const f_string_t f_print_sequence_cancel_s; @@ -84,34 +83,41 @@ extern "C" { extern const f_string_t f_print_sequence_device_control_2_s; extern const f_string_t f_print_sequence_device_control_3_s; extern const f_string_t f_print_sequence_device_control_4_s; - extern const f_string_t f_print_sequence_end_of_enquiry_s; extern const f_string_t f_print_sequence_end_of_medium_s; extern const f_string_t f_print_sequence_end_of_text_s; extern const f_string_t f_print_sequence_end_of_transmission_s; extern const f_string_t f_print_sequence_end_of_transmission_block_s; extern const f_string_t f_print_sequence_escape_s; - extern const f_string_t f_print_sequence_file_separator_s; + extern const f_string_t f_print_sequence_equiry_s; extern const f_string_t f_print_sequence_form_feed_s; - extern const f_string_t f_print_sequence_group_separator_s; extern const f_string_t f_print_sequence_line_feed_s; - extern const f_string_t f_print_sequence_negative_acknowledge_s; - extern const f_string_t f_print_sequence_new_line_s; extern const f_string_t f_print_sequence_null_s; - extern const f_string_t f_print_sequence_record_separator_s; + extern const f_string_t f_print_sequence_separator_file_s; + extern const f_string_t f_print_sequence_separator_group_s; + extern const f_string_t f_print_sequence_separator_record_s; + extern const f_string_t f_print_sequence_separator_unit_s; extern const f_string_t f_print_sequence_shift_in_s; extern const f_string_t f_print_sequence_shift_out_s; - extern const f_string_t f_print_sequence_space_s; extern const f_string_t f_print_sequence_start_of_header_s; extern const f_string_t f_print_sequence_start_of_text_s; extern const f_string_t f_print_sequence_substitute_s; extern const f_string_t f_print_sequence_synchronous_idle_s; extern const f_string_t f_print_sequence_tab_s; extern const f_string_t f_print_sequence_tab_vertical_s; - extern const f_string_t f_print_sequence_unit_separator_s; extern const f_string_t f_print_sequence_unknown_s; #endif // _di_f_print_sequences_ /** + * A map for converting control ASCII codes into the representation sequences. + * + * The key should represents the ASCII code. + * With the exception being ASCII code 127, which is not present in this map. + */ +#ifndef _di_f_print_sequences_set_control_ + extern const char f_print_sequence_set_control_s[32][3]; +#endif // _di_f_print_sequences_set_control_ + +/** * Provide basic format flags. * * f_print_format_flag_*: @@ -166,23 +172,23 @@ extern "C" { * - character_safe: "C", type is a 1-byte unsigned character, where control characters and other problems are handled. * - color_after: "]", type is f_color_set_t such that the f_color_set_t.after is used. * - color_before: "[", type is f_color_set_t such that the f_color_set_t.begin is used. - * - long: "l", "L", type is a signed integer. - * - long_long: "ll", "LL", type is a signed integer. * - number: "n", "N", type is an f_number_signed_t. - * - signed: "i", "I", type is a signed integer. - * - signed_16: "ii", "II", type is a signed int16_t. - * - signed_8: "iii", "III", type is a signed integer. + * - signed_8: "iii", "III", type is a int8_t. + * - signed_16: "ii", "II", type is a int16_t. + * - signed_32: "i", "I", type is a int32_t. + * - signed_64: "il", "IL", type is a signed int64_t. + * - signed_128: "ill", "ILL", type is a f_int_128_t. * - size: "z", "Z", type is a size_t. * - string_safe: "S", type is a NULL terminated string, where control characters and other problems are handled. * - string_static: "q", type is an f_string_static_t or f_string_dynamic_t and NULLs are ignored (not printed). * - string_static_raw: "r", type is an f_string_static_t or f_string_dynamic_t and NULLs (and all other control characters) are printed. * - string_static_safe: "Q", type is an f_string_static_t or f_string_dynamic_t and NULLs are printed, where control characters and other problems are handled. - * - unsigned: "u", "U", type is an unsigned integer. - * - unsigned_16: "ui", "UI", type is an uint16_t. * - unsigned_8: "uii", "UII", type is an uint8_t. - * - unsigned_long: "ul", "UL", type is an unsigned long. - * - unsigned_long_long: "ull", "ULL", type is an unsigned long long. - * - unsigned_number: "un", "UN", type is an f_number_unsigned_t. + * - unsigned_16: "ui", "UI", type is an uint16_t. + * - unsigned_32: "u", "U", type is an uint32_t. + * - unsigned_64: "ul", "UL", type is an uint64_t. + * - unsigned_128: "ull", "ULL", type is an f_uint_128_t. + * - unsigned_number: "un", "UN", type is an f_number_unsigned_t (which by default is what f_array_length_t is a type of). * * @see fprintf() */ @@ -192,23 +198,23 @@ extern "C" { f_print_format_type_character_safe, f_print_format_type_color_after, f_print_format_type_color_before, - f_print_format_type_long, - f_print_format_type_long_long, f_print_format_type_number, - f_print_format_type_signed, - f_print_format_type_signed_16, f_print_format_type_signed_8, + f_print_format_type_signed_16, + f_print_format_type_signed_32, + f_print_format_type_signed_64, + f_print_format_type_signed_128, f_print_format_type_size, f_print_format_type_string, f_print_format_type_string_safe, f_print_format_type_string_static, f_print_format_type_string_static_raw, f_print_format_type_string_static_safe, - f_print_format_type_unsigned, - f_print_format_type_unsigned_16, f_print_format_type_unsigned_8, - f_print_format_type_unsigned_long, - f_print_format_type_unsigned_long_long, + f_print_format_type_unsigned_16, + f_print_format_type_unsigned_32, + f_print_format_type_unsigned_64, + f_print_format_type_unsigned_128, f_print_format_type_unsigned_number, }; #endif // _di_f_print_format_type_ diff --git a/level_0/f_print/c/print.c b/level_0/f_print/c/print.c index d29b926..9564c1a 100644 --- a/level_0/f_print/c/print.c +++ b/level_0/f_print/c/print.c @@ -466,57 +466,54 @@ extern "C" { return F_data_not; } - char *current = string; + f_status_t status = F_none; - f_string_t s = 0; + f_array_length_t start = 0; + f_array_length_t total = 0; - while (*current) { + for (register f_array_length_t i = 0; string[i]; ) { - s = private_f_print_character_safely_get(*current); + if (string[i] > 0x1f && string[i] != 0x7f || string[i] == 0x09) { + ++total; + ++i; - if (s) { - if (!fputc_unlocked(s[0], output)) { - return F_status_set_error(F_output); - } + continue; + } - if (!fputc_unlocked(s[1], output)) { - return F_status_set_error(F_output); - } + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(s[2], output)) { return F_status_set_error(F_output); } - - current = current + 1; } - else { - // @todo: redo this as done in private_f_print_safely, but add a NULL check as well. - if (macro_f_utf_byte_width(current[0]) == 1) { - if (!fputc_unlocked(current[0], output)) { - return F_status_set_error(F_output); - } - } - else { - if (!fputc_unlocked(current[1], output)) { - return F_status_set_error(F_output); - } - - if (macro_f_utf_byte_width(current[0]) > 2) { - if (!fputc_unlocked(current[2], output)) { - return F_status_set_error(F_output); - } - - if (macro_f_utf_byte_width(current[0]) > 3) { - if (!fputc_unlocked(current[3], output)) { - return F_status_set_error(F_output); - } - } - } - } - current = current + macro_f_utf_byte_width((*current)); + for (; string[i] && (string[i] < 32 && string[i] != 0x09 || string[i] == 0x7f); ++i) { + + status = private_f_print_character_safely(string[i], output); + if (F_status_is_error(status)) return status; + } // for + + start = i; + } // for + + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); + + return F_status_set_error(F_output); } - } // while + } return F_none; } diff --git a/level_0/f_print/c/print.h b/level_0/f_print/c/print.h index a3fe2d9..3a3fd2c 100644 --- a/level_0/f_print/c/print.h +++ b/level_0/f_print/c/print.h @@ -97,6 +97,7 @@ extern "C" { * UTF-8 sequences with invalid widths are converted to the unknown character '�'. * * The returned string will either be NULL (for characters that are already safe) or a string representing the replacement. + * This can result in a 3-byte character being returned as a string of 3 1-bytes. * * This should only be called for the first 1-byte character of a multibyte character. * diff --git a/level_0/f_print/c/private-print.c b/level_0/f_print/c/private-print.c index 6c1400f..d9d1b33 100644 --- a/level_0/f_print/c/private-print.c +++ b/level_0/f_print/c/private-print.c @@ -8,15 +8,56 @@ extern "C" { #if !defined(_di_f_print_) || !defined(_di_f_print_dynamic_) || !defined(_di_f_print_dynamic_partial_) f_status_t private_f_print(const f_string_t string, const f_array_length_t length, FILE *output) { - for (register f_array_length_t i = 0; i < length; ++i) { + f_array_length_t start = 0; + f_array_length_t total = 0; + + for (register f_array_length_t i = 0; i < length; ) { + + total = strlen(string + start); + + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (string[i]) { - if (!fputc_unlocked(string[i], output)) { return F_status_set_error(F_output); } + + i += total; + } + + start = i; + + if (start < length && !string[start]) { + total = 0; + + do { + ++i; + ++total; + + } while (i < length && !string[i]); + + start = i; } } // for + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); + + return F_status_set_error(F_output); + } + } + return F_none; } #endif // !defined(_di_f_print_) || !defined(_di_f_print_dynamic_) || !defined(_di_f_print_dynamic_partial_) @@ -24,125 +65,29 @@ extern "C" { #if !defined(_di_f_print_character_safely_) || !defined(_di_f_print_safely_) || !defined(_di_f_print_safely_dynamic_) || !defined(_di_f_print_safely_dynamic_partial_) || !defined(_di_f_print_safely_terminated_) || !defined(_di_f_print_except_safely_) || !defined(_di_f_print_except_dynamic_safely_) || !defined(_di_f_print_except_dynamic_partial_safely_) || !defined(_di_f_print_except_in_safely_) || !defined(_di_f_print_except_in_dynamic_safely_) || !defined(_di_f_print_except_in_dynamic_partial_safely_) f_status_t private_f_print_character_safely(const char character, FILE *output) { - if (character > 31 && character != 127) { - if (!fputc_unlocked(character, output)) { - return F_status_set_error(F_output); + if (character > 0x1f && character != 0x7f) { + if (fputc_unlocked(character, output)) { + return F_none; } - } - - f_string_t string = 0; - - if (character == 0) { - string = f_print_sequence_null_s; - } - else if (character == 1) { - string = f_print_sequence_start_of_header_s; - } - else if (character == 2) { - string = f_print_sequence_start_of_text_s; - } - else if (character == 3) { - string = f_print_sequence_end_of_text_s; - } - else if (character == 4) { - string = f_print_sequence_end_of_transmission_s; - } - else if (character == 5) { - string = f_print_sequence_end_of_enquiry_s; - } - else if (character == 6) { - string = f_print_sequence_acknowledge_s; - } - else if (character == 7) { - string = f_print_sequence_bell_s; - } - else if (character == 8) { - string = f_print_sequence_backspace_s; - } - else if (character == 9) { - string = f_print_sequence_tab_s; - } - else if (character == 10) { - string = f_print_sequence_new_line_s; - } - else if (character == 11) { - string = f_print_sequence_tab_vertical_s; - } - else if (character == 12) { - string = f_print_sequence_form_feed_s; - } - else if (character == 13) { - string = f_print_sequence_carriage_return_s; - } - else if (character == 14) { - string = f_print_sequence_shift_out_s; - } - else if (character == 15) { - string = f_print_sequence_shift_in_s; - } - else if (character == 16) { - string = f_print_sequence_data_link_escape_s; - } - else if (character == 17) { - string = f_print_sequence_device_control_1_s; - } - else if (character == 18) { - string = f_print_sequence_device_control_2_s; - } - else if (character == 19) { - string = f_print_sequence_device_control_3_s; - } - else if (character == 20) { - string = f_print_sequence_device_control_4_s; - } - else if (character == 21) { - string = f_print_sequence_negative_acknowledge_s; - } - else if (character == 22) { - string = f_print_sequence_synchronous_idle_s; - } - else if (character == 23) { - string = f_print_sequence_end_of_transmission_block_s; - } - else if (character == 24) { - string = f_print_sequence_cancel_s; - } - else if (character == 25) { - string = f_print_sequence_end_of_medium_s; - } - else if (character == 26) { - string = f_print_sequence_substitute_s; - } - else if (character == 27) { - string = f_print_sequence_escape_s; - } - else if (character == 28) { - string = f_print_sequence_file_separator_s; - } - else if (character == 29) { - string = f_print_sequence_group_separator_s; - } - else if (character == 30) { - string = f_print_sequence_record_separator_s; - } - else if (character == 31) { - string = f_print_sequence_unit_separator_s; - } - else { - // character == 127. - string = f_print_sequence_delete_s; - } + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(character, output)) { return F_status_set_error(F_output); } - if (!fputc_unlocked(character, output)) { - return F_status_set_error(F_output); - } + if (fwrite_unlocked(character == 0x7f ? f_print_sequence_delete_s : f_print_sequence_set_control_s[character], 1, 3, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(character, output)) { return F_status_set_error(F_output); } @@ -153,152 +98,77 @@ extern "C" { #if !defined(_di_f_print_character_safely_get_) || !defined(_di_f_print_dynamic_to_safely_) || !defined(_di_f_print_dynamic_partial_to_safely_) || !defined(_di_f_print_to_except_dynamic_safely_) || !defined(_di_f_print_to_except_dynamic_partial_safely_) || !defined(_di_f_print_to_except_safely_) || !defined(_di_f_print_to_safely_) f_string_t private_f_print_character_safely_get(const char character) { - if (character > 31 && character != 127) { + if (character > 0x1f && character != 0x7f) { return 0; } - if (character == 0) { - return f_print_sequence_null_s; - } - - if (character == 1) { - return f_print_sequence_start_of_header_s; - } - - if (character == 2) { - return f_print_sequence_start_of_text_s; - } - - if (character == 3) { - return f_print_sequence_end_of_text_s; - } - - if (character == 4) { - return f_print_sequence_end_of_transmission_s; - } - - if (character == 5) { - return f_print_sequence_end_of_enquiry_s; - } - - if (character == 6) { - return f_print_sequence_acknowledge_s; - } - - if (character == 7) { - return f_print_sequence_bell_s; - } - - if (character == 8) { - return f_print_sequence_backspace_s; - } - - if (character == 9) { - return f_print_sequence_tab_s; - } - - if (character == 10) { - return f_print_sequence_new_line_s; - } - - if (character == 11) { - return f_print_sequence_tab_vertical_s; - } - - if (character == 12) { - return f_print_sequence_form_feed_s; - } - - if (character == 13) { - return f_print_sequence_carriage_return_s; - } - - if (character == 14) { - return f_print_sequence_shift_out_s; - } - - if (character == 15) { - return f_print_sequence_shift_in_s; - } - - if (character == 16) { - return f_print_sequence_data_link_escape_s; - } - - if (character == 17) { - return f_print_sequence_device_control_1_s; - } - - if (character == 18) { - return f_print_sequence_device_control_2_s; - } - - if (character == 19) { - return f_print_sequence_device_control_3_s; - } + return character == 0x7f ? f_print_sequence_delete_s : (f_string_t) f_print_sequence_set_control_s[character]; + } +#endif // !defined(_di_f_print_character_safely_get_) || !defined(_di_f_print_dynamic_to_safely_) || !defined(_di_f_print_dynamic_partial_to_safely_) || !defined(_di_f_print_to_except_dynamic_safely_) || !defined(_di_f_print_to_except_dynamic_partial_safely_) || !defined(_di_f_print_to_except_safely_) || !defined(_di_f_print_to_safely_) - if (character == 20) { - return f_print_sequence_device_control_4_s; - } +#if !defined(_di_f_print_raw_) || !defined(_di_f_print_raw_dynamic_) || !defined(_di_f_print_raw_dynamic_partial_) + f_status_t private_f_print_raw(const f_string_t string, const f_array_length_t length, FILE *output) { - if (character == 21) { - return f_print_sequence_negative_acknowledge_s; - } + f_array_length_t start = 0; + f_array_length_t total = 0; - if (character == 22) { - return f_print_sequence_synchronous_idle_s; - } + for (register f_array_length_t i = 0; i < length; ) { - if (character == 23) { - return f_print_sequence_end_of_transmission_block_s; - } + total = strlen(string + start); - if (character == 24) { - return f_print_sequence_cancel_s; - } + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (character == 25) { - return f_print_sequence_end_of_medium_s; - } + return F_status_set_error(F_output); + } - if (character == 26) { - return f_print_sequence_substitute_s; - } + i += total; + } - if (character == 27) { - return f_print_sequence_escape_s; - } + start = i; - if (character == 28) { - return f_print_sequence_file_separator_s; - } + if (start < length && !string[start]) { + total = 0; - if (character == 29) { - return f_print_sequence_group_separator_s; - } + do { + ++i; + ++total; - if (character == 30) { - return f_print_sequence_record_separator_s; - } + } while (i < length && !string[i]); - if (character == 31) { - return f_print_sequence_unit_separator_s; - } + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - // character == 127. - return f_print_sequence_delete_s; - } -#endif // !defined(_di_f_print_character_safely_get_) || !defined(_di_f_print_dynamic_to_safely_) || !defined(_di_f_print_dynamic_partial_to_safely_) || !defined(_di_f_print_to_except_dynamic_safely_) || !defined(_di_f_print_to_except_dynamic_partial_safely_) || !defined(_di_f_print_to_except_safely_) || !defined(_di_f_print_to_safely_) + return F_status_set_error(F_output); + } -#if !defined(_di_f_print_raw_) || !defined(_di_f_print_raw_dynamic_) || !defined(_di_f_print_raw_dynamic_partial_) - f_status_t private_f_print_raw(const f_string_t string, const f_array_length_t length, FILE *output) { + start = i; + } + } // for - for (register f_array_length_t i = 0; i < length; ++i) { + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(string[i], output)) { return F_status_set_error(F_output); } - } // for + } return F_none; } @@ -307,92 +177,54 @@ extern "C" { #if !defined(_di_f_print_safely_) || !defined(_di_f_print_safely_dynamic_) || !defined(_di_f_print_safely_dynamic_partial_) f_status_t private_f_print_safely(const f_string_t string, const f_array_length_t length, FILE *output) { - register f_array_length_t i = 0; - f_status_t status = F_none; - f_string_t s = 0; - - while (i < length) { - - s = private_f_print_character_safely_get(string[i]); - if (s) { - if (!fputc_unlocked(s[i], output)) { - return F_status_set_error(F_output); - } - - if (!fputc_unlocked(s[i + 1], output)) { - return F_status_set_error(F_output); - } + f_array_length_t start = 0; + f_array_length_t total = 0; - if (!fputc_unlocked(s[i + 2], output)) { - return F_status_set_error(F_output); - } + for (register f_array_length_t i = 0; i < length; ) { + if ((string[i] > 0x1f && string[i] != 0x7f) && total < f_print_write_max) { + ++total; ++i; - } - else { - status = f_utf_is_valid(string + i, length - i); - - if (F_status_is_error(status) || status == F_false) { - if (!fputc_unlocked(f_print_sequence_unknown_s[0], output)) { - return F_status_set_error(F_output); - } - - if (!fputc_unlocked(f_print_sequence_unknown_s[1], output)) { - return F_status_set_error(F_output); - } - - if (!fputc_unlocked(f_print_sequence_unknown_s[2], output)) { - return F_status_set_error(F_output); - } - - i += macro_f_utf_byte_width(string[i]); - continue; - } - - if (i + macro_f_utf_byte_width(string[i]) >= length) { - if (!fputc_unlocked(f_print_sequence_unknown_s[0], output)) { - return F_status_set_error(F_output); - } - - if (!fputc_unlocked(f_print_sequence_unknown_s[1], output)) { - return F_status_set_error(F_output); - } - if (!fputc_unlocked(f_print_sequence_unknown_s[2], output)) { - return F_status_set_error(F_output); - } + continue; + } - i = length; - continue; - } + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(string[i], output)) { return F_status_set_error(F_output); } + } - if (macro_f_utf_byte_width(string[i]) > 1) { - if (!fputc_unlocked(string[i + 1], output)) { - return F_status_set_error(F_output); - } + for (; i < length && (string[i] < 32 || string[i] == 0x7f); ++i) { - if (macro_f_utf_byte_width(string[i]) > 2) { - if (!fputc_unlocked(string[i + 2], output)) { - return F_status_set_error(F_output); - } + status = private_f_print_character_safely(string[i], output); + if (F_status_is_error(status)) return status; + } // for - if (macro_f_utf_byte_width(string[i]) > 3) { - if (!fputc_unlocked(string[i + 3], output)) { - return F_status_set_error(F_output); - } - } - } - } + start = i; + } // for - i += macro_f_utf_byte_width(string[i]); + if (total) { + if (fwrite_unlocked(string + start, 1, total, output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); + + return F_status_set_error(F_output); } - } // while + } return F_none; } @@ -401,6 +233,7 @@ extern "C" { #if !defined(_di_f_print_except_) || !defined(_di_f_print_except_dynamic_) || !defined(_di_f_print_except_dynamic_partial_) f_status_t private_f_print_except(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t j = 0; @@ -426,6 +259,7 @@ extern "C" { #if !defined(_di_f_print_except_raw_) || !defined(_di_f_print_except_dynamic_raw_) || !defined(_di_f_print_except_dynamic_partial_raw_) f_status_t private_f_print_except_raw(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t j = 0; @@ -449,6 +283,7 @@ extern "C" { #if !defined(_di_f_print_except_safely_) || !defined(_di_f_print_except_dynamic_safely_) || !defined(_di_f_print_except_dynamic_partial_safely_) f_status_t private_f_print_except_safely(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t j = 0; @@ -554,6 +389,7 @@ extern "C" { #if !defined(_di_f_print_except_in_) || !defined(_di_f_print_except_in_dynamic_) || !defined(_di_f_print_except_in_dynamic_partial_) f_status_t private_f_print_except_in(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except_at, const f_string_ranges_t except_in, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t at = 0; f_array_length_t in = 0; @@ -598,6 +434,7 @@ extern "C" { #if !defined(_di_f_print_except_in_raw_) || !defined(_di_f_print_except_in_dynamic_raw_) || !defined(_di_f_print_except_in_dynamic_partial_raw_) f_status_t private_f_print_except_in_raw(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except_at, const f_string_ranges_t except_in, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t at = 0; f_array_length_t in = 0; @@ -640,6 +477,7 @@ extern "C" { #if !defined(_di_f_print_except_in_safely_) || !defined(_di_f_print_except_in_dynamic_safely_) || !defined(_di_f_print_except_in_dynamic_partial_safely_) f_status_t private_f_print_except_in_safely(const f_string_t string, const f_array_length_t offset, const f_array_length_t stop, const f_array_lengths_t except_at, const f_string_ranges_t except_in, FILE *output) { + // @todo update logic to use fwrite() f_array_length_t i = offset; f_array_length_t at = 0; f_array_length_t in = 0; @@ -758,12 +596,16 @@ extern "C" { #if !defined(_di_f_print_terminated_) || !defined(_di_f_print_raw_terminated_) f_status_t private_f_print_terminated(const f_string_t string, FILE *output) { - for (char *current = string; *current; current = current + 1) { + if (fwrite_unlocked(string, 1, strlen(string), output) == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK) return F_status_set_error(F_block); + if (errno == EFAULT) return F_status_set_error(F_buffer); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == EIO) return F_status_set_error(F_input_output); + if (errno == EISDIR) return F_status_set_error(F_file_type_directory); - if (!fputc_unlocked(*current, output)) { - return F_status_set_error(F_output); - } - } // for + return F_status_set_error(F_output); + } return F_none; } diff --git a/level_0/f_print/c/private-print.h b/level_0/f_print/c/private-print.h index b20edf6..cc9a7da 100644 --- a/level_0/f_print/c/private-print.h +++ b/level_0/f_print/c/private-print.h @@ -31,6 +31,11 @@ extern "C" { * F_none on success. * F_data_not if length is 0. * + * F_block (with error bit) if output is set to non-block and the write would result in a blocking operation. + * F_buffer (with error bit) if the buffer is invalid. + * F_file_type_directory (with error bit) if output represents a directory. + * F_input_output (with error bit) on I/O error. + * F_interrupt (with error bit) if interrupt was received. * F_output (with error bit) on failure. * F_parameter (with error bit) if a parameter is invalid. * @@ -58,6 +63,11 @@ extern "C" { * F_none on success. * F_data_not if length is 0. * + * F_block (with error bit) if output is set to non-block and the write would result in a blocking operation. + * F_buffer (with error bit) if the buffer is invalid. + * F_file_type_directory (with error bit) if output represents a directory. + * F_input_output (with error bit) on I/O error. + * F_interrupt (with error bit) if interrupt was received. * F_output (with error bit) on failure. * F_parameter (with error bit) if a parameter is invalid. * @@ -392,6 +402,11 @@ extern "C" { * F_none on success. * F_data_not if length is 0. * + * F_block (with error bit) if output is set to non-block and the write would result in a blocking operation. + * F_buffer (with error bit) if the buffer is invalid. + * F_file_type_directory (with error bit) if output represents a directory. + * F_input_output (with error bit) on I/O error. + * F_interrupt (with error bit) if interrupt was received. * F_output (with error bit) on failure. * F_parameter (with error bit) if a parameter is invalid. * diff --git a/level_0/f_print/data/build/settings b/level_0/f_print/data/build/settings index e257986..ce21ec5 100644 --- a/level_0/f_print/data/build/settings +++ b/level_0/f_print/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_serialize/data/build/settings b/level_0/f_serialize/data/build/settings index f17aab0..ec4a495 100644 --- a/level_0/f_serialize/data/build/settings +++ b/level_0/f_serialize/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_signal/data/build/settings b/level_0/f_signal/data/build/settings index 6875e9e..92c1839 100644 --- a/level_0/f_signal/data/build/settings +++ b/level_0/f_signal/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_socket/data/build/settings b/level_0/f_socket/data/build/settings index fa79af9..5960f87 100644 --- a/level_0/f_socket/data/build/settings +++ b/level_0/f_socket/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_status/data/build/settings b/level_0/f_status/data/build/settings index d9e039b..fa3c4f1 100644 --- a/level_0/f_status/data/build/settings +++ b/level_0/f_status/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_string/data/build/settings b/level_0/f_string/data/build/settings index 274d90b..195ae1b 100644 --- a/level_0/f_string/data/build/settings +++ b/level_0/f_string/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_thread/data/build/settings b/level_0/f_thread/data/build/settings index 452477f..39970b7 100644 --- a/level_0/f_thread/data/build/settings +++ b/level_0/f_thread/data/build/settings @@ -49,7 +49,7 @@ defines_all -D_pthread_attr_unsupported_ -D_pthread_sigqueue_unsupported_ defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_type/data/build/settings b/level_0/f_type/data/build/settings index 9814906..c83be62 100644 --- a/level_0/f_type/data/build/settings +++ b/level_0/f_type/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_type_array/data/build/settings b/level_0/f_type_array/data/build/settings index acc5998..8ae637d 100644 --- a/level_0/f_type_array/data/build/settings +++ b/level_0/f_type_array/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_0/f_utf/data/build/settings b/level_0/f_utf/data/build/settings index 8499d58..7ad3a85 100644 --- a/level_0/f_utf/data/build/settings +++ b/level_0/f_utf/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_console/data/build/settings b/level_1/fl_console/data/build/settings index 283560a..3458125 100644 --- a/level_1/fl_console/data/build/settings +++ b/level_1/fl_console/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_control_group/data/build/settings b/level_1/fl_control_group/data/build/settings index ffc9182..96fbbb8 100644 --- a/level_1/fl_control_group/data/build/settings +++ b/level_1/fl_control_group/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_conversion/data/build/settings b/level_1/fl_conversion/data/build/settings index 0ef5724..12cdeb6 100644 --- a/level_1/fl_conversion/data/build/settings +++ b/level_1/fl_conversion/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_directory/data/build/settings b/level_1/fl_directory/data/build/settings index f9eadf8..bc1acfe 100644 --- a/level_1/fl_directory/data/build/settings +++ b/level_1/fl_directory/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_environment/data/build/settings b/level_1/fl_environment/data/build/settings index 655ba00..867e757 100644 --- a/level_1/fl_environment/data/build/settings +++ b/level_1/fl_environment/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_execute/data/build/settings b/level_1/fl_execute/data/build/settings index 3a7d1cb..7a56d14 100644 --- a/level_1/fl_execute/data/build/settings +++ b/level_1/fl_execute/data/build/settings @@ -50,7 +50,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_fss/data/build/settings b/level_1/fl_fss/data/build/settings index 6aaa88c..67cac61 100644 --- a/level_1/fl_fss/data/build/settings +++ b/level_1/fl_fss/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_iki/data/build/settings b/level_1/fl_iki/data/build/settings index cdbbb87..f63a293 100644 --- a/level_1/fl_iki/data/build/settings +++ b/level_1/fl_iki/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_print/c/print.c b/level_1/fl_print/c/print.c index 9162d16..1936c27 100644 --- a/level_1/fl_print/c/print.c +++ b/level_1/fl_print/c/print.c @@ -8,8 +8,8 @@ extern "C" { #ifndef _di_fl_print_string_ f_status_t fl_print_string(const f_string_t string, FILE *output, ...) { #ifndef _di_level_1_parameter_checking_ - if (!string) return F_status_set_error(F_parameter); - if (!output) return F_status_set_error(F_parameter); + if (!string) return 0; + if (!output) return 0; #endif // _di_level_1_parameter_checking_ f_status_t status = F_none; @@ -18,18 +18,18 @@ extern "C" { va_start(ap, output); - for (f_string_t current = string; *current; current = current + 1) { + for (f_string_t current = string; *current; current += 1) { if (*current == f_string_ascii_percent_s[0]) { - current = current + 1; + current += 1; - status = private_fl_print_string_convert(¤t, output, &ap); + current = private_fl_print_string_convert(current, output, &ap, &status); if (F_status_is_error(status)) break; - - if (!*current) break; } - else if (!fputc_unlocked(*current, output)) { - return F_status_set_error(F_output); + else { + if (!fputc_unlocked(*current, output)) { + break; + } } } // for @@ -40,38 +40,38 @@ extern "C" { #endif // _di_fl_print_string_ #ifndef _di_fl_print_string_convert_ - f_status_t fl_print_string_convert(f_string_t *current, FILE *output, va_list *ap) { + f_string_t fl_print_string_convert(const f_string_t string, FILE *output, va_list *ap, f_status_t *status) { #ifndef _di_level_1_parameter_checking_ - if (!output) return F_status_set_error(F_parameter); - if (!ap) return F_status_set_error(F_parameter); + if (!output) return 0; + if (!ap) return 0; #endif // _di_level_1_parameter_checking_ - return private_fl_print_string_convert(current, output, ap); + return private_fl_print_string_convert(string, output, ap, status); } #endif // _di_fl_print_string_convert_ #ifndef _di_fl_print_string_va_ f_status_t fl_print_string_va(const f_string_t string, FILE *output, va_list *ap) { #ifndef _di_level_1_parameter_checking_ - if (!string) return F_status_set_error(F_parameter); - if (!output) return F_status_set_error(F_parameter); - if (!ap) return F_status_set_error(F_parameter); + if (!string) return 0; + if (!output) return 0; + if (!ap) return 0; #endif // _di_level_1_parameter_checking_ f_status_t status = F_none; - for (f_string_t current = string; *current; current = current + 1) { + for (f_string_t current = string; *current; current += 1) { if (*current == f_string_ascii_percent_s[0]) { - current = current + 1; + current += 1; - status = private_fl_print_string_convert(¤t, output, ap); + current = private_fl_print_string_convert(current, output, ap, &status); if (F_status_is_error(status)) break; - - if (!*current) break; } - else if (!fputc_unlocked(*current, output)) { - return F_status_set_error(F_output); + else { + if (!fputc_unlocked(*current, output)) { + break; + } } } // for diff --git a/level_1/fl_print/c/print.h b/level_1/fl_print/c/print.h index a6a4217..0c96108 100644 --- a/level_1/fl_print/c/print.h +++ b/level_1/fl_print/c/print.h @@ -47,24 +47,8 @@ extern "C" { * Additional arguments relating to the string. * * @return - * F_none on success. - * - * F_output (with error bit) on failure to print to the output file. - * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). - * - * Success from: f_print_dynamic(). - * Success from: f_print_dynamic_raw(). - * Success from: f_print_dynamic_safely(). - * Success from: f_print_safely(). - * Success from: f_print_terminated(). - * - * Errors (with error bit) from: f_conversion_number_signed_to_file(). - * Errors (with error bit) from: f_conversion_number_unsigned_to_file(). - * Errors (with error bit) from: f_print_dynamic(). - * Errors (with error bit) from: f_print_dynamic_raw(). - * Errors (with error bit) from: f_print_dynamic_safely(). - * Errors (with error bit) from: f_print_safely(). - * Errors (with error bit) from: f_print_terminated(). + * The number of 1-byte characters processed from the string. + * Any error will will result in the current count at the time of the error to be returned. * * @see fputc_unlocked() * @see va_start() @@ -90,33 +74,42 @@ extern "C" { * * This print function does not use locking, be sure something like flockfile() and funlockfile() are appropriately called. * - * @param current + * @param string * The current character position within the string. * This pointer might be updated by this function. * @param output * The file stream to output to, including standard streams such as stdout and stderr. * @param ap * The variable arguments list. + * @param status + * The status is stored here rather then via the return. * * @return - * F_none on success. + * This returns a string at either the start position (if nothing done or an error occurred) or at the character last processed. + * The caller is expected to increment past this if they wish to continue processing the string. * - * F_output (with error bit) on failure to print to the output file. - * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). + * The status parameter will be set as follows: * - * Success from: f_print_dynamic(). - * Success from: f_print_dynamic_raw(). - * Success from: f_print_dynamic_safely(). - * Success from: f_print_safely(). - * Success from: f_print_terminated(). + * F_none on success. * - * Errors (with error bit) from: f_conversion_number_signed_to_file(). - * Errors (with error bit) from: f_conversion_number_unsigned_to_file(). - * Errors (with error bit) from: f_print_dynamic(). - * Errors (with error bit) from: f_print_dynamic_raw(). - * Errors (with error bit) from: f_print_dynamic_safely(). - * Errors (with error bit) from: f_print_safely(). - * Errors (with error bit) from: f_print_terminated(). + * F_output (with error bit) on failure to print to the output file. + * F_parameter (with error bit) if a parameter is invalid. + * F_utf_not (with error bit) if character is an invalid UTF-8 character. + * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). + * + * Success from: f_print_dynamic(). + * Success from: f_print_dynamic_raw(). + * Success from: f_print_dynamic_safely(). + * Success from: f_print_safely(). + * Success from: f_print_terminated(). + * + * Errors (with error bit) from: f_conversion_number_signed_to_file(). + * Errors (with error bit) from: f_conversion_number_unsigned_to_file(). + * Errors (with error bit) from: f_print_dynamic(). + * Errors (with error bit) from: f_print_dynamic_raw(). + * Errors (with error bit) from: f_print_dynamic_safely(). + * Errors (with error bit) from: f_print_safely(). + * Errors (with error bit) from: f_print_terminated(). * * @see fputc_unlocked() * @@ -129,7 +122,7 @@ extern "C" { * @see f_print_terminated() */ #ifndef _di_fl_print_string_convert_ - extern f_status_t fl_print_string_convert(f_string_t *current, FILE *output, va_list *ap); + extern f_string_t fl_print_string_convert(const f_string_t string, FILE *output, va_list *ap, f_status_t *status); #endif // _di_fl_print_string_convert_ /** diff --git a/level_1/fl_print/c/private-print.c b/level_1/fl_print/c/private-print.c index ac36158..46ca516 100644 --- a/level_1/fl_print/c/private-print.c +++ b/level_1/fl_print/c/private-print.c @@ -6,13 +6,18 @@ extern "C" { #endif #if !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) - f_status_t private_fl_print_string_convert(f_string_t *current, FILE *output, va_list *ap) { + f_string_t private_fl_print_string_convert(f_string_t string, FILE *output, va_list *ap, f_status_t *status) { + + const f_string_t start = string; // An unpaired '%' character must not be at the end of the string. - if (!**current) { - return F_status_set_error(F_valid_not); + if (!*string) { + *status = F_status_set_error(F_valid_not); + return string; } + *status = F_none; + uint8_t base = 10; uint16_t flag = 0; uint8_t type = 0; @@ -20,153 +25,167 @@ extern "C" { unsigned int width = 1; unsigned int precision = 1; - for (; **current; *current = *current + 1) { + for (; *string; string += 1) { - if (**current == f_string_ascii_minus_s[0]) { - flag |= f_print_format_flag_align_left; - } - else if (**current == f_string_ascii_pound_s[0]) { - flag |= f_print_format_flag_convert; - } - else if (**current == f_string_ascii_colon_semi_s[0]) { - flag |= f_print_format_flag_ignore_index; - } - else if (**current == f_string_ascii_colon_s[0]) { - flag |= f_print_format_flag_ignore_range; - } - else if (**current == f_string_ascii_plus_s[0]) { - flag |= f_print_format_flag_sign_always; - } - else if (**current == f_string_ascii_space_s[0]) { - flag |= f_print_format_flag_sign_pad; - } - else if (**current == f_string_ascii_equal_s[0]) { - flag |= f_print_format_flag_trim; - } - else if (**current > 0x29 && **current < 0x40) { - if (!(flag & f_print_format_flag_width)) { - if (**current == f_string_ascii_0_s[0]) { - flag |= f_print_format_flag_zeros_leading; - } - else { - flag |= f_print_format_flag_width; + if (*string < 0x2d) { + if (*string == f_string_ascii_space_s[0]) { + flag |= f_print_format_flag_sign_pad; + + continue; + } + else if (*string == f_string_ascii_exclamation_s[0]) { + base = 2; - if (private_fl_print_convert_number(current, ap, &width)) { - break; + continue; + } + else if (*string == f_string_ascii_pound_s[0]) { + flag |= f_print_format_flag_convert; + + continue; + } + else if (*string == f_string_ascii_dollar_s[0]) { + + // If followed immediately by a '$' this is ignored. + // Use '%$' to separate, such as '%l%$l' would allow for '0l' to be printed where '%ll' would interpret the 'l', resulting in a long long. + return string; + } + else if (*string == f_string_ascii_percent_s[0]) { + + // The first percent found represents a literal '%' to be printed, otherwise return as invalid. + if (string == start) { + if (!fputc_unlocked(f_string_ascii_percent_s[0], output)) { + return string; } } + + *status = F_status_set_error(F_valid_not); + return string; + } + else if (*string == f_string_ascii_ampersand_s[0]) { + base = 12; + + continue; + } + else if (*string == f_string_ascii_asterisk_s[0]) { + // @fixme: what should I do here? review the fprintf() docs. + continue; + } + else if (*string == f_string_ascii_plus_s[0]) { + flag |= f_print_format_flag_sign_always; + + continue; } else { - return F_status_set_error(F_valid_not); + *status = F_status_set_error(F_valid_not); + return string; } } - else if (**current == f_string_ascii_dollar_s[0]) { - // If followed immediately by a '$' this is ignored. - // Use '%$' to separate, such as '%l%$l' would allow for '0l' to be printed where '%ll' would interpret the 'l', resulting in a long long. - return F_none; - } - else if (**current == f_string_ascii_exclamation_s[0]) { - base = 2; - } - else if (**current == f_string_ascii_sign_at_s[0]) { - base = 8; - } - else if (**current == f_string_ascii_caret_s[0]) { - base = 10; - } - else if (**current == f_string_ascii_ampersand_s[0]) { - base = 12; - } - else if (**current == f_string_ascii_underscore_s[0]) { - base = 16; - } - else if (**current == f_string_ascii_period_s[0]) { - if (!*(*current + 1)) { - return F_status_set_error(F_valid_not); + else if (*string < 0x49) { + if (*string == f_string_ascii_minus_s[0]) { + flag |= f_print_format_flag_align_left; + + continue; } + else if (*string == f_string_ascii_period_s[0]) { + if (!*(string + 1)) { + *status = F_status_set_error(F_valid_not); + return string; + } - *current = *current + 1; + string += 1; - // @todo this probably needs to check to see if *current + 1 is in fact a number. - if (private_fl_print_convert_number(current, ap, &precision)) { - break; + if (*string < 0x30 || *string > 0x39) { + *status = F_status_set_error(F_valid_not); + return string; + } + + string = private_fl_print_convert_number(string, ap, &precision, status); + if (F_status_is_error(*status)) return string; + + --string; + + continue; } - } - else { - if (**current == f_string_ascii_c_s[0]) { + else if (*string > 0x2f && *string < 0x3a) { + if (!(flag & f_print_format_flag_width)) { + if (*string == f_string_ascii_0_s[0]) { + flag |= f_print_format_flag_zeros_leading; - // char. - const char value = (char) va_arg(*ap, int); + continue; + } - if (!fputc_unlocked(value, output)) { - return F_status_set_error(F_output); + flag |= f_print_format_flag_width; + + string = private_fl_print_convert_number(string, ap, &width, status); + if (F_status_is_error(*status)) return string; + + --string; + + continue; + } + else { + *status = F_status_set_error(F_valid_not); + return string; } + } + else if (*string == f_string_ascii_colon_s[0]) { + flag |= f_print_format_flag_ignore_range; + + continue; + } + else if (*string == f_string_ascii_colon_semi_s[0]) { + flag |= f_print_format_flag_ignore_index; - return F_none; + continue; } - else if (**current == f_string_ascii_C_s[0]) { + else if (*string == f_string_ascii_equal_s[0]) { + flag |= f_print_format_flag_trim; - // safe character. + continue; + } + else if (*string == f_string_ascii_C_s[0]) { char value[1] = { (char) va_arg(*ap, int) }; - return f_print_safely(value, 1, output); + *status = f_print_safely(value, 1, output); + + return string; } - else if (**current == f_string_ascii_i_s[0]) { - type = f_print_format_type_signed; + else { + *status = F_status_set_error(F_valid_not); + return string; + } + } + else if (*string < 0x5b) { + if (*string == f_string_ascii_I_s[0]) { + type = f_print_format_type_signed_32; + flag |= f_print_format_flag_uppercase; - if (*(*current + 1) == f_string_ascii_i_s[0]) { - if (*(*current + 2) == f_string_ascii_i_s[0]) { + if (*(string + 1) == f_string_ascii_I_s[0]) { + if (*(string + 2) == f_string_ascii_I_s[0]) { type = f_print_format_type_signed_8; - *current = *current + 2; + string = string + 2; } else { type = f_print_format_type_signed_16; - *current = *current + 1; + string += 1; } } - } - else if (**current == f_string_ascii_I_s[0]) { - type = f_print_format_type_signed; - flag |= f_print_format_flag_uppercase; - - if (*(*current + 1) == f_string_ascii_I_s[0]) { - if (*(*current + 2) == f_string_ascii_I_s[0]) { - type = f_print_format_type_signed_8; - *current = *current + 2; + else if (*(string + 1) == f_string_ascii_L_s[0]) { + if (*(string + 2) == f_string_ascii_L_s[0]) { + type = f_print_format_type_signed_128; + string = string + 2; } else { - type = f_print_format_type_signed_16; - *current = *current + 1; + type = f_print_format_type_signed_64; + string += 1; } } } - else if (**current == f_string_ascii_l_s[0]) { - type = f_print_format_type_long; - - if (*(*current + 1) == f_string_ascii_l_s[0]) { - type = f_print_format_type_long_long; - *current = *current + 1; - } - } - else if (**current == f_string_ascii_L_s[0]) { - type = f_print_format_type_long; - flag |= f_print_format_flag_uppercase; - - if (*(*current + 1) == f_string_ascii_L_s[0]) { - type = f_print_format_type_long_long; - *current = *current + 1; - } - } - else if (**current == f_string_ascii_n_s[0]) { - type = f_print_format_type_number; - } - else if (**current == f_string_ascii_N_s[0]) { + else if (*string == f_string_ascii_N_s[0]) { type = f_print_format_type_number; flag |= f_print_format_flag_uppercase; } - else if (**current == f_string_ascii_q_s[0]) { - - // static/dynamic string. + else if (*string == f_string_ascii_Q_s[0]) { const f_string_static_t value = va_arg(*ap, f_string_static_t); if (flag & f_print_format_flag_trim) { @@ -175,23 +194,31 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; } - return private_fl_print_trim(value.string, value.used, output); + *status = private_fl_print_trim_safely(value.string, value.used, output); + + return string; } if (flag & f_print_format_flag_ignore_index) { @@ -199,27 +226,154 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return f_print_except_in(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + + return string; + } + + *status = f_print_dynamic_safely(value, output); + + return string; + } + else if (*string == f_string_ascii_S_s[0]) { + const f_string_t value = va_arg(*ap, f_string_t); + + *status = f_print_safely_terminated(value, output); + + return string; + } + else if (*string == f_string_ascii_U_s[0]) { + type = f_print_format_type_unsigned_32; + flag |= f_print_format_flag_uppercase; + + if (*(string + 1) == f_string_ascii_I_s[0]) { + if (*(string + 2) == f_string_ascii_I_s[0]) { + type = f_print_format_type_unsigned_8; + string = string + 2; + } + else { + type = f_print_format_type_unsigned_16; + string += 1; + } + } + else if (*(string + 1) == f_string_ascii_L_s[0]) { + if (*(string + 2) == f_string_ascii_L_s[0]) { + type = f_print_format_type_unsigned_128; + string = string + 2; + } + else { + type = f_print_format_type_unsigned_64; + string += 1; + } + } + else if (*(string + 1) == f_string_ascii_N_s[0]) { + type = f_print_format_type_unsigned_number; + string += 1; + } + else if (*string == f_string_ascii_Z_s[0]) { + type = f_print_format_type_size; + flag |= f_print_format_flag_uppercase; + } + } + else { + *status = F_status_set_error(F_valid_not); + return string; + } + } + else if (*string < 0x63) { + if (*string == f_string_ascii_bracket_open_s[0]) { + const f_color_set_t value = va_arg(*ap, f_color_set_t); + + if (value.before) { + *status = f_print_terminated(value.before->string, output); + } + + return string; + } + else if (*string == f_string_ascii_bracket_close_s[0]) { + const f_color_set_t value = va_arg(*ap, f_color_set_t); + + if (value.after) { + *status = f_print_terminated(value.after->string, output); + } + + return string; + } + else if (*string == f_string_ascii_caret_s[0]) { + base = 10; + + continue; + } + else if (*string == f_string_ascii_underscore_s[0]) { + base = 16; + + continue; + } + else if (*string == f_string_ascii_sign_at_s[0]) { + base = 8; + + continue; + } + else { + *status = F_status_set_error(F_valid_not); + return string; + } + } + else if (*string < 0x72) { + if (*string == f_string_ascii_c_s[0]) { + const char value = (char) va_arg(*ap, uint32_t); + + if (!fputc_unlocked(value, output)) { + *status = F_status_set_error(F_output); } - return f_print_dynamic(value, output); + return string; } - else if (**current == f_string_ascii_Q_s[0]) { + else if (*string == f_string_ascii_i_s[0]) { + type = f_print_format_type_signed_32; - // safe static/dynamic string. + if (*(string + 1) == f_string_ascii_i_s[0]) { + if (*(string + 2) == f_string_ascii_i_s[0]) { + type = f_print_format_type_signed_8; + string = string + 2; + } + else { + type = f_print_format_type_signed_16; + string += 1; + } + } + else if (*(string + 1) == f_string_ascii_l_s[0]) { + if (*(string + 2) == f_string_ascii_l_s[0]) { + type = f_print_format_type_signed_128; + string = string + 2; + } + else { + type = f_print_format_type_signed_64; + string += 1; + } + } + } + else if (*string == f_string_ascii_n_s[0]) { + type = f_print_format_type_number; + } + else if (*string == f_string_ascii_q_s[0]) { const f_string_static_t value = va_arg(*ap, f_string_static_t); if (flag & f_print_format_flag_trim) { @@ -228,23 +382,31 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in(value.string, value.used, except_at, except_in, output); + + return string; } - return private_fl_print_trim_safely(value.string, value.used, output); + *status = private_fl_print_trim(value.string, value.used, output); + + return string; } if (flag & f_print_format_flag_ignore_index) { @@ -252,25 +414,39 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in_safely(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in(value.string, value.used, except_at, except_in, output); + + return string; } - return f_print_dynamic_safely(value, output); + *status = f_print_dynamic(value, output); + + return string; } - else if (**current == f_string_ascii_r_s[0]) { + else { + *status = F_status_set_error(F_valid_not); + return string; + } + } + else { + if (*string == f_string_ascii_r_s[0]) { // raw static/dynamic string. const f_string_static_t value = va_arg(*ap, f_string_static_t); @@ -281,23 +457,31 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + *status = private_fl_print_trim_except_in_raw(value.string, value.used, except_at, except_in, output); + + return string; } - return private_fl_print_trim_raw(value.string, value.used, output); + *status = private_fl_print_trim_raw(value.string, value.used, output); + + return string; } if (flag & f_print_format_flag_ignore_index) { @@ -305,301 +489,220 @@ extern "C" { f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in_raw(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in_raw(value.string, value.used, except_at, except_in, output); + + return string; } f_array_lengths_t except_at = va_arg(*ap, f_array_lengths_t); f_string_ranges_t except_in = f_string_ranges_t_initialize; - return f_print_except_in_raw(value.string, value.used, except_at, except_in, output); + *status = f_print_except_in_raw(value.string, value.used, except_at, except_in, output); + + return string; } if (flag & f_print_format_flag_ignore_range) { f_array_lengths_t except_at = f_array_lengths_t_initialize; f_string_ranges_t except_in = va_arg(*ap, f_string_ranges_t); - return f_print_except_in_raw(value.string, value.used, except_at, except_in, output); - } + *status = f_print_except_in_raw(value.string, value.used, except_at, except_in, output); - return f_print_dynamic_raw(value, output); - } - else if (**current == f_string_ascii_s_s[0]) { + return string; + } - // NULL terminated string. - const f_string_t value = va_arg(*ap, f_string_t); + *status = f_print_dynamic_raw(value, output); - return f_print_terminated(value, output); + return string; } - else if (**current == f_string_ascii_S_s[0]) { - - // NULL terminated safe string. + else if (*string == f_string_ascii_s_s[0]) { const f_string_t value = va_arg(*ap, f_string_t); - return f_print_safely_terminated(value, output); - } - else if (**current == f_string_ascii_u_s[0]) { - type = f_print_format_type_unsigned; + *status = f_print_terminated(value, output); - if (*(*current + 1) == f_string_ascii_i_s[0]) { - if (*(*current + 2) == f_string_ascii_i_s[0]) { - type = f_print_format_type_unsigned_8; - *current = *current + 2; - } - else { - type = f_print_format_type_unsigned_16; - *current = *current + 1; - } - } - else if (*(*current + 1) == f_string_ascii_l_s[0]) { - if (*(*current + 2) == f_string_ascii_l_s[0]) { - type = f_print_format_type_unsigned_long_long; - *current = *current + 2; - } - else { - type = f_print_format_type_unsigned_long; - *current = *current + 1; - } - } - else if (*(*current + 1) == f_string_ascii_n_s[0]) { - type = f_print_format_type_unsigned_number; - *current = *current + 1; - } + return string; } - else if (**current == f_string_ascii_U_s[0]) { - type = f_print_format_type_unsigned; - flag |= f_print_format_flag_uppercase; + else if (*string == f_string_ascii_u_s[0]) { + type = f_print_format_type_unsigned_32; - if (*(*current + 1) == f_string_ascii_I_s[0]) { - if (*(*current + 2) == f_string_ascii_I_s[0]) { + if (*(string + 1) == f_string_ascii_i_s[0]) { + if (*(string + 2) == f_string_ascii_i_s[0]) { type = f_print_format_type_unsigned_8; - *current = *current + 2; + string = string + 2; } else { type = f_print_format_type_unsigned_16; - *current = *current + 1; + string += 1; } } - else if (*(*current + 1) == f_string_ascii_L_s[0]) { - if (*(*current + 2) == f_string_ascii_L_s[0]) { - type = f_print_format_type_unsigned_long_long; - *current = *current + 2; + else if (*(string + 1) == f_string_ascii_l_s[0]) { + if (*(string + 2) == f_string_ascii_l_s[0]) { + type = f_print_format_type_unsigned_128; + string = string + 2; } else { - type = f_print_format_type_unsigned_long; - *current = *current + 1; + type = f_print_format_type_unsigned_64; + string += 1; } } - else if (*(*current + 1) == f_string_ascii_N_s[0]) { + else if (*(string + 1) == f_string_ascii_n_s[0]) { type = f_print_format_type_unsigned_number; - *current = *current + 1; + string += 1; } } - else if (**current == f_string_ascii_z_s[0]) { + else if (*string == f_string_ascii_z_s[0]) { type = f_print_format_type_size; } - else if (**current == f_string_ascii_Z_s[0]) { - type = f_print_format_type_size; - flag |= f_print_format_flag_uppercase; - } - else if (**current == f_string_ascii_bracket_open_s[0]) { - const f_color_set_t value = va_arg(*ap, f_color_set_t); - - if (value.before) { - return f_print_dynamic(*value.before, output); - } - - return F_none; - } - else if (**current == f_string_ascii_bracket_close_s[0]) { - const f_color_set_t value = va_arg(*ap, f_color_set_t); - - if (value.after) { - return f_print_dynamic(*value.after, output); - } - - return F_none; - } else { - return F_status_set_error(F_valid_not); + *status = F_status_set_error(F_valid_not); + return string; } + } - f_conversion_data_t conversion_data = macro_f_conversion_data_t_initialize(base, 0, 1); - - if (flag & f_print_format_flag_align_left) { - conversion_data.flag |= f_conversion_data_flag_align_left; - } + f_conversion_data_t conversion_data = macro_f_conversion_data_t_initialize(base, 0, 1); - if (flag & f_print_format_flag_convert) { - conversion_data.flag |= f_conversion_data_flag_base_prepend; - } - - if (flag & f_print_format_flag_sign_always) { - conversion_data.flag |= f_conversion_data_flag_sign_always; - } + if (flag & f_print_format_flag_align_left) { + conversion_data.flag |= f_conversion_data_flag_align_left; + } - if (flag & f_print_format_flag_sign_pad) { - conversion_data.flag |= f_conversion_data_flag_sign_pad; - } + if (flag & f_print_format_flag_convert) { + conversion_data.flag |= f_conversion_data_flag_base_prepend; + } - if (flag & f_print_format_flag_uppercase) { - conversion_data.flag |= f_conversion_data_flag_base_upper; - } + if (flag & f_print_format_flag_sign_always) { + conversion_data.flag |= f_conversion_data_flag_sign_always; + } - if (flag & f_print_format_flag_zeros_leading) { - conversion_data.flag |= f_conversion_data_flag_zeros_leading; - } + if (flag & f_print_format_flag_sign_pad) { + conversion_data.flag |= f_conversion_data_flag_sign_pad; + } - if (flag & f_print_format_flag_width) { - conversion_data.width = width; - } - else if (flag & f_print_format_flag_precision) { - conversion_data.width = precision; - } + if (flag & f_print_format_flag_uppercase) { + conversion_data.flag |= f_conversion_data_flag_base_upper; + } - f_status_t status = F_none; + if (flag & f_print_format_flag_zeros_leading) { + conversion_data.flag |= f_conversion_data_flag_zeros_leading; + } - if (type == f_print_format_type_long) { - status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, long), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_long_long) { - status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, long), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_number) { - status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, f_number_signed_t), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_signed) { - status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, int), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_signed_16) { - // @todo research this: 'short int' is promoted to 'int' when passed through '...'. - const int16_t value = (int16_t) va_arg(*ap, int); + if (flag & f_print_format_flag_width) { + conversion_data.width = width; + } + else if (flag & f_print_format_flag_precision) { + conversion_data.width = precision; + } - status = f_conversion_number_signed_to_file((f_number_signed_t) value, conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_signed_8) { - // @todo research this: 'signed char' is promoted to 'int' when passed through '...'. - const int8_t value = (int8_t) va_arg(*ap, int); + if (type == f_print_format_type_number) { + *status = f_conversion_number_signed_to_file(va_arg(*ap, f_number_signed_t), conversion_data, output); + } + else if (type == f_print_format_type_signed_64) { + *status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, int64_t), conversion_data, output); + } + else if (type == f_print_format_type_signed_128) { + *status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, f_int_128_t), conversion_data, output); + } + else if (type == f_print_format_type_signed_32) { + *status = f_conversion_number_signed_to_file((f_number_signed_t) va_arg(*ap, int32_t), conversion_data, output); + } + else if (type == f_print_format_type_signed_16) { + const int16_t value = (int16_t) va_arg(*ap, int); - status = f_conversion_number_signed_to_file((f_number_signed_t) value, conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_size) { - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, size_t), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned) { - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, unsigned int), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned_16) { - // @todo research this: 'short unsigned int' is promoted to 'int' when passed through '...'. - const uint16_t value = (uint16_t) va_arg(*ap, int); + *status = f_conversion_number_signed_to_file((f_number_signed_t) value, conversion_data, output); + } + else if (type == f_print_format_type_signed_8) { + const int8_t value = (int8_t) va_arg(*ap, int); - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) value, conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned_8) { - // @todo research this: 'unsigned char' is promoted to 'int' when passed through '...'. - const uint8_t value = (uint8_t) va_arg(*ap, int); + *status = f_conversion_number_signed_to_file((f_number_signed_t) value, conversion_data, output); + } + else if (type == f_print_format_type_size) { + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, size_t), conversion_data, output); + } + else if (type == f_print_format_type_unsigned_32) { + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, uint32_t), conversion_data, output); + } + else if (type == f_print_format_type_unsigned_16) { + const uint16_t value = (uint16_t) va_arg(*ap, unsigned); - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) value, conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned_long) { - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, unsigned long), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned_long_long) { - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, unsigned long long), conversion_data, output); - if (F_status_is_error(status)) return status; - } - else if (type == f_print_format_type_unsigned_number) { - status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, f_number_unsigned_t), conversion_data, output); - if (F_status_is_error(status)) return status; - } + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) value, conversion_data, output); + } + else if (type == f_print_format_type_unsigned_8) { + const uint8_t value = (uint8_t) va_arg(*ap, unsigned); - return F_none; + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) value, conversion_data, output); + } + else if (type == f_print_format_type_unsigned_64) { + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, uint64_t), conversion_data, output); + } + else if (type == f_print_format_type_unsigned_128) { + *status = f_conversion_number_unsigned_to_file((f_number_unsigned_t) va_arg(*ap, f_uint_128_t), conversion_data, output); + } + else if (type == f_print_format_type_unsigned_number) { + *status = f_conversion_number_unsigned_to_file(va_arg(*ap, f_number_unsigned_t), conversion_data, output); } - } // for - if (**current) { - return F_none; - } + return string; + } // for - return F_status_set_error(F_valid_not); + *status = F_status_set_error(F_valid_not); + return string; } #endif // !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) #if !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) - f_status_t private_fl_print_convert_number(f_string_t *current, va_list *ap, unsigned int *number) { - - *number = 0; + f_string_t private_fl_print_convert_number(f_string_t string, va_list *ap, unsigned int *number, f_status_t *status) { - for (; **current; *current = *current + 1) { + for (*number = 0; *string; string += 1) { - if (**current == f_string_ascii_0_s[0]) { + if (*string == f_string_ascii_0_s[0]) { *number *= 10; } - else if (**current == f_string_ascii_1_s[0]) { + else if (*string == f_string_ascii_1_s[0]) { *number *= 10; *number += 1; } - else if (**current == f_string_ascii_2_s[0]) { + else if (*string == f_string_ascii_2_s[0]) { *number *= 10; *number += 2; } - else if (**current == f_string_ascii_3_s[0]) { + else if (*string == f_string_ascii_3_s[0]) { *number *= 10; *number += 3; } - else if (**current == f_string_ascii_4_s[0]) { + else if (*string == f_string_ascii_4_s[0]) { *number *= 10; *number += 4; } - else if (**current == f_string_ascii_5_s[0]) { + else if (*string == f_string_ascii_5_s[0]) { *number *= 10; *number += 5; } - else if (**current == f_string_ascii_6_s[0]) { + else if (*string == f_string_ascii_6_s[0]) { *number *= 10; *number += 6; } - else if (**current == f_string_ascii_7_s[0]) { + else if (*string == f_string_ascii_7_s[0]) { *number *= 10; *number += 7; } - else if (**current == f_string_ascii_8_s[0]) { + else if (*string == f_string_ascii_8_s[0]) { *number *= 10; *number += 8; } - else if (**current == f_string_ascii_9_s[0]) { + else if (*string == f_string_ascii_9_s[0]) { *number *= 10; *number += 9; } - else if (**current == f_string_ascii_asterisk_s[0]) { + else if (*string == f_string_ascii_asterisk_s[0]) { *number = va_arg(*ap, unsigned int); break; } else { - - // reset position non-number. - *current = *current - 1; - break; } } // for - if (**current) { - return F_false; - } - - return F_true; + return string; } #endif // !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) diff --git a/level_1/fl_print/c/private-print.h b/level_1/fl_print/c/private-print.h index 23e84cf..79b4e25 100644 --- a/level_1/fl_print/c/private-print.h +++ b/level_1/fl_print/c/private-print.h @@ -21,35 +21,41 @@ extern "C" { * This should be called after each first '%' is encountered. * This should return only after a single '%' group is fully processed, end of current is reached, or an error occurs. * - * @param current + * @param string * The current character position within the string. * @param output * The file stream to output to, including standard streams such as stdout and stderr. * @param ap * The variable arguments list. + * @param status + * The status is stored here rather then via the return. * * @return - * F_none on success. + * This returns a string at either the start position (if nothing done or an error occurred) or at the character last processed. + * The caller is expected to increment past this if they wish to continue processing the string. * - * F_output (with error bit) on failure to print to the output file. - * F_parameter (with error bit) if a parameter is invalid. - * F_utf_not (with error bit) if character is an invalid UTF-8 character. - * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). - * - * Success from: f_print_dynamic(). - * Success from: f_print_dynamic_raw(). - * Success from: f_print_dynamic_safely(). - * Success from: f_print_safely(). - * Success from: f_print_terminated(). - * - * Errors (with error bit) from: f_conversion_number_signed_to_file(). - * Errors (with error bit) from: f_conversion_number_unsigned_to_file(). - * Errors (with error bit) from: f_print_dynamic(). - * Errors (with error bit) from: f_print_dynamic_raw(). - * Errors (with error bit) from: f_print_dynamic_safely(). - * Errors (with error bit) from: f_print_safely(). - * Errors (with error bit) from: f_print_terminated(). - * Errors (with error bit) from: f_utf_is_whitespace(). + * The status parameter will be set as follows: + * + * F_none on success. + * + * F_output (with error bit) on failure to print to the output file. + * F_parameter (with error bit) if a parameter is invalid. + * F_utf_not (with error bit) if character is an invalid UTF-8 character. + * F_valid_not (with error bit) on invalid syntax (such as terminating the string on a single '%'). + * + * Success from: f_print_dynamic(). + * Success from: f_print_dynamic_raw(). + * Success from: f_print_dynamic_safely(). + * Success from: f_print_safely(). + * Success from: f_print_terminated(). + * + * Errors (with error bit) from: f_conversion_number_signed_to_file(). + * Errors (with error bit) from: f_conversion_number_unsigned_to_file(). + * Errors (with error bit) from: f_print_dynamic(). + * Errors (with error bit) from: f_print_dynamic_raw(). + * Errors (with error bit) from: f_print_dynamic_safely(). + * Errors (with error bit) from: f_print_safely(). + * Errors (with error bit) from: f_print_terminated(). * * @see fputc_unlocked() * @@ -64,7 +70,7 @@ extern "C" { * @see private_fl_print_convert_number() */ #if !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) - extern f_status_t private_fl_print_string_convert(f_string_t *current, FILE *output, va_list *ap) f_attribute_visibility_internal; + extern f_string_t private_fl_print_string_convert(f_string_t string, FILE *output, va_list *ap, f_status_t *status) f_attribute_visibility_internal; #endif // !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) /** @@ -74,7 +80,7 @@ extern "C" { * * On return the current will point to either the last consecutive character representing a number, the asterisk, or NULL. * - * @param current + * @param string * The current character position within the string. * @param ap * The variable arguments list. @@ -88,7 +94,7 @@ extern "C" { * @see va_arg() */ #if !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) - extern f_status_t private_fl_print_convert_number(f_string_t *current, va_list *ap, unsigned int *number) f_attribute_visibility_internal; + extern f_string_t private_fl_print_convert_number(f_string_t string, va_list *ap, unsigned int *number, f_status_t *status) f_attribute_visibility_internal; #endif // !defined(_di_fl_print_string_convert_) || !defined(_di_fl_print_string_) /** diff --git a/level_1/fl_print/data/build/settings b/level_1/fl_print/data/build/settings index 67eea4f..8fe3b99 100644 --- a/level_1/fl_print/data/build/settings +++ b/level_1/fl_print/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_signal/data/build/settings b/level_1/fl_signal/data/build/settings index dd47cd8..e2f04b8 100644 --- a/level_1/fl_signal/data/build/settings +++ b/level_1/fl_signal/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_status/data/build/settings b/level_1/fl_status/data/build/settings index ea3c017..fa24e2d 100644 --- a/level_1/fl_status/data/build/settings +++ b/level_1/fl_status/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_string/data/build/settings b/level_1/fl_string/data/build/settings index df4febe..729a85c 100644 --- a/level_1/fl_string/data/build/settings +++ b/level_1/fl_string/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_utf/data/build/settings b/level_1/fl_utf/data/build/settings index f4c64a8..0efea9d 100644 --- a/level_1/fl_utf/data/build/settings +++ b/level_1/fl_utf/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_1/fl_utf_file/data/build/settings b/level_1/fl_utf_file/data/build/settings index 53f8bce..02edb09 100644 --- a/level_1/fl_utf_file/data/build/settings +++ b/level_1/fl_utf_file/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_control_group/data/build/settings b/level_2/fll_control_group/data/build/settings index 1d54f73..2ef531a 100644 --- a/level_2/fll_control_group/data/build/settings +++ b/level_2/fll_control_group/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_error/data/build/settings b/level_2/fll_error/data/build/settings index cff1fc9..f6c18c0 100644 --- a/level_2/fll_error/data/build/settings +++ b/level_2/fll_error/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_execute/data/build/settings b/level_2/fll_execute/data/build/settings index 40efb65..3b0a735 100644 --- a/level_2/fll_execute/data/build/settings +++ b/level_2/fll_execute/data/build/settings @@ -52,7 +52,7 @@ defines_all-individual_threadless -D_di_pthread_support_ defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_all-individual -pthread flags_shared flags_static diff --git a/level_2/fll_file/data/build/settings b/level_2/fll_file/data/build/settings index 2f4cc2c..d59b9a8 100644 --- a/level_2/fll_file/data/build/settings +++ b/level_2/fll_file/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_fss/data/build/settings b/level_2/fll_fss/data/build/settings index b49d1c7..5ec4d41 100644 --- a/level_2/fll_fss/data/build/settings +++ b/level_2/fll_fss/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_iki/data/build/settings b/level_2/fll_iki/data/build/settings index 8210403..6a3b7d6 100644 --- a/level_2/fll_iki/data/build/settings +++ b/level_2/fll_iki/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_path/data/build/settings b/level_2/fll_path/data/build/settings index 4897c50..d7d410f 100644 --- a/level_2/fll_path/data/build/settings +++ b/level_2/fll_path/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_print/c/print.c b/level_2/fll_print/c/print.c index ccfa8af..79971b3 100644 --- a/level_2/fll_print/c/print.c +++ b/level_2/fll_print/c/print.c @@ -414,15 +414,15 @@ extern "C" { #endif // _di_fll_print_string_ #ifndef _di_fll_print_string_convert_ - f_status_t fll_print_string_convert(f_string_t *current, FILE *output, va_list *ap) { + f_string_t fll_print_string_convert(const f_string_t string, FILE *output, va_list *ap, f_status_t *status) { flockfile(output); - const f_status_t status = fl_print_string_convert(current, output, ap); + f_string_t str = fl_print_string_convert(string, output, ap, status); funlockfile(output); - return status; + return str; } #endif // _di_fll_print_string_convert_ diff --git a/level_2/fll_print/c/print.h b/level_2/fll_print/c/print.h index 215d54c..aa6a3f4 100644 --- a/level_2/fll_print/c/print.h +++ b/level_2/fll_print/c/print.h @@ -898,11 +898,11 @@ extern "C" { * The file stream to output to, including standard streams such as stdout and stderr. * @param ap * The variable arguments list. + * @param status + * The status is stored here rather then via the return. * * @return - * Success from: fl_print_string_convert(). - * - * Errors (with error bit) from: fl_print_string_convert(). + * Result from: fl_print_string_convert(). * * @see flockfile() * @see funlockfile() @@ -910,7 +910,7 @@ extern "C" { * @see fl_print_string_convert() */ #ifndef _di_fll_print_string_convert_ - extern f_status_t fll_print_string_convert(f_string_t *current, FILE *output, va_list *ap); + extern f_string_t fll_print_string_convert(const f_string_t current, FILE *output, va_list *ap, f_status_t *status); #endif // _di_fll_print_string_convert_ /** diff --git a/level_2/fll_print/data/build/settings b/level_2/fll_print/data/build/settings index a44d01b..b97cccc 100644 --- a/level_2/fll_print/data/build/settings +++ b/level_2/fll_print/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_program/data/build/settings b/level_2/fll_program/data/build/settings index 4e31a67..0baf3d5 100644 --- a/level_2/fll_program/data/build/settings +++ b/level_2/fll_program/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_2/fll_status/data/build/settings b/level_2/fll_status/data/build/settings index 7c8a1f3..67bd9ae 100644 --- a/level_2/fll_status/data/build/settings +++ b/level_2/fll_status/data/build/settings @@ -49,7 +49,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index a74ac08..443865f 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -55,14 +55,14 @@ extern "C" { fll_program_print_help_usage(output, context, byte_dump_name, "filename(s)"); f_print_terminated(" When using the ", output.stream); - fl_print_string("%[%S%S%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_text, context.set.notable); + fl_print_string("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_text, context.set.notable); f_print_terminated(" option, some UTF-8 characters may be replaced by your instance and cause display alignment issues.", output.stream); f_print_terminated(f_string_eol_s, output.stream); f_print_terminated(f_string_eol_s, output.stream); f_print_terminated(" Special UTF-8 characters and non-spacing UTF-8 characters may be replaced with a space (or a placeholder when the ", output.stream); - fl_print_string("%[%S%S%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_placeholder, context.set.notable); + fl_print_string("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_placeholder, context.set.notable); f_print_terminated(" option is used).", output.stream); f_print_terminated(f_string_eol_s, output.stream); @@ -74,14 +74,14 @@ extern "C" { f_print_terminated(f_string_eol_s, output.stream); f_print_terminated(" When ", output.stream); - fl_print_string("%[%S%S%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, context.set.notable); + fl_print_string("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, context.set.notable); f_print_terminated(" is used, any UTF-8 sequences will still be printed in full should any part is found within the requested range.", output.stream); f_print_terminated(f_string_eol_s, output.stream); f_print_terminated(f_string_eol_s, output.stream); f_print_terminated(" When using the ", output.stream); - fl_print_string("%[%S%S%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_unicode, context.set.notable); + fl_print_string("%[%s%s%]", output.stream, context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_unicode, context.set.notable); f_print_terminated(" option, invalid Unicode will fallback to being displayed using one of the other modes.", output.stream); f_print_terminated(f_string_eol_s, output.stream); @@ -234,7 +234,7 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_width, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_width, main->context.set.notable); fl_print_string("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -254,7 +254,7 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_width, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_width, main->context.set.notable); fl_print_string("%[' value can only be a number (inclusively) between %]", main->error.to.stream, main->context.set.error, main->context.set.error); fl_print_string("%[1%]", main->error.to.stream, main->context.set.notable, main->context.set.notable); fl_print_string("%[ and %]", main->error.to.stream, main->context.set.error, main->context.set.error); @@ -274,7 +274,7 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); fl_print_string("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -294,11 +294,11 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); fl_print_string("%[' value can only be a number (inclusively) between %]", main->error.to.stream, main->context.set.error, main->context.set.error); fl_print_string("%[0%]", main->error.to.stream, main->context.set.notable, main->context.set.notable); fl_print_string("%[ and %]", main->error.to.stream, main->context.set.error, main->context.set.error); - fl_print_string("%[%llu%]", main->error.to.stream, main->context.set.notable, f_number_t_size_unsigned, main->context.set.notable); + fl_print_string("%[%ul%]", main->error.to.stream, main->context.set.notable, f_number_t_size_unsigned, main->context.set.notable); fl_print_string("%[.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -314,7 +314,7 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); fl_print_string("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -334,11 +334,11 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); fl_print_string("%[' value can only be a number (inclusively) between %]", main->error.to.stream, main->context.set.error, main->context.set.error); fl_print_string("%[0%]", main->error.to.stream, main->context.set.notable, main->context.set.notable); fl_print_string("%[ and %]", main->error.to.stream, main->context.set.error, main->context.set.error); - fl_print_string("%[%llu%]", main->error.to.stream, main->context.set.notable, f_number_t_size_unsigned, main->context.set.notable); + fl_print_string("%[%ul%]", main->error.to.stream, main->context.set.notable, f_number_t_size_unsigned, main->context.set.notable); fl_print_string("%[.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -355,9 +355,9 @@ extern "C" { flockfile(main->error.to.stream); fl_print_string("%[%sThe parameter '%]", main->error.to.stream, main->context.set.error, fll_error_print_error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_first, main->context.set.notable); fl_print_string("%[' value cannot be greater than the parameter '%]", main->error.to.stream, main->context.set.error, main->context.set.error); - fl_print_string("%[%S%S%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); + fl_print_string("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, byte_dump_long_last, main->context.set.notable); fl_print_string("%[' value.%]%c", main->error.to.stream, main->context.set.error, main->context.set.error, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -475,6 +475,8 @@ extern "C" { fl_print_string(")%]%c", main->output.stream, main->context.set.title, f_string_eol_s[0]); + funlockfile(main->output.stream); + status = byte_dump_file(*main, arguments.argv[main->remaining.array[counter]], file); f_file_stream_close(F_true, &file); diff --git a/level_3/byte_dump/c/byte_dump.h b/level_3/byte_dump/c/byte_dump.h index 5c36737..91ee210 100644 --- a/level_3/byte_dump/c/byte_dump.h +++ b/level_3/byte_dump/c/byte_dump.h @@ -91,6 +91,7 @@ extern "C" { }; #define byte_dump_sequence_acknowledge "␆" + #define byte_dump_sequence_acknowledge_negative "␕" #define byte_dump_sequence_backspace "␈" #define byte_dump_sequence_bell "␇" #define byte_dump_sequence_cancel "␘" @@ -111,7 +112,6 @@ extern "C" { #define byte_dump_sequence_form_feed "␌" #define byte_dump_sequence_group_separator "␝" #define byte_dump_sequence_line_feed "␊" - #define byte_dump_sequence_negative_acknowledge "␕" #define byte_dump_sequence_new_line "␤" #define byte_dump_sequence_null "␀" #define byte_dump_sequence_record_separator "␞" diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index dd45481..0204106 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -314,7 +314,7 @@ extern "C" { } if (!cell->column) { - fl_print_string("%[%016ULL%] ", main.output.stream, main.context.set.notable, (uint64_t) cell->row, main.context.set.notable); + fl_print_string("%[%016_UL%] ", main.output.stream, main.context.set.notable, cell->row, main.context.set.notable); if (*offset) { uint8_t offset_to_print = *offset; @@ -702,7 +702,7 @@ extern "C" { f_print_terminated(byte_dump_sequence_device_control_4, main.output.stream); } else if (output == 21) { - f_print_terminated(byte_dump_sequence_negative_acknowledge, main.output.stream); + f_print_terminated(byte_dump_sequence_acknowledge_negative, main.output.stream); } else if (output == 22) { f_print_terminated(byte_dump_sequence_synchronous_idle, main.output.stream); diff --git a/level_3/byte_dump/data/build/settings b/level_3/byte_dump/data/build/settings index 86d7f58..97015d7 100644 --- a/level_3/byte_dump/data/build/settings +++ b/level_3/byte_dump/data/build/settings @@ -51,7 +51,7 @@ defines_all defines_static defines_shared -flags_all -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses +flags_all -O2 -z now -g -fdiagnostics-color=always -Wno-logical-not-parentheses -Wno-logical-op-parentheses -Wno-parentheses flags_shared flags_static flags_library -fPIC