]> Kevux Git Server - fll/commitdiff
Bugfix: Fix handling of --line when not using --whole.
authorKevin Day <Kevin@kevux.org>
Tue, 10 Dec 2024 03:34:41 +0000 (21:34 -0600)
committerKevin Day <Kevin@kevux.org>
Tue, 10 Dec 2024 03:42:09 +0000 (21:42 -0600)
The function `iki_read_process_at()` is incorrectly named and should instead be called `iki_read_process_line()`.

The `--object`, `--content`, and `--literal` parameters with `--line` should print the line number for the output of those commands raather than the output of the file.
The printing of the line from the original file is very confusing and so I am considering this a bug.

Update the print help message.

level_3/iki_read/c/iki_read.c
level_3/iki_read/c/private-read.c
level_3/iki_read/c/private-read.h

index 830bb9c1ecd326a49e27028321f3d4944a0c8c48..01ca2049effd2aeab7d0f996135e242eeec62789 100644 (file)
@@ -57,7 +57,7 @@ extern "C" {
     f_print_dynamic_raw(f_string_eol_s, file.stream);
 
     fll_program_print_help_option(file, context, iki_read_short_content_s, iki_read_long_content_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Print the Content (default).");
-    fll_program_print_help_option(file, context, iki_read_short_line_s, iki_read_long_line_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "   Print only the Variables at the given line within the file.");
+    fll_program_print_help_option(file, context, iki_read_short_line_s, iki_read_long_line_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "   Print only the given line of the output.");
     fll_program_print_help_option(file, context, iki_read_short_literal_s, iki_read_long_literal_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Print the entire Variable (Vocabulary, Content, and syntax).");
     fll_program_print_help_option(file, context, iki_read_short_object_s, iki_read_long_object_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Print the Vocabulary (aka: Object).");
     fll_program_print_help_option(file, context, iki_read_short_total_s, iki_read_long_total_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "  Print the total number of Variables.");
index 30c8d5321387084aa19d4f0e1877405415093089..8c063a45f481c6c5e6fabd0747c4b89a9b4523ec 100644 (file)
@@ -7,8 +7,8 @@
 extern "C" {
 #endif
 
-#ifndef _di_iki_read_process_at_
-  f_status_t iki_read_process_at(iki_read_data_t * const data, f_string_range_t *range) {
+#ifndef _di_iki_read_process_line_
+  f_status_t iki_read_process_line(iki_read_data_t * const data, f_string_range_t *range) {
 
     if (data->main->parameters.array[iki_read_parameter_line_e].result != f_console_result_additional_e) {
       return F_false;
@@ -33,7 +33,7 @@ extern "C" {
 
     return F_data_not;
   }
-#endif // _di_iki_read_process_at_
+#endif // _di_iki_read_process_line_
 
 #ifndef _di_iki_read_process_buffer_
   f_status_t iki_read_process_buffer(iki_read_data_t * const data) {
@@ -41,53 +41,47 @@ extern "C" {
     f_status_t status = F_none;
     f_iki_data_t iki_data = f_iki_data_t_initialize;
 
-    if (data->main->parameters.array[iki_read_parameter_whole_e].result == f_console_result_found_e && data->main->parameters.array[iki_read_parameter_total_e].result == f_console_result_none_e) {
-      f_string_range_t buffer_range = macro_f_string_range_t_initialize2(data->buffer.used);
+    if (data->main->parameters.array[iki_read_parameter_whole_e].result == f_console_result_found_e) {
+      if (data->main->parameters.array[iki_read_parameter_total_e].result == f_console_result_none_e) {
+        f_string_range_t buffer_range = macro_f_string_range_t_initialize2(data->buffer.used);
 
-      status = iki_read_process_at(data, &buffer_range);
+        status = iki_read_process_line(data, &buffer_range);
 
-      if (status == F_true) {
-        if (buffer_range.start > data->buffer.used) return F_data_not;
-      }
-      else if (status == F_data_not) {
-        return F_data_not;
-      }
+        if (status == F_true) {
+          if (buffer_range.start > data->buffer.used) return F_data_not;
+        }
+        else if (status == F_data_not) {
+          return F_data_not;
+        }
 
-      if (data->mode == iki_read_mode_content_e) {
-        status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.content);
-      }
-      else if (data->mode == iki_read_mode_literal_e) {
-        status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.variable);
-      }
-      else if (data->mode == iki_read_mode_object_e) {
-        status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.vocabulary);
-      }
-    }
-    else if (data->main->parameters.array[iki_read_parameter_total_e].result == f_console_result_found_e && data->main->parameters.array[iki_read_parameter_whole_e].result == f_console_result_found_e) {
-      if (data->main->parameters.array[iki_read_parameter_line_e].result == f_console_result_additional_e) {
-        status = iki_read_process_buffer_total(data, &iki_data);
+        if (data->mode == iki_read_mode_content_e) {
+          status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.content);
+        }
+        else if (data->mode == iki_read_mode_literal_e) {
+          status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.variable);
+        }
+        else if (data->mode == iki_read_mode_object_e) {
+          status = iki_read_process_buffer_ranges_whole(data, buffer_range, &iki_data, &iki_data.vocabulary);
+        }
       }
-      else {
-        f_number_unsigned_t total = 0;
+      else if (data->main->parameters.array[iki_read_parameter_total_e].result == f_console_result_found_e) {
+        if (data->main->parameters.array[iki_read_parameter_line_e].result == f_console_result_additional_e) {
+          status = iki_read_process_buffer_total(data, &iki_data);
+        }
+        else {
+          f_number_unsigned_t total = 0;
 
-        for (f_number_unsigned_t i = 0; i < data->buffer.used; ++i) {
-          if (data->buffer.string[i] == f_string_eol_s.string[0]) ++total;
-        } // for
+          for (f_number_unsigned_t i = 0; i < data->buffer.used; ++i) {
+            if (data->buffer.string[i] == f_string_eol_s.string[0]) ++total;
+          } // for
 
-        fll_print_format("%ul%r", data->main->output.to.stream, total, f_string_eol_s);
+          fll_print_format("%ul%r", data->main->output.to.stream, total, f_string_eol_s);
+        }
       }
     }
     else {
       f_string_range_t buffer_range = macro_f_string_range_t_initialize2(data->buffer.used);
 
-      status = iki_read_process_at(data, &buffer_range);
-
-      if ((status == F_true && buffer_range.start > data->buffer.used) || status == F_data_not) {
-        f_iki_data_delete(&iki_data);
-
-        return F_data_not;
-      }
-
       if (data->mode == iki_read_mode_content_e) {
         status = iki_read_process_buffer_ranges(data, &buffer_range, &iki_data, &iki_data.content);
       }
@@ -230,6 +224,12 @@ extern "C" {
 
         for (j = 0; j < iki_data->vocabulary.used; ++j) {
 
+          // The variable parts, when not using --wrap, each is represented on its own line.
+          if (data->main->parameters.array[iki_read_parameter_line_e].result == f_console_result_additional_e) {
+            if (j < data->line) continue;
+            if (j > data->line) break;
+          }
+
           status = fl_string_dynamic_partial_compare(name, data->buffer, *buffer_range, iki_data->vocabulary.array[j]);
 
           if (status == F_equal_to) {
@@ -281,8 +281,12 @@ extern "C" {
       }
     }
     else if (ranges->used) {
+      f_array_length_t line = 0;
+
       if (data->main->parameters.array[iki_read_parameter_at_e].result == f_console_result_additional_e) {
-        if (data->at < ranges->used) {
+
+        // The --line is processed after the --at and so any value greater than 0 should produce no results.
+        if (data->at < ranges->used && (data->main->parameters.array[iki_read_parameter_line_e].result != f_console_result_additional_e || data->line == 0)) {
           flockfile(data->main->output.to.stream);
 
           if (replacements[data->at].replace.used || wraps[data->at].replace.used || wraps[data->at].with.used || substitutionss[data->at].used || reassignments[data->at].used) {
@@ -307,6 +311,12 @@ extern "C" {
 
         for (i = 0; i < ranges->used; ++i) {
 
+          // The variable parts, when not using --wrap, each is represented on its own line.
+          if (data->main->parameters.array[iki_read_parameter_line_e].result == f_console_result_additional_e) {
+            if (i < data->line) continue;
+            if (i > data->line) break;
+          }
+
           if (replacements[i].replace.used || wraps[i].replace.used || wraps[i].with.used || substitutionss[i].used || reassignments[i].used) {
             iki_read_substitutions_print(data, *iki_data, *ranges, replacements[i], wraps[i], substitutionss[i], reassignments[i], i, content_only);
           }
@@ -319,7 +329,9 @@ extern "C" {
 
         funlockfile(data->main->output.to.stream);
 
-        status = F_none;
+        status = data->main->parameters.array[iki_read_parameter_line_e].result == f_console_result_additional_e && data->line >= ranges->used
+          ? F_data_not
+          : F_none;
       }
     }
     else {
@@ -603,7 +615,7 @@ extern "C" {
     f_status_t status = F_none;
     f_string_range_t range = macro_f_string_range_t_initialize2(data->buffer.used);
 
-    status = iki_read_process_at(data, &range);
+    status = iki_read_process_line(data, &range);
 
     if (status == F_true) {
       if (range.start > data->buffer.used) {
index a92b99a329891855566920c087ce070e2ecd8e98..502beb716d63f1e856c114f8f1526cb05bcc8a89 100644 (file)
@@ -13,15 +13,15 @@ extern "C" {
 #endif
 
 /**
- * Determine the range based on the --at parameter.
+ * Determine the range based on the --line parameter.
  *
- * If the --at parameter is not specified in the console arguments, then range is untouched.
- * The range.start will be greater than main->buffer.used if the --at range is not found before buffer end is reached.
+ * If the --line parameter is not specified in the console arguments, then range is untouched.
+ * The range.start will be greater than main->buffer.used if the --line range is not found before buffer end is reached.
  *
  * @param data
  *   The program data.
  * @param range
- *   The range value to represent the --at values.
+ *   The range value to represent the --line values.
  *
  * @return
  *   F_true is returned if the range is processed.
@@ -30,9 +30,9 @@ extern "C" {
  *
  *   Status codes (with error bit) are returned on any problem.
  */
-#ifndef _di_iki_read_process_at_
-  extern f_status_t iki_read_process_at(iki_read_data_t * const data, f_string_range_t *range) F_attribute_visibility_internal_d;
-#endif // _di_iki_read_process_at_
+#ifndef _di_iki_read_process_line_
+  extern f_status_t iki_read_process_line(iki_read_data_t * const data, f_string_range_t *range) F_attribute_visibility_internal_d;
+#endif // _di_iki_read_process_line_
 
 /**
  * Process a given buffer.