Simplify the parameters being passed to functions by providing a helper structure called f_console_arguments to handle the argc and argv standard arguments.
Due to being standard arguments, I am leaving the names as 'argc' and 'argv' despite it being a violation of the naming policy of this project.
('argc' should be something like 'used', and 'argv' should be 'arguments'.)
The firewall had a naming conflict, so rename the usage of "arguments" in firewall into "parameters".
#endif // _di_f_console_parameter_id_
/**
+ * Provide a helper structure for referencing the argc and argv standard main arguments.
+ *
+ * This is intended to only store the argc and argv and should not be treated as dynamic.
+ *
+ * No structure initializer is provided due to the use of constant properties.
+ */
+#ifndef _di_f_console_arguments_
+ typedef struct {
+ const int argc;
+ const f_string *argv;
+ } f_console_arguments;
+#endif // _di_f_console_arguments_
+
+/**
* Determine the type code the given input parameter represents.
*
* @param input
#endif
#ifndef _di_fl_console_parameter_process_
- f_return_status fl_console_parameter_process(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining) {
+ f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining) {
#ifndef _di_level_1_parameter_checking_
if (remaining == 0) return f_status_set_error(f_invalid_parameter);
#endif // _di_level_1_parameter_checking_
f_string_lengths needs_additional = f_string_lengths_initialize;
// loop through and read all parameters
- while (location < argc) {
- f_console_identify(argv[location], &result);
+ while (location < arguments.argc) {
+ f_console_identify(arguments.argv[location], &result);
- string_length = strnlen(argv[location], f_console_max_size);
+ string_length = strnlen(arguments.argv[location], f_console_max_size);
// process the current parameter
if (result == f_console_short_enable || result == f_console_short_disable) {
continue;
}
- if (strncmp(&argv[location][sub_location], parameters[parameter_counter].symbol_short, increment_by + 1) != 0) {
+ if (strncmp(&arguments.argv[location][sub_location], parameters[parameter_counter].symbol_short, increment_by + 1) != 0) {
continue;
}
}
continue;
}
- if (strncmp(&argv[location][sub_location], parameters[parameter_counter].symbol_long, increment_by + 1) != 0) {
+ if (strncmp(&arguments.argv[location][sub_location], parameters[parameter_counter].symbol_long, increment_by + 1) != 0) {
continue;
}
}
continue;
}
- if (strncmp(argv[location], parameters[parameter_counter].symbol_other, string_length + 1) != 0) {
+ if (strncmp(arguments.argv[location], parameters[parameter_counter].symbol_other, string_length + 1) != 0) {
continue;
}
*
* The UTF-8 BOM is not allowed in the parameters.
*
- * @param argc
- * The number of parameters passed to the process.
- * @param argv
+ * @param arguments
* The parameters passed to the process.
* @param parameters
* The console parameters to look for.
* f_reallocation_error (with error bit) on memory reallocation error.
*/
#ifndef _di_fl_console_parameter_process_
- extern f_return_status fl_console_parameter_process(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining);
+ extern f_return_status fl_console_parameter_process(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, f_string_lengths *remaining);
#endif // _di_fl_console_parameter_process_
/**
#endif // _di_fll_program_print_version_
#ifndef _di_fll_program_process_parameters_
- f_return_status fll_program_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context) {
+ f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context) {
f_status status = f_none;
f_status allocation_status = f_none;
- status = fl_console_parameter_process(argc, argv, parameters, parameters_total, remaining);
+ status = fl_console_parameter_process(arguments, parameters, parameters_total, remaining);
f_console_parameter_ids choices = f_console_parameter_ids_initialize;
f_console_parameter_id decision = parameter_dark;
/**
* Perform basic parameter loading, including initialization of color context and printing errors.
*
- * @param argc
- * The number of parameters passed to the process.
- * @param argv
+ * @param arguments
* The parameters passed to the process.
* @param parameters
* The console parameters to look for.
* f_reallocation_error (with error bit) on memory reallocation error.
*/
#ifndef _di_fll_program_process_parameters_
- extern f_return_status fll_program_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context);
+ extern f_return_status fll_program_process_parameters(const f_console_arguments arguments, f_console_parameter parameters[], const f_array_length parameters_total, const f_array_length parameter_no_color, const f_array_length parameter_light, const f_array_length parameter_dark, f_string_lengths *remaining, fl_color_context *context);
#endif // _di_fll_program_process_parameters_
#ifdef __cplusplus
#endif // _di_bit_dump_print_help_
#ifndef _di_bit_dump_main_
- f_return_status bit_dump_main(const f_array_length argc, const f_string argv[], bit_dump_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, bit_dump_total_parameters, bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark, &data->remaining, &data->context);
+ f_return_status bit_dump_main(const f_console_arguments arguments, bit_dump_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, bit_dump_total_parameters, bit_dump_parameter_no_color, bit_dump_parameter_light, bit_dump_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
bit_dump_delete_data(data);
return f_status_set_error(status);
}
else if (data->parameters[bit_dump_parameter_width].result == f_console_result_additional) {
- uint64_t number = atoll(argv[data->parameters[bit_dump_parameter_width].additional.array[0]]);
+ uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_width].additional.array[0]]);
if (number < 1 || number >= 0xfb) {
fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Width option can only be a number between 0 and 251.");
return f_status_set_error(status);
}
else if (data->parameters[bit_dump_parameter_first].result == f_console_result_additional) {
- uint64_t number = atoll(argv[data->parameters[bit_dump_parameter_first].additional.array[0]]);
+ uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_first].additional.array[0]]);
if (number < 1 || number >= 0xffffffffffffffff) {
fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "First option can only be a number between 0 and 18446744073709551615.");
return f_status_set_error(status);
}
else if (data->parameters[bit_dump_parameter_last].result == f_console_result_additional) {
- uint64_t number = atoll(argv[data->parameters[bit_dump_parameter_last].additional.array[0]]);
+ uint64_t number = atoll(arguments.argv[data->parameters[bit_dump_parameter_last].additional.array[0]]);
if (number < 1 || number >= 0xffffffffffffffff) {
fl_color_print_line(f_standard_output, data->context.error, data->context.reset, "Last option can only be a number between 0 and 18446744073709551615.");
f_status missing_files = f_none;
for (f_array_length counter = 0; counter < data->remaining.used; counter++) {
- status = f_file_exists(argv[data->remaining.array[counter]]);
+ status = f_file_exists(arguments.argv[data->remaining.array[counter]]);
if (status == f_false || f_status_is_error(status)) {
if (missing_files == f_none) {
missing_files = status;
}
- bit_dump_print_file_error(data->context, status, "f_file_exists", argv[data->remaining.array[counter]]);
+ bit_dump_print_file_error(data->context, status, "f_file_exists", arguments.argv[data->remaining.array[counter]]);
}
} // for
for (f_array_length counter = 0; counter < data->remaining.used; counter++) {
f_file file = f_file_initialize;
- status = f_file_open(&file, argv[data->remaining.array[counter]]);
+ status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]);
if (f_status_is_error(status)) {
- bit_dump_print_file_error(data->context, status, "f_file_open", argv[data->remaining.array[counter]]);
+ bit_dump_print_file_error(data->context, status, "f_file_open", arguments.argv[data->remaining.array[counter]]);
bit_dump_delete_data(data);
return status;
}
printf("%c", f_string_eol);
fl_color_print(f_standard_output, data->context.title, data->context.reset, "Byte Dump of: ");
- fl_color_print_line(f_standard_output, data->context.notable, data->context.reset, "%s", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_output, data->context.notable, data->context.reset, "%s", arguments.argv[data->remaining.array[counter]]);
- status = bit_dump_file(*data, argv[data->remaining.array[counter]], file);
+ status = bit_dump_file(*data, arguments.argv[data->remaining.array[counter]], file);
f_file_close(&file);
*
* Be sure to call bit_dump_delete_data() after executing this.
*
- * @param argc
- * The number of parameters passed to the process.
- * @param argv
+ * @param arguments
* The parameters passed to the process.
* @param data
* The program data.
* @see bit_dump_delete_data()
*/
#ifndef _di_bit_dump_main_
- extern f_return_status bit_dump_main(const f_array_length argc, const f_string argv[], bit_dump_data *data);
+ extern f_return_status bit_dump_main(const f_console_arguments arguments, bit_dump_data *data);
#endif // _di_bit_dump_main_
/**
#include <level_3/bit_dump.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
bit_dump_data data = bit_dump_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- f_status status = bit_dump_main(argc, argv, &data);
+ f_status status = bit_dump_main(arguments, &data);
if (f_status_is_error(status)) {
return 1;
#endif // _di_firewall_print_help_
#ifndef _di_firewall_main_
- f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, firewall_total_parameters, firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark, &data->remaining, &data->context);
+ f_return_status firewall_main(const f_console_arguments arguments, firewall_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, firewall_total_parameters, firewall_parameter_no_color, firewall_parameter_light, firewall_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
firewall_delete_data(data);
f_bool show_mangle = f_true;
f_bool show_ports = f_true;
- f_string_dynamics arguments = f_string_dynamics_initialize;
+ f_string_dynamics parameters = f_string_dynamics_initialize;
f_s_int results = 0;
if (data->remaining.used > 0) {
f_string_length counter = 0;
for (; counter < data->remaining.used; counter++) {
- if (strncmp("nat", argv[data->remaining.array[counter]], 4) != 0) {
- if (strncmp("mangle", argv[data->remaining.array[counter]], 7) != 0) {
- if (strncmp("ports", argv[data->remaining.array[counter]], 6) != 0) {
- fl_color_print_line(f_standard_warning, data->context.warning, data->context.reset, "WARNING: '%s' is not a valid show option", argv[data->remaining.array[counter]]);
+ if (strncmp("nat", arguments.argv[data->remaining.array[counter]], 4) != 0) {
+ if (strncmp("mangle", arguments.argv[data->remaining.array[counter]], 7) != 0) {
+ if (strncmp("ports", arguments.argv[data->remaining.array[counter]], 6) != 0) {
+ fl_color_print_line(f_standard_warning, data->context.warning, data->context.reset, "WARNING: '%s' is not a valid show option", arguments.argv[data->remaining.array[counter]]);
}
else {
show_ports = f_true;
} // for
}
- f_macro_string_dynamics_resize(status, arguments, 7);
+ f_macro_string_dynamics_resize(status, parameters, 7);
if (f_status_is_error(status)) {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory");
fl_color_print_line(f_standard_output, data->context.standout, data->context.reset, " ============================");
fflush(f_standard_output);
- arguments.used = 6;
+ parameters.used = 6;
- arguments.array[0].string = (f_string) "-x";
- arguments.array[1].string = (f_string) "-v";
- arguments.array[2].string = (f_string) "-t";
- arguments.array[3].string = (f_string) "nat";
- arguments.array[4].string = (f_string) "--numeric";
- arguments.array[5].string = (f_string) "--list";
+ parameters.array[0].string = (f_string) "-x";
+ parameters.array[1].string = (f_string) "-v";
+ parameters.array[2].string = (f_string) "-t";
+ parameters.array[3].string = (f_string) "nat";
+ parameters.array[4].string = (f_string) "--numeric";
+ parameters.array[5].string = (f_string) "--list";
- arguments.array[0].used = 2;
- arguments.array[1].used = 2;
- arguments.array[2].used = 2;
- arguments.array[3].used = 3;
- arguments.array[4].used = 9;
- arguments.array[5].used = 6;
+ parameters.array[0].used = 2;
+ parameters.array[1].used = 2;
+ parameters.array[2].used = 2;
+ parameters.array[3].used = 3;
+ parameters.array[4].used = 9;
+ parameters.array[5].used = 6;
- status = fll_execute_program((f_string) firewall_tool_iptables, arguments, &results);
+ status = fll_execute_program((f_string) firewall_tool_iptables, parameters, &results);
fprintf(f_standard_output, "\n");
fflush(f_standard_output);
fl_color_print_line(f_standard_output, data->context.standout, data->context.reset, " ==========================");
fflush(f_standard_output);
- arguments.used = 6;
+ parameters.used = 6;
- arguments.array[0].string = (f_string) "-x";
- arguments.array[1].string = (f_string) "-v";
- arguments.array[2].string = (f_string) "-t";
- arguments.array[3].string = (f_string) "mangle";
- arguments.array[4].string = (f_string) "--numeric";
- arguments.array[5].string = (f_string) "--list";
+ parameters.array[0].string = (f_string) "-x";
+ parameters.array[1].string = (f_string) "-v";
+ parameters.array[2].string = (f_string) "-t";
+ parameters.array[3].string = (f_string) "mangle";
+ parameters.array[4].string = (f_string) "--numeric";
+ parameters.array[5].string = (f_string) "--list";
- arguments.array[0].used = 2;
- arguments.array[1].used = 2;
- arguments.array[2].used = 2;
- arguments.array[3].used = 6;
- arguments.array[4].used = 9;
- arguments.array[5].used = 6;
+ parameters.array[0].used = 2;
+ parameters.array[1].used = 2;
+ parameters.array[2].used = 2;
+ parameters.array[3].used = 6;
+ parameters.array[4].used = 9;
+ parameters.array[5].used = 6;
- status = fll_execute_program((f_string) firewall_tool_iptables, arguments, &results);
+ status = fll_execute_program((f_string) firewall_tool_iptables, parameters, &results);
fprintf(f_standard_output, "\n");
fflush(f_standard_output);
fl_color_print_line(f_standard_output, data->context.standout, data->context.reset, " ==========================");
fflush(f_standard_output);
- arguments.used = 4;
+ parameters.used = 4;
- arguments.array[0].string = (f_string) "-x";
- arguments.array[1].string = (f_string) "-v";
- arguments.array[2].string = (f_string) "--numeric";
- arguments.array[3].string = (f_string) "--list";
+ parameters.array[0].string = (f_string) "-x";
+ parameters.array[1].string = (f_string) "-v";
+ parameters.array[2].string = (f_string) "--numeric";
+ parameters.array[3].string = (f_string) "--list";
- arguments.array[0].used = 2;
- arguments.array[1].used = 2;
- arguments.array[2].used = 9;
- arguments.array[3].used = 6;
+ parameters.array[0].used = 2;
+ parameters.array[1].used = 2;
+ parameters.array[2].used = 9;
+ parameters.array[3].used = 6;
- status = fll_execute_program((f_string) firewall_tool_iptables, arguments, &results);
+ status = fll_execute_program((f_string) firewall_tool_iptables, parameters, &results);
fprintf(f_standard_output, "\n");
fflush(f_standard_output);
fl_color_print_code(f_standard_error, data->context.error);
fprintf(f_standard_error, "%s ", firewall_tool_iptables);
- for (; i < arguments.used; i++) {
- fprintf(f_standard_error, "%s ", arguments.array[i].string);
+ for (; i < parameters.used; i++) {
+ fprintf(f_standard_error, "%s ", parameters.array[i].string);
} // for
fl_color_print_code(f_standard_error, data->context.reset);
status = f_status_set_error(status);
}
- arguments.array[0].string = 0;
- arguments.array[1].string = 0;
- arguments.array[2].string = 0;
- arguments.array[3].string = 0;
- arguments.array[4].string = 0;
- arguments.array[5].string = 0;
- arguments.array[6].string = 0;
- arguments.array[0].used = 0;
- arguments.array[1].used = 0;
- arguments.array[2].used = 0;
- arguments.array[3].used = 0;
- arguments.array[4].used = 0;
- arguments.array[5].used = 0;
- arguments.array[6].used = 0;
-
- f_macro_string_dynamics_delete(status, arguments);
+ parameters.array[0].string = 0;
+ parameters.array[1].string = 0;
+ parameters.array[2].string = 0;
+ parameters.array[3].string = 0;
+ parameters.array[4].string = 0;
+ parameters.array[5].string = 0;
+ parameters.array[6].string = 0;
+ parameters.array[0].used = 0;
+ parameters.array[1].used = 0;
+ parameters.array[2].used = 0;
+ parameters.array[3].used = 0;
+ parameters.array[4].used = 0;
+ parameters.array[5].used = 0;
+ parameters.array[6].used = 0;
+
+ f_macro_string_dynamics_delete(status, parameters);
firewall_delete_local_data(&local);
firewall_delete_data(data);
return status;
}
#endif // _di_firewall_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_firewall_print_help_
- /**
- * Print help.
- */
extern f_return_status firewall_print_help(const firewall_data data);
#endif // _di_firewall_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call firewall_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 firewall_delete_data()
+ */
#ifndef _di_firewall_main_
- /**
- * Main.
- */
- extern f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data);
+ extern f_return_status firewall_main(const f_console_arguments arguments, firewall_data *data);
#endif // _di_firewall_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing firewall_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see firewall_main()
+ */
#ifndef _di_firewall_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status firewall_delete_data(firewall_data *data);
#endif // _di_firewall_delete_data_
#include <level_0/status.h>
#include <level_3/firewall.h>
-int main(const f_s_int argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
firewall_data data = firewall_data_initialize;
- if (f_status_is_error(firewall_main(argc, argv, &data))) {
+ if (f_status_is_error(firewall_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_basic_list_read_print_help_
#ifndef _di_fss_basic_list_read_main_
- f_return_status fss_basic_list_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal")));
+ f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal")));
- f_return_status fss_basic_list_read_main(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_basic_list_read_total_parameters, fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_basic_list_read_main(const f_console_arguments arguments, fss_basic_list_read_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_list_read_total_parameters, fss_basic_list_read_parameter_no_color, fss_basic_list_read_parameter_light, fss_basic_list_read_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_basic_list_read_delete_data(data);
f_string_length original_size = data->file_position.total_elements;
if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) {
- target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_count].additional.array[0]]);
+ target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_count].additional.array[0]]);
}
if (data->process_pipe) {
return status;
}
- status = fss_basic_list_read_main_process_file(argc, argv, data, "-", target);
+ status = fss_basic_list_read_main_process_file(arguments, data, "-", target);
if (f_status_is_error(status)) {
return status;
for (; counter < data->remaining.used; counter++) {
f_file file = f_file_initialize;
- status = f_file_open(&file, argv[data->remaining.array[counter]]);
+ status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]);
data->file_position.total_elements = original_size;
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()");
}
else if (status == f_overflow) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_not_open) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_seek_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_read_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_allocation_error || status == f_reallocation_error) {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory");
return f_status_set_error(status);
}
- status = fss_basic_list_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target);
+ status = fss_basic_list_read_main_process_file(arguments, data, arguments.argv[data->remaining.array[counter]], target);
if (f_status_is_error(status)) {
return status;
return status;
}
- f_return_status fss_basic_list_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data, const f_string filename, const f_string_length target) {
+ f_return_status fss_basic_list_read_main_process_file(const f_console_arguments arguments, fss_basic_list_read_data *data, const f_string filename, const f_string_length target) {
f_status status = f_none;
f_status status2 = f_none;
if (data->contents.array[current].used > 0) {
f_string_length counter = data->contents.array[current].array[0].start;
f_string_length position = 0;
- f_string_length target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
+ f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
f_string_location range = f_string_location_initialize;
// use an invalid range to communicate range not found
f_string_length argv_length = 0;
if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) {
- argv_length = strlen(argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]]);
+ argv_length = strlen(arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]]);
if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) {
for (; current < data->objects.used; current++) {
name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) {
if (data->contents.array[current].used > 0) {
if (data->contents.array[current].used > 0) {
f_string_length counter = data->contents.array[current].array[0].start;
f_string_length position = 0;
- f_string_length target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
+ f_string_length target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_list_read_parameter_line].additional.array[0]]);
f_string_location range = f_string_location_initialize;
// use an invalid range to communicate range not found
name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_list_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) {
f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]);
fprintf(f_standard_output, "\n");
}
#endif // _di_fss_basic_list_read_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_basic_list_read_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_basic_list_read_print_help(const fss_basic_list_read_data data);
#endif // _di_fss_basic_list_read_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_basic_list_read_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 fss_basic_list_read_delete_data()
+ */
#ifndef _di_fss_basic_list_read_main_
- /**
- * Main
- */
- extern f_return_status fss_basic_list_read_main(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data);
+ extern f_return_status fss_basic_list_read_main(const f_console_arguments arguments, fss_basic_list_read_data *data);
#endif // _di_fss_basic_list_read_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_basic_list_read_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_basic_list_read_main()
+ */
#ifndef _di_fss_basic_list_read_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_basic_list_read_delete_data(fss_basic_list_read_data *data);
#endif // _di_fss_basic_list_read_delete_data_
#include <level_3/fss_basic_list_read.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_basic_list_read_data data = fss_basic_list_read_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_basic_list_read_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_basic_list_read_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_basic_list_write_print_help_
#ifndef _di_fss_basic_list_write_main_
- f_return_status fss_basic_list_write_main(const f_array_length argc, const f_string argv[], fss_basic_list_write_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_basic_list_write_total_parameters, fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_basic_list_write_main(const f_console_arguments arguments, fss_basic_list_write_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_list_write_total_parameters, fss_basic_list_write_parameter_no_color, fss_basic_list_write_parameter_light, fss_basic_list_write_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_basic_list_write_delete_data(data);
else if (data->parameters[fss_basic_list_write_parameter_string].result == f_console_result_additional) {
f_string_dynamic input = f_string_dynamic_initialize;
- input.string = argv[data->parameters[fss_basic_list_write_parameter_string].additional.array[0]];
+ input.string = arguments.argv[data->parameters[fss_basic_list_write_parameter_string].additional.array[0]];
input.used = strlen(input.string);
location.start = 0;
f_file output = f_file_initialize;
output.mode = f_file_write_append;
- status = f_file_open(&output, argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
+ status = f_file_open(&output, arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
if (f_status_is_error(status)) {
status = f_status_set_fine(status);
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()");
}
else if (status == f_file_write_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status));
}
#endif // _di_fss_basic_list_write_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_basic_list_write_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_basic_list_write_print_help(const fss_basic_list_write_data data);
#endif // _di_fss_basic_list_write_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_basic_list_write_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 fss_basic_list_write_delete_data()
+ */
#ifndef _di_fss_basic_list_write_main_
- /**
- * Main.
- */
- extern f_return_status fss_basic_list_write_main(const f_array_length argc, const f_string argv[], fss_basic_list_write_data *data);
+ extern f_return_status fss_basic_list_write_main(const f_console_arguments arguments, fss_basic_list_write_data *data);
#endif // _di_fss_basic_list_write_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_basic_list_write_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_basic_list_write_main()
+ */
#ifndef _di_fss_basic_list_write_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_basic_list_write_delete_data(fss_basic_list_write_data *data);
#endif // _di_fss_basic_list_write_delete_data_
#include <level_3/fss_basic_list_write.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_basic_list_write_data data = fss_basic_list_write_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_basic_list_write_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_basic_list_write_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_basic_read_print_help_
#ifndef _di_fss_basic_read_main_
- f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal;
+ f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) f_gcc_attribute_visibility_internal;
- f_return_status fss_basic_read_main(const f_array_length argc, const f_string argv[], fss_basic_read_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_basic_read_total_parameters, fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_basic_read_main(const f_console_arguments arguments, fss_basic_read_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_read_total_parameters, fss_basic_read_parameter_no_color, fss_basic_read_parameter_light, fss_basic_read_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_basic_read_delete_data(data);
f_string_length original_size = data->file_position.total_elements;
if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) {
- target = (f_string_length) atoll(argv[data->parameters[fss_basic_read_parameter_count].additional.array[0]]);
+ target = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_read_parameter_count].additional.array[0]]);
}
if (data->process_pipe) {
return f_status_set_error(status);
}
- status = fss_basic_read_main_process_file(argc, argv, data, "-", target);
+ status = fss_basic_read_main_process_file(arguments, data, "-", target);
if (f_status_is_error(status)) {
return status;
for (; counter < data->remaining.used; counter++) {
f_file file = f_file_initialize;
- status = f_file_open(&file, argv[data->remaining.array[counter]]);
+ status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]);
data->file_position.total_elements = original_size;
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()");
}
else if (status == f_overflow) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_not_open) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_seek_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_read_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_allocation_error || status == f_reallocation_error) {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory");
return f_status_set_error(status);
}
- status = fss_basic_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target);
+ status = fss_basic_read_main_process_file(arguments, data, arguments.argv[data->remaining.array[counter]], target);
if (f_status_is_error(status)) {
return status;
return status;
}
- f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target) {
+ f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const f_string_length target) {
f_status status = f_none;
f_status status2 = f_none;
f_string_length argv_length = 0;
if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) {
- argv_length = strlen(argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]);
+ argv_length = strlen(arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]);
if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) {
for (; current < data->objects.used; current++) {
name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) {
if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) {
name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->contents.array[current].array[0].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) {
f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]);
fprintf(f_standard_output, "\n");
}
#endif // _di_fss_basic_read_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_basic_read_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_basic_read_print_help(const fss_basic_read_data data);
#endif // _di_fss_basic_read_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_basic_read_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 fss_basic_read_delete_data()
+ */
#ifndef _di_fss_basic_read_main_
- /**
- * Main.
- */
- extern f_return_status fss_basic_read_main(const f_array_length argc, const f_string argv[], fss_basic_read_data *data);
+ extern f_return_status fss_basic_read_main(const f_console_arguments arguments, fss_basic_read_data *data);
#endif // _di_fss_basic_read_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_basic_read_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_basic_read_main()
+ */
#ifndef _di_fss_basic_read_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_basic_read_delete_data(fss_basic_read_data *data);
#endif // _di_fss_basic_read_delete_data_
#include <level_3/fss_basic_read.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_basic_read_data data = fss_basic_read_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_basic_read_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_basic_read_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_basic_write_print_help_
#ifndef _di_fss_basic_write_main_
- f_return_status fss_basic_write_main(const f_array_length argc, const f_string argv[], fss_basic_write_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_basic_write_total_parameters, fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_basic_write_main(const f_console_arguments arguments, fss_basic_write_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_basic_write_total_parameters, fss_basic_write_parameter_no_color, fss_basic_write_parameter_light, fss_basic_write_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_basic_write_delete_data(data);
else if (data->parameters[fss_basic_write_parameter_string].result == f_console_result_additional) {
f_string_dynamic input = f_string_dynamic_initialize;
- input.string = argv[data->parameters[fss_basic_write_parameter_string].additional.array[0]];
+ input.string = arguments.argv[data->parameters[fss_basic_write_parameter_string].additional.array[0]];
input.used = strlen(input.string);
location.start = 0;
f_file output = f_file_initialize;
output.mode = f_file_write_append;
- status = f_file_open(&output, argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
+ status = f_file_open(&output, arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
if (f_status_is_error(status)) {
status = f_status_set_fine(status);
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()");
}
else if (status == f_file_write_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status));
}
#endif // _di_fss_basic_write_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_basic_write_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_basic_write_print_help(const fss_basic_write_data data);
#endif // _di_fss_basic_write_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_basic_write_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 fss_basic_write_delete_data()
+ */
#ifndef _di_fss_basic_write_main_
- /**
- * Main.
- */
- extern f_return_status fss_basic_write_main(const f_array_length argc, const f_string argv[], fss_basic_write_data *data);
+ extern f_return_status fss_basic_write_main(const f_console_arguments arguments, fss_basic_write_data *data);
#endif // _di_fss_basic_write_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_basic_write_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_basic_write_main()
+ */
#ifndef _di_fss_basic_write_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_basic_write_delete_data(fss_basic_write_data *data);
#endif // _di_fss_basic_write_delete_data_
#include <level_3/fss_basic_write.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_basic_write_data data = fss_basic_write_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_basic_write_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_basic_write_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_extended_read_print_help_
#ifndef _di_fss_extended_read_main_
- f_return_status fss_extended_read_main_process_file(const f_array_length argc, const f_string argv[], fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) f_gcc_attribute_visibility_internal;
+ f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) f_gcc_attribute_visibility_internal;
- f_return_status fss_extended_read_main(const f_array_length argc, const f_string argv[], fss_extended_read_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_extended_read_total_parameters, fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_extended_read_main(const f_console_arguments arguments, fss_extended_read_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_extended_read_total_parameters, fss_extended_read_parameter_no_color, fss_extended_read_parameter_light, fss_extended_read_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_extended_read_delete_data(data);
f_string_length original_size = data->file_position.total_elements;
if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) {
- target = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_count].additional.array[0]]);
+ target = (f_string_length) atoll(arguments.argv[data->parameters[fss_extended_read_parameter_count].additional.array[0]]);
}
if (data->parameters[fss_extended_read_parameter_select].result == f_console_result_additional) {
- select = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_select].additional.array[0]]);
+ select = (f_string_length) atoll(arguments.argv[data->parameters[fss_extended_read_parameter_select].additional.array[0]]);
}
if (data->process_pipe) {
return f_status_set_error(status);
}
- status = fss_extended_read_main_process_file(argc, argv, data, "-", target, select);
+ status = fss_extended_read_main_process_file(arguments, data, "-", target, select);
if (f_status_is_error(status)) {
for (; counter < data->remaining.used; counter++) {
f_file file = f_file_initialize;
- status = f_file_open(&file, argv[data->remaining.array[counter]]);
+ status = f_file_open(&file, arguments.argv[data->remaining.array[counter]]);
data->file_position.total_elements = original_size;
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()");
}
else if (status == f_overflow) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_not_open) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_seek_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_file_read_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", arguments.argv[data->remaining.array[counter]]);
}
else if (status == f_allocation_error || status == f_reallocation_error) {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory");
return f_status_set_error(status);
}
- status = fss_extended_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target, select);
+ status = fss_extended_read_main_process_file(arguments, data, arguments.argv[data->remaining.array[counter]], target, select);
if (f_status_is_error(status)) {
return status;
return status;
}
- f_return_status fss_extended_read_main_process_file(const f_array_length argc, const f_string argv[], fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) {
+ f_return_status fss_extended_read_main_process_file(const f_console_arguments arguments, fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) {
f_status status = f_none;
f_status status2 = f_none;
f_string_length argv_length = 0;
if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional) {
- argv_length = strlen(argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]]);
+ argv_length = strlen(arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]]);
if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) {
for (; current < data->objects.used; current++) {
name_length = data->objects.array[current].stop - data->objects.array[current].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->objects.array[current].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) {
if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) {
name_length = data->contents.array[current].array[select].stop - data->contents.array[current].array[select].start + 1;
if (name_length == argv_length) {
- if (fl_string_compare(data->buffer.string + data->contents.array[current].array[select].start, argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
+ if (fl_string_compare(data->buffer.string + data->contents.array[current].array[select].start, arguments.argv[data->parameters[fss_extended_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) {
if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) {
f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[current]);
fprintf(f_standard_output, "\n");
}
#endif // _di_fss_extended_read_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_extended_read_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_extended_read_print_help(const fss_extended_read_data data);
#endif // _di_fss_extended_read_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_extended_read_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 fss_extended_read_delete_data()
+ */
#ifndef _di_fss_extended_read_main_
- /**
- * Main.
- */
- extern f_return_status fss_extended_read_main(const f_array_length argc, const f_string argv[], fss_extended_read_data *data);
+ extern f_return_status fss_extended_read_main(const f_console_arguments arguments, fss_extended_read_data *data);
#endif // _di_fss_extended_read_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_extended_read_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_extended_read_main()
+ */
#ifndef _di_fss_extended_read_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_extended_read_delete_data(fss_extended_read_data *data);
#endif // _di_fss_extended_read_delete_data_
#include <level_3/fss_extended_read.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_extended_read_data data = fss_extended_read_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_extended_read_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_extended_read_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_extended_write_print_help_
#ifndef _di_fss_extended_write_main_
- f_return_status fss_extended_write_main(const f_array_length argc, const f_string argv[], fss_extended_write_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_extended_write_total_parameters, fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_extended_write_main(const f_console_arguments arguments, fss_extended_write_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_extended_write_total_parameters, fss_extended_write_parameter_no_color, fss_extended_write_parameter_light, fss_extended_write_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_extended_write_delete_data(data);
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass.");
// TODO: there is a way to identify which parameter is incorrect
// to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0
- // nothing can be 0 as that represents the program name, unless argv[] is improperly created
+ // nothing can be 0 as that represents the program name, unless arguments.argv[] is improperly created
}
else if (status == f_allocation_error || status == f_reallocation_error) {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory.");
f_string_dynamic input = f_string_dynamic_initialize;
if (object) {
- input.string = argv[data->parameters[fss_extended_write_parameter_string].additional.array[0]];
+ input.string = arguments.argv[data->parameters[fss_extended_write_parameter_string].additional.array[0]];
input.used = strlen(input.string);
location.start = 0;
f_string_length i = 0;
while (i < data->parameters[fss_extended_write_parameter_string].additional.used) {
- input.string = argv[data->parameters[fss_extended_write_parameter_string].additional.array[i]];
+ input.string = arguments.argv[data->parameters[fss_extended_write_parameter_string].additional.array[i]];
input.used = strlen(input.string);
location.start = 0;
f_file output = f_file_initialize;
output.mode = f_file_write_append;
- status = f_file_open(&output, argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
+ status = f_file_open(&output, arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
if (f_status_is_error(status)) {
status = f_status_set_fine(status);
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()");
}
else if (status == f_file_not_found) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_open_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
}
else if (status == f_file_descriptor_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status));
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()");
}
else if (status == f_file_write_error) {
- fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
+ fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]);
}
else {
fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status));
}
#endif // _di_fss_extended_write_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_extended_write_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_extended_write_print_help(const fss_extended_write_data data);
#endif // _di_fss_extended_write_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_extended_write_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 fss_extended_write_delete_data()
+ */
#ifndef _di_fss_extended_write_main_
- /**
- * Main.
- */
- extern f_return_status fss_extended_write_main(const f_array_length argc, const f_string argv[], fss_extended_write_data *data);
+ extern f_return_status fss_extended_write_main(const f_console_arguments arguments, fss_extended_write_data *data);
#endif // _di_fss_extended_write_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_extended_write_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_extended_write_main()
+ */
#ifndef _di_fss_extended_write_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_extended_write_delete_data(fss_extended_write_data *data);
#endif // _di_fss_extended_write_delete_data_
#include <level_3/fss_extended_write.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_extended_write_data data = fss_extended_write_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- if (f_status_is_error(fss_extended_write_main(argc, argv, &data))) {
+ if (f_status_is_error(fss_extended_write_main(arguments, &data))) {
return 1;
}
#endif // _di_fss_status_code_print_help_
#ifndef _di_fss_status_code_main_
- f_return_status fss_status_code_main(const f_array_length argc, const f_string argv[], fss_status_code_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, fss_status_code_total_parameters, fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark, &data->remaining, &data->context);
+ f_return_status fss_status_code_main(const f_console_arguments arguments, fss_status_code_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, fss_status_code_total_parameters, fss_status_code_parameter_no_color, fss_status_code_parameter_light, fss_status_code_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
fss_status_code_delete_data(data);
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// numbers are not valid status code strings.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_true) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
status = f_false;
continue;
}
- status2 = fll_status_from_string(argv[data->remaining.array[counter]], &code);
+ status2 = fll_status_from_string(arguments.argv[data->remaining.array[counter]], &code);
if (f_status_is_error(status2)) {
status = status2;
if (data->remaining.used > 0) {
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status code.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
}
#endif // _di_fss_status_code_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_fss_status_code_print_help_
- /**
- * Print help.
- */
extern f_return_status fss_status_code_print_help(const fss_status_code_data data);
#endif // _di_fss_status_code_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call fss_status_code_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 fss_status_code_delete_data()
+ */
#ifndef _di_fss_status_code_main_
- /**
- * Main.
- */
- extern f_return_status fss_status_code_main(const f_array_length argc, const f_string argv[], fss_status_code_data *data);
+ extern f_return_status fss_status_code_main(const f_console_arguments arguments, fss_status_code_data *data);
#endif // _di_fss_status_code_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing fss_status_code_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see fss_status_code_main()
+ */
#ifndef _di_fss_status_code_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status fss_status_code_delete_data(fss_status_code_data *data);
#endif // _di_fss_status_code_delete_data_
#include <level_3/fss_status_code.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
fss_status_code_data data = fss_status_code_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- f_status status = fss_status_code_main(argc, argv, &data);
+ f_status status = fss_status_code_main(arguments, &data);
if (f_status_is_error(status) || status == f_false) {
return 1;
#endif // _di_init_print_help_
#ifndef _di_init_main_
- f_return_status init_main(const f_s_int argc, const f_string argv[], init_argument *argument) {
+ f_return_status init_main(const f_console_arguments arguments, init_argument *argument) {
f_status status = f_none;
f_autochar run_level[init_kernel_runlevel_buffer];
f_u_short do_socket_file = f_true;
f_u_short do_socket_port = f_false;
- status = fll_program_process_parameters(argc, argv, data->parameters, init_total_parameters, init_parameter_no_color, init_parameter_light, init_parameter_dark, &data->remaining, &data->context);
+ status = fll_program_process_parameters(arguments, data->parameters, init_total_parameters, init_parameter_no_color, init_parameter_light, init_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
init_delete_data(data);
if (argument->parameters[init_parameter_runlevel].result == f_console_result_found) {
- const f_u_int parameter_length = strlen(argv[argument->parameters[init_parameter_runlevel].additional.array[0]]);
+ const f_u_int parameter_length = strlen(arguments.argv[argument->parameters[init_parameter_runlevel].additional.array[0]]);
// if the run_level value is greater than the static buffer size, ignore the entire string rather than process a cut off value.
if (parameter_length > 0 && parameter_length < init_kernel_runlevel_buffer) {
- strncpy(&run_level, argv[argument->parameters[init_parameter_runlevel].additional.array[0]], parameter_length);
+ strncpy(&run_level, arguments.argv[argument->parameters[init_parameter_runlevel].additional.array[0]], parameter_length);
}
}
extern f_return_status init_print_version(const init_argument data);
#endif // _di_init_print_version_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_init_print_help_
extern f_return_status init_print_help(const init_argument data);
#endif // _di_init_print_help_
+/**
+ * Execute main program.
+ *
+ * @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.
+ */
#ifndef _di_init_main_
- extern f_return_status init_main(const f_s_int argc, const f_string argv[], init_argument *data);
+ extern f_return_status init_main(const f_console_arguments arguments, init_argument *data);
#endif // _di_init_main_
#ifdef __cplusplus
#include <level_3/init.h>
-int main(const f_s_int argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
init_argument data = init_argument_initialize;
- return init_main(argc, argv, &data);
+ return init_main(arguments, &data);
}
#include <level_3/status_code.h>
-int main(const f_array_length argc, const f_string argv[]) {
+int main(const int argc, const f_string *argv) {
+ const f_console_arguments arguments = { argc, argv };
status_code_data data = status_code_data_initialize;
if (f_pipe_exists()) {
data.process_pipe = f_true;
}
- f_status status = status_code_main(argc, argv, &data);
+ f_status status = status_code_main(arguments, &data);
if (f_status_is_error(status) || status == f_false) {
return 1;
#endif // _di_status_code_print_help_
#ifndef _di_status_code_main_
- f_return_status status_code_main(const f_array_length argc, const f_string argv[], status_code_data *data) {
- f_status status = fll_program_process_parameters(argc, argv, data->parameters, status_code_total_parameters, status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark, &data->remaining, &data->context);
+ f_return_status status_code_main(const f_console_arguments arguments, status_code_data *data) {
+ f_status status = fll_program_process_parameters(arguments, data->parameters, status_code_total_parameters, status_code_parameter_no_color, status_code_parameter_light, status_code_parameter_dark, &data->remaining, &data->context);
if (f_status_is_error(status)) {
status_code_delete_data(data);
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status codes.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
for (; counter < data->remaining.used; counter++) {
// numbers are not valid status code strings.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_true) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_true) {
status = f_false;
continue;
}
- status2 = fll_status_from_string(argv[data->remaining.array[counter]], &code);
+ status2 = fll_status_from_string(arguments.argv[data->remaining.array[counter]], &code);
if (f_status_is_error(status2)) {
status = status2;
break;
if (data->remaining.used > 0) {
for (; counter < data->remaining.used; counter++) {
// only numbers are valid status code.
- if (f_is_digit(argv[data->remaining.array[counter]][0]) == f_false) {
+ if (f_is_digit(arguments.argv[data->remaining.array[counter]][0]) == f_false) {
status = f_false;
continue;
}
- long long number = atoll(argv[data->remaining.array[counter]]);
+ long long number = atoll(arguments.argv[data->remaining.array[counter]]);
if (number >= 0x10000 || number < 0) {
status = f_false;
continue;
}
#endif // _di_status_code_data_
+/**
+ * Print help to standard output.
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ */
#ifndef _di_status_code_print_help_
- /**
- * Print help.
- */
extern f_return_status status_code_print_help(const status_code_data data);
#endif // _di_status_code_print_help_
+/**
+ * Execute main program.
+ *
+ * Be sure to call status_code_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 status_code_delete_data()
+ */
#ifndef _di_status_code_main_
- /**
- * Main.
- */
- extern f_return_status status_code_main(const f_array_length argc, const f_string argv[], status_code_data *data);
+ extern f_return_status status_code_main(const f_console_arguments arguments, status_code_data *data);
#endif // _di_status_code_main_
+/**
+ * Deallocate data.
+ *
+ * Be sure to call this after executing status_code_main().
+ *
+ * @param data
+ * The program data.
+ *
+ * @return
+ * f_none on success.
+ * Status codes (with error bit) are returned on any problem.
+ *
+ * @see status_code_main()
+ */
#ifndef _di_status_code_delete_data_
- /**
- * Deallocate data.
- */
extern f_return_status status_code_delete_data(status_code_data *data);
#endif // _di_status_code_delete_data_