]> Kevux Git Server - fll/commitdiff
Feature: Add eki_write program.
authorKevin Day <Kevin@kevux.org>
Sat, 30 Nov 2024 12:58:15 +0000 (06:58 -0600)
committerKevin Day <Kevin@kevux.org>
Sat, 30 Nov 2024 13:44:59 +0000 (07:44 -0600)
The eki_write program is now added and complete.

This resolves the progress commits for this, such as 740d5fc88d6e05edf2a7267c422642bd14cc473c.

There are no iki_write runtime tests yet, so this does not add any yet.

13 files changed:
level_3/iki_write/c/eki/common.c
level_3/iki_write/c/eki/print.c
level_3/iki_write/c/eki/process.c
level_3/iki_write/c/eki/process.h
level_3/iki_write/c/iki/common.c
level_3/iki_write/c/iki/print.c
level_3/iki_write/c/iki/process.c
level_3/iki_write/c/iki/process.h
level_3/iki_write/c/main/common/print.c
level_3/iki_write/c/main/common/print.h
level_3/iki_write/c/main/common/type.h
level_3/iki_write/c/main/iki_write.c
level_3/iki_write/data/build/settings.eki_write

index ea8b1efc024da6e0f49135f0a6ef028666c98852..d17fcfee4aa7e7b47d2ebf624264b650e7c627a1 100644 (file)
@@ -41,6 +41,8 @@ extern "C" {
       // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0).
       for (index = 0; at_object < object->values.used; ) {
 
+        if (iki_write_signal_check(main)) return;
+
         main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &objectss->array[objectss->used].array, &objectss->array[objectss->used].used, &objectss->array[objectss->used].size);
 
         if (F_status_is_error(main->setting.state.status)) {
@@ -103,6 +105,8 @@ extern "C" {
       // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0).
       for (index = 0; main->setting.contents.used < content->values.used; ) {
 
+        if (iki_write_signal_check(main)) return;
+
         index = content->values.array[main->setting.contents.used];
 
         main->setting.contents.array[main->setting.contents.used].string = main->program.parameters.arguments.array[index].string;
index b3201effe19ac18327ef5a38a391c65dc14cb1f8..a770b93cbe31d7e19edec26a9f9344e7991a7896 100644 (file)
@@ -73,8 +73,8 @@ extern "C" {
   void iki_write_eki_print_message_help_note_pipe(fl_print_t * const print) {
 
     if (!print) return;
-    fl_print_format("%r  When piping main to this program, a single form-feed character (\\f) (U+000C) must be used to separate each Object set from the Content.%r", print->to, f_string_eol_s, f_string_eol_s);
-    fl_print_format("  Each Object within an Object set is is separated by a single backspace character (\\b) (U+0008).%r", print->to, f_string_eol_s);
+    fl_print_format("%r  When piping main to this program, a single Form-Feed character (\\f) (U+000C) must be used to separate each Object set from the Content.%r", print->to, f_string_eol_s, f_string_eol_s);
+    fl_print_format("  Each Object within an Object set is is separated by a single Backspace character (\\b) (U+0008).%r", print->to, f_string_eol_s);
     fl_print_format("  Each Object set must be followed by a Content.%r", print->to, f_string_eol_s);
   }
 #endif // _di_iki_write_eki_print_message_help_note_pipe_
index 8316c4c17cec4d99b6bf9267d23f916af0cb6ca3..6cd7d8b344f6095ac1e75544dadc623fa36b437c 100644 (file)
@@ -5,13 +5,13 @@ extern "C" {
 #endif
 
 #ifndef _di_iki_write_eki_load_objects_content_pipe_
-  void iki_write_eki_load_objects_content_pipe(void * const void_main, const f_range_t range, bool * const object_ended) {
+  void iki_write_eki_load_objects_content_pipe(void * const void_main, const f_range_t range, uint8_t * const pipe_state) {
 
     if (!void_main) return;
 
     iki_write_main_t * const main = (iki_write_main_t *) void_main;
 
-    if (!object_ended || !main->callback.process_objects_content) {
+    if (!pipe_state || !main->callback.process_objects_content) {
       main->setting.state.status = F_status_set_error(F_parameter);
 
       iki_write_print_error(&main->program.error, macro_iki_write_f(iki_write_callback_load_objects_content_pipe));
@@ -19,61 +19,99 @@ extern "C" {
       return;
     }
 
-    if (*object_ended) {
-      main->cache.content.used = 0;
-
+    if (*pipe_state) {
       if (main->cache.buffer.used) {
         main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.content);
 
         if (F_status_is_error(main->setting.state.status)) {
           iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless));
 
-          *object_ended = F_false;
-
           return;
         }
       }
 
       main->callback.process_objects_content((void *) main, main->cache.objects, main->cache.content);
-
-      if (F_status_is_error(main->setting.state.status)) {
-        *object_ended = F_false;
-
-        return;
-      }
+      if (F_status_is_error(main->setting.state.status)) return;
 
       fll_print_dynamic_raw(f_string_eol_s, main->program.output.to);
 
-      *object_ended = F_false;
+      *pipe_state = 0x0;
       main->cache.objects.used = 0;
+      main->cache.content.used = 0;
     }
     else {
       f_range_t range_object = range;
+      f_number_unsigned_t total = 0;
+
+      for (; range_object.start <= range_object.stop; ++total) {
+
+        if (iki_write_signal_check(main)) return;
+
+        main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_space_back_s.string[0], &range_object);
 
-      f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size);
+        if (F_status_is_error(main->setting.state.status)) {
+          iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to));
+
+          return;
+        }
 
-      if (F_status_is_error(main->setting.state.status)) {
-        iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase));
+        // Seek past the found colon when the end is not reached.
+        if (main->setting.state.status == F_okay) {
+          ++range_object.start;
+        }
+      } // for
 
-        *object_ended = F_false;
+      // Designate that no Object is found.
+      if (!total) {
+        *pipe_state = 0x0;
 
         return;
       }
 
-      main->cache.objects.array[0].used = 0;
+      if (main->cache.objects.size < total) {
+        f_memory_array_increase_by(total, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size);
 
-      main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.objects.array[0]);
+        if (F_status_is_error(main->setting.state.status)) {
+          iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase_by));
 
-      if (F_status_is_error(main->setting.state.status)) {
-        iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless));
+          return;
+        }
+      }
 
-        *object_ended = F_false;
+      range_object = range;
 
-        return;
-      }
+      f_number_unsigned_t i = 0;
+      f_range_t range_next = range;
+
+      for (; i < total; ++i) {
+
+        if (iki_write_signal_check(main)) return;
+
+        main->cache.objects.array[main->cache.objects.used].used = 0;
+
+        main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_space_back_s.string[0], &range_next);
+
+        if (F_status_is_error(main->setting.state.status)) {
+          iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to));
+
+          return;
+        }
+
+        range_object.stop = range_next.start - 1;
+
+        main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range_object, &main->cache.objects.array[main->cache.objects.used]);
+
+        if (F_status_is_error(main->setting.state.status)) {
+          iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless));
+
+          return;
+        }
+
+        ++main->cache.objects.used;
+        range_object.start = ++range_next.start;
+      } // for
 
-      *object_ended = F_true;
-      ++main->cache.objects.used;
+      *pipe_state = 0x1;
     }
   }
 #endif // _di_iki_write_eki_load_objects_content_pipe_
index e9fadc5d3752f2a03fe0831f67f13c04563da95a..1fc7e2a0685efa81cc8c1a3c2ea0b04c7d17287e 100644 (file)
@@ -32,15 +32,20 @@ extern "C" {
  *     Errors (with error bit) from: f_iki_write().
  *
  *     F_failure (with error bit) for any other failure.
- * @param objects
- *   The objects to process and print.
- * @param content
- *   The content to process and print.
+ * @param range
+ *   The range within the buffer representing the objects.
+ * @param pipe_state
+ *   Designate that the Object part of the pipe is complete.
+ *   For EKI, this may represent the end of the entire set of multiple Objects.
+ *
+ *   State Bits:
+ *     - 0x0: No Object has been found.
+ *     - 0x1: Object is found and processed.
  *
  * @see f_iki_write()
  */
 #ifndef _di_iki_write_eki_load_objects_content_pipe_
-  extern void iki_write_eki_load_objects_content_pipe(void * const main, const f_range_t range, bool * const object_ended);
+  extern void iki_write_eki_load_objects_content_pipe(void * const main, const f_range_t range, uint8_t * const pipe_state);
 #endif // _di_iki_write_eki_load_objects_content_pipe_
 
 /**
index bd9b0a181137628ce75e37531b662138efdf46e1..22c68db24a48e92c28bc5d5eadbd8df781441715 100644 (file)
@@ -36,6 +36,8 @@ extern "C" {
       // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0).
       for (index = 0; main->setting.objectss.used < values->used; ) {
 
+        if (iki_write_signal_check(main)) return;
+
         main->setting.state.status = f_memory_arrays_resize(1, sizeof(f_string_dynamic_t), (void **) &main->setting.objectss.array[main->setting.objectss.used].array, &main->setting.objectss.array[main->setting.objectss.used].used, &main->setting.objectss.array[main->setting.objectss.used].size, &f_string_dynamics_delete_callback);
 
         if (F_status_is_error(main->setting.state.status)) {
@@ -78,6 +80,8 @@ extern "C" {
       // Construct the array without allocating any more memory by setting this as a static string (used > 0, size = 0).
       for (index = 0; main->setting.contents.used < values->used; ) {
 
+        if (iki_write_signal_check(main)) return;
+
         index = values->array[main->setting.contents.used];
 
         main->setting.contents.array[main->setting.contents.used].string = main->program.parameters.arguments.array[index].string;
index 68788c4c948afaa4dd2f91514714217f2012e033..1c2d78c26eb4c1df205347e2c1956b40315da7b5 100644 (file)
@@ -51,7 +51,7 @@ extern "C" {
 
     if (!print) return;
 
-    fl_print_format("%r  When piping main to this program, a single form-feed character (\\f) (U+000C) must be used to separate each Object from each Content.%r", print->to, f_string_eol_s, f_string_eol_s);
+    fl_print_format("%r  When piping main to this program, a single Form-Feed character (\\f) (U+000C) must be used to separate each Object from each Content.%r", print->to, f_string_eol_s, f_string_eol_s);
     fl_print_format("  Each Object must be followed by a Content.%r", print->to, f_string_eol_s);
   }
 #endif // _di_iki_write_iki_print_message_help_note_pipe_
index 8ff02b43eb02b8e6aba09310ce25a3925971383f..28a480d632f4c3efd1d5d01c63d4bbd18c9cbe43 100644 (file)
@@ -5,13 +5,13 @@ extern "C" {
 #endif
 
 #ifndef _di_iki_write_iki_load_objects_content_pipe_
-  void iki_write_iki_load_objects_content_pipe(void * const void_main, const f_range_t range, bool * const object_ended) {
+  void iki_write_iki_load_objects_content_pipe(void * const void_main, const f_range_t range, uint8_t * const pipe_state) {
 
     if (!void_main) return;
 
     iki_write_main_t * const main = (iki_write_main_t *) void_main;
 
-    if (!object_ended || !main->callback.process_objects_content) {
+    if (!pipe_state || !main->callback.process_objects_content) {
       main->setting.state.status = F_status_set_error(F_parameter);
 
       iki_write_print_error(&main->program.error, macro_iki_write_f(iki_write_callback_load_objects_content_pipe));
@@ -19,7 +19,7 @@ extern "C" {
       return;
     }
 
-    if (*object_ended) {
+    if (*pipe_state) {
       main->cache.content.used = 0;
 
       if (main->cache.buffer.used) {
@@ -28,33 +28,26 @@ extern "C" {
         if (F_status_is_error(main->setting.state.status)) {
           iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless));
 
-          *object_ended = F_false;
-
           return;
         }
       }
 
       main->callback.process_objects_content((void *) main, main->cache.objects, main->cache.content);
-
-      if (F_status_is_error(main->setting.state.status)) {
-        *object_ended = F_false;
-
-        return;
-      }
+      if (F_status_is_error(main->setting.state.status)) return;
 
       fll_print_dynamic_raw(f_string_eol_s, main->program.output.to);
 
-      *object_ended = F_false;
+      *pipe_state = 0x0;
       main->cache.objects.used = 0;
     }
     else {
+      main->cache.objects.used = 0;
+
       f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.objects.array, &main->cache.objects.used, &main->cache.objects.size);
 
       if (F_status_is_error(main->setting.state.status)) {
         iki_write_print_error(&main->program.error, macro_iki_write_f(f_memory_array_increase));
 
-        *object_ended = F_false;
-
         return;
       }
 
@@ -65,12 +58,10 @@ extern "C" {
       if (F_status_is_error(main->setting.state.status)) {
         iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_partial_append_nulless));
 
-        *object_ended = F_false;
-
         return;
       }
 
-      *object_ended = F_true;
+      *pipe_state = 0x1;
       ++main->cache.objects.used;
     }
   }
index 30da911e696267337005c43b2098c90ae760b9a8..adba6eca6ada26db1c0c76cbecbe1975b2f21b86 100644 (file)
@@ -32,15 +32,19 @@ extern "C" {
  *     Errors (with error bit) from: f_iki_write().
  *
  *     F_failure (with error bit) for any other failure.
- * @param objects
- *   The objects to process and print.
- * @param content
- *   The content to process and print.
+ * @param range
+ *   The range within the buffer representing the objects.
+ * @param pipe_state
+ *   Designate that the Object part of the pipe is complete.
+ *
+ *   State Bits:
+ *     - 0x0: No Object has been found.
+ *     - 0x1: Object is found and processed.
  *
  * @see f_iki_write()
  */
 #ifndef _di_iki_write_iki_load_objects_content_pipe_
-  extern void iki_write_iki_load_objects_content_pipe(void * const main, const f_range_t range, bool * const object_ended);
+  extern void iki_write_iki_load_objects_content_pipe(void * const main, const f_range_t range, uint8_t * const pipe_state);
 #endif // _di_iki_write_iki_load_objects_content_pipe_
 
 /**
index 9f1b5464b021e3eed3467cb877167da4115e4086..6862137e243cf1ae911e78dec928fe1d24206d16 100644 (file)
@@ -11,6 +11,7 @@ extern "C" {
     "f_file_stream_open",
     "f_iki_write",
     "f_memory_array_increase",
+    "f_memory_array_increase_by",
     "f_memory_arrays_resize",
     "f_string_dynamic_partial_append_nulless",
     "f_string_dynamic_seek_to",
index c4cfb9d5b4224d9160812f6ba59195e4a64d612e..0579ed7987c54fb93d50b8c0de939c138c0995d1 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
     iki_write_f_f_file_stream_open_e,
     iki_write_f_f_iki_write_e,
     iki_write_f_f_memory_array_increase_e,
+    iki_write_f_f_memory_array_increase_by_e,
     iki_write_f_f_memory_arrays_resize_e,
     iki_write_f_f_string_dynamic_partial_append_nulless_e,
     iki_write_f_f_string_dynamic_seek_to_e,
index 9c2babc3d3813858b5abb0c59a173e15a40487e0..dd3497eb9d74a169d48220bf71af2ed18808b0d1 100644 (file)
@@ -27,7 +27,7 @@ extern "C" {
  */
 #ifndef _di_iki_write_callback_t_
   typedef struct {
-    void (*load_objects_content_pipe)(void * const main, const f_range_t range, bool * const object_ended);
+    void (*load_objects_content_pipe)(void * const main, const f_range_t range, uint8_t * const pipe_state);
 
     void (*print_help)(fl_print_t * const print);
 
index b6389bd7fac3a8f87aad5b2d11888feb023a52b3..eb9ab45faee1e840a427d3f72190bf3bb2f1ca75 100644 (file)
@@ -28,7 +28,7 @@ extern "C" {
     }
 
     if (main->setting.flag & iki_write_main_flag_pipe_d) {
-      bool object_ended = F_false;
+      uint8_t pipe_state = 0x0;
       f_number_unsigned_t previous = 0;
       f_range_t range = f_range_t_initialize;
       f_status_t status = F_okay;
@@ -44,17 +44,7 @@ extern "C" {
       range.start = 0;
 
       do {
-        if (!((++main->program.signal_check) % iki_write_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            object_ended = F_false;
-
-            break;
-          }
-
-          main->program.signal_check = 0;
-        }
+        if (iki_write_signal_check(main)) return;
 
         if (status != F_okay_eof) {
           status = f_file_read(pipe, &main->cache.buffer);
@@ -64,8 +54,6 @@ extern "C" {
 
             iki_write_print_error_file(&main->program.error, macro_iki_write_f(f_file_read), f_string_ascii_minus_s, f_file_operation_read_s, fll_error_file_type_pipe_e);
 
-            object_ended = F_false;
-
             break;
           }
 
@@ -74,8 +62,6 @@ extern "C" {
 
             fll_program_print_error_pipe_missing_content(&main->program.error);
 
-            object_ended = F_false;
-
             break;
           }
 
@@ -92,18 +78,14 @@ extern "C" {
         if (F_status_is_error(main->setting.state.status)) {
           iki_write_print_error(&main->program.error, macro_iki_write_f(f_string_dynamic_seek_to));
 
-          object_ended = F_false;
-
           break;
         }
 
-        if (object_ended && previous == range.start) {
+        if (pipe_state && previous == range.start) {
           main->setting.state.status = F_status_set_error(F_parameter);
 
           fll_program_print_error_pipe_invalid_form_feed(&main->program.error);
 
-          object_ended = F_false;
-
           break;
         }
 
@@ -111,7 +93,7 @@ extern "C" {
         range.start = previous;
 
         if (main->callback.load_objects_content_pipe) {
-          main->callback.load_objects_content_pipe((void *) main, range, &object_ended);
+          main->callback.load_objects_content_pipe((void *) main, range, &pipe_state);
           if (F_status_is_error(main->setting.state.status)) break;
         }
 
@@ -125,9 +107,9 @@ extern "C" {
           main->cache.buffer.used = 0;
         }
 
-      } while (status != F_okay_eof || main->cache.buffer.used || object_ended);
+      } while (status != F_okay_eof || main->cache.buffer.used || pipe_state);
 
-      if (F_status_is_error_not(main->setting.state.status) && object_ended) {
+      if (F_status_is_error_not(main->setting.state.status) && pipe_state) {
         main->setting.state.status = F_status_set_error(F_parameter);
 
         fll_program_print_error_pipe_object_without_content(&main->program.error);
@@ -137,15 +119,7 @@ extern "C" {
     if (F_status_is_error_not(main->setting.state.status) && F_status_set_fine(main->setting.state.status) != F_interrupt) {
       for (f_number_unsigned_t i = 0; i < main->setting.objectss.used; ++i) {
 
-        if (!((++main->program.signal_check) % iki_write_signal_check_d)) {
-          if (fll_program_standard_signal_received(&main->program)) {
-            main->setting.state.status = F_status_set_error(F_interrupt);
-
-            break;
-          }
-
-          main->program.signal_check = 0;
-        }
+        if (iki_write_signal_check(main)) return;
 
         main->callback.process_objects_content((void *) main, main->setting.objectss.array[i], main->setting.contents.array[i]);
         if (F_status_is_error(main->setting.state.status)) break;
index 917dda7dfadb81eaeec34c0cfd595e0560c8af3f..0efd57b55677e39b2563225123b70e11de2acc63 100644 (file)
@@ -1,6 +1,6 @@
 # fss-0001
 #
-# Builds the "iki_write" program.
+# Builds the "eki_write" program.
 # This must be called after the "setting".
 #