From 4c6f5a2d22148db758cd656d6271e1e6e05e851e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 5 Sep 2021 15:49:06 -0500 Subject: [PATCH] Bugfix: iki_read never implemented --at. The --at parameter appears to have never been implemented or the implementation was somehow lost. It should be possible to have the --total with the --at, however odd it may be. The --whole, however, doesn't seem like it would be a good idea to allow supporting the --at paramter. Add the "--" characters when displaying the error via fll_error_parameter_integer_print(). --- level_3/iki_read/c/iki_read.c | 8 ++--- level_3/iki_read/c/private-iki_read.c | 60 ++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/level_3/iki_read/c/iki_read.c b/level_3/iki_read/c/iki_read.c index 30dc929..775b7e8 100644 --- a/level_3/iki_read/c/iki_read.c +++ b/level_3/iki_read/c/iki_read.c @@ -176,21 +176,21 @@ extern "C" { status = fl_conversion_string_to_number_unsigned(arguments.argv[index], range, &number); if (F_status_is_error(status)) { - fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, iki_read_long_at, arguments.argv[index]); + fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, f_console_symbol_long_enable iki_read_long_at, arguments.argv[index]); status = F_status_set_error(F_parameter); } main->at = number; - if (main->parameters[iki_read_parameter_total].result == f_console_result_found) { + if (main->parameters[iki_read_parameter_whole].result == f_console_result_found) { if (main->error.verbosity != f_console_verbosity_quiet) { flockfile(main->error.to.stream); fl_print_format("%c%[%sCannot specify the '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix, main->error.context); fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, iki_read_long_at, main->error.notable); fl_print_format("%[' parameter with the '%]", main->error.to.stream, main->error.context, main->error.context); - fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, iki_read_long_total, main->error.notable); + fl_print_format("%[%s%s%]", main->error.to.stream, main->error.notable, f_console_symbol_long_enable_s, iki_read_long_whole, main->error.notable); fl_print_format("%[' parameter.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); funlockfile(main->error.to.stream); @@ -222,7 +222,7 @@ extern "C" { status = fl_conversion_string_to_number_unsigned(arguments.argv[index], range, &number); if (F_status_is_error(status)) { - fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, iki_read_long_line, arguments.argv[index]); + fll_error_parameter_integer_print(main->error, F_status_set_fine(status), "fl_conversion_string_to_number_unsigned", F_true, f_console_symbol_long_enable iki_read_long_line, arguments.argv[index]); status = F_status_set_error(F_parameter); } diff --git a/level_3/iki_read/c/private-iki_read.c b/level_3/iki_read/c/private-iki_read.c index c7284d9..2c8925e 100644 --- a/level_3/iki_read/c/private-iki_read.c +++ b/level_3/iki_read/c/private-iki_read.c @@ -148,6 +148,7 @@ extern "C" { f_array_length_t index = 0; f_array_length_t i = 0; f_array_length_t j = 0; + f_array_length_t matches = 0; buffer_range->start = 0; for (; i < main->parameters[iki_read_parameter_name].values.used; ++i) { @@ -179,6 +180,10 @@ extern "C" { if (status == F_equal_to) { unmatched = F_false; + if (main->parameters[iki_read_parameter_at].result == f_console_result_additional) { + if (matches++ != main->at) continue; + } + if (substitutionss[j].used) { iki_read_substitutions_print(*main, *variable, *content, *ranges, substitutionss[j], j, content_only); } @@ -199,26 +204,46 @@ extern "C" { else status = F_none; } else if (ranges->used) { - f_array_length_t i = 0; - f_array_length_t j = 0; + if (main->parameters[iki_read_parameter_at].result == f_console_result_additional) { + if (main->at < ranges->used) { + flockfile(main->output.stream); - flockfile(main->output.stream); + if (substitutionss[main->at].used) { + iki_read_substitutions_print(*main, *variable, *content, *ranges, substitutionss[main->at], main->at, content_only); + } + else { + f_print_dynamic_partial(main->buffer, ranges->array[main->at], main->output.stream); + } + + f_print_character(f_string_eol_s[0], main->output.stream); - for (; i < ranges->used; ++i) { + funlockfile(main->output.stream); - if (substitutionss[i].used) { - iki_read_substitutions_print(*main, *variable, *content, *ranges, substitutionss[i], i, content_only); + status = F_none; } else { - f_print_dynamic_partial(main->buffer, ranges->array[i], main->output.stream); + status = F_data_not; } + } + else { + flockfile(main->output.stream); - f_print_character(f_string_eol_s[0], main->output.stream); - } // for + for (f_array_length_t i = 0; i < ranges->used; ++i) { - funlockfile(main->output.stream); + if (substitutionss[i].used) { + iki_read_substitutions_print(*main, *variable, *content, *ranges, substitutionss[i], i, content_only); + } + else { + f_print_dynamic_partial(main->buffer, ranges->array[i], main->output.stream); + } + + f_print_character(f_string_eol_s[0], main->output.stream); + } // for + + funlockfile(main->output.stream); - status = F_none; + status = F_none; + } } else { status = F_data_not; @@ -337,13 +362,14 @@ extern "C" { f_array_length_t i = buffer_range.start; f_array_length_t j = 0; f_array_length_t k = 0; + f_array_length_t stop = variable->used; range = buffer_range; name_range.start = 0; flockfile(main->output.stream); - while (i <= range.stop && j < variable->used) { + while (i <= range.stop && j < stop) { if (i < variable->array[j].start) { range.start = i; @@ -492,6 +518,16 @@ extern "C" { total = variable->used; } + // if that at position is within the actual total, then the total at the given position is 1, otherwise is 0. + if (main->parameters[iki_read_parameter_at].result == f_console_result_additional) { + if (main->at < total) { + total = 1; + } + else { + total = 0; + } + } + fll_print_format("%ul%c", main->output.stream, total, f_string_eol_s[0]); return F_none; -- 1.8.3.1