From c1399b1c92ffbdbbef2cb256f19ca5c350300289 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 10 Sep 2020 20:12:59 -0500 Subject: [PATCH] Progress: featureless make. Finish implementing -f/--fakefile and updating -s/--settings parameters. This adds a new function f_path_is(), which is a dirt simple function for checking if the path separator exist in a given string. --- level_0/f_path/c/path.c | 19 ++++++++++++++++++- level_0/f_path/c/path.h | 24 ++++++++++++++++++++++++ level_3/fake/c/fake.c | 1 + level_3/fake/c/fake.h | 12 ++++-------- level_3/fake/c/private-fake.c | 26 ++++++++++++++++++++------ level_3/fake/data/build/fakefile-example-bzip2 | 2 +- 6 files changed, 68 insertions(+), 16 deletions(-) diff --git a/level_0/f_path/c/path.c b/level_0/f_path/c/path.c index c4d6d56..45dd030 100644 --- a/level_0/f_path/c/path.c +++ b/level_0/f_path/c/path.c @@ -91,10 +91,27 @@ extern "C" { } #endif // _di_f_path_current_ +#ifndef _di_f_path_is_ + f_return_status f_path_is(const f_string_t path, const f_string_length_t length) { + if (!path || !length) { + return F_false; + } + + for (f_string_length_t i = 0; i < length; i++) { + + if (path[i] == f_path_separator[0]) { + return F_true; + } + } // for + + return F_false; + } +#endif // _di_f_path_is_ + #ifndef _di_f_path_real_ f_return_status f_path_real(const f_string_t path, f_string_dynamic_t *real) { #ifndef _di_level_0_parameter_checking_ - if (real == 0) return F_status_set_error(F_parameter); + if (!real) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ return private_f_path_real(path, real); diff --git a/level_0/f_path/c/path.h b/level_0/f_path/c/path.h index aa400d7..06c2b32 100644 --- a/level_0/f_path/c/path.h +++ b/level_0/f_path/c/path.h @@ -32,6 +32,9 @@ extern "C" { * The path separator, intended to be represented as a single character. * The path separator length must be a 1-byte wide character. * + * The "current" path separator "." represents a part of the path that potentially may represent the current path. + * This is expected to be followed by a separator "/". + * * The path variable separator is intended to represent the path separator used in the PATH environment variable. * PATH="/bin:/usr/bin", the path variable separator is ':'. * The path variable separator must be a 1-byte wide character. @@ -40,9 +43,11 @@ extern "C" { */ #ifndef _di_f_path_defines_ #define f_path_separator "/" + #define f_path_separator_current "." #define f_path_separator_variable ":" #define f_path_separator_length 1 + #define f_path_separator_current_length 1 #define f_path_separator_variable_length 1 #define f_path_extension_separator "." @@ -146,6 +151,25 @@ extern "C" { #endif // _di_f_path_current_ /** + * Identify whether or not a string represents a path string. + * + * A string without any path parts that could be a path is not considered a path by this function. + * That is to say "my_file.txt" is not a path string but "./my_file.txt" is a path string. + * + * @param path + * The string that may or may not represent a path.. + * @param length + * Length of the path string. + * + * @return + * F_true if this string is a path string. + * F_false if this string is not a path string. + */ +#ifndef _di_f_path_is_ + extern f_return_status f_path_is(const f_string_t path, const f_string_length_t length); +#endif // _di_f_path_is_ + +/** * Get the real path for the given path. * * This does check to see if the path exists or not (path must exist). diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index e49c4a0..aa7dcd2 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -380,6 +380,7 @@ extern "C" { f_macro_string_lengths_t_delete_simple(data->remaining); f_macro_string_dynamics_t_delete_simple(data->define); + f_macro_string_dynamic_t_delete_simple(data->fakefile); f_macro_string_dynamics_t_delete_simple(data->mode); f_macro_string_dynamic_t_delete_simple(data->process); f_macro_string_dynamic_t_delete_simple(data->settings); diff --git a/level_3/fake/c/fake.h b/level_3/fake/c/fake.h index 3bd8c8a..269d463 100644 --- a/level_3/fake/c/fake.h +++ b/level_3/fake/c/fake.h @@ -146,19 +146,11 @@ extern "C" { #ifndef _di_fake_file_ #define fake_file_defines "defines" #define fake_file_dependencies "dependencies" - #define fake_file_fakefile "fakefile" - #define fake_file_process_post "process_post.sh" - #define fake_file_process_pre "process_pre.sh" #define fake_file_readme "readme" - #define fake_file_settings "settings" #define fake_file_defines_length 7 #define fake_file_dependencies_length 12 - #define fake_file_fakefile_length 8 - #define fake_file_process_post_length 15 - #define fake_file_process_pre_length 14 #define fake_file_readme_length 6 - #define fake_file_settings_length 8 #endif // _di_fake_file_ /** @@ -176,11 +168,13 @@ extern "C" { #define fake_default_path_work_length 0 #define fake_default_define "" + #define fake_default_fakefile "fakefile" #define fake_default_mode "" #define fake_default_process "" #define fake_default_settings "settings" #define fake_default_define_length 0 + #define fake_default_fakefile_length 8 #define fake_default_mode_length 0 #define fake_default_process_length 0 #define fake_default_settings_length 8 @@ -385,6 +379,7 @@ extern "C" { uint8_t verbosity; f_string_dynamics_t define; + f_string_dynamic_t fakefile; f_string_dynamics_t mode; f_string_dynamic_t process; f_string_dynamic_t settings; @@ -448,6 +443,7 @@ extern "C" { 0, \ fake_verbosity_normal, \ f_string_dynamics_t_initialize, \ + f_string_dynamic_t_initialize, \ f_string_dynamics_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamic_t_initialize, \ diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 2815671..42926b2 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -291,6 +291,15 @@ extern "C" { } // for } + // When custom fakefile or settings are used and they are paths to a file, remove the default path. + if (f_path_is(data->fakefile.string, data->fakefile.used)) { + data->file_data_build_fakefile.used = 0; + } + + if (f_path_is(data->settings.string, data->settings.used)) { + data->file_data_build_settings.used = 0; + } + { const f_string_t parameters_source[] = { fake_path_part_script, @@ -301,7 +310,7 @@ extern "C" { fake_path_part_static, fake_file_defines, fake_file_dependencies, - fake_file_fakefile, + data->fakefile.string, data->settings.string, fake_file_readme, }; @@ -315,7 +324,7 @@ extern "C" { fake_path_part_static_length, fake_file_defines_length, fake_file_dependencies_length, - fake_file_fakefile_length, + data->fakefile.used, data->settings.used, fake_file_readme_length, }; @@ -468,8 +477,6 @@ extern "C" { } } - // @todo use fakefile and settings file if a custom path is provided by the command line instead of the default. - { f_string_dynamic_t *parameters_value[] = { &data->path_build_documents, @@ -503,11 +510,12 @@ extern "C" { &data->path_work_programs_static, &data->file_data_build_defines, &data->file_data_build_dependencies, + &data->file_data_build_fakefile, &data->file_data_build_settings, &data->file_documents_readme, }; - for (i = 0; i < 33; i++) { + for (i = 0; i < 34; i++) { if (parameters_value[i]->used == 0) continue; status = fl_string_dynamic_terminate_after(parameters_value[i]); @@ -573,36 +581,42 @@ extern "C" { { const uint8_t parameters_id[] = { + fake_parameter_fakefile, fake_parameter_process, fake_parameter_settings, }; const f_string_t parameters_name[] = { + fake_long_fakefile, fake_long_process, fake_long_settings, }; const f_string_t parameter_defaults[] = { + fake_default_fakefile, fake_default_process, fake_default_settings, }; const f_string_length_t parameter_default_lengths[] = { + fake_default_fakefile_length, fake_default_process_length, fake_default_settings_length, }; f_string_dynamic_t *parameters_value[] = { + &data->fakefile, &data->process, &data->settings, }; bool parameters_validate_word[] = { + F_false, F_true, F_false, }; - for (uint8_t i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 3; i++) { if (data->parameters[parameters_id[i]].result == f_console_result_found) { fake_print_error_parameter_missing_value(*data, parameters_name[i]); return F_status_set_error(F_parameter); diff --git a/level_3/fake/data/build/fakefile-example-bzip2 b/level_3/fake/data/build/fakefile-example-bzip2 index eacd97b..ee45f30 100644 --- a/level_3/fake/data/build/fakefile-example-bzip2 +++ b/level_3/fake/data/build/fakefile-example-bzip2 @@ -7,7 +7,7 @@ # 2) change into the extracted bzip2-1.0.8 directory. # 3) create the directory path "data/build/" within this bzip2-1.0.8 directory. # 4) copy the files fakefile-example-bzip2, settings-example-bzip2, and settings-example-bzip2recover) into the created directory path "data/build/". -# 5) use the featureless make build operation to make, such as: "fake make". +# 5) use the featureless make build operation to make, such as: "fake make -f fakefile-example-bzip2". settings: load_build no -- 1.8.3.1