From 3fe85f303ea0e1c13211c26bbabd4bef5d558855 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 13 Nov 2019 00:12:42 -0600 Subject: [PATCH] Progress: continue implementing fss_basic_read, also numerous other fixes/tweaks I decided to allow --at and --name to be used at the same time (and therefore at the same --depth). The depth code is to be rewritten and that is only partially rewritten. Many of the parameters are now written and the fss_basic_read needs to be tested and reviewed. (There fss_basic_read is still incomplete, but there is enough working code to begin testing.) --- level_0/f_conversion/c/conversion.c | 54 ++- level_0/f_conversion/c/conversion.h | 5 +- level_0/f_fss/c/fss.h | 24 +- level_0/f_memory/c/memory.h | 8 +- level_0/f_status/c/status.h | 1 + level_0/f_string/c/string.h | 8 +- level_0/f_utf/c/utf.h | 8 +- level_1/fl_console/c/console.c | 4 +- level_1/fl_console/c/console.h | 4 +- level_1/fl_fss/c/fss.c | 4 +- level_1/fl_fss/c/fss_basic.c | 7 +- level_1/fl_fss/c/fss_extended.c | 6 +- level_1/fl_fss/c/fss_macro.h | 10 +- level_1/fl_status/c/status.c | 3 + level_1/fl_status/c/status.h | 3 + level_2/fll_fss/c/fss_basic.c | 10 +- level_2/fll_fss/c/fss_basic.h | 2 +- level_2/fll_fss/c/fss_basic_list.c | 4 +- level_2/fll_fss/c/fss_basic_list.h | 2 +- level_2/fll_fss/c/fss_extended.c | 4 +- level_2/fll_fss/c/fss_extended.h | 2 +- level_2/fll_fss/c/fss_extended_list.c | 4 +- level_2/fll_fss/c/fss_extended_list.h | 2 +- level_2/fll_program/c/program.c | 18 +- level_2/fll_status/c/status.c | 5 + level_3/byte_dump/c/private-byte_dump.c | 2 +- level_3/firewall/c/firewall.c | 8 +- level_3/firewall/c/private-firewall.c | 40 +- level_3/firewall/c/private-firewall.h | 2 +- .../fss_basic_list_read/c/fss_basic_list_read.h | 2 + .../c/private-fss_basic_list_read.c | 12 +- .../c/private-fss_basic_list_read.h | 4 +- .../fss_basic_list_write/c/fss_basic_list_write.c | 6 +- level_3/fss_basic_read/c/fss_basic_read.c | 60 ++- level_3/fss_basic_read/c/fss_basic_read.h | 2 + level_3/fss_basic_read/c/private-fss_basic_read.c | 442 ++++++++------------- level_3/fss_basic_read/c/private-fss_basic_read.h | 43 +- level_3/fss_basic_write/c/fss_basic_write.c | 6 +- .../c/fss_extended_list_read.h | 2 + .../c/private-fss_extended_list_read.c | 12 +- .../c/private-fss_extended_list_read.h | 4 +- level_3/fss_extended_read/c/fss_extended_read.h | 2 + .../c/private-fss_extended_read.c | 12 +- .../c/private-fss_extended_read.h | 4 +- level_3/fss_extended_write/c/fss_extended_write.c | 10 +- level_3/init/c/private-init.c | 32 +- level_3/init/c/private-init.h | 16 +- 47 files changed, 475 insertions(+), 450 deletions(-) diff --git a/level_0/f_conversion/c/conversion.c b/level_0/f_conversion/c/conversion.c index 869d489..6cbf5fc 100644 --- a/level_0/f_conversion/c/conversion.c +++ b/level_0/f_conversion/c/conversion.c @@ -725,6 +725,10 @@ extern "C" { if (location.stop < location.start) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ + if (string[0] == '\0') { + return f_status_set_error(f_no_data); + } + uint8_t width = 0; uint8_t width_max = 0; uint8_t mode = 0; @@ -834,7 +838,7 @@ extern "C" { } // for if (mode == 0) { - return f_no_data; + return f_status_set_error(f_invalid_number); } f_string_location location_offset = f_string_location_initialize; @@ -870,12 +874,17 @@ extern "C" { if (location.stop < location.start) return f_status_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ + if (string[0] == '\0') { + return f_status_set_error(f_no_data); + } + uint8_t width = 0; uint8_t width_max = 0; uint8_t mode = 0; f_string_length j = 0; f_string_length offset = 0; f_status status = f_none; + int8_t sign_found = 0; for (f_string_length i = location.start; i <= location.stop; i++) { width = f_macro_utf_byte_width_is(string[i]); @@ -947,14 +956,14 @@ extern "C" { break; } - // plus sign is not allowed. if (string[i] == 0x2b) { - return f_status_set_error(f_invalid_number); + offset++; + sign_found = 1; } - // negative sign is not allowed. if (string[i] == 0x2d) { - return f_status_set_error(f_negative_number); + offset++; + sign_found = -1; } if (f_conversion_character_is_decimal(string[i]) == f_true) { @@ -966,7 +975,7 @@ extern "C" { } // for if (mode == 0) { - return f_no_data; + return f_status_set_error(f_invalid_number); } f_string_location location_offset = f_string_location_initialize; @@ -974,22 +983,35 @@ extern "C" { location_offset.stop = location.stop; if (mode == 10) { - return f_conversion_string_to_decimal_unsigned(string, number, location_offset); + status = f_conversion_string_to_decimal_unsigned(string, number, location_offset); } - - if (mode == 16) { - return f_conversion_string_to_hexidecimal_unsigned(string, number, location_offset); + else if (mode == 16) { + status = f_conversion_string_to_hexidecimal_unsigned(string, number, location_offset); } - - if (mode == 12) { - return f_conversion_string_to_duodecimal_unsigned(string, number, location_offset); + else if (mode == 12) { + status = f_conversion_string_to_duodecimal_unsigned(string, number, location_offset); + } + else if (mode == 8) { + status = f_conversion_string_to_octal_unsigned(string, number, location_offset); + } + else { + status = f_conversion_string_to_binary_unsigned(string, number, location_offset); } - if (mode == 8) { - return f_conversion_string_to_octal_unsigned(string, number, location_offset); + // +/- signs are not allowed. + if (sign_found) { + if (status == f_none) { + if (sign_found == -1) { + return f_status_set_error(f_negative_number); + } + + return f_status_set_error(f_positive_number); + } + + return f_status_set_error(f_invalid_number); } - return f_conversion_string_to_binary_unsigned(string, number, location_offset); + return status; } #endif // _di_f_conversion_string_to_number_unsigned_ diff --git a/level_0/f_conversion/c/conversion.h b/level_0/f_conversion/c/conversion.h index a90ab8b..1c67884 100644 --- a/level_0/f_conversion/c/conversion.h +++ b/level_0/f_conversion/c/conversion.h @@ -535,7 +535,7 @@ extern "C" { * * @return * f_none on success. - * f_no_data is returned if string only contains valid whitespace. + * f_no_data (with error bit) if string starts with a null (length is 0). * f_invalid_parameter (with error bit) if a parameter is invalid. * f_invalid_number (with error bit) if parameter is not a number. * f_overflow (with error bit) on integer overflow. @@ -578,10 +578,11 @@ extern "C" { * * @return * f_none on success. - * f_no_data is returned if string only contains valid whitespace. + * f_no_data (with error bit) if string starts with a null (length is 0). * f_invalid_parameter (with error bit) if a parameter is invalid. * f_invalid_number (with error bit) if parameter is not a number. * f_negative_number (with error bit) on negative value. + * f_positive_number (with error bit) on positive value (has a +, such as '+1', when only '1' is valid here). * f_overflow (with error bit) on integer overflow. * f_incomplete_utf (with error bit) if an incomplete UTF-8 fragment is found. * diff --git a/level_0/f_fss/c/fss.h b/level_0/f_fss/c/fss.h index fb2c755..ecb7fef 100644 --- a/level_0/f_fss/c/fss.h +++ b/level_0/f_fss/c/fss.h @@ -490,7 +490,7 @@ extern "C" { status = f_none; \ if (new_length < content_childs.size) { \ f_array_length i = content_childs.size - new_length; \ - for (; i < content_childs.size; ++i) { \ + for (; i < content_childs.size; i++) { \ f_macro_fss_content_child_delete(status, content_childs.array[i]); \ if (status != f_none) break; \ } \ @@ -499,7 +499,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_childs.size) { \ f_array_length i = content_childs.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_childs.array[i], 0, sizeof(f_fss_content_child)); \ } \ } \ @@ -520,7 +520,7 @@ extern "C" { status = f_none; \ if (new_length < content_childs.size) { \ length_variable i = content_childs.size - new_length; \ - for (; i < content_childs.size; ++i) { \ + for (; i < content_childs.size; i++) { \ f_macro_fss_content_child_destroy(status, content_childs.array[i]); \ if (status != f_none) break; \ } \ @@ -529,7 +529,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_childs.size) { \ length_variable i = content_childs.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_childs.array[i], 0, sizeof(f_fss_content_child)); \ } \ } \ @@ -634,7 +634,7 @@ extern "C" { status = f_none; \ if (new_length < content_nest.size) { \ f_array_length i = content_nest.size - new_length; \ - for (; i < content_nest.size; ++i) { \ + for (; i < content_nest.size; i++) { \ f_macro_fss_content_childs_delete(status, content_nest.array[i]); \ if (status != f_none) break; \ } \ @@ -643,7 +643,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_nest.size) { \ f_array_length i = content_nest.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_nest.array[i], 0, sizeof(f_fss_content_childs)); \ } \ } \ @@ -662,7 +662,7 @@ extern "C" { status = f_none; \ if (new_length < content_nest.size) { \ f_array_length i = content_nest.size - new_length; \ - for (; i < content_nest.size; ++i) { \ + for (; i < content_nest.size; i++) { \ f_macro_fss_content_childs_destroy(status, content_nest.array[i]); \ if (status != f_none) break; \ } \ @@ -671,7 +671,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_nest.size) { \ f_array_length i = content_nest.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_childs.array[i], 0, sizeof(f_fss_content_child)); \ } \ } \ @@ -770,7 +770,7 @@ extern "C" { status = f_none; \ if (new_length < content_nests.size) { \ f_array_length i = content_nests.size - new_length; \ - for (; i < content_nests.size; ++i) { \ + for (; i < content_nests.size; i++) { \ f_macro_fss_content_nest_delete(status, content_nests.array[i]); \ if (status != f_none) break; \ } \ @@ -779,7 +779,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_nests.size) { \ f_array_length i = content_nests.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_nests.array[i], 0, sizeof(f_fss_content_nest)); \ } \ } \ @@ -798,7 +798,7 @@ extern "C" { status = f_none; \ if (new_length < content_nests.size) { \ f_array_length i = content_nests.size - new_length; \ - for (; i < content_nests.size; ++i) { \ + for (; i < content_nests.size; i++) { \ f_macro_fss_content_nest_destroy(status, content_nests.array[i]); \ if (status != f_none) break; \ } \ @@ -807,7 +807,7 @@ extern "C" { if (status == f_none) { \ if (new_length > content_nests.size) { \ f_array_length i = content_nests.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&content_nests.array[i], 0, sizeof(f_fss_content_nest)); \ } \ } \ diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index 116b4d7..97ba4c8 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -369,7 +369,7 @@ extern "C" { status = f_none; \ if (new_length < structures.size) { \ length_variable i = structures.size - new_length; \ - for (; i < structures.size; ++i) { \ + for (; i < structures.size; i++) { \ f_macro_memory_structure_delete(status, structures.array[i], type); \ if (status != f_none) break; \ } \ @@ -378,7 +378,7 @@ extern "C" { if (status == f_none) { \ if (new_length > structures.size) { \ length_variable i = structures.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&structures.array[i], 0, sizeof(type)); \ } \ } \ @@ -401,7 +401,7 @@ extern "C" { status = f_none; \ if (new_length < structures.size) { \ length_variable i = structures.size - new_length; \ - for (; i < structures.size; ++i) { \ + for (; i < structures.size; i++) { \ f_macro_memory_structure_destroy(status, structures.array[i], type); \ if (status != f_none) break; \ } \ @@ -410,7 +410,7 @@ extern "C" { if (status == f_none) { \ if (new_length > structures.size) { \ length_variable i = structures.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&structures.array[i], 0, sizeof(type)); \ } \ } \ diff --git a/level_0/f_status/c/status.h b/level_0/f_status/c/status.h index ec3e090..e3e6f6e 100644 --- a/level_0/f_status/c/status.h +++ b/level_0/f_status/c/status.h @@ -145,6 +145,7 @@ enum { f_failure, f_interrupted, // usually by a signal. f_loop, // such as infinite recursion. + f_incomplete, // incomplete information #endif // _di_f_status_basic_ #ifndef _di_f_status_invalid_ diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index c03678c..ae553a3 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -313,7 +313,7 @@ extern "C" { status = f_none; \ if (new_length < dynamics.size) { \ f_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i) { \ + for (; i < dynamics.size; i++) { \ f_macro_string_dynamic_destroy(status, dynamics.array[i]); \ if (status != f_none) break; \ } \ @@ -322,7 +322,7 @@ extern "C" { if (status == f_none) { \ if (new_length > dynamics.size) { \ f_string_length i = dynamics.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ } \ } \ @@ -334,7 +334,7 @@ extern "C" { status = f_none; \ if (new_length < dynamics.size) { \ f_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i) { \ + for (; i < dynamics.size; i++) { \ f_macro_string_dynamic_destroy(status, dynamics.array[i], f_string_dynamic); \ if (status != f_none) break; \ } \ @@ -343,7 +343,7 @@ extern "C" { if (status == f_none) { \ if (new_length > dynamics.size) { \ f_string_length i = dynamics.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&dynamics.array[i], 0, sizeof(f_string_dynamic)); \ } \ } \ diff --git a/level_0/f_utf/c/utf.h b/level_0/f_utf/c/utf.h index 67e6b9c..8e9b372 100644 --- a/level_0/f_utf/c/utf.h +++ b/level_0/f_utf/c/utf.h @@ -370,7 +370,7 @@ extern "C" { status = f_none; \ if (new_length < dynamics.size) { \ f_utf_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i) { \ + for (; i < dynamics.size; i++) { \ f_macro_utf_string_dynamic_destroy(status, dynamics.array[i]); \ if (status != f_none) break; \ } \ @@ -379,7 +379,7 @@ extern "C" { if (status == f_none) { \ if (new_length > dynamics.size) { \ f_utf_string_length i = dynamics.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&dynamics.array[i], 0, sizeof(f_utf_string_dynamic)); \ } \ } \ @@ -391,7 +391,7 @@ extern "C" { status = f_none; \ if (new_length < dynamics.size) { \ f_utf_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i) { \ + for (; i < dynamics.size; i++) { \ f_macro_utf_string_dynamic_destroy(status, dynamics.array[i], f_utf_string_dynamic); \ if (status != f_none) break; \ } \ @@ -400,7 +400,7 @@ extern "C" { if (status == f_none) { \ if (new_length > dynamics.size) { \ f_utf_string_length i = dynamics.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&dynamics.array[i], 0, sizeof(f_utf_string_dynamic)); \ } \ } \ diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index 244d864..292f421 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -11,7 +11,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_f if (argument[0] == '\0') { - return f_no_data; + return f_status_set_error(f_no_data); } f_string_location location = f_string_location_initialize; @@ -29,7 +29,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_f if (argument[0] == '\0') { - return f_no_data; + return f_status_set_error(f_no_data); } f_string_location location = f_string_location_initialize; diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index 39ee897..286d403 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -48,7 +48,7 @@ extern "C" { * * @return * f_none on success. - * f_no_data the argument is empty or only contains valid whitespace. + * f_no_data (with error bit) if string starts wth a null (length is 0). * f_invalid_parameter (with error bit) if a parameter is invalid. * f_invalid_number (with error bit) if parameter is not a number. * f_overflow (with error bit) on integer overflow. @@ -83,7 +83,7 @@ extern "C" { * * @return * f_none on success. - * f_no_data the argument is empty or only contains valid whitespace. + * f_no_data (with error bit) if string starts wth a null (length is 0). * f_invalid_parameter (with error bit) if a parameter is invalid. * f_invalid_number (with error bit) if parameter is not a number. * f_negative_number (with error bit) on negative value. diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index ec4c3f6..be73638 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -310,7 +310,7 @@ extern "C" { max_width = buffer.used - location->start; } - while (buffer.string[location->start] == f_string_eos || (status = f_utf_is_graph(buffer.string + location->start, max_width)) == f_false) { + while (buffer.string[location->start] == f_string_eos || (status = f_utf_is_whitespace(buffer.string + location->start, max_width)) == f_true) { if (f_status_is_error(status)) { return status; } @@ -463,7 +463,7 @@ extern "C" { if (distance > 0) { while (position < buffer->used + distance && position <= location.stop) { buffer->string[position] = f_fss_delimit_placeholder; - ++position; + position++; } } diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index 92b3c03..3485f5f 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -125,7 +125,7 @@ extern "C" { // identify where the object ends if (quoted == f_string_eos) { status = f_none; - while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = fl_fss_is_graph(*buffer, *location)) == f_true) { + while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = fl_fss_is_space(*buffer, *location)) == f_false) { status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; @@ -354,7 +354,6 @@ extern "C" { return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -374,7 +373,6 @@ extern "C" { return fl_fss_found_no_object; } - status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; } // while @@ -396,7 +394,6 @@ extern "C" { f_macro_string_lengths_delete(allocation_status, delimits); } - status = fl_fss_increment_buffer(*buffer, location, 1); if (f_status_is_error(status)) return status; @@ -442,7 +439,7 @@ extern "C" { if (buffer->string[location->start] == f_fss_basic_close) break; - ++location->start; + location->start++; } while (f_true); // Save the stop length diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 807f357..2361fe7 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -66,7 +66,7 @@ extern "C" { continue; } - else if ((status = fl_fss_is_graph(*buffer, *location)) == f_false) { + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { found->stop = location->start - 1; status = fl_fss_increment_buffer(*buffer, location, 1); @@ -444,7 +444,7 @@ extern "C" { continue; } - else if ((status = fl_fss_is_graph(*buffer, *location)) == f_false) { + else if ((status = fl_fss_is_space(*buffer, *location)) == f_true) { found->array[found->used].stop = location->start - 1; status = fl_fss_increment_buffer(*buffer, location, 1); @@ -1179,7 +1179,7 @@ extern "C" { return f_none_on_eol; } - if (content.string[location->start] != f_fss_delimit_placeholder && (status = fl_fss_is_graph(*buffer, *location)) == f_false) { + if (content.string[location->start] != f_fss_delimit_placeholder && (status = fl_fss_is_space(*buffer, *location)) == f_true) { quoted = f_fss_delimit_double_quote; pre_allocate_size += 2; diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index 8574123..eeca21a 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -34,7 +34,7 @@ extern "C" { #ifndef _di_fl_macro_fss_skip_past_delimit_placeholders_ #define fl_macro_fss_skip_past_delimit_placeholders(buffer, location) \ while (buffer.string[location.start] == f_fss_delimit_placeholder) { \ - ++location.start;\ + location.start++;\ \ if (location.start >= buffer.used) break; \ if (location.start > location.stop) break; \ @@ -221,7 +221,7 @@ extern "C" { #ifndef _di_fl_macro_fss_object_seek_till_newline_ #define fl_macro_fss_object_seek_till_newline(buffer, location, delimits, eos_status, stop_status) \ while (buffer.string[location.start] != f_string_eol) { \ - ++location.start; \ + location.start++; \ if (location.start >= buffer.used) { \ f_status macro_allocation_status = f_none; \ f_macro_string_lengths_delete(macro_allocation_status, delimits); \ @@ -240,7 +240,7 @@ extern "C" { #ifndef _di_fl_macro_fss_object_delimited_seek_till_newline_ #define fl_macro_fss_object_delimited_seek_till_newline(buffer, location, delimits, eos_status, stop_status) \ while (buffer.string[location.start] != f_string_eol) { \ - ++location.start; \ + location.start++; \ if (location.start >= buffer.used) { \ f_status macro_allocation_status = f_none; \ f_string_length i = 0; \ @@ -271,7 +271,7 @@ extern "C" { #ifndef _di_fl_macro_fss_content_seek_till_newline_ #define fl_macro_fss_content_seek_till_newline(buffer, location, found, delimits, eos_status, stop_status) \ while (buffer.string[location.start] != f_string_eol) { \ - ++location.start; \ + location.start++; \ if (location.start >= buffer.used) { \ f_status macro_allocation_status = f_none; \ f_macro_string_lengths_delete(macro_allocation_status, delimits); \ @@ -292,7 +292,7 @@ extern "C" { #ifndef _di_fl_macro_fss_content_delimited_seek_till_newline_ #define fl_macro_fss_content_delimited_seek_till_newline(buffer, location, found, delimits, eos_status, stop_status) \ while (buffer.string[location.start] != f_string_eol) { \ - ++location.start; \ + location.start++; \ if (location.start >= buffer.used) { \ f_status macro_allocation_status = f_none; \ f_string_length i = 0; \ diff --git a/level_1/fl_status/c/status.c b/level_1/fl_status/c/status.c index 5dc290f..7870e2c 100644 --- a/level_1/fl_status/c/status.c +++ b/level_1/fl_status/c/status.c @@ -267,6 +267,9 @@ extern "C" { case f_loop: *string = fl_status_string_loop; break; + case f_incomplete: + *string = fl_status_string_incomplete; + break; #endif // _di_fl_status_basic_ #ifdef _di_fl_status_invalid_ diff --git a/level_1/fl_status/c/status.h b/level_1/fl_status/c/status.h index 1cd11da..5bd8ff8 100644 --- a/level_1/fl_status/c/status.h +++ b/level_1/fl_status/c/status.h @@ -274,6 +274,9 @@ extern "C" { #define fl_status_string_loop "f_loop" #define fl_status_string_loop_length 7 + + #define fl_status_string_incomplete "f_incomplete" + #define fl_status_string_incomplete_length 13 #endif // _di_fl_status_basic_ #ifndef _di_fl_status_invalid_ diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index 69263b4..27ed63b 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -71,7 +71,7 @@ extern "C" { if (status == fl_fss_found_object) { found_data = f_true; - status = fl_fss_basic_content_read(buffer, input, &contents->array[contents->used]); + status = fl_fss_basic_content_read(buffer, input, &contents->array[contents->used]); break; } @@ -100,7 +100,7 @@ extern "C" { } 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 at least some valid object was found, then return f_none equivelents. if (objects->used > initial_used) { if (status == f_no_data_on_eos) return f_none_on_eos; if (status == f_no_data_on_stop) return f_none_on_stop; @@ -111,7 +111,7 @@ extern "C" { 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 + // 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) { 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++; @@ -127,9 +127,9 @@ extern "C" { objects->used++; contents->used++; - } while (f_true); + } while (input->start < f_string_max_size); - return f_unknown; + return f_overflow; } #endif // _di_fll_fss_basic_read_ diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index e45a551..c82d96f 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -51,7 +51,7 @@ extern "C" { * f_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. * f_reallocation_error (with error bit) on reallocation error. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_unknown (with error bit) if a (what should be) impossible execution point is reached. + * f_overflow (with error bit) if the maximimum buffer size is reached. */ #ifndef _di_fll_fss_basic_read_ extern f_return_status fll_fss_basic_read(f_string_dynamic *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 1575682..087cc05 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -127,9 +127,9 @@ extern "C" { objects->used++; contents->used++; - } while (f_true); + } while (input->start < f_string_max_size); - return f_status_is_error(f_unknown); + return f_status_is_error(f_overflow); } #endif // _di_fll_fss_basic_list_read_ diff --git a/level_2/fll_fss/c/fss_basic_list.h b/level_2/fll_fss/c/fss_basic_list.h index 55c97fb..3d42034 100644 --- a/level_2/fll_fss/c/fss_basic_list.h +++ b/level_2/fll_fss/c/fss_basic_list.h @@ -50,7 +50,7 @@ extern "C" { * f_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. * f_reallocation_error (with error bit) on reallocation error. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_unknown (with error bit) if a (what should be) impossible execution point is reached. + * f_overflow (with error bit) if the maximimum buffer size is reached. */ #ifndef _di_fll_fss_basic_list_read_ extern f_return_status fll_fss_basic_list_read(f_string_dynamic *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 55b32da..50f63da 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -127,9 +127,9 @@ extern "C" { objects->used++; contents->used++; - } while (f_true); + } while (input->start < f_string_max_size); - return f_status_is_error(f_unknown); + return f_status_is_error(f_overflow); } #endif // _di_fll_fss_extended_read_ diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index d434b3b..3000ba2 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -50,7 +50,7 @@ extern "C" { * f_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. * f_reallocation_error (with error bit) on reallocation error. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_unknown (with error bit) if a (what should be) impossible execution point is reached. + * f_overflow (with error bit) if the maximimum buffer size is reached. */ #ifndef _di_fll_fss_extended_read_ extern f_return_status fll_fss_extended_read(f_string_dynamic *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents); diff --git a/level_2/fll_fss/c/fss_extended_list.c b/level_2/fll_fss/c/fss_extended_list.c index d466e57..2bef881 100644 --- a/level_2/fll_fss/c/fss_extended_list.c +++ b/level_2/fll_fss/c/fss_extended_list.c @@ -127,9 +127,9 @@ extern "C" { objects->used++; contents->used++; - } while (f_true); + } while (input->start < f_string_max_size); - return f_status_is_error(f_unknown); + return f_status_is_error(f_overflow); } #endif // _di_fll_fss_extended_list_read_ diff --git a/level_2/fll_fss/c/fss_extended_list.h b/level_2/fll_fss/c/fss_extended_list.h index 3351a6c..0f33abb 100644 --- a/level_2/fll_fss/c/fss_extended_list.h +++ b/level_2/fll_fss/c/fss_extended_list.h @@ -50,7 +50,7 @@ extern "C" { * f_invalid_utf (with error bit) is returned on failure to read/process a UTF-8 character. * f_reallocation_error (with error bit) on reallocation error. * f_invalid_parameter (with error bit) if a parameter is invalid. - * f_unknown (with error bit) if a (what should be) impossible execution point is reached. + * f_overflow (with error bit) if the maximimum buffer size is reached. */ #ifndef _di_fll_fss_extended_list_read_ extern f_return_status fll_fss_extended_list_read(f_string_dynamic *buffer, f_string_location *input, f_fss_objects *objects, f_fss_content_nests *contents); diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 9d1040c..4ab170a 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -94,7 +94,7 @@ extern "C" { fl_macro_color_context_new(allocation_status, (*context)); if (f_status_is_error(allocation_status)) { - fprintf(f_standard_error, "Critical Error: unable to allocate memory.\n"); + fprintf(f_standard_error, "CRITICAL ERROR: Unable to allocate memory.\n"); return allocation_status; } @@ -111,16 +111,24 @@ extern "C" { // nothing can be 0 as that represents the program name, unless argv[] is improperly created } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context->error, context->reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context->error, context->reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_invalid_utf) { - fl_color_print_line(f_standard_error, context->error, context->reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling fl_console_parameter_process()."); + fl_color_print(f_standard_error, context->error, context->reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling "); + fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print_line(f_standard_error, context->error, context->reset, "."); } else if (status == f_invalid_parameter) { - fl_color_print_line(f_standard_error, context->error, context->reset, "INTERNAL ERROR: Invalid parameter when calling fl_console_parameter_process()."); + fl_color_print(f_standard_error, context->error, context->reset, "INTERNAL ERROR: Invalid parameter when calling "); + fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print_line(f_standard_error, context->error, context->reset, "."); } else { - fl_color_print_line(f_standard_error, context->error, context->reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_console_parameter_process().", status); + fl_color_print(f_standard_error, context->error, context->reset, "INTERNAL ERROR: An unhandled error ("); + fl_color_print(f_standard_error, context->notable, context->reset, "%u", status); + fl_color_print(f_standard_error, context->error, context->reset, ") has occured while calling "); + fl_color_print(f_standard_error, context->notable, context->reset, "fl_console_parameter_process()"); + fl_color_print_line(f_standard_error, context->error, context->reset, "."); } return f_status_set_error(status); diff --git a/level_2/fll_status/c/status.c b/level_2/fll_status/c/status.c index e6ef62a..e149080 100644 --- a/level_2/fll_status/c/status.c +++ b/level_2/fll_status/c/status.c @@ -445,6 +445,11 @@ extern "C" { *code = f_loop; return f_none; } + + if (fl_string_compare(string, fl_status_string_incomplete, length, fl_status_string_incomplete_length) == f_equal_to) { + *code = f_incomplete; + return f_none; + } #endif // _di_fll_status_basic_ #ifndef _di_fll_status_invalid_ diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 3131790..2283d2a 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -751,7 +751,7 @@ extern "C" { } if (error == f_out_of_memory) { - fl_color_print(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory, while trying to access file '"); + fl_color_print(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory, while trying to access file '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", file_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); return; diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index 937138c..eedc244 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -182,7 +182,7 @@ extern "C" { f_macro_string_dynamics_resize(status, parameters, 7); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -272,7 +272,7 @@ extern "C" { status = f_status_set_fine(status); if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_tool_iptables); @@ -322,7 +322,7 @@ extern "C" { status = f_status_set_fine(status); if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else if (status == f_no_data) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: could not find any network devices"); @@ -528,7 +528,7 @@ extern "C" { f_macro_string_dynamic_resize(status, file_path, network_path_length + data->devices.array[i].used + firewall_file_suffix_length + 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); firewall_delete_local_data(&local); firewall_delete_data(data); return status; diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 78f2fa0..2049883 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -601,10 +601,10 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const fl_color_print_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 (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } if (status != f_file_not_found) { @@ -643,10 +643,10 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: A read error occurred while accessing the file '%.*s'", file_path.used, file_path.string); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", status); } status = f_status_set_error(status); @@ -670,10 +670,10 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const // empty files are to be silently ignored } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_read() for the file '%.*s'", f_status_set_error(status), file_path.used, file_path.string); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_read() for the file '%.*s'", status, file_path.used, file_path.string); } status = f_status_set_error(status); @@ -706,7 +706,7 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const } if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); f_macro_string_dynamic_delete(status2, ip_list_action); } @@ -726,7 +726,7 @@ f_return_status firewall_perform_commands(const firewall_local_data local, const f_macro_string_dynamic_new(status, ip_argument, ip_length); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); break; } @@ -1117,7 +1117,7 @@ f_return_status firewall_create_custom_chains(firewall_reserved_chains *reserved fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", status); } f_macro_string_dynamics_delete(status2, arguments); @@ -1191,7 +1191,7 @@ f_return_status firewall_delete_chains(const firewall_data data) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", status); } return status; @@ -1249,7 +1249,7 @@ f_return_status firewall_delete_chains(const firewall_data data) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", status); } return status; @@ -1328,7 +1328,7 @@ f_return_status firewall_default_lock(const firewall_data data) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_execute_program()"); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", status); } return status; @@ -1353,7 +1353,7 @@ f_return_status firewall_buffer_rules(const f_string filename, const bool option fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); } else if (status != f_file_not_found && status != f_file_open_error && status != f_file_descriptor_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); } } else { if (status == f_invalid_parameter) { @@ -1369,7 +1369,7 @@ f_return_status firewall_buffer_rules(const f_string filename, const bool option fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'.", filename); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); } } @@ -1402,10 +1402,10 @@ f_return_status firewall_buffer_rules(const f_string filename, const bool option fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'.", filename); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", status); } return status; @@ -1428,10 +1428,10 @@ f_return_status firewall_buffer_rules(const f_string filename, const bool option fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: No relevant data was found within the file '%s'.", filename); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_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_status_set_error(status), filename); + fl_color_print_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'.", status, filename); } return status; @@ -1453,13 +1453,13 @@ f_return_status firewall_process_rules(f_string_location *input, firewall_local_ status = f_status_set_fine(status); if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_failure) { // the error message has already been displayed. } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", status); } f_macro_fss_objects_delete(status2, local->rule_objects); diff --git a/level_3/firewall/c/private-firewall.h b/level_3/firewall/c/private-firewall.h index 785b0d3..bc4b443 100644 --- a/level_3/firewall/c/private-firewall.h +++ b/level_3/firewall/c/private-firewall.h @@ -88,7 +88,7 @@ typedef struct { (structure.array[index].stop - structure.array[index].start) + 1 // TODO: temporarily added, convert this to a function below. -// TODO: also report: fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); +// TODO: also report: fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory"); #define firewall_macro_append_argument_to_arguments(status, arguments, argument) \ if (arguments.used >= arguments.size) { \ f_macro_string_dynamics_resize(status, arguments, arguments.used + firewall_default_allocation_step); \ 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 51370ea..0ff11b0 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 @@ -8,6 +8,8 @@ * This is the FSS Basic List Read program * This program utilizes the Featureless Linux Library. * This program processes files or other input in fss format and stores the results in the fss_basic_list_read_data. + * + * This processes in accordance to the FSS-0002 Basic List specification. */ #ifndef _fss_basic_list_read_h diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c index 1f41ac9..763f4c3 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.c @@ -54,7 +54,7 @@ extern "C" { fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error ("); @@ -75,7 +75,7 @@ extern "C" { macro_fss_basic_list_read_depths_new(status, (*depths), data.parameters[fss_basic_list_read_parameter_depth].locations.used); if (f_status_is_error(status)) { f_status status2 = f_none; - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); macro_fss_basic_list_read_depths_delete(status2, (*depths)); return f_status_set_error(f_invalid_parameter); @@ -189,7 +189,7 @@ extern "C" { macro_fss_basic_list_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -201,7 +201,7 @@ extern "C" { else if (data.parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) { macro_fss_basic_list_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -239,7 +239,7 @@ extern "C" { fl_color_print_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_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else if (status == f_incomplete_utf_on_stop) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); @@ -248,7 +248,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); } else { - fl_color_print_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_status_set_error(status), filename); + fl_color_print_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'", status, filename); } fss_basic_list_read_delete_data(data); diff --git a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h index bb37a47..0d7c72c 100644 --- a/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h +++ b/level_3/fss_basic_list_read/c/private-fss_basic_list_read.h @@ -29,8 +29,8 @@ extern "C" { #define fss_basic_list_read_depth_initialize \ { \ 0, \ - f_array_length_initialize, \ - f_array_length_initialize, \ + 0, \ + 0, \ } #endif // _di_fss_basic_list_read_depth_ 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 5f37256..5702e94 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 @@ -83,7 +83,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } f_status status2 = f_none; @@ -164,7 +164,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } fss_basic_list_write_delete_data(data); @@ -184,7 +184,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); } fss_basic_list_write_delete_data(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 4d3937f..136f770 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -23,7 +23,7 @@ extern "C" { fll_program_print_help_option(data.context, fss_basic_read_short_name, fss_basic_read_long_name, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select object with this name."); fll_program_print_help_option(data.context, fss_basic_read_short_object, fss_basic_read_long_object, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the object instead of the content."); fll_program_print_help_option(data.context, fss_basic_read_short_select, fss_basic_read_long_select, f_console_symbol_short_enable, f_console_symbol_long_enable, " Select sub-content at this index."); - fll_program_print_help_option(data.context, fss_basic_read_short_total, fss_basic_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of objects."); + fll_program_print_help_option(data.context, fss_basic_read_short_total, fss_basic_read_long_total, f_console_symbol_short_enable, f_console_symbol_long_enable, " Print the total number of lines."); fll_program_print_help_usage(data.context, fss_basic_read_name, "filename(s)"); @@ -75,10 +75,10 @@ extern "C" { printf("%c", f_string_eol); printf(" Specify both "); - fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_total); + fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_object); printf(" and the "); fl_color_print(f_standard_output, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_line); - printf(" parameters to get the total lines.%c", f_string_eol); + printf(" parameters to get the total objects.%c", f_string_eol); printf("%c", f_string_eol); @@ -132,8 +132,48 @@ extern "C" { fll_program_print_version(fss_basic_read_version); } else if (data->remaining.used > 0 || data->process_pipe) { + if (data->parameters[fss_basic_read_parameter_at].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_at); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' requires a positive number."); + + return f_status_set_error(f_invalid_parameter); + } + + if (data->parameters[fss_basic_read_parameter_depth].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_depth); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' requires a positive number."); + + return f_status_set_error(f_invalid_parameter); + } + + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_line); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' requires a positive number."); + + return f_status_set_error(f_invalid_parameter); + } + + if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_name); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' requires a string."); + + return f_status_set_error(f_invalid_parameter); + } + + if (data->parameters[fss_basic_read_parameter_select].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_select); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' requires a positive number."); + + return f_status_set_error(f_invalid_parameter); + } + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_found) { - if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_found) { + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: Cannot specify the '"); fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_object); fl_color_print(f_standard_error, data->context.error, data->context.reset, "' parameter with the '"); @@ -154,6 +194,18 @@ extern "C" { } } + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { + fl_color_print(f_standard_error, data->context.error, data->context.reset, "ERROR: Cannot specify the '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_line); + fl_color_print(f_standard_error, data->context.error, data->context.reset, "' parameter with the '"); + fl_color_print(f_standard_error, data->context.notable, data->context.reset, "--%s", fss_basic_read_long_total); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "' parameter."); + + return f_status_set_error(f_invalid_parameter); + } + } + fss_basic_read_depths depths = fss_basic_read_depths_initialize; f_status status2 = f_none; 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 dbd1a22..b3d6ca5 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.h +++ b/level_3/fss_basic_read/c/fss_basic_read.h @@ -8,6 +8,8 @@ * This is the FSS Basic Read program * This program utilizes the Featureless Linux Library. * This program processes files or other input in fss format and stores the results in the fss_basic_read_data. + * + * This processes in accordance to the FSS-0000 Basic specification. */ #ifndef _fss_basic_read_h diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.c b/level_3/fss_basic_read/c/private-fss_basic_read.c index f00a77b..a8c02c3 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.c +++ b/level_3/fss_basic_read/c/private-fss_basic_read.c @@ -54,7 +54,7 @@ extern "C" { fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error ("); @@ -75,33 +75,47 @@ extern "C" { fl_color_print_line(f_standard_error, context.error, context.reset, "."); } else if (status == f_invalid_number) { - fl_color_print(f_standard_error, context.error, context.reset, "ERROR: the argument '"); + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The argument '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", argument); fl_color_print(f_standard_error, context.error, context.reset, "' is not a valid number for the parameter '"); fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_underflow) { - fl_color_print(f_standard_error, context.error, context.reset, "ERROR: the argument '"); + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The argument '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", argument); fl_color_print(f_standard_error, context.error, context.reset, "' is too small for the parameter '"); fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_overflow) { - fl_color_print(f_standard_error, context.error, context.reset, "ERROR: the argument '"); + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The argument '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", argument); fl_color_print(f_standard_error, context.error, context.reset, "' is too large for the parameter '"); fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_negative_number) { - fl_color_print(f_standard_error, context.error, context.reset, "ERROR: the argument '"); + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The argument '"); fl_color_print(f_standard_error, context.notable, context.reset, "%s", argument); fl_color_print(f_standard_error, context.error, context.reset, "' is negative, which is not allowed for the parameter '"); fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } + else if (status == f_positive_number) { + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The argument '"); + fl_color_print(f_standard_error, context.notable, context.reset, "%s", argument); + fl_color_print(f_standard_error, context.error, context.reset, "' contains a '"); + fl_color_print(f_standard_error, context.notable, context.reset, "+"); + fl_color_print(f_standard_error, context.error, context.reset, "', which is not allowed for the parameter '"); + fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); + fl_color_print_line(f_standard_error, context.error, context.reset, "'."); + } + else if (status == f_no_data) { + fl_color_print(f_standard_error, context.error, context.reset, "ERROR: The parameter '"); + fl_color_print(f_standard_error, context.notable, context.reset, "--%s", parameter_name); + fl_color_print_line(f_standard_error, context.error, context.reset, "' must not be an empty string."); + } else { fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error ("); fl_color_print(f_standard_error, context.notable, context.reset, "%u", status); @@ -120,145 +134,60 @@ extern "C" { f_return_status fss_basic_read_main_preprocess_depth(const f_console_arguments arguments, const fss_basic_read_data data, fss_basic_read_depths *depths) { f_status status = f_none; - // pre-process the depth and depth-sensitive parameters. - if (data.parameters[fss_basic_read_parameter_depth].result == f_console_result_additional) { - macro_fss_basic_read_depths_new(status, (*depths), data.parameters[fss_basic_read_parameter_depth].locations.used); - if (f_status_is_error(status)) { - f_status status2 = f_none; - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); - - macro_fss_basic_read_depths_delete(status2, (*depths)); - return f_status_set_error(f_invalid_parameter); - } - - f_array_length depth_position = data.parameters[fss_basic_read_parameter_depth].additional.array[0]; - f_array_length at_index = 0; - f_array_length name_index = 0; + macro_fss_basic_read_depths_new(status, (*depths), 1); + if (f_status_is_error(status)) { + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); + return status; + } - depths->array[0].depth = (f_string_length) atoll(arguments.argv[depth_position]); - depths->array[0].parameter = 0; - depths->array[0].position = 0; - depths->used = 1; + depths->array[0].depth = 0; + depths->array[0].index_at = 0; + depths->array[0].index_name = 0; + depths->array[0].value_at = 0; + depths->array[0].value_name = f_string_eos; + depths->used = 1; - f_string_length depth_previous = depths->array[0].depth; - f_string_length depth_current = depths->array[0].depth; + // @todo: walk through all depth parameters and build the loop, get and validate all --at and --name parameters on a per depth basis. + if (data.parameters[fss_basic_read_parameter_depth].result == f_console_result_additional) { + f_array_length depth_position = data.parameters[fss_basic_read_parameter_depth].additional.array[data.parameters[fss_basic_read_parameter_depth].additional.used - 1]; - if (data.parameters[fss_basic_read_parameter_at].result == f_console_result_additional) { - for (; at_index < data.parameters[fss_basic_read_parameter_at].additional.used; at_index++) { - if (data.parameters[fss_basic_read_parameter_at].additional.array[at_index] > depth_position) { - if (data.parameters[fss_basic_read_parameter_depth].additional.used > 1) { - if (data.parameters[fss_basic_read_parameter_at].additional.array[at_index] > data.parameters[fss_basic_read_parameter_depth].additional.array[1]) { - break; - } - } - - depths->array[0].parameter = fss_basic_read_parameter_at; - } - } // for - } + status = fl_console_parameter_to_number_unsigned(arguments.argv[depth_position], &depths->array[0].depth); - if (data.parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { - for (; name_index < data.parameters[fss_basic_read_parameter_name].additional.used; name_index++) { - if (data.parameters[fss_basic_read_parameter_name].additional.array[name_index] > depth_position) { - if (data.parameters[fss_basic_read_parameter_depth].additional.used > 1) { - if (data.parameters[fss_basic_read_parameter_name].additional.array[name_index] > data.parameters[fss_basic_read_parameter_depth].additional.array[1]) { - break; - } - } - - if (depths->array[0].parameter == fss_basic_read_parameter_at) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: The '--%s' and '--%s' parameters cannot be specified at the same time (specified for depth '%llu').", fss_basic_read_long_at, fss_basic_read_long_name, depth_current); - return f_status_set_error(f_invalid_parameter); - } - - depths->array[0].parameter = fss_basic_read_parameter_name; - } - } // for + if (f_status_is_error(status)) { + fss_basic_read_print_number_argument_error(data.context, "fl_console_parameter_to_number_unsigned", fss_basic_read_long_depth, arguments.argv[depth_position], f_status_set_fine(status)); + return status; } - - for (f_array_length i = 1; i < data.parameters[fss_basic_read_parameter_depth].locations.used; i++) { - depth_position = data.parameters[fss_basic_read_parameter_depth].additional.array[i]; - depth_current = (f_string_length) atoll(arguments.argv[depth_position]); - - if (depth_current > depth_previous) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: The depth '%llu' cannot be specified before the depth '%llu'.", depth_previous, depth_current); - return f_status_set_error(f_invalid_parameter); - } - - if (depth_current == depth_previous) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: The depth '%llu' cannot be the same as the depth '%llu'.", depth_previous, depth_current); - return f_status_set_error(f_invalid_parameter); - } - - if (data.parameters[fss_basic_read_parameter_at].result == f_console_result_additional) { - for (; at_index < data.parameters[fss_basic_read_parameter_at].additional.used; at_index++) { - if (data.parameters[fss_basic_read_parameter_at].additional.array[at_index] > depth_position) { - if (data.parameters[fss_basic_read_parameter_depth].additional.used > 1) { - if (data.parameters[fss_basic_read_parameter_at].additional.array[at_index] > data.parameters[fss_basic_read_parameter_depth].additional.array[i+1]) { - break; - } - } - - depths->array[i].parameter = fss_basic_read_parameter_at; - depths->array[i].position = data.parameters[fss_basic_read_parameter_at].additional.array[i]; - } - } // for - } - - if (data.parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { - for (; name_index < data.parameters[fss_basic_read_parameter_name].additional.used; name_index++) { - if (data.parameters[fss_basic_read_parameter_name].additional.array[name_index] > depth_position) { - if (data.parameters[fss_basic_read_parameter_depth].additional.used > 1) { - if (data.parameters[fss_basic_read_parameter_name].additional.array[name_index] > data.parameters[fss_basic_read_parameter_depth].additional.array[i+1]) { - break; - } - } - - if (depths->array[i].parameter == fss_basic_read_parameter_at) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: The '--%s' and '--%s' parameters cannot be specified at the same time (specified for depth '%llu').", fss_basic_read_long_at, fss_basic_read_long_name, depth_current); - return f_status_set_error(f_invalid_parameter); - } - - depths->array[i].parameter = fss_basic_read_parameter_name; - depths->array[i].position = data.parameters[fss_basic_read_parameter_name].additional.array[i]; - } - } // for - } - - depths->array[i].depth = (f_string_length) atoll(arguments.argv[depth_position]); - depths->used++; - } // for } - // when no depth parameter is specified, provide a implicit depth of 0 when depth-sensitive parameters are in use. else { + // @todo: walk though each --at and --name parameter, validating them (consider warning for multiple values because only the last one will be used). if (data.parameters[fss_basic_read_parameter_at].result == f_console_result_additional) { - if (data.parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: The '%s' and '%s' parameters must not be specified at the same time.", fss_basic_read_long_name, fss_basic_read_long_object); - return f_status_set_error(f_invalid_parameter); - } + depths->array[0].index_at = data.parameters[fss_basic_read_parameter_at].additional.array[data.parameters[fss_basic_read_parameter_at].additional.used - 1]; + + status = fl_console_parameter_to_number_unsigned(arguments.argv[depths->array[0].index_at], &depths->array[0].value_at); - macro_fss_basic_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); - return f_status_set_error(f_invalid_parameter); + fss_basic_read_print_number_argument_error(data.context, "fl_console_parameter_to_number_unsigned", fss_basic_read_long_at, arguments.argv[depths->array[0].index_at], f_status_set_fine(status)); + return status; } - - depths->array[0].depth = (f_string_length) atoll(arguments.argv[data.parameters[fss_basic_read_parameter_depth].additional.array[0]]); - depths->array[0].parameter = fss_basic_read_parameter_at; - depths->array[0].position = 0; - depths->used = 1; } - else if (data.parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { + + if (data.parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { macro_fss_basic_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); - return f_status_set_error(f_invalid_parameter); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); + return status; } - depths->array[0].depth = (f_string_length) atoll(arguments.argv[data.parameters[fss_basic_read_parameter_depth].additional.array[0]]); - depths->array[0].parameter = fss_basic_read_parameter_name; - depths->array[0].position = 0; - depths->used = 1; + depths->array[0].index_name = data.parameters[fss_basic_read_parameter_name].additional.array[data.parameters[fss_basic_read_parameter_name].additional.used - 1]; + depths->array[0].value_name = arguments.argv[depths->array[0].index_name]; + + if (depths->array[0].value_name[0] == '\0') { + fl_color_print(f_standard_error, data.context.error, data.context.reset, "ERROR: The '"); + fl_color_print(f_standard_error, data.context.notable, data.context.reset, "--%s", fss_basic_read_long_name); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "' must not be an empty string."); + + return f_status_set_error(f_invalid_parameter); + } } } @@ -286,7 +215,7 @@ extern "C" { fl_color_print_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_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else if (status == f_incomplete_utf_on_stop) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); @@ -295,7 +224,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); } else { - fl_color_print_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_status_set_error(status), filename); + fl_color_print_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'", status, filename); } return f_status_set_error(status); @@ -310,201 +239,176 @@ extern "C" { } } - // depth is always 0 in this standard, so when specifying --total with --object, just print the total of all. - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { - fprintf(f_standard_output, "%llu%c", data->objects.used, f_string_eol); - return f_none; - } - } - f_string_length select = 0; + if (data->parameters[fss_basic_read_parameter_select].result == f_console_result_additional) { - status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[fss_basic_read_parameter_select].additional.array[0]], &select); + status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[fss_basic_read_parameter_select].additional.array[data->parameters[fss_basic_read_parameter_select].additional.used - 1]], &select); if (f_status_is_error(status)) { fss_basic_read_print_number_argument_error(data->context, "fl_console_parameter_to_number_unsigned", fss_basic_read_long_select, arguments.argv[data->parameters[fss_basic_read_parameter_select].additional.array[0]], f_status_set_fine(status)); return status; } - // this standard does not support multiple content groups, so a select value of anything other than 0 should return nothing. + // this standard does not support multiple content groups. if (select > 0) { return f_none; } } - // now that the file has been read, process the objects and contents. - if (depths.used > 0 && depths.array[0].parameter == fss_basic_read_parameter_name) { - /* - // @todo: this if-block is not updated. - // @todo: printing conditions need to handle --line as well as --relative. - // @todo: when --total is specified, process it here (and --relative will matter). - f_string_length total = 0; + f_string_length line = 0; + + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { + status = fl_console_parameter_to_number_unsigned(arguments.argv[data->parameters[fss_basic_read_parameter_line].additional.array[data->parameters[fss_basic_read_parameter_line].additional.used - 1]], &line); + + if (f_status_is_error(status)) { + fss_basic_read_print_number_argument_error(data->context, "fl_console_parameter_to_number_unsigned", fss_basic_read_long_line, arguments.argv[data->parameters[fss_basic_read_parameter_line].additional.array[0]], f_status_set_fine(status)); + return status; + } + } + + bool names[data->objects.used]; + + if (depths.array[0].index_name > 0) { + memset(names, 0, sizeof(bool) * data->objects.used); + + f_string_length argv_length = strlen(depths.array[0].value_name); f_string_length name_length = 0; - f_string_length argv_length = 0; - f_string_length found = 0; - if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { - argv_length = strlen(arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]]); + for (f_string_length i = 0; i < data->objects.used; i++) { + name_length = data->objects.array[i].stop - data->objects.array[i].start + 1; + + if (name_length == argv_length) { + if (fl_string_compare(data->buffer.string + data->objects.array[i].start, depths.array[0].value_name, name_length, argv_length) == f_equal_to) { + names[i] = 1; + } + } + } // for + } + else { + memset(names, 1, sizeof(bool) * data->objects.used); + } + + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_found) { + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { + if (depths.array[0].index_at > 0) { + if (depths.array[0].value_at < data->objects.used && names[depths.array[0].value_at]) { + fprintf(f_standard_output, "1%c", f_string_eol); + } + else { + fprintf(f_standard_output, "0%c", f_string_eol); + } + } + else if (depths.array[0].index_name > 0) { + f_string_length total = 0; - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { for (f_string_length i = 0; i < data->objects.used; i++) { - name_length = data->objects.array[i].stop - data->objects.array[i].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->objects.array[i].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - - if (data->parameters[fss_basic_read_parameter_at].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_at].result == f_console_result_additional && found == target)) { - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { - total++; - } - else { - if (data->contents.array[i].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[i].array[0]); - fprintf(f_standard_output, "%c", f_string_eol); - } - else { - // for all objects with no data, print a newline. - fprintf(f_standard_output, "%c", f_string_eol); - } - } - } - - if (data->parameters[fss_basic_read_parameter_at].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } + if (names[i] == 0) continue; + + total++; } // for - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_at].result == f_console_result_none) { - fprintf(f_standard_output, f_string_length_printf "%s%c", total, f_string_eol); - } + fprintf(f_standard_output, "%llu%c", total, f_string_eol); } 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 (f_string_length i = 0; i < data->contents.used; i++) { - if (data->contents.array[i].used > 0) { - name_length = data->contents.array[i].array[0].stop - data->contents.array[i].array[0].start + 1; - - if (name_length == argv_length) { - if (fl_string_compare(data->buffer.string + data->contents.array[i].array[0].start, arguments.argv[data->parameters[fss_basic_read_parameter_name].additional.array[0]], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_basic_read_parameter_at].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_at].result == f_console_result_additional && found == target)) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); - fprintf(f_standard_output, "%c", f_string_eol); - } - - if (data->parameters[fss_basic_read_parameter_at].result == f_console_result_additional) { - if (found == target) { - break; - } - else { - found++; - } - } - } - } - } - } // for + fprintf(f_standard_output, "%llu%c", data->objects.used, f_string_eol); } + + return f_none; } -*/ + + if (depths.array[0].index_at > 0) { + if (depths.array[0].value_at < data->objects.used && names[depths.array[0].value_at]) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[depths.array[0].value_at]); + fprintf(f_standard_output, "%c", f_string_eol); + } + + return f_none; + } + + for (f_string_length i = 0; i < data->objects.used; i++) { + if (names[i] == 0) continue; + + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + fprintf(f_standard_output, "%c", f_string_eol); + } // for + return f_none; } - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { - if (depths.used > 0 && depths.array[0].parameter == fss_basic_read_parameter_at) { - f_string_length target = (f_string_length) atoll(arguments.argv[depths.array[0].position]); - - if (target >= data->objects.used) { - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_additional) { + if (depths.array[0].index_at > 0) { + if (names[depths.array[0].value_at]) { + if (depths.array[0].value_at >= data->objects.used) { + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { fprintf(f_standard_output, "0%c", f_string_eol); } return f_none; } - - if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_additional) { - f_string_length total = 0; - - for (f_string_length i = data->contents.array[target].array[0].start; i < data->contents.array[target].array[0].stop; i++) { - if (data->buffer.string[i] == f_string_eol) { - total++; - } - } // for - - fprintf(f_standard_output, "%llu%c", total, f_string_eol); + else if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { + if (data->contents.array[depths.array[0].value_at].used == 0) { + fprintf(f_standard_output, "0%c", f_string_eol); } else { - f_string_length line = (f_string_length) atoll(arguments.argv[data->parameters[fss_basic_read_parameter_line].additional.array[0]]); - f_string_length total = 0; - f_string_location line_position = f_string_location_initialize; - - line_position.start = data->contents.array[target].array[0].start; - for (f_string_length i = line_position.start; i <= data->contents.array[target].array[0].stop; i++) { - if (data->buffer.string[i] == f_string_eol) { - total++; - - if (total == line) { - if (i != line_position.start) { - line_position.stop = i - 1; - - f_print_string_dynamic_partial(f_standard_output, data->buffer, line_position); - } - - fprintf(f_standard_output, "%c", f_string_eol); - break; - } - } - } // for + fprintf(f_standard_output, "1%c", f_string_eol); } return f_none; } - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[target].array[0]); + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { + if (data->contents.array[depths.array[0].value_at].used > 0 && line == 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[depths.array[0].value_at].array[0]); + fprintf(f_standard_output, "%c", f_string_eol); + } - // newline is printed even when there is no content for this object. - fprintf(f_standard_output, "%c", f_string_eol); + return f_none; + } - return f_none; + if (data->contents.array[depths.array[0].value_at].used > 0) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[depths.array[0].value_at].array[0]); + fprintf(f_standard_output, "%c", f_string_eol); + } } + return f_none; + } + + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { + f_string_length total = 0; + for (f_string_length i = 0; i < data->objects.used; i++) { - if (data->contents.array[i].used > 0) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[i].array[0]); - } + if (names[i] == 0 || data->contents.array[i].used == 0) continue; - // newline is printed even when there is no content for this object. - fprintf(f_standard_output, "%c", f_string_eol); + total++; } // for + fprintf(f_standard_output, "%llu%c", total, f_string_eol); return f_none; } - if (depths.used > 0 && depths.array[0].parameter == fss_basic_read_parameter_at) { - f_string_length target = (f_string_length) atoll(arguments.argv[depths.array[0].position]); + if (data->parameters[fss_basic_read_parameter_line].result == f_console_result_additional) { + f_string_length line_current = 0; - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[target]); + for (f_string_length i = 0; i < data->contents.used; i++) { + if (names[i] == 0 || data->contents.array[i].used == 0) continue; - // newline is printed even when there is no content for this object. - fprintf(f_standard_output, "%c", f_string_eol); + if (line_current == line) { + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[i].array[0]); + fprintf(f_standard_output, "%c", f_string_eol); + + break; + } + + line_current++; + } // for return f_none; } - // @todo: when --total is specified, process it here (and --relative will matter) for standards that support nesting (also handle other nesting state changes here). - for (f_string_length i = 0; i < data->objects.used; i++) { - f_print_string_dynamic_partial(f_standard_output, data->buffer, data->objects.array[i]); + for (f_string_length i = 0; i < data->contents.used; i++) { + if (!names[i] || data->contents.array[i].used == 0) continue; - // newline is printed for all objects. + f_print_string_dynamic_partial(f_standard_output, data->buffer, data->contents.array[i].array[0]); fprintf(f_standard_output, "%c", f_string_eol); } // for diff --git a/level_3/fss_basic_read/c/private-fss_basic_read.h b/level_3/fss_basic_read/c/private-fss_basic_read.h index 7329c9f..1a880fe 100644 --- a/level_3/fss_basic_read/c/private-fss_basic_read.h +++ b/level_3/fss_basic_read/c/private-fss_basic_read.h @@ -23,15 +23,20 @@ extern "C" { typedef struct { f_string_length depth; - f_array_length parameter; - f_array_length position; + f_array_length index_at; + f_array_length index_name; + + f_number_unsigned value_at; + f_string value_name; } fss_basic_read_depth; #define fss_basic_read_depth_initialize \ { \ 0, \ - f_array_length_initialize, \ - f_array_length_initialize, \ + 0, \ + 0, \ + 0, \ + f_string_initialize, \ } #endif // _di_fss_basic_read_depth_ @@ -54,13 +59,13 @@ extern "C" { #define macro_fss_basic_read_depths_clear(depths) f_macro_memory_structure_clear(depths) - #define macro_fss_basic_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_basic_read_depths, length) + #define macro_fss_basic_read_depths_new(status, depths, length) f_macro_memory_structure_new(status, depths, fss_basic_read_depth, length) - #define macro_fss_basic_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_basic_read_depths) - #define macro_fss_basic_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_basic_read_depths) + #define macro_fss_basic_read_depths_delete(status, depths) f_macro_memory_structure_delete(status, depths, fss_basic_read_depth) + #define macro_fss_basic_read_depths_destroy(status, depths) f_macro_memory_structure_destroy(status, depths, fss_basic_read_depth) - #define macro_fss_basic_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_basic_read_depths, new_length) - #define macro_fss_basic_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_basic_read_depths, new_length) + #define macro_fss_basic_read_depths_resize(status, depths, new_length) f_macro_memory_structure_resize(status, depths, fss_basic_read_depth, new_length) + #define macro_fss_basic_read_depths_adjust(status, depths, new_length) f_macro_memory_structure_adjust(status, depths, fss_basic_read_depth, new_length) #endif // _di_fss_basic_read_depths_ /** @@ -100,10 +105,12 @@ extern "C" { /** * Pre-process the parameters, parsing out and handling the depth and depth related parameters. * + * Will handle depth-sensitive parameter conflicts, such as --name being used with --at (which is not allowed). + * * @param arguments * The console arguments to pre-process. * @param data - * The Program specific data. + * The program specific data. * @param depths * This stores the pre-processed depth parameters. * @@ -115,8 +122,22 @@ extern "C" { extern f_return_status fss_basic_read_main_preprocess_depth(const f_console_arguments arguments, const fss_basic_read_data data, fss_basic_read_depths *depths) f_gcc_attribute_visibility_internal; #endif // _di_fss_basic_read_main_preprocess_depth_ +/** + * Process a given file. + * + * @param arguments + * The console arguments passed to the program. + * @param data + * The program specific data. + * @param file_name + * The name of the file being processed. + * @param depths + * The processed depth parameters. + * + * @see fss_basic_read_main_preprocess_depth() + */ #ifndef _di_fss_basic_read_main_process_file_ - extern f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string filename, const fss_basic_read_depths depths) f_gcc_attribute_visibility_internal; + extern f_return_status fss_basic_read_main_process_file(const f_console_arguments arguments, fss_basic_read_data *data, const f_string file_name, const fss_basic_read_depths depths) f_gcc_attribute_visibility_internal; #endif // _di_fss_basic_read_main_process_file_ #ifdef __cplusplus 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 b4d31a5..47d1d5e 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -83,7 +83,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } f_status status2 = f_none; @@ -164,7 +164,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } fss_basic_write_delete_data(data); @@ -184,7 +184,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); } fss_basic_write_delete_data(data); diff --git a/level_3/fss_extended_list_read/c/fss_extended_list_read.h b/level_3/fss_extended_list_read/c/fss_extended_list_read.h index d45c25c..9e58829 100644 --- a/level_3/fss_extended_list_read/c/fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/fss_extended_list_read.h @@ -8,6 +8,8 @@ * This is the FSS Basic List Read program * This program utilizes the Featureless Linux Library. * This program processes files or other input in fss format and stores the results in the fss_extended_list_read_data. + * + * This processes in accordance to the FSS-0003 Extended List specification. */ #ifndef _fss_extended_list_read_h diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c index 5b35bd6..877c721 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.c @@ -54,7 +54,7 @@ extern "C" { fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error ("); @@ -75,7 +75,7 @@ extern "C" { macro_fss_extended_list_read_depths_new(status, (*depths), data.parameters[fss_extended_list_read_parameter_depth].locations.used); if (f_status_is_error(status)) { f_status status2 = f_none; - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); macro_fss_extended_list_read_depths_delete(status2, (*depths)); return f_status_set_error(f_invalid_parameter); @@ -189,7 +189,7 @@ extern "C" { macro_fss_extended_list_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -201,7 +201,7 @@ extern "C" { else if (data.parameters[fss_extended_list_read_parameter_name].result == f_console_result_additional) { macro_fss_extended_list_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -239,7 +239,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_list_read() for the file '%s'", filename); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else if (status == f_incomplete_utf_on_stop) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); @@ -248,7 +248,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_list_read() for the file '%s'", f_status_set_error(status), filename); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_list_read() for the file '%s'", status, filename); } fss_extended_list_read_delete_data(data); diff --git a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h index 36f911f..5aac844 100644 --- a/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h +++ b/level_3/fss_extended_list_read/c/private-fss_extended_list_read.h @@ -29,8 +29,8 @@ extern "C" { #define fss_extended_list_read_depth_initialize \ { \ 0, \ - f_array_length_initialize, \ - f_array_length_initialize, \ + 0, \ + 0, \ } #endif // _di_fss_extended_list_read_depth_ 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 87e1010..504aa96 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.h +++ b/level_3/fss_extended_read/c/fss_extended_read.h @@ -8,6 +8,8 @@ * This is the FSS Basic Read program * This program utilizes the Featureless Linux Library. * This program processes files or other input in fss format and stores the results in the fss_extended_read_data. + * + * This processes in accordance to the FSS-0001 Extended specification. */ #ifndef _fss_extended_read_h diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.c b/level_3/fss_extended_read/c/private-fss_extended_read.c index b1243d1..69429f2 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.c +++ b/level_3/fss_extended_read/c/private-fss_extended_read.c @@ -54,7 +54,7 @@ extern "C" { fl_color_print_line(f_standard_error, context.error, context.reset, "'."); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { fl_color_print(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error ("); @@ -75,7 +75,7 @@ extern "C" { macro_fss_extended_read_depths_new(status, (*depths), data.parameters[fss_extended_read_parameter_depth].locations.used); if (f_status_is_error(status)) { f_status status2 = f_none; - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); macro_fss_extended_read_depths_delete(status2, (*depths)); return f_status_set_error(f_invalid_parameter); @@ -189,7 +189,7 @@ extern "C" { macro_fss_extended_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -201,7 +201,7 @@ extern "C" { else if (data.parameters[fss_extended_read_parameter_name].result == f_console_result_additional) { macro_fss_extended_read_depths_new(status, (*depths), 1); if (f_status_is_error(status)) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); return f_status_set_error(f_invalid_parameter); } @@ -239,7 +239,7 @@ extern "C" { fl_color_print_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 (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory"); } else if (status == f_incomplete_utf_on_stop) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at stop position (at %d).", input.start); @@ -248,7 +248,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: error occured on invalid UTF-8 character at end of string (at %d).", input.start); } else { - fl_color_print_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_status_set_error(status), filename); + fl_color_print_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'", status, filename); } fss_extended_read_delete_data(data); diff --git a/level_3/fss_extended_read/c/private-fss_extended_read.h b/level_3/fss_extended_read/c/private-fss_extended_read.h index 4eb77e9..5535320 100644 --- a/level_3/fss_extended_read/c/private-fss_extended_read.h +++ b/level_3/fss_extended_read/c/private-fss_extended_read.h @@ -29,8 +29,8 @@ extern "C" { #define fss_extended_read_depth_initialize \ { \ 0, \ - f_array_length_initialize, \ - f_array_length_initialize, \ + 0, \ + 0, \ } #endif // _di_fss_extended_read_depth_ 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 3b19fcd..e2db381 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -56,7 +56,7 @@ extern "C" { // nothing can be 0 as that represents the program name, unless arguments.argv[] is improperly created } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_invalid_utf) { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ENCODING ERROR: Invalid UTF-8 character in parameter when calling fl_console_parameter_process()."); @@ -65,7 +65,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_console_parameter_process()."); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_console_parameter_process().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_console_parameter_process().", status); } fss_extended_write_delete_data(data); @@ -110,7 +110,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } f_status status2 = f_none; @@ -229,7 +229,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); } fss_extended_write_delete_data(data); @@ -249,7 +249,7 @@ extern "C" { fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", arguments.argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]); } else { - fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); } fss_extended_write_delete_data(data); diff --git a/level_3/init/c/private-init.c b/level_3/init/c/private-init.c index 81a5d8a..0ec1556 100644 --- a/level_3/init/c/private-init.c +++ b/level_3/init/c/private-init.c @@ -19,7 +19,7 @@ if (status == f_invalid_parameter) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); } else if (status != f_file_not_found && status != f_file_open_error && status != f_file_descriptor_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); } } else { if (status == f_invalid_parameter) { @@ -31,7 +31,7 @@ } else if (status == f_file_descriptor_error) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: File descriptor error while trying to open the file '%s'.", filename); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); } } @@ -59,9 +59,9 @@ } else if (status == f_file_read_error) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: A read error occurred while accessing the file '%s'.", filename); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", status); } return f_status_set_error(status); @@ -81,9 +81,9 @@ } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: No relevant data was found within the file '%s'.", filename); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_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_status_set_error(status), filename); + fl_color_print_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'.", status, filename); } return f_status_set_error(status); @@ -108,11 +108,11 @@ status = f_status_set_fine(status); if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_failure) { // the error message has already been displayed. } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", status); } f_macro_fss_objects_delete(status2, local->rule_objects); @@ -500,9 +500,9 @@ } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "ERROR: No relevant data was found within the file '%s'.", init_rule_core_file); } else if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_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_status_set_error(status), init_rule_core_file); + fl_color_print_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'.", status, init_rule_core_file); } f_macro_string_dynamic_delete(buffer); @@ -527,10 +527,10 @@ if (f_status_is_error(status_process)) { if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling init_load_main_rule().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling init_load_main_rule().", status); } // @todo: init_delete_data((*data)); @@ -554,11 +554,11 @@ status = f_status_set_fine(status); if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, data.context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, data.context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else if (status == f_failure) { // the error message has already been displayed. } else { - fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", status); } f_macro_fss_objects_delete(status2, (*rule_objects)); @@ -568,10 +568,10 @@ } else { if (status == f_allocation_error || status == f_reallocation_error) { - fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: unable to allocate memory."); + fl_color_print_line(f_standard_error, context.error, context.reset, "CRITICAL ERROR: Unable to allocate memory."); } else { - fl_color_print_line(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling init_load_main_rule().", f_status_set_error(status)); + fl_color_print_line(f_standard_error, context.error, context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling init_load_main_rule().", status); } } diff --git a/level_3/init/c/private-init.h b/level_3/init/c/private-init.h index f500e62..1115306 100644 --- a/level_3/init/c/private-init.h +++ b/level_3/init/c/private-init.h @@ -110,7 +110,7 @@ extern "C" { status = f_none; \ if (new_length < rules.size) { \ f_string_length i = rules.size - new_length; \ - for (; i < rules.size; ++i) { \ + for (; i < rules.size; i++) { \ delete_init_rule(status, rules.array[i]); \ if (status != f_none) break; \ } \ @@ -119,7 +119,7 @@ extern "C" { if (status == f_none) { \ if (new_length > rules.size) { \ f_string_length i = rules.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&rules.array[i], 0, sizeof(f_string)); \ } \ } \ @@ -131,7 +131,7 @@ extern "C" { status = f_none; \ if (new_length < rules.size) { \ f_string_length i = rules.size - new_length; \ - for (; i < rules.size; ++i) { \ + for (; i < rules.size; i++) { \ destroy_init_rule(status, rules.array[i]); \ if (status != f_none) break; \ } \ @@ -140,7 +140,7 @@ extern "C" { if (status == f_none) { \ if (new_length > rules.size) { \ f_string_length i = rules.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&rules.array[i], 0, sizeof(init_rule)); \ } \ } \ @@ -210,7 +210,7 @@ extern "C" { status = f_none; \ if (new_length < categorys.size) { \ f_string_length i = categorys.size - new_length; \ - for (; i < categorys.size; ++i) { \ + for (; i < categorys.size; i++) { \ delete_init_category(status, categorys.array[i]); \ if (status != f_none) break; \ } \ @@ -219,7 +219,7 @@ extern "C" { if (status == f_none) { \ if (new_length > categorys.size) { \ f_string_length i = categorys.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&categorys.array[i], 0, sizeof(f_string)); \ } \ } \ @@ -231,7 +231,7 @@ extern "C" { status = f_none; \ if (new_length < categorys.size) { \ f_string_length i = categorys.size - new_length; \ - for (; i < categorys.size; ++i) { \ + for (; i < categorys.size; i++) { \ destroy_init_category(status, categorys.array[i]); \ if (status != f_none) break; \ } \ @@ -240,7 +240,7 @@ extern "C" { if (status == f_none) { \ if (new_length > categorys.size) { \ f_string_length i = categorys.size; \ - for (; i < new_length; ++i) { \ + for (; i < new_length; i++) { \ memset(&categorys.array[i], 0, sizeof(init_category)); \ } \ } \ -- 1.8.3.1