From a04dbccf15c15ccfb93f3e02028e170e70ffe64f Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 19 Nov 2019 19:00:00 -0600 Subject: [PATCH] Update: rewrite status code functions and related changes Fix several problems with the status code processing, namely missing or incomplete data. Add status code max size defines. Add missing "#ifndef _di_f_status_codes_" to status codes. Update cases where 'error' was not renamed to 'code' in status code sources. Add missing status codes. Fix incorrect define, "#ifdef _di_fl_status_invalid_" should instead be "#ifndef _di_fl_status_invalid_". Fix incorrect sizes associated with status code output strings. Prepare pipe support (not yet implemented). Ensure f_utf is included and linked in all appriopriate dependencies. Treat f_utf as a core level_0 project and update documentation accodingly. Relocate fl_console_parameter_process() into f_console_parameter_process(). --- build/documents/readme | 5 +- level_0/f_console/c/console.c | 328 +++++++++++++ level_0/f_console/c/console.h | 74 +++ level_0/f_console/data/build/dependencies | 1 + level_0/f_console/data/build/settings | 6 +- level_0/f_status/c/status.h | 509 +++++++++++---------- level_0/f_string/data/build/settings | 2 +- level_0/f_type/c/type.h | 8 +- level_1/fl_console/c/console.c | 328 ------------- level_1/fl_console/c/console.h | 73 --- level_1/fl_status/c/status.c | 30 +- level_1/fl_status/c/status.h | 13 +- level_1/fl_string/c/string.c | 410 ++++++++--------- level_1/fl_string/c/string.h | 234 +++++----- level_2/fll_fss/c/fss_status.c | 54 +-- level_2/fll_fss/c/fss_status.h | 42 +- level_2/fll_program/c/program.c | 10 +- level_2/fll_program/c/program.h | 1 - level_2/fll_program/data/build/dependencies | 1 - level_2/fll_program/data/build/settings | 2 +- level_2/fll_status/c/status.c | 15 + level_3/byte_dump/c/byte_dump.c | 5 +- level_3/firewall/c/firewall.c | 1 - .../fss_basic_list_read/c/fss_basic_list_read.c | 1 - level_3/fss_basic_list_read/data/build/settings | 2 +- .../fss_basic_list_write/c/fss_basic_list_write.c | 1 - level_3/fss_basic_list_write/data/build/settings | 2 +- level_3/fss_basic_read/c/fss_basic_read.c | 1 - level_3/fss_basic_read/data/build/settings | 2 +- level_3/fss_basic_write/c/fss_basic_write.c | 1 - level_3/fss_basic_write/data/build/settings | 2 +- .../c/fss_extended_list_read.c | 1 - level_3/fss_extended_list_read/data/build/settings | 2 +- level_3/fss_extended_read/c/fss_extended_read.c | 1 - level_3/fss_extended_read/data/build/settings | 2 +- level_3/fss_extended_write/c/fss_extended_write.c | 7 +- level_3/fss_extended_write/c/fss_extended_write.h | 1 - level_3/fss_extended_write/data/build/dependencies | 1 - level_3/fss_extended_write/data/build/settings | 2 +- level_3/fss_status_code/c/fss_status_code.c | 227 +++------ level_3/fss_status_code/c/fss_status_code.h | 1 + .../fss_status_code/c/private-fss_status_code.c | 159 +++++++ .../fss_status_code/c/private-fss_status_code.h | 102 +++++ level_3/fss_status_code/data/build/settings | 2 +- level_3/status_code/c/private-status_code.c | 153 +++++++ level_3/status_code/c/private-status_code.h | 102 +++++ level_3/status_code/c/status_code.c | 226 +++------ level_3/status_code/c/status_code.h | 11 +- level_3/status_code/data/build/settings | 2 +- 49 files changed, 1765 insertions(+), 1401 deletions(-) create mode 100644 level_3/fss_status_code/c/private-fss_status_code.c create mode 100644 level_3/fss_status_code/c/private-fss_status_code.h create mode 100644 level_3/status_code/c/private-status_code.c create mode 100644 level_3/status_code/c/private-status_code.h diff --git a/build/documents/readme b/build/documents/readme index 4fd8f71..f1158f1 100644 --- a/build/documents/readme +++ b/build/documents/readme @@ -51,8 +51,9 @@ These level_0 projects are: - f_status: provides status codes and other status codes to be used by the entire set of FLL projects. - f_memory: provides common memory allocation/deallocation to be used by the entire set of FLL projects. - f_string: provides common string management to be used by the entire set of the FLL projects. +- f_utf: provides common UTF-8 related string management to be used by the entire set of the FLL projects. -The above projects should be installed first, and in the provided order (f_type, then f_status, then f_memory, and finally f_string). -No other level_0 project should depend on another and can be installed in any order (future designs may add f_utf to this list). +The above projects should be installed first, and in the provided order (f_type, then f_status, then f_memory, f_string, and finally f_utf). +No other level_0 project should depend on another and can be installed in any order. See: data/build/dependencies for specific dependencies of this project. diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index dbfcd29..48b763a 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -47,6 +47,334 @@ extern "C" { } #endif // _di_f_console_identify_ +#ifndef _di_f_console_parameter_process_ + f_return_status f_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining) { + #ifndef _di_level_0_parameter_checking_ + if (remaining == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_0_parameter_checking_ + + f_status status = f_none; + f_console_id result = 0; + bool found = f_false; + + unsigned long location = 1; // Parameter 0 represents the program name so skip it. + f_string_length sub_location = 0; + f_string_length increment_by = 0; + f_string_length string_length = 0; + f_array_length parameter_counter = 0; + + unsigned short console_short = f_console_none; + unsigned short console_long = f_console_none; + unsigned short console_type = f_console_type_normal; + + f_string_lengths needs_additional = f_string_lengths_initialize; + + unsigned short width = 0; + + // loop through and read all parameters. + while (location < arguments.argc) { + f_console_identify(arguments.argv[location], &result); + + string_length = strnlen(arguments.argv[location], f_console_max_size); + + // process the current parameter. + if (result == f_console_short_enable || result == f_console_short_disable) { + increment_by = 1; + sub_location = 1; + } + else if (result == f_console_long_enable || result == f_console_long_disable) { + increment_by = string_length; + sub_location = 2; + } + else { + increment_by = string_length; + sub_location = 0; + } + + // Handle the normal commands. + if (result == f_console_short_enable || result == f_console_long_enable) { + console_short = f_console_short_enable; + console_long = f_console_long_enable; + console_type = f_console_type_normal; + } + else if (result == f_console_short_disable || result == f_console_long_disable) { + console_short = f_console_short_disable; + console_long = f_console_long_disable; + console_type = f_console_type_inverse; + } + else { + console_short = f_console_none; + } + + // Additional parameters must always follow what requests them. + if (needs_additional.used > 0) { + parameter_counter = needs_additional.array[0]; + + if (parameters.parameter[parameter_counter].additional.used >= parameters.parameter[parameter_counter].additional.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].additional, parameters.parameter[parameter_counter].additional.size + f_console_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + parameters.parameter[parameter_counter].result = f_console_result_additional; + parameters.parameter[parameter_counter].additional.array[parameters.parameter[parameter_counter].additional.used] = location; + parameters.parameter[parameter_counter].additional.used++; + + needs_additional.used--; + + // Pop the matched parameter off of the top of the needs_additional array. + for (f_string_length i = 0; i < needs_additional.used; i++) { + needs_additional.array[i] = needs_additional.array[i + 1]; + } // for + } + else if (console_short != f_console_none) { + // The sub_location is used on a per increment basis (such as 'tar -xcf', the '-' would have an increment of 1, therefore x, c, and f would all be three separate parameters). + while (sub_location < string_length) { + for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) { + if (parameters.parameter[parameter_counter].type != console_type) { + continue; + } + + if (result == console_short) { + if (parameters.parameter[parameter_counter].symbol_short == 0) { + continue; + } + + width = f_macro_utf_byte_width_is(arguments.argv[location][sub_location]); + if (width > 0) { + increment_by = width; + } + + if (arguments.argv[location][sub_location] != *parameters.parameter[parameter_counter].symbol_short) { + continue; + } + + if (width > 0) { + f_utf_character character_argument_utf = 0; + f_utf_character character_console_utf = 0; + + unsigned short max_width = string_length - sub_location; + + status = f_utf_char_to_character(arguments.argv[location] + sub_location, max_width, &character_argument_utf); + + if (status != f_none) { + f_macro_string_lengths_delete(status, needs_additional); + return status; + } + + max_width = strlen(parameters.parameter[parameter_counter].symbol_short); + + status = f_utf_char_to_character((f_string) parameters.parameter[parameter_counter].symbol_short, max_width, &character_console_utf); + + if (status != f_none) { + f_macro_string_lengths_delete(status, needs_additional); + return status; + } + + if (character_argument_utf != character_console_utf) { + continue; + } + } + } + else if (result == console_long) { + if (parameters.parameter[parameter_counter].symbol_long == 0) { + continue; + } + + if (strncmp(&arguments.argv[location][sub_location], parameters.parameter[parameter_counter].symbol_long, increment_by + 1) != 0) { + continue; + } + } + else { + continue; + } + + if (parameters.parameter[parameter_counter].locations.used >= parameters.parameter[parameter_counter].locations.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].locations, parameters.parameter[parameter_counter].locations.size + f_console_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + parameters.parameter[parameter_counter].locations.array[parameters.parameter[parameter_counter].locations.used] = location; + parameters.parameter[parameter_counter].locations.used++; + + parameters.parameter[parameter_counter].result = f_console_result_found; + parameters.parameter[parameter_counter].location = location; + parameters.parameter[parameter_counter].location_sub = 0; + parameters.parameter[parameter_counter].total++; + + if (result == console_short) { + parameters.parameter[parameter_counter].location_sub = sub_location; + } + + if (parameters.parameter[parameter_counter].has_additional) { + if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) { + needs_additional.array[needs_additional.used] = parameter_counter; + needs_additional.used++; + } // for + } + + break; + } // for + + sub_location += increment_by; + } // while + } + else { + found = f_false; + + for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) { + if (parameters.parameter[parameter_counter].type != f_console_type_other) { + continue; + } + + if (parameters.parameter[parameter_counter].symbol_other == 0) { + continue; + } + + if (strncmp(arguments.argv[location], parameters.parameter[parameter_counter].symbol_other, string_length + 1) != 0) { + continue; + } + + if (parameters.parameter[parameter_counter].locations.used >= parameters.parameter[parameter_counter].locations.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].locations, parameters.parameter[parameter_counter].locations.size + f_console_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + parameters.parameter[parameter_counter].locations.array[parameters.parameter[parameter_counter].locations.used] = location; + parameters.parameter[parameter_counter].locations.used++; + + parameters.parameter[parameter_counter].result = f_console_result_found; + parameters.parameter[parameter_counter].location = location; + parameters.parameter[parameter_counter].location_sub = 0; + parameters.parameter[parameter_counter].total++; + + if (parameters.parameter[parameter_counter].has_additional) { + if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) { + needs_additional.array[needs_additional.used] = parameter_counter; + needs_additional.used++; + } // for + } + + found = f_true; + break; + } // for + + if (!found) { + // populate list of remaining parameters.parameter not associated with anything. + if (remaining->used >= remaining->size) { + f_status allocation_status = f_none; + + f_macro_string_lengths_resize(allocation_status, (*remaining), remaining->size + f_console_default_allocation_step); + + if (f_status_is_error(allocation_status)) { + f_macro_string_lengths_delete(status, needs_additional); + return f_status_set_error(allocation_status); + } + } + + remaining->array[remaining->used] = location; + remaining->used++; + } + } + + location++; + } // while + + if (needs_additional.used > 0) { + status = f_no_data; + } + else { + status = f_none; + } + + { + f_status allocation_status = f_none; + f_macro_string_lengths_delete(allocation_status, needs_additional); + } + + return status; + } +#endif // _di_f_console_parameter_process_ + +#ifndef _di_f_console_parameter_prioritize_ + f_return_status f_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision) { + #ifndef _di_level_0_parameter_checking_ + if (decision == 0) return f_status_set_error(f_invalid_parameter); + if (parameters.used == 0) return f_status_set_error(f_invalid_parameter); + if (choices.id == 0) return f_status_set_error(f_invalid_parameter); + if (choices.used == 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_0_parameter_checking_ + + f_array_length location = 0; + f_array_length location_sub = 0; + f_console_parameter_id priority = 0; + + for (f_array_length i = 0; i < choices.used; i++) { + if (choices.id[i] > parameters.used) return f_status_set_error(f_invalid_parameter); + + if (parameters.parameter[choices.id[i]].result == f_console_result_found) { + if (parameters.parameter[choices.id[i]].location > location) { + location = parameters.parameter[choices.id[i]].location; + location_sub = parameters.parameter[choices.id[i]].location_sub; + priority = choices.id[i]; + } + else if (parameters.parameter[choices.id[i]].location == location && parameters.parameter[choices.id[i]].location_sub > location_sub) { + location_sub = parameters.parameter[choices.id[i]].location_sub; + priority = choices.id[i]; + } + } + } // for + + // The first parameter location (argc = 0) is the program name, therefore if the location is 0, then no matches were found. + if (location == 0) { + return f_no_data; + } + + *decision = priority; + + return f_none; + } +#endif // _di_f_console_parameter_prioritize_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 537ddaa..bb78438 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -234,6 +235,79 @@ extern "C" { extern f_return_status f_console_identify(const f_string input, f_console_id *result); #endif // _di_f_console_identify_ +/** + * Process console parameters. + * + * Short parameters are processed as follows: + * - Begin with either '-' or '+'. + * - "Empty" parameters are allow, such that '-' or '+' are valid parameters. + * - Are one character long. + * - May be grouped as a single parameter, such as "tar -xcf" and "tar -x -c -f" are equivalent. + * - Additional parameters must immediately follow the parameter or grouped parameters, such as "tar -xfc file.tar.gz" or "tar -x -f file.tar.gz -c". + * + * Long parameters are processed as follows: + * - Begin with either '--' or '++'. + * - "Empty" parameters are allow, such that '--' or '++' are valid parameters. + * - Are any length long so long as it is less than f_console_max_size. + * - May not be grouped and must be separated from any subsequent parameter, such as: "tar --extract --create --file". + * - Additional parameters must immediately follow the parameter, such as "tar --extract --file file.tar.gz --create". + * + * Other parameters are processed as follows: + * - Anything that does not begin with '-', '+', '--', or '++'. + * - Are any length long so long as it is less than f_console_max_size. + * - May not be grouped and must be separated from any subsequent parameter, such as: "tar extract create file". + * - Additional parameters must immediately follow the parameter, such as "tar extract file file.tar.gz create". + * + * @param arguments + * The parameters passed to the process. + * @param parameters + * The console parameters to look for. + * This will be updated by this function with the results. + * @param remaining + * A list of remaining parameters not associated with anything. + * + * @return + * f_none on success. + * f_no_data if "additional" parameters were expected but not found. + * f_failure (with error bit) if width is not long enough to convert when processing arguments as UTF-8. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_utf (with error bit) if character is an invalid UTF-8 character, when processing arguments. + * f_reallocation_error (with error bit) on memory reallocation error. + */ +#ifndef _di_f_console_parameter_process_ + extern f_return_status f_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining); +#endif // _di_f_console_parameter_process_ + +/** + * Given a set of parameter choices, determine which one has the highest priority. + * + * The priority is determined by viewing the parameters from left to right. + * The right-most parameter defined in the set has the priority over others. + * + * For example, the color context modes override each other, so only one gets priority. + * If given, say "+l ++no_color +d", the "+d" would be the right-most parameter "+l" and "++no_color". + * The decision would be "+d". + * + * This also applies to short parameters combined into one, such as "+lnd", the "d" would again be the decision. + * + * @param parameters + * The parameters to process. + * @param choices + * An array of numeric ids, each representing a parameter within the parameters variable. + * The order does not matter. + * @param decision + * The resulting decision. + * If none of the parameters are found, then this will not be updated (therefore it is safe to have it pre-initialized to the default). + * + * @return + * f_none on success. + * f_no_data if no parameters were found. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_console_parameter_prioritize__ + extern f_return_status f_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision); +#endif // _di_f_console_parameter_prioritize__ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_console/data/build/dependencies b/level_0/f_console/data/build/dependencies index d8175f5..13b45c7 100644 --- a/level_0/f_console/data/build/dependencies +++ b/level_0/f_console/data/build/dependencies @@ -2,3 +2,4 @@ f_type f_status f_memory f_string +f_utf diff --git a/level_0/f_console/data/build/settings b/level_0/f_console/data/build/settings index 2cae8c0..7c60020 100644 --- a/level_0/f_console/data/build/settings +++ b/level_0/f_console/data/build/settings @@ -9,10 +9,10 @@ version_micro 0 build_compiler gcc build_linker ar -build_libraries -lc -build_libraries_fll -lf_memory +build_libraries -lc +build_libraries_fll -lf_utf -lf_memory build_sources_library console.c -build_sources_program +build_sources_program build_sources_headers console.h build_sources_bash build_sources_settings diff --git a/level_0/f_status/c/status.h b/level_0/f_status/c/status.h index 633097b..7b76ada 100644 --- a/level_0/f_status/c/status.h +++ b/level_0/f_status/c/status.h @@ -45,8 +45,12 @@ extern "C" { #define f_status_set_signal(status) (status | f_status_bit_signal) #define f_status_set_warning(status) (status | f_status_bit_warning) - // use f_status_set_fine to remove the error, warning, and signal bits + // Use f_status_set_fine to remove the error, warning, and signal bits. #define f_status_set_fine(status) (status & f_status_mask_fine) + + // Maximum size of the status code. + #define f_status_size_max 0x3fff + #define f_status_size_max_with_signal 0x10000 #endif // _di_f_status_masks_ /** @@ -54,270 +58,275 @@ extern "C" { * * The code f_status_code_last is intended to be used as the starting point for anything extending this and povided its own status codes. */ -enum { - #ifndef _di_f_status_booleans_ - f_false = 0, - f_true, - #endif // _di_f_status_booleans_ +#ifndef _di_f_status_codes_ + enum { + #ifndef _di_f_status_booleans_ + f_false = 0, + f_true, + #endif // _di_f_status_booleans_ - #ifndef _di_f_status_signals_ - f_signal_hangup = 1, - f_signal_interrupt, - f_signal_quit, - f_signal_illegal, - f_signal_trap, - f_signal_abort, - f_signal_bus_error, - f_signal_floating_point_exception, - f_signal_kill, // unblockable - f_signal_user_1, - f_signal_segmentation_fault, - f_signal_user_2, - f_signal_broken_pipe, - f_signal_alarm_clock, - f_signal_termination, - f_signal_stack_fault, - f_signal_child, - f_signal_continue, - f_signal_stop, // unblockable - f_signal_keyboard_stop, - f_signal_tty_in, - f_signal_tty_out, - f_signal_urgent, - f_signal_cpu_limit, - f_signal_file_size_limit, - f_signal_virtual_alarm_clock, - f_signal_profile_alarm_clock, - f_signal_window_size_change, - f_signal_pollable_event, - f_signal_power_failure, - f_signal_bad_system_call, - f_signal_reserved_32, - f_signal_reserved_33, - f_signal_reserved_34, - f_signal_reserved_35, - f_signal_reserved_36, - f_signal_reserved_37, - f_signal_reserved_38, - f_signal_reserved_39, - f_signal_reserved_40, - f_signal_reserved_41, - f_signal_reserved_42, - f_signal_reserved_43, - f_signal_reserved_44, - f_signal_reserved_45, - f_signal_reserved_46, - f_signal_reserved_47, - f_signal_reserved_48, - f_signal_reserved_49, - f_signal_reserved_50, - f_signal_reserved_51, - f_signal_reserved_52, - f_signal_reserved_53, - f_signal_reserved_54, - f_signal_reserved_55, - f_signal_reserved_56, - f_signal_reserved_57, - f_signal_reserved_58, - f_signal_reserved_59, - f_signal_reserved_60, - f_signal_reserved_61, - f_signal_reserved_62, - f_signal_reserved_63, - f_signal_reserved_64, - #endif // _di_f_status_signals_ + #ifndef _di_f_status_signals_ + f_signal_hangup = 1, + f_signal_interrupt, + f_signal_quit, + f_signal_illegal, + f_signal_trap, + f_signal_abort, + f_signal_bus_error, + f_signal_floating_point_exception, + f_signal_kill, // unblockable + f_signal_user_1, + f_signal_segmentation_fault, + f_signal_user_2, + f_signal_broken_pipe, + f_signal_alarm_clock, + f_signal_termination, + f_signal_stack_fault, + f_signal_child, + f_signal_continue, + f_signal_stop, // unblockable + f_signal_keyboard_stop, + f_signal_tty_in, + f_signal_tty_out, + f_signal_urgent, + f_signal_cpu_limit, + f_signal_file_size_limit, + f_signal_virtual_alarm_clock, + f_signal_profile_alarm_clock, + f_signal_window_size_change, + f_signal_pollable_event, + f_signal_power_failure, + f_signal_bad_system_call, + f_signal_reserved_32, + f_signal_reserved_33, + f_signal_reserved_34, + f_signal_reserved_35, + f_signal_reserved_36, + f_signal_reserved_37, + f_signal_reserved_38, + f_signal_reserved_39, + f_signal_reserved_40, + f_signal_reserved_41, + f_signal_reserved_42, + f_signal_reserved_43, + f_signal_reserved_44, + f_signal_reserved_45, + f_signal_reserved_46, + f_signal_reserved_47, + f_signal_reserved_48, + f_signal_reserved_49, + f_signal_reserved_50, + f_signal_reserved_51, + f_signal_reserved_52, + f_signal_reserved_53, + f_signal_reserved_54, + f_signal_reserved_55, + f_signal_reserved_56, + f_signal_reserved_57, + f_signal_reserved_58, + f_signal_reserved_59, + f_signal_reserved_60, + f_signal_reserved_61, + f_signal_reserved_62, + f_signal_reserved_63, + f_signal_reserved_64, + #endif // _di_f_status_signals_ - #ifndef _di_f_status_basic_ - f_none = 197, // start at 197 to allow compatibility with the reserved bash return codes (keep in mind fss return codes can be larger than 255). - f_maybe, - f_dummy, // to only be used as a placeholder - f_warn, // warning - f_critical, - f_unknown, // For the "code should never get here" errors. (this is an EMERGENCY error) - f_unsupported, - f_no_data, // warning - f_out_of_memory, - f_input_error, - f_output_error, - f_input_output_error, - f_does_not_exist, - f_not_connected, - f_failure, - f_interrupted, // usually by a signal. - f_loop, // such as infinite recursion. - f_incomplete, // incomplete information - #endif // _di_f_status_basic_ + #ifndef _di_f_status_basic_ + f_none = 197, // Start at 197 to allow compatibility with the reserved bash return codes (keep in mind fss return codes can be larger than 255). + f_maybe, + f_dummy, // To only be used as a placeholder. + f_warn, // Warning. + f_critical, + f_unknown, // For the "code should never get here" errors. (this is an EMERGENCY error). + f_unsupported, + f_no_data, // Warning. + f_out_of_memory, + f_input_error, + f_output_error, + f_input_output_error, + f_does_not_exist, + f_not_connected, + f_failure, + f_interrupted, // Usually by a signal. + f_loop, // Such as infinite recursion. + f_incomplete, // Incomplete information. + #endif // _di_f_status_basic_ - #ifndef _di_f_status_invalid_ - f_invalid, - f_invalid_name, - f_invalid_parameter, - f_invalid_syntax, - f_invalid_data, - f_invalid_file, - f_invalid_directory, - f_invalid_descriptor, - f_invalid_socket, - f_invalid_device, - f_invalid_link, - f_invalid_pipe, - f_invalid_address, - f_invalid_port, - f_invalid_value, // similar to f_invalid_parameter, but the parameter value is invalid (example: an integer value representing aboolean and having a 3 as a value). - f_invalid_buffer, - f_invalid_process, - f_invalid_utf, - f_invalid_on_eof, - f_invalid_on_eol, - f_invalid_on_eos, - f_invalid_on_stop, - #endif // _di_f_status_invalid_ + #ifndef _di_f_status_invalid_ + f_invalid, + f_invalid_name, + f_invalid_parameter, + f_invalid_syntax, + f_invalid_data, + f_invalid_file, + f_invalid_directory, + f_invalid_descriptor, + f_invalid_socket, + f_invalid_device, + f_invalid_link, + f_invalid_pipe, + f_invalid_address, + f_invalid_port, + f_invalid_value, + f_invalid_buffer, + f_invalid_process, + f_invalid_utf, + f_invalid_on_eof, + f_invalid_on_eol, + f_invalid_on_eos, + f_invalid_on_stop, + #endif // _di_f_status_invalid_ - #ifndef _di_f_status_busy_ - f_busy, // such as address in use, or port in use. - f_busy_address, - f_busy_port, - f_busy_socket, - f_busy_device, - f_busy_pipe, - f_busy_buffer, - f_busy_process, - #endif // _di_f_status_busy_ + #ifndef _di_f_status_busy_ + f_busy, + f_busy_address, + f_busy_port, + f_busy_socket, + f_busy_device, + f_busy_pipe, + f_busy_buffer, + f_busy_process, + #endif // _di_f_status_busy_ - #ifndef _di_f_status_unavailable_ - f_unavailable, - f_unavailable_address, - f_unavailable_port, - f_unavailable_socket, - f_unavailable_device, - f_unavailable_pipe, - f_unavailable_buffer, - f_unavailable_process, - #endif // _di_f_status_unavailable_ + #ifndef _di_f_status_unavailable_ + f_unavailable, + f_unavailable_address, + f_unavailable_port, + f_unavailable_socket, + f_unavailable_device, + f_unavailable_pipe, + f_unavailable_buffer, + f_unavailable_process, + #endif // _di_f_status_unavailable_ - #ifndef _di_f_status_digits_ - f_underflow, - f_overflow, - f_divide_by_zero, - f_negative_number, - f_positive_number, - f_zero_number, - f_decimal_number, - f_invalid_number, - #endif // _di_f_status_digits_ + #ifndef _di_f_status_digits_ + f_underflow, + f_overflow, + f_divide_by_zero, + f_negative_number, + f_positive_number, + f_zero_number, + f_decimal_number, + f_whole_number, + f_invalid_number, + #endif // _di_f_status_digits_ - #ifndef _di_f_status_buffers_ - f_no_data_on_eof, // warning - f_no_data_on_eol, // warning - f_no_data_on_eos, // warning - f_no_data_on_stop, // warning - f_none_on_eof, // warning - f_none_on_eol, // warning - f_none_on_eos, // warning - f_none_on_stop, // "stop" location was reached - f_error_on_eof, - f_error_on_eol, - f_error_on_eos, - f_error_on_stop, - f_buffer_too_small, - f_buffer_too_large, - f_string_too_small, - f_string_too_large, - f_unterminated_nest, - f_unterminated_nest_on_eof, - f_unterminated_nest_on_eol, - f_unterminated_nest_on_eos, - f_unterminated_nest_on_stop, - f_unterminated_group, - f_unterminated_group_on_eof, - f_unterminated_group_on_eol, - f_unterminated_group_on_eos, - f_unterminated_group_on_stop, - f_incomplete_utf, - f_incomplete_utf_on_eof, - f_incomplete_utf_on_eol, - f_incomplete_utf_on_eos, - f_incomplete_utf_on_stop, - #endif // _di_f_status_buffers_ + #ifndef _di_f_status_buffers_ + f_no_data_on_eof, + f_no_data_on_eol, + f_no_data_on_eos, + f_no_data_on_stop, + f_none_on_eof, + f_none_on_eol, + f_none_on_eos, + f_none_on_stop, + f_error_on_eof, + f_error_on_eol, + f_error_on_eos, + f_error_on_stop, + f_buffer_too_small, + f_buffer_too_large, + f_string_too_small, + f_string_too_large, + f_unterminated_nest, + f_unterminated_nest_on_eof, + f_unterminated_nest_on_eol, + f_unterminated_nest_on_eos, + f_unterminated_nest_on_stop, + f_unterminated_group, + f_unterminated_group_on_eof, + f_unterminated_group_on_eol, + f_unterminated_group_on_eos, + f_unterminated_group_on_stop, + f_incomplete_utf, + f_incomplete_utf_on_eof, + f_incomplete_utf_on_eol, + f_incomplete_utf_on_eos, + f_incomplete_utf_on_stop, + #endif // _di_f_status_buffers_ - #ifndef _di_f_status_allocation_ - f_allocation_error, - f_reallocation_error, - #endif // _di_f_status_allocation_ + #ifndef _di_f_status_allocation_ + f_allocation_error, + f_reallocation_error, + f_deallocation_error, + #endif // _di_f_status_allocation_ - #ifndef _di_f_status_fork_ - f_fork_failed, - f_too_many_processes, - #endif // _di_f_status_fork_ + #ifndef _di_f_status_fork_ + f_fork_failed, + f_too_many_processes, + #endif // _di_f_status_fork_ - #ifndef _di_f_status_file_ - f_file_seek_error, - f_file_read_error, - f_file_write_error, - f_file_flush_error, - f_file_purge_error, - f_file_open_error, - f_file_close_error, - f_file_synchronize_error, - f_file_descriptor_error, - f_file_not_found, - f_file_found, - f_file_is_empty, - f_file_not_open, - f_file_allocation_error, - f_file_reallocation_error, - f_file_stat_error, - f_file_error, - f_file_not_utf, - #endif // _di_f_status_file_ + #ifndef _di_f_status_file_ + f_file_seek_error, + f_file_read_error, + f_file_write_error, + f_file_flush_error, + f_file_purge_error, + f_file_open_error, + f_file_close_error, + f_file_synchronize_error, + f_file_descriptor_error, + f_file_not_found, + f_file_found, + f_file_is_empty, + f_file_not_open, + f_file_allocation_error, + f_file_reallocation_error, + f_file_deallocation_error, + f_file_stat_error, + f_file_error, + f_file_not_utf, + #endif // _di_f_status_file_ - // most of these are a guess until I get around to researching & implementing linux directory I/O - #ifndef _di_f_status_directory_ - f_directory_read_error, - f_directory_write_error, - f_directory_flush_error, - f_directory_purge_error, - f_directory_open_error, - f_directory_close_error, - f_directory_synchronize_error, - f_directory_descriptor_error, - f_directory_not_found, - f_directory_is_empty, - f_directory_not_open, - f_directory_allocation_error, - f_directory_reallocation_error, - f_directory_error, - f_directory_not_utf, - #endif // _di_f_status_directory_ + // Most of these are a guess until I get around to researching & implementing linux directory I/O. + #ifndef _di_f_status_directory_ + f_directory_read_error, + f_directory_write_error, + f_directory_flush_error, + f_directory_purge_error, + f_directory_open_error, + f_directory_close_error, + f_directory_synchronize_error, + f_directory_descriptor_error, + f_directory_not_found, + f_directory_is_empty, + f_directory_not_open, + f_directory_allocation_error, + f_directory_reallocation_error, + f_directory_error, + f_directory_not_utf, + #endif // _di_f_status_directory_ - #ifndef _di_f_status_socket_ - f_socket_connection_client_error, - f_socket_connection_target_error, - f_socket_receive_error, - f_socket_send_error, - #endif // _di_f_status_socket_ + #ifndef _di_f_status_socket_ + f_socket_connection_client_error, + f_socket_connection_target_error, + f_socket_receive_error, + f_socket_send_error, + #endif // _di_f_status_socket_ - #ifndef _di_f_status_non_ - f_less_than, - f_equal_to, - f_not_equal_to, - f_greater_than, - #endif // _di_f_status_non_ + #ifndef _di_f_status_non_ + f_less_than, + f_equal_to, + f_not_equal_to, + f_greater_than, + #endif // _di_f_status_non_ - #ifndef _di_f_status_access_denied_ - f_access_denied, - f_access_denied_user, - f_access_denied_group, - f_access_denied_world, - f_access_denied_read, - f_access_denied_write, - f_access_denied_execute, - f_access_denied_super, // not super user (aka: not root). - #endif // _di_f_status_access_denied_ + #ifndef _di_f_status_access_denied_ + f_access_denied, + f_access_denied_user, + f_access_denied_group, + f_access_denied_world, + f_access_denied_read, + f_access_denied_write, + f_access_denied_execute, + f_access_denied_super, // Not super user (aka: not root). + #endif // _di_f_status_access_denied_ - // required - f_status_code_last -}; // enum + // Required. + f_status_code_last + }; // enum +#endif // _di_f_status_codes_ #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_string/data/build/settings b/level_0/f_string/data/build/settings index 4b3ee1e..2de8da4 100644 --- a/level_0/f_string/data/build/settings +++ b/level_0/f_string/data/build/settings @@ -11,7 +11,7 @@ build_compiler gcc build_linker ar build_libraries -lc build_libraries_fll -lf_memory -build_sources_library +build_sources_library build_sources_program build_sources_headers string.h build_sources_bash diff --git a/level_0/f_type/c/type.h b/level_0/f_type/c/type.h index b318f55..fc849bc 100644 --- a/level_0/f_type/c/type.h +++ b/level_0/f_type/c/type.h @@ -24,9 +24,11 @@ extern "C" { #ifndef _di_f_type_status_ typedef uint16_t f_status; - // The c language gives warnings about return types of constants. - // Remove the const for c, but keep it for c++, which is only for function call declarations & prototypes. - // Do not declare these for the return data types themselves, instead use f_status; only use these for function prototypes and declarations. + /** + * The c language gives warnings about return types of constants. + * Remove the const for c, but keep it for c++, which is only for function call declarations & prototypes. + * Do not declare these for the return data types themselves, instead use f_status; only use these for function prototypes and declarations. + */ #ifdef __cplusplus #define f_return_status const f_status #else diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index 292f421..9037ab9 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -40,334 +40,6 @@ extern "C" { } #endif // _fl_console_parameter_to_number_unsigned_ -#ifndef _di_fl_console_parameter_process_ - f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining) { - #ifndef _di_level_1_parameter_checking_ - if (remaining == 0) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - f_status status = f_none; - f_console_id result = 0; - bool found = f_false; - - unsigned long location = 1; // Parameter 0 represents the program name so skip it. - f_string_length sub_location = 0; - f_string_length increment_by = 0; - f_string_length string_length = 0; - f_array_length parameter_counter = 0; - - unsigned short console_short = f_console_none; - unsigned short console_long = f_console_none; - unsigned short console_type = f_console_type_normal; - - f_string_lengths needs_additional = f_string_lengths_initialize; - - unsigned short width = 0; - - // loop through and read all parameters. - while (location < arguments.argc) { - f_console_identify(arguments.argv[location], &result); - - string_length = strnlen(arguments.argv[location], f_console_max_size); - - // process the current parameter. - if (result == f_console_short_enable || result == f_console_short_disable) { - increment_by = 1; - sub_location = 1; - } - else if (result == f_console_long_enable || result == f_console_long_disable) { - increment_by = string_length; - sub_location = 2; - } - else { - increment_by = string_length; - sub_location = 0; - } - - // Handle the normal commands. - if (result == f_console_short_enable || result == f_console_long_enable) { - console_short = f_console_short_enable; - console_long = f_console_long_enable; - console_type = f_console_type_normal; - } - else if (result == f_console_short_disable || result == f_console_long_disable) { - console_short = f_console_short_disable; - console_long = f_console_long_disable; - console_type = f_console_type_inverse; - } - else { - console_short = f_console_none; - } - - // Additional parameters must always follow what requests them. - if (needs_additional.used > 0) { - parameter_counter = needs_additional.array[0]; - - if (parameters.parameter[parameter_counter].additional.used >= parameters.parameter[parameter_counter].additional.size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].additional, parameters.parameter[parameter_counter].additional.size + f_console_default_allocation_step); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - parameters.parameter[parameter_counter].result = f_console_result_additional; - parameters.parameter[parameter_counter].additional.array[parameters.parameter[parameter_counter].additional.used] = location; - parameters.parameter[parameter_counter].additional.used++; - - needs_additional.used--; - - // Pop the matched parameter off of the top of the needs_additional array. - for (f_string_length i = 0; i < needs_additional.used; i++) { - needs_additional.array[i] = needs_additional.array[i + 1]; - } // for - } - else if (console_short != f_console_none) { - // The sub_location is used on a per increment basis (such as 'tar -xcf', the '-' would have an increment of 1, therefore x, c, and f would all be three separate parameters). - while (sub_location < string_length) { - for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) { - if (parameters.parameter[parameter_counter].type != console_type) { - continue; - } - - if (result == console_short) { - if (parameters.parameter[parameter_counter].symbol_short == 0) { - continue; - } - - width = f_macro_utf_byte_width_is(arguments.argv[location][sub_location]); - if (width > 0) { - increment_by = width; - } - - if (arguments.argv[location][sub_location] != *parameters.parameter[parameter_counter].symbol_short) { - continue; - } - - if (width > 0) { - f_utf_character character_argument_utf = 0; - f_utf_character character_console_utf = 0; - - unsigned short max_width = string_length - sub_location; - - status = f_utf_char_to_character(arguments.argv[location] + sub_location, max_width, &character_argument_utf); - - if (status != f_none) { - f_macro_string_lengths_delete(status, needs_additional); - return status; - } - - max_width = strlen(parameters.parameter[parameter_counter].symbol_short); - - status = f_utf_char_to_character((f_string) parameters.parameter[parameter_counter].symbol_short, max_width, &character_console_utf); - - if (status != f_none) { - f_macro_string_lengths_delete(status, needs_additional); - return status; - } - - if (character_argument_utf != character_console_utf) { - continue; - } - } - } - else if (result == console_long) { - if (parameters.parameter[parameter_counter].symbol_long == 0) { - continue; - } - - if (strncmp(&arguments.argv[location][sub_location], parameters.parameter[parameter_counter].symbol_long, increment_by + 1) != 0) { - continue; - } - } - else { - continue; - } - - if (parameters.parameter[parameter_counter].locations.used >= parameters.parameter[parameter_counter].locations.size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].locations, parameters.parameter[parameter_counter].locations.size + f_console_default_allocation_step); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - parameters.parameter[parameter_counter].locations.array[parameters.parameter[parameter_counter].locations.used] = location; - parameters.parameter[parameter_counter].locations.used++; - - parameters.parameter[parameter_counter].result = f_console_result_found; - parameters.parameter[parameter_counter].location = location; - parameters.parameter[parameter_counter].location_sub = 0; - parameters.parameter[parameter_counter].total++; - - if (result == console_short) { - parameters.parameter[parameter_counter].location_sub = sub_location; - } - - if (parameters.parameter[parameter_counter].has_additional) { - if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) { - needs_additional.array[needs_additional.used] = parameter_counter; - needs_additional.used++; - } // for - } - - break; - } // for - - sub_location += increment_by; - } // while - } - else { - found = f_false; - - for (parameter_counter = 0; parameter_counter < parameters.used; parameter_counter++) { - if (parameters.parameter[parameter_counter].type != f_console_type_other) { - continue; - } - - if (parameters.parameter[parameter_counter].symbol_other == 0) { - continue; - } - - if (strncmp(arguments.argv[location], parameters.parameter[parameter_counter].symbol_other, string_length + 1) != 0) { - continue; - } - - if (parameters.parameter[parameter_counter].locations.used >= parameters.parameter[parameter_counter].locations.size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, parameters.parameter[parameter_counter].locations, parameters.parameter[parameter_counter].locations.size + f_console_default_allocation_step); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - parameters.parameter[parameter_counter].locations.array[parameters.parameter[parameter_counter].locations.used] = location; - parameters.parameter[parameter_counter].locations.used++; - - parameters.parameter[parameter_counter].result = f_console_result_found; - parameters.parameter[parameter_counter].location = location; - parameters.parameter[parameter_counter].location_sub = 0; - parameters.parameter[parameter_counter].total++; - - if (parameters.parameter[parameter_counter].has_additional) { - if (needs_additional.used + parameters.parameter[parameter_counter].has_additional > needs_additional.size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, needs_additional, needs_additional.used + parameters.parameter[parameter_counter].has_additional); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - for (f_array_length additional = 0; additional < parameters.parameter[parameter_counter].has_additional; additional++) { - needs_additional.array[needs_additional.used] = parameter_counter; - needs_additional.used++; - } // for - } - - found = f_true; - break; - } // for - - if (!found) { - // populate list of remaining parameters.parameter not associated with anything. - if (remaining->used >= remaining->size) { - f_status allocation_status = f_none; - - f_macro_string_lengths_resize(allocation_status, (*remaining), remaining->size + f_console_default_allocation_step); - - if (f_status_is_error(allocation_status)) { - f_macro_string_lengths_delete(status, needs_additional); - return f_status_set_error(allocation_status); - } - } - - remaining->array[remaining->used] = location; - remaining->used++; - } - } - - location++; - } // while - - if (needs_additional.used > 0) { - status = f_no_data; - } - else { - status = f_none; - } - - { - f_status allocation_status = f_none; - f_macro_string_lengths_delete(allocation_status, needs_additional); - } - - return status; - } -#endif // _di_fl_console_parameter_process_ - -#ifndef _di_fl_console_parameter_prioritize_ - f_return_status fl_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision) { - #ifndef _di_level_1_parameter_checking_ - if (decision == 0) return f_status_set_error(f_invalid_parameter); - if (parameters.used == 0) return f_status_set_error(f_invalid_parameter); - if (choices.id == 0) return f_status_set_error(f_invalid_parameter); - if (choices.used == 0) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - f_array_length location = 0; - f_array_length location_sub = 0; - f_console_parameter_id priority = 0; - - for (f_array_length i = 0; i < choices.used; i++) { - if (choices.id[i] > parameters.used) return f_status_set_error(f_invalid_parameter); - - if (parameters.parameter[choices.id[i]].result == f_console_result_found) { - if (parameters.parameter[choices.id[i]].location > location) { - location = parameters.parameter[choices.id[i]].location; - location_sub = parameters.parameter[choices.id[i]].location_sub; - priority = choices.id[i]; - } - else if (parameters.parameter[choices.id[i]].location == location && parameters.parameter[choices.id[i]].location_sub > location_sub) { - location_sub = parameters.parameter[choices.id[i]].location_sub; - priority = choices.id[i]; - } - } - } // for - - // The first parameter location (argc = 0) is the program name, therefore if the location is 0, then no matches were found. - if (location == 0) { - return f_no_data; - } - - *decision = priority; - - return f_none; - } -#endif // _di_fl_console_parameter_prioritize_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index 286d403..4513785 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -96,79 +96,6 @@ extern "C" { f_return_status fl_console_parameter_to_number_unsigned(const f_string argument, f_number_unsigned *number); #endif // _fl_console_parameter_to_number_unsigned_ -/** - * Process console parameters. - * - * Short parameters are processed as follows: - * - Begin with either '-' or '+'. - * - "Empty" parameters are allow, such that '-' or '+' are valid parameters. - * - Are one character long. - * - May be grouped as a single parameter, such as "tar -xcf" and "tar -x -c -f" are equivalent. - * - Additional parameters must immediately follow the parameter or grouped parameters, such as "tar -xfc file.tar.gz" or "tar -x -f file.tar.gz -c". - * - * Long parameters are processed as follows: - * - Begin with either '--' or '++'. - * - "Empty" parameters are allow, such that '--' or '++' are valid parameters. - * - Are any length long so long as it is less than f_console_max_size. - * - May not be grouped and must be separated from any subsequent parameter, such as: "tar --extract --create --file". - * - Additional parameters must immediately follow the parameter, such as "tar --extract --file file.tar.gz --create". - * - * Other parameters are processed as follows: - * - Anything that does not begin with '-', '+', '--', or '++'. - * - Are any length long so long as it is less than f_console_max_size. - * - May not be grouped and must be separated from any subsequent parameter, such as: "tar extract create file". - * - Additional parameters must immediately follow the parameter, such as "tar extract file file.tar.gz create". - * - * @param arguments - * The parameters passed to the process. - * @param parameters - * The console parameters to look for. - * This will be updated by this function with the results. - * @param remaining - * A list of remaining parameters not associated with anything. - * - * @return - * f_none on success. - * f_no_data if "additional" parameters were expected but not found. - * f_failure (with error bit) if width is not long enough to convert when processing arguments as UTF-8. - * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_invalid_utf (with error bit) if character is an invalid UTF-8 character, when processing arguments. - * f_reallocation_error (with error bit) on memory reallocation error. - */ -#ifndef _di_fl_console_parameter_process_ - extern f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameters parameters, f_string_lengths *remaining); -#endif // _di_fl_console_parameter_process_ - -/** - * Given a set of parameter choices, determine which one has the highest priority. - * - * The priority is determined by viewing the parameters from left to right. - * The right-most parameter defined in the set has the priority over others. - * - * For example, the color context modes override each other, so only one gets priority. - * If given, say "+l ++no_color +d", the "+d" would be the right-most parameter "+l" and "++no_color". - * The decision would be "+d". - * - * This also applies to short parameters combined into one, such as "+lnd", the "d" would again be the decision. - * - * @param parameters - * The parameters to process. - * @param choices - * An array of numeric ids, each representing a parameter within the parameters variable. - * The order does not matter. - * @param decision - * The resulting decision. - * If none of the parameters are found, then this will not be updated (therefore it is safe to have it pre-initialized to the default). - * - * @return - * f_none on success. - * f_no_data if no parameters were found. - * f_invalid_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_fl_console_parameter_prioritize__ - extern f_return_status fl_console_parameter_prioritize(const f_console_parameters parameters, const f_console_parameter_ids choices, f_console_parameter_id *decision); -#endif // _di_fl_console_parameter_prioritize__ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index dfcc353..f6c0601 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -10,9 +10,9 @@ extern "C" { if (string == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_status umasked_error = f_status_set_fine(code); + f_status unmasked_code = f_status_set_fine(code); - switch (umasked_error) { + switch (unmasked_code) { #ifndef _di_fl_status_booleans_ case f_false: *string = fl_status_string_false; @@ -272,7 +272,7 @@ extern "C" { break; #endif // _di_fl_status_basic_ - #ifdef _di_fl_status_invalid_ + #ifndef _di_fl_status_invalid_ case f_invalid: *string = fl_status_string_invalid; break; @@ -417,6 +417,9 @@ extern "C" { case f_decimal_number: *string = fl_status_string_decimal_number; break; + case f_whole_number: + *string = fl_status_string_whole_number; + break; case f_invalid_number: *string = fl_status_string_invalid_number; break; @@ -525,6 +528,9 @@ extern "C" { case f_reallocation_error: *string = fl_status_string_reallocation_error; break; + case f_deallocation_error: + *string = fl_status_string_deallocation_error; + break; #endif // _di_fl_status_allocation_ #ifndef _di_fl_status_fork_ @@ -582,6 +588,9 @@ extern "C" { case f_file_reallocation_error: *string = fl_status_string_file_reallocation_error; break; + case f_file_deallocation_error: + *string = fl_status_string_file_deallocation_error; + break; case f_file_stat_error: *string = fl_status_string_file_stat_error; break; @@ -641,6 +650,21 @@ extern "C" { break; #endif // _di_fl_status_directory_ + #ifndef _di_fl_status_socket_ + case f_socket_connection_client_error: + *string = fl_status_string_socket_connection_client_error; + break; + case f_socket_connection_target_error: + *string = fl_status_string_socket_connection_target_error; + break; + case f_socket_receive_error: + *string = fl_status_string_socket_receive_error; + break; + case f_socket_send_error: + *string = fl_status_string_socket_send_error; + break; + #endif // _di_fl_status_socket_ + #ifndef _di_fll_error_non_ case f_less_than: *string = fl_status_string_less_than; diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index 6600a70..7a788db 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -419,10 +419,13 @@ extern "C" { #define fl_status_string_zero_number_length 14 #define fl_status_string_decimal_number "f_decimal_number" - #define fl_status_string_decimal_number_length 15 + #define fl_status_string_decimal_number_length 17 + + #define fl_status_string_whole_number "f_whole_number" + #define fl_status_string_whole_number_length 15 #define fl_status_string_invalid_number "f_invalid_number" - #define fl_status_string_invalid_number_length 15 + #define fl_status_string_invalid_number_length 17 #endif // _di_fl_status_digits_ #ifndef _di_fl_status_buffers_ @@ -526,6 +529,9 @@ extern "C" { #define fl_status_string_reallocation_error "f_reallocation_error" #define fl_status_string_reallocation_error_length 21 + + #define fl_status_string_deallocation_error "f_deallocation_error" + #define fl_status_string_deallocation_error_length 21 #endif // _di_fl_status_allocation_ #ifndef _di_fl_status_fork_ @@ -582,6 +588,9 @@ extern "C" { #define fl_status_string_file_reallocation_error "f_file_reallocation_error" #define fl_status_string_file_reallocation_error_length 26 + #define fl_status_string_file_deallocation_error "f_file_deallocation_error" + #define fl_status_string_file_deallocation_error_length 26 + #define fl_status_string_file_stat_error "f_file_stat_error" #define fl_status_string_file_stat_error_length 18 diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index 008bfcd..6230dbd 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -4,6 +4,126 @@ extern "C" { #endif +#ifndef _di_fl_string_compare_ + f_return_status fl_string_compare(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2) { + #ifndef _di_level_1_parameter_checking_ + if (length1 <= 0) return f_status_set_error(f_invalid_parameter); + if (length2 <= 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_string_length i1 = 0; + f_string_length i2 = 0; + + for (; i1 < length1 && i2 < length2; i1++, i2++) { + // skip past newlines in string1. + while (i1 < length1 && string1[i1] == f_string_eos) i1++; + if (i1 == length1) break; + + // skip past newlines in string2. + while (i2 < length2 && string2[i2] == f_string_eos) i2++; + if (i2 == length2) break; + + if (string1[i1] != string2[i2]) return f_not_equal_to; + } // for + + // only return f_equal_to if all remaining characters are NULL. + while (i1 < length1) { + if (string1[i1] != f_string_eos) return f_not_equal_to; + i1++; + } // while + + while (i2 < length2) { + if (string2[i2] != f_string_eos) return f_not_equal_to; + i2++; + } // while + + return f_equal_to; + } +#endif // _di_fl_string_compare_ + +#ifndef _di_f_string_dynamics_compare_ + f_return_status f_string_dynamics_compare(const f_string_dynamic string1, const f_string_dynamic string2) { + #ifndef _di_level_1_parameter_checking_ + if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); + if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_string_length i1 = 0; + f_string_length i2 = 0; + + for (; i1 < string1.used && i2 < string2.used; i1++, i2++) { + // skip past newlines in string1. + while (i1 < string1.used && string1.string[i1] == f_string_eos) i1++; + if (i1 == string1.used) break; + + // skip past newlines in string2. + while (i2 < string2.used && string2.string[i2] == f_string_eos) i2++; + if (i2 == string2.used) break; + + if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; + } // for + + // only return f_equal_to if all remaining characters are NULL. + while (i1 < string1.used) { + if (string1.string[i1] != f_string_eos) return f_not_equal_to; + i1++; + } // while + + while (i2 < string2.used) { + if (string2.string[i2] != f_string_eos) return f_not_equal_to; + i2++; + } // while + + return f_equal_to; + } +#endif // _di_f_string_dynamics_compare_ + +#ifndef _di_fl_string_dynamic_partial_compare_ + f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2) { + #ifndef _di_level_1_parameter_checking_ + if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); + if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); + + if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); + if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); + + if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); + if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + f_string_length i1 = offset1.start; + f_string_length i2 = offset2.start; + + const f_string_length stop1 = offset1.stop + 1; + const f_string_length stop2 = offset2.stop + 1; + + for (; i1 < stop1 && i2 < stop2; i1++, i2++) { + // skip past newlines in string1. + while (i1 < stop1 && string1.string[i1] == f_string_eos) i1++; + if (i1 == stop1) break; + + // skip past newlines in string2. + while (i2 < stop2 && string2.string[i2] == f_string_eos) i2++; + if (i2 == stop2) break; + + if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; + } // for + + // only return f_equal_to if all remaining characters are NULL. + while (i1 < stop1) { + if (string1.string[i1] != f_string_eos) return f_not_equal_to; + i1++; + } // while + + while (i2 < stop2) { + if (string2.string[i2] != f_string_eos) return f_not_equal_to; + i2++; + } // while + + return f_equal_to; + } +#endif // _di_fl_string_dynamic_partial_compare_ + #ifndef _di_fl_string_rip_ f_return_status fl_string_rip(const f_string_dynamic buffer, const f_string_location location, f_string_dynamic *result) { #ifndef _di_level_1_parameter_checking_ @@ -13,7 +133,7 @@ extern "C" { if (location.start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - // the start and stop point are inclusive locations, and therefore start - stop is actually 1 too few locations + // The start and stop point are inclusive locations, and therefore start - stop is actually 1 too few locations. f_string_length size = (location.stop - location.start) + 1; if (size > 0) { @@ -40,8 +160,31 @@ extern "C" { } #endif // _di_fl_string_rip_ -#ifndef _di_fl_string_seek_line_until_graph_ - f_return_status fl_string_seek_line_until_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder) { +#ifndef _di_fl_string_seek_line_to_ + f_return_status fl_string_seek_line_to(const f_string_dynamic buffer, f_string_location *location, const int8_t seek_to_this) { + #ifndef _di_level_1_parameter_checking_ + if (location == 0) return f_status_set_error(f_invalid_parameter); + if (location->start < 0) return f_status_set_error(f_invalid_parameter); + if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); + if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); + #endif // _di_level_1_parameter_checking_ + + while (buffer.string[location->start] != seek_to_this) { + if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; + + location->start++; + + if (location->start >= buffer.used) return f_none_on_eos; + if (location->start > location->stop) return f_none_on_stop; + } // while + + return f_none; + } +#endif // _di_fl_string_seek_line_to_ + +#ifndef _di_fl_string_seek_line_to_utf_character_ + f_return_status fl_string_seek_line_to_utf_character(const f_string_dynamic buffer, f_string_location *location, const f_utf_character seek_to_this) { #ifndef _di_level_1_parameter_checking_ if (location == 0) return f_status_set_error(f_invalid_parameter); if (location->start < 0) return f_status_set_error(f_invalid_parameter); @@ -50,26 +193,31 @@ extern "C" { if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ + const unsigned short seek_width = f_macro_utf_character_width(seek_to_this); + f_status status = f_none; + unsigned short width = 0; - f_string_length max_width = (location->stop - location->start) + 1; + f_string_length max_width = 0; - if (max_width > buffer.used - location->start) { - max_width = buffer.used - location->start; - } + while (location->start < buffer.used) { + max_width = (location->stop - location->start) + 1; - while (buffer.string[location->start] == placeholder || (status = f_utf_is_graph(buffer.string + location->start, max_width)) == f_false) { - if (f_status_is_error(status)) { - return status; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; } - if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; - width = f_macro_utf_byte_width_is(buffer.string[location->start]); if (width == 0) { width = 1; + + if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; + + if (seek_width == width) { + if (buffer.string[location->start] == seek_to_this) return f_none; + } } // Do not operate on UTF-8 fragments that are not the first byte of the character. else if (width == 1) { @@ -78,30 +226,32 @@ extern "C" { else { if (location->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); if (location->start + width > location->stop) return f_status_set_error(f_incomplete_utf_on_stop); - } - - location->start += width; - if (location->start >= buffer.used) return f_none_on_eos; - if (location->start > location->stop) return f_none_on_stop; + if (width == seek_width) { + f_utf_character character = 0; + status = f_utf_char_to_character(buffer.string + location->start, max_width, &character); - max_width = (location->stop - location->start) + 1; + if (f_status_is_error(status)) { + return status; + } - if (max_width > buffer.used - location->start) { - max_width = buffer.used - location->start; + if (character == seek_to_this) { + return f_none; + } + } } - } // while - if (f_status_is_error(status)) { - return status; - } + location->start += width; - return f_none; + if (location->start >= location->stop) return f_none_on_stop; + } // while + + return f_none_on_eos; } -#endif // _di_fl_string_seek_line_until_graph_ +#endif // _di_fl_string_seek_line_to_utf_character_ -#ifndef _di_fl_string_seek_line_until_non_graph_ - f_return_status fl_string_seek_line_until_non_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder) { +#ifndef _di_fl_string_seek_line_until_graph_ + f_return_status fl_string_seek_line_until_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder) { #ifndef _di_level_1_parameter_checking_ if (location == 0) return f_status_set_error(f_invalid_parameter); if (location->start < 0) return f_status_set_error(f_invalid_parameter); @@ -119,7 +269,7 @@ extern "C" { max_width = buffer.used - location->start; } - while (buffer.string[location->start] == placeholder || (status = f_utf_is_whitespace(buffer.string + location->start, max_width)) == f_false) { + while (buffer.string[location->start] == placeholder || (status = f_utf_is_graph(buffer.string + location->start, max_width)) == f_false) { if (f_status_is_error(status)) { return status; } @@ -158,33 +308,10 @@ extern "C" { return f_none; } -#endif // _di_fl_string_seek_line_until_non_graph_ - -#ifndef _di_fl_string_seek_line_to_ - f_return_status fl_string_seek_line_to(const f_string_dynamic buffer, f_string_location *location, const int8_t seek_to_this) { - #ifndef _di_level_1_parameter_checking_ - if (location == 0) return f_status_set_error(f_invalid_parameter); - if (location->start < 0) return f_status_set_error(f_invalid_parameter); - if (location->stop < location->start) return f_status_set_error(f_invalid_parameter); - if (buffer.used <= 0) return f_status_set_error(f_invalid_parameter); - if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - while (buffer.string[location->start] != seek_to_this) { - if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; - - location->start++; - - if (location->start >= buffer.used) return f_none_on_eos; - if (location->start > location->stop) return f_none_on_stop; - } // while - - return f_none; - } -#endif // _di_fl_string_seek_line_to_ +#endif // _di_fl_string_seek_line_until_graph_ -#ifndef _di_fl_string_seek_line_to_utf_character_ - f_return_status fl_string_seek_line_to_utf_character(const f_string_dynamic buffer, f_string_location *location, const f_utf_character seek_to_this) { +#ifndef _di_fl_string_seek_line_until_non_graph_ + f_return_status fl_string_seek_line_until_non_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder) { #ifndef _di_level_1_parameter_checking_ if (location == 0) return f_status_set_error(f_invalid_parameter); if (location->start < 0) return f_status_set_error(f_invalid_parameter); @@ -193,31 +320,26 @@ extern "C" { if (location->start >= buffer.used) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - const unsigned short seek_width = f_macro_utf_character_width(seek_to_this); - f_status status = f_none; - unsigned short width = 0; - f_string_length max_width = 0; + f_string_length max_width = (location->stop - location->start) + 1; - while (location->start < buffer.used) { - max_width = (location->stop - location->start) + 1; + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; + } - if (max_width > buffer.used - location->start) { - max_width = buffer.used - location->start; + while (buffer.string[location->start] == placeholder || (status = f_utf_is_whitespace(buffer.string + location->start, max_width)) == f_false) { + if (f_status_is_error(status)) { + return status; } + if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; + width = f_macro_utf_byte_width_is(buffer.string[location->start]); if (width == 0) { width = 1; - - if (buffer.string[location->start] == f_string_eol) return f_none_on_eol; - - if (seek_width == width) { - if (buffer.string[location->start] == seek_to_this) return f_none; - } } // Do not operate on UTF-8 fragments that are not the first byte of the character. else if (width == 1) { @@ -226,29 +348,27 @@ extern "C" { else { if (location->start + width >= buffer.used) return f_status_set_error(f_incomplete_utf_on_eos); if (location->start + width > location->stop) return f_status_set_error(f_incomplete_utf_on_stop); - - if (width == seek_width) { - f_utf_character character = 0; - status = f_utf_char_to_character(buffer.string + location->start, max_width, &character); - - if (f_status_is_error(status)) { - return status; - } - - if (character == seek_to_this) { - return f_none; - } - } } location->start += width; - if (location->start >= location->stop) return f_none_on_stop; + if (location->start >= buffer.used) return f_none_on_eos; + if (location->start > location->stop) return f_none_on_stop; + + max_width = (location->stop - location->start) + 1; + + if (max_width > buffer.used - location->start) { + max_width = buffer.used - location->start; + } } // while - return f_none_on_eos; + if (f_status_is_error(status)) { + return status; + } + + return f_none; } -#endif // _di_fl_string_seek_line_to_utf_character_ +#endif // _di_fl_string_seek_line_until_non_graph_ #ifndef _di_fl_string_seek_to_ f_return_status fl_string_seek_to(const f_string_dynamic buffer, f_string_location *location, const int8_t seek_to_this) { @@ -336,126 +456,6 @@ extern "C" { } #endif // _di_fl_string_seek_to_utf_character_ -#ifndef _di_fl_string_compare_ - f_return_status fl_string_compare(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2) { - #ifndef _di_level_1_parameter_checking_ - if (length1 <= 0) return f_status_set_error(f_invalid_parameter); - if (length2 <= 0) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - f_string_length i1 = 0; - f_string_length i2 = 0; - - for (; i1 < length1 && i2 < length2; i1++, i2++) { - // skip past newlines in string1. - while (i1 < length1 && string1[i1] == f_string_eos) i1++; - if (i1 == length1) break; - - // skip past newlines in string2. - while (i2 < length2 && string2[i2] == f_string_eos) i2++; - if (i2 == length2) break; - - if (string1[i1] != string2[i2]) return f_not_equal_to; - } // for - - // only return f_equal_to if all remaining characters are NULL. - while (i1 < length1) { - if (string1[i1] != f_string_eos) return f_not_equal_to; - i1++; - } // while - - while (i2 < length2) { - if (string2[i2] != f_string_eos) return f_not_equal_to; - i2++; - } // while - - return f_equal_to; - } -#endif // _di_fl_string_compare_ - -#ifndef _di_fl_string_dynamics_compare_ - f_return_status fl_string_dynamics_compare(const f_string_dynamic string1, const f_string_dynamic string2) { - #ifndef _di_level_1_parameter_checking_ - if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); - if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - f_string_length i1 = 0; - f_string_length i2 = 0; - - for (; i1 < string1.used && i2 < string2.used; i1++, i2++) { - // skip past newlines in string1. - while (i1 < string1.used && string1.string[i1] == f_string_eos) i1++; - if (i1 == string1.used) break; - - // skip past newlines in string2. - while (i2 < string2.used && string2.string[i2] == f_string_eos) i2++; - if (i2 == string2.used) break; - - if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; - } // for - - // only return f_equal_to if all remaining characters are NULL. - while (i1 < string1.used) { - if (string1.string[i1] != f_string_eos) return f_not_equal_to; - i1++; - } // while - - while (i2 < string2.used) { - if (string2.string[i2] != f_string_eos) return f_not_equal_to; - i2++; - } // while - - return f_equal_to; - } -#endif // _di_fl_string_dynamics_compare_ - -#ifndef _di_fl_string_dynamic_partial_compare_ - f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2) { - #ifndef _di_level_1_parameter_checking_ - if (string1.used <= 0) return f_status_set_error(f_invalid_parameter); - if (string2.used <= 0) return f_status_set_error(f_invalid_parameter); - - if (offset1.start > offset1.stop) return f_status_set_error(f_invalid_parameter); - if (offset2.start > offset2.stop) return f_status_set_error(f_invalid_parameter); - - if (string1.used <= offset1.stop) return f_status_set_error(f_invalid_parameter); - if (string2.used <= offset2.stop) return f_status_set_error(f_invalid_parameter); - #endif // _di_level_1_parameter_checking_ - - f_string_length i1 = offset1.start; - f_string_length i2 = offset2.start; - - const f_string_length stop1 = offset1.stop + 1; - const f_string_length stop2 = offset2.stop + 1; - - for (; i1 < stop1 && i2 < stop2; i1++, i2++) { - // skip past newlines in string1. - while (i1 < stop1 && string1.string[i1] == f_string_eos) i1++; - if (i1 == stop1) break; - - // skip past newlines in string2. - while (i2 < stop2 && string2.string[i2] == f_string_eos) i2++; - if (i2 == stop2) break; - - if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; - } // for - - // only return f_equal_to if all remaining characters are NULL. - while (i1 < stop1) { - if (string1.string[i1] != f_string_eos) return f_not_equal_to; - i1++; - } // while - - while (i2 < stop2) { - if (string2.string[i2] != f_string_eos) return f_not_equal_to; - i2++; - } // while - - return f_equal_to; - } -#endif // _di_fl_string_dynamic_partial_compare_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index dc97956..9e257d6 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -26,6 +26,83 @@ extern "C" { #endif /** + * Compare two strings, similar to strncmp(). + * + * This does not stop on NULL. + * NULL characters are ignored. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param length1 + * Length of string1. + * @param length2 + * Length of string2. + * + * @return + * f_equal_to when both strings equal. + * f_not_equal_to when both strings do not equal. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * + * @see f_string_dynamics_compare() + * @see fl_string_dynamic_partial_compare() + */ +#ifndef _di_fl_string_compare_ + extern f_return_status fl_string_compare(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2); +#endif // _di_fl_string_compare_ + +/** + * Compare two strings, similar to strncmp(). + * + * This does not stop on NULL. + * NULL characters are ignored. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * + * @return + * f_equal_to when both strings equal. + * f_not_equal_to when both strings do not equal. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * + * @see fl_string_compare() + * @see fl_string_dynamic_partial_compare() + */ +#ifndef _di_f_string_dynamics_compare_ + extern f_return_status f_string_dynamics_compare(const f_string_dynamic string1, const f_string_dynamic string2); +#endif // _di_f_string_dynamics_compare_ + +/** + * Compare two strings, similar to strncmp(), but restricted to the given ranges. + * + * This does not stop on NULL. + * NULL characters are ignored. + * + * @param string1 + * String to compare. + * @param string2 + * String to compare. + * @param offset1 + * A range within the string1 to restrict the comparison to. + * @param offset2 + * A range within the string2 to restrict the comparison to. + * + * @return + * f_equal_to when both strings equal. + * f_not_equal_to when both strings do not equal. + * f_invalid_parameter (with error bit) if a parameter is invalid. + * + * @see fl_string_compare() + * @see f_string_dynamics_compare() + */ +#ifndef _di_fl_string_dynamic_partial_compare_ + extern f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2); +#endif // _di_fl_string_dynamic_partial_compare_ + +/** * Allocated a new string from the provided range in the buffer. * * @param buffer @@ -47,106 +124,106 @@ extern "C" { #endif // _di_fl_string_rip_ /** - * Increment buffer location until a graph character (including UTF-8) or an EOL is matched. + * Seek the buffer location forward until the character (1-byte wide) or EOL is reached. * * @param buffer * The buffer to traverse. * @param location * A range within the buffer representing the start and stop locations. - * @param placeholder - * A single-width character representing a placeholder to ignore (may be NULL). + * The start location will be incremented by seek. + * @param seek_to_this + * A single-width character representing a character to seek to. * * @return * f_none on success. * f_none_on_eol on success, but stopped at EOL. * f_none_on_eos on success, but stopped at end of buffer. - * f_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. - * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. - * f_incomplete_utf_on_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. + * f_none_on_stop on success, but stopped stop location. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_allocation_error (with error bit) on memory allocation error. - * f_reallocation_error (with error bit) on memory reallocation error. + * + * @see fl_string_seek_line_to_utf_character() */ -#ifndef _di_fl_string_seek_line_until_graph_ - extern f_return_status fl_string_seek_line_until_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder); -#endif // _di_fl_string_seek_line_until_graph_ +#ifndef _di_fl_string_seek_line_to_ + extern f_return_status fl_string_seek_line_to(const f_string_dynamic buffer, f_string_location *location, const int8_t seek_to_this); +#endif // _di_fl_string_seek_line_to_ /** - * Increment buffer location until a non-graph character (including UTF-8) or an EOL is matched. + * Seek the buffer location forward until the character (up to 4-byte wide) or EOL is reached. * * @param buffer * The buffer to traverse. * @param location * A range within the buffer representing the start and stop locations. - * @param placeholder - * A single-width character representing a placeholder to ignore (may be NULL). + * The start location will be incremented by seek. + * @param seek_to_this + * A 1-width, 2-width, 3-width, or 4-width character representing a character to seek to. * * @return * f_none on success. * f_none_on_eol on success, but stopped at EOL. * f_none_on_eos on success, but stopped at end of buffer. - * f_none_on_stop on success, but stopped stop location. + * f_invalid_utf (with error bit) if character is an invalid UTF-8 character. * f_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * f_incomplete_utf_on_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_allocation_error (with error bit) on memory allocation error. - * f_reallocation_error (with error bit) on memory reallocation error. + * + * @see fl_string_seek_line_to() */ -#ifndef _di_fl_string_seek_line_until_non_graph_ - extern f_return_status fl_string_seek_line_until_non_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder); -#endif // _di_fl_string_seek_line_until_non_graph_ +#ifndef _di_fl_string_seek_line_to_utf_character_ + extern f_return_status fl_string_seek_line_to_utf_character(const f_string_dynamic buffer, f_string_location *location, const f_utf_character seek_to_this); +#endif // _di_fl_string_seek_line_to_utf_character_ /** - * Seek the buffer location forward until the character (1-byte wide) or EOL is reached. + * Increment buffer location until a graph character (including UTF-8) or an EOL is matched. * * @param buffer * The buffer to traverse. * @param location * A range within the buffer representing the start and stop locations. - * The start location will be incremented by seek. - * @param seek_to_this - * A single-width character representing a character to seek to. + * @param placeholder + * A single-width character representing a placeholder to ignore (may be NULL). * * @return * f_none on success. * f_none_on_eol on success, but stopped at EOL. * f_none_on_eos on success, but stopped at end of buffer. - * f_none_on_stop on success, but stopped stop location. + * f_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. + * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * f_incomplete_utf_on_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * f_invalid_parameter (with error bit) if a parameter is invalid. - * - * @see fl_string_seek_line_to_utf_character() + * f_allocation_error (with error bit) on memory allocation error. + * f_reallocation_error (with error bit) on memory reallocation error. */ -#ifndef _di_fl_string_seek_line_to_ - extern f_return_status fl_string_seek_line_to(const f_string_dynamic buffer, f_string_location *location, const int8_t seek_to_this); -#endif // _di_fl_string_seek_line_to_ +#ifndef _di_fl_string_seek_line_until_graph_ + extern f_return_status fl_string_seek_line_until_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder); +#endif // _di_fl_string_seek_line_until_graph_ /** - * Seek the buffer location forward until the character (up to 4-byte wide) or EOL is reached. + * Increment buffer location until a non-graph character (including UTF-8) or an EOL is matched. * * @param buffer * The buffer to traverse. * @param location * A range within the buffer representing the start and stop locations. - * The start location will be incremented by seek. - * @param seek_to_this - * A 1-width, 2-width, 3-width, or 4-width character representing a character to seek to. + * @param placeholder + * A single-width character representing a placeholder to ignore (may be NULL). * * @return * f_none on success. * f_none_on_eol on success, but stopped at EOL. * f_none_on_eos on success, but stopped at end of buffer. - * f_invalid_utf (with error bit) if character is an invalid UTF-8 character. + * f_none_on_stop on success, but stopped stop location. * f_incomplete_utf (with error bit) if character is an incomplete UTF-8 fragment. * f_incomplete_utf_on_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. * f_incomplete_utf_on_eos (with error bit) if end of string is reached before a complete UTF-8 character can be processed. * f_invalid_parameter (with error bit) if a parameter is invalid. - * - * @see fl_string_seek_line_to() + * f_allocation_error (with error bit) on memory allocation error. + * f_reallocation_error (with error bit) on memory reallocation error. */ -#ifndef _di_fl_string_seek_line_to_utf_character_ - extern f_return_status fl_string_seek_line_to_utf_character(const f_string_dynamic buffer, f_string_location *location, const f_utf_character seek_to_this); -#endif // _di_fl_string_seek_line_to_utf_character_ +#ifndef _di_fl_string_seek_line_until_non_graph_ + extern f_return_status fl_string_seek_line_until_non_graph(const f_string_dynamic buffer, f_string_location *location, const int8_t placeholder); +#endif // _di_fl_string_seek_line_until_non_graph_ /** * Seek the buffer location forward until the character (1-byte wide) is reached. @@ -201,83 +278,6 @@ extern "C" { extern f_return_status fl_string_seek_to_utf_character(const f_string_dynamic buffer, f_string_location *location, const f_utf_character seek_to_this); #endif // _di_fl_string_seek_to_utf_character_ -/** - * Compare two strings, similar to strncmp(). - * - * This does not stop on NULL. - * NULL characters are ignored. - * - * @param string1 - * String to compare. - * @param string2 - * String to compare. - * @param length1 - * Length of string1. - * @param length2 - * Length of string2. - * - * @return - * f_equal_to when both strings equal. - * f_not_equal_to when both strings do not equal. - * f_invalid_parameter (with error bit) if a parameter is invalid. - * - * @see fl_string_dynamics_compare() - * @see fl_string_dynamic_partial_compare() - */ -#ifndef _di_fl_string_compare_ - extern f_return_status fl_string_compare(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2); -#endif // _di_fl_string_compare_ - -/** - * Compare two strings, similar to strncmp(). - * - * This does not stop on NULL. - * NULL characters are ignored. - * - * @param string1 - * String to compare. - * @param string2 - * String to compare. - * - * @return - * f_equal_to when both strings equal. - * f_not_equal_to when both strings do not equal. - * f_invalid_parameter (with error bit) if a parameter is invalid. - * - * @see fl_string_compare() - * @see fl_string_dynamic_partial_compare() - */ -#ifndef _di_fl_string_dynamics_compare_ - extern f_return_status fl_string_dynamics_compare(const f_string_dynamic string1, const f_string_dynamic string2); -#endif // _di_fl_string_dynamics_compare_ - -/** - * Compare two strings, similar to strncmp(), but restricted to the given ranges. - * - * This does not stop on NULL. - * NULL characters are ignored. - * - * @param string1 - * String to compare. - * @param string2 - * String to compare. - * @param offset1 - * A range within the string1 to restrict the comparison to. - * @param offset2 - * A range within the string2 to restrict the comparison to. - * - * @return - * f_equal_to when both strings equal. - * f_not_equal_to when both strings do not equal. - * f_invalid_parameter (with error bit) if a parameter is invalid. - * - * @see fl_string_compare() - * @see fl_string_dynamics_compare() - */ -#ifndef _di_fl_string_dynamic_partial_compare_ - extern f_return_status fl_string_dynamic_partial_compare(const f_string_dynamic string1, const f_string_dynamic string2, const f_string_location offset1, const f_string_location offset2); -#endif // _di_fl_string_dynamic_partial_compare_ - #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 bea7008..1f9b999 100644 --- a/level_2/fll_fss/c/fss_status.c +++ b/level_2/fll_fss/c/fss_status.c @@ -5,9 +5,9 @@ extern "C" { #endif #ifndef _di_fll_fss_status_from_string_ - f_return_status fll_fss_status_from_string(const f_string string, f_status *error) { + f_return_status fll_fss_status_from_string(const f_string string, f_status *code) { #ifndef _di_level_1_parameter_checking_ - if (error == 0) return f_status_set_error(f_invalid_parameter); + if (code == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_none; @@ -28,79 +28,79 @@ extern "C" { #ifndef _di_fll_fss_status_error_ if (fl_string_compare(string, fll_fss_status_string_invalid_format, length, fll_fss_status_string_invalid_format_length) == f_equal_to) { - *error = fl_fss_invalid_format; + *code = fl_fss_invalid_format; return f_none; } if (fl_string_compare(string, fll_fss_status_string_invalid_format_eos, length, fll_fss_status_string_invalid_format_eos_length) == f_equal_to) { - *error = fl_fss_invalid_format_eos; + *code = fl_fss_invalid_format_eos; return f_none; } #endif // _di_fll_fss_status_error_ #ifndef _di_fll_fss_status_warning_ if (fl_string_compare(string, fll_fss_status_string_no_header, length, fll_fss_status_string_no_header_length) == f_equal_to) { - *error = fl_fss_no_header; + *code = fl_fss_no_header; return f_none; } if (fl_string_compare(string, fll_fss_status_string_accepted_but_invalid, length, fll_fss_status_string_accepted_but_invalid_length) == f_equal_to) { - *error = fl_fss_accepted_but_invalid; + *code = fl_fss_accepted_but_invalid; return f_none; } if (fl_string_compare(string, fll_fss_status_string_no_header_eos, length, fll_fss_status_string_no_header_eos_length) == f_equal_to) { - *error = fl_fss_no_header_eos; + *code = fl_fss_no_header_eos; return f_none; } if (fl_string_compare(string, fll_fss_status_string_accepted_but_invalid_eos, length, fll_fss_status_string_accepted_but_invalid_eos_length) == f_equal_to) { - *error = fl_fss_accepted_but_invalid_eos; + *code = fl_fss_accepted_but_invalid_eos; return f_none; } #endif // _di_fll_fss_status_warning_ #ifndef _di_fll_fss_status_success_ if (fl_string_compare(string, fll_fss_status_string_found_object, length, fll_fss_status_string_found_object_length) == f_equal_to) { - *error = fl_fss_found_object; + *code = fl_fss_found_object; return f_none; } if (fl_string_compare(string, fll_fss_status_string_found_content, length, fll_fss_status_string_found_content_length) == f_equal_to) { - *error = fl_fss_found_content; + *code = fl_fss_found_content; return f_none; } if (fl_string_compare(string, fll_fss_status_string_found_no_object, length, fll_fss_status_string_found_no_object_length) == f_equal_to) { - *error = fl_fss_found_no_object; + *code = fl_fss_found_no_object; return f_none; } if (fl_string_compare(string, fll_fss_status_string_found_no_content, length, fll_fss_status_string_found_no_content_length) == f_equal_to) { - *error = fl_fss_found_no_content; + *code = fl_fss_found_no_content; return f_none; } if (fl_string_compare(string, fll_fss_status_string_found_object_no_content, length, fll_fss_status_string_found_object_no_content_length) == f_equal_to) { - *error = fl_fss_found_object_no_content; + *code = fl_fss_found_object_no_content; return f_none; } #endif // _di_fll_fss_status_success_ #ifndef _di_fll_fss_status_codes_ if (fl_string_compare(string, fll_fss_status_string_found_comment, length, fll_fss_status_string_found_comment_length) == f_equal_to) { - *error = fl_fss_found_object; + *code = fl_fss_found_object; return f_none; } #endif // _di_fll_fss_status_codes_ if (fl_string_compare(string, fll_fss_status_string_status_code_first, length, fll_fss_status_string_status_code_first_length) == f_equal_to) { - *error = fl_fss_status_code_first; + *code = fl_fss_status_code_first; return f_none; } if (fl_string_compare(string, fll_fss_status_string_status_code_last, length, fll_fss_status_string_status_code_last_length) == f_equal_to) { - *error = fl_fss_status_code_last; + *code = fl_fss_status_code_last; return f_none; } @@ -109,14 +109,14 @@ extern "C" { #endif // _di_fll_fss_status_from_string_ #ifndef _di_fll_fss_status_to_string_ - f_return_status fll_fss_status_to_string(const f_status error, f_string *string) { + f_return_status fll_fss_status_to_string(const f_status code, f_string *string) { #ifndef _di_level_2_parameter_checking_ if (string == 0) return f_status_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status unmasked_error = f_status_set_fine(error); + f_status unmasked_code = f_status_set_fine(code); - switch (unmasked_error) { + switch (unmasked_code) { #ifndef _di_fll_fss_status_error_ case fl_fss_invalid_format: *string = fll_fss_status_string_invalid_format; @@ -174,7 +174,7 @@ extern "C" { break; default: - return fl_status_to_string(error, string); + return fl_status_to_string(code, string); } return f_none; @@ -182,11 +182,11 @@ extern "C" { #endif // _di_fll_status_to_string_ #ifndef _di_fll_fss_status_is_error_ - f_return_status fll_fss_status_is_error(const f_status error) { - if (fll_fss_status_is_fine(error) == f_true) { + f_return_status fll_fss_status_is_error(const f_status code) { + if (fll_fss_status_is_fine(code) == f_true) { return f_false; } - else if (fll_fss_status_is_warning(error) == f_true) { + else if (fll_fss_status_is_warning(code) == f_true) { return f_false; } @@ -195,8 +195,8 @@ extern "C" { #endif // _di_fll_fss_status_is_error_ #ifndef _di_fll_fss_status_is_warning_ - f_return_status fll_fss_status_is_warning(const f_status error) { - switch (error) { + f_return_status fll_fss_status_is_warning(const f_status code) { + switch (code) { #ifndef _di_fll_fss_status_basic_ case f_no_data: return f_true; @@ -223,8 +223,8 @@ extern "C" { #endif // _di_fll_fss_status_is_warning_ #ifndef _di_fll_fss_status_is_fine_ - f_return_status fll_fss_status_is_fine(const f_status error) { - switch (error) { + f_return_status fll_fss_status_is_fine(const f_status code) { + switch (code) { #ifndef _di_fll_fss_status_booleans_ case f_false: return f_true; diff --git a/level_2/fll_fss/c/fss_status.h b/level_2/fll_fss/c/fss_status.h index 3cb3ef6..417844c 100644 --- a/level_2/fll_fss/c/fss_status.h +++ b/level_2/fll_fss/c/fss_status.h @@ -32,11 +32,11 @@ extern "C" { #ifndef _di_fll_fss_status_string_ #ifndef _di_fll_fss_status_error_ - #define fll_fss_status_string_invalid_format "invalid_format" - #define fll_fss_status_string_invalid_format_length 15 + #define fll_fss_status_string_invalid_format "fl_fss_invalid_format" + #define fll_fss_status_string_invalid_format_length 22 - #define fll_fss_status_string_invalid_format_eos "invalid_format_eos" - #define fll_fss_status_string_invalid_format_eos_length 19 + #define fll_fss_status_string_invalid_format_eos "fl_fss_invalid_format_eos" + #define fll_fss_status_string_invalid_format_eos_length 26 #endif // _di_fll_fss_status_error_ #ifndef _di_fll_fss_status_warning_ @@ -85,56 +85,56 @@ extern "C" { /** * Convert FSS status codes from their string equivalents to a status code. * - * Error, warning, and signal flags will not be assigned to the error. + * Error, warning, and signal flags will not be assigned to the code. * * This process the string until either a match or NULL is reached. * * @param string - * The error name to process. - * @param error - * The error code a matched string represents. + * The code name to process. + * @param code + * The code code a matched string represents. * * @return * f_none on success. * f_no_data if string is empty. - * f_invalid_data if not found. + * f_invalid_data (with error bit) if not found. * f_invalid_parameter (with error bit) if a parameter is invalid. * * @see fll_status_from_string */ #ifndef _di_fll_fss_status_from_string_ - extern f_return_status fll_fss_status_from_string(const f_string string, f_status *error); + extern f_return_status fll_fss_status_from_string(const f_string string, f_status *code); #endif // _di_fll_fss_status_to_string_ #ifndef _di_fll_fss_status_to_string_ /** - * Convert error codes to their string equivalents. + * Convert code codes to their string equivalents. */ - extern f_return_status fll_fss_status_to_string(const f_status error, f_string *string); + extern f_return_status fll_fss_status_to_string(const f_status code, f_string *string); #endif // _di_fll_status_to_string_ #ifndef _di_fll_fss_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 error codes are context-specific and may be reported as an error here when it is in fact not an error. + * Returns true or false depending on whether the standard context of the code code represents an code. + * Keep in mind that many of the code codes are context-specific and may be reported as an code here when it is in fact not an code. */ - extern f_return_status fll_fss_status_is_error(const f_status error); + extern f_return_status fll_fss_status_is_error(const f_status code); #endif // _di_fll_fss_status_is_error_ #ifndef _di_fll_fss_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 error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + * Returns true or false depending on whether the standard context of the code code represents a warning. + * Keep in mind that many of the code 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_status_is_warning(const f_status error); + extern f_return_status fll_fss_status_is_warning(const f_status code); #endif // _di_fll_fss_status_is_warning_ #ifndef _di_fll_fss_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 error codes are context-specific and may be reported as "fine" here when it is in fact not fine. + * Returns true or false depending on whether the standard context of the code code represents an normal return status and not an code. + * Keep in mind that many of the code codes are context-specific and may be reported as "fine" here when it is in fact not fine. */ - extern f_return_status fll_fss_status_is_fine(const f_status error); + extern f_return_status fll_fss_status_is_fine(const f_status code); #endif // _di_fll_fss_status_is_fine_ #ifdef __cplusplus diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 4ab170a..1d1205f 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -83,11 +83,11 @@ extern "C" { f_status status = f_none; f_status allocation_status = f_none; - status = fl_console_parameter_process(arguments, parameters, remaining); + status = f_console_parameter_process(arguments, parameters, remaining); f_console_parameter_id decision = choices.id[2]; - fl_console_parameter_prioritize(parameters, choices, &decision); + f_console_parameter_prioritize(parameters, choices, &decision); // load colors unless told not to. if (decision != choices.id[0]) { @@ -115,19 +115,19 @@ extern "C" { } else if (status == f_invalid_utf) { fl_color_print(f_standard_error, context->error, context->reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling "); - fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print(f_standard_error, context->notable, context->reset, "f_console_parameter_process()"); fl_color_print_line(f_standard_error, context->error, context->reset, "."); } else if (status == f_invalid_parameter) { fl_color_print(f_standard_error, context->error, context->reset, "INTERNAL ERROR: Invalid parameter when calling "); - fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print(f_standard_error, context->notable, context->reset, "f_console_parameter_process()"); fl_color_print_line(f_standard_error, context->error, context->reset, "."); } else { fl_color_print(f_standard_error, context->error, context->reset, "INTERNAL ERROR: An unhandled error ("); fl_color_print(f_standard_error, context->notable, context->reset, "%u", status); fl_color_print(f_standard_error, context->error, context->reset, ") has occured while calling "); - fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print(f_standard_error, context->notable, context->reset, "f_console_parameter_process()"); fl_color_print_line(f_standard_error, context->error, context->reset, "."); } diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index da45dd1..31b341b 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -21,7 +21,6 @@ // fll-1 includes #include -#include #ifdef __cplusplus extern "C" { diff --git a/level_2/fll_program/data/build/dependencies b/level_2/fll_program/data/build/dependencies index 79cc2f4..33e491a 100644 --- a/level_2/fll_program/data/build/dependencies +++ b/level_2/fll_program/data/build/dependencies @@ -4,4 +4,3 @@ f_memory f_string f_console fl_color -fl_console diff --git a/level_2/fll_program/data/build/settings b/level_2/fll_program/data/build/settings index dc05494..af125a6 100644 --- a/level_2/fll_program/data/build/settings +++ b/level_2/fll_program/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfl_console -lf_utf -lfl_color -lf_print -lf_file -lf_console -lf_memory +build_libraries_fll -lfl_color -lf_utf -lf_print -lf_file -lf_console -lf_memory build_sources_library program.c build_sources_program build_sources_headers program.h diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index eee8dd0..57337b3 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -684,6 +684,11 @@ extern "C" { return f_none; } + if (fl_string_compare(string, fl_status_string_whole_number, length, fl_status_string_whole_number_length) == f_equal_to) { + *code = f_whole_number; + return f_none; + } + if (fl_string_compare(string, fl_status_string_invalid_number, length, fl_status_string_invalid_number_length) == f_equal_to) { *code = f_invalid_number; return f_none; @@ -857,6 +862,11 @@ extern "C" { *code = f_reallocation_error; return f_none; } + + if (fl_string_compare(string, fl_status_string_deallocation_error, length, fl_status_string_deallocation_error_length) == f_equal_to) { + *code = f_deallocation_error; + return f_none; + } #endif // _di_fll_status_allocation_ #ifndef _di_fll_status_fork_ @@ -947,6 +957,11 @@ extern "C" { return f_none; } + if (fl_string_compare(string, fl_status_string_file_deallocation_error, length, fl_status_string_file_deallocation_error_length) == f_equal_to) { + *code = f_file_deallocation_error; + return f_none; + } + if (fl_string_compare(string, fl_status_string_file_stat_error, length, fl_status_string_file_stat_error_length) == f_equal_to) { *code = f_file_stat_error; return f_none; diff --git a/level_3/byte_dump/c/byte_dump.c b/level_3/byte_dump/c/byte_dump.c index bcb019b..f3be9f3 100644 --- a/level_3/byte_dump/c/byte_dump.c +++ b/level_3/byte_dump/c/byte_dump.c @@ -91,7 +91,7 @@ extern "C" { choices.id = ids; choices.used = 5; - status = fl_console_parameter_prioritize(parameters, choices, &choice); + status = f_console_parameter_prioritize(parameters, choices, &choice); if (f_status_is_error(status)) { byte_dump_delete_data(data); @@ -122,7 +122,7 @@ extern "C" { choices.id = ids; choices.used = 3; - status = fl_console_parameter_prioritize(parameters, choices, &choice); + status = f_console_parameter_prioritize(parameters, choices, &choice); if (f_status_is_error(status)) { byte_dump_delete_data(data); @@ -143,7 +143,6 @@ extern "C" { status = f_none; - // Execute parameter results. if (data->parameters[byte_dump_parameter_help].result == f_console_result_found) { byte_dump_print_help(*data); } diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 309cfdd..629c93f 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -73,7 +73,6 @@ extern "C" { status = f_none; - // Execute parameter results. if (data->parameters[firewall_parameter_help].result == f_console_result_found) { firewall_print_help(*data); } diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index 49c97ab..67eb683 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -133,7 +133,6 @@ extern "C" { status = f_none; } - // Execute parameter results. if (data->parameters[fss_basic_list_read_parameter_help].result == f_console_result_found) { fss_basic_list_read_print_help(*data); } diff --git a/level_3/fss_basic_list_read/data/build/settings b/level_3/fss_basic_list_read/data/build/settings index b8d57e2..e868d7b 100644 --- a/level_3/fss_basic_list_read/data/build/settings +++ b/level_3/fss_basic_list_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_basic_list_read.c private-fss_basic_list_read.c diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index 37284a7..6dd0a50 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -45,7 +45,6 @@ extern "C" { status = f_none; - // Execute parameter results. if (data->parameters[fss_basic_list_write_parameter_help].result == f_console_result_found) { fss_basic_list_write_print_help(*data); } diff --git a/level_3/fss_basic_list_write/data/build/settings b/level_3/fss_basic_list_write/data/build/settings index 3d9820b..b99d6a9 100644 --- a/level_3/fss_basic_list_write/data/build/settings +++ b/level_3/fss_basic_list_write/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_basic_list_write.c diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 123b2a3..21dbb09 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -133,7 +133,6 @@ extern "C" { status = f_none; } - // Execute parameter results. if (data->parameters[fss_basic_read_parameter_help].result == f_console_result_found) { fss_basic_read_print_help(*data); } diff --git a/level_3/fss_basic_read/data/build/settings b/level_3/fss_basic_read/data/build/settings index a645866..84b96e8 100644 --- a/level_3/fss_basic_read/data/build/settings +++ b/level_3/fss_basic_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_basic_read.c private-fss_basic_read.c diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index dfb4532..5807453 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -45,7 +45,6 @@ extern "C" { status = f_none; - // Execute parameter results. if (data->parameters[fss_basic_write_parameter_help].result == f_console_result_found) { fss_basic_write_print_help(*data); } diff --git a/level_3/fss_basic_write/data/build/settings b/level_3/fss_basic_write/data/build/settings index 44cc613..79c15cb 100644 --- a/level_3/fss_basic_write/data/build/settings +++ b/level_3/fss_basic_write/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_basic_write.c diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.c b/level_3/fss_extended_list_read/c/fss_extended_list_read.c index 9a89a81..92e29e7 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.c @@ -126,7 +126,6 @@ extern "C" { f_status status2 = f_none; - // Execute parameter results. if (data->parameters[fss_extended_list_read_parameter_help].result == f_console_result_found) { fss_extended_list_read_print_help(*data); } diff --git a/level_3/fss_extended_list_read/data/build/settings b/level_3/fss_extended_list_read/data/build/settings index ef71199..ee7055b 100644 --- a/level_3/fss_extended_list_read/data/build/settings +++ b/level_3/fss_extended_list_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_extended_list_read.c private-fss_extended_list_read.c diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 23b8684..e314a3d 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -133,7 +133,6 @@ extern "C" { status = f_none; } - // Execute parameter results. if (data->parameters[fss_extended_read_parameter_help].result == f_console_result_found) { fss_extended_read_print_help(*data); } diff --git a/level_3/fss_extended_read/data/build/settings b/level_3/fss_extended_read/data/build/settings index 1b4a0fa..f25b633 100644 --- a/level_3/fss_extended_read/data/build/settings +++ b/level_3/fss_extended_read/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_extended_read.c private-fss_extended_read.c diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index 1b4d3fd..01e6632 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -59,20 +59,19 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_invalid_utf) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling fl_console_parameter_process()."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling f_console_parameter_process()."); } else if (status == f_invalid_parameter) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_console_parameter_process()."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_console_parameter_process()."); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_console_parameter_process().", status); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_console_parameter_process().", status); } fss_extended_write_delete_data(data); return f_status_set_error(status); } - // Execute parameter results. if (data->parameters[fss_extended_write_parameter_help].result == f_console_result_found) { fss_extended_write_print_help(*data); } diff --git a/level_3/fss_extended_write/c/fss_extended_write.h b/level_3/fss_extended_write/c/fss_extended_write.h index eb79264..f06918f 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.h +++ b/level_3/fss_extended_write/c/fss_extended_write.h @@ -23,7 +23,6 @@ // fll-1 includes #include -#include #include #include #include diff --git a/level_3/fss_extended_write/data/build/dependencies b/level_3/fss_extended_write/data/build/dependencies index fd8beec..2f284aa 100644 --- a/level_3/fss_extended_write/data/build/dependencies +++ b/level_3/fss_extended_write/data/build/dependencies @@ -7,7 +7,6 @@ f_fss f_pipe f_print fl_color -fl_console fl_directory fl_file fl_fss diff --git a/level_3/fss_extended_write/data/build/settings b/level_3/fss_extended_write/data/build/settings index 162ecf9..95818e5 100644 --- a/level_3/fss_extended_write/data/build/settings +++ b/level_3/fss_extended_write/data/build/settings @@ -10,7 +10,7 @@ version_micro 0 build_compiler gcc build_linker ar build_libraries -lc -build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_console -lf_utf -lfl_color -lf_file -lf_print -lf_pipe -lf_console -lf_memory +build_libraries_fll -lfll_program -lfll_fss -lfll_execute -lfl_string -lfl_status -lfl_fss -lf_conversion -lfl_file -lfl_directory -lfl_color -lf_utf -lf_file -lf_print -lf_pipe -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll build_sources_library fss_extended_write.c 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 693bfd5..5f998d2 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -1,4 +1,5 @@ #include +#include "private-fss_status_code.h" #ifdef __cplusplus extern "C" { @@ -16,9 +17,9 @@ extern "C" { printf("%c", f_string_eol); - fll_program_print_help_option(data.context, fss_status_code_short_is_fine, fss_status_code_long_is_fine, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is not an error."); - fll_program_print_help_option(data.context, fss_status_code_short_is_warning, fss_status_code_long_is_warning, f_console_symbol_short_enable, f_console_symbol_long_enable, "Print f_true if the error code is a warning."); - fll_program_print_help_option(data.context, fss_status_code_short_is_error, fss_status_code_long_is_error, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is an error."); + fll_program_print_help_option(data.context, fss_status_code_short_is_fine, fss_status_code_long_is_fine, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is not an error, f_false otherwise."); + fll_program_print_help_option(data.context, fss_status_code_short_is_warning, fss_status_code_long_is_warning, f_console_symbol_short_enable, f_console_symbol_long_enable, "Print f_true if the error code is a warning, f_false otherwise."); + fll_program_print_help_option(data.context, fss_status_code_short_is_error, fss_status_code_long_is_error, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is an error, f_false otherwise."); fll_program_print_help_option(data.context, fss_status_code_short_number, fss_status_code_long_number, f_console_symbol_short_enable, f_console_symbol_long_enable, " Convert status code name to number."); fll_program_print_help_usage(data.context, fss_status_code_name, "status code(s)"); @@ -44,208 +45,104 @@ extern "C" { return f_status_set_error(status); } + f_status status2 = f_none; status = f_none; - // Execute parameter results. if (data->parameters[fss_status_code_parameter_help].result == f_console_result_found) { fss_status_code_print_help(*data); + fss_status_code_delete_data(data); + return f_none; } else if (data->parameters[fss_status_code_parameter_version].result == f_console_result_found) { fll_program_print_version(fss_status_code_version); + fss_status_code_delete_data(data); + return f_none; } - else if (data->parameters[fss_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; - unsigned int is_true = 0; - - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } + if (data->parameters[fss_status_code_parameter_is_error].result == f_console_result_found) { + if (data->parameters[fss_status_code_parameter_is_warning].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_error); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_warning); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } - - code = (f_status) number; - is_true = f_status_is_error(code) && !f_status_is_warning(code); - - if (status == f_none) { - status = f_true; - } - - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); - } - } // for + fss_status_code_delete_data(data); + return f_status_set_error(status); } - else { - status = f_false; + else if (data->parameters[fss_status_code_parameter_is_fine].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_error); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_fine); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); + + fss_status_code_delete_data(data); + return f_status_set_error(status); } } - 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; - unsigned int is_true = 0; - - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } + else if (data->parameters[fss_status_code_parameter_is_warning].result == f_console_result_found && data->parameters[fss_status_code_parameter_is_fine].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_warning); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_status_code_long_is_fine); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } - - code = (f_status) number; - is_true = f_status_is_warning(code) && !f_status_is_error(code); - - if (status == f_none) { - status = f_true; - } - - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); - } - } // for - } - else { - status = f_false; - } + fss_status_code_delete_data(data); + return f_status_set_error(status); } - 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; - unsigned int is_true = 0; - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } + if (data->remaining.used == 0 && !data->process_pipe) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } + fss_status_code_delete_data(data); + return f_status_set_error(f_invalid_parameter); + } - code = (f_status) number; - is_true = f_status_is_fine(code); + if (data->parameters[fss_status_code_parameter_is_error].result == f_console_result_found || data->parameters[fss_status_code_parameter_is_warning].result == f_console_result_found || data->parameters[fss_status_code_parameter_is_fine].result == f_console_result_found) { + if (data->process_pipe) { + // @todo: call fss_status_code_process_check() here for all data from pipe that is space separated. + } - if (status == f_none) { - status = f_true; - } + if (data->remaining.used > 0) { + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = fss_status_code_process_check(*data, arguments.argv[data->remaining.array[i]]); - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); + if (f_status_is_error(status2) && status == f_none) { + status = status2; } } // for } - 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++) { - // Numbers are not valid status code strings. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_true) { - status = f_false; - continue; - } + if (data->process_pipe) { + // @todo: call fss_status_code_process_number() here for all data from pipe that is space separated. + } - status2 = fll_fss_status_from_string(arguments.argv[data->remaining.array[counter]], &code); + if (data->remaining.used > 0) { + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = fss_status_code_process_number(*data, arguments.argv[data->remaining.array[i]]); - if (f_status_is_error(status2)) { + if (f_status_is_error(status2) && status == f_none) { status = status2; - break; - } - else if (status2 == f_invalid_data) { - status = f_false; - continue; } - else if (status == f_none) { - status = f_true; - } - - printf("%u\n", code); } // for } - else { - status = f_false; - } } - else if (data->remaining.used > 0 || data->process_pipe) { - f_array_length counter = 0; - + else { if (data->process_pipe) { - // TODO: how should this be done? + // @todo: call fss_status_code_process_normal() here for all data from pipe that is space separated. } if (data->remaining.used > 0) { - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status code. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } - - long long number = atoll(arguments.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; + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = fss_status_code_process_normal(*data, arguments.argv[data->remaining.array[i]]); - if (fll_fss_status_to_string(code, &string) == f_none) { - printf("%s\n", string); - } - else { - status = f_false; + if (f_status_is_error(status2) && status == f_none) { + status = status2; } } // 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."); - status = f_status_set_error(f_invalid_parameter); } fss_status_code_delete_data(data); 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 c2deff6..f000ef1 100644 --- a/level_3/fss_status_code/c/fss_status_code.h +++ b/level_3/fss_status_code/c/fss_status_code.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/level_3/fss_status_code/c/private-fss_status_code.c b/level_3/fss_status_code/c/private-fss_status_code.c new file mode 100644 index 0000000..48b9429 --- /dev/null +++ b/level_3/fss_status_code/c/private-fss_status_code.c @@ -0,0 +1,159 @@ +#include +#include "private-fss_status_code.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_status_code_process_check_ + f_return_status fss_status_code_process_check(const fss_status_code_data data, const f_string value) { + f_number_unsigned number = 0; + f_status status = fss_status_code_convert_number(data, value, &number); + + if (f_status_is_error(status)) { + return status; + } + + if (data.parameters[fss_status_code_parameter_is_error].result == f_console_result_found) { + if (f_status_is_error(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + else if (data.parameters[fss_status_code_parameter_is_warning].result == f_console_result_found) { + if (f_status_is_warning(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + else if (data.parameters[fss_status_code_parameter_is_fine].result == f_console_result_found) { + if (f_status_is_fine(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + + return f_none; + } +#endif // _di_fss_status_code_process_check_ + +#ifndef _di_fss_status_code_process_number_ + f_return_status fss_status_code_process_number(const fss_status_code_data data, const f_string value) { + f_status status = f_none; + + { + f_number_unsigned number = 0; + + status = fl_console_parameter_to_number_unsigned(value, &number); + + if (status == f_none) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid name"); + + return f_status_set_error(f_invalid_parameter); + } + + if (status == f_no_data || f_status_set_fine(status) == f_invalid_parameter) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid data"); + + return status; + } + } + + f_status code = f_none; + + status = fll_fss_status_from_string(value, &code); + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_invalid_data) { + status = fll_status_from_string(value, &code); + } + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "unknown name"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "failed to convert"); + } + + return status; + } + } + + if (status == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.warning, data.context.reset, "unknown code"); + + return f_none; + } + + printf("%u\n", code); + + return f_none; + } +#endif // _di_fss_status_code_process_number_ + +#ifndef _di_fss_status_code_process_normal_ + f_return_status fss_status_code_process_normal(const fss_status_code_data data, const f_string value) { + f_number_unsigned number = 0; + f_status status = fss_status_code_convert_number(data, value, &number); + + if (f_status_is_error(status)) { + return status; + } + + f_status code = (f_status) number; + f_string string = 0; + + status = fll_fss_status_to_string(code, &string); + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "unknown code"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "failed to convert"); + } + + return status; + } + + printf("%s\n", string); + + return f_none; + } +#endif // _di_fss_status_code_process_normal_ + +#ifndef _di_fss_status_code_convert_number_ + f_return_status fss_status_code_convert_number(const fss_status_code_data data, const f_string value, f_number_unsigned *number) { + f_status status = fl_console_parameter_to_number_unsigned(value, number); + + if (*number > f_status_size_max_with_signal) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "out of range"); + + return status; + } + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_negative_number) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "out of range"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid number"); + } + + return status; + } + + return f_none; + } +#endif // _di_fss_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_status_code/c/private-fss_status_code.h b/level_3/fss_status_code/c/private-fss_status_code.h new file mode 100644 index 0000000..07b9083 --- /dev/null +++ b/level_3/fss_status_code/c/private-fss_status_code.h @@ -0,0 +1,102 @@ +/** + * FLL - Level 3 + * + * Project: FSS + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_fss_status_code_h +#define _PRIVATE_fss_status_code_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the 'check' processes, such as --fine or --error. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_fss_status_code_process_check_ + extern f_return_status fss_status_code_process_check(const fss_status_code_data data, const f_string value); +#endif // _di_fss_status_code_process_check_ + +/** + * Perform the 'number' processes, such as --number. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string is empty. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fss_status_code_process_number_ + extern f_return_status fss_status_code_process_number(const fss_status_code_data data, const f_string value); +#endif // _di_fss_status_code_process_number_ + +/** + * Perform the normal processes. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_fss_status_code_process_normal_ + extern f_return_status fss_status_code_process_normal(const fss_status_code_data data, const f_string value); +#endif // _di_fss_status_code_process_normal_ + +/** + * Convert the value string to the number, reporting any errors. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * @param number + * The converted number. + * Will not be updated on error. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_fss_status_code_convert_number_ + extern f_return_status fss_status_code_convert_number(const fss_status_code_data data, const f_string value, f_number_unsigned *number); +#endif // _di_fss_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_fss_status_code_h diff --git a/level_3/fss_status_code/data/build/settings b/level_3/fss_status_code/data/build/settings index db39b7b..34756fe 100644 --- a/level_3/fss_status_code/data/build/settings +++ b/level_3/fss_status_code/data/build/settings @@ -13,7 +13,7 @@ build_libraries -lc build_libraries_fll -lfll_status -lfll_program -lfll_fss -lfll_execute -lfl_utf -lfl_string -lfl_status -lfl_fss -lfl_file -lfl_directory -lfl_console -lfl_color -lf_utf -lf_print -lf_pipe -lf_file -lf_conversion -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library fss_status_code.c +build_sources_library fss_status_code.c private-fss_status_code.c build_sources_program main.c build_sources_headers fss_status_code.h build_sources_bash diff --git a/level_3/status_code/c/private-status_code.c b/level_3/status_code/c/private-status_code.c new file mode 100644 index 0000000..256f254 --- /dev/null +++ b/level_3/status_code/c/private-status_code.c @@ -0,0 +1,153 @@ +#include +#include "private-status_code.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_status_code_process_check_ + f_return_status status_code_process_check(const status_code_data data, const f_string value) { + f_number_unsigned number = 0; + f_status status = status_code_convert_number(data, value, &number); + + if (f_status_is_error(status)) { + return status; + } + + if (data.parameters[status_code_parameter_is_error].result == f_console_result_found) { + if (f_status_is_error(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + else if (data.parameters[status_code_parameter_is_warning].result == f_console_result_found) { + if (f_status_is_warning(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + else if (data.parameters[status_code_parameter_is_fine].result == f_console_result_found) { + if (f_status_is_fine(number)) { + printf("%s\n", fl_status_string_true); + } + else { + printf("%s\n", fl_status_string_false); + } + } + + return f_none; + } +#endif // _di_status_code_process_check_ + +#ifndef _di_status_code_process_number_ + f_return_status status_code_process_number(const status_code_data data, const f_string value) { + f_status status = f_none; + + { + f_number_unsigned number = 0; + + status = fl_console_parameter_to_number_unsigned(value, &number); + + if (status == f_none) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid name"); + + return f_status_set_error(f_invalid_parameter); + } + + if (status == f_no_data || f_status_set_fine(status) == f_invalid_parameter) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid data"); + + return status; + } + } + + f_status code = f_none; + + status = fll_status_from_string(value, &code); + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "unknown name"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "failed to convert"); + } + + return status; + } + + if (status == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.warning, data.context.reset, "unknown code"); + + return f_none; + } + + printf("%u\n", code); + + return f_none; + } +#endif // _di_status_code_process_number_ + +#ifndef _di_status_code_process_normal_ + f_return_status status_code_process_normal(const status_code_data data, const f_string value) { + f_number_unsigned number = 0; + f_status status = status_code_convert_number(data, value, &number); + + if (f_status_is_error(status)) { + return status; + } + + f_status code = (f_status) number; + f_string string = 0; + + status = fl_status_to_string(code, &string); + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_invalid_data) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "unknown code"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "failed to convert"); + } + + return status; + } + + printf("%s\n", string); + + return f_none; + } +#endif // _di_status_code_process_normal_ + +#ifndef _di_status_code_convert_number_ + f_return_status status_code_convert_number(const status_code_data data, const f_string value, f_number_unsigned *number) { + f_status status = fl_console_parameter_to_number_unsigned(value, number); + + if (*number > f_status_size_max_with_signal) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "out of range"); + + return status; + } + + if (f_status_is_error(status)) { + if (f_status_set_fine(status) == f_negative_number) { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "out of range"); + } + else { + fl_color_print_line(f_standard_output, data.context.error, data.context.reset, "invalid number"); + } + + return status; + } + + return f_none; + } +#endif // _di_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/status_code/c/private-status_code.h b/level_3/status_code/c/private-status_code.h new file mode 100644 index 0000000..2268b4e --- /dev/null +++ b/level_3/status_code/c/private-status_code.h @@ -0,0 +1,102 @@ +/** + * FLL - Level 3 + * + * Project: Status Code + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_status_code_h +#define _PRIVATE_status_code_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the 'check' processes, such as --fine or --error. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_status_code_process_check_ + extern f_return_status status_code_process_check(const status_code_data data, const f_string value); +#endif // _di_status_code_process_check_ + +/** + * Perform the 'number' processes, such as --number. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string is empty. + * f_invalid_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_status_code_process_number_ + extern f_return_status status_code_process_number(const status_code_data data, const f_string value); +#endif // _di_status_code_process_number_ + +/** + * Perform the normal processes. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_status_code_process_normal_ + extern f_return_status status_code_process_normal(const status_code_data data, const f_string value); +#endif // _di_status_code_process_normal_ + +/** + * Convert the value string to the number, reporting any errors. + * + * @param data + * The program data. + * @param value + * The parameter value to process. + * @param number + * The converted number. + * Will not be updated on error. + * + * @return + * f_none on success. + * f_no_data (with error bit) if string starts wth a null (length is 0). + * f_invalid_parameter (with error bit) if a parameter is invalid. + * f_invalid_number (with error bit) if parameter is not a number. + * f_negative_number (with error bit) on negative value. + * f_overflow (with error bit) on integer overflow. + * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. + */ +#ifndef _di_status_code_convert_number_ + extern f_return_status status_code_convert_number(const status_code_data data, const f_string value, f_number_unsigned *number); +#endif // _di_status_code_convert_number_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_status_code_h diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 9d99fdf..4d66b0a 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -1,4 +1,5 @@ #include +#include "private-status_code.h" #ifdef __cplusplus extern "C" { @@ -16,9 +17,9 @@ extern "C" { printf("%c", f_string_eol); - fll_program_print_help_option(data.context, status_code_short_is_fine, status_code_long_is_fine, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is not an error."); - fll_program_print_help_option(data.context, status_code_short_is_warning, status_code_long_is_warning, f_console_symbol_short_enable, f_console_symbol_long_enable, "Print f_true if the error code is a warning."); - fll_program_print_help_option(data.context, status_code_short_is_error, status_code_long_is_error, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is an error."); + fll_program_print_help_option(data.context, status_code_short_is_fine, status_code_long_is_fine, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is not an error, f_false otherwise."); + fll_program_print_help_option(data.context, status_code_short_is_warning, status_code_long_is_warning, f_console_symbol_short_enable, f_console_symbol_long_enable, "Print f_true if the error code is a warning, f_false otherwise."); + fll_program_print_help_option(data.context, status_code_short_is_error, status_code_long_is_error, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print f_true if the error code is an error, f_false otherwise."); fll_program_print_help_option(data.context, status_code_short_number, status_code_long_number, f_console_symbol_short_enable, f_console_symbol_long_enable, " Convert status code name to number."); fll_program_print_help_usage(data.context, status_code_name, "status code(s)"); @@ -44,207 +45,104 @@ extern "C" { return f_status_set_error(status); } + f_status status2 = f_none; status = f_none; - // Execute parameter results. if (data->parameters[status_code_parameter_help].result == f_console_result_found) { status_code_print_help(*data); + status_code_delete_data(data); + return f_none; } else if (data->parameters[status_code_parameter_version].result == f_console_result_found) { fll_program_print_version(status_code_version); + status_code_delete_data(data); + return f_none; } - 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; - unsigned short is_true = 0; - - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } - - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } - code = (f_status) number; - is_true = f_status_is_error(code) && !f_status_is_warning(code); + if (data->parameters[status_code_parameter_is_error].result == f_console_result_found) { + if (data->parameters[status_code_parameter_is_warning].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_error); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_warning); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); - if (status == f_none) { - status = f_true; - } - - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); - } - } // for + status_code_delete_data(data); + return f_status_set_error(status); } - else { - status = f_false; + else if (data->parameters[status_code_parameter_is_fine].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_error); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_fine); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); + + status_code_delete_data(data); + return f_status_set_error(status); } } - 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; - unsigned short is_true = 0; - - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } - - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } - - code = (f_status) number; - is_true = f_status_is_warning(code) && !f_status_is_error(code); + else if (data->parameters[status_code_parameter_is_warning].result == f_console_result_found && data->parameters[status_code_parameter_is_fine].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_warning); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' cannot be used with the parameter "); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", status_code_long_is_fine); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "."); - if (status == f_none) { - status = f_true; - } - - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); - } - } // for - } - else { - status = f_false; - } + status_code_delete_data(data); + return f_status_set_error(status); } - 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; - unsigned short is_true = 0; - - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status codes. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } + if (data->remaining.used == 0 && !data->process_pipe) { + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); - long long number = atoll(arguments.argv[data->remaining.array[counter]]); - if (number >= 0x10000 || number < 0) { - status = f_false; - continue; - } + status_code_delete_data(data); + return f_status_set_error(f_invalid_parameter); + } - code = (f_status) number; - is_true = f_status_is_fine(code); + if (data->parameters[status_code_parameter_is_error].result == f_console_result_found || data->parameters[status_code_parameter_is_warning].result == f_console_result_found || data->parameters[status_code_parameter_is_fine].result == f_console_result_found) { + if (data->process_pipe) { + // @todo: call status_code_process_check() here for all data from pipe that is space separated. + } - if (status == f_none) { - status = f_true; - } + if (data->remaining.used > 0) { + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = status_code_process_check(*data, arguments.argv[data->remaining.array[i]]); - if (is_true) { - printf("%s\n", fl_status_string_true); - } - else { - printf("%s\n", fl_status_string_false); + if (f_status_is_error(status2) && status == f_none) { + status = status2; } } // for } - else { - status = f_false; - } } else if (data->parameters[status_code_parameter_number].result == f_console_result_found) { + if (data->process_pipe) { + // @todo: call status_code_process_number() here for all data from pipe that is space separated. + } + 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++) { - // Numbers are not valid status code strings. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_true) { - status = f_false; - continue; - } + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = status_code_process_number(*data, arguments.argv[data->remaining.array[i]]); - status2 = fll_status_from_string(arguments.argv[data->remaining.array[counter]], &code); - if (f_status_is_error(status2)) { + if (f_status_is_error(status2) && status == f_none) { status = status2; - break; - } - else if (status2 == f_invalid_data) { - status = f_false; - continue; } - else if (status == f_none) { - status = f_true; - } - - printf("%u\n", code); } // for } - else { - status = f_false; - } } - else if (data->remaining.used > 0 || data->process_pipe) { - f_array_length counter = 0; - + else { if (data->process_pipe) { - // TODO: how should this be done? + // @todo: call status_code_process_normal() here for all data from pipe that is space separated. } if (data->remaining.used > 0) { - for (; counter < data->remaining.used; counter++) { - // only numbers are valid status code. - if (f_conversion_character_is_decimal(arguments.argv[data->remaining.array[counter]][0]) == f_false) { - status = f_false; - continue; - } - - long long number = atoll(arguments.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; + for (f_array_length i = 0; i < data->remaining.used; i++) { + status2 = status_code_process_normal(*data, arguments.argv[data->remaining.array[i]]); - if (fl_status_to_string(code, &string) == f_none) { - printf("%s\n", string); - } - else { - status = f_false; + if (f_status_is_error(status2) && status == f_none) { + status = status2; } } // 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."); - status = f_status_set_error(f_invalid_parameter); } status_code_delete_data(data); diff --git a/level_3/status_code/c/status_code.h b/level_3/status_code/c/status_code.h index d5b3b94..e48f2f8 100644 --- a/level_3/status_code/c/status_code.h +++ b/level_3/status_code/c/status_code.h @@ -4,6 +4,8 @@ * Project: Status Code * API Version: 0.5 * Licenses: lgplv2.1 + * + * This program provides status code to/from string translation. */ #ifndef _status_code_h @@ -13,10 +15,11 @@ #include // fll-0 includes -#include #include +#include #include #include +#include #include #include @@ -27,8 +30,8 @@ #include // fll-2 includes -#include #include +#include #ifdef __cplusplus extern "C" { @@ -42,8 +45,8 @@ extern "C" { #endif // _di_status_code_version_ #ifndef _di_status_code_name_ - #define status_code_name "status_code" - #define status_code_name_long "Status Code" + #define status_code_name "status_code" + #define status_code_name_long "FSS Status Code" #endif // _di_status_code_name_ #ifndef _di_status_code_defines_ diff --git a/level_3/status_code/data/build/settings b/level_3/status_code/data/build/settings index 0d3f2cc..1c5f836 100644 --- a/level_3/status_code/data/build/settings +++ b/level_3/status_code/data/build/settings @@ -13,7 +13,7 @@ build_libraries -lc build_libraries_fll -lfll_status -lfll_program -lfl_utf -lfl_string -lfl_status -lfl_file -lfl_console -lfl_color -lf_utf -lf_print -lf_pipe -lf_file -lf_conversion -lf_console -lf_memory #build_libraries_fll-level -lfll_2 -lfll_1 -lfll_0 #build_libraries_fll-monolithic -lfll -build_sources_library status_code.c +build_sources_library status_code.c private-status_code.c build_sources_program main.c build_sources_headers status_code.h build_sources_bash -- 1.8.3.1