From 3546b5998806877a331ccc8e5da5fa05165c9896 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 8 Jun 2012 23:19:00 -0500 Subject: [PATCH] Update: redesign error codes This is a major rewrite of the error code system. Previously, the error system did the following: - used an unsigned short data type - allowed for all 16 bits to be used - because it was unsigned short, different architectures might have different size. - it is rather inefficient and ugly to check for errors when there may be as many as 30 different error codes to compare against. The new error system does the following: - enforce exactly 16-bit unsigned integer by using uint16_t. - reserves the first two high order bits in the following manner: - bit 1 = error bit (1000 0000 0000 0000) - bit 2 = warning bit (0100 0000 0000 0000) - (note setting both bit 1 and bit 2 is unsupported) - provide a series of macros to quickly detect and manage the new bits - limits the total available number of error codes to 14-bits instead of 16-bits The advantage of the new system is that what the status code is can be detected in one or two conditionals (using bitwise operations). This should speed up performance and make the code easier to read. --- level_0/f_console/c/console.c | 2 +- level_0/f_conversion/c/conversion.c | 28 +-- level_0/f_conversion/c/conversion.h | 2 +- level_0/f_errors/c/errors.h | 21 ++ level_0/f_file/c/file.c | 56 +++--- level_0/f_file/c/file.h | 2 +- level_0/f_memory/c/memory.c | 34 ++-- level_0/f_memory/c/memory.h | 2 +- level_0/f_output/c/output.c | 16 +- level_0/f_output/c/output.h | 2 +- level_0/f_pipe/c/pipe.c | 2 +- level_0/f_pipe/c/pipe.h | 2 +- level_0/f_serialized/c/serialized.h | 2 +- level_0/f_types/c/types.h | 13 +- level_1/fl_colors/c/colors.c | 22 +- level_1/fl_console/c/console.c | 42 ++-- level_1/fl_console/c/console.h | 1 - level_1/fl_directory/c/directory.c | 18 +- level_1/fl_directory/c/directory.h | 2 +- level_1/fl_errors/c/errors.c | 16 +- level_1/fl_errors/c/errors.h | 10 +- level_1/fl_file/c/file.c | 48 ++--- level_1/fl_fss/c/fss.c | 28 +-- level_1/fl_fss/c/fss.h | 4 +- level_1/fl_fss/c/fss_basic.c | 57 +++--- level_1/fl_fss/c/fss_basic.h | 4 +- level_1/fl_fss/c/fss_basic_list.c | 46 ++--- level_1/fl_fss/c/fss_basic_list.h | 4 +- level_1/fl_fss/c/fss_extended.c | 88 ++++---- level_1/fl_fss/c/fss_extended.h | 4 +- level_1/fl_fss/c/fss_macro.h | 2 +- level_1/fl_serialized/c/serialized.c | 14 +- level_1/fl_serialized/c/serialized.h | 2 +- level_1/fl_strings/c/strings.c | 70 +++---- level_1/fl_strings/c/strings.h | 2 +- level_2/fll_colors/c/colors.c | 26 +-- level_2/fll_colors/c/colors.h | 48 ++--- level_2/fll_execute/c/execute.c | 26 +-- level_2/fll_execute/c/execute.h | 2 +- level_2/fll_fss/c/fss_basic.c | 20 +- level_2/fll_fss/c/fss_basic.h | 4 +- level_2/fll_fss/c/fss_basic_list.c | 22 +- level_2/fll_fss/c/fss_basic_list.h | 4 +- level_2/fll_fss/c/fss_errors.c | 14 +- level_2/fll_fss/c/fss_errors.h | 12 +- level_2/fll_fss/c/fss_extended.c | 18 +- level_2/fll_fss/c/fss_extended.h | 4 +- level_3/firewall/c/firewall.c | 104 +++++----- level_3/firewall/c/private-firewall.c | 221 ++++++++++++--------- .../fss_basic_list_read/c/fss_basic_list_read.c | 94 ++++----- .../fss_basic_list_write/c/fss_basic_list_write.c | 68 ++++--- level_3/fss_basic_read/c/fss_basic_read.c | 96 ++++----- level_3/fss_basic_write/c/fss_basic_write.c | 66 +++--- level_3/fss_extended_read/c/fss_extended_read.c | 103 +++++----- level_3/fss_extended_write/c/fss_extended_write.c | 70 ++++--- level_3/fss_return_code/c/fss_return_code.c | 72 +++++-- level_3/fss_return_code/c/fss_return_code.h | 14 +- level_3/return_code/c/return_code.c | 72 +++++-- level_3/return_code/c/return_code.h | 14 +- 59 files changed, 1020 insertions(+), 842 deletions(-) diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index 52eb9a0..5f59c27 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -13,7 +13,7 @@ extern "C"{ #ifndef _di_f_console_identify_ f_return_status f_console_identify(const f_string input, f_console_id *result) { #ifndef _di_level_0_parameter_checking_ - if (result == f_null) return f_invalid_parameter; + if (result == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ const f_string_length length = strnlen(input, 4); diff --git a/level_0/f_conversion/c/conversion.c b/level_0/f_conversion/c/conversion.c index 869e257..ce40dba 100644 --- a/level_0/f_conversion/c/conversion.c +++ b/level_0/f_conversion/c/conversion.c @@ -69,7 +69,7 @@ extern "C"{ #ifndef _di_f_character_to_digit_ f_return_status f_character_to_digit(const f_autochar character, f_u_long *digit) { #ifndef _di_level_0_parameter_checking_ - if (digit == f_null) return f_invalid_parameter; + if (digit == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ switch (character) { @@ -94,7 +94,7 @@ extern "C"{ #ifndef _di_f_character_to_hexdigit_ f_return_status f_character_to_hexdigit(const f_autochar character, f_u_long *digit) { #ifndef _di_level_0_parameter_checking_ - if (digit == f_null) return f_invalid_parameter; + if (digit == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ switch (character) { @@ -131,15 +131,15 @@ extern "C"{ #ifndef _di_f_string_to_digit_ f_return_status f_string_to_digit(const f_string string, f_u_long *digit, const f_string_location location) { #ifndef _di_level_0_parameter_checking_ - if (digit == f_null) return f_invalid_parameter; - if (location.start < 0) return f_invalid_parameter; - if (location.stop <= location.start) return f_invalid_parameter; - if (string == 0) return f_invalid_parameter; + if (digit == f_null) return f_error_set_error(f_invalid_parameter); + if (location.start < 0) return f_error_set_error(f_invalid_parameter); + if (location.stop <= location.start) return f_error_set_error(f_invalid_parameter); + if (string == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ f_string_length current_location = location.start; - f_u_long scale = 0; - f_u_long temp_digit = 0; + f_u_long scale = 0; + f_u_long temp_digit = 0; while (current_location < location.stop) { if (f_character_to_digit(string[current_location], &temp_digit) == f_none) { @@ -166,15 +166,15 @@ extern "C"{ #ifndef _di_f_string_to_hexdigit_ f_return_status f_string_to_hexdigit(const f_string string, f_u_long *digit, const f_string_location location) { #ifndef _di_level_0_parameter_checking_ - if (digit == f_null) return f_invalid_parameter; - if (location.start < 0) return f_invalid_parameter; - if (location.stop <= location.start) return f_invalid_parameter; - if (string == 0) return f_invalid_parameter; + if (digit == f_null) return f_error_set_error(f_invalid_parameter); + if (location.start < 0) return f_error_set_error(f_invalid_parameter); + if (location.stop <= location.start) return f_error_set_error(f_invalid_parameter); + if (string == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ f_string_length current_location = location.start; - f_u_long scale = 0; - f_u_long temp_digit = 0; + f_u_long scale = 0; + f_u_long temp_digit = 0; while (current_location < location.stop) { if (f_character_to_hexdigit(string[current_location], &temp_digit) == f_none) { diff --git a/level_0/f_conversion/c/conversion.h b/level_0/f_conversion/c/conversion.h index 005a8f1..2fa4e39 100644 --- a/level_0/f_conversion/c/conversion.h +++ b/level_0/f_conversion/c/conversion.h @@ -23,8 +23,8 @@ #define _F_conversion_h // fll includes -#include #include +#include #include #ifdef __cplusplus diff --git a/level_0/f_errors/c/errors.h b/level_0/f_errors/c/errors.h index 832450d..6bcc012 100644 --- a/level_0/f_errors/c/errors.h +++ b/level_0/f_errors/c/errors.h @@ -136,6 +136,27 @@ extern "C"{ potential_error == f_unterminated_group_on_stop) #endif // _di_f_macro_test_for_unterminated_group_errors_ +#ifndef _di_f_error_masks_ + // f_status is required to be exactly 16 bits, the first two high order bits represent error and warning respectively. + #define f_error_bit_error 32768 + #define f_error_bit_warning 16384 + #define f_error_bit_mask 49152 + #define f_error_bit_fine 16383 + #define f_error_bit_not_error 32767 + + #define f_error_is_error(status) status & f_error_bit_error + #define f_error_is_warning(status) status & f_error_bit_warning + #define f_error_is_problem(status) status & f_error_bit_mask // this is either a warning or an error + #define f_error_is_fine(status) (status & f_error_bit_mask) == 0 + #define f_error_is_not_error(status) (status & f_error_bit_not_error) == 0 + + #define f_error_set_error(status) status | f_error_bit_error + #define f_error_set_warning(status) status | f_error_bit_warning + + // use f_error_unmask to remove the error and warning bits + #define f_error_unmask(status) status & f_error_bit_fine +#endif // _di_f_error_masks_ + // use of an enumerator makes more sense here than explicitly defining every error code enum { #ifndef _di_f_errors_booleans_ diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 0daf0be..23c2ba7 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -17,20 +17,20 @@ extern "C"{ #ifndef _di_f_file_open_ f_return_status f_file_open(f_file *file_information, const f_string filename) { #ifndef _di_level_0_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // if file->mode is unset, then this may cause a segfault, depending on whether or not the libc will handle this appropriately - if (file_information->mode == 0) return f_invalid_parameter; + if (file_information->mode == 0) return f_error_set_error(f_invalid_parameter); file_information->file = fopen(filename, file_information->mode); - if (file_information->file == 0) return f_file_not_found; - if (ferror(file_information->file) != 0) return f_file_open_error; + if (file_information->file == 0) return f_error_set_error(f_file_not_found); + if (ferror(file_information->file) != 0) return f_error_set_error(f_file_open_error); file_information->id = fileno(file_information->file); - if (file_information->id == -1) return f_file_descriptor_error; + if (file_information->id == -1) return f_error_set_error(f_file_descriptor_error); return f_none; } @@ -39,59 +39,59 @@ extern "C"{ #ifndef _di_f_file_close_ f_return_status f_file_close(f_file *file_information) { #ifndef _di_level_0_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_file_not_open; + if (file_information->file == 0) return f_error_set_error(f_file_not_open); // if we were given a file descriptor as well, make sure to flush all changes to the disk that are not flushed by the 'fflush()' command if (file_information->id != 0) { // make sure all unfinished data gets completed - if (fsync(file_information->id) != 0) return f_file_synchronize_error; + if (fsync(file_information->id) != 0) return f_error_set_error(f_file_synchronize_error); } if (fclose(file_information->file) == 0) { file_information->file = 0; return f_none; } - else return f_file_close_error; + else return f_error_set_error(f_file_close_error); } #endif // _di_f_file_close_ #ifndef _di_f_file_flush_ f_return_status f_file_flush(f_file *file_information) { #ifndef _di_level_0_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_file_not_open; + if (file_information->file == 0) return f_error_set_error(f_file_not_open); if (fflush(file_information->file) == 0) return f_none; - else return f_file_flush_error; + else return f_error_set_error(f_file_flush_error); } #endif // _di_f_file_flush_ #ifndef _di_f_file_read_ f_return_status f_file_read(f_file *file_information, f_dynamic_string *buffer, const f_file_position location) { #ifndef _di_level_0_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; - if (buffer->used >= buffer->size) return f_invalid_parameter; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); + if (buffer->used >= buffer->size) return f_error_set_error(f_invalid_parameter); - if (location.buffer_start < 0) return f_invalid_parameter; - if (location.file_start < 0) return f_invalid_parameter; - if (location.total_elements < 0) return f_invalid_parameter; + if (location.buffer_start < 0) return f_error_set_error(f_invalid_parameter); + if (location.file_start < 0) return f_error_set_error(f_invalid_parameter); + if (location.total_elements < 0) return f_error_set_error(f_invalid_parameter); // when the available buffer size is smaller than the total elements, then there is not enough allocated memory available to read the file if (location.total_elements > 0) { - if (buffer->size - location.buffer_start < location.total_elements) return f_invalid_parameter; + if (buffer->size - location.buffer_start < location.total_elements) return f_error_set_error(f_invalid_parameter); } #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_file_not_open; + if (file_information->file == 0) return f_error_set_error(f_file_not_open); // first seek to 'where' we need to begin the read f_u_long current_file_position = ftell(file_information->file); - if (current_file_position == (f_u_long) -1) return f_file_seek_error; + if (current_file_position == (f_u_long) -1) return f_error_set_error(f_file_seek_error); f_s_int result = 0; @@ -101,7 +101,7 @@ extern "C"{ result = f_file_seek_from_current(file_information->file, file_information->byte_size * (location.file_start - current_file_position)); } - if (result != 0) return f_file_seek_error; + if (result != 0) return f_error_set_error(f_file_seek_error); // now do the actual read if (location.total_elements == 0) { @@ -110,8 +110,8 @@ extern "C"{ result = fread(buffer->string + location.buffer_start, file_information->byte_size, location.total_elements, file_information->file); } - if (file_information->file == 0) return f_file_read_error; - if (ferror(file_information->file) != 0) return f_file_read_error; + if (file_information->file == 0) return f_error_set_error(f_file_read_error); + if (ferror(file_information->file) != 0) return f_error_set_error(f_file_read_error); // now save how much of our allocated buffer is actually used // also make sure that we aren't making used space vanish @@ -136,19 +136,19 @@ extern "C"{ #ifndef _di_f_file_read_fifo_ f_return_status f_file_read_fifo(f_file *file_information, f_dynamic_string *buffer) { #ifndef _di_level_0_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; - if (buffer->used >= buffer->size) return f_invalid_parameter; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); + if (buffer->used >= buffer->size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ - if (file_information->file == 0) return f_file_not_open; + if (file_information->file == 0) return f_error_set_error(f_file_not_open); f_s_int result = 0; // now do the actual read result = fread(buffer->string + buffer->used, file_information->byte_size, buffer->size - buffer->used - 1, file_information->file); - if (file_information->file == 0) return f_file_read_error; - if (ferror(file_information->file) != 0) return f_file_read_error; + if (file_information->file == 0) return f_error_set_error(f_file_read_error); + if (ferror(file_information->file) != 0) return f_error_set_error(f_file_read_error); buffer->used += (result / file_information->byte_size); diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 16277a0..ccaed5b 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -19,9 +19,9 @@ #include // fll-0 includes -#include #include #include +#include #ifdef __cplusplus extern "C"{ diff --git a/level_0/f_memory/c/memory.c b/level_0/f_memory/c/memory.c index ddc6b8f..1fb4b37 100644 --- a/level_0/f_memory/c/memory.c +++ b/level_0/f_memory/c/memory.c @@ -16,8 +16,8 @@ extern "C"{ #ifndef _di_f_new_ f_return_status f_new_array(void **pointer, const f_memory_size_t type, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return f_invalid_parameter; - if (pointer == 0) return f_invalid_parameter; + if (type <= 0) return f_error_set_error(f_invalid_parameter); + if (pointer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-allocations @@ -32,14 +32,14 @@ extern "C"{ return f_none; } - return f_allocation_error; + return f_error_set_error(f_allocation_error); } #endif // _di_f_new_ #if ! ( defined (_di_f_delete_) || defined (_f_memory_FORCE_secure_memory_) ) f_return_status f_delete(void **pointer, const f_memory_size_t type, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ - if (pointer == 0) return f_invalid_parameter; + if (pointer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-frees @@ -57,9 +57,9 @@ extern "C"{ #if ! ( defined (_di_f_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) f_return_status f_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length) { #ifndef _di_level_0_parameter_checking_ - if (length < 0) return f_invalid_parameter; - if (type <= 0) return f_invalid_parameter; - if (pointer == 0) return f_invalid_parameter; + if (length < 0) return f_error_set_error(f_invalid_parameter); + if (type <= 0) return f_error_set_error(f_invalid_parameter); + if (pointer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // prevent double-frees @@ -81,10 +81,10 @@ extern "C"{ #if ! ( defined (_di_f_resize_) || defined (_f_memory_FORCE_secure_memory_) ) f_return_status f_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return f_invalid_parameter; - if (old_length < 0) return f_invalid_parameter; - if (new_length < 0) return f_invalid_parameter; - if (pointer == 0) return f_invalid_parameter; + if (type <= 0) return f_error_set_error(f_invalid_parameter); + if (old_length < 0) return f_error_set_error(f_invalid_parameter); + if (new_length < 0) return f_error_set_error(f_invalid_parameter); + if (pointer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // don't be wasteful @@ -128,17 +128,17 @@ extern "C"{ return f_none; } - return f_reallocation_error; + return f_error_set_error(f_reallocation_error); } #endif // ! ( defined (_di_f_resize_) || defined (_f_memory_FORCE_secure_memory_) ) #if ! ( defined (_di_f_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) f_return_status f_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) { #ifndef _di_level_0_parameter_checking_ - if (type <= 0) return f_invalid_parameter; - if (old_length < 0) return f_invalid_parameter; - if (new_length < 0) return f_invalid_parameter; - if (pointer == 0) return f_invalid_parameter; + if (type <= 0) return f_error_set_error(f_invalid_parameter); + if (old_length < 0) return f_error_set_error(f_invalid_parameter); + if (new_length < 0) return f_error_set_error(f_invalid_parameter); + if (pointer == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ // don't be wasteful @@ -190,7 +190,7 @@ extern "C"{ return f_none; } - return f_reallocation_error; + return f_error_set_error(f_reallocation_error); } #endif // ! ( defined (_di_f_adjust_) || defined (_f_memory_FORCE_fast_memory_) ) diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index c58ba33..855af54 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -29,8 +29,8 @@ #include // fll includes -#include #include +#include #ifdef __cplusplus extern "C"{ diff --git a/level_0/f_output/c/output.c b/level_0/f_output/c/output.c index f310e35..0c229d1 100644 --- a/level_0/f_output/c/output.c +++ b/level_0/f_output/c/output.c @@ -16,7 +16,7 @@ extern "C"{ for (; i < length; i++) { if (string[i] != f_eos) { - if (fputc(string[i], output) == 0) return f_output_error; + if (fputc(string[i], output) == 0) return f_error_set_error(f_output_error); } } @@ -34,7 +34,7 @@ extern "C"{ for (; i < buffer.used; i++) { if (buffer.string[i] != f_eos) { - if (fputc(buffer.string[i], output) == 0) return f_output_error; + if (fputc(buffer.string[i], output) == 0) return f_error_set_error(f_output_error); } } @@ -45,18 +45,18 @@ extern "C"{ #ifndef _di_f_print_partial_dynamic_string_ f_return_status f_print_partial_dynamic_string(f_file_type output, const f_dynamic_string buffer, const f_string_location location) { #ifndef _di_level_0_parameter_checking_ - if (location.start < 0) return f_invalid_parameter; - if (location.stop < location.start) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; - if (location.start >= buffer.used) return f_invalid_parameter; - if (location.stop >= buffer.used) return f_invalid_parameter; + if (location.start < 0) return f_error_set_error(f_invalid_parameter); + if (location.stop < location.start) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); + if (location.start >= buffer.used) return f_error_set_error(f_invalid_parameter); + if (location.stop >= buffer.used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ register f_string_length i = location.start; for (; i <= location.stop; i++) { if (buffer.string[i] != f_eos) { - if (fputc(buffer.string[i], output) == 0) return f_output_error; + if (fputc(buffer.string[i], output) == 0) return f_error_set_error(f_output_error); } } diff --git a/level_0/f_output/c/output.h b/level_0/f_output/c/output.h index 18582b9..f1e13da 100644 --- a/level_0/f_output/c/output.h +++ b/level_0/f_output/c/output.h @@ -17,9 +17,9 @@ #include // fll-0 includes -#include #include #include +#include #ifdef __cplusplus extern "C"{ diff --git a/level_0/f_pipe/c/pipe.c b/level_0/f_pipe/c/pipe.c index 69bd2d0..7ec221f 100644 --- a/level_0/f_pipe/c/pipe.c +++ b/level_0/f_pipe/c/pipe.c @@ -19,7 +19,7 @@ extern "C"{ struct stat st_info; if (fstat(fileno(f_pipe), &st_info) != 0) { - return f_file_stat_error; + return f_error_set_error(f_file_stat_error); } if (S_ISFIFO(st_info.st_mode)) { diff --git a/level_0/f_pipe/c/pipe.h b/level_0/f_pipe/c/pipe.h index 3d481cc..30a0a1a 100644 --- a/level_0/f_pipe/c/pipe.h +++ b/level_0/f_pipe/c/pipe.h @@ -16,8 +16,8 @@ #include // fll includes -#include #include +#include #ifdef __cplusplus extern "C"{ diff --git a/level_0/f_serialized/c/serialized.h b/level_0/f_serialized/c/serialized.h index ae90e3e..ccbfc19 100644 --- a/level_0/f_serialized/c/serialized.h +++ b/level_0/f_serialized/c/serialized.h @@ -16,8 +16,8 @@ #include // fll-0 includes -#include #include +#include #ifdef __cplusplus extern "C"{ diff --git a/level_0/f_types/c/types.h b/level_0/f_types/c/types.h index dad5ce4..2243909 100644 --- a/level_0/f_types/c/types.h +++ b/level_0/f_types/c/types.h @@ -14,6 +14,16 @@ * long: 2^128 = 3.40282e38 * long long: 2^256 = 1.15792e77 * + * If you need exact size, use one of the following: + * int8_t: 2^8 (signed) + * uint8_t: 2^8 (unsigned) + * int16_t: 2^16 (signed) + * uint16_t: 2^16 (unsigned) + * int32_t: 2^32 (signed) + * uint32_t: 2^32 (unsigned) + * int64_t: 2^64 (signed) + * uint64_t: 2^64 (unsigned) + * * TODO: Should a range type be implemented? (ie: f_range_short_long -> min=short, max=long) */ #ifndef _F_types_h @@ -22,6 +32,7 @@ // libc includes #include // contains mode_t, dev_t, gid_t, uid_t, etc.. #include +#include #ifdef __cplusplus extern "C"{ @@ -98,7 +109,7 @@ extern "C"{ #endif // _di_f_types_max #ifndef _di_f_status_ - typedef f_u_short f_status; + typedef uint16_t f_status; #define f_status_initialize 0 diff --git a/level_1/fl_colors/c/colors.c b/level_1/fl_colors/c/colors.c index 7f40f15..5c8e8a9 100644 --- a/level_1/fl_colors/c/colors.c +++ b/level_1/fl_colors/c/colors.c @@ -13,8 +13,8 @@ extern "C"{ #ifndef _di_fl_set_color_ f_return_status fl_set_color(f_file_type file, const f_colors_format format, const f_autochar *color1, const f_autochar *color2, const f_autochar *color3, const f_autochar *color4, const f_autochar *color5) { #ifndef _di_level_1_parameter_checking_ - if (file == f_null) return f_invalid_parameter; - if (color1 == f_null) return f_invalid_parameter; + if (file == f_null) return f_error_set_error(f_invalid_parameter); + if (color1 == f_null) return f_error_set_error(f_invalid_parameter); // make sure all data is in the proper order if (color2 == f_null && (color3 != f_null || color4 != f_null || color5 != f_null)) return f_invalid_parameter; @@ -35,13 +35,13 @@ extern "C"{ #ifndef _di_fl_save_color_ f_return_status fl_save_color(f_dynamic_string *buffer, const f_colors_format format, const f_autochar *color1, const f_autochar *color2, const f_autochar *color3, const f_autochar *color4, const f_autochar *color5) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (color1 == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (color1 == f_null) return f_error_set_error(f_invalid_parameter); // make sure all data is in the proper order - if (color2 == f_null && (color3 != f_null || color4 != f_null || color5 != f_null)) return f_invalid_parameter; - if (color3 == f_null && (color4 != f_null || color5 != f_null)) return f_invalid_parameter; - if (color4 == f_null && color5 != f_null) return f_invalid_parameter; + if (color2 == f_null && (color3 != f_null || color4 != f_null || color5 != f_null)) return f_error_set_error(f_invalid_parameter); + if (color3 == f_null && (color4 != f_null || color5 != f_null)) return f_error_set_error(f_invalid_parameter); + if (color4 == f_null && color5 != f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length string_size = strnlen(format.begin, f_color_max_size) + strnlen(format.end, f_color_max_size) + 1; @@ -118,8 +118,8 @@ extern "C"{ #ifndef _di_fl_print_color_ f_return_status fl_print_color(f_file_type file, const f_dynamic_string start_color, const f_dynamic_string end_color, const f_autochar *string, ...) { #ifndef _di_level_1_parameter_checking_ - if (file == f_null) return f_invalid_parameter; - if (string == f_null) return f_invalid_parameter; + if (file == f_null) return f_error_set_error(f_invalid_parameter); + if (string == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ if (start_color.used != 0) { @@ -145,8 +145,8 @@ extern "C"{ #ifndef _di_fl_print_color_line_ f_return_status fl_print_color_line(f_file_type file, const f_dynamic_string start_color, const f_dynamic_string end_color, const f_autochar *string, ...) { #ifndef _di_level_1_parameter_checking_ - if (file == f_null) return f_invalid_parameter; - if (string == f_null) return f_invalid_parameter; + if (file == f_null) return f_error_set_error(f_invalid_parameter); + if (string == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ if (start_color.used != 0) { diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index 81b0e7d..e272b88 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -13,17 +13,17 @@ extern "C"{ #ifndef _di_fl_process_parameters_ f_return_status fl_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length total_parameters, f_string_lengths *remaining) { #ifndef _di_level_1_parameter_checking_ - if (remaining == f_null) return f_invalid_parameter; + if (remaining == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - f_status status = f_status_initialize; + f_status status = f_status_initialize; f_console_id result = 0; - f_bool found = f_false; + f_bool found = f_false; - f_array_length location = 1; // parameter 0 represents the program name so skip it - f_string_length sub_location = 0; - f_string_length increments = 0; - f_string_length string_length = 0; + f_array_length location = 1; // parameter 0 represents the program name so skip it + f_string_length sub_location = 0; + f_string_length increments = 0; + f_string_length string_length = 0; f_array_length parameter_counter = 0; f_string_lengths extra_initiator = f_string_lengths_initialize; @@ -64,9 +64,9 @@ extern "C"{ f_status allocation_status = f_status_initialize; f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } } @@ -86,9 +86,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } } @@ -118,9 +118,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } } @@ -140,9 +140,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, extra_initiator, extra_initiator.size + f_console_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } } @@ -170,9 +170,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, parameters[parameter_counter].additional, parameters[parameter_counter].additional.size + f_console_default_allocation_step); } - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } parameters[parameter_counter].result = f_console_result_found; @@ -196,9 +196,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, parameters[extra_initiator.array[0]].additional, parameters[extra_initiator.array[0]].additional.size + f_console_default_allocation_step); } - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } parameters[extra_initiator.array[0]].result = f_console_result_additional; @@ -218,9 +218,9 @@ extern "C"{ f_resize_string_lengths(allocation_status, (*remaining), remaining->size + f_console_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(status, extra_initiator); - return allocation_status; + return f_error_set_error(allocation_status); } } diff --git a/level_1/fl_console/c/console.h b/level_1/fl_console/c/console.h index 6d69b45..c2b9738 100644 --- a/level_1/fl_console/c/console.h +++ b/level_1/fl_console/c/console.h @@ -27,7 +27,6 @@ extern "C"{ extern f_return_status fl_process_parameters(const f_array_length argc, const f_string argv[], f_console_parameter parameters[], const f_array_length total_parameters, f_string_lengths *remaining); #endif // _di_fl_process_parameters_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 605cc1f..8e44469 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -15,14 +15,14 @@ extern "C"{ // put the names of each file and/or directory inside the names parameter f_return_status fl_directory_list(const f_string directory_path, f_dynamic_strings *names) { #ifndef _di_level_1_parameter_checking_ - if (names == f_null) return f_invalid_parameter; + if (names == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ struct dirent **listing = 0; - f_s_int length = 0; - f_s_int counter = 0; - f_string_length size = f_string_length_initialize; - f_status status = f_status_initialize; + f_s_int length = 0; + f_s_int counter = 0; + f_string_length size = f_string_length_initialize; + f_status status = f_status_initialize; length = scandir(directory_path, &listing, 0, alphasort); @@ -34,13 +34,13 @@ extern "C"{ if (names->used >= names->size) { f_resize_dynamic_strings(status, (*names), names->used + fl_directory_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } f_resize_dynamic_string(status, names->array[names->used], size); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } @@ -60,8 +60,8 @@ extern "C"{ // an empty directory return f_no_data; } else if (length == -1) { - if (errno == ENOMEM) return f_allocation_error; - else return f_failure; + if (errno == ENOMEM) return f_error_set_error(f_allocation_error); + else return f_error_set_error(f_failure); } return f_none; diff --git a/level_1/fl_directory/c/directory.h b/level_1/fl_directory/c/directory.h index f5d3fd5..1a3cb0e 100644 --- a/level_1/fl_directory/c/directory.h +++ b/level_1/fl_directory/c/directory.h @@ -19,9 +19,9 @@ #include // fll-0 includes -#include #include #include +#include #include #ifdef __cplusplus diff --git a/level_1/fl_errors/c/errors.c b/level_1/fl_errors/c/errors.c index 0168c8c..2aa734f 100644 --- a/level_1/fl_errors/c/errors.c +++ b/level_1/fl_errors/c/errors.c @@ -16,10 +16,12 @@ extern "C"{ #ifndef _di_fl_errors_to_string_ f_return_status fl_errors_to_string(const f_status error, f_string *string) { #ifndef _di_level_1_parameter_checking_ - if (string == f_null) return f_invalid_parameter; + if (string == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - switch (error) { + f_status umasked_error = f_error_unmask(error); + + switch (umasked_error) { #ifndef _di_fl_errors_booleans_ case f_false: *string = "f_false"; @@ -311,7 +313,7 @@ extern "C"{ #ifndef _di_fl_errors_is_error_ f_return_status fl_errors_is_error(const f_status error) { - if (fl_errors_is_okay(error) == f_true) { + if (fl_errors_is_fine(error) == f_true) { return f_false; } else if (fl_errors_is_warning(error) == f_true) { return f_false; @@ -353,10 +355,8 @@ extern "C"{ } #endif // _di_fl_errors_is_warning_ -#ifndef _di_fl_errors_is_okay_ - // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. - // Keep in mind that many of the error codes are context-specific and may be reported as an "okay" here when it is in fact not okay. - f_return_status fl_errors_is_okay(const f_status error) { +#ifndef _di_fl_errors_is_fine_ + f_return_status fl_errors_is_fine(const f_status error) { switch (error) { #ifndef _di_fl_errors_booleans_ case f_false: @@ -386,7 +386,7 @@ extern "C"{ return f_false; } -#endif // _di_fl_errors_is_okay_ +#endif // _di_fl_errors_is_fine_ #ifdef __cplusplus } // extern "C" diff --git a/level_1/fl_errors/c/errors.h b/level_1/fl_errors/c/errors.h index 96d527e..2c0e329 100644 --- a/level_1/fl_errors/c/errors.h +++ b/level_1/fl_errors/c/errors.h @@ -11,6 +11,7 @@ #define _FL_errors_h // fll-0 includes +#include #include #include @@ -35,12 +36,11 @@ extern "C"{ extern f_return_status fl_errors_is_warning(const f_status error); #endif // _di_fl_errors_is_warning_ - -#ifndef _di_fl_errors_is_okay_ +#ifndef _di_fl_errors_is_fine_ // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. - // Keep in mind that many of the error codes are context-specific and may be reported as an "okay" here when it is in fact not okay. - extern f_return_status fl_errors_is_okay(const f_status error); -#endif // _di_fl_errors_is_okay_ + // Keep in mind that many of the error codes are context-specific and may be reported as an "fine" here when it is in fact not fine. + extern f_return_status fl_errors_is_fine(const f_status error); +#endif // _di_fl_errors_is_fine_ #ifdef __cplusplus } // extern "C" diff --git a/level_1/fl_file/c/file.c b/level_1/fl_file/c/file.c index 8b923e5..b8ec523 100644 --- a/level_1/fl_file/c/file.c +++ b/level_1/fl_file/c/file.c @@ -13,18 +13,18 @@ extern "C"{ #ifndef _di_fl_file_read_ f_return_status fl_file_read(f_file file, const f_file_position position, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); - if (position.buffer_start < 0) return f_invalid_parameter; - if (position.file_start < 0) return f_invalid_parameter; - if (position.total_elements < 0) return f_invalid_parameter; + if (position.buffer_start < 0) return f_error_set_error(f_invalid_parameter); + if (position.file_start < 0) return f_error_set_error(f_invalid_parameter); + if (position.total_elements < 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (file.file == 0) return f_file_not_open; + if (file.file == 0) return f_error_set_warning(f_file_not_open); - f_status status = f_status_initialize; - f_string_length size = f_string_length_initialize; - f_bool infinite = f_false; + f_status status = f_status_initialize; + f_string_length size = f_string_length_initialize; + f_bool infinite = f_false; // when total_elements is 0, this means the file read will until EOF is reached if (position.total_elements == 0) { @@ -39,7 +39,7 @@ extern "C"{ if (buffer->size <= size) { f_resize_dynamic_string(status, (*buffer), size); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -48,13 +48,13 @@ extern "C"{ if (status == f_none_on_eof) { break; - } else if (status != f_none) { + } else if (f_error_is_error(status)) { return status; } if (infinite) { if (size + f_file_default_read_size > f_string_max_size) { - return f_overflow; + return f_error_set_error(f_overflow); } size += f_file_default_read_size; @@ -68,13 +68,13 @@ extern "C"{ #ifndef _di_fl_file_read_fifo_ f_return_status fl_file_read_fifo(f_file file, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ - if (file.file == 0) return f_file_not_open; + if (file.file == 0) return f_error_set_warning(f_file_not_open); - f_status status = f_status_initialize; - f_string_length size = f_string_length_initialize; + f_status status = f_status_initialize; + f_string_length size = f_string_length_initialize; size = f_file_default_read_size; @@ -83,7 +83,7 @@ extern "C"{ if (buffer->size <= size) { f_resize_dynamic_string(status, (*buffer), size); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -92,12 +92,12 @@ extern "C"{ if (status == f_none_on_eof) { break; - } else if (status != f_none) { + } else if (f_error_is_error(status)) { return status; } if (size + f_file_default_read_size > f_string_max_size) { - return f_overflow; + return f_error_set_error(f_overflow); } size += f_file_default_read_size; @@ -109,15 +109,15 @@ extern "C"{ #ifndef _di_fl_file_write_ f_return_status fl_file_write(f_file file, const f_dynamic_string buffer) { - if (file.file == 0) return f_file_not_open; + if (file.file == 0) return f_error_set_error(f_file_not_open); f_status status = f_status_initialize; - f_size_t size = 0; + f_size_t size = 0; size = fwrite(buffer.string, file.byte_size, buffer.used, file.file); if (size < buffer.used * file.byte_size) { - return f_file_write_error; + return f_error_set_error(f_file_write_error); } return f_none; @@ -127,20 +127,20 @@ extern "C"{ #ifndef _di_fl_file_write_partial_ f_return_status fl_file_write_partial(f_file file, const f_dynamic_string buffer, const f_string_location position) { #ifndef _di_level_1_parameter_checking_ - if (position.start < position.stop) return f_invalid_parameter; + if (position.start < position.stop) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ if (file.file == 0) return f_file_not_open; f_status status = f_status_initialize; - f_size_t size = 0; + f_size_t size = 0; f_string_length total = buffer.used - (position.stop - position.start + 1); size = fwrite(buffer.string + position.start, file.byte_size, total, file.file); if (size < total * file.byte_size) { - return f_file_write_error; + return f_error_set_error(f_file_write_error); } return f_none; diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index c99f2e3..2e39dfb 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -14,8 +14,8 @@ extern "C"{ #ifndef _di_fl_fss_identify_ f_return_status fl_fss_identify(const f_dynamic_string buffer, f_fss_header *header) { #ifndef _di_level_1_parameter_checking_ - if (header == f_null) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; + if (header == f_null) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ register f_string_length i = 0; @@ -51,7 +51,7 @@ extern "C"{ i++; header->length = i; - return fl_fss_accepted_but_invalid; + return f_error_is_warning(fl_fss_accepted_but_invalid); } } } @@ -80,7 +80,7 @@ extern "C"{ header->length = i + 1; - return fl_fss_accepted_but_invalid; + return f_error_is_warning(fl_fss_accepted_but_invalid); } } } @@ -101,10 +101,10 @@ extern "C"{ #ifndef _di_fl_fss_identify_file_ f_return_status fl_fss_identify_file(f_file *file_information, f_fss_header *header) { #ifndef _di_level_1_parameter_checking_ - if (file_information == f_null) return f_invalid_parameter; - if (header == f_null) return f_invalid_parameter; - if (file_information->file == 0) return f_file_not_open; - if (ferror(file_information->file) != 0) return f_file_error; + if (file_information == f_null) return f_error_set_error(f_invalid_parameter); + if (header == f_null) return f_error_set_error(f_invalid_parameter); + if (file_information->file == 0) return f_file_not_open; + if (ferror(file_information->file) != 0) return f_file_error; #endif // _di_level_1_parameter_checking_ clearerr(file_information->file); @@ -125,14 +125,14 @@ extern "C"{ f_adjust_dynamic_string(status, buffer, location.total_elements + 1); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } // 2: buffer the file status = f_file_read(file_information, &buffer, location); - if (f_macro_test_for_basic_errors(status) || f_macro_test_for_file_errors(status)) { + if (f_error_is_error(status)) { return status; } @@ -146,10 +146,10 @@ extern "C"{ #ifndef _di_fl_fss_shift_delimiters_ f_return_status fl_fss_shift_delimiters(f_dynamic_string *buffer, const f_string_location location) { #ifndef _di_level_1_parameter_checking_ - if (buffer->used <= 0) return f_invalid_parameter; - if (location.start < 0) return f_invalid_parameter; - if (location.stop < location.start) return f_invalid_parameter; - if (location.start >= buffer->used) return f_invalid_parameter; + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (location.start < 0) return f_error_set_error(f_invalid_parameter); + if (location.stop < location.start) return f_error_set_error(f_invalid_parameter); + if (location.start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length position = f_string_length_initialize; diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index 3488ce6..6d5c9c3 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -12,9 +12,9 @@ #include // fll-0 includes -#include -#include #include +#include +#include #include #include #include diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index 5be601b..dbe0ccd 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -13,13 +13,13 @@ extern "C"{ #ifndef _di_fl_fss_basic_object_read_ f_return_status fl_fss_basic_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -81,7 +81,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -136,7 +136,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) if (buffer->string[input->start] == quoted) { f_string_length location = input->start; @@ -149,7 +149,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -208,7 +208,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -278,7 +278,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) } // seek to the end of the line when no valid object is found @@ -302,14 +302,13 @@ extern "C"{ #ifndef _di_fl_fss_basic_content_read_ f_return_status fl_fss_basic_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; - if (found->used > found->size) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -348,7 +347,7 @@ extern "C"{ #ifndef _di_fl_fss_basic_object_write_ f_return_status fl_fss_basic_object_write(const f_dynamic_string object, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -374,7 +373,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer_position.start = buffer->used; @@ -400,7 +399,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -414,7 +413,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -445,7 +444,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } // restart the loop searching for f_fss_delimit_double_quote. @@ -465,7 +464,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -491,7 +490,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } break; @@ -552,7 +551,7 @@ extern "C"{ #ifndef _di_fl_fss_basic_content_write_ f_return_status fl_fss_basic_content_write(const f_dynamic_string content, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -570,7 +569,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } while (input->start <= input->stop && input->start < content.used) { diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index db139f8..fb9f342 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -15,9 +15,9 @@ #include // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 15b86d4..c781373 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -13,13 +13,13 @@ extern "C"{ #ifndef _di_fl_fss_basic_list_object_read_ f_return_status fl_fss_basic_list_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -88,7 +88,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -167,13 +167,13 @@ extern "C"{ #ifndef _di_fl_fss_basic_list_content_read_ f_return_status fl_fss_basic_list_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -261,7 +261,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -348,7 +348,7 @@ extern "C"{ #ifndef _di_fl_fss_basic_list_object_write_ f_return_status fl_fss_basic_list_object_write(const f_dynamic_string object, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -374,7 +374,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer_position.start = buffer->used; @@ -425,7 +425,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } while (slash_count > 0) { @@ -470,7 +470,7 @@ extern "C"{ #ifndef _di_fl_fss_basic_list_content_write_ f_return_status fl_fss_basic_list_content_write(const f_dynamic_string content, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -497,7 +497,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer_position.start = buffer->used; @@ -546,7 +546,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } while (slash_count > 0) { @@ -586,7 +586,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; diff --git a/level_1/fl_fss/c/fss_basic_list.h b/level_1/fl_fss/c/fss_basic_list.h index 3492d27..43acf62 100644 --- a/level_1/fl_fss/c/fss_basic_list.h +++ b/level_1/fl_fss/c/fss_basic_list.h @@ -15,9 +15,9 @@ #include // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 29b862d..35d65f9 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -13,13 +13,13 @@ extern "C"{ #ifndef _di_fl_fss_extended_object_read_ f_return_status fl_fss_extended_object_read(f_dynamic_string *buffer, f_string_location *input, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -81,7 +81,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -136,7 +136,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) if (buffer->string[input->start] == quoted) { f_string_length location = input->start; @@ -148,7 +148,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -171,7 +171,7 @@ extern "C"{ input->start = location + 1; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) if (isgraph(buffer->string[input->start])) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { @@ -202,7 +202,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -262,7 +262,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) } // seek to the end of the line when no valid object is found @@ -280,13 +280,13 @@ extern "C"{ #ifndef _di_fl_fss_extended_content_read_ f_return_status fl_fss_extended_content_read(f_dynamic_string *buffer, f_string_location *input, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (input == f_null) return f_invalid_parameter; - if (found == f_null) return f_invalid_parameter; - if (input->start < 0) return f_invalid_parameter; - if (input->stop < input->start) return f_invalid_parameter; - if (buffer->used <= 0) return f_invalid_parameter; - if (input->start >= buffer->used) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (input == f_null) return f_error_set_error(f_invalid_parameter); + if (found == f_null) return f_error_set_error(f_invalid_parameter); + if (input->start < 0) return f_error_set_error(f_invalid_parameter); + if (input->stop < input->start) return f_error_set_error(f_invalid_parameter); + if (buffer->used <= 0) return f_error_set_error(f_invalid_parameter); + if (input->start >= buffer->used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // delimits must only be applied once a valid object is found @@ -316,7 +316,7 @@ extern "C"{ if (found->used >= found->size) { f_resize_fss_content(status, (*found), found->size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)){ + if (f_error_is_error(status)){ f_status allocation_status = f_status_initialize; f_delete_string_lengths(allocation_status, delimits); @@ -372,7 +372,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -428,7 +428,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) if (buffer->string[input->start] == quoted) { location = input->start; @@ -440,7 +440,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -469,10 +469,10 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) input->start++; - return f_unterminated_group; + return f_error_is_warning(f_unterminated_group); } else if (buffer->string[input->start] == f_eol) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); @@ -493,7 +493,7 @@ extern "C"{ f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(allocation_status)) { + if (f_error_is_error(allocation_status)) { f_delete_string_lengths(allocation_status, delimits); return allocation_status; } @@ -537,10 +537,10 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) input->start++; - return f_unterminated_group; + return f_error_is_warning(f_unterminated_group); } input->start++; @@ -570,7 +570,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_error_is_warning(f_unterminated_group_on_eos), f_error_is_warning(f_unterminated_group_on_stop)) } if (continue_main_loop) { @@ -605,7 +605,7 @@ extern "C"{ #ifndef _di_fl_fss_extended_object_write_ f_return_status fl_fss_extended_object_write(const f_dynamic_string object, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -631,7 +631,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer_position.start = buffer->used; @@ -657,7 +657,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -671,7 +671,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -718,7 +718,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } // restart the loop searching for f_fss_delimit_double_quote. @@ -738,7 +738,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -764,7 +764,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } break; @@ -825,7 +825,7 @@ extern "C"{ #ifndef _di_fl_fss_extended_content_write_ f_return_status fl_fss_extended_content_write(const f_dynamic_string content, f_string_location *input, f_dynamic_string *buffer) { #ifndef _di_level_1_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_status status = f_status_initialize; @@ -844,7 +844,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } fl_macro_fss_skip_past_delimit_placeholders(content, (*input)) @@ -894,7 +894,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -908,7 +908,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; @@ -932,7 +932,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } input->start = start_position; @@ -978,7 +978,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } while (slash_count > 0) { @@ -1004,7 +1004,7 @@ extern "C"{ if (pre_allocate_size > buffer->size) { f_resize_dynamic_string(status, (*buffer), pre_allocate_size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; diff --git a/level_1/fl_fss/c/fss_extended.h b/level_1/fl_fss/c/fss_extended.h index 6993f72..9f8d3e7 100644 --- a/level_1/fl_fss/c/fss_extended.h +++ b/level_1/fl_fss/c/fss_extended.h @@ -15,9 +15,9 @@ #include // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index 34bd531..68f9584 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -210,7 +210,7 @@ extern "C"{ f_status status = f_status_initialize; \ \ f_resize_fss_content(status, content, content.size + f_fss_default_allocation_step); \ - if (f_macro_test_for_allocation_errors(status)) { \ + if (f_error_is_error(status)) { \ f_status allocation_status = f_status_initialize; \ f_delete_string_lengths(allocation_status, delimits); \ \ diff --git a/level_1/fl_serialized/c/serialized.c b/level_1/fl_serialized/c/serialized.c index ce2be79..5c50c59 100644 --- a/level_1/fl_serialized/c/serialized.c +++ b/level_1/fl_serialized/c/serialized.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_fl_serialize_simple_ f_return_status fl_serialize_simple(const f_dynamic_string value, f_dynamic_string *serialized) { #ifndef _di_level_0_parameter_checking_ - if (serialized == f_null) return f_invalid_parameter; + if (serialized == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ f_status status = f_status_initialize; @@ -22,7 +22,7 @@ extern "C" { if (serialized->used + value.used + 1 >= serialized->size) { f_resize_dynamic_string(status, (*serialized), serialized->size + value.used + f_serialized_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } if (serialized->used == 0) { @@ -41,12 +41,12 @@ extern "C" { #ifndef _di_fl_unserialize_simple_ f_return_status fl_unserialize_simple(const f_dynamic_string serialized, f_string_locations *locations) { #ifndef _di_level_0_parameter_checking_ - if (locations == f_null) return f_invalid_parameter; + if (locations == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ f_status status = f_status_initialize; - f_array_length i = 0; + f_array_length i = 0; f_array_length start = 0; while (i <= serialized.used) { @@ -54,7 +54,7 @@ extern "C" { if (locations->used + 1 >= locations->size) { f_resize_string_locations(status, (*locations), locations->size + f_serialized_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } if (start == i) { @@ -80,12 +80,12 @@ extern "C" { #ifndef _di_fl_unserialize_simple_get_ f_return_status fl_unserialize_simple_get(const f_dynamic_string serialized, const f_array_length index, f_string_location *location) { #ifndef _di_level_0_parameter_checking_ - if (location == f_null) return f_invalid_parameter; + if (location == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_0_parameter_checking_ f_status status = f_status_initialize; - f_array_length i = 0; + f_array_length i = 0; f_array_length current = 0; location->start = 1; diff --git a/level_1/fl_serialized/c/serialized.h b/level_1/fl_serialized/c/serialized.h index 36ccc05..87a70ba 100644 --- a/level_1/fl_serialized/c/serialized.h +++ b/level_1/fl_serialized/c/serialized.h @@ -16,9 +16,9 @@ #include // fll-0 includes -#include #include #include +#include #include #ifdef __cplusplus diff --git a/level_1/fl_strings/c/strings.c b/level_1/fl_strings/c/strings.c index ff3771d..bf7ac2c 100644 --- a/level_1/fl_strings/c/strings.c +++ b/level_1/fl_strings/c/strings.c @@ -13,11 +13,11 @@ extern "C"{ #ifndef _di_fl_rip_string_ f_return_status fl_rip_string(const f_dynamic_string buffer, const f_string_location position, f_dynamic_string *results) { #ifndef _di_level_1_parameter_checking_ - if (results == f_null) return f_invalid_parameter; - if (position.start < 0) return f_invalid_parameter; - if (position.stop < position.start) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; - if (position.start >= buffer.used) return f_invalid_parameter; + if (results == f_null) return f_error_set_error(f_invalid_parameter); + if (position.start < 0) return f_error_set_error(f_invalid_parameter); + if (position.stop < position.start) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); + if (position.start >= buffer.used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ // the start and stop point are inclusive locations, and therefore start - stop is actually 1 too few locations @@ -28,7 +28,7 @@ extern "C"{ f_resize_dynamic_string(status, (*results), size); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } @@ -45,11 +45,11 @@ extern "C"{ #ifndef _di_fl_seek_line_past_non_graph_ f_return_status fl_seek_line_past_non_graph(const f_dynamic_string buffer, f_string_location *position, const f_autochar placeholder) { #ifndef _di_level_1_parameter_checking_ - if (position == f_null) return f_invalid_parameter; - if (position->start < 0) return f_invalid_parameter; - if (position->stop < position->start) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; - if (position->start >= buffer.used) return f_invalid_parameter; + if (position == f_null) return f_error_set_error(f_invalid_parameter); + if (position->start < 0) return f_error_set_error(f_invalid_parameter); + if (position->stop < position->start) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); + if (position->start >= buffer.used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ while (!isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder) { @@ -57,8 +57,8 @@ extern "C"{ ++position->start; - if (position->start >= buffer.used) return f_none_on_eos; - if (position->start > position->stop) return f_none_on_stop; + if (position->start >= buffer.used) return f_none_on_eos; + if (position->start > position->stop) return f_none_on_stop; } // while return f_none; @@ -68,10 +68,10 @@ extern "C"{ #ifndef _di_fl_seek_line_until_non_graph_ f_return_status fl_seek_line_until_non_graph(const f_dynamic_string buffer, f_string_location *position, const f_autochar placeholder) { #ifndef _di_level_1_parameter_checking_ - if (position->start < 0) return f_invalid_parameter; - if (position->stop < position->start) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; - if (position->start >= buffer.used) return f_invalid_parameter; + if (position->start < 0) return f_error_set_error(f_invalid_parameter); + if (position->stop < position->start) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); + if (position->start >= buffer.used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ while (isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder) { @@ -79,8 +79,8 @@ extern "C"{ ++position->start; - if (position->start >= buffer.used) return f_none_on_eos; - if (position->start > position->stop) return f_none_on_stop; + if (position->start >= buffer.used) return f_none_on_eos; + if (position->start > position->stop) return f_none_on_stop; } // while return f_none; @@ -90,10 +90,10 @@ extern "C"{ #ifndef _di_fl_seek_to_ f_return_status fl_seek_to(const f_dynamic_string buffer, f_string_location *position, const f_autochar seek_to_this) { #ifndef _di_level_1_parameter_checking_ - if (position->start < 0) return f_invalid_parameter; - if (position->stop < position->start) return f_invalid_parameter; - if (buffer.used <= 0) return f_invalid_parameter; - if (position->start >= buffer.used) return f_invalid_parameter; + if (position->start < 0) return f_error_set_error(f_invalid_parameter); + if (position->stop < position->start) return f_error_set_error(f_invalid_parameter); + if (buffer.used <= 0) return f_error_set_error(f_invalid_parameter); + if (position->start >= buffer.used) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ while (buffer.string[position->start] != seek_to_this) { @@ -101,8 +101,8 @@ extern "C"{ ++position->start; - if (position->start >= buffer.used) return f_none_on_eos; - if (position->start > position->stop) return f_none_on_stop; + if (position->start >= buffer.used) return f_none_on_eos; + if (position->start > position->stop) return f_none_on_stop; } // while return f_none; @@ -112,8 +112,8 @@ extern "C"{ #ifndef _di_fl_compare_strings_ f_return_status fl_compare_strings(const f_string string1, const f_string string2, const f_string_length length1, const f_string_length length2) { #ifndef _di_level_1_parameter_checking_ - if (length1 <= 0) return f_invalid_parameter; - if (length2 <= 0) return f_invalid_parameter; + if (length1 <= 0) return f_error_set_error(f_invalid_parameter); + if (length2 <= 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length i1 = f_string_length_initialize; @@ -146,8 +146,8 @@ extern "C"{ #ifndef _di_fl_compare_dynamic_strings_ f_return_status fl_compare_dynamic_strings(const f_dynamic_string string1, const f_dynamic_string string2) { #ifndef _di_level_1_parameter_checking_ - if (string1.used <= 0) return f_invalid_parameter; - if (string2.used <= 0) return f_invalid_parameter; + if (string1.used <= 0) return f_error_set_error(f_invalid_parameter); + if (string2.used <= 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length i1 = f_string_length_initialize; @@ -180,14 +180,14 @@ extern "C"{ #ifndef _di_fl_compare_partial_dynamic_strings_ f_return_status fl_compare_partial_dynamic_strings(const f_dynamic_string string1, const f_dynamic_string string2, const f_string_location offset1, const f_string_location offset2) { #ifndef _di_level_1_parameter_checking_ - if (string1.used <= 0) return f_invalid_parameter; - if (string2.used <= 0) return f_invalid_parameter; + if (string1.used <= 0) return f_error_set_error(f_invalid_parameter); + if (string2.used <= 0) return f_error_set_error(f_invalid_parameter); - if (offset1.start > offset1.stop) return f_invalid_parameter; - if (offset2.start > offset2.stop) return f_invalid_parameter; + if (offset1.start > offset1.stop) return f_error_set_error(f_invalid_parameter); + if (offset2.start > offset2.stop) return f_error_set_error(f_invalid_parameter); - if (string1.used <= offset1.stop) return f_invalid_parameter; - if (string2.used <= offset2.stop) return f_invalid_parameter; + if (string1.used <= offset1.stop) return f_error_set_error(f_invalid_parameter); + if (string2.used <= offset2.stop) return f_error_set_error(f_invalid_parameter); #endif // _di_level_1_parameter_checking_ f_string_length i1 = offset1.start; diff --git a/level_1/fl_strings/c/strings.h b/level_1/fl_strings/c/strings.h index 7757428..14c45d6 100644 --- a/level_1/fl_strings/c/strings.h +++ b/level_1/fl_strings/c/strings.h @@ -15,8 +15,8 @@ #include // fll includes -#include #include +#include #include #include diff --git a/level_2/fll_colors/c/colors.c b/level_2/fll_colors/c/colors.c index d504785..e9b2585 100644 --- a/level_2/fll_colors/c/colors.c +++ b/level_2/fll_colors/c/colors.c @@ -13,7 +13,7 @@ extern "C"{ #ifndef _di_fll_colors_load_context_ f_return_status fll_colors_load_context(fll_color_context *data, f_bool use_light_colors) { #ifndef _di_level_2_parameter_checking_ - if (data == 0) return f_invalid_parameter; + if (data == 0) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = f_status_initialize; @@ -33,21 +33,21 @@ extern "C"{ if (use_light_colors) { status = fl_save_color1(&data->reset, data->color_format, data->color_list.reset); - if (status == f_none) status = fl_save_color1(&data->warning, data->color_format, data->color_list.yellow); - if (status == f_none) status = fl_save_color2(&data->error, data->color_format, data->color_list.bold, data->color_list.red); - if (status == f_none) status = fl_save_color2(&data->title, data->color_format, data->color_list.bold, data->color_list.blue); - if (status == f_none) status = fl_save_color1(&data->notable, data->color_format, data->color_list.bold); - if (status == f_none) status = fl_save_color1(&data->important, data->color_format, data->color_list.blue); - if (status == f_none) status = fl_save_color1(&data->standout, data->color_format, data->color_list.purple); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->warning, data->color_format, data->color_list.yellow); + if (f_error_is_not_error(status)) status = fl_save_color2(&data->error, data->color_format, data->color_list.bold, data->color_list.red); + if (f_error_is_not_error(status)) status = fl_save_color2(&data->title, data->color_format, data->color_list.bold, data->color_list.blue); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->notable, data->color_format, data->color_list.bold); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->important, data->color_format, data->color_list.blue); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->standout, data->color_format, data->color_list.purple); } else { status = fl_save_color1(&data->reset, data->color_format, data->color_list.reset); - if (status == f_none) status = fl_save_color1(&data->warning, data->color_format, data->color_list.yellow); - if (status == f_none) status = fl_save_color2(&data->error, data->color_format, data->color_list.bold, data->color_list.red); - if (status == f_none) status = fl_save_color2(&data->title, data->color_format, data->color_list.bold, data->color_list.yellow); - if (status == f_none) status = fl_save_color1(&data->notable, data->color_format, data->color_list.bold); - if (status == f_none) status = fl_save_color2(&data->important, data->color_format, data->color_list.bold, data->color_list.green); - if (status == f_none) status = fl_save_color1(&data->standout, data->color_format, data->color_list.green); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->warning, data->color_format, data->color_list.yellow); + if (f_error_is_not_error(status)) status = fl_save_color2(&data->error, data->color_format, data->color_list.bold, data->color_list.red); + if (f_error_is_not_error(status)) status = fl_save_color2(&data->title, data->color_format, data->color_list.bold, data->color_list.yellow); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->notable, data->color_format, data->color_list.bold); + if (f_error_is_not_error(status)) status = fl_save_color2(&data->important, data->color_format, data->color_list.bold, data->color_list.green); + if (f_error_is_not_error(status)) status = fl_save_color1(&data->standout, data->color_format, data->color_list.green); } return status; diff --git a/level_2/fll_colors/c/colors.h b/level_2/fll_colors/c/colors.h index 422e115..6366e7b 100644 --- a/level_2/fll_colors/c/colors.h +++ b/level_2/fll_colors/c/colors.h @@ -45,36 +45,36 @@ extern "C"{ #define fll_new_color_context(status, color_context) \ f_resize_dynamic_string(status, color_context.reset, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.warning, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.error, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.title, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.notable, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.important, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.standout, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.normal, f_color_max_size + 1); \ - if (status == f_none) f_resize_dynamic_string(status, color_context.normal_reset, f_color_max_size + 1); + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.warning, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.error, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.title, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.notable, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.important, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.standout, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.normal, f_color_max_size + 1); \ + if (f_error_is_not_error(status)) f_resize_dynamic_string(status, color_context.normal_reset, f_color_max_size + 1); #define fll_delete_color_context(status, color_context) \ f_delete_dynamic_string(status, color_context.reset); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.warning); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.error); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.title); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.notable); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.important); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.standout); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.normal); \ - if (status == f_none) f_delete_dynamic_string(status, color_context.normal_reset); + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.warning); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.error); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.title); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.notable); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.important); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.standout); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.normal); \ + if (f_error_is_not_error(status)) f_delete_dynamic_string(status, color_context.normal_reset); #define fll_destroy_color_context(status, color_context, size) \ f_destroy_dynamic_string(status, color_context.reset); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.warning, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.error, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.title, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.notable, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.important, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.standout, size); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.normal); \ - if (status == f_none) f_destroy_dynamic_string(status, color_context.normal_reset); + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.warning, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.error, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.title, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.notable, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.important, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.standout, size); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.normal); \ + if (f_error_is_not_error(status)) f_destroy_dynamic_string(status, color_context.normal_reset); #endif // _di_fll_color_context_ #ifndef _di_fll_colors_load_context_ diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index 813a00b..89e4227 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -16,10 +16,10 @@ extern "C"{ #ifndef _di_fll_execute_path_ f_return_status fll_execute_path(const f_string program_path, const f_dynamic_strings arguments, f_s_int *results) { #ifndef _di_level_2_parameter_checking_ - if (results == f_null) return f_invalid_parameter; + if (results == f_null) return f_error_set_error(f_invalid_parameter); - if (arguments.used < 0) return f_invalid_parameter; - if (arguments.used > arguments.size) return f_invalid_parameter; + if (arguments.used < 0) return f_error_set_error(f_invalid_parameter); + if (arguments.used > arguments.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ // create a string array that is compatible with execv() calls @@ -38,7 +38,7 @@ extern "C"{ if (name_size > 1) { f_new_string(status, program_name, name_size + 1); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; memcpy(program_name, last_slash + 1, name_size); memset(program_name, name_size, 0); @@ -49,7 +49,7 @@ extern "C"{ status = f_new_array((void **) & arguments_array, sizeof(f_autochar **), arguments.used + 2); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_status tmp_status = f_status_initialize; f_delete_string(tmp_status, program_name, name_size); @@ -76,7 +76,7 @@ extern "C"{ process_id = vfork(); if (process_id < 0) { - return f_fork_failed; + return f_error_set_error(f_fork_failed); } if (process_id == 0) { // child @@ -92,7 +92,7 @@ extern "C"{ if (name_size > 0) f_delete_string(status, program_name, name_size); f_delete((void **) & arguments_array, sizeof(f_autochar), arguments.used + 2); - if (*results != 0) return f_failure; + if (*results != 0) return f_error_set_error(f_failure); return f_none; } @@ -101,10 +101,10 @@ extern "C"{ #ifndef _di_fll_execute_program_ f_return_status fll_execute_program(const f_string program_name, const f_dynamic_strings arguments, f_s_int *results) { #ifndef _di_level_2_parameter_checking_ - if (results == f_null) return f_invalid_parameter; + if (results == f_null) return f_error_set_error(f_invalid_parameter); - if (arguments.used < 0) return f_invalid_parameter; - if (arguments.used > arguments.size) return f_invalid_parameter; + if (arguments.used < 0) return f_error_set_error(f_invalid_parameter); + if (arguments.used > arguments.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ // create a string array that is compatible with execv() calls @@ -113,7 +113,7 @@ extern "C"{ status = f_new_array((void **) & arguments_array, sizeof(f_autochar **), arguments.used + 2); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; { f_string_length counter = f_string_length_initialize; @@ -135,7 +135,7 @@ extern "C"{ process_id = vfork(); if (process_id < 0) { - return f_fork_failed; + return f_error_set_error(f_fork_failed); } if (process_id == 0) { // child @@ -150,7 +150,7 @@ extern "C"{ f_delete((void **) & arguments_array, sizeof(f_autochar), arguments.used + 2); - if (*results != 0) return f_failure; + if (*results != 0) return f_error_set_error(f_failure); return f_none; } diff --git a/level_2/fll_execute/c/execute.h b/level_2/fll_execute/c/execute.h index 988f81e..e315a27 100644 --- a/level_2/fll_execute/c/execute.h +++ b/level_2/fll_execute/c/execute.h @@ -19,9 +19,9 @@ #include // fll-0 includes -#include #include #include +#include #include // fll-1 includes diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index eb02e88..f1ee7c2 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -13,9 +13,9 @@ extern "C"{ #ifndef _di_fll_fss_basic_read_ f_return_status fll_fss_basic_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (objects == f_null) return f_invalid_parameter; - if (contents == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (objects == f_null) return f_error_set_error(f_invalid_parameter); + if (contents == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = f_status_initialize; @@ -26,13 +26,13 @@ extern "C"{ if (objects->used >= objects->size) { f_resize_fss_objects(status, (*objects), objects->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } f_resize_fss_contents(status, (*contents), contents->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -49,7 +49,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -87,7 +87,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -137,8 +137,8 @@ extern "C"{ #ifndef _di_fll_fss_basic_write_ f_return_status fll_fss_basic_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (contents.used > contents.size) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = 0; @@ -166,7 +166,7 @@ extern "C"{ } else { if (buffer->used >= buffer->size) { f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer->used] = f_eol; diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index 6924728..33c8e7f 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -11,9 +11,9 @@ #define _FLL_fss_basic_h // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index ef97455..2858f9f 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -13,9 +13,9 @@ extern "C"{ #ifndef _di_fll_fss_basic_list_read_ f_return_status fll_fss_basic_list_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (objects == f_null) return f_invalid_parameter; - if (contents == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (objects == f_null) return f_error_set_error(f_invalid_parameter); + if (contents == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = f_status_initialize; @@ -26,13 +26,13 @@ extern "C"{ if (objects->used >= objects->size) { f_resize_fss_objects(status, (*objects), objects->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } f_resize_fss_contents(status, (*contents), contents->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -49,7 +49,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -87,7 +87,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -130,15 +130,15 @@ extern "C"{ contents->used++; } while (f_true); - return f_unknown; + return f_error_is_error(f_unknown); } #endif // _di_fll_fss_basic_list_read_ #ifndef _di_fll_fss_basic_list_write_ f_return_status fll_fss_basic_list_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (contents.used > contents.size) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = 0; @@ -166,7 +166,7 @@ extern "C"{ } else { if (buffer->used >= buffer->size) { f_resize_dynamic_string(status, (*buffer), buffer->size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_error_is_error(status)) return status; } buffer->string[buffer->used] = f_eol; diff --git a/level_2/fll_fss/c/fss_basic_list.h b/level_2/fll_fss/c/fss_basic_list.h index f99ec3d..375a3b7 100644 --- a/level_2/fll_fss/c/fss_basic_list.h +++ b/level_2/fll_fss/c/fss_basic_list.h @@ -11,9 +11,9 @@ #define _FLL_fss_basic_list_h // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_2/fll_fss/c/fss_errors.c b/level_2/fll_fss/c/fss_errors.c index ab9bcff..d8fe601 100644 --- a/level_2/fll_fss/c/fss_errors.c +++ b/level_2/fll_fss/c/fss_errors.c @@ -13,10 +13,12 @@ extern "C"{ #ifndef _di_fll_fss_errors_to_string_ f_return_status fll_fss_errors_to_string(const f_status error, f_string *string) { #ifndef _di_level_2_parameter_checking_ - if (string == f_null) return f_invalid_parameter; + if (string == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ - switch (error) { + f_status unmasked_error = f_error_unmask(error); + + switch (unmasked_error) { #ifndef _di_fll_fss_errors_error_ case fl_fss_invalid_format: *string = "fl_fss_invalid_format"; @@ -68,7 +70,7 @@ extern "C"{ #ifndef _di_fll_fss_errors_is_error_ f_return_status fll_fss_errors_is_error(const f_status error) { - if (fll_fss_errors_is_okay(error) == f_true) { + if (fll_fss_errors_is_fine(error) == f_true) { return f_false; } else if (fll_fss_errors_is_warning(error) == f_true) { return f_false; @@ -106,8 +108,8 @@ extern "C"{ } #endif // _di_fll_fss_errors_is_warning_ -#ifndef _di_fll_fss_errors_is_okay_ - f_return_status fll_fss_errors_is_okay(const f_status error) { +#ifndef _di_fll_fss_errors_is_fine_ + f_return_status fll_fss_errors_is_fine(const f_status error) { switch (error) { #ifndef _di_fll_fss_errors_booleans_ case f_false: @@ -137,7 +139,7 @@ extern "C"{ return f_false; } -#endif // _di_fll_fss_errors_is_okay_ +#endif // _di_fll_fss_errors_is_fine_ #ifdef __cplusplus } // extern "C" diff --git a/level_2/fll_fss/c/fss_errors.h b/level_2/fll_fss/c/fss_errors.h index 89bec53..34203e7 100644 --- a/level_2/fll_fss/c/fss_errors.h +++ b/level_2/fll_fss/c/fss_errors.h @@ -11,9 +11,9 @@ #define _FLL_fss_errors_h // fll-0 includes -#include -#include #include +#include +#include #include #include @@ -46,11 +46,11 @@ extern "C"{ #endif // _di_fll_fss_errors_is_warning_ -#ifndef _di_fll_fss_errors_is_okay_ +#ifndef _di_fll_fss_errors_is_fine_ // Returns true or false depending on whether the standard context of the error code represents an normal return status and not an error. - // Keep in mind that many of the error codes are context-specific and may be reported as "okay" here when it is in fact not okay. - extern f_return_status fll_fss_errors_is_okay(const f_status error); -#endif // _di_fll_fss_errors_is_okay_ + // Keep in mind that many of the error codes are context-specific and may be reported as "fine" here when it is in fact not fine. + extern f_return_status fll_fss_errors_is_fine(const f_status error); +#endif // _di_fll_fss_errors_is_fine_ #ifdef __cplusplus } // extern "C" diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index ff2573b..1f8bdb6 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -13,9 +13,9 @@ extern "C"{ #ifndef _di_fll_fss_extended_read_ f_return_status fll_fss_extended_read(f_dynamic_string *buffer, f_string_location *input, f_fss_objects *objects, f_fss_contents *contents) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (objects == f_null) return f_invalid_parameter; - if (contents == f_null) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (objects == f_null) return f_error_set_error(f_invalid_parameter); + if (contents == f_null) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = f_status_initialize; @@ -26,13 +26,13 @@ extern "C"{ if (objects->used >= objects->size) { f_resize_fss_objects(status, (*objects), objects->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } f_resize_fss_contents(status, (*contents), contents->used + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -49,7 +49,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -87,7 +87,7 @@ extern "C"{ f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -137,8 +137,8 @@ extern "C"{ #ifndef _di_fll_fss_extended_write_ f_return_status fll_fss_extended_write(const f_dynamic_string object, const f_dynamic_strings contents, f_dynamic_string *buffer) { #ifndef _di_level_2_parameter_checking_ - if (buffer == f_null) return f_invalid_parameter; - if (contents.used > contents.size) return f_invalid_parameter; + if (buffer == f_null) return f_error_set_error(f_invalid_parameter); + if (contents.used > contents.size) return f_error_set_error(f_invalid_parameter); #endif // _di_level_2_parameter_checking_ f_status status = 0; diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index c97ae7a..56efbbf 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -11,9 +11,9 @@ #define _FLL_fss_extended_h // fll-0 includes -#include -#include #include +#include +#include #include #include diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index ebb9a63..8b7ba54 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -126,7 +126,9 @@ extern "C"{ } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -134,14 +136,14 @@ extern "C"{ // nothing can be 0 as that represents the program name, unless argv[] is improperly created } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter) { + } else if (f_error_unmask(status) == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } firewall_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -243,7 +245,7 @@ extern "C"{ f_resize_dynamic_strings(status, arguments, 7); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { fl_print_color_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); @@ -280,7 +282,7 @@ extern "C"{ fflush(f_standard_output); } - if (status != f_failure && show_mangle) { + if (f_error_is_not_error(status) && show_mangle) { fl_print_color(f_standard_output, data->context.standout, data->context.reset, "========================== "); fl_print_color(f_standard_output, data->context.title, data->context.reset, "MANGLE"); fl_print_color_line(f_standard_output, data->context.standout, data->context.reset, " =========================="); @@ -310,7 +312,7 @@ extern "C"{ fflush(f_standard_output); } - if (status != f_failure && show_ports) { + if (f_error_is_not_error(status) && show_ports) { fl_print_color(f_standard_output, data->context.standout, data->context.reset, "========================== "); fl_print_color(f_standard_output, data->context.title, data->context.reset, "PORTS"); fl_print_color_line(f_standard_output, data->context.standout, data->context.reset, " ==========================="); @@ -336,22 +338,28 @@ extern "C"{ fflush(f_standard_output); } - if (status == f_failure) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_program_name); - fprintf(f_standard_error, " "); + if (f_error_is_error(status)) { + status = f_error_unmask(status); + + if (f_macro_test_for_allocation_errors(status)) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + } else { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_program_name); + fprintf(f_standard_error, " "); + + f_string_length i = f_string_length_initialize; - f_string_length i = f_string_length_initialize; + fl_print_color_code(f_standard_error, data->context.error); - fl_print_color_code(f_standard_error, data->context.error); + for (; i < arguments.used; i++) { + fprintf(f_standard_error, "%s ", arguments.array[i].string); + } - for (; i < arguments.used; i++) { - fprintf(f_standard_error, "%s ", arguments.array[i].string); + fl_print_color_code(f_standard_error, data->context.reset); + fprintf(f_standard_error, "\n"); } - fl_print_color_code(f_standard_error, data->context.reset); - fprintf(f_standard_error, "\n"); - } else if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + status = f_error_set_error(status); } arguments.array[0].string = 0; @@ -372,27 +380,26 @@ extern "C"{ f_delete_dynamic_strings(status, arguments); firewall_delete_local_data(&local); firewall_delete_data(data); - return f_none; + return status; } // load all network devices status = fl_directory_list((f_string) network_devices, &data->devices); - if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - firewall_delete_local_data(&local); - firewall_delete_data(data); - return status; - } else if (status == f_no_data) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: could not find any network devices"); - firewall_delete_local_data(&local); - firewall_delete_data(data); - return status; - } else if (status == f_failure) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: failed to read the device directory '%s'", network_devices); + if (f_error_is_error(status)) { + status = f_error_unmask(status); + + if (f_macro_test_for_allocation_errors(status)) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); + } else if (status == f_no_data) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: could not find any network devices"); + } else if (status == f_failure) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: failed to read the device directory '%s'", network_devices); + } + firewall_delete_local_data(&local); firewall_delete_data(data); - return status; + return f_error_set_error(status); } // remove "lo" (loopback) from the device listing @@ -417,7 +424,7 @@ extern "C"{ if (command == firewall_parameter_command_stop || command == firewall_parameter_command_restart || command == firewall_parameter_command_lock) { status = firewall_buffer_rules(network_path firewall_file_other, f_false, &local, data); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -477,7 +484,7 @@ extern "C"{ status = firewall_process_rules(&input, &local, data); - if (status != f_none || command == firewall_parameter_command_stop) { + if (f_error_is_error(status) || command == firewall_parameter_command_stop) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -497,7 +504,7 @@ extern "C"{ if (command == firewall_parameter_command_start || command == firewall_parameter_command_restart) { status = firewall_buffer_rules(network_path firewall_file_first, f_false, &local, data); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -505,7 +512,7 @@ extern "C"{ status = firewall_create_custom_chains(&reserved, &local, data); - if (status != f_none) { + if (f_error_is_error(status)) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -526,7 +533,7 @@ extern "C"{ status = firewall_process_rules(&input, &local, data); - if ((status != f_none && status != f_no_data && status != f_no_data_on_stop) || command == firewall_parameter_command_stop) { + if (f_error_is_error(status) || command == firewall_parameter_command_stop) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -545,8 +552,8 @@ extern "C"{ f_resize_dynamic_string(status, file_path, network_path_length + data->devices.array[i].used + firewall_file_suffix_length + 1); - if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory.", status); + if (f_error_is_error(status)) { + fl_print_color_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; @@ -563,20 +570,23 @@ extern "C"{ f_delete_dynamic_string(status2, file_path); } - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos && status != f_none_on_stop) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + firewall_delete_local_data(&local); if (status == f_file_not_found || status == f_file_open_error || status == f_file_descriptor_error || status == fl_fss_found_object_no_content) { + status = f_error_set_error(status); continue; } firewall_delete_data(data); - return status; + return f_error_set_error(status); } status = firewall_create_custom_chains(&reserved, &local, data); - if (status != f_none) { + if (f_error_is_error(status)) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -597,7 +607,7 @@ extern "C"{ status = firewall_process_rules(&input, &local, data); - if ((status != f_none && status != f_no_data && status != f_no_data_on_stop) || command == firewall_parameter_command_stop) { + if (f_error_is_error(status) || command == firewall_parameter_command_stop) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -619,7 +629,7 @@ extern "C"{ status = firewall_buffer_rules(network_path firewall_file_last, f_false, &local, data); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -627,7 +637,7 @@ extern "C"{ status = firewall_create_custom_chains(&reserved, &local, data); - if (status != f_none) { + if (f_error_is_error(status)) { firewall_macro_delete_fss_buffers(status2, local.buffer, local.chain_objects, local.chain_contents) firewall_delete_data(data); return status; @@ -648,7 +658,7 @@ extern "C"{ status = firewall_process_rules(&input, &local, data); - if (status != f_none || command == firewall_parameter_command_stop) { + if (f_error_is_error(status) || command == firewall_parameter_command_stop) { firewall_delete_local_data(&local); firewall_delete_data(data); return status; @@ -662,7 +672,7 @@ extern "C"{ firewall_delete_local_data(&local); } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: You did not pass a command"); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } } diff --git a/level_3/firewall/c/private-firewall.c b/level_3/firewall/c/private-firewall.c index 5fd48a0..3ba6f5a 100644 --- a/level_3/firewall/c/private-firewall.c +++ b/level_3/firewall/c/private-firewall.c @@ -36,7 +36,7 @@ } else { f_resize_dynamic_string(status, device, data.devices.array[local.device].used); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_string(status2, device); return status; @@ -150,7 +150,7 @@ f_delete_dynamic_string(status, device); f_resize_dynamic_string(status, device, data.devices.array[local.device].used); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(device.string, data.devices.array[local.device].string, data.devices.array[local.device].used); device.used = data.devices.array[local.device].used; @@ -162,7 +162,7 @@ f_delete_dynamic_string(status, device); f_resize_dynamic_string(status, device, length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(device.string, local.buffer.string + local.rule_contents.array[i].array[0].start, length); device.used = length; @@ -213,7 +213,7 @@ f_delete_dynamic_string(status, protocol); f_resize_dynamic_string(status, protocol, length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; if (fl_compare_strings(local.buffer.string + local.rule_objects.array[i].start, (f_string) firewall_protocol_none, length, firewall_protocol_none_length) == f_equal_to) { use_protocol = f_false; @@ -263,11 +263,11 @@ f_delete_dynamic_strings(status, arguments); f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; f_resize_dynamic_string(status, argument, firewall_program_name_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_program_name, firewall_program_name_length); argument.used = firewall_program_name_length; @@ -287,21 +287,21 @@ if (action == firewall_action_append_id) { f_resize_dynamic_string(status, argument, firewall_action_append_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_action_append_command, firewall_action_append_command_length); argument.used = firewall_action_append_command_length; } else if (action == firewall_action_insert_id) { f_resize_dynamic_string(status, argument, firewall_action_insert_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_action_insert_command, firewall_action_insert_command_length); argument.used = firewall_action_insert_command_length; } else if (action == firewall_action_policy_id) { f_resize_dynamic_string(status, argument, firewall_action_policy_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_action_policy_command, firewall_action_policy_command_length); argument.used = firewall_action_policy_command_length; @@ -310,7 +310,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -326,7 +326,7 @@ if (!(local.is_main || local.is_stop || local.is_lock)) { f_resize_dynamic_string(status, argument, data.chains.array[local.chain_ids.array[local.chain]].used); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, data.chains.array[local.chain_ids.array[local.chain]].string, data.chains.array[local.chain_ids.array[local.chain]].used); argument.used = data.chains.array[local.chain].used; @@ -334,35 +334,35 @@ } else if (direction == firewall_direction_forward_id) { f_resize_dynamic_string(status, argument, firewall_direction_forward_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_direction_forward_command, firewall_direction_forward_command_length); argument.used = firewall_direction_forward_command_length; } else if (direction == firewall_direction_postrouting_id) { f_resize_dynamic_string(status, argument, firewall_direction_postrouting_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_direction_postrouting_command, firewall_direction_postrouting_command_length); argument.used += firewall_direction_postrouting_command_length; } else if (direction == firewall_direction_prerouting_id) { f_resize_dynamic_string(status, argument, firewall_direction_prerouting_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_direction_prerouting_command, firewall_direction_prerouting_command_length); argument.used = firewall_direction_prerouting_command_length; } else if (direction_input) { f_resize_dynamic_string(status, argument, firewall_direction_input_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_direction_input_command, firewall_direction_input_command_length); argument.used = firewall_direction_input_command_length; } else if (direction_output) { f_resize_dynamic_string(status, argument, firewall_direction_output_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_direction_output_command, firewall_direction_output_command_length); argument.used = firewall_direction_output_command_length; @@ -372,7 +372,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -387,13 +387,13 @@ if (length < firewall_device_all_length || fl_compare_strings(local.buffer.string + local.rule_contents.array[i].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_not_equal_to) { if (direction_input) { f_resize_dynamic_string(status, argument, firewall_device_input_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_device_input_command, firewall_device_input_command_length); argument.used = firewall_device_input_command_length; } else if (direction_output) { f_resize_dynamic_string(status, argument, firewall_device_output_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_device_output_command, firewall_device_output_command_length); argument.used = firewall_device_output_command_length; @@ -403,7 +403,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -416,7 +416,7 @@ if (direction_input || direction_output) { f_resize_dynamic_string(status, argument, device.used); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, device.string, device.used); argument.used = device.used; @@ -426,7 +426,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -439,7 +439,7 @@ if (use_protocol) { f_resize_dynamic_string(status, argument, firewall_protocol_command_length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, firewall_protocol_command, firewall_protocol_command_length); argument.used = firewall_protocol_command_length; @@ -447,7 +447,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -459,7 +459,7 @@ } f_resize_dynamic_string(status, argument, protocol.used); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, protocol.string, protocol.used); argument.used = protocol.used; @@ -468,7 +468,7 @@ if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -491,7 +491,7 @@ f_resize_dynamic_string(status, ip_list, length); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { subcounter = local.rule_contents.array[i].used; } else { strncat(ip_list.string, local.buffer.string + local.rule_contents.array[i].array[subcounter].start, length); @@ -506,7 +506,7 @@ f_resize_dynamic_string(status, argument, length); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; strncat(argument.string, local.buffer.string + local.rule_contents.array[i].array[subcounter].start, length); argument.used = length; @@ -514,7 +514,7 @@ if (length > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); - if (f_macro_test_for_allocation_errors(status)) break; + if (f_error_is_error(status)) break; arguments.array[arguments.used].string = argument.string; arguments.array[arguments.used].size = argument.size; @@ -559,7 +559,9 @@ status = f_file_open(&file, file_path.string); } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -571,9 +573,13 @@ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: File descriptor error while trying to open the file '%s'", file_path.string); } else if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); + } + + if (status != f_file_not_found) { + status = f_error_set_error(status); } f_file_close(&file); @@ -588,7 +594,9 @@ f_file_close(&file); - if (status != f_none && status != f_none_on_eof) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); } else if (status == f_overflow) { @@ -600,10 +608,12 @@ } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: A read error occurred while accessing the file '%s'", file_path.string); } else if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", status); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } + + status = f_error_set_error(status); } else { { f_string_location input = f_string_location_initialize; @@ -613,16 +623,20 @@ status = fll_fss_basic_read(&local_buffer, &input, &basic_objects, &basic_contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_set_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_read() for the file '%s'", file_path.string); } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { // empty files are to be silently ignored } else if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_read() for the file '%s'", status, file_path.string); + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_read() for the file '%s'", f_error_set_error(status), file_path.string); } + + status = f_error_set_error(status); } else { f_string_length buffer_counter = f_string_length_initialize; f_string_length ip_length = f_string_length_initialize; @@ -640,15 +654,15 @@ ip_list_action.used = ip_list_action.size; ip_list_action.string[ip_list_action.used] = 0; - if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + if (f_error_is_error(status)) { + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { ip_list_action.used = ip_list_action.size; f_resize_dynamic_strings(status, arguments, arguments.used + 2); - if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + if (f_error_is_error(status)) { + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { arguments.array[arguments.used].string = ip_list_action.string; arguments.array[arguments.used].size = ip_list_action.size; @@ -661,8 +675,8 @@ f_resize_dynamic_string(status, ip_argument, ip_length); - if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", status); + if (f_error_is_error(status)) { + fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory"); break; } @@ -794,19 +808,19 @@ local->chain_ids.used = 0; - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } f_resize_dynamic_strings(status, arguments, 3); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { return status; } f_resize_dynamic_string(status, arguments.array[0], firewall_program_name_length); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -814,7 +828,7 @@ f_resize_dynamic_string(status, arguments.array[1], firewall_chain_create_command_length); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -893,7 +907,7 @@ if (data->chains.used >= data->chains.size) { f_resize_dynamic_strings(status, data->chains, data->chains.used + firewall_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -903,7 +917,7 @@ if (length >= arguments.array[2].size) { f_resize_dynamic_string(status, arguments.array[2], length + firewall_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -912,7 +926,7 @@ f_resize_dynamic_string(status, data->chains.array[data->chains.used], length); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -938,7 +952,7 @@ f_resize_dynamic_string(status, data->chains.array[data->chains.used], data->chains.array[data->chains.used].used); - if (f_macro_test_for_allocation_errors(status)) { + if (f_error_is_error(status)) { f_delete_dynamic_strings(status2, arguments); return status; @@ -946,29 +960,31 @@ status = fll_execute_program((f_string) firewall_program_name, arguments, &results); - if (status == f_failure) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_program_name); - fprintf(f_standard_error, " "); + if (f_error_is_error(status)) { + status = f_error_unmask(status); - f_string_length i = f_string_length_initialize; + if (status == f_failure) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Failed to perform requested %s operation:", firewall_program_name); + fprintf(f_standard_error, " "); - fl_print_color_code(f_standard_error, data->context.error); + f_string_length i = f_string_length_initialize; - for (; i < arguments.used; i++) { - fprintf(f_standard_error, "%s ", arguments.array[i].string); - } + fl_print_color_code(f_standard_error, data->context.error); - fl_print_color_code(f_standard_error, data->context.reset); - fprintf(f_standard_error, "\n"); + for (; i < arguments.used; i++) { + fprintf(f_standard_error, "%s ", arguments.array[i].string); + } - f_delete_dynamic_strings(status2, arguments); + fl_print_color_code(f_standard_error, data->context.reset); + fprintf(f_standard_error, "\n"); + } else if (status == f_invalid_parameter) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_execute_path()"); + } else { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_execute_program()", f_error_set_error(status)); + } - return status; - } else if (status == f_invalid_parameter) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_execute_path()"); f_delete_dynamic_strings(status2, arguments); - - return status; + return f_error_set_error(status); } data->chains.used++; @@ -988,36 +1004,42 @@ status = f_file_open(&file, filename); - if (optional && status != f_none) { - if (status == f_invalid_parameter) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); - } else if (status != f_file_not_found && status != f_file_open_error && status != f_file_descriptor_error) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); - } + if (f_error_is_error(status)) { + status = f_error_unmask(status); - return status; - } else if (status != f_none) { - if (status == f_invalid_parameter) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); - } else if (status == f_file_not_found) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'.", filename); - } else if (status == f_file_open_error) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'.", filename); - } else if (status == f_file_descriptor_error) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'.", filename); + if (optional) { + if (status == f_invalid_parameter) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); + } else if (status != f_file_not_found && status != f_file_open_error && status != f_file_descriptor_error) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_error_set_error(status)); + } } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", status); + if (status == f_invalid_parameter) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()."); + } else if (status == f_file_not_found) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'.", filename); + } else if (status == f_file_open_error) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'.", filename); + } else if (status == f_file_descriptor_error) { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'.", filename); + } else { + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open().", f_error_set_error(status)); + } } - return status; + return f_error_set_error(status); } f_macro_file_reset_position(local->file_position, file) + + fflush(stdout); status = fl_file_read(file, local->file_position, &local->buffer); f_file_close(&file); - if (status != f_none && status != f_none_on_eof) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()."); } else if (status == f_overflow) { @@ -1031,10 +1053,10 @@ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read().", f_error_set_error(status)); } - return status; + return f_error_set_error(status); } else { f_string_location input = f_string_location_initialize; @@ -1043,7 +1065,9 @@ status = fll_fss_basic_list_read(&local->buffer, &input, &local->chain_objects, &local->chain_contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'.", filename); } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { @@ -1051,10 +1075,10 @@ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'.", status, filename); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'.", f_error_set_error(status), filename); } - return status; + return f_error_set_error(status); } return status; @@ -1068,22 +1092,23 @@ status = fll_fss_extended_read(&local->buffer, input, &local->rule_objects, &local->rule_contents); - - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { + if (f_error_is_not_error(status)) { status = firewall_perform_commands(*local, *data); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (f_macro_test_for_allocation_errors(status)) { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory.", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); } else if (status == f_failure) { // the error message has already been displayed. } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling firewall_perform_commands().", f_error_set_error(status)); } f_delete_fss_objects(status2, local->rule_objects); f_delete_fss_contents(status2, local->rule_contents); - return status; + return f_error_set_error(status); } } diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index f3b0766..78d200e 100644 --- a/level_3/fss_basic_list_read/c/fss_basic_list_read.c +++ b/level_3/fss_basic_list_read/c/fss_basic_list_read.c @@ -132,25 +132,27 @@ extern "C"{ f_return_status fss_basic_list_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal"))); f_return_status fss_basic_list_read_main(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_basic_list_read_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_basic_list_read_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_basic_list_read_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_list_read_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_basic_list_read_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -161,11 +163,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } fss_basic_list_read_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -189,7 +191,9 @@ extern "C"{ status = fl_file_read_fifo(file, &data->buffer); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -199,7 +203,7 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_basic_list_read_delete_data(data); @@ -208,14 +212,14 @@ extern "C"{ status = fss_basic_list_read_main_process_file(argc, argv, data, "-", target); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before continuing - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } for (; counter < data->remaining.used; counter++) { @@ -225,7 +229,9 @@ extern "C"{ data->file_position.total_elements = original_size; - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -235,14 +241,13 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_basic_list_read_delete_data(data); - return status; + return f_error_set_error(status); } - // TODO: this file size set functionality might be turned into an fl_file (or f_file) function if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); @@ -261,7 +266,9 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); } else if (status == f_overflow) { @@ -275,27 +282,27 @@ extern "C"{ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } fss_basic_list_read_delete_data(data); - return status; + return f_error_set_error(status); } status = fss_basic_list_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before repeating the loop - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } // for } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } fss_basic_list_read_delete_data(data); @@ -303,11 +310,11 @@ extern "C"{ } f_return_status fss_basic_list_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data, const f_string filename, const f_string_length target) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; f_string_length current = f_string_length_initialize; - f_string_length found = f_string_length_initialize; + f_string_length found = f_string_length_initialize; { f_string_location input = f_string_location_initialize; @@ -318,29 +325,26 @@ extern "C"{ status = fll_fss_basic_list_read(&data->buffer, &input, &data->objects, &data->contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - - fss_basic_list_read_delete_data(data); - return status; - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop || status == f_no_data_on_eof) { - // not an error in this case } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - - fss_basic_list_read_delete_data(data); - return status; } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", status, filename); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_error_set_error(status), filename); } + fss_basic_list_read_delete_data(data); + return f_error_set_error(status); + } else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); - return status; + return f_error_set_warning(status); } // now that all of the files have been read, process the objects and contents 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 d87790c..a324e69 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 @@ -104,25 +104,27 @@ extern "C"{ #ifndef _di_fss_basic_list_write_main_ f_return_status fss_basic_list_write_main(const f_array_length argc, const f_string argv[], fss_basic_list_write_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_basic_list_write_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_basic_list_write_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_basic_list_write_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_list_write_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_basic_list_write_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -133,11 +135,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } fss_basic_list_write_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -160,7 +162,9 @@ extern "C"{ status = fl_file_read_fifo(file, &input); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -170,12 +174,12 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } - f_delete_dynamic_string(status, input); + f_delete_dynamic_string(status2, input); fss_basic_list_write_delete_data(data); - return status; + return f_error_set_error(status); } location.start = 0; @@ -184,14 +188,14 @@ extern "C"{ if (object) { status = fl_fss_basic_list_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { status = fl_fss_basic_list_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } @@ -208,14 +212,14 @@ extern "C"{ if (object) { status = fl_fss_basic_list_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { status = fl_fss_basic_list_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } @@ -228,7 +232,9 @@ extern "C"{ output.mode = f_file_write_append; status = f_file_open(&output, argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + f_file_close(&output); if (status == f_invalid_parameter) { @@ -240,27 +246,29 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_basic_list_write_delete_data(data); - return status; + return f_error_set_error(status); } status = fl_file_write(output, buffer); f_file_close(&output); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()"); } else if (status == f_file_write_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_basic_list_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_basic_list_write_delete_data(data); - return status; + return f_error_set_error(status); } } else { f_print_dynamic_string(f_standard_output, buffer); @@ -274,8 +282,8 @@ extern "C"{ #ifndef _di_fss_basic_list_write_delete_data_ f_return_status fss_basic_list_write_delete_data(fss_basic_list_write_data *data) { - f_status status = f_status_initialize; - f_string_length i = 0; + f_status status = f_status_initialize; + f_string_length i = 0; while (i < fss_basic_list_write_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); 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 1b2e07a..091f05c 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -118,25 +118,27 @@ extern "C"{ f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility("internal"))); f_return_status fss_basic_read_main(const f_array_length argc, const f_string argv[], fss_basic_read_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_basic_read_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_basic_read_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_basic_read_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_read_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_basic_read_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -147,11 +149,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } fss_basic_read_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -175,7 +177,9 @@ extern "C"{ status = fl_file_read_fifo(file, &data->buffer); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); } else if (status == f_overflow) { @@ -189,23 +193,23 @@ extern "C"{ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", "-"); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } fss_basic_read_delete_data(data); - return status; + return f_error_set_error(status); } status = fss_basic_read_main_process_file(argc, argv, data, "-", target); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before continuing - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } if (data->remaining.used > 0) { @@ -216,7 +220,9 @@ extern "C"{ data->file_position.total_elements = original_size; - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -226,14 +232,13 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_basic_read_delete_data(data); - return status; + return f_error_set_error(status); } - // TODO: this file size set functionality might be turned into an fl_file (or f_file) function if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); @@ -252,7 +257,9 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); } else if (status == f_overflow) { @@ -266,28 +273,28 @@ extern "C"{ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", argv[data->remaining.array[counter]]); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } fss_basic_read_delete_data(data); - return status; + return f_error_set_error(status); } status = fss_basic_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before repeating the loop - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } // for } } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } fss_basic_read_delete_data(data); @@ -295,11 +302,11 @@ extern "C"{ } f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; f_string_length current = f_string_length_initialize; - f_string_length found = f_string_length_initialize; + f_string_length found = f_string_length_initialize; { f_string_location input = f_string_location_initialize; @@ -310,29 +317,26 @@ extern "C"{ status = fll_fss_basic_read(&data->buffer, &input, &data->objects, &data->contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_basic_list_read() for the file '%s'", filename); - - fss_basic_read_delete_data(data); - return status; - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop || status == f_no_data_on_eof) { - // not an error in this case } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - - fss_basic_read_delete_data(data); - return status; } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", status, filename); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_basic_list_read() for the file '%s'", f_error_set_error(status), filename); } + fss_basic_read_delete_data(data); + return f_error_set_error(status); + } else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); - return f_none; + return f_error_set_warning(status); } // now that the file has been read, process the objects and contents 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 28aabf6..82ee763 100644 --- a/level_3/fss_basic_write/c/fss_basic_write.c +++ b/level_3/fss_basic_write/c/fss_basic_write.c @@ -104,25 +104,27 @@ extern "C"{ #ifndef _di_fss_basic_write_main_ f_return_status fss_basic_write_main(const f_array_length argc, const f_string argv[], fss_basic_write_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_basic_write_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_basic_write_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_basic_write_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_basic_write_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_basic_write_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -133,11 +135,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } fss_basic_write_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -160,7 +162,9 @@ extern "C"{ status = fl_file_read_fifo(file, &input); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -170,12 +174,12 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } - f_delete_dynamic_string(status, input); + f_delete_dynamic_string(status2, input); fss_basic_write_delete_data(data); - return status; + return f_error_set_error(status); } location.start = 0; @@ -184,14 +188,14 @@ extern "C"{ if (object) { status = fl_fss_basic_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { status = fl_fss_basic_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } @@ -208,14 +212,14 @@ extern "C"{ if (object) { status = fl_fss_basic_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { status = fl_fss_basic_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } @@ -228,7 +232,9 @@ extern "C"{ output.mode = f_file_write_append; status = f_file_open(&output, argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + f_file_close(&output); if (status == f_invalid_parameter) { @@ -240,7 +246,7 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_basic_write_delete_data(data); @@ -250,17 +256,19 @@ extern "C"{ status = fl_file_write(output, buffer); f_file_close(&output); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()"); } else if (status == f_file_write_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_basic_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_basic_write_delete_data(data); - return status; + return f_error_set_error(status); } } else { f_print_dynamic_string(f_standard_output, buffer); @@ -274,8 +282,8 @@ extern "C"{ #ifndef _di_fss_basic_write_delete_data_ f_return_status fss_basic_write_delete_data(fss_basic_write_data *data) { - f_status status = f_status_initialize; - f_string_length i = 0; + f_status status = f_status_initialize; + f_string_length i = 0; while (i < fss_basic_write_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); diff --git a/level_3/fss_extended_read/c/fss_extended_read.c b/level_3/fss_extended_read/c/fss_extended_read.c index af2782d..61fd032 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -125,25 +125,27 @@ extern "C"{ f_return_status fss_extended_read_main_process_file(const f_array_length argc, const f_string argv[], fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) __attribute__((visibility("internal"))); f_return_status fss_extended_read_main(const f_array_length argc, const f_string argv[], fss_extended_read_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_extended_read_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_extended_read_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_extended_read_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_extended_read_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_extended_read_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -154,11 +156,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters()", f_error_set_error(status)); } fss_extended_read_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -187,7 +189,9 @@ extern "C"{ status = fl_file_read_fifo(file, &data->buffer); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -197,24 +201,24 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_extended_read_delete_data(data); - return status; + return f_error_set_error(status); } status = fss_extended_read_main_process_file(argc, argv, data, "-", target, select); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before continuing - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } for (; counter < data->remaining.used; counter++) { @@ -224,7 +228,9 @@ extern "C"{ data->file_position.total_elements = original_size; - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -234,14 +240,20 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_extended_read_delete_data(data); - return status; + return f_error_set_error(status); + } else if (f_macro_test_for_no_data_errors(status)) { + // clear buffers, then attempt the next file + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); + + return f_error_set_warning(status); } - // TODO: this file size set functionality might be turned into an fl_file (or f_file) function if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); @@ -260,7 +272,9 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); } else if (status == f_overflow) { @@ -274,27 +288,27 @@ extern "C"{ } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_read()", f_error_set_error(status)); } fss_extended_read_delete_data(data); - return status; + return f_error_set_error(status); } status = fss_extended_read_main_process_file(argc, argv, data, argv[data->remaining.array[counter]], target, select); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (f_error_is_error(status)) { return status; } // clear buffers before repeating the loop - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); } // for } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify one or more files"); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } fss_extended_read_delete_data(data); @@ -302,11 +316,11 @@ extern "C"{ } f_return_status fss_extended_read_main_process_file(const f_array_length argc, const f_string argv[], fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; f_string_length current = f_string_length_initialize; - f_string_length found = f_string_length_initialize; + f_string_length found = f_string_length_initialize; { f_string_location input = f_string_location_initialize; @@ -317,29 +331,26 @@ extern "C"{ status = fll_fss_extended_read(&data->buffer, &input, &data->objects, &data->contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_read() for the file '%s'", filename); - - fss_extended_read_delete_data(data); - return status; - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop || status == f_no_data_on_eof) { - // not an error in this case } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - - fss_extended_read_delete_data(data); - return status; } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_read() for the file '%s'", status, filename); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fll_fss_extended_read() for the file '%s'", f_error_set_error(status), filename); } + fss_extended_read_delete_data(data); + return f_error_set_error(status); + } else if (f_macro_test_for_no_data_errors(status)) { // clear buffers, then attempt the next file - f_delete_fss_contents(allocation_status, data->contents); - f_delete_fss_objects(allocation_status, data->objects); - f_delete_dynamic_string(allocation_status, data->buffer); + f_delete_fss_contents(status2, data->contents); + f_delete_fss_objects(status2, data->objects); + f_delete_dynamic_string(status2, data->buffer); - return status; + return f_error_set_warning(status); } // now that all of the files have been read, process the objects and contents 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 5d02034..0139847 100644 --- a/level_3/fss_extended_write/c/fss_extended_write.c +++ b/level_3/fss_extended_write/c/fss_extended_write.c @@ -111,25 +111,27 @@ extern "C"{ #ifndef _di_fss_extended_write_main_ f_return_status fss_extended_write_main(const f_array_length argc, const f_string argv[], fss_extended_write_data *data) { - f_status status = f_status_initialize; - f_status allocation_status = f_status_initialize; + f_status status = f_status_initialize; + f_status status2 = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_extended_write_total_parameters, &data->remaining); // load colors when not told to show no colors if (data->parameters[fss_extended_write_parameter_no_color].result == f_console_result_none) { - fll_new_color_context(allocation_status, data->context); + fll_new_color_context(status2, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_extended_write_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(status2)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_extended_write_delete_data(data); - return allocation_status; + return status2; + } else { + fll_colors_load_context(&data->context, data->parameters[fss_extended_write_parameter_light].result == f_console_result_found); } } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -140,11 +142,11 @@ extern "C"{ } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_process_parameters().", f_error_set_error(status)); } fss_extended_write_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -167,7 +169,9 @@ extern "C"{ status = fl_file_read_fifo(file, &input); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling f_file_open()"); } else if (status == f_file_not_found) { @@ -177,12 +181,12 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } - f_delete_dynamic_string(status, input); + f_delete_dynamic_string(status2, input); fss_extended_write_delete_data(data); - return status; + return f_error_set_error(status); } location.start = 0; @@ -191,21 +195,21 @@ extern "C"{ if (object) { status = fl_fss_extended_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { status = fl_fss_extended_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } if (data->parameters[fss_extended_write_parameter_partial].result == f_console_result_none) { if (buffer.used >= buffer.size) { f_resize_dynamic_string(status, buffer, buffer.used + f_fss_default_allocation_step); - if (f_macro_test_for_no_data_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -228,8 +232,8 @@ extern "C"{ status = fl_fss_extended_object_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } } else { f_string_length i = 0; @@ -243,8 +247,8 @@ extern "C"{ status = fl_fss_extended_content_write(input, &location, &buffer); - if (f_macro_test_for_no_data_errors(status)) { - return status; + if (f_error_is_error(status) || f_macro_test_for_no_data_errors(status)) { + return f_error_set_error(status); } i++; @@ -254,7 +258,7 @@ extern "C"{ if (buffer.used >= buffer.size) { f_resize_dynamic_string(status, buffer, buffer.used + f_fss_default_allocation_step); - if (f_macro_test_for_no_data_errors(status)) { + if (f_error_is_error(status)) { return status; } } @@ -273,7 +277,9 @@ extern "C"{ output.mode = f_file_write_append; status = f_file_open(&output, argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + f_file_close(&output); if (status == f_invalid_parameter) { @@ -285,7 +291,7 @@ extern "C"{ } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling f_file_open()", f_error_set_error(status)); } fss_extended_write_delete_data(data); @@ -295,17 +301,19 @@ extern "C"{ status = fl_file_write(output, buffer); f_file_close(&output); - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_write()"); } else if (status == f_file_write_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to write to the file '%s'", argv[data->parameters[fss_extended_write_parameter_file].additional.array[0]]); } else { - fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", status); + fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: An unhandled error (%u) has occured while calling fl_file_write()", f_error_set_error(status)); } fss_extended_write_delete_data(data); - return status; + return f_error_set_error(status); } } else { f_print_dynamic_string(f_standard_output, buffer); @@ -319,8 +327,8 @@ extern "C"{ #ifndef _di_fss_extended_write_delete_data_ f_return_status fss_extended_write_delete_data(fss_extended_write_data *data) { - f_status status = f_status_initialize; - f_string_length i = 0; + f_status status = f_status_initialize; + f_string_length i = 0; while (i < fss_extended_write_total_parameters) { f_delete_string_lengths(status, data->parameters[i].additional); diff --git a/level_3/fss_return_code/c/fss_return_code.c b/level_3/fss_return_code/c/fss_return_code.c index 9992191..1bbccfb 100644 --- a/level_3/fss_return_code/c/fss_return_code.c +++ b/level_3/fss_return_code/c/fss_return_code.c @@ -62,25 +62,32 @@ extern "C"{ printf("\n"); printf("\n %s", f_console_symbol_short_enable); - fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_short_is_okay); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_short_is_fine); printf(", %s", f_console_symbol_long_enable); - fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_long_is_okay); - printf(" Returns true if the error code is not an error."); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_long_is_fine); + printf(" Returns true if the error code is not an error."); printf("\n %s", f_console_symbol_short_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_short_is_warning); printf(", %s", f_console_symbol_long_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_long_is_warning); - printf(" Returns true if the error code is a warning."); + printf(" Returns true if the error code is a warning."); printf("\n %s", f_console_symbol_short_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_short_is_error); printf(", %s", f_console_symbol_long_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_long_is_error); - printf(" Returns true if the error code is an error."); + printf(" Returns true if the error code is an error."); + + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_short_context); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, fss_return_code_long_context); + printf(" Guess error state from context of error (ignores masks)."); printf("\n\n"); @@ -119,16 +126,18 @@ extern "C"{ if (data->parameters[fss_return_code_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[fss_return_code_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(allocation_status)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); fss_return_code_delete_data(data); return allocation_status; } + + fll_colors_load_context(&data->context, data->parameters[fss_return_code_parameter_light].result == f_console_result_found); } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -143,7 +152,7 @@ extern "C"{ } fss_return_code_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -159,9 +168,16 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_error(code)) { - fss_return_code_delete_data(data); - return f_true; + if (data->parameters[fss_return_code_parameter_context].result == f_console_result_found) { + if (fll_fss_errors_is_error(code)) { + fss_return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_error(code)) { + fss_return_code_delete_data(data); + return f_true; + } } } @@ -175,15 +191,22 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_warning(code)) { - fss_return_code_delete_data(data); - return f_true; + if (data->parameters[fss_return_code_parameter_context].result == f_console_result_found) { + if (fll_fss_errors_is_warning(code)) { + fss_return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_warning(code)) { + fss_return_code_delete_data(data); + return f_true; + } } } fss_return_code_delete_data(data); return f_false; - } else if (data->parameters[fss_return_code_parameter_is_okay].result == f_console_result_found && data->remaining.used > 0) { + } else if (data->parameters[fss_return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; @@ -191,9 +214,16 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_okay(code)) { - fss_return_code_delete_data(data); - return f_true; + if (data->parameters[fss_return_code_parameter_context].result == f_console_result_found) { + if (fll_fss_errors_is_fine(code)) { + fss_return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_fine(code)) { + fss_return_code_delete_data(data); + return f_true; + } } } @@ -218,7 +248,7 @@ extern "C"{ } } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } fss_return_code_delete_data(data); diff --git a/level_3/fss_return_code/c/fss_return_code.h b/level_3/fss_return_code/c/fss_return_code.h index 4a3341d..f5910b2 100644 --- a/level_3/fss_return_code/c/fss_return_code.h +++ b/level_3/fss_return_code/c/fss_return_code.h @@ -48,13 +48,15 @@ extern "C"{ #endif // _di_fss_return_code_name_ #ifndef _di_fss_return_code_defines_ - #define fss_return_code_short_is_okay "o" + #define fss_return_code_short_is_fine "f" #define fss_return_code_short_is_warning "w" #define fss_return_code_short_is_error "e" + #define fss_return_code_short_context "c" - #define fss_return_code_long_is_okay "is_okay" + #define fss_return_code_long_is_fine "is_fine" #define fss_return_code_long_is_warning "is_warning" #define fss_return_code_long_is_error "is_error" + #define fss_return_code_long_context "context" enum { fss_return_code_parameter_help, @@ -62,9 +64,10 @@ extern "C"{ fss_return_code_parameter_no_color, fss_return_code_parameter_version, - fss_return_code_parameter_is_okay, + fss_return_code_parameter_is_fine, fss_return_code_parameter_is_warning, fss_return_code_parameter_is_error, + fss_return_code_parameter_context, }; #define f_console_parameter_initialize_fss_return_code \ @@ -73,12 +76,13 @@ extern "C"{ f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_false, f_console_type_normal, 0), \ - f_console_parameter_initialize(fss_return_code_short_is_okay, fss_return_code_long_is_okay, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(fss_return_code_short_is_fine, fss_return_code_long_is_fine, 0, 0, f_false, f_console_type_normal, 0), \ f_console_parameter_initialize(fss_return_code_short_is_warning, fss_return_code_long_is_warning, 0, 0, f_false, f_console_type_normal, 0), \ f_console_parameter_initialize(fss_return_code_short_is_error, fss_return_code_long_is_error, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(fss_return_code_short_context, fss_return_code_long_context, 0, 0, f_false, f_console_type_normal, 0), \ } - #define fss_return_code_total_parameters 7 + #define fss_return_code_total_parameters 8 #endif // _di_fss_return_code_defines_ #ifndef _di_fss_return_code_data_ diff --git a/level_3/return_code/c/return_code.c b/level_3/return_code/c/return_code.c index 8ed9ca9..04defb3 100644 --- a/level_3/return_code/c/return_code.c +++ b/level_3/return_code/c/return_code.c @@ -62,25 +62,32 @@ extern "C"{ printf("\n"); printf("\n %s", f_console_symbol_short_enable); - fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_short_is_okay); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_short_is_fine); printf(", %s", f_console_symbol_long_enable); - fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_long_is_okay); - printf(" Returns true if the error code is not an error."); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_long_is_fine); + printf(" Returns true if the error code is not an error."); printf("\n %s", f_console_symbol_short_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_short_is_warning); printf(", %s", f_console_symbol_long_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_long_is_warning); - printf(" Returns true if the error code is a warning."); + printf(" Returns true if the error code is a warning."); printf("\n %s", f_console_symbol_short_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_short_is_error); printf(", %s", f_console_symbol_long_enable); fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_long_is_error); - printf(" Returns true if the error code is an error."); + printf(" Returns true if the error code is an error."); + + printf("\n %s", f_console_symbol_short_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_short_context); + + printf(", %s", f_console_symbol_long_enable); + fl_print_color(f_standard_output, data.context.standout, data.context.reset, return_code_long_context); + printf(" Guess error state from context of error (ignores masks)."); printf("\n\n"); @@ -119,16 +126,18 @@ extern "C"{ if (data->parameters[return_code_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none) { - fll_colors_load_context(&data->context, data->parameters[return_code_parameter_light].result == f_console_result_found); - } else { + if (f_error_is_error(allocation_status)) { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); return_code_delete_data(data); return allocation_status; } + + fll_colors_load_context(&data->context, data->parameters[return_code_parameter_light].result == f_console_result_found); } - if (status != f_none) { + if (f_error_is_error(status)) { + status = f_error_unmask(status); + if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: One of the parameters you passed requires an additional parameter that you did not pass."); // TODO: there is a way to identify which parameter is incorrect @@ -143,7 +152,7 @@ extern "C"{ } return_code_delete_data(data); - return status; + return f_error_set_error(status); } // execute parameter results @@ -159,9 +168,16 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_error(code)) { - return_code_delete_data(data); - return f_true; + if (data->parameters[return_code_parameter_context].result == f_console_result_found) { + if (fl_errors_is_error(code)) { + return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_error(code)) { + return_code_delete_data(data); + return f_true; + } } } @@ -175,15 +191,22 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_warning(code)) { - return_code_delete_data(data); - return f_true; + if (data->parameters[return_code_parameter_context].result == f_console_result_found) { + if (fl_errors_is_warning(code)) { + return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_warning(code)) { + return_code_delete_data(data); + return f_true; + } } } return_code_delete_data(data); return f_false; - } else if (data->parameters[return_code_parameter_is_okay].result == f_console_result_found && data->remaining.used > 0) { + } else if (data->parameters[return_code_parameter_is_fine].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; @@ -191,9 +214,16 @@ extern "C"{ for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_okay(code)) { - return_code_delete_data(data); - return f_true; + if (data->parameters[return_code_parameter_context].result == f_console_result_found) { + if (fl_errors_is_fine(code)) { + return_code_delete_data(data); + return f_true; + } + } else { + if (f_error_is_fine(code)) { + return_code_delete_data(data); + return f_true; + } } } @@ -218,7 +248,7 @@ extern "C"{ } } else { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: you failed to specify an error code."); - status = f_invalid_parameter; + status = f_error_set_error(f_invalid_parameter); } return_code_delete_data(data); diff --git a/level_3/return_code/c/return_code.h b/level_3/return_code/c/return_code.h index 5f60899..396ee22 100644 --- a/level_3/return_code/c/return_code.h +++ b/level_3/return_code/c/return_code.h @@ -47,13 +47,15 @@ extern "C"{ #endif // _di_return_code_name_ #ifndef _di_return_code_defines_ - #define return_code_short_is_okay "o" + #define return_code_short_is_fine "f" #define return_code_short_is_warning "w" #define return_code_short_is_error "e" + #define return_code_short_context "c" - #define return_code_long_is_okay "is_okay" + #define return_code_long_is_fine "is_fine" #define return_code_long_is_warning "is_warning" #define return_code_long_is_error "is_error" + #define return_code_long_context "context" enum { return_code_parameter_help, @@ -61,9 +63,10 @@ extern "C"{ return_code_parameter_no_color, return_code_parameter_version, - return_code_parameter_is_okay, + return_code_parameter_is_fine, return_code_parameter_is_warning, return_code_parameter_is_error, + return_code_parameter_context, }; #define f_console_parameter_initialize_return_code \ @@ -72,12 +75,13 @@ extern "C"{ f_console_parameter_initialize(f_console_standard_short_light, f_console_standard_long_light, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_no_color, f_console_standard_long_no_color, 0, 0, f_false, f_console_type_inverse, 0), \ f_console_parameter_initialize(f_console_standard_short_version, f_console_standard_long_version, 0, 0, f_false, f_console_type_normal, 0), \ - f_console_parameter_initialize(return_code_short_is_okay, return_code_long_is_okay, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(return_code_short_is_fine, return_code_long_is_fine, 0, 0, f_false, f_console_type_normal, 0), \ f_console_parameter_initialize(return_code_short_is_warning, return_code_long_is_warning, 0, 0, f_false, f_console_type_normal, 0), \ f_console_parameter_initialize(return_code_short_is_error, return_code_long_is_error, 0, 0, f_false, f_console_type_normal, 0), \ + f_console_parameter_initialize(return_code_short_context, return_code_long_context, 0, 0, f_false, f_console_type_normal, 0), \ } - #define return_code_total_parameters 7 + #define return_code_total_parameters 8 #endif // _di_return_code_defines_ #ifndef _di_return_code_data_ -- 1.8.3.1