]> Kevux Git Server - fll/commitdiff
Update: Switch iki_write to using f_iki_write(). development
authorKevin Day <Kevin@kevux.org>
Sun, 24 Nov 2024 04:43:40 +0000 (22:43 -0600)
committerKevin Day <Kevin@kevux.org>
Sun, 24 Nov 2024 04:44:47 +0000 (22:44 -0600)
The old iki_write is using the simple processing functions.
Switch to using the dedicated `f_iki_write()` function.

Switch to using the main cache design.

level_3/iki_write/c/main/common.c
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.c
level_3/iki_write/c/main/common/type.h
level_3/iki_write/c/main/iki_write.c
level_3/iki_write/c/main/iki_write.h
level_3/iki_write/c/main/print/error.c
level_3/iki_write/c/main/process.c
level_3/iki_write/c/main/process.h

index 59b4cd511ae5a99a6b2c43698f3149f06bb823d8..cf62d631d00c1716e12963b4841c53610842847a 100644 (file)
@@ -174,6 +174,10 @@ extern "C" {
 
     if (main->program.parameters.array[iki_write_parameter_wrap_e].result & f_console_result_found_e) {
       main->setting.flag |= iki_write_main_flag_wrap_d;
+      main->setting.state.flag |= f_iki_state_flag_force_wrap_e;
+    }
+    else {
+      main->setting.state.flag &= ~f_iki_state_flag_force_wrap_e;
     }
 
     main->setting.quote = f_iki_syntax_quote_double_s;
index 44d80026fe2e25e9e0198e462a97920ca2a663ff..d22642b6eaf2900919424b285303a7f55d7d610a 100644 (file)
@@ -9,12 +9,11 @@ extern "C" {
     "f_console_parameter_process",
     "f_file_read",
     "f_file_stream_open",
-    "f_iki_object_is",
+    "f_iki_write",
     "f_memory_arrays_resize",
     "f_string_dynamic_partial_append_nulless",
     "f_string_dynamic_seek_to",
     "f_thread_create",
-    "fll_iki_content_escape",
     "fll_program_parameter_process_context_standard",
     "fll_program_parameter_process_verbosity_standard",
   };
index 1121f2d76c65db0420296f9c4c9f955ea21f5400..bba8c099407d886fdb39b04f0f79953b04b8abe6 100644 (file)
@@ -42,12 +42,11 @@ extern "C" {
     iki_write_f_f_console_parameter_process_e,
     iki_write_f_f_file_read_e,
     iki_write_f_f_file_stream_open_e,
-    iki_write_f_f_iki_object_is_e,
+    iki_write_f_f_iki_write_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,
     iki_write_f_f_thread_create_e,
-    iki_write_f_fll_iki_content_escape_e,
     iki_write_f_fll_program_parameter_process_context_standard_e,
     iki_write_f_fll_program_parameter_process_verbosity_standard_e,
   }; // enum
index ed5f5287f07e407bb1ef52f7c8c70ff99d8732d7..11f9da4035c235a6b2432a0dbe8535e3741cde33 100644 (file)
@@ -4,12 +4,26 @@
 extern "C" {
 #endif
 
+#ifndef _di_iki_write_cache_delete_
+  void iki_write_cache_delete(iki_write_cache_t * const cache) {
+
+    if (!cache) return;
+
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size);
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->content.string, &cache->content.used, &cache->content.size);
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->iki.string, &cache->iki.used, &cache->iki.size);
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->object.string, &cache->object.used, &cache->object.size);
+  }
+#endif // _di_iki_write_cache_delete_
+
 #ifndef _di_iki_write_main_delete_
   void iki_write_main_delete(iki_write_main_t * const main) {
 
     if (!main) return;
 
     fll_program_data_delete(&main->program);
+
+    iki_write_cache_delete(&main->cache);
     iki_write_setting_delete(&main->setting);
   }
 #endif // _di_iki_write_main_delete_
@@ -19,11 +33,6 @@ extern "C" {
 
     if (!setting) return;
 
-    f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->escaped.string, &setting->escaped.used, &setting->escaped.size);
-    f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->buffer.string, &setting->buffer.used, &setting->buffer.size);
-    f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->object.string, &setting->object.used, &setting->object.size);
-    f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->content.string, &setting->content.used, &setting->content.size);
-
     f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->objects.array, &setting->objects.used, &setting->objects.size, &f_string_dynamics_delete_callback);
     f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->contents.array, &setting->contents.used, &setting->contents.size, &f_string_dynamics_delete_callback);
   }
index d684511c64653ddcc650008dd2dec6d1cf858ebf..35d4f69ecfb51a62515d44d9fcfe48cf0d356f8d 100644 (file)
@@ -17,6 +17,31 @@ extern "C" {
 #endif
 
 /**
+ * The iki write main program cache.
+ *
+ * buffer:  A buffer used during processing the file.
+ * content: A buffer used to hold a Content during processing.
+ * iki:     A buffer used for writing the IKI during processing.
+ * object:  A buffer used to hold an Object during processing.
+ */
+#ifndef _di_iki_write_setting_t_
+  typedef struct {
+    f_string_dynamic_t buffer;
+    f_string_dynamic_t content;
+    f_string_dynamic_t iki;
+    f_string_dynamic_t object;
+  } iki_write_cache_t;
+
+  #define iki_write_cache_t_initialize \
+    { \
+      f_string_dynamic_t_initialize, \
+      f_string_dynamic_t_initialize, \
+      f_string_dynamic_t_initialize, \
+      f_string_dynamic_t_initialize, \
+    }
+#endif // _di_iki_write_cache_t_
+
+/**
  * The iki write main program settings.
  *
  * This is passed to the program-specific main entry point to designate program settings.
@@ -29,11 +54,6 @@ extern "C" {
  *
  * quote: This holds the quote used during processing.
  *
- * escaped: A buffer used for escaping strings during processing.
- * buffer:  A buffer used during processing the file.
- * object:  A buffer used to hold an Object during processing.
- * content: A buffer used to hold a Content during processing.
- *
  * objects:  An array of objects passed as values to the "--object" parameter.
  * contents: An array of objects passed as values to the "--content" parameter and must match the length of objects.
  */
@@ -46,11 +66,6 @@ extern "C" {
 
     f_string_static_t quote;
 
-    f_string_dynamic_t escaped;
-    f_string_dynamic_t buffer;
-    f_string_dynamic_t object;
-    f_string_dynamic_t content;
-
     f_string_dynamics_t objects;
     f_string_dynamics_t contents;
   } iki_write_setting_t;
@@ -61,10 +76,6 @@ extern "C" {
       F_okay, \
       f_state_t_initialize, \
       f_string_static_t_initialize, \
-      f_string_dynamic_t_initialize, \
-      f_string_dynamic_t_initialize, \
-      f_string_dynamic_t_initialize, \
-      f_string_dynamic_t_initialize, \
       f_string_dynamics_t_initialize, \
       f_string_dynamics_t_initialize, \
     }
@@ -73,23 +84,40 @@ extern "C" {
 /**
  * The main program data as a single structure.
  *
+ * cache:   The cache data.
  * program: The main program data.
  * setting: The settings data.
  */
 #ifndef _di_iki_write_main_t_
   typedef struct {
+    iki_write_cache_t cache;
     fll_program_data_t program;
     iki_write_setting_t setting;
   } iki_write_main_t;
 
   #define iki_write_main_t_initialize \
     { \
+      iki_write_cache_t_initialize, \
       fll_program_data_t_initialize, \
       iki_write_setting_t_initialize, \
     }
 #endif // _di_iki_write_main_t_
 
 /**
+ * Delete the program main cache data.
+ *
+ * @param cache
+ *   The program main cache data.
+ *
+ *   Must not be NULL.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_iki_write_cache_delete_
+  extern void iki_write_cache_delete(iki_write_cache_t * const cache);
+#endif // _di_iki_write_cache_delete_
+
+/**
  * De-allocate main program data.
  *
  * @param main
@@ -100,6 +128,7 @@ extern "C" {
  *   This does not alter main.setting.state.status.
  *
  * @see fll_program_data_delete()
+ * @see iki_write_cache_delete()
  * @see iki_write_setting_delete()
  */
 #ifndef _di_iki_write_main_delete_
@@ -116,7 +145,6 @@ extern "C" {
  *
  *   This does not alter setting.state.status.
  *
- * @see f_memory_array_resize()
  * @see f_memory_arrays_resize()
  */
 #ifndef _di_iki_write_setting_delete_
index c7dc893ee945bc3be1088365e0a70725e484b153..f5c0ea6c02d21bba83a5d87bdc5ca874cf0c8638 100644 (file)
@@ -25,11 +25,8 @@ extern "C" {
       return;
     }
 
-    main->setting.escaped.used = 0;
-
     if (main->setting.flag & iki_write_main_flag_pipe_d) {
       bool object_ended = F_false;
-
       f_number_unsigned_t previous = 0;
       f_range_t range = f_range_t_initialize;
       f_status_t status = F_okay;
@@ -38,9 +35,9 @@ extern "C" {
       pipe.id = F_type_descriptor_input_d;
       pipe.size_read = 1;
 
-      main->setting.buffer.used = 0;
-      main->setting.object.used = 0;
-      main->setting.content.used = 0;
+      main->cache.buffer.used = 0;
+      main->cache.object.used = 0;
+      main->cache.content.used = 0;
 
       range.start = 0;
 
@@ -58,7 +55,7 @@ extern "C" {
         }
 
         if (status != F_okay_eof) {
-          status = f_file_read(pipe, &main->setting.buffer);
+          status = f_file_read(pipe, &main->cache.buffer);
 
           if (F_status_is_error(status)) {
             main->setting.state.status = F_status_set_error(F_pipe);
@@ -70,7 +67,7 @@ extern "C" {
             break;
           }
 
-          if (!main->setting.buffer.used) {
+          if (!main->cache.buffer.used) {
             main->setting.state.status = F_status_set_error(F_parameter);
 
             fll_program_print_error_pipe_missing_content(&main->program.error);
@@ -80,11 +77,11 @@ extern "C" {
             break;
           }
 
-          range.stop = main->setting.buffer.used - 1;
+          range.stop = main->cache.buffer.used - 1;
         }
 
         previous = range.start;
-        main->setting.state.status = f_string_dynamic_seek_to(main->setting.buffer, f_string_ascii_feed_form_s.string[0], &range);
+        main->setting.state.status = f_string_dynamic_seek_to(main->cache.buffer, f_string_ascii_feed_form_s.string[0], &range);
 
         if (main->setting.state.status == F_data_not_stop) {
           main->setting.state.status = F_status_set_error(F_parameter);
@@ -112,10 +109,10 @@ extern "C" {
         range.start = previous;
 
         if (object_ended) {
-          main->setting.content.used = 0;
+          main->cache.content.used = 0;
 
-          if (main->setting.buffer.used) {
-            main->setting.state.status = f_string_dynamic_partial_append_nulless(main->setting.buffer, range, &main->setting.content);
+          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));
@@ -126,7 +123,7 @@ extern "C" {
             }
           }
 
-          iki_write_process(main, main->setting.object, main->setting.content);
+          iki_write_process(main, main->cache.object, main->cache.content);
 
           if (F_status_is_error(main->setting.state.status)) {
             object_ended = F_false;
@@ -139,9 +136,9 @@ extern "C" {
           object_ended = F_false;
         }
         else {
-          main->setting.object.used = 0;
+          main->cache.object.used = 0;
 
-          main->setting.state.status = f_string_dynamic_partial_append_nulless(main->setting.buffer, range, &main->setting.object);
+          main->setting.state.status = f_string_dynamic_partial_append_nulless(main->cache.buffer, range, &main->cache.object);
 
           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));
@@ -156,15 +153,15 @@ extern "C" {
 
         // Restore the range, positioned after the new line.
         range.start = range.stop + 2;
-        range.stop = main->setting.buffer.used - 1;
+        range.stop = main->cache.buffer.used - 1;
 
         // Only clear the buffer and reset the start when the entire buffer has been processed.
         if (range.start > range.stop) {
           range.start = 0;
-          main->setting.buffer.used = 0;
+          main->cache.buffer.used = 0;
         }
 
-      } while (status != F_okay_eof || main->setting.buffer.used || object_ended);
+      } while (status != F_okay_eof || main->cache.buffer.used || object_ended);
 
       if (object_ended) {
         main->setting.state.status = F_status_set_error(F_parameter);
index 006a6685926f562213014fedb1aa0d75e4234ad3..192f65640ee404dc05ba551682da8279821143ad 100644 (file)
@@ -88,18 +88,14 @@ extern "C" {
  *
  *   This alters main.setting.state.status:
  *     F_okay on success.
- *     F_true on success when performing verification and verify passed.
- *     F_false on success when performing verification and verify failed.
  *     F_interrupt on (exit) signal received.
  *
  *     F_failure (with error bit) on processing failure.
  *     F_parameter (with error bit) if main is NULL or setting is NULL.
  *
- *     Errors (with error bit) from: f_iki_object_is().
- *     Errors (with error bit) from: fll_iki_content_escape().
+ *     Errors (with error bit) from: iki_write_process().
  *
- * @see f_iki_object_is()
- * @see fll_iki_content_escape()
+ * @see iki_write_process()
  */
 #ifndef _di_iki_write_main_
   extern void iki_write_main(iki_write_main_t * const main);
index 85e88af57444ffdcbe453cd027681cc8a71f6494..fa389dcc035e493d388c0283bbc0c9603891353e 100644 (file)
@@ -60,7 +60,7 @@ extern "C" {
 
     fl_print_format("%[%QThe object '%]", print->to, print->set->error, print->prefix, print->set->error);
     fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, object, print->set->notable);
-    fl_print_format("%[' is not a valid IKI Object.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s);
+    fl_print_format("%[' is not a valid IKI Object (IKI Vocabulary).%]%r", print->to, print->set->error, print->set->error, f_string_eol_s);
 
     f_file_stream_unlock(print->to);
 
index 8cd8ce10f8bc6e0d98df5384a6f99a3246237b54..3fd6316e366a9fa479d3e766dad5181bcc5b44fe 100644 (file)
@@ -7,6 +7,8 @@ extern "C" {
 #ifndef _di_iki_write_process_
   void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content) {
 
+    if (!main) return;
+
     if (!object.used) {
       main->setting.state.status = F_status_set_error(F_failure);
 
@@ -15,38 +17,24 @@ extern "C" {
       return;
     }
 
-    main->setting.state.status = f_iki_object_is(object);
-
-    if (main->setting.state.status == F_false) {
-      main->setting.state.status = F_status_set_error(F_failure);
+    main->cache.iki.used = 0;
 
-      iki_write_print_error_object_not_valid(&main->program.error, object);
-
-      return;
-    }
+    f_iki_write(object, content, main->setting.quote, &main->cache.iki, &main->setting.state);
 
     if (F_status_is_error(main->setting.state.status)) {
-      iki_write_print_error(&main->program.error, macro_iki_write_f(f_iki_object_is));
+      if (F_status_set_fine(main->setting.state.status) == F_syntax) {
+        iki_write_print_error_object_not_valid(&main->program.error, object);
+      }
+      else {
+        iki_write_print_error(&main->program.error, macro_iki_write_f(f_iki_write));
+      }
 
       return;
     }
 
-    main->setting.escaped.used = 0;
-
-    main->setting.state.status = fll_iki_content_escape(content, main->setting.quote, &main->setting.escaped);
+    f_print_dynamic(main->cache.iki, main->program.output.to);
 
-    if (F_status_is_error(main->setting.state.status)) {
-      iki_write_print_error(&main->program.error, macro_iki_write_f(fll_iki_content_escape));
-
-      return;
-    }
-
-    if (main->setting.flag & iki_write_main_flag_wrap_d) {
-      fl_print_format("%r%Q%r%r%r%Q%r", main->program.output.to, f_iki_syntax_wrap_open_s, object, f_iki_syntax_wrap_close_s, f_iki_syntax_separator_s, main->setting.quote, main->setting.escaped, main->setting.quote);
-    }
-    else {
-      fl_print_format("%Q%r%r%Q%r", main->program.output.to, object, f_iki_syntax_separator_s, main->setting.quote, main->setting.escaped, main->setting.quote);
-    }
+    main->setting.state.status = F_okay;
   }
 #endif // _di_iki_write_process_
 
index 485e87702d816f1ccc1e17870aa07f3b0ffacf34..59d5b5044a29c0a5d12152829f11e40aa898d8d7 100644 (file)
@@ -17,7 +17,7 @@ extern "C" {
 #endif
 
 /**
- * Process a given object and content, printing the IKI if valid or an error if invalid.
+ * Process a given object and content, printing it.
  *
  * @param main
  *   The program and settings data.
@@ -25,8 +25,7 @@ extern "C" {
  *   This alters main.setting.state.status:
  *     F_okay on success.
  *
- *     Errors (with error bit) from: f_iki_object_is().
- *     Errors (with error bit) from: fll_iki_content_escape().
+ *     Errors (with error bit) from: f_iki_write().
  *
  *     F_failure (with error bit) for any other failure.
  * @param object
@@ -34,11 +33,11 @@ extern "C" {
  * @param content
  *   The content to escape and print.
  *
- * @see f_iki_object_is()
- * @see fll_iki_content_escape()
+ * @see iki_write_print_error_object_not_valid()
+ * @see f_iki_write()
  */
 #ifndef _di_iki_write_process_
-  extern void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content) F_attribute_visibility_internal_d;
+  extern void iki_write_process(iki_write_main_t * const main, const f_string_static_t object, const f_string_static_t content);
 #endif // _di_iki_write_process_
 
 #ifdef __cplusplus