From 2162a2c06199660540bb42b8e735e2bb7cac322e Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 27 Jun 2024 22:59:42 -0500 Subject: [PATCH] Progress: Continue migrating the project. --- sources/c/main/print/error/lock.c | 1 - sources/c/main/print/error/perform/pid.h | 2 + sources/c/main/print/error/rule.c | 22 ++++++++++ sources/c/main/print/error/rule.h | 31 ++++++++++++++ sources/c/main/print/error/rule/action.c | 70 ++++++++++++++++++++++++++++++++ sources/c/main/print/error/rule/action.h | 66 +++++++++++++++++++++++++++++- sources/c/main/print/error/rule/item.c | 15 ++++++- sources/c/main/rule/instance.c | 65 ++++------------------------- 8 files changed, 210 insertions(+), 62 deletions(-) diff --git a/sources/c/main/print/error/lock.c b/sources/c/main/print/error/lock.c index ee0789f..3face96 100644 --- a/sources/c/main/print/error/lock.c +++ b/sources/c/main/print/error/lock.c @@ -7,7 +7,6 @@ extern "C" { #ifndef _di_controller_print_error_lock_critical_ f_status_t controller_print_error_lock_critical(fl_print_t * const print, const f_status_t status, const uint8_t is_read) { - // A signal is not an error. if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e || status == F_interrupt) return F_output_not; diff --git a/sources/c/main/print/error/perform/pid.h b/sources/c/main/print/error/perform/pid.h index c13c2bf..88a8c6c 100644 --- a/sources/c/main/print/error/perform/pid.h +++ b/sources/c/main/print/error/perform/pid.h @@ -25,6 +25,8 @@ extern "C" { * This requires print.custom to be controller_t. * * This does not alter print.custom.setting.state.status. + * + * Must not be NULL. * @param status * The status code to process. * Make sure this has F_status_set_fine() called if the status code has any error or warning bits. diff --git a/sources/c/main/print/error/rule.c b/sources/c/main/print/error/rule.c index c9a4644..56dfe75 100644 --- a/sources/c/main/print/error/rule.c +++ b/sources/c/main/print/error/rule.c @@ -62,6 +62,28 @@ extern "C" { } #endif // _di_controller_print_error_rule_cache_ +#ifndef _di_controller_print_error_rule_stack_already_ + f_status_t controller_print_error_rule_stack_already(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const uint8_t item) { + + if (!print || !print->custom || !action) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + controller_t * const main = (controller_t *) print->custom; + + controller_lock_print(print->to, &main->thread); + + fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable); + fl_print_format("%[' is already on the execution dependency stack, this recursion is prohibited.%]%r", print->to, print->context, print->context, f_string_eol_s); + + controller_print_error_rule_cache(print, action, item); + + controller_unlock_print_flush(print->to, &main->thread); + + return F_okay; + } +#endif // _di_controller_print_error_rule_stack_already_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/print/error/rule.h b/sources/c/main/print/error/rule.h index 23aa856..1193163 100644 --- a/sources/c/main/print/error/rule.h +++ b/sources/c/main/print/error/rule.h @@ -88,6 +88,37 @@ extern "C" { extern f_status_t controller_print_error_rule_cache(fl_print_t * const print, controller_cache_action_t * const action, const uint8_t item); #endif // _di_controller_print_error_rule_cache_ +/** + * Print error regarding the rule already being on the execution stack. + * + * @param print + * The output structure to print to. + * + * This requires print.custom to be controller_t. + * + * This does not alter print.custom.setting.state.status. + * + * Must not be NULL. + * @param action + * The action cache. + * + * Must not be NULL. + * @param name + * The rule name. + * @param item + * If TRUE, then this error is associated with an item. + * If FALSE, then this error is associated with a rule setting. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_controller_print_error_rule_stack_already_ + extern f_status_t controller_print_error_rule_stack_already(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const uint8_t item); +#endif // _di_controller_print_error_rule_stack_already_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/print/error/rule/action.c b/sources/c/main/print/error/rule/action.c index ddb61f3..1862027 100644 --- a/sources/c/main/print/error/rule/action.c +++ b/sources/c/main/print/error/rule/action.c @@ -7,16 +7,86 @@ extern "C" { #ifndef _di_controller_print_error_rule_action_missing_pid_ f_status_t controller_print_error_rule_action_missing_pid(fl_print_t * const print, const f_string_static_t alias) { + if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + controller_t * const main = (controller_t *) print->custom; + + controller_lock_print(print->to, &main->thread); + fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, alias, print->notable); fl_print_format("%[' is not designating a pid file.%]%r", print->to, print->context, print->context, f_string_eol_s); + controller_unlock_print_flush(print->to, &main->thread); + return F_okay; } #endif // _di_controller_print_error_rule_action_missing_pid_ +#ifndef _di_controller_print_error_rule_action_type_supported_not_ + f_status_t controller_print_error_rule_action_type_supported_not(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t type) { + + if (!print || !print->custom || !action) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + controller_t * const main = (controller_t *) print->custom; + + controller_lock_print(print->to, &main->thread); + + fl_print_format("%r%[%QUnsupported action type '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, type, print->notable); + fl_print_format("%[' while attempting to execute rule.%]%r", print->to, print->context, print->context, f_string_eol_s); + + controller_print_error_rule_cache(print, action, F_true); + + controller_unlock_print_flush(print->to, &main->thread); + + return F_okay; + } +#endif // _di_controller_print_error_rule_action_type_supported_not_ + +#ifndef _di_controller_print_error_rule_action_unknown_execute_ + f_status_t controller_print_error_rule_action_unknown_execute(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const f_string_static_t type, const f_number_unsigned_t total) { + + if (!print || !print->custom) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + controller_t * const main = (controller_t *) print->custom; + + controller_lock_print(print->to, &main->thread); + + if (total) { + fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable); + fl_print_format("%[' has no '%]", print->to, print->context, print->context); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, type, print->notable); + fl_print_format("%[' action to execute.%]%r", print->to, print->context, print->context, f_string_eol_s); + } + else { + fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable); + fl_print_format("%[ has no known '%]", print->to, print->context, print->context); + fl_print_format("%[%r %r%]", print->to, print->notable, controller_rule_s, controller_type_s, print->notable); + fl_print_format("%[' (such as '%]", print->to, print->context, print->context); + fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_command_s, print->notable); + fl_print_format("%[', '%]", print->to, print->context, print->context); + fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_service_s, print->notable); + fl_print_format("%[', '%]", print->to, print->context, print->context); + fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_script_s, print->notable); + fl_print_format("%[', or '%]", print->to, print->context, print->context); + fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_utility_s, print->notable); + fl_print_format("%[') to execute.%]%r", print->to, print->context, print->context, f_string_eol_s); + } + + controller_print_error_rule_cache(print, action, F_true); + + controller_unlock_print_flush(print->to, &main->thread); + + return F_okay; + } +#endif // _di_controller_print_error_rule_action_unknown_execute_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/print/error/rule/action.h b/sources/c/main/print/error/rule/action.h index e933fb0..0d50391 100644 --- a/sources/c/main/print/error/rule/action.h +++ b/sources/c/main/print/error/rule/action.h @@ -20,7 +20,13 @@ extern "C" { * Print an error or warning message about some rule not having the pid file information. * * @param print - * The error or warning output structure. + * The output structure to print to. + * + * This requires print.custom to be controller_t. + * + * This does not alter print.custom.setting.state.status. + * + * Must not be NULL. * @param alias * The rule alias of the rule that is missing the pid file designation. * @@ -34,6 +40,64 @@ extern "C" { extern f_status_t controller_print_error_rule_action_missing_pid(fl_print_t * const print, const f_string_static_t alias); #endif // _di_controller_print_error_rule_action_missing_pid_ +/** + * Print an error about Rule Action type not being supported. + * + * @param print + * The output structure to print to. + * + * This requires print.custom to be controller_t. + * + * This does not alter print.custom.setting.state.status. + * + * Must not be NULL. + * @param action + * The action cache. + * + * Must not be NULL. + * @param type + * The Action type name. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_controller_print_error_rule_action_type_supported_not_ + extern f_status_t controller_print_error_rule_action_type_supported_not(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t type); +#endif // _di_controller_print_error_rule_action_type_supported_not_ + +/** + * Print an error about Rule Action type not being supported. + * + * @param print + * The output structure to print to. + * + * This requires print.custom to be controller_t. + * + * This does not alter print.custom.setting.state.status. + * + * Must not be NULL. + * @param action + * The action cache. + * + * Must not be NULL. + * @param name + * The Rule name. + * @param type + * The Action type name. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. + */ +#ifndef _di_controller_print_error_rule_action_unknown_execute_ + extern f_status_t controller_print_error_rule_action_unknown_execute(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const f_string_static_t type, const f_number_unsigned_t total); +#endif // _di_controller_print_error_rule_action_unknown_execute_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/print/error/rule/item.c b/sources/c/main/print/error/rule/item.c index 11156ed..437ba63 100644 --- a/sources/c/main/print/error/rule/item.c +++ b/sources/c/main/print/error/rule/item.c @@ -7,9 +7,8 @@ extern "C" { #ifndef _di_controller_print_error_rule_item_ f_status_t controller_print_error_rule_item(fl_print_t * const print, controller_cache_action_t * const action, const uint8_t item, const f_status_t status) { - if (!print || !print->custom || !action) return F_status_set_error(F_output_not); + if (!print || !print->custom || !action || status == F_interrupt) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - if (status == F_interrupt) return F_status_set_error(F_output_not); controller_t * const main = (controller_t *) print->custom; @@ -96,6 +95,8 @@ extern "C" { controller_print_error_rule_cache(print, &cache->action, F_true); controller_unlock_print_flush(print->to, &main->thread); + + return F_okay; } #endif // _di_controller_print_error_rule_item_action_positive_number_not_ @@ -405,6 +406,11 @@ extern "C" { #ifndef _di_controller_print_error_rule_item_need_want_wish_ f_status_t controller_print_error_rule_item_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why) { + if (!print || !print->custom) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + controller_t * const main = (controller_t *) print->custom; + if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; fl_print_format("%r%[%QThe %r rule '%]", print->to, f_string_eol_s, print->context, print->prefix, need_want_wish, print->context); @@ -418,6 +424,11 @@ extern "C" { #ifndef _di_controller_print_error_rule_item_rule_not_loaded_ f_status_t controller_print_error_rule_item_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias) { + if (!print || !print->custom) return F_status_set_error(F_output_not); + if (print->verbosity < f_console_verbosity_error_e) return F_output_not; + + controller_t * const main = (controller_t *) print->custom; + if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); diff --git a/sources/c/main/rule/instance.c b/sources/c/main/rule/instance.c index f27fefd..749a056 100644 --- a/sources/c/main/rule/instance.c +++ b/sources/c/main/rule/instance.c @@ -24,17 +24,7 @@ extern "C" { break; default: - if (main->program.error.verbosity > f_console_verbosity_quiet_e) { - controller_lock_print(main->program.error.to, &main->thread); - - fl_print_format("%r%[%QUnsupported action type '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context); - fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, controller_convert_rule_action_type_string(instance->action), main->program.error.notable); - fl_print_format("%[' while attempting to execute rule.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s); - - controller_print_error_rule_cache(&main->program.error, &instance->cache.action, F_true); - - controller_unlock_print_flush(main->program.error.to, &main->thread); - } + controller_print_error_rule_action_type_supported_not(&main->program.error, &instance->cache.action, controller_convert_rule_action_type_string(instance->action)); return F_status_set_error(F_parameter); } @@ -444,47 +434,15 @@ extern "C" { } // for if (missing) { - if (main->program.error.verbosity > f_console_verbosity_quiet_e) { - controller_lock_print(main->program.error.to, &main->thread); - - if (instance->rule.items.used) { - fl_print_format("%r%[%QThe rule '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context); - fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, instance->rule.name, main->program.error.notable); - fl_print_format("%[' has no '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, controller_convert_rule_action_type_string(instance->action), main->program.error.notable); - fl_print_format("%[' action to execute.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s); - } - else { - fl_print_format("%r%[%QThe rule '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context); - fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, instance->rule.name, main->program.error.notable); - fl_print_format("%[ has no known '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format("%[%r %r%]", main->program.error.to, main->program.error.notable, controller_rule_s, controller_type_s, main->program.error.notable); - fl_print_format("%[' (such as '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_command_s, main->program.error.notable); - fl_print_format("%[', '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_service_s, main->program.error.notable); - fl_print_format("%[', '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_script_s, main->program.error.notable); - fl_print_format("%[', or '%]", main->program.error.to, main->program.error.context, main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_utility_s, main->program.error.notable); - fl_print_format("%[') to execute.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s); - } - - controller_print_error_rule_cache(&main->program.error, &instance->cache.action, F_true); - - controller_unlock_print_flush(main->program.error.to, &main->thread); - } - status = F_status_set_error(F_parameter); + + controller_print_error_rule_action_unknown_execute(&main->program.error, &instance->cache.action, instance->rule.name, controller_convert_rule_action_type_string(instance->action), instance->rule.items.used); } } if (F_status_is_error_not(status)) { status = controller_rule_execute(main, instance->action, instance->options, instance); - - if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) { - return status; - } + if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) return status; if (F_status_is_error(status)) { controller_print_error_rule_item(&main->program.error, &instance->cache.action, F_true, F_status_set_fine(status)); @@ -531,7 +489,7 @@ extern "C" { // Update the rule status, which is stored separately from the rule status for this instance. if (controller_rule_find(instance->rule.alias, main->process.rules, &id_rule) == F_true) { - controller_rule_t *rule = &main->process.rules.array[id_rule]; + controller_rule_t * const rule = &main->process.rules.array[id_rule]; rule->status[instance->action] = instance->rule.status[instance->action]; @@ -901,21 +859,12 @@ extern "C" { for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_thread_is_enabled_instance(instance); ++i) { if (instance->stack.array[i] == id_rule) { - if (instance->main->program.error.verbosity > f_console_verbosity_quiet_e) { - controller_lock_print(instance->main->program.error.to, &instance->main->thread); - - fl_print_format("%r%[%QThe rule '%]", instance->main->program.error.to, f_string_eol_s, instance->main->program.error.context, instance->main->program.error.prefix, instance->main->program.error.context); - fl_print_format(f_string_format_Q_single_s.string, instance->main->program.error.to, instance->main->program.error.notable, instance->rule.alias, instance->main->program.error.notable); - fl_print_format("%[' is already on the execution dependency stack, this recursion is prohibited.%]%r", instance->main->program.error.to, instance->main->program.error.context, instance->main->program.error.context, f_string_eol_s); - - controller_print_error_rule_cache(&instance->main->program.error, &instance->cache.action, F_true); - - controller_unlock_print_flush(instance->main->program.error.to, &instance->main->thread); - } // Never continue on circular recursion errors even in simulate mode. status = F_status_set_error(F_recurse); + controller_print_error_rule_stack_already(&instance->main->program.error, &instance->cache.action, instance->rule.alias, F_true); + break; } } // for -- 1.8.3.1