From: Kevin Day Date: Sat, 26 Sep 2020 19:57:04 +0000 (-0500) Subject: Update: replace fake_print_message_file() with fll_error_file_print() and other minor... X-Git-Tag: 0.5.1~59 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=08545cce9a0650307135277889d12a457aa5a8d0;p=fll Update: replace fake_print_message_file() with fll_error_file_print() and other minor changes. The fake_print_message_file() function is no longer needed and should be replaced with fll_error_file_print(). --- diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 5c16a3b..41423eb 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -2309,7 +2309,7 @@ extern "C" { } if (operation == fake_make_operation_type_clone) { - const f_array_length_t total = arguments.used -1; + 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; @@ -2325,10 +2325,10 @@ extern "C" { // 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); + status_file = f_directory_is(arguments.array[1].string); if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[1].string, "identify", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[1].string, "identify", fll_error_file_type_directory); *status = F_status_set_error(F_failure); return; } @@ -2339,6 +2339,7 @@ extern "C" { } for (f_array_length_t i = 0; i < total; i++) { + destination_length = arguments.array[total].used; if (existing) { @@ -2362,7 +2363,7 @@ extern "C" { 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, data_make->error, F_status_set_fine(status_file), "fl_directory_clone", arguments.array[i].string, "clone", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "fl_directory_clone", F_true, arguments.array[i].string, "clone", fll_error_file_type_directory); *status = F_status_set_error(F_failure); } } @@ -2370,7 +2371,7 @@ extern "C" { 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, data_make->error, F_status_set_fine(status_file), "f_file_clone", arguments.array[i].string, "clone", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_file_clone", F_true, arguments.array[i].string, "clone", fll_error_file_type_file); *status = F_status_set_error(F_failure); } else if (data.error.verbosity == f_console_verbosity_verbose) { @@ -2382,7 +2383,7 @@ extern "C" { } } else if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[i].string, "identify", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[i].string, "identify", fll_error_file_type_directory); *status = F_status_set_error(F_failure); break; } @@ -2424,10 +2425,11 @@ extern "C" { // 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); + status_file = f_directory_is(arguments.array[1].string); if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[1].string, "identify", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[1].string, "identify", fll_error_file_type_directory); + *status = F_status_set_error(F_failure); return; } @@ -2461,7 +2463,7 @@ extern "C" { 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, data_make->error, F_status_set_fine(status_file), "fl_directory_copy", arguments.array[i].string, "copy", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "fl_directory_copy", F_true, arguments.array[i].string, "copy", fll_error_file_type_directory); *status = F_status_set_error(F_failure); } } @@ -2469,7 +2471,7 @@ extern "C" { 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, data_make->error, F_status_set_fine(status_file), "f_file_copy", arguments.array[i].string, "copy", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_file_copy", F_true, arguments.array[i].string, "copy", fll_error_file_type_file); *status = F_status_set_error(F_failure); } else if (data.error.verbosity == f_console_verbosity_verbose) { @@ -2481,7 +2483,7 @@ extern "C" { } } else if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[i].string, "identify", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[i].string, "identify", fll_error_file_type_directory); *status = F_status_set_error(F_failure); break; } @@ -3358,7 +3360,7 @@ extern "C" { // 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); + status_file = f_directory_is(arguments.array[1].string); if (F_status_is_error(status_file)) { fll_error_file_print(data_make->error, F_status_set_fine(*status), "f_directory_is", F_true, arguments.array[1].string, "identify", fll_error_file_type_directory); @@ -3373,6 +3375,7 @@ extern "C" { } for (f_array_length_t i = 0; i < total; i++) { + destination_length = arguments.array[total].used; if (existing) { @@ -4110,6 +4113,7 @@ extern "C" { } // for if (arguments.used > 2) { + // the last file must be a directory. f_status_t status_file = f_directory_is(arguments.array[arguments.used - 1].string); @@ -4124,11 +4128,12 @@ extern "C" { *status = F_status_set_error(F_failure); } else if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[arguments.used - 1].string, "find", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[arguments.used - 1].string, "find", fll_error_file_type_directory); *status = F_status_set_error(F_failure); } } else { + // when the first file is a directory, then the second, if it exists, must also be a directory. f_status_t status_file = f_directory_is(arguments.array[0].string); @@ -4139,7 +4144,7 @@ extern "C" { if (data.error.verbosity != f_console_verbosity_quiet && data_make->error.to.stream) { fprintf(data_make->error.to.stream, "%c", f_string_eol[0]); fl_color_print(data_make->error.to.stream, data_make->error.context, "%sThe last file '", data_make->error.prefix); - fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[arguments.used - 1].string); + fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[1].string); fl_color_print(data_make->error.to.stream, data_make->error.context, "' must be a valid directory.%c", f_string_eol[0]); } @@ -4213,6 +4218,7 @@ extern "C" { } // for if (arguments.used > 2) { + // the last file must be a directory. f_status_t status_file = f_directory_is(arguments.array[arguments.used - 1].string); @@ -4227,11 +4233,12 @@ extern "C" { *status = F_status_set_error(F_failure); } else if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[arguments.used - 1].string, "find", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[arguments.used - 1].string, "identify", fll_error_file_type_directory); *status = F_status_set_error(F_failure); } } else { + // when the first file is a directory, then the second, if it exists, must also be a directory. f_status_t status_file = f_directory_is(arguments.array[0].string); @@ -4242,7 +4249,7 @@ extern "C" { if (data.error.verbosity != f_console_verbosity_quiet && data_make->error.to.stream) { fprintf(data_make->error.to.stream, "%c", f_string_eol[0]); fl_color_print(data_make->error.to.stream, data_make->error.context, "%sThe last file '", data_make->error.prefix); - fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[arguments.used - 1].string); + fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[1].string); fl_color_print(data_make->error.to.stream, data_make->error.context, "' must be a valid directory.%c", f_string_eol[0]); } @@ -4446,6 +4453,7 @@ extern "C" { f_status_t status_file = F_none; for (f_array_length_t i = 1; i < arguments.used; i++) { + status_file = f_file_is(arguments.array[i].string, f_file_type_regular, F_false); if (status_file == F_file_found_not) { @@ -4460,7 +4468,7 @@ extern "C" { } else if (F_status_is_error(status_file)) { if (data.error.verbosity != f_console_verbosity_quiet && data_make->error.to.stream) { - fake_print_message_file(data, data_make->error, *status, "f_file_is", arguments.array[i].string, "find", F_true, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(*status), "f_file_is", F_true, arguments.array[i].string, "find", fll_error_file_type_directory); } *status = status_file; @@ -4931,6 +4939,7 @@ extern "C" { } // for if (arguments.used > 2) { + // the last file must be a directory. f_status_t status_file = f_directory_is(arguments.array[arguments.used - 1].string); @@ -4945,11 +4954,12 @@ extern "C" { *status = F_status_set_error(F_failure); } else if (F_status_is_error(status_file)) { - fake_print_message_file(data, data_make->error, F_status_set_fine(status_file), "f_directory_is", arguments.array[arguments.used - 1].string, "find", F_false, F_true); + fll_error_file_print(data_make->error, F_status_set_fine(status_file), "f_directory_is", F_true, arguments.array[arguments.used - 1].string, "identify", fll_error_file_type_directory); *status = F_status_set_error(F_failure); } } else { + // when the first file is a directory, then the second, if it exists, must also be a directory. f_status_t status_file = f_directory_is(arguments.array[0].string); @@ -4960,7 +4970,7 @@ extern "C" { if (data.error.verbosity != f_console_verbosity_quiet && data_make->error.to.stream) { fprintf(data_make->error.to.stream, "%c", f_string_eol[0]); fl_color_print(data_make->error.to.stream, data_make->error.context, "%sThe last file '", data_make->error.prefix); - fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[arguments.used - 1].string); + fl_color_print(data_make->error.to.stream, data_make->error.notable, "%s", arguments.array[1].string); fl_color_print(data_make->error.to.stream, data_make->error.context, "' must be a valid directory.%c", f_string_eol[0]); } diff --git a/level_3/fake/c/private-print.c b/level_3/fake/c/private-print.c index a78386d..c70121a 100644 --- a/level_3/fake/c/private-print.c +++ b/level_3/fake/c/private-print.c @@ -298,204 +298,6 @@ extern "C" { } #endif // _di_fake_print_error_parameter_too_many_ -#ifndef _di_fake_print_message_file_ - bool fake_print_message_file(const fake_data_t data, const fll_error_print_t error, const f_status_t status, const f_string_t function, const f_string_t name, const f_string_t operation, const bool is_file, const bool fallback) { - const f_string_t file_or_directory = is_file ? "file" : "directory"; - - if (status == F_file_found_not) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Failed to find %s '", data.error.prefix, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_file_found) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: The %s '", data.error.prefix, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "' already exists.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_directory_empty_not) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: The %s '", data.error.prefix, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "' is not empty.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_parameter) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "INTERNAL %s: Invalid parameter when calling ", data.error.prefix); - fl_color_print(error.to.stream, data.context.set.notable, "%s", function); - fl_color_print(error.to.stream, data.error.context, "() for the %s '", file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_name) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Invalid %s name '", data.error.prefix, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_memory_out) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "CRITICAL %s: Unable to allocate memory, while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_number_overflow) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Overflow while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_directory) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Invalid directory while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_access_denied) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Access denied while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_loop) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Loop while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_prohibited) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Prohibited by system while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_access_owner) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Currrent user is not allowed to use the given owner while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_access_group) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Currrent user is not allowed to use the given group while trying to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - - if (is_file) { - if (status == F_directory_found_not) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Failed to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "' due to an invalid directory in the path.%c", f_string_eol[0]); - } - - return F_false; - } - } - else { - if (status == F_directory_found_not) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Failed to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "' due to an invalid directory in the path.%c", f_string_eol[0]); - } - - return F_false; - } - - if (status == F_failure) { - if (data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "%s: Failed to %s %s '", data.error.prefix, operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_false; - } - } - - if (fll_error_print(data.error, status, function, F_false) == F_unknown && fallback && data.error.verbosity != f_console_verbosity_quiet) { - fprintf(error.to.stream, "%c", f_string_eol[0]); - fl_color_print(error.to.stream, data.error.context, "UNKNOWN %s: (", data.error.prefix); - fl_color_print(error.to.stream, data.context.set.notable, "%llu", status); - fl_color_print(error.to.stream, data.error.context, ") occurred while trying to %s %s '", operation, file_or_directory); - fl_color_print(error.to.stream, data.context.set.notable, "%s", name); - fl_color_print(error.to.stream, data.error.context, "'.%c", f_string_eol[0]); - } - - return F_true; - } -#endif // _di_fake_print_message_file_ - #ifndef _di_fake_print_message_section_operation_failed_ void fake_print_message_section_operation_failed(const fake_data_t data, const fll_error_print_t error, const f_string_static_t buffer, const f_string_range_t section_name, const f_string_range_t operation_name) { if (data.error.verbosity == f_console_verbosity_quiet || !error.to.stream) return; diff --git a/level_3/fake/c/private-print.h b/level_3/fake/c/private-print.h index b8aef1e..aea88d2 100644 --- a/level_3/fake/c/private-print.h +++ b/level_3/fake/c/private-print.h @@ -93,36 +93,6 @@ extern "C" { #endif // _di_fake_print_error_parameter_too_many_ /** - * Print file/directory error/warning messages. - * - * @todo the fll_file_error_print() needs to be reviewed and possibly changed. - * - * @param data - * The program data. - * @param error - * Designates how the section error/warning should be printed. - * @param status - * The error status code to report on. - * @param function - * The function call that returned the error. - * @param name - * The name of the file or directory. - * @param operation - * The operation that fails, such as 'create' or 'access'. - * @param is_file - * Set to TRUE if this is a file and FALSE if this is a directory. - * @param fallback - * Set to F_true to print the fallback error message for unknown errors. - * - * @return - * F_true is returned if the status code has no print message. - * F_false is returned on successful print of known errors. - */ -#ifndef _di_fake_print_message_file_ - extern bool fake_print_message_file(const fake_data_t data, const fll_error_print_t error, const f_status_t status, const f_string_t function, const f_string_t name, const f_string_t operation, const bool is_file, const bool fallback) f_gcc_attribute_visibility_internal; -#endif // _di_fake_print_message_file_ - -/** * Print error messages when processing some fakefile section, for a specific line and operation, and that operation failed. * * @param data