This is a part of the traditional "init" process, such as those done in sysvinit or initng.
Unlike those, this only communicates with the "Controller" program to give the "Controller" program commands.
For the booting part of the process, see the "Init" program.
This is also intended to be control from service "Controller" program.
--- /dev/null
+#include "control.h"
+#include "private-control.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_control_print_help_
+ f_return_status control_print_help(const f_file_t output, const f_color_context_t context) {
+
+ fll_program_print_help_header(output, context, control_name_long, control_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, control_name, "");
+
+ return F_none;
+ }
+#endif // _di_control_print_help_
+
+#ifndef _di_control_main_
+ f_return_status control_main(const f_console_arguments_t arguments, control_data_t *data) {
+ f_status_t status = F_none;
+
+ {
+ const f_console_parameters_t parameters = f_macro_console_parameters_t_initialize(data->parameters, control_total_parameters);
+
+ {
+ f_console_parameter_id_t ids[3] = { control_parameter_no_color, control_parameter_light, control_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]);
+ }
+
+ control_delete_data(data);
+ return F_status_set_error(status);
+ }
+ }
+
+ // Identify priority of verbosity related parameters.
+ {
+ f_console_parameter_id_t ids[4] = { control_parameter_verbosity_quiet, control_parameter_verbosity_normal, control_parameter_verbosity_verbose, control_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)) {
+ control_delete_data(data);
+ return status;
+ }
+
+ if (choice == control_parameter_verbosity_quiet) {
+ data->error.verbosity = f_console_verbosity_quiet;
+ }
+ else if (choice == control_parameter_verbosity_normal) {
+ data->error.verbosity = f_console_verbosity_normal;
+ }
+ else if (choice == control_parameter_verbosity_verbose) {
+ data->error.verbosity = f_console_verbosity_verbose;
+ }
+ else if (choice == control_parameter_verbosity_debug) {
+ data->error.verbosity = f_console_verbosity_debug;
+ }
+ }
+
+ status = F_none;
+ }
+
+ if (data->parameters[control_parameter_help].result == f_console_result_found) {
+ control_print_help(data->output, data->context);
+
+ control_delete_data(data);
+ return F_none;
+ }
+
+ if (data->parameters[control_parameter_version].result == f_console_result_found) {
+ fll_program_print_version(data->output, control_version);
+
+ control_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]);
+ }
+ }
+
+ control_delete_data(data);
+ return status;
+ }
+#endif // _di_control_main_
+
+#ifndef _di_control_delete_data_
+ f_return_status control_delete_data(control_data_t *data) {
+
+ for (f_string_length_t i = 0; i < control_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_control_delete_data_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
--- /dev/null
+/**
+ * FLL - Level 3
+ *
+ * Project: Control
+ * API Version: 0.5
+ * Licenses: lgplv2.1
+ *
+ * This is the Control program.
+ *
+ * This program utilizes the Featureless Linux Library.
+ * This program is used to communicate with the "controller" program that exists as a system init (an alternative to sysvinit, initng, etc..).
+ */
+#ifndef _control_h
+
+// libc includes
+
+// fll-0 includes
+#include <level_0/type.h>
+#include <level_0/status.h>
+#include <level_0/memory.h>
+#include <level_0/string.h>
+#include <level_0/utf.h>
+#include <level_0/console.h>
+#include <level_0/directory.h>
+#include <level_0/file.h>
+#include <level_0/pipe.h>
+#include <level_0/print.h>
+
+// fll-1 includes
+#include <level_1/color.h>
+#include <level_1/console.h>
+#include <level_1/string.h>
+
+// fll-2 includes
+#include <level_2/error.h>
+#include <level_2/program.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_control_version_
+ #define control_major_version "0"
+ #define control_minor_version "5"
+ #define control_micro_version "2"
+ #define control_version control_major_version "." control_minor_version "." control_micro_version
+#endif // _di_control_version_
+
+#ifndef _di_control_name_
+ #define control_name "control"
+ #define control_name_long "Control Program"
+#endif // _di_control_name_
+
+#ifndef _di_control_defines_
+
+ enum {
+ control_parameter_help,
+ control_parameter_light,
+ control_parameter_dark,
+ control_parameter_no_color,
+ control_parameter_verbosity_quiet,
+ control_parameter_verbosity_normal,
+ control_parameter_verbosity_verbose,
+ control_parameter_verbosity_debug,
+ control_parameter_version,
+ };
+
+ #define control_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 control_total_parameters 9
+#endif // _di_control_defines_
+
+#ifndef _di_control_data_t_
+ typedef struct {
+ f_console_parameter_t parameters[control_total_parameters];
+
+ f_string_lengths_t remaining;
+ bool process_pipe;
+
+ f_file_t output;
+ fll_error_print_t error;
+
+ f_color_context_t context;
+ } control_data_t;
+
+ #define control_data_initialize \
+ { \
+ control_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_control_data_t_
+
+/**
+ * Print help.
+ *
+ * @param output
+ * The file to print to.
+ * @param context
+ * The color context settings.
+ *
+ * @return
+ * F_none on success.
+ */
+#ifndef _di_control_print_help_
+ extern f_return_status control_print_help(const f_file_t output, const f_color_context_t context);
+#endif // _di_control_print_help_
+
+/**
+ * Execute main program.
+ *
+ * Be sure to call control_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 control_delete_data()
+ */
+#ifndef _di_control_main_
+ extern f_return_status control_main(const f_console_arguments_t arguments, control_data_t *data);
+#endif // _di_control_main_
+
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing control_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * F_none on success.
+ *
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see control_main()
+ */
+#ifndef _di_control_delete_data_
+ extern f_return_status control_delete_data(control_data_t *data);
+#endif // _di_control_delete_data_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _control_h
--- /dev/null
+#include "control.h"
+
+int main(const unsigned long argc, const f_string_t *argv) {
+ const f_console_arguments_t arguments = { argc, argv };
+ control_data_t data = control_data_initialize;
+
+ if (f_pipe_input_exists()) {
+ data.process_pipe = F_true;
+ }
+
+ if (F_status_is_error(control_main(arguments, &data))) {
+ return 1;
+ }
+
+ return 0;
+}
--- /dev/null
+#include "control.h"
+#include "private-control.h"
--- /dev/null
+/**
+ * FLL - Level 3
+ *
+ * Project: Control
+ * API Version: 0.5
+ * Licenses: lgplv2.1
+ */
+#ifndef _PRIVATE_control_h
+#define _PRIVATE_control_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _PRIVATE_control_h
--- /dev/null
+# fss-0000
+
--- /dev/null
+# 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
--- /dev/null
+# fss-0001
+
+project_name control
+
+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 control.c private-control.c
+build_sources_program main.c
+build_sources_headers control.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