From: Kevin Day Date: Sun, 8 Sep 2019 21:46:27 +0000 (-0500) Subject: Cleanup: replace argc and argv usage with a single structure of argc and argv (f_cons... X-Git-Tag: 0.5.0~445 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=61a70352d8eef60031c892308dedf4943d3b89da;p=fll Cleanup: replace argc and argv usage with a single structure of argc and argv (f_console_arguments) 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". --- diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 10931ad..60409c2 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -179,6 +179,20 @@ extern "C" { #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 diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index da63b50..df0419b 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -5,7 +5,7 @@ extern "C" { #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_ @@ -27,10 +27,10 @@ extern "C" { 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) { @@ -100,7 +100,7 @@ extern "C" { 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; } } @@ -109,7 +109,7 @@ extern "C" { 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; } } @@ -162,7 +162,7 @@ extern "C" { 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; } diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index 58b0f37..223d67b 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -48,9 +48,7 @@ extern "C" { * * 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. @@ -66,7 +64,7 @@ extern "C" { * 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_ /** diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 92b3588..184ca4b 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -79,11 +79,11 @@ extern "C" { #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; diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index 80c9dbf..2a5b865 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -120,9 +120,7 @@ extern "C" { /** * 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. @@ -146,7 +144,7 @@ extern "C" { * 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 diff --git a/level_3/bit_dump/c/bit_dump.c b/level_3/bit_dump/c/bit_dump.c index 20ebbc4..b4a9a39 100644 --- a/level_3/bit_dump/c/bit_dump.c +++ b/level_3/bit_dump/c/bit_dump.c @@ -39,8 +39,8 @@ extern "C" { #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); @@ -136,7 +136,7 @@ extern "C" { 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."); @@ -154,7 +154,7 @@ extern "C" { 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."); @@ -172,7 +172,7 @@ extern "C" { 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."); @@ -204,13 +204,13 @@ extern "C" { 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 @@ -225,18 +225,18 @@ extern "C" { 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); diff --git a/level_3/bit_dump/c/bit_dump.h b/level_3/bit_dump/c/bit_dump.h index cddcf74..f106b7e 100644 --- a/level_3/bit_dump/c/bit_dump.h +++ b/level_3/bit_dump/c/bit_dump.h @@ -217,9 +217,7 @@ extern "C" { * * 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. @@ -231,7 +229,7 @@ extern "C" { * @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_ /** diff --git a/level_3/bit_dump/c/main.c b/level_3/bit_dump/c/main.c index f6c10b2..b20d152 100644 --- a/level_3/bit_dump/c/main.c +++ b/level_3/bit_dump/c/main.c @@ -1,13 +1,14 @@ #include -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; diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 4dd189c..39d4007 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -55,8 +55,8 @@ extern "C" { #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); @@ -141,7 +141,7 @@ extern "C" { 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) { @@ -152,10 +152,10 @@ extern "C" { 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; @@ -171,7 +171,7 @@ extern "C" { } // 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"); @@ -186,23 +186,23 @@ extern "C" { 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); @@ -214,23 +214,23 @@ extern "C" { 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); @@ -242,19 +242,19 @@ extern "C" { 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); @@ -275,8 +275,8 @@ extern "C" { 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); @@ -286,22 +286,22 @@ extern "C" { 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; diff --git a/level_3/firewall/c/firewall.h b/level_3/firewall/c/firewall.h index dff2708..c3c0525 100644 --- a/level_3/firewall/c/firewall.h +++ b/level_3/firewall/c/firewall.h @@ -293,24 +293,54 @@ extern "C" { } #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_ diff --git a/level_3/firewall/c/main.c b/level_3/firewall/c/main.c index 72163ad..14a81a6 100644 --- a/level_3/firewall/c/main.c +++ b/level_3/firewall/c/main.c @@ -1,10 +1,11 @@ #include #include -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; } diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index f8b90d1..f8573df 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -30,10 +30,10 @@ extern "C" { #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); @@ -56,7 +56,7 @@ extern "C" { 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) { @@ -89,7 +89,7 @@ extern "C" { 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; @@ -104,7 +104,7 @@ extern "C" { 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; @@ -115,13 +115,13 @@ extern "C" { 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)); @@ -156,16 +156,16 @@ extern "C" { 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"); @@ -178,7 +178,7 @@ extern "C" { 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; @@ -199,7 +199,7 @@ extern "C" { 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; @@ -280,7 +280,7 @@ extern "C" { 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 @@ -356,14 +356,14 @@ extern "C" { 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) { @@ -387,7 +387,7 @@ extern "C" { 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 @@ -457,7 +457,7 @@ extern "C" { 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"); diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.h b/level_3/fss_basic_list_read/c/fss_basic_list_read.h index 695bab1..00e0178 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.h @@ -128,24 +128,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_basic_list_read/c/main.c b/level_3/fss_basic_list_read/c/main.c index 4daf61c..9d493f5 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index caa414a..6428253 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.c @@ -27,8 +27,8 @@ extern "C" { #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); @@ -108,7 +108,7 @@ extern "C" { 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; @@ -136,7 +136,7 @@ extern "C" { 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); @@ -147,13 +147,13 @@ extern "C" { 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)); @@ -173,7 +173,7 @@ extern "C" { 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)); diff --git a/level_3/fss_basic_list_write/c/fss_basic_list_write.h b/level_3/fss_basic_list_write/c/fss_basic_list_write.h index 472791b..aa48b46 100644 --- a/level_3/fss_basic_list_write/c/fss_basic_list_write.h +++ b/level_3/fss_basic_list_write/c/fss_basic_list_write.h @@ -104,24 +104,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_basic_list_write/c/main.c b/level_3/fss_basic_list_write/c/main.c index 4b3052d..e631ff8 100644 --- a/level_3/fss_basic_list_write/c/main.c +++ b/level_3/fss_basic_list_write/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_basic_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index df8e010..fc73792 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -28,10 +28,10 @@ extern "C" { #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); @@ -54,7 +54,7 @@ extern "C" { 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) { @@ -93,7 +93,7 @@ extern "C" { 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; @@ -109,7 +109,7 @@ extern "C" { 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; @@ -120,13 +120,13 @@ extern "C" { 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)); @@ -161,16 +161,16 @@ extern "C" { 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"); @@ -183,7 +183,7 @@ extern "C" { 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; @@ -205,7 +205,7 @@ extern "C" { 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; @@ -309,14 +309,14 @@ extern "C" { 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) { @@ -358,7 +358,7 @@ extern "C" { 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"); diff --git a/level_3/fss_basic_read/c/fss_basic_read.h b/level_3/fss_basic_read/c/fss_basic_read.h index e176f1e..d17e369 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -120,24 +120,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index 8674a0c..5815373 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_basic_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index 7b82120..966ab7c 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -27,8 +27,8 @@ extern "C" { #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); @@ -108,7 +108,7 @@ extern "C" { 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; @@ -136,7 +136,7 @@ extern "C" { 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); @@ -147,13 +147,13 @@ extern "C" { 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)); @@ -173,7 +173,7 @@ extern "C" { 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)); diff --git a/level_3/fss_basic_write/c/fss_basic_write.h b/level_3/fss_basic_write/c/fss_basic_write.h index 9a46e68..103ec2f 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.h +++ b/level_3/fss_basic_write/c/fss_basic_write.h @@ -103,24 +103,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_basic_write/c/main.c b/level_3/fss_basic_write/c/main.c index eeb6d3f..ed207cb 100644 --- a/level_3/fss_basic_write/c/main.c +++ b/level_3/fss_basic_write/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 31cad9e..9e98b04 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -29,10 +29,10 @@ extern "C" { #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); @@ -56,11 +56,11 @@ extern "C" { 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) { @@ -93,7 +93,7 @@ extern "C" { 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)) { @@ -109,7 +109,7 @@ extern "C" { 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; @@ -120,13 +120,13 @@ extern "C" { 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)); @@ -161,16 +161,16 @@ extern "C" { 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"); @@ -183,7 +183,7 @@ extern "C" { 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; @@ -204,7 +204,7 @@ extern "C" { 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; @@ -307,14 +307,14 @@ extern "C" { 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) { @@ -360,7 +360,7 @@ extern "C" { 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"); diff --git a/level_3/fss_extended_read/c/fss_extended_read.h b/level_3/fss_extended_read/c/fss_extended_read.h index 7138277..64f6311 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -124,24 +124,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index 52d1bd4..9afa9c8 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_extended_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index 32b6ff1..226efcb 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -28,8 +28,8 @@ extern "C" { #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); @@ -45,7 +45,7 @@ extern "C" { 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."); @@ -146,7 +146,7 @@ extern "C" { 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; @@ -162,7 +162,7 @@ extern "C" { 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; @@ -198,7 +198,7 @@ extern "C" { 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); @@ -209,13 +209,13 @@ extern "C" { 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)); @@ -235,7 +235,7 @@ extern "C" { 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)); diff --git a/level_3/fss_extended_write/c/fss_extended_write.h b/level_3/fss_extended_write/c/fss_extended_write.h index 2988f7d..10f8ac8 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.h +++ b/level_3/fss_extended_write/c/fss_extended_write.h @@ -108,24 +108,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_extended_write/c/main.c b/level_3/fss_extended_write/c/main.c index cf812f0..d9cab58 100644 --- a/level_3/fss_extended_write/c/main.c +++ b/level_3/fss_extended_write/c/main.c @@ -1,13 +1,14 @@ #include -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; } diff --git a/level_3/fss_status_code/c/fss_status_code.c b/level_3/fss_status_code/c/fss_status_code.c index f4792c2..453ff06 100644 --- a/level_3/fss_status_code/c/fss_status_code.c +++ b/level_3/fss_status_code/c/fss_status_code.c @@ -28,8 +28,8 @@ extern "C" { #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); @@ -54,12 +54,12 @@ extern "C" { 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; @@ -93,12 +93,12 @@ extern "C" { 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; @@ -132,12 +132,12 @@ extern "C" { 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; @@ -170,12 +170,12 @@ extern "C" { 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; @@ -206,12 +206,12 @@ extern "C" { 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; diff --git a/level_3/fss_status_code/c/fss_status_code.h b/level_3/fss_status_code/c/fss_status_code.h index 3388f08..f53394f 100644 --- a/level_3/fss_status_code/c/fss_status_code.h +++ b/level_3/fss_status_code/c/fss_status_code.h @@ -108,24 +108,54 @@ extern "C" { } #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_ diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c index 4bc2b82..3bf1ed5 100644 --- a/level_3/fss_status_code/c/main.c +++ b/level_3/fss_status_code/c/main.c @@ -1,13 +1,14 @@ #include -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; diff --git a/level_3/init/c/init.c b/level_3/init/c/init.c index 34f8461..46c9aac 100644 --- a/level_3/init/c/init.c +++ b/level_3/init/c/init.c @@ -43,7 +43,7 @@ extern "C" { #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]; @@ -52,7 +52,7 @@ extern "C" { 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); @@ -63,11 +63,11 @@ extern "C" { 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); } } diff --git a/level_3/init/c/init.h b/level_3/init/c/init.h index a1365d7..4b42366 100644 --- a/level_3/init/c/init.h +++ b/level_3/init/c/init.h @@ -219,12 +219,33 @@ extern "C" { 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 diff --git a/level_3/init/c/main.c b/level_3/init/c/main.c index 27fe671..709b424 100644 --- a/level_3/init/c/main.c +++ b/level_3/init/c/main.c @@ -1,7 +1,8 @@ #include -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); } diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index 76f3aee..fc6375e 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -1,13 +1,14 @@ #include -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; diff --git a/level_3/status_code/c/status_code.c b/level_3/status_code/c/status_code.c index 68b1b32..1dcf67f 100644 --- a/level_3/status_code/c/status_code.c +++ b/level_3/status_code/c/status_code.c @@ -28,8 +28,8 @@ extern "C" { #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); @@ -54,12 +54,12 @@ extern "C" { 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; @@ -93,12 +93,12 @@ extern "C" { 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; @@ -132,12 +132,12 @@ extern "C" { 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; @@ -170,12 +170,12 @@ extern "C" { 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; @@ -205,12 +205,12 @@ extern "C" { 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; diff --git a/level_3/status_code/c/status_code.h b/level_3/status_code/c/status_code.h index 2e4145a..87917c4 100644 --- a/level_3/status_code/c/status_code.h +++ b/level_3/status_code/c/status_code.h @@ -105,24 +105,54 @@ extern "C" { } #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_