From aa6079d2a4f8b0b24bed35780b84552f33d1a7a4 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 10 Jul 2022 17:49:53 -0500 Subject: [PATCH] Feature: Add support to the "print" operation for escape sequences just like the "write" operation has. The print now prints raw data. Fix documentation comments. --- level_3/fake/c/private-make-operate_process.c | 18 +----- level_3/fake/c/private-make-operate_process.h | 1 + level_3/fake/c/private-make-operate_process_type.c | 71 ++++++++++++++++++++++ level_3/fake/c/private-make-operate_process_type.h | 66 +++++++++++++------- level_3/fake/documents/fakefile.txt | 22 ++++++- 5 files changed, 139 insertions(+), 39 deletions(-) diff --git a/level_3/fake/c/private-make-operate_process.c b/level_3/fake/c/private-make-operate_process.c index 91cf46a..f669364 100644 --- a/level_3/fake/c/private-make-operate_process.c +++ b/level_3/fake/c/private-make-operate_process.c @@ -396,21 +396,7 @@ extern "C" { } if (state_process->operation == fake_make_operation_type_print_e) { - flockfile(data_make->main->output.to.stream); - - for (f_array_length_t i = 0; i < arguments.used; ++i) { - - f_print_dynamic(arguments.array[i], data_make->main->output.to.stream); - - if (i + 1 < arguments.used) { - f_print_dynamic_raw(f_string_space_s, data_make->main->output.to.stream); - } - } // for - - f_print_dynamic_raw(f_string_space_s, data_make->main->output.to.stream); - f_print_dynamic_raw(f_string_eol_s, data_make->main->output.to.stream); - - funlockfile(data_make->main->output.to.stream); + *status = fake_make_operate_process_type_print(data_make, arguments); return 0; } @@ -466,8 +452,6 @@ extern "C" { #ifndef _di_fake_make_operate_process_buffer_escape_ f_status_t fake_make_operate_process_buffer_escape(fake_make_data_t * const data_make, const f_string_static_t source, f_string_dynamic_t * const destination) { - destination->used = 0; - if (!source.used) return F_data_not; f_status_t status = f_string_dynamic_increase_by(source.used, destination); diff --git a/level_3/fake/c/private-make-operate_process.h b/level_3/fake/c/private-make-operate_process.h index 5d00e36..c885cab 100644 --- a/level_3/fake/c/private-make-operate_process.h +++ b/level_3/fake/c/private-make-operate_process.h @@ -69,6 +69,7 @@ extern "C" { * The source string to process and esacpe. * @param destination * The processed and escaped string. + * This is appended to. * * @return * F_none on success. diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index 4b9d5f4..c769eda 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -1317,6 +1317,75 @@ extern "C" { } #endif // _di_fake_make_operate_process_type_pop_ +#ifndef _di_fake_make_operate_process_type_print_ + f_status_t fake_make_operate_process_type_print(fake_make_data_t * const data_make, const f_string_dynamics_t arguments) { + + f_status_t status = F_none; + + data_make->cache_1.used = 0; + + { + f_array_length_t i = 0; + + // Pre-allocate the cache to reduce allocations. + { + f_array_length_t total = arguments.used; + + for (; i < arguments.used; ++i) { + total += arguments.array[i].used; + } // for + + status = f_string_dynamic_increase_by(total, &data_make->cache_1); + + if (F_status_is_error(status)) { + fll_error_print(data_make->error, F_status_set_fine(status), "f_file_stream_open", F_true); + + return status; + } + } + + for (i = 0; i < arguments.used; ++i) { + + status = fake_make_operate_process_buffer_escape(data_make, arguments.array[i], &data_make->cache_1); + + if (F_status_is_error(status)) { + fll_error_print(data_make->error, F_status_set_fine(status), "f_file_stream_open", F_true); + + return status; + } + + if (i + 1 < arguments.used) { + status = f_string_dynamic_increase_by(1, &data_make->cache_1); + + if (F_status_is_error(status)) { + fll_error_print(data_make->error, F_status_set_fine(status), "f_file_stream_open", F_true); + + return status; + } + + status = f_string_dynamic_append(f_string_space_s, &data_make->cache_1); + + if (F_status_is_error(status)) { + fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamic_append", F_true); + + return status; + } + } + } // for + } + + flockfile(data_make->main->output.to.stream); + + fll_print_dynamic_raw(data_make->cache_1, data_make->main->output.to.stream); + fll_print_dynamic_raw(f_string_space_s, data_make->main->output.to.stream); + fll_print_dynamic_raw(f_string_eol_s, data_make->main->output.to.stream); + + funlockfile(data_make->main->output.to.stream); + + return F_none; + } +#endif // _di_fake_make_operate_process_type_print_ + #ifndef _di_fake_make_operate_process_type_to_ f_status_t fake_make_operate_process_type_to(fake_make_data_t * const data_make, const f_string_dynamics_t arguments) { @@ -1514,6 +1583,8 @@ extern "C" { if (F_status_is_error_not(status)) { for (f_array_length_t i = 1; i < arguments.used; ++i) { + data_make->cache_1.used = 0; + status = fake_make_operate_process_buffer_escape(data_make, arguments.array[i], &data_make->cache_1); if (F_status_is_error(status)) { diff --git a/level_3/fake/c/private-make-operate_process_type.h b/level_3/fake/c/private-make-operate_process_type.h index e83c655..98676f7 100644 --- a/level_3/fake/c/private-make-operate_process_type.h +++ b/level_3/fake/c/private-make-operate_process_type.h @@ -18,7 +18,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param clone * If TRUE, perform a copy that is a clone (preserved timestamps, roles, and permissions). * If FALSE, perforrm a normaly copy without preserving properties. @@ -48,7 +48,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param all * If TRUE, then if the path is a directory, then recursively apply to all paths within the directory. * If FALSE, then only apply to the given path. @@ -76,7 +76,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. */ #ifndef _di_fake_make_operate_process_type_fail_ extern void fake_make_operate_process_type_fail(fake_make_data_t * const data_make, const f_string_dynamics_t arguments) F_attribute_visibility_internal_d; @@ -88,7 +88,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param all * If TRUE, then if the path is a directory, then recursively apply to all paths within the directory. * If FALSE, then only apply to the given path. @@ -118,7 +118,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -138,7 +138,7 @@ extern "C" { * When TRUE, perform the if not is. * When FALSE, perform the if is. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param state_process * The operation process state. * @@ -159,7 +159,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param state_process * The operation process state. * @@ -180,7 +180,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -208,7 +208,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -232,7 +232,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -262,7 +262,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -290,7 +290,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param if_not * When TRUE, perform the if not is. * When FALSE, perform the if is. @@ -307,7 +307,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param all * If TRUE, then if the path is a directory, then recursively apply to all paths within the directory. * If FALSE, then only apply to the given path. @@ -337,7 +337,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -358,7 +358,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * @param all * If TRUE, then if the path is a directory, then recursively apply to all paths within the directory. * If FALSE, then only apply to the given path. @@ -388,7 +388,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -414,7 +414,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -432,12 +432,36 @@ extern "C" { #endif // _di_fake_make_operate_process_type_pop_ /** + * Perform the print operation process. + * + * @param data_make + * All make related setting data, including data from the fakefile and the build settings file. + * This resets and uses data_make.cache_1. + * @param arguments + * The arguments for print operation. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: fake_make_operate_process_buffer_escape(). + * Errors (with error bit) from: f_string_dynamic_append(). + * Errors (with error bit) from: f_string_dynamic_increase_by(). + * + * @see fake_make_operate_process_buffer_escape() + * @see f_string_dynamic_append() + * @see f_string_dynamic_increase_by() + */ +#ifndef _di_fake_make_operate_process_type_print_ + extern f_status_t fake_make_operate_process_type_print(fake_make_data_t * const data_make, const f_string_dynamics_t arguments) F_attribute_visibility_internal_d; +#endif // _di_fake_make_operate_process_type_print_ + +/** * Perform the to operation process. * * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -465,7 +489,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -486,7 +510,7 @@ extern "C" { * @param data_make * All make related setting data, including data from the fakefile and the build settings file. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. @@ -508,7 +532,7 @@ extern "C" { * All make related setting data, including data from the fakefile and the build settings file. * This resets and uses data_make.cache_1. * @param arguments - * The arguments for the run or shell operation. + * The arguments for the operation. * * @return * F_none on success. diff --git a/level_3/fake/documents/fakefile.txt b/level_3/fake/documents/fakefile.txt index bef4bf4..f21c8eb 100644 --- a/level_3/fake/documents/fakefile.txt +++ b/level_3/fake/documents/fakefile.txt @@ -395,10 +395,30 @@ Fakefile Documentation: - print\: Print the content to the output screen. - This always prints a newline. + This always prints a newline at the end. All Content is printed, and if no Content is provided, an empty line is printed. + The following escape sequences are supported for printing special characters: + - "\f": Form Feed. + - "\n": New Line. + - "\r": Carriage Return. + - "\t": Tab. + - "\v": Vertical Tab. + - "\\": Backslash Character (may require additional slashes in certain circumstances.) + - "\0": NULL Character. + - "\U+": Unicode Sequence (followed by a valid Unicode sequence with a minimum 4 hexidecimal digits and a maximum of 6 hexidecimal digits). + - "\U-": Terminate a Unicode Sequence, allowing for "\U+000A\U-5" to be equivalent to "\n5". + + If the Unicode is invalid, then nothing is printed for that character (the invalid character is skipped when printing). + Example Unicodes\: + - "\U+000A": Prints a new line, equivalent to "\n". + - "\U+2E19": Prints the Unicode feather-like character "⸙". + + Only ASCII alpha-numeric hexidecimal digits are allowed in the Unicode sequence (upper or lower case). + + Invalid or unknown escape sequences are not printed. + - run\: Manually execute a remote program or script. This program must be in the appropriate PATH environment or otherwise automatically detected when calling without a specific path to the program or script. -- 1.8.3.1