From 05cea4edd86d43eba519f939cafa590129879d5a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 19 Feb 2022 09:24:34 -0600 Subject: [PATCH] Feature: The fll_identify -n/--name now supports full name as well as type code. For an example "fss-0001", in addition to matching "fss", also match "0001" or "fss-0001" if requested. --- level_3/fss_identify/c/fss_identify.c | 9 ++-- level_3/fss_identify/c/private-identify.c | 88 +++++++++++++++++++++++++------ level_3/fss_identify/c/private-identify.h | 35 ++++++++++-- 3 files changed, 107 insertions(+), 25 deletions(-) diff --git a/level_3/fss_identify/c/fss_identify.c b/level_3/fss_identify/c/fss_identify.c index 36e8e59..959be2f 100644 --- a/level_3/fss_identify/c/fss_identify.c +++ b/level_3/fss_identify/c/fss_identify.c @@ -31,7 +31,7 @@ extern "C" { f_print_dynamic_raw(f_string_eol_s, file.stream); fll_program_print_help_option(file, context, fss_identify_short_line_s, fss_identify_long_line_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print only the Identifier at the given line."); - fll_program_print_help_option(file, context, fss_identify_short_name_s, fss_identify_long_name_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select Object with this name."); + fll_program_print_help_option(file, context, fss_identify_short_name_s, fss_identify_long_name_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Select FSS using this full or partial type name or code."); fll_program_print_help_option(file, context, fss_identify_short_total_s, fss_identify_long_total_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Print the total Identifiers found."); fll_program_print_help_usage(file, context, fss_identify_program_name_s, fll_program_parameter_filenames_s); @@ -255,10 +255,10 @@ extern "C" { for (f_array_length_t i = range.start; i <= range.stop; ++i) { - status = f_utf_is_word(data.argv[index].string + i, length, F_true); + 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", F_true); + fll_error_print(main->error, F_status_set_fine(status), "f_utf_is_word_dash", F_true); break; } @@ -269,7 +269,7 @@ extern "C" { fl_print_format("%[%Q%]", main->error.to.stream, main->error.notable, data.argv[index], main->error.notable); fl_print_format("%[' for the parameter '%]", main->error.to.stream, main->error.context, main->error.context); fl_print_format("%[%r%r%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, fss_identify_long_name_s, main->error.notable); - fl_print_format("%[' may only contain word characters.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s); + fl_print_format("%[' may only contain word characters or the dash (minus)y character.%]%r", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s); funlockfile(main->error.to.stream); @@ -308,6 +308,7 @@ extern "C" { if (!((++signal_check) % fss_identify_signal_check_d)) { if (fss_identify_signal_received(main)) { status = F_status_set_error(F_interrupt); + break; } diff --git a/level_3/fss_identify/c/private-identify.c b/level_3/fss_identify/c/private-identify.c index e8e9eab..5970d2e 100644 --- a/level_3/fss_identify/c/private-identify.c +++ b/level_3/fss_identify/c/private-identify.c @@ -8,7 +8,7 @@ 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 name, f_string_static_t *buffer, f_string_range_t *range) { + 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; uint16_t signal_check = 0; @@ -33,7 +33,7 @@ extern "C" { 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", F_true, 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); + fll_error_file_print(main->error, F_status_set_fine(status), "f_string_dynamic_resize", F_true, 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; } @@ -42,7 +42,7 @@ extern "C" { 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", F_true, 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); + fll_error_file_print(main->error, F_status_set_fine(status), "f_file_stream_read_block", F_true, 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; } @@ -65,7 +65,7 @@ extern "C" { #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 name, const f_string_static_t buffer, f_string_range_t *range) { + 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; @@ -73,22 +73,38 @@ extern "C" { 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", F_true, name.used ? name : f_string_ascii_pipe_s, f_file_operation_read_s, name.used ? fll_error_file_type_file_e : fll_error_file_type_pipe_e); + fll_error_file_print(main->error, F_status_set_fine(status), "fll_fss_identify", F_true, 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; } - if (main->parameters.array[fss_identify_parameter_line_e].result == f_console_result_additional_e) { + // 0 = is name, 1 = is type, 2 = is full. + uint8_t mode = 1; + f_array_length_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; - for (f_array_length_t i = 0; i < ids.used; ++i, ++data->current) { + break; + } + + if (f_utf_is_digit(data->name.string + i, data->name.used - i) != F_true) { + mode = 0; + } + } // for + } + + if (main->parameters.array[fss_identify_parameter_line_e].result == f_console_result_additional_e) { + for (i = 0; i < ids.used; ++i, ++data->current) { if (data->current == data->line) { if (data->name.used) { - if (fl_string_dynamic_compare_string(ids.array[i].name, data->name, ids.array[i].used) != F_equal_to) { - continue; - } + 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) { @@ -107,9 +123,9 @@ extern "C" { else if (main->parameters.array[fss_identify_parameter_total_e].result == f_console_result_found_e) { if (data->name.used) { - for (f_array_length_t i = 0; i < ids.used; ++i, ++data->current) { + for (i = 0; i < ids.used; ++i, ++data->current) { - if (fl_string_dynamic_compare_string(ids.array[i].name, data->name, ids.array[i].used) == F_equal_to) { + if (fss_identify_process_name_compare(data, ids.array[i], mode) == F_equal_to) { ++data->total; } } // for @@ -119,13 +135,10 @@ extern "C" { } } else if (status == F_found || status == F_maybe) { - - for (f_array_length_t i = 0; i < ids.used; ++i) { + for (i = 0; i < ids.used; ++i) { if (data->name.used) { - if (fl_string_dynamic_compare_string(ids.array[i].name, data->name, ids.array[i].used) != F_equal_to) { - continue; - } + if (fss_identify_process_name_compare(data, ids.array[i], mode) != F_equal_to) continue; } fss_identify_print(main, ids.array[i]); @@ -138,6 +151,47 @@ extern "C" { } #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_array_length_t number = 0; + f_string_range_t range = macro_f_string_range_t_initialize(data->name.used); + + for (f_array_length_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_string_to_hexidecimal_unsigned(data->name.string, 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 fl_string_dynamic_partial_compare_string((const f_string_t) id.name, data->name, id.used, range); + } + + return fl_string_dynamic_compare_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 index ab6542b..518ba6d 100644 --- a/level_3/fss_identify/c/private-identify.h +++ b/level_3/fss_identify/c/private-identify.h @@ -19,7 +19,7 @@ extern "C" { * The main program data. * @param file * The file or pipe to load from. - * @param name + * @param file_name * The name of the file. * Set to NULL to designate that this is a pipe. * @param buffer @@ -37,7 +37,7 @@ extern "C" { * @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 name, f_string_static_t *buffer, f_string_range_t *range) F_attribute_visibility_internal_d; + 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_ /** @@ -47,7 +47,7 @@ extern "C" { * The main program data. * @param data * The program data. - * @param name + * @param file_name * The name of the file. * Set to NULL to designate that this is a pipe. * @param buffer @@ -63,9 +63,36 @@ extern "C" { * @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 name, const f_string_static_t buffer, f_string_range_t *range) F_attribute_visibility_internal_d; + 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_string_to_hexidecimal_unsigned(). + * Errors (with error bit) from fl_string_dynamic_compare_string(). + * + * @see fl_conversion_string_to_hexidecimal_unsigned() + * @see fl_string_dynamic_compare_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 -- 1.8.3.1