From: Kevin Day Date: Wed, 9 Sep 2020 02:53:35 +0000 (-0500) Subject: Progress: featureless make. X-Git-Tag: 0.5.0~13 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b504624bbc36c5f28284a089b8dc3951f0105b11;p=fll Progress: featureless make. Fix mistakes where I forgot the '!' in the parameter check comparisons. Fix mistakes where I used 'i' when I needed to use 'j'. Finish implementing clone. Finish implementing copy. --- diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index fb323c6..49864e9 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -8,8 +8,8 @@ extern "C" { #ifndef _di_fl_directory_clone_ f_return_status fl_directory_clone(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse) { #ifndef _di_level_1_parameter_checking_ - if (source) return F_status_set_error(F_parameter); - if (destination) return F_status_set_error(F_parameter); + if (!source) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = f_directory_exists(source); @@ -82,8 +82,8 @@ extern "C" { #ifndef _di_fl_directory_clone_content_ f_return_status fl_directory_clone_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const bool role, const fl_directory_recurse_t recurse) { #ifndef _di_level_1_parameter_checking_ - if (source) return F_status_set_error(F_parameter); - if (destination) return F_status_set_error(F_parameter); + if (!source) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = f_directory_exists(source); @@ -128,8 +128,8 @@ extern "C" { #ifndef _di_fl_directory_copy_ f_return_status fl_directory_copy(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse) { #ifndef _di_level_1_parameter_checking_ - if (source) return F_status_set_error(F_parameter); - if (destination) return F_status_set_error(F_parameter); + if (!source) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = f_directory_exists(source); @@ -190,8 +190,8 @@ extern "C" { #ifndef _di_fl_directory_copy_content_ f_return_status fl_directory_copy_content(const f_string_t source, const f_string_t destination, const f_string_length_t source_length, const f_string_length_t destination_length, const f_mode_t mode, const fl_directory_recurse_t recurse) { #ifndef _di_level_1_parameter_checking_ - if (source) return F_status_set_error(F_parameter); - if (destination) return F_status_set_error(F_parameter); + if (!source) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status_t status = f_directory_exists(source); @@ -318,7 +318,7 @@ extern "C" { #ifndef _di_fl_directory_path_push_ f_return_status fl_directory_path_push(const f_string_t source, f_string_length_t length, f_string_dynamic_t *destination) { #ifndef _di_level_0_parameter_checking_ - if (source) return F_status_set_error(F_parameter); + if (!source) return F_status_set_error(F_parameter); if (destination->used > destination->size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index d4b09df..924add5 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -79,7 +79,7 @@ extern "C" { #endif // _di_fl_directory_recurse_t_ /** - * Copy a directory and its contents, as well as its file mode and possibly the owner and group.. + * Copy a directory and its contents, as well as its file mode and possibly the owner and group. * * The paths must not contain NULL except for the terminating NULL. * The paths must be NULL terminated. diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index e79e45e..775bad8 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -37,7 +37,7 @@ extern "C" { for (; i < 7; i++) { for (j = 0; F_status_is_fine(status) && j < list[i]->used; j++) { - status = private_fl_directory_clone_file(list[i]->array[i], source, destination, role, recurse); + status = private_fl_directory_clone_file(list[i]->array[j], source, destination, role, recurse); } // for f_macro_string_dynamics_t_delete_simple((*list[i])); @@ -203,7 +203,7 @@ extern "C" { } if (recurse.verbose) { - fprintf(recurse.verbose, "Cloned '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]); + fprintf(recurse.verbose, "Cloned '%s' to '%s'.%c", path_source, path_destination, f_string_eol[0]); } return F_none; @@ -242,7 +242,7 @@ extern "C" { for (; i < 7; i++) { for (j = 0; F_status_is_fine(status) && j < list[i]->used; j++) { - status = private_fl_directory_copy_file(list[i]->array[i], source, destination, mode, recurse); + status = private_fl_directory_copy_file(list[i]->array[j], source, destination, mode, recurse); } // for f_macro_string_dynamics_t_delete_simple((*list[i])); @@ -394,7 +394,7 @@ extern "C" { } if (recurse.verbose) { - fprintf(recurse.verbose, "Copied '%s' to '%s'.%c", source.string, destination.string, f_string_eol[0]); + fprintf(recurse.verbose, "Copied '%s' to '%s'.%c", path_source, path_destination, f_string_eol[0]); } return F_none; diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index bf5fc57..e521d40 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -1429,6 +1429,7 @@ extern "C" { f_macro_string_static_t_initialize(fake_make_operation_break, fake_make_operation_break_length), f_macro_string_static_t_initialize(fake_make_operation_build, fake_make_operation_build_length), f_macro_string_static_t_initialize(fake_make_operation_clean, fake_make_operation_clean_length), + f_macro_string_static_t_initialize(fake_make_operation_clone, fake_make_operation_clone_length), f_macro_string_static_t_initialize(fake_make_operation_compile, fake_make_operation_compile_length), f_macro_string_static_t_initialize(fake_make_operation_copy, fake_make_operation_copy_length), f_macro_string_static_t_initialize(fake_make_operation_define, fake_make_operation_define_length), @@ -1462,6 +1463,7 @@ extern "C" { f_macro_string_range_initialize(fake_make_operation_break_length), f_macro_string_range_initialize(fake_make_operation_build_length), f_macro_string_range_initialize(fake_make_operation_clean_length), + f_macro_string_range_initialize(fake_make_operation_clone_length), f_macro_string_range_initialize(fake_make_operation_compile_length), f_macro_string_range_initialize(fake_make_operation_copy_length), f_macro_string_range_initialize(fake_make_operation_define_length), @@ -1495,6 +1497,7 @@ extern "C" { fake_make_operation_type_break, fake_make_operation_type_build, fake_make_operation_type_clean, + fake_make_operation_type_clone, fake_make_operation_type_compile, fake_make_operation_type_copy, fake_make_operation_type_define, @@ -1790,17 +1793,72 @@ extern "C" { const f_array_length_t total = arguments.used -1; f_status_t status_file = F_none; + fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize; + + f_string_length_t destination_length = 0; + + if (data.verbosity == fake_verbosity_verbose) { + recurse.verbose = f_type_output; + } + + bool existing = F_true; + + // in this case, the destination could be a file, so confirm this. + if (arguments.used == 2) { + status_file = f_directory_is(arguments.array[total].string); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "f_directory_is", arguments.array[1].string, "identify", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + return; + } + + if (status_file == F_false || status_file == F_file_found_not) { + existing = F_false; + } + } + for (f_array_length_t i = 0; i < total; i++) { + destination_length = arguments.array[total].used; + + if (existing) { + destination_length += arguments.array[i].used + 1; + } + + char destination[destination_length + 1]; + + memcpy(destination, arguments.array[total].string, arguments.array[total].used); + + 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[destination_length] = 0; + status_file = f_directory_is(arguments.array[i].string); if (status_file == F_true) { - // @todo: *status = fl_directory_clone(); + status_file = fl_directory_clone(arguments.array[i].string, destination, arguments.array[i].used, destination_length, F_true, recurse); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "fl_directory_clone", arguments.array[i].string, "clone", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + } } - else if (status_file == F_true) { - // @todo: *status = f_file_clone(); + else if (status_file == F_false) { + status_file = f_file_clone(arguments.array[i].string, destination, F_true, recurse.size_block, recurse.exclusive); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "f_file_clone", arguments.array[i].string, "clone", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + } + else if (data.verbosity == fake_verbosity_verbose) { + printf("Cloned '%s' to '%s'.%c", arguments.array[i].string, destination, f_string_eol[0]); + } } else if (F_status_is_error(status_file)) { - // @todo + fake_print_message_file(data, F_status_set_fine(status_file), "f_directory_is", arguments.array[i].string, "identify", F_false, F_true, data_make->print); *status = F_status_set_error(F_failure); break; } @@ -1826,17 +1884,74 @@ extern "C" { const f_array_length_t total = arguments.used -1; f_status_t status_file = F_none; + fl_directory_recurse_t recurse = fl_directory_recurse_t_initialize; + + f_string_length_t destination_length = 0; + + f_mode_t mode = f_mode_t_initialize;f_macro_mode_t_set_default_umask(mode, data.umask); + + if (data.verbosity == fake_verbosity_verbose) { + recurse.verbose = f_type_output; + } + + bool existing = F_true; + + // in this case, the destination could be a file, so confirm this. + if (arguments.used == 2) { + status_file = f_directory_is(arguments.array[total].string); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "f_directory_is", arguments.array[1].string, "identify", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + return; + } + + if (status_file == F_false || status_file == F_file_found_not) { + existing = F_false; + } + } + for (f_array_length_t i = 0; i < total; i++) { + destination_length = arguments.array[total].used; + + if (existing) { + destination_length += arguments.array[i].used + 1; + } + + char destination[destination_length + 1]; + + memcpy(destination, arguments.array[total].string, arguments.array[total].used); + + 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[destination_length] = 0; + status_file = f_directory_is(arguments.array[i].string); if (status_file == F_true) { - // @todo: *status = fl_directory_copy(); + status_file = fl_directory_copy(arguments.array[i].string, destination, arguments.array[i].used, destination_length, mode, recurse); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "fl_directory_copy", arguments.array[i].string, "copy", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + } } - else if (status_file == F_true) { - // @todo: *status = f_file_copy(); + else if (status_file == F_false) { + status_file = f_file_copy(arguments.array[i].string, destination, mode, recurse.size_block, recurse.exclusive); + + if (F_status_is_error(status_file)) { + fake_print_message_file(data, F_status_set_fine(status_file), "f_file_copy", arguments.array[i].string, "copy", F_false, F_true, data_make->print); + *status = F_status_set_error(F_failure); + } + else if (data.verbosity == fake_verbosity_verbose) { + printf("Copied '%s' to '%s'.%c", arguments.array[i].string, destination, f_string_eol[0]); + } } else if (F_status_is_error(status_file)) { - // @todo + fake_print_message_file(data, F_status_set_fine(status_file), "f_directory_is", arguments.array[i].string, "identify", F_false, F_true, data_make->print); *status = F_status_set_error(F_failure); break; } diff --git a/level_3/fake/c/private-make.h b/level_3/fake/c/private-make.h index 62247d1..1f69dd8 100644 --- a/level_3/fake/c/private-make.h +++ b/level_3/fake/c/private-make.h @@ -60,8 +60,8 @@ extern "C" { #endif // _di_fake_make_setting_t_ #ifndef _di_fake_make_operation_ - #define fake_make_operation_build "build" #define fake_make_operation_break "break" + #define fake_make_operation_build "build" #define fake_make_operation_clean "clean" #define fake_make_operation_clone "clone" #define fake_make_operation_compile "compile" @@ -92,7 +92,6 @@ extern "C" { #define fake_make_operation_top "top" #define fake_make_operation_touch "touch" - #define fake_make_operation_index_length 5 #define fake_make_operation_break_length 5 #define fake_make_operation_build_length 5 #define fake_make_operation_clean_length 5 @@ -108,6 +107,7 @@ extern "C" { #define fake_make_operation_group_length 5 #define fake_make_operation_groups_length 6 #define fake_make_operation_if_length 2 + #define fake_make_operation_index_length 5 #define fake_make_operation_link_length 4 #define fake_make_operation_mode_length 4 #define fake_make_operation_modes_length 5