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.
/**
* 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 {
/**
* 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
* 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);
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);
fll_print_dynamic_raw(f_string_eol_s, main->error.to.stream);
}
- controller_main_delete(main);
-
return F_status_set_error(status);
}
}
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;
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;
}
controller_unlock_print_flush(main->output.to, 0);
- controller_main_delete(main);
-
return F_none;
}
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;
}
}
controller_setting_delete_simple(&setting);
- controller_main_delete(main);
if (status == F_child) {
return status;
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;
}
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.