From 744e49a48e91f4dbdae42132c0d416c3ad2a0948 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 26 Jul 2019 23:10:01 -0500 Subject: [PATCH] Cleanup: update to newer style practices and fix existing style problems found Use alphabetic whenever possible (structure context overrides this often). Perform the initial prepatory work for new comment practices. else end else if blocks are now to be on separate lines instead of inline with '}'. --- level_0/f_colors/c/colors.h | 71 +++++--- level_0/f_console/c/console.c | 40 +++-- level_0/f_console/c/console.h | 108 ++++++++---- level_0/f_conversion/c/conversion.c | 12 +- level_0/f_conversion/c/conversion.h | 54 +++--- level_0/f_errors/c/errors.h | 25 +-- level_0/f_file/c/file.c | 6 +- level_0/f_file/c/file.h | 56 +++--- level_0/f_fss/c/fss.h | 73 +++++--- level_0/f_memory/c/memory.c | 18 +- level_0/f_memory/c/memory.h | 150 +++++++++------- level_0/f_paths/c/filesystem_paths.h | 188 ++++++++++----------- level_0/f_paths/c/fll_paths.h | 32 ++-- level_0/f_pipe/c/pipe.h | 6 +- level_0/f_print/c/print.c | 12 +- level_0/f_print/c/print.h | 40 +++-- level_0/f_serialized/c/serialized.h | 10 +- level_0/f_socket/c/socket.h | 18 +- level_0/f_strings/c/strings.h | 77 ++++++--- level_0/f_types/c/types.h | 70 ++++---- level_0/f_types/c/types_array.h | 14 +- level_1/fl_colors/c/colors.c | 12 +- level_1/fl_colors/c/colors.h | 34 ++-- level_1/fl_console/c/console.c | 51 +++--- level_1/fl_console/c/console.h | 7 +- level_1/fl_directory/c/directory.c | 3 +- level_1/fl_directory/c/directory.h | 14 +- level_1/fl_errors/c/errors.c | 3 +- level_1/fl_errors/c/errors.h | 24 ++- level_1/fl_file/c/file.c | 9 +- level_1/fl_file/c/file.h | 16 +- level_1/fl_fss/c/fss.c | 16 +- level_1/fl_fss/c/fss.h | 24 ++- level_1/fl_fss/c/fss_basic.c | 85 ++++++---- level_1/fl_fss/c/fss_basic.h | 24 ++- level_1/fl_fss/c/fss_basic_list.c | 69 +++++--- level_1/fl_fss/c/fss_basic_list.h | 26 ++- level_1/fl_fss/c/fss_extended.c | 151 +++++++++++------ level_1/fl_fss/c/fss_extended.h | 26 ++- level_1/fl_fss/c/fss_macro.h | 18 +- level_1/fl_serialized/c/serialized.c | 14 +- level_1/fl_serialized/c/serialized.h | 16 +- level_1/fl_socket/c/socket.h | 20 ++- level_1/fl_strings/c/strings.c | 6 +- level_1/fl_strings/c/strings.h | 50 ++++-- level_2/fll_colors/c/colors.c | 6 +- level_2/fll_colors/c/colors.h | 12 +- level_2/fll_execute/c/execute.c | 15 +- level_2/fll_execute/c/execute.h | 20 ++- level_2/fll_fss/c/fss_basic.c | 26 +-- level_2/fll_fss/c/fss_basic.h | 14 +- level_2/fll_fss/c/fss_basic_list.c | 30 ++-- level_2/fll_fss/c/fss_basic_list.h | 18 +- level_2/fll_fss/c/fss_errors.c | 3 +- level_2/fll_fss/c/fss_errors.h | 32 ++-- level_2/fll_fss/c/fss_extended.c | 22 ++- level_2/fll_fss/c/fss_extended.h | 16 +- level_3/firewall/c/firewall.c | 92 ++++++---- level_3/firewall/c/firewall.h | 30 +++- level_3/firewall/c/private-firewall.c | 161 +++++++++++------- level_3/firewall/c/private-firewall.h | 30 +++- .../fss_basic_list_read/c/fss_basic_list_read.c | 142 ++++++++++------ .../fss_basic_list_read/c/fss_basic_list_read.h | 42 +++-- .../fss_basic_list_write/c/fss_basic_list_write.c | 67 +++++--- .../fss_basic_list_write/c/fss_basic_list_write.h | 26 ++- level_3/fss_basic_read/c/fss_basic_read.c | 118 ++++++++----- level_3/fss_basic_read/c/fss_basic_read.h | 42 +++-- level_3/fss_basic_write/c/fss_basic_write.c | 67 +++++--- level_3/fss_basic_write/c/fss_basic_write.h | 26 ++- level_3/fss_extended_read/c/fss_extended_read.c | 118 ++++++++----- level_3/fss_extended_read/c/fss_extended_read.h | 40 +++-- level_3/fss_extended_write/c/fss_extended_write.c | 67 +++++--- level_3/fss_extended_write/c/fss_extended_write.h | 26 ++- level_3/fss_return_code/c/fss_return_code.c | 51 +++--- level_3/fss_return_code/c/fss_return_code.h | 24 ++- level_3/return_code/c/return_code.c | 51 +++--- level_3/return_code/c/return_code.h | 26 ++- 77 files changed, 2046 insertions(+), 1212 deletions(-) diff --git a/level_0/f_colors/c/colors.h b/level_0/f_colors/c/colors.h index ac14d88..b42616f 100644 --- a/level_0/f_colors/c/colors.h +++ b/level_0/f_colors/c/colors.h @@ -12,8 +12,8 @@ #define _F_colors_h // fll-0 includes -#include #include +#include #ifdef __cplusplus extern "C" { @@ -31,58 +31,74 @@ extern "C" { #define f_color_xterminal 1 #endif // _di_f_color_types_ -// the purpose behind these data types are not to dynamically allocate data -// instead, they are intended to only point to existing data, so these should neither be allocated nor deallocated +/** + * The purpose behind these data types are not to dynamically allocate data. + * instead, they are intended to only point to existing data, so these should neither be allocated nor deallocated. + */ #ifndef _di_f_color_control_ typedef struct f_color_control { - const char *bold; - const char *underline; const char *blink; - const char *reverse; + const char *bold; const char *conceal; + const char *reverse; + const char *underline; } f_color_control; - #define f_color_control_names_initialize { "bold", "underline", "blink", "reverse", "conceal" } + #define f_color_control_names_initialize { "blink", "bold", "conceal", "reverse", "underline" } #endif // _di_f_color_control_ +/** + * strong represents emphasis. + */ #ifndef _di_f_color_standard_io_ typedef struct { + const char *error; const char *message; const char *warning; - const char *error; - const char *strong_message; // an emphasized message - const char *strong_warning; // an emphasized warning - const char *strong_error; // an emphasized error + const char *strong_error; + const char *strong_message; + const char *strong_warning; } f_color_standard_io; - #define f_color_standard_io_names_initialize { "message", "warning", "error", "strong_message", "strong_warning", "strong_error" } + #define f_color_standard_io_names_initialize { "error", "message", "warning", "strong_error", "strong_message", "strong_warning" } #endif // _di_f_color_standard_io_ +/** + * alert = some form of alert such as 'Not Implemented Yet'. + * command = color for a specific command, such as '-h'. + * comment = not quite important text, but still should be seen. + * emphasize = make sure something stands out to emphasize it. + * standard = the normal text color. + * syntax = color for syntax, such as '[' and '<'. + * title = name printed. + * topic = topic such as 'Usage'. + * version = version printed. + */ #ifndef _di_f_color_help_ typedef struct { - const char *title; // name printed - const char *version; // version printed - const char *topic; // topic such as 'Usage' - const char *command; // color for a specific command, such as '-h' - const char *syntax; // color for syntax, such as '[' and '<' - const char *alert; // some form of alert such as 'Not Implemented Yet' - const char *comment; // not quite important text, but still should be seen - const char *standard; // the normal text color - const char *emphasize; // make sure something stands out to emphasize it + const char *alert; + const char *command; + const char *comment; + const char *emphasize; + const char *standard; + const char *syntax; + const char *title; + const char *topic; + const char *version; } f_color_help; - #define f_color_help_names_initialize { "title", "version", "topic", "command", "syntax", "alert", "comment", "standard", "emphasize" } + #define f_color_help_names_initialize { "alert", "command", "comment", "emphasize", "standard", "syntax", "title", "topic", "version" } #endif // _di_f_color_help_ #ifndef _di_f_colors_format_ typedef struct { const char *begin; - const char *medium; const char *end; + const char *medium; } f_colors_format; - #define f_colors_format_initialize_linux { "\033[", ";", "m" } - #define f_colors_format_initialize_xterminal { "\033[", ";", "m" } + #define f_colors_format_initialize_linux { "\033[", "m", ";" } + #define f_colors_format_initialize_xterminal { "\033[", "m", ";" } #endif // _di_f_colors_format_ #ifndef _di_f_colors_ @@ -134,8 +150,9 @@ extern "C" { #ifndef _di_f_default_colors_ static const f_colors_format f_colors_format_linux = f_colors_format_initialize_linux; static const f_colors_format f_colors_format_xterminal = f_colors_format_initialize_xterminal; - static const f_colors f_colors_linux = f_colors_initialize_linux; - static const f_colors f_colors_xterminal = f_colors_initialize_xterminal; + + static const f_colors f_colors_linux = f_colors_initialize_linux; + static const f_colors f_colors_xterminal = f_colors_initialize_xterminal; #endif // _di_f_default_colors_ #ifdef __cplusplus diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index fef3d26..d0a6a0f 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -22,28 +22,34 @@ extern "C" { if (input[1] == f_console_symbol_enable) { if (length > 2) { if (input[2] == f_console_symbol_enable) { - if (length > 3) { - *result = f_console_extra_enable; - } else *result = f_console_empty_extra_enable; - } else *result = f_console_long_enable; - } else *result = f_console_empty_long_enable; - } else *result = f_console_short_enable; - } else *result = f_console_empty_short_enable; - } else if (input[0] == f_console_symbol_disable) { + if (length > 3) *result = f_console_extra_enable; + else *result = f_console_empty_extra_enable; + } + else *result = f_console_long_enable; + } + else *result = f_console_empty_long_enable; + } + else *result = f_console_short_enable; + } + else *result = f_console_empty_short_enable; + } + else if (input[0] == f_console_symbol_disable) { if (length > 1) { if (input[1] == f_console_symbol_disable) { if (length > 2) { if (input[2] == f_console_symbol_disable) { - if (length > 3) { - *result = f_console_extra_disable; - } else *result = f_console_empty_extra_disable; - } else *result = f_console_long_disable; - } else *result = f_console_empty_long_disable; - } else *result = f_console_short_disable; - } else *result = f_console_empty_short_disable; - } else { - *result = f_console_none; + if (length > 3) *result = f_console_extra_disable; + else *result = f_console_empty_extra_disable; + } + else *result = f_console_long_disable; + } + else *result = f_console_empty_long_disable; + } + else *result = f_console_short_disable; + } + else *result = f_console_empty_short_disable; } + else *result = f_console_none; return f_none; } diff --git a/level_0/f_console/c/console.h b/level_0/f_console/c/console.h index 4e5e3cc..138bcf7 100644 --- a/level_0/f_console/c/console.h +++ b/level_0/f_console/c/console.h @@ -14,56 +14,69 @@ #include // fll-0 includes -#include #include +#include #include #ifdef __cplusplus extern "C" { #endif -// result values that represent the type of command found +/** + * result values that represent the type of command found. + */ #ifndef _di_f_console_ids_ - #define f_console_none 0 - #define f_console_short_enable 1 - #define f_console_short_disable 2 - #define f_console_long_enable 3 - #define f_console_long_disable 4 - #define f_console_extra_enable 5 - #define f_console_extra_disable 6 - #define f_console_empty_short_enable 7 - #define f_console_empty_short_disable 8 - #define f_console_empty_long_enable 9 - #define f_console_empty_long_disable 10 - #define f_console_empty_extra_enable 11 - #define f_console_empty_extra_disable 12 + enum { + f_console_none, + f_console_short_enable, + f_console_short_disable, + f_console_long_enable, + f_console_long_disable, + f_console_extra_enable, + f_console_extra_disable, + f_console_empty_short_enable, + f_console_empty_short_disable, + f_console_empty_long_enable, + f_console_empty_long_disable, + f_console_empty_extra_enable, + f_console_empty_extra_disable, + }; #endif // _di_f_console_ids_ -// the symbols passed to the program for option handling +/** + * the symbols passed to the program for option handling. + * + * The following will be processed as an integer and therefore must not be string. + * - f_console_symbol_enable + * - f_console_symbol_disable + */ #ifndef _di_f_console_symbols_ - #define f_console_symbol_enable '-' // this will be processed as an integer and therefore must not be string - #define f_console_symbol_disable '+' // this will be processed as an integer and therefore must not be string + #define f_console_symbol_enable '-' + #define f_console_symbol_disable '+' + #define f_console_symbol_short_enable "-" #define f_console_symbol_short_disable "+" - #define f_console_symbol_long_enable "--" - #define f_console_symbol_long_disable "++" + + #define f_console_symbol_long_enable "--" + #define f_console_symbol_long_disable "++" + #define f_console_symbol_extra_enable "---" #define f_console_symbol_extra_disable "+++" #endif // _di_f_console_symbols_ -// create some standard command line parameter options required by the kevux/fss/fll specifications +// create some standard command line parameter options required by the kevux/fss/fll specifications. #ifndef _di_f_standard_console_parameters_ + #define f_console_standard_short_debug "d" #define f_console_standard_short_help "h" #define f_console_standard_short_light "l" #define f_console_standard_short_no_color "n" #define f_console_standard_short_version "v" - #define f_console_standard_short_debug "d" + #define f_console_standard_long_debug "debug" #define f_console_standard_long_help "help" #define f_console_standard_long_light "light" #define f_console_standard_long_no_color "no_color" #define f_console_standard_long_version "version" - #define f_console_standard_long_debug "debug" #endif // _di_f_standard_console_parameters_ // the maximum size for a single parameter (this should be hellishly more than enough) @@ -78,12 +91,22 @@ extern "C" { #ifndef _di_f_console_types_ typedef f_min_u_short f_console_id; + /** + * none: parameter not found. + * found: parameter found. + * additional: parameter found, extra data exists (such as '-f filename', filename would be the extra data). + */ enum { f_console_result_none, f_console_result_found, - f_console_result_additional, // something was found and extra data exists (such as '-f filename', filename would be the extra data) + f_console_result_additional, }; + /** + * normal: parameters using minus sign, such as '--help'. + * inverse: parameters using plus sign, such as '++version'. + * other: parameters using neither minus nor plus sign, such as 'build'. + */ enum { f_console_type_normal, f_console_type_inverse, @@ -98,9 +121,10 @@ extern "C" { const char *symbol_extra; const char *symbol_other; - const f_bool has_additional; - const f_u_int type; - f_u_int result; + const f_bool has_additional; + const f_u_int type; + f_u_int result; + f_string_lengths additional; f_string_length length; } f_console_parameter; @@ -110,45 +134,59 @@ extern "C" { #endif // _di_f_console_parameter_ #ifndef _di_f_console_identify_ - // This is used to help standardize a single method of handling command line option parsing. - // This should allow for every single command line program to use the same form of syntax for command line options. + /** + * This is used to help standardize a single method of handling command line option parsing. + * This should allow for every single command line program to use the same form of syntax for command line options. + */ extern f_return_status f_console_identify(const f_string input, f_console_id *result); #endif // _di_f_console_identify_ -// perform checks against short & long options to see if the string is one of them (normal) #ifndef _di_f_console_is_enable_ + /** + * perform checks against short & long options to see if the string is one of them (normal). + */ #define f_console_is_enable(result, string, short_option, long_option, max_length) \ ((result == f_console_short_enable && strncmp(string, short_option, 1) == 0) || \ (result == f_console_long_enable && strncmp(string, long_option, max_length) == 0)) #endif // _di_f_console_is_enable_ -// perform checks against short & long options to see if the string is one of them (inverse) #ifndef _di_f_console_is_disable_ + /** + * perform checks against short & long options to see if the string is one of them (inverse). + */ #define f_console_is_disable(result, string, short_option, long_option, max_length) \ ((result == f_console_short_disable && strncmp(string, short_option, 1) == 0) || \ (result == f_console_long_disable && strncmp(string, long_option, max_length) == 0)) #endif // _di_f_console_is_disable_ -// perform checks against extra option to see if the string is one of them (normal) #ifndef _di_f_console_is_extra_enable_ + /** + * perform checks against extra option to see if the string is one of them (normal). + */ #define f_console_is_extra_enable(result, string, extra_option, max_length) \ (result == f_console_extra_enable && strncmp(string, extra_option, max_length) == 0) #endif // _di_f_console_is_extra_enable_ -// perform checks against extra option to see if the string is one of them (inverse) #ifndef _di_f_console_is_extra_disable_ + /** + * perform checks against extra option to see if the string is one of them (inverse). + */ #define f_console_is_extra_disable(result, string, extra_option, max_length) \ (result == f_console_extra_disable && strncmp(string, extra_option, max_length) == 0) #endif // _di_f_console_is_extra_disable_ -// perform checks against empty options to see if the string is one of them (normal) #ifndef _di_f_console_is_empty_enable_ + /** + * perform checks against empty options to see if the string is one of them (normal). + */ #define f_console_is_empty_enable(result, string) \ (result == f_console_empty_short_enable || result == f_console_empty_long_enable || result == f_console_empty_extra_enable) #endif // _di_f_console_is_empty_enable_ -// perform checks against empty options to see if the string is one of them (inverse) #ifndef _di_f_console_is_empty_disable_ + /** + * perform checks against empty options to see if the string is one of them (inverse). + */ #define f_console_is_empty_disable(result, string) \ (result == f_console_empty_short_disable || result == f_console_empty_long_disable || result == f_console_empty_extra_disable) #endif // _di_f_console_is_empty_disable_ diff --git a/level_0/f_conversion/c/conversion.c b/level_0/f_conversion/c/conversion.c index 1e9efa5..b89f49c 100644 --- a/level_0/f_conversion/c/conversion.c +++ b/level_0/f_conversion/c/conversion.c @@ -143,11 +143,13 @@ extern "C" { if (scale > 0) { *digit = 10 * *digit; *digit += temp_digit; - } else { + } + else { scale = 1; *digit = temp_digit; } - } else { + } + else { break; } @@ -178,11 +180,13 @@ extern "C" { if (scale > 0) { *digit <<= 4; *digit += temp_digit; - } else { + } + else { scale = 1; *digit = temp_digit; } - } else { + } + else { break; } diff --git a/level_0/f_conversion/c/conversion.h b/level_0/f_conversion/c/conversion.h index 45effac..25628d4 100644 --- a/level_0/f_conversion/c/conversion.h +++ b/level_0/f_conversion/c/conversion.h @@ -10,58 +10,74 @@ * In the future this will have to link to locale support, due to interpeting strings. * * Possible error values on return: - * f_warn - a possible problem, but not an error (warning) - * f_critical - an error - * f_unknown - an unknown error - * f_invalid_parameter - a parameter sent to this function is invalid, error - * f_invalid_syntax - syntax for data sent to this is invalid, error - * f_invalid_data - something is wrong with the data sent to this function, error - * f_no_data - something is wrong with the data sent to this function, warning - * f_none - no errors or warnings + * f_critical - an error. + * f_invalid_data - something is wrong with the data sent to this function, error. + * f_invalid_parameter - a parameter sent to this function is invalid, error. + * f_invalid_syntax - syntax for data sent to this is invalid, error. + * f_no_data - something is wrong with the data sent to this function, warning. + * f_none - no errors or warnings. + * f_unknown - an unknown error. + * f_warn - a possible problem, but not an error (warning). */ #ifndef _F_conversion_h #define _F_conversion_h +// libc includes +#include + // fll includes -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_f_is_digit_ - // convert a single character into the digit that it represents + /** + * convert a single character into the digit that it represents. + */ extern f_return_status f_is_digit(const char character); #endif // _di_f_is_digit_ #ifndef _di_f_is_hexdigit_ - // convert a single character into the hexidecimal digit that it represents + /** + * convert a single character into the hexidecimal digit that it represents + */ extern f_return_status f_is_hexdigit(const char character); #endif // _di_f_is_hexdigit_ #ifndef _di_f_character_to_digit_ - // convert a single character into the digit that it represents + /** + * convert a single character into the digit that it represents. + */ extern f_return_status f_character_to_digit(const char character, f_u_long *digit); #endif // _di_f_character_to_digit_ #ifndef _di_f_character_to_hexdigit_ - // convert a single character into the hexidecimal digit that it represents + /** + *convert a single character into the hexidecimal digit that it represents. + */ extern f_return_status f_character_to_hexdigit(const char character, f_u_long *digit); #endif // _di_f_character_to_hexdigit_ #ifndef _di_f_string_to_digit_ - // works like atoi, except there is a start/stop range - // convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-digit - // will not process signed statuses (+/-) + /** + * works like atoi, except there is a start/stop range. + * convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-digit. + * will not process signed statuses (+/-). + */ extern f_return_status f_string_to_digit(const f_string string, f_u_long *digit, const f_string_location location); #endif // _di_f_string_to_digit_ #ifndef _di_f_string_to_hexdigit_ - // works like atoi, except there is a start/stop range and that this is for hexidecimal digits - // convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-hexdigit - // will not process signed statuses (+/-) + + /** + * works like atoi, except there is a start/stop range and that this is for hexidecimal digits. + * convert a series of positive numbers into a string, stopping at one of the following: EOS, max_length, or a non-hexdigit. + * will not process signed statuses (+/-). + */ extern f_return_status f_string_to_hexdigit(const f_string string, f_u_long *digit, const f_string_location location); #endif // _di_f_string_to_hexdigit_ diff --git a/level_0/f_errors/c/errors.h b/level_0/f_errors/c/errors.h index d4a809b..6ba80b8 100644 --- a/level_0/f_errors/c/errors.h +++ b/level_0/f_errors/c/errors.h @@ -141,26 +141,27 @@ extern "C" { #ifndef _di_f_error_masks_ // f_status is required to be exactly 16 bits, the first two high order bits represent error and warning respectively. - #define f_error_bit_error 32768 - #define f_error_bit_warning 16384 - #define f_error_bit_mask 49152 - #define f_error_bit_fine 16383 - #define f_error_bit_signal 49152 - - #define f_error_is_error(status) status & f_error_bit_error - #define f_error_is_warning(status) status & f_error_bit_warning - #define f_error_is_problem(status) status & f_error_bit_mask - #define f_error_is_fine(status) (status & f_error_bit_mask) == 0 + #define f_error_bit_error 32768 + #define f_error_bit_fine 16383 + #define f_error_bit_mask 49152 + #define f_error_bit_signal 49152 + #define f_error_bit_warning 16384 + + #define f_error_is_error(status) status & f_error_bit_error + #define f_error_is_fine(status) (status & f_error_bit_mask) == 0 + #define f_error_is_problem(status) status & f_error_bit_mask + #define f_error_is_warning(status) status & f_error_bit_warning + #define f_error_is_not_error(status) (status & f_error_bit_error) == 0 - #define f_error_is_not_warning(status) (status & f_error_bit_warning) == 0 #define f_error_is_not_signal(status) (status & f_error_bit_signal) == 0 + #define f_error_is_not_warning(status) (status & f_error_bit_warning) == 0 // use both error and warning bits to designate that the response is a signal. #define f_error_is_signal(status) (status & f_error_bit_signal) == f_error_bit_signal #define f_error_set_error(status) status | f_error_bit_error - #define f_error_set_warning(status) status | f_error_bit_warning #define f_error_set_signal(status) status | f_error_bit_signal + #define f_error_set_warning(status) status | f_error_bit_warning // use f_error_set_fine to remove the error, warning, and signal bits #define f_error_set_fine(status) status & f_error_bit_fine diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 2a16a79..96a9033 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -97,7 +97,8 @@ extern "C" { if (current_file_position > location.file_start) { result = f_file_seek_from_current(file_information->file, file_information->byte_size * (0 - (current_file_position - location.file_start))); - } else if (current_file_position < location.file_start) { + } + else if (current_file_position < location.file_start) { result = f_file_seek_from_current(file_information->file, file_information->byte_size * (location.file_start - current_file_position)); } @@ -106,7 +107,8 @@ extern "C" { // now do the actual read if (location.total_elements == 0) { result = fread(buffer->string + location.buffer_start, file_information->byte_size, buffer->size - buffer->used - 1, file_information->file); - } else { + } + else { result = fread(buffer->string + location.buffer_start, file_information->byte_size, location.total_elements, file_information->file); } diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index d8fc2c2..4ca4fc2 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -12,17 +12,17 @@ #define _F_file_h // libc includes -#include -#include #include -#include +#include +#include #include +#include #include // fll-0 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { @@ -54,20 +54,22 @@ extern "C" { #ifndef _di_f_file_ typedef struct { - f_file_id id; // file descriptor - FILE * file; // the file data type - f_file_mode mode; // how the file is to be accessed (or is being accessed) - size_t byte_size; // how many bytes to use on each read/write (for normal string handling this should be sizeof(f_string) + f_file_id id; // file descriptor + size_t byte_size; // how many bytes to use on each read/write (for normal string handling this should be sizeof(f_string) + FILE * file; // the file data type + f_file_mode mode; // how the file is to be accessed (or is being accessed) } f_file; - #define f_file_initialize { 0, 0, (f_file_mode) f_file_read_only, sizeof(char) } + #define f_file_initialize { 0, sizeof(char), 0, (f_file_mode) f_file_read_only } #endif // _di_f_file_ #ifndef _di_f_file_position_ - // buffer_start designate where to start writing to the buffer - // file_start is the positions where to begin reading the file - // total_elements is the total number of elements to read from the file into the buffer - // if total_elements is set to 0, then this means to buffer the entire file no matter how big it is (crazy?) + /** + * buffer_start designate where to start writing to the buffer. + * file_start is the positions where to begin reading the file. + * total_elements is the total number of elements to read from the file into the buffer. + * if total_elements is set to 0, then this means to buffer the entire file no matter how big it is (crazy?). + */ typedef struct { f_string_length buffer_start; f_string_length file_start; @@ -197,36 +199,52 @@ extern "C" { #endif // _di_f_macro_file_reset_position_ #ifndef _di_f_file_open_ - // open a particular file and save its stream - // filename = name of the file + /** + * open a particular file and save its stream. + * filename = name of the file. + */ extern f_return_status f_file_open(f_file *file_information, const f_string filename); #endif // _di_f_file_open_ #ifndef _di_f_file_close_ - // close file + /** + * close file. + */ extern f_return_status f_file_close(f_file *file_information); #endif // _di_f_file_close_ #ifndef _di_f_file_flush_ - // flush file + /** + * flush file. + */ extern f_return_status f_file_flush(f_file *file_information); #endif // _di_f_file_flush_ #ifndef _di_f_file_read_ - // read a given amount of data from the buffer, will auto-seek to where + /** + * read a given amount of data from the buffer, will auto-seek to where. + */ extern f_return_status f_file_read(f_file *file_information, f_dynamic_string *buffer, const f_file_position location); #endif // _di_f_file_read_ #ifndef _di_f_file_read_fifo_ - // read a given amount of data from the buffer, will not auto seek + /** + * read a given amount of data from the buffer, will not auto seek. + */ extern f_return_status f_file_read_fifo(f_file *file_information, f_dynamic_string *buffer); #endif // _di_f_file_read_fifo_ #ifndef _di_f_file_stat_ + /** + * read file statistics. + */ extern f_return_status f_file_stat(const f_string file, struct stat *file_stat); #endif // _di_f_file_stat_ #ifndef _di_f_file_stat_by_id_ + /** + * read file statistics by file id. + */ extern f_return_status f_file_stat_by_id(const f_s_int file_id, struct stat *file_stat); #endif // _di_f_file_stat_by_id_ diff --git a/level_0/f_fss/c/fss.h b/level_0/f_fss/c/fss.h index 07933ab..0447579 100644 --- a/level_0/f_fss/c/fss.h +++ b/level_0/f_fss/c/fss.h @@ -15,8 +15,8 @@ // fll includes #include -#include #include +#include #ifdef __cplusplus extern "C" { @@ -96,22 +96,32 @@ enum { #define f_adjust_fss_delimits(status, array, new_length) f_adjust_string_location_array(status, array, new_length) #endif // _di_f_fss_delimits_ -// stores information about a particular fss file, otherwise know as its header +/** + * stores information about a particular fss file, otherwise know as its header. + * + * type: the kind of fss file is this. + * length: Total length of the header. + */ #ifndef _di_f_fss_header_ typedef struct { - f_fss_id type; // what kind of fss file is this? - f_fss_header_length length; // Total length of the header + f_fss_id type; + f_fss_header_length length; } f_fss_header; #define f_fss_header_initialize { f_fss_id_initialize, f_fss_header_length_initialize } #endif // _di_f_fss_header_ -// This holds an array of fss_headers +/** + * This holds an array of fss_headers. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_fss_headers_ typedef struct { - f_fss_header *array; // the array of fss headers - f_string_length size; // total amount of allocated space - f_string_length used; // total number of allocated spaces used + f_fss_header *array; + f_string_length size; + f_string_length used; } f_fss_headers; #define f_fss_headers_initialize { 0, 0, 0 } @@ -131,7 +141,9 @@ enum { #endif // _di_f_fss_headers_ -// This is a location that represents an object +/** + * This is a location that represents an object. + */ #ifndef _di_fss_object_ typedef f_string_location f_fss_object; #define f_fss_object_initialize f_string_location_initialize @@ -147,12 +159,17 @@ enum { status = f_adjust((void **) & object, sizeof(f_fss_object), old_length, new_length) #endif // _di_fss_object_ -// This holds an array of fss_object +/** + * This holds an array of fss_object. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_fss_objects_ typedef struct { - f_fss_object *array; // the array of fss objects - f_string_length size; // total amount of allocated space - f_string_length used; // total number of allocated spaces used + f_fss_object *array; + f_string_length size; + f_string_length used; } f_fss_objects; #define f_fss_objects_initialize { 0, 0, 0 } @@ -170,15 +187,20 @@ enum { f_destroy_structure(status, objects, f_fss_object, new_length) #endif // _di_fss_objects_ -// This holds an array of string locations that represent the content -// The very first string location will represent the outmost content -// All of the following string locations will represent the first level of nesting of all sub-content -// There will be no nesting beyond the first level recorded in this structure +/** + * This holds an array of string locations that represent the content. + * The very first string location will represent the outmost content. + * All of the following string locations will represent the first level of nesting of all sub-content. + * There will be no nesting beyond the first level recorded in this structure. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_fss_content_ typedef struct { f_string_location *array; // the array of locations - f_array_length size; // total amount of allocated space - f_array_length used; // total number of allocated spaces used + f_array_length size; // total amount of allocated space + f_array_length used; // total number of allocated spaces used } f_fss_content; #define f_fss_content_initialize { 0, 0, 0 } @@ -196,12 +218,17 @@ enum { f_adjust_structure(status, content, f_string_location, new_length) #endif // _di_fss_content_ -// This holds an array of fss_content +/** + * This holds an array of fss_content. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_fss_contents_ typedef struct { - f_fss_content *array; // the array of fss content - f_array_length size; // total amount of allocated space - f_array_length used; // total number of allocated spaces used + f_fss_content *array; + f_array_length size; + f_array_length used; } f_fss_contents; #define f_fss_contents_initialize { 0, 0, 0 } diff --git a/level_0/f_memory/c/memory.c b/level_0/f_memory/c/memory.c index c460fc5..c5155d3 100644 --- a/level_0/f_memory/c/memory.c +++ b/level_0/f_memory/c/memory.c @@ -86,7 +86,8 @@ extern "C" { // allocate new space if (new_length > 0) { new_pointer = realloc(*pointer, type * new_length); - } else { + } + else { free(*pointer); // it has been deallocated, so reset the pointer @@ -108,13 +109,15 @@ extern "C" { return f_none; } - } else if (new_length > 0) { + } + else if (new_length > 0) { *pointer = calloc(type, new_length); if (*pointer) { return f_none; } - } else { + } + else { return f_none; } @@ -148,7 +151,8 @@ extern "C" { // allocate new space if (new_length > 0) { new_pointer = realloc(*pointer, type * new_length); - } else { + } + else { free(*pointer); // it has been deallocated, so reset the pointer @@ -170,13 +174,15 @@ extern "C" { return f_none; } - } else if (new_length > 0) { + } + else if (new_length > 0) { *pointer = calloc(type, new_length); if (*pointer) { return f_none; } - } else { + } + else { return f_none; } diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index 65d2d5b..74b4f54 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -8,29 +8,29 @@ * Provide means to use memory routines, with error checking. * * Possible error values on return: - * f_warn - a possible problem, but not an error (warning) - * f_critical - an error - * f_unknown - an unknown error - * f_invalid_parameter - a parameter sent to this function is invalid, error - * f_invalid_syntax - syntax for data sent to this is invalid, error - * f_invalid_data - something is wrong with the data sent to this function, error - * f_no_data - something is wrong with the data sent to this function, warning - * f_none - no errors or warnings - * f_allocation_error - an error during the allocation process - * f_reallocation_error - an error during the reallocation process - * f_deallocation_error - an error during the deallocation process + * f_allocation_error - an error during the allocation process. + * f_critical - an error. + * f_deallocation_error - an error during the deallocation process. + * f_invalid_data - something is wrong with the data sent to this function, error. + * f_invalid_parameter - a parameter sent to this function is invalid, error. + * f_invalid_syntax - syntax for data sent to this is invalid, error. + * f_no_data - something is wrong with the data sent to this function, warning. + * f_none - no errors or warnings. + * f_reallocation_error - an error during the reallocation process. + * f_unknown - an unknown error. + * f_warn - a possible problem, but not an error (warning). */ #ifndef _F_memory_h #define _F_memory_h // libc includes +#include #include #include -#include // fll includes -#include #include +#include #ifdef __cplusplus extern "C" { @@ -52,10 +52,12 @@ extern "C" { #ifndef _di_f_memory_default_allocation_step_ - // Everytime some array needs a single new element, reallocated by this amount - // Normally, this should be small, but when a large number of singular allocations are made, the overhead can be reduced by not having to reallocate space as often - // The problem then is that the more space allocated beyond what is initially needed will waste precious memory - // Change this if you know your application can afford to reduce the allocation overhead at the cost of more memory + /** + * Everytime some array needs a single new element, reallocated by this amount. + * Normally, this should be small, but when a large number of singular allocations are made, the overhead can be reduced by not having to reallocate space as often. + * The problem then is that the more space allocated beyond what is initially needed will waste precious memory. + * Change this if you know your application can afford to reduce the allocation overhead at the cost of more memory. + */ #define f_memory_default_allocation_step 3 #endif // _di_f_memory_default_allocation_step_ @@ -71,34 +73,44 @@ extern "C" { #endif // _di_f_new_ #if ! ( defined (_di_f_delete_) || defined (_f_memory_FORCE_secure_memory_) ) - // deletes some dynamically allocated data - // f_delete, will not change any of the data to 0 prior to deallocation - // type and length are not used by this function normally but must be provided for the cases when f_delete is swapped with f_destroy (or vice-versa) + /** + * deletes some dynamically allocated data. + * f_delete, will not change any of the data to 0 prior to deallocation. + * type and length are not used by this function normally but must be provided for the cases when f_delete is swapped with f_destroy (or vice-versa). + */ extern f_return_status f_delete(void **pointer, const f_memory_size_t type, const f_memory_length length); #endif // ! ( defined (_di_f_delete_) || defined (_f_memory_FORCE_secure_memory_) ) #if ! ( defined (_di_f_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) - // securely deletes some dynamically allocated data - // f_destroy, will change all data to 0 prior to deallocation + /** + * securely deletes some dynamically allocated data. + * f_destroy, will change all data to 0 prior to deallocation. + */ extern f_return_status f_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length); #endif // ! ( defined (_di_f_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) #if ! ( defined (_di_f_resize_) || defined (_f_memory_FORCE_secure_memory_) ) - // resizes some dynamically allocated data - // f_resize, will not change any of the data prior to deallocation + /** + * resizes some dynamically allocated data. + * f_resize, will not change any of the data prior to deallocation. + */ extern f_return_status f_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length); #endif // ! ( defined (_di_f_resize_) || defined (_f_memory_FORCE_secure_memory_) ) #if ! ( defined (_di_f_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) - // securely resizes some dynamically allocated data - // f_adjust, will change all data to 0 prior to deallocation + /** + * securely resizes some dynamically allocated data. + * f_adjust, will change all data to 0 prior to deallocation. + */ extern f_return_status f_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length); #endif // _di_f_adjust_ // centralize allocation for all FLL structures that follow the size+used approach. #ifndef _di_f_clear_structure_ - // structure: the structure to operate on + /** + * structure: the structure to operate on. + */ #define f_clear_structure(structure) \ structure.array = 0; \ structure.size = 0; \ @@ -106,9 +118,11 @@ extern "C" { #endif // _di_f_clear_structure_ #ifndef _di_f_new_structure_ - // status: the status to return - // structure: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ #define f_new_structure(status, structure, type, length) \ structure.array = 0; \ structure.size = 0; \ @@ -122,9 +136,11 @@ extern "C" { // improper use of these defines can lead to memory leaks and compilation errors #ifndef _di_f_delete_structure_ - // status: the status to return - // structure: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ #define f_delete_structure(status, structure, type) \ status = f_delete((void **) & structure.array, sizeof(type), structure.size); \ if (status == f_none) { \ @@ -134,9 +150,11 @@ extern "C" { #endif // _di_f_delete_structure_ #ifndef _di_f_destroy_structure_ - // status: the status to return - // structure: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ #define f_destroy_structure(status, structure, type) \ status = f_destroy((void **) & structure.array, sizeof(type), structure.size); \ if (status == f_none) { \ @@ -146,9 +164,11 @@ extern "C" { #endif // _di_f_destroy_structure_ #ifndef _di_f_resize_structure_ - // status: the status to return - // structure: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ #define f_resize_structure(status, structure, type, new_length) \ status = f_resize((void **) & structure.array, sizeof(type), structure.size, new_length); \ if (status == f_none) { \ @@ -158,9 +178,11 @@ extern "C" { #endif // _di_f_resize_structure_ #ifndef _di_f_adjust_structure_ - // status: the status to return - // structure: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structure: the structure to operate on. + * type: the structure type. + */ #define f_adjust_structure(status, structure, type, new_length) \ status = f_adjust((void **) & structure.array, sizeof(type), structure.size, new_length); \ if (status == f_none) { \ @@ -173,7 +195,9 @@ extern "C" { // however, these hold an array of structure // improper use of these defines can lead to memory leaks and compilation errors #ifndef _di_f_clear_structures_ - // structure: the structure to operate on + /** + * structure: the structure to operate on. + */ #define f_clear_structures(structures) \ structures.array = 0; \ structures.size = 0; \ @@ -181,9 +205,11 @@ extern "C" { #endif // _di_f_clear_structures_ #ifndef _di_f_new_structures_ - // status: the status to return - // structures: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structures: the structure to operate on. + * type: the structure type. + */ #define f_new_structures(status, structures, type, new_length) \ structures.array = 0; \ structures.size = 0; \ @@ -196,9 +222,11 @@ extern "C" { #endif // _di_f_new_structures_ #ifndef _di_f_delete_structures_ - // status: the status to return - // structures: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structures: the structure to operate on. + * type: the structure type. + */ #define f_delete_structures(status, structures, type) \ status = f_none; \ while (structures.size > 0) { \ @@ -211,9 +239,11 @@ extern "C" { #endif // _di_f_delete_structures_ #ifndef _di_f_destroy_structures_ - // status: the status to return - // structures: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structures: the structure to operate on. + * type: the structure type. + */ #define f_destroy_structures(status, structures, type) \ status = f_none; \ while (structures.size > 0) { \ @@ -226,9 +256,11 @@ extern "C" { #endif // _di_f_destroy_structures_ #ifndef _di_f_resize_structures_ - // status: the status to return - // structures: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structures: the structure to operate on. + * type: the structure type. + */ #define f_resize_structures(status, structures, type, new_length, length_variable) \ status = f_none; \ if (new_length < structures.size) { \ @@ -252,9 +284,11 @@ extern "C" { #endif // _di_f_resize_structures_ #ifndef _di_f_adjust_structures_ - // status: the status to return - // structures: the structure to operate on - // type: the structure type + /** + * status: the status to return. + * structures: the structure to operate on. + * type: the structure type. + */ #define f_adjust_structures(status, structures, type, new_length, length_variable) \ status = f_none; \ if (new_length < structures.size) { \ diff --git a/level_0/f_paths/c/filesystem_paths.h b/level_0/f_paths/c/filesystem_paths.h index dad5c92..8ee02a8 100644 --- a/level_0/f_paths/c/filesystem_paths.h +++ b/level_0/f_paths/c/filesystem_paths.h @@ -22,67 +22,67 @@ extern "C" { #define _di_filesystem_hierarch_standard_paths_ // KFS Root Level - #define f_path_devices "/devices" - #define f_path_external "/external" - #define f_path_libraries "/libraries" - #define f_path_programs "/programs" - #define f_path_temporary "/temporary" - #define f_path_home "/home" - #define f_path_run "/run" - #define f_path_binary "/.system" + #define f_path_devices "/devices" + #define f_path_external "/external" + #define f_path_libraries "/libraries" + #define f_path_programs "/programs" + #define f_path_temporary "/temporary" + #define f_path_home "/home" + #define f_path_run "/run" + #define f_path_binary "/.system" // Kernel Level - #define f_path_boot f_path_devices"/boot" - #define f_path_hardware f_path_devices"/devices" - #define f_path_processes f_path_devices"/processes" - #define f_path_system f_path_devices"/system" + #define f_path_boot f_path_devices"/boot" + #define f_path_hardware f_path_devices"/devices" + #define f_path_processes f_path_devices"/processes" + #define f_path_system f_path_devices"/system" // Program Level - #define f_path_programs_public f_path_programs"/public" - #define f_path_programs_system f_path_programs"/system" - #define f_path_programs_remote f_path_programs"/remote" - #define f_path_programs_services f_path_programs"/targets" - #define f_path_programs_toolchain f_path_programs"/toolchain" - #define f_path_programs_users f_path_programs"/users" - #define f_path_programs_susers f_path_programs"/users" - #define f_path_programs_boot f_path_boot"/programs" - #define f_path_programs_sboot f_path_boot"/programs" + #define f_path_programs_public f_path_programs"/public" + #define f_path_programs_system f_path_programs"/system" + #define f_path_programs_remote f_path_programs"/remote" + #define f_path_programs_services f_path_programs"/targets" + #define f_path_programs_toolchain f_path_programs"/toolchain" + #define f_path_programs_users f_path_programs"/users" + #define f_path_programs_susers f_path_programs"/users" + #define f_path_programs_boot f_path_boot"/programs" + #define f_path_programs_sboot f_path_boot"/programs" // Library Level - #define f_path_libraries_public f_path_libraries"/public" - #define f_path_libraries_system f_path_libraries"/system" - #define f_path_libraries_remote f_path_libraries"/remote" - #define f_path_libraries_services f_path_libraries"/targets" - #define f_path_libraries_toolchain f_path_libraries"/toolchain" - #define f_path_libraries_users f_path_libraries"/users" - #define f_path_libraries_boot f_path_boot"/libraries" + #define f_path_libraries_public f_path_libraries"/public" + #define f_path_libraries_system f_path_libraries"/system" + #define f_path_libraries_remote f_path_libraries"/remote" + #define f_path_libraries_services f_path_libraries"/targets" + #define f_path_libraries_toolchain f_path_libraries"/toolchain" + #define f_path_libraries_users f_path_libraries"/users" + #define f_path_libraries_boot f_path_boot"/libraries" // Home Level - #define f_path_home_services f_path_home"/services" - #define f_path_home_share f_path_home"/share" - #define f_path_home_users f_path_home"/users" - #define f_path_home_websites f_path_home"/websites" + #define f_path_home_services f_path_home"/services" + #define f_path_home_share f_path_home"/share" + #define f_path_home_users f_path_home"/users" + #define f_path_home_websites f_path_home"/websites" // System Level - #define f_path_system_logs f_path_system"/logs" - #define f_path_system_settings f_path_system"/settings" - #define f_path_system_data f_path_system"/data" - #define f_path_system_variables f_path_system"/variables" // for backwards FHS support only, use of this directory is considered bad practice for KFS, use f_path_temporary_variables instead + #define f_path_system_logs f_path_system"/logs" + #define f_path_system_settings f_path_system"/settings" + #define f_path_system_data f_path_system"/data" + #define f_path_system_variables f_path_system"/variables" // for backwards FHS support only, use of this directory is considered bad practice for KFS, use f_path_temporary_variables instead // Temporary Level - #define f_path_temporary_public f_path_temporary"/public" - #define f_path_temporary_services f_path_temporary"/services" - #define f_path_temporary_users f_path_temporary"/users" - #define f_path_temporary_variables f_path_temporary"/variables" + #define f_path_temporary_public f_path_temporary"/public" + #define f_path_temporary_services f_path_temporary"/services" + #define f_path_temporary_users f_path_temporary"/users" + #define f_path_temporary_variables f_path_temporary"/variables" // Private User Directories - #define f_path_user_downloads "downloads" - #define f_path_user_desktop "desktop" - #define f_path_user_private "private" - #define f_path_user_settings "settings" - #define f_path_user_data "data" - #define f_path_user_temporary "temporary" - #define f_path_user_shared "shared" + #define f_path_user_downloads "downloads" + #define f_path_user_desktop "desktop" + #define f_path_user_private "private" + #define f_path_user_settings "settings" + #define f_path_user_data "data" + #define f_path_user_temporary "temporary" + #define f_path_user_shared "shared" #endif // _di_kevux_standard_paths_ // FHS Filesystem Paths @@ -91,67 +91,67 @@ extern "C" { #define _di_kevux_standard_paths_ // KFS Root Level - #define f_path_devices "/" - #define f_path_external "/mnt" - #define f_path_libraries "/" - #define f_path_programs "/" - #define f_path_temporary "/" - #define f_path_home "/home" - #define f_path_run "/run" - #define f_path_binary "/.system" + #define f_path_devices "/" + #define f_path_external "/mnt" + #define f_path_libraries "/" + #define f_path_programs "/" + #define f_path_temporary "/" + #define f_path_home "/home" + #define f_path_run "/run" + #define f_path_binary "/.system" // FHS Root Level - #define f_path_boot "/boot" - #define f_path_hardware "/dev" - #define f_path_processes "/proc" - #define f_path_system "/sysfs" + #define f_path_boot "/boot" + #define f_path_hardware "/dev" + #define f_path_processes "/proc" + #define f_path_system "/sysfs" // Program Level - #define f_path_programs_public "/usr/bin" - #define f_path_programs_system "/usr/sbin" - #define f_path_programs_remote "/usr/bin" - #define f_path_programs_services "/usr/sbin" - #define f_path_programs_toolchain "/usr/bin" - #define f_path_programs_users "/usr/local/bin" - #define f_path_programs_susers "/usr/local/sbin" - #define f_path_programs_boot "/bin" - #define f_path_programs_sboot "/sbin" + #define f_path_programs_public "/usr/bin" + #define f_path_programs_system "/usr/sbin" + #define f_path_programs_remote "/usr/bin" + #define f_path_programs_services "/usr/sbin" + #define f_path_programs_toolchain "/usr/bin" + #define f_path_programs_users "/usr/local/bin" + #define f_path_programs_susers "/usr/local/sbin" + #define f_path_programs_boot "/bin" + #define f_path_programs_sboot "/sbin" // Library Level - #define f_path_libraries_public "/usr/lib" - #define f_path_libraries_system "/usr/lib" - #define f_path_libraries_remote "/usr/lib" - #define f_path_libraries_services "/usr/lib" - #define f_path_libraries_toolchain "/usr/lib" - #define f_path_libraries_users "/usr/local/lib" - #define f_path_libraries_boot "/lib" + #define f_path_libraries_public "/usr/lib" + #define f_path_libraries_system "/usr/lib" + #define f_path_libraries_remote "/usr/lib" + #define f_path_libraries_services "/usr/lib" + #define f_path_libraries_toolchain "/usr/lib" + #define f_path_libraries_users "/usr/local/lib" + #define f_path_libraries_boot "/lib" // Home Level - #define f_path_home_services "/srv" - #define f_path_home_share "/" - #define f_path_home_users f_path_home - #define f_path_home_websites "/srv/www" + #define f_path_home_services "/srv" + #define f_path_home_share "/" + #define f_path_home_users f_path_home + #define f_path_home_websites "/srv/www" // System Level - #define f_path_system_logs "/var/log" - #define f_path_system_settings "/etc" - #define f_path_system_data "/usr/share" - #define f_path_system_variables "/var" + #define f_path_system_logs "/var/log" + #define f_path_system_settings "/etc" + #define f_path_system_data "/usr/share" + #define f_path_system_variables "/var" // Temporary Level - #define f_path_temporary_public "/tmp" - #define f_path_temporary_services "/tmp" - #define f_path_temporary_users "/tmp" - #define f_path_temporary_variables "/var/tmp" + #define f_path_temporary_public "/tmp" + #define f_path_temporary_services "/tmp" + #define f_path_temporary_users "/tmp" + #define f_path_temporary_variables "/var/tmp" // Private User Directories - #define f_path_user_downloads "downloads" - #define f_path_user_desktop "desktop" - #define f_path_user_private "" - #define f_path_user_settings "" - #define f_path_user_data "" - #define f_path_user_temporary "" - #define f_path_user_shared "" + #define f_path_user_downloads "downloads" + #define f_path_user_desktop "desktop" + #define f_path_user_private "" + #define f_path_user_settings "" + #define f_path_user_data "" + #define f_path_user_temporary "" + #define f_path_user_shared "" #endif // _di_filesystem_hierarch_standard_paths_ #ifdef __cplusplus diff --git a/level_0/f_paths/c/fll_paths.h b/level_0/f_paths/c/fll_paths.h index 7ac452c..03bf40c 100644 --- a/level_0/f_paths/c/fll_paths.h +++ b/level_0/f_paths/c/fll_paths.h @@ -19,23 +19,23 @@ extern "C" { #endif -// TODO: don't forget to completely restructure the paths layout before 0.1.0 is released +// TODO: don't forget to completely restructure the paths layout before 1.0.0 is released #ifndef _di_fll_paths_ - #define f_path_fll_base f_path_system_settings "/fll" // directory - #define f_path_fll_settings "settings" // directory - #define f_path_fll_packages "packages" // directory - #define f_path_fll_patches "patches" // directory - #define f_path_fll_archive "archive" // directory - #define f_path_fll_groups "groups" // directory - #define f_path_fll_licenses "licenses" // directory - #define f_path_fll_global "global" // file - #define f_path_fll_paths "paths" // file - #define f_path_fll_listing "listing" // file - #define f_path_fll_headers "headers" // file - #define f_path_fll_libraries "libraries" // file - #define f_path_fll_programs "programs" // file - #define f_path_fll_scripts "scripts" // file - #define f_path_fll_fakefile "fakefile" // file + #define f_path_fll_base f_path_system_settings "/fll" // directory + #define f_path_fll_settings "settings" // directory + #define f_path_fll_packages "packages" // directory + #define f_path_fll_patches "patches" // directory + #define f_path_fll_archive "archive" // directory + #define f_path_fll_groups "groups" // directory + #define f_path_fll_licenses "licenses" // directory + #define f_path_fll_global "global" // file + #define f_path_fll_paths "paths" // file + #define f_path_fll_listing "listing" // file + #define f_path_fll_headers "headers" // file + #define f_path_fll_libraries "libraries" // file + #define f_path_fll_programs "programs" // file + #define f_path_fll_scripts "scripts" // file + #define f_path_fll_fakefile "fakefile" // file #endif // _di_fll_paths_ #ifndef _di_fll_file_endings_ diff --git a/level_0/f_pipe/c/pipe.h b/level_0/f_pipe/c/pipe.h index 7235102..ba658aa 100644 --- a/level_0/f_pipe/c/pipe.h +++ b/level_0/f_pipe/c/pipe.h @@ -15,8 +15,8 @@ #include // fll includes -#include #include +#include #ifdef __cplusplus extern "C" { @@ -27,7 +27,9 @@ extern "C" { #endif // _di_f_pipe_ #ifndef _di_f_pipe_exists_ - // returns f_true if the standard input contains piped data. + /** + * returns f_true if the standard input contains piped data. + */ extern f_return_status f_pipe_exists(); #endif // _di_f_pipe_exists_ diff --git a/level_0/f_print/c/print.c b/level_0/f_print/c/print.c index 60ab93a..77e3851 100644 --- a/level_0/f_print/c/print.c +++ b/level_0/f_print/c/print.c @@ -10,7 +10,9 @@ extern "C" { for (; i < length; i++) { if (string[i] != f_eos) { - if (fputc(string[i], output) == 0) return f_error_set_error(f_output_error); + if (fputc(string[i], output) == 0) { + return f_error_set_error(f_output_error); + } } } @@ -28,7 +30,9 @@ extern "C" { for (; i < buffer.used; i++) { if (buffer.string[i] != f_eos) { - if (fputc(buffer.string[i], output) == 0) return f_error_set_error(f_output_error); + if (fputc(buffer.string[i], output) == 0) { + return f_error_set_error(f_output_error); + } } } @@ -50,7 +54,9 @@ extern "C" { for (; i <= location.stop; i++) { if (buffer.string[i] != f_eos) { - if (fputc(buffer.string[i], output) == 0) return f_error_set_error(f_output_error); + if (fputc(buffer.string[i], output) == 0) { + return f_error_set_error(f_output_error); + } } } diff --git a/level_0/f_print/c/print.h b/level_0/f_print/c/print.h index 7bee5d9..f8cbf2f 100644 --- a/level_0/f_print/c/print.h +++ b/level_0/f_print/c/print.h @@ -11,44 +11,50 @@ #define _F_print_h // libc includes -#include -#include #include +#include +#include #include // fll-0 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_f_print_string_ - // Similar to a c-library printf, except that this will only print a specific range - // will not stop at \0 - // will not print \0 - // This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability + /** + * Similar to a c-library printf, except that this will only print a specific range. + * will not stop at \0. + * will not print \0. + * This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability. + */ extern f_return_status f_print_string(FILE *output, const f_string string, const f_string_length length); #endif // _di_f_print_string_ #ifndef _di_f_print_dynamic_string_ - // Similar to a c-library printf, except that this will only print a specific range - // will not stop at \0 - // will not print \0 - // will print the entire dynamic string - // This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability + /** + * Similar to a c-library printf, except that this will only print a specific range. + * will not stop at \0. + * will not print \0. + * will print the entire dynamic string. + * This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability. + */ extern f_return_status f_print_dynamic_string(FILE *output, const f_dynamic_string buffer); #endif // _di_f_print_dynamic_string_ #ifndef _di_f_print_partial_dynamic_string_ - // Similar to a c-library printf, except that this will only print a specific range ( - // will not stop at \0 - // will not print \0 - // will print the only the buffer range specified by location - // This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability + /** + * Similar to a c-library printf, except that this will only print a specific range. + * will not stop at \0. + * will not print \0. + * will print the only the buffer range specified by location. + * This implementation will not proces special characters, such as %s in the same way as printf functions, I am undecided whether or not to add this capability. + */ extern f_return_status f_print_partial_dynamic_string(FILE *output, const f_dynamic_string buffer, const f_string_location location); #endif // _di_f_print_partial_dynamic_string_ diff --git a/level_0/f_serialized/c/serialized.h b/level_0/f_serialized/c/serialized.h index 9e16c09..8872379 100644 --- a/level_0/f_serialized/c/serialized.h +++ b/level_0/f_serialized/c/serialized.h @@ -16,20 +16,20 @@ #include // fll-0 includes -#include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_f_serialized_splitters_ - #define f_serialized_simple_splitter ':' - #define f_serialized_delimited_splitter '\'' + #define f_serialized_simple_splitter ':' + #define f_serialized_delimited_splitter '\'' #define f_serialized_delimited_delimiter '\\' - #define f_serialized_simple_splitter_string ":" - #define f_serialized_delimited_splitter_string "'" + #define f_serialized_simple_splitter_string ":" + #define f_serialized_delimited_splitter_string "'" #define f_serialized_delimited_delimiter_string "\\" #endif // _di_f_serialized_splitters_ diff --git a/level_0/f_socket/c/socket.h b/level_0/f_socket/c/socket.h index 8709d78..0487417 100644 --- a/level_0/f_socket/c/socket.h +++ b/level_0/f_socket/c/socket.h @@ -11,30 +11,30 @@ #define _F_socket_h // libc includes +#include #include #include -#include #include // fll includes -#include #include #include +#include #ifdef __cplusplus extern "C"{ #endif #ifndef _di_f_socket_types_ - #define f_socket_address struct sockaddr_un - #define f_socket_id f_s_int - #define f_socket_close_id f_u_short + #define f_socket_address struct sockaddr_un + #define f_socket_id f_s_int + #define f_socket_close_id f_u_short enum { - f_socket_close_fast, // As in close(); - f_socket_close_read, // As in shutdown(, SHUT_RD); - f_socket_close_write, // As in shutdown(, SHUT_WR); - f_socket_close_read_write, // As in shutdown(, SHUT_RDWR); + f_socket_close_fast, // As in close(); + f_socket_close_read, // As in shutdown(, SHUT_RD); + f_socket_close_write, // As in shutdown(, SHUT_WR); + f_socket_close_read_write, // As in shutdown(, SHUT_RDWR); }; #endif // _di_f_socket_types_ diff --git a/level_0/f_strings/c/strings.h b/level_0/f_strings/c/strings.h index 06474c7..88793c3 100644 --- a/level_0/f_strings/c/strings.h +++ b/level_0/f_strings/c/strings.h @@ -14,27 +14,33 @@ #include // fll includes -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif -// BUG: for whatever reason strnlen is considered not included with -Wall, even with __USE_GNU defined -// therefore this gets defined here +/** + * BUG: for whatever reason strnlen is considered not included with -Wall, even with __USE_GNU defined. + * therefore this gets defined here. + */ #ifdef _en_BUG_strnlen_ extern size_t strnlen (const char *string, size_t max_length); #endif // _en_BUG_strnlen_ -// Define the end of string character +/** + * Define the end of string character. + */ #ifndef _di_f_have_eos_ #define f_eos '\0' #endif // _di_f_have_eos_ -// Define the end of line character -// FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored +/** + * Define the end of line character. + * FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored. + */ #ifndef _di_f_have_eol_ #define f_eol '\n' #endif // _di_f_have_eol_ @@ -67,7 +73,9 @@ extern "C" { #define f_array_length_long_printf string_format_long_integer #endif // _di_f_array_length_printf_ -// define the basic string type +/** + * define the basic string type. + */ #ifndef _di_f_have_string_ typedef char *f_string; @@ -101,11 +109,15 @@ extern "C" { status = f_adjust((void **) & length, sizeof(f_string_length), old_length, new_length) #endif // _di_f_string_length_ +/** + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_string_lengths_ typedef struct { f_string_length *array; - f_array_length size; // total amount of allocated space - f_array_length used; // total number of allocated spaces used + f_array_length size; + f_array_length used; } f_string_lengths; #define f_string_lengths_initialize { 0, 0, 0 } @@ -126,8 +138,10 @@ extern "C" { f_adjust_structure(status, lengths, f_string_length, new_length) #endif // _di_f_string_lengths_ -// designates a start and stop position that represents a sub-string inside of some parent string -// use this to avoid resizing, restructuring, and reallocating the parent string to separate the sub-string +/** + * designates a start and stop position that represents a sub-string inside of some parent string. + * use this to avoid resizing, restructuring, and reallocating the parent string to separate the sub-string. + */ #ifndef _di_f_string_location_ typedef struct { f_string_length start; @@ -147,12 +161,17 @@ extern "C" { status = f_adjust((void **) & string_location, sizeof(f_string_location), old_length, new_length) #endif // _di_f_string_location_ -// an array of string locations +/** + * an array of string locations. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_string_locations_ typedef struct { - f_string_location *array; // the array of string locations - f_array_length size; // total amount of allocated space - f_array_length used; // total number of allocated spaces used + f_string_location *array; + f_array_length size; + f_array_length used; } f_string_locations; #define f_string_locations_initialize {0, 0, 0} @@ -176,13 +195,18 @@ extern "C" { f_adjust_structure(status, locations, f_string_location, new_length) #endif // _di_f_string_locations_ -// a string that supports contains a size attribute to handle dynamic allocations and deallocations -// save the string size along with the string, so that strlen(..) commands can be avoided as much as possible +/** + * a string that supports contains a size attribute to handle dynamic allocations and deallocations. + * save the string size along with the string, so that strlen(..) commands can be avoided as much as possible. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_dynamic_string_ typedef struct { - f_string string; // the string itself - f_string_length size; // total amount of allocated space - f_string_length used; // total number of allocated spaces used + f_string string; + f_string_length size; + f_string_length used; } f_dynamic_string; #define f_dynamic_string_initialize { f_string_initialize, 0, 0 } @@ -229,12 +253,17 @@ extern "C" { } #endif // _di_f_dynamic_string_ -// an array of dynamic strings +/** + * an array of dynamic strings. + * + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_dynamic_strings_ typedef struct { - f_dynamic_string *array; // the array of dynamic strings - f_string_length size; // total amount of allocated space - f_string_length used; // total number of allocated spaces used + f_dynamic_string *array; + f_string_length size; + f_string_length used; } f_dynamic_strings; #define f_dynamic_strings_initialize { 0, 0, 0 } diff --git a/level_0/f_types/c/types.h b/level_0/f_types/c/types.h index 76d47c5..9cde8ac 100644 --- a/level_0/f_types/c/types.h +++ b/level_0/f_types/c/types.h @@ -8,20 +8,20 @@ * Provides datatype re-definitions * If your compiler lacks the ability to produce such, simply re-define them as needed * An "ideal" definition for a standard expected size would be (64-bit): - * char: 2^16 = 65536 + * char: 2^8 = 256 * short: 2^32 = 4294967296 * int: 2^64 = 1.84467e19 * long: 2^128 = 3.40282e38 * long long: 2^256 = 1.15792e77 * * If you need exact size, use one of the following: - * int8_t: 2^8 (signed) + * int8_t: 2^7 (signed) * uint8_t: 2^8 (unsigned) - * int16_t: 2^16 (signed) + * int16_t: 2^15 (signed) * uint16_t: 2^16 (unsigned) - * int32_t: 2^32 (signed) + * int32_t: 2^31 (signed) * uint32_t: 2^32 (unsigned) - * int64_t: 2^64 (signed) + * int64_t: 2^63 (signed) * uint64_t: 2^64 (unsigned) */ #ifndef _F_types_h @@ -35,24 +35,26 @@ extern "C" { #endif #ifndef _di_f_types_normal - #define f_s_int signed int - #define f_s_long signed long - #define f_s_short signed short - #define f_s_long_long signed long long - #define f_s_short_short signed short - #define f_s_double double - #define f_s_long_double long double - #define f_u_int unsigned int - #define f_u_short unsigned short - #define f_u_short_short unsigned short - #define f_u_long unsigned long - #define f_u_long_long unsigned long long - #define f_u_double double - #define f_u_long_double long double - #define f_bool unsigned short + #define f_s_int signed int + #define f_s_long signed long + #define f_s_short signed short + #define f_s_long_long signed long long + #define f_s_short_short signed short + #define f_s_double double + #define f_s_long_double long double + #define f_u_int unsigned int + #define f_u_short unsigned short + #define f_u_short_short unsigned short + #define f_u_long unsigned long + #define f_u_long_long unsigned long long + #define f_u_double double + #define f_u_long_double long double + #define f_bool unsigned short #endif // _di_f_types_normal -// The minimal types represent to the system admin or whomever else handles compilation that the data type should NOT be smaller than the specified size, but can be any size larger. +/** + * The minimal types represent to the system admin or whomever else handles compilation that the data type should NOT be smaller than the specified size, but can be any size larger. + */ #ifndef _di_f_types_min #define f_min_s_int f_s_int #define f_min_s_short f_s_short @@ -70,7 +72,9 @@ extern "C" { #define f_min_u_long_double f_u_long_double #endif // _di_f_types_min -// The maximum types represent to the system admin or whomever else handles compilation that the data type should NOT be larger than the specified size, but can be any size smaller. +/** + * The maximum types represent to the system admin or whomever else handles compilation that the data type should NOT be larger than the specified size, but can be any size smaller. + */ #ifndef _di_f_types_max #define f_max_s_int f_s_int #define f_max_s_short f_s_short @@ -91,9 +95,9 @@ extern "C" { #ifndef _di_f_status_ typedef uint16_t f_status; - // The c language gives warnings about return types of constants, I pretty much hate not being able to forcefully specify that these are not the be changed as that could be a security issue - // Therefore, I need to remove the const for c, but keep it for c++, thus I define the type f_return_status, which is only for function call declarations & prototypes - // DO NOT DECLARE THESE FOR THE RETURN DATA TYPES THEMSELVES, USE f_status. ONLY USE THESE FOR FUNCTION PROTOTYPES AND DECLARATIONS + // The c language gives warnings about return types of constants. + // Remove the const for c, but keep it for c++, which is only for function call declarations & prototypes. + // Do not declare these for the return data types themselves, instead use f_status; only use these for function prototypes and declarations. #ifdef __cplusplus #define f_return_status const f_status #else @@ -101,7 +105,10 @@ extern "C" { #endif // __cplusplus #endif // _di_f_status_ -// Defines the maximum size to be supported +/** + * Defines the maximum size to be supported. + * Ideally these don't get optimized away and are detected at runtime as a result of the bitwise operator. + */ #ifndef _di_f_types_sizes_ #define f_unsigned_char_size ((unsigned char) -1) #define f_unsigned_short_size ((unsigned short) -1) @@ -117,16 +124,17 @@ extern "C" { #define f_signed_long_long_size (((unsigned long long) -1) / 2) #endif // _di_f_types_sizes_ -// These should define some types use by stdio #ifndef _di_f_types_standard_output_ + #define f_standard_debug stdout + #define f_standard_error stderr #define f_standard_input stdin #define f_standard_output stdout - #define f_standard_error stderr - #define f_standard_warning stdout // I still hope for a separate pipe for warnings - #define f_standard_debug stdout // I still hope for a separate pipe for debug + #define f_standard_warning stdout #endif // _di_f_types_standard_output_ -// Defines a variable to be used by arrays. +/** + * Defines a variable to be used by arrays. + */ #ifndef _di_f_array_length_ typedef f_s_long f_array_length; typedef f_s_int f_array_length_short; diff --git a/level_0/f_types/c/types_array.h b/level_0/f_types/c/types_array.h index 9da8ca9..36c0e7c 100644 --- a/level_0/f_types/c/types_array.h +++ b/level_0/f_types/c/types_array.h @@ -10,23 +10,23 @@ #ifndef _F_types_array_h #define _F_types_array_h -// libc includes -#include // contains mode_t, dev_t, gid_t, uid_t, etc.. -#include - // fll includes -#include #include +#include #ifdef __cplusplus extern "C" { #endif +/** + * size: total amount of allocated space. + * used: total number of allocated spaces used. + */ #ifndef _di_f_array_lengths_ typedef struct { f_array_length *array; - f_array_length size; // total amount of allocated space - f_array_length used; // total number of allocated spaces used + f_array_length size; + f_array_length used; } f_array_lengths; #define f_array_lengths_initialize { 0, 0, 0 } diff --git a/level_1/fl_colors/c/colors.c b/level_1/fl_colors/c/colors.c index b617f05..736e7be 100644 --- a/level_1/fl_colors/c/colors.c +++ b/level_1/fl_colors/c/colors.c @@ -61,13 +61,15 @@ extern "C" { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color3 == 0) { + } + else if (color3 == 0) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); strncat(buffer->string, color2, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color4 == 0) { + } + else if (color4 == 0) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); @@ -75,7 +77,8 @@ extern "C" { strncat(buffer->string, format.medium, f_color_max_size); strncat(buffer->string, color3, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color5 == 0) { + } + else if (color5 == 0) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); @@ -85,7 +88,8 @@ extern "C" { strncat(buffer->string, format.medium, f_color_max_size); strncat(buffer->string, color4, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else { + } + else { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); diff --git a/level_1/fl_colors/c/colors.h b/level_1/fl_colors/c/colors.h index 8d4f538..549a59e 100644 --- a/level_1/fl_colors/c/colors.h +++ b/level_1/fl_colors/c/colors.h @@ -16,11 +16,11 @@ #include // fll-0 includes -#include +#include #include -#include #include -#include +#include +#include #ifdef __cplusplus extern "C" { @@ -28,7 +28,7 @@ extern "C" { #ifndef _di_fl_color_context_ typedef struct { - f_colors color_list; + f_colors color_list; f_colors_format color_format; f_dynamic_string reset; f_dynamic_string warning; @@ -78,7 +78,9 @@ extern "C" { #endif // _di_fl_color_context_ #ifndef _di_fl_set_color_ - // this will accept some file or standard io, and push color information to that file or standard io + /** + * this will accept some file or standard io, and push color information to that file or standard io. + */ extern f_return_status fl_set_color(FILE *file, const f_colors_format format, const char *color1, const char *color2, const char *color3, const char *color4, const char *color5); #define fl_set_color1(file, format, color1) fl_set_color(file, format, color1, 0, 0, 0, 0) @@ -90,7 +92,9 @@ extern "C" { #ifndef _di_fl_save_color_ - // this will place all appropriate color effects into a string, handling any necessary allocations + /** + * this will place all appropriate color effects into a string, handling any necessary allocations. + */ extern f_return_status fl_save_color(f_dynamic_string *buffer, const f_colors_format format, const char *color1, const char *color2, const char *color3, const char *color4, const char *color5); #define fl_save_color1(buffer, format, color1) fl_save_color(buffer, format, color1, 0, 0, 0, 0) @@ -101,20 +105,26 @@ extern "C" { #endif // _di_fl_save_color_ #ifndef _di_fl_print_color_ - // this will wrap the passed text in the passed start and end colors - // this will work like fprintf with the variable arguments - // if the colors strings have nothing used in them, then this will only print the string + /** + * this will wrap the passed text in the passed start and end colors. + * this will work like fprintf with the variable arguments. + * if the colors strings have nothing used in them, then this will only print the string. + */ extern f_return_status fl_print_color(FILE *file, const f_dynamic_string start_color, const f_dynamic_string end_color, const char *string, ...); #endif // _di_fl_print_color_ #ifndef _di_fl_print_color_line_ - // this is identical to fl_print_color, but also prints a trailing newline + /** + * this is identical to fl_print_color, but also prints a trailing newline. + */ extern f_return_status fl_print_color_line(FILE *file, const f_dynamic_string start_color, const f_dynamic_string end_color, const char *string, ...); #endif // _di_fl_print_color_line_ #ifndef _di_fl_print_color_code_ - // this will print a single color code so that all print commands following this command will print in color (or not..) - // do not forget to print the color reset when done + /** + * this will print a single color code so that all print commands following this command will print in color (or not..). + * do not forget to print the color reset when done. + */ extern f_return_status fl_print_color_code(FILE *file, const f_dynamic_string color); #endif // _di_fl_print_color_code_ diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index b187fc1..0936b93 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -12,7 +12,7 @@ extern "C" { f_status status = f_none; f_console_id result = 0; - f_bool found = f_false; + f_bool found = f_false; f_array_length location = 1; // parameter 0 represents the program name so skip it f_string_length sub_location = 0; @@ -31,16 +31,19 @@ extern "C" { // process the current parameter if (result == f_console_short_enable || result == f_console_short_disable) { - increments = 1; + increments = 1; sub_location = 1; - } else if (result == f_console_long_enable || result == f_console_long_disable) { - increments = string_length; + } + else if (result == f_console_long_enable || result == f_console_long_disable) { + increments = string_length; sub_location = 2; - } else if (result == f_console_extra_enable || result == f_console_extra_disable) { - increments = string_length; + } + else if (result == f_console_extra_enable || result == f_console_extra_disable) { + increments = string_length; sub_location = 3; - } else { - increments = 1; + } + else { + increments = 1; sub_location = 0; } @@ -92,13 +95,14 @@ extern "C" { } } } - } // for() + } // for sub_location += increments; } // while // now handle the inverse commands - } else if (argv[location][0] == f_console_symbol_disable) { + } + else if (argv[location][0] == f_console_symbol_disable) { while (sub_location < string_length) { for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) { if (parameters[parameter_counter].type == f_console_type_inverse) { @@ -146,11 +150,12 @@ extern "C" { } } } - } // for() + } // for sub_location += increments; } // while - } else { + } + else { // use found to determine if the remaining parameter should be populated found = f_false; @@ -180,20 +185,20 @@ extern "C" { } } } - } // for() + } // for if (!found) { if (extra_initiator.used > 0) { f_status allocation_status = f_none; if (parameters[extra_initiator.array[0]].additional.used >= parameters[extra_initiator.array[0]].additional.size) { - f_resize_string_lengths(allocation_status, parameters[extra_initiator.array[0]].additional, parameters[extra_initiator.array[0]].additional.size + f_console_default_allocation_step); - } + f_resize_string_lengths(allocation_status, parameters[extra_initiator.array[0]].additional, parameters[extra_initiator.array[0]].additional.size + f_console_default_allocation_step); + } - if (f_error_is_error(allocation_status)) { - f_delete_string_lengths(status, extra_initiator); - return f_error_set_error(allocation_status); - } + if (f_error_is_error(allocation_status)) { + f_delete_string_lengths(status, extra_initiator); + return f_error_set_error(allocation_status); + } parameters[extra_initiator.array[0]].result = f_console_result_additional; parameters[extra_initiator.array[0]].additional.array[parameters[extra_initiator.array[0]].additional.used] = location; @@ -205,8 +210,9 @@ extern "C" { for (; i < extra_initiator.used; i++) { extra_initiator.array[i] = extra_initiator.array[i + 1]; - } - } else { + } // for + } + else { if (remaining->used >= remaining->size) { f_status allocation_status = f_none; @@ -229,7 +235,8 @@ extern "C" { if (extra_initiator.used > 0) { status = f_no_data; - } else { + } + else { status = f_none; } diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index 273185a..31a5d4d 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -14,16 +14,19 @@ #include // fll-0 includes -#include +#include #include #include -#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_process_parameters_ + /** + * Process console parameters. + */ extern f_return_status fl_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length total_parameters, f_string_lengths *remaining); #endif // _di_fl_process_parameters_ diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 83df1c9..06956d7 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -52,7 +52,8 @@ extern "C" { if (length == 0) { // an empty directory return f_no_data; - } else if (length == -1) { + } + else if (length == -1) { if (errno == ENOMEM) return f_error_set_error(f_allocation_error); else return f_error_set_error(f_failure); } diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index 5291199..ba275cb 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -11,18 +11,18 @@ #define _FL_directory_h // libc includes -#include -#include #include +#include +#include +#include #include #include -#include // fll-0 includes -#include #include -#include #include +#include +#include #ifdef __cplusplus extern "C" { @@ -33,7 +33,9 @@ extern "C" { #endif // _di_fl_directory_limitations_ #ifndef _di_fl_directory_list_ - // put the names of each file and/or directory inside the names parameter + /** + * put the names of each file and/or directory inside the names parameter. + */ extern f_return_status fl_directory_list(const f_string directory_path, f_dynamic_strings *names); #endif // _di_fl_directory_list_ diff --git a/level_1/fl_errors/c/errors.c b/level_1/fl_errors/c/errors.c index 58adcf7..9d4ac37 100644 --- a/level_1/fl_errors/c/errors.c +++ b/level_1/fl_errors/c/errors.c @@ -306,7 +306,8 @@ extern "C" { f_return_status fl_errors_is_error(const f_status error) { if (fl_errors_is_fine(error) == f_true) { return f_false; - } else if (fl_errors_is_warning(error) == f_true) { + } + else if (fl_errors_is_warning(error) == f_true) { return f_false; } diff --git a/level_1/fl_errors/c/errors.h b/level_1/fl_errors/c/errors.h index 52e9544..b7597f7 100644 --- a/level_1/fl_errors/c/errors.h +++ b/level_1/fl_errors/c/errors.h @@ -11,34 +11,42 @@ #define _FL_errors_h // fll-0 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_errors_to_string_ - // Convert error codes to their string equivalents. + /** + * Convert error codes to their string equivalents. + */ extern f_return_status fl_errors_to_string(const f_status error, f_string *string); #endif // _di_fl_errors_to_string_ #ifndef _di_fl_errors_is_error_ - // Returns true or false depending on whether the standard context of the error code represents an error. - // Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + /** + * Returns true or false depending on whether the standard context of the error code represents an error. + * Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + */ extern f_return_status fl_errors_is_error(const f_status error); #endif // _di_fl_errors_is_error_ #ifndef _di_fl_errors_is_warning_ - // Returns true or false depending on whether the standard context of the error code represents a warning. - // Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + /** + * Returns true or false depending on whether the standard context of the error code represents a warning. + * Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + */ extern f_return_status fl_errors_is_warning(const f_status error); #endif // _di_fl_errors_is_warning_ #ifndef _di_fl_errors_is_fine_ - // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. - // Keep in mind that many of the error codes are context-specific and may be reported as an "fine" here when it is in fact not fine. + /** + * Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. + * Keep in mind that many of the error codes are context-specific and may be reported as an "fine" here when it is in fact not fine. + */ extern f_return_status fl_errors_is_fine(const f_status error); #endif // _di_fl_errors_is_fine_ diff --git a/level_1/fl_file/c/file.c b/level_1/fl_file/c/file.c index f8bcf80..180c2c7 100644 --- a/level_1/fl_file/c/file.c +++ b/level_1/fl_file/c/file.c @@ -24,7 +24,8 @@ extern "C" { if (position.total_elements == 0) { infinite = f_true; size = f_file_default_read_size; - } else { + } + else { size = position.total_elements; } @@ -42,7 +43,8 @@ extern "C" { if (status == f_none_on_eof) { break; - } else if (f_error_is_error(status)) { + } + else if (f_error_is_error(status)) { return status; } @@ -86,7 +88,8 @@ extern "C" { if (status == f_none_on_eof) { break; - } else if (f_error_is_error(status)) { + } + else if (f_error_is_error(status)) { return status; } diff --git a/level_1/fl_file/c/file.h b/level_1/fl_file/c/file.h index 7b85183..d5b3996 100644 --- a/level_1/fl_file/c/file.h +++ b/level_1/fl_file/c/file.h @@ -11,27 +11,39 @@ #define _FL_file_h // fll-0 includes -#include -#include #include +#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_file_read_ + /** + * read file, specific positions. + */ extern f_return_status fl_file_read(f_file file, const f_file_position position, f_dynamic_string *buffer); #endif // _di_fl_file_read_ #ifndef _di_fl_file_read_fifo_ + /** + * read file, entire file. + */ extern f_return_status fl_file_read_fifo(f_file file, f_dynamic_string *buffer); #endif // _di_fl_file_read_fifo_ #ifndef _di_fl_file_write_ + /** + * write file, entire file. + */ extern f_return_status fl_file_write(f_file file, const f_dynamic_string buffer); #endif // _di_fl_file_write_ #ifndef _di_fl_file_write_partial_ + /** + * write file, specific positions. + */ extern f_return_status fl_file_write_partial(f_file file, const f_dynamic_string buffer, const f_string_location position); #endif // _di_fl_file_write_partial_ diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index e97f1cc..1d8e525 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -28,7 +28,7 @@ extern "C" { f_string_location location = f_string_location_initialize; location.start = i - 4; - location.stop = i; + location.stop = i; // 1: A possibly valid header type was found, now convert it into its proper format and save the header type f_string_to_hexdigit(buffer.string, &header->type, location); @@ -39,7 +39,8 @@ extern "C" { header->length = i; return f_none; - } else { + } + else { // if "# fss-0000" is there, regardless of whats next, we can guess this to be of fss-0000, even if its fss-00001 (this is a guess afterall) i++; header->length = i; @@ -55,7 +56,8 @@ extern "C" { } } // people can miss spaces, so lets accept in an attempt to interpret the file anyway, but return values at this point are to be flagged as invalid - } else if (buffer.string[i] == f_fss_type_header_part2) { i++; + } + else if (buffer.string[i] == f_fss_type_header_part2) { i++; if (buffer.string[i] == f_fss_type_header_part3) { i++; if (buffer.string[i] == f_fss_type_header_part4) { i++; if (buffer.string[i] == f_fss_type_header_part5) { i++; @@ -67,7 +69,7 @@ extern "C" { f_string_location location = f_string_location_initialize; location.start = i - 4; - location.stop = i; + location.stop = i; f_string_to_hexdigit(buffer.string, &header->type, location); @@ -102,9 +104,9 @@ extern "C" { clearerr(file_information->file); - f_status status = f_none; - f_dynamic_string buffer = f_dynamic_string_initialize; - f_file_position location = f_file_position_initialize; + f_status status = f_none; + f_dynamic_string buffer = f_dynamic_string_initialize; + f_file_position location = f_file_position_initialize; // make sure we are in the proper location in the file { diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index 960553d..a0c26b3 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -9,16 +9,16 @@ #define _FL_fss_h // libc includes -#include #include +#include // fll-0 includes -#include +#include #include -#include -#include #include -#include +#include +#include +#include // fll-1 includes #include @@ -28,17 +28,25 @@ extern "C" { #endif #ifndef _di_fl_fss_identify_ + /** + * Identify FSS type from a buffered string. + */ extern f_return_status fl_fss_identify(const f_dynamic_string buffer, f_fss_header *header); #endif // _di_fl_fss_identify_ #ifndef _di_fl_fss_identify_file_ + /** + * Ideentify FSS type from a file. + */ extern f_return_status fl_fss_identify_file(f_file *file_information, f_fss_header *header); #endif // _di_fl_fss_identify_file_ #ifndef _di_fl_fss_shift_delimiters_ - // This provides a means to shift all of the delimiters to the end of the used buffer - // This allows one to do a printf on the dynamic string without the delimiters arbitrarily stopping the output - // No reallocations are performed, this will only shift characters + /** + * This provides a means to shift all of the delimiters to the end of the used buffer. + * This allows one to do a printf on the dynamic string without the delimiters arbitrarily stopping the output. + * No reallocations are performed, this will only shift characters. + */ extern f_return_status fl_fss_shift_delimiters(f_dynamic_string *buffer, const f_string_location location); #endif // _di_fl_fss_shift_delimiters_ diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index b03c977..20d67d4 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -55,11 +55,13 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (!isgraph(buffer->string[input->start])) { + } + else if (!isgraph(buffer->string[input->start])) { found->stop = input->start - 1; input->start++; return fl_fss_found_object; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -85,7 +87,8 @@ extern "C" { delimits.used++; input->start++; } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + } + else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; found->start = input->start; @@ -111,7 +114,8 @@ extern "C" { input->start++; return fl_fss_found_object; } - } else { + } + else { while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; @@ -122,7 +126,8 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -182,7 +187,8 @@ extern "C" { input->start++; return fl_fss_found_no_object; - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = location - 1; @@ -196,7 +202,8 @@ extern "C" { found->stop = location - 1; input->start++; return fl_fss_found_object; - } else { + } + else { if (delimits.used + (slash_count / 2) >= delimits.size) { f_status allocation_status = f_none; @@ -224,7 +231,8 @@ extern "C" { input->start = location; } } - } else if (buffer->string[input->start] == quoted) { + } + else if (buffer->string[input->start] == quoted) { found->stop = input->start - 1; input->start++; @@ -233,11 +241,13 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); input->start++; return fl_fss_found_object_no_content; - } else if (isspace(buffer->string[input->start])) { + } + else if (isspace(buffer->string[input->start])) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); input->start++; return fl_fss_found_object; - } else if (buffer->string[input->start] != f_fss_delimit_placeholder) { + } + else if (buffer->string[input->start] != f_fss_delimit_placeholder) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while @@ -258,7 +268,8 @@ extern "C" { } // while fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { { f_status allocation_status = f_none; @@ -345,17 +356,18 @@ extern "C" { #endif // _di_level_1_parameter_checking_ f_status status = f_none; - f_bool quoted = f_false; + f_bool quoted = f_false; - f_string_location buffer_position = f_string_location_initialize; - f_string_length start_position = f_string_initialize; - f_string_length pre_allocate_size = 0; + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) if (input->start > input->stop) { return f_no_data_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_no_data_on_eos; } @@ -378,7 +390,8 @@ extern "C" { if (object.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (object.string[input->start] != f_fss_delimit_slash) { + } + else if (object.string[input->start] != f_fss_delimit_slash) { break; } @@ -401,7 +414,8 @@ extern "C" { buffer_position.stop += 2; input->start++; } - } else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + } + else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -414,7 +428,8 @@ extern "C" { buffer->string[buffer_position.stop + 1] = object.string[input->start]; buffer_position.stop += 2; input->start++; - } else if (object.string[input->start] == f_fss_comment) { + } + else if (object.string[input->start] == f_fss_comment) { quoted = f_true; } @@ -422,7 +437,8 @@ extern "C" { if (object.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (object.string[input->start] == f_eol) { + } + else if (object.string[input->start] == f_eol) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -432,7 +448,8 @@ extern "C" { buffer->used = buffer_position.stop + 1; return f_none_on_eol; - } else if (isspace(object.string[input->start]) || quoted) { + } + else if (isspace(object.string[input->start]) || quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -452,7 +469,8 @@ extern "C" { if (object.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (object.string[input->start] == f_fss_delimit_double_quote) { + } + else if (object.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -463,7 +481,8 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - } else if (object.string[input->start] == f_fss_delimit_slash) { + } + else if (object.string[input->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; do { @@ -488,7 +507,8 @@ extern "C" { } break; - } else if (object.string[input->start] != f_fss_delimit_slash) { + } + else if (object.string[input->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -501,7 +521,8 @@ extern "C" { } // while continue; - } else if (object.string[input->start] == f_eol) { + } + else if (object.string[input->start] == f_eol) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -534,7 +555,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_none_on_eos; } @@ -550,15 +572,15 @@ extern "C" { f_status status = f_none; - f_string_location input_position = f_string_location_initialize; - f_string_location buffer_position = f_string_location_initialize; - f_string_length pre_allocate_size = 0; + f_string_location input_position = f_string_location_initialize; + f_string_location buffer_position = f_string_location_initialize; + f_string_length pre_allocate_size = 0; // add an additional 1 to ensure that there is room for the terminating newline. pre_allocate_size = buffer->used + (content.used) + 1 + f_fss_default_allocation_step; buffer_position.start = buffer->used; - buffer_position.stop = buffer->used; + buffer_position.stop = buffer->used; if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); @@ -586,7 +608,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index b76e7af..eaf227f 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -11,42 +11,50 @@ #define _FL_fss_basic_h // libc includes -#include #include +#include // fll-0 includes -#include #include +#include #include +#include #include -#include // fll-1 includes #include -#include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_object_read_ - // read an fss-0000 object + /** + * read an fss-0000 object. + */ extern f_return_status fl_fss_basic_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found); #endif // _di_fl_fss_basic_object_read_ #ifndef _di_fl_fss_basic_content_read_ - // read an fss-0000 content + /** + * read an fss-0000 content. + */ extern f_return_status fl_fss_basic_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found); #endif // _di_fl_fss_basic_content_read_ #ifndef _di_fl_fss_basic_object_write_ - // write an fss-0000 object + /** + * write an fss-0000 object. + */ extern f_return_status fl_fss_basic_object_write(f_dynamic_string *buffer, const f_dynamic_string object, f_string_location *input); #endif // _di_fl_fss_basic_object_write_ #ifndef _di_fl_fss_basic_content_write_ - // write an fss-0000 content + /** + * write an fss-0000 content. + */ extern f_return_status fl_fss_basic_content_write(f_dynamic_string *buffer, const f_dynamic_string content, f_string_location *input); #endif // _di_fl_fss_basic_content_write_ diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index c926f79..a3d090a 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -116,7 +116,8 @@ extern "C" { } continue; - } else if (buffer->string[input->start] == f_fss_basic_list_open) { + } + else if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length stop_point = input->start - 1; input->start++; @@ -179,8 +180,8 @@ extern "C" { fl_macro_fss_allocate_content_if_necessary((*found), delimits); found->array[found->used].start = input->start; - f_string_length last_newline = input->start; - f_bool found_newline = f_false; + f_string_length last_newline = input->start; + f_bool found_newline = f_false; // identify where the content ends while (input->start < buffer->used && input->start <= input->stop) { @@ -207,7 +208,8 @@ extern "C" { if (found_newline) { fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else { + } + else { fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } @@ -226,7 +228,8 @@ extern "C" { if (found_newline) { fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else { + } + else { fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } @@ -280,7 +283,8 @@ extern "C" { } continue; - } else if (buffer->string[input->start] == f_fss_basic_list_open) { + } + else if (buffer->string[input->start] == f_fss_basic_list_open) { input->start++; while (input->start < buffer->used && input->start <= input->stop) { @@ -293,7 +297,8 @@ extern "C" { if (found_newline) { fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else { + } + else { fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } @@ -347,16 +352,17 @@ extern "C" { f_status status = f_none; - f_string_location buffer_position = f_string_location_initialize; - f_string_length start_position = f_string_initialize; - f_string_length pre_allocate_size = 0; - f_string_length start_buffer = 0; + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; + f_string_length start_buffer = 0; fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) if (input->start > input->stop) { return f_no_data_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_no_data_on_eos; } @@ -378,7 +384,8 @@ extern "C" { if (object.string[input->start] == f_fss_comment) { // comments are not allowed and this format has no way of "wrapping" a comment. return f_invalid_data; - } else if (isgraph(object.string[input->start])) { + } + else if (isgraph(object.string[input->start])) { break; } @@ -453,7 +460,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_none_on_eos; } @@ -467,19 +475,20 @@ extern "C" { if (buffer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_status status = f_none; - f_bool is_comment = f_false; - f_bool has_graph = f_false; + f_status status = f_none; + f_bool is_comment = f_false; + f_bool has_graph = f_false; - f_string_location buffer_position = f_string_location_initialize; - f_string_length start_position = f_string_initialize; - f_string_length pre_allocate_size = 0; + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; fl_macro_fss_skip_past_delimit_placeholders(content, (*input)) if (input->start > input->stop) { return f_no_data_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { return f_no_data_on_eos; } @@ -511,7 +520,8 @@ extern "C" { if (content.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (content.string[input->start] != f_fss_delimit_slash) { + } + else if (content.string[input->start] != f_fss_delimit_slash) { break; } @@ -560,7 +570,8 @@ extern "C" { input->start = location + 1; continue; } - } else if (content.string[input->start] == f_fss_basic_list_open && !is_comment) { + } + else if (content.string[input->start] == f_fss_basic_list_open && !is_comment) { f_string_length location = input->start; has_graph = f_true; @@ -593,12 +604,15 @@ extern "C" { buffer_position.stop++; input->start = location + 1; continue; - } else if (content.string[input->start] == f_fss_comment && !has_graph) { + } + else if (content.string[input->start] == f_fss_comment && !has_graph) { is_comment = f_true; - } else if (content.string[input->start] == f_eol) { + } + else if (content.string[input->start] == f_eol) { has_graph = f_false; is_comment = f_false; - } else if (isgraph(content.string[input->start])) { + } + else if (isgraph(content.string[input->start])) { has_graph = f_true; } @@ -615,7 +629,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_basic_list.h b/level_1/fl_fss/c/fss_basic_list.h index f490cb0..a1d5f5f 100644 --- a/level_1/fl_fss/c/fss_basic_list.h +++ b/level_1/fl_fss/c/fss_basic_list.h @@ -11,43 +11,51 @@ #define _FL_fss_basic_list_h // libc includes -#include #include +#include // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_list_object_read_ - // read an fss-0002 object + /** + * read an fss-0002 object. + */ extern f_return_status fl_fss_basic_list_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found); #endif // _di_fl_fss_basic_list_object_read_ #ifndef _di_fl_fss_basic_list_content_read_ - // read an fss-0002 content + /** + * read an fss-0002 content. + */ extern f_return_status fl_fss_basic_list_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found); #endif // _di_fl_fss_basic_list_content_read_ #ifndef _di_fl_fss_basic_list_object_write_ - // write an fss-0002 object + /** + * write an fss-0002 object. + */ extern f_return_status fl_fss_basic_list_object_write(const f_dynamic_string object, f_string_location *input, f_dynamic_string *buffer); #endif // _di_fl_fss_basic_list_object_write_ #ifndef _di_fl_fss_basic_list_content_write_ - // write an fss-0002 content + /** + * write an fss-0002 content. + */ extern f_return_status fl_fss_basic_list_content_write(const f_dynamic_string content, f_string_location *input, f_dynamic_string *buffer); #endif // _di_fl_fss_basic_list_content_write_ diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 9ddb638..da86914 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -55,11 +55,13 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (!isgraph(buffer->string[input->start])) { + } + else if (!isgraph(buffer->string[input->start])) { found->stop = input->start - 1; input->start++; return fl_fss_found_object; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -85,7 +87,8 @@ extern "C" { delimits.used++; input->start++; } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + } + else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; found->start = input->start; @@ -111,7 +114,8 @@ extern "C" { input->start++; return fl_fss_found_object; } - } else { + } + else { while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; @@ -122,7 +126,8 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -176,7 +181,8 @@ extern "C" { input->start++; return fl_fss_found_no_object; - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = location - 1; @@ -190,7 +196,8 @@ extern "C" { found->stop = location - 1; input->start++; return fl_fss_found_object; - } else { + } + else { if (delimits.used + (slash_count / 2) >= delimits.size) { f_status allocation_status = f_none; @@ -218,7 +225,8 @@ extern "C" { input->start = location; } } - } else if (buffer->string[input->start] == quoted) { + } + else if (buffer->string[input->start] == quoted) { found->stop = input->start - 1; input->start++; @@ -228,12 +236,14 @@ extern "C" { input->start++; return fl_fss_found_object_no_content; - } else if (isspace(buffer->string[input->start])) { + } + else if (isspace(buffer->string[input->start])) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); input->start++; return fl_fss_found_object; - } else if (buffer->string[input->start] != f_fss_delimit_placeholder) { + } + else if (buffer->string[input->start] != f_fss_delimit_placeholder) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while @@ -248,7 +258,8 @@ extern "C" { } // while fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_no_object; } @@ -295,14 +306,14 @@ extern "C" { return fl_fss_found_no_content; } - f_status status = f_none; - f_bool has_delimit = f_false; - char quoted = f_eos; + f_status status = f_none; + f_bool has_delimit = f_false; + char quoted = f_eos; f_bool continue_main_loop = f_false; - f_string_length location = 0; - f_array_length already_used = found->used; + f_string_length location = 0; + f_array_length already_used = found->used; while (input->start <= input->stop && input->start < buffer->used) { quoted = f_eos; @@ -332,7 +343,8 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (!isgraph(buffer->string[input->start])) { + } + else if (!isgraph(buffer->string[input->start])) { found->array[found->used].stop = input->start - 1; input->start++; found->used++; @@ -345,7 +357,8 @@ extern "C" { continue_main_loop = f_true; break; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -376,7 +389,8 @@ extern "C" { delimits.used++; input->start++; } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { + } + else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; found->array[found->used].start = input->start; @@ -403,7 +417,8 @@ extern "C" { input->start++; continue; } - } else { + } + else { while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; @@ -414,7 +429,8 @@ extern "C" { if (buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (buffer->string[input->start] != f_fss_delimit_slash) { + } + else if (buffer->string[input->start] != f_fss_delimit_slash) { break; } @@ -467,7 +483,8 @@ extern "C" { input->start++; return f_error_is_warning(f_unterminated_group); - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = location - 1; @@ -481,7 +498,8 @@ extern "C" { input->start++; found->used++; continue; - } else { + } + else { if (delimits.used + (slash_count / 2) >= delimits.size) { f_status allocation_status = f_none; @@ -509,7 +527,8 @@ extern "C" { input->start = location; } } - } else if (buffer->string[input->start] == quoted) { + } + else if (buffer->string[input->start] == quoted) { found->array[found->used].stop = input->start - 1; input->start++; @@ -521,12 +540,14 @@ extern "C" { found->used++; return fl_fss_found_content; - } else if (isspace(buffer->string[input->start])) { + } + else if (isspace(buffer->string[input->start])) { input->start++; found->used++; continue_main_loop = f_true; break; - } else if (buffer->string[input->start] != f_fss_delimit_placeholder) { + } + else if (buffer->string[input->start] != f_fss_delimit_placeholder) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while @@ -545,12 +566,14 @@ extern "C" { } fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - } else if (buffer->string[input->start] == f_eol) { + } + else if (buffer->string[input->start] == f_eol) { if (found->used == already_used) { input->start++; return fl_fss_found_no_content; - } else { + } + else { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = input->start - 1; @@ -603,17 +626,18 @@ extern "C" { #endif // _di_level_1_parameter_checking_ f_status status = f_none; - f_bool quoted = f_false; + f_bool quoted = f_false; - f_string_location buffer_position = f_string_location_initialize; - f_string_length start_position = f_string_initialize; - f_string_length pre_allocate_size = 0; + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = f_string_initialize; + f_string_length pre_allocate_size = 0; fl_macro_fss_skip_past_delimit_placeholders(object, (*input)) if (input->start > input->stop) { return f_no_data_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_no_data_on_eos; } @@ -659,7 +683,8 @@ extern "C" { buffer_position.stop += 2; input->start++; } - } else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { + } + else if (object.string[input->start] == f_fss_delimit_single_quote || object.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -672,7 +697,8 @@ extern "C" { buffer->string[buffer_position.stop + 1] = object.string[input->start]; buffer_position.stop += 2; input->start++; - } else if (object.string[input->start] == f_fss_comment) { + } + else if (object.string[input->start] == f_fss_comment) { quoted = f_true; } @@ -680,7 +706,8 @@ extern "C" { if (object.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (object.string[input->start] == f_eol) { + } + else if (object.string[input->start] == f_eol) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -690,7 +717,8 @@ extern "C" { buffer->used = buffer_position.stop + 1; return f_none_on_eol; - } else if (isspace(object.string[input->start]) || quoted) { + } + else if (isspace(object.string[input->start]) || quoted) { f_string_length first_space = input->start; if (!quoted) { @@ -726,7 +754,8 @@ extern "C" { if (object.string[input->start] == f_fss_delimit_placeholder) { input->start++; continue; - } else if (object.string[input->start] == f_fss_delimit_double_quote) { + } + else if (object.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -737,7 +766,8 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - } else if (object.string[input->start] == f_fss_delimit_slash) { + } + else if (object.string[input->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; do { @@ -762,7 +792,8 @@ extern "C" { } break; - } else if (object.string[input->start] != f_fss_delimit_slash) { + } + else if (object.string[input->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -775,7 +806,8 @@ extern "C" { } // while continue; - } else if (object.string[input->start] == f_eol) { + } + else if (object.string[input->start] == f_eol) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -808,7 +840,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= object.used) { + } + else if (input->start >= object.used) { return f_none_on_eos; } @@ -822,18 +855,18 @@ extern "C" { if (buffer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_status status = f_none; + f_status status = f_none; char quoted = f_eos; - f_string_location buffer_position = f_string_location_initialize; - f_string_length start_position = 0; - f_string_length pre_allocate_size = 0; + f_string_location buffer_position = f_string_location_initialize; + f_string_length start_position = 0; + f_string_length pre_allocate_size = 0; // add an additional 1 to ensure that there is room for the terminating newline. pre_allocate_size = buffer->used + (content.used) + 1 + f_fss_default_allocation_step; buffer_position.start = buffer->used; - buffer_position.stop = buffer->used; + buffer_position.stop = buffer->used; if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); @@ -845,7 +878,8 @@ extern "C" { if (input->start > input->stop) { return f_no_data_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { return f_no_data_on_eos; } @@ -876,7 +910,8 @@ extern "C" { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return f_none_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return f_none_on_eos; @@ -896,7 +931,8 @@ extern "C" { buffer_position.stop += 2; input->start++; } - } else if (content.string[input->start] == f_fss_delimit_single_quote || content.string[input->start] == f_fss_delimit_double_quote) { + } + else if (content.string[input->start] == f_fss_delimit_single_quote || content.string[input->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -988,11 +1024,13 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer->string[buffer_position.stop + 1] = quoted; buffer_position.stop += 2; - } else { + } + else { buffer->string[buffer_position.stop] = content.string[input->start]; buffer_position.stop++; } - } else if (content.string[input->start] == quoted) { + } + else if (content.string[input->start] == quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1004,12 +1042,14 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer->string[buffer_position.stop + 1] = quoted; buffer_position.stop += 2; - } else if (content.string[input->start] == f_eol) { + } + else if (content.string[input->start] == f_eol) { buffer->string[buffer_position.stop] = quoted; buffer->string[buffer_position.stop + 1] = ' '; buffer->used = buffer_position.stop + 2; return f_none_on_eol; - } else if (content.string[input->start] != f_fss_delimit_placeholder) { + } + else if (content.string[input->start] != f_fss_delimit_placeholder) { buffer->string[buffer_position.stop] = content.string[input->start]; buffer_position.stop++; } @@ -1026,7 +1066,8 @@ extern "C" { if (input->start > input->stop) { return f_none_on_stop; - } else if (input->start >= content.used) { + } + else if (input->start >= content.used) { return f_none_on_eos; } diff --git a/level_1/fl_fss/c/fss_extended.h b/level_1/fl_fss/c/fss_extended.h index 3b5c237..5216d60 100644 --- a/level_1/fl_fss/c/fss_extended.h +++ b/level_1/fl_fss/c/fss_extended.h @@ -11,42 +11,50 @@ #define _FL_fss_extended_h // libc includes -#include #include +#include // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include -#include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_extended_object_read_ - // read an fss-0001 object + /** + * read an fss-0001 object. + */ extern f_return_status fl_fss_extended_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found); #endif // _di_fl_fss_extended_object_read_ #ifndef _di_fl_fss_extended_content_read_ - // read an fss-0001 content + /** + * read an fss-0001 content. + */ extern f_return_status fl_fss_extended_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found); #endif // _di_fl_fss_extended_content_read_ #ifndef _di_fl_fss_extended_object_write_ - // write an fss-0001 object + /** + * write an fss-0001 object. + */ extern f_return_status fl_fss_extended_object_write(const f_dynamic_string object, f_string_location *input, f_dynamic_string *buffer); #endif // _di_fl_fss_extended_object_write_ #ifndef _di_fl_fss_extended_content_write_ - // write an fss-0001 content + /** + * write an fss-0001 content. + */ extern f_return_status fl_fss_extended_content_write(const f_dynamic_string content, f_string_location *input, f_dynamic_string *buffer); #endif // _di_fl_fss_extended_content_write_ diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index d76abb0..29a1790 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -70,7 +70,8 @@ extern "C" { \ found.stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_delete_string_lengths(allocation_status, delimits); \ \ @@ -93,7 +94,8 @@ extern "C" { \ found.stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -116,7 +118,8 @@ extern "C" { \ found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_delete_string_lengths(allocation_status, delimits); \ \ @@ -139,7 +142,8 @@ extern "C" { \ found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ @@ -163,7 +167,8 @@ extern "C" { input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_delete_string_lengths(allocation_status, delimits); \ \ @@ -188,7 +193,8 @@ extern "C" { input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ - } else if (input.start > input.stop) { \ + } \ + else if (input.start > input.stop) { \ f_status allocation_status = f_none; \ f_string_length i = 0; \ \ diff --git a/level_1/fl_serialized/c/serialized.c b/level_1/fl_serialized/c/serialized.c index 65bb528..b81da09 100644 --- a/level_1/fl_serialized/c/serialized.c +++ b/level_1/fl_serialized/c/serialized.c @@ -22,7 +22,8 @@ extern "C" { if (serialized->used == 0) { memcpy(serialized->string + serialized->used, value.string, sizeof(char) * value.used); serialized->used += value.used; - } else { + } + else { memcpy(serialized->string + serialized->used, f_serialized_simple_splitter_string, sizeof(char)); memcpy(serialized->string + serialized->used + 1, value.string, sizeof(char) * value.used); serialized->used += value.used + 1; @@ -53,11 +54,12 @@ extern "C" { if (start == i) { locations->array[locations->used].start = 1; - locations->array[locations->used].stop = 0; + locations->array[locations->used].stop = 0; locations->used++; - } else { + } + else { locations->array[locations->used].start = start; - locations->array[locations->used].stop = i - 1; + locations->array[locations->used].stop = i - 1; locations->used++; } @@ -83,13 +85,13 @@ extern "C" { f_array_length current = 0; location->start = 1; - location->stop = 0; + location->stop = 0; while (i < serialized.used) { if (current == index) { if (location->start > location->stop) { location->start = i; - location->stop = i; + location->stop = i; } if (serialized.string[i] == f_serialized_simple_splitter) { diff --git a/level_1/fl_serialized/c/serialized.h b/level_1/fl_serialized/c/serialized.h index 3e54aea..db4882d 100644 --- a/level_1/fl_serialized/c/serialized.h +++ b/level_1/fl_serialized/c/serialized.h @@ -16,27 +16,33 @@ #include // fll-0 includes -#include #include -#include #include +#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_serialize_simple_ - // this function will append a string to the serialize. + /** + * this function will append a string to the serialize. + */ extern f_return_status fl_serialize_simple(const f_dynamic_string value, f_dynamic_string *serialized); #endif // _di_fl_serialize_simple_ #ifndef _di_fl_unserialize_simple_ - // this function will unserialize a serialized string and store the results in an array of strings. + /** + * this function will unserialize a serialized string and store the results in an array of strings. + */ extern f_return_status fl_unserialize_simple(const f_dynamic_string serialized, f_string_locations *locations); #endif // _di_fl_unserialize_ #ifndef _di_fl_unserialize_simple_get_ - // this function will pull a single serialized value from the serialized string at the given index. + /** + * this function will pull a single serialized value from the serialized string at the given index. + */ extern f_return_status fl_unserialize_simple_get(const f_dynamic_string serialized, const f_array_length index, f_string_location *location); #endif // _di_fl_unserialize_simple_get_ diff --git a/level_1/fl_socket/c/socket.h b/level_1/fl_socket/c/socket.h index f312af1..d625dc4 100644 --- a/level_1/fl_socket/c/socket.h +++ b/level_1/fl_socket/c/socket.h @@ -11,34 +11,40 @@ #define _F_socket_h // libc includes +#include #include #include -#include #include // fll includes -#include #include #include +#include #ifdef __cplusplus extern "C"{ #endif #ifndef _di_fl_socket_file_bind_ - // bind a socket. + /** + * bind a socket. + */ extern f_return_status fl_socket_file_bind(const f_string socket_path, f_socket_id *socket_id, f_socket_address *socket_address); #endif // _di_fl_socket_file_bind_ #ifndef _di_fl_socket_listen_ - // terminate a socket connection - // suggested socket_backlog default setting = 8. + /** + * terminate a socket connection. + * suggested socket_backlog default setting = 8. + */ extern f_return_status fl_socket_listen(const f_socket_id socket_id, const f_u_int socket_backlog); #endif // _di_fl_socket_listen_ #ifndef _di_fl_socket_close_client_ - // terminate a socket connection - // suggested default close_action = f_socket_close_fast. + /** + * terminate a socket connection. + * suggested default close_action = f_socket_close_fast. + */ extern f_return_status fl_socket_close_client(const f_socket_id socket_id_client, const f_socket_close_id close_action); #endif // _di_fl_socket_close_client_ diff --git a/level_1/fl_strings/c/strings.c b/level_1/fl_strings/c/strings.c index 246ac8c..0e4cd2c 100644 --- a/level_1/fl_strings/c/strings.c +++ b/level_1/fl_strings/c/strings.c @@ -121,7 +121,7 @@ extern "C" { while (i2 < stop2 && string2[i2] == f_eos) i2++; if (string1[i1] != string2[i2]) return f_not_equal_to; - } // for() + } // for while (i1 < stop1) { if (string1[i1] != f_eos) return f_not_equal_to; @@ -155,7 +155,7 @@ extern "C" { while (i2 < stop2 && string2.string[i2] == f_eos) i2++; if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; - } // for() + } // for while (i1 < stop1) { if (string1.string[i1] != f_eos) return f_not_equal_to; @@ -195,7 +195,7 @@ extern "C" { while (i2 < stop2 && string2.string[i2] == f_eos) i2++; if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; - } // for() + } // for while (i1 < stop1) { if (string1.string[i1] != f_eos) return f_not_equal_to; diff --git a/level_1/fl_strings/c/strings.h b/level_1/fl_strings/c/strings.h index a6c6c36..831d2ef 100644 --- a/level_1/fl_strings/c/strings.h +++ b/level_1/fl_strings/c/strings.h @@ -11,59 +11,73 @@ #define _FL_strings_h // libc includes -#include #include +#include // fll includes -#include #include -#include #include +#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_rip_string_ - // given a start and stop position, this will return a new string based from the supplied buffer, based on the passed positions - // this will replace/overwrite existing information inside of the results variable + /** + * given a start and stop position, this will return a new string based from the supplied buffer, based on the passed positions. + * this will replace/overwrite existing information inside of the results variable. + */ extern f_return_status fl_rip_string(const f_dynamic_string buffer, const f_string_location position, f_dynamic_string *results); #endif // _di_fl_rip_string_ #ifndef _di_fl_seek_line_past_non_graph_ - // given a dynamic string and a string location, seek past all non-graph characters until a graph is reached - // will ignore the given placeholder + /** + * given a dynamic string and a string location, seek past all non-graph characters until a graph is reached. + * will ignore the given placeholder. + */ extern f_return_status fl_seek_line_past_non_graph(const f_dynamic_string buffer, f_string_location *position, const char placeholder); #endif // _di_fl_seek_line_past_non_graph_ #ifndef _di_fl_seek_line_until_non_graph_ - // given a dynamic string and a string location, seek past all graph characters until a non-graph is reached - // will ignore the given placeholder + /** + * given a dynamic string and a string location, seek past all graph characters until a non-graph is reached. + * will ignore the given placeholder. + */ extern f_return_status fl_seek_line_until_non_graph(const f_dynamic_string buffer, f_string_location *position, const char placeholder); #endif // _di_fl_seek_line_until_non_graph_ #ifndef _di_fl_seek_to_ - // given a dynamic string and a string location, seek past all characters until the given character is reached + /** + * given a dynamic string and a string location, seek past all characters until the given character is reached. + */ extern f_return_status fl_seek_to(const f_dynamic_string buffer, f_string_location *position, const char seek_to_this); #endif // _di_fl_seek_to_ #ifndef _di_fl_compare_strings_ - // this compares two strings and works similar to that of strncmp(..) but has significant differences to strncmp(..) - // given two strings, this will return either f_equal_to or f_not_equal_to - // this does not stop on f_eos and f_eos will be ignored as if it were not taking up any space, therefor a 5 character string could return f_equal_to if the 5 character string contains an f_eos anywhere within it + /** + * this compares two strings and works similar to that of strncmp(..) but has significant differences to strncmp(..). + * given two strings, this will return either f_equal_to or f_not_equal_to. + * this does not stop on f_eos and f_eos will be ignored as if it were not taking up any space, therefor a 5 character string could return f_equal_to if the 5 character string contains an f_eos anywhere within it. + */ extern f_return_status fl_compare_strings(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2); #endif // _di_fl_compare_strings_ #ifndef _di_fl_compare_dynamic_strings_ - // this compares two dynamic strings and works similar to that of strncmp(..) but has significant differences to strncmp(..) - // given two strings, this will return either f_equal_to or f_not_equal_to - // this is far safer than fl_compare_strings(..) as dynamic string contain size information within them - // this does not stop on f_eos and f_eos will be ignored as if it were not taking up any space, therefor a 5 character string could return f_equal_to if the 5 character string contains an f_eos anywhere within it + /** + * this compares two dynamic strings and works similar to that of strncmp(..) but has significant differences to strncmp(..). + * given two strings, this will return either f_equal_to or f_not_equal_to. + * this is far safer than fl_compare_strings(..) as dynamic string contain size information within them. + * this does not stop on f_eos and f_eos will be ignored as if it were not taking up any space, therefor a 5 character string could return f_equal_to if the 5 character string contains an f_eos anywhere within it. + */ extern f_return_status fl_compare_dynamic_strings(const f_dynamic_string string1, const f_dynamic_string string2); #endif // _di_fl_compare_dynamic_strings_ #ifndef _di_fl_compare_partial_dynamic_strings_ - // this functions identical to fl_compare_dynamic_strings, but uses offsets for both strings + /** + * this functions identical to fl_compare_dynamic_strings, but uses offsets for both strings. + */ extern f_return_status fl_compare_partial_dynamic_strings(const f_dynamic_string string1, const f_dynamic_string string2, const f_string_location offset1, const f_string_location offset2); #endif // _di_fl_compare_partial_dynamic_strings_ diff --git a/level_2/fll_colors/c/colors.c b/level_2/fll_colors/c/colors.c index 308cabf..40c559b 100644 --- a/level_2/fll_colors/c/colors.c +++ b/level_2/fll_colors/c/colors.c @@ -18,7 +18,8 @@ extern "C" { if (!environment || strncmp(environment, "linux", 6) == 0) { data->color_list = f_colors_linux; - } else { + } + else { data->color_list = f_colors_xterminal; } } @@ -33,7 +34,8 @@ extern "C" { if (f_error_is_not_error(status)) status = fl_save_color1(&data->notable, data->color_format, data->color_list.bold); if (f_error_is_not_error(status)) status = fl_save_color1(&data->important, data->color_format, data->color_list.blue); if (f_error_is_not_error(status)) status = fl_save_color1(&data->standout, data->color_format, data->color_list.purple); - } else { + } + else { status = fl_save_color1(&data->reset, data->color_format, data->color_list.reset); if (f_error_is_not_error(status)) status = fl_save_color1(&data->warning, data->color_format, data->color_list.yellow); diff --git a/level_2/fll_colors/c/colors.h b/level_2/fll_colors/c/colors.h index 79a3b13..9a0586e 100644 --- a/level_2/fll_colors/c/colors.h +++ b/level_2/fll_colors/c/colors.h @@ -15,9 +15,9 @@ #include // fll-0 includes -#include -#include #include +#include +#include // fll-1 includes #include @@ -27,9 +27,11 @@ extern "C" { #endif #ifndef _di_fll_colors_load_context_ - // For any application that uses the standard color contexts, this function will load the appropriate colors to the structure - // This will handle the difference betweem xorg terminals and linux consoles - // If you wish to use non-standard colors either redefine this function or don't use it + /** + * For any application that uses the standard color contexts, this function will load the appropriate colors to the structure. + * This will handle the difference betweem xorg terminals and linux consoles. + * If you wish to use non-standard colors either redefine this function or don't use it. + */ extern f_return_status fll_colors_load_context(fl_color_context *data, f_bool use_light_colors); #endif // _di_fll_colors_load_context_ diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index 789b018..28a327e 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -16,7 +16,7 @@ extern "C" { // create a string array that is compatible with execv() calls. f_string fixed_arguments[arguments.used + 2]; - f_string last_slash = f_string_initialize; + f_string last_slash = f_string_initialize; f_string program_name = f_string_initialize; f_string_length name_size = 0; @@ -37,7 +37,8 @@ extern "C" { memcpy(program_name, last_slash + 1, sizeof(f_string_length) * name_size); memset(program_name, name_size, 0); - } else { + } + else { name_size = 0; } } @@ -66,7 +67,7 @@ extern "C" { memcpy(fixed_arguments[i + 1], arguments.array[i].string, sizeof(char) * arguments.array[i].used); fixed_arguments[i + 1][arguments.array[i].used] = f_eos; - } + } // for // insert the required array terminated fixed_arguments[arguments.used + 2] = 0; @@ -83,7 +84,7 @@ extern "C" { for (f_string_length i = 0; i < arguments.used; i++) { f_delete_string(status2, fixed_arguments[i + 1], arguments.array[i].used + 1); - } + } // for return f_error_set_error(f_fork_failed); } @@ -106,7 +107,7 @@ extern "C" { for (f_string_length i = 0; i < arguments.used; i++) { f_delete_string(status2, fixed_arguments[i + 1], arguments.array[i].used + 1); - } + } // for } if (*results != 0) return f_error_set_error(f_failure); @@ -146,7 +147,7 @@ extern "C" { memcpy(fixed_arguments[i + 1], arguments.array[i].string, sizeof(char) * arguments.array[i].used); fixed_arguments[i + 1][arguments.array[i].used] = f_eos; - } + } // for // insert the required array terminated fixed_arguments[arguments.used + 2] = 0; @@ -161,7 +162,7 @@ extern "C" { for (f_string_length i = 0; i < arguments.used; i++) { f_delete_string(status2, fixed_arguments[i + 1], arguments.array[i].used + 1); - } + } // for return f_error_set_error(f_fork_failed); } diff --git a/level_2/fll_execute/c/execute.h b/level_2/fll_execute/c/execute.h index 7d28411..6ccc295 100644 --- a/level_2/fll_execute/c/execute.h +++ b/level_2/fll_execute/c/execute.h @@ -11,18 +11,18 @@ #define _FLL_execute_h // libc includes -#include -#include -#include #include // defines PATH_MAX -#include #include +#include +#include +#include +#include // fll-0 includes -#include #include -#include #include +#include +#include // fll-1 includes @@ -31,12 +31,16 @@ extern "C" { #endif #ifndef _di_fll_execute_path_ - // This will execute a program given some path + program name (such as "/bin/bash") + /** + * This will execute a program given some path + program name (such as "/bin/bash"). + */ extern f_return_status fll_execute_path(const f_string program_path, const f_dynamic_strings arguments, f_s_int *results); #endif // _di_fll_execute_path_ #ifndef _di_fll_execute_program_ - // This will find the program based on PATH environment so that static paths do not have to be used as with f_execute_path + /** + * This will find the program based on PATH environment so that static paths do not have to be used as with f_execute_path. + */ extern f_return_status fll_execute_program(const f_string program_name, const f_dynamic_strings arguments, f_s_int *results); #endif // _di_fll_execute_program_ diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index b4bd338..d9012f8 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -12,9 +12,9 @@ extern "C" { if (contents == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = f_none; + f_status status = f_none; f_string_length initial_used = objects->used; - f_bool found_data = f_false; + f_bool found_data = f_false; do { if (objects->used >= objects->size) { @@ -59,7 +59,8 @@ extern "C" { } return f_none_on_stop; - } else { + } + else { if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -73,7 +74,8 @@ extern "C" { status = fl_fss_basic_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content) { + } + else if (status == fl_fss_found_object_no_content) { found_data = f_true; if (contents->array[contents->used].used >= contents->array[contents->used].size) { @@ -95,7 +97,8 @@ extern "C" { objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { + } + else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivelents if (objects->used > initial_used) { @@ -104,10 +107,12 @@ extern "C" { } return status; - } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { + } + else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; + } // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used) { + else if (input->start >= input->stop || input->start >= buffer->used) { if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; @@ -135,8 +140,8 @@ extern "C" { if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = 0; - f_array_length current = 0; + f_status status = 0; + f_array_length current = 0; f_string_location location = f_string_location_initialize; location.start = 0; @@ -157,7 +162,8 @@ extern "C" { if (f_macro_test_for_no_data_errors(status)) { return status; } - } else { + } + else { if (buffer->used >= buffer->size) { f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); if (f_error_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index 9257c4d..0d892c5 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -11,11 +11,11 @@ #define _FLL_fss_basic_h // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include @@ -28,12 +28,16 @@ extern "C" { #endif #ifndef _di_fll_fss_basic_read_ - // read an fss-0000 object and then content + /** + * read an fss-0000 object and then content. + */ extern f_return_status fll_fss_basic_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_read_ #ifndef _di_fll_fss_basic_write_ - // write an fss-0000 object and then content + /** + * write an fss-0000 object and then content. + */ extern f_return_status fll_fss_basic_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); #endif // _di_fll_fss_basic_write_ diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 4f38d1c..42df25c 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -12,9 +12,9 @@ extern "C" { if (contents == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = f_none; + f_status status = f_none; f_string_length initial_used = objects->used; - f_bool found_data = f_false; + f_bool found_data = f_false; do { if (objects->used >= objects->size) { @@ -59,7 +59,8 @@ extern "C" { } return f_none_on_stop; - } else { + } + else { if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -70,10 +71,11 @@ extern "C" { if (status == fl_fss_found_object) { found_data = f_true; - status = fl_fss_basic_list_content_read(buffer, input, &contents->array[contents->used]); + status = fl_fss_basic_list_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content) { + } + else if (status == fl_fss_found_object_no_content) { found_data = f_true; if (contents->array[contents->used].used >= contents->array[contents->used].size) { @@ -95,19 +97,22 @@ extern "C" { objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { + } + else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivalents if (objects->used > initial_used) { - if (status == f_no_data_on_eos) return f_none_on_eos; + if (status == f_no_data_on_eos) return f_none_on_eos; if (status == f_no_data_on_stop) return f_none_on_stop; } return status; - } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { + } + else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; + } // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used) { + else if (input->start >= input->stop || input->start >= buffer->used) { if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; @@ -135,8 +140,8 @@ extern "C" { if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = 0; - f_array_length current = 0; + f_status status = 0; + f_array_length current = 0; f_string_location location = f_string_location_initialize; location.start = 0; @@ -157,7 +162,8 @@ extern "C" { if (f_macro_test_for_no_data_errors(status)) { return status; } - } else { + } + else { if (buffer->used >= buffer->size) { f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); if (f_error_is_error(status)) return status; diff --git a/level_2/fll_fss/c/fss_basic_list.h b/level_2/fll_fss/c/fss_basic_list.h index 3612083..0afe3e4 100644 --- a/level_2/fll_fss/c/fss_basic_list.h +++ b/level_2/fll_fss/c/fss_basic_list.h @@ -11,29 +11,33 @@ #define _FLL_fss_basic_list_h // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include -#include -#include #include +#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fll_fss_basic_list_read_ - // read an fss-0002 object and then content + /** + * read an fss-0002 object and then content. + */ extern f_return_status fll_fss_basic_list_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_list_read_ #ifndef _di_fll_fss_basic_list_write_ - // write an fss-0000 object and then content + /** + * write an fss-0000 object and then content. + */ extern f_return_status fll_fss_basic_list_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); #endif // _di_fll_fss_basic_list_write_ diff --git a/level_2/fll_fss/c/fss_errors.c b/level_2/fll_fss/c/fss_errors.c index e5fad3f..47b1c44 100644 --- a/level_2/fll_fss/c/fss_errors.c +++ b/level_2/fll_fss/c/fss_errors.c @@ -66,7 +66,8 @@ extern "C" { f_return_status fll_fss_errors_is_error(const f_status error) { if (fll_fss_errors_is_fine(error) == f_true) { return f_false; - } else if (fll_fss_errors_is_warning(error) == f_true) { + } + else if (fll_fss_errors_is_warning(error) == f_true) { return f_false; } diff --git a/level_2/fll_fss/c/fss_errors.h b/level_2/fll_fss/c/fss_errors.h index 5be69f7..cbcdbe8 100644 --- a/level_2/fll_fss/c/fss_errors.h +++ b/level_2/fll_fss/c/fss_errors.h @@ -11,44 +11,52 @@ #define _FLL_fss_errors_h // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include #include -#include -#include #include +#include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fll_fss_errors_to_string_ - // Convert error codes to their string equivalents. + /** + * Convert error codes to their string equivalents. + */ extern f_return_status fll_fss_errors_to_string(const f_status error, f_string *string); #endif // _di_fll_errors_to_string_ #ifndef _di_fll_fss_errors_is_error_ - // Returns true or false depending on whether the standard context of the error code represents an error. - // Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + /** + * Returns true or false depending on whether the standard context of the error code represents an error. + * Keep in mind that many of the error codes are context-specific and may be reported as an error here when it is in fact not an error. + */ extern f_return_status fll_fss_errors_is_error(const f_status error); #endif // _di_fll_fss_errors_is_error_ #ifndef _di_fll_fss_errors_is_warning_ - // Returns true or false depending on whether the standard context of the error code represents a warning. - // Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + /** + * Returns true or false depending on whether the standard context of the error code represents a warning. + * Keep in mind that many of the error codes are context-specific and may be reported as a warning here when it is in fact not a warning. + */ extern f_return_status fll_fss_errors_is_warning(const f_status error); #endif // _di_fll_fss_errors_is_warning_ #ifndef _di_fll_fss_errors_is_fine_ - // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. - // Keep in mind that many of the error codes are context-specific and may be reported as "fine" here when it is in fact not fine. + /** + * Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. + * Keep in mind that many of the error codes are context-specific and may be reported as "fine" here when it is in fact not fine. + */ extern f_return_status fll_fss_errors_is_fine(const f_status error); #endif // _di_fll_fss_errors_is_fine_ diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 10a24eb..42092f7 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -12,9 +12,9 @@ extern "C" { if (contents == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = f_none; + f_status status = f_none; f_string_length initial_used = objects->used; - f_bool found_data = f_false; + f_bool found_data = f_false; do { if (objects->used >= objects->size) { @@ -59,7 +59,8 @@ extern "C" { } return f_none_on_stop; - } else { + } + else { if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -73,7 +74,8 @@ extern "C" { status = fl_fss_extended_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content) { + } + else if (status == fl_fss_found_object_no_content) { found_data = f_true; if (contents->array[contents->used].used >= contents->array[contents->used].size) { @@ -95,7 +97,8 @@ extern "C" { objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { + } + else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivelents if (objects->used > initial_used) { @@ -106,8 +109,9 @@ extern "C" { return status; } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; + } // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used) { + else if (input->start >= input->stop || input->start >= buffer->used) { if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; @@ -132,11 +136,11 @@ extern "C" { f_return_status fll_fss_extended_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { #ifndef _di_level_2_parameter_checking_ if (buffer == 0) return f_error_set_error(f_invalid_parameter); - if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); + if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - f_status status = 0; - f_array_length current = 0; + f_status status = 0; + f_array_length current = 0; f_string_location location = f_string_location_initialize; location.start = 0; diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index 9c02b2b..3f5ff13 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -11,29 +11,33 @@ #define _FLL_fss_extended_h // fll-0 includes -#include #include -#include -#include #include +#include +#include +#include // fll-1 includes #include -#include #include #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef _di_fll_fss_extended_read_ - // read an fss-0001 object and then content + /** + * read an fss-0001 object and then content. + */ extern f_return_status fll_fss_extended_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_extended_read_ #ifndef _di_fll_fss_extended_write_ - // write an fss-0000 object and then content + /** + * write an fss-0000 object and then content. + */ extern f_return_status fll_fss_extended_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer); #endif // _di_fll_fss_extended_write_ diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 978d948..d6f9ff1 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -117,7 +117,7 @@ extern "C" { #ifndef _di_firewall_main_ f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data) { - f_status status = f_none; + f_status status = f_none; f_status status2 = f_none; status = fl_process_parameters(argc, argv, data->parameters, firewall_total_parameters, &data->remaining); @@ -128,7 +128,8 @@ extern "C" { if (status2 == f_none) { fll_colors_load_context(&data->context, data->parameters[firewall_parameter_light].result == f_console_result_found); - } else { + } + else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); firewall_delete_data(data); return status2; @@ -143,11 +144,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (f_error_set_fine(status) == f_invalid_parameter) { + } + else if (f_error_set_fine(status) == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } @@ -158,15 +162,17 @@ extern "C" { // execute parameter results if (data->parameters[firewall_parameter_help].result == f_console_result_found) { firewall_print_help(*data); - } else if (data->parameters[firewall_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[firewall_parameter_version].result == f_console_result_found) { firewall_print_version(*data); - } else { + } + else { // now determine which command was placed first - f_bool found_command = f_false; - f_u_int command = 0; + f_bool found_command = f_false; + f_u_int command = 0; if (data->parameters[firewall_parameter_command_start].result == f_console_result_found) { - command = firewall_parameter_command_start; + command = firewall_parameter_command_start; found_command = f_true; } @@ -175,8 +181,9 @@ extern "C" { if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_stop].additional.array[0]) { command = firewall_parameter_command_stop; } - } else { - command = firewall_parameter_command_stop; + } + else { + command = firewall_parameter_command_stop; found_command = f_true; } } @@ -186,8 +193,9 @@ extern "C" { if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_restart].additional.array[0]) { command = firewall_parameter_command_restart; } - } else { - command = firewall_parameter_command_restart; + } + else { + command = firewall_parameter_command_restart; found_command = f_true; } } @@ -197,8 +205,9 @@ extern "C" { if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_lock].additional.array[0]) { command = firewall_parameter_command_lock; } - } else { - command = firewall_parameter_command_lock; + } + else { + command = firewall_parameter_command_lock; found_command = f_true; } } @@ -208,8 +217,9 @@ extern "C" { if (data->parameters[command].additional.array[0] > data->parameters[firewall_parameter_command_show].additional.array[0]) { command = firewall_parameter_command_show; } - } else { - command = firewall_parameter_command_show; + } + else { + command = firewall_parameter_command_show; found_command = f_true; } } @@ -221,17 +231,17 @@ extern "C" { if (command == firewall_parameter_command_show) { // Warning: these are hardcoded print commands (I am not certain how I am going to implement external 'show' rules as the default-firewall setting file is the wrong place to put this) - f_bool show_nat = f_true; + f_bool show_nat = f_true; f_bool show_mangle = f_true; - f_bool show_ports = f_true; + f_bool show_ports = f_true; f_dynamic_strings arguments = f_dynamic_strings_initialize; - f_s_int results = 0; + f_s_int results = 0; if (data->remaining.used > 0) { - show_nat = f_false; + show_nat = f_false; show_mangle = f_false; - show_ports = f_false; + show_ports = f_false; f_string_length counter = 0; @@ -240,13 +250,16 @@ extern "C" { if (strncmp("mangle", argv[data->remaining.array[counter]], 7) != 0) { if (strncmp("ports", argv[data->remaining.array[counter]], 6) != 0) { fl_print_color_line(f_standard_warning, data->context.warning, data->context.reset, "WARNING: '%s' is not a valid show option", argv[data->remaining.array[counter]]); - } else { + } + else { show_ports = f_true; } - } else { + } + else { show_mangle = f_true; } - } else { + } + else { show_nat = f_true; } } // for @@ -346,7 +359,8 @@ extern "C" { if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_tool_iptables); fprintf(f_standard_error, " "); @@ -357,7 +371,7 @@ extern "C" { fprintf(f_standard_error, "%s ", firewall_tool_iptables); for (; i < arguments.used; i++) { fprintf(f_standard_error, "%s ", arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data->context.reset); fprintf(f_standard_error, "\n"); @@ -395,9 +409,11 @@ extern "C" { if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_no_data) { + } + else if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: could not find any network devices"); - } else if (status == f_failure) { + } + else if (status == f_failure) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: failed to read the device directory '%s'", network_devices); } @@ -418,11 +434,11 @@ extern "C" { for (; i < data->devices.used; i++) { data->devices.array[i] = data->devices.array[i+1]; - } + } // for data->devices.array[data->devices.used] = swap_string; } - } + } // for } if (command == firewall_parameter_command_stop || command == firewall_parameter_command_restart || command == firewall_parameter_command_lock) { @@ -444,7 +460,8 @@ extern "C" { if (!reserved.has_stop && fl_compare_strings((f_string) firewall_group_stop, local.buffer.string + local.chain_objects.array[i].start, firewall_group_stop_length, length) == f_equal_to) { reserved.stop_at = i; reserved.has_stop = f_true; - } else if (!reserved.has_lock && fl_compare_strings((f_string) firewall_group_lock, local.buffer.string + local.chain_objects.array[i].start, firewall_group_lock_length, length) == f_equal_to) { + } + else if (!reserved.has_lock && fl_compare_strings((f_string) firewall_group_lock, local.buffer.string + local.chain_objects.array[i].start, firewall_group_lock_length, length) == f_equal_to) { reserved.lock_at = i; reserved.has_lock = f_true; } @@ -530,7 +547,7 @@ extern "C" { firewall_delete_local_data(&local); firewall_delete_data(data); return status; - }; + } if (command == firewall_parameter_command_start) { status = firewall_delete_chains(*data); @@ -693,7 +710,8 @@ extern "C" { // cleanup firewall_delete_local_data(&local); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: You did not pass a command"); status = f_error_set_error(f_invalid_parameter); } @@ -706,8 +724,8 @@ extern "C" { #ifndef _di_firewall_delete_data_ f_return_status firewall_delete_data(firewall_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < firewall_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); diff --git a/level_3/firewall/c/firewall.h b/level_3/firewall/c/firewall.h index f94a77a..a2fc991 100644 --- a/level_3/firewall/c/firewall.h +++ b/level_3/firewall/c/firewall.h @@ -12,31 +12,31 @@ #ifndef _firewall_h // libc includes +#include #include #include -#include // fll-0 includes -#include -#include -#include -#include #include +#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include -#include // fll-2 includes +#include #include #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -50,7 +50,7 @@ extern "C" { #endif // _di_firewall_version_ #ifndef _di_firewall_name_ - #define firewall_name "firewall" + #define firewall_name "firewall" #define firewall_name_long "Kevux Firewall Manager" #endif // _di_firewall_name_ @@ -280,7 +280,7 @@ extern "C" { f_console_parameter parameters[firewall_total_parameters]; f_dynamic_strings chains; - f_string_lengths remaining; + f_string_lengths remaining; f_dynamic_strings devices; fl_color_context context; @@ -297,18 +297,30 @@ extern "C" { #endif // _di_firewall_data_ #ifndef _di_firewall_print_version_ + /** + * Print version. + */ extern f_return_status firewall_print_version(const firewall_data data); #endif // _di_firewall_print_version_ #ifndef _di_firewall_print_help_ + /** + * Print help. + */ extern f_return_status firewall_print_help(const firewall_data data); #endif // _di_firewall_print_help_ #ifndef _di_firewall_main_ + /** + * Main. + */ extern f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data); #endif // _di_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/private-firewall.c b/level_3/firewall/c/private-firewall.c index 3ec02e9..b8c1f13 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -36,7 +36,8 @@ if (local.is_global) { device_all = f_true; - } else { + } + else { if (data.devices.array[local.device].used > 0) { f_new_dynamic_string(status, device, data.devices.array[local.device].used); @@ -60,7 +61,7 @@ length = firewall_macro_structure_size(local.rule_objects, i); invalid = f_false; - is_ip_list = f_false; + is_ip_list = f_false; ip_list_direction = f_false; f_delete_dynamic_string(status2, ip_list); @@ -131,11 +132,13 @@ if (firewall_macro_rule_contents_has_incorrect_items(i, 1)) { invalid = f_true; - } else if (length >= firewall_device_all_length && fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_equal_to) { + } + else if (length >= firewall_device_all_length && fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_equal_to) { f_delete_dynamic_string(status, device); device_all = f_true; continue; - } else if (length >= firewall_device_this_length && fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_device_this, length, firewall_device_this_length) == f_equal_to) { + } + else if (length >= firewall_device_this_length && fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_device_this, length, firewall_device_this_length) == f_equal_to) { if (data.devices.array[local.device].used > 0) { if (data.devices.array[local.device].used > device.size) { f_resize_dynamic_string(status, device, data.devices.array[local.device].used); @@ -247,23 +250,27 @@ if (firewall_macro_rule_contents_has_incorrect_items(i, 1)) { invalid = f_true; - } else { + } + else { if (fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_tool_iptables, length, firewall_tool_iptables_length) == f_equal_to) { tool = firewall_program_iptables; current_tool = firewall_tool_iptables; current_tool_length = firewall_tool_iptables_length; repeat = 1; - } else if (fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_tool_ip6tables, length, firewall_tool_ip6tables_length) == f_equal_to) { + } + else if (fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_tool_ip6tables, length, firewall_tool_ip6tables_length) == f_equal_to) { tool = firewall_program_ip6tables; current_tool = firewall_tool_ip6tables; current_tool_length = firewall_tool_ip6tables_length; repeat = 1; - } else if (fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_tool_ip46tables, length, firewall_tool_ip46tables_length) == f_equal_to) { + } + else if (fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_tool_ip46tables, length, firewall_tool_ip46tables_length) == f_equal_to) { tool = firewall_program_ip46tables; current_tool = firewall_tool_iptables; current_tool_length = firewall_tool_iptables_length; repeat = 2; - } else { + } + else { invalid = f_true; } @@ -278,7 +285,8 @@ f_print_string(f_standard_warning, local.buffer.string + local.rule_objects.array[i].start, length); fprintf(f_standard_warning, "' is invalid"); fl_print_color_code(f_standard_warning, data.context.reset); - } else { + } + else { fprintf(f_standard_warning, "WARNING: At line %i, the object is missing", i); } @@ -298,7 +306,8 @@ fprintf(f_standard_warning, "'"); fl_print_color_code(f_standard_warning, data.context.reset); fprintf(f_standard_warning, "\n"); - } else { + } + else { fl_print_color_line(f_standard_warning, data.context.warning, data.context.reset, "WARNING: At line %i, the object has no content", i); } @@ -316,7 +325,8 @@ if (r == 2) { current_tool = firewall_tool_iptables; current_tool_length = firewall_tool_iptables_length; - } else { + } + else { current_tool = firewall_tool_ip6tables; current_tool_length = firewall_tool_ip6tables_length; } @@ -386,21 +396,24 @@ firewall_macro_concat_string(argument.string, firewall_chain_postrouting, firewall_chain_postrouting_length); argument.used += firewall_chain_postrouting_length; - } else if (chain == firewall_chain_prerouting_id) { + } + else if (chain == firewall_chain_prerouting_id) { f_new_dynamic_string(status, argument, firewall_chain_prerouting_length); if (f_error_is_error(status)) break; firewall_macro_concat_string(argument.string, firewall_chain_prerouting, firewall_chain_prerouting_length); argument.used = firewall_chain_prerouting_length; - } else if (chain == firewall_chain_input_id) { + } + else if (chain == firewall_chain_input_id) { f_new_dynamic_string(status, argument, firewall_chain_input_length); if (f_error_is_error(status)) break; firewall_macro_concat_string(argument.string, firewall_chain_input, firewall_chain_input_length); argument.used = firewall_chain_input_length; - } else if (chain == firewall_chain_output_id) { + } + else if (chain == firewall_chain_output_id) { f_new_dynamic_string(status, argument, firewall_chain_output_length); if (f_error_is_error(status)) break; @@ -548,12 +561,12 @@ // now execute the generated commands. if (arguments.used > 1) { if (is_ip_list) { - f_file file = f_file_initialize; - f_dynamic_string file_path = f_dynamic_string_initialize; - f_dynamic_string local_buffer = f_dynamic_string_initialize; - f_file_position file_position = f_file_position_initialize; + f_file file = f_file_initialize; + f_dynamic_string file_path = f_dynamic_string_initialize; + f_dynamic_string local_buffer = f_dynamic_string_initialize; + f_file_position file_position = f_file_position_initialize; - f_fss_objects basic_objects = f_fss_objects_initialize; + f_fss_objects basic_objects = f_fss_objects_initialize; f_fss_contents basic_contents = f_fss_objects_initialize; f_new_dynamic_string(status, file_path, network_path_length + ip_list.used + firewall_default_allocation_step); @@ -572,17 +585,22 @@ if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { // the file does not have to exist fl_print_color_line(f_standard_warning, data.context.warning, data.context.reset, "WARNING: Cannot find the file '%.*s'", file_path.used, file_path.string); status = f_none; - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to open the file '%.*s'", file_path.used, file_path.string); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: File descriptor error while trying to open the file '%.*s'", file_path.used, file_path.string); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -658,8 +676,8 @@ status = f_error_set_error(status); } else { - f_string_length buffer_counter = 0; - f_string_length ip_length = 0; + f_string_length buffer_counter = 0; + f_string_length ip_length = 0; f_dynamic_string ip_list_action = f_dynamic_string_initialize; if (ip_list_direction) { @@ -723,7 +741,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data.context.reset); fprintf(f_standard_debug, "\n"); @@ -741,7 +759,7 @@ fprintf(f_standard_error, "%s ", current_tool); for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data.context.reset); fprintf(f_standard_error, "\n"); @@ -765,7 +783,7 @@ // remove ip_argument from arguments string. f_delete_dynamic_string(status2, arguments.array[arguments.used]); arguments.used--; - } + } // for f_delete_dynamic_string(status2, ip_argument); @@ -793,7 +811,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data.context.reset); fprintf(f_standard_debug, "\n"); @@ -810,13 +828,14 @@ fprintf(f_standard_error, "%s ", current_tool); for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data.context.reset); fprintf(f_standard_error, "\n"); break; - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); break; } @@ -1035,7 +1054,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data->context.reset); fprintf(f_standard_debug, "\n"); @@ -1054,7 +1073,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data->context.reset); fprintf(f_standard_debug, "\n"); @@ -1071,7 +1090,8 @@ if (status == f_failure) { if (tool == firewall_program_iptables) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_tool_iptables); - } else if (tool == firewall_program_ip6tables) { + } + else if (tool == firewall_program_ip6tables) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_tool_ip6tables); } @@ -1087,13 +1107,15 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data->context.reset); fprintf(f_standard_error, "\n"); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_error_set_error(status)); } @@ -1140,7 +1162,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data.context.reset); fprintf(f_standard_debug, "\n"); @@ -1161,7 +1183,7 @@ fprintf(f_standard_error, "%s ", tools[i]); for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data.context.reset); fprintf(f_standard_error, "\n"); @@ -1175,7 +1197,7 @@ return status; } - } + } // for for (f_string_length i = 0; i < 2; i++) { f_dynamic_strings arguments = f_dynamic_strings_initialize; @@ -1198,7 +1220,7 @@ for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_debug, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_debug, data.context.reset); fprintf(f_standard_debug, "\n"); @@ -1219,7 +1241,7 @@ fprintf(f_standard_error, "%s ", tools[i]); for (f_string_length i = 0; i < arguments.used; i++) { fprintf(f_standard_error, "%.*s ", arguments.array[i].used, arguments.array[i].string); - } + } // for fl_print_color_code(f_standard_error, data.context.reset); fprintf(f_standard_error, "\n"); @@ -1252,19 +1274,24 @@ if (optional) { if (status == f_invalid_parameter) { fl_print_color_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 && status != f_file_open_error && status != f_file_descriptor_error) { + } + else if (status != f_file_not_found && status != f_file_open_error && status != f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_error_set_error(status)); } } else { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'.", filename); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'.", filename); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'.", filename); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_error_set_error(status)); } } @@ -1284,22 +1311,29 @@ if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()."); - } else if (status == f_overflow) { + } + else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'.", filename); - } else if (status == f_file_not_open) { + } + else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open.", filename); - } else if (status == f_file_seek_error) { + } + else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'.", filename); - } else if (status == f_file_read_error) { + } + else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'.", filename); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", f_error_set_error(status)); } return status; - } else { + } + else { f_string_location input = f_string_location_initialize; input.stop = local->buffer.used - 1; @@ -1312,11 +1346,14 @@ if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'.", filename); - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { + } + else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: No relevant data was found within the file '%s'.", filename); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'.", f_error_set_error(status), filename); } @@ -1329,7 +1366,7 @@ #ifndef _di_firewall_process_rules_ f_return_status firewall_process_rules(f_string_location *input, firewall_local_data *local, firewall_data *data) { - f_status status = f_none; + f_status status = f_none; f_status status2 = f_none; status = fll_fss_extended_read(&local->buffer, input, &local->rule_objects, &local->rule_contents); @@ -1342,9 +1379,11 @@ if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_failure) { + } + else if (status == f_failure) { // the error message has already been displayed. - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", f_error_set_error(status)); } diff --git a/level_3/firewall/c/private-firewall.h b/level_3/firewall/c/private-firewall.h index 4ddc620..9689e19 100644 --- a/level_3/firewall/c/private-firewall.h +++ b/level_3/firewall/c/private-firewall.h @@ -24,12 +24,12 @@ extern "C" { f_array_length device; f_dynamic_string buffer; - f_array_length chain; - f_array_lengths chain_ids; - f_fss_objects chain_objects; - f_fss_contents chain_contents; - f_fss_objects rule_objects; - f_fss_contents rule_contents; + f_array_length chain; + f_array_lengths chain_ids; + f_fss_objects chain_objects; + f_fss_contents chain_contents; + f_fss_objects rule_objects; + f_fss_contents rule_contents; } firewall_local_data; #define firewall_local_data_initialize \ @@ -110,26 +110,44 @@ extern "C" { #endif // _di_firewall_macro_private_ #ifndef _di_firewall_perform_commands_ + /** + * Perform commands. + */ f_return_status firewall_perform_commands(const firewall_local_data local, const firewall_data data) f_gcc_attribute_visibility_internal; #endif // _di_firewall_perform_commands_ #ifndef _di_firewall_create_custom_chains_ + /** + * Create custom chains. + */ f_return_status firewall_create_custom_chains(firewall_reserved_chains *reserved, firewall_local_data *local, firewall_data *data) f_gcc_attribute_visibility_internal; #endif // _di_firewall_create_custom_chains_ #ifndef _di_firewall_delete_chains_ + /** + * Deallocate chains. + */ f_return_status firewall_delete_chains(const firewall_data data) f_gcc_attribute_visibility_internal; #endif // _di_firewall_delete_chains_ #ifndef _di_firewall_buffer_rules_ + /** + * Buffer firewall rules. + */ f_return_status firewall_buffer_rules(const f_string filename, const f_bool optional, firewall_local_data *local, firewall_data *data) f_gcc_attribute_visibility_internal; #endif // _di_firewall_buffer_rules_ #ifndef _di_firewall_process_rules_ + /** + * Process buffered rules. + */ f_return_status firewall_process_rules(f_string_location *input, firewall_local_data *local, firewall_data *data) f_gcc_attribute_visibility_internal; #endif // _di_firewall_process_rules_ #ifndef _di_firewall_delete_local_data_ + /** + * Delete allocated data. + */ f_return_status firewall_delete_local_data(firewall_local_data *local) f_gcc_attribute_visibility_internal; #endif // _di_firewall_delete_local_data_ 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 472c83b..4c1d541 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 @@ -139,7 +139,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_list_read_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_basic_list_read_parameter_light].result == f_console_result_found); } } @@ -152,11 +153,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } @@ -167,9 +171,11 @@ extern "C" { // execute parameter results if (data->parameters[fss_basic_list_read_parameter_help].result == f_console_result_found) { fss_basic_list_read_print_help(*data); - } else if (data->parameters[fss_basic_list_read_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_basic_list_read_parameter_version].result == f_console_result_found) { fss_basic_list_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe) { + } + else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = 0; f_string_length target = 0; f_string_length original_size = data->file_position.total_elements; @@ -190,13 +196,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -228,13 +238,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -265,17 +279,23 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow) { + } + else if (status == f_overflow) { fl_print_color_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]]); - } else if (status == f_file_not_open) { + } + else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error) { + } + else if (status == f_file_seek_error) { fl_print_color_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]]); - } else if (status == f_file_read_error) { + } + else if (status == f_file_read_error) { fl_print_color_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]]); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } @@ -294,7 +314,8 @@ extern "C" { f_delete_fss_objects(status2, data->objects); f_delete_dynamic_string(status2, data->buffer); } // for - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); status = f_error_set_error(f_invalid_parameter); } @@ -324,15 +345,18 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_error_set_error(status), filename); } fss_basic_list_read_delete_data(data); return f_error_set_error(status); - } else if (f_macro_test_for_no_data_errors(status)) { + } + else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file f_delete_fss_contents(status2, data->contents); f_delete_fss_objects(status2, data->objects); @@ -344,7 +368,8 @@ extern "C" { // now that all of the files have been read, process the objects and contents if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } else { + } + else { current = 0; if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { @@ -365,15 +390,17 @@ extern "C" { size++; fprintf(f_standard_output, "%u\n", (unsigned int) size); - } else { + } + else { fprintf(f_standard_output, "0\n"); } - } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + } + else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { 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_location range = f_string_location_initialize; + 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_location range = f_string_location_initialize; // use an invalid range to communicate range not found range.start = 1; @@ -403,7 +430,8 @@ extern "C" { f_print_partial_dynamic_string(f_standard_output, data->buffer, range); } } - } else { + } + else { if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); @@ -414,12 +442,14 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } } // for - } else { + } + else { for (; current < data->objects.used; current++) { 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_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); @@ -429,16 +459,18 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } } // for } - } else { + } + else { current = 0; - f_string_length total = 0; + f_string_length total = 0; f_string_length name_length = 0; f_string_length argv_length = 0; @@ -465,19 +497,21 @@ extern "C" { size++; fprintf(f_standard_output, "%u\n", (unsigned int) size); - } else { + } + else { fprintf(f_standard_output, "0\n"); } - } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + } + else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { 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_location range = f_string_location_initialize; + 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_location range = f_string_location_initialize; // use an invalid range to communicate range not found range.start = 1; - range.stop = 0; + range.stop = 0; for (; counter <= data->contents.array[current].array[0].stop; counter++) { if (position == target) { @@ -503,11 +537,13 @@ extern "C" { f_print_partial_dynamic_string(f_standard_output, data->buffer, range); } } - } else { + } + else { 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)) { if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { total++; - } else { + } + else { if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); @@ -519,7 +555,8 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -530,7 +567,8 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none) { fprintf(f_standard_output, f_string_length_printf "\n", total); } - } else { + } + else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object for (; current < data->contents.used; current++) { @@ -547,7 +585,8 @@ extern "C" { if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -566,8 +605,8 @@ extern "C" { #ifndef _di_fss_basic_list_read_delete_data_ f_return_status fss_basic_list_read_delete_data(fss_basic_list_read_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < fss_basic_list_read_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); @@ -585,7 +624,6 @@ extern "C" { } #endif // _di_fss_basic_list_read_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 d5727d5..413253d 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 @@ -12,30 +12,30 @@ #ifndef _fss_basic_list_read_h // libc includes -#include -#include #include +#include #include +#include // fll-0 includes -#include -#include -#include #include -#include +#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include -#include // fll-2 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { @@ -49,7 +49,7 @@ extern "C" { #endif // _di_fss_basic_list_read_version_ #ifndef _di_fss_basic_list_read_name_ - #define fss_basic_list_read_name "fss_basic_list_read" + #define fss_basic_list_read_name "fss_basic_list_read" #define fss_basic_list_read_name_long "FSS Basic List Read" #endif // _di_fss_basic_list_read_name_ @@ -103,12 +103,12 @@ extern "C" { typedef struct { f_console_parameter parameters[fss_basic_list_read_total_parameters]; - f_dynamic_string buffer; - f_fss_objects objects; - f_fss_contents contents; - f_file_position file_position; - f_string_lengths remaining; - f_bool process_pipe; + f_dynamic_string buffer; + f_fss_objects objects; + f_fss_contents contents; + f_file_position file_position; + f_string_lengths remaining; + f_bool process_pipe; fl_color_context context; } fss_basic_list_read_data; @@ -127,18 +127,30 @@ extern "C" { #endif // _di_fss_basic_list_read_data_ #ifndef _di_fss_basic_list_read_print_version_ + /** + * Print version. + */ extern f_return_status fss_basic_list_read_print_version(const fss_basic_list_read_data data); #endif // _di_fss_basic_list_read_print_version_ #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_ #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); #endif // _di_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_write/c/fss_basic_list_write.c b/level_3/fss_basic_list_write/c/fss_basic_list_write.c index 3451d37..0f728f2 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 @@ -111,7 +111,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_list_write_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_basic_list_write_parameter_light].result == f_console_result_found); } } @@ -124,11 +125,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } @@ -139,17 +143,19 @@ extern "C" { // execute parameter results if (data->parameters[fss_basic_list_write_parameter_help].result == f_console_result_found) { fss_basic_list_write_print_help(*data); - } else if (data->parameters[fss_basic_list_write_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_basic_list_write_parameter_version].result == f_console_result_found) { fss_basic_list_write_print_version(*data); - } else { + } + else { f_array_length counter = 0; - f_bool object = (data->parameters[fss_basic_list_write_parameter_object].result == f_console_result_found); + f_bool object = (data->parameters[fss_basic_list_write_parameter_object].result == f_console_result_found); - f_dynamic_string buffer = f_dynamic_string_initialize; + f_dynamic_string buffer = f_dynamic_string_initialize; f_string_location location = f_string_location_initialize; if (data->process_pipe) { - f_file file = f_file_initialize; + f_file file = f_file_initialize; f_dynamic_string input = f_dynamic_string_initialize; file.file = f_pipe; @@ -161,13 +167,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -185,7 +195,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { status = fl_fss_basic_list_content_write(input, &location, &buffer); if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { @@ -194,7 +205,8 @@ extern "C" { } f_delete_dynamic_string(status, input); - } else if (data->parameters[fss_basic_list_write_parameter_string].result == f_console_result_additional) { + } + else if (data->parameters[fss_basic_list_write_parameter_string].result == f_console_result_additional) { f_dynamic_string input = f_dynamic_string_initialize; input.string = argv[data->parameters[fss_basic_list_write_parameter_string].additional.array[0]]; @@ -209,7 +221,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { status = fl_fss_basic_list_content_write(input, &location, &buffer); if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { @@ -233,13 +246,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_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]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_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]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -255,16 +272,19 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_write_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_basic_list_write_delete_data(data); return f_error_set_error(status); } - } else { + } + else { f_print_dynamic_string(f_standard_output, buffer); } } @@ -291,7 +311,6 @@ extern "C" { } #endif // _di_fss_basic_list_write_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 5765183..8557deb 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 @@ -11,23 +11,23 @@ // libc includes #include -#include #include +#include // fll-0 includes -#include -#include #include -#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include #include -#include // fll-2 includes #include @@ -45,7 +45,7 @@ extern "C" { #endif // _di_fss_basic_list_write_version_ #ifndef _di_fss_basic_list_write_name_ - #define fss_basic_list_write_name "fss_basic_list_write" + #define fss_basic_list_write_name "fss_basic_list_write" #define fss_basic_list_write_name_long "FSS Basic List Write" #endif // _di_fss_basic_list_write_name_ @@ -88,7 +88,7 @@ extern "C" { f_console_parameter parameters[fss_basic_list_write_total_parameters]; f_string_lengths remaining; - f_bool process_pipe; + f_bool process_pipe; fl_color_context context; } fss_basic_list_write_data; @@ -103,18 +103,30 @@ extern "C" { #endif // _di_fss_basic_list_write_data_ #ifndef _di_fss_basic_list_write_print_version_ + /** + * Print version. + */ extern f_return_status fss_basic_list_write_print_version(const fss_basic_list_write_data data); #endif // _di_fss_basic_list_write_print_version_ #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_ #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); #endif // _di_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_read/c/fss_basic_read.c b/level_3/fss_basic_read/c/fss_basic_read.c index 5e1234f..313fac3 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -125,7 +125,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_read_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_basic_read_parameter_light].result == f_console_result_found); } } @@ -138,11 +139,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } @@ -153,9 +157,11 @@ extern "C" { // execute parameter results if (data->parameters[fss_basic_read_parameter_help].result == f_console_result_found) { fss_basic_read_print_help(*data); - } else if (data->parameters[fss_basic_read_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_basic_read_parameter_version].result == f_console_result_found) { fss_basic_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe) { + } + else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = 0; f_string_length target = 0; f_string_length original_size = data->file_position.total_elements; @@ -176,17 +182,23 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow) { + } + else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", "-"); - } else if (status == f_file_not_open) { + } + else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", "-"); - } else if (status == f_file_seek_error) { + } + else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", "-"); - } else if (status == f_file_read_error) { + } + else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", "-"); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } @@ -219,13 +231,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -256,17 +272,23 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow) { + } + else if (status == f_overflow) { fl_print_color_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]]); - } else if (status == f_file_not_open) { + } + else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error) { + } + else if (status == f_file_seek_error) { fl_print_color_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]]); - } else if (status == f_file_read_error) { + } + else if (status == f_file_read_error) { fl_print_color_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]]); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } @@ -286,7 +308,8 @@ extern "C" { f_delete_dynamic_string(status2, data->buffer); } // for } - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); status = f_error_set_error(f_invalid_parameter); } @@ -316,15 +339,18 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_error_set_error(status), filename); } fss_basic_read_delete_data(data); return f_error_set_error(status); - } else if (f_macro_test_for_no_data_errors(status)) { + } + else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file f_delete_fss_contents(status2, data->contents); f_delete_fss_objects(status2, data->objects); @@ -336,7 +362,8 @@ extern "C" { // now that the file has been read, process the objects and contents if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } else { + } + else { current = 0; if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { @@ -346,7 +373,8 @@ extern "C" { if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); - } else { + } + else { // for all objects with no data, print a newline fprintf(f_standard_output, "\n"); } @@ -355,12 +383,14 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } } // for - } else { + } + else { for (; current < data->objects.used; current++) { 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_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); @@ -370,16 +400,18 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } } // for } - } else { + } + else { current = 0; - f_string_length total = 0; + f_string_length total = 0; f_string_length name_length = 0; f_string_length argv_length = 0; @@ -396,11 +428,13 @@ extern "C" { 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) { total++; - } else { + } + else { if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); - } else { + } + else { // for all objects with no data, print a newline fprintf(f_standard_output, "\n"); } @@ -410,7 +444,8 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -421,7 +456,8 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none) { fprintf(f_standard_output, f_string_length_printf "\n", total); } - } else { + } + else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object for (; current < data->contents.used; current++) { @@ -438,7 +474,8 @@ extern "C" { if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -457,8 +494,8 @@ extern "C" { #ifndef _di_fss_basic_read_delete_data_ f_return_status fss_basic_read_delete_data(fss_basic_read_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < fss_basic_read_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); @@ -476,7 +513,6 @@ extern "C" { } #endif // _di_fss_basic_read_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 f548be7..3ae81f8 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -12,30 +12,30 @@ #ifndef _fss_basic_read_h // libc includes -#include -#include #include +#include #include +#include // fll-0 includes -#include -#include -#include #include -#include +#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include -#include // fll-2 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { @@ -49,7 +49,7 @@ extern "C" { #endif // _di_fss_basic_read_version_ #ifndef _di_fss_basic_read_name_ - #define fss_basic_read_name "fss_basic_read" + #define fss_basic_read_name "fss_basic_read" #define fss_basic_read_name_long "FSS Basic Read" #endif // _di_fss_basic_read_name_ @@ -95,12 +95,12 @@ extern "C" { typedef struct { f_console_parameter parameters[fss_basic_read_total_parameters]; - f_dynamic_string buffer; - f_fss_objects objects; - f_fss_contents contents; - f_file_position file_position; - f_string_lengths remaining; - f_bool process_pipe; + f_dynamic_string buffer; + f_fss_objects objects; + f_fss_contents contents; + f_file_position file_position; + f_string_lengths remaining; + f_bool process_pipe; fl_color_context context; } fss_basic_read_data; @@ -119,18 +119,30 @@ extern "C" { #endif // _di_fss_basic_read_data_ #ifndef _di_fss_basic_read_print_version_ + /** + * Print version. + */ extern f_return_status fss_basic_read_print_version(const fss_basic_read_data data); #endif // _di_fss_basic_read_print_version_ #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_ #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); #endif // _di_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_write/c/fss_basic_write.c b/level_3/fss_basic_write/c/fss_basic_write.c index 644de3b..3dee730 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -111,7 +111,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_write_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_basic_write_parameter_light].result == f_console_result_found); } } @@ -124,11 +125,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } @@ -139,17 +143,19 @@ extern "C" { // execute parameter results if (data->parameters[fss_basic_write_parameter_help].result == f_console_result_found) { fss_basic_write_print_help(*data); - } else if (data->parameters[fss_basic_write_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_basic_write_parameter_version].result == f_console_result_found) { fss_basic_write_print_version(*data); - } else { + } + else { f_array_length counter = 0; - f_bool object = (data->parameters[fss_basic_write_parameter_object].result == f_console_result_found); + f_bool object = (data->parameters[fss_basic_write_parameter_object].result == f_console_result_found); - f_dynamic_string buffer = f_dynamic_string_initialize; + f_dynamic_string buffer = f_dynamic_string_initialize; f_string_location location = f_string_location_initialize; if (data->process_pipe) { - f_file file = f_file_initialize; + f_file file = f_file_initialize; f_dynamic_string input = f_dynamic_string_initialize; file.file = f_pipe; @@ -161,13 +167,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -185,7 +195,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { status = fl_fss_basic_content_write(&buffer, input, &location); if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { @@ -194,7 +205,8 @@ extern "C" { } f_delete_dynamic_string(status, input); - } else if (data->parameters[fss_basic_write_parameter_string].result == f_console_result_additional) { + } + else if (data->parameters[fss_basic_write_parameter_string].result == f_console_result_additional) { f_dynamic_string input = f_dynamic_string_initialize; input.string = argv[data->parameters[fss_basic_write_parameter_string].additional.array[0]]; @@ -209,7 +221,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { status = fl_fss_basic_content_write(&buffer, input, &location); if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { @@ -233,13 +246,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_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]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_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]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -255,16 +272,19 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_write_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_basic_write_delete_data(data); return f_error_set_error(status); } - } else { + } + else { f_print_dynamic_string(f_standard_output, buffer); } } @@ -291,7 +311,6 @@ extern "C" { } #endif // _di_fss_basic_write_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 2463429..5bcca41 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.h +++ b/level_3/fss_basic_write/c/fss_basic_write.h @@ -11,22 +11,22 @@ // libc includes #include -#include #include +#include // fll-0 includes -#include -#include #include -#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include -#include // fll-2 includes #include @@ -44,7 +44,7 @@ extern "C" { #endif // _di_fss_basic_write_version_ #ifndef _di_fss_basic_write_name_ - #define fss_basic_write_name "fss_basic_write" + #define fss_basic_write_name "fss_basic_write" #define fss_basic_write_name_long "FSS Basic Write" #endif // _di_fss_basic_write_name_ @@ -87,7 +87,7 @@ extern "C" { f_console_parameter parameters[fss_basic_write_total_parameters]; f_string_lengths remaining; - f_bool process_pipe; + f_bool process_pipe; fl_color_context context; } fss_basic_write_data; @@ -102,18 +102,30 @@ extern "C" { #endif // _di_fss_basic_write_data_ #ifndef _di_fss_basic_write_print_version_ + /** + * Print version. + */ extern f_return_status fss_basic_write_print_version(const fss_basic_write_data data); #endif // _di_fss_basic_write_print_version_ #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_ #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); #endif // _di_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_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index 6fbfd00..8f3452c 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -132,7 +132,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_extended_read_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_extended_read_parameter_light].result == f_console_result_found); } } @@ -145,11 +146,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } @@ -160,12 +164,14 @@ extern "C" { // execute parameter results if (data->parameters[fss_extended_read_parameter_help].result == f_console_result_found) { fss_extended_read_print_help(*data); - } else if (data->parameters[fss_extended_read_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_extended_read_parameter_version].result == f_console_result_found) { fss_extended_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe) { + } + else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = 0; - f_string_length target = 0; - f_string_length select = 0; + f_string_length target = 0; + f_string_length select = 0; f_string_length original_size = data->file_position.total_elements; if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { @@ -188,13 +194,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -227,19 +237,24 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_extended_read_delete_data(data); return f_error_set_error(status); - } else if (f_macro_test_for_no_data_errors(status)) { + } + else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file f_delete_fss_contents(status2, data->contents); f_delete_fss_objects(status2, data->objects); @@ -271,17 +286,23 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow) { + } + else if (status == f_overflow) { fl_print_color_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]]); - } else if (status == f_file_not_open) { + } + else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error) { + } + else if (status == f_file_seek_error) { fl_print_color_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]]); - } else if (status == f_file_read_error) { + } + else if (status == f_file_read_error) { fl_print_color_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]]); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } @@ -300,7 +321,8 @@ extern "C" { f_delete_fss_objects(status2, data->objects); f_delete_dynamic_string(status2, data->buffer); } // for - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); status = f_error_set_error(f_invalid_parameter); } @@ -320,7 +342,7 @@ extern "C" { f_string_location input = f_string_location_initialize; input.start = 0; - input.stop = data->buffer.used - 1; + input.stop = data->buffer.used - 1; status = fll_fss_extended_read(&data->buffer, &input, &data->objects, &data->contents); } @@ -330,15 +352,18 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_read() for the file '%s'", filename); - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_read() for the file '%s'", f_error_set_error(status), filename); } fss_extended_read_delete_data(data); return f_error_set_error(status); - } else if (f_macro_test_for_no_data_errors(status)) { + } + else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file f_delete_fss_contents(status2, data->contents); f_delete_fss_objects(status2, data->objects); @@ -350,7 +375,8 @@ extern "C" { // now that all of the files have been read, process the objects and contents if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); - } else { + } + else { current = 0; if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { @@ -360,7 +386,8 @@ extern "C" { if (data->contents.array[current].used > select) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); fprintf(f_standard_output, "\n"); - } else { + } + else { // for all objects with no data, print a newline fprintf(f_standard_output, "\n"); } @@ -369,12 +396,14 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } } // for - } else { + } + else { for (; current < data->objects.used; current++) { 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_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); @@ -384,7 +413,8 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -393,7 +423,7 @@ extern "C" { } else { current = 0; - f_string_length total = 0; + f_string_length total = 0; f_string_length name_length = 0; f_string_length argv_length = 0; @@ -410,11 +440,13 @@ extern "C" { 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) { total++; - } else { + } + else { if (data->contents.array[current].used > select) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); fprintf(f_standard_output, "\n"); - } else { + } + else { // for all objects with no data, print a newline fprintf(f_standard_output, "\n"); } @@ -428,7 +460,8 @@ extern "C" { if (found == target) { break; - } else { + } + else { found++; } } @@ -439,7 +472,8 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { fprintf(f_standard_output, f_string_length_printf "\n", total); } - } else { + } + else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object for (; current < data->contents.used; current++) { @@ -456,7 +490,8 @@ extern "C" { if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { if (found == target) { break; - } else { + } + else { found++; } } @@ -475,8 +510,8 @@ extern "C" { #ifndef _di_fss_extended_read_delete_data_ f_return_status fss_extended_read_delete_data(fss_extended_read_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < fss_extended_read_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); @@ -494,7 +529,6 @@ extern "C" { } #endif // _di_fss_extended_read_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 ed1499b..6ea6bf3 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -12,30 +12,30 @@ #ifndef _fss_extended_read_h // libc includes -#include -#include #include +#include #include +#include // fll-0 includes -#include -#include -#include #include -#include +#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include -#include // fll-2 includes -#include #include #include +#include #ifdef __cplusplus extern "C" { @@ -99,12 +99,12 @@ extern "C" { typedef struct { f_console_parameter parameters[fss_extended_read_total_parameters]; - f_dynamic_string buffer; - f_fss_objects objects; - f_fss_contents contents; - f_file_position file_position; - f_string_lengths remaining; - f_bool process_pipe; + f_dynamic_string buffer; + f_fss_objects objects; + f_fss_contents contents; + f_file_position file_position; + f_string_lengths remaining; + f_bool process_pipe; fl_color_context context; } fss_extended_read_data; @@ -123,18 +123,30 @@ extern "C" { #endif // _di_fss_extended_read_data_ #ifndef _di_fss_extended_read_print_version_ + /** + * Print version. + */ extern f_return_status fss_extended_read_print_version(const fss_extended_read_data data); #endif // _di_fss_extended_read_print_version_ #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_ #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); #endif // _di_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_write/c/fss_extended_write.c b/level_3/fss_extended_write/c/fss_extended_write.c index df4fae2..0ad4afd 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -118,7 +118,8 @@ extern "C" { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_extended_write_delete_data(data); return status2; - } else { + } + else { fll_colors_load_context(&data->context, data->parameters[fss_extended_write_parameter_light].result == f_console_result_found); } } @@ -131,11 +132,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } @@ -146,17 +150,19 @@ extern "C" { // execute parameter results if (data->parameters[fss_extended_write_parameter_help].result == f_console_result_found) { fss_extended_write_print_help(*data); - } else if (data->parameters[fss_extended_write_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_extended_write_parameter_version].result == f_console_result_found) { fss_extended_write_print_version(*data); - } else { + } + else { f_array_length counter = 0; - f_bool object = (data->parameters[fss_extended_write_parameter_object].result == f_console_result_found); + f_bool object = (data->parameters[fss_extended_write_parameter_object].result == f_console_result_found); - f_dynamic_string buffer = f_dynamic_string_initialize; + f_dynamic_string buffer = f_dynamic_string_initialize; f_string_location location = f_string_location_initialize; if (data->process_pipe) { - f_file file = f_file_initialize; + f_file file = f_file_initialize; f_dynamic_string input = f_dynamic_string_initialize; file.file = f_pipe; @@ -168,13 +174,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -192,7 +202,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { status = fl_fss_extended_content_write(input, &location, &buffer); if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { @@ -214,7 +225,8 @@ extern "C" { } f_delete_dynamic_string(status, input); - } else if (data->parameters[fss_extended_write_parameter_string].result == f_console_result_additional) { + } + else if (data->parameters[fss_extended_write_parameter_string].result == f_console_result_additional) { f_dynamic_string input = f_dynamic_string_initialize; if (object) { @@ -229,7 +241,8 @@ extern "C" { if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { return f_error_set_error(status); } - } else { + } + else { f_string_length i = 0; while (i < data->parameters[fss_extended_write_parameter_string].additional.used) { @@ -278,13 +291,17 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_not_found) { fl_print_color_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]]); - } else if (status == f_file_open_error) { + } + else if (status == f_file_open_error) { fl_print_color_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]]); - } else if (status == f_file_descriptor_error) { + } + else if (status == f_file_descriptor_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } @@ -300,16 +317,19 @@ extern "C" { if (status == f_invalid_parameter) { fl_print_color_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) { + } + else if (status == f_file_write_error) { fl_print_color_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]]); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_extended_write_delete_data(data); return f_error_set_error(status); } - } else { + } + else { f_print_dynamic_string(f_standard_output, buffer); } } @@ -336,7 +356,6 @@ extern "C" { } #endif // _di_fss_extended_write_delete_data_ - #ifdef __cplusplus } // extern "C" #endif 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 cb82cac..f8e2cbc 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.h +++ b/level_3/fss_extended_write/c/fss_extended_write.h @@ -11,23 +11,23 @@ // libc includes #include -#include #include +#include // fll-0 includes -#include -#include #include -#include #include +#include +#include +#include // fll-1 includes #include #include +#include #include #include #include -#include // fll-2 includes #include @@ -45,7 +45,7 @@ extern "C" { #endif // _di_fss_extended_write_version_ #ifndef _di_fss_extended_write_name_ - #define fss_extended_write_name "fss_extended_write" + #define fss_extended_write_name "fss_extended_write" #define fss_extended_write_name_long "FSS Extended Write" #endif // _di_fss_extended_write_name_ @@ -92,7 +92,7 @@ extern "C" { f_console_parameter parameters[fss_extended_write_total_parameters]; f_string_lengths remaining; - f_bool process_pipe; + f_bool process_pipe; fl_color_context context; } fss_extended_write_data; @@ -107,18 +107,30 @@ extern "C" { #endif // _di_fss_extended_write_data_ #ifndef _di_fss_extended_write_print_version_ + /** + * Print version. + */ extern f_return_status fss_extended_write_print_version(const fss_extended_write_data data); #endif // _di_fss_extended_write_print_version_ #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_ #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); #endif // _di_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_return_code/c/fss_return_code.c b/level_3/fss_return_code/c/fss_return_code.c index fc7fb4b..941f2e3 100644 --- a/level_3/fss_return_code/c/fss_return_code.c +++ b/level_3/fss_return_code/c/fss_return_code.c @@ -111,7 +111,7 @@ extern "C" { #ifndef _di_fss_return_code_main_ f_return_status fss_return_code_main(const f_array_length argc, const f_string argv[], fss_return_code_data *data) { - f_status status = f_none; + f_status status = f_none; f_status allocation_status = f_none; status = fl_process_parameters(argc, argv, data->parameters, fss_return_code_total_parameters, &data->remaining); @@ -137,11 +137,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status); } @@ -152,9 +155,11 @@ extern "C" { // execute parameter results if (data->parameters[fss_return_code_parameter_help].result == f_console_result_found) { fss_return_code_print_help(*data); - } else if (data->parameters[fss_return_code_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[fss_return_code_parameter_version].result == f_console_result_found) { fss_return_code_print_version(*data); - } else if (data->parameters[fss_return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[fss_return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -167,17 +172,19 @@ extern "C" { fss_return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_error(code)) { fss_return_code_delete_data(data); return f_true; } } - } + } // for fss_return_code_delete_data(data); return f_false; - } else if (data->parameters[fss_return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[fss_return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -190,17 +197,19 @@ extern "C" { fss_return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_warning(code)) { fss_return_code_delete_data(data); return f_true; } } - } + } // for fss_return_code_delete_data(data); return f_false; - } else if (data->parameters[fss_return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[fss_return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -213,17 +222,19 @@ extern "C" { fss_return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_fine(code)) { fss_return_code_delete_data(data); return f_true; } } - } + } // for fss_return_code_delete_data(data); return f_false; - } else if (data->remaining.used > 0 || data->process_pipe) { + } + else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = 0; if (data->process_pipe) { @@ -232,7 +243,7 @@ extern "C" { if (data->remaining.used > 0) { for (; counter < data->remaining.used; counter++) { - f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); + f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); f_string string = 0; if (fll_fss_errors_to_string(code, &string) == f_none) { @@ -240,7 +251,8 @@ extern "C" { } } // for } - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); status = f_error_set_error(f_invalid_parameter); } @@ -252,8 +264,8 @@ extern "C" { #ifndef _di_fss_return_code_delete_data_ f_return_status fss_return_code_delete_data(fss_return_code_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < fss_return_code_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); @@ -267,7 +279,6 @@ extern "C" { } #endif // _di_fss_return_code_delete_data_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/fss_return_code/c/fss_return_code.h b/level_3/fss_return_code/c/fss_return_code.h index fb2e886..0359e66 100644 --- a/level_3/fss_return_code/c/fss_return_code.h +++ b/level_3/fss_return_code/c/fss_return_code.h @@ -11,21 +11,21 @@ // libc includes #include -#include #include +#include // fll-0 includes -#include -#include #include -#include #include +#include +#include +#include // fll-1 includes #include #include -#include #include +#include // fll-2 includes #include @@ -90,7 +90,7 @@ extern "C" { f_console_parameter parameters[fss_return_code_total_parameters]; f_string_lengths remaining; - f_bool process_pipe; + f_bool process_pipe; fl_color_context context; } fss_return_code_data; @@ -105,18 +105,30 @@ extern "C" { #endif // _di_fss_return_code_data_ #ifndef _di_fss_return_code_print_version_ + /** + * Print version. + */ extern f_return_status fss_return_code_print_version(const fss_return_code_data data); #endif // _di_fss_return_code_print_version_ #ifndef _di_fss_return_code_print_help_ + /** + * Print help. + */ extern f_return_status fss_return_code_print_help(const fss_return_code_data data); #endif // _di_fss_return_code_print_help_ #ifndef _di_fss_return_code_main_ + /** + * Main. + */ extern f_return_status fss_return_code_main(const f_array_length argc, const f_string argv[], fss_return_code_data *data); #endif // _di_fss_return_code_main_ #ifndef _di_fss_return_code_delete_data_ + /** + * Deallocate data. + */ extern f_return_status fss_return_code_delete_data(fss_return_code_data *data); #endif // _di_fss_return_code_delete_data_ diff --git a/level_3/return_code/c/return_code.c b/level_3/return_code/c/return_code.c index aec79d0..b053360 100644 --- a/level_3/return_code/c/return_code.c +++ b/level_3/return_code/c/return_code.c @@ -111,7 +111,7 @@ extern "C" { #ifndef _di_return_code_main_ f_return_status return_code_main(const f_array_length argc, const f_string argv[], return_code_data *data) { - f_status status = f_none; + f_status status = f_none; f_status allocation_status = f_none; status = fl_process_parameters(argc, argv, data->parameters, return_code_total_parameters, &data->remaining); @@ -137,11 +137,14 @@ extern "C" { // 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 - } else if (f_macro_test_for_allocation_errors(status)) { + } + else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter) { + } + else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status); } @@ -152,9 +155,11 @@ extern "C" { // execute parameter results if (data->parameters[return_code_parameter_help].result == f_console_result_found) { return_code_print_help(*data); - } else if (data->parameters[return_code_parameter_version].result == f_console_result_found) { + } + else if (data->parameters[return_code_parameter_version].result == f_console_result_found) { return_code_print_version(*data); - } else if (data->parameters[return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -167,17 +172,19 @@ extern "C" { return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_error(code)) { return_code_delete_data(data); return f_true; } } - } + } // for return_code_delete_data(data); return f_false; - } else if (data->parameters[return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -190,17 +197,19 @@ extern "C" { return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_warning(code)) { return_code_delete_data(data); return f_true; } } - } + } // for return_code_delete_data(data); return f_false; - } else if (data->parameters[return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { + } + else if (data->parameters[return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = 0; f_status code = f_none; @@ -213,17 +222,19 @@ extern "C" { return_code_delete_data(data); return f_true; } - } else { + } + else { if (f_error_is_fine(code)) { return_code_delete_data(data); return f_true; } } - } + } // for return_code_delete_data(data); return f_false; - } else if (data->remaining.used > 0 || data->process_pipe) { + } + else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = 0; if (data->process_pipe) { @@ -232,7 +243,7 @@ extern "C" { if (data->remaining.used > 0) { for (; counter < data->remaining.used; counter++) { - f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); + f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); f_string string = 0; if (fl_errors_to_string(code, &string) == f_none) { @@ -240,7 +251,8 @@ extern "C" { } } // for } - } else { + } + else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); status = f_error_set_error(f_invalid_parameter); } @@ -252,8 +264,8 @@ extern "C" { #ifndef _di_return_code_delete_data_ f_return_status return_code_delete_data(return_code_data *data) { - f_status status = f_none; - f_string_length i = 0; + f_status status = f_none; + f_string_length i = 0; while (i < return_code_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); @@ -267,7 +279,6 @@ extern "C" { } #endif // _di_return_code_delete_data_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/return_code/c/return_code.h b/level_3/return_code/c/return_code.h index 6752788..aa22951 100644 --- a/level_3/return_code/c/return_code.h +++ b/level_3/return_code/c/return_code.h @@ -9,21 +9,21 @@ // libc includes #include -#include #include +#include // fll-0 includes -#include -#include #include -#include #include +#include +#include +#include // fll-1 includes #include #include -#include #include +#include // fll-2 includes #include @@ -40,7 +40,7 @@ extern "C" { #endif // _di_return_code_version_ #ifndef _di_return_code_name_ - #define return_code_name "return_code" + #define return_code_name "return_code" #define return_code_name_long "Error Code" #endif // _di_return_code_name_ @@ -87,7 +87,7 @@ extern "C" { f_console_parameter parameters[return_code_total_parameters]; f_string_lengths remaining; - f_bool process_pipe; + f_bool process_pipe; fl_color_context context; } return_code_data; @@ -102,18 +102,30 @@ extern "C" { #endif // _di_return_code_data_ #ifndef _di_return_code_print_version_ + /** + * Print version. + */ extern f_return_status return_code_print_version(const return_code_data data); #endif // _di_return_code_print_version_ #ifndef _di_return_code_print_help_ + /** + * Print help. + */ extern f_return_status return_code_print_help(const return_code_data data); #endif // _di_return_code_print_help_ #ifndef _di_return_code_main_ + /** + * Main. + */ extern f_return_status return_code_main(const f_array_length argc, const f_string argv[], return_code_data *data); #endif // _di_return_code_main_ #ifndef _di_return_code_delete_data_ + /** + * Deallocate data. + */ extern f_return_status return_code_delete_data(return_code_data *data); #endif // _di_return_code_delete_data_ -- 1.8.3.1