From: Kevin Day Date: Wed, 22 Jul 2020 02:04:31 +0000 (-0500) Subject: Cleanup: relocate f_path_explode_* functions to f_environment project. X-Git-Tag: 0.5.0~59 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=781b1ce4794d9f1ace415e8d9f3f55f73ef27e44;p=fll Cleanup: relocate f_path_explode_* functions to f_environment project. These path explode functions are in regards to the environment variable PATH. Having these functions exist in f_environment makes more sense. --- diff --git a/level_0/f_environment/c/environment.c b/level_0/f_environment/c/environment.c index ccca086..2bc1522 100644 --- a/level_0/f_environment/c/environment.c +++ b/level_0/f_environment/c/environment.c @@ -43,6 +43,348 @@ extern "C" { } #endif // _di_f_environment_get_dynamic_ +#ifndef _di_f_environment_path_explode_ + f_return_status f_environment_path_explode(const f_string path, f_string_dynamics *paths) { + #ifndef _di_level_0_parameter_checking_ + if (paths == 0) return F_status_set_error(F_parameter); + if (paths->used > paths->size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status status = F_none; + const f_string_length length = strnlen(path, PATH_MAX); + + if (length == 0) { + // When PATH is "", this is actually a valid search path for PWD. + // Therefore append an equivalent representation of PWD (string used length is 0). + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + f_macro_string_dynamic_clear(paths->array[paths->used]); + paths->used++; + + return F_none; + } + + f_string_length i = length; + f_string_length first = 0; + f_string_length total = 0; + + for (i = 0; i <= length; i++) { + if (i == length || path[i] == f_path_separator_variable[0]) { + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + if (i == 0) { + f_macro_string_dynamic_clear(paths->array[paths->used]); + paths->used++; + + first = 1; + continue; + } + + f_string_dynamic part = f_string_dynamic_initialize; + + total = i - first; + + if (total > 0) { + if (path[i - 1] == f_path_separator[0]) { + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + part.used = total; + } + else { + f_macro_string_dynamic_new(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.string[total] = f_path_separator[0]; + part.used = total + 1; + } + + memcpy(part.string, path + first, total); + } + + paths->array[paths->used].string = part.string; + paths->array[paths->used].used = part.used; + paths->array[paths->used].size = part.size; + paths->used++; + + first = i + 1; + } + } // for + + return F_none; + } +#endif // _di_f_environment_path_explode_ + +#ifndef _di_f_environment_path_explode_dynamic_ + f_return_status f_environment_path_explode_dynamic(const f_string_static path, f_string_dynamics *paths) { + #ifndef _di_level_0_parameter_checking_ + if (path.used > path.size) return F_status_set_error(F_parameter); + if (paths == 0) return F_status_set_error(F_parameter); + if (paths->used > paths->size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status status = F_none; + + if (path.used == 0) { + // When PATH is "", this is actually a valid search path for PWD. + // Therefore append an equivalent representation of PWD (string used length is 0). + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + f_macro_string_dynamic_clear(paths->array[paths->used]); + paths->used++; + + return F_none; + } + + f_string_length i = 0; + f_string_length j = 0; + f_string_length first = 0; + f_string_length total = 0; + + f_string_dynamic part = f_string_dynamic_initialize; + + for (i = 0; i <= path.used; i++) { + if (i == path.used || path.string[i] == f_path_separator_variable[0]) { + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + if (i == 0) { + f_macro_string_dynamic_clear(paths->array[paths->used]); + paths->used++; + + first = 1; + continue; + } + + total = i - first; + + if (total > 0) { + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + for (j = 0; j < total; j++) { + if (path.string[first + j] == 0) continue; + + part.string[part.used] = path.string[first + j]; + part.used++; + } // for + + if (part.string[part.used - 1] != f_path_separator[0]) { + f_macro_string_dynamic_resize(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.string[part.used] = f_path_separator[0]; + part.used++; + } + } + + paths->array[paths->used].string = part.string; + paths->array[paths->used].used = part.used; + paths->array[paths->used].size = part.size; + paths->used++; + + first = i + 1; + } + } // for + + return F_none; + } +#endif // _di_f_environment_path_explode_dynamic_ + +#ifndef _di_f_environment_path_explode_reverse_ + f_return_status f_environment_path_explode_reverse(const f_string path, f_string_dynamics *paths) { + #ifndef _di_level_0_parameter_checking_ + if (paths == 0) return F_status_set_error(F_parameter); + if (paths->used > paths->size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status status = F_none; + const f_string_length length = strnlen(path, PATH_MAX); + + if (length == 0) { + // When PATH is "", this is actually a valid search path for PWD. + // Therefore append an equivalent representation of PWD (string used length is 0). + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + paths->array[paths->used].string = 0; + paths->array[paths->used].used = 0; + paths->array[paths->used].size = 0; + paths->used++; + + return F_none; + } + + f_string_length i = length; + f_string_length j = length; + f_string_length last = length; + f_string_length total = 0; + + f_string_dynamic part = f_string_dynamic_initialize; + + for (; i > 0; i--) { + j--; + + if (j == 0 || path[j] == f_path_separator_variable[0]) { + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + if (path[j] == f_path_separator_variable[0]) { + total = last - i; + + if (total > 0) { + if (path[j + total] == f_path_separator[0]) { + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + part.used = total; + } + else { + f_macro_string_dynamic_new(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.string[total] = f_path_separator[0]; + part.used = total + 1; + } + + memcpy(part.string, path + i, total); + } + + last = j; + } + else if (j == 0) { + // when j = 0, the total is actually the entire length to max. + total = last - j; + + if (total > 0) { + if (path[last - 1] == f_path_separator[0]) { + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + part.used = total; + } + else { + f_macro_string_dynamic_new(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.used = total + 1; + part.string[total] = f_path_separator[0]; + } + + memcpy(part.string, path, total); + } + } + + paths->array[paths->used].string = part.string; + paths->array[paths->used].used = part.used; + paths->array[paths->used].size = part.size; + paths->used++; + } + } // for + + return F_none; + } +#endif // _di_f_environment_path_explode_reverse_ + +#ifndef _di_f_environment_path_explode_reverse_dynamic_ + f_return_status f_environment_path_explode_reverse_dynamic(const f_string_static path, f_string_dynamics *paths) { + #ifndef _di_level_0_parameter_checking_ + if (path.used > path.size) return F_status_set_error(F_parameter); + if (paths == 0) return F_status_set_error(F_parameter); + if (paths->used > paths->size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status status = F_none; + + if (path.used == 0) { + // When PATH is "", this is actually a valid search path for PWD. + // Therefore append an equivalent representation of PWD (string used length is 0). + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + f_macro_string_dynamic_clear(paths->array[paths->used]); + paths->used++; + + return F_none; + } + + f_string_length i = path.used; + f_string_length j = path.used; + f_string_length k = 0; + f_string_length last = path.used; + f_string_length total = 0; + + f_string_dynamic part = f_string_dynamic_initialize; + + for (; i > 0; i--) { + j--; + + if (j == 0 || path.string[j] == f_path_separator_variable[0]) { + f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); + if (F_status_is_error(status)) return status; + + if (path.string[j] == f_path_separator_variable[0]) { + total = last - i; + + if (total > 0) { + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + for (k = 0; k < total; k++) { + if (path.string[i + k] == 0) continue; + + part.string[part.used] = path.string[i + k]; + part.used++; + } // for + + if (part.string[part.used - 1] != f_path_separator[0]) { + f_macro_string_dynamic_resize(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.string[part.used] = f_path_separator[0]; + part.used++; + } + } + + last = j; + } + else if (j == 0) { + // when j = 0, the total is actually the entire length to max. + total = last - j; + + f_macro_string_dynamic_new(status, part, total); + if (F_status_is_error(status)) return status; + + for (k = 0; k < total; k++) { + if (path.string[i + k] == 0) continue; + + part.string[part.used] = path.string[i + k]; + part.used++; + } // for + + if (part.string[part.used - 1] != f_path_separator[0]) { + f_macro_string_dynamic_resize(status, part, total + 1); + if (F_status_is_error(status)) return status; + + part.string[part.used - 1] = f_path_separator[0]; + part.used++; + } + } + + paths->array[paths->used].string = part.string; + paths->array[paths->used].used = part.used; + paths->array[paths->used].size = part.size; + paths->used++; + } + } // for + + return F_none; + } +#endif // _di_f_environment_path_explode_reverse_dynamic_ + #ifndef _di_f_environment_set_ f_return_status f_environment_set(const f_string name, const f_string value, const bool replace) { return private_f_environment_set(name, value, replace); diff --git a/level_0/f_environment/c/environment.h b/level_0/f_environment/c/environment.h index be12382..19a10f8 100644 --- a/level_0/f_environment/c/environment.h +++ b/level_0/f_environment/c/environment.h @@ -99,6 +99,106 @@ extern "C" { #endif // _di_f_environment_get_dynamic_ /** + * Separate a given PATH-style string into multiple separate paths. + * + * @param path + * The string to process that is expected to follow the traditional Linux standard PATH environment variable. + * Each seperate path is separated by a single ':'. + * Must not contain NULLs except for the terminating NULL. + * Must be NULL terminated. + * @param paths + * All of the strings exploded from PATH. + * Each exploded path, when not empty, is guaranteed to have a trailing '/'. + * Each exploded path is not NULL terminated. + * + * @return + * F_none on success. + * F_buffer_too_large (with error bit) if paths array is too large for further addressing. + * F_memory_reallocation (with error bit) on reallocation error. + * F_memory_allocation (with error bit) on allocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_environment_path_explode_ + extern f_return_status f_environment_path_explode(const f_string path, f_string_dynamics *paths); +#endif // _di_f_environment_path_explode_ + +/** + * Separate a given PATH-style string into multiple separate paths. + * + * @param path + * The string to process that is expected to follow the traditional Linux standard PATH environment variable. + * Each seperate path is separated by a single ':'. + * Need not be NULL terminated. + * NULLs are ignored and are not copied into the exploded paths. + * @param paths + * All of the strings exploded from PATH. + * Each exploded path, when not empty, is guaranteed to have a trailing '/'. + * Each exploded path is not NULL terminated. + * + * @return + * F_none on success. + * F_buffer_too_large (with error bit) if paths array is too large for further addressing. + * F_memory_reallocation (with error bit) on reallocation error. + * F_memory_allocation (with error bit) on allocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_environment_path_explode_dynamic_ + extern f_return_status f_environment_path_explode_dynamic(const f_string_static path, f_string_dynamics *paths); +#endif // _di_f_environment_path_explode_dynamic_ + +/** + * Separate a given PATH-style string into multiple separate paths. + * + * The paths are created in reverse order. + * + * @param path + * The string to process that is expected to follow the traditional Linux standard PATH environment variable. + * Each seperate path is separated by a single ':'. + * Must not contain NULLs except for the terminating NULL. + * Must be NULL terminated. + * @param paths + * All of the strings exploded from PATH. + * Each exploded path, when not empty, is guaranteed to have a trailing '/'. + * Each exploded path is not NULL terminated. + * + * @return + * F_none on success. + * F_buffer_too_large (with error bit) if paths array is too large for further addressing. + * F_memory_reallocation (with error bit) on reallocation error. + * F_memory_allocation (with error bit) on allocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_environment_path_explode_reverse_ + extern f_return_status f_environment_path_explode_reverse(const f_string path, f_string_dynamics *paths); +#endif // _di_f_environment_path_explode_reverse_ + +/** + * Separate a given PATH-style string into multiple separate paths. + * + * The paths are created in reverse order. + * + * @param path + * The string to process that is expected to follow the traditional Linux standard PATH environment variable. + * Each seperate path is separated by a single ':'. + * Need not be NULL terminated. + * NULLs are ignored and are not copied into the exploded paths. + * @param paths + * All of the strings exploded from PATH. + * Each exploded path, when not empty, is guaranteed to have a trailing '/'. + * Each exploded path is not NULL terminated. + * + * @return + * F_none on success. + * F_buffer_too_large (with error bit) if paths array is too large for further addressing. + * F_memory_reallocation (with error bit) on reallocation error. + * F_memory_allocation (with error bit) on allocation error. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_environment_path_explode_reverse_dynamic_ + extern f_return_status f_environment_path_explode_reverse_dynamic(const f_string_static path, f_string_dynamics *paths); +#endif // _di_f_environment_path_explode_reverse_dynamic_ + +/** * Assign the given value to the named environment variable. * * If the name does not exist, then it is created. diff --git a/level_0/f_path/c/path.c b/level_0/f_path/c/path.c index 41afc02..5653c8d 100644 --- a/level_0/f_path/c/path.c +++ b/level_0/f_path/c/path.c @@ -91,157 +91,6 @@ extern "C" { } #endif // _di_f_path_current_ -#ifndef _di_f_path_explode_ - f_return_status f_path_explode(const f_string path, f_string_dynamics *paths) { - #ifndef _di_level_0_parameter_checking_ - if (paths == 0) return F_status_set_error(F_parameter); - if (paths->used > paths->size) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status status = F_none; - const f_string_length length = strnlen(path, PATH_MAX); - - if (length == 0) { - // When PATH is "", this is actually a valid search path for PWD. - // Therefore append an equivalent representation of PWD (string used length is 0). - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - f_macro_string_dynamic_clear(paths->array[paths->used]); - paths->used++; - - return F_none; - } - - f_string_length i = length; - f_string_length first = 0; - f_string_length total = 0; - - for (i = 0; i <= length; i++) { - if (i == length || path[i] == f_path_separator_variable[0]) { - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - if (i == 0) { - f_macro_string_dynamic_clear(paths->array[paths->used]); - paths->used++; - - first = 1; - continue; - } - - f_string_dynamic part = f_string_dynamic_initialize; - - total = i - first; - - if (total > 0) { - if (path[i - 1] == f_path_separator[0]) { - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - part.used = total; - } - else { - f_macro_string_dynamic_new(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.string[total] = f_path_separator[0]; - part.used = total + 1; - } - - memcpy(part.string, path + first, total); - } - - paths->array[paths->used].string = part.string; - paths->array[paths->used].used = part.used; - paths->array[paths->used].size = part.size; - paths->used++; - - first = i + 1; - } - } // for - - return F_none; - } -#endif // _di_f_path_explode_ - -#ifndef _di_f_path_explode_dynamic_ - f_return_status f_path_explode_dynamic(const f_string_static path, f_string_dynamics *paths) { - #ifndef _di_level_0_parameter_checking_ - if (path.used > path.size) return F_status_set_error(F_parameter); - if (paths == 0) return F_status_set_error(F_parameter); - if (paths->used > paths->size) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status status = F_none; - - if (path.used == 0) { - // When PATH is "", this is actually a valid search path for PWD. - // Therefore append an equivalent representation of PWD (string used length is 0). - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - f_macro_string_dynamic_clear(paths->array[paths->used]); - paths->used++; - - return F_none; - } - - f_string_length i = 0; - f_string_length j = 0; - f_string_length first = 0; - f_string_length total = 0; - - f_string_dynamic part = f_string_dynamic_initialize; - - for (i = 0; i <= path.used; i++) { - if (i == path.used || path.string[i] == f_path_separator_variable[0]) { - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - if (i == 0) { - f_macro_string_dynamic_clear(paths->array[paths->used]); - paths->used++; - - first = 1; - continue; - } - - total = i - first; - - if (total > 0) { - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - for (j = 0; j < total; j++) { - if (path.string[first + j] == 0) continue; - - part.string[part.used] = path.string[first + j]; - part.used++; - } // for - - if (part.string[part.used - 1] != f_path_separator[0]) { - f_macro_string_dynamic_resize(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.string[part.used] = f_path_separator[0]; - part.used++; - } - } - - paths->array[paths->used].string = part.string; - paths->array[paths->used].used = part.used; - paths->array[paths->used].size = part.size; - paths->used++; - - first = i + 1; - } - } // for - - return F_none; - } -#endif // _di_f_path_explode_dynamic_ - #ifndef _di_f_path_real_ f_return_status f_path_real(const f_string path, f_string_dynamic *real) { #ifndef _di_level_0_parameter_checking_ @@ -252,197 +101,6 @@ extern "C" { } #endif // _di_f_path_real_ -#ifndef _di_f_path_explode_reverse_ - f_return_status f_path_explode_reverse(const f_string path, f_string_dynamics *paths) { - #ifndef _di_level_0_parameter_checking_ - if (paths == 0) return F_status_set_error(F_parameter); - if (paths->used > paths->size) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status status = F_none; - const f_string_length length = strnlen(path, PATH_MAX); - - if (length == 0) { - // When PATH is "", this is actually a valid search path for PWD. - // Therefore append an equivalent representation of PWD (string used length is 0). - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - paths->array[paths->used].string = 0; - paths->array[paths->used].used = 0; - paths->array[paths->used].size = 0; - paths->used++; - - return F_none; - } - - f_string_length i = length; - f_string_length j = length; - f_string_length last = length; - f_string_length total = 0; - - f_string_dynamic part = f_string_dynamic_initialize; - - for (; i > 0; i--) { - j--; - - if (j == 0 || path[j] == f_path_separator_variable[0]) { - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - if (path[j] == f_path_separator_variable[0]) { - total = last - i; - - if (total > 0) { - if (path[j + total] == f_path_separator[0]) { - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - part.used = total; - } - else { - f_macro_string_dynamic_new(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.string[total] = f_path_separator[0]; - part.used = total + 1; - } - - memcpy(part.string, path + i, total); - } - - last = j; - } - else if (j == 0) { - // when j = 0, the total is actually the entire length to max. - total = last - j; - - if (total > 0) { - if (path[last - 1] == f_path_separator[0]) { - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - part.used = total; - } - else { - f_macro_string_dynamic_new(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.used = total + 1; - part.string[total] = f_path_separator[0]; - } - - memcpy(part.string, path, total); - } - } - - paths->array[paths->used].string = part.string; - paths->array[paths->used].used = part.used; - paths->array[paths->used].size = part.size; - paths->used++; - } - } // for - - return F_none; - } -#endif // _di_f_path_explode_reverse_ - -#ifndef _di_f_path_explode_reverse_dynamic_ - f_return_status f_path_explode_reverse_dynamic(const f_string_static path, f_string_dynamics *paths) { - #ifndef _di_level_0_parameter_checking_ - if (path.used > path.size) return F_status_set_error(F_parameter); - if (paths == 0) return F_status_set_error(F_parameter); - if (paths->used > paths->size) return F_status_set_error(F_parameter); - #endif // _di_level_0_parameter_checking_ - - f_status status = F_none; - - if (path.used == 0) { - // When PATH is "", this is actually a valid search path for PWD. - // Therefore append an equivalent representation of PWD (string used length is 0). - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - f_macro_string_dynamic_clear(paths->array[paths->used]); - paths->used++; - - return F_none; - } - - f_string_length i = path.used; - f_string_length j = path.used; - f_string_length k = 0; - f_string_length last = path.used; - f_string_length total = 0; - - f_string_dynamic part = f_string_dynamic_initialize; - - for (; i > 0; i--) { - j--; - - if (j == 0 || path.string[j] == f_path_separator_variable[0]) { - f_macro_memory_structure_macro_increment(status, (*paths), 1, f_memory_default_allocation_step, f_macro_string_dynamics_resize, F_buffer_too_large); - if (F_status_is_error(status)) return status; - - if (path.string[j] == f_path_separator_variable[0]) { - total = last - i; - - if (total > 0) { - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - for (k = 0; k < total; k++) { - if (path.string[i + k] == 0) continue; - - part.string[part.used] = path.string[i + k]; - part.used++; - } // for - - if (part.string[part.used - 1] != f_path_separator[0]) { - f_macro_string_dynamic_resize(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.string[part.used] = f_path_separator[0]; - part.used++; - } - } - - last = j; - } - else if (j == 0) { - // when j = 0, the total is actually the entire length to max. - total = last - j; - - f_macro_string_dynamic_new(status, part, total); - if (F_status_is_error(status)) return status; - - for (k = 0; k < total; k++) { - if (path.string[i + k] == 0) continue; - - part.string[part.used] = path.string[i + k]; - part.used++; - } // for - - if (part.string[part.used - 1] != f_path_separator[0]) { - f_macro_string_dynamic_resize(status, part, total + 1); - if (F_status_is_error(status)) return status; - - part.string[part.used - 1] = f_path_separator[0]; - part.used++; - } - } - - paths->array[paths->used].string = part.string; - paths->array[paths->used].used = part.used; - paths->array[paths->used].size = part.size; - paths->used++; - } - } // for - - return F_none; - } -#endif // _di_f_path_explode_reverse_dynamic_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_path/c/path.h b/level_0/f_path/c/path.h index 66f5846..5160fd7 100644 --- a/level_0/f_path/c/path.h +++ b/level_0/f_path/c/path.h @@ -146,54 +146,6 @@ extern "C" { #endif // _di_f_path_current_ /** - * Separate a given PATH-style string into multiple separate paths. - * - * @param path - * The string to process that is expected to follow the traditional Linux standard PATH environment variable. - * Each seperate path is separated by a single ':'. - * Must not contain NULLs except for the terminating NULL. - * Must be NULL terminated. - * @param paths - * All of the strings exploded from PATH. - * Each exploded path, when not empty, is guaranteed to have a trailing '/'. - * Each exploded path is not NULL terminated. - * - * @return - * F_none on success. - * F_buffer_too_large (with error bit) if paths array is too large for further addressing. - * F_memory_reallocation (with error bit) on reallocation error. - * F_memory_allocation (with error bit) on allocation error. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_path_explode_ - extern f_return_status f_path_explode(const f_string path, f_string_dynamics *paths); -#endif // _di_f_path_explode_ - -/** - * Separate a given PATH-style string into multiple separate paths. - * - * @param path - * The string to process that is expected to follow the traditional Linux standard PATH environment variable. - * Each seperate path is separated by a single ':'. - * Need not be NULL terminated. - * NULLs are ignored and are not copied into the exploded paths. - * @param paths - * All of the strings exploded from PATH. - * Each exploded path, when not empty, is guaranteed to have a trailing '/'. - * Each exploded path is not NULL terminated. - * - * @return - * F_none on success. - * F_buffer_too_large (with error bit) if paths array is too large for further addressing. - * F_memory_reallocation (with error bit) on reallocation error. - * F_memory_allocation (with error bit) on allocation error. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_path_explode_dynamic_ - extern f_return_status f_path_explode_dynamic(const f_string_static path, f_string_dynamics *paths); -#endif // _di_f_path_explode_dynamic_ - -/** * Get the real path for some path. * * All symbolic links and relative path parts are expanded to yield the real full path. @@ -226,58 +178,6 @@ extern "C" { extern f_return_status f_path_real(const f_string path, f_string_dynamic *real); #endif // _di_f_path_real_ -/** - * Separate a given PATH-style string into multiple separate paths. - * - * The paths are created in reverse order. - * - * @param path - * The string to process that is expected to follow the traditional Linux standard PATH environment variable. - * Each seperate path is separated by a single ':'. - * Must not contain NULLs except for the terminating NULL. - * Must be NULL terminated. - * @param paths - * All of the strings exploded from PATH. - * Each exploded path, when not empty, is guaranteed to have a trailing '/'. - * Each exploded path is not NULL terminated. - * - * @return - * F_none on success. - * F_buffer_too_large (with error bit) if paths array is too large for further addressing. - * F_memory_reallocation (with error bit) on reallocation error. - * F_memory_allocation (with error bit) on allocation error. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_path_explode_reverse_ - extern f_return_status f_path_explode_reverse(const f_string path, f_string_dynamics *paths); -#endif // _di_f_path_explode_reverse_ - -/** - * Separate a given PATH-style string into multiple separate paths. - * - * The paths are created in reverse order. - * - * @param path - * The string to process that is expected to follow the traditional Linux standard PATH environment variable. - * Each seperate path is separated by a single ':'. - * Need not be NULL terminated. - * NULLs are ignored and are not copied into the exploded paths. - * @param paths - * All of the strings exploded from PATH. - * Each exploded path, when not empty, is guaranteed to have a trailing '/'. - * Each exploded path is not NULL terminated. - * - * @return - * F_none on success. - * F_buffer_too_large (with error bit) if paths array is too large for further addressing. - * F_memory_reallocation (with error bit) on reallocation error. - * F_memory_allocation (with error bit) on allocation error. - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_f_path_explode_reverse_dynamic_ - extern f_return_status f_path_explode_reverse_dynamic(const f_string_static path, f_string_dynamics *paths); -#endif // _di_f_path_explode_reverse_dynamic_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index 7f8a846..eb323a4 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -587,7 +587,7 @@ extern "C" { } } else { - status = f_path_explode_dynamic(path, &paths); + status = f_environment_path_explode_dynamic(path, &paths); } if (F_status_is_error(status)) {