From 0249adb9fc22941be96f441195c16eff22f9781b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 12 Mar 2012 11:48:49 -0500 Subject: [PATCH] Update: add support for identifying errors, warnings, and okays Add three new parameters: is_okay, is_warning, and is_error. These should test to see if the error code is in fact an error, a warning, or not an error. --- level_1/fl_errors/c/errors.c | 84 ++++++++++++++++++++++++++++++- level_1/fl_errors/c/errors.h | 19 +++++++ level_1/fl_fss/c/fss_errors.h | 1 - level_2/fll_fss/c/fss_errors.c | 80 ++++++++++++++++++++++++++++- level_2/fll_fss/c/fss_errors.h | 19 +++++++ level_3/error_code/c/error_code.c | 77 ++++++++++++++++++++++++++++ level_3/error_code/c/error_code.h | 17 ++++++- level_3/fss_error_code/c/fss_error_code.c | 77 ++++++++++++++++++++++++++++ level_3/fss_error_code/c/fss_error_code.h | 17 ++++++- 9 files changed, 385 insertions(+), 6 deletions(-) diff --git a/level_1/fl_errors/c/errors.c b/level_1/fl_errors/c/errors.c index 8d8b3e6..6788532 100644 --- a/level_1/fl_errors/c/errors.c +++ b/level_1/fl_errors/c/errors.c @@ -14,8 +14,7 @@ extern "C"{ #endif #ifndef _di_fl_errors_to_string_ - // Convert error codes to their string equivalents. - f_return_status fl_errors_to_string(const f_status error, f_string *string){ + f_return_status fl_errors_to_string(const f_status error, f_string *string) { #ifndef _di_level_1_parameter_checking_ if (string == f_null) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ @@ -295,6 +294,87 @@ extern "C"{ } #endif // _di_fl_errors_to_string_ +#ifndef _di_fl_errors_is_error_ + f_return_status fl_errors_is_error(const f_status error) { + if (fl_errors_is_okay(error) == f_true) { + return f_false; + } else if (fl_errors_is_warning(error) == f_true) { + return f_false; + } + + return f_true; + } +#endif // _di_fl_errors_is_error_ + +#ifndef _di_fl_errors_is_warning_ + f_return_status fl_errors_is_warning(const f_status error) { + switch(error){ + #ifndef _di_fl_errors_basic_ + case f_no_data: + return f_true; + #endif // _di_fl_errors_basic_ + + #ifndef _di_f_errors_buffers_ + case f_no_data_on_eof: + return f_true; + case f_no_data_on_eos: + return f_true; + case f_no_data_on_stop: + return f_true; + case f_none_on_eof: + return f_true; + case f_none_on_eos: + return f_true; + case f_none_on_stop: + return f_true; + #endif // _di_f_errors_buffers_ + + default: + return f_false; + } + + return f_unknown; + } +#endif // _di_fl_errors_is_warning_ + +#ifndef _di_fl_errors_is_okay_ + // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. + // Keep in mind that many of the error codes are context-specific and may be reported as an "okay" here when it is in fact not okay. + f_return_status fl_errors_is_okay(const f_status error) { + switch(error){ + #ifndef _di_fl_errors_booleans_ + case f_false: + return f_true; + case f_true: + return f_true; + #endif // _di_fl_errors_booleans_ + + #ifndef _di_fl_errors_basic_ + case f_none: + return f_true; + case f_dummy: + return f_true; + #endif // _di_fl_errors_basic_ + + #ifndef _di_fll_error_non_ + case f_less_than: + return f_true; + case f_equal_to: + return f_true; + case f_not_equal_to: + return f_true; + case f_greater_than: + return f_true; + #endif // _di_fl_errors_non_ + + default: + return f_false; + } + + return f_unknown; + } +#endif // _di_fl_errors_is_okay_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_errors/c/errors.h b/level_1/fl_errors/c/errors.h index 429ac4b..96d527e 100644 --- a/level_1/fl_errors/c/errors.h +++ b/level_1/fl_errors/c/errors.h @@ -23,6 +23,25 @@ extern "C"{ extern f_return_status fl_errors_to_string(const f_status error, f_string *string); #endif // _di_fl_errors_to_string_ +#ifndef _di_fl_errors_is_error_ + // Returns true or false depending on whether the standard context of the error code represents an error. + // Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + extern f_return_status fl_errors_is_error(const f_status error); +#endif // _di_fl_errors_is_error_ + +#ifndef _di_fl_errors_is_warning_ + // Returns true or false depending on whether the standard context of the error code represents a warning. + // Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + extern f_return_status fl_errors_is_warning(const f_status error); +#endif // _di_fl_errors_is_warning_ + + +#ifndef _di_fl_errors_is_okay_ + // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. + // Keep in mind that many of the error codes are context-specific and may be reported as an "okay" here when it is in fact not okay. + extern f_return_status fl_errors_is_okay(const f_status error); +#endif // _di_fl_errors_is_okay_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/c/fss_errors.h b/level_1/fl_fss/c/fss_errors.h index 8d10a43..1165d8b 100644 --- a/level_1/fl_fss/c/fss_errors.h +++ b/level_1/fl_fss/c/fss_errors.h @@ -47,7 +47,6 @@ enum { #endif // _di_fl_fss_errors_success_ }; // enum - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_errors.c b/level_2/fll_fss/c/fss_errors.c index 4ac8e25..80b18df 100644 --- a/level_2/fll_fss/c/fss_errors.c +++ b/level_2/fll_fss/c/fss_errors.c @@ -11,7 +11,6 @@ extern "C"{ #endif #ifndef _di_fll_fss_errors_to_string_ - // Convert error codes to their string equivalents. f_return_status fll_fss_errors_to_string(const f_status error, f_string *string) { #ifndef _di_level_2_parameter_checking_ if (string == f_null) return f_invalid_parameter; @@ -67,6 +66,85 @@ extern "C"{ } #endif // _di_fll_errors_to_string_ +#ifndef _di_fll_fss_errors_is_error_ + f_return_status fll_fss_errors_is_error(const f_status error) { + if (fll_fss_errors_is_okay(error) == f_true) { + return f_false; + } else if (fll_fss_errors_is_warning(error) == f_true) { + return f_false; + } + + return f_true; + } +#endif // _di_fll_fss_errors_is_error_ + +#ifndef _di_fll_fss_errors_is_warning_ + f_return_status fll_fss_errors_is_warning(const f_status error) { + switch(error){ + #ifndef _di_fll_fss_errors_basic_ + case f_no_data: + return f_true; + #endif // _di_fll_fss_errors_basic_ + + #ifndef _di_f_errors_buffers_ + case f_no_data_on_eof: + return f_true; + case f_no_data_on_eos: + return f_true; + case f_no_data_on_stop: + return f_true; + case f_none_on_eof: + return f_true; + case f_none_on_eos: + return f_true; + case f_none_on_stop: + return f_true; + #endif // _di_f_errors_buffers_ + + default: + return f_false; + } + + return f_unknown; + } +#endif // _di_fll_fss_errors_is_warning_ + +#ifndef _di_fll_fss_errors_is_okay_ + f_return_status fll_fss_errors_is_okay(const f_status error) { + switch(error){ + #ifndef _di_fll_fss_errors_booleans_ + case f_false: + return f_true; + case f_true: + return f_true; + #endif // _di_fll_fss_errors_booleans_ + + #ifndef _di_fll_fss_errors_basic_ + case f_none: + return f_true; + case f_dummy: + return f_true; + #endif // _di_fll_fss_errors_basic_ + + #ifndef _di_fll_error_non_ + case f_less_than: + return f_true; + case f_equal_to: + return f_true; + case f_not_equal_to: + return f_true; + case f_greater_than: + return f_true; + #endif // _di_fll_fss_errors_non_ + + default: + return f_false; + } + + return f_unknown; + } +#endif // _di_fll_fss_errors_is_okay_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_errors.h b/level_2/fll_fss/c/fss_errors.h index adc4f7a..89bec53 100644 --- a/level_2/fll_fss/c/fss_errors.h +++ b/level_2/fll_fss/c/fss_errors.h @@ -33,6 +33,25 @@ extern "C"{ extern f_return_status fll_fss_errors_to_string(const f_status error, f_string *string); #endif // _di_fll_errors_to_string_ +#ifndef _di_fll_fss_errors_is_error_ + // Returns true or false depending on whether the standard context of the error code represents an error. + // Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + extern f_return_status fll_fss_errors_is_error(const f_status error); +#endif // _di_fll_fss_errors_is_error_ + +#ifndef _di_fll_fss_errors_is_warning_ + // Returns true or false depending on whether the standard context of the error code represents a warning. + // Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + extern f_return_status fll_fss_errors_is_warning(const f_status error); +#endif // _di_fll_fss_errors_is_warning_ + + +#ifndef _di_fll_fss_errors_is_okay_ + // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. + // Keep in mind that many of the error codes are context-specific and may be reported as "okay" here when it is in fact not okay. + extern f_return_status fll_fss_errors_is_okay(const f_status error); +#endif // _di_fll_fss_errors_is_okay_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/error_code/c/error_code.c b/level_3/error_code/c/error_code.c index 7345cbb..2ad6ad7 100644 --- a/level_3/error_code/c/error_code.c +++ b/level_3/error_code/c/error_code.c @@ -59,6 +59,29 @@ extern "C"{ fl_print_color(f_standard_output, data.context.standout, data.context.reset, f_console_standard_long_version); printf(" Print only the version number"); + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_short_is_okay); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_long_is_okay); + printf(" Returns true if the error code is not an error."); + + + printf("\n"); + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_short_is_warning); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_long_is_warning); + printf(" Returns true if the error code is a warning."); + + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_short_is_error); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, error_code_long_is_error); + printf(" Returns true if the error code is an error."); + printf("\n\n"); fl_print_color(f_standard_output, data.context.important, data.context.reset, " Usage: "); @@ -128,6 +151,60 @@ extern "C"{ error_code_print_help(*data); } else if (data->parameters[error_code_parameter_version].result == f_console_result_found){ error_code_print_version(*data); + } else if (data->parameters[error_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fl_errors_is_error(code)){ + error_code_delete_data(data); + return f_true; + } + } + + error_code_delete_data(data); + return f_false; + } else if (data->parameters[error_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fl_errors_is_warning(code)){ + error_code_delete_data(data); + return f_true; + } + } + + error_code_delete_data(data); + return f_false; + } else if (data->parameters[error_code_parameter_is_okay].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fl_errors_is_okay(code)){ + error_code_delete_data(data); + return f_true; + } + } + + error_code_delete_data(data); + return f_false; } else if (data->remaining.used > 0 || data->process_pipe){ f_array_length counter = f_array_length_initialize; diff --git a/level_3/error_code/c/error_code.h b/level_3/error_code/c/error_code.h index 454f983..09f979f 100644 --- a/level_3/error_code/c/error_code.h +++ b/level_3/error_code/c/error_code.h @@ -47,11 +47,23 @@ extern "C"{ #endif // _di_error_code_name_ #ifndef _di_error_code_defines_ + #define error_code_short_is_okay "o" + #define error_code_short_is_warning "w" + #define error_code_short_is_error "e" + + #define error_code_long_is_okay "is_okay" + #define error_code_long_is_warning "is_warning" + #define error_code_long_is_error "is_error" + enum { error_code_parameter_help, error_code_parameter_light, error_code_parameter_no_color, error_code_parameter_version, + + error_code_parameter_is_okay, + error_code_parameter_is_warning, + error_code_parameter_is_error, }; #define f_console_parameter_initialize_error_code \ @@ -60,9 +72,12 @@ extern "C"{ f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(error_code_short_is_okay, error_code_long_is_okay, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(error_code_short_is_warning, error_code_long_is_warning, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(error_code_short_is_error, error_code_long_is_error, 0, 0, f_false, f_console_type_normal, 0), \ } - #define error_code_total_parameters 4 + #define error_code_total_parameters 7 #endif // _di_error_code_defines_ #ifndef _di_error_code_data_ diff --git a/level_3/fss_error_code/c/fss_error_code.c b/level_3/fss_error_code/c/fss_error_code.c index f8b5d0a..4c3bb9a 100644 --- a/level_3/fss_error_code/c/fss_error_code.c +++ b/level_3/fss_error_code/c/fss_error_code.c @@ -60,6 +60,29 @@ extern "C"{ printf(" Print only the version number"); + printf("\n"); + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_short_is_okay); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_long_is_okay); + printf(" Returns true if the error code is not an error."); + + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_short_is_warning); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_long_is_warning); + printf(" Returns true if the error code is a warning."); + + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_short_is_error); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_error_code_long_is_error); + printf(" Returns true if the error code is an error."); + + printf("\n\n"); fl_print_color(f_standard_output, data.context.important, data.context.reset, " Usage: "); @@ -128,6 +151,60 @@ extern "C"{ fss_error_code_print_help(*data); } else if (data->parameters[fss_error_code_parameter_version].result == f_console_result_found){ fss_error_code_print_version(*data); + } else if (data->parameters[fss_error_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fll_fss_errors_is_error(code)){ + fss_error_code_delete_data(data); + return f_true; + } + } + + fss_error_code_delete_data(data); + return f_false; + } else if (data->parameters[fss_error_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fll_fss_errors_is_warning(code)){ + fss_error_code_delete_data(data); + return f_true; + } + } + + fss_error_code_delete_data(data); + return f_false; + } else if (data->parameters[fss_error_code_parameter_is_okay].result == f_console_result_found && data->remaining.used > 0){ + f_array_length counter = f_array_length_initialize; + + f_status code = f_status_initialize; + + status = f_false; + + for (; counter < data->remaining.used; counter++){ + code = (f_status) atoll(argv[data->remaining.array[counter]]); + + if (fll_fss_errors_is_okay(code)){ + fss_error_code_delete_data(data); + return f_true; + } + } + + fss_error_code_delete_data(data); + return f_false; } else if (data->remaining.used > 0 || data->process_pipe){ f_array_length counter = f_array_length_initialize; diff --git a/level_3/fss_error_code/c/fss_error_code.h b/level_3/fss_error_code/c/fss_error_code.h index 5ab002f..8d73dff 100644 --- a/level_3/fss_error_code/c/fss_error_code.h +++ b/level_3/fss_error_code/c/fss_error_code.h @@ -48,11 +48,23 @@ extern "C"{ #endif // _di_fss_error_code_name_ #ifndef _di_fss_error_code_defines_ + #define fss_error_code_short_is_okay "o" + #define fss_error_code_short_is_warning "w" + #define fss_error_code_short_is_error "e" + + #define fss_error_code_long_is_okay "is_okay" + #define fss_error_code_long_is_warning "is_warning" + #define fss_error_code_long_is_error "is_error" + enum { fss_error_code_parameter_help, fss_error_code_parameter_light, fss_error_code_parameter_no_color, fss_error_code_parameter_version, + + fss_error_code_parameter_is_okay, + fss_error_code_parameter_is_warning, + fss_error_code_parameter_is_error, }; #define f_console_parameter_initialize_fss_error_code \ @@ -61,9 +73,12 @@ extern "C"{ f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(fss_error_code_short_is_okay, fss_error_code_long_is_okay, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(fss_error_code_short_is_warning, fss_error_code_long_is_warning, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(fss_error_code_short_is_error, fss_error_code_long_is_error, 0, 0, f_false, f_console_type_normal, 0), \ } - #define fss_error_code_total_parameters 4 + #define fss_error_code_total_parameters 7 #endif // _di_fss_error_code_defines_ #ifndef _di_fss_error_code_data_ -- 1.8.3.1