]> Kevux Git Server - controller/commitdiff
Progress: Continue implementing controlfile and initfile support.
authorKevin Day <Kevin@kevux.org>
Wed, 19 Nov 2025 05:27:17 +0000 (23:27 -0600)
committerKevin Day <Kevin@kevux.org>
Wed, 19 Nov 2025 05:27:17 +0000 (23:27 -0600)
Fix issue where the `extern` prefix strings accidentally have `_length` in their names.

The entry and rule names should be without their prefixes.
Perform the prefix matching before pulling out the string.
Skip anything that doesn't match the correct prefix when using a loaded file.
Otherwise, operate normally.

This relocates the exit file loading to be at the start, right after loading the entry file.

It may be worth loading all of the rules specified in the entry and the exit at the start.
I added `@todo` and `@fixme` to represent these areas that I need to figure out how I want to handle.

data/build/stand_alone/config.h
sources/c/program/controller/main/common/string.h
sources/c/program/controller/main/entry.c
sources/c/program/controller/main/entry/process.c
sources/c/program/controller/main/rule/read.c
sources/c/program/controller/main/thread/entry.c

index e45e8700fd83cc42b224dad0cb1988fb38b7e81c..b4fdb45c6e8a61b5e5fab6d7eba793b8f8592b0d 100644 (file)
 #define _di_f_compare_dynamic_except_string_
 #define _di_f_compare_dynamic_except_trim_
 #define _di_f_compare_dynamic_except_trim_string_
-#define _di_f_compare_dynamic_partial_
+//#define _di_f_compare_dynamic_partial_
 #define _di_f_compare_dynamic_partial_dynamic_
 #define _di_f_compare_dynamic_partial_except_
 #define _di_f_compare_dynamic_partial_except_dynamic_
index dd3438594b6b9961324fbd393de115130343bae0..6acb8a3aefcac231bbfe2ab8c44575b531ab9aab 100644 (file)
@@ -71,9 +71,9 @@ extern "C" {
 
   extern const f_string_static_t controller_controlfile_s;
 
-  extern const f_string_static_t controller_prefix_entry_s_length;
-  extern const f_string_static_t controller_prefix_exit_s_length;
-  extern const f_string_static_t controller_prefix_rule_s_length;
+  extern const f_string_static_t controller_prefix_entry_s;
+  extern const f_string_static_t controller_prefix_exit_s;
+  extern const f_string_static_t controller_prefix_rule_s;
 #endif // !defined(_di_controller_controlfile_s_) && defined(_support_controller_controlfile_)
 
 /**
index 9548b0476daf1b8ff662ef924fd7680530c36de3..d8118d776f38913b577c5b4787721fff45e3968d 100644 (file)
@@ -30,6 +30,13 @@ extern "C" {
         // 0x1 = main found, 0x2 = found existing.
         uint8_t code = 0;
 
+        #ifdef _support_controller_controlfile_
+          const f_string_static_t prefix = is_entry ? controller_prefix_entry_s : controller_prefix_exit_s;
+          const f_range_t prefix_range = macro_f_range_t_initialize_2(prefix.used);
+
+          f_range_t offset = f_range_t_initialize;
+        #endif // _support_controller_controlfile_
+
         for (i = 0; i < main->thread.cache.object_items.used && controller_thread_enable_is_normal(&main->thread, is_entry); ++i) {
 
           code &= ~0x2;
@@ -60,7 +67,22 @@ extern "C" {
             break;
           }
 
-          state.status = f_string_dynamic_partial_append(main->thread.cache.buffer_file, main->thread.cache.object_items.array[i], &main->thread.cache.action.name_item);
+          // Process the entry or exit items normally, but if pre-loaded (as with controlfile or initfile), then only process if the proper prefix is present.
+          offset = main->thread.cache.object_items.array[i];
+
+          if (main->setting.flag & controller_main_flag_loaded_d) {
+            if (f_compare_dynamic_partial(main->thread.cache.buffer_file, prefix, offset, prefix_range) != F_equal_to) continue;
+
+            // Determine the next range position, skipping past any NULL characters.
+            for (j = 0; offset.start <= offset.stop && j < prefix.used; ++offset.start) {
+
+              if (!main->thread.cache.buffer_file.string[offset.start]) continue;
+
+              ++j;
+            } // for
+          }
+
+          state.status = f_string_dynamic_partial_append(main->thread.cache.buffer_file, offset, &main->thread.cache.action.name_item);
 
           if (F_status_is_error(state.status)) {
             controller_print_error_entry(&main->program.error, is_entry, F_status_set_fine(state.status), F_status_debug_source_d, F_true, F_status_debug_source_d);
@@ -313,13 +335,6 @@ extern "C" {
       }
       else {
         state.status = controller_file_load(main, F_false, controller_exits_s, main->process.name_entry, controller_exit_s);
-
-        // Immediately return on error whole loading the Exit.
-        if (state.status == F_file_found_not) {
-          entry->status = controller_status_simplify_error(F_file_found_not);
-
-          return F_status_set_error(F_file_found_not);
-        }
       }
     }
 
index 3d0c090b993027be3b6d0c4244ccf4130e59c5a8..c74655041ea3e689bd722f18eb12f4c3358d9e4b 100644 (file)
@@ -242,7 +242,7 @@ extern "C" {
             memcpy(cache_name_item, cache->action.name_item.string, sizeof(f_char_t) * cache->action.name_item.used);
             memcpy(cache_name_file, cache->action.name_file.string, sizeof(f_char_t) * cache->action.name_file.used);
 
-            status = controller_rule_read(main, cache, is_entry, alias_rule, entry, rule);
+            status = controller_rule_read(main, cache, is_entry, alias_rule, entry, rule); // @fixme this re-uses the buffer_file, which may be a problem for entry reading.
 
             // Restore cache.
             memcpy(cache->action.name_action.string, cache_name_action, sizeof(f_char_t) * cache_name_action_used);
index b9279362a37cc164453b9c02cc743c21608a4aa7..9381a9631612d7ea5c5f9dcf0ab7950b6e4dff4d 100644 (file)
@@ -173,26 +173,37 @@ extern "C" {
       controller_print_error_status(&main->program.error, F_status_debug_source_d, F_status_set_fine(state.status));
     }
     else {
-      state.status = controller_file_load(main, F_true, controller_rules_s, rule->alias, controller_rule_s);
-    }
+      if (!(main->setting.flag & controller_main_flag_loaded_d)) {
+        state.status = controller_file_load(main, F_true, controller_rules_s, rule->alias, controller_rule_s);
 
-    if (F_status_is_error_not(state.status)) {
-      rule->timestamp = cache->timestamp;
+        /* @todo, how should this be handled?
+         * Load the files at the start, so that this does not need to be loaded here?
+        f_range_t offset = f_range_t_initialize;
 
-      if (cache->buffer_file.used) {
-        f_range_t range = macro_f_range_t_initialize_2(cache->buffer_file.used);
+        offset = main->thread.cache.object_actions.array[i];
 
-        fll_fss_basic_list_read(cache->buffer_file, &range, &cache->object_items, &cache->content_items, &cache->delimits, 0, &cache->comments, &state);
+        if (main->setting.flag & controller_main_flag_loaded_d) {
+        }*/
+      }
 
-        if (F_status_is_error(state.status)) {
-          controller_print_error_status(&main->program.error, F_status_debug_source_d, F_status_set_fine(state.status));
-        }
-        else {
-          f_fss_apply_delimit(cache->delimits, &cache->buffer_file, &state);
+      if (F_status_is_error_not(state.status)) {
+        rule->timestamp = cache->timestamp;
+
+        if (cache->buffer_file.used) {
+          f_range_t range = macro_f_range_t_initialize_2(cache->buffer_file.used);
+
+          fll_fss_basic_list_read(cache->buffer_file, &range, &cache->object_items, &cache->content_items, &cache->delimits, 0, &cache->comments, &state);
 
           if (F_status_is_error(state.status)) {
             controller_print_error_status(&main->program.error, F_status_debug_source_d, F_status_set_fine(state.status));
           }
+          else {
+            f_fss_apply_delimit(cache->delimits, &cache->buffer_file, &state);
+
+            if (F_status_is_error(state.status)) {
+              controller_print_error_status(&main->program.error, F_status_debug_source_d, F_status_set_fine(state.status));
+            }
+          }
         }
       }
     }
index 9e4ef5842c038ef822199c6d157cf095e0c1db53..87f5f5e7b35ee78675fe7cb59cbc998566778808 100644 (file)
@@ -20,6 +20,13 @@ extern "C" {
 
     *status = controller_entry_read(main, F_true);
 
+    // Also load the exit file on start.
+    if (F_status_is_error_not(*status) && F_status_set_fine(*status) != F_interrupt && *status != F_child) {
+      *status = controller_entry_read(main, F_false);
+    }
+
+    // @todo pre-load all rule files? find all rules in the entry files and exit files and then load them?
+
     if (F_status_set_fine(*status) == F_interrupt) {
       main->process.ready = controller_process_ready_abort_e;
     }
@@ -27,6 +34,10 @@ extern "C" {
       main->process.ready = controller_process_ready_fail_e;
     }
     else if (*status != F_child) {
+
+      // Free up memory consumed by the buffered file.
+      f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->thread.cache.buffer_file.string, &main->thread.cache.buffer_file.used, &main->thread.cache.buffer_file.size);
+
       *status = controller_entry_preprocess(main, F_true);
 
       if ((main->setting.flag & controller_main_flag_simulate_d) && (main->setting.flag & controller_main_flag_validate_d)) {
@@ -113,23 +124,11 @@ extern "C" {
     controller_t * const main = (controller_t *) argument;
     f_status_t * const status = &main->thread.status;
 
-    *status = controller_entry_read(main, F_false);
-
-    if (F_status_set_fine(*status) == F_interrupt) {
-      main->process.ready = controller_process_ready_abort_e;
-    }
-    else if (F_status_is_error(*status)) {
-      main->process.ready = controller_process_ready_fail_e;
-    }
-    else if (*status == F_file_found_not) {
-      main->process.ready = controller_process_ready_done_e;
-    }
-    else if (*status != F_child) {
-      *status = controller_entry_preprocess(main, F_false);
+    // The exit file is loaded on start, so go straight into the pre-process.
+    *status = controller_entry_preprocess(main, F_false);
 
-      if ((main->setting.flag & controller_main_flag_simulate_d) && (main->setting.flag & controller_main_flag_validate_d)) {
-        controller_print_output_entry_setting_validate(&main->program.output, F_false);
-      }
+    if ((main->setting.flag & controller_main_flag_simulate_d) && (main->setting.flag & controller_main_flag_validate_d)) {
+      controller_print_output_entry_setting_validate(&main->program.output, F_false);
     }
 
     if (F_status_is_error_not(*status) && *status != F_child && *status != F_file_found_not) {