]> Kevux Git Server - fll/commitdiff
Progress: Continue work on refactoring fss_*_read into fss_read.
authorKevin Day <kevin@kevux.org>
Fri, 12 May 2023 03:09:58 +0000 (22:09 -0500)
committerKevin Day <kevin@kevux.org>
Fri, 12 May 2023 03:09:58 +0000 (22:09 -0500)
16 files changed:
level_3/fss_read/c/basic/main.c
level_3/fss_read/c/basic_list/main.c
level_3/fss_read/c/embedded_list/main.c
level_3/fss_read/c/extended/main.c
level_3/fss_read/c/extended_list/main.c
level_3/fss_read/c/main/common.c
level_3/fss_read/c/main/common.h
level_3/fss_read/c/main/common/print.c
level_3/fss_read/c/main/common/print.h
level_3/fss_read/c/main/common/type.c
level_3/fss_read/c/main/common/type.h
level_3/fss_read/c/main/fss_read.c
level_3/fss_read/c/main/fss_read.h
level_3/fss_read/c/payload/fss_read.c
level_3/fss_read/c/payload/fss_read.h
level_3/fss_read/c/payload/main.c

index b740c363c618234eeae798c1a7221b67d199adb9..1211f498513e01619e499ceebee3a00f7c217400 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_basic_standard_s;
-  data.setting.process_content = &fss_read_basic_process_content;
   data.setting.process_help = &fss_read_basic_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = &fss_read_basic_process_object;
   data.setting.process_pipe = &fss_read_process_pipe;
-  data.setting.process_set = &fss_read_process_set;
 
   f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize;
   data.program.parameters.array = parameters;
index cc3c03183b036a3d3ee04c864ee8aae78470c587..8b15c770465d43dd6a49a74b1a6186fc9eb6678f 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_basic_list_standard_s;
-  data.setting.process_content = &fss_read_basic_list_process_content;
   data.setting.process_help = &fss_read_basic_list_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = &fss_read_basic_list_process_object;
   data.setting.process_pipe = &fss_read_process_pipe;
-  data.setting.process_set = &fss_read_process_set;
 
   f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize;
   data.program.parameters.array = parameters;
index 499eb8b154dad4fa96b4dfdfa6977b07387d5506..4eed5ed4c1e3bea02d42bbccb25c9e09569f2533 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_embedded_list_standard_s;
-  data.setting.process_content = &fss_read_embedded_list_process_content;
   data.setting.process_help = &fss_read_embedded_list_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = &fss_read_embedded_list_process_object;
   data.setting.process_pipe = &fss_read_process_pipe;
-  data.setting.process_set = &fss_read_process_set;
   data.setting.flag |= fss_read_main_flag_ignore_e;
   data.setting.flag |= fss_read_main_flag_content_multiple_e;
 
index f0a733ffbe7c3249d76681694c48b47e321fe306..0d7a900018998e275b186d37edf2282c4e5a7c98 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_extended_standard_s;
-  data.setting.process_content = &fss_read_extended_process_content;
   data.setting.process_help = &fss_read_extended_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = &fss_read_extended_process_object;
   data.setting.process_pipe = &fss_read_process_pipe;
-  data.setting.process_set = &fss_read_process_set;
   data.setting.flag |= fss_read_main_flag_content_multiple_e;
 
   f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize;
index 87cd830389adaef005bc638de21d151e7f251547..3974995541231621e7d01240730330252223ab91 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_extended_list_standard_s;
-  data.setting.process_content = &fss_read_extended_list_process_content;
   data.setting.process_help = &fss_read_extended_list_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = &fss_read_extended_list_process_object;
   data.setting.process_pipe = &fss_read_process_pipe;
-  data.setting.process_set = &fss_read_process_set;
   data.setting.flag |= fss_read_main_flag_ignore_e;
 
   f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize;
index db21a159920117255f21f765e906ddb5549e7d5e..8f9ddccf1042e47cd7f5e65a3cdec01ec757a12a 100644 (file)
@@ -241,17 +241,7 @@ extern "C" {
 
       for (i = 0; i < main->parameters.array[fss_read_parameter_delimit_e].values.used; ++i) {
 
-        if (!((++main->signal_check) % fss_read_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            fll_program_print_signal_received(main->warning, main->signal_received);
-
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            return;
-          }
-
-          main->signal_check = 0;
-        }
+        if (fss_read_signal_check(main)) return;
 
         index = main->parameters.array[fss_read_parameter_delimit_e].values.array[i];
         length = main->program.parameters.arguments.array[index].used;
@@ -410,6 +400,153 @@ extern "C" {
     if (main->program.parameters.array[fss_read_parameter_trim_e].result & f_console_result_found_e) {
       main->setting.flag |= fss_read_main_flag_trim_e;
     }
+
+    f_file_t file = f_file_t_initialize;
+
+    if (main->pipe & fll_program_data_pipe_input_e) {
+      file.id = F_type_descriptor_input_d;
+      file.stream = F_type_input_d;
+
+      main->setting.files.array[0].range.start = 0;
+
+      main->setting.state.status = f_file_stream_read(file, &main->setting.buffer);
+
+      if (F_status_is_error(main->setting.state.status)) {
+        if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+          fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+        }
+
+        fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_read), fll_error_file_flag_fallback_e, f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e);
+
+        return;
+      }
+
+      if (main->setting.buffer.used) {
+        main->setting.files.array[0].range.stop = main->setting.buffer.used - 1;
+
+        if (main->setting.process_last_line) {
+          main->setting.process_last_line((void *) &main);
+          if (F_status_is_error(main->setting.state.status)) return;
+        }
+      }
+      else {
+        main->setting.files.array[0].range.start = 1;
+      }
+    }
+
+    if (main->program.parameters.remaining.used) {
+      f_array_length_t index = 0;
+      off_t size_block = 0;
+      off_t size_file = 0;
+      off_t size_read = 0;
+
+      for (i = 0; i < main->parameters.remaining.used; ++i) {
+
+        if (fss_read_signal_check(main)) return;
+
+        index = main->parameters.remaining.array[i];
+
+        main->setting.files.array[main->setting.files.used].name = main->program.parameters.arguments.array[index];
+        main->setting.files.array[main->setting.files.used].range.start = main->setting.buffer.used;
+
+        file.id = -1;
+        file.stream = 0;
+
+        main->setting.state.status = f_file_stream_open(main->setting.files.array[main->setting.files.used].name, f_string_empty_s, &file);
+
+        if (F_status_is_error(main->setting.state.status)) {
+          if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+            fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+          }
+
+          fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_open), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_open_s, fll_error_file_type_file_e);
+
+          break;
+        }
+
+        size_file = 0;
+
+        main->setting.state.status = f_file_size_by_id(file.id, &size_file);
+
+        if (F_status_is_error(main->setting.state.status)) {
+          if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+            fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+          }
+
+          fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_size_by_id), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_read_s, fll_error_file_type_file_e);
+
+          break;
+        }
+
+        if (size_file) {
+
+          // Enforce a max block read size to allow for interrupts to be processed between blocks.
+          if (size_file > fss_basic_list_read_block_max) {
+            file.size_read = fss_basic_list_read_block_read_large;
+            size_block = fss_basic_list_read_block_max;
+
+            // Pre-allocate entire file buffer plus space for the terminating NULL.
+            f_string_dynamic_increase_by(size_file + (size_block - (size_file % size_block)) + 1, &main->setting.buffer);
+          }
+          else {
+            file.size_read = fss_basic_list_read_block_read_small;
+            size_block = size_file;
+
+            // Pre-allocate entire file buffer plus space for the terminating NULL.
+            f_string_dynamic_increase_by(size_file + 1, &main->setting.buffer);
+          }
+
+          if (F_status_is_error(main->setting.state.status)) {
+            if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+              fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+            }
+
+            fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_string_dynamic_increase_by), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_process_s, fll_error_file_type_file_e);
+
+            break;
+          }
+
+          for (size_read = 0; size_read < size_file; size_read += size_block) {
+
+            if (size_file > fss_basic_list_read_block_max && fss_read_signal_check(main)) break;
+
+            main->setting.state.status = f_file_stream_read_until(file, size_block, &main->setting.buffer);
+            if (F_status_is_error(main->setting.state.status)) break;
+          } // for
+
+          if (F_status_is_error(main->setting.state.status)) {
+            if (F_status_set_fine(status) != F_interrupt) {
+              if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+                fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+              }
+
+              fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_file_stream_read_until), fll_error_file_flag_fallback_e, main->program.parameters.arguments.array[index], f_file_operation_read_s, fll_error_file_type_file_e);
+            }
+
+            break;
+          }
+
+          f_file_stream_flush(file);
+          f_file_stream_close(&file);
+
+          if (main->setting.buffer.used > main->setting.files.array[main->setting.files.used].range.start) {
+            main->setting.files.array[main->setting.files.used++].range.stop = main->setting.buffer.used - 1;
+
+            if (main->setting.process_last_line) {
+              main->setting.process_last_line((void *) &main);
+              if (F_status_is_error(main->setting.state.status)) break;
+            }
+          }
+        }
+        else {
+          main->setting.files.array[main->setting.files.used].range.start = 1;
+          main->setting.files.array[main->setting.files.used].range.stop = 1;
+        }
+      } // for
+
+      f_file_stream_flush(file);
+      f_file_stream_close(&file);
+    }
   }
 #endif // _di_fss_read_setting_load_
 
@@ -446,17 +583,7 @@ extern "C" {
 
     for (i = 0; i < data->depths.used; ++i) {
 
-      if (!((++main->signal_check) % fss_read_signal_check_d)) {
-        if (fll_program_standard_signal_received(&main->program)) {
-          fll_program_print_signal_received(main->warning, main->signal_received);
-
-          main->setting.state.status = F_status_set_error(F_interrupt);
-
-          return;
-        }
-
-        main->signal_check = 0;
-      }
+      if (fss_read_signal_check(main)) return;
 
       data->depths.array[i].depth = 0;
       data->depths.array[i].index_at = 0;
@@ -551,17 +678,7 @@ extern "C" {
 
       for (j = i + 1; j < data->depths.used; ++j) {
 
-        if (!((++main->signal_check) % fss_read_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            fll_program_print_signal_received(main->warning, main->signal_received);
-
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            return;
-          }
-
-          main->signal_check = 0;
-        }
+        if (fss_read_signal_check(main)) return;
 
         if (data->depths.array[i].depth == data->depths.array[j].depth) {
           main->setting.state.status = F_status_set_error(F_parameter);
index 0b8d077dafaaa4f30305d54a1cc2fbdde5815269..ca7f0aecb5f230b5ab4a6aebdfd0d62cd035c47a 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
  *     Errors (with error bit) from: fll_program_parameter_process_verbosity().
  *
  *     Errors (with error bit) from: fss_read_setting_load_depth(). @todo fss_read_depths_resize() is to be relocated to "callback".
+ *     Errors (with error bit) from: fss_read_signal_check()
  * @param callback
  *   (optional) Designate a function to call after performing the initial processing, but before printing help.
  *   If the function returns F_done, then this function immediately returns, resetting status to F_none.
@@ -56,6 +57,7 @@ extern "C" {
  * @see fll_program_parameter_process_verbosity()
  *
  * @see fss_read_setting_load_depth() @todo fss_read_depths_resize() is to be relocated to "callback".
+ * @see fss_read_signal_check()
  */
 #ifndef _di_fss_read_setting_load_
   extern void fss_read_setting_load(const f_console_arguments_t arguments, fss_read_main_t * const main, void (*callback)(const f_console_arguments_t arguments, fss_read_main_t * const main));
index d611b9a2ec03f94d2098aa20e60cb6bd09125756..4551b8adbf5157455779e0a22cb1ee41b231e5da 100644 (file)
@@ -8,10 +8,14 @@ extern "C" {
   const f_string_t fss_read_f_a[] = {
     "f_console_parameter_process",
     "f_file_read_block",
+    "f_file_size_by_id",
     "f_file_stream_open",
+    "f_file_stream_read",
+    "f_file_stream_read_until",
     "f_fss_is_space",
     "f_rip_dynamic",
     "f_string_dynamic_append",
+    "f_string_dynamic_append_assure",
     "f_string_dynamic_append_nulless",
     "f_string_dynamic_increase_by",
     "f_string_dynamics_increase",
index 0d9788051c4ed5a7ea31a941a013055db1fe26db..a8b9573a60a1a5f26c14b9b7d4470f15cbf1b1e4 100644 (file)
@@ -41,10 +41,14 @@ extern "C" {
   enum {
     fss_read_f_f_console_parameter_process_e,
     fss_read_f_f_file_read_block_e,
+    fss_read_f_f_file_size_by_id_e,
     fss_read_f_f_file_stream_open_e,
+    fss_read_f_f_file_stream_read_e,
+    fss_read_f_f_file_stream_read_until_e,
     fss_read_f_f_fss_is_space_e,
     fss_read_f_f_rip_dynamic_e,
     fss_read_f_f_string_dynamic_append_e,
+    fss_read_f_f_string_dynamic_append_assure_e,
     fss_read_f_f_string_dynamic_append_nulless_e,
     fss_read_f_f_string_dynamic_increase_by_e,
     fss_read_f_f_string_dynamics_increase_e,
index 50abdaf4b4789bf7771d7ccd81d24bcbf21dbe62..b414df2fb55f2a3b94a826f4716df3c3a359905e 100644 (file)
@@ -4,6 +4,15 @@
 extern "C" {
 #endif
 
+#ifndef _di_fss_read_depth_delete_
+  void fss_read_depth_delete(fss_read_depth_t * const depth) {
+
+    if (!depth) return;
+
+    f_string_dynamic_resize(0, &depth->value_name);
+  }
+#endif // _di_fss_read_depth_delete_
+
 #ifndef _di_fss_read_main_data_delete_
   void fss_read_main_delete(fss_read_main_t * const main) {
 
index 5f3af403b41287e0d6cabd3e51f29c1f87d568e2..dc96f4f725addd443e3978976c5d5b5cd06cfd81 100644 (file)
@@ -17,6 +17,65 @@ extern "C" {
 #endif
 
 /**
+ * A structure of parameters applied at some depth.
+ *
+ * depth: The depth number in which this is to be processed at.
+ *
+ * index_at:   Position of the "--at" parameter value in the argv list, when 0 there is no parameter.
+ * index_name: Position of the "--name" parameter value in the argv list, when 0 there is no parameter.
+ *
+ * value_at:   The value of the "--at" parameter, already processed and ready to use, only when index_at > 0.
+ * value_name: The value of the "--name" parameter, already processed and ready to use, only when index_name > 0.
+ */
+#ifndef _di_fss_read_depth_t_
+  typedef struct {
+    f_array_length_t depth;
+
+    f_array_length_t index_at;
+    f_array_length_t index_name;
+
+    f_number_unsigned_t value_at;
+    f_string_dynamic_t  value_name;
+  } fss_read_depth_t;
+
+  #define fss_read_depth_t_initialize \
+    { \
+      0, \
+      0, \
+      0, \
+      0, \
+      f_string_dynamic_t_initialize, \
+    }
+
+  #define macro_fss_read_depth_t_clear(structure) \
+    structure.depth = 0; \
+    structure.index_at = 0; \
+    structure.index_name = 0; \
+    structure.value_at = 0; \
+    macro_f_string_dynamic_t_clear(structure.value_name)
+#endif // _di_fss_read_depth_t_
+
+/**
+ * An array of depth parameters.
+ *
+ * array: The array of depths.
+ * size:  Total amount of allocated space.
+ * used:  Total number of allocated spaces used.
+ */
+#ifndef _di_fss_read_depths_t_
+  typedef struct {
+    fss_read_depth_t *array;
+
+    f_array_length_t size;
+    f_array_length_t used;
+  } fss_read_depths_t;
+
+  #define fss_read_depths_t_initialize { 0, 0, 0 }
+
+  #define macro_fss_read_depths_t_clear(depths) macro_f_memory_structure_clear(depths)
+#endif // _di_fss_read_depths_t_
+
+/**
  * A structure for designating where within the buffer a particular file exists, using a statically allocated array.
  *
  * name:  The name of the file representing the range.
@@ -89,12 +148,10 @@ extern "C" {
  * delimits_content: The positions within the buffer representing Content character delimits.
  * comments:         The positions within the buffer representing comments.
  *
- * process_content: Process a single Content.
- * process_help:    Process help (generally printing help).
- * process_normal:  Process normally (data from parameters and files).
- * process_object:  Process a single Object.
- * process_pipe:    Process using the data from input pipe.
- * process_set:     Process a set of Object and one or more Content.
+ * process_help:      Process help (generally printing help).
+ * process_last_line: Process printing last line if necessary when loading in a file (or pipe).
+ * process_normal:    Process normally (data from parameters and files).
+ * process_pipe:      Process using the data from input pipe.
  */
 #ifndef _di_fss_read_setting_t_
   typedef struct {
@@ -122,12 +179,10 @@ extern "C" {
     f_fss_delimits_t delimits_content;
     f_fss_comments_t comments;
 
-    void (*process_content)(void * const main, const bool last);
     void (*process_help)(void * const main);
+    void (*process_last_line)(void * const main);
     void (*process_normal)(void * const main);
-    void (*process_object)(void * const main);
     void (*process_pipe)(void * const main);
-    void (*process_set)(void * const main);
   } fss_read_setting_t;
 
   #define fss_read_setting_t_initialize \
@@ -153,8 +208,6 @@ extern "C" {
       0, \
       0, \
       0, \
-      0, \
-      0, \
     }
 #endif // _di_fss_read_setting_t_
 
@@ -178,6 +231,16 @@ extern "C" {
 #endif // _di_fss_read_main_t_
 
 /**
+ * Deallocate the read depth.
+ *
+ * @param depth
+ *   The depth to deallocate.
+ */
+#ifndef _di_fss_read_depth_delete_
+  extern void fss_read_depth_delete(fss_read_depth_t * const depth);
+#endif // _di_fss_read_depth_delete_
+
+/**
  * Deallocate main program data.
  *
  * @param setting_make
index 930dad36d0f6014825fb08cfc359ff30b1df8075..2852496739e0c90fe60ab245b6215bfc8acb5987 100644 (file)
@@ -70,11 +70,32 @@ extern "C" {
   }
 #endif // _di_fss_read_main_
 
+#ifndef _di_fss_read_process_last_line_
+  void fss_read_process_last_line(void * const void_main) {
+
+    if (!void_main) return;
+
+    fss_read_main_t * const main = (fss_read_main_t *) void_main;
+
+    status = f_string_dynamic_append_assure(f_string_eol_s, &main->setting.buffer);
+
+    if (F_status_is_error(status)) {
+      if ((main->setting.flag & fss_read_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+        fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+      }
+
+      fll_error_file_print(&main->error, F_status_set_fine(main->setting.state.status), macro_fss_read_f(f_string_dynamic_append_assure), fll_error_file_flag_fallback_e, f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e);
+    }
+  }
+#endif // _di_fss_read_process_last_line_
+
 #ifndef _di_fss_read_process_normal_
   void fss_read_process_normal(void * const void_main) {
 
     if (!void_main) return;
 
+    // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this.
+
     fss_read_process_normal_data(
       (fss_read_main_t *) void_main,
       (((fss_read_main_t *) void_main)->setting.flag & fss_read_main_flag_object_e)
@@ -91,6 +112,8 @@ extern "C" {
 
     fss_read_main_t * const main = (fss_read_main_t *) void_main;
 
+    // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this.
+
     main->setting.ignores = 0;
     main->setting.object = 0;
     main->setting.content = 0;
@@ -99,16 +122,7 @@ extern "C" {
     if (length) {
       for (f_array_length_t i = 0; i < length; ++i) {
 
-        // @todo replace all signal checks with forked main process that independently checks and assigns main->program.signal_received.
-        if (!((++main->program.signal_check) % fss_read_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            return;
-          }
-
-          main->program.signal_check = 0;
-        }
+        if (fss_read_signal_check(main)) return;
 
         if (main->setting.objects.used) {
           main->setting.object = &main->setting.objects.array[i];
@@ -147,6 +161,8 @@ extern "C" {
 
     if (!main->setting.process_set) return;
 
+    // @todo this is entirely copied from fss_write and may not represent how fss_read needs to handle this.
+
     if (main->program.message.verbosity > f_console_verbosity_error_e) {
       fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
     }
@@ -217,17 +233,7 @@ extern "C" {
 
     for (;;) {
 
-      if (!((++main->program.signal_check) % fss_read_signal_check_d)) {
-        if (fll_program_standard_signal_received(&main->program)) {
-          fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
-          main->setting.state.status = F_status_set_error(F_interrupt);
-
-          break;
-        }
-
-        main->program.signal_check = 0;
-      }
+      if (fss_read_signal_check(main)) break;
 
       if (range.start > range.stop) {
         if (status_pipe == F_none_eof) break;
@@ -453,70 +459,6 @@ extern "C" {
   }
 #endif // _di_fss_read_process_pipe_
 
-#ifndef _di_fss_read_process_set_
-  void fss_read_process_set(void * const void_main) {
-
-    if (!void_main) return;
-
-    fss_read_main_t * const main = (fss_read_main_t *) void_main;
-
-    main->setting.buffer.used = 0;
-
-    if ((!(main->setting.flag & fss_read_main_flag_partial_e) || (main->setting.flag & fss_read_main_flag_partial_e) && (main->setting.flag & fss_read_main_flag_object_e)) && main->setting.object || (main->setting.flag & fss_read_main_flag_object_open_e)) {
-
-      if (main->setting.object) {
-        if (main->setting.object->used) {
-          main->setting.range.start = 0;
-          main->setting.range.stop = main->setting.object->used - 1;
-        }
-        else {
-          main->setting.range.start = 1;
-          main->setting.range.stop = 0;
-        }
-      }
-
-      if (main->setting.process_object) {
-        main->setting.process_object(void_main);
-        if (F_status_is_error(main->setting.state.status)) return;
-      }
-    }
-
-    if ((!(main->setting.flag & fss_read_main_flag_partial_e) || (main->setting.flag & fss_read_main_flag_partial_e) && (main->setting.flag & fss_read_main_flag_content_e)) && main->setting.contents || (main->setting.flag & (fss_read_main_flag_content_next_e | fss_read_main_flag_content_end_e))) {
-
-      if (main->setting.process_content) {
-        if (main->setting.contents && main->setting.contents->used) {
-          for (f_array_length_t i = 0; i < main->setting.contents->used; ++i) {
-
-            if (main->setting.contents->array[i].used) {
-              main->setting.range.start = 0;
-              main->setting.range.stop = main->setting.contents->array[i].used - 1;
-            }
-            else {
-              main->setting.range.start = 1;
-              main->setting.range.stop = 0;
-            }
-
-            main->setting.content = &main->setting.contents->array[i];
-
-            main->setting.process_content(void_main, i + 1 == main->setting.contents->used);
-            if (F_status_is_error(main->setting.state.status)) return;
-          } // for
-        }
-        else {
-          main->setting.content = 0;
-
-          main->setting.process_content(void_main, F_true);
-          if (F_status_is_error(main->setting.state.status)) return;
-        }
-      }
-    }
-
-    if (main->setting.buffer.used) {
-      fll_print_dynamic(main->setting.buffer, main->program.output.to);
-    }
-  }
-#endif // _di_fss_read_process_set_
-
 #ifdef __cplusplus
 } // extern "C"
 #endif
index 1b2f2448483f0e84a3ed0e288a36f40ca0cbb7db..5860ab72ae442cc00ff31f4c0b46eb8cff334bda 100644 (file)
@@ -92,7 +92,34 @@ extern "C" {
 #endif // _di_fss_read_main_
 
 /**
- * Process normally, writing to the output for the assigned FSS format.
+ * Process the current buffer, guarantee that a newline exists at the end of the buffer.
+ *
+ * Most standards are new line sensitive.
+ * When appending files to the buffer, if the file lacks a final new line then this could break the format for files appended thereafter.
+ *
+ * @param main
+ *   The program and settings data.
+ *   Must be of type fss_read_main_t.
+ *
+ *   This alters main.custom.setting.state.status:
+ *     F_none on success.
+ *
+ *     F_parameter (with error bit) if main is NULL or setting is NULL.
+ *
+ *     Errors (with error bit) from: f_string_dynamic_append_assure().
+ *
+ *     Errors (with error bit) from: fss_read_signal_check().
+ *
+ * @see f_string_dynamic_append_assure()
+ *
+ * @see fss_read_signal_check()
+ */
+#ifndef _di_fss_read_process_last_line_
+  extern void fss_read_process_last_line(void * const void_main);
+#endif // _di_fss_read_process_last_line_
+
+/**
+ * Process normally, reading from the input for the assigned FSS format.
  *
  * @param main
  *   The program and settings data.
@@ -101,7 +128,7 @@ extern "C" {
  *   This alters main.custom.setting.state.status:
  *     status from fss_read_process_normal_data().
  *
- *     Errors (with error bit) from fss_read_process_normal_data().
+ *     Errors (with error bit) from: fss_read_process_normal_data().
  *
  * @see fss_read_process_normal_data()
  */
@@ -110,7 +137,7 @@ extern "C" {
 #endif // _di_fss_read_process_normal_
 
 /**
- * Process the data normally, writing to the output for the assigned FSS format.
+ * Process the data normally, reading from the input for the assigned FSS format.
  *
  * @param main
  *   The program and settings data.
@@ -118,9 +145,12 @@ extern "C" {
  *
  *   This alters main.custom.setting.state.status:
  *     F_none on success.
- *     F_interrupt on (exit) signal received.
  *
  *     F_parameter (with error bit) if main is NULL or setting is NULL.
+ *
+ *     Errors (with error bit) from: fss_read_signal_check().
+ *
+ * @see fss_read_signal_check()
  */
 #ifndef _di_fss_read_process_normal_data_
   void fss_read_process_normal_data(void * const main, const f_array_length_t length);
@@ -137,9 +167,12 @@ extern "C" {
  *     F_none on success.
  *     F_data_not on success but pipe contained no relevant data.
  *     F_basic on success and the basic has been printed.
- *     F_interrupt on (exit) signal received.
  *
  *     F_parameter (with error bit) if main is NULL or setting is NULL.
+ *
+ *     Errors (with error bit) from: fss_read_signal_check().
+ *
+ * @see fss_read_signal_check()
  */
 #ifndef _di_fss_read_process_pipe_
   extern void fss_read_process_pipe(void * const main);
index bcd85d1ec788a289b61a40f2ab58d619018e1e9d..89685f08466d8260264b9ac99aa23fdb6623a56e 100644 (file)
@@ -86,17 +86,7 @@ extern "C" {
 
     for (;;) {
 
-      if (!((++main->program.signal_check) % fss_read_signal_check_d)) {
-        if (fll_program_standard_signal_received(&main->program)) {
-          fll_program_print_signal_received(&main->program.warning, main->program.signal_received);
-
-          main->setting.state.status = F_status_set_error(F_interrupt);
-
-          break;
-        }
-
-        main->program.signal_check = 0;
-      }
+      if (fss_read_signal_check(main)) return;
 
       if (range.start > range.stop) {
         if (status_pipe == F_none_eof) break;
index 31db3a3fd6a5f6edc172b63df4512e116474b0cc..6033db7b76eb9f97655485d64dfe1ffaa962571f 100644 (file)
@@ -91,6 +91,10 @@ extern "C" {
  *     F_interrupt on (exit) signal received.
  *
  *     F_parameter (with error bit) if main is NULL or setting is NULL.
+ *
+ *     Errors (with error bit) from: fss_read_signal_check().
+ *
+ * @see fss_read_signal_check()
  */
 #ifndef _di_fss_read_payload_process_pipe_
   extern void fss_read_payload_process_pipe(void * const main);
index ce4b54b3d86ef3dbc3a33d50c5cc0642422c8e6a..af54ccfebcb0343e92d3af2ada5bd091eca667f0 100644 (file)
@@ -18,12 +18,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   data.setting.state.custom = (void *) &data;
   data.setting.standard = fss_read_payload_standard_s;
-  data.setting.process_content = 0; // Not used by payload.
   data.setting.process_help = &fss_read_payload_process_help;
+  data.setting.process_last_line = &fss_read_process_last_line;
   data.setting.process_normal = &fss_read_process_normal;
-  data.setting.process_object = 0; // Not used by payload.
   data.setting.process_pipe = &fss_read_payload_process_pipe;
-  data.setting.process_set = &fss_read_payload_process_set;
 
   f_console_parameter_t parameters[] = fss_read_console_parameter_t_initialize;
   data.program.parameters.array = parameters;