From: Kevin Day Date: Sun, 23 Oct 2022 02:58:16 +0000 (-0500) Subject: Progress: Fix problems in iki_read. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=bcaeef117bede5037b0404ebf299446dd1be3fcc;p=fll Progress: Fix problems in iki_read. As I suspected, the interruptions resulted in incomplete and problematic code. Fix copy and paste problems where modulus should instead be a slash (divide). Use _increase_by functions rather than _resize functions to be more memory recycling friendly. When processing parameters the index relative to the argv should be used. Change the logic in the loops to increment "i" across all parameter values rather than the total sets. Fix copy and paste mistakes where "wrap" is being incremented for non-wrap data. The "--whole" parameter is not being processed and having the appropriate flag set. The print function has incorrect ordering and structure of some of the functions called. The print function is further simplified now that settings is passing the flag along. The "wrap" append functions are not comparing against the correct variable (I swapped them by accident). Do not do "register" types of optimizations at this point in time (this can be done far in the future when things are stable-ish). Be sure to clear the lengths using memset(). The variable "k" can be moved inside the if condition following its assignment. --- diff --git a/level_3/iki_read/c/common.c b/level_3/iki_read/c/common.c index e6294ec..a2249f5 100644 --- a/level_3/iki_read/c/common.c +++ b/level_3/iki_read/c/common.c @@ -296,15 +296,13 @@ extern "C" { return; } - const f_array_length_t total = main->parameters.array[iki_read_parameter_replace_e].values.used % 2; - setting->replace.used = 0; - setting->status = f_string_maps_resize(total, &setting->replace); + setting->status = f_string_maps_increase_by(main->parameters.array[iki_read_parameter_replace_e].values.used / 2, &setting->replace); 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_maps_resize", F_true); + fll_error_print(main->error, F_status_set_fine(setting->status), "f_string_maps_increase_by", F_true); iki_read_print_line_last_locked(setting, main->error); return; @@ -315,11 +313,16 @@ extern "C" { f_array_length_t i = 0; f_array_length_t j = 0; - for (; i < total; ++i) { + for (; i < main->parameters.array[iki_read_parameter_replace_e].values.used; ++i) { - // Replace any existing values so that each name exists only once. + index = main->parameters.array[iki_read_parameter_replace_e].values.array[i]; + + // Replace any existing value so that each name exists only once. for (j = 0; j < setting->replace.used; ++j) { - if (fl_string_dynamic_compare(main->parameters.arguments.array[i], setting->replace.array[j].name) == F_equal_to) break; + + if (fl_string_dynamic_compare(main->parameters.arguments.array[index], setting->replace.array[j].name) == F_equal_to) { + break; + } } // for at = j; @@ -341,20 +344,18 @@ extern "C" { return; } - index = main->parameters.array[iki_read_parameter_replace_e].values.array[i]; - setting->replace.array[at].name.string = main->parameters.arguments.array[index].string; setting->replace.array[at].name.used = main->parameters.arguments.array[index].used; setting->replace.array[at].name.size = 0; - index = main->parameters.array[iki_read_parameter_replace_e].values.array[i + 1]; + index = main->parameters.array[iki_read_parameter_replace_e].values.array[++i]; setting->replace.array[at].value.string = main->parameters.arguments.array[index].string; setting->replace.array[at].value.used = main->parameters.arguments.array[index].used; setting->replace.array[at].value.size = 0; - if (at == setting->wrap.used) { - ++setting->wrap.used; + if (at == setting->replace.used) { + ++setting->replace.used; } } // for @@ -372,15 +373,13 @@ extern "C" { return; } - const f_array_length_t total = main->parameters.array[iki_read_parameter_substitute_e].values.used % 3; - setting->substitute.used = 0; - setting->status = f_string_triples_resize(total, &setting->substitute); + 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_resize", F_true); + 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; @@ -391,7 +390,7 @@ extern "C" { f_array_length_t i = 0; f_array_length_t j = 0; - for (; i < total; ++i) { + 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]; @@ -432,20 +431,20 @@ extern "C" { 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 + 1]; + 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 + 2]; + 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 (at == setting->wrap.used) { - ++setting->wrap.used; + if (at == setting->substitute.used) { + ++setting->substitute.used; } } // for @@ -463,15 +462,13 @@ extern "C" { return; } - const f_array_length_t total = main->parameters.array[iki_read_parameter_wrap_e].values.used % 3; - setting->wrap.used = 0; - setting->status = f_string_triples_resize(total, &setting->wrap); + setting->status = f_string_triples_increase_by(main->parameters.array[iki_read_parameter_wrap_e].values.used / 3, &setting->wrap); 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_resize", F_true); + 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; @@ -482,13 +479,16 @@ extern "C" { f_array_length_t i = 0; f_array_length_t j = 0; - for (; i < total; ++i) { + for (; i < main->parameters.array[iki_read_parameter_wrap_e].values.used; ++i) { index = main->parameters.array[iki_read_parameter_wrap_e].values.array[i]; // Replace any existing values so that each name exists only once. for (j = 0; j < setting->wrap.used; ++j) { - if (fl_string_dynamic_compare(main->parameters.arguments.array[index], setting->wrap.array[j].a) == F_equal_to) break; + + if (fl_string_dynamic_compare(main->parameters.arguments.array[index], setting->wrap.array[j].a) == F_equal_to) { + break; + } } // for at = j; @@ -518,13 +518,13 @@ extern "C" { setting->wrap.array[at].a.used = main->parameters.arguments.array[index].used; setting->wrap.array[at].a.size = 0; - index = main->parameters.array[iki_read_parameter_wrap_e].values.array[i + 1]; + index = main->parameters.array[iki_read_parameter_wrap_e].values.array[++i]; setting->wrap.array[at].b.string = main->parameters.arguments.array[index].string; setting->wrap.array[at].b.used = main->parameters.arguments.array[index].used; setting->wrap.array[at].b.size = 0; - index = main->parameters.array[iki_read_parameter_wrap_e].values.array[i + 2]; + index = main->parameters.array[iki_read_parameter_wrap_e].values.array[++i]; setting->wrap.array[at].c.string = main->parameters.arguments.array[index].string; setting->wrap.array[at].c.used = main->parameters.arguments.array[index].used; @@ -624,6 +624,10 @@ extern "C" { setting->flag |= iki_read_main_flag_content_e; } + if (main->parameters.array[iki_read_parameter_whole_e].result == f_console_result_found_e) { + setting->flag |= iki_read_main_flag_whole_e; + } + if (main->parameters.remaining.used) { setting->files.used = 0; diff --git a/level_3/iki_read/c/private-print.c b/level_3/iki_read/c/private-print.c index 7e24979..7fb1dfa 100644 --- a/level_3/iki_read/c/private-print.c +++ b/level_3/iki_read/c/private-print.c @@ -8,7 +8,7 @@ extern "C" { #endif #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, const bool content_only) { + 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; @@ -17,59 +17,45 @@ extern "C" { } if (at < setting->substitute.used) { - if (content_only) { - iki_read_print_wrap_prepend(main, setting, index); - - f_print_dynamic(setting->substitute.array[at].c, main->output.to); - - iki_read_print_wrap_append(main, setting, index); + if (!(setting->flag & iki_read_main_flag_content_e)) { + f_print_dynamic(setting->substitute.array[at].a, 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); - iki_read_print_wrap_prepend(main, setting, index); - - f_print_dynamic(setting->substitute.array[at].a, main->output.to); + iki_read_print_wrap_prepend(main, setting, index); - iki_read_print_wrap_append(main, setting, index); + f_print_dynamic(setting->substitute.array[at].c, main->output.to); - f_print_dynamic(setting->substitute.array[at].c, main->output.to); - } + iki_read_print_wrap_append(main, setting, index); } else if (setting->replace.used && setting->map_replaces[index] < setting->replace.used) { - if (content_only) { + if (setting->flag & iki_read_main_flag_content_e) { iki_read_print_wrap_prepend(main, setting, index); - f_print_dynamic(setting->replace.array[index].value, main->output.to); + f_print_dynamic(setting->replace.array[setting->map_replaces[index]].value, main->output.to); iki_read_print_wrap_append(main, setting, index); } else if (setting->flag & iki_read_main_flag_object_e) { - f_print_dynamic(setting->replace.array[index].name, main->output.to); + f_print_dynamic(setting->replace.array[setting->map_replaces[index]].name, 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, setting->data.vocabulary.array[index], main->output.to); f_print_dynamic_partial(setting->buffer, range, main->output.to); iki_read_print_wrap_prepend(main, setting, index); - f_print_dynamic_partial(setting->buffer, setting->data.content.array[index], main->output.to); + f_print_dynamic(setting->replace.array[setting->map_replaces[index]].value, main->output.to); iki_read_print_wrap_append(main, setting, index); - f_print_dynamic(setting->replace.array[index].value, 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); } } - else if (content_only) { + else if (setting->flag & iki_read_main_flag_content_e) { iki_read_print_wrap_prepend(main, setting, index); f_print_dynamic_partial(setting->buffer, setting->data.content.array[index], main->output.to); @@ -82,7 +68,6 @@ extern "C" { 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, setting->data.vocabulary.array[index], main->output.to); f_print_dynamic_partial(setting->buffer, range, main->output.to); iki_read_print_wrap_prepend(main, setting, index); @@ -102,7 +87,12 @@ extern "C" { #ifndef _di_iki_read_print_wrap_append_ void iki_read_print_wrap_append(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_array_length_t index) { - if (!(index < setting->wrap.used && setting->wrap.array[setting->map_wraps[index]].c.used)) return; + if (index < setting->data.vocabulary.used && setting->map_wraps[index] < setting->wrap.used) { + if (!setting->wrap.array[setting->map_wraps[index]].c.used) return; + } + else { + return; + } f_print_dynamic(setting->wrap.array[setting->map_wraps[index]].c, main->output.to); } @@ -111,7 +101,12 @@ extern "C" { #ifndef _di_iki_read_print_wrap_prepend_ void iki_read_print_wrap_prepend(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_array_length_t index) { - if (!(index < setting->wrap.used && setting->wrap.array[setting->map_wraps[index]].b.used)) return; + if (index < setting->data.vocabulary.used && setting->map_wraps[index] < setting->wrap.used) { + if (!setting->wrap.array[setting->map_wraps[index]].b.used) return; + } + else { + return; + } f_print_dynamic(setting->wrap.array[setting->map_wraps[index]].b, main->output.to); } diff --git a/level_3/iki_read/c/private-print.h b/level_3/iki_read/c/private-print.h index 611c716..4ac7eb3 100644 --- a/level_3/iki_read/c/private-print.h +++ b/level_3/iki_read/c/private-print.h @@ -29,12 +29,9 @@ extern "C" { * This does not alter setting.status. * @param index * The index used to identify the desired range in variable, content, and ranges. - * @param content_only - * Set to TRUE to only print the value (Content) when printing. - * Set to FALSE to print the entire variable when printing. */ #ifndef _di_iki_read_print_ - extern void iki_read_print(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_array_length_t index, const bool content_only) F_attribute_visibility_internal_d; + extern void iki_read_print(fll_program_data_t * const main, iki_read_setting_t * const setting, const f_array_length_t index) F_attribute_visibility_internal_d; #endif // _di_iki_read_print_ /** diff --git a/level_3/iki_read/c/private-read.c b/level_3/iki_read/c/private-read.c index 56b6c69..1c83989 100644 --- a/level_3/iki_read/c/private-read.c +++ b/level_3/iki_read/c/private-read.c @@ -10,10 +10,12 @@ extern "C" { #ifndef _di_iki_read_identify_alteration_ void iki_read_identify_alteration(iki_read_setting_t * const setting) { - register f_array_length_t i = 0; + if (!(setting->replace.used || setting->wrap.used)) return; + + f_array_length_t i = 0; if (setting->flag & (iki_read_main_flag_content_e | iki_read_main_flag_literal_e)) { - register f_array_length_t j = 0; + f_array_length_t j = 0; for (i = 0; i < setting->data.vocabulary.used; ++i) { @@ -178,6 +180,9 @@ extern "C" { f_array_length_t replaces[setting->data.vocabulary.used]; f_array_length_t wraps[setting->data.vocabulary.used]; + memset(replaces, 0, sizeof(f_array_length_t) * setting->data.vocabulary.used); + memset(wraps, 0, sizeof(f_array_length_t) * setting->data.vocabulary.used); + setting->map_replaces = replaces; setting->map_wraps = wraps; @@ -211,7 +216,7 @@ extern "C" { if (matches++ > setting->at) break; } - iki_read_print(main, setting, i, setting->flag & iki_read_main_flag_content_e); + iki_read_print(main, setting, i); f_print_dynamic_raw(f_string_eol_s, main->output.to); } @@ -233,7 +238,7 @@ extern "C" { if (setting->at < setting->data.variable.used) { flockfile(main->output.to.stream); - iki_read_print(main, setting, setting->at, setting->flag & iki_read_main_flag_content_e); + iki_read_print(main, setting, setting->at); f_print_dynamic_raw(f_string_eol_s, main->output.to); @@ -250,7 +255,7 @@ extern "C" { for (i = 0; i < setting->data.variable.used; ++i) { - iki_read_print(main, setting, i, setting->flag & iki_read_main_flag_content_e); + iki_read_print(main, setting, i); f_print_dynamic_raw(f_string_eol_s, main->output.to); } // for @@ -300,6 +305,15 @@ extern "C" { return; } + f_array_length_t replaces[setting->data.vocabulary.used]; + f_array_length_t wraps[setting->data.vocabulary.used]; + + memset(replaces, 0, sizeof(f_array_length_t) * setting->data.vocabulary.used); + memset(wraps, 0, sizeof(f_array_length_t) * setting->data.vocabulary.used); + + setting->map_replaces = replaces; + setting->map_wraps = wraps; + iki_read_identify_alteration(setting); { @@ -326,18 +340,17 @@ extern "C" { i = setting->data.variable.array[j].start; } - k = 0; if (setting->names.used) { - for (; k < setting->names.used; ++k) { + for (k = 0; k < setting->names.used; ++k) { if (fl_string_dynamic_partial_compare_string(setting->names.array[k].string, setting->buffer, setting->names.array[k].used, setting->data.vocabulary.array[j]) == F_equal_to) break; } // for if (k < setting->names.used) { - iki_read_print(main, setting, j, F_true); + iki_read_print(main, setting, j); } } else { - iki_read_print(main, setting, j, F_true); + iki_read_print(main, setting, j); } i = setting->data.variable.array[j].stop + 1;