From: Kevin Day Date: Sun, 23 Oct 2022 21:31:53 +0000 (-0500) Subject: Progress: The iki_read should also support the previous "--substitute" behavior via... X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b5da024e8b18d566dd80522f0afeb3bcc839de2e;p=fll Progress: The iki_read should also support the previous "--substitute" behavior via "--reassign". A "--substitute" bug is now fixed where the "--wrap" is applied. It seems to me that the old behavior of "--substitute" should still exist. Introduce a new parameter called "--reassign" that provides the old substitute behavior. --- diff --git a/level_3/iki_read/c/common.c b/level_3/iki_read/c/common.c index 7234fe2..a9dd4d7 100644 --- a/level_3/iki_read/c/common.c +++ b/level_3/iki_read/c/common.c @@ -25,6 +25,7 @@ extern "C" { const f_string_static_t iki_read_short_literal_s = macro_f_string_static_t_initialize(IKI_READ_short_literal_s, 0, IKI_READ_short_literal_s_length); const f_string_static_t iki_read_short_name_s = macro_f_string_static_t_initialize(IKI_READ_short_name_s, 0, IKI_READ_short_name_s_length); const f_string_static_t iki_read_short_object_s = macro_f_string_static_t_initialize(IKI_READ_short_object_s, 0, IKI_READ_short_object_s_length); + const f_string_static_t iki_read_short_reassign_s = macro_f_string_static_t_initialize(IKI_READ_short_reassign_s, 0, IKI_READ_short_reassign_s_length); const f_string_static_t iki_read_short_replace_s = macro_f_string_static_t_initialize(IKI_READ_short_replace_s, 0, IKI_READ_short_replace_s_length); const f_string_static_t iki_read_short_substitute_s = macro_f_string_static_t_initialize(IKI_READ_short_substitute_s, 0, IKI_READ_short_substitute_s_length); const f_string_static_t iki_read_short_total_s = macro_f_string_static_t_initialize(IKI_READ_short_total_s, 0, IKI_READ_short_total_s_length); @@ -37,6 +38,7 @@ extern "C" { const f_string_static_t iki_read_long_literal_s = macro_f_string_static_t_initialize(IKI_READ_long_literal_s, 0, IKI_READ_long_literal_s_length); const f_string_static_t iki_read_long_name_s = macro_f_string_static_t_initialize(IKI_READ_long_name_s, 0, IKI_READ_long_name_s_length); const f_string_static_t iki_read_long_object_s = macro_f_string_static_t_initialize(IKI_READ_long_object_s, 0, IKI_READ_long_object_s_length); + const f_string_static_t iki_read_long_reassign_s = macro_f_string_static_t_initialize(IKI_READ_long_reassign_s, 0, IKI_READ_long_reassign_s_length); const f_string_static_t iki_read_long_replace_s = macro_f_string_static_t_initialize(IKI_READ_long_replace_s, 0, IKI_READ_long_replace_s_length); const f_string_static_t iki_read_long_substitute_s = macro_f_string_static_t_initialize(IKI_READ_long_substitute_s, 0, IKI_READ_long_substitute_s_length); const f_string_static_t iki_read_long_total_s = macro_f_string_static_t_initialize(IKI_READ_long_total_s, 0, IKI_READ_long_total_s_length); @@ -62,6 +64,7 @@ extern "C" { f_string_dynamics_resize(0, &setting->files); f_string_maps_resize(0, &setting->replace); + f_string_triples_resize(0, &setting->reassign); f_string_triples_resize(0, &setting->substitute); f_string_triples_resize(0, &setting->wrap); @@ -362,95 +365,18 @@ extern "C" { setting->flag |= iki_read_main_flag_replace_e; } - if (main->parameters.array[iki_read_parameter_substitute_e].result != f_console_result_none_e) { - if (main->parameters.array[iki_read_parameter_substitute_e].result == f_console_result_found_e || main->parameters.array[iki_read_parameter_substitute_e].values.used % 3 != 0) { - setting->status = F_status_set_error(F_parameter); - - iki_read_print_line_first_locked(setting, main->error); - fll_program_print_error_parameter_missing_value_requires_amount(main->error, f_console_symbol_long_enable_s, iki_read_long_substitute_s, iki_read_string_three_s); - iki_read_print_line_last_locked(setting, main->error); - - return; - } - - setting->substitute.used = 0; - - setting->status = f_string_triples_increase_by(main->parameters.array[iki_read_parameter_substitute_e].values.used / 3, &setting->substitute); - - if (F_status_is_error(setting->status)) { - iki_read_print_line_first_locked(setting, main->error); - fll_error_print(main->error, F_status_set_fine(setting->status), "f_string_triples_increase_by", F_true); - iki_read_print_line_last_locked(setting, main->error); - - return; - } - - f_array_length_t at = 0; - f_array_length_t index = 0; - f_array_length_t i = 0; - f_array_length_t j = 0; - - for (; i < main->parameters.array[iki_read_parameter_substitute_e].values.used; ++i) { - - index = main->parameters.array[iki_read_parameter_substitute_e].values.array[i]; - - // Replace any existing values so that each name and value pair exists only once. - for (j = 0; j < setting->substitute.used; ++j) { - - if (fl_string_dynamic_compare(main->parameters.arguments.array[index], setting->substitute.array[j].a) == F_equal_to) { - if (fl_string_dynamic_compare(main->parameters.arguments.array[main->parameters.array[iki_read_parameter_substitute_e].values.array[i + 1]], setting->substitute.array[j].b) == F_equal_to) { - break; - } - } - } // for - - at = j; - - // Static strings are being used, so if a dynamic string exists (size > 0), then de-allocate it. - if (setting->substitute.array[at].a.size) { - setting->status = f_string_dynamic_resize(0, &setting->substitute.array[at].a); - } - - if (F_status_is_error_not(setting->status) && setting->substitute.array[at].b.size) { - setting->status = f_string_dynamic_resize(0, &setting->substitute.array[at].b); - } - - if (F_status_is_error_not(setting->status) && setting->substitute.array[at].c.size) { - setting->status = f_string_dynamic_resize(0, &setting->substitute.array[at].c); - } - - if (F_status_is_error(setting->status)) { - iki_read_print_line_first_locked(setting, main->error); - fll_error_print(main->error, F_status_set_fine(setting->status), "f_string_dynamic_resize", F_true); - iki_read_print_line_last_locked(setting, main->error); - - return; - } - - setting->substitute.array[at].a.string = main->parameters.arguments.array[index].string; - setting->substitute.array[at].a.used = main->parameters.arguments.array[index].used; - setting->substitute.array[at].a.size = 0; - - index = main->parameters.array[iki_read_parameter_substitute_e].values.array[++i]; - - setting->substitute.array[at].b.string = main->parameters.arguments.array[index].string; - setting->substitute.array[at].b.used = main->parameters.arguments.array[index].used; - setting->substitute.array[at].b.size = 0; - - index = main->parameters.array[iki_read_parameter_substitute_e].values.array[++i]; - - setting->substitute.array[at].c.string = main->parameters.arguments.array[index].string; - setting->substitute.array[at].c.used = main->parameters.arguments.array[index].used; - setting->substitute.array[at].c.size = 0; + if (iki_read_setting_load_parameter_substitution(main, setting, main->parameters.array[iki_read_parameter_reassign_e], iki_read_long_reassign_s, &setting->reassign)) { + setting->flag |= iki_read_main_flag_reassign_e; + } - if (at == setting->substitute.used) { - ++setting->substitute.used; - } - } // for + if (F_status_is_error(setting->status)) return; + if (iki_read_setting_load_parameter_substitution(main, setting, main->parameters.array[iki_read_parameter_substitute_e], iki_read_long_substitute_s, &setting->substitute)) { setting->flag |= iki_read_main_flag_substitute_e; } + if (F_status_is_error(setting->status)) return; + if (main->parameters.array[iki_read_parameter_wrap_e].result != f_console_result_none_e) { if (main->parameters.array[iki_read_parameter_wrap_e].result == f_console_result_found_e || main->parameters.array[iki_read_parameter_wrap_e].values.used % 3 != 0) { setting->status = F_status_set_error(F_parameter); @@ -678,6 +604,100 @@ extern "C" { } #endif // _di_iki_read_setting_load_ +#ifndef _di_iki_read_setting_load_parameter_substitution_ + f_status_t iki_read_setting_load_parameter_substitution(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_console_parameter_t parameter, const f_string_static_t name, f_string_triples_t *triple) { + + if (parameter.result == f_console_result_none_e) return F_false; + + if (parameter.result == f_console_result_found_e || parameter.values.used % 3 != 0) { + setting->status = F_status_set_error(F_parameter); + + iki_read_print_line_first_locked(setting, main->error); + fll_program_print_error_parameter_missing_value_requires_amount(main->error, f_console_symbol_long_enable_s, name, iki_read_string_three_s); + iki_read_print_line_last_locked(setting, main->error); + + return F_false; + } + + triple->used = 0; + + setting->status = f_string_triples_increase_by(parameter.values.used / 3, triple); + + if (F_status_is_error(setting->status)) { + iki_read_print_line_first_locked(setting, main->error); + fll_error_print(main->error, F_status_set_fine(setting->status), "f_string_triples_increase_by", F_true); + iki_read_print_line_last_locked(setting, main->error); + + return F_false; + } + + f_array_length_t at = 0; + f_array_length_t index = 0; + f_array_length_t i = 0; + f_array_length_t j = 0; + + for (; i < parameter.values.used; ++i) { + + index = parameter.values.array[i]; + + // Replace any existing values so that each name and value pair exists only once. + for (j = 0; j < triple->used; ++j) { + + if (fl_string_dynamic_compare(main->parameters.arguments.array[index], triple->array[j].a) == F_equal_to) { + if (fl_string_dynamic_compare(main->parameters.arguments.array[parameter.values.array[i + 1]], triple->array[j].b) == F_equal_to) { + break; + } + } + } // for + + at = j; + + // Static strings are being used, so if a dynamic string exists (size > 0), then de-allocate it. + if (triple->array[at].a.size) { + setting->status = f_string_dynamic_resize(0, &triple->array[at].a); + } + + if (F_status_is_error_not(setting->status) && triple->array[at].b.size) { + setting->status = f_string_dynamic_resize(0, &triple->array[at].b); + } + + if (F_status_is_error_not(setting->status) && triple->array[at].c.size) { + setting->status = f_string_dynamic_resize(0, &triple->array[at].c); + } + + if (F_status_is_error(setting->status)) { + iki_read_print_line_first_locked(setting, main->error); + fll_error_print(main->error, F_status_set_fine(setting->status), "f_string_dynamic_resize", F_true); + iki_read_print_line_last_locked(setting, main->error); + + return F_false; + } + + triple->array[at].a.string = main->parameters.arguments.array[index].string; + triple->array[at].a.used = main->parameters.arguments.array[index].used; + triple->array[at].a.size = 0; + + index = parameter.values.array[++i]; + + triple->array[at].b.string = main->parameters.arguments.array[index].string; + triple->array[at].b.used = main->parameters.arguments.array[index].used; + triple->array[at].b.size = 0; + + index = parameter.values.array[++i]; + + triple->array[at].c.string = main->parameters.arguments.array[index].string; + triple->array[at].c.used = main->parameters.arguments.array[index].used; + triple->array[at].c.size = 0; + + if (at == triple->used) { + ++triple->used; + } + } // for + + return F_true; + } +#endif // _di_iki_read_setting_load_parameter_substitution_ + #ifndef _di_iki_read_setting_unload_ f_status_t iki_read_setting_unload(fll_program_data_t * const main, iki_read_setting_t * const setting) { diff --git a/level_3/iki_read/c/common.h b/level_3/iki_read/c/common.h index 8c6b7a6..e887b2b 100644 --- a/level_3/iki_read/c/common.h +++ b/level_3/iki_read/c/common.h @@ -90,6 +90,7 @@ extern "C" { #define IKI_READ_short_literal_s "L" #define IKI_READ_short_name_s "n" #define IKI_READ_short_object_s "o" + #define IKI_READ_short_reassign_s "R" #define IKI_READ_short_replace_s "r" #define IKI_READ_short_substitute_s "s" #define IKI_READ_short_total_s "t" @@ -102,6 +103,7 @@ extern "C" { #define IKI_READ_long_literal_s "literal" #define IKI_READ_long_name_s "name" #define IKI_READ_long_object_s "object" + #define IKI_READ_long_reassign_s "reassign" #define IKI_READ_long_replace_s "replace" #define IKI_READ_long_substitute_s "substitute" #define IKI_READ_long_total_s "total" @@ -114,6 +116,7 @@ extern "C" { #define IKI_READ_short_literal_s_length 1 #define IKI_READ_short_name_s_length 1 #define IKI_READ_short_object_s_length 1 + #define IKI_READ_short_reassign_s_length 1 #define IKI_READ_short_replace_s_length 1 #define IKI_READ_short_substitute_s_length 1 #define IKI_READ_short_total_s_length 1 @@ -126,6 +129,7 @@ extern "C" { #define IKI_READ_long_literal_s_length 7 #define IKI_READ_long_name_s_length 4 #define IKI_READ_long_object_s_length 6 + #define IKI_READ_long_reassign_s_length 8 #define IKI_READ_long_replace_s_length 7 #define IKI_READ_long_substitute_s_length 10 #define IKI_READ_long_total_s_length 5 @@ -138,6 +142,7 @@ extern "C" { extern const f_string_static_t iki_read_short_literal_s; extern const f_string_static_t iki_read_short_name_s; extern const f_string_static_t iki_read_short_object_s; + extern const f_string_static_t iki_read_short_reassign_s; extern const f_string_static_t iki_read_short_replace_s; extern const f_string_static_t iki_read_short_substitute_s; extern const f_string_static_t iki_read_short_total_s; @@ -150,6 +155,7 @@ extern "C" { extern const f_string_static_t iki_read_long_literal_s; extern const f_string_static_t iki_read_long_name_s; extern const f_string_static_t iki_read_long_object_s; + extern const f_string_static_t iki_read_long_reassign_s; extern const f_string_static_t iki_read_long_replace_s; extern const f_string_static_t iki_read_long_substitute_s; extern const f_string_static_t iki_read_long_total_s; @@ -176,6 +182,7 @@ extern "C" { iki_read_parameter_literal_e, iki_read_parameter_name_e, iki_read_parameter_object_e, + iki_read_parameter_reassign_e, iki_read_parameter_replace_e, iki_read_parameter_substitute_e, iki_read_parameter_total_e, @@ -204,6 +211,7 @@ extern "C" { macro_f_console_parameter_t_initialize2(iki_read_short_literal_s.string, iki_read_long_literal_s.string, 0, 0, f_console_type_normal_e), \ macro_f_console_parameter_t_initialize2(iki_read_short_name_s.string, iki_read_long_name_s.string, 0, 1, f_console_type_normal_e), \ macro_f_console_parameter_t_initialize2(iki_read_short_object_s.string, iki_read_long_object_s.string, 0, 0, f_console_type_normal_e), \ + macro_f_console_parameter_t_initialize2(iki_read_short_reassign_s.string, iki_read_long_reassign_s.string, 0, 3, f_console_type_normal_e), \ macro_f_console_parameter_t_initialize2(iki_read_short_replace_s.string, iki_read_long_replace_s.string, 0, 2, f_console_type_normal_e), \ macro_f_console_parameter_t_initialize2(iki_read_short_substitute_s.string, iki_read_long_substitute_s.string, 0, 3, f_console_type_normal_e), \ macro_f_console_parameter_t_initialize2(iki_read_short_total_s.string, iki_read_long_total_s.string, 0, 0, f_console_type_normal_e), \ @@ -211,7 +219,7 @@ extern "C" { macro_f_console_parameter_t_initialize2(iki_read_short_wrap_s.string, iki_read_long_wrap_s.string, 0, 3, f_console_type_normal_e), \ } - #define iki_read_total_parameters_d 23 + #define iki_read_total_parameters_d 24 #endif // _di_iki_read_parameters_ #ifndef _di_iki_read_substitution_t_ @@ -246,6 +254,7 @@ extern "C" { * - line: Selecting at a specific line. * - name: Selecting using a specific Vocabulary name. * - object: Print Objects. + * - replace: Using re-assignments. * - replace: Using replacements. * - substitute: Using substitutions. * - total: Enable printing of "total" count. @@ -263,12 +272,13 @@ extern "C" { iki_read_main_flag_line_e = 0x10, iki_read_main_flag_name_e = 0x20, iki_read_main_flag_object_e = 0x40, - iki_read_main_flag_replace_e = 0x80, - iki_read_main_flag_substitute_e = 0x100, - iki_read_main_flag_total_e = 0x200, - iki_read_main_flag_version_e = 0x400, - iki_read_main_flag_whole_e = 0x800, - iki_read_main_flag_wrap_e = 0x1000, + iki_read_main_flag_reassign_e = 0x80, + iki_read_main_flag_replace_e = 0x100, + iki_read_main_flag_substitute_e = 0x200, + iki_read_main_flag_total_e = 0x400, + iki_read_main_flag_version_e = 0x800, + iki_read_main_flag_whole_e = 0x1000, + iki_read_main_flag_wrap_e = 0x2000, }; #endif // _di_iki_read_main_flag_e_ @@ -293,6 +303,7 @@ extern "C" { * files: An array of all files to process (except for the input pipe). * * replace: A map containing the Vocabulary name and its replacement as the value. + * reassign: A triple containing the Vocabulary name (a), Content to match (b), and the string used as the reassign (c). * substitute: A triple containing the Vocabulary name (a), Content to match (b), and the string used as the substitute (c). * wrap: A triple containing the Vocabulary name (a), the string to prepend (b), and the string to append (c). * @@ -318,6 +329,7 @@ extern "C" { f_string_dynamics_t files; f_string_maps_t replace; + f_string_triples_t reassign; f_string_triples_t substitute; f_string_triples_t wrap; @@ -341,6 +353,7 @@ extern "C" { f_string_maps_t_initialize, \ f_string_triples_t_initialize, \ f_string_triples_t_initialize, \ + f_string_triples_t_initialize, \ 0, \ 0, \ f_iki_data_t_initialize, \ @@ -404,6 +417,38 @@ extern "C" { #endif // _di_iki_read_setting_load_ /** + * Load the specific parameter that uses a substitution type, such as reassign or substitute. + * + * This prints error messages as appropriate. + * + * @param main + * The main program data. + * @param setting + * The main program settings. + * + * This alters setting.status: + * F_none on success. + * + * Errors (with error bit) from: f_string_dynamic_resize(). + * Errors (with error bit) from: f_string_triples_resize(). + * @param name + * The name of the parameter. + * This is used for printing error messages. + * @param triple + * The setting, such as setting->substitute, to update. + * + * @return + * F_true if found and processed. + * F_false if not found or not processed. + * + * @see f_string_dynamic_resize() + * @see f_string_triples_resize() + */ +#ifndef _di_iki_read_setting_load_parameter_substitution_ + extern f_status_t iki_read_setting_load_parameter_substitution(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_console_parameter_t parameter, const f_string_static_t name, f_string_triples_t *triple); +#endif // _di_iki_read_setting_load_parameter_substitution_ + +/** * Perform the standard program setting unload process. * * @param main diff --git a/level_3/iki_read/c/print.c b/level_3/iki_read/c/print.c index 161bf92..c18c8d7 100644 --- a/level_3/iki_read/c/print.c +++ b/level_3/iki_read/c/print.c @@ -32,6 +32,7 @@ extern "C" { f_print_dynamic_raw(f_string_eol_s, print.to); + fll_program_print_help_option(print, iki_read_short_reassign_s, iki_read_long_reassign_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Re-assign the variable for the given name and matching content value with the given string."); fll_program_print_help_option(print, iki_read_short_replace_s, iki_read_long_replace_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Simple substitution, replacing the variable for the given name with the given string."); fll_program_print_help_option(print, iki_read_short_substitute_s, iki_read_long_substitute_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Substitute the variable for the given name and matching content value with the given string."); fll_program_print_help_option(print, iki_read_short_wrap_s, iki_read_long_wrap_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Prepend and append strings for the given name."); @@ -53,14 +54,15 @@ extern "C" { fl_print_format(" The vocabulary is case-sensitive and must exactly match.%r%r", print.to, f_string_eol_s, f_string_eol_s); - fl_print_format(" The %[%r%r%] option requires 3 additional parameters:", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_substitute_s, print.set->notable); + fl_print_format(" The %[%r%r%] and the", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_reassign_s, print.set->notable); + fl_print_format(" %[%r%r%] options require 3 additional parameters:", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_substitute_s, print.set->notable); fl_print_format(" %[<%]%r%[>%]", print.to, print.set->notable, print.set->notable, iki_read_substitution_vocabulary_s, print.set->notable, print.set->notable); fl_print_format(" %[<%]%r%[>%]", print.to, print.set->notable, print.set->notable, iki_read_substitution_replace_s, print.set->notable, print.set->notable); fl_print_format(" %[<%]%r%[>%].%r", print.to, print.set->notable, print.set->notable, iki_read_substitution_with_s, print.set->notable, print.set->notable, f_string_eol_s); - fl_print_format(" %[%r%]: The name of the vocabulary whose content is to be substituted.%r", print.to, print.set->notable, iki_read_substitution_vocabulary_s, print.set->notable, f_string_eol_s); - fl_print_format(" %[%r%]: The content matching this exact string will be substituted.%r", print.to, print.set->notable, iki_read_substitution_replace_s, print.set->notable, f_string_eol_s); - fl_print_format(" %[%r%]: The new string to use as the substitute.%r%r", print.to, print.set->notable, iki_read_substitution_with_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format(" %[%r%]: The name of the vocabulary whose content is to be substituted or re-assigned.%r", print.to, print.set->notable, iki_read_substitution_vocabulary_s, print.set->notable, f_string_eol_s); + fl_print_format(" %[%r%]: The content matching this exact string will be substituted or re-assigned.%r", print.to, print.set->notable, iki_read_substitution_replace_s, print.set->notable, f_string_eol_s); + fl_print_format(" %[%r%]: The new string to use as the substitute or re-assignment.%r%r", print.to, print.set->notable, iki_read_substitution_with_s, print.set->notable, f_string_eol_s, f_string_eol_s); fl_print_format(" The vocabulary and replacement are case-sensitive and must exactly match.%r%r", print.to, f_string_eol_s, f_string_eol_s); @@ -80,6 +82,10 @@ extern "C" { fl_print_format(" %[%r%r%] option substitutes all matching vocabulary names and the", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_replace_s, print.set->notable); fl_print_format(" %[%r%r%] option substitutes all matching vocabulary names that must also have the given matching content.%r%r", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_substitute_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format(" The %[%r%r%]", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_reassign_s, print.set->notable); + fl_print_format(" option is identical to the %[%r%r%] option", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_substitute_s, print.set->notable); + fl_print_format(" except that the %[%r%r%] option is ignored (not applied).%r%r", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_wrap_s, print.set->notable, f_string_eol_s, f_string_eol_s); + fl_print_format(" The %[%r%r%]", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_substitute_s, print.set->notable); fl_print_format(" option takes priority over the %[%r%r%] option when matching the same variable.%r%r", print.to, print.set->notable, f_console_symbol_long_enable_s, iki_read_long_replace_s, print.set->notable, f_string_eol_s, f_string_eol_s); diff --git a/level_3/iki_read/c/private-print.c b/level_3/iki_read/c/private-print.c index 96a95e0..5fd8187 100644 --- a/level_3/iki_read/c/private-print.c +++ b/level_3/iki_read/c/private-print.c @@ -10,10 +10,36 @@ extern "C" { #ifndef _di_iki_read_print_ void iki_read_print(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_array_length_t index) { - f_array_length_t at = setting->substitute.used; + f_array_length_t at = setting->reassign.used; + + if (setting->reassign.used && (setting->flag & (iki_read_main_flag_content_e | iki_read_main_flag_literal_e))) { + at = iki_read_identify_substitution(setting, setting->data.vocabulary.array[index], setting->data.content.array[index], &setting->reassign); + } + + if (at < setting->reassign.used) { + if (setting->flag & iki_read_main_flag_content_e) { + f_print_dynamic(setting->reassign.array[at].c, main->output.to); + } + else { + f_string_range_t range = macro_f_string_range_t_initialize(setting->data.variable.array[index].start, setting->data.content.array[index].start - 1); + + f_print_dynamic_partial(setting->buffer, range, main->output.to); + + f_print_dynamic(setting->reassign.array[at].c, main->output.to); + + range.start = setting->data.content.array[index].stop + 1; + range.stop = setting->data.variable.array[index].stop; + + f_print_dynamic_partial(setting->buffer, range, main->output.to); + } + + return; + } + + at = setting->substitute.used; if (setting->substitute.used && (setting->flag & (iki_read_main_flag_content_e | iki_read_main_flag_literal_e))) { - at = iki_read_identify_substitution(setting, setting->data.vocabulary.array[index], setting->data.content.array[index]); + at = iki_read_identify_substitution(setting, setting->data.vocabulary.array[index], setting->data.content.array[index], &setting->substitute); } if (at < setting->substitute.used) { diff --git a/level_3/iki_read/c/private-read.c b/level_3/iki_read/c/private-read.c index 4b5c6f9..22354e4 100644 --- a/level_3/iki_read/c/private-read.c +++ b/level_3/iki_read/c/private-read.c @@ -66,20 +66,20 @@ extern "C" { #endif // _di_iki_read_identify_alteration_ #ifndef _di_iki_read_identify_substitution_ - f_array_length_t iki_read_identify_substitution(iki_read_setting_t * const setting, const f_string_range_t name, const f_string_range_t value) { + f_array_length_t iki_read_identify_substitution(iki_read_setting_t * const setting, const f_string_range_t name, const f_string_range_t value, f_string_triples_t *triple) { - register f_array_length_t i = setting->substitute.used - 1; + f_array_length_t i = triple->used - 1; do { - if (fl_string_dynamic_partial_compare_string(setting->substitute.array[i].a.string, setting->buffer, setting->substitute.array[i].a.used, name) == F_equal_to) { - if (fl_string_dynamic_partial_compare_string(setting->substitute.array[i].b.string, setting->buffer, setting->substitute.array[i].b.used, value) == F_equal_to) { + if (fl_string_dynamic_partial_compare_string(triple->array[i].a.string, setting->buffer, triple->array[i].a.used, name) == F_equal_to) { + if (fl_string_dynamic_partial_compare_string(triple->array[i].b.string, setting->buffer, triple->array[i].b.used, value) == F_equal_to) { return i; } } } while (i--); - return setting->substitute.used; + return triple->used; } #endif // _di_iki_read_identify_substitution_ diff --git a/level_3/iki_read/c/private-read.h b/level_3/iki_read/c/private-read.h index acaf583..3d554b9 100644 --- a/level_3/iki_read/c/private-read.h +++ b/level_3/iki_read/c/private-read.h @@ -35,9 +35,9 @@ extern "C" { #endif // _di_iki_read_identify_alteration_ /** - * Process the arguments, associating the last matching substitution with a given vocabulary name and value (Object and Content). + * Process the arguments, associating the last matching reassignment or substitution with a given vocabulary name and value (Object and Content). * - * This function expects appropriate sanity checks are performed on the substitutions array before calling. + * This function expects appropriate sanity checks are performed on the reassignments or substitutions array before calling. * * @param setting * The main program settings. @@ -45,13 +45,15 @@ extern "C" { * A range within setting->buffer representing the name (Object) to match. * @param value * A range within setting->buffer representing the value (Content) to match. + * @param triple + * The setting, such as setting->substitute, to update. * * @return * The matched substitution. - * The value of setting->substitute.used is returned on no match. + * The value of the triple.used is returned on no match. */ #ifndef _di_iki_read_identify_substitution_ - extern f_array_length_t iki_read_identify_substitution(iki_read_setting_t * const setting, const f_string_range_t name, const f_string_range_t value) F_attribute_visibility_internal_d; + extern f_array_length_t iki_read_identify_substitution(iki_read_setting_t * const setting, const f_string_range_t name, const f_string_range_t value, f_string_triples_t *triple) F_attribute_visibility_internal_d; #endif // _di_iki_read_identify_substitution_ /**