From: Kevin Day Date: Tue, 8 Feb 2022 05:39:57 +0000 (-0600) Subject: Bugfix: Bugs and regressions in recent "Progress:.." commits as well as in the Fake... X-Git-Tag: 0.5.8~69 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=90a993388be898234238434ee3f0a408492d1f6e;p=fll Bugfix: Bugs and regressions in recent "Progress:.." commits as well as in the Fake program. This is in a way a continuation of the "Progress: Continue mass converting to f_string_static_t." commits. However, there were some notable bugs that needed to be brought out and I feel they deserved to be treated as a bug rather than in-progress code changes. Put the testfile context in a quote and fix the color context to perform the reset rather than leak red all over the console. NULL terminate some f_environment functions to make compatibility with working with NULL terminated string functions more straight-forward. This is noticed with the libc/POSIX execute family of functions. The fl_console_parameter_to_string_dynamic_directory() needed to be converted in regards to the mass converting to f_string_static_t. Make sure NULL termination is performed, which is previously may not have been (prior to transition to f_string_static_t, making this a bug). I accidentally over-fixed "c1906053 Bugfix: File stream read inefficiency, allocation f_string_t instead of char, and actually use state.step_small.". There is a case where the array is in fact an array of f_string_t and I incorrectly changed it to "char", resulting in a regression. Have the fll_fss_snatch_apart() use *_increase_by() and similar functions rather than *_resize(). The *_resize() functions are more expensive in that the *_increase_by() only perform reallocations when necessary whereas the *_resize() almost always performs reallocations. Make sure fll_fss_snatch_apart() calls f_string_dynamic_terminate_after(). I started to convert some of the macro delete functions in the Fake program to actual functions, but this process is very incomplete. Add a couple of cache objects to th Fake program. There are a lot of areas where caching can be used for increasing memory use efficiency, but much of this is ignore for now. I hope to do more work in more completely utilizing caches in the Fake program before the upcoming stable release. The Fake program needs to use the fake_default_allocation_small_d more consistently rather than F_memory_default_allocation_small_d. Miscellaneous "Progress: Continue mass converting to f_string_static_t." related changes in the Fake program. Some of these are just f_print_format() string fixes where '%S' is changed to '%Q' or '%r'. The fake_make_operate_process_run() can be optimized to just perform an offset on the array rather than making an entirely new copy. This should save a notable amount of memory. --- diff --git a/level_0/f_account/data/build/testfile b/level_0/f_account/data/build/testfile index 6acb1da..aa214a7 100644 --- a/level_0/f_account/data/build/testfile +++ b/level_0/f_account/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_capability/data/build/testfile b/level_0/f_capability/data/build/testfile index 11eb658..25e57dd 100644 --- a/level_0/f_capability/data/build/testfile +++ b/level_0/f_capability/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_color/data/build/testfile b/level_0/f_color/data/build/testfile index 64b0d9e..4e9d3f8 100644 --- a/level_0/f_color/data/build/testfile +++ b/level_0/f_color/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_console/data/build/testfile b/level_0/f_console/data/build/testfile index ed22f9c..311e81a 100644 --- a/level_0/f_console/data/build/testfile +++ b/level_0/f_console/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_control_group/data/build/testfile b/level_0/f_control_group/data/build/testfile index a9369e8..40f0679 100644 --- a/level_0/f_control_group/data/build/testfile +++ b/level_0/f_control_group/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_conversion/data/build/testfile b/level_0/f_conversion/data/build/testfile index f3dfc09..53cf788 100644 --- a/level_0/f_conversion/data/build/testfile +++ b/level_0/f_conversion/data/build/testfile @@ -26,7 +26,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_environment/c/environment.c b/level_0/f_environment/c/environment.c index a1106bd..171909a 100644 --- a/level_0/f_environment/c/environment.c +++ b/level_0/f_environment/c/environment.c @@ -50,13 +50,19 @@ extern "C" { const f_array_length_t size = strnlen(result, f_environment_max_length); if (size) { - const f_status_t status = f_string_dynamic_increase_by(size, value); + const f_status_t status = f_string_dynamic_increase_by(size + 1, value); if (F_status_is_error(status)) return status; memcpy(value->string + value->used, result, size); + value->used += size; + value->string[value->used] = 0; } else { + const f_status_t status = f_string_dynamic_increase_by(1, value); + if (F_status_is_error(status)) return status; + + value->string[0] = 0; value->used = 0; } diff --git a/level_0/f_environment/c/environment.h b/level_0/f_environment/c/environment.h index 6233eb3..506e495 100644 --- a/level_0/f_environment/c/environment.h +++ b/level_0/f_environment/c/environment.h @@ -76,8 +76,8 @@ extern "C" { * The name must be NULL terminated. * @param value * The value associated with name. - * The value will not be null terminated. - * The value will be appended (set value->used to 0 to replace). + * The value is be null terminated. + * The value is be appended (set value->used to 0 before calling this to fully replace). * * @return * F_none on success. diff --git a/level_0/f_memory/data/build/testfile b/level_0/f_memory/data/build/testfile index 28e8486..ebd9fb3 100644 --- a/level_0/f_memory/data/build/testfile +++ b/level_0/f_memory/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h index ba909f5..406d52b 100644 --- a/level_0/f_string/c/string-common.h +++ b/level_0/f_string/c/string-common.h @@ -42,11 +42,11 @@ extern "C" { #define macro_f_string_t_clear(string) string = 0; - #define macro_f_string_t_resize(status, string, length_old, length_new) status = f_memory_resize(length_old, length_new, sizeof(char), (void **) & string); - #define macro_f_string_t_adjust(status, string, length_old, length_new) status = f_memory_adjust(length_old, length_new, sizeof(char), (void **) & string); + #define macro_f_string_t_resize(status, string, length_old, length_new) status = f_memory_resize(length_old, length_new, 1, (void **) & string); + #define macro_f_string_t_adjust(status, string, length_old, length_new) status = f_memory_adjust(length_old, length_new, 1, (void **) & string); - #define macro_f_string_t_delete_simple(string, length) f_memory_resize(length, 0, sizeof(char), (void **) & string); - #define macro_f_string_t_destroy_simple(string, length) f_memory_adjust(length, 0, sizeof(char), (void **) & string); + #define macro_f_string_t_delete_simple(string, length) f_memory_resize(length, 0, 1, (void **) & string); + #define macro_f_string_t_destroy_simple(string, length) f_memory_adjust(length, 0, 1, (void **) & string); #define F_string_t_size_d F_number_t_size_positive_d #endif // _di_f_string_t_ diff --git a/level_0/f_string/c/string_dynamic.c b/level_0/f_string/c/string_dynamic.c index ab55d23..a80ed02 100644 --- a/level_0/f_string/c/string_dynamic.c +++ b/level_0/f_string/c/string_dynamic.c @@ -985,15 +985,12 @@ extern "C" { return F_status_set_error(F_string_too_large); } - const f_array_length_t total = destination->used + 1; - - if (total > destination->size) { - const f_status_t status = private_f_string_dynamic_resize(total, destination); + if (destination->used + 1 > destination->size) { + const f_status_t status = private_f_string_dynamic_resize(destination->used + (destination->used + 1 == F_string_t_size_d ? 1 : F_memory_default_allocation_small_d), destination); if (F_status_is_error(status)) return status; } - destination->string[destination->used] = 0; - destination->used = total; + destination->string[destination->used++] = 0; return F_none; } @@ -1005,13 +1002,10 @@ extern "C" { if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (destination->used) { - for (; destination->used; --destination->used) { - - if (!destination->string[destination->used - 1]) continue; - - break; - } // for + if (destination->used < destination->size) { + if (!destination->string[destination->used]) { + return F_none; + } } if (destination->used == F_string_t_size_d) { @@ -1019,7 +1013,7 @@ extern "C" { } if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_string_dynamic_resize(destination->used + F_memory_default_allocation_small_d, destination); + const f_status_t status = private_f_string_dynamic_resize(destination->used + (destination->used + 1 == F_string_t_size_d ? 1 : F_memory_default_allocation_small_d), destination); if (F_status_is_error(status)) return status; } diff --git a/level_0/f_type_array/data/build/testfile b/level_0/f_type_array/data/build/testfile index e2264ee..19a83aa 100644 --- a/level_0/f_type_array/data/build/testfile +++ b/level_0/f_type_array/data/build/testfile @@ -24,7 +24,7 @@ main: not_created: print - print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" + print 'context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"reset"' exit failure diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index 36cf6ff..b844761 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -5,13 +5,12 @@ extern "C" { #endif #ifndef _fl_console_parameter_to_string_dynamic_directory_ - f_status_t fl_console_parameter_to_string_dynamic_directory(const f_string_t argument, f_string_dynamic_t *directory) { + f_status_t fl_console_parameter_to_string_dynamic_directory(const f_string_static_t argument, f_string_dynamic_t *directory) { #ifndef _di_level_1_parameter_checking_ - if (!argument) return F_status_set_error(F_parameter); + if (!directory) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status_t status = F_none; - f_array_length_t length = strlen(argument); + f_array_length_t length = argument.used; if (!length) { directory->used = 0; @@ -19,150 +18,145 @@ extern "C" { return F_none; } + f_status_t status = F_none; + if (length > 1) { - while (length > 1 && argument[length - 1] == f_path_separator_s.string[0]) { + while (length > 1 && argument.string[length - 1] == f_path_separator_s.string[0]) { --length; } // while - if (argument[0] == f_path_separator_s.string[0]) { + if (argument.string[0] == f_path_separator_s.string[0]) { f_array_length_t begin = 1; - while (begin < length && argument[begin] == f_path_separator_s.string[0]) { + while (begin < length && argument.string[begin] == f_path_separator_s.string[0]) { ++begin; } // while length -= begin; + directory->used = 0; - if (length > 0) { - length += 2; + if (length) { + directory->used = 0; - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), length) + status = f_string_dynamic_increase_by(length + 3, directory); if (F_status_is_error(status)) return status; - memcpy(directory->string + 1, argument + begin, length - 2); + memcpy(directory->string + 1, argument.string + begin, length); - directory->used = length; - directory->size = length; directory->string[0] = f_path_separator_s.string[0]; - directory->string[length - 1] = f_path_separator_s.string[0]; + directory->string[length + 1] = f_path_separator_s.string[0]; + directory->string[length + 2] = 0; + directory->used = length + 2; } else { - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), 1) + status = f_string_dynamic_increase_by(2, directory); if (F_status_is_error(status)) return status; - directory->used = 1; - directory->size = 1; directory->string[0] = f_path_separator_s.string[0]; + directory->string[length + 1] = 0; + directory->used = length + 1; } } - else if (length > 3 && argument[0] == f_path_separator_current_s.string[0] && argument[1] == f_path_separator_current_s.string[0] && argument[2] == f_path_separator_s.string[0]) { + else if (length > 3 && argument.string[0] == f_path_separator_current_s.string[0] && argument.string[1] == f_path_separator_current_s.string[0] && argument.string[2] == f_path_separator_s.string[0]) { f_array_length_t begin = 3; - while (begin < length && argument[begin] == f_path_separator_s.string[0]) { + while (begin < length && argument.string[begin] == f_path_separator_s.string[0]) { ++begin; } // while length -= begin; + directory->used = 0; - if (length > 0) { - length += 4; - - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), length); + if (length) { + status = f_string_dynamic_increase_by(length + 5, directory); if (F_status_is_error(status)) return status; - memcpy(directory->string + 3, argument + begin, length - 4); + memcpy(directory->string + 3, argument.string + begin, length); - directory->used = length; - directory->size = length; directory->string[0] = f_path_separator_current_s.string[0]; directory->string[1] = f_path_separator_current_s.string[0]; directory->string[2] = f_path_separator_s.string[0]; - directory->string[length - 1] = f_path_separator_s.string[0]; + directory->string[length] = f_path_separator_s.string[0]; + directory->string[length + 4] = 0; + directory->used = length + 4; } else { - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), 3) + status = f_string_dynamic_increase_by(5, directory); if (F_status_is_error(status)) return status; - directory->used = 3; - directory->size = 3; directory->string[0] = f_path_separator_current_s.string[0]; directory->string[1] = f_path_separator_current_s.string[0]; directory->string[2] = f_path_separator_s.string[0]; + directory->string[3] = f_path_separator_s.string[0]; + directory->string[4] = 0; + directory->used = 4; } } - else if (length > 2 && argument[0] == f_path_separator_current_s.string[0] && argument[1] == f_path_separator_s.string[0]) { + else if (length > 2 && argument.string[0] == f_path_separator_current_s.string[0] && argument.string[1] == f_path_separator_s.string[0]) { f_array_length_t begin = 2; - while (begin < length && argument[begin] == f_path_separator_s.string[0]) { + while (begin < length && argument.string[begin] == f_path_separator_s.string[0]) { ++begin; } // while length -= begin; + directory->used = 0; - if (length > 0) { - length += 3; - - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), length) + if (length) { + status = f_string_dynamic_increase_by(length + 4, directory); if (F_status_is_error(status)) return status; - memcpy(directory->string + 2, argument + begin, length - 3); + memcpy(directory->string + 2, argument.string + begin, length); - directory->used = length; - directory->size = length; directory->string[0] = f_path_separator_current_s.string[0]; directory->string[1] = f_path_separator_s.string[0]; - directory->string[length - 1] = f_path_separator_s.string[0]; + directory->string[length] = f_path_separator_s.string[0]; + directory->string[length + 3] = 0; + directory->used = length + 3; } else { - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), 2) + status = f_string_dynamic_increase_by(4, directory); if (F_status_is_error(status)) return status; - directory->used = 2; - directory->size = 2; directory->string[0] = f_path_separator_current_s.string[0]; directory->string[1] = f_path_separator_s.string[0]; + directory->string[2] = f_path_separator_s.string[0]; + directory->string[3] = 0; + directory->used = 3; } } else { - ++length; + directory->used = 0; - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), length) + status = f_string_dynamic_increase_by(length + 2, directory); if (F_status_is_error(status)) return status; - memcpy(directory->string, argument, length - 1); + memcpy(directory->string, argument.string, length); - directory->used = length; - directory->size = length; - directory->string[length - 1] = f_path_separator_s.string[0]; + directory->string[length] = f_path_separator_s.string[0]; + directory->string[length + 1] = 0; + directory->used = length + 1; } } - else if (argument[0] != f_path_separator_s.string[0]) { - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), 2) - if (F_status_is_error(status)) return status; + else if (argument.string[0] != f_path_separator_s.string[0]) { + directory->used = 0; - memcpy(directory->string, argument, 2); + status = f_string_dynamic_increase_by(2, directory); + if (F_status_is_error(status)) return status; - directory->used = 2; - directory->size = 2; - directory->string[1] = f_path_separator_s.string[0]; + directory->string[0] = f_path_separator_s.string[0]; + directory->string[1] = 0; + directory->used = 1; } else { - macro_f_string_dynamic_t_clear((*directory)) - macro_f_string_dynamic_t_resize(status, (*directory), 1) - if (F_status_is_error(status)) return status; + directory->used = 0; - memcpy(directory->string, argument, 1); + status = f_string_dynamic_increase_by(2, directory); + if (F_status_is_error(status)) return status; + directory->string[0] = argument.string[0]; + directory->string[1] = 0; directory->used = 1; - directory->size = 1; } return F_none; diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index bdae9d5..3fc7bfc 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -40,6 +40,8 @@ extern "C" { * - Ensures that multiple '/' following './' at the start of the string is reduced to only './' ('.////' would become './'). * - Ensures that multiple '/' following '../' at the start of the string is reduced to only '../' ('..////' would become '../'). * + * The directory string will be NULL terminated after directory.used. + * * This does not perform complex cleanup, such as '..///..///' to '../../'. * * The purpose of the cleanups is to ensure/enforce a consistent beginning and ending of the path strings. @@ -47,9 +49,9 @@ extern "C" { * * @param argv * The argument string expected to be a number. - * This is generally passed from the argv[]. * @param directory * The dynamically allocated processed directory string. + * The string will be replaced on success. * * @return * F_none on success. @@ -58,7 +60,7 @@ extern "C" { * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _fl_console_parameter_to_string_dynamic_directory_ - extern f_status_t fl_console_parameter_to_string_dynamic_directory(const f_string_t argument, f_string_dynamic_t *directory); + extern f_status_t fl_console_parameter_to_string_dynamic_directory(const f_string_static_t argument, f_string_dynamic_t *directory); #endif // _fl_console_parameter_to_string_dynamic_directory_ #ifdef __cplusplus diff --git a/level_1/fl_environment/c/environment.c b/level_1/fl_environment/c/environment.c index 10d9608..75bb2f3 100644 --- a/level_1/fl_environment/c/environment.c +++ b/level_1/fl_environment/c/environment.c @@ -20,13 +20,23 @@ extern "C" { environment->array[environment->used].name.used = 0; environment->array[environment->used].value.used = 0; - status = f_string_dynamic_append_nulless(name, &environment->array[environment->used].name); - if (F_status_is_error(status)) return status; + status = f_string_dynamic_increase_by(name.used + 1, &environment->array[environment->used].name); + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append_nulless(name, &environment->array[environment->used].name); + } + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_terminate_after(&environment->array[environment->used].name); + } - status = f_environment_get(name, &environment->array[environment->used].value); + if (F_status_is_error_not(status)) { + status = f_environment_get(name, &environment->array[environment->used].value); + } if (F_status_is_error(status) || status == F_data_not || status == F_exist_not) { environment->array[environment->used].name.used = 0; + environment->array[environment->used].value.used = 0; return status; } @@ -55,23 +65,29 @@ extern "C" { environment->array[environment->used].name.used = 0; environment->array[environment->used].value.used = 0; - status = f_string_dynamic_append_nulless(names.array[i], &environment->array[environment->used].name); - if (F_status_is_error(status)) return status; + status = f_string_dynamic_increase_by(names.array[i].used + 1, &environment->array[environment->used].name); - status = f_environment_get(names.array[i], &environment->array[environment->used].value); + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append_nulless(names.array[i], &environment->array[environment->used].name); + } - if (F_status_is_error(status)) { - environment->array[environment->used].name.used = 0; + if (F_status_is_error_not(status)) { + status = f_string_dynamic_terminate_after(&environment->array[environment->used].name); + } - return status; + if (F_status_is_error_not(status)) { + status = f_environment_get(names.array[i], &environment->array[environment->used].value); } - if (status == F_data_not || status == F_exist_not) { + if (F_status_is_error(status)) { environment->array[environment->used].name.used = 0; + environment->array[environment->used].value.used = 0; - continue; + return status; } + if (status == F_data_not || status == F_exist_not) continue; + ++environment->used; } // for diff --git a/level_1/fl_environment/c/environment.h b/level_1/fl_environment/c/environment.h index 039b1a5..944bc39 100644 --- a/level_1/fl_environment/c/environment.h +++ b/level_1/fl_environment/c/environment.h @@ -31,6 +31,8 @@ extern "C" { * If the environment variable name is not found, then it is not added to the map. * If the environment variable name is found but has an empty value, then it is added to the map with an empty value. * + * Each name and value in the map is NULL terminated after the name.used or size.used. + * * This does not check for uniqueness in the map. * * @param name @@ -45,10 +47,14 @@ extern "C" { * * Errors (with error bit) from: f_environment_get(). * Errors (with error bit) from: f_string_dynamic_append_nulless(). + * Errors (with error bit) from: f_string_dynamic_increase_by(). + * Errors (with error bit) from: f_string_dynamic_terminate_after(). * Errors (with error bit) from: f_string_maps_increase_by(). * * @see f_environment_get() * @see f_string_dynamic_append_nulless() + * @see f_string_dynamic_increase_by() + * @see f_string_dynamic_terminate_after() * @see f_string_maps_increase_by() */ #ifndef _di_fl_environment_load_name_ @@ -61,6 +67,8 @@ extern "C" { * If the environment variable name is not found, then it is not added to the map. * If the environment variable name is found but has an empty value, then it is added to the map with an empty value. * + * Each name and value in the map is NULL terminated after the name.used or size.used. + * * This does not check for uniqueness in the map. * * @param names diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index efb7cee..71cb58a 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -280,7 +280,6 @@ extern "C" { // Create a string array that is compatible with execv() calls. f_string_t fixed_arguments[arguments.used + 2]; - f_string_static_t program_name = f_string_static_t_initialize; const f_string_t last_slash = strrchr(program.used ? program.string : arguments.array[0].string, f_path_separator_s.string[0]); diff --git a/level_2/fll_execute/c/private-execute.c b/level_2/fll_execute/c/private-execute.c index 4890414..16b8bc9 100644 --- a/level_2/fll_execute/c/private-execute.c +++ b/level_2/fll_execute/c/private-execute.c @@ -588,7 +588,7 @@ extern "C" { void private_fll_execute_path_arguments_fixate(const f_string_static_t program_path, const f_string_statics_t arguments, const f_string_t last_slash, const bool fixated_is, f_string_static_t program_name, f_string_t fixed_arguments[]) { memset(program_name.string, 0, program_name.used + 1); - memset(fixed_arguments, 0, sizeof(char) * (arguments.used + 2)); + memset(fixed_arguments, 0, sizeof(f_string_t) * (arguments.used + 2)); memcpy(program_name.string, last_slash ? last_slash + 1 : program_path.string, program_name.used); diff --git a/level_2/fll_fss/c/fss.c b/level_2/fll_fss/c/fss.c index 5091ceb..bb5be88 100644 --- a/level_2/fll_fss/c/fss.c +++ b/level_2/fll_fss/c/fss.c @@ -251,7 +251,6 @@ extern "C" { if (!contents.used) return F_data_not; f_status_t status = F_none; - f_string_dynamics_t *value = 0; f_fss_content_t *content = 0; f_array_length_t i = 0; @@ -267,7 +266,6 @@ extern "C" { if (F_status_is_error(status)) return status; if (status == F_equal_to_not) continue; - value = values[j]; content = &contents.array[i]; if (matches) { @@ -279,11 +277,11 @@ extern "C" { return F_status_set_error(F_array_too_large); } - macro_f_string_dynamics_t_resize(status, (*value), (values[j]->used + content->used)); + status = f_string_dynamics_increase_by(content->used, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_resize(status, (*indexs[j]), (indexs[j]->used + content->used)); + status = f_type_array_lengths_increase_by(content->used, indexs[j]); if (F_status_is_error(status)) return status; } } @@ -293,11 +291,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(buffer, contents.array[i].array[k], &values[j]->array[values[j]->used]); if (F_status_is_error(status)) return status; + status = f_string_dynamic_terminate_after(&values[j]->array[values[j]->used]); + if (F_status_is_error(status)) return status; + ++values[j]->used; if (indexs) { - indexs[j]->array[indexs[j]->used] = i; - ++indexs[j]->used; + indexs[j]->array[indexs[j]->used++] = i; } } // for } // for diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 694a5c9..ce4bad5 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -244,7 +244,7 @@ extern "C" { * * @param arguments * The program argument array to parse. - * The caller must guarantee that the values.used does not exceed the argv length. + * The caller must guarantee that the indexes within values do not exceed the arguments array length. * @param values * The string locations where the console parameters are found. * @param destination @@ -273,7 +273,7 @@ extern "C" { * A string to append between the source and destination, such as a space: ' '. * @param arguments * The program argument array to parse. - * The caller must guarantee that the values.used does not exceed the argv length. + * The caller must guarantee that the indexes within values do not exceed the arguments array length. * @param values * The string locations where the console parameters are found. * @param destination @@ -302,7 +302,7 @@ extern "C" { * * @param arguments * The program argument array to parse. - * The caller must guarantee that the values.used does not exceed the argv length. + * The caller must guarantee that the indexes within values do not exceed the arguments array length. * @param values * The string locations where the console parameters are found. * @param destination @@ -332,6 +332,7 @@ extern "C" { * A string to append between the source and destination, such as a space: ' '. * @param arguments * The program argument array to parse. + * The caller must guarantee that the indexes within values do not exceed the arguments array length. * @param values * The string locations where the console parameters are found. * @param destination diff --git a/level_3/fake/c/common.h b/level_3/fake/c/common.h index 2c9b072..a9e2329 100644 --- a/level_3/fake/c/common.h +++ b/level_3/fake/c/common.h @@ -75,8 +75,8 @@ extern "C" { * Set to at least 4 to provide a UTF-8 friendly allocation step. */ #ifndef _di_fake_default_allocation_step_ - #define fake_default_allocation_small_d 4 #define fake_default_allocation_large_d 64 + #define fake_default_allocation_small_d 8 #endif // _di_fake_default_allocation_step_ /** diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index 7d5bc49..f52b7a5 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -268,7 +268,7 @@ extern "C" { if (operations_length) { bool validate_parameter_directories = F_true; - status = fake_process_console_parameters(arguments, main); + status = fake_process_console_parameters(main); if (F_status_is_error_not(status)) { status = fake_path_generate(main); @@ -299,7 +299,7 @@ extern "C" { if (main->operation == fake_operation_build_e) { if (validate_parameter_directories) { - status = fake_validate_parameter_directories(arguments, main); + status = fake_validate_parameter_directories(main); validate_parameter_directories = F_false; } @@ -309,7 +309,7 @@ extern "C" { } else if (main->operation == fake_operation_clean_e) { if (validate_parameter_directories) { - status = fake_validate_parameter_directories(arguments, main); + status = fake_validate_parameter_directories(main); validate_parameter_directories = F_false; } @@ -319,7 +319,7 @@ extern "C" { } else if (main->operation == fake_operation_make_e) { if (validate_parameter_directories) { - status = fake_validate_parameter_directories(arguments, main); + status = fake_validate_parameter_directories(main); validate_parameter_directories = F_false; } diff --git a/level_3/fake/c/private-clean.c b/level_3/fake/c/private-clean.c index 7f691f6..1e44e11 100644 --- a/level_3/fake/c/private-clean.c +++ b/level_3/fake/c/private-clean.c @@ -63,7 +63,7 @@ extern "C" { #if !defined(_di_fake_clean_operate_) int fake_clean_remove_recursively_verbosely(const char *path, const struct stat *file_stat, int type, struct FTW *entity) { - if (!entity->level) return 0; + if (!entity->level || !path) return 0; const int result = remove(path); diff --git a/level_3/fake/c/private-common.c b/level_3/fake/c/private-common.c index 5804b40..d261a6d 100644 --- a/level_3/fake/c/private-common.c +++ b/level_3/fake/c/private-common.c @@ -287,6 +287,30 @@ extern "C" { const f_string_static_t fake_file_data_build_process_pre_s = macro_f_string_static_t_initialize(FAKE_file_data_build_process_pre_s, 0, FAKE_file_data_build_process_pre_s_length); #endif // _di_fake_file_data_build_strings_ +#ifndef _di_fake_make_data_delete_ + f_status_t fake_make_data_delete(fake_make_data_t * const data) { + + macro_fake_build_setting_t_delete_simple(data->setting_build); + macro_fake_make_setting_t_delete_simple(data->setting_make); + + f_string_maps_resize(0, &data->environment); + + macro_fake_make_parameter_delete_simple(data->parameter); + macro_fake_make_parameter_delete_simple(data->parameter_option); + macro_fake_make_parameter_delete_simple(data->parameter_value); + macro_fake_make_path_delete_simple(data->path); + + f_fss_nameds_resize(0, &data->fakefile); + + f_string_dynamic_resize(0, &data->buffer); + f_string_dynamic_resize(0, &data->cache_1); + f_string_dynamic_resize(0, &data->cache_2); + f_string_dynamic_resize(0, &data->path_cache); + + return F_none; + } +#endif // _di_fake_make_data_delete_ + #ifndef _di_fake_signal_received_ f_status_t fake_signal_received(fake_main_t * const main) { diff --git a/level_3/fake/c/private-common.h b/level_3/fake/c/private-common.h index 18eab55..a93870a 100644 --- a/level_3/fake/c/private-common.h +++ b/level_3/fake/c/private-common.h @@ -1217,6 +1217,8 @@ extern "C" { f_fss_nameds_t fakefile; f_string_dynamic_t buffer; + f_string_dynamic_t cache_1; + f_string_dynamic_t cache_2; f_string_dynamic_t path_cache; f_array_length_t id_main; @@ -1236,21 +1238,11 @@ extern "C" { f_fss_nameds_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ 0, \ 0, \ } - - #define macro_fake_make_data_t_delete_simple(structure) \ - macro_fake_build_setting_t_delete_simple(structure.setting_build) \ - macro_fake_make_setting_t_delete_simple(structure.setting_make) \ - macro_f_string_maps_t_delete_simple(structure.environment) \ - macro_fake_make_parameter_delete_simple(structure.parameter) \ - macro_fake_make_parameter_delete_simple(structure.parameter_option) \ - macro_fake_make_parameter_delete_simple(structure.parameter_value) \ - macro_fake_make_path_delete_simple(structure.path) \ - macro_f_fss_nameds_t_delete_simple(structure.fakefile) \ - macro_f_string_dynamic_t_delete_simple(structure.buffer) \ - macro_f_string_dynamic_t_delete_simple(structure.path_cache) #endif // _di_fake_make_data_t_ /** @@ -1390,6 +1382,23 @@ extern "C" { #endif // _di_fake_file_data_build_strings_ /** + * Deallocate make data. + * + * @param data + * The make data. + * + * @return + * F_none on success. + * + * @see f_fss_nameds_resize() + * @see f_string_dynamic_resize() + * @see f_string_maps_resize() + */ +#ifndef _di_fake_make_data_delete_ + extern f_status_t fake_make_data_delete(fake_make_data_t * const data) F_attribute_visibility_internal_d; +#endif // _di_fake_make_data_delete_ + +/** * Check to see if a process signal is received. * * Only signals that are blocked via main.signal will be received. diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 3de20df..59dedc7 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -153,7 +153,7 @@ extern "C" { #endif // _di_fake_file_buffer_ #ifndef _di_fake_process_console_parameters_ - f_status_t fake_process_console_parameters(const f_console_arguments_t *arguments, fake_main_t *main) { + f_status_t fake_process_console_parameters(fake_main_t * const main) { f_status_t status = F_none; @@ -206,16 +206,16 @@ extern "C" { f_array_length_t index = main->parameters.array[parameters_id[i]].values.array[0]; - if (argv[index].used) { + if (main->parameters.arguments.array[index].used) { if (parameters_validate_word[i]) { f_array_length_t j = 0; f_array_length_t width_max = 0; - for (j = 0; j < argv[index].used; ++j) { + for (j = 0; j < main->parameters.arguments.array[index].used; ++j) { - width_max = argv[index].used - j; + width_max = main->parameters.arguments.array[index].used - j; - status = f_utf_is_word_dash_plus(argv[index] + j, width_max, F_false); + status = f_utf_is_word_dash_plus(main->parameters.arguments.array[index].string + j, width_max, F_false); if (F_status_is_error(status)) { if (fll_error_print(main->error, F_status_set_fine(status), "f_utf_is_word_dash_plus", F_false) == F_known_not && main->error.verbosity != f_console_verbosity_quiet_e) { @@ -238,7 +238,7 @@ extern "C" { fl_print_format("%r%[%QThe '%]", main->error.to.stream, f_string_eol_s, main->error.context, main->error.prefix, main->error.context); fl_print_format("%[%r%r%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fake_long_process_s, main->error.notable); fl_print_format("%[' parameters value '%]", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s); - fl_print_format("%[%S%]", main->error.to.stream, main->error.notable, argv[index], main->error.notable); + fl_print_format("%[%Q%]", main->error.to.stream, main->error.notable, main->parameters.arguments.array[index], main->error.notable); fl_print_format("%[' contains non-word, non-dash, and non-plus characters.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s); funlockfile(main->error.to.stream); @@ -249,7 +249,15 @@ extern "C" { } // for } - status = f_string_append(argv[index], argv[index].used, parameters_value[i]); + status = f_string_dynamic_increase_by(main->parameters.arguments.array[index].used + 1, parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_increase_by", F_true); + + return status; + } + + status = f_string_dynamic_append(main->parameters.arguments.array[index], parameters_value[i]); if (F_status_is_error(status)) { if (status == F_status_set_error(F_string_too_large)) { @@ -274,7 +282,7 @@ extern "C" { } } - if (!argv[index].used || status == F_data_not) { + if (!main->parameters.arguments.array[index].used || status == F_data_not) { if (main->error.verbosity != f_console_verbosity_quiet_e) { flockfile(main->error.to.stream); @@ -289,6 +297,14 @@ extern "C" { else if (parameter_defaults[i].used) { parameters_value[i]->used = 0; + status = f_string_dynamic_increase_by(parameter_defaults[i].used + 1, parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_increase_by", F_true); + + return status; + } + status = f_string_dynamic_append(parameter_defaults[i], parameters_value[i]); if (F_status_is_error(status)) { @@ -297,6 +313,14 @@ extern "C" { return status; } } + + status = f_string_dynamic_terminate_after(parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); + + return status; + } } // for } @@ -349,7 +373,17 @@ extern "C" { return F_status_set_error(F_parameter); } - status = fl_console_parameter_to_string_dynamic_directory(argv[main->parameters.array[parameters_id[i]].values.array[0]], parameters_value[i]); + const f_array_length_t index = main->parameters.array[parameters_id[i]].values.array[main->parameters.array[parameters_id[i]].values.used - 1]; + + status = f_string_dynamic_increase_by(main->parameters.arguments.array[index].used + 1, parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_increase_by", F_true); + + return status; + } + + status = fl_console_parameter_to_string_dynamic_directory(main->parameters.arguments.array[index], parameters_value[i]); if (F_status_is_error(status)) { if (fll_error_print(main->error, F_status_set_fine(status), "fl_console_parameter_to_string_dynamic_directory", F_false) == F_known_not && main->error.verbosity != f_console_verbosity_quiet_e) { @@ -368,6 +402,14 @@ extern "C" { else if (parameter_defaults[i].used) { parameters_value[i]->used = 0; + status = f_string_dynamic_increase_by(parameter_defaults[i].used + 1, parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_increase_by", F_true); + + return status; + } + status = f_string_dynamic_append(parameter_defaults[i], parameters_value[i]); if (F_status_is_error(status)) { @@ -384,11 +426,19 @@ extern "C" { return status; } } + + status = f_string_dynamic_terminate_after(parameters_value[i]); + + if (F_status_is_error(status)) { + fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); + + return status; + } } // for } if (main->parameters.array[fake_parameter_define_e].result == f_console_result_additional_e) { - status = fll_program_parameter_additional_rip(argv, main->parameters.array[fake_parameter_define_e].values, &main->define); + status = fll_program_parameter_additional_rip(main->parameters.arguments.array, main->parameters.array[fake_parameter_define_e].values, &main->define); if (F_status_is_error(status)) { if (fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_additional_rip", F_false) == F_known_not && main->error.verbosity != f_console_verbosity_quiet_e) { @@ -407,10 +457,11 @@ extern "C" { if (main->parameters.array[fake_parameter_mode_e].result == f_console_result_found_e) { fake_print_error_parameter_missing_value(main, fake_long_mode_s); + return F_status_set_error(F_parameter); } else if (main->parameters.array[fake_parameter_mode_e].result == f_console_result_additional_e) { - status = fll_program_parameter_additional_rip(argv, main->parameters.array[fake_parameter_mode_e].values, &main->mode); + status = fll_program_parameter_additional_rip(main->parameters.arguments.array, main->parameters.array[fake_parameter_mode_e].values, &main->mode); if (F_status_is_error(status)) { if (fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_additional_rip", F_false) == F_known_not && main->error.verbosity != f_console_verbosity_quiet_e) { @@ -530,7 +581,7 @@ extern "C" { #endif // _di_fake_signal_state_interrupt_iki_ #ifndef _di_fake_validate_directories_ - f_status_t fake_validate_parameter_directories(const f_console_arguments_t *arguments, fake_main_t * const main) { + f_status_t fake_validate_parameter_directories(fake_main_t * const main) { if (fake_signal_received(main)) { return F_status_set_error(F_interrupt); @@ -542,10 +593,10 @@ extern "C" { fake_long_path_work_s, }; - const f_string_dynamic_t *parameters_value[] = { - &main->path_build, - &main->path_data, - &main->path_work, + const f_string_dynamic_t parameters_value[] = { + main->path_build, + main->path_data, + main->path_work, }; const bool parameters_required[] = { @@ -559,16 +610,16 @@ extern "C" { for (uint8_t i = 0; i < 3; ++i) { - if (parameters_value[i]->used) { + if (parameters_value[i].used) { memset(&directory_stat, 0, sizeof(struct stat)); - status = f_file_stat(*parameters_value[i], F_true, &directory_stat); + status = f_file_stat(parameters_value[i], F_true, &directory_stat); if (status == F_status_set_error(F_file_found_not)) status = F_status_set_error(F_directory_found_not); if (F_status_is_error(status)) { if (F_status_set_fine(status) != F_directory_found_not || parameters_required[i]) { - fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stat", F_true, *parameters_value[i], f_file_operation_access_s, fll_error_file_type_directory_e); + fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stat", F_true, parameters_value[i], f_file_operation_access_s, fll_error_file_type_directory_e); return status; } @@ -593,19 +644,19 @@ extern "C" { #ifndef _di_fake_verbose_print_clone_ void fake_verbose_print_clone(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Cloned '%S' to '%S'.%r", output.stream, source, destination, f_string_eol_s); + fll_print_format("Cloned '%Q' to '%Q'.%r", output.stream, source, destination, f_string_eol_s); } #endif // _di_fake_verbose_print_clone_ #ifndef _di_fake_verbose_print_copy_ void fake_verbose_print_copy(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Copied '%S' to '%S'.%r", output.stream, source, destination, f_string_eol_s); + fll_print_format("Copied '%Q' to '%Q'.%r", output.stream, source, destination, f_string_eol_s); } #endif // _di_fake_verbose_print_copy_ #ifndef _di_fake_verbose_print_move_ void fake_verbose_print_move(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { - fll_print_format("Moved '%S' to '%S'.%r", output.stream, source, destination, f_string_eol_s); + fll_print_format("Moved '%Q' to '%Q'.%r", output.stream, source, destination, f_string_eol_s); } #endif // _di_fake_verbose_print_move_ diff --git a/level_3/fake/c/private-fake.h b/level_3/fake/c/private-fake.h index 01a2afb..369dbb2 100644 --- a/level_3/fake/c/private-fake.h +++ b/level_3/fake/c/private-fake.h @@ -62,8 +62,6 @@ extern "C" { /** * Validate console arguments and print any relating error messages. * - * @param arguments - * The parameters passed to the process. * @param main * The main program data. * @@ -73,7 +71,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_fake_process_console_parameters_ - extern f_status_t fake_process_console_parameters(const f_console_arguments_t *arguments, fake_main_t *main) F_attribute_visibility_internal_d; + extern f_status_t fake_process_console_parameters(fake_main_t * const main) F_attribute_visibility_internal_d; #endif // _di_validate_console_parameters_ /** @@ -115,8 +113,6 @@ extern "C" { * * This should not be called for skeleton as in that case the directories probably do not exist. * - * @param arguments - * The parameters passed to the process. * @param main * The main program data. * @@ -128,7 +124,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_fake_validate_parameter_directories_ - extern f_status_t fake_validate_parameter_directories(const f_console_arguments_t *arguments, fake_main_t * const main) F_attribute_visibility_internal_d; + extern f_status_t fake_validate_parameter_directories(fake_main_t * const main) F_attribute_visibility_internal_d; #endif // _di_fake_validate_parameter_directories_ /** diff --git a/level_3/fake/c/private-make-load_fakefile.c b/level_3/fake/c/private-make-load_fakefile.c index d329a24..fbdba40 100644 --- a/level_3/fake/c/private-make-load_fakefile.c +++ b/level_3/fake/c/private-make-load_fakefile.c @@ -215,7 +215,7 @@ extern "C" { { f_string_t function_name = "macro_f_string_map_multis_t_resize"; - macro_f_string_map_multis_t_resize(*status, data_make->setting_make.parameter, F_memory_default_allocation_small_d); + macro_f_string_map_multis_t_resize(*status, data_make->setting_make.parameter, fake_default_allocation_small_d); if (F_status_is_error_not(*status)) { data_make->setting_make.parameter.used = 1; @@ -526,7 +526,7 @@ extern "C" { } // for if (j == data_make->setting_build.environment.used) { - status = f_string_dynamics_increase(F_memory_default_allocation_small_d, &data_make->setting_build.environment); + status = f_string_dynamics_increase(fake_default_allocation_small_d, &data_make->setting_build.environment); if (F_status_is_error(status)) { fll_error_print(data_make->main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); diff --git a/level_3/fake/c/private-make-operate.c b/level_3/fake/c/private-make-operate.c index a6ae66b..8f9a0c8 100644 --- a/level_3/fake/c/private-make-operate.c +++ b/level_3/fake/c/private-make-operate.c @@ -36,7 +36,7 @@ extern "C" { data_make.main = main; - status = f_string_dynamics_increase(F_memory_default_allocation_small_d, &data_make.path.stack); + status = f_string_dynamics_increase(fake_default_allocation_small_d, &data_make.path.stack); if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); @@ -49,7 +49,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_path_current", F_true); - macro_fake_make_data_t_delete_simple(data_make); + fake_make_data_delete(&data_make); return status; } @@ -59,7 +59,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_directory_open", F_true); - macro_fake_make_data_t_delete_simple(data_make); + fake_make_data_delete(&data_make); return status; } @@ -73,7 +73,7 @@ extern "C" { fake_make_load_fakefile(&data_make, &status); if (F_status_is_error(status)) { - macro_fake_make_data_t_delete_simple(data_make) + fake_make_data_delete(&data_make); return status; } @@ -131,7 +131,7 @@ extern "C" { f_file_stream_close(F_true, &data_make.path.top); f_type_array_lengths_resize(0, §ion_stack); - macro_fake_make_data_t_delete_simple(data_make) + fake_make_data_delete(&data_make); return status; } @@ -337,10 +337,10 @@ extern "C" { } } else { - *status = f_string_append("0", 1, &arguments->array[arguments->used]); + *status = f_string_dynamic_append(f_string_ascii_0_s, &arguments->array[arguments->used]); if (F_status_is_error(*status)) { - fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_append", F_true); + fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_dynamic_append", F_true); break; } @@ -357,7 +357,7 @@ extern "C" { unmatched = F_false; - *status = f_string_dynamics_increase(F_memory_default_allocation_small_d, arguments); + *status = f_string_dynamics_increase(fake_default_allocation_small_d, arguments); if (F_status_is_error(*status)) { fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_dynamics_increase", F_true); @@ -427,7 +427,7 @@ extern "C" { } // for } else { - *status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); + *status = f_string_dynamics_increase_by(fake_default_allocation_small_d, arguments); if (F_status_is_error(*status)) { fll_error_print(data_make->error, F_status_set_fine(*status), "f_string_dynamics_increase_by", F_true); @@ -809,7 +809,7 @@ extern "C" { status = f_string_dynamic_append_nulless(value, &arguments->array[arguments->used]); } else { - status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); + status = f_string_dynamics_increase_by(fake_default_allocation_small_d, arguments); if (F_status_is_error_not(status)) { status = f_string_dynamic_append_nulless(value, &arguments->array[arguments->used]); @@ -876,7 +876,7 @@ extern "C" { status = f_string_dynamic_append_nulless(*context, &arguments->array[arguments->used]); } else { - status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); + status = f_string_dynamics_increase_by(fake_default_allocation_small_d, arguments); if (F_status_is_error_not(status)) { status = f_string_dynamic_append_nulless(*context, &arguments->array[arguments->used]); @@ -902,56 +902,47 @@ extern "C" { f_status_t fake_make_operate_expand_environment(fake_make_data_t * const data_make, const f_fss_quote_t quoted, const f_string_range_t range_name, f_string_dynamics_t *arguments) { f_status_t status = F_none; - f_string_dynamic_t value = f_string_dynamic_t_initialize; - - bool unmatched = F_false; - - { - f_string_dynamic_t name = f_string_dynamic_t_initialize; - status = f_string_dynamic_partial_append_nulless(data_make->buffer, range_name, &name); - if (F_status_is_error(status)) return status; + data_make->cache_1.used = 0; + data_make->cache_2.used = 0; - status = f_environment_get(name, &value); + status = f_string_dynamic_increase_by((range_name.stop - range_name.start) + 1, &data_make->cache_1); - f_string_dynamic_resize(0, &name); + if (F_status_is_error_not(status)) { + status = f_string_dynamic_partial_append_nulless(data_make->buffer, range_name, &data_make->cache_1); } - if (F_status_is_error(status)) { - f_string_dynamic_resize(0, &value); - - return status; + if (F_status_is_error_not(status)) { + status = f_string_dynamic_terminate_after(&data_make->cache_1); } - if (status == F_exist_not) { - f_string_dynamic_resize(0, &value); - - return F_false; + if (F_status_is_error_not(status)) { + status = f_environment_get(data_make->cache_1, &data_make->cache_2); } - if (quoted) { - status = f_string_dynamic_append_nulless(value, &arguments->array[arguments->used]); - } - else { - status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); + if (F_status_is_error(status)) return status; + if (status == F_exist_not) return F_false; - if (F_status_is_error_not(status)) { - status = f_string_dynamic_append_nulless(value, &arguments->array[arguments->used]); + status = f_string_dynamics_increase(fake_default_allocation_small_d, arguments); - if (F_status_is_error_not(status)) { - status = f_string_dynamic_terminate_after(&arguments->array[arguments->used]); + if (F_status_is_error_not(status)) { + status = f_string_dynamic_increase_by(data_make->cache_2.used + 1, &arguments->array[arguments->used]); + } - if (F_status_is_error_not(status)) { - ++arguments->used; - } - } - } + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append_nulless(data_make->cache_2, &arguments->array[arguments->used]); } - f_string_dynamic_resize(0, &value); + if (F_status_is_error_not(status)) { + status = f_string_dynamic_terminate_after(&arguments->array[arguments->used]); + } if (F_status_is_error(status)) return status; + if (!quoted) { + ++arguments->used; + } + return F_true; } #endif // _di_fake_make_operate_expand_environment_ diff --git a/level_3/fake/c/private-make-operate.h b/level_3/fake/c/private-make-operate.h index b9bc3dc..3a028d4 100644 --- a/level_3/fake/c/private-make-operate.h +++ b/level_3/fake/c/private-make-operate.h @@ -98,7 +98,17 @@ extern "C" { * F_true on success and match expanded. * F_false on no matches to expand. * - * Status codes (with error bit) are returned on any problem. + * Errors (with error bit) from: f_string_dynamic_append_nulless(). + * Errors (with error bit) from: f_string_dynamic_partial_append_nulless(). + * Errors (with error bit) from: f_string_dynamic_increase_by(). + * Errors (with error bit) from: f_string_dynamic_terminate_after(). + * Errors (with error bit) from: f_string_dynamics_increase(). + * + * @see f_string_dynamic_append_nulless() + * @see f_string_dynamic_partial_append_nulless() + * @see f_string_dynamic_increase_by() + * @see f_string_dynamic_terminate_after() + * @see f_string_dynamics_increase() */ #ifndef _di_fake_make_operate_expand_environment_ extern f_status_t fake_make_operate_expand_environment(fake_make_data_t * const data_make, const f_fss_quote_t quoted, const f_string_range_t range_name, f_string_dynamics_t *arguments) F_attribute_visibility_internal_d; diff --git a/level_3/fake/c/private-make-operate_process.c b/level_3/fake/c/private-make-operate_process.c index b2e234f..b21e7dd 100644 --- a/level_3/fake/c/private-make-operate_process.c +++ b/level_3/fake/c/private-make-operate_process.c @@ -511,7 +511,7 @@ extern "C" { f_status_t status = F_none; - // reset the environment. + // Reset the environment. for (f_array_length_t i = 0; i < data_make->environment.used; ++i) { data_make->environment.array[i].name.used = 0; @@ -544,7 +544,7 @@ extern "C" { funlockfile(data_make->main->output.to.stream); - // flush to stdout before executing command. + // Flush to stdout before executing command. fflush(data_make->main->output.to.stream); } @@ -666,48 +666,15 @@ extern "C" { #ifndef _di_fake_make_operate_process_run_ f_status_t fake_make_operate_process_run(fake_make_data_t * const data_make, const f_string_statics_t arguments, const bool as_shell) { - const f_string_static_t *program = &arguments.array[0]; - - f_status_t status = F_none; - f_string_dynamics_t args = f_string_dynamics_t_initialize; + f_string_statics_t args = f_string_statics_t_initialize; if (arguments.used > 1) { - status = f_string_dynamics_resize(arguments.used - 1, &args); - - if (F_status_is_error(status)) { - fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamics_resize", F_true); - return status; - } - - for (f_array_length_t i = 0; i < args.size; ++i) { - - status = f_string_dynamic_append(arguments.array[i + 1], &args.array[i]); - - if (F_status_is_error(status)) { - fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamic_append", F_true); - - f_string_dynamics_resize(0, &args); - - return status; - } - - status = f_string_dynamic_terminate(&args.array[i]); - - if (F_status_is_error(status)) { - fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamic_terminate", F_true); - - f_string_dynamics_resize(0, &args); - - return status; - } - - ++args.used; - } // for + args.array = arguments.array + 1; + args.used = arguments.used - 1; + args.size = 0; } - status = fake_make_operate_process_execute(data_make, *program, args, as_shell); - - f_string_dynamics_resize(0, &args); + const f_status_t status = fake_make_operate_process_execute(data_make, arguments.array[0], args, as_shell); return status; } 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 54657e1..f5ed6c3 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -1168,7 +1168,7 @@ extern "C" { } } else { - status = f_string_map_multis_resize(F_memory_default_allocation_small_d, &data_make->setting_make.parameter); + status = f_string_map_multis_resize(fake_default_allocation_small_d, &data_make->setting_make.parameter); if (F_status_is_error(status)) { fll_error_print(data_make->error, F_status_set_fine(status), "f_string_map_multis_resize", F_true); @@ -1283,7 +1283,7 @@ extern "C" { fake_print_message_section_operation_path_stack_max(data_make->main, data_make->error, F_status_set_fine(status), "f_path_change", arguments.array[0]); } else { - status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, &data_make->path.stack); + status = f_string_dynamics_increase_by(fake_default_allocation_small_d, &data_make->path.stack); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_array_too_large) {