From 27868e1f4903c54699f749f3ed41d8fbf27259e2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 12 Dec 2020 22:20:39 -0600 Subject: [PATCH] Cleanup: further utilize static stringss and correct the FSS Extended read function documentation. --- level_0/f_path/c/path-common.h | 11 +++++++++ level_0/f_path/c/path.c | 2 +- level_1/fl_directory/c/directory.c | 22 ++++++++--------- level_1/fl_directory/c/private-directory.c | 38 +++++++++++++++--------------- level_1/fl_environment/c/environment.c | 24 +++++++++---------- level_1/fl_fss/c/fss_basic.h | 1 + level_1/fl_fss/c/fss_extended.h | 1 + level_2/fll_file/c/private-file.c | 8 +++---- level_3/fake/c/private-build.c | 10 ++++---- level_3/fake/c/private-make.c | 8 +++---- 10 files changed, 69 insertions(+), 56 deletions(-) diff --git a/level_0/f_path/c/path-common.h b/level_0/f_path/c/path-common.h index 8fd92ea..7177cde 100644 --- a/level_0/f_path/c/path-common.h +++ b/level_0/f_path/c/path-common.h @@ -55,6 +55,17 @@ extern "C" { #define f_path_present_working_old_length 6 #define f_path_max PATH_MAX + + const static f_string_t f_path_separator_s = f_path_separator; + const static f_string_t f_path_separator_current_s = f_path_separator_current; + const static f_string_t f_path_separator_variable_s = f_path_separator_variable; + + #define f_path_extension_separator_s f_path_separator_current_s + + const static f_string_t f_path_environment_s = f_path_environment; + const static f_string_t f_path_home_wildcard_s = f_path_home_wildcard; + const static f_string_t f_path_present_working_s = f_path_present_working; + const static f_string_t f_path_present_working_old_s = f_path_present_working_old; #endif // _di_f_path_defines_ #ifdef __cplusplus diff --git a/level_0/f_path/c/path.c b/level_0/f_path/c/path.c index e7ad088..1429263 100644 --- a/level_0/f_path/c/path.c +++ b/level_0/f_path/c/path.c @@ -99,7 +99,7 @@ extern "C" { for (f_string_length_t i = 0; i < length; i++) { - if (path[i] == f_path_separator[0]) { + if (path[i] == f_path_separator_s[0]) { return F_true; } } // for diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 0e0ce03..e8447cf 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -28,7 +28,7 @@ extern "C" { for (; path[at_path]; ++at_path) { - if (at_path && path[at_path] == f_path_separator[0]) { + if (at_path && path[at_path] == f_path_separator_s[0]) { memcpy(tree, path + at_tree, at_path - at_tree); tree[at_path] = 0; @@ -99,7 +99,7 @@ extern "C" { for (; i > 0; i--, static_source.used--) { if (!source[i - 1]) continue; - if (source[i - 1] == f_path_separator[0]) continue; + if (source[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -109,7 +109,7 @@ extern "C" { for (; i > 0; i--, static_destination.used--) { if (!destination[i - 1]) continue; - if (destination[i - 1] == f_path_separator[0]) continue; + if (destination[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -153,7 +153,7 @@ extern "C" { for (; i > 0; i--, static_source.used--) { if (!source[i - 1]) continue; - if (source[i - 1] == f_path_separator[0]) continue; + if (source[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -163,7 +163,7 @@ extern "C" { for (; i > 0; i--, static_destination.used--) { if (!destination[i - 1]) continue; - if (destination[i - 1] == f_path_separator[0]) continue; + if (destination[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -221,7 +221,7 @@ extern "C" { for (; i > 0; i--, static_source.used--) { if (!source[i - 1]) continue; - if (source[i - 1] == f_path_separator[0]) continue; + if (source[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -231,7 +231,7 @@ extern "C" { for (; i > 0; i--, static_destination.used--) { if (!destination[i - 1]) continue; - if (destination[i - 1] == f_path_separator[0]) continue; + if (destination[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -275,7 +275,7 @@ extern "C" { for (; i > 0; i--, static_source.used--) { if (!source[i - 1]) continue; - if (source[i - 1] == f_path_separator[0]) continue; + if (source[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -285,7 +285,7 @@ extern "C" { for (; i > 0; i--, static_destination.used--) { if (!destination[i - 1]) continue; - if (destination[i - 1] == f_path_separator[0]) continue; + if (destination[i - 1] == f_path_separator_s[0]) continue; break; } // for @@ -346,7 +346,7 @@ extern "C" { } if (first_nulless) { - if (path->string[i] == f_path_separator[0]) { + if (path->string[i] == f_path_separator_s[0]) { if (null_terminated) { path->string[i + 1] = 0; path->used = i + 2; @@ -373,7 +373,7 @@ extern "C" { return status; } - if (path->string[j] != f_path_separator[0]) { + if (path->string[j] != f_path_separator_s[0]) { i = j + 1; break; } diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index e62fadb..1cc8a80 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -65,10 +65,10 @@ extern "C" { memcpy(path_destination_sub, destination.string, destination.used); memcpy(path_destination_sub + destination.used + 1, listing.directory.array[i].string, listing.directory.array[i].used); - path_source_sub[source.used] = f_path_separator[0]; + path_source_sub[source.used] = f_path_separator_s[0]; path_source_sub[source_sub.used] = 0; - path_destination_sub[destination.used] = f_path_separator[0]; + path_destination_sub[destination.used] = f_path_separator_s[0]; path_destination_sub[destination_sub.used] = 0; source_sub.string = path_source_sub; @@ -139,12 +139,12 @@ extern "C" { memcpy(path_source, source.string, source.used); memcpy(path_source + source.used + 1, file.string, file.used); - path_source[source.used] = f_path_separator[0]; + path_source[source.used] = f_path_separator_s[0]; path_source[source.used + file.used + 1] = 0; memcpy(path_destination, destination.string, destination.used); memcpy(path_destination + destination.used + 1, file.string, file.used); - path_destination[destination.used] = f_path_separator[0]; + path_destination[destination.used] = f_path_separator_s[0]; path_destination[destination.used + file.used + 1] = 0; f_status_t status = f_file_clone(path_source, path_destination, role, recurse.size_block, recurse.exclusive); @@ -275,10 +275,10 @@ extern "C" { memcpy(path_destination_sub, destination.string, destination.used); memcpy(path_destination_sub + destination.used + 1, listing.directory.array[i].string, listing.directory.array[i].used); - path_source_sub[source.used] = f_path_separator[0]; + path_source_sub[source.used] = f_path_separator_s[0]; path_source_sub[source_sub.used] = 0; - path_destination_sub[destination.used] = f_path_separator[0]; + path_destination_sub[destination.used] = f_path_separator_s[0]; path_destination_sub[destination_sub.used] = 0; source_sub.string = path_source_sub; @@ -335,12 +335,12 @@ extern "C" { memcpy(path_source, source.string, source.used); memcpy(path_source + source.used + 1, file.string, file.used); - path_source[source.used] = f_path_separator[0]; + path_source[source.used] = f_path_separator_s[0]; path_source[source.used + file.used + 1] = 0; memcpy(path_destination, destination.string, destination.used); memcpy(path_destination + destination.used + 1, file.string, file.used); - path_destination[destination.used] = f_path_separator[0]; + path_destination[destination.used] = f_path_separator_s[0]; path_destination[destination.used + file.used + 1] = 0; f_status_t status = f_file_copy(path_source, path_destination, mode, recurse.size_block, recurse.exclusive); @@ -603,7 +603,7 @@ extern "C" { return status; } - if (destination->string[i] == f_path_separator[0]) { + if (destination->string[i] == f_path_separator_s[0]) { if (i - 1 > 0) { for (j = i - 1; j > 0; j--) { if (!destination->string[j]) continue; @@ -617,7 +617,7 @@ extern "C" { return status; } - if (destination->string[j] == f_path_separator[0]) { + if (destination->string[j] == f_path_separator_s[0]) { destination->used = j + 1; } else { @@ -635,7 +635,7 @@ extern "C" { } // for if (destination->used > 0 && !i) { - if (destination->string[0] != 0 && destination->string[0] != f_path_separator[0]) { + if (destination->string[0] != 0 && destination->string[0] != f_path_separator_s[0]) { separator_prepend = F_true; total++; } @@ -654,7 +654,7 @@ extern "C" { return status; } - if (source[i] == f_path_separator[0]) { + if (source[i] == f_path_separator_s[0]) { if (!separator_prepend && destination->used > 0) { destination->used--; } @@ -672,7 +672,7 @@ extern "C" { return status; } - if (source[j] == f_path_separator[0]) { + if (source[j] == f_path_separator_s[0]) { length_truncated = j + 1; } else { @@ -689,7 +689,7 @@ extern "C" { break; } // for - if (!i && source[0] != f_path_separator[0]) { + if (!i && source[0] != f_path_separator_s[0]) { separator_append = F_true; total++; } @@ -708,7 +708,7 @@ extern "C" { start = i; - if (source[0] == f_path_separator[0]) { + if (source[0] == f_path_separator_s[0]) { if (i + 1 < length_truncated) { for (j = i + 1; j < length_truncated; j++) { if (!source[j]) continue; @@ -722,7 +722,7 @@ extern "C" { return status; } - if (source[j] == f_path_separator[0]) { + if (source[j] == f_path_separator_s[0]) { start = j; } else { @@ -748,7 +748,7 @@ extern "C" { } if (separator_prepend) { - destination->string[destination->used] = f_path_separator[0]; + destination->string[destination->used] = f_path_separator_s[0]; destination->used++; total--; } @@ -761,11 +761,11 @@ extern "C" { if (separator_append) { if (terminated_null) { - destination->string[destination->used - 2] = f_path_separator[0]; + destination->string[destination->used - 2] = f_path_separator_s[0]; destination->string[destination->used - 1] = 0; } else { - destination->string[destination->used - 1] = f_path_separator[0]; + destination->string[destination->used - 1] = f_path_separator_s[0]; } } else if (terminated_null) { diff --git a/level_1/fl_environment/c/environment.c b/level_1/fl_environment/c/environment.c index 1670a73..f6416d2 100644 --- a/level_1/fl_environment/c/environment.c +++ b/level_1/fl_environment/c/environment.c @@ -50,7 +50,7 @@ extern "C" { total = i - first; if (total > 0) { - if (path[i - 1] == f_path_separator[0]) { + if (path[i - 1] == f_path_separator_s[0]) { f_macro_string_dynamic_t_new(status, part, total); if (F_status_is_error(status)) return status; @@ -60,7 +60,7 @@ extern "C" { f_macro_string_dynamic_t_new(status, part, total + 1); if (F_status_is_error(status)) return status; - part.string[total] = f_path_separator[0]; + part.string[total] = f_path_separator_s[0]; part.used = total + 1; } @@ -137,11 +137,11 @@ extern "C" { part.used++; } // for - if (part.string[part.used - 1] != f_path_separator[0]) { + if (part.string[part.used - 1] != f_path_separator_s[0]) { f_macro_string_dynamic_t_resize(status, part, total + 1); if (F_status_is_error(status)) return status; - part.string[part.used] = f_path_separator[0]; + part.string[part.used] = f_path_separator_s[0]; part.used++; } } @@ -202,7 +202,7 @@ extern "C" { total = last - i; if (total > 0) { - if (path[j + total] == f_path_separator[0]) { + if (path[j + total] == f_path_separator_s[0]) { f_macro_string_dynamic_t_new(status, part, total); if (F_status_is_error(status)) return status; @@ -212,7 +212,7 @@ extern "C" { f_macro_string_dynamic_t_new(status, part, total + 1); if (F_status_is_error(status)) return status; - part.string[total] = f_path_separator[0]; + part.string[total] = f_path_separator_s[0]; part.used = total + 1; } @@ -227,7 +227,7 @@ extern "C" { total = last - j; if (total > 0) { - if (path[last - 1] == f_path_separator[0]) { + if (path[last - 1] == f_path_separator_s[0]) { f_macro_string_dynamic_t_new(status, part, total); if (F_status_is_error(status)) return status; @@ -238,7 +238,7 @@ extern "C" { if (F_status_is_error(status)) return status; part.used = total + 1; - part.string[total] = f_path_separator[0]; + part.string[total] = f_path_separator_s[0]; } memcpy(part.string, path, total); @@ -307,11 +307,11 @@ extern "C" { part.used++; } // for - if (part.string[part.used - 1] != f_path_separator[0]) { + if (part.string[part.used - 1] != f_path_separator_s[0]) { f_macro_string_dynamic_t_resize(status, part, total + 1); if (F_status_is_error(status)) return status; - part.string[part.used] = f_path_separator[0]; + part.string[part.used] = f_path_separator_s[0]; part.used++; } } @@ -332,11 +332,11 @@ extern "C" { part.used++; } // for - if (part.string[part.used - 1] != f_path_separator[0]) { + if (part.string[part.used - 1] != f_path_separator_s[0]) { f_macro_string_dynamic_t_resize(status, part, total + 1); if (F_status_is_error(status)) return status; - part.string[part.used - 1] = f_path_separator[0]; + part.string[part.used - 1] = f_path_separator_s[0]; part.used++; } } diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index ab4613c..d3fedfa 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -53,6 +53,7 @@ extern "C" { * * @return * FL_fss_found_object on success and object was found (start location is at end of object). + * FL_fss_found_object_content_not on success but object ended at the line so there can be no content. * FL_fss_found_object_not on success and no object was found (start location is after character designating this is not an object). * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed). diff --git a/level_1/fl_fss/c/fss_extended.h b/level_1/fl_fss/c/fss_extended.h index 4c6733f..1b9d02a 100644 --- a/level_1/fl_fss/c/fss_extended.h +++ b/level_1/fl_fss/c/fss_extended.h @@ -53,6 +53,7 @@ extern "C" { * * @return * FL_fss_found_object on success and object was found (start location is at end of object). + * FL_fss_found_object_content_not on success but object ended at the line so there can be no content. * FL_fss_found_object_not on success and no object was found (start location is after character designating this is not an object). * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed). diff --git a/level_2/fll_file/c/private-file.c b/level_2/fll_file/c/private-file.c index d73fca3..93287af 100644 --- a/level_2/fll_file/c/private-file.c +++ b/level_2/fll_file/c/private-file.c @@ -54,7 +54,7 @@ extern "C" { memcpy(path_sub, path, path_length); memcpy(path_sub + path_length + 1, list[i]->array[j].string, list[i]->array[j].used); - path_sub[path_length] = f_path_separator[0]; + path_sub[path_length] = f_path_separator_s[0]; path_sub[length] = 0; status = f_file_mode_set(path_sub, mode); @@ -75,7 +75,7 @@ extern "C" { memcpy(path_sub, path, path_length); memcpy(path_sub + path_length + 1, listing.directory.array[i].string, listing.directory.array[i].used); - path_sub[path_length] = f_path_separator[0]; + path_sub[path_length] = f_path_separator_s[0]; path_sub[length] = 0; status = f_directory_exists(path_sub); @@ -151,7 +151,7 @@ extern "C" { memcpy(path_sub, path, path_length); memcpy(path_sub + path_length + 1, list[i]->array[j].string, list[i]->array[j].used); - path_sub[path_length] = f_path_separator[0]; + path_sub[path_length] = f_path_separator_s[0]; path_sub[length] = 0; status = f_file_role_change(path_sub, uid, gid, dereference); @@ -170,7 +170,7 @@ extern "C" { memcpy(path_sub, path, path_length); memcpy(path_sub + path_length + 1, listing.directory.array[i].string, listing.directory.array[i].used); - path_sub[path_length] = f_path_separator[0]; + path_sub[path_length] = f_path_separator_s[0]; path_sub[length] = 0; status = f_directory_exists(path_sub); diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index 8691c8f..87b0803 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -1123,7 +1123,7 @@ extern "C" { break; } - *status = fl_string_append_assure(f_path_separator, f_path_separator_length, &source_path); + *status = fl_string_append_assure(f_path_separator_s, f_path_separator_length, &source_path); if (F_status_is_error(*status)) { fll_error_print(data.error, F_status_set_fine(*status), "fl_string_append_assure", F_true); @@ -1190,8 +1190,8 @@ extern "C" { { // add the guaranteed environment variables. const f_string_t variables_name[] = { - f_path_environment, - f_path_present_working + f_path_environment_s, + f_path_present_working_s }; const f_string_length_t variables_length[] = { @@ -2032,7 +2032,7 @@ extern "C" { } if (settings_single_type[i] == 2) { - *status = fl_string_append_assure(f_path_separator, f_path_separator_length, settings_single_destination[i]); + *status = fl_string_append_assure(f_path_separator_s, f_path_separator_length, settings_single_destination[i]); if (F_status_is_error(*status)) { fll_error_print(data.error, F_status_set_fine(*status), "fl_string_append_assure", F_true); break; @@ -2445,7 +2445,7 @@ extern "C" { break; } - *status = fl_string_append_assure(f_path_separator, f_path_separator_length, &destination_path); + *status = fl_string_append_assure(f_path_separator_s, f_path_separator_length, &destination_path); if (F_status_is_error(*status)) { fll_error_print(data.error, F_status_set_fine(*status), "fl_string_append_assure", F_true); diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index f2ed7aa..1b984e0 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -33,7 +33,7 @@ extern "C" { return F_true; } - if (data_make->path_cache.string[data_make->path.stack.array[0].used] == f_path_separator[0]) { + if (data_make->path_cache.string[data_make->path.stack.array[0].used] == f_path_separator_s[0]) { return F_true; } } @@ -2383,7 +2383,7 @@ extern "C" { if (existing) { memcpy(destination + arguments.array[total].used + 1, arguments.array[i].string, arguments.array[i].used); - destination[arguments.array[total].used] = f_path_separator[0]; + destination[arguments.array[total].used] = f_path_separator_s[0]; } destination[destination_length] = 0; @@ -2483,7 +2483,7 @@ extern "C" { if (existing) { memcpy(destination + arguments.array[total].used + 1, arguments.array[i].string, arguments.array[i].used); - destination[arguments.array[total].used] = f_path_separator[0]; + destination[arguments.array[total].used] = f_path_separator_s[0]; } destination[destination_length] = 0; @@ -3419,7 +3419,7 @@ extern "C" { if (existing) { memcpy(destination + arguments.array[total].used + 1, arguments.array[i].string, arguments.array[i].used); - destination[arguments.array[total].used] = f_path_separator[0]; + destination[arguments.array[total].used] = f_path_separator_s[0]; } destination[destination_length] = 0; -- 1.8.3.1