From: Kevin Day Date: Sat, 31 Aug 2019 23:07:16 +0000 (-0500) Subject: Update: improve status code handling, remove unnecessary code, and update status... X-Git-Tag: 0.5.0~462 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=6ab684f6f3e7afcd1a2e8dea2cc639e14d6b6788;p=fll Update: improve status code handling, remove unnecessary code, and update status programs The fl_status_is_fine(), fl_status_is_warning(), and fl_status_is_error() functions are no longer needed or valid with the current design around using error and warning bits. The status conversion code should be more aware of digits. Get rid of the "context" parameter in the status programs. Redesign logic in the status programs to work with changes and function correctly (and consistently). The status programs will eventually need to perform more extensive tests on parameters when digits or non-digits are required. The current design only provides a very basic test on the first character of a given parameter. --- diff --git a/level_0/f_conversion/c/conversion.c b/level_0/f_conversion/c/conversion.c index ccbadbe..cd098dc 100644 --- a/level_0/f_conversion/c/conversion.c +++ b/level_0/f_conversion/c/conversion.c @@ -19,12 +19,12 @@ extern "C" { case '7': case '8': case '9': - return f_true; + break; default: return f_false; } - return f_unknown; + return f_true; } #endif // _di_f_is_digit_ @@ -54,10 +54,12 @@ extern "C" { case 'd': case 'e': case 'f': - return f_true; + break; default: return f_false; } + + return f_true; } #endif // _di_f_is_hexdigit_ @@ -68,16 +70,16 @@ extern "C" { #endif // _di_level_0_parameter_checking_ switch (character) { - case '0': *digit = 0; break; - case '1': *digit = 1; break; - case '2': *digit = 2; break; - case '3': *digit = 3; break; - case '4': *digit = 4; break; - case '5': *digit = 5; break; - case '6': *digit = 6; break; - case '7': *digit = 7; break; - case '8': *digit = 8; break; - case '9': *digit = 9; break; + case '0': *digit = 0; break; + case '1': *digit = 1; break; + case '2': *digit = 2; break; + case '3': *digit = 3; break; + case '4': *digit = 4; break; + case '5': *digit = 5; break; + case '6': *digit = 6; break; + case '7': *digit = 7; break; + case '8': *digit = 8; break; + case '9': *digit = 9; break; default: return f_no_data; } @@ -93,16 +95,16 @@ extern "C" { #endif // _di_level_0_parameter_checking_ switch (character) { - case '0': *digit = 0; break; - case '1': *digit = 1; break; - case '2': *digit = 2; break; - case '3': *digit = 3; break; - case '4': *digit = 4; break; - case '5': *digit = 5; break; - case '6': *digit = 6; break; - case '7': *digit = 7; break; - case '8': *digit = 8; break; - case '9': *digit = 9; break; + case '0': *digit = 0; break; + case '1': *digit = 1; break; + case '2': *digit = 2; break; + case '3': *digit = 3; break; + case '4': *digit = 4; break; + case '5': *digit = 5; break; + case '6': *digit = 6; break; + case '7': *digit = 7; break; + case '8': *digit = 8; break; + case '9': *digit = 9; break; case 'A': *digit = 10; break; case 'B': *digit = 11; break; case 'C': *digit = 12; break; diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index 3d71563..d7391fc 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -681,84 +681,6 @@ extern "C" { } #endif // _di_fl_status_to_string_ -#ifndef _di_fl_status_is_error_ - f_return_status fl_status_is_error(const f_status code) { - if (fl_status_is_fine(code) == f_true) { - return f_false; - } - else if (fl_status_is_warning(code) == f_true) { - return f_false; - } - - return f_true; - } -#endif // _di_fl_status_is_error_ - -#ifndef _di_fl_status_is_warning_ - f_return_status fl_status_is_warning(const f_status code) { - switch (code) { - #ifndef _di_fl_status_basic_ - case f_no_data: - return f_true; - #endif // _di_fl_status_basic_ - - #ifndef _di_f_status_buffers_ - case f_no_data_on_eof: - return f_true; - case f_no_data_on_eol: - 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_eol: - return f_true; - case f_none_on_eos: - return f_true; - case f_none_on_stop: - return f_true; - #endif // _di_f_status_buffers_ - } - - return f_false; - } -#endif // _di_fl_status_is_warning_ - -#ifndef _di_fl_status_is_fine_ - f_return_status fl_status_is_fine(const f_status code) { - switch (code) { - #ifndef _di_fl_status_booleans_ - case f_false: - return f_true; - case f_true: - return f_true; - #endif // _di_fl_status_booleans_ - - #ifndef _di_fl_status_basic_ - case f_none: - return f_true; - case f_dummy: - return f_true; - #endif // _di_fl_status_basic_ - - #ifndef _di_fl_status_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_status_non_ - } - - return f_false; - } -#endif // _di_fl_status_is_fine_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index 65894e1..1157554 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -701,30 +701,6 @@ extern "C" { extern f_return_status fl_status_to_string(const f_status code, f_string *string); #endif // _di_fl_status_to_string_ -#ifndef _di_fl_status_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 status 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_status_is_error(const f_status code); -#endif // _di_fl_status_is_error_ - -#ifndef _di_fl_status_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 status 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_status_is_warning(const f_status code); -#endif // _di_fl_status_is_warning_ - -#ifndef _di_fl_status_is_fine_ - /** - * 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 status codes are context-specific and may be reported as an "fine" here when it is in fact not fine. - */ - extern f_return_status fl_status_is_fine(const f_status code); -#endif // _di_fl_status_is_fine_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_status.c b/level_2/fll_fss/c/fss_status.c index ee6e5cc..f452f87 100644 --- a/level_2/fll_fss/c/fss_status.c +++ b/level_2/fll_fss/c/fss_status.c @@ -13,6 +13,19 @@ extern "C" { f_status status = f_none; f_string_length length = strlen(string); + if (length == 0) { + return f_no_data; + } + + // numbers are not valid status code strings. + if ((status = f_is_digit(string[0])) == f_true) { + return f_invalid_data; + } + + if (f_status_is_error(status)) { + return status; + } + #ifndef _di_fll_fss_status_error_ if (fl_compare_strings(string, fll_fss_status_string_invalid_format, length, fll_fss_status_string_invalid_format_length) == f_equal_to) { *error = fl_fss_invalid_format; diff --git a/level_2/fll_fss/c/fss_status.h b/level_2/fll_fss/c/fss_status.h index 0a9afa9..c0f9fa5 100644 --- a/level_2/fll_fss/c/fss_status.h +++ b/level_2/fll_fss/c/fss_status.h @@ -11,6 +11,7 @@ #define _FLL_fss_status_h // fll-0 includes +#include #include #include #include @@ -87,6 +88,7 @@ extern "C" { * * @return * f_none on success. + * f_no_data if string is empty. * f_invalid_data if not found. * f_invalid_parameter (with error bit) if a parameter is invalid. * diff --git a/level_2/fll_fss/data/build/dependencies b/level_2/fll_fss/data/build/dependencies index ae20d2e..3078a1e 100644 --- a/level_2/fll_fss/data/build/dependencies +++ b/level_2/fll_fss/data/build/dependencies @@ -2,6 +2,8 @@ f_types f_status f_strings f_memory +f_conversion +f_utf f_fss fl_fss fl_status diff --git a/level_2/fll_fss/data/build/settings b/level_2/fll_fss/data/build/settings index ca2a991..7710ded 100644 --- a/level_2/fll_fss/data/build/settings +++ b/level_2/fll_fss/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfl_status -lfl_strings -lfl_fss -lf_conversion -lf_file -lf_memory -lf_utf +build_libraries_fll -lfl_status -lfl_strings -lfl_fss -lf_conversion -lf_file -lf_memory -lf_conversion -lf_utf build_sources_library fss_basic.c fss_basic_list.c fss_extended.c fss_status.c build_sources_program build_sources_headers fss_basic.h fss_basic_list.h fss_extended.h fss_status.h diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index d62e6df..27d5db0 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -13,6 +13,19 @@ extern "C" { f_status status = f_none; f_string_length length = strlen(string); + if (length == 0) { + return f_no_data; + } + + // numbers are not valid status code strings. + if ((status = f_is_digit(string[0])) == f_true) { + return f_invalid_data; + } + + if (f_status_is_error(status)) { + return status; + } + #ifndef _di_fll_status_booleans_ if (fl_compare_strings(string, fl_status_string_false, length, fl_status_string_false_length) == f_equal_to) { *code = f_false; diff --git a/level_2/fll_status/c/status.h b/level_2/fll_status/c/status.h index ec8c2cf..da08e98 100644 --- a/level_2/fll_status/c/status.h +++ b/level_2/fll_status/c/status.h @@ -11,6 +11,7 @@ #define _FLL_errors_h // fll-0 includes +#include #include #include #include @@ -38,6 +39,7 @@ extern "C" { * * @return * f_none on success. + * f_no_data if string is empty. * f_invalid_data if not found. * f_invalid_parameter (with error bit) if a parameter is invalid. */ diff --git a/level_2/fll_status/data/build/dependencies b/level_2/fll_status/data/build/dependencies index f4f5594..72e702a 100644 --- a/level_2/fll_status/data/build/dependencies +++ b/level_2/fll_status/data/build/dependencies @@ -1,6 +1,7 @@ f_types f_status f_memory +f_conversion f_strings f_utf fl_strings diff --git a/level_2/fll_status/data/build/settings b/level_2/fll_status/data/build/settings index 72c5bc1..3bd362b 100644 --- a/level_2/fll_status/data/build/settings +++ b/level_2/fll_status/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfl_status -lfl_strings -lf_memory -lf_utf +build_libraries_fll -lfl_status -lfl_strings -lf_memory -lf_conversion -lf_utf build_sources_library status.c build_sources_program build_sources_headers status.h diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c index ff97402..a66a5eb 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -68,13 +68,6 @@ extern "C" { printf(" Returns true if the error code is an error."); printf("\n %s", f_console_symbol_short_enable); - fl_color_print(f_standard_output, data.context.standout, data.context.reset, fss_status_code_short_context); - - printf(", %s", f_console_symbol_long_enable); - fl_color_print(f_standard_output, data.context.standout, data.context.reset, fss_status_code_long_context); - printf(" Guess error state from context of error (ignores masks)."); - - printf("\n %s", f_console_symbol_short_enable); fl_color_print(f_standard_output, data.context.standout, data.context.reset, fss_status_code_short_number); printf(", %s", f_console_symbol_long_enable); @@ -162,99 +155,143 @@ extern "C" { f_array_length counter = 0; f_status code = f_none; + f_u_int true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } + + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } - if (data->parameters[fss_status_code_parameter_context].result == f_console_result_found) { - if (fll_fss_status_is_error(code)) { - fss_status_code_delete_data(data); - return f_true; - } + code = (f_status) number; + true = f_status_is_error(code) && !f_status_is_warning(code); + + if (status == f_none) { + status = f_true; + } + + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_error(code)) { - fss_status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - fss_status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[fss_status_code_parameter_is_warning].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; + f_u_int true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } + + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + + code = (f_status) number; + true = f_status_is_warning(code) && !f_status_is_error(code); + + if (status == f_none) { + status = f_true; + } - if (data->parameters[fss_status_code_parameter_context].result == f_console_result_found) { - if (fll_fss_status_is_warning(code)) { - fss_status_code_delete_data(data); - return f_true; - } + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_warning(code)) { - fss_status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - fss_status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[fss_status_code_parameter_is_fine].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; + f_u_int true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } - if (data->parameters[fss_status_code_parameter_context].result == f_console_result_found) { - if (fll_fss_status_is_fine(code)) { - fss_status_code_delete_data(data); - return f_true; - } + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + + code = (f_status) number; + true = f_status_is_fine(code); + + if (status == f_none) { + status = f_true; + } + + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_fine(code)) { - fss_status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - fss_status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[fss_status_code_parameter_number].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; + f_status status2 = f_none; for (; counter < data->remaining.used; counter++) { - status = fll_status_from_string(argv[data->remaining.array[counter]], &code); - - if (status == f_invalid_data) { - status = fll_fss_status_from_string(argv[data->remaining.array[counter]], &code); + // numbers are not valid status code strings. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_true) { + status = f_false; + continue; } - if (f_status_is_error(status)) { + status2 = fll_status_from_string(argv[data->remaining.array[counter]], &code); + + if (f_status_is_error(status2)) { + status = status2; break; } - else { - status = f_none; + else if (status2 == f_invalid_data) { + status = f_false; + continue; + } + else if (status == f_none) { + status = f_true; } printf("%u\n", code); @@ -263,9 +300,6 @@ extern "C" { else { status = f_false; } - - fss_status_code_delete_data(data); - return status; } else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = 0; @@ -276,14 +310,35 @@ extern "C" { if (data->remaining.used > 0) { for (; counter < data->remaining.used; counter++) { - f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status code. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } + + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + else if (status == f_none) { + status = f_true; + } + + f_status code = (f_status) number; f_string string = 0; if (fll_fss_status_to_string(code, &string) == f_none) { printf("%s\n", string); } + else { + status = f_false; + } } // for } + else { + status = f_false; + } } else { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); diff --git a/level_3/fss_status_code/c/fss_status_code.h b/level_3/fss_status_code/c/fss_status_code.h index d7f5cce..66bd293 100644 --- a/level_3/fss_status_code/c/fss_status_code.h +++ b/level_3/fss_status_code/c/fss_status_code.h @@ -15,6 +15,7 @@ #include // fll-0 includes +#include #include #include #include @@ -53,13 +54,11 @@ extern "C" { #define fss_status_code_short_is_fine "f" #define fss_status_code_short_is_warning "w" #define fss_status_code_short_is_error "e" - #define fss_status_code_short_context "c" #define fss_status_code_short_number "n" #define fss_status_code_long_is_fine "is_fine" #define fss_status_code_long_is_warning "is_warning" #define fss_status_code_long_is_error "is_error" - #define fss_status_code_long_context "context" #define fss_status_code_long_number "number" enum { @@ -71,7 +70,6 @@ extern "C" { fss_status_code_parameter_is_fine, fss_status_code_parameter_is_warning, fss_status_code_parameter_is_error, - fss_status_code_parameter_context, fss_status_code_parameter_number, }; @@ -84,7 +82,6 @@ extern "C" { f_console_parameter_initialize(fss_status_code_short_is_fine, fss_status_code_long_is_fine, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_status_code_short_is_warning, fss_status_code_long_is_warning, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_status_code_short_is_error, fss_status_code_long_is_error, 0, f_false, f_console_type_normal), \ - f_console_parameter_initialize(fss_status_code_short_context, fss_status_code_long_context, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(fss_status_code_short_number, fss_status_code_long_number, 0, f_false, f_console_type_normal), \ } diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c index 4080bb3..4bc2b82 100644 --- a/level_3/fss_status_code/c/main.c +++ b/level_3/fss_status_code/c/main.c @@ -7,7 +7,9 @@ int main(const f_array_length argc, const f_string argv[]) { data.process_pipe = f_true; } - if (f_status_is_error(fss_status_code_main(argc, argv, &data))) { + f_status status = fss_status_code_main(argc, argv, &data); + + if (f_status_is_error(status) || status == f_false) { return 1; } diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index b48a13a..76f3aee 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -7,7 +7,9 @@ int main(const f_array_length argc, const f_string argv[]) { data.process_pipe = f_true; } - if (f_status_is_error(status_code_main(argc, argv, &data))) { + f_status status = status_code_main(argc, argv, &data); + + if (f_status_is_error(status) || status == f_false) { return 1; } diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index f952165..982162c 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -68,13 +68,6 @@ extern "C" { printf(" Returns true if the error code is an error."); printf("\n %s", f_console_symbol_short_enable); - fl_color_print(f_standard_output, data.context.standout, data.context.reset, status_code_short_context); - - printf(", %s", f_console_symbol_long_enable); - fl_color_print(f_standard_output, data.context.standout, data.context.reset, status_code_long_context); - printf(" Guess error state from context of error (ignores masks)."); - - printf("\n %s", f_console_symbol_short_enable); fl_color_print(f_standard_output, data.context.standout, data.context.reset, status_code_short_number); printf(", %s", f_console_symbol_long_enable); @@ -160,92 +153,143 @@ extern "C" { else if (data->parameters[status_code_parameter_is_error].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; + f_status code = f_none; + f_u_short true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } - if (data->parameters[status_code_parameter_context].result == f_console_result_found) { - if (fl_status_is_error(code)) { - status_code_delete_data(data); - return f_true; - } + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + + code = (f_status) number; + true = f_status_is_error(code) && !f_status_is_warning(code); + + if (status == f_none) { + status = f_true; + } + + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_error(code)) { - status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[status_code_parameter_is_warning].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; + f_status code = f_none; + f_u_short true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } - if (data->parameters[status_code_parameter_context].result == f_console_result_found) { - if (fl_status_is_warning(code)) { - status_code_delete_data(data); - return f_true; - } + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + + code = (f_status) number; + true = f_status_is_warning(code) && !f_status_is_error(code); + + if (status == f_none) { + status = f_true; + } + + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_warning(code)) { - status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[status_code_parameter_is_fine].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; + f_status code = f_none; + f_u_short true = 0; for (; counter < data->remaining.used; counter++) { - code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status codes. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } + + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + + code = (f_status) number; + true = f_status_is_fine(code); + + if (status == f_none) { + status = f_true; + } - if (data->parameters[status_code_parameter_context].result == f_console_result_found) { - if (fl_status_is_fine(code)) { - status_code_delete_data(data); - return f_true; - } + if (true) { + printf("%s\n", fl_status_string_true); } else { - if (f_status_is_fine(code)) { - status_code_delete_data(data); - return f_true; - } + printf("%s\n", fl_status_string_false); } } // for } - - status_code_delete_data(data); - return f_false; + else { + status = f_false; + } } else if (data->parameters[status_code_parameter_number].result == f_console_result_found) { if (data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; + f_status status2 = f_none; for (; counter < data->remaining.used; counter++) { - status = fll_status_from_string(argv[data->remaining.array[counter]], &code); - if (f_status_is_error(status)) { + // numbers are not valid status code strings. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_true) { + status = f_false; + continue; + } + + status2 = fll_status_from_string(argv[data->remaining.array[counter]], &code); + if (f_status_is_error(status2)) { + status = status2; break; } - else { + else if (status2 == f_invalid_data) { + status = f_false; + continue; + } + else if (status == f_none) { status = f_true; } @@ -255,9 +299,6 @@ extern "C" { else { status = f_false; } - - status_code_delete_data(data); - return status; } else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = 0; @@ -268,14 +309,35 @@ extern "C" { if (data->remaining.used > 0) { for (; counter < data->remaining.used; counter++) { - f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); + // only numbers are valid status code. + if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) { + status = f_false; + continue; + } + + long long number = atoll(argv[data->remaining.array[counter]]); + if (number >= 0x10000 || number < 0) { + status = f_false; + continue; + } + else if (status == f_none) { + status = f_true; + } + + f_status code = (f_status) number; f_string string = 0; if (fl_status_to_string(code, &string) == f_none) { printf("%s\n", string); } + else { + status = f_false; + } } // for } + else { + status = f_false; + } } else { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); diff --git a/level_3/status_code/c/status_code.h b/level_3/status_code/c/status_code.h index d89f948..0a485db 100644 --- a/level_3/status_code/c/status_code.h +++ b/level_3/status_code/c/status_code.h @@ -14,6 +14,7 @@ // fll-0 includes #include +#include #include #include #include @@ -50,13 +51,11 @@ extern "C" { #define status_code_short_is_fine "f" #define status_code_short_is_warning "w" #define status_code_short_is_error "e" - #define status_code_short_context "c" #define status_code_short_number "n" #define status_code_long_is_fine "is_fine" #define status_code_long_is_warning "is_warning" #define status_code_long_is_error "is_error" - #define status_code_long_context "context" #define status_code_long_number "number" enum { @@ -68,7 +67,6 @@ extern "C" { status_code_parameter_is_fine, status_code_parameter_is_warning, status_code_parameter_is_error, - status_code_parameter_context, status_code_parameter_number, }; @@ -81,7 +79,6 @@ extern "C" { f_console_parameter_initialize(status_code_short_is_fine, status_code_long_is_fine, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(status_code_short_is_warning, status_code_long_is_warning, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(status_code_short_is_error, status_code_long_is_error, 0, f_false, f_console_type_normal), \ - f_console_parameter_initialize(status_code_short_context, status_code_long_context, 0, f_false, f_console_type_normal), \ f_console_parameter_initialize(status_code_short_number, status_code_long_number, 0, f_false, f_console_type_normal), \ } diff --git a/level_3/status_code/data/build/dependencies b/level_3/status_code/data/build/dependencies index f494110..16a54b7 100644 --- a/level_3/status_code/data/build/dependencies +++ b/level_3/status_code/data/build/dependencies @@ -1,4 +1,5 @@ f_console +f_conversion f_status f_pipe f_print