From: Kevin Day Date: Tue, 8 Nov 2022 04:00:53 +0000 (-0600) Subject: Update: Merge fss_status_code into status_code. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=3151f98437273ee3491893bcce3b70c5c52b11e0;p=fll Update: Merge fss_status_code into status_code. The only difference between status_code and fss_status_code are different by two function calls, a library dependency, and some constants. Simplify the code and shrink the resulting binary file sizes. --- diff --git a/level_3/fss_status_code/c/common.c b/level_3/fss_status_code/c/common.c deleted file mode 100644 index 2aaff4c..0000000 --- a/level_3/fss_status_code/c/common.c +++ /dev/null @@ -1,210 +0,0 @@ -#include "fss_status_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_status_code_program_version_ - const f_string_static_t fss_status_code_program_version_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_program_version_s, 0, FSS_STATUS_CODE_program_version_s_length); -#endif // _di_fss_status_code_program_version_ - -#ifndef _di_fss_status_code_program_name_ - const f_string_static_t fss_status_code_program_name_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_program_name_s, 0, FSS_STATUS_CODE_program_name_s_length); - const f_string_static_t fss_status_code_program_name_long_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_program_name_long_s, 0, FSS_STATUS_CODE_program_name_long_s_length); -#endif // _di_fss_status_code_program_name_ - -#ifndef _di_fss_status_code_program_help_parameters_ - const f_string_static_t fss_status_code_program_help_parameters_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_program_help_parameters_s, 0, FSS_STATUS_CODE_program_help_parameters_s_length); -#endif // _di_fss_status_code_program_help_parameters_ - -#ifndef _di_fss_status_code_strings_ - const f_string_static_t fss_status_code_failed_to_convert_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_failed_to_convert_s, 0, FSS_STATUS_CODE_failed_to_convert_s_length); - const f_string_static_t fss_status_code_invalid_number_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_invalid_number_s, 0, FSS_STATUS_CODE_invalid_number_s_length); - const f_string_static_t fss_status_code_invalid_name_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_invalid_number_s, 0, FSS_STATUS_CODE_invalid_number_s_length); - const f_string_static_t fss_status_code_invalid_main_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_invalid_main_s, 0, FSS_STATUS_CODE_invalid_main_s_length); - const f_string_static_t fss_status_code_out_of_range_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_out_of_range_s, 0, FSS_STATUS_CODE_out_of_range_s_length); - const f_string_static_t fss_status_code_unknown_code_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_unknown_code_s, 0, FSS_STATUS_CODE_unknown_code_s_length); - const f_string_static_t fss_status_code_unknown_name_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_unknown_name_s, 0, FSS_STATUS_CODE_unknown_name_s_length); -#endif // _di_fss_status_code_strings_ - -#ifndef _di_fss_status_code_parameters_ - const f_string_static_t fss_status_code_short_fine_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_short_fine_s, 0, FSS_STATUS_CODE_short_fine_s_length); - const f_string_static_t fss_status_code_short_warning_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_short_warning_s, 0, FSS_STATUS_CODE_short_warning_s_length); - const f_string_static_t fss_status_code_short_error_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_short_error_s, 0, FSS_STATUS_CODE_short_error_s_length); - const f_string_static_t fss_status_code_short_number_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_short_number_s, 0, FSS_STATUS_CODE_short_number_s_length); - - const f_string_static_t fss_status_code_long_fine_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_long_fine_s, 0, FSS_STATUS_CODE_long_fine_s_length); - const f_string_static_t fss_status_code_long_warning_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_long_warning_s, 0, FSS_STATUS_CODE_long_warning_s_length); - const f_string_static_t fss_status_code_long_error_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_long_error_s, 0, FSS_STATUS_CODE_long_error_s_length); - const f_string_static_t fss_status_code_long_number_s = macro_f_string_static_t_initialize(FSS_STATUS_CODE_long_number_s, 0, FSS_STATUS_CODE_long_number_s_length); -#endif // _di_fss_status_code_parameters_ - -#ifndef _di_fss_status_code_setting_delete_ - f_status_t fss_status_code_setting_delete(fss_status_code_setting_t * const setting) { - - if (!setting) return F_status_set_error(F_parameter); - - return F_none; - } -#endif // _di_fss_status_code_setting_delete_ - -#ifndef _di_fss_status_code_setting_load_ - void fss_status_code_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_status_code_setting_t * const setting) { - - if (!main || !setting) return; - - // Load parameters. - setting->status = f_console_parameter_process(arguments, &main->parameters); - - if (F_status_is_error(setting->status)) { - fss_status_code_print_line_first_locked(setting, main->error); - fll_error_print(main->error, F_status_set_fine(setting->status), "f_console_parameter_process", F_true); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - - { - f_array_length_t choice = 0; - f_uint16s_t choices = f_uint16s_t_initialize; - - // Identify and prioritize "color context" parameters. - { - uint16_t choices_array[3] = { fss_status_code_parameter_no_color_e, fss_status_code_parameter_light_e, fss_status_code_parameter_dark_e }; - choices.array = choices_array; - choices.used = 3; - - const uint8_t modes[3] = { f_color_mode_color_not_e, f_color_mode_light_e, f_color_mode_dark_e }; - - setting->status = fll_program_parameter_process_context(choices, modes, F_true, main); - - if (F_status_is_error(setting->status)) { - fss_status_code_print_line_first_locked(setting, main->error); - fll_error_print(main->error, F_status_set_fine(setting->status), "fll_program_parameter_process_context", F_true); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - } - - if (main->parameters.array[fss_status_code_parameter_line_first_no_e].result == f_console_result_found_e) { - setting->line_first = f_string_empty_s; - } - else { - setting->line_first = f_string_eol_s; - } - - if (main->parameters.array[fss_status_code_parameter_line_last_no_e].result == f_console_result_found_e) { - setting->line_last = f_string_empty_s; - } - else { - setting->line_last = f_string_eol_s; - } - - // Identify and prioritize "verbosity" parameters. - { - uint16_t choices_array[5] = { fss_status_code_parameter_verbosity_quiet_e, fss_status_code_parameter_verbosity_error_e, fss_status_code_parameter_verbosity_verbose_e, fss_status_code_parameter_verbosity_debug_e, fss_status_code_parameter_verbosity_normal_e }; - choices.array = choices_array; - choices.used = 5; - - const uint8_t verbosity[5] = { f_console_verbosity_quiet_e, f_console_verbosity_error_e, f_console_verbosity_verbose_e, f_console_verbosity_debug_e, f_console_verbosity_normal_e }; - - setting->status = fll_program_parameter_process_verbosity(choices, verbosity, F_true, main); - - if (F_status_is_error(setting->status)) { - fss_status_code_print_line_first_locked(setting, main->error); - fll_error_print(main->error, F_status_set_fine(setting->status), "fll_program_parameter_process_verbosity", F_true); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - } - - if (main->parameters.array[fss_status_code_parameter_help_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_help_e; - - return; - } - - if (main->parameters.array[fss_status_code_parameter_version_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_version_e; - - return; - } - } - - if (main->parameters.array[fss_status_code_parameter_error_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_error_e; - } - - if (main->parameters.array[fss_status_code_parameter_fine_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_fine_e; - } - - if (main->parameters.array[fss_status_code_parameter_warning_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_warning_e; - } - - if (main->parameters.array[fss_status_code_parameter_number_e].result == f_console_result_found_e) { - setting->flag |= fss_status_code_main_flag_number_e; - } - - if (setting->flag & fss_status_code_main_flag_error_e) { - if (setting->flag & fss_status_code_main_flag_warning_e) { - if (!(setting->flag & fss_status_code_main_flag_number_e)) { - setting->status = F_status_set_error(F_parameter); - - fss_status_code_print_line_first_locked(setting, main->error); - fss_status_code_print_error_cannot_error_warning_number(setting, main->error); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - } - - if (setting->flag & fss_status_code_main_flag_fine_e) { - setting->status = F_status_set_error(F_parameter); - - fss_status_code_print_line_first_locked(setting, main->error); - fll_program_print_error_parameter_cannot_use_with(main->error, f_console_symbol_long_enable_s, f_console_symbol_long_enable_s, fss_status_code_long_error_s, fss_status_code_long_fine_s); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - } - else if (setting->flag & fss_status_code_main_flag_warning_e && setting->flag & fss_status_code_main_flag_fine_e) { - setting->status = F_status_set_error(F_parameter); - - fss_status_code_print_line_first_locked(setting, main->error); - fll_program_print_error_parameter_cannot_use_with(main->error, f_console_symbol_long_enable_s, f_console_symbol_long_enable_s, fss_status_code_long_warning_s, fss_status_code_long_fine_s); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - - if (main->parameters.remaining.used == 0 && !(main->pipe & fll_program_data_pipe_input_e)) { - setting->status = F_status_set_error(F_parameter); - - fss_status_code_print_line_first_locked(setting, main->error); - fss_status_code_print_error_no_fss_status_codes(setting, main->error); - fss_status_code_print_line_last_locked(setting, main->error); - - return; - } - } -#endif // _di_fss_status_code_setting_load_ - -#ifndef _di_fss_status_code_setting_unload_ - f_status_t fss_status_code_setting_unload(fll_program_data_t * const main, fss_status_code_setting_t * const setting) { - - if (!main || !setting) return F_status_set_error(F_parameter); - - fss_status_code_setting_delete(setting); - - return F_none; - } -#endif // _di_fss_status_code_setting_unload_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_status_code/c/common.h b/level_3/fss_status_code/c/common.h deleted file mode 100644 index 137cbd0..0000000 --- a/level_3/fss_status_code/c/common.h +++ /dev/null @@ -1,316 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Status Code - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Provides the common data structures. - * - * This is auto-included and should not need to be explicitly included. - */ -#ifndef _fss_status_code_common_h -#define _fss_status_code_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The program version. - */ -#ifndef _di_fss_status_code_program_version_ - #define FSS_STATUS_CODE_program_version_major_s F_string_ascii_0_s - #define FSS_STATUS_CODE_program_version_minor_s F_string_ascii_7_s - #define FSS_STATUS_CODE_program_version_micro_s F_string_ascii_0_s - - #define FSS_STATUS_CODE_program_version_major_s_length F_string_ascii_0_s_length - #define FSS_STATUS_CODE_program_version_minor_s_length F_string_ascii_7_s_length - #define FSS_STATUS_CODE_program_version_micro_s_length F_string_ascii_0_s_length - - #if !(defined(FSS_STATUS_CODE_program_version_nano_prefix_s) && defined(FSS_STATUS_CODE_program_version_nano_prefix_s_length)) - #define FSS_STATUS_CODE_program_version_nano_prefix_s - #define FSS_STATUS_CODE_program_version_nano_prefix_s_length 0 - #endif // !(defined(FSS_STATUS_CODE_program_version_nano_prefix_s) && defined(FSS_STATUS_CODE_program_version_nano_prefix_s_length)) - - #if !(defined(FSS_STATUS_CODE_program_version_nano_s) && defined(FSS_STATUS_CODE_program_version_nano_s_length)) - #define FSS_STATUS_CODE_program_version_nano_s - #define FSS_STATUS_CODE_program_version_nano_s_length 0 - #endif // !(defined(FSS_STATUS_CODE_program_version_nano_s) && defined(FSS_STATUS_CODE_program_version_nano_s_length)) - - #define FSS_STATUS_CODE_program_version_s FSS_STATUS_CODE_program_version_major_s F_string_ascii_period_s FSS_STATUS_CODE_program_version_minor_s F_string_ascii_period_s FSS_STATUS_CODE_program_version_micro_s FSS_STATUS_CODE_program_version_nano_prefix_s FSS_STATUS_CODE_program_version_nano_s - - #define FSS_STATUS_CODE_program_version_s_length FSS_STATUS_CODE_program_version_major_s_length + F_string_ascii_period_s_length + FSS_STATUS_CODE_program_version_minor_s_length + F_string_ascii_period_s_length + FSS_STATUS_CODE_program_version_micro_s_length + FSS_STATUS_CODE_program_version_nano_prefix_s_length + FSS_STATUS_CODE_program_version_nano_s_length - - extern const f_string_static_t fss_status_code_program_version_s; -#endif // _di_fss_status_code_program_version_ - -/** - * The program name. - */ -#ifndef _di_fss_status_code_program_name_ - #define FSS_STATUS_CODE_program_name_s "fss_status_code" - #define FSS_STATUS_CODE_program_name_long_s "FSS Status Code" - - #define FSS_STATUS_CODE_program_name_s_length 15 - #define FSS_STATUS_CODE_program_name_long_s_length 15 - - extern const f_string_static_t fss_status_code_program_name_s; - extern const f_string_static_t fss_status_code_program_name_long_s; -#endif // _di_fss_status_code_program_name_ - -/** - * The program help related data. - */ -#ifndef _di_fss_status_code_program_help_parameters_ - #define FSS_STATUS_CODE_program_help_parameters_s "status code(s)" - #define FSS_STATUS_CODE_program_help_parameters_s_length 14 - - extern const f_string_static_t fss_status_code_program_help_parameters_s; -#endif // _di_fss_status_code_program_help_parameters_ - -/** - * Special strings used by this program. - */ -#ifndef _di_fss_status_code_strings_ - #define FSS_STATUS_CODE_failed_to_convert_s "failed to convert" - #define FSS_STATUS_CODE_invalid_number_s "invalid number" - #define FSS_STATUS_CODE_invalid_name_s "invalid name" - #define FSS_STATUS_CODE_invalid_main_s "invalid main" - #define FSS_STATUS_CODE_out_of_range_s "out of range" - #define FSS_STATUS_CODE_unknown_code_s "unknown code" - #define FSS_STATUS_CODE_unknown_name_s "unknown name" - - #define FSS_STATUS_CODE_failed_to_convert_s_length 17 - #define FSS_STATUS_CODE_invalid_number_s_length 14 - #define FSS_STATUS_CODE_invalid_name_s_length 12 - #define FSS_STATUS_CODE_invalid_main_s_length 12 - #define FSS_STATUS_CODE_out_of_range_s_length 12 - #define FSS_STATUS_CODE_unknown_code_s_length 12 - #define FSS_STATUS_CODE_unknown_name_s_length 12 - - extern const f_string_static_t fss_status_code_failed_to_convert_s; - extern const f_string_static_t fss_status_code_invalid_number_s; - extern const f_string_static_t fss_status_code_invalid_name_s; - extern const f_string_static_t fss_status_code_invalid_main_s; - extern const f_string_static_t fss_status_code_out_of_range_s; - extern const f_string_static_t fss_status_code_unknown_code_s; - extern const f_string_static_t fss_status_code_unknown_name_s; -#endif // _di_fss_status_code_strings_ - -/** - * The program defines. - */ -#ifndef _di_fss_status_code_defines_ - #define fss_status_code_signal_check_d 20000 -#endif // _di_fss_status_code_defines_ - -/** - * The main program parameters. - */ -#ifndef _di_fss_status_code_parameters_ - #define FSS_STATUS_CODE_short_fine_s "f" - #define FSS_STATUS_CODE_short_warning_s "w" - #define FSS_STATUS_CODE_short_error_s "e" - #define FSS_STATUS_CODE_short_number_s "n" - - #define FSS_STATUS_CODE_long_fine_s "fine" - #define FSS_STATUS_CODE_long_warning_s "warning" - #define FSS_STATUS_CODE_long_error_s "error" - #define FSS_STATUS_CODE_long_number_s "number" - - #define FSS_STATUS_CODE_short_fine_s_length 1 - #define FSS_STATUS_CODE_short_warning_s_length 1 - #define FSS_STATUS_CODE_short_error_s_length 1 - #define FSS_STATUS_CODE_short_number_s_length 1 - - #define FSS_STATUS_CODE_long_fine_s_length 4 - #define FSS_STATUS_CODE_long_warning_s_length 7 - #define FSS_STATUS_CODE_long_error_s_length 5 - #define FSS_STATUS_CODE_long_number_s_length 6 - - extern const f_string_static_t fss_status_code_short_fine_s; - extern const f_string_static_t fss_status_code_short_warning_s; - extern const f_string_static_t fss_status_code_short_error_s; - extern const f_string_static_t fss_status_code_short_number_s; - - extern const f_string_static_t fss_status_code_long_fine_s; - extern const f_string_static_t fss_status_code_long_warning_s; - extern const f_string_static_t fss_status_code_long_error_s; - extern const f_string_static_t fss_status_code_long_number_s; - - enum { - fss_status_code_parameter_help_e, - fss_status_code_parameter_light_e, - fss_status_code_parameter_dark_e, - fss_status_code_parameter_no_color_e, - fss_status_code_parameter_verbosity_quiet_e, - fss_status_code_parameter_verbosity_error_e, - fss_status_code_parameter_verbosity_normal_e, - fss_status_code_parameter_verbosity_verbose_e, - fss_status_code_parameter_verbosity_debug_e, - fss_status_code_parameter_version_e, - fss_status_code_parameter_line_first_no_e, - fss_status_code_parameter_line_last_no_e, - - fss_status_code_parameter_fine_e, - fss_status_code_parameter_warning_e, - fss_status_code_parameter_error_e, - fss_status_code_parameter_number_e, - }; - - #define fss_status_code_console_parameter_t_initialize \ - { \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_help_s, f_console_standard_long_help_s, 0, f_console_type_normal_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_light_s, f_console_standard_long_light_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_dark_s, f_console_standard_long_dark_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_no_color_s, f_console_standard_long_no_color_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_quiet_s, f_console_standard_long_quiet_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_error_s, f_console_standard_long_error_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_normal_s, f_console_standard_long_normal_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_verbose_s, f_console_standard_long_verbose_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_debug_s, f_console_standard_long_debug_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_version_s, f_console_standard_long_version_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_line_first_no_s, f_console_standard_long_line_first_no_s, 0, f_console_type_inverse_e), \ - macro_f_console_parameter_t_initialize4(f_console_standard_short_line_last_no_s, f_console_standard_long_line_last_no_s, 0, f_console_type_inverse_e), \ - \ - macro_f_console_parameter_t_initialize2(fss_status_code_short_fine_s.string, fss_status_code_long_fine_s.string, 0, 0, f_console_type_normal_e), \ - macro_f_console_parameter_t_initialize2(fss_status_code_short_warning_s.string, fss_status_code_long_warning_s.string, 0, 0, f_console_type_normal_e), \ - macro_f_console_parameter_t_initialize2(fss_status_code_short_error_s.string, fss_status_code_long_error_s.string, 0, 0, f_console_type_normal_e), \ - macro_f_console_parameter_t_initialize2(fss_status_code_short_number_s.string, fss_status_code_long_number_s.string, 0, 0, f_console_type_normal_e), \ - } - - #define fss_status_code_total_parameters_d 16 -#endif // _di_fss_status_code_parameters_ - -/** - * Flags used to represent flags passed to the main function. - * - * When number mode is not specified, then mode is "string" mode (there is no flag for "string" mode). - * - * fss_status_code_main_flag_*_e: - * - none: No modes in use. - * - error: Check if status is "error". - * - fine: Check if status is "fine". - * - help: Print help. - * - number: Operate in number mode. - * - version: Print version. - * - warning: Check if status is "warning". - */ -#ifndef _di_fss_status_code_main_flag_e_ - enum { - fss_status_code_main_flag_none_e = 0x0, - fss_status_code_main_flag_error_e = 0x1, - fss_status_code_main_flag_fine_e = 0x2, - fss_status_code_main_flag_help_e = 0x4, - fss_status_code_main_flag_number_e = 0x8, - fss_status_code_main_flag_version_e = 0x10, - fss_status_code_main_flag_warning_e = 0x20, - }; -#endif // _di_fss_status_code_main_flag_e_ - -/** - * The status code main program settings. - * - * This is passed to the program-specific main entry point to designate program settings. - * These program settings are often processed from the program arguments (often called the command line arguments). - * - * flag: Flags passed to the main function. - * - * status: The main status code, generally used by the load settings and main functions. - * - * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. - * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. - */ -#ifndef _di_fss_status_code_setting_t_ - typedef struct { - uint16_t flag; - - f_status_t status; - - f_string_static_t line_first; - f_string_static_t line_last; - } fss_status_code_setting_t; - - #define fss_status_code_setting_t_initialize \ - { \ - fss_status_code_main_flag_none_e, \ - F_none, \ - f_string_static_t_initialize, \ - f_string_static_t_initialize, \ - } -#endif // _di_fss_status_code_setting_t_ - -/** - * Delete the program main setting data. - * - * @param setting - * The program main setting data. - * - * This does not alter setting.status. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_fss_status_code_setting_delete_ - extern f_status_t fss_status_code_setting_delete(fss_status_code_setting_t * const setting); -#endif // _di_fss_status_code_setting_delete_ - -/** - * Perform the standard program setting load process. - * - * This prints error messages as appropriate. - * - * If either main or setting is NULL, then this immediately retuns without doing anything. - * - * @param arguments - * The parameters passed to the process (often referred to as command line arguments). - * @param main - * The main program data. - * @param setting - * The main program settings. - * - * This alters setting.status: - * F_none on success. - * - * Errors (with error bit) from: f_console_parameter_process(). - * Errors (with error bit) from: fll_program_parameter_process_context(). - * - * @see f_console_parameter_process() - * @see fll_program_parameter_process_context() - */ -#ifndef _di_fss_status_code_setting_load_ - extern void fss_status_code_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_status_code_setting_t * const setting); -#endif // _di_fss_status_code_setting_load_ - -/** - * Perform the standard program setting unload process. - * - * @param main - * The main program data. - * @param setting - * The main program settings. - * All buffers are deallocated. - * - * This does not alter setting.status. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: utf8_setting_delete(). - * - * @see utf8_setting_delete() - */ -#ifndef _di_fss_status_code_setting_unload_ - extern f_status_t fss_status_code_setting_unload(fll_program_data_t * const main, fss_status_code_setting_t * const setting); -#endif // _di_fss_status_code_setting_unload_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _fss_status_code_common_h diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c deleted file mode 100644 index 97d27fa..0000000 --- a/level_3/fss_status_code/c/fss_status_code.c +++ /dev/null @@ -1,138 +0,0 @@ -#include "fss_status_code.h" -#include "private-common.h" -#include "private-fss_status_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_status_code_main_ - void fss_status_code_main(fll_program_data_t * const main, fss_status_code_setting_t * const setting) { - - if (!main || !setting || F_status_is_error(setting->status)) return; - - setting->status = F_none; - - if (setting->flag & fss_status_code_main_flag_help_e) { - fss_status_code_print_help(setting, main->message); - - return; - } - - if (setting->flag & fss_status_code_main_flag_version_e) { - fll_program_print_version(main->message, fss_status_code_program_version_s); - - return; - } - - f_status_t status2 = F_none; - - if (setting->flag & fss_status_code_main_flag_number_e) { - if (main->pipe & fll_program_data_pipe_input_e) { - // @todo call fss_status_code_process_number() here for all main from pipe that is space separated. - } - - if (main->parameters.remaining.used) { - f_file_stream_lock(main->output.to); - - for (f_array_length_t i = 0; i < main->parameters.remaining.used; ++i) { - - if (!((++main->signal_check) % fss_status_code_signal_check_d)) { - if (fll_program_standard_signal_received(main)) { - fll_program_print_signal_received(main->warning, setting->line_first, main->signal_received); - - setting->status = F_status_set_error(F_signal); - - break; - } - - main->signal_check = 0; - } - - status2 = fss_status_code_process_number(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); - - if (F_status_is_error(status2) && setting->status == F_none) { - setting->status = status2; - } - } // for - - f_file_stream_unlock(main->output.to); - } - } - else if (setting->flag & fss_status_code_main_flag_error_e || setting->flag & fss_status_code_main_flag_warning_e || setting->flag & fss_status_code_main_flag_fine_e) { - if (main->pipe & fll_program_data_pipe_input_e) { - // @todo call fss_status_code_process_check() here for all main from pipe that is space separated. - } - - if (main->parameters.remaining.used) { - f_file_stream_lock(main->output.to); - - for (f_array_length_t i = 0; i < main->parameters.remaining.used; ++i) { - - if (!((++main->signal_check) % fss_status_code_signal_check_d)) { - if (fll_program_standard_signal_received(main)) { - fll_program_print_signal_received(main->warning, setting->line_first, main->signal_received); - - setting->status = F_status_set_error(F_signal); - - break; - } - - main->signal_check = 0; - } - - status2 = fss_status_code_process_check(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); - - if (F_status_is_error(status2) && setting->status == F_none) { - setting->status = status2; - } - } // for - - f_file_stream_unlock(main->output.to); - } - } - else { - if (main->pipe & fll_program_data_pipe_input_e) { - // @todo call fss_status_code_process_normal() here for all main from pipe that is space separated. - } - - if (main->parameters.remaining.used) { - f_file_stream_lock(main->output.to); - - for (f_array_length_t i = 0; i < main->parameters.remaining.used; ++i) { - - if (!((++main->signal_check) % fss_status_code_signal_check_d)) { - if (fll_program_standard_signal_received(main)) { - fll_program_print_signal_received(main->warning, setting->line_first, main->signal_received); - - setting->status = F_status_set_error(F_signal); - - break; - } - - main->signal_check = 0; - } - - status2 = fss_status_code_process_normal(main, setting, main->parameters.arguments.array[main->parameters.remaining.array[i]]); - - if (F_status_is_error(status2) && setting->status == F_none) { - setting->status = status2; - } - } // for - - f_file_stream_unlock(main->output.to); - } - } - - if (F_status_is_error(setting->status)) { - fss_status_code_print_line_last_locked(setting, main->error); - } - else if (setting->status != F_interrupt) { - fss_status_code_print_line_last_locked(setting, main->message); - } - } -#endif // _di_fss_status_code_main_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_status_code/c/fss_status_code.h b/level_3/fss_status_code/c/fss_status_code.h deleted file mode 100644 index e3458dd..0000000 --- a/level_3/fss_status_code/c/fss_status_code.h +++ /dev/null @@ -1,85 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Status Code - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * This program provides status code to/from string translation. - */ -#ifndef _fss_status_code_h -#define _fss_status_code_h - -// Libc includes. -#include -#include -#include -#include - -// FLL-0 includes. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// FLL-1 includes. -#include -#include -#include - -// FLL-2 includes. -#include -#include -#include -#include -#include - -// FSS Status Code includes. -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Execute main program. - * - * If main.signal is non-zero, then this blocks and handles the following signals: - * - F_signal_abort - * - F_signal_broken_pipe - * - F_signal_hangup - * - F_signal_interrupt - * - F_signal_quit - * - F_signal_termination - * - * @param main - * The main program data. - * @param setting - * The main program settings. - * - * This alters setting.status: - * F_none on success. - * F_true on success when performing verification and verify passed. - * F_false on success when performing verification and verify failed. - * F_interrupt on (exit) signal received. - * - * F_parameter (with error bit) if main is NULL or setting is NULL. - */ -#ifndef _di_fss_status_code_main_ - extern void fss_status_code_main(fll_program_data_t * const main, fss_status_code_setting_t * const setting); -#endif // _di_fss_status_code_main_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _fss_status_code_h diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c deleted file mode 100644 index 1f56485..0000000 --- a/level_3/fss_status_code/c/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "fss_status_code.h" - -int main(const int argc, const f_string_t *argv, const f_string_t *envp) { - - fll_program_data_t data = fll_program_data_t_initialize; - fss_status_code_setting_t setting = fss_status_code_setting_t_initialize; - - f_console_parameter_t parameters[] = fss_status_code_console_parameter_t_initialize; - data.parameters.array = parameters; - data.parameters.used = fss_status_code_total_parameters_d; - data.environment = envp; - - if (f_pipe_input_exists()) { - data.pipe = fll_program_data_pipe_input_e; - } - - fll_program_standard_set_up(&data); - - { - const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); - - fss_status_code_setting_load(arguments, &data, &setting); - } - - fss_status_code_main(&data, &setting); - - fss_status_code_setting_unload(&data, &setting); - - fll_program_data_delete(&data); - - fll_program_standard_set_down(&data); - - return (F_status_is_error(setting.status) || setting.status == F_false) ? 1 : 0; -} diff --git a/level_3/fss_status_code/c/print.c b/level_3/fss_status_code/c/print.c deleted file mode 100644 index faa9d73..0000000 --- a/level_3/fss_status_code/c/print.c +++ /dev/null @@ -1,135 +0,0 @@ -#include "fss_status_code.h" -#include "private-common.h" -#include "print.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_status_code_print_error_cannot_error_warning_number_ - f_status_t fss_status_code_print_error_cannot_error_warning_number(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - f_file_stream_lock(print.to); - - fl_print_format("%[%QCannot specify the '%]", print.to, print.context, print.prefix, print.context); - fl_print_format("%[%r%r%]", print.to, print.notable, f_console_symbol_long_enable_s, fss_status_code_long_error_s, print.notable); - fl_print_format("%[' parameter with the '%]", print.to, print.context, print.context); - fl_print_format("%[%r%r%]", print.to, print.notable, f_console_symbol_long_enable_s, fss_status_code_long_warning_s, print.notable); - fl_print_format("%[' parameter when not also specifying the '%]", print.to, print.context, print.context); - fl_print_format("%[%r%r%]", print.to, print.notable, f_console_symbol_long_enable_s, fss_status_code_long_number_s, print.notable); - fl_print_format("%[' parameter.%]%r", print.to, print.context, print.context, f_string_eol_s); - - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_error_cannot_error_warning_number_ - -#ifndef _di_fss_status_code_print_error_no_fss_status_codes_ - f_status_t fss_status_code_print_error_no_fss_status_codes(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - fll_print_format("%[No status code is specified.%]%r", print.to, print.context, print.context, f_string_eol_s); - - return F_none; - } -#endif // _di_fss_status_code_print_error_no_fss_status_codes_ - -#ifndef _di_fss_status_code_print_help_ - f_status_t fss_status_code_print_help(fss_status_code_setting_t * const setting, const fl_print_t print) { - - f_file_stream_lock(print.to); - - f_print_dynamic_raw(setting->line_first, print.to); - - fll_program_print_help_header(print, fss_status_code_program_name_long_s, fss_status_code_program_version_s); - - fll_program_print_help_option_standard(print); - - f_print_dynamic_raw(f_string_eol_s, print.to); - - fll_program_print_help_option(print, fss_status_code_short_fine_s, fss_status_code_long_fine_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print F_true or F_false if status code is neither an error nor a warning or print number with neither the error code nor the warning code bits set."); - fll_program_print_help_option(print, fss_status_code_short_warning_s, fss_status_code_long_warning_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Print F_true or F_false if status code is a warning or print number with warning code bit set."); - fll_program_print_help_option(print, fss_status_code_short_error_s, fss_status_code_long_error_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print F_true or F_false if status code is an error or print number with error code bit set."); - fll_program_print_help_option(print, fss_status_code_short_number_s, fss_status_code_long_number_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Convert status code name to number."); - - f_print_dynamic_raw(f_string_eol_s, print.to); - f_print_dynamic_raw(f_string_eol_s, print.to); - - fll_program_print_help_usage(print, fss_status_code_program_name_s, fss_status_code_program_help_parameters_s); - - f_print_dynamic_raw(setting->line_last, print.to); - - f_file_stream_flush(print.to); - f_file_stream_unlock(print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_help_ - -#ifndef _di_fss_status_code_print_line_first_locked_ - f_status_t fss_status_code_print_line_first_locked(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - if (!F_status_is_error(setting->status)) { - if (print.verbosity == f_console_verbosity_error_e) return F_output_not; - } - - f_print_dynamic_raw(setting->line_first, print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_line_first_locked_ - -#ifndef _di_fss_status_code_print_line_first_unlocked_ - f_status_t fss_status_code_print_line_first_unlocked(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - if (!F_status_is_error(setting->status)) { - if (print.verbosity == f_console_verbosity_error_e) return F_output_not; - } - - fll_print_dynamic_raw(setting->line_first, print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_line_first_unlocked_ - -#ifndef _di_fss_status_code_print_line_last_locked_ - f_status_t fss_status_code_print_line_last_locked(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - if (!F_status_is_error(setting->status)) { - if (print.verbosity == f_console_verbosity_error_e) return F_output_not; - } - - fll_print_dynamic_raw(setting->line_last, print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_line_last_locked_ - -#ifndef _di_fss_status_code_print_line_last_unlocked_ - f_status_t fss_status_code_print_line_last_unlocked(fss_status_code_setting_t * const setting, const fl_print_t print) { - - if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; - - if (!F_status_is_error(setting->status)) { - if (print.verbosity == f_console_verbosity_error_e) return F_output_not; - } - - f_print_dynamic_raw(setting->line_last, print.to); - - return F_none; - } -#endif // _di_fss_status_code_print_line_last_unlocked_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_status_code/c/print.h b/level_3/fss_status_code/c/print.h deleted file mode 100644 index 62c7095..0000000 --- a/level_3/fss_status_code/c/print.h +++ /dev/null @@ -1,161 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Status Code - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _fss_status_code_print_h -#define _fss_status_code_print_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Print an error message when error parameter and warning parameter are specified without number parameter. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_error_cannot_error_warning_number_ - extern f_status_t fss_status_code_print_error_cannot_error_warning_number(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_error_cannot_error_warning_number_ - -/** - * Print an error message when no status codes are provided. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_error_no_fss_status_codes_ - extern f_status_t fss_status_code_print_error_no_fss_status_codes(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_error_no_fss_status_codes_ - -/** - * Print help. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * The output structure to print to. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_help_ - extern f_status_t fss_status_code_print_help(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_help_ - -/** - * Print first new line, unless verbosity says otherwise. - * - * This is generally either the first line in the program or the first line printed before an error message. - * - * This function locks and then unlocks the input stream when printing. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_line_first_locked_ - extern f_status_t fss_status_code_print_line_first_locked(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_line_first_locked_ - -/** - * Print first new line, unless verbosity says otherwise. - * - * This is generally either the first line in the program or the first line printed before an error message. - * - * This function neither locks nor unlocks the input stream. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_line_first_unlocked_ - extern f_status_t fss_status_code_print_line_first_unlocked(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_line_first_unlocked_ - -/** - * Print last new line when the main is complete, unless verbosity says otherwise. - * - * This is generally the very last line printed in the program. - * - * This function locks and then unlocks the input stream when printing. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_line_last_locked_ - extern f_status_t fss_status_code_print_line_last_locked(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_line_last_locked_ - -/** - * Print last new line when the main is complete, unless verbosity says otherwise. - * - * This is generally the very last line printed in the program. - * - * This function neither locks nor unlocks the input stream. - * - * @param setting - * The main program settings. - * - * This does not alter setting.status. - * @param print - * Designates the how and where to print. - * - * @return - * F_none on success. - * F_output_not on success, but no printing is performed. - */ -#ifndef _di_fss_status_code_print_line_last_unlocked_ - extern f_status_t fss_status_code_print_line_last_unlocked(fss_status_code_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_status_code_print_line_last_unlocked_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _fss_status_code_print_h diff --git a/level_3/fss_status_code/c/private-common.c b/level_3/fss_status_code/c/private-common.c deleted file mode 100644 index 24a88a7..0000000 --- a/level_3/fss_status_code/c/private-common.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "fss_status_code.h" -#include "private-common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_status_code/c/private-common.h b/level_3/fss_status_code/c/private-common.h deleted file mode 100644 index 53a416e..0000000 --- a/level_3/fss_status_code/c/private-common.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Status Code - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _PRIVATE_common_h -#define _PRIVATE_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_common_h 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 deleted file mode 100644 index bd05b4a..0000000 --- a/level_3/fss_status_code/c/private-fss_status_code.c +++ /dev/null @@ -1,153 +0,0 @@ -#include "fss_status_code.h" -#include "private-common.h" -#include "private-fss_status_code.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_status_code_process_check_ - f_status_t fss_status_code_process_check(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) { - - f_number_unsigned_t number = 0; - - { - f_status_t status = fss_status_code_convert_number(main, setting, value, &number); - if (F_status_is_error(status)) return status; - } - - if ((setting->flag & fss_status_code_main_flag_error_e) && F_status_is_error(number) || (setting->flag & fss_status_code_main_flag_warning_e) && F_status_is_warning(number) || (setting->flag & fss_status_code_main_flag_fine_e) && F_status_is_fine(number)) { - f_print_dynamic_raw(f_status_true_s, main->output.to); - } - else { - f_print_dynamic_raw(f_status_false_s, main->output.to); - } - - f_print_dynamic_raw(f_string_eol_s, main->output.to); - - return F_none; - } -#endif // _di_fss_status_code_process_check_ - -#ifndef _di_fss_status_code_process_number_ - f_status_t fss_status_code_process_number(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) { - - f_status_t status = F_none; - - { - f_number_unsigned_t number = 0; - - status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, &number); - - if (status == F_none) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_invalid_name_s, main->context.set.error, f_string_eol_s); - - return F_status_set_error(F_parameter); - } - - if (status == F_data_not || F_status_set_fine(status) == F_parameter) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_invalid_main_s, main->context.set.error, f_string_eol_s); - - return status; - } - } - - f_status_t code = F_none; - - status = fll_fss_status_string_from(value, &code); - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_data) { - status = fll_status_string_from(value, &code); - } - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_unknown_name_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_failed_to_convert_s, main->context.set.error, f_string_eol_s); - } - - return status; - } - } - - if (status == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_unknown_code_s, main->context.set.error, f_string_eol_s); - - return F_none; - } - - if (setting->flag & fss_status_code_main_flag_error_e) { - code = F_status_set_error(code); - } - - if (setting->flag & fss_status_code_main_flag_warning_e) { - code = F_status_set_warning(code); - } - - fl_print_format("%ui%r", main->output.to, code, f_string_eol_s); - - return F_none; - } -#endif // _di_fss_status_code_process_number_ - -#ifndef _di_fss_status_code_process_normal_ - f_status_t fss_status_code_process_normal(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) { - - f_number_unsigned_t number = 0; - - f_status_t status = fss_status_code_convert_number(main, setting, value, &number); - if (F_status_is_error(status)) return status; - - f_string_static_t name = f_string_static_t_initialize; - - status = fll_fss_status_string_to((f_status_t) number, &name); - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_data) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_unknown_code_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_failed_to_convert_s, main->context.set.error, f_string_eol_s); - } - - return status; - } - - fl_print_format("%Q%r", main->output.to, name, f_string_eol_s); - - return F_none; - } -#endif // _di_fss_status_code_process_normal_ - -#ifndef _di_fss_status_code_convert_number_ - f_status_t fss_status_code_convert_number(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number) { - - const f_status_t status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, value, number); - - if (*number > F_status_size_max_with_bits_d) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_out_of_range_s, main->context.set.error, f_string_eol_s); - - return F_status_set_error(F_number_overflow); - } - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_number_negative) { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_out_of_range_s, main->context.set.error, f_string_eol_s); - } - else { - fl_print_format("%[%r%]%r", main->output.to, main->context.set.error, fss_status_code_invalid_number_s, main->context.set.error, f_string_eol_s); - } - - 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 deleted file mode 100644 index 56a600b..0000000 --- a/level_3/fss_status_code/c/private-fss_status_code.h +++ /dev/null @@ -1,121 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Status Code - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#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 main - * The main program data. - * @param value - * The parameter value to process. - * - * @return - * F_none on success. - * F_data_not if string starts wth a null (length is 0). - * F_parameter (with error bit) if a parameter is invalid. - * F_number (with error bit) if parameter is not a number. - * F_number_negative (with error bit) on negative value. - * F_number_overflow (with error bit) on integer overflow. - * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. - * - * Errors (with error bit) from: fss_fss_status_code_convert_number(). - * - * @see fss_fss_status_code_convert_number() - */ -#ifndef _di_fss_status_code_process_check_ - extern f_status_t fss_status_code_process_check(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; -#endif // _di_fss_status_code_process_check_ - -/** - * Perform the 'number' processes, such as --number. - * - * @param main - * The main program data. - * @param value - * The parameter value to process. - * - * @return - * F_none on success. - * F_data_not if string is empty. - * - * Errors (with error bit) from: fl_console_parameter_to_number_unsigned(). - * Errors (with error bit) from: fll_fss_status_string_from(). - * - * @see fl_console_parameter_to_number_unsigned() - * @see fll_fss_status_string_from() - */ -#ifndef _di_fss_status_code_process_number_ - extern f_status_t fss_status_code_process_number(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; -#endif // _di_fss_status_code_process_number_ - -/** - * Perform the normal processes. - * - * @param main - * The main program data. - * @param value - * The parameter value to process. - * - * @return - * F_none on success. - * F_data_not if string starts wth a null (length is 0). - * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. - * F_number (with error bit) if parameter is not a number. - * F_number_negative (with error bit) on negative value. - * F_number_overflow (with error bit) on integer overflow. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: fll_fss_status_string_from(). - * Errors (with error bit) from: fss_fss_status_code_convert_number(). - * - * @see fll_fss_status_string_from() - * @see fss_fss_status_code_convert_number() - */ -#ifndef _di_fss_status_code_process_normal_ - extern f_status_t fss_status_code_process_normal(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; -#endif // _di_fss_status_code_process_normal_ - -/** - * Convert the value string to the number, reporting any errors. - * - * @param main - * The main 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_data_not if string starts wth a null (length is 0). - * F_complete_not_utf (with error bit) if an incomplete UTF-8 fragment is found. - * F_number (with error bit) if parameter is not a number. - * F_number_negative (with error bit) on negative value. - * F_number_overflow (with error bit) on integer overflow. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: fl_console_parameter_to_number_unsigned(). - * - * @see fl_console_parameter_to_number_unsigned() - */ -#ifndef _di_fss_status_code_convert_number_ - extern f_status_t fss_status_code_convert_number(fll_program_data_t * const main, fss_status_code_setting_t * const setting, const f_string_static_t value, f_number_unsigned_t *number) F_attribute_visibility_internal_d; -#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/defines b/level_3/fss_status_code/data/build/defines deleted file mode 100644 index c665317..0000000 --- a/level_3/fss_status_code/data/build/defines +++ /dev/null @@ -1,2 +0,0 @@ -# fss-0000 - diff --git a/level_3/status_code/c/common.c b/level_3/status_code/c/common.c index b21cf92..8a6601c 100644 --- a/level_3/status_code/c/common.c +++ b/level_3/status_code/c/common.c @@ -8,11 +8,6 @@ extern "C" { const f_string_static_t status_code_program_version_s = macro_f_string_static_t_initialize(STATUS_CODE_program_version_s, 0, STATUS_CODE_program_version_s_length); #endif // _di_status_code_program_version_ -#ifndef _di_status_code_program_name_ - const f_string_static_t status_code_program_name_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_s, 0, STATUS_CODE_program_name_s_length); - const f_string_static_t status_code_program_name_long_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_long_s, 0, STATUS_CODE_program_name_long_s_length); -#endif // _di_status_code_program_name_ - #ifndef _di_status_code_program_help_parameters_ const f_string_static_t status_code_program_help_parameters_s = macro_f_string_static_t_initialize(STATUS_CODE_program_help_parameters_s, 0, STATUS_CODE_program_help_parameters_s_length); #endif // _di_status_code_program_help_parameters_ diff --git a/level_3/status_code/c/common.h b/level_3/status_code/c/common.h index bd5e3e7..2fc55de 100644 --- a/level_3/status_code/c/common.h +++ b/level_3/status_code/c/common.h @@ -49,11 +49,19 @@ extern "C" { * The program name. */ #ifndef _di_status_code_program_name_ - #define STATUS_CODE_program_name_s "status_code" - #define STATUS_CODE_program_name_long_s "Status Code" + #ifdef _status_code_as_fss_status_code + #define STATUS_CODE_program_name_s "fss_status_code" + #define STATUS_CODE_program_name_long_s "FSS Status Code" - #define STATUS_CODE_program_name_s_length 11 - #define STATUS_CODE_program_name_long_s_length 11 + #define STATUS_CODE_program_name_s_length 15 + #define STATUS_CODE_program_name_long_s_length 15 + #else + #define STATUS_CODE_program_name_s "status_code" + #define STATUS_CODE_program_name_long_s "Status Code" + + #define STATUS_CODE_program_name_s_length 11 + #define STATUS_CODE_program_name_long_s_length 11 + #endif // _status_code_as_fss_status_code extern const f_string_static_t status_code_program_name_s; extern const f_string_static_t status_code_program_name_long_s; @@ -221,6 +229,9 @@ extern "C" { * * line_first: A string expected to represent either "\n" or NULL to allow for easy handling of when to print first new line or not. * line_last: A string expected to represent either "\n" or NULL to allow for easy handling of when to print last new line or not. + * + * status_string_from: A pointer to the status string function (usually either f_status_string_from() or fll_fss_status_string_from()). + * status_string_to: A pointer to the status string function (usually either f_status_string_to() or fll_fss_status_string_to()). */ #ifndef _di_status_code_setting_t_ typedef struct { @@ -230,6 +241,9 @@ extern "C" { f_string_static_t line_first; f_string_static_t line_last; + + f_status_t (*status_string_from)(const f_string_static_t name, f_status_t * const code); + f_status_t (*status_string_to)(const f_status_t code, f_string_static_t * const name); } status_code_setting_t; #define status_code_setting_t_initialize \ @@ -238,6 +252,8 @@ extern "C" { F_none, \ f_string_static_t_initialize, \ f_string_static_t_initialize, \ + &fll_status_string_from, \ + &f_status_string_to, \ } #endif // _di_status_code_setting_t_ diff --git a/level_3/status_code/c/main-fss_status_code.c b/level_3/status_code/c/main-fss_status_code.c new file mode 100644 index 0000000..8643661 --- /dev/null +++ b/level_3/status_code/c/main-fss_status_code.c @@ -0,0 +1,45 @@ +#include "status_code.h" + +// FLL-2 includes. +#include + +#ifndef _di_status_code_program_name_ + const f_string_static_t status_code_program_name_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_s, 0, STATUS_CODE_program_name_s_length); + const f_string_static_t status_code_program_name_long_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_long_s, 0, STATUS_CODE_program_name_long_s_length); +#endif // _di_status_code_program_name_ + +int main(const int argc, const f_string_t *argv, const f_string_t *envp) { + + fll_program_data_t data = fll_program_data_t_initialize; + status_code_setting_t setting = status_code_setting_t_initialize; + + f_console_parameter_t parameters[] = status_code_console_parameter_t_initialize; + data.parameters.array = parameters; + data.parameters.used = status_code_total_parameters_d; + data.environment = envp; + + if (f_pipe_input_exists()) { + data.pipe = fll_program_data_pipe_input_e; + } + + fll_program_standard_set_up(&data); + + { + const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); + + status_code_setting_load(arguments, &data, &setting); + + setting.status_string_from = &fll_fss_status_string_from; + setting.status_string_to = &fll_fss_status_string_to; + } + + status_code_main(&data, &setting); + + status_code_setting_unload(&data, &setting); + + fll_program_data_delete(&data); + + fll_program_standard_set_down(&data); + + return (F_status_is_error(setting.status) || setting.status == F_false) ? 1 : 0; +} diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main-status_code.c similarity index 70% rename from level_3/status_code/c/main.c rename to level_3/status_code/c/main-status_code.c index 5c7ac19..e5dde74 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main-status_code.c @@ -1,5 +1,10 @@ #include "status_code.h" +#ifndef _di_status_code_program_name_ + const f_string_static_t status_code_program_name_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_s, 0, STATUS_CODE_program_name_s_length); + const f_string_static_t status_code_program_name_long_s = macro_f_string_static_t_initialize(STATUS_CODE_program_name_long_s, 0, STATUS_CODE_program_name_long_s_length); +#endif // _di_status_code_program_name_ + int main(const int argc, const f_string_t *argv, const f_string_t *envp) { fll_program_data_t data = fll_program_data_t_initialize; diff --git a/level_3/status_code/c/print.c b/level_3/status_code/c/print.c index c0c93fb..e457d5a 100644 --- a/level_3/status_code/c/print.c +++ b/level_3/status_code/c/print.c @@ -38,6 +38,23 @@ extern "C" { } #endif // _di_status_code_print_error_no_status_codes_ +#ifndef _di_status_code_print_error_invalid_callback_ + f_status_t status_code_print_error_invalid_callback(status_code_setting_t * const setting, const fl_print_t print, const f_string_t name) { + + if (print.verbosity == f_console_verbosity_quiet_e) return F_output_not; + + f_file_stream_lock(print.to); + + fl_print_format("%[%QInvalid callback specified for '%]", print.to, print.context, print.prefix, print.context); + fl_print_format("%[%s%]", print.to, print.notable, name, print.notable); + fl_print_format("%[' internal setting.%]%r", print.to, print.context, print.context, f_string_eol_s); + + f_file_stream_unlock(print.to); + + return F_none; + } +#endif // _di_status_code_print_error_invalid_callback_ + #ifndef _di_status_code_print_help_ f_status_t status_code_print_help(status_code_setting_t * const setting, const fl_print_t print) { diff --git a/level_3/status_code/c/print.h b/level_3/status_code/c/print.h index 3c65826..97a0a13 100644 --- a/level_3/status_code/c/print.h +++ b/level_3/status_code/c/print.h @@ -49,6 +49,27 @@ extern "C" { #endif // _di_status_code_print_error_no_status_codes_ /** + * Print an error message when a callback from status_code_setting_t is invalid. + * + * @param setting + * The main program settings. + * + * This does not alter setting.status. + * @param print + * Designates the how and where to print. + * @param name + * The name of the callback setting that is invalid. + * This should either be 'status_string_from' or 'status_string_to'. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + */ +#ifndef _di_status_code_print_error_invalid_callback_ + extern f_status_t status_code_print_error_invalid_callback(status_code_setting_t * const setting, const fl_print_t print, const f_string_t name); +#endif // _di_status_code_print_error_invalid_callback_ + +/** * Print help. * * @param setting diff --git a/level_3/status_code/c/private-status_code.c b/level_3/status_code/c/private-status_code.c index bf81ebf..2eb0c0e 100644 --- a/level_3/status_code/c/private-status_code.c +++ b/level_3/status_code/c/private-status_code.c @@ -54,7 +54,7 @@ extern "C" { f_status_t code = F_none; - status = fll_status_string_from(value, &code); + status = setting->status_string_from(value, &code); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_data) { @@ -97,7 +97,7 @@ extern "C" { f_string_static_t name = f_string_static_t_initialize; - status = f_status_string_to((f_status_t) number, &name); + status = setting->status_string_to((f_status_t) number, &name); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_data) { diff --git a/level_3/status_code/c/private-status_code.h b/level_3/status_code/c/private-status_code.h index 889ea70..132cbc0 100644 --- a/level_3/status_code/c/private-status_code.h +++ b/level_3/status_code/c/private-status_code.h @@ -50,10 +50,13 @@ extern "C" { * F_data_not if string is empty. * * Errors (with error bit) from: fl_console_parameter_to_number_unsigned(). - * Errors (with error bit) from: fll_fss_status_string_from(). + * Errors (with error bit) from: fll_fss_status_string_to(). + * Errors (with error bit) from: fll_status_string_from(). + * * * @see fl_console_parameter_to_number_unsigned() * @see fll_fss_status_string_from() + * @see fll_status_string_from() */ #ifndef _di_status_code_process_number_ extern f_status_t status_code_process_number(fll_program_data_t * const main, status_code_setting_t * const setting, const f_string_static_t value) F_attribute_visibility_internal_d; @@ -76,10 +79,12 @@ extern "C" { * F_number_overflow (with error bit) on integer overflow. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: fll_fss_status_string_from(). + * Errors (with error bit) from: f_status_string_to(). + * Errors (with error bit) from: fll_fss_status_string_to(). * Errors (with error bit) from: fss_status_code_convert_number(). * - * @see fll_fss_status_string_from() + * @see f_status_string_to() + * @see fll_fss_status_string_to() * @see fss_status_code_convert_number() */ #ifndef _di_status_code_process_normal_ diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 44d3624..26881be 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -11,6 +11,21 @@ extern "C" { if (!main || !setting || F_status_is_error(setting->status)) return; + if (!setting->status_string_from || !setting->status_string_to) { + + if (!setting->status_string_from) { + status_code_print_error_invalid_callback(setting, main->error, "status_string_from"); + } + + if (!setting->status_string_to) { + status_code_print_error_invalid_callback(setting, main->error, "status_string_to"); + } + + setting->status = F_status_set_error(F_parameter); + + return; + } + setting->status = F_none; if (setting->flag & status_code_main_flag_help_e) { diff --git a/level_3/status_code/data/build/defines b/level_3/status_code/data/build/defines index c665317..f8ebb04 100644 --- a/level_3/status_code/data/build/defines +++ b/level_3/status_code/data/build/defines @@ -1,2 +1,5 @@ # fss-0000 +# +# Defines for the "status_code" program. +# diff --git a/level_3/status_code/data/build/defines.fss_status_code b/level_3/status_code/data/build/defines.fss_status_code new file mode 100644 index 0000000..10ae951 --- /dev/null +++ b/level_3/status_code/data/build/defines.fss_status_code @@ -0,0 +1,5 @@ +# fss-0000 +# +# Defines for the "fss_status_code" program. +# +_status_code_as_fss_status_code Compile the fss_status_code program rather than the status_code program. diff --git a/level_3/status_code/data/build/dependencies b/level_3/status_code/data/build/dependencies index 0f3432b..d60ae8b 100644 --- a/level_3/status_code/data/build/dependencies +++ b/level_3/status_code/data/build/dependencies @@ -1,4 +1,7 @@ # fss-0000 +# +# Dependencies for the "status_code" program. +# f_type f_status diff --git a/level_3/fss_status_code/data/build/dependencies b/level_3/status_code/data/build/dependencies.fss_status_code similarity index 82% rename from level_3/fss_status_code/data/build/dependencies rename to level_3/status_code/data/build/dependencies.fss_status_code index a1d3955..3027384 100644 --- a/level_3/fss_status_code/data/build/dependencies +++ b/level_3/status_code/data/build/dependencies.fss_status_code @@ -1,4 +1,7 @@ # fss-0000 +# +# Dependencies for the "fss_status_code" program. +# f_type f_status @@ -8,8 +11,6 @@ f_utf f_color f_console f_conversion -f_directory -f_environment f_file f_fss f_pipe @@ -21,8 +22,6 @@ fl_fss fl_print fl_string fll_error -fll_file -fll_fss fll_fss_status_string fll_print fll_program diff --git a/level_3/status_code/data/build/fakefile b/level_3/status_code/data/build/fakefile new file mode 100644 index 0000000..286fa07 --- /dev/null +++ b/level_3/status_code/data/build/fakefile @@ -0,0 +1,21 @@ +# fss-0005 iki-0002 + +settings: + fail exit + modes monolithic level individual + + environment PATH LD_LIBRARY_PATH + +main: + if parameter mode + operate using_mode + else + operate using_default + +using_default: + build settings + build settings.fss_status_code + +using_mode: + build settings parameter:'mode:value' + build settings.fss_status_code parameter:'mode:value' diff --git a/level_3/status_code/data/build/settings b/level_3/status_code/data/build/settings index d4692cf..366d881 100644 --- a/level_3/status_code/data/build/settings +++ b/level_3/status_code/data/build/settings @@ -1,4 +1,7 @@ # fss-0001 +# +# Settings for the "status_code" program. +# build_name status_code @@ -24,7 +27,7 @@ build_libraries-monolithic -lfll build_sources_library status_code.c common.c print.c private-common.c private-status_code.c -build_sources_program main.c +build_sources_program main-status_code.c build_sources_headers status_code.h common.h print.h diff --git a/level_3/fss_status_code/data/build/settings b/level_3/status_code/data/build/settings.fss_status_code similarity index 67% rename from level_3/fss_status_code/data/build/settings rename to level_3/status_code/data/build/settings.fss_status_code index f223e89..dedfadb 100644 --- a/level_3/fss_status_code/data/build/settings +++ b/level_3/status_code/data/build/settings.fss_status_code @@ -1,4 +1,7 @@ # fss-0001 +# +# Settings for the "fss_status_code" program. +# build_name fss_status_code @@ -17,22 +20,18 @@ build_indexer ar build_indexer_arguments rcs build_language c -build_libraries -lc -build_libraries-individual -lfll_error -lfll_file -lfll_fss -lfll_fss_status_string -lfll_print -lfll_program -lfll_status_string -lfl_conversion -lfl_directory -lfl_fss -lfl_print -lfl_string -lf_color -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_signal -lf_status_string -lf_string -lf_type_array -lf_utf +build_libraries -lc -lstatus_code +build_libraries-individual -lfll_error -lfll_fss_status_string -lfll_print -lfll_program -lfll_status_string -lfl_conversion -lfl_fss -lfl_print -lfl_string -lf_color -lf_console -lf_conversion -lf_file -lf_fss -lf_memory -lf_pipe -lf_print -lf_signal -lf_status_string -lf_string -lf_type_array -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll -build_sources_library fss_status_code.c common.c print.c private-common.c private-fss_status_code.c - -build_sources_program main.c - -build_sources_headers fss_status_code.h common.h print.h +build_sources_program main-fss_status_code.c build_script yes build_shared yes build_static no -path_headers program/fss_status_code +path_headers program/status_code path_library_script script path_library_shared shared path_library_static static @@ -52,6 +51,8 @@ search_static yes environment PATH LD_LIBRARY_PATH +defines -D_status_code_as_fss_status_code + #defines -D_di_libcap_ -D_di_thread_support_ defines -D_libcap_legacy_only_ -D_pthread_attr_unsupported_ -D_pthread_sigqueue_unsupported_