From: Kevin Day Date: Thu, 5 Nov 2020 03:10:06 +0000 (-0600) Subject: Feature: Stub out the Controller program. X-Git-Tag: 0.5.2~87 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c1876d944dc6c81729eae1fad9cd9d590f04f6a0;p=fll Feature: Stub out the Controller program. This is a part of the traditional "init" process, such as those done in sysvinit or initng. Unlike those, this only performs tasks and manages services. For the booting part of the process, see the "Init" program. This is also intended to be controlled from user space via the "Control" program. --- diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c new file mode 100644 index 0000000..74daabc --- /dev/null +++ b/level_3/controller/c/controller.c @@ -0,0 +1,133 @@ +#include "controller.h" +#include "private-controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_print_help_ + f_return_status controller_print_help(const f_file_t output, const f_color_context_t context) { + + fll_program_print_help_header(output, context, controller_name_long, controller_version); + + fll_program_print_help_option(output, context, f_console_standard_short_help, f_console_standard_long_help, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print this help message."); + fll_program_print_help_option(output, context, f_console_standard_short_dark, f_console_standard_long_dark, f_console_symbol_short_disable, f_console_symbol_long_disable, " Output using colors that show up better on dark backgrounds."); + fll_program_print_help_option(output, context, f_console_standard_short_light, f_console_standard_long_light, f_console_symbol_short_disable, f_console_symbol_long_disable, " Output using colors that show up better on light backgrounds."); + fll_program_print_help_option(output, context, f_console_standard_short_no_color, f_console_standard_long_no_color, f_console_symbol_short_disable, f_console_symbol_long_disable, "Do not output in color."); + fll_program_print_help_option(output, context, f_console_standard_short_quiet, f_console_standard_long_quiet, f_console_symbol_short_disable, f_console_symbol_long_disable, " Decrease verbosity beyond normal output."); + fll_program_print_help_option(output, context, f_console_standard_short_normal, f_console_standard_long_normal, f_console_symbol_short_disable, f_console_symbol_long_disable, " Set verbosity to normal output."); + fll_program_print_help_option(output, context, f_console_standard_short_verbose, f_console_standard_long_verbose, f_console_symbol_short_disable, f_console_symbol_long_disable, " Increase verbosity beyond normal output."); + fll_program_print_help_option(output, context, f_console_standard_short_debug, f_console_standard_long_debug, f_console_symbol_short_disable, f_console_symbol_long_disable, " Enable debugging, inceasing verbosity beyond normal output."); + fll_program_print_help_option(output, context, f_console_standard_short_version, f_console_standard_long_version, f_console_symbol_short_disable, f_console_symbol_long_disable, " Print only the version number."); + + fll_program_print_help_usage(output, context, controller_name, ""); + + return F_none; + } +#endif // _di_controller_print_help_ + +#ifndef _di_controller_main_ + f_return_status controller_main(const f_console_arguments_t arguments, controller_data_t *data) { + f_status_t status = F_none; + + { + const f_console_parameters_t parameters = f_macro_console_parameters_t_initialize(data->parameters, controller_total_parameters); + + { + f_console_parameter_id_t ids[3] = { controller_parameter_no_color, controller_parameter_light, controller_parameter_dark }; + const f_console_parameter_ids_t choices = f_macro_console_parameter_ids_t_initialize(ids, 3); + + status = fll_program_parameter_process(arguments, parameters, choices, F_true, &data->remaining, &data->context); + + data->error.context = data->context.set.error; + data->error.notable = data->context.set.notable; + + if (F_status_is_error(status)) { + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "fll_program_parameter_process", F_true); + fprintf(data->error.to.stream, "%c", f_string_eol[0]); + } + + controller_delete_data(data); + return F_status_set_error(status); + } + } + + // Identify priority of verbosity related parameters. + { + f_console_parameter_id_t ids[4] = { controller_parameter_verbosity_quiet, controller_parameter_verbosity_normal, controller_parameter_verbosity_verbose, controller_parameter_verbosity_debug }; + f_console_parameter_id_t choice = 0; + const f_console_parameter_ids_t choices = f_macro_console_parameter_ids_t_initialize(ids, 4); + + status = f_console_parameter_prioritize_right(parameters, choices, &choice); + + if (F_status_is_error(status)) { + controller_delete_data(data); + return status; + } + + if (choice == controller_parameter_verbosity_quiet) { + data->error.verbosity = f_console_verbosity_quiet; + } + else if (choice == controller_parameter_verbosity_normal) { + data->error.verbosity = f_console_verbosity_normal; + } + else if (choice == controller_parameter_verbosity_verbose) { + data->error.verbosity = f_console_verbosity_verbose; + } + else if (choice == controller_parameter_verbosity_debug) { + data->error.verbosity = f_console_verbosity_debug; + } + } + + status = F_none; + } + + if (data->parameters[controller_parameter_help].result == f_console_result_found) { + controller_print_help(data->output, data->context); + + controller_delete_data(data); + return F_none; + } + + if (data->parameters[controller_parameter_version].result == f_console_result_found) { + fll_program_print_version(data->output, controller_version); + + controller_delete_data(data); + return F_none; + } + + // @todo + + // ensure a newline is always put at the end of the program execution, unless in quiet mode. + if (data->error.verbosity != f_console_verbosity_quiet) { + if (F_status_is_error(status)) { + fprintf(data->error.to.stream, "%c", f_string_eol[0]); + } + } + + controller_delete_data(data); + return status; + } +#endif // _di_controller_main_ + +#ifndef _di_controller_delete_data_ + f_return_status controller_delete_data(controller_data_t *data) { + + for (f_string_length_t i = 0; i < controller_total_parameters; i++) { + f_macro_string_lengths_t_delete_simple(data->parameters[i].locations); + f_macro_string_lengths_t_delete_simple(data->parameters[i].locations_sub); + f_macro_string_lengths_t_delete_simple(data->parameters[i].values); + } // for + + f_macro_string_lengths_t_delete_simple(data->remaining); + + f_macro_color_context_t_delete_simple(data->context); + + return F_none; + } +#endif // _di_controller_delete_data_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/controller/c/controller.h b/level_3/controller/c/controller.h new file mode 100644 index 0000000..7f069bf --- /dev/null +++ b/level_3/controller/c/controller.h @@ -0,0 +1,168 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.5 + * Licenses: lgplv2.1 + * + * This is the Controller program. + * + * This program utilizes the Featureless Linux Library. + * This program provides system service management, much like sysvcontroller and controllerng. + * This program can be controlled from user-space via the "control" program. + */ +#ifndef _controller_h + +// libc includes + +// fll-0 includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// fll-1 includes +#include +#include +#include + +// fll-2 includes +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_version_ + #define controller_major_version "0" + #define controller_minor_version "5" + #define controller_micro_version "2" + #define controller_version controller_major_version "." controller_minor_version "." controller_micro_version +#endif // _di_controller_version_ + +#ifndef _di_controller_name_ + #define controller_name "controller" + #define controller_name_long "Controller Program" +#endif // _di_controller_name_ + +#ifndef _di_controller_defines_ + + enum { + controller_parameter_help, + controller_parameter_light, + controller_parameter_dark, + controller_parameter_no_color, + controller_parameter_verbosity_quiet, + controller_parameter_verbosity_normal, + controller_parameter_verbosity_verbose, + controller_parameter_verbosity_debug, + controller_parameter_version, + }; + + #define controller_console_parameter_t_initialize \ + { \ + f_console_parameter_t_initialize(f_console_standard_short_help, f_console_standard_long_help, 0, 0, f_console_type_normal), \ + f_console_parameter_t_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_dark, f_console_standard_long_dark, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_quiet, f_console_standard_long_quiet, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_normal, f_console_standard_long_normal, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_verbose, f_console_standard_long_verbose, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_debug, f_console_standard_long_debug, 0, 0, f_console_type_inverse), \ + f_console_parameter_t_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_console_type_inverse), \ + } + + #define controller_total_parameters 9 +#endif // _di_controller_defines_ + +#ifndef _di_controller_data_t_ + typedef struct { + f_console_parameter_t parameters[controller_total_parameters]; + + f_string_lengths_t remaining; + bool process_pipe; + + f_file_t output; + fll_error_print_t error; + + f_color_context_t context; + } controller_data_t; + + #define controller_data_initialize \ + { \ + controller_console_parameter_t_initialize, \ + f_string_lengths_t_initialize, \ + F_false, \ + f_macro_file_t_initialize(f_type_output, f_type_descriptor_output, f_file_flag_write_only), \ + fll_error_print_t_initialize, \ + f_color_context_t_initialize, \ + } +#endif // _di_controller_data_t_ + +/** + * Print help. + * + * @param output + * The file to print to. + * @param context + * The color context settings. + * + * @return + * F_none on success. + */ +#ifndef _di_controller_print_help_ + extern f_return_status controller_print_help(const f_file_t output, const f_color_context_t context); +#endif // _di_controller_print_help_ + +/** + * Execute main program. + * + * Be sure to call controller_delete_data() after executing this. + * + * @param arguments + * The parameters passed to the process. + * @param data + * The program data. + * + * @return + * F_none on success. + * + * Status codes (with error bit) are returned on any problem. + * + * @see controller_delete_data() + */ +#ifndef _di_controller_main_ + extern f_return_status controller_main(const f_console_arguments_t arguments, controller_data_t *data); +#endif // _di_controller_main_ + +/** + * Deallocate data. + * + * Be sure to call this after executing controller_main(). + * + * @param data + * The program data. + * + * @return + * F_none on success. + * + * Status codes (with error bit) are returned on any problem. + * + * @see controller_main() + */ +#ifndef _di_controller_delete_data_ + extern f_return_status controller_delete_data(controller_data_t *data); +#endif // _di_controller_delete_data_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_h diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c new file mode 100644 index 0000000..affca75 --- /dev/null +++ b/level_3/controller/c/main.c @@ -0,0 +1,16 @@ +#include "controller.h" + +int main(const unsigned long argc, const f_string_t *argv) { + const f_console_arguments_t arguments = { argc, argv }; + controller_data_t data = controller_data_initialize; + + if (f_pipe_input_exists()) { + data.process_pipe = F_true; + } + + if (F_status_is_error(controller_main(arguments, &data))) { + return 1; + } + + return 0; +} diff --git a/level_3/controller/c/private-controller.c b/level_3/controller/c/private-controller.c new file mode 100644 index 0000000..fbcc4b8 --- /dev/null +++ b/level_3/controller/c/private-controller.c @@ -0,0 +1,2 @@ +#include "controller.h" +#include "private-controller.h" diff --git a/level_3/controller/c/private-controller.h b/level_3/controller/c/private-controller.h new file mode 100644 index 0000000..c69c3a4 --- /dev/null +++ b/level_3/controller/c/private-controller.h @@ -0,0 +1,19 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.5 + * Licenses: lgplv2.1 + */ +#ifndef _PRIVATE_controller_h +#define _PRIVATE_controller_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_controller_h diff --git a/level_3/controller/data/build/defines b/level_3/controller/data/build/defines new file mode 100644 index 0000000..c665317 --- /dev/null +++ b/level_3/controller/data/build/defines @@ -0,0 +1,2 @@ +# fss-0000 + diff --git a/level_3/controller/data/build/dependencies b/level_3/controller/data/build/dependencies new file mode 100644 index 0000000..3b53a6c --- /dev/null +++ b/level_3/controller/data/build/dependencies @@ -0,0 +1,18 @@ +# fss-0000 + +f_type +f_status +f_memory +f_string +f_utf +f_color +f_console +f_file +f_pipe +f_print +fl_color +fl_console +fl_string +fll_error +fll_program +fll_status diff --git a/level_3/controller/data/build/settings b/level_3/controller/data/build/settings new file mode 100644 index 0000000..72c9bc7 --- /dev/null +++ b/level_3/controller/data/build/settings @@ -0,0 +1,57 @@ +# fss-0001 + +project_name controller + +version_major 0 +version_minor 5 +version_micro 2 +version_target major + +environment + +process_pre +process_post + +modes individual level monolithic +modes_default monolithic + +build_compiler gcc +build_indexer ar +build_language c +build_libraries -lc +build_libraries-individual -lfll_error -lfll_program -lfll_status -lfl_color -lfl_console -lfl_status -lfl_string -lf_console -lf_conversion -lf_file -lf_memory -lf_pipe -lf_print -lf_utf +build_libraries-level -lfll_2 -lfll_1 -lfll_0 +build_libraries-monolithic -lfll +build_sources_library controller.c private-controller.c +build_sources_program main.c +build_sources_headers controller.h +build_sources_script +build_sources_setting +build_script yes +build_shared yes +build_static yes + +path_headers level_3 +path_headers_preserve no +path_library_script script +path_library_shared shared +path_library_static static +path_program_script script +path_program_shared shared +path_program_static static +path_sources +path_standard yes + +search_exclusive yes +search_shared yes +search_static yes + +defines_all +defines_static +defines_shared + +flags_all -z now -g -fdiagnostics-color=always +flags_shared +flags_static +flags_library -fPIC +flags_program -fPIE