From: Kevin Day Date: Thu, 31 Mar 2022 03:42:23 +0000 (-0500) Subject: Update: Partially move program data into the main for controller. X-Git-Tag: 0.5.9~16 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=28d79c7508a2a290aedb75f1295cb7a194320541;p=fll Update: Partially move program data into the main for controller. This does not use fll_program_data. The controller needs a more complex structure than the one provided by fll_program_data. The parts that can be moved are moved to be more consistent with other FLL provided programs. --- diff --git a/level_3/controller/c/common.h b/level_3/controller/c/common.h index 247b87f..2de0e39 100644 --- a/level_3/controller/c/common.h +++ b/level_3/controller/c/common.h @@ -324,14 +324,22 @@ extern "C" { /** * The main program data. * - * parameters: The state of pre-defined parameters passed to the program. - * remaining: The remaining, non-pre-defined parameters, passed to the program. - * process_pipe: Designate whether or not to process the input pipe. - * output: The output file for general printing. - * error: The output file for error printing. - * warning: The output file for warning printing. - * signal: The process signal management structure. - * context: The color context. + * child: Reserved for a child process, often representing the child return status or the child process ID. + * context: The color context. + * default_path_setting: The default setting path. + * default_path_pid: The default PID file path. + * default_path_socket: The default socket file path. + * error: The output file for error printing. + * as_init: Designate whether or not this is running as an init program. + * output: The output file for general printing. + * parameters: The state of pre-defined parameters passed to the program. + * pid: The PID of the program. + * process_pipe: Designate whether or not to process the input pipe. + * program_name: The name of the program. + * program_name_long: The long name of the program. + * signal: The process signal management structure. + * umask: The umask settings, needed for avoiding calls to umask() to read the current umask. + * warning: The output file for warning printing. */ #ifndef _di_controller_main_t_ typedef struct { @@ -620,8 +628,6 @@ extern "C" { /** * Deallocate main. * - * Be sure to call this after executing controller_main(). - * * If main.signal is non-zero, then this blocks and handles the following signals: * - F_signal_abort * - F_signal_broken_pipe @@ -637,8 +643,6 @@ extern "C" { * F_none on success. * * Status codes (with error bit) are returned on any problem. - * - * @see controller_main() */ #ifndef _di_controller_main_delete_ extern f_status_t controller_main_delete(controller_main_t * const main); diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 583e33a..ee4560c 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -68,10 +68,6 @@ extern "C" { f_status_t status = F_none; - f_console_parameter_t parameters[] = controller_console_parameter_t_initialize; - main->parameters.array = parameters; - main->parameters.used = controller_total_parameters_d; - { f_console_parameter_id_t ids[3] = { controller_parameter_no_color_e, controller_parameter_light_e, controller_parameter_dark_e }; const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 3); @@ -104,8 +100,6 @@ extern "C" { fll_print_dynamic_raw(f_string_eol_s, main->error.to.stream); } - controller_main_delete(main); - return F_status_set_error(status); } } @@ -117,12 +111,7 @@ extern "C" { const f_console_parameter_ids_t choices = macro_f_console_parameter_ids_t_initialize(ids, 4); status = f_console_parameter_prioritize_right(main->parameters, choices, &choice); - - if (F_status_is_error(status)) { - controller_main_delete(main); - - return status; - } + if (F_status_is_error(status)) return status; if (choice == controller_parameter_verbosity_quiet_e) { main->output.verbosity = f_console_verbosity_quiet_e; @@ -153,8 +142,6 @@ extern "C" { if (main->parameters.array[controller_parameter_help_e].result == f_console_result_found_e) { controller_print_help(main); - controller_main_delete(main); - return F_none; } @@ -165,8 +152,6 @@ extern "C" { controller_unlock_print_flush(main->output.to, 0); - controller_main_delete(main); - return F_none; } @@ -189,8 +174,6 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_string_dynamic_append", F_true); - controller_main_delete(main); - return status; } @@ -470,7 +453,6 @@ extern "C" { } controller_setting_delete_simple(&setting); - controller_main_delete(main); if (status == F_child) { return status; diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c index 376f31b..4c31e5a 100644 --- a/level_3/controller/c/main.c +++ b/level_3/controller/c/main.c @@ -5,6 +5,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize(argc, argv, envp); controller_main_t data = controller_main_t_initialize; + f_console_parameter_t parameters[] = controller_console_parameter_t_initialize; + data.parameters.array = parameters; + data.parameters.used = controller_total_parameters_d; + if (f_pipe_input_exists()) { data.process_pipe = F_true; } @@ -34,6 +38,8 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { const f_status_t status = controller_main(&data, &arguments); + controller_main_delete(&data); + fll_program_standard_setdown(&data.signal); // When the child process exits, it must return the code to the parent so the parent knows how to handle the exit.