From 013bf6bfbcc428b0acd4f92a35615ec8a5582392 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 12 Dec 2021 10:05:34 -0600 Subject: [PATCH] Update: Handle more error messages for file types and cleanup organization a little. --- level_2/fll_error/c/error.c | 123 ++++++++++++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 33 deletions(-) diff --git a/level_2/fll_error/c/error.c b/level_2/fll_error/c/error.c index d78b0dd..e46e5d0 100644 --- a/level_2/fll_error/c/error.c +++ b/level_2/fll_error/c/error.c @@ -94,6 +94,20 @@ extern "C" { return F_false; } + if (status == F_failure) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); + + fl_print_format("%c%[%SFailed to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); + + funlockfile(print.to.stream); + } + + return F_false; + } + if (status == F_file_close) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); @@ -290,13 +304,13 @@ extern "C" { return F_false; } - if (status == F_read_only) { + if (status == F_file_seek) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); - fl_print_format("%c%[%SUnable to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%c%[%SSeek failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); - fl_print_format("%[', %S is read only.%]%c", print.to.stream, print.context, type_name, print.context, f_string_eol_s[0]); + fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); funlockfile(print.to.stream); } @@ -304,11 +318,11 @@ extern "C" { return F_false; } - if (status == F_file_seek) { + if (status == F_file_stat) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); - fl_print_format("%c%[%SSeek failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%c%[%SStat failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); @@ -318,11 +332,11 @@ extern "C" { return F_false; } - if (status == F_file_stat) { + if (status == F_file_synchronize) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); - fl_print_format("%c%[%SStat failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%c%[%SSynchronize failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); @@ -332,13 +346,13 @@ extern "C" { return F_false; } - if (status == F_file_synchronize) { + if (status == F_file_type_unknown) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); - fl_print_format("%c%[%SSynchronize failed while trying to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%c%[%SFailed to %S %S, the path '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); - fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); + fl_print_format("%[' is an unknown file type.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); funlockfile(print.to.stream); } @@ -402,20 +416,6 @@ extern "C" { return F_false; } - if (status == F_write_only) { - if (print.verbosity != f_console_verbosity_quiet) { - flockfile(print.to.stream); - - fl_print_format("%c%[%SUnable to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); - fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); - fl_print_format("%[', %S is write only.%]%c", print.to.stream, print.context, type_name, print.context, f_string_eol_s[0]); - - funlockfile(print.to.stream); - } - - return F_false; - } - if (status == F_loop) { if (print.verbosity != f_console_verbosity_quiet) { flockfile(print.to.stream); @@ -504,6 +504,34 @@ extern "C" { return F_false; } + if (status == F_read_only) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); + + fl_print_format("%c%[%SUnable to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%[', %S is read only.%]%c", print.to.stream, print.context, type_name, print.context, f_string_eol_s[0]); + + funlockfile(print.to.stream); + } + + return F_false; + } + + if (status == F_write_only) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); + + fl_print_format("%c%[%SUnable to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%[', %S is write only.%]%c", print.to.stream, print.context, type_name, print.context, f_string_eol_s[0]); + + funlockfile(print.to.stream); + } + + return F_false; + } + if (type == fll_error_file_type_file) { if (status == F_file_type_not_directory) { if (print.verbosity != f_console_verbosity_quiet) { @@ -518,20 +546,35 @@ extern "C" { return F_false; } - } - if (status == F_failure) { - if (print.verbosity != f_console_verbosity_quiet) { - flockfile(print.to.stream); + if (status == F_file_type_directory) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); - fl_print_format("%c%[%SFailed to %S %S '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); - fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); - fl_print_format("%['.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); + fl_print_format("%c%[%SFailed to %S %S, the path '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%[' is a directory.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); - funlockfile(print.to.stream); + funlockfile(print.to.stream); + } + + return F_false; } + } + else if (type == fll_error_file_type_directory) { + if (status == F_file_type_regular) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); - return F_false; + fl_print_format("%c%[%SFailed to %S %S, the path '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%[' is a file.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); + + funlockfile(print.to.stream); + } + + return F_false; + } } if (type == fll_error_file_type_file || type == fll_error_file_type_directory) { @@ -548,6 +591,20 @@ extern "C" { return F_false; } + + if (status == F_file_type_pipe || status == F_file_type_socket) { + if (print.verbosity != f_console_verbosity_quiet) { + flockfile(print.to.stream); + + fl_print_format("%c%[%SFailed to %S %S, the path '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix, operation, type_name, print.context); + fl_print_format("%[%S%]", print.to.stream, print.notable, name, print.notable); + fl_print_format("%[' is a %s.%]%c", print.to.stream, print.context, status == F_file_type_pipe ? "pipe" : "socket", print.context, f_string_eol_s[0]); + + funlockfile(print.to.stream); + } + + return F_false; + } } return private_fll_error_print(print, status, function, fallback); -- 1.8.3.1