From: Kevin Day Date: Wed, 19 Nov 2025 05:27:17 +0000 (-0600) Subject: Progress: Continue implementing controlfile and initfile support. X-Git-Tag: 0.7.3~5 X-Git-Url: https://www.git.kevux.org/?a=commitdiff_plain;h=e9d91df2016487649fd33a271799ca4003b8a85e;p=controller Progress: Continue implementing controlfile and initfile support. 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. --- diff --git a/data/build/stand_alone/config.h b/data/build/stand_alone/config.h index e45e870..b4fdb45 100644 --- a/data/build/stand_alone/config.h +++ b/data/build/stand_alone/config.h @@ -171,7 +171,7 @@ #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_ diff --git a/sources/c/program/controller/main/common/string.h b/sources/c/program/controller/main/common/string.h index dd34385..6acb8a3 100644 --- a/sources/c/program/controller/main/common/string.h +++ b/sources/c/program/controller/main/common/string.h @@ -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_) /** diff --git a/sources/c/program/controller/main/entry.c b/sources/c/program/controller/main/entry.c index 9548b04..d8118d7 100644 --- a/sources/c/program/controller/main/entry.c +++ b/sources/c/program/controller/main/entry.c @@ -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); - } } } diff --git a/sources/c/program/controller/main/entry/process.c b/sources/c/program/controller/main/entry/process.c index 3d0c090..c746550 100644 --- a/sources/c/program/controller/main/entry/process.c +++ b/sources/c/program/controller/main/entry/process.c @@ -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); diff --git a/sources/c/program/controller/main/rule/read.c b/sources/c/program/controller/main/rule/read.c index b927936..9381a96 100644 --- a/sources/c/program/controller/main/rule/read.c +++ b/sources/c/program/controller/main/rule/read.c @@ -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)); + } + } } } } diff --git a/sources/c/program/controller/main/thread/entry.c b/sources/c/program/controller/main/thread/entry.c index 9e4ef58..87f5f5e 100644 --- a/sources/c/program/controller/main/thread/entry.c +++ b/sources/c/program/controller/main/thread/entry.c @@ -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) {