From 7adc53ec79b1550e452d10b32d6fb51b4d5cde00 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 24 Jun 2023 22:15:39 -0500 Subject: [PATCH] Update: The FSS Identify program to the latest practices. --- level_3/fss_identify/c/common.c | 165 ---------- level_3/fss_identify/c/common.h | 282 ----------------- level_3/fss_identify/c/fss_identify.c | 288 ------------------ level_3/fss_identify/c/main/common.c | 332 +++++++++++++++++++++ level_3/fss_identify/c/main/common.h | 48 +++ level_3/fss_identify/c/main/common/define.c | 9 + level_3/fss_identify/c/main/common/define.h | 56 ++++ level_3/fss_identify/c/main/common/enumeration.c | 9 + level_3/fss_identify/c/main/common/enumeration.h | 128 ++++++++ level_3/fss_identify/c/main/common/print.c | 26 ++ level_3/fss_identify/c/main/common/print.h | 61 ++++ level_3/fss_identify/c/main/common/string.c | 36 +++ level_3/fss_identify/c/main/common/string.h | 117 ++++++++ level_3/fss_identify/c/main/common/type.c | 35 +++ level_3/fss_identify/c/main/common/type.h | 131 ++++++++ level_3/fss_identify/c/main/fss_identify.c | 101 +++++++ level_3/fss_identify/c/{ => main}/fss_identify.h | 45 +-- level_3/fss_identify/c/main/load.c | 57 ++++ level_3/fss_identify/c/main/load.h | 44 +++ level_3/fss_identify/c/{ => main}/main.c | 45 ++- level_3/fss_identify/c/{ => main}/main.h | 0 level_3/fss_identify/c/main/print/data.c | 51 ++++ level_3/fss_identify/c/main/print/data.h | 61 ++++ level_3/fss_identify/c/main/print/error.c | 86 ++++++ level_3/fss_identify/c/main/print/error.h | 142 +++++++++ .../c/{print.c => main/print/message.c} | 51 ++-- level_3/fss_identify/c/main/print/message.h | 52 ++++ level_3/fss_identify/c/main/process.c | 161 ++++++++++ level_3/fss_identify/c/main/process.h | 75 +++++ level_3/fss_identify/c/main/signal.c | 113 +++++++ level_3/fss_identify/c/main/signal.h | 86 ++++++ level_3/fss_identify/c/main/thread.c | 26 ++ level_3/fss_identify/c/main/thread.h | 46 +++ level_3/fss_identify/c/print.h | 36 --- level_3/fss_identify/c/private-common.c | 19 -- level_3/fss_identify/c/private-common.h | 59 ---- level_3/fss_identify/c/private-identify.c | 198 ------------ level_3/fss_identify/c/private-identify.h | 100 ------- level_3/fss_identify/c/private-print.c | 34 --- level_3/fss_identify/c/private-print.h | 31 -- level_3/fss_identify/data/build/settings | 6 +- 41 files changed, 2181 insertions(+), 1267 deletions(-) delete mode 100644 level_3/fss_identify/c/common.c delete mode 100644 level_3/fss_identify/c/common.h delete mode 100644 level_3/fss_identify/c/fss_identify.c create mode 100644 level_3/fss_identify/c/main/common.c create mode 100644 level_3/fss_identify/c/main/common.h create mode 100644 level_3/fss_identify/c/main/common/define.c create mode 100644 level_3/fss_identify/c/main/common/define.h create mode 100644 level_3/fss_identify/c/main/common/enumeration.c create mode 100644 level_3/fss_identify/c/main/common/enumeration.h create mode 100644 level_3/fss_identify/c/main/common/print.c create mode 100644 level_3/fss_identify/c/main/common/print.h create mode 100644 level_3/fss_identify/c/main/common/string.c create mode 100644 level_3/fss_identify/c/main/common/string.h create mode 100644 level_3/fss_identify/c/main/common/type.c create mode 100644 level_3/fss_identify/c/main/common/type.h create mode 100644 level_3/fss_identify/c/main/fss_identify.c rename level_3/fss_identify/c/{ => main}/fss_identify.h (56%) create mode 100644 level_3/fss_identify/c/main/load.c create mode 100644 level_3/fss_identify/c/main/load.h rename level_3/fss_identify/c/{ => main}/main.c (51%) rename level_3/fss_identify/c/{ => main}/main.h (100%) create mode 100644 level_3/fss_identify/c/main/print/data.c create mode 100644 level_3/fss_identify/c/main/print/data.h create mode 100644 level_3/fss_identify/c/main/print/error.c create mode 100644 level_3/fss_identify/c/main/print/error.h rename level_3/fss_identify/c/{print.c => main/print/message.c} (54%) create mode 100644 level_3/fss_identify/c/main/print/message.h create mode 100644 level_3/fss_identify/c/main/process.c create mode 100644 level_3/fss_identify/c/main/process.h create mode 100644 level_3/fss_identify/c/main/signal.c create mode 100644 level_3/fss_identify/c/main/signal.h create mode 100644 level_3/fss_identify/c/main/thread.c create mode 100644 level_3/fss_identify/c/main/thread.h delete mode 100644 level_3/fss_identify/c/print.h delete mode 100644 level_3/fss_identify/c/private-common.c delete mode 100644 level_3/fss_identify/c/private-common.h delete mode 100644 level_3/fss_identify/c/private-identify.c delete mode 100644 level_3/fss_identify/c/private-identify.h delete mode 100644 level_3/fss_identify/c/private-print.c delete mode 100644 level_3/fss_identify/c/private-print.h diff --git a/level_3/fss_identify/c/common.c b/level_3/fss_identify/c/common.c deleted file mode 100644 index 544d3bd..0000000 --- a/level_3/fss_identify/c/common.c +++ /dev/null @@ -1,165 +0,0 @@ -#include "fss_identify.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_identify_program_version_s_ - const f_string_static_t fss_identify_program_version_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_version_s, 0, FSS_IDENTIFY_program_version_s_length); -#endif // _di_fss_identify_program_version_s_ - -#ifndef _di_fss_identify_program_name_s_ - const f_string_static_t fss_identify_program_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_name_s, 0, FSS_IDENTIFY_program_name_s_length); - const f_string_static_t fss_identify_program_name_long_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_name_long_s, 0, FSS_IDENTIFY_program_name_long_s_length); -#endif // _di_fss_identify_program_name_s_ - -#ifndef _di_fss_identify_parameter_d_ - const f_string_static_t fss_identify_short_content_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_content_s, 0, FSS_IDENTIFY_short_content_s_length); - const f_string_static_t fss_identify_short_line_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_line_s, 0, FSS_IDENTIFY_short_line_s_length); - const f_string_static_t fss_identify_short_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_name_s, 0, FSS_IDENTIFY_short_name_s_length); - const f_string_static_t fss_identify_short_object_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_object_s, 0, FSS_IDENTIFY_short_object_s_length); - const f_string_static_t fss_identify_short_total_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_total_s, 0, FSS_IDENTIFY_short_total_s_length); - - const f_string_static_t fss_identify_long_content_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_content_s, 0, FSS_IDENTIFY_long_content_s_length); - const f_string_static_t fss_identify_long_line_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_line_s, 0, FSS_IDENTIFY_long_line_s_length); - const f_string_static_t fss_identify_long_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_name_s, 0, FSS_IDENTIFY_long_name_s_length); - const f_string_static_t fss_identify_long_object_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_object_s, 0, FSS_IDENTIFY_long_object_s_length); - const f_string_static_t fss_identify_long_total_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_total_s, 0, FSS_IDENTIFY_long_total_s_length); -#endif // _di_fss_identify_parameter_d_ - -#ifndef _di_fss_identify_setting_delete_ - f_status_t fss_identify_setting_delete(fss_identify_setting_t * const setting) { - - if (!setting) return F_status_set_error(F_parameter); - - return F_none; - } -#endif // _di_fss_identify_setting_delete_ - -#ifndef _di_fss_identify_setting_load_ - void fss_identify_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_identify_setting_t * const setting) { - - if (!main) return; - - main->setting.state.step_small = fss_identify_allocation_console_d; - - f_console_parameter_process(arguments, &main->program.parameters, &main->setting.state, 0); - - main->setting.state.step_small = fss_identify_allocation_small_d; - - // Identify and pocess first/last parameters. - if (main->program.parameters.array[fss_identify_parameter_line_first_no_e].result & f_console_result_found_e) { - main->setting.flag -= main->setting.flag & fss_identify_main_flag_print_first_e; - } - else { - main->setting.flag |= fss_identify_main_flag_print_first_e; - } - - if (main->program.parameters.array[fss_identify_parameter_line_last_no_e].result & f_console_result_found_e) { - main->setting.flag -= main->setting.flag & fss_identify_main_flag_print_last_e; - } - else { - main->setting.flag |= fss_identify_main_flag_print_last_e; - } - - if (F_status_is_error(main->setting.state.status)) { - fll_error_print(&main->program.error, F_status_set_fine(main->setting.state.status), "f_console_parameter_process", fll_error_file_flag_fallback_e); - - if (main->program.error.verbosity > f_console_verbosity_quiet_e) { - fll_print_dynamic_raw(f_string_eol_s, main->program.error); - } - - return; - } - - { - f_number_unsigned_t choice = 0; - f_uint16s_t choices = f_uint16s_t_initialize; - - // Identify and prioritize "color context" parameters. - { - uint16_t choices_array[3] = { fss_identify_parameter_no_color_e, fss_identify_parameter_light_e, fss_identify_parameter_dark_e }; - choices.array = choices_array; - choices.used = 3; - - static const uint8_t modes[3] = { f_color_mode_not_e, f_color_mode_light_e, f_color_mode_dark_e }; - - main->setting.state.status = fll_program_parameter_process_context(choices, modes, F_true, &main->program); - - if (F_status_is_error(main->setting.state.status)) { - fll_error_print(&main->program.error, F_status_set_fine(main->setting.state.status), "fll_program_parameter_process_context", fll_error_file_flag_fallback_e); - - if (main->program.error.verbosity > f_console_verbosity_quiet_e) { - fll_print_dynamic_raw(f_string_eol_s, main->program.error); - } - - return; - } - } - - // Identify and prioritize "verbosity" parameters. - { - uint16_t choices_array[5] = { fss_identify_parameter_verbosity_quiet_e, fss_identify_parameter_verbosity_error_e, fss_identify_parameter_verbosity_verbose_e, fss_identify_parameter_verbosity_debug_e, fss_identify_parameter_verbosity_normal_e }; - choices.array = choices_array; - choices.used = 5; - - static 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 }; - - main->setting.state.status = fll_program_parameter_process_verbosity(choices, verbosity, F_true, &main->program); - - if (F_status_is_error(main->setting.state.status)) { - fll_error_print(&main->program.error, F_status_set_fine(main->setting.state.status), "fll_program_parameter_process_verbosity", fll_error_file_flag_fallback_e); - - if (main->program.error.verbosity > f_console_verbosity_quiet_e) { - fll_print_dynamic_raw(f_string_eol_s, main->program.error); - } - - return; - } - } - } - - main->program.output.to.id = F_type_descriptor_output_d; - main->program.output.to.stream = F_type_output_d; - main->program.output.to.flag = F_file_flag_create_d | F_file_flag_write_only_d | F_file_flag_append_d; - - if (main->program.parameters.array[fss_identify_parameter_help_e].result & f_console_result_found_e) { - main->setting.flag |= fss_identify_main_flag_help_e; - - return; - } - - if (main->program.parameters.array[fss_identify_parameter_version_e].result & f_console_result_found_e) { - main->setting.flag |= fss_identify_main_flag_version_e; - - return; - } - - if (main->program.parameters.array[fss_identify_parameter_copyright_e].result & f_console_result_found_e) { - main->setting.flag |= fss_identify_main_flag_copyright_e; - - return; - } - - f_string_static_t * const args = main->program.parameters.arguments.array; - - if (main->program.parameters.array[fss_identify_parameter_strip_invalid_e].result & f_console_result_found_e) { - main->setting.flag |= fss_identify_main_flag_strip_invalid_e; - } - } -#endif // _di_fss_identify_setting_load_ - -#ifndef _di_fss_identify_setting_unload_ - f_status_t fss_identify_setting_unload(fss_identify_main_t * const main) { - - if (!main) return F_status_set_error(F_parameter); - - fss_identify_setting_delete(&main->setting); - - return F_none; - } -#endif // _di_fss_identify_setting_unload_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_identify/c/common.h b/level_3/fss_identify/c/common.h deleted file mode 100644 index 80dfa84..0000000 --- a/level_3/fss_identify/c/common.h +++ /dev/null @@ -1,282 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Identify - * 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_identify_common_h -#define _fss_identify_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The program version. - */ -#ifndef _di_fss_identify_program_version_s_ - #define FSS_IDENTIFY_program_version_major_s F_string_ascii_0_s - #define FSS_IDENTIFY_program_version_minor_s F_string_ascii_7_s - #define FSS_IDENTIFY_program_version_micro_s F_string_ascii_0_s - - #define FSS_IDENTIFY_program_version_major_s_length F_string_ascii_0_s_length - #define FSS_IDENTIFY_program_version_minor_s_length F_string_ascii_7_s_length - #define FSS_IDENTIFY_program_version_micro_s_length F_string_ascii_0_s_length - - #if !(defined(FSS_IDENTIFY_program_version_nano_prefix_s) && defined(FSS_IDENTIFY_program_version_nano_prefix_s_length)) - #define FSS_IDENTIFY_program_version_nano_prefix_s - #define FSS_IDENTIFY_program_version_nano_prefix_s_length 0 - #endif // !(defined(FSS_IDENTIFY_program_version_nano_prefix_s) && defined(FSS_IDENTIFY_program_version_nano_prefix_s_length)) - - #if !(defined(FSS_IDENTIFY_program_version_nano_s) && defined(FSS_IDENTIFY_program_version_nano_s_length)) - #define FSS_IDENTIFY_program_version_nano_s - #define FSS_IDENTIFY_program_version_nano_s_length 0 - #endif // !(defined(FSS_IDENTIFY_program_version_nano_s) && defined(FSS_IDENTIFY_program_version_nano_s_length)) - - #define FSS_IDENTIFY_program_version_s FSS_IDENTIFY_program_version_major_s F_string_ascii_period_s FSS_IDENTIFY_program_version_minor_s F_string_ascii_period_s FSS_IDENTIFY_program_version_micro_s FSS_IDENTIFY_program_version_nano_prefix_s FSS_IDENTIFY_program_version_nano_s - - #define FSS_IDENTIFY_program_version_s_length FSS_IDENTIFY_program_version_major_s_length + F_string_ascii_period_s_length + FSS_IDENTIFY_program_version_minor_s_length + F_string_ascii_period_s_length + FSS_IDENTIFY_program_version_micro_s_length + FSS_IDENTIFY_program_version_nano_prefix_s_length + FSS_IDENTIFY_program_version_nano_s_length - - extern const f_string_static_t fss_identify_program_version_s; -#endif // _di_fss_identify_program_version_s_ - -/** - * The program name. - */ -#ifndef _di_fss_identify_program_name_s_ - #define FSS_IDENTIFY_program_name_s "fss_identify" - #define FSS_IDENTIFY_program_name_long_s "FSS Identify" - - #define FSS_IDENTIFY_program_name_s_length 12 - #define FSS_IDENTIFY_program_name_long_s_length 12 - - extern const f_string_static_t fss_identify_program_name_s; - extern const f_string_static_t fss_identify_program_name_long_s; -#endif // _di_fss_identify_program_name_s_ - -/** - * The program defines. - * - * fss_identify_*_d: - * - allocation_console: An allocation step used for small buffers specifically for console parameter. - * - allocation_large: An allocation step used for buffers that are anticipated to have large buffers. - * - allocation_small: An allocation step used for buffers that are anticipated to have small buffers. - * - signal_check: Number of iterations before performing signal check in non-threaded signal handling. - */ -#ifndef _di_fss_identify_d_ - #define fss_identify_allocation_console_d 4 - #define fss_identify_allocation_large_d 256 - #define fss_identify_allocation_small_d 16 - #define fss_identify_signal_check_d 20000 -#endif // _di_fss_identify_d_ - -/** - * The main program parameters. - */ -#ifndef _di_fss_identify_parameter_d_ - #define FSS_IDENTIFY_short_content_s "c" - #define FSS_IDENTIFY_short_line_s "l" - #define FSS_IDENTIFY_short_name_s "n" - #define FSS_IDENTIFY_short_object_s "o" - #define FSS_IDENTIFY_short_total_s "t" - - #define FSS_IDENTIFY_long_content_s "content" - #define FSS_IDENTIFY_long_line_s "line" - #define FSS_IDENTIFY_long_name_s "name" - #define FSS_IDENTIFY_long_object_s "object" - #define FSS_IDENTIFY_long_total_s "total" - - #define FSS_IDENTIFY_short_content_s_length 1 - #define FSS_IDENTIFY_short_line_s_length 1 - #define FSS_IDENTIFY_short_name_s_length 1 - #define FSS_IDENTIFY_short_object_s_length 1 - #define FSS_IDENTIFY_short_total_s_length 1 - - #define FSS_IDENTIFY_long_content_s_length 7 - #define FSS_IDENTIFY_long_line_s_length 4 - #define FSS_IDENTIFY_long_name_s_length 4 - #define FSS_IDENTIFY_long_object_s_length 6 - #define FSS_IDENTIFY_long_total_s_length 5 - - extern const f_string_static_t fss_identify_short_content_s; - extern const f_string_static_t fss_identify_short_line_s; - extern const f_string_static_t fss_identify_short_name_s; - extern const f_string_static_t fss_identify_short_object_s; - extern const f_string_static_t fss_identify_short_total_s; - - extern const f_string_static_t fss_identify_long_content_s; - extern const f_string_static_t fss_identify_long_line_s; - extern const f_string_static_t fss_identify_long_name_s; - extern const f_string_static_t fss_identify_long_object_s; - extern const f_string_static_t fss_identify_long_total_s; - - enum { - fss_identify_parameter_help_e, - fss_identify_parameter_copyright_e, - fss_identify_parameter_light_e, - fss_identify_parameter_dark_e, - fss_identify_parameter_no_color_e, - fss_identify_parameter_verbosity_quiet_e, - fss_identify_parameter_verbosity_error_e, - fss_identify_parameter_verbosity_normal_e, - fss_identify_parameter_verbosity_verbose_e, - fss_identify_parameter_verbosity_debug_e, - fss_identify_parameter_version_e, - fss_identify_parameter_line_first_no_e, - fss_identify_parameter_line_last_no_e, - - fss_identify_parameter_content_e, - fss_identify_parameter_line_e, - fss_identify_parameter_name_e, - fss_identify_parameter_object_e, - fss_identify_parameter_total_e, - }; // enum - - #define fss_identify_console_parameter_t_initialize \ - { \ - macro_fll_program_console_parameter_standard_initialize, \ - \ - macro_f_console_parameter_t_initialize_3(fss_identify_short_content_s, fss_identify_long_content_s, 0, 0, f_console_flag_normal_e), \ - macro_f_console_parameter_t_initialize_3(fss_identify_short_line_s, fss_identify_long_line_s, 0, 1, f_console_flag_normal_e), \ - macro_f_console_parameter_t_initialize_3(fss_identify_short_name_s, fss_identify_long_name_s, 0, 1, f_console_flag_normal_e), \ - macro_f_console_parameter_t_initialize_3(fss_identify_short_object_s, fss_identify_long_object_s, 0, 0, f_console_flag_normal_e), \ - macro_f_console_parameter_t_initialize_3(fss_identify_short_total_s, fss_identify_long_total_s, 0, 0, f_console_flag_normal_e), \ - } - - #define fss_identify_parameter_total_d 18 -#endif // _di_fss_identify_parameter_d_ - -/** - * Flags passed to the main function or program. - * - * fss_identify_main_flag_*_e: - * - none: No flags set. - * - copyright: Print copyright. - * - file_from: Using a specified source file. - * - file_to: Using a specified destination file. - * - help: Print help. - * - header: Enable printing of headers. - * - print_first: When set, print new line to message output on program begin after loading settings. - * - print_last: When set, print new line to message output on program end. - * - separate: Enable printing of separators. - * - strip_invalid: Using strip invalid character mode. - * - verify: Using verify mode. - * - version: Print version. - */ -#ifndef _di_fss_identify_main_flag_e_ - enum { - fss_identify_main_flag_none_e = 0x0, - fss_identify_main_flag_copyright_e = 0x1, - fss_identify_main_flag_file_from_e = 0x2, - fss_identify_main_flag_file_to_e = 0x4, - fss_identify_main_flag_header_e = 0x8, - fss_identify_main_flag_help_e = 0x10, - fss_identify_main_flag_print_first_e = 0x20, - fss_identify_main_flag_print_last_e = 0x40, - fss_identify_main_flag_separate_e = 0x80, - fss_identify_main_flag_strip_invalid_e = 0x100, - fss_identify_main_flag_verify_e = 0x200, - fss_identify_main_flag_version_e = 0x400, - }; // enum -#endif // _di_fss_identify_main_flag_e_ - -/** - * The fss identify 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. - * - * state: The state information. - */ -#ifndef _di_fss_identify_setting_t_ - typedef struct { - uint16_t flag; - - f_state_t state; - } fss_identify_setting_t; - - #define fss_identify_setting_t_initialize \ - { \ - fss_identify_main_flag_none_e, \ - f_state_t_initialize, \ - } -#endif // _di_fss_identify_setting_t_ - -/** - * Delete the program main setting data. - * - * @param setting - * The program main setting data. - * - * This does not alter setting.state.status. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - */ -#ifndef _di_fss_identify_setting_delete_ - extern f_status_t fss_identify_setting_delete(fss_identify_setting_t * const setting); -#endif // _di_fss_identify_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 returns 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.state.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_identify_setting_load_ - extern void fss_identify_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, fss_identify_setting_t * const setting); -#endif // _di_fss_identify_setting_load_ - -/** - * Perform the standard program setting unload process. - * - * @param main - * The main program and setting data. - * All buffers are deallocated. - * - * This does not alter main.setting.state.status. - * - * @return - * F_none on success. - * - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: fss_identify_setting_delete(). - * - * @see fss_identify_setting_delete() - */ -#ifndef _di_fss_identify_setting_unload_ - extern f_status_t fss_identify_setting_unload(fss_identify_main_t * const main); -#endif // _di_fss_identify_setting_unload_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _fss_identify_common_h diff --git a/level_3/fss_identify/c/fss_identify.c b/level_3/fss_identify/c/fss_identify.c deleted file mode 100644 index 368c911..0000000 --- a/level_3/fss_identify/c/fss_identify.c +++ /dev/null @@ -1,288 +0,0 @@ -#include "fss_identify.h" -#include "private-common.h" -#include "private-identify.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_identify_main_ - f_status_t fss_identify_main(fll_program_data_t * const main, fss_identify_setting_t * const setting) { - - f_status_t status = F_none; - - setting->state.step_small = fss_identify_allocation_console_d; - - status = f_console_parameter_process(arguments, &main->parameters, &setting->state, 0); - - setting->state.step_small = fss_identify_allocation_small_d; - - if (F_status_is_error(status)) return; - - { - f_number_unsigned_t choice = 0; - f_uint16s_t choices = f_uint16s_t_initialize; - - // Identify and prioritize "color context" parameters. - { - uint16_t choices_array[3] = { fss_identify_parameter_no_color_e, fss_identify_parameter_light_e, fss_identify_parameter_dark_e }; - choices.array = choices_array; - choices.used = 3; - - static const uint8_t modes[3] = { f_color_mode_not_e, f_color_mode_light_e, f_color_mode_dark_e }; - - status = fll_program_parameter_process_context(choices, modes, F_true, &main->program); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process_context", fll_error_file_flag_fallback_e); - - if (main->error.verbosity > f_console_verbosity_quiet_e) { - fll_print_dynamic_raw(f_string_eol_s, main->error); - } - - return; - } - } - - // Identify and prioritize "verbosity" parameters. - { - uint16_t choices_array[5] = { fss_identify_parameter_verbosity_quiet_e, fss_identify_parameter_verbosity_error_e, fss_identify_parameter_verbosity_verbose_e, fss_identify_parameter_verbosity_debug_e, fss_identify_parameter_verbosity_normal_e }; - choices.array = choices_array; - choices.used = 5; - - static 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 }; - - status = fll_program_parameter_process_verbosity(choices, verbosity, F_true, &main->program); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process_verbosity", fll_error_file_flag_fallback_e); - - if (main->error.verbosity > f_console_verbosity_quiet_e) { - fll_print_dynamic_raw(f_string_eol_s, main->error); - } - - return; - } - } - } - - if (main->parameters.array[fss_identify_parameter_help_e].result & f_console_result_found_e) { - fss_identify_print_help(setting, main->message); - - return F_none; - } - - if (main->parameters.array[fss_identify_parameter_version_e].result & f_console_result_found_e) { - fll_program_print_version(&main->message, fss_identify_program_version_s); - - return F_none; - } - - if (main->parameters.array[fss_identify_parameter_copyright_e].result & f_console_result_found_e) { - fll_program_print_copyright(&main->message); - - return F_none; - } - - status = F_none; - - fss_identify_data_t data = fss_identify_data_t_initialize; - - data.argv = main->parameters.arguments.array; - - if (F_status_is_error_not(status)) { - if (main->parameters.array[fss_identify_parameter_line_e].result & f_console_result_found_e) { - f_file_stream_lock(main->error.to); - - fl_print_format("%r%[%QThe parameter '%]", main->error.to, f_string_eol_s, main->error.context, main->error.prefix, main->error.context); - fl_print_format("%[%r%r%]", main->error.to, main->error.notable, f_console_symbol_long_normal_s, fss_identify_long_line_s, main->error.notable); - fl_print_format("%[' requires a positive number.%]%r", main->error.to, main->error.context, main->error.context, f_string_eol_s); - - f_file_stream_unlock(main->error.to); - - status = F_status_set_error(F_parameter); - } - else if (main->parameters.array[fss_identify_parameter_line_e].result & f_console_result_value_e) { - const f_number_unsigned_t index = main->parameters.array[fss_identify_parameter_line_e].values.array[main->parameters.array[fss_identify_parameter_line_e].values.used - 1]; - - status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, data.argv[index], &data.line); - - if (F_status_is_error(status)) { - fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_dynamic_to_unsigned_detect", F_true, fss_identify_long_line_s, data.argv[index]); - } - } - } - - if (F_status_is_error_not(status) && (main->parameters.array[fss_identify_parameter_total_e].result & f_console_result_found_e)) { - if (main->parameters.array[fss_identify_parameter_object_e].result & f_console_result_found_e) { - if (main->error.verbosity > f_console_verbosity_quiet_e) { - fll_program_print_error_parameter_cannot_use_with(&main->error, f_console_symbol_long_normal_s, f_console_symbol_long_normal_s, fss_identify_long_object_s, fss_identify_long_total_s); - } - - status = F_status_set_error(F_parameter); - } - else if (main->parameters.array[fss_identify_parameter_content_e].result & f_console_result_found_e) { - if (main->error.verbosity > f_console_verbosity_quiet_e) { - fll_program_print_error_parameter_cannot_use_with(&main->error, f_console_symbol_long_normal_s, f_console_symbol_long_normal_s, f_console_symbol_long_normal_s, fss_identify_long_content_s, fss_identify_long_total_s); - } - - status = F_status_set_error(F_parameter); - } - } - - if (F_status_is_error_not(status)) { - if (main->parameters.array[fss_identify_parameter_name_e].result & f_console_result_found_e) { - f_file_stream_lock(main->error.to); - - fl_print_format("%r%[%QThe parameter '%]", main->error.to, f_string_eol_s, main->error.context, main->error.prefix, main->error.context); - fl_print_format("%[%r%r%]", main->error.to, main->error.notable, f_console_symbol_long_normal_s, fss_identify_long_name_s, main->error.notable); - fl_print_format("%[' requires a string.%]%r", main->error.to, main->error.context, main->error.context, f_string_eol_s); - - f_file_stream_unlock(main->error.to); - - status = F_status_set_error(F_parameter); - } - else if (main->parameters.array[fss_identify_parameter_name_e].result & f_console_result_value_e) { - const f_number_unsigned_t index = main->parameters.array[fss_identify_parameter_name_e].values.array[main->parameters.array[fss_identify_parameter_name_e].values.used - 1]; - const f_number_unsigned_t length = data.argv[index].used; - const f_string_range_t range = macro_f_string_range_t_initialize_2(length); - - if (length == 0) { - f_file_stream_lock(main->error.to); - - fl_print_format("%r%[%QThe parameter '%]", main->error.to, f_string_eol_s, main->error.context, main->error.prefix, main->error.context); - fl_print_format("%[%r%r%]", main->error.to, main->error.notable, f_console_symbol_long_normal_s, fss_identify_long_name_s, main->error.notable); - fl_print_format("%[' does not allow zero length strings.%]%r", main->error.to, main->error.context, main->error.context, f_string_eol_s); - - f_file_stream_unlock(main->error.to); - - status = F_status_set_error(F_parameter); - } - else { - status = f_string_dynamic_resize(length, &data.name); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "f_utf_is_word", fll_error_file_flag_fallback_e); - } - } - - if (F_status_is_error_not(status)) { - - for (f_number_unsigned_t i = range.start; i <= range.stop; ++i) { - - status = f_utf_is_word_dash(data.argv[index].string + i, length, F_true); - - if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "f_utf_is_word_dash", fll_error_file_flag_fallback_e); - - break; - } - else if (status == F_false) { - f_file_stream_lock(main->error.to); - - fl_print_format("%r%[%QThe value '%]", main->error.to, f_string_eol_s, main->error.context, main->error.prefix, main->error.context); - fl_print_format("%[%Q%]", main->error.to, main->error.notable, data.argv[index], main->error.notable); - fl_print_format("%[' for the parameter '%]", main->error.to, main->error.context, main->error.context); - fl_print_format("%[%r%r%]", main->error.to, main->error.notable, f_console_symbol_long_normal_s, fss_identify_long_name_s, main->error.notable); - fl_print_format("%[' may only contain word characters or the dash (minus)y character.%]%r", main->error.to, main->error.context, main->error.context, f_string_eol_s); - - f_file_stream_unlock(main->error.to); - - status = F_status_set_error(F_parameter); - - break; - } - - data.name.string[data.name.used++] = data.argv[index].string[i]; - } // for - } - } - } - - f_string_range_t range = f_string_range_t_initialize; - f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_file_t file = f_file_t_initialize; - - if (F_status_is_error_not(status) && (main->pipe & fll_program_data_pipe_input_e)) { - file.id = F_type_descriptor_input_d; - file.stream = F_type_input_d; - file.size_read = 512; - - status = fss_identify_load_line(main, file, f_string_empty_s, &buffer, &range); - - if (F_status_is_error_not(status)) { - status = fss_identify_process(main, &data, f_string_ascii_minus_s, buffer, &range); - } - } - - if (F_status_is_error_not(status)) { - for (f_number_unsigned_t i = 0; i < main->parameters.remaining.used; ++i) { - - if (!((++main->signal_check) % fss_identify_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(&main->warning, main->signal_received); - - status = F_status_set_error(F_interrupt); - - break; - } - - main->signal_check = 0; - } - - if (main->parameters.array[fss_identify_parameter_line_e].result & f_console_result_value_e) { - if (data.current > data.line) break; - } - - macro_f_file_t_reset(file); - - file.size_read = 512; - - status = f_file_stream_open(data.argv[main->parameters.remaining.array[i]], f_string_empty_s, &file); - - if (F_status_is_error(status)) { - fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_open", fll_error_file_flag_fallback_e, data.argv[main->parameters.remaining.array[i]], f_file_operation_open_s, fll_error_file_type_file_e); - } - else { - status = fss_identify_load_line(main, file, data.argv[main->parameters.remaining.array[i]], &buffer, &range); - - if (F_status_is_error_not(status)) { - status = fss_identify_process(main, &data, data.argv[main->parameters.remaining.array[i]], buffer, &range); - } - } - - f_file_stream_flush(file); - f_file_stream_close(&file); - - if (F_status_is_error(status)) break; - } // for - } - - f_string_dynamic_resize(0, &buffer); - - if (F_status_is_error_not(status)) { - if (main->parameters.array[fss_identify_parameter_total_e].result & f_console_result_found_e) { - fll_print_format("%ul%r", main->output.to, data.total, f_string_eol_s); - } - } - - // Ensure a newline is always put at the end of the program execution, unless in quiet mode. - if (main->error.verbosity > f_console_verbosity_quiet_e) { - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_interrupt) { - f_file_stream_flush(main->output.to); - } - - fll_print_dynamic_raw(f_string_eol_s, main->output.to); - } - } - - fss_identify_data_delete(&data); - - return status; - } -#endif // _di_fss_identify_main_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_identify/c/main/common.c b/level_3/fss_identify/c/main/common.c new file mode 100644 index 0000000..aa8a519 --- /dev/null +++ b/level_3/fss_identify/c/main/common.c @@ -0,0 +1,332 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_setting_load_ + void fss_identify_setting_load(const f_console_arguments_t arguments, fss_identify_main_t * const main) { + + if (!main) return; + + main->setting.state.step_small = fss_identify_allocation_console_d; + + f_console_parameter_process(arguments, &main->program.parameters, &main->setting.state, 0); + + main->setting.state.step_small = fss_identify_allocation_small_d; + + // Identify and pocess first/last parameters. + if (main->program.parameters.array[fss_identify_parameter_line_first_no_e].result & f_console_result_found_e) { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_print_first_e; + } + else { + main->setting.flag |= fss_identify_main_flag_print_first_e; + } + + if (main->program.parameters.array[fss_identify_parameter_line_last_no_e].result & f_console_result_found_e) { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_print_last_e; + } + else { + main->setting.flag |= fss_identify_main_flag_print_last_e; + } + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(f_console_parameter_process)); + + return; + } + + { + f_number_unsigned_t choice = 0; + f_uint16s_t choices = f_uint16s_t_initialize; + + // Identify and prioritize "color context" parameters. + { + uint16_t choices_array[3] = { fss_identify_parameter_no_color_e, fss_identify_parameter_light_e, fss_identify_parameter_dark_e }; + choices.array = choices_array; + choices.used = 3; + + static const uint8_t modes[3] = { f_color_mode_not_e, f_color_mode_light_e, f_color_mode_dark_e }; + + main->setting.state.status = fll_program_parameter_process_context(choices, modes, F_true, &main->program); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(fll_program_parameter_process_context)); + + return; + } + } + } + + if (main->program.parameters.array[fss_identify_parameter_help_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_help_e; + + return; + } + + if (main->program.parameters.array[fss_identify_parameter_version_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_version_e; + + return; + } + + if (main->program.parameters.array[fss_identify_parameter_copyright_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_copyright_e; + + return; + } + + f_number_unsigned_t index = 0; + + if (main->program.parameters.array[fss_identify_parameter_content_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_content_e; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_content_e; + } + + if (main->program.parameters.array[fss_identify_parameter_object_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_object_e; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_object_e; + } + + if (main->program.parameters.array[fss_identify_parameter_total_e].result & f_console_result_found_e) { + main->setting.flag |= fss_identify_main_flag_total_e; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_total_e; + } + + if (main->program.parameters.array[fss_identify_parameter_line_e].result & f_console_result_value_e) { + index = main->program.parameters.array[fss_identify_parameter_line_e].values.array[main->program.parameters.array[fss_identify_parameter_line_e].values.used - 1]; + + main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, main->program.parameters.arguments.array[index], &main->setting.line); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_program_print_error_parameter_integer_not(&main->program.error, f_console_symbol_long_normal_s, fss_identify_long_line_s, main->program.parameters.arguments.array[index]); + + return; + } + + main->setting.flag |= fss_identify_main_flag_line_e; + } + else if (main->program.parameters.array[fss_identify_parameter_line_e].result & f_console_result_found_e) { + main->setting.state.status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_program_print_error_parameter_missing_value(&main->program.error, f_console_symbol_long_normal_s, fss_identify_long_line_s); + + return; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_line_e; + } + + if (main->program.parameters.array[fss_identify_parameter_name_e].result & f_console_result_value_e) { + main->setting.names.used = 0; + + main->setting.state.status = f_string_dynamics_increase_by(main->program.parameters.array[fss_identify_parameter_name_e].values.used, &main->setting.names); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(f_string_dynamics_increase_by)); + + return; + } + + main->setting.names.used = main->program.parameters.array[fss_identify_parameter_name_e].values.used; + + f_number_unsigned_t i = 0; + f_number_unsigned_t j = 0; + f_status_t status = F_none; + + for (; i < main->setting.names.used; ++i) { + + if (fss_identify_signal_check(main)) return; + + index = main->program.parameters.array[fss_identify_parameter_name_e].values.array[i]; + main->setting.names.array[i].used = 0; + + main->setting.state.status = f_string_dynamic_append_nulless(main->program.parameters.arguments.array[index], &main->setting.names.array[i]); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(f_string_dynamic_append_nulless)); + + break; + } + + if (main->setting.names.array[i].used) { + for (j = 0; j < main->setting.names.array[i].used; ++j) { + + if (fss_identify_signal_check(main)) return; + + main->setting.state.status = f_utf_is_word_dash(main->setting.names.array[i].string + j, main->setting.names.array[i].used, F_true); + + if (F_status_is_error(main->setting.state.status)) { + if (F_status_is_error_not(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(f_utf_is_word_dash)); + + return; + } + + if (main->setting.state.status == F_false) { + main->setting.state.status = F_status_set_error(F_parameter); + + if (F_status_is_error_not(main->setting.state.status)) { + status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + } + + fss_identify_print_error_parameter_file_name_invalid(&main->program.error, index, main->setting.names.array[i]); + + break; + } + } // for + } + else { + if (F_status_is_error_not(main->setting.state.status)) { + status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + } + + fss_identify_print_error_parameter_file_name_empty(&main->program.error, index); + } + } // for + + if (F_status_is_error(main->setting.state.status)) return; + + if (F_status_is_error(status)) { + main->setting.state.status = status; + + return; + } + + main->setting.flag |= fss_identify_main_flag_name_e; + } + else if (main->program.parameters.array[fss_identify_parameter_name_e].result & f_console_result_found_e) { + main->setting.state.status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fll_program_print_error_parameter_missing_value(&main->program.error, f_console_symbol_long_normal_s, fss_identify_long_name_s); + + return; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_parameter_name_e; + } + + if (main->program.parameters.remaining.used) { + main->setting.files.used = 0; + + main->setting.state.status = f_string_dynamics_increase_by(main->program.parameters.remaining.used, &main->setting.files); + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error(&main->program.error, macro_fss_identify_f(f_string_dynamics_increase_by)); + + return; + } + + // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0). + for (f_number_unsigned_t index = 0; main->setting.files.used < main->program.parameters.remaining.used; ) { + + if (fss_identify_signal_check(main)) return; + + index = main->program.parameters.remaining.array[main->setting.files.used]; + + main->setting.files.array[main->setting.files.used].string = main->program.parameters.arguments.array[index].string; + main->setting.files.array[main->setting.files.used].used = main->program.parameters.arguments.array[index].used; + main->setting.files.array[main->setting.files.used++].size = 0; + } // for + + main->setting.flag |= fss_identify_main_flag_file_from_e; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_file_from_e; + } + + if (main->program.pipe & fll_program_data_pipe_input_e) { + main->setting.flag |= fss_identify_main_flag_pipe_e; + } + else { + main->setting.flag -= main->setting.flag & fss_identify_main_flag_pipe_e; + } + + if (!(main->setting.flag & fss_identify_main_flag_pipe_e | fss_identify_main_flag_file_from_e)) { + main->setting.state.status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + fss_identify_print_error_no_from(&main->program.error); + + return; + } + + // Default to both Object and Content when neither are specified. + if (!(main->setting.flag & (fss_identify_main_flag_object_e | fss_identify_main_flag_content_e | fss_identify_main_flag_total_e))) { + main->setting.flag |= fss_identify_main_flag_object_e; + main->setting.flag |= fss_identify_main_flag_content_e; + } + + if (main->setting.flag & fss_identify_main_flag_total_e) { + if (main->setting.flag & (fss_identify_main_flag_content_e | fss_identify_main_flag_object_e)) { + main->setting.state.status = F_status_set_error(F_parameter); + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + if (main->program.error.verbosity > f_console_verbosity_quiet_e) { + fll_program_print_error_parameter_cannot_use_with(&main->program.error, f_console_symbol_long_normal_s, f_console_symbol_long_normal_s, main->setting.flag & fss_identify_main_flag_content_e ? fss_identify_long_content_s : fss_identify_long_object_s, fss_identify_long_total_s); + } + } + } + } +#endif // _di_fss_identify_setting_load_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common.h b/level_3/fss_identify/c/main/common.h new file mode 100644 index 0000000..6238b21 --- /dev/null +++ b/level_3/fss_identify/c/main/common.h @@ -0,0 +1,48 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * 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_identify_common_h +#define _fss_identify_common_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the standard program setting load process. + * + * This prints error messages as appropriate. + * + * If either main or setting is NULL, then this immediately returns without doing anything. + * + * @param arguments + * The parameters passed to the process (often referred to as command line arguments). + * @param main + * The main program data and settings. + * + * This alters main.setting.state.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_identify_setting_load_ + extern void fss_identify_setting_load(const f_console_arguments_t arguments, fss_identify_main_t * const main); +#endif // _di_fss_identify_setting_load_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_h diff --git a/level_3/fss_identify/c/main/common/define.c b/level_3/fss_identify/c/main/common/define.c new file mode 100644 index 0000000..a14a7d8 --- /dev/null +++ b/level_3/fss_identify/c/main/common/define.c @@ -0,0 +1,9 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common/define.h b/level_3/fss_identify/c/main/common/define.h new file mode 100644 index 0000000..b8973e7 --- /dev/null +++ b/level_3/fss_identify/c/main/common/define.h @@ -0,0 +1,56 @@ + +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common define types. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_common_define_h +#define _fss_identify_common_define_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The program allocation defines. + * + * fss_identify_allocation_*_d: + * - console: An allocation step used for small buffers specifically for console parameter. + * - large: An allocation step used for buffers that are anticipated to have large buffers. + * - pipe: A buffer size used for processing piped data. + * - small: An allocation step used for buffers that are anticipated to have small buffers. + */ +#ifndef _di_fss_identify_allocation_d_ + #define fss_identify_allocation_console_d 4 + #define fss_identify_allocation_large_d 256 + #define fss_identify_allocation_pipe_d 16384 + #define fss_identify_allocation_small_d 16 +#endif // _di_fss_identify_allocation_d_ + +/** + * The program signal defines. + * + * fss_identify_signal_*_d: + * - check: Number of iterations before performing signal check in non-threaded signal handling. + * - check_failsafe: When using threads, how many consecutive failures to check signal before aborting (as a recursion failsafe). + * - check_tiny: The tiny check. + * - check_short: The short signal check. + */ +#ifndef _di_fss_identify_signal_d_ + #define fss_identify_signal_check_d 500000 + #define fss_identify_signal_check_failsafe_d 20000 + #define fss_identify_signal_check_tiny_d 4 + #define fss_identify_signal_check_short_d 16 +#endif // _di_fss_identify_signal_d_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_define_h diff --git a/level_3/fss_identify/c/main/common/enumeration.c b/level_3/fss_identify/c/main/common/enumeration.c new file mode 100644 index 0000000..a14a7d8 --- /dev/null +++ b/level_3/fss_identify/c/main/common/enumeration.c @@ -0,0 +1,9 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common/enumeration.h b/level_3/fss_identify/c/main/common/enumeration.h new file mode 100644 index 0000000..cfd9ed4 --- /dev/null +++ b/level_3/fss_identify/c/main/common/enumeration.h @@ -0,0 +1,128 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common enumeration types. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_common_enumeration_h +#define _fss_identify_common_enumeration_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Flags passed to the main function or program. + * + * fss_identify_main_flag_*_e: + * - none: No flags set. + * - content: Use the content (The "0000" part of "FSS-0000"). + * - copyright: Print copyright. + * - file_from: Using a specified source file. + * - file_to: Using a specified destination file. (Not used at this time.) + * - help: Print help. + * - header: Enable printing of headers. + * - line: Print only the identifier at a given line. + * - name: Select using this full or partial type name or code. + * - object: Use the object (The "FSS" part of "FSS-0000"). + * - pipe: Use the input pipe. + * - print_first: When set, print new line to message output on program begin after loading settings. + * - print_last: When set, print new line to message output on program end. + * - total: Print the total Identifiers found. + * - version: Print version. + */ +#ifndef _di_fss_identify_main_flag_e_ + enum { + fss_identify_main_flag_none_e = 0x0, + fss_identify_main_flag_content_e = 0x1, + fss_identify_main_flag_copyright_e = 0x2, + fss_identify_main_flag_file_from_e = 0x4, + fss_identify_main_flag_file_to_e = 0x8, + fss_identify_main_flag_header_e = 0x10, + fss_identify_main_flag_help_e = 0x20, + fss_identify_main_flag_line_e = 0x40, + fss_identify_main_flag_name_e = 0x80, + fss_identify_main_flag_object_e = 0x100, + fss_identify_main_flag_pipe_e = 0x200, + fss_identify_main_flag_print_first_e = 0x400, + fss_identify_main_flag_print_last_e = 0x800, + fss_identify_main_flag_total_e = 0x1000, + fss_identify_main_flag_version_e = 0x2000, + }; // enum +#endif // _di_fss_identify_main_flag_e_ + +/** + * The main program parameters. + */ +#ifndef _di_fss_identify_parameter_e_ + enum { + fss_identify_parameter_help_e, + fss_identify_parameter_copyright_e, + fss_identify_parameter_light_e, + fss_identify_parameter_dark_e, + fss_identify_parameter_no_color_e, + fss_identify_parameter_verbosity_quiet_e, + fss_identify_parameter_verbosity_error_e, + fss_identify_parameter_verbosity_normal_e, + fss_identify_parameter_verbosity_verbose_e, + fss_identify_parameter_verbosity_debug_e, + fss_identify_parameter_version_e, + fss_identify_parameter_line_first_no_e, + fss_identify_parameter_line_last_no_e, + + fss_identify_parameter_content_e, + fss_identify_parameter_line_e, + fss_identify_parameter_name_e, + fss_identify_parameter_object_e, + fss_identify_parameter_total_e, + }; // enum + + #define fss_identify_console_parameter_t_initialize \ + { \ + macro_fll_program_console_parameter_standard_initialize, \ + \ + macro_f_console_parameter_t_initialize_3(fss_identify_short_content_s, fss_identify_long_content_s, 0, f_console_flag_normal_e), \ + macro_f_console_parameter_t_initialize_3(fss_identify_short_line_s, fss_identify_long_line_s, 1, f_console_flag_normal_e), \ + macro_f_console_parameter_t_initialize_3(fss_identify_short_name_s, fss_identify_long_name_s, 1, f_console_flag_normal_e), \ + macro_f_console_parameter_t_initialize_3(fss_identify_short_object_s, fss_identify_long_object_s, 0, f_console_flag_normal_e), \ + macro_f_console_parameter_t_initialize_3(fss_identify_short_total_s, fss_identify_long_total_s, 0, f_console_flag_normal_e), \ + } + + #define fss_identify_parameter_total_d 18 +#endif // _di_fss_identify_parameter_e_ + +/** + * Flags for fine-tuned print control. + * + * fss_identify_print_flag_*_e: + * - none: No flags set. + * - debug: Stream is for debug printing. + * - error: Stream is for error printing. + * - in: Stream is a source file. + * - message: Stream is for message printing. + * - out: Stream is a destination file. + * - warning: Stream is for warning printing. + */ +#ifndef _di_fss_identify_print_flag_e_ + enum { + fss_identify_print_flag_none_e = 0x0, + fss_identify_print_flag_debug_e = 0x1, + fss_identify_print_flag_error_e = 0x2, + fss_identify_print_flag_file_e = 0x4, + fss_identify_print_flag_in_e = 0x8, + fss_identify_print_flag_out_e = 0x10, + fss_identify_print_flag_message_e = 0x20, + fss_identify_print_flag_warning_e = 0x40, + }; // enum +#endif // _di_fss_identify_print_flag_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_enumeration_h diff --git a/level_3/fss_identify/c/main/common/print.c b/level_3/fss_identify/c/main/common/print.c new file mode 100644 index 0000000..5386a40 --- /dev/null +++ b/level_3/fss_identify/c/main/common/print.c @@ -0,0 +1,26 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_f_a_ + const f_string_t fss_identify_f_a[] = { + "f_console_parameter_prioritize_right", + "f_console_parameter_process", + "f_file_stream_open", + "f_file_stream_read_block", + "f_string_dynamic_append_nulless", + "f_string_dynamic_increase_by", + "f_string_dynamics_increase_by", + "f_thread_create", + "f_utf_is_word_dash", + "fll_fss_identify", + "fll_program_parameter_process_context", + "fll_program_parameter_process_verbosity", + }; +#endif // _di_fss_identify_f_a_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common/print.h b/level_3/fss_identify/c/main/common/print.h new file mode 100644 index 0000000..07a176e --- /dev/null +++ b/level_3/fss_identify/c/main/common/print.h @@ -0,0 +1,61 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common print functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_common_print_h +#define _fss_identify_common_print_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A special array of strings intended for representing funciton names. + * + * These are primarily used for printing errors with the function names. + * + * The macro macro_fss_identify_f() is used to reference the array index by the enum name. + * + * macro_fss_identify_f(): + * - name: The name of the function. + */ +#ifndef _di_fss_identify_f_a_ + extern const f_string_t fss_identify_f_a[]; + + #define macro_fss_identify_f(name) fss_identify_f_a[fss_identify_f_##name##_e] +#endif // _di_fss_identify_f_a_ + +/** + * An enum representing specific indexes within the above array. + * + * This is a convenience enum used to make code slightly more readable. + */ +#ifndef _di_fss_identify_f_e_ + enum { + fss_identify_f_f_console_parameter_prioritize_right_e, + fss_identify_f_f_console_parameter_process_e, + fss_identify_f_f_file_stream_open_e, + fss_identify_f_f_file_stream_read_block_e, + fss_identify_f_f_string_dynamic_append_nulless_e, + fss_identify_f_f_string_dynamic_increase_by_e, + fss_identify_f_f_string_dynamics_increase_by_e, + fss_identify_f_f_thread_create_e, + fss_identify_f_f_utf_is_word_dash_e, + fss_identify_f_fll_fss_identify_e, + fss_identify_f_fll_program_parameter_process_context_e, + fss_identify_f_fll_program_parameter_process_verbosity_e, + }; // enum +#endif // _di_fss_identify_f_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_print_h diff --git a/level_3/fss_identify/c/main/common/string.c b/level_3/fss_identify/c/main/common/string.c new file mode 100644 index 0000000..7454d14 --- /dev/null +++ b/level_3/fss_identify/c/main/common/string.c @@ -0,0 +1,36 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_program_version_s_ + const f_string_static_t fss_identify_program_version_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_version_s, 0, FSS_IDENTIFY_program_version_s_length); +#endif // _di_fss_identify_program_version_s_ + +#ifndef _di_fss_identify_program_name_s_ + const f_string_static_t fss_identify_program_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_name_s, 0, FSS_IDENTIFY_program_name_s_length); + const f_string_static_t fss_identify_program_name_long_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_name_long_s, 0, FSS_IDENTIFY_program_name_long_s_length); +#endif // _di_fss_identify_program_name_s_ + +#ifndef _di_fss_identify_program_help_parameters_s_ + const f_string_static_t fss_identify_program_help_parameters_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_program_help_parameters_s, 0, FSS_IDENTIFY_program_help_parameters_s_length); +#endif // _di_fss_identify_program_help_parameters_s_ + +#ifndef _di_fss_identify_parameter_s_ + const f_string_static_t fss_identify_short_content_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_content_s, 0, FSS_IDENTIFY_short_content_s_length); + const f_string_static_t fss_identify_short_line_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_line_s, 0, FSS_IDENTIFY_short_line_s_length); + const f_string_static_t fss_identify_short_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_name_s, 0, FSS_IDENTIFY_short_name_s_length); + const f_string_static_t fss_identify_short_object_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_object_s, 0, FSS_IDENTIFY_short_object_s_length); + const f_string_static_t fss_identify_short_total_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_short_total_s, 0, FSS_IDENTIFY_short_total_s_length); + + const f_string_static_t fss_identify_long_content_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_content_s, 0, FSS_IDENTIFY_long_content_s_length); + const f_string_static_t fss_identify_long_line_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_line_s, 0, FSS_IDENTIFY_long_line_s_length); + const f_string_static_t fss_identify_long_name_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_name_s, 0, FSS_IDENTIFY_long_name_s_length); + const f_string_static_t fss_identify_long_object_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_object_s, 0, FSS_IDENTIFY_long_object_s_length); + const f_string_static_t fss_identify_long_total_s = macro_f_string_static_t_initialize_1(FSS_IDENTIFY_long_total_s, 0, FSS_IDENTIFY_long_total_s_length); +#endif // _di_fss_identify_parameter_s_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common/string.h b/level_3/fss_identify/c/main/common/string.h new file mode 100644 index 0000000..9b8cc59 --- /dev/null +++ b/level_3/fss_identify/c/main/common/string.h @@ -0,0 +1,117 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common string structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_common_string_h +#define _fss_identify_common_string_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The program version. + */ +#ifndef _di_fss_identify_program_version_s_ + #define FSS_IDENTIFY_program_version_major_s F_string_ascii_0_s + #define FSS_IDENTIFY_program_version_minor_s F_string_ascii_7_s + #define FSS_IDENTIFY_program_version_micro_s F_string_ascii_0_s + + #define FSS_IDENTIFY_program_version_major_s_length F_string_ascii_0_s_length + #define FSS_IDENTIFY_program_version_minor_s_length F_string_ascii_7_s_length + #define FSS_IDENTIFY_program_version_micro_s_length F_string_ascii_0_s_length + + #if !(defined(FSS_IDENTIFY_program_version_nano_prefix_s) && defined(FSS_IDENTIFY_program_version_nano_prefix_s_length)) + #define FSS_IDENTIFY_program_version_nano_prefix_s + #define FSS_IDENTIFY_program_version_nano_prefix_s_length 0 + #endif // !(defined(FSS_IDENTIFY_program_version_nano_prefix_s) && defined(FSS_IDENTIFY_program_version_nano_prefix_s_length)) + + #if !(defined(FSS_IDENTIFY_program_version_nano_s) && defined(FSS_IDENTIFY_program_version_nano_s_length)) + #define FSS_IDENTIFY_program_version_nano_s + #define FSS_IDENTIFY_program_version_nano_s_length 0 + #endif // !(defined(FSS_IDENTIFY_program_version_nano_s) && defined(FSS_IDENTIFY_program_version_nano_s_length)) + + #define FSS_IDENTIFY_program_version_s FSS_IDENTIFY_program_version_major_s F_string_ascii_period_s FSS_IDENTIFY_program_version_minor_s F_string_ascii_period_s FSS_IDENTIFY_program_version_micro_s FSS_IDENTIFY_program_version_nano_prefix_s FSS_IDENTIFY_program_version_nano_s + + #define FSS_IDENTIFY_program_version_s_length FSS_IDENTIFY_program_version_major_s_length + F_string_ascii_period_s_length + FSS_IDENTIFY_program_version_minor_s_length + F_string_ascii_period_s_length + FSS_IDENTIFY_program_version_micro_s_length + FSS_IDENTIFY_program_version_nano_prefix_s_length + FSS_IDENTIFY_program_version_nano_s_length + + extern const f_string_static_t fss_identify_program_version_s; +#endif // _di_fss_identify_program_version_s_ + +/** + * The program name. + */ +#ifndef _di_fss_identify_program_name_s_ + #define FSS_IDENTIFY_program_name_s "fss_identify" + #define FSS_IDENTIFY_program_name_long_s "FSS Identify" + + #define FSS_IDENTIFY_program_name_s_length 12 + #define FSS_IDENTIFY_program_name_long_s_length 12 + + extern const f_string_static_t fss_identify_program_name_s; + extern const f_string_static_t fss_identify_program_name_long_s; +#endif // _di_fss_identify_program_name_s_ + +/** + * The program help related data. + */ +#ifndef _di_fss_identify_program_help_parameters_s_ + #define FSS_IDENTIFY_program_help_parameters_s "filename(s)" + #define FSS_IDENTIFY_program_help_parameters_s_length 11 + + extern const f_string_static_t fss_identify_program_help_parameters_s; +#endif // _di_fss_identify_program_help_parameters_s_ + +/** + * The main program parameters. + */ +#ifndef _di_fss_identify_parameter_s_ + #define FSS_IDENTIFY_short_content_s "c" + #define FSS_IDENTIFY_short_line_s "l" + #define FSS_IDENTIFY_short_name_s "n" + #define FSS_IDENTIFY_short_object_s "o" + #define FSS_IDENTIFY_short_total_s "t" + + #define FSS_IDENTIFY_long_content_s "content" + #define FSS_IDENTIFY_long_line_s "line" + #define FSS_IDENTIFY_long_name_s "name" + #define FSS_IDENTIFY_long_object_s "object" + #define FSS_IDENTIFY_long_total_s "total" + + #define FSS_IDENTIFY_short_content_s_length 1 + #define FSS_IDENTIFY_short_line_s_length 1 + #define FSS_IDENTIFY_short_name_s_length 1 + #define FSS_IDENTIFY_short_object_s_length 1 + #define FSS_IDENTIFY_short_total_s_length 1 + + #define FSS_IDENTIFY_long_content_s_length 7 + #define FSS_IDENTIFY_long_line_s_length 4 + #define FSS_IDENTIFY_long_name_s_length 4 + #define FSS_IDENTIFY_long_object_s_length 6 + #define FSS_IDENTIFY_long_total_s_length 5 + + extern const f_string_static_t fss_identify_short_content_s; + extern const f_string_static_t fss_identify_short_line_s; + extern const f_string_static_t fss_identify_short_name_s; + extern const f_string_static_t fss_identify_short_object_s; + extern const f_string_static_t fss_identify_short_total_s; + + extern const f_string_static_t fss_identify_long_content_s; + extern const f_string_static_t fss_identify_long_line_s; + extern const f_string_static_t fss_identify_long_name_s; + extern const f_string_static_t fss_identify_long_object_s; + extern const f_string_static_t fss_identify_long_total_s; +#endif // _di_fss_identify_parameter_s_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_string_h diff --git a/level_3/fss_identify/c/main/common/type.c b/level_3/fss_identify/c/main/common/type.c new file mode 100644 index 0000000..54928c0 --- /dev/null +++ b/level_3/fss_identify/c/main/common/type.c @@ -0,0 +1,35 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_main_data_delete_ + void fss_identify_main_delete(fss_identify_main_t * const main) { + + if (!main) return; + + fll_program_data_delete(&main->program); + fss_identify_setting_delete(&main->setting); + } +#endif // _di_fss_identify_main_data_delete_ + +#ifndef _di_fss_identify_setting_delete_ + f_status_t fss_identify_setting_delete(fss_identify_setting_t * const setting) { + + if (!setting) return F_status_set_error(F_parameter); + + f_string_dynamic_resize(0, &setting->buffer); + + f_fll_ids_resize(0, &setting->ids); + + f_string_dynamics_resize(0, &setting->names); + f_string_dynamics_resize(0, &setting->files); + + return F_none; + } +#endif // _di_fss_identify_setting_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/common/type.h b/level_3/fss_identify/c/main/common/type.h new file mode 100644 index 0000000..0ce794f --- /dev/null +++ b/level_3/fss_identify/c/main/common/type.h @@ -0,0 +1,131 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_common_type_h +#define _fss_identify_common_type_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The fss identify 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. + * + * current: The current position within the ids, used to determine when the line is matched. + * line: The line number to select. + * total: The total ids across all files. + * + * range: A range used for processing as needed. + * + * status_thread: A status used eclusively by the threaded signal handler. + * state: The state information. + * + * buffer:A buffer used for processing files. + * ids: A cache for FLL IDs. + * names: An array of names to select. + * files: The files to process. + */ +#ifndef _di_fss_identify_setting_t_ + typedef struct { + uint16_t flag; + + f_number_unsigned_t current; + f_number_unsigned_t line; + f_number_unsigned_t total; + + f_string_range_t range; + + f_status_t status_thread; + f_state_t state; + + f_file_t file; + + f_string_dynamic_t buffer; + f_fll_ids_t ids; + f_string_dynamics_t names; + f_string_dynamics_t files; + } fss_identify_setting_t; + + #define fss_identify_setting_t_initialize \ + { \ + fss_identify_main_flag_none_e, \ + 0, \ + 0, \ + 0, \ + f_string_range_t_initialize, \ + F_none, \ + f_state_t_initialize, \ + f_file_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_fll_ids_t_initialize, \ + f_string_dynamics_t_initialize, \ + f_string_dynamics_t_initialize, \ + } +#endif // _di_fss_identify_setting_t_ + +/** + * The main program data as a single structure. + * + * program: The main program data. + * setting: The settings data. + */ +#ifndef _di_fss_identify_main_t_ + typedef struct { + fll_program_data_t program; + fss_identify_setting_t setting; + } fss_identify_main_t; + + #define fss_identify_main_t_initialize \ + { \ + fll_program_data_t_initialize, \ + fss_identify_setting_t_initialize, \ + } +#endif // _di_fss_identify_main_t_ + +/** + * Deallocate main program data. + * + * @param setting_make + * The make setting data. + * + * This does not alter data_make.main.setting.state.status. + */ +#ifndef _di_fss_identify_main_data_delete_ + extern void fss_identify_main_delete(fss_identify_main_t * const main); +#endif // _di_fss_identify_main_data_delete_ + +/** + * Delete the program main setting data. + * + * @param setting + * The program main setting data. + * + * This does not alter setting.state.status. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_fss_identify_setting_delete_ + extern f_status_t fss_identify_setting_delete(fss_identify_setting_t * const setting); +#endif // _di_fss_identify_setting_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_common_type_h diff --git a/level_3/fss_identify/c/main/fss_identify.c b/level_3/fss_identify/c/main/fss_identify.c new file mode 100644 index 0000000..a34b129 --- /dev/null +++ b/level_3/fss_identify/c/main/fss_identify.c @@ -0,0 +1,101 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_main_ + void fss_identify_main(fss_identify_main_t * const main) { + + if (!main) return; + + if (F_status_is_error(main->setting.state.status)) { + if ((main->setting.flag & fss_identify_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + return; + } + + if ((main->setting.flag & fss_identify_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + main->setting.state.status = F_none; + + if (main->setting.flag & (fss_identify_main_flag_help_e | fss_identify_main_flag_version_e | fss_identify_main_flag_copyright_e)) { + if (main->setting.flag & fss_identify_main_flag_help_e) { + fss_identify_print_message_help(&main->program.message); + } + else if (main->setting.flag & fss_identify_main_flag_version_e) { + fll_program_print_version(&main->program.message, fss_identify_program_version_s); + } + else if (main->setting.flag & fss_identify_main_flag_copyright_e) { + fll_program_print_copyright(&main->program.message); + } + + if ((main->setting.flag & fss_identify_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + return; + } + + if (F_status_is_error_not(main->setting.state.status) && (main->setting.flag & fss_identify_main_flag_pipe_e)) { + main->setting.file.id = F_type_descriptor_input_d; + main->setting.file.stream = F_type_input_d; + main->setting.file.size_read = 512; + + fss_identify_load_line(main, f_string_empty_s); + + if (F_status_is_error_not(main->setting.state.status)) { + fss_identify_process(main, f_string_empty_s); + } + } + + for (f_number_unsigned_t i = 0; F_status_is_error_not(main->setting.state.status) && i < main->setting.files.used; ++i) { + + if (fss_identify_signal_check(main)) break; + if ((main->setting.flag & fss_identify_main_flag_line_e) && main->setting.current > main->setting.line) break; + + macro_f_file_t_reset(main->setting.file); + + main->setting.file.size_read = 512; + + main->setting.state.status = f_file_stream_open(main->setting.files.array[i], f_string_empty_s, &main->setting.file); + + if (F_status_is_error(main->setting.state.status)) { + fss_identify_print_error_file(&main->program.error, macro_fss_identify_f(f_file_stream_open), main->setting.files.array[i], f_file_operation_open_s, fll_error_file_type_file_e); + } + else { + fss_identify_load_line(main, main->setting.files.array[i]); + + if (F_status_is_error_not(main->setting.state.status)) { + fss_identify_process(main, main->setting.files.array[i]); + } + } + + f_file_stream_flush(main->setting.file); + f_file_stream_close(&main->setting.file); + } // for + + if (F_status_is_error_not(main->setting.state.status)) { + if (main->setting.flag & fss_identify_main_flag_total_e) { + fss_identify_print_data_total(&main->program.message); + } + } + + if ((main->setting.flag & fss_identify_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) { + fll_print_dynamic_raw(f_string_eol_s, main->program.message.to); + } + + if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; + if (F_status_is_error(main->setting.state.status)) return; + + main->setting.state.status = F_none; + } +#endif // _di_fss_identify_main_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/fss_identify.h b/level_3/fss_identify/c/main/fss_identify.h similarity index 56% rename from level_3/fss_identify/c/fss_identify.h rename to level_3/fss_identify/c/main/fss_identify.h index b0a0b26..92de992 100644 --- a/level_3/fss_identify/c/fss_identify.h +++ b/level_3/fss_identify/c/main/fss_identify.h @@ -34,6 +34,7 @@ #include #include #include +#include // FLL-1 includes. #include @@ -47,8 +48,19 @@ #include // FSS Identify includes. -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -57,29 +69,24 @@ extern "C" { /** * 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. + * The main program and setting data. * - * This alters setting.state.status: + * This alters main.setting.state.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. + * F_interrupt (with error bit) on interrupt signal received. + * + * Errors (with error bit) from: f_file_stream_open() + * Errors (with error bit) from: fss_identify_load_line() + * Errors (with error bit) from: fss_identify_process() + * + * @see f_file_stream_open() + * @see fss_identify_load_line() + * @see fss_identify_process() */ #ifndef _di_fss_identify_main_ - extern f_status_t fss_identify_main(fll_program_data_t * const main, fss_identify_setting_t * const setting); + extern void fss_identify_main(fss_identify_main_t * const main); #endif // _di_fss_identify_main_ #ifdef __cplusplus diff --git a/level_3/fss_identify/c/main/load.c b/level_3/fss_identify/c/main/load.c new file mode 100644 index 0000000..9b1d157 --- /dev/null +++ b/level_3/fss_identify/c/main/load.c @@ -0,0 +1,57 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_load_line_ + void fss_identify_load_line(fss_identify_main_t * const main, const f_string_static_t name) { + + if (!main) return; + + main->setting.state.status = F_none; + main->setting.buffer.used = 0; + main->setting.range.start = 0; + main->setting.range.stop = 0; + + do { + if (fss_identify_signal_check(main)) return; + + main->setting.state.status = f_string_dynamic_increase_by(main->setting.file.size_read, &main->setting.buffer); + + if (F_status_is_error(main->setting.state.status)) { + fss_identify_print_error_file(&main->program.error, macro_fss_identify_f(f_string_dynamic_increase_by), name.used ? name : f_string_ascii_minus_s, f_file_operation_read_s, name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); + + return; + } + + main->setting.state.status = f_file_stream_read_block(main->setting.file, &main->setting.buffer); + + if (F_status_is_error(main->setting.state.status)) { + fss_identify_print_error_file(&main->program.error, macro_fss_identify_f(f_file_stream_read_block), name.used ? name : f_string_ascii_minus_s, f_file_operation_read_s, name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); + + return; + } + + for (; main->setting.range.start < main->setting.buffer.used; ++main->setting.range.start) { + if (main->setting.buffer.string[main->setting.range.start] == f_string_eol_s.string[0]) break; + } // for + + main->setting.range.stop = main->setting.range.start; + + } while (main->setting.state.status != F_none_eof && main->setting.buffer.string[main->setting.range.start] != f_string_eol_s.string[0]); + + // Reset the start point to prepare the buffer for processing. + main->setting.range.start = 0; + + main->setting.state.status = F_none; + } +#endif // _di_fss_identify_load_line_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/load.h b/level_3/fss_identify/c/main/load.h new file mode 100644 index 0000000..55552d6 --- /dev/null +++ b/level_3/fss_identify/c/main/load.h @@ -0,0 +1,44 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides load functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_load_h +#define _fss_identify_load_h + +/** + * Load a pipe or a file 1 block at a time untul a newline is found. + * + * @param main + * The main program and settings data. + * + * This alters setting.status: + * F_none on success. + * + * Errors (with error bit) from: f_file_stream_read_block(). + * Errors (with error bit) from: f_string_dynamic_resize(). + * + * @param main + * The main program data. + * @param name + * The name of the file. + * file_name.used to 0 to designate that this is a pipe. + * + * @see f_file_stream_read_block() + * @see f_string_dynamic_resize() + */ +#ifndef _di_fss_identify_load_line_ + extern void fss_identify_load_line(fss_identify_main_t * const main, const f_string_static_t name); +#endif // _di_fss_identify_load_line_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_load_h diff --git a/level_3/fss_identify/c/main.c b/level_3/fss_identify/c/main/main.c similarity index 51% rename from level_3/fss_identify/c/main.c rename to level_3/fss_identify/c/main/main.c index bb013ea..593c3c2 100644 --- a/level_3/fss_identify/c/main.c +++ b/level_3/fss_identify/c/main/main.c @@ -16,6 +16,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.program.warning.custom = (void *) &data; f_console_parameter_t parameters[] = fss_identify_console_parameter_t_initialize; + data.program.parameters.array = parameters; data.program.parameters.used = fss_identify_parameter_total_d; data.program.environment = envp; @@ -26,19 +27,47 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { fll_program_standard_set_up(&data.program); - { - const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp); + f_file_umask_get(&data.program.umask); - fss_identify_setting_load(arguments, &data); - } + #ifdef _di_thread_support_ + { + const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp); + + fss_identify_setting_load(arguments, &data); + } + + fss_identify_main(&data); + #else + { + f_thread_id_t id_signal; + + memset(&id_signal, 0, sizeof(f_thread_id_t)); + + data.setting.state.status = f_thread_create(0, &id_signal, &fss_identify_thread_signal, (void *) &data); + + if (F_status_is_error(data.setting.state.status)) { + fss_identify_print_error(&data.program.error, macro_fss_identify_f(f_thread_create)); + } + else { + { + const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp); + + fss_identify_setting_load(arguments, &data); + } - fss_identify_main(&data); + if (!fss_identify_signal_check(&data)) { + fss_identify_main(&data); + } - fss_identify_setting_unload(&data); + f_thread_cancel(id_signal); + f_thread_join(id_signal, 0); + } + } + #endif // _di_thread_support_ - fll_program_data_delete(&data.program); + fss_identify_main_delete(&data); fll_program_standard_set_down(&data.program); - return F_status_is_error(data.setting.state.status) ? 1 : 0; + return (F_status_is_error(data.setting.state.status) || data.setting.state.status == F_false) ? 1 : 0; } diff --git a/level_3/fss_identify/c/main.h b/level_3/fss_identify/c/main/main.h similarity index 100% rename from level_3/fss_identify/c/main.h rename to level_3/fss_identify/c/main/main.h diff --git a/level_3/fss_identify/c/main/print/data.c b/level_3/fss_identify/c/main/print/data.c new file mode 100644 index 0000000..5b5fab2 --- /dev/null +++ b/level_3/fss_identify/c/main/print/data.c @@ -0,0 +1,51 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_print_data_id_ + f_status_t fss_identify_print_data_id(fl_print_t * const print, const f_fll_id_t id) { + + if (!print->custom) return F_status_set_error(F_output_not); + + fss_identify_main_t * const main = (fss_identify_main_t *) print->custom; + + f_file_stream_lock(print->to); + + if (main->setting.flag & fss_identify_main_flag_object_e) { + f_print((const f_string_t) id.name, id.used, print->to); + + if (main->setting.flag & fss_identify_main_flag_content_e) { + f_print_dynamic_raw(f_fss_type_header_part5_s, print->to); + } + } + + if (main->setting.flag & fss_identify_main_flag_content_e) { + fl_print_format("%04_ui", print->to, id.type); + } + + f_print_dynamic_raw(f_string_eol_s, print->to); + + f_file_stream_unlock(print->to); + + return F_none; + } +#endif // _di_fss_identify_print_data_id_ + +#ifndef _di_fss_identify_print_data_total_ + f_status_t fss_identify_print_data_total(fl_print_t * const print) { + + if (!print->custom) return F_status_set_error(F_output_not); + + fss_identify_main_t * const main = (fss_identify_main_t *) print->custom; + + fll_print_format("%ul%r", print->to, main->setting.total, f_string_eol_s); + + return F_none; + } +#endif // _di_fss_identify_print_data_total_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/print/data.h b/level_3/fss_identify/c/main/print/data.h new file mode 100644 index 0000000..182b859 --- /dev/null +++ b/level_3/fss_identify/c/main/print/data.h @@ -0,0 +1,61 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the print data functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_print_data_data_h +#define _fss_identify_print_data_data_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Print the given FLL identifier. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param id + * The Identifier to print. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_fss_identify_print_data_id_ + extern f_status_t fss_identify_print_data_id(fl_print_t * const print, const f_fll_id_t id); +#endif // _di_fss_identify_print_data_id_ + +/** + * Print the total. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_fss_identify_print_data_total_ + extern f_status_t fss_identify_print_data_total(fl_print_t * const print); +#endif // _di_fss_identify_print_data_total_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_print_data_data_h diff --git a/level_3/fss_identify/c/main/print/error.c b/level_3/fss_identify/c/main/print/error.c new file mode 100644 index 0000000..4695f36 --- /dev/null +++ b/level_3/fss_identify/c/main/print/error.c @@ -0,0 +1,86 @@ +#include "../fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_print_error_ + f_status_t fss_identify_print_error(fl_print_t * const print, const f_string_t function) { + + if (!print->custom) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + fll_error_print(print, F_status_set_fine(((fss_identify_main_t *) print->custom)->setting.state.status), function, fll_error_file_flag_fallback_e); + + return F_none; + } +#endif // _di_fss_identify_print_error_ + +#ifndef _di_fss_identify_print_error_file_ + f_status_t fss_identify_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { + + if (!print->custom) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + fss_identify_main_t * const main = (fss_identify_main_t *) print->custom; + + fll_error_file_print(print, F_status_set_fine(main->setting.state.status), function, fll_error_file_flag_fallback_e, name, operation, type); + + return F_none; + } +#endif // _di_fss_identify_print_error_file_ + +#ifndef _di_fss_identify_print_error_no_from_ + f_status_t fss_identify_print_error_no_from(fl_print_t * const print) { + + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + fll_print_format("%[%QNo sources are specified, please pipe data or designate a file.%]%r", print->to, print->set->error, print->prefix, print->set->error, f_string_eol_s); + + return F_none; + } +#endif // _di_fss_identify_print_error_no_from_ + +#ifndef _di_fss_identify_print_error_parameter_file_name_empty_ + f_status_t fss_identify_print_error_parameter_file_name_empty(fl_print_t * const print, const f_number_unsigned_t index) { + + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print->to); + + fl_print_format("%[%QEmpt string is not allowed at index%] ", print->to, print->set->error, print->prefix, print->set->error); + fl_print_format("%[%ul%] ", print->to, print->set->notable, index, print->set->notable); + fl_print_format("%[for the parameter '%]", print->to, print->set->error, print->set->error); + fl_print_format("%[%r%r%]", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_name_s, print->set->notable); + fl_print_format("%['.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s); + + f_file_stream_unlock(print->to); + + return F_none; + } +#endif // _di_fss_identify_print_error_parameter_file_name_empty_ + +#ifndef _di_fss_identify_print_error_parameter_file_name_invalid_ + f_status_t fss_identify_print_error_parameter_file_name_invalid(fl_print_t * const print, const f_number_unsigned_t index, const f_string_static_t name) { + + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + f_file_stream_lock(print->to); + + fl_print_format("%[%QThe value '%]", print->to, print->set->error, print->prefix, print->set->error); + fl_print_format("%[%Q%]", print->to, print->set->notable, name, print->set->notable); + fl_print_format("%[' at index%] ", print->to, print->set->error, print->set->error); + fl_print_format("%[%ul%] ", print->to, print->set->notable, index, print->set->notable); + fl_print_format("%[for the parameter '%]", print->to, print->set->error, print->set->error); + fl_print_format("%[%r%r%]", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_name_s, print->set->notable); + fl_print_format("%[' may only contain word characters or the dash (minus) character.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s); + + f_file_stream_unlock(print->to); + + return F_none; + } +#endif // _di_fss_identify_print_error_parameter_file_name_invalid_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/print/error.h b/level_3/fss_identify/c/main/print/error.h new file mode 100644 index 0000000..b5d6e90 --- /dev/null +++ b/level_3/fss_identify/c/main/print/error.h @@ -0,0 +1,142 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the print error functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_print_error_h +#define _fss_identify_print_error_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Print generic error message regarding a function failing in some way. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_print() + */ +#ifndef _di_fss_identify_print_error_ + extern f_status_t fss_identify_print_error(fl_print_t * const print, const f_string_t function); +#endif // _di_fss_identify_print_error_ + +/** + * Print file related error or warning messages. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param function + * The name of the function where the error happened. + * Set to 0 to disable. + * @param name + * The name of the file or directory. + * @param operation + * The operation that fails, such as 'create' or 'access'. + * @param type + * A valid file type code from the fll_error_file_type enum. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_fss_identify_print_error_file_ + extern f_status_t fss_identify_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type); +#endif // _di_fss_identify_print_error_file_ + +/** + * Print error message for when no input sources (file or pipe) are provided. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see fll_error_file_print() + */ +#ifndef _di_fss_identify_print_error_no_from_ + extern f_status_t fss_identify_print_error_no_from(fl_print_t * const print); +#endif // _di_fss_identify_print_error_no_from_ + +/** + * Print error message for when the file parameter is an empty string. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param index + * The index within the argv[] array where the empty string is found. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + */ +#ifndef _di_fss_identify_print_error_parameter_file_name_empty_ + extern f_status_t fss_identify_print_error_parameter_file_name_empty(fl_print_t * const print, const f_number_unsigned_t index); +#endif // _di_fss_identify_print_error_parameter_file_name_empty_ + +/** + * Print error message for when the file parameter is invalid. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * @param index + * The index within the argv[] array where the empty string is found. + * @param name + * The parameter name value string that is invalid. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see fl_print_format() + */ +#ifndef _di_fss_identify_print_error_parameter_file_name_invalid_ + extern f_status_t fss_identify_print_error_parameter_file_name_invalid(fl_print_t * const print, const f_number_unsigned_t index, const f_string_static_t name); +#endif // _di_fss_identify_print_error_parameter_file_name_invalid_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_print_error_h diff --git a/level_3/fss_identify/c/print.c b/level_3/fss_identify/c/main/print/message.c similarity index 54% rename from level_3/fss_identify/c/print.c rename to level_3/fss_identify/c/main/print/message.c index 993a886..dc789f3 100644 --- a/level_3/fss_identify/c/print.c +++ b/level_3/fss_identify/c/main/print/message.c @@ -1,57 +1,58 @@ -#include "fss_identify.h" -#include "private-common.h" +#include "../fss_identify.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_fss_identify_print_help_ - f_status_t fss_identify_print_help(fss_identify_setting_t * const setting, const fl_print_t print) { +#ifndef _di_fss_identify_print_message_help_ + f_status_t fss_identify_print_message_help(fl_print_t * const print) { - f_file_stream_lock(print.to); + if (!print || !print->custom) return F_status_set_error(F_output_not); + + fss_identify_main_t * const main = (fss_identify_main_t *) print->custom; + + f_file_stream_lock(print->to); fll_program_print_help_header(print, fss_identify_program_name_long_s, fss_identify_program_version_s); fll_program_print_help_option_standard(print); - f_print_dynamic_raw(f_string_eol_s, print.to); + f_print_dynamic_raw(f_string_eol_s, print->to); fll_program_print_help_option(print, fss_identify_short_content_s, fss_identify_long_content_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "Print the Identifier content (the 4-digit hexidecimal type code)."); fll_program_print_help_option(print, fss_identify_short_object_s, fss_identify_long_object_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Print the Identifier object (the name)."); - f_print_dynamic_raw(f_string_eol_s, print.to); + f_print_dynamic_raw(f_string_eol_s, print->to); fll_program_print_help_option(print, fss_identify_short_line_s, fss_identify_long_line_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Print only the Identifier at the given line."); fll_program_print_help_option(print, fss_identify_short_name_s, fss_identify_long_name_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Select FSS using this full or partial type name or code."); fll_program_print_help_option(print, fss_identify_short_total_s, fss_identify_long_total_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "Print the total Identifiers found."); - f_print_dynamic_raw(f_string_eol_s, print.to); - 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_identify_program_name_s, fll_program_parameter_filenames_s); + fll_program_print_help_usage(print, fss_identify_program_name_s, fss_identify_program_help_parameters_s); - fl_print_format("%r The %[%r%r%] parameter refers to the file lines and not the lines in a given file.%r%r", print.to, f_string_eol_s, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_line_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format("%r The %[%r%r%] parameter refers to the file lines and not the lines in a given file.%r%r", print->to, f_string_eol_s, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_line_s, print->set->notable, f_string_eol_s, f_string_eol_s); - fl_print_format(" If neither the %[%r%r%] nor", print.to, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_object_s, print.set->notable); - fl_print_format(" %[%r%r%] are specified, then the default behavior is to print both.%r%r", print.to, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_content_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format(" If neither the %[%r%r%] nor", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_object_s, print->set->notable); + fl_print_format(" %[%r%r%] are specified, then the default behavior is to print both.%r%r", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_content_s, print->set->notable, f_string_eol_s, f_string_eol_s); - fl_print_format(" When specifying the %[%r%r%] parameter, neither the", print.to, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_total_s, print.set->notable); - fl_print_format(" %[%r%r%] nor the", print.to, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_object_s, print.set->notable); - fl_print_format(" %[%r%r%] parameter may be specified.%r%r", print.to, print.set->notable, f_console_symbol_long_normal_s, fss_identify_long_content_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format(" When specifying the %[%r%r%] parameter, neither the", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_total_s, print->set->notable); + fl_print_format(" %[%r%r%] nor the", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_object_s, print->set->notable); + fl_print_format(" %[%r%r%] parameter may be specified.%r%r", print->to, print->set->notable, f_console_symbol_long_normal_s, fss_identify_long_content_s, print->set->notable, f_string_eol_s, f_string_eol_s); - fl_print_format(" An FSS file is identified by the following format: '%[# Object-Content%]'", print.to, print.set->notable, print.set->notable); - fl_print_format(" where the Object, is a machine-name representing the name and may only consist of 'word' characters and the Content is a 4-digit hexidecimal number representing a particular variant of the Object.%r", print.to, f_string_eol_s); - fl_print_format(" This identifier, if provided, must exist on the first line in a file and must begin with the pound character: '#'.%r", print.to, f_string_eol_s); - fl_print_format(" Whitespace must follow this pound character.%r", print.to, f_string_eol_s); - fl_print_format(" There may be multiple Object and Content pairs, separated by white space, such as: '# fss-0002 fss-0000 iki-0002'.%r", print.to, f_string_eol_s); + fl_print_format(" An FSS file is identified by the following format: '%[# Object-Content%]'", print->to, print->set->notable, print->set->notable); + fl_print_format(" where the Object, is a machine-name representing the name and may only consist of 'word' characters and the Content is a 4-digit hexidecimal number representing a particular variant of the Object.%r", print->to, f_string_eol_s); + fl_print_format(" This identifier, if provided, must exist on the first line in a file and must begin with the pound character: '#'.%r", print->to, f_string_eol_s); + fl_print_format(" Whitespace must follow this pound character.%r", print->to, f_string_eol_s); + fl_print_format(" There may be multiple Object and Content pairs, separated by white space, such as: '# fss-0002 fss-0000 iki-0002'.%r", print->to, f_string_eol_s); - f_file_stream_flush(print.to); - f_file_stream_unlock(print.to); + f_file_stream_flush(print->to); + f_file_stream_unlock(print->to); return F_none; } -#endif // _di_fss_identify_print_help_ - +#endif // _di_fss_identify_print_message_help_ #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fss_identify/c/main/print/message.h b/level_3/fss_identify/c/main/print/message.h new file mode 100644 index 0000000..e3eacae --- /dev/null +++ b/level_3/fss_identify/c/main/print/message.h @@ -0,0 +1,52 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the print functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_print_message_h +#define _fss_identify_print_message_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Print help. + * + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. + * + * @return + * F_none on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + * + * @see f_file_stream_flush() + * @see f_file_stream_lock() + * @see f_file_stream_unlock() + * @see f_print_dynamic_raw() + * @see fl_print_format() + * + * @see fll_program_print_help_header() + * @see fll_program_print_help_option() + * @see fll_program_print_help_option_standard() + * @see fll_program_print_help_usage() + */ +#ifndef _di_fss_identify_print_message_help_ + extern f_status_t fss_identify_print_message_help(fl_print_t * const print); +#endif // _di_fss_identify_print_message_help_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_print_message_h diff --git a/level_3/fss_identify/c/main/process.c b/level_3/fss_identify/c/main/process.c new file mode 100644 index 0000000..71c1590 --- /dev/null +++ b/level_3/fss_identify/c/main/process.c @@ -0,0 +1,161 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_fss_identify_process_ + void fss_identify_process(fss_identify_main_t * const main, const f_string_static_t name) { + + if (!main) return; + + main->setting.ids.used = 0; + + main->setting.state.status = fll_fss_identify(main->setting.buffer, &main->setting.range, &main->setting.ids); + + if (F_status_is_error(main->setting.state.status)) { + fss_identify_print_error_file(&main->program.error, macro_fss_identify_f(fll_fss_identify), name.used ? name : f_string_ascii_minus_s, f_file_operation_read_s, name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); + + return; + } + + // 0 = is name, 1 = is type, 2 = is full. + uint8_t modes[main->setting.names.used]; + f_number_unsigned_t i = 0; + + if (main->setting.names.used) { + for (f_number_unsigned_t j = 0; i < main->setting.names.used; ++i) { + + modes[i] = 1; + + for (j = 0; j < main->setting.names.array[i].used; ++j) { + + if (main->setting.names.array[i].string[j] == f_string_ascii_minus_s.string[0]) { + modes[i] = 2; + + break; + } + + if (f_utf_is_digit(main->setting.names.array[i].string + j, main->setting.names.array[i].used - j, 0) != F_true) { + modes[i] = 0; + } + } // for + } // for + } + + if (main->setting.flag & fss_identify_main_flag_line_e) { + for (i = 0; i < main->setting.ids.used; ++i, ++main->setting.current) { + + if (main->setting.current == main->setting.line) { + if (main->setting.names.used) { + if (fss_identify_process_name_compare(main, main->setting.ids.array[i], modes) != F_equal_to) continue; + } + + if (main->setting.flag & fss_identify_main_flag_total_e) { + ++main->setting.total; + } + else { + fss_identify_print_data_id(&main->program.output, main->setting.ids.array[i]); + } + + ++main->setting.current; + + break; + } + } // for + } + else if (main->setting.flag & fss_identify_main_flag_total_e) { + if (main->setting.names.used) { + for (i = 0; i < main->setting.ids.used; ++i, ++main->setting.current) { + + if (fss_identify_process_name_compare(main, main->setting.ids.array[i], modes) == F_equal_to) { + ++main->setting.total; + } + } // for + } + else { + main->setting.total += main->setting.ids.used; + } + } + else if (main->setting.state.status == F_found || main->setting.state.status == F_maybe) { + for (i = 0; i < main->setting.ids.used; ++i) { + + if (main->setting.names.used) { + if (fss_identify_process_name_compare(main, main->setting.ids.array[i], modes) != F_equal_to) continue; + } + + fss_identify_print_data_id(&main->program.output, main->setting.ids.array[i]); + } // for + } + + main->setting.state.status = F_none; + } +#endif // _di_fss_identify_process_ + +#ifndef _di_fss_identify_process_name_compare_ + f_status_t fss_identify_process_name_compare(fss_identify_main_t * const main, const f_fll_id_t id, const uint8_t modes[]) { + + if (!main) return F_equal_to_not; + + f_number_unsigned_t i = 0; + f_number_unsigned_t j = 0; + f_number_unsigned_t number = 0; + f_string_range_t range = f_string_range_t_initialize; + + for (main->setting.state.status = F_equal_to_not; i < main->setting.names.used && main->setting.state.status == F_equal_to_not; ++i) { + + if (modes[i]) { + if (main->setting.names.array[i].used) { + range.start = 0; + range.stop = main->setting.names.array[i].used - 1; + } + else { + range.start = 1; + range.stop = 0; + } + + for (j = 0; j < main->setting.names.array[i].used; ++j) { + + if (main->setting.names.array[i].string[j] == f_string_ascii_minus_s.string[0] && j + 1 < main->setting.names.array[i].used) { + range.start = j + 1; + + break; + } + } // for + + { + main->setting.state.status = fl_conversion_dynamic_partial_to_unsigned(fl_conversion_data_base_16_c, main->setting.names.array[i], range, &number); + if (F_status_is_error(main->setting.state.status)) return F_equal_to_not; + } + + if (id.type != number) { + main->setting.state.status = F_equal_to_not; + + continue; + } + + if (modes[i] == 1) return F_equal_to; + + if (range.start) { + range.stop = range.start - 2; + range.start = 0; + } + + main->setting.state.status = f_compare_dynamic_partial_string((const f_string_t) id.name, main->setting.names.array[i], id.used, range); + } + else { + main->setting.state.status = f_compare_dynamic_string((const f_string_t) id.name, main->setting.names.array[i], id.used); + } + } // for + + return main->setting.state.status == F_equal_to ? F_equal_to : F_equal_to_not; + } +#endif // _di_fss_identify_process_name_compare_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/process.h b/level_3/fss_identify/c/main/process.h new file mode 100644 index 0000000..1e8c8ab --- /dev/null +++ b/level_3/fss_identify/c/main/process.h @@ -0,0 +1,75 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides process functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_process_h +#define _fss_identify_process_h + + +/** + * Process a given pipe or file. + * + * @param main + * The main program and settings data. + * + * This alters main.program.signal_received, setting it to a received signal. + * + * This alters setting.status: + * F_none on success. + * + * Errors (with error bit) from: fll_fss_identify(). + * @param name + * The name of the file. + * file_name.used to 0 to designate that this is a pipe. + * + * @see fll_fss_identify() + */ +#ifndef _di_fss_identify_process_ + extern void fss_identify_process(fss_identify_main_t * const main, const f_string_static_t name); +#endif // _di_fss_identify_process_ + +/** + * Determine if the given FLL ID matches the requested range. + * + * @param main + * The main program and settings data. + * + * This alters main.program.signal_received, setting it to a received signal. + * + * This alters setting.status: + * Errors (with error bit) from: f_compare_dynamic_partial_string(). + * Errors (with error bit) from: f_compare_dynamic_string(). + * Errors (with error bit) from: fl_conversion_dynamic_partial_to_hexidecimal_unsigned(). + * @param id + * The identifier to compare against. + * @param mode + * An array of modes specifying how to compare: + * 0 = Compare against just the ID Name (such as "fss" in "fss-0001"). + * 1 = Compare against just the ID Type (such as "0001" in "fss-0001"). + * 2 = Compare against the full name (such as "fss-0001" in "fss-0001"). + * + * The array size must exactly match main.setting.names.used. + * + * @return + * F_equal_to on match. + * F_equal_to_not on no match or on error. + * + * @see fl_conversion_dynamic_partial_to_hexidecimal_unsigned() + * @see f_compare_dynamic_string() + */ +#ifndef _di_fss_identify_process_name_compare_ + extern f_status_t fss_identify_process_name_compare(fss_identify_main_t * const main, const f_fll_id_t id, const uint8_t modes[]); +#endif // _di_fss_identify_process_name_compare_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_process_h diff --git a/level_3/fss_identify/c/main/signal.c b/level_3/fss_identify/c/main/signal.c new file mode 100644 index 0000000..4272b3a --- /dev/null +++ b/level_3/fss_identify/c/main/signal.c @@ -0,0 +1,113 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_fss_identify_signal_check_) && defined(_di_thread_support_) + f_status_t fss_identify_signal_check(fss_identify_main_t * const main) { + + if (!main) return F_false; + if (main->program.signal.id == -1) return F_false; + + if (!((++main->program.signal_check) % fss_identify_signal_check_d)) { + if (fll_program_standard_signal_received(&main->program)) { + fll_program_print_signal_received(&main->program.warning, main->program.signal_received); + + main->setting.state.status = F_status_set_error(F_interrupt); + + return F_true; + } + + main->program.signal_check = 0; + } + + return F_false; + } +#endif // !defined(_di_fss_identify_signal_check_) && defined(_di_thread_support_) + +#if !defined(_di_fss_identify_signal_check_) && !defined(_di_thread_support_) + f_status_t fss_identify_signal_check(fss_identify_main_t * const main) { + + if (!main) return F_false; + if (main->program.signal.id == -1) return F_false; + + if (main->program.signal_received) { + fll_program_print_signal_received(&main->program.warning, main->program.signal_received); + + main->setting.state.status = F_status_set_error(F_interrupt); + + return F_true; + } + + return F_false; + } +#endif // !defined(_di_fss_identify_signal_check_) && !defined(_di_thread_support_) + +#if !defined(_di_fss_identify_signal_handler_) && !defined(_di_thread_support_) + void fss_identify_signal_handler(fss_identify_main_t * const main) { + + if (!main) return; + + siginfo_t information; + f_number_unsigned_t failsafe = 0; + + memset(&information, 0, sizeof(siginfo_t)); + + main->program.signal_received = 0; + + f_signal_set_empty(&main->program.signal.set); + f_signal_set_add(F_signal_abort, &main->program.signal.set); + f_signal_set_add(F_signal_broken_pipe, &main->program.signal.set); + f_signal_set_add(F_signal_hangup, &main->program.signal.set); + f_signal_set_add(F_signal_interrupt, &main->program.signal.set); + f_signal_set_add(F_signal_quit, &main->program.signal.set); + f_signal_set_add(F_signal_termination, &main->program.signal.set); + + if (main->program.signal.id == -1) { + main->setting.status_thread = f_signal_open(&main->program.signal); + + if (F_status_is_error(main->setting.status_thread)) { + main->program.signal_received = F_signal_abort; + + return; + } + } + + do { + memset(&information, 0, sizeof(siginfo_t)); + + main->setting.status_thread = f_signal_wait(&main->program.signal.set, &information); + + if (F_status_is_error(main->setting.status_thread) && F_status_set_fine(main->setting.status_thread) != F_interrupt) { + if (++failsafe >= fss_identify_signal_check_failsafe_d) break; + } + + switch (information.si_signo) { + case F_signal_abort: + case F_signal_broken_pipe: + case F_signal_hangup: + case F_signal_interrupt: + case F_signal_quit: + case F_signal_termination: + main->program.signal_received = information.si_signo; + + break; + } + + failsafe = 0; + main->setting.status_thread = F_none; + + } while (!main->program.signal_received); + + f_signal_close(&main->program.signal); + + if (F_status_is_error(main->setting.status_thread)) { + main->program.signal_received = F_signal_abort; + } + } +#endif // !defined(_di_fss_identify_signal_handler_) && !defined(_di_thread_support_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/signal.h b/level_3/fss_identify/c/main/signal.h new file mode 100644 index 0000000..9df4c8e --- /dev/null +++ b/level_3/fss_identify/c/main/signal.h @@ -0,0 +1,86 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides signal functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_signal_h +#define _fss_identify_signal_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Check to see if a signal is received. + * + * If main.signal is non-zero, then this handles the following signals: + * - F_signal_abort + * - F_signal_broken_pipe + * - F_signal_hangup + * - F_signal_interrupt + * - F_signal_quit + * - F_signal_termination + * + * There is a threaded and a non-threaded version of this. + * The non-threaded version checks periodically using fss_identify_signal_check_d and updates main->signal_check as needed. + * The threaded version checks the flag state which is set by a separate thread that is blocking until signal is received. + * + * @param main + * The main program and settings data. + * + * This does not alter main.setting.state.status. + * + * @return + * F_true on signal received. + * F_false otherwise. + * + * @see fss_identify_signal_handler() + * + * @see fll_program_standard_signal_received() + */ +#ifndef _di_fss_identify_signal_check_ + extern f_status_t fss_identify_signal_check(fss_identify_main_t * const main); +#endif // _di_fss_identify_signal_check_ + +/** + * Signal handler for signals/interrupts. + * + * This blocks until an expected signal is recieved. + * When an expected signal is received it then sets the + * + * If main.signal is non-zero, then this 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 and settings data. + * + * This alters main.program.signal_received, setting it to a received signal. + * + * This alters setting.status: + * Errors (with error bit) from: f_signal_open() + * Errors (with error bit) from: f_signal_wait() + * + * @see f_signal_close() + * @see f_signal_open() + * @see f_signal_wait() + */ +#if !defined(_di_fss_identify_signal_handler_) && !defined(_di_thread_support_) + extern void fss_identify_signal_handler(fss_identify_main_t * const main); +#endif // !defined(_di_fss_identify_signal_handler_) && !defined(_di_thread_support_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_signal_h diff --git a/level_3/fss_identify/c/main/thread.c b/level_3/fss_identify/c/main/thread.c new file mode 100644 index 0000000..6196bd2 --- /dev/null +++ b/level_3/fss_identify/c/main/thread.c @@ -0,0 +1,26 @@ +#include "fss_identify.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_fss_identify_thread_signal_) && !defined(_di_thread_support_) + void * fss_identify_thread_signal(void * const main) { + + f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); + + if (main) { + fss_identify_signal_handler((fss_identify_main_t *) main); + } + + return 0; + } +#endif // !defined(_di_fss_identify_thread_signal_) && !defined(_di_thread_support_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/fss_identify/c/main/thread.h b/level_3/fss_identify/c/main/thread.h new file mode 100644 index 0000000..69bb750 --- /dev/null +++ b/level_3/fss_identify/c/main/thread.h @@ -0,0 +1,46 @@ +/** + * FLL - Level 3 + * + * Project: FSS Identify + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides thread functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _fss_identify_thread_h +#define _fss_identify_thread_h + +/** + * Thread handler for signals/interrupts. + * + * If main.signal is non-zero, then this 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 program and settings data. + * + * Must be of type fss_identify_main_t. + * + * @return + * 0, always. + * + * @see f_thread_cancel_state_set() + * + * @see fss_identify_signal_handler() + */ +#if !defined(_di_fss_identify_thread_signal_) && !defined(_di_thread_support_) + extern void * fss_identify_thread_signal(void * const main); +#endif // !defined(_di_fss_identify_thread_signal_) && !defined(_di_thread_support_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _fss_identify_thread_h diff --git a/level_3/fss_identify/c/print.h b/level_3/fss_identify/c/print.h deleted file mode 100644 index 1dbfbef..0000000 --- a/level_3/fss_identify/c/print.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Identify - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _fss_identify_print_h -#define _fss_identify_print_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Print help. - * - * @param setting - * The main program settings. - * - * This does not alter setting.state.status. - * @param print - * The output structure to print to. - * - * @return - * F_none on success. - */ -#ifndef _di_fss_identify_print_help_ - extern f_status_t fss_identify_print_help(fss_identify_setting_t * const setting, const fl_print_t print); -#endif // _di_fss_identify_print_help_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _fss_identify_print_h diff --git a/level_3/fss_identify/c/private-common.c b/level_3/fss_identify/c/private-common.c deleted file mode 100644 index e6d4b34..0000000 --- a/level_3/fss_identify/c/private-common.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "fss_identify.h" -#include "private-common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_identify_data_delete_ - void fss_identify_data_delete(fss_identify_data_t *data) { - - if (!data) return; - - f_string_dynamic_resize(0, &data->name); - } -#endif // _di_fss_identify_data_delete_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_identify/c/private-common.h b/level_3/fss_identify/c/private-common.h deleted file mode 100644 index 96acf55..0000000 --- a/level_3/fss_identify/c/private-common.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Identify - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _PRIVATE_common_h -#define _PRIVATE_common_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The data structure for FSS Identify. - * - * argv: The argument structure in the progam data parameters for simplifying syntax. - * current: The current position within the ids, used to determine when the line is matched. - * line: The line number to select. - * name: The name to select. - * total: The total ids across all files. - */ -#ifndef _di_fss_identify_data_t_ - typedef struct { - f_number_unsigned_t current; - f_number_unsigned_t line; - f_number_unsigned_t total; - - f_string_static_t *argv; - - f_string_dynamic_t name; - } fss_identify_data_t; - - #define fss_identify_data_t_initialize \ - { \ - 0, \ - 0, \ - 0, \ - 0, \ - f_string_dynamic_t_initialize, \ - } -#endif // _di_fss_identify_data_t_ - -/** - * Fully deallocate all memory. - * - * @param data - * The data to deallocate. - */ -#ifndef _di_fss_identify_data_delete_ - extern void fss_identify_data_delete(fss_identify_data_t *data) F_attribute_visibility_internal_d; -#endif // _di_fss_identify_data_delete_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_common_h diff --git a/level_3/fss_identify/c/private-identify.c b/level_3/fss_identify/c/private-identify.c deleted file mode 100644 index 3e43b5c..0000000 --- a/level_3/fss_identify/c/private-identify.c +++ /dev/null @@ -1,198 +0,0 @@ -#include "fss_identify.h" -#include "private-common.h" -#include "private-identify.h" -#include "private-print.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_identify_load_line_ - f_status_t fss_identify_load_line(fll_program_data_t * const main, const f_file_t file, const f_string_static_t file_name, f_string_static_t *buffer, f_string_range_t *range) { - - f_status_t status = F_none; - - buffer->used = 0; - - range->start = 0; - range->stop = 0; - - do { - if (!((++main->signal_check) % fss_identify_signal_check_d)) { - if (fll_program_standard_signal_received(&main->program)) { - fll_program_print_signal_received(main->warning, main->signal_received); - - status = F_status_set_error(F_interrupt); - - break; - } - - main->signal_check = 0; - } - - if (buffer->used + file.size_read > buffer->size) { - status = f_string_dynamic_resize(buffer->size + file.size_read, buffer); - - if (F_status_is_error(status)) { - fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", fll_error_file_flag_fallback_e, file_name.used ? file_name : f_string_ascii_minus_s, f_file_operation_read_s, file_name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); - - return status; - } - } - - status = f_file_stream_read_block(file, buffer); - - if (F_status_is_error(status)) { - fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_read_block", fll_error_file_flag_fallback_e, file_name.used ? file_name : f_string_ascii_minus_s, f_file_operation_read_s, file_name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); - - return status; - } - - for (; range->start < buffer->used; ++range->start) { - if (buffer->string[range->start] == f_string_eol_s.string[0]) break; - } // for - - range->stop = range->start; - - if (buffer->string[range->start] == f_string_eol_s.string[0]) break; - - } while (F_status_is_error_not(status) && status != F_none_eof); - - // Reset the start point to prepare the buffer for processing. - range->start = 0; - - return status; - } -#endif // _di_fss_identify_load_line_ - -#ifndef _di_fss_identify_process_ - f_status_t fss_identify_process(fll_program_data_t * const main, fss_identify_data_t * const data, const f_string_static_t file_name, const f_string_static_t buffer, f_string_range_t *range) { - - f_status_t status = F_none; - f_fll_ids_t ids = f_fll_ids_t_initialize; - - status = fll_fss_identify(buffer, range, &ids); - - if (F_status_is_error(status)) { - fll_error_file_print(main->error, F_status_set_fine(status), "fll_fss_identify", fll_error_file_flag_fallback_e, file_name.used ? file_name : f_string_ascii_pipe_s, f_file_operation_read_s, file_name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); - - f_fll_ids_resize(0, &ids); - - return status; - } - - // 0 = is name, 1 = is type, 2 = is full. - uint8_t mode = 1; - f_number_unsigned_t i = 0; - - if (data->name.used) { - for (; i < data->name.used; ++i) { - - if (data->name.string[i] == f_string_ascii_minus_s.string[0]) { - mode = 2; - - break; - } - - if (f_utf_is_digit(data->name.string + i, data->name.used - i, 0) != F_true) { - mode = 0; - } - } // for - } - - if (main->parameters.array[fss_identify_parameter_line_e].result & f_console_result_value_e) { - for (i = 0; i < ids.used; ++i, ++data->current) { - - if (data->current == data->line) { - if (data->name.used) { - if (fss_identify_process_name_compare(data, ids.array[i], mode) != F_equal_to) continue; - } - - if (main->parameters.array[fss_identify_parameter_total_e].result & f_console_result_found_e) { - ++data->total; - } - else { - fss_identify_print(main, ids.array[i]); - } - - ++data->current; - - break; - } - } // for - } - else if (main->parameters.array[fss_identify_parameter_total_e].result & f_console_result_found_e) { - if (data->name.used) { - - for (i = 0; i < ids.used; ++i, ++data->current) { - - if (fss_identify_process_name_compare(data, ids.array[i], mode) == F_equal_to) { - ++data->total; - } - } // for - } - else { - data->total += ids.used; - } - } - else if (status == F_found || status == F_maybe) { - for (i = 0; i < ids.used; ++i) { - - if (data->name.used) { - if (fss_identify_process_name_compare(data, ids.array[i], mode) != F_equal_to) continue; - } - - fss_identify_print(main, ids.array[i]); - } // for - } - - f_fll_ids_resize(0, &ids); - - return F_none; - } -#endif // _di_fss_identify_process_ - -#ifndef _di_fss_identify_process_name_compare_ - f_status_t fss_identify_process_name_compare(fss_identify_data_t * const data, const f_fll_id_t id, const uint8_t mode) { - - if (mode) { - f_number_unsigned_t number = 0; - f_string_range_t range = macro_f_string_range_t_initialize_2(data->name.used); - - for (f_number_unsigned_t i = 0; i < data->name.used; ++i) { - - if (data->name.string[i] == f_string_ascii_minus_s.string[0] && i + 1 < data->name.used) { - range.start = i + 1; - - break; - } - } // for - - { - const f_status_t status = fl_conversion_dynamic_partial_to_unsigned(fl_conversion_data_base_16_c, data->name, range, &number); - if (F_status_is_error(status)) return status; - } - - if (id.type != number) { - return F_equal_to_not; - } - - if (mode == 1) { - return F_equal_to; - } - - if (range.start) { - range.stop = range.start - 2; - range.start = 0; - } - - return f_compare_dynamic_partial_string((const f_string_t) id.name, data->name, id.used, range); - } - - return f_compare_dynamic_string((const f_string_t) id.name, data->name, id.used); - } -#endif // _di_fss_identify_process_name_compare_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_identify/c/private-identify.h b/level_3/fss_identify/c/private-identify.h deleted file mode 100644 index 23cbc65..0000000 --- a/level_3/fss_identify/c/private-identify.h +++ /dev/null @@ -1,100 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Identify - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _PRIVATE_identify_h -#define _PRIVATE_identify_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Load a pipe or a file 1 block at a time untul a newline is found. - * - * @param main - * The main program data. - * @param file - * The file or pipe to load from. - * @param file_name - * The name of the file. - * Set to NULL to designate that this is a pipe. - * @param buffer - * The string representing the file to process. - * @param range - * The range representing the line in the buffer. - * - * @return - * Status from: f_file_stream_read_block(). - * - * Errors (with error bit) from: f_file_stream_read_block(). - * Errors (with error bit) from: f_string_dynamic_resize(). - * - * @see f_file_stream_read_block() - * @see f_string_dynamic_resize() - */ -#ifndef _di_fss_identify_load_line_ - extern f_status_t fss_identify_load_line(fll_program_data_t * const main, const f_file_t file, const f_string_static_t file_name, f_string_static_t *buffer, f_string_range_t *range) F_attribute_visibility_internal_d; -#endif // _di_fss_identify_load_line_ - -/** - * Process a given pipe or file. - * - * @param main - * The main program data. - * @param data - * The program data. - * @param file_name - * The name of the file. - * Set to NULL to designate that this is a pipe. - * @param buffer - * The string representing the file to process. - * @param range - * The range representing the line in the buffer. - * - * @return - * F_none on success. - * - * Errors (with error bit) from: fll_fss_identify(). - * - * @see fll_fss_identify() - */ -#ifndef _di_fss_identify_process_ - extern f_status_t fss_identify_process(fll_program_data_t * const main, fss_identify_data_t * const data, const f_string_static_t file_name, const f_string_static_t buffer, f_string_range_t *range) F_attribute_visibility_internal_d; -#endif // _di_fss_identify_process_ - -/** - * Determine if the given FLL ID matches the requested range. - * - * @param data - * The program data. - * @param id - * The FLL ID to compare against. - * @param mode - * A mode specifying how to compare. - * 0 = Compare against just the ID Name (such as "fss" in "fss-0001"). - * 1 = Compare against just the ID Type (such as "0001" in "fss-0001"). - * 2 = Compare against the full name (such as "fss-0001" in "fss-0001"). - * - * @return - * F_true on match. - * F_false on no match. - * - * Errors (with error bit) from fl_conversion_dynamic_partial_to_hexidecimal_unsigned(). - * Errors (with error bit) from f_compare_dynamic_string(). - * - * @see fl_conversion_dynamic_partial_to_hexidecimal_unsigned() - * @see f_compare_dynamic_string() - */ -#ifndef _di_fss_identify_process_name_compare_ - f_status_t fss_identify_process_name_compare(fss_identify_data_t * const data, const f_fll_id_t id, const uint8_t mode) F_attribute_visibility_internal_d; -#endif // _di_fss_identify_process_name_compare_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_identify_h diff --git a/level_3/fss_identify/c/private-print.c b/level_3/fss_identify/c/private-print.c deleted file mode 100644 index 4b320e8..0000000 --- a/level_3/fss_identify/c/private-print.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "fss_identify.h" -#include "private-common.h" -#include "private-print.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_fss_identify_print_ - void fss_identify_print(fll_program_data_t * const main, const f_fll_id_t id) { - - f_file_stream_lock(main->output.to); - - if ((main->parameters.array[fss_identify_parameter_object_e].result & f_console_result_found_e) || main->parameters.array[fss_identify_parameter_content_e].result != f_console_result_found_e) { - f_print((const f_string_t) id.name, id.used, main->output.to); - - if (main->parameters.array[fss_identify_parameter_object_e].result != f_console_result_found_e || (main->parameters.array[fss_identify_parameter_content_e].result & f_console_result_found_e)) { - f_print_dynamic_raw(f_fss_type_header_part5_s, main->output.to); - } - } - - if (main->parameters.array[fss_identify_parameter_object_e].result != f_console_result_found_e || (main->parameters.array[fss_identify_parameter_content_e].result & f_console_result_found_e)) { - fl_print_format("%04_ui", main->output.to, id.type); - } - - f_print_dynamic_raw(f_string_eol_s, main->output.to); - - f_file_stream_unlock(main->output.to); - } -#endif // _di_fss_identify_print_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/fss_identify/c/private-print.h b/level_3/fss_identify/c/private-print.h deleted file mode 100644 index e0a828a..0000000 --- a/level_3/fss_identify/c/private-print.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: FSS Identify - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - */ -#ifndef _PRIVATE_print_h -#define _PRIVATE_print_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Print the given FLL Identifier. - * - * @param main - * The main program data. - * @param id - * The Identifier to print. - */ -#ifndef _di_fss_identify_print_ - extern void fss_identify_print(fll_program_data_t * const main, const f_fll_id_t id) F_attribute_visibility_internal_d; -#endif // _di_fss_identify_print_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_print_h diff --git a/level_3/fss_identify/data/build/settings b/level_3/fss_identify/data/build/settings index 994bae0..bd2252e 100644 --- a/level_3/fss_identify/data/build/settings +++ b/level_3/fss_identify/data/build/settings @@ -35,11 +35,11 @@ build_libraries-individual_thread -lf_thread build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll -build_sources_library fss_identify.c common.c print.c private-common.c private-identify.c private-print.c +build_sources_library main/common.c main/common/define.c main/common/enumeration.c main/common/print.c main/common/string.c main/common/type.c main/load.c main/print/data.c main/print/error.c main/print/message.c main/process.c main/signal.c main/thread.c main/fss_identify.c -build_sources_program main.c +build_sources_program main/main.c -build_sources_headers fss_identify.h common.h print.h +build_sources_headers main/common.h main/common/define.h main/common/enumeration.h main/common/print.h main/common/string.h main/common/type.h main/load.h main/print.h main/print/data.h main/print/error.h main/print/message.h main/process.h main/signal.h main/thread.h main/fss_identify.h build_sources_documentation man -- 1.8.3.1