From fb657855b0dec8f86480ce0408cff65442476284 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 16 Mar 2012 17:00:06 -0500 Subject: [PATCH] Cleanup: mass change ){ into ) { I have decided that the syntax style should have a space between ){ from now on. I did this change in mass via a sed script. I did not notice any incorrect changes, but there is more to review than I am willing to review. --- level_0/f_console/c/console.c | 28 +- level_0/f_conversion/c/conversion.c | 32 +- level_0/f_file/c/file.c | 30 +- level_0/f_memory/c/memory.c | 46 +-- level_0/f_memory/c/memory.h | 28 +- level_0/f_output/c/output.c | 18 +- level_0/f_pipe/c/pipe.c | 2 +- level_0/f_strings/c/strings.h | 28 +- level_1/fl_colors/c/colors.c | 32 +- level_1/fl_console/c/console.c | 74 ++-- level_1/fl_directory/c/directory.c | 14 +- level_1/fl_errors/c/errors.c | 6 +- level_1/fl_file/c/file.c | 28 +- level_1/fl_fss/c/fss.c | 60 +-- level_1/fl_fss/c/fss_basic.c | 52 +-- level_1/fl_fss/c/fss_basic_list.c | 116 +++--- level_1/fl_fss/c/fss_extended.c | 86 ++-- level_1/fl_fss/c/fss_macro.h | 32 +- level_1/fl_serialized/c/serialized.c | 2 +- level_1/fl_strings/c/strings.c | 42 +- level_2/fll_colors/c/colors.c | 6 +- level_2/fll_execute/c/execute.c | 22 +- level_2/fll_fss/c/fss_basic.c | 36 +- level_2/fll_fss/c/fss_basic_list.c | 36 +- level_2/fll_fss/c/fss_errors.c | 6 +- level_2/fll_fss/c/fss_extended.c | 36 +- level_3/firewall/c/firewall.c | 458 ++++++++++----------- level_3/firewall/c/main.c | 2 +- .../fss_basic_list_read/c/fss_basic_list_read.c | 184 ++++----- level_3/fss_basic_list_read/c/main.c | 4 +- level_3/fss_basic_read/c/fss_basic_read.c | 148 +++---- level_3/fss_basic_read/c/main.c | 4 +- level_3/fss_extended_read/c/fss_extended_read.c | 142 +++---- level_3/fss_extended_read/c/main.c | 4 +- level_3/fss_return_code/c/fss_return_code.c | 50 +-- level_3/fss_return_code/c/main.c | 4 +- level_3/return_code/c/main.c | 4 +- level_3/return_code/c/return_code.c | 50 +-- 38 files changed, 976 insertions(+), 976 deletions(-) diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index d20f258..52eb9a0 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -11,36 +11,36 @@ extern "C"{ #endif #ifndef _di_f_console_identify_ - f_return_status f_console_identify(const f_string input, f_console_id *result){ + 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; #endif // _di_level_0_parameter_checking_ const f_string_length length = strnlen(input, 4); - if (length == 0){ + if (length == 0) { *result = f_console_none; return f_none; } - if (input[0] == f_console_symbol_enable){ - if (length > 1){ - if (input[1] == f_console_symbol_enable){ - if (length > 2){ - if (input[2] == f_console_symbol_enable){ - if (length > 3){ + if (input[0] == f_console_symbol_enable) { + if (length > 1) { + if (input[1] == f_console_symbol_enable) { + if (length > 2) { + if (input[2] == f_console_symbol_enable) { + if (length > 3) { *result = f_console_extra_enable; } else *result = f_console_empty_extra_enable; } else *result = f_console_long_enable; } else *result = f_console_empty_long_enable; } else *result = f_console_short_enable; } else *result = f_console_empty_short_enable; - } else if (input[0] == f_console_symbol_disable){ - if (length > 1){ - if (input[1] == f_console_symbol_disable){ - if (length > 2){ - if (input[2] == f_console_symbol_disable){ - if (length > 3){ + } else if (input[0] == f_console_symbol_disable) { + if (length > 1) { + if (input[1] == f_console_symbol_disable) { + if (length > 2) { + if (input[2] == f_console_symbol_disable) { + if (length > 3) { *result = f_console_extra_disable; } else *result = f_console_empty_extra_disable; } else *result = f_console_long_disable; diff --git a/level_0/f_conversion/c/conversion.c b/level_0/f_conversion/c/conversion.c index 391dbe3..9ac93b5 100644 --- a/level_0/f_conversion/c/conversion.c +++ b/level_0/f_conversion/c/conversion.c @@ -11,10 +11,10 @@ extern "C"{ #endif #ifndef _di_f_is_digit_ - f_return_status f_is_digit(const f_autochar character){ + f_return_status f_is_digit(const f_autochar character) { // at this point, it seems that it would incur more overhead to use the libc isdigit here, so just use one less call and test it here - switch(character){ + switch(character) { case '0': case '1': case '2': @@ -34,9 +34,9 @@ extern "C"{ #endif // _di_f_is_digit_ #ifndef _di_f_is_hexdigit_ - f_return_status f_is_hexdigit(const f_autochar character){ + f_return_status f_is_hexdigit(const f_autochar character) { - switch(character){ + switch(character) { case '0': case '1': case '2': @@ -67,12 +67,12 @@ extern "C"{ #endif // _di_f_is_hexdigit_ #ifndef _di_f_character_to_digit_ - f_return_status f_character_to_digit(const f_autochar character, f_u_long *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; #endif // _di_level_0_parameter_checking_ - switch(character){ + switch(character) { case '0': *digit = 0; break; case '1': *digit = 1; break; case '2': *digit = 2; break; @@ -92,12 +92,12 @@ extern "C"{ #endif // _di_f_character_to_digit_ #ifndef _di_f_character_to_hexdigit_ - f_return_status f_character_to_hexdigit(const f_autochar character, f_u_long *digit){ + 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; #endif // _di_level_0_parameter_checking_ - switch(character){ + switch(character) { case '0': *digit = 0; break; case '1': *digit = 1; break; case '2': *digit = 2; break; @@ -129,7 +129,7 @@ extern "C"{ #endif // _di_f_character_to_hexdigit_ #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){ + 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; @@ -141,11 +141,11 @@ extern "C"{ 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){ + while(current_location < location.stop) { + if (f_character_to_digit(string[current_location], &temp_digit) == f_none) { // when the scale exists, then we need to make the number larger, for this function the scale is base 10 - if (scale > 0){ + if (scale > 0) { *digit = 10 * *digit; *digit += temp_digit; } else { @@ -164,7 +164,7 @@ extern "C"{ #endif // _di_f_string_to_digit_ #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){ + 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; @@ -176,11 +176,11 @@ extern "C"{ 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){ + while(current_location < location.stop) { + if (f_character_to_hexdigit(string[current_location], &temp_digit) == f_none) { // when the scale exists, then we need to make the number larger, for this function the scale is base 16 - if (scale > 0){ + if (scale > 0) { *digit <<= 4; *digit += temp_digit; } else { diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 12257b5..0daf0be 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -15,7 +15,7 @@ extern "C"{ #endif #ifndef _di_f_file_open_ - f_return_status f_file_open(f_file *file_information, const f_string filename){ + 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; #endif // _di_level_0_parameter_checking_ @@ -37,7 +37,7 @@ extern "C"{ #endif // _di_f_file_open_ #ifndef _di_f_file_close_ - f_return_status f_file_close(f_file *file_information){ + 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; #endif // _di_level_0_parameter_checking_ @@ -45,12 +45,12 @@ extern "C"{ if (file_information->file == 0) return 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){ + if (file_information->id != 0) { // make sure all unfinished data gets completed if (fsync(file_information->id) != 0) return f_file_synchronize_error; } - if (fclose(file_information->file) == 0){ + if (fclose(file_information->file) == 0) { file_information->file = 0; return f_none; } @@ -59,7 +59,7 @@ extern "C"{ #endif // _di_f_file_close_ #ifndef _di_f_file_flush_ - f_return_status f_file_flush(f_file *file_information){ + 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; #endif // _di_level_0_parameter_checking_ @@ -72,7 +72,7 @@ extern "C"{ #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){ + 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; @@ -82,7 +82,7 @@ extern "C"{ if (location.total_elements < 0) return 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 (location.total_elements > 0) { if (buffer->size - location.buffer_start < location.total_elements) return f_invalid_parameter; } #endif // _di_level_0_parameter_checking_ @@ -95,16 +95,16 @@ extern "C"{ f_s_int result = 0; - if (current_file_position > location.file_start){ + if (current_file_position > location.file_start) { result = f_file_seek_from_current(file_information->file, file_information->byte_size * (0 - (current_file_position - location.file_start))); - } else if (current_file_position < location.file_start){ + } else if (current_file_position < location.file_start) { result = f_file_seek_from_current(file_information->file, file_information->byte_size * (location.file_start - current_file_position)); } if (result != 0) return f_file_seek_error; // now do the actual read - if (location.total_elements == 0){ + if (location.total_elements == 0) { result = fread(buffer->string + location.buffer_start, file_information->byte_size, buffer->size - buffer->used - 1, file_information->file); } else { result = fread(buffer->string + location.buffer_start, file_information->byte_size, location.total_elements, file_information->file); @@ -115,17 +115,17 @@ extern "C"{ // now save how much of our allocated buffer is actually used // also make sure that we aren't making used space vanish - if (location.buffer_start + result > buffer->used){ + if (location.buffer_start + result > buffer->used) { buffer->used = location.buffer_start + (result / file_information->byte_size); } // append an EOS only when the total elements were set to 0 - if (location.total_elements == 0){ + if (location.total_elements == 0) { buffer->string[buffer->used] = f_eos; } // make sure to communicate that we are done without a problem and the eof was reached - if (feof(file_information->file)){ + if (feof(file_information->file)) { return f_none_on_eof; } @@ -134,7 +134,7 @@ extern "C"{ #endif // _di_f_file_read_ #ifndef _di_f_file_read_fifo_ - f_return_status f_file_read_fifo(f_file *file_information, f_dynamic_string *buffer){ + 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; @@ -153,7 +153,7 @@ extern "C"{ buffer->used += (result / file_information->byte_size); // make sure to communicate that we are done without a problem and the eof was reached - if (feof(file_information->file)){ + if (feof(file_information->file)) { return f_none_on_eof; } diff --git a/level_0/f_memory/c/memory.c b/level_0/f_memory/c/memory.c index a242dea..ddc6b8f 100644 --- a/level_0/f_memory/c/memory.c +++ b/level_0/f_memory/c/memory.c @@ -14,7 +14,7 @@ extern "C"{ #endif #ifndef _di_f_new_ - f_return_status f_new_array(void **pointer, const f_memory_size_t type, const f_memory_length length){ + 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; @@ -27,7 +27,7 @@ extern "C"{ // I have noticed this sometimes causes an increase in L1/L2 cache misses (0.02% L1 increase, 0.01% L2 increase) *pointer = calloc(type, length); - if (*pointer){ + if (*pointer) { //memset(*pointer, 0, type * length); return f_none; } @@ -37,7 +37,7 @@ extern "C"{ #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){ + 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; #endif // _di_level_0_parameter_checking_ @@ -55,7 +55,7 @@ extern "C"{ #endif // ! ( defined (_di_f_delete_) || defined (_f_memory_FORCE_secure_memory_) ) #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){ + 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; @@ -65,7 +65,7 @@ extern "C"{ // prevent double-frees if (*pointer == 0) return f_none; - if (length > 0){ + if (length > 0) { memset(*pointer, 0, type * length); } @@ -79,7 +79,7 @@ extern "C"{ #endif // ! ( defined (_di_f_destroy_) || defined (_f_memory_FORCE_fast_memory_) ) #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){ + 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; @@ -90,11 +90,11 @@ extern "C"{ // don't be wasteful if (old_length == new_length) return f_none; - if (*pointer != 0){ + if (*pointer != 0) { void *new_pointer = 0; // allocate new space - if (new_length > 0){ + if (new_length > 0) { new_pointer = realloc(*pointer, type * new_length); } else { free(*pointer); @@ -105,9 +105,9 @@ extern "C"{ return f_none; } - if (new_pointer){ - if (new_pointer != *pointer){ - if (new_length > old_length){ + if (new_pointer) { + if (new_pointer != *pointer) { + if (new_length > old_length) { // bool * is of a data type size of 1, casting it to bool should result in a single-length increment // this is done to avoid problems with (void *) having arithmetic issues memset(((char *) new_pointer) + (type * old_length), 0, type * (new_length - old_length)); @@ -118,10 +118,10 @@ extern "C"{ return f_none; } - } else if (new_length > 0){ + } else if (new_length > 0) { *pointer = calloc(type, new_length); - if (*pointer){ + if (*pointer) { return f_none; } } else { @@ -133,7 +133,7 @@ extern "C"{ #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){ + 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; @@ -144,11 +144,11 @@ extern "C"{ // don't be wasteful if (old_length == new_length) return f_none; - if (*pointer != 0){ + if (*pointer != 0) { void *new_pointer = 0; - if (old_length > 0){ - if (new_length < old_length){ + if (old_length > 0) { + if (new_length < old_length) { // bool * is of a data type size of 1, casting it to bool should result in a single-length increment // this is done to avoid problems with (void *) having arithmetic issues memset(((char *)*pointer) + new_length, 0, type * (old_length - new_length)); @@ -156,7 +156,7 @@ extern "C"{ } // allocate new space - if (new_length > 0){ + if (new_length > 0) { new_pointer = realloc(*pointer, type * new_length); } else { free(*pointer); @@ -167,9 +167,9 @@ extern "C"{ return f_none; } - if (new_pointer){ - if (new_pointer != *pointer){ - if (new_length > old_length){ + if (new_pointer) { + if (new_pointer != *pointer) { + if (new_length > old_length) { // char * is of a data type size of 1, casting it to bool should result in a single-length increment // this is done to avoid problems with (void *) having arithmetic issues memset(((char *)new_pointer) + (type * old_length), 0, type * (new_length - old_length)); @@ -180,10 +180,10 @@ extern "C"{ return f_none; } - } else if (new_length > 0){ + } else if (new_length > 0) { *pointer = calloc(type, new_length); - if (*pointer){ + if (*pointer) { return f_none; } } else { diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index 34ad682..c58ba33 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -104,7 +104,7 @@ extern "C"{ // type: the structure type #define f_delete_structure(status, structure, type) \ status = f_delete((void **) & structure.array, sizeof(type), structure.size); \ - if (status == f_none){ \ + if (status == f_none) { \ structure.size = 0; \ structure.used = 0; \ } @@ -116,7 +116,7 @@ extern "C"{ // type: the structure type #define f_destroy_structure(status, structure, type) \ status = f_destroy((void **) & structure.array, sizeof(type), structure.size); \ - if (status == f_none){ \ + if (status == f_none) { \ structure.size = 0; \ structure.used = 0; \ } @@ -128,7 +128,7 @@ extern "C"{ // type: the structure type #define f_resize_structure(status, structure, type, new_length) \ status = f_resize((void **) & structure.array, sizeof(type), structure.size, new_length); \ - if (status == f_none){ \ + if (status == f_none) { \ structure.size = new_length; \ if (structure.used > structure.size) structure.used = new_length; \ } @@ -140,7 +140,7 @@ extern "C"{ // type: the structure type #define f_adjust_structure(status, structure, type, new_length) \ status = f_adjust((void **) & structure.array, sizeof(type), structure.size, new_length); \ - if (status == f_none){ \ + if (status == f_none) { \ structure.size = new_length; \ if (structure.used > structure.size) structure.used = new_length; \ } @@ -155,7 +155,7 @@ extern "C"{ // type: the structure type #define f_delete_structures(status, structures, type) \ status = f_none; \ - while (structures.size > 0){ \ + while (structures.size > 0) { \ --structures.size; \ f_delete_structure(status, structures.array[structures.size], type); \ if (status != f_none) break; \ @@ -170,7 +170,7 @@ extern "C"{ // type: the structure type #define f_destroy_structures(status, structures, type) \ status = f_none; \ - while (structures.size > 0){ \ + while (structures.size > 0) { \ --structures.size; \ f_destroy_structure(status, structures.array[structures.size], type); \ if (status != f_none) break; \ @@ -185,18 +185,18 @@ extern "C"{ // type: the structure type #define f_resize_structures(status, structures, type, new_length, length_variable) \ status = f_none; \ - if (new_length < structures.size){ \ + if (new_length < structures.size) { \ length_variable i = structures.size - new_length; \ - for (; i < structures.size; ++i){ \ + for (; i < structures.size; ++i) { \ f_delete_structure(status, structures.array[i], type); \ if (status != f_none) break; \ } \ } \ if (status == f_none) status = f_resize((void **) & structures.array, sizeof(type), structures.size, new_length); \ if (status == f_none) { \ - if (new_length > structures.size){ \ + if (new_length > structures.size) { \ length_variable i = structures.size; \ - for (; i < new_length; ++i){ \ + for (; i < new_length; ++i) { \ memset(&structures.array[i], 0, sizeof(type)); \ } \ } \ @@ -211,18 +211,18 @@ extern "C"{ // type: the structure type #define f_adjust_structures(status, structures, type, new_length, length_variable) \ status = f_none; \ - if (new_length < structures.size){ \ + if (new_length < structures.size) { \ length_variable i = structures.size - new_length; \ - for (; i < structures.size; ++i){ \ + for (; i < structures.size; ++i) { \ f_destroy_structure(status, structures.array[i], type); \ if (status != f_none) break; \ } \ } \ if (status == f_none) status = f_adjust((void **) & structures.array, sizeof(type), structures.size, new_length); \ if (status == f_none) { \ - if (new_length > structures.size){ \ + if (new_length > structures.size) { \ length_variable i = structures.size; \ - for (; i < new_length; ++i){ \ + for (; i < new_length; ++i) { \ memset(&structures.array[i], 0, sizeof(type)); \ } \ } \ diff --git a/level_0/f_output/c/output.c b/level_0/f_output/c/output.c index 809a3b6..f310e35 100644 --- a/level_0/f_output/c/output.c +++ b/level_0/f_output/c/output.c @@ -11,11 +11,11 @@ extern "C"{ #endif #ifndef _di_f_print_string_ - f_return_status f_print_string(f_file_type output, const f_string string, const f_string_length length){ + f_return_status f_print_string(f_file_type output, const f_string string, const f_string_length length) { register f_string_length i = 0; - for (; i < length; i++){ - if (string[i] != f_eos){ + for (; i < length; i++) { + if (string[i] != f_eos) { if (fputc(string[i], output) == 0) return f_output_error; } } @@ -25,15 +25,15 @@ extern "C"{ #endif // _di_f_print_string_ #ifndef _di_f_print_dynamic_string_ - f_return_status f_print_dynamic_string(f_file_type output, const f_dynamic_string buffer){ + f_return_status f_print_dynamic_string(f_file_type output, const f_dynamic_string buffer) { #ifndef _di_level_0_parameter_checking_ if (buffer.used <= 0) return f_invalid_parameter; #endif // _di_level_0_parameter_checking_ register f_string_length i = 0; - for (; i < buffer.used; i++){ - if (buffer.string[i] != f_eos){ + for (; i < buffer.used; i++) { + if (buffer.string[i] != f_eos) { if (fputc(buffer.string[i], output) == 0) return f_output_error; } } @@ -43,7 +43,7 @@ extern "C"{ #endif // _di_f_print_dynamic_string_ #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){ + 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; @@ -54,8 +54,8 @@ extern "C"{ register f_string_length i = location.start; - for (; i <= location.stop; i++){ - if (buffer.string[i] != f_eos){ + for (; i <= location.stop; i++) { + if (buffer.string[i] != f_eos) { if (fputc(buffer.string[i], output) == 0) return f_output_error; } } diff --git a/level_0/f_pipe/c/pipe.c b/level_0/f_pipe/c/pipe.c index 771a0af..69bd2d0 100644 --- a/level_0/f_pipe/c/pipe.c +++ b/level_0/f_pipe/c/pipe.c @@ -15,7 +15,7 @@ extern "C"{ #ifndef _di_f_pipe_exists_ // returns f_true if the standard input contains piped data. - f_return_status f_pipe_exists(){ + f_return_status f_pipe_exists() { struct stat st_info; if (fstat(fileno(f_pipe), &st_info) != 0) { diff --git a/level_0/f_strings/c/strings.h b/level_0/f_strings/c/strings.h index a7cdbcc..546ccf3 100644 --- a/level_0/f_strings/c/strings.h +++ b/level_0/f_strings/c/strings.h @@ -181,28 +181,28 @@ extern "C"{ #define f_delete_dynamic_string(status, dynamic) \ status = f_delete((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - if (status == f_none){ \ + if (status == f_none) { \ dynamic.size = 0; \ dynamic.used = 0; \ } #define f_destroy_dynamic_string(status, dynamic) \ status = f_destroy((void **) & dynamic.string, sizeof(f_string), dynamic.size); \ - if (status == f_none){ \ + if (status == f_none) { \ dynamic.size = 0; \ dynamic.used = 0; \ } #define f_resize_dynamic_string(status, dynamic, new_length) \ status = f_resize((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ - if (status == f_none){ \ + if (status == f_none) { \ dynamic.size = new_length; \ if (dynamic.used > dynamic.size) dynamic.used = new_length; \ } #define f_adjust_dynamic_string(status, dynamic, new_length) \ status = f_adjust((void **) & dynamic.string, sizeof(f_string), dynamic.size, new_length); \ - if (status == f_none){ \ + if (status == f_none) { \ dynamic.size = new_length; \ if (dynamic.used > dynamic.size) dynamic.used = new_length; \ } @@ -220,7 +220,7 @@ extern "C"{ #define f_delete_dynamic_strings(status, dynamics) \ status = f_none; \ - while (dynamics.size > 0){ \ + while (dynamics.size > 0) { \ --dynamics.size; \ f_delete_dynamic_string(status, dynamics.array[dynamics.size]); \ if (status != f_none) break; \ @@ -230,7 +230,7 @@ extern "C"{ #define f_destroy_dynamic_strings(status, dynamics) \ status = f_none; \ - while (dynamics.size > 0){ \ + while (dynamics.size > 0) { \ --dynamics.size; \ f_destroy_dynamic_string(status, dynamics.array[dynamics.size]); \ if (status != f_none) break; \ @@ -240,18 +240,18 @@ extern "C"{ #define f_resize_dynamic_strings(status, dynamics, new_length) \ status = f_none; \ - if (new_length < dynamics.size){ \ + if (new_length < dynamics.size) { \ f_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i){ \ + for (; i < dynamics.size; ++i) { \ f_delete_dynamic_string(status, dynamics.array[i]); \ if (status != f_none) break; \ } \ } \ if (status == f_none) status = f_resize((void **) & dynamics.array, sizeof(f_dynamic_string), dynamics.size, new_length); \ if (status == f_none) { \ - if (new_length > dynamics.size){ \ + if (new_length > dynamics.size) { \ f_string_length i = dynamics.size; \ - for (; i < new_length; ++i){ \ + for (; i < new_length; ++i) { \ memset(&dynamics.array[i], 0, sizeof(f_string)); \ } \ } \ @@ -261,18 +261,18 @@ extern "C"{ #define f_adjust_dynamic_strings(status, dynamics, new_length) \ status = f_none; \ - if (new_length < dynamics.size){ \ + if (new_length < dynamics.size) { \ f_string_length i = dynamics.size - new_length; \ - for (; i < dynamics.size; ++i){ \ + for (; i < dynamics.size; ++i) { \ f_destroy_dynamic_string(status, dynamics.array[i]); \ if (status != f_none) break; \ } \ } \ if (status == f_none) status = f_adjust((void **) & dynamics.array, sizeof(f_dynamic_string), dynamics.size, new_length); \ if (status == f_none) { \ - if (new_length > dynamics.size){ \ + if (new_length > dynamics.size) { \ f_string_length i = dynamics.size; \ - for (; i < new_length; ++i){ \ + for (; i < new_length; ++i) { \ memset(&dynamics.array[i], 0, sizeof(f_dynamic_string)); \ } \ } \ diff --git a/level_1/fl_colors/c/colors.c b/level_1/fl_colors/c/colors.c index 379b7a7..7f40f15 100644 --- a/level_1/fl_colors/c/colors.c +++ b/level_1/fl_colors/c/colors.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -33,7 +33,7 @@ extern "C"{ #endif // _di_fl_set_color_ #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){ + 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; @@ -53,27 +53,27 @@ extern "C"{ else string_size += strnlen(color1, f_color_max_size) + strnlen(color2, f_color_max_size) + strnlen(color3, f_color_max_size) + strnlen(color4, f_color_max_size) + strnlen(color5, f_color_max_size); // make sure there is enough allocated space, if not, then allocate some more - if (buffer->size - buffer->used - 1 < string_size){ + if (buffer->size - buffer->used - 1 < string_size) { f_status status = f_status_initialize; f_resize_dynamic_string(status, (*buffer), buffer->used + string_size + 1); // the additional 1 is the EOS - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { return status; } } - if (color2 == f_null){ + if (color2 == f_null) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color3 == f_null){ + } else if (color3 == f_null) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); strncat(buffer->string, color2, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color4 == f_null){ + } else if (color4 == f_null) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); @@ -81,7 +81,7 @@ extern "C"{ strncat(buffer->string, format.medium, f_color_max_size); strncat(buffer->string, color3, f_color_max_size); strncat(buffer->string, format.end, f_color_max_size); - } else if (color5 == f_null){ + } else if (color5 == f_null) { strncat(buffer->string, format.begin, f_color_max_size); strncat(buffer->string, color1, f_color_max_size); strncat(buffer->string, format.medium, f_color_max_size); @@ -116,13 +116,13 @@ extern "C"{ #endif // _di_fl_save_color_ #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, ...){ + 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; #endif // _di_level_1_parameter_checking_ - if (start_color.used != 0){ + if (start_color.used != 0) { fprintf(file, "%s", start_color.string); } @@ -134,7 +134,7 @@ extern "C"{ va_end(ap); - if (end_color.used != 0){ + if (end_color.used != 0) { fprintf(file, "%s", end_color.string); } @@ -143,13 +143,13 @@ extern "C"{ #endif // _di_fl_print_color_ #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, ...){ + 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; #endif // _di_level_1_parameter_checking_ - if (start_color.used != 0){ + if (start_color.used != 0) { fprintf(file, "%s", start_color.string); } @@ -161,7 +161,7 @@ extern "C"{ va_end(ap); - if (end_color.used != 0){ + if (end_color.used != 0) { fprintf(file, "%s", end_color.string); } @@ -173,8 +173,8 @@ extern "C"{ #endif // _di_fl_print_color_line_ #ifndef _di_fl_print_color_code_ - f_return_status fl_print_color_code(f_file_type file, const f_dynamic_string color){ - if (color.used != 0){ + f_return_status fl_print_color_code(f_file_type file, const f_dynamic_string color) { + if (color.used != 0) { fprintf(file, "%s", color.string); } diff --git a/level_1/fl_console/c/console.c b/level_1/fl_console/c/console.c index 4bcc30a..bb9cbbc 100644 --- a/level_1/fl_console/c/console.c +++ b/level_1/fl_console/c/console.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; #endif // _di_level_1_parameter_checking_ @@ -30,7 +30,7 @@ extern "C"{ // loop through and read all parameters - while (location < argc){ + while (location < argc) { f_console_identify(argv[location], &result); string_length = strnlen(argv[location], f_console_max_size); @@ -51,20 +51,20 @@ extern "C"{ } // Now handle the normal commands - if (argv[location][0] == f_console_symbol_enable){ - while (sub_location < string_length){ - for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++){ - if (parameters[parameter_counter].type == f_console_type_normal){ - if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0){ - if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)){ + if (argv[location][0] == f_console_symbol_enable) { + while (sub_location < string_length) { + for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) { + if (parameters[parameter_counter].type == f_console_type_normal) { + if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) { + if (f_console_is_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) { parameters[parameter_counter].result = f_console_result_found; - if (parameters[parameter_counter].has_additional){ - if (extra_initiator.used >= extra_initiator.size){ + if (parameters[parameter_counter].has_additional) { + if (extra_initiator.used >= extra_initiator.size) { 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_macro_test_for_allocation_errors(allocation_status)) { f_delete_string_lengths(status, extra_initiator); return allocation_status; } @@ -77,15 +77,15 @@ extern "C"{ } if (parameters[parameter_counter].symbol_extra != 0) { - if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)){ + if (f_console_is_extra_enable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) { parameters[parameter_counter].result = f_console_result_found; - if (parameters[parameter_counter].has_additional){ - if (extra_initiator.used >= extra_initiator.size){ + if (parameters[parameter_counter].has_additional) { + if (extra_initiator.used >= extra_initiator.size) { 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_macro_test_for_allocation_errors(allocation_status)) { f_delete_string_lengths(status, extra_initiator); return allocation_status; } @@ -104,19 +104,19 @@ extern "C"{ // now handle the inverse commands } else if (argv[location][0] == f_console_symbol_disable) { - while (sub_location < string_length){ - for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++){ - if (parameters[parameter_counter].type == f_console_type_inverse){ - if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0){ - if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)){ + while (sub_location < string_length) { + for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) { + if (parameters[parameter_counter].type == f_console_type_inverse) { + if (parameters[parameter_counter].symbol_short != 0 && parameters[parameter_counter].symbol_long != 0) { + if (f_console_is_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_short, parameters[parameter_counter].symbol_long, string_length + 1)) { parameters[parameter_counter].result = f_console_result_found; - if (parameters[parameter_counter].has_additional){ - if (extra_initiator.used >= extra_initiator.size){ + if (parameters[parameter_counter].has_additional) { + if (extra_initiator.used >= extra_initiator.size) { 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_macro_test_for_allocation_errors(allocation_status)) { f_delete_string_lengths(status, extra_initiator); return allocation_status; } @@ -129,15 +129,15 @@ extern "C"{ } if (parameters[parameter_counter].symbol_extra != 0) { - if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)){ + if (f_console_is_extra_disable(result, &argv[location][sub_location], parameters[parameter_counter].symbol_extra, string_length + 1)) { parameters[parameter_counter].result = f_console_result_found; - if (parameters[parameter_counter].has_additional){ - if (extra_initiator.used >= extra_initiator.size){ + if (parameters[parameter_counter].has_additional) { + if (extra_initiator.used >= extra_initiator.size) { 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_macro_test_for_allocation_errors(allocation_status)) { f_delete_string_lengths(status, extra_initiator); return allocation_status; } @@ -157,10 +157,10 @@ extern "C"{ // use found to determine if the remaining parameter should be populated found = f_false; - for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++){ - if (parameters[parameter_counter].type == f_console_type_other){ - if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0){ - if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0){ + for (parameter_counter = 0; parameter_counter < total_parameters; parameter_counter++) { + if (parameters[parameter_counter].type == f_console_type_other) { + if (parameters[parameter_counter].length > 0 && parameters[parameter_counter].symbol_other != 0) { + if (strncmp(argv[location], parameters[parameter_counter].symbol_other, parameters[parameter_counter].length + 1) == 0) { parameters[parameter_counter].result = f_console_result_found; // when "other" is supplied, the extra will be recycled to represent the location of the "other" such that ordering can be determined by the caller @@ -173,8 +173,8 @@ extern "C"{ } } // for() - if (!found){ - if (extra_initiator.used > 0){ + if (!found) { + if (extra_initiator.used > 0) { parameters[extra_initiator.array[0]].result = f_console_result_additional; parameters[extra_initiator.array[0]].additional = location; @@ -182,16 +182,16 @@ extern "C"{ f_string_length i = 0; - for (; i < extra_initiator.used; i++){ + for (; i < extra_initiator.used; i++) { extra_initiator.array[i] = extra_initiator.array[i + 1]; } } else { - if (remaining->used >= remaining->size){ + if (remaining->used >= remaining->size) { f_status allocation_status = f_status_initialize; 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_macro_test_for_allocation_errors(allocation_status)) { f_delete_string_lengths(status, extra_initiator); return allocation_status; } @@ -206,7 +206,7 @@ extern "C"{ ++location; } // while() - if (extra_initiator.used > 0){ + if (extra_initiator.used > 0) { status = f_no_data; } else { status = f_none; diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 2cab81e..605cc1f 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -13,7 +13,7 @@ extern "C"{ #ifndef _di_fl_directory_list_ // 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){ + 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; #endif // _di_level_1_parameter_checking_ @@ -30,17 +30,17 @@ extern "C"{ size = strnlen(listing[counter]->d_name, 256); // as far as I can tell 256 is the max directory name length // there is no reason to include "." and ".." in the directory listing - if (strncmp(listing[counter]->d_name, "..", 3) != 0 && strncmp(listing[counter]->d_name, ".", 2) != 0){ - if (names->used >= names->size){ + if (strncmp(listing[counter]->d_name, "..", 3) != 0 && strncmp(listing[counter]->d_name, ".", 2) != 0) { + 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_macro_test_for_allocation_errors(status)) { return status; } } f_resize_dynamic_string(status, names->array[names->used], size); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { return status; } @@ -56,10 +56,10 @@ extern "C"{ // FIXME: the second and third paramater are probably wrong f_delete((void **) & listing, sizeof(struct dirent *), 0); - if (length == 0){ + if (length == 0) { // an empty directory return f_no_data; - } else if (length == -1){ + } else if (length == -1) { if (errno == ENOMEM) return f_allocation_error; else return f_failure; } diff --git a/level_1/fl_errors/c/errors.c b/level_1/fl_errors/c/errors.c index b145aa3..f61d410 100644 --- a/level_1/fl_errors/c/errors.c +++ b/level_1/fl_errors/c/errors.c @@ -19,7 +19,7 @@ extern "C"{ if (string == f_null) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ - switch(error){ + switch(error) { #ifndef _di_fl_errors_booleans_ case f_false: *string = "f_false"; @@ -308,7 +308,7 @@ extern "C"{ #ifndef _di_fl_errors_is_warning_ f_return_status fl_errors_is_warning(const f_status error) { - switch(error){ + switch(error) { #ifndef _di_fl_errors_basic_ case f_no_data: return f_true; @@ -341,7 +341,7 @@ extern "C"{ // 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) { - switch(error){ + switch(error) { #ifndef _di_fl_errors_booleans_ case f_false: return f_true; diff --git a/level_1/fl_file/c/file.c b/level_1/fl_file/c/file.c index 347d38a..6516198 100644 --- a/level_1/fl_file/c/file.c +++ b/level_1/fl_file/c/file.c @@ -11,7 +11,7 @@ extern "C"{ #endif #ifndef _di_fl_file_read_ - f_return_status fl_file_read(f_file file, const f_file_position position, f_dynamic_string *buffer){ + 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; @@ -27,7 +27,7 @@ extern "C"{ 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){ + if (position.total_elements == 0) { infinite = f_true; size = f_file_default_read_size; } else { @@ -36,24 +36,24 @@ extern "C"{ // populate the buffer do{ - if (buffer->size <= size){ + if (buffer->size <= size) { f_resize_dynamic_string(status, (*buffer), size); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { return status; } } status = f_file_read(&file, buffer, position); - if (status == f_none_on_eof){ + if (status == f_none_on_eof) { break; - } else if (status != f_none){ + } else if (status != f_none) { return status; } - if (infinite){ - if (size + f_file_default_read_size > f_string_max_size){ + if (infinite) { + if (size + f_file_default_read_size > f_string_max_size) { return f_overflow; } @@ -66,7 +66,7 @@ extern "C"{ #endif // _di_fl_file_read_ #ifndef _di_fl_file_read_fifo_ - f_return_status fl_file_read_fifo(f_file file, f_dynamic_string *buffer){ + 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; #endif // _di_level_1_parameter_checking_ @@ -80,23 +80,23 @@ extern "C"{ // populate the buffer do { - if (buffer->size <= size){ + if (buffer->size <= size) { f_resize_dynamic_string(status, (*buffer), size); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { return status; } } status = f_file_read_fifo(&file, buffer); - if (status == f_none_on_eof){ + if (status == f_none_on_eof) { break; - } else if (status != f_none){ + } else if (status != f_none) { return status; } - if (size + f_file_default_read_size > f_string_max_size){ + if (size + f_file_default_read_size > f_string_max_size) { return f_overflow; } diff --git a/level_1/fl_fss/c/fss.c b/level_1/fl_fss/c/fss.c index 5418bdb..c99f2e3 100644 --- a/level_1/fl_fss/c/fss.c +++ b/level_1/fl_fss/c/fss.c @@ -12,7 +12,7 @@ extern "C"{ #endif #ifndef _di_fl_fss_identify_ - f_return_status fl_fss_identify(const f_dynamic_string buffer, f_fss_header *header){ + 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; @@ -21,16 +21,16 @@ extern "C"{ register f_string_length i = 0; // If this correctly follows the FSS specification, then this should be all that needs to be done (as well as atoh for ascii to hex) - if (buffer.string[i] == f_fss_type_header_open){ i++; - if (buffer.string[i] == f_fss_type_header_part1){ i++; - if (buffer.string[i] == f_fss_type_header_part2){ i++; - if (buffer.string[i] == f_fss_type_header_part3){ i++; - if (buffer.string[i] == f_fss_type_header_part4){ i++; - if (buffer.string[i] == f_fss_type_header_part5){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; + if (buffer.string[i] == f_fss_type_header_open) { i++; + if (buffer.string[i] == f_fss_type_header_part1) { i++; + if (buffer.string[i] == f_fss_type_header_part2) { i++; + if (buffer.string[i] == f_fss_type_header_part3) { i++; + if (buffer.string[i] == f_fss_type_header_part4) { i++; + if (buffer.string[i] == f_fss_type_header_part5) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; f_string_location location = f_string_location_initialize; @@ -41,7 +41,7 @@ extern "C"{ f_string_to_hexdigit(buffer.string, &header->type, location); // 2: At this point, we can still know the proper format for the file and still have a invalid header, handle accordingly - if (buffer.string[i] == f_fss_type_header_close){ + if (buffer.string[i] == f_fss_type_header_close) { i++; header->length = i; @@ -62,14 +62,14 @@ extern "C"{ } } // people can miss spaces, so lets accept in an attempt to interpret the file anyway, but return values at this point are to be flagged as invalid - } else if (buffer.string[i] == f_fss_type_header_part2){ i++; - if (buffer.string[i] == f_fss_type_header_part3){ i++; - if (buffer.string[i] == f_fss_type_header_part4){ i++; - if (buffer.string[i] == f_fss_type_header_part5){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; - if (f_is_hexdigit(buffer.string[i]) == f_true){ i++; + } else if (buffer.string[i] == f_fss_type_header_part2) { i++; + if (buffer.string[i] == f_fss_type_header_part3) { i++; + if (buffer.string[i] == f_fss_type_header_part4) { i++; + if (buffer.string[i] == f_fss_type_header_part5) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; + if (f_is_hexdigit(buffer.string[i]) == f_true) { i++; f_string_location location = f_string_location_initialize; @@ -99,7 +99,7 @@ extern "C"{ #endif // _di_fl_fss_identify_ #ifndef _di_fl_fss_identify_file_ - f_return_status fl_fss_identify_file(f_file *file_information, f_fss_header *header){ + 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; @@ -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_macro_test_for_allocation_errors(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_macro_test_for_basic_errors(status) || f_macro_test_for_file_errors(status)) { return status; } @@ -144,7 +144,7 @@ extern "C"{ #endif // _di_fl_fss_identify_file_ #ifndef _di_fl_fss_shift_delimiters_ -f_return_status fl_fss_shift_delimiters(f_dynamic_string *buffer, const f_string_location location){ +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; @@ -157,26 +157,26 @@ f_return_status fl_fss_shift_delimiters(f_dynamic_string *buffer, const f_string position = location.start; - while (position < buffer->used && position <= location.stop){ - if (buffer->string[position] == f_fss_delimit_placeholder){ + while (position < buffer->used && position <= location.stop) { + if (buffer->string[position] == f_fss_delimit_placeholder) { distance++; } // do not waste time trying to process what is only going to be replaced with a delimit placeholder - if (position + distance >= buffer->used || position + distance > location.stop){ + if (position + distance >= buffer->used || position + distance > location.stop) { break; } // shift everything down one for each placeholder found - if (distance > 0){ + if (distance > 0) { buffer->string[position] = buffer->string[position + distance]; } ++position; } - if (distance > 0){ - while (position < buffer->used + distance && position <= location.stop){ + if (distance > 0) { + while (position < buffer->used + distance && position <= location.stop) { buffer->string[position] = f_fss_delimit_placeholder; ++position; } diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index 79fc160..bb51c7d 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -26,7 +26,7 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_fss_basic_close){ + if (buffer->string[input->start] == f_fss_basic_close) { input->start++; return fl_fss_found_no_object; } @@ -41,7 +41,7 @@ extern "C"{ found->start = input->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment){ + if (buffer->string[input->start] == f_fss_comment) { fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_error_on_eos, f_error_on_stop) input->start++; @@ -52,7 +52,7 @@ extern "C"{ f_autochar quoted = f_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; input->start++; @@ -60,19 +60,19 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { location = first_slash; has_delimit = f_true; quoted = buffer->string[input->start]; input->start++; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { do{ ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { location = first_slash; has_delimit = f_true; quoted = buffer->string[input->start]; @@ -85,23 +85,23 @@ extern "C"{ } } while (buffer->string[input->start] == f_fss_delimit_slash); } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; location = input->start; } // identify where the object ends - if (quoted == f_eos){ - while (isgraph(buffer->string[input->start]) || buffer->string[input->start] == f_fss_delimit_placeholder){ + if (quoted == f_eos) { + while (isgraph(buffer->string[input->start]) || buffer->string[input->start] == f_fss_delimit_placeholder) { ++input->start; fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) } // while - if (isspace(buffer->string[input->start])){ + if (isspace(buffer->string[input->start])) { found->stop = input->start - 1; - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_object_no_content; } @@ -121,8 +121,8 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_eol){ - if (found_space){ + if (buffer->string[input->start] == f_eol) { + if (found_space) { found->stop = pre_space; input->start = pre_space; } else { @@ -134,13 +134,13 @@ extern "C"{ f_status status = f_status_initialize; f_delete_string_lengths(status, delimits) - if (found_space){ + if (found_space) { return fl_fss_found_object; } else { return fl_fss_found_object_no_content; } } else if (isspace(buffer->string[input->start])) { - if (!found_space){ + if (!found_space) { pre_space = input->start - 1; found_space = f_true; } @@ -153,11 +153,11 @@ extern "C"{ if (isspace(buffer->string[input->start])) { // this quote is a valid object close quote, so handle appropriately - if (has_delimit){ + if (has_delimit) { buffer->string[location] = f_fss_delimit_placeholder; - if (ignore_quotes){ - if (found_space){ + if (ignore_quotes) { + if (found_space) { found->stop = pre_space; input->start = pre_space; } else { @@ -195,14 +195,14 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits here if whitespace would follow the quote - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (isspace(buffer->string[input->start])){ - if (delimits.used >= delimits.size){ + if (isspace(buffer->string[input->start])) { + if (delimits.used >= delimits.size) { f_status status = f_status_initialize; f_resize_string_lengths(status, delimits, delimits.size + f_fss_default_allocation_step); @@ -221,14 +221,14 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits here if whitespace would follow the quote - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (isspace(buffer->string[input->start])){ - if (delimits.used >= delimits.size){ + if (isspace(buffer->string[input->start])) { + if (delimits.used >= delimits.size) { f_status status = f_status_initialize; f_resize_string_lengths(status, delimits, delimits.size + f_fss_default_allocation_step); @@ -275,7 +275,7 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_no_content; } diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 2737e5c..58bc03c 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -26,10 +26,10 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_no_object; - } else if (buffer->string[input->start] == f_fss_basic_list_open){ + } else if (buffer->string[input->start] == f_fss_basic_list_open) { fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_error_on_eos, f_error_on_stop) input->start++; @@ -45,7 +45,7 @@ extern "C"{ found->start = input->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment){ + if (buffer->string[input->start] == f_fss_comment) { fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_error_on_eos, f_error_on_stop) input->start++; @@ -56,7 +56,7 @@ extern "C"{ f_autochar quoted = f_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; input->start++; @@ -64,12 +64,12 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { // because the slash properly delimited the quote, the quote then becomes the start of the content found->start = first_slash + 1; quote_delimit = first_slash; has_quote_delimit = f_true; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { // only apply a slash delimit if the line begins with slashes followed by a quote do { ++input->start; @@ -77,7 +77,7 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { found->start = first_slash + 1; quote_delimit = first_slash; has_quote_delimit = f_true; @@ -90,7 +90,7 @@ extern "C"{ } } while (buffer->string[input->start] == f_fss_delimit_slash); } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; @@ -103,14 +103,14 @@ extern "C"{ } // identify where the object ends - if (quoted == f_eos){ + if (quoted == f_eos) { do{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (!isgraph(buffer->string[input->start])){ + if (!isgraph(buffer->string[input->start])) { break; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; ++input->start; @@ -118,14 +118,14 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // A slash only delimits here if a basic list opener would follow the slash - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { ++input->start; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // found a would be valid basic list object that has been delimited to not be a valid objecy, so exit - if (buffer->string[input->start] == f_fss_basic_list_close){ + if (buffer->string[input->start] == f_fss_basic_list_close) { input->start++; return fl_fss_found_no_object; } else { @@ -135,14 +135,14 @@ extern "C"{ input->start++; return fl_fss_found_no_object; } - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length second_slash = input->start; ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length open_position = input->start; ++input->start; @@ -150,8 +150,8 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // found a valid basic list object, so apply the delimit - if (buffer->string[input->start] == f_eol){ - if (has_quote_delimit){ + if (buffer->string[input->start] == f_eol) { + if (has_quote_delimit) { buffer->string[quote_delimit] = f_fss_delimit_placeholder; } @@ -165,7 +165,7 @@ extern "C"{ input->start = second_slash; } } - } else if (buffer->string[input->start] == f_fss_basic_list_open){ + } else if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length open_position = input->start; input->start++; @@ -173,8 +173,8 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // found a valid basic list object - if (buffer->string[input->start] == f_eol){ - if (has_quote_delimit){ + if (buffer->string[input->start] == f_eol) { + if (has_quote_delimit) { buffer->string[quote_delimit] = f_fss_delimit_placeholder; } @@ -194,13 +194,13 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_no_object; } // close quotes do not need to be delimited in this case as a valid quoted object must end with: ":\n - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { // at this point, a valid object will need to be determined // if nothing else is between the colon and the newline, then a valid object has been found // otherwise restart the loop at this new position, looking for the next proper close quote @@ -213,13 +213,13 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { input->start++; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { found->stop = quote_location - 1; input->start++; return fl_fss_found_object; @@ -243,7 +243,7 @@ extern "C"{ #endif // _di_fl_fss_basic_list_object_read_ #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){ + 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; @@ -271,19 +271,19 @@ extern "C"{ // search until stop point, end of string, or until a valid basic list object is found do{ - if (has_quote_delimit){ + if (has_quote_delimit) { has_quote_delimit = f_false; } fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { has_newlines = f_true; last_newline = input->start; ++input->start; continue; - } else if (buffer->string[input->start] == f_fss_basic_list_open){ + } else if (buffer->string[input->start] == f_fss_basic_list_open) { // a line that begins with only the basic list opener cannot be a valid list object so skip to next line fl_macro_fss_content_seek_till_newline((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) @@ -291,7 +291,7 @@ extern "C"{ last_newline = input->start; ++input->start; continue; - } else if (buffer->string[input->start] == f_fss_comment){ + } else if (buffer->string[input->start] == f_fss_comment) { // comment lines are not valid objects so skip to next line fl_macro_fss_content_seek_till_newline((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) @@ -304,7 +304,7 @@ extern "C"{ f_autochar quoted = f_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; input->start++; @@ -312,11 +312,11 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { // because the slash properly delimited the quote, the quote then becomes the start of the content quote_delimit = first_slash; has_quote_delimit = f_true; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { // only apply a slash delimit if the line begins with slashes followed by a quote do { ++input->start; @@ -324,7 +324,7 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quote_delimit = first_slash; has_quote_delimit = f_true; break; @@ -340,7 +340,7 @@ extern "C"{ continue; } } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; @@ -352,22 +352,22 @@ extern "C"{ } // identify where the potential object ends - if (quoted == f_eos){ + if (quoted == f_eos) { do{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (!isgraph(buffer->string[input->start])){ - while(buffer->string[input->start] != f_eol){ + if (!isgraph(buffer->string[input->start])) { + while(buffer->string[input->start] != f_eol) { ++input->start; - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { found->array[found->used].stop = input->stop; found->used++; return f_none_on_eos; } - if (input->start > input->stop){ + if (input->start > input->stop) { found->array[found->used].stop = input->stop; found->used++; return f_none_on_stop; @@ -377,7 +377,7 @@ extern "C"{ has_newlines = f_true; last_newline = input->start; break; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; ++input->start; @@ -385,13 +385,13 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits here if a basic list opener would follow the slash - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length open_position = input->start; ++input->start; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - if (has_newlines){ + if (has_newlines) { // In this case, assume a valid object was found when eos/eof was reached and reset the start position fl_macro_fss_content_return_on_overflow_reset((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop, last_newline) } else { @@ -399,7 +399,7 @@ extern "C"{ } // found a would be valid basic list object, so apply the delimit - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { buffer->string[first_slash] = f_fss_delimit_placeholder; has_newlines = f_true; last_newline = input->start; @@ -409,20 +409,20 @@ extern "C"{ ++input->start; continue; } - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length second_slash = input->start; ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length open_position = input->start; ++input->start; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - if (has_newlines){ + if (has_newlines) { // In this case, assume a valid object was found when eos/eof was reached and reset the start position fl_macro_fss_content_return_on_overflow_reset((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop, last_newline) } else { @@ -430,9 +430,9 @@ extern "C"{ } // found a valid basic list object - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { // the content should not apply delimits for valid objects - if (has_newlines){ + if (has_newlines) { input->start = last_newline; found->array[found->used].stop = input->start - 1; input->start++; @@ -455,13 +455,13 @@ extern "C"{ continue; } } - } else if (buffer->string[input->start] == f_fss_basic_list_open){ + } else if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length open_position = input->start; input->start++; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - if (has_newlines){ + if (has_newlines) { // In this case, assume a valid object was found when eos/eof was reached and reset the start position fl_macro_fss_content_return_on_overflow_reset((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop, last_newline) } else { @@ -469,9 +469,9 @@ extern "C"{ } // found a valid basic list object - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { // the content should not apply delimits for valid objects - if (has_newlines){ + if (has_newlines) { input->start = last_newline; found->array[found->used].stop = input->start - 1; input->start++; @@ -495,14 +495,14 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { has_newlines = f_true; last_newline = input->start; break; } // close quotes do not need to be delimited in this case as a valid quoted object must end with: ":\n - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { // at this point, a valid object will need to be determined // if nothing else is between the colon and the newline, then a valid object has been found // otherwise restart the loop at this new position, looking for the next proper close quote @@ -514,14 +514,14 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) - if (buffer->string[input->start] == f_fss_basic_list_open){ + if (buffer->string[input->start] == f_fss_basic_list_open) { input->start++; fl_macro_fss_skip_past_whitespace((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) - if (buffer->string[input->start] == f_eol){ - if (has_newlines){ + if (buffer->string[input->start] == f_eol) { + if (has_newlines) { input->start = last_newline; found->array[found->used].stop = input->start - 1; input->start++; diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index c83afe2..81dcc49 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -26,7 +26,7 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_error_on_eos, f_error_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[input->start] == f_fss_extended_close){ + if (buffer->string[input->start] == f_fss_extended_close) { input->start++; return fl_fss_found_no_object; } @@ -41,7 +41,7 @@ extern "C"{ found->start = input->start; // ignore all comment lines - if (buffer->string[input->start] == f_fss_comment){ + if (buffer->string[input->start] == f_fss_comment) { fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_error_on_eos, f_error_on_stop) input->start++; @@ -52,7 +52,7 @@ extern "C"{ f_autochar quoted = f_eos; // identify where the object begins - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; input->start++; @@ -60,19 +60,19 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { location = first_slash; has_delimit = f_true; quoted = buffer->string[input->start]; input->start++; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { do{ ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { location = first_slash; has_delimit = f_true; quoted = buffer->string[input->start]; @@ -85,23 +85,23 @@ extern "C"{ } } while (buffer->string[input->start] == f_fss_delimit_slash); } - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; location = input->start; } // identify where the object ends - if (quoted == f_eos){ - while (isgraph(buffer->string[input->start]) || buffer->string[input->start] == f_fss_delimit_placeholder){ + if (quoted == f_eos) { + while (isgraph(buffer->string[input->start]) || buffer->string[input->start] == f_fss_delimit_placeholder) { ++input->start; fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) } // while - if (isspace(buffer->string[input->start])){ + if (isspace(buffer->string[input->start])) { found->stop = input->start - 1; - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_object_no_content; } @@ -121,8 +121,8 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_eol){ - if (found_space){ + if (buffer->string[input->start] == f_eol) { + if (found_space) { found->stop = pre_space; input->start = pre_space; } else { @@ -134,13 +134,13 @@ extern "C"{ f_status status = f_status_initialize; f_delete_string_lengths(status, delimits) - if (found_space){ + if (found_space) { return fl_fss_found_object; } else { return fl_fss_found_object_no_content; } } else if (isspace(buffer->string[input->start])) { - if (!found_space){ + if (!found_space) { pre_space = input->start - 1; found_space = f_true; } @@ -153,11 +153,11 @@ extern "C"{ if (isspace(buffer->string[input->start])) { // this quote is a valid object close quote, so handle appropriately - if (has_delimit){ + if (has_delimit) { buffer->string[location] = f_fss_delimit_placeholder; - if (ignore_quotes){ - if (found_space){ + if (ignore_quotes) { + if (found_space) { found->stop = pre_space; input->start = pre_space; } else { @@ -195,14 +195,14 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits here if whitespace would follow the quote - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (isspace(buffer->string[input->start])){ - if (delimits.used >= delimits.size){ + if (isspace(buffer->string[input->start])) { + if (delimits.used >= delimits.size) { f_status status = f_status_initialize; f_resize_string_lengths(status, delimits, delimits.size + f_fss_default_allocation_step); @@ -221,14 +221,14 @@ extern "C"{ fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits here if whitespace would follow the quote - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (isspace(buffer->string[input->start])){ - if (delimits.used >= delimits.size){ + if (isspace(buffer->string[input->start])) { + if (delimits.used >= delimits.size) { f_status status = f_status_initialize; f_resize_string_lengths(status, delimits, delimits.size + f_fss_default_allocation_step); @@ -249,7 +249,7 @@ extern "C"{ } // seek to the end of the line - while(input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol){ + while(input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { ++input->start; } @@ -259,7 +259,7 @@ extern "C"{ #endif // _di_fl_fss_extended_object_read_ #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){ + 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; @@ -277,12 +277,12 @@ extern "C"{ fl_macro_fss_allocate_content_if_necessary((*found)) found->array[found->used].start = input->start; - while (input->start <= input->stop){ + while (input->start <= input->stop) { // get past all leading spaces/tabs (allowed) fl_macro_fss_skip_past_whitespace((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_eol){ + if (buffer->string[input->start] == f_eol) { break; } @@ -295,7 +295,7 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // handle delimited quotes, single quotes, and double quotes - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { do{ f_string_length first_slash = input->start; ++input->start; @@ -304,19 +304,19 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { // because the slash properly delimited the quote, the quote then becomes the start of the content found->array[found->used].start = input->start; buffer->string[first_slash] = f_fss_delimit_placeholder; break; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length second_slash = input->start; ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { buffer->string[first_slash] = f_fss_delimit_placeholder; quoted = buffer->string[input->start]; @@ -336,7 +336,7 @@ extern "C"{ break; } } while (f_true); - } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote){ + } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { quoted = buffer->string[input->start]; input->start++; @@ -347,12 +347,12 @@ extern "C"{ } // when quoted is null, then spaces will end the content, otherwise the quote defined in quoted will end the content (or a newline) - if (quoted == f_eos){ + if (quoted == f_eos) { do{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_extended_close){ + if (buffer->string[input->start] == f_fss_extended_close) { // Save the stop point found->array[found->used].stop = input->start - 1; found->used++; @@ -369,13 +369,13 @@ extern "C"{ fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) - if (buffer->string[input->start] == f_fss_extended_close){ + if (buffer->string[input->start] == f_fss_extended_close) { input->start++; return f_unterminated_group; } // handle delimited quotes - if (buffer->string[input->start] == f_fss_delimit_slash){ + if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length first_slash = input->start; ++input->start; @@ -383,18 +383,18 @@ extern "C"{ fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) // A slash only delimits if a delimit quote would follow the slash (or a slash and a delimit quote follows) - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { buffer->string[first_slash] = f_fss_delimit_placeholder; ++input->start; continue; - } else if (buffer->string[input->start] == f_fss_delimit_slash){ + } else if (buffer->string[input->start] == f_fss_delimit_slash) { f_string_length second_slash = input->start; ++input->start; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) - if (buffer->string[input->start] == quoted){ + if (buffer->string[input->start] == quoted) { buffer->string[first_slash] = f_fss_delimit_placeholder; quoted = f_eos; break; @@ -405,7 +405,7 @@ extern "C"{ continue; } } - } else if (buffer->string[input->start] == quoted){ + } else if (buffer->string[input->start] == quoted) { quoted = f_eos; break; } @@ -424,7 +424,7 @@ extern "C"{ } // When original is the same as the current found->used, then there was no data found - if (original == found->used){ + if (original == found->used) { input->start++; return fl_fss_found_no_content; } diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index b705b3b..4334976 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -16,7 +16,7 @@ extern "C"{ #ifndef _di_fl_macro_fss_skip_past_whitespace_ #define fl_macro_fss_skip_past_whitespace(buffer, input) \ - while (!isgraph(buffer.string[input.start]) || buffer.string[input.start] == f_fss_delimit_placeholder){ \ + while (!isgraph(buffer.string[input.start]) || buffer.string[input.start] == f_fss_delimit_placeholder) { \ if (buffer.string[input.start] == f_eol) break; \ \ ++input.start;\ @@ -28,7 +28,7 @@ extern "C"{ #ifndef _di_fl_macro_fss_skip_past_all_whitespace_ #define fl_macro_fss_skip_past_all_whitespace(buffer, input) \ - while (!isgraph(buffer.string[input.start]) || buffer.string[input.start] == f_fss_delimit_placeholder){ \ + while (!isgraph(buffer.string[input.start]) || buffer.string[input.start] == f_fss_delimit_placeholder) { \ ++input.start;\ \ if (input.start >= buffer.used) break; \ @@ -38,7 +38,7 @@ extern "C"{ #ifndef _di_fl_macro_fss_skip_past_delimit_placeholders_ #define fl_macro_fss_skip_past_delimit_placeholders(buffer, input) \ - while (buffer.string[input.start] == f_fss_delimit_placeholder){ \ + while (buffer.string[input.start] == f_fss_delimit_placeholder) { \ ++input.start;\ \ if (input.start >= buffer.used) break; \ @@ -48,10 +48,10 @@ extern "C"{ #ifndef _di_fl_macro_fss_object_return_on_overflow_ #define fl_macro_fss_object_return_on_overflow(buffer, input, found, eos_status, stop_status) \ - if (input.start >= buffer.used){ \ + if (input.start >= buffer.used) { \ found.stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop){ \ + } else if (input.start > input.stop) { \ found.stop = input.stop; \ return stop_status; \ } @@ -59,10 +59,10 @@ extern "C"{ #ifndef _di_fl_macro_fss_content_return_on_overflow_ #define fl_macro_fss_content_return_on_overflow(buffer, input, found, eos_status, stop_status) \ - if (input.start >= buffer.used){ \ + if (input.start >= buffer.used) { \ found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ - } else if (input.start > input.stop){ \ + } else if (input.start > input.stop) { \ found.array[found.used].stop = input.stop; \ return stop_status; \ } @@ -70,11 +70,11 @@ extern "C"{ #ifndef _di_fl_macro_fss_content_return_on_overflow_reset_ #define fl_macro_fss_content_return_on_overflow_reset(buffer, input, found, eos_status, stop_status, set_stop) \ - if (input.start >= buffer.used){ \ + if (input.start >= buffer.used) { \ input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ - } else if (input.start > input.stop){ \ + } else if (input.start > input.stop) { \ input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return stop_status; \ @@ -83,7 +83,7 @@ extern "C"{ #ifndef _di_fl_macro_fss_allocate_content_if_necessary_ #define fl_macro_fss_allocate_content_if_necessary(content) \ - if (content.used >= content.size){ \ + if (content.used >= content.size) { \ f_status status = f_status_initialize; \ \ f_resize_fss_content(status, content, content.size + f_fss_default_allocation_step); \ @@ -93,12 +93,12 @@ extern "C"{ #ifndef _di_fl_macro_fss_object_seek_till_newline_ #define fl_macro_fss_object_seek_till_newline(buffer, input, eos_status, stop_status) \ - while(buffer.string[input.start] != f_eol){ \ + while(buffer.string[input.start] != f_eol) { \ ++input.start; \ - if (input.start >= buffer.used){ \ + if (input.start >= buffer.used) { \ return eos_status; \ } \ - if (input.start > input.stop){ \ + if (input.start > input.stop) { \ return stop_status; \ } \ } // while @@ -106,13 +106,13 @@ extern "C"{ #ifndef _di_fl_macro_fss_content_seek_till_newline_ #define fl_macro_fss_content_seek_till_newline(buffer, input, found, eos_status, stop_status) \ - while(buffer.string[input.start] != f_eol){ \ + while(buffer.string[input.start] != f_eol) { \ ++input.start; \ - if (input.start >= buffer.used){ \ + if (input.start >= buffer.used) { \ found.array[found.used].stop = input.stop; \ return eos_status; \ } \ - if (input.start > input.stop){ \ + if (input.start > input.stop) { \ found.array[found.used].stop = input.stop; \ return stop_status; \ } \ diff --git a/level_1/fl_serialized/c/serialized.c b/level_1/fl_serialized/c/serialized.c index dfed03c..ce2be79 100644 --- a/level_1/fl_serialized/c/serialized.c +++ b/level_1/fl_serialized/c/serialized.c @@ -92,7 +92,7 @@ extern "C" { location->stop = 0; while (i < serialized.used) { - if (current == index){ + if (current == index) { if (location->start > location->stop) { location->start = i; location->stop = i; diff --git a/level_1/fl_strings/c/strings.c b/level_1/fl_strings/c/strings.c index b1003fd..b3de206 100644 --- a/level_1/fl_strings/c/strings.c +++ b/level_1/fl_strings/c/strings.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -23,12 +23,12 @@ extern "C"{ // the start and stop point are inclusive locations, and therefore start - stop is actually 1 too few locations f_string_length size = position.stop - position.start + 1; - if (size > 0){ + if (size > 0) { f_status status = f_status_initialize; f_resize_dynamic_string(status, (*results), size); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { return status; } @@ -43,7 +43,7 @@ extern "C"{ #endif // _di_fl_rip_string_ #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){ + 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; @@ -52,7 +52,7 @@ extern "C"{ if (position->start >= buffer.used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ - while (!isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder){ + while (!isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder) { if (buffer.string[position->start] == f_eol) return f_none; ++position->start; @@ -66,7 +66,7 @@ extern "C"{ #endif // _di_fl_seek_line_past_non_graph_ #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){ + 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; @@ -74,7 +74,7 @@ extern "C"{ if (position->start >= buffer.used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ - while (isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder){ + while (isgraph(buffer.string[position->start]) || buffer.string[position->start] == placeholder) { if (buffer.string[position->start] == f_eol) return f_none; ++position->start; @@ -88,7 +88,7 @@ extern "C"{ #endif // _di_fl_seek_line_until_non_graph_ #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){ + 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; @@ -96,7 +96,7 @@ extern "C"{ if (position->start >= buffer.used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ - while (buffer.string[position->start] != seek_to_this){ + while (buffer.string[position->start] != seek_to_this) { if (buffer.string[position->start] == f_eol) return f_none; ++position->start; @@ -110,7 +110,7 @@ extern "C"{ #endif // _di_fl_seek_to_ #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){ + 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; @@ -122,19 +122,19 @@ extern "C"{ f_string_length stop1 = length1; f_string_length stop2 = length2; - for (; i1 < stop1 && i2 < stop2; i1++, i2++){ + for (; i1 < stop1 && i2 < stop2; i1++, i2++) { while (i1 < stop1 && string1[i1] == f_eos) i1++; while (i2 < stop2 && string2[i2] == f_eos) i2++; if (string1[i1] != string2[i2]) return f_not_equal_to; } // for() - while (i1 < stop1){ + while (i1 < stop1) { if (string1[i1] != f_eos) return f_not_equal_to; i1++; } // while() - while (i2 < stop2){ + while (i2 < stop2) { if (string2[i2] != f_eos) return f_not_equal_to; i2++; } // while() @@ -144,7 +144,7 @@ extern "C"{ #endif // _di_fl_compare_strings_ #ifndef _di_fl_compare_dynamic_strings_ - f_return_status fl_compare_dynamic_strings(const f_dynamic_string string1, const f_dynamic_string string2){ + 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; @@ -159,19 +159,19 @@ extern "C"{ f_string_length stop1 = string1.used; f_string_length stop2 = string2.used; - for (; i1 < stop1 && i2 < stop2; i1++, i2++){ + for (; i1 < stop1 && i2 < stop2; i1++, i2++) { while (i1 < stop1 && string1.string[i1] == f_eos) i1++; while (i2 < stop2 && string2.string[i2] == f_eos) i2++; if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; } // for() - while (i1 < stop1){ + while (i1 < stop1) { if (string1.string[i1] != f_eos) return f_not_equal_to; i1++; } // while() - while (i2 < stop2){ + while (i2 < stop2) { if (string2.string[i2] != f_eos) return f_not_equal_to; i2++; } // while() @@ -181,7 +181,7 @@ extern "C"{ #endif // _di_fl_compare_dynamic_strings_ #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){ + 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; @@ -202,19 +202,19 @@ extern "C"{ f_string_length stop1 = offset1.stop + 1; f_string_length stop2 = offset2.stop + 1; - for (; i1 < stop1 && i2 < stop2; i1++, i2++){ + for (; i1 < stop1 && i2 < stop2; i1++, i2++) { while (i1 < stop1 && string1.string[i1] == f_eos) i1++; while (i2 < stop2 && string2.string[i2] == f_eos) i2++; if (string1.string[i1] != string2.string[i2]) return f_not_equal_to; } // for() - while (i1 < stop1){ + while (i1 < stop1) { if (string1.string[i1] != f_eos) return f_not_equal_to; i1++; } // while() - while (i2 < stop2){ + while (i2 < stop2) { if (string2.string[i2] != f_eos) return f_not_equal_to; i2++; } // while() diff --git a/level_2/fll_colors/c/colors.c b/level_2/fll_colors/c/colors.c index 2558851..d504785 100644 --- a/level_2/fll_colors/c/colors.c +++ b/level_2/fll_colors/c/colors.c @@ -11,7 +11,7 @@ extern "C"{ #endif #ifndef _di_fll_colors_load_context_ - f_return_status fll_colors_load_context(fll_color_context *data, f_bool use_light_colors){ + 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; #endif // _di_level_2_parameter_checking_ @@ -22,7 +22,7 @@ extern "C"{ { f_autochar *environment = getenv("TERM"); - if (!environment || strncmp(environment, "linux", 6) == 0){ + if (!environment || strncmp(environment, "linux", 6) == 0) { data->color_list = f_colors_linux; } else { data->color_list = f_colors_xterminal; @@ -30,7 +30,7 @@ extern "C"{ } // load the colors - if (use_light_colors){ + 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); diff --git a/level_2/fll_execute/c/execute.c b/level_2/fll_execute/c/execute.c index 8d941a2..813a00b 100644 --- a/level_2/fll_execute/c/execute.c +++ b/level_2/fll_execute/c/execute.c @@ -14,7 +14,7 @@ extern "C"{ #endif #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){ + 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; @@ -32,10 +32,10 @@ extern "C"{ last_slash = strrchr(program_path, '/'); - if (last_slash != f_null){ + if (last_slash != f_null) { name_size = strnlen(last_slash, PATH_MAX); - if (name_size > 1){ + if (name_size > 1) { f_new_string(status, program_name, name_size + 1); if (f_macro_test_for_allocation_errors(status)) return status; @@ -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_macro_test_for_allocation_errors(status)) { f_status tmp_status = f_status_initialize; f_delete_string(tmp_status, program_name, name_size); @@ -62,7 +62,7 @@ extern "C"{ arguments_array[0] = program_name; counter++; - for (; counter < arguments.used; counter++){ + for (; counter < arguments.used; counter++) { arguments_array[counter] = arguments.array[counter].string; } @@ -75,11 +75,11 @@ extern "C"{ process_id = vfork(); - if (process_id < 0){ + if (process_id < 0) { return f_fork_failed; } - if (process_id == 0){ // child + if (process_id == 0) { // child execv(program_path, arguments_array); // according to manpages, calling _exit() is safer and should be called here instead of exit() @@ -99,7 +99,7 @@ extern "C"{ #endif // _di_fll_execute_path_ #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){ + 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; @@ -121,7 +121,7 @@ extern "C"{ arguments_array[0] = program_name; counter++; - for (; counter < arguments.used; counter++){ + for (; counter < arguments.used; counter++) { arguments_array[counter] = arguments.array[counter].string; } @@ -134,11 +134,11 @@ extern "C"{ process_id = vfork(); - if (process_id < 0){ + if (process_id < 0) { return f_fork_failed; } - if (process_id == 0){ // child + if (process_id == 0) { // child execvp(program_name, arguments_array); // according to manpages, calling _exit() is safer and should be called here instead of exit() diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index e4856ae..4cc2d52 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -23,16 +23,16 @@ extern "C"{ f_bool found_data = f_false; do { - if (objects->used >= objects->size){ + 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_macro_test_for_allocation_errors(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_macro_test_for_allocation_errors(status)) { return status; } } @@ -40,8 +40,8 @@ extern "C"{ do { status = fl_fss_basic_object_read(buffer, input, &objects->array[objects->used]); - if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_object_no_content){ + if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_object_no_content) { objects->used++; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -51,14 +51,14 @@ extern "C"{ return fl_fss_found_object_no_content; } - if (found_data){ - if (input->start >= buffer->used){ + if (found_data) { + if (input->start >= buffer->used) { return f_none_on_eos; } return f_none_on_stop; } else { - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -66,12 +66,12 @@ extern "C"{ } } - if (status == fl_fss_found_object){ + if (status == fl_fss_found_object) { found_data = f_true; status = fl_fss_basic_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content){ + } else if (status == fl_fss_found_object_no_content) { found_data = f_true; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -80,30 +80,30 @@ extern "C"{ } } while (status == fl_fss_found_no_object); - if (status == f_none_on_eos || status == f_none_on_stop){ + if (status == f_none_on_eos || status == f_none_on_stop) { contents->array[contents->used].used++; objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivelents - if (objects->used > initial_used){ + if (objects->used > initial_used) { if (status == f_no_data_on_eos) return f_none_on_eos; if (status == f_no_data_on_stop) return f_none_on_stop; } return status; - } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content){ + } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content){ + } else if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; } - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_none_on_eos; } diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 29e1cbd..93c76c4 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -23,16 +23,16 @@ extern "C"{ f_bool found_data = f_false; do { - if (objects->used >= objects->size){ + 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_macro_test_for_allocation_errors(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_macro_test_for_allocation_errors(status)) { return status; } } @@ -40,8 +40,8 @@ extern "C"{ do { status = fl_fss_basic_list_object_read(buffer, input, &objects->array[objects->used]); - if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_object_no_content){ + if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_object_no_content) { objects->used++; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -51,14 +51,14 @@ extern "C"{ return fl_fss_found_object_no_content; } - if (found_data){ - if (input->start >= buffer->used){ + if (found_data) { + if (input->start >= buffer->used) { return f_none_on_eos; } return f_none_on_stop; } else { - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -66,12 +66,12 @@ extern "C"{ } } - if (status == fl_fss_found_object){ + if (status == fl_fss_found_object) { found_data = f_true; status = fl_fss_basic_list_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content){ + } else if (status == fl_fss_found_object_no_content) { found_data = f_true; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -80,30 +80,30 @@ extern "C"{ } } while (status == fl_fss_found_no_object); - if (status == f_none_on_eos || status == f_none_on_stop){ + if (status == f_none_on_eos || status == f_none_on_stop) { contents->array[contents->used].used++; objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivalents - if (objects->used > initial_used){ + if (objects->used > initial_used) { if (status == f_no_data_on_eos) return f_none_on_eos; if (status == f_no_data_on_stop) return f_none_on_stop; } return status; - } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content){ + } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content){ + } else if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; } - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_none_on_eos; } diff --git a/level_2/fll_fss/c/fss_errors.c b/level_2/fll_fss/c/fss_errors.c index 0d2c54f..696d79d 100644 --- a/level_2/fll_fss/c/fss_errors.c +++ b/level_2/fll_fss/c/fss_errors.c @@ -16,7 +16,7 @@ extern "C"{ if (string == f_null) return f_invalid_parameter; #endif // _di_level_2_parameter_checking_ - switch(error){ + switch(error) { #ifndef _di_fll_fss_errors_error_ case fl_fss_invalid_format: *string = "fl_fss_invalid_format"; @@ -80,7 +80,7 @@ extern "C"{ #ifndef _di_fll_fss_errors_is_warning_ f_return_status fll_fss_errors_is_warning(const f_status error) { - switch(error){ + switch(error) { #ifndef _di_fll_fss_errors_basic_ case f_no_data: return f_true; @@ -111,7 +111,7 @@ extern "C"{ #ifndef _di_fll_fss_errors_is_okay_ f_return_status fll_fss_errors_is_okay(const f_status error) { - switch(error){ + switch(error) { #ifndef _di_fll_fss_errors_booleans_ case f_false: return f_true; diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 0449f73..7fb209e 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -11,7 +11,7 @@ extern "C"{ #endif #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){ + 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; @@ -23,16 +23,16 @@ extern "C"{ f_bool found_data = f_false; do { - if (objects->used >= objects->size){ + 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_macro_test_for_allocation_errors(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_macro_test_for_allocation_errors(status)) { return status; } } @@ -40,8 +40,8 @@ extern "C"{ do { status = fl_fss_extended_object_read(buffer, input, &objects->array[objects->used]); - if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_object_no_content){ + if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_object_no_content) { objects->used++; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -51,14 +51,14 @@ extern "C"{ return fl_fss_found_object_no_content; } - if (found_data){ - if (input->start >= buffer->used){ + if (found_data) { + if (input->start >= buffer->used) { return f_none_on_eos; } return f_none_on_stop; } else { - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_no_data_on_eos; } @@ -66,12 +66,12 @@ extern "C"{ } } - if (status == fl_fss_found_object){ + if (status == fl_fss_found_object) { found_data = f_true; status = fl_fss_extended_content_read(buffer, input, &contents->array[contents->used]); break; - } else if (status == fl_fss_found_object_no_content){ + } else if (status == fl_fss_found_object_no_content) { found_data = f_true; fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); @@ -80,30 +80,30 @@ extern "C"{ } } while (status == fl_fss_found_no_object); - if (status == f_none_on_eos || status == f_none_on_stop){ + if (status == f_none_on_eos || status == f_none_on_stop) { contents->array[contents->used].used++; objects->used++; contents->used++; return status; - } else if (status == f_no_data_on_eos || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data_on_stop) { // if at least some valid object was found, then return f_none equivelents - if (objects->used > initial_used){ + if (objects->used > initial_used) { if (status == f_no_data_on_eos) return f_none_on_eos; if (status == f_no_data_on_stop) return f_none_on_stop; } return status; - } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content){ + } else if (status != fl_fss_found_object && status != fl_fss_found_content && status != fl_fss_found_no_content && status != fl_fss_found_object_no_content) { return status; // when content is found, the input->start is incremented, if content is found at input->stop, then input->start will be > input.stop - } else if (input->start >= input->stop || input->start >= buffer->used){ - if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content){ + } else if (input->start >= input->stop || input->start >= buffer->used) { + if (status == fl_fss_found_object || status == fl_fss_found_content || status == fl_fss_found_no_content || status == fl_fss_found_object_no_content) { objects->used++; contents->used++; } - if (input->start >= buffer->used){ + if (input->start >= buffer->used) { return f_none_on_eos; } diff --git a/level_3/firewall/c/firewall.c b/level_3/firewall/c/firewall.c index dfd1366..1e1708e 100644 --- a/level_3/firewall/c/firewall.c +++ b/level_3/firewall/c/firewall.c @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_firewall_print_version_ - f_return_status firewall_print_version(const firewall_data data){ + f_return_status firewall_print_version(const firewall_data data) { printf("%s\n", firewall_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _firewall_print_version_ #ifndef _di_firewall_print_help_ - f_return_status firewall_print_help(const firewall_data data){ + f_return_status firewall_print_help(const firewall_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", firewall_name_long); @@ -108,17 +108,17 @@ extern "C"{ #ifndef _di_firewall_main_ f_return_status firewall_perform_commands(const f_fss_objects objects, const f_fss_contents contents, const f_bool is_global, const f_string_length this_device, const f_dynamic_string buffer, const firewall_data data) __attribute__((visibility("internal"))); - f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data){ + f_return_status firewall_main(const f_s_int argc, const f_string argv[], firewall_data *data) { f_status status = f_status_initialize; f_status allocation_status = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, firewall_total_parameters, &data->remaining); // load colors when not told to show no colors - if (data->parameters[firewall_parameter_no_color].result == f_console_result_none){ + if (data->parameters[firewall_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none){ + if (allocation_status == f_none) { fll_colors_load_context(&data->context, data->parameters[firewall_parameter_light].result == f_console_result_found); } else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -127,15 +127,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additiona" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { 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); @@ -146,23 +146,23 @@ extern "C"{ } // execute parameter results - if (data->parameters[firewall_parameter_help].result == f_console_result_found){ + if (data->parameters[firewall_parameter_help].result == f_console_result_found) { firewall_print_help(*data); - } else if (data->parameters[firewall_parameter_version].result == f_console_result_found){ + } else if (data->parameters[firewall_parameter_version].result == f_console_result_found) { firewall_print_version(*data); } else { // now determine which command was placed first f_bool found_command = f_false; f_u_int command = 0; - if (data->parameters[firewall_parameter_command_start].result == f_console_result_found){ + if (data->parameters[firewall_parameter_command_start].result == f_console_result_found) { command = firewall_parameter_command_start; found_command = f_true; } - if (data->parameters[firewall_parameter_command_stop].result == f_console_result_found){ - if (found_command){ - if (data->parameters[command].additional > data->parameters[firewall_parameter_command_stop].additional){ + if (data->parameters[firewall_parameter_command_stop].result == f_console_result_found) { + if (found_command) { + if (data->parameters[command].additional > data->parameters[firewall_parameter_command_stop].additional) { command = firewall_parameter_command_stop; } } else { @@ -171,9 +171,9 @@ extern "C"{ } } - if (data->parameters[firewall_parameter_command_restart].result == f_console_result_found){ - if (found_command){ - if (data->parameters[command].additional > data->parameters[firewall_parameter_command_restart].additional){ + if (data->parameters[firewall_parameter_command_restart].result == f_console_result_found) { + if (found_command) { + if (data->parameters[command].additional > data->parameters[firewall_parameter_command_restart].additional) { command = firewall_parameter_command_restart; } } else { @@ -182,9 +182,9 @@ extern "C"{ } } - if (data->parameters[firewall_parameter_command_lock].result == f_console_result_found){ - if (found_command){ - if (data->parameters[command].additional > data->parameters[firewall_parameter_command_lock].additional){ + if (data->parameters[firewall_parameter_command_lock].result == f_console_result_found) { + if (found_command) { + if (data->parameters[command].additional > data->parameters[firewall_parameter_command_lock].additional) { command = firewall_parameter_command_lock; } } else { @@ -193,9 +193,9 @@ extern "C"{ } } - if (data->parameters[firewall_parameter_command_show].result == f_console_result_found){ - if (found_command){ - if (data->parameters[command].additional > data->parameters[firewall_parameter_command_show].additional){ + if (data->parameters[firewall_parameter_command_show].result == f_console_result_found) { + if (found_command) { + if (data->parameters[command].additional > data->parameters[firewall_parameter_command_show].additional) { command = firewall_parameter_command_show; } } else { @@ -204,21 +204,21 @@ extern "C"{ } } - if (found_command){ + if (found_command) { // load the global file { f_file file = f_file_initialize; status = f_file_open(&file, (f_string) network_path firewall_file_default); - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } 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'", network_path firewall_file_default); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", network_path firewall_file_default); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", network_path firewall_file_default); } 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); @@ -229,7 +229,7 @@ extern "C"{ } // TODO: this file size set functionality might be turned into an fl_file (or f_file) function - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); data->file_position.total_elements = ftell(file.file); fseek(file.file, 0, SEEK_SET); @@ -239,18 +239,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", network_path firewall_file_default); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", network_path firewall_file_default); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", network_path firewall_file_default); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", network_path firewall_file_default); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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); @@ -266,12 +266,12 @@ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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'", network_path firewall_file_default); - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: No relevant data was found within the file '%s'", network_path firewall_file_default); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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, network_path firewall_file_default); @@ -282,7 +282,7 @@ extern "C"{ } } - if (command == firewall_parameter_command_show){ + if (command == firewall_parameter_command_show) { // Warning: these are hardcoded print commands (I am not certain how I am going to implement external 'show' rules as the default-firewall setting file is the wrong place to put this) f_bool show_nat = f_true; f_bool show_mangle = f_true; @@ -291,17 +291,17 @@ extern "C"{ f_dynamic_strings arguments = f_dynamic_strings_initialize; f_s_int results = 0; - if (data->remaining.used > 0){ + if (data->remaining.used > 0) { show_nat = f_false; show_mangle = f_false; show_ports = f_false; f_string_length counter = f_string_length_initialize; - for (; counter < data->remaining.used; counter++){ - if (strncmp("nat", argv[data->remaining.array[counter]], 4) != 0){ - if (strncmp("mangle", argv[data->remaining.array[counter]], 7) != 0){ - if (strncmp("ports", argv[data->remaining.array[counter]], 6) != 0){ + for (; counter < data->remaining.used; counter++) { + if (strncmp("nat", argv[data->remaining.array[counter]], 4) != 0) { + if (strncmp("mangle", argv[data->remaining.array[counter]], 7) != 0) { + if (strncmp("ports", argv[data->remaining.array[counter]], 6) != 0) { fl_print_color_line(f_standard_warning, data->context.warning, data->context.reset, "WARNING: '%s' is not a valid show option", argv[data->remaining.array[counter]]); } else { show_ports = f_true; @@ -317,13 +317,13 @@ extern "C"{ f_resize_dynamic_strings(status, arguments, 7); - if (f_macro_test_for_allocation_errors(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"); firewall_delete_data(data); return status; } - if (show_nat){ + if (show_nat) { fl_print_color(f_standard_output, data->context.standout, data->context.reset, "=========================== "); fl_print_color(f_standard_output, data->context.title, data->context.reset, "NAT"); fl_print_color_line(f_standard_output, data->context.standout, data->context.reset, " ============================"); @@ -353,7 +353,7 @@ extern "C"{ fflush(f_standard_output); } - if (status != f_failure && show_mangle){ + if (status != f_failure && 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, " =========================="); @@ -383,7 +383,7 @@ extern "C"{ fflush(f_standard_output); } - if (status != f_failure && show_ports){ + if (status != f_failure && 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, " ==========================="); @@ -409,7 +409,7 @@ extern "C"{ fflush(f_standard_output); } - if (status == f_failure){ + 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, " "); @@ -417,13 +417,13 @@ extern "C"{ fl_print_color_code(f_standard_error, data->context.error); - for (; i < arguments.used; i++){ + 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"); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } @@ -450,15 +450,15 @@ extern "C"{ // load all network devices status = fl_directory_list((f_string) network_devices, &data->devices); - if (f_macro_test_for_allocation_errors(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"); firewall_delete_data(data); return status; - } else if (status == f_no_data){ + } else if (status == f_no_data) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: could not find any network devices"); firewall_delete_data(data); return status; - } else if (status == f_failure){ + } else if (status == f_failure) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: failed to read the device directory '%s'", network_devices); firewall_delete_data(data); return status; @@ -468,13 +468,13 @@ extern "C"{ { f_string_length counter = f_string_length_initialize; - for (; counter < data->devices.used; counter++){ - if (fl_compare_strings((f_string) "lo", data->devices.array[counter].string, 3, data->devices.array[counter].used) == f_equal_to){ + for (; counter < data->devices.used; counter++) { + if (fl_compare_strings((f_string) "lo", data->devices.array[counter].string, 3, data->devices.array[counter].used) == f_equal_to) { f_dynamic_string swap_string = data->devices.array[counter]; data->devices.used--; - for (; counter < data->devices.used; counter++){ + for (; counter < data->devices.used; counter++) { data->devices.array[counter] = data->devices.array[counter+1]; } @@ -484,28 +484,28 @@ extern "C"{ } // if at least one specific device was specified, then only use the specified devices, otherwise use all - if (data->remaining.used > 0){ + if (data->remaining.used > 0) { f_string_length device = f_string_length_initialize; f_string_length counter = f_string_length_initialize; f_string_length total = f_string_length_initialize; f_string_length i = f_string_length_initialize; f_bool matched = f_false; - for (total = data->devices.used; device < total; device++){ + for (total = data->devices.used; device < total; device++) { matched = f_false; - for (counter = 0; counter < data->remaining.used; counter++){ - if (strncmp(data->devices.array[device].string, argv[data->remaining.array[counter]], strlen(argv[data->remaining.array[counter]])) == 0){ + for (counter = 0; counter < data->remaining.used; counter++) { + if (strncmp(data->devices.array[device].string, argv[data->remaining.array[counter]], strlen(argv[data->remaining.array[counter]])) == 0) { matched = f_true; } } - if (!matched){ + if (!matched) { f_dynamic_string swap_string = data->devices.array[device]; data->devices.used--; - for (i = device; i < data->devices.used; i++){ + for (i = device; i < data->devices.used; i++) { data->devices.array[i] = data->devices.array[i+1]; } @@ -523,16 +523,16 @@ extern "C"{ f_string_length counter = f_string_length_initialize; f_bool matched = f_false; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { matched = f_false; - for (device = 0; device < data->devices.used; device++){ - if (strncmp(data->devices.array[device].string, argv[data->remaining.array[counter]], strlen(argv[data->remaining.array[counter]])) == 0){ + for (device = 0; device < data->devices.used; device++) { + if (strncmp(data->devices.array[device].string, argv[data->remaining.array[counter]], strlen(argv[data->remaining.array[counter]])) == 0) { matched = f_true; } } - if (!matched){ + if (!matched) { fl_print_color_line(f_standard_warning, data->context.warning, data->context.reset, "WARNING: There is no device by the name of '%s'", argv[data->remaining.array[counter]]); } } @@ -556,46 +556,46 @@ extern "C"{ f_string_length counter = f_string_length_initialize; // identify which position is which - for (; counter < data->objects.used; counter++){ + for (; counter < data->objects.used; counter++) { length = data->objects.array[counter].stop - data->objects.array[counter].start + 1; - if (!found_first && length >= firewall_group_first_length){ - if (fl_compare_strings((f_string) firewall_group_first, data->buffer.string + data->objects.array[counter].start, firewall_group_first_length, length) == f_equal_to){ + if (!found_first && length >= firewall_group_first_length) { + if (fl_compare_strings((f_string) firewall_group_first, data->buffer.string + data->objects.array[counter].start, firewall_group_first_length, length) == f_equal_to) { first = counter; found_first = f_true; } } - if (!found_last && length >= firewall_group_last_length){ - if (fl_compare_strings((f_string) firewall_group_last, data->buffer.string + data->objects.array[counter].start, firewall_group_last_length, length) == f_equal_to){ + if (!found_last && length >= firewall_group_last_length) { + if (fl_compare_strings((f_string) firewall_group_last, data->buffer.string + data->objects.array[counter].start, firewall_group_last_length, length) == f_equal_to) { last = counter; found_last = f_true; } } - if (!found_stop && length >= firewall_group_stop_length){ - if (fl_compare_strings((f_string) firewall_group_stop, data->buffer.string + data->objects.array[counter].start, firewall_group_stop_length, length) == f_equal_to){ + if (!found_stop && length >= firewall_group_stop_length) { + if (fl_compare_strings((f_string) firewall_group_stop, data->buffer.string + data->objects.array[counter].start, firewall_group_stop_length, length) == f_equal_to) { stop = counter; found_stop = f_true; } } - if (!found_lock && length >= firewall_group_lock_length){ - if (fl_compare_strings((f_string) firewall_group_lock, data->buffer.string + data->objects.array[counter].start, firewall_group_lock_length, length) == f_equal_to){ + if (!found_lock && length >= firewall_group_lock_length) { + if (fl_compare_strings((f_string) firewall_group_lock, data->buffer.string + data->objects.array[counter].start, firewall_group_lock_length, length) == f_equal_to) { lock = counter; found_lock = f_true; } } } - if (found_first && found_last && found_stop && found_lock){ + if (found_first && found_last && found_stop && found_lock) { f_string_length error_file = f_string_length_initialize; status = f_none; f_fss_objects extended_objects = f_fss_objects_initialize; f_fss_contents extended_contents = f_fss_contents_initialize; - if (command == firewall_parameter_command_lock){ + if (command == firewall_parameter_command_lock) { f_string_location input = f_string_location_initialize; input.start = data->contents.array[lock].array[0].start; @@ -604,13 +604,13 @@ extern "C"{ status = fll_fss_extended_read(&data->buffer, &input, &extended_objects, &extended_contents); - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos){ + if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { status = firewall_perform_commands(extended_objects, extended_contents, f_true, 0, data->buffer, *data); - if (status != f_none){ - if (f_macro_test_for_allocation_errors(status)){ + if (status != f_none) { + 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); - } else if (status == f_failure){ + } 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); @@ -624,7 +624,7 @@ extern "C"{ } } } else { - if (command == firewall_parameter_command_stop || command == firewall_parameter_command_restart){ + if (command == firewall_parameter_command_stop || command == firewall_parameter_command_restart) { f_string_location input = f_string_location_initialize; input.start = data->contents.array[stop].array[0].start; @@ -633,12 +633,12 @@ extern "C"{ status = fll_fss_extended_read(&data->buffer, &input, &extended_objects, &extended_contents); - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos){ + if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { status = firewall_perform_commands(extended_objects, extended_contents, f_true, 0, data->buffer, *data); } } - if ((status == f_none || status == f_none_on_stop || status == f_none_on_eos) && (command == firewall_parameter_command_start || command == firewall_parameter_command_restart)){ + if ((status == f_none || status == f_none_on_stop || status == f_none_on_eos) && (command == firewall_parameter_command_start || command == firewall_parameter_command_restart)) { f_delete_fss_objects(status, extended_objects); f_delete_fss_contents(status, extended_contents); @@ -650,13 +650,13 @@ extern "C"{ status = fll_fss_extended_read(&data->buffer, &input, &extended_objects, &extended_contents); - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos){ + if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { status = firewall_perform_commands(extended_objects, extended_contents, f_true, 0, data->buffer, *data); - if (status != f_none){ - if (f_macro_test_for_allocation_errors(status)){ + if (status != f_none) { + 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); - } else if (status == f_failure){ + } 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); @@ -673,7 +673,7 @@ extern "C"{ f_string_length counter = f_string_length_initialize; - for (; counter < data->devices.used; counter++){ + for (; counter < data->devices.used; counter++) { f_file file = f_file_initialize; f_dynamic_string file_path = f_dynamic_string_initialize; f_dynamic_string buffer = f_dynamic_string_initialize; @@ -684,7 +684,7 @@ extern "C"{ f_resize_dynamic_string(status, file_path, network_path_length + data->devices.array[counter].used + firewall_file_suffix_length + 1); - if (status == f_none){ + if (status == f_none) { strncat(file_path.string, network_path, network_path_length); strncat(file_path.string + network_path_length, data->devices.array[counter].string, data->devices.array[counter].used); strncat(file_path.string, firewall_file_suffix, firewall_file_suffix_length); @@ -694,16 +694,16 @@ extern "C"{ status = f_file_open(&file, file_path.string); } - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { // If these files do not exist, it is not a problem (they are not required) - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", file_path.string); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory", status); f_file_close(&file); @@ -720,7 +720,7 @@ extern "C"{ } - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); data->file_position.total_elements = ftell(file.file); fseek(file.file, 0, SEEK_SET); @@ -730,18 +730,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", file_path.string); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", file_path.string); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", file_path.string); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory", status); f_delete_dynamic_string(allocation_status, buffer); @@ -765,12 +765,12 @@ extern "C"{ status = fll_fss_basic_list_read(&buffer, &input, &list_objects, &list_contents); } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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'", file_path.string); - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: No relevant data was found within the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory", 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, file_path.string); @@ -788,11 +788,11 @@ extern "C"{ f_string_length buffer_counter = f_string_length_initialize; f_string_length name_length = f_string_length_initialize; - for (; buffer_counter < list_objects.used; buffer_counter++){ + for (; buffer_counter < list_objects.used; buffer_counter++) { name_length = list_objects.array[buffer_counter].stop - list_objects.array[buffer_counter].start + 1; - if (name_length >= firewall_group_main_length){ - if (fl_compare_strings((f_string) firewall_group_main, buffer.string + list_objects.array[buffer_counter].start, firewall_group_main_length, length) == f_equal_to){ + if (name_length >= firewall_group_main_length) { + if (fl_compare_strings((f_string) firewall_group_main, buffer.string + list_objects.array[buffer_counter].start, firewall_group_main_length, length) == f_equal_to) { f_string_location input = f_string_location_initialize; input.start = list_contents.array[buffer_counter].array[0].start; @@ -800,24 +800,24 @@ extern "C"{ status = fll_fss_extended_read(&buffer, &input, &extended_objects, &extended_contents); - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos){ + if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { status = firewall_perform_commands(extended_objects, extended_contents, f_false, counter, buffer, *data); - if (status != f_none){ - if (f_macro_test_for_allocation_errors(status)){ + if (status != f_none) { + 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); - } else if (status == f_failure){ + } 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); } } } else { - if (status == f_invalid_parameter){ + 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'", file_path.string); - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop){ + } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: No relevant data was found within the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory", 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, file_path.string); @@ -846,13 +846,13 @@ extern "C"{ status = fll_fss_extended_read(&data->buffer, &input, &extended_objects, &extended_contents); - if (status == f_none || status == f_none_on_stop || status == f_none_on_eos){ + if (status == f_none || status == f_none_on_stop || status == f_none_on_eos) { status = firewall_perform_commands(extended_objects, extended_contents, f_true, 0, data->buffer, *data); - if (status != f_none){ - if (f_macro_test_for_allocation_errors(status)){ + if (status != f_none) { + 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); - } else if (status == f_failure){ + } 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); @@ -870,16 +870,16 @@ extern "C"{ } } - if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + if (status == f_invalid_parameter) { fl_print_color_code(f_standard_error, data->context.error); fprintf(f_standard_error, "INTERNAL ERROR: Invalid parameter when calling fll_fss_extended_read() for the file '"); f_print_partial_dynamic_string(f_standard_error, data->buffer, data->contents.array[error_file].array[0]); fprintf(f_standard_error, "'"); fl_print_color_code(f_standard_error, data->context.reset); fprintf(f_standard_error, "\n"); - } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop){ - if (error_file == first || error_file == last || error_file == stop || error_file == lock){ + } else if (status == f_no_data_on_eos || status == f_no_data || status == f_no_data_on_stop) { + if (error_file == first || error_file == last || error_file == stop || error_file == lock) { fl_print_color_code(f_standard_error, data->context.error); fprintf(f_standard_error, "ERROR: No relevant data was found within the file '"); f_print_partial_dynamic_string(f_standard_error, data->buffer, data->contents.array[error_file].array[0]); @@ -887,9 +887,9 @@ extern "C"{ fl_print_color_code(f_standard_error, data->context.reset); fprintf(f_standard_error, "\n"); } - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory", status); - } else if (status == f_failure){ + } else if (status == f_failure) { // the error message has already been displayed } else { fl_print_color_code(f_standard_error, data->context.error); @@ -906,13 +906,13 @@ extern "C"{ } else { const f_autochar *string = f_null; - if (!found_first){ + if (!found_first) { string = firewall_group_first; - } else if (!found_last){ + } else if (!found_last) { string = firewall_group_last; - } else if (!found_stop){ + } else if (!found_stop) { string = firewall_group_stop; - } else if (!found_lock){ + } else if (!found_lock) { string = firewall_group_lock; } @@ -933,7 +933,7 @@ extern "C"{ return status; } - f_return_status firewall_perform_commands(const f_fss_objects objects, const f_fss_contents contents, const f_bool is_global, const f_string_length this_device, const f_dynamic_string buffer, const firewall_data data){ + f_return_status firewall_perform_commands(const f_fss_objects objects, const f_fss_contents contents, const f_bool is_global, const f_string_length this_device, const f_dynamic_string buffer, const firewall_data data) { f_status status = f_status_initialize; f_status allocation_status = f_status_initialize; @@ -957,12 +957,12 @@ extern "C"{ f_dynamic_string device = f_dynamic_string_initialize; f_string_length action = firewall_action_append_id; - if (is_global){ + if (is_global) { device_all = f_true; } else { f_resize_dynamic_string(status, device, data.devices.array[this_device].used); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { f_delete_dynamic_string(allocation_status, device); return status; @@ -972,7 +972,7 @@ extern "C"{ device.used = data.devices.array[this_device].used; } - for (; counter < objects.used; counter++){ + for (; counter < objects.used; counter++) { length = (objects.array[counter].stop - objects.array[counter].start) + 1; invalid = f_false; @@ -981,24 +981,24 @@ extern "C"{ f_delete_dynamic_string(allocation_status, ip_list); - if (length >= firewall_direction_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_direction, length, firewall_direction_length) == f_equal_to){ + if (length >= firewall_direction_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_direction, length, firewall_direction_length) == f_equal_to) { length = (contents.array[counter].array[0].stop - contents.array[counter].array[0].start) + 1; - if (contents.array[counter].used <= 0 || contents.array[counter].used > 1){ + if (contents.array[counter].used <= 0 || contents.array[counter].used > 1) { invalid = f_true; } else { - if (length < firewall_direction_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_input, length, firewall_direction_input_length) == f_not_equal_to){ - if (length < firewall_direction_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_output, length, firewall_direction_output_length) == f_not_equal_to){ - if (length < firewall_direction_forward_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward, length, firewall_direction_forward_length) == f_not_equal_to){ - if (length < firewall_direction_postrouting_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting, length, firewall_direction_postrouting_length) == f_not_equal_to){ - if (length < firewall_direction_prerouting_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting, length, firewall_direction_prerouting_length) == f_not_equal_to){ - if (length < firewall_direction_none_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_none, length, firewall_direction_none_length) == f_not_equal_to){ - if (length < firewall_direction_forward_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward_input, length, firewall_direction_forward_input_length) == f_not_equal_to){ - if (length < firewall_direction_forward_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward_output, length, firewall_direction_forward_output_length) == f_not_equal_to){ - if (length < firewall_direction_postrouting_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting_input, length, firewall_direction_postrouting_input_length) == f_not_equal_to){ - if (length < firewall_direction_postrouting_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting_output, length, firewall_direction_postrouting_output_length) == f_not_equal_to){ - if (length < firewall_direction_prerouting_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting_input, length, firewall_direction_prerouting_input_length) == f_not_equal_to){ - if (length < firewall_direction_prerouting_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting_output, length, firewall_direction_prerouting_output_length) == f_not_equal_to){ + if (length < firewall_direction_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_input, length, firewall_direction_input_length) == f_not_equal_to) { + if (length < firewall_direction_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_output, length, firewall_direction_output_length) == f_not_equal_to) { + if (length < firewall_direction_forward_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward, length, firewall_direction_forward_length) == f_not_equal_to) { + if (length < firewall_direction_postrouting_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting, length, firewall_direction_postrouting_length) == f_not_equal_to) { + if (length < firewall_direction_prerouting_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting, length, firewall_direction_prerouting_length) == f_not_equal_to) { + if (length < firewall_direction_none_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_none, length, firewall_direction_none_length) == f_not_equal_to) { + if (length < firewall_direction_forward_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward_input, length, firewall_direction_forward_input_length) == f_not_equal_to) { + if (length < firewall_direction_forward_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_forward_output, length, firewall_direction_forward_output_length) == f_not_equal_to) { + if (length < firewall_direction_postrouting_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting_input, length, firewall_direction_postrouting_input_length) == f_not_equal_to) { + if (length < firewall_direction_postrouting_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_postrouting_output, length, firewall_direction_postrouting_output_length) == f_not_equal_to) { + if (length < firewall_direction_prerouting_input_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting_input, length, firewall_direction_prerouting_input_length) == f_not_equal_to) { + if (length < firewall_direction_prerouting_output_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_direction_prerouting_output, length, firewall_direction_prerouting_output_length) == f_not_equal_to) { invalid = f_true; } else { direction_input = f_false; @@ -1063,16 +1063,16 @@ extern "C"{ } if (!invalid) continue; - } else if (length >= firewall_device_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_device, length, firewall_device_length) == f_equal_to){ + } else if (length >= firewall_device_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_device, length, firewall_device_length) == f_equal_to) { length = (contents.array[counter].array[0].stop - contents.array[counter].array[0].start) + 1; - if (contents.array[counter].used <= 0 || contents.array[counter].used > 1){ + if (contents.array[counter].used <= 0 || contents.array[counter].used > 1) { invalid = f_true; - } else if (length >= firewall_device_all_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_equal_to){ + } else if (length >= firewall_device_all_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_equal_to) { f_delete_dynamic_string(status, device); device_all = f_true; continue; - } else if (length >= firewall_device_this_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_device_this, length, firewall_device_this_length) == f_equal_to){ + } else if (length >= firewall_device_this_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_device_this, length, firewall_device_this_length) == f_equal_to) { f_delete_dynamic_string(status, device); f_resize_dynamic_string(status, device, data.devices.array[this_device].used); @@ -1084,7 +1084,7 @@ extern "C"{ continue; } - if (!invalid){ + if (!invalid) { f_delete_dynamic_string(status, device); f_resize_dynamic_string(status, device, length); @@ -1095,15 +1095,15 @@ extern "C"{ device_all = f_false; continue; } - } else if (length >= firewall_action_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_action, length, firewall_action_length) == f_equal_to){ + } else if (length >= firewall_action_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_action, length, firewall_action_length) == f_equal_to) { length = (contents.array[counter].array[0].stop - contents.array[counter].array[0].start) + 1; - if (contents.array[counter].used <= 0 || contents.array[counter].used > 1){ + if (contents.array[counter].used <= 0 || contents.array[counter].used > 1) { invalid = f_true; - } else if (length < firewall_action_append_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_append, length, firewall_action_append_length) == f_not_equal_to){ - if (length < firewall_action_insert_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_insert, length, firewall_action_insert_length) == f_not_equal_to){ - if (length < firewall_action_policy_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_policy, length, firewall_action_policy_length) == f_not_equal_to){ - if (length < firewall_action_none_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_none, length, firewall_action_none_length) == f_not_equal_to){ + } else if (length < firewall_action_append_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_append, length, firewall_action_append_length) == f_not_equal_to) { + if (length < firewall_action_insert_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_insert, length, firewall_action_insert_length) == f_not_equal_to) { + if (length < firewall_action_policy_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_policy, length, firewall_action_policy_length) == f_not_equal_to) { + if (length < firewall_action_none_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_action_none, length, firewall_action_none_length) == f_not_equal_to) { invalid = f_true; } else { action = firewall_action_none_id; @@ -1119,19 +1119,19 @@ extern "C"{ } if (!invalid) continue; - } else if (length >= firewall_ip_list_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_ip_list, length, firewall_ip_list_length) == f_equal_to){ + } else if (length >= firewall_ip_list_length && fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_ip_list, length, firewall_ip_list_length) == f_equal_to) { length = (contents.array[counter].array[0].stop - contents.array[counter].array[0].start) + 1; is_ip_list = f_true; - if (length >= firewall_ip_list_source_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_ip_list_source, length, firewall_ip_list_source_length) == f_equal_to){ + if (length >= firewall_ip_list_source_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_ip_list_source, length, firewall_ip_list_source_length) == f_equal_to) { ip_list_direction = f_false; - } else if (length >= firewall_ip_list_destination_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_ip_list_destination, length, firewall_ip_list_destination_length) == f_equal_to){ + } else if (length >= firewall_ip_list_destination_length && fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_ip_list_destination, length, firewall_ip_list_destination_length) == f_equal_to) { ip_list_direction = f_true; } else { invalid = f_true; } - } else if (length < firewall_rule_length || fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_rule, length, firewall_rule_length) == f_not_equal_to){ - if (length > 0){ + } else if (length < firewall_rule_length || fl_compare_strings(buffer.string + objects.array[counter].start, (f_string) firewall_rule, length, firewall_rule_length) == f_not_equal_to) { + if (length > 0) { fl_print_color_code(f_standard_warning, data.context.warning); fprintf(f_standard_warning, "WARNING: At line %u, the object '", (unsigned int) counter); f_print_string(f_standard_warning, buffer.string + objects.array[counter].start, length); @@ -1145,10 +1145,10 @@ extern "C"{ continue; } - if (invalid){ + if (invalid) { length = (objects.array[counter].stop - objects.array[counter].start) + 1; - if (length > 0){ + if (length > 0) { fl_print_color_code(f_standard_warning, data.context.warning); fprintf(f_standard_warning, "WARNING: At line %u, the object '", (unsigned int) counter); f_print_string(f_standard_warning, buffer.string + objects.array[counter].start, length); @@ -1190,21 +1190,21 @@ extern "C"{ // FIXME: (this issue is probably everywhere) Implement an strncat function for dynamic strings or if I already have one implement, make sure it is used in every applicable place // (this way I can automatically handle updating the used buffer) // also look into auto-allocated space if necessary with the said function - if (action == firewall_action_append_id){ + 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; 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){ + } 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; 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){ + } 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; @@ -1213,7 +1213,7 @@ extern "C"{ argument.used = firewall_action_policy_command_length; } - if (argument.used > 0){ + if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); if (f_macro_test_for_allocation_errors(status)) break; @@ -1227,36 +1227,36 @@ extern "C"{ argument.used = 0; } - if (action != firewall_action_none_id){ - if (direction == firewall_direction_forward_id){ + if (action != firewall_action_none_id) { + 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; 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){ + } 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; 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){ + } 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; strncat(argument.string, firewall_direction_prerouting_command, firewall_direction_prerouting_command_length); argument.used = firewall_direction_prerouting_command_length; - } else if (direction_input){ + } else if (direction_input) { f_resize_dynamic_string(status, argument, firewall_direction_input_command_length); if (f_macro_test_for_allocation_errors(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){ + } else if (direction_output) { f_resize_dynamic_string(status, argument, firewall_direction_output_command_length); if (f_macro_test_for_allocation_errors(status)) break; @@ -1266,7 +1266,7 @@ extern "C"{ } } - if (argument.used > 0){ + if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); if (f_macro_test_for_allocation_errors(status)) break; @@ -1280,15 +1280,15 @@ extern "C"{ argument.used = 0; } - if (device.used > 0){ - if (length < firewall_device_all_length || fl_compare_strings(buffer.string + contents.array[counter].array[0].start, (f_string) firewall_device_all, length, firewall_device_all_length) == f_not_equal_to){ - if (direction_input){ + if (device.used > 0) { + if (length < firewall_device_all_length || fl_compare_strings(buffer.string + contents.array[counter].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; strncat(argument.string, firewall_device_input_command, firewall_device_input_command_length); argument.used = firewall_device_input_command_length; - } else if (direction_output){ + } else if (direction_output) { f_resize_dynamic_string(status, argument, firewall_device_output_command_length); if (f_macro_test_for_allocation_errors(status)) break; @@ -1297,7 +1297,7 @@ extern "C"{ } } - if (argument.used > 0){ + if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); if (f_macro_test_for_allocation_errors(status)) break; @@ -1311,7 +1311,7 @@ extern "C"{ argument.used = 0; } - if (direction_input || direction_output){ + if (direction_input || direction_output) { f_resize_dynamic_string(status, argument, device.used); if (f_macro_test_for_allocation_errors(status)) break; @@ -1320,7 +1320,7 @@ extern "C"{ } } - if (argument.used > 0){ + if (argument.used > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); if (f_macro_test_for_allocation_errors(status)) break; @@ -1335,10 +1335,10 @@ extern "C"{ } // last up is the "rule" - if ((!is_ip_list && contents.array[counter].used > 0) || (is_ip_list && contents.array[counter].used > 1)){ + if ((!is_ip_list && contents.array[counter].used > 0) || (is_ip_list && contents.array[counter].used > 1)) { f_string_length subcounter = f_string_length_initialize; - if (is_ip_list){ + if (is_ip_list) { // skip past the direction subcounter++; @@ -1346,7 +1346,7 @@ extern "C"{ f_resize_dynamic_string(status, ip_list, length); - if (f_macro_test_for_allocation_errors(status)){ + if (f_macro_test_for_allocation_errors(status)) { subcounter = contents.array[counter].used; } else { strncat(ip_list.string, buffer.string + contents.array[counter].array[subcounter].start, length); @@ -1356,7 +1356,7 @@ extern "C"{ } } - for (; subcounter < contents.array[counter].used; subcounter++){ + for (; subcounter < contents.array[counter].used; subcounter++) { length = (contents.array[counter].array[subcounter].stop - contents.array[counter].array[subcounter].start) + 1; f_resize_dynamic_string(status, argument, length); @@ -1366,7 +1366,7 @@ extern "C"{ strncat(argument.string, buffer.string + contents.array[counter].array[subcounter].start, length); argument.used = length; - if (length > 0){ + if (length > 0) { f_resize_dynamic_strings(status, arguments, arguments.used + 1); if (f_macro_test_for_allocation_errors(status)) break; @@ -1393,8 +1393,8 @@ extern "C"{ break; } - if (arguments.used > 1){ - if (is_ip_list){ + if (arguments.used > 1) { + if (is_ip_list) { f_file file = f_file_initialize; f_dynamic_string file_path = f_dynamic_string_initialize; f_dynamic_string local_buffer = f_dynamic_string_initialize; @@ -1405,7 +1405,7 @@ extern "C"{ f_resize_dynamic_string(status, file_path, network_path_length + ip_list.used + 1); - if (status == f_none){ + if (status == f_none) { strncat(file_path.string, network_path, network_path_length); strncat(file_path.string + network_path_length, ip_list.string, ip_list.used); file_path.used = file_path.size; @@ -1414,18 +1414,18 @@ extern "C"{ status = f_file_open(&file, file_path.string); } - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { // the file does not have to exist fl_print_color_line(f_standard_warning, data.context.warning, data.context.reset, "WARNING: Cannot find the file '%s'", file_path.string); status = f_none; - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: Unable to open the file '%s'", file_path.string); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: File descriptor error while trying to open the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", 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); @@ -1433,7 +1433,7 @@ extern "C"{ f_file_close(&file); } else { - if (file_position.total_elements == 0){ + if (file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); file_position.total_elements = ftell(file.file); fseek(file.file, 0, SEEK_SET); @@ -1443,18 +1443,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", file_path.string); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: The file '%s' is no longer open", file_path.string); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: A seek error occurred while accessing the file '%s'", file_path.string); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "ERROR: A read error occurred while accessing the file '%s'", file_path.string); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "CRITICAL ERROR: unable to allocate memory", 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 fl_file_read()", status); @@ -1468,12 +1468,12 @@ extern "C"{ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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){ + } 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)){ + } 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); } 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); @@ -1484,7 +1484,7 @@ extern "C"{ f_dynamic_string ip_argument = f_dynamic_string_initialize; f_dynamic_string ip_list_action = f_dynamic_string_initialize; - if (ip_list_direction){ + if (ip_list_direction) { f_resize_dynamic_string(status, ip_list_action, firewall_ip_list_destination_action_length + 1); strncat(ip_list_action.string, firewall_ip_list_destination_action, firewall_ip_list_destination_action_length); } else { @@ -1495,14 +1495,14 @@ extern "C"{ 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)){ + 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); } 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)){ + 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); } else { arguments.array[arguments.used].string = ip_list_action.string; @@ -1511,12 +1511,12 @@ extern "C"{ arguments.used++; // the ip_list file contains objects and no content, all objects are what matter an nothing else - for (; buffer_counter < basic_objects.used; buffer_counter++){ + for (; buffer_counter < basic_objects.used; buffer_counter++) { ip_length = (basic_objects.array[buffer_counter].stop - basic_objects.array[buffer_counter].start) + 1; f_resize_dynamic_string(status, ip_argument, ip_length); - if (f_macro_test_for_allocation_errors(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); break; } @@ -1532,7 +1532,7 @@ extern "C"{ status = fll_execute_program((f_string) firewall_program_name, arguments, &results); - if (status == f_failure){ + 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, " "); @@ -1540,7 +1540,7 @@ extern "C"{ fl_print_color_code(f_standard_error, data.context.error); - for (; i < arguments.used; i++){ + for (; i < arguments.used; i++) { fprintf(f_standard_error, "%s ", arguments.array[i].string); } @@ -1553,7 +1553,7 @@ extern "C"{ arguments.array[arguments.used].used = 0; break; - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_execute_path()"); arguments.used--; @@ -1594,7 +1594,7 @@ extern "C"{ } else { status = fll_execute_program((f_string) firewall_program_name, arguments, &results); - if (status == f_failure){ + 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, " "); @@ -1602,7 +1602,7 @@ extern "C"{ fl_print_color_code(f_standard_error, data.context.error); - for (; i < arguments.used; i++){ + for (; i < arguments.used; i++) { fprintf(f_standard_error, "%s ", arguments.array[i].string); } @@ -1610,7 +1610,7 @@ extern "C"{ fprintf(f_standard_error, "\n"); break; - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data.context.error, data.context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_execute_path()"); break; } @@ -1628,7 +1628,7 @@ extern "C"{ #endif // _di_firewall_main_ #ifndef _di_firewall_delete_data_ - f_return_status firewall_delete_data(firewall_data *data){ + f_return_status firewall_delete_data(firewall_data *data) { f_status status = f_status_initialize; f_delete_fss_contents(status, data->contents); diff --git a/level_3/firewall/c/main.c b/level_3/firewall/c/main.c index de08204..fbac576 100644 --- a/level_3/firewall/c/main.c +++ b/level_3/firewall/c/main.c @@ -1,6 +1,6 @@ #include -int main(const f_s_int argc, const f_string argv[]){ +int main(const f_s_int argc, const f_string argv[]) { firewall_data data = firewall_data_initialize; return firewall_main(argc, argv, &data); diff --git a/level_3/fss_basic_list_read/c/fss_basic_list_read.c b/level_3/fss_basic_list_read/c/fss_basic_list_read.c index c0de567..9954a4a 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 @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_fss_basic_list_read_print_version_ - f_return_status fss_basic_list_read_print_version(const fss_basic_list_read_data data){ + f_return_status fss_basic_list_read_print_version(const fss_basic_list_read_data data) { printf("%s\n", fss_basic_list_read_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _fss_basic_list_read_print_version_ #ifndef _di_fss_basic_list_read_print_help_ - f_return_status fss_basic_list_read_print_help(const fss_basic_list_read_data data){ + f_return_status fss_basic_list_read_print_help(const fss_basic_list_read_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", fss_basic_list_read_name_long); @@ -131,17 +131,17 @@ extern "C"{ #ifndef _di_fss_basic_list_read_main_ f_return_status fss_basic_list_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data, const f_string filename, const f_string_length target) __attribute__((visibility ("internal"))); - f_return_status fss_basic_list_read_main(const f_array_length argc, const f_string argv[], fss_basic_list_read_data *data){ + 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; 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){ + if (data->parameters[fss_basic_list_read_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none){ + 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 { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -150,15 +150,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { 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); @@ -169,16 +169,16 @@ extern "C"{ } // execute parameter results - if (data->parameters[fss_basic_list_read_parameter_help].result == f_console_result_found){ + if (data->parameters[fss_basic_list_read_parameter_help].result == f_console_result_found) { fss_basic_list_read_print_help(*data); - } else if (data->parameters[fss_basic_list_read_parameter_version].result == f_console_result_found){ + } else if (data->parameters[fss_basic_list_read_parameter_version].result == f_console_result_found) { fss_basic_list_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe){ + } else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = f_string_length_initialize; f_string_length target = f_string_length_initialize; f_string_length original_size = data->file_position.total_elements; - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_count].additional]); } @@ -189,14 +189,14 @@ extern "C"{ status = fl_file_read_fifo(file, &data->buffer); - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { 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); @@ -208,7 +208,7 @@ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -218,21 +218,21 @@ extern "C"{ f_delete_dynamic_string(allocation_status, data->buffer); } - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { f_file file = f_file_initialize; status = f_file_open(&file, argv[data->remaining.array[counter]]); data->file_position.total_elements = original_size; - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { 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); @@ -243,13 +243,13 @@ extern "C"{ } // TODO: this file size set functionality might be turned into an fl_file (or f_file) function - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); data->file_position.total_elements = ftell(file.file); // skip past empty files - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { f_file_close(&file); continue; } @@ -261,18 +261,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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); @@ -284,7 +284,7 @@ extern "C"{ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -318,15 +318,15 @@ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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){ + } 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)){ + } 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); @@ -344,22 +344,22 @@ extern "C"{ } // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none){ + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; - if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none){ - if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)){ + if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { - if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found){ - if (data->contents.array[current].used > 0){ + if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { + if (data->contents.array[current].used > 0) { f_string_length counter = data->contents.array[current].array[0].start; f_string_length size = 0; - for (; counter <= data->contents.array[current].array[0].stop; counter++){ + for (; counter <= data->contents.array[current].array[0].stop; counter++) { if (data->buffer.string[counter] == f_eol) size++; } // for @@ -370,8 +370,8 @@ extern "C"{ } else { fprintf(f_standard_output, "0\n"); } - } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional){ - if (data->contents.array[current].used > 0){ + } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + if (data->contents.array[current].used > 0) { f_string_length counter = data->contents.array[current].array[0].start; f_string_length position = 0; f_string_length target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional]); @@ -381,13 +381,13 @@ extern "C"{ range.start = 1; range.stop = 0; - for (; counter <= data->contents.array[current].array[0].stop; counter++){ - if (position == target){ + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (position == target) { range.start = counter; // explicit use of < instead of <= is done here so that the range.stop will always be accurate - for (; counter < data->contents.array[current].array[0].stop; counter++){ - if (data->buffer.string[counter] == f_eol){ + for (; counter < data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_eol) { break; } } // for @@ -396,25 +396,25 @@ extern "C"{ break; } - if (data->buffer.string[counter] == f_eol){ + if (data->buffer.string[counter] == f_eol) { position++; } } // for - if (range.start <= range.stop){ + if (range.start <= range.stop) { f_print_partial_dynamic_string(f_standard_output, data->buffer, range); } } } else { - if (data->contents.array[current].used > 0){ + if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); } } } - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -422,14 +422,14 @@ extern "C"{ } } // for } else { - for (; current < data->objects.used; current++){ - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)){ + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -444,22 +444,22 @@ extern "C"{ f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; - if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional){ + if (data->parameters[fss_basic_list_read_parameter_name].result == f_console_result_additional) { argv_length = strlen(argv[data->parameters[fss_basic_list_read_parameter_name].additional]); - if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ + if (data->parameters[fss_basic_list_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found){ - if (data->contents.array[current].used > 0){ + if (data->parameters[fss_basic_list_read_parameter_size].result == f_console_result_found) { + if (data->contents.array[current].used > 0) { f_string_length counter = data->contents.array[current].array[0].start; f_string_length size = 0; - for (; counter <= data->contents.array[current].array[0].stop; counter++){ + for (; counter <= data->contents.array[current].array[0].stop; counter++) { if (data->buffer.string[counter] == f_eol) size++; } // for @@ -470,8 +470,8 @@ extern "C"{ } else { fprintf(f_standard_output, "0\n"); } - } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional){ - if (data->contents.array[current].used > 0){ + } else if (data->parameters[fss_basic_list_read_parameter_line].result == f_console_result_additional) { + if (data->contents.array[current].used > 0) { f_string_length counter = data->contents.array[current].array[0].start; f_string_length position = 0; f_string_length target = (f_string_length) atoll(argv[data->parameters[fss_basic_list_read_parameter_line].additional]); @@ -481,13 +481,13 @@ extern "C"{ range.start = 1; range.stop = 0; - for (; counter <= data->contents.array[current].array[0].stop; counter++){ - if (position == target){ + for (; counter <= data->contents.array[current].array[0].stop; counter++) { + if (position == target) { range.start = counter; // explicit use of < instead of <= is done here so that the range.stop will always be accurate - for (; counter < data->contents.array[current].array[0].stop; counter++){ - if (data->buffer.string[counter] == f_eol){ + for (; counter < data->contents.array[current].array[0].stop; counter++) { + if (data->buffer.string[counter] == f_eol) { break; } } // for @@ -496,21 +496,21 @@ extern "C"{ break; } - if (data->buffer.string[counter] == f_eol){ + if (data->buffer.string[counter] == f_eol) { position++; } } // for - if (range.start <= range.stop){ + if (range.start <= range.stop) { f_print_partial_dynamic_string(f_standard_output, data->buffer, range); } } } else { - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found) { total++; } else { - if (data->contents.array[current].used > 0){ + if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); } @@ -518,8 +518,8 @@ extern "C"{ } } - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -529,25 +529,25 @@ extern "C"{ } } // for - if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none){ + if (data->parameters[fss_basic_list_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none) { fprintf(f_standard_output, f_string_length_printf "\n", total); } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++){ - if (data->contents.array[current].used > 0){ + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > 0) { name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_list_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_list_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -567,7 +567,7 @@ extern "C"{ #endif // _di_fss_basic_list_read_main_ #ifndef _di_fss_basic_list_read_delete_data_ - f_return_status fss_basic_list_read_delete_data(fss_basic_list_read_data *data){ + f_return_status fss_basic_list_read_delete_data(fss_basic_list_read_data *data) { f_status status = f_status_initialize; f_delete_fss_contents(status, data->contents); diff --git a/level_3/fss_basic_list_read/c/main.c b/level_3/fss_basic_list_read/c/main.c index 257c897..0339ab0 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -1,9 +1,9 @@ #include -int main(const f_array_length argc, const f_string argv[]){ +int main(const f_array_length argc, const f_string argv[]) { fss_basic_list_read_data data = fss_basic_list_read_data_initialize; - if (f_pipe_exists()){ + if (f_pipe_exists()) { data.process_pipe = f_true; } 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 a7acb4e..73c069c 100644 --- a/level_3/fss_basic_read/c/fss_basic_read.c +++ b/level_3/fss_basic_read/c/fss_basic_read.c @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_fss_basic_read_print_version_ - f_return_status fss_basic_read_print_version(const fss_basic_read_data data){ + f_return_status fss_basic_read_print_version(const fss_basic_read_data data) { printf("%s\n", fss_basic_read_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _fss_basic_read_print_version_ #ifndef _di_fss_basic_read_print_help_ - f_return_status fss_basic_read_print_help(const fss_basic_read_data data){ + f_return_status fss_basic_read_print_help(const fss_basic_read_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", fss_basic_read_name_long); @@ -117,17 +117,17 @@ extern "C"{ #ifndef _di_fss_basic_read_main_ f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target) __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_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; 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){ + if (data->parameters[fss_basic_read_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none){ + if (allocation_status == f_none) { fll_colors_load_context(&data->context, data->parameters[fss_basic_read_parameter_light].result == f_console_result_found); } else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -136,15 +136,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { 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); @@ -155,16 +155,16 @@ extern "C"{ } // execute parameter results - if (data->parameters[fss_basic_read_parameter_help].result == f_console_result_found){ + if (data->parameters[fss_basic_read_parameter_help].result == f_console_result_found) { fss_basic_read_print_help(*data); - } else if (data->parameters[fss_basic_read_parameter_version].result == f_console_result_found){ + } else if (data->parameters[fss_basic_read_parameter_version].result == f_console_result_found) { fss_basic_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe){ + } else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = f_string_length_initialize; f_string_length target = f_string_length_initialize; f_string_length original_size = data->file_position.total_elements; - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { target = (f_string_length) atoll(argv[data->parameters[fss_basic_read_parameter_count].additional]); } @@ -175,18 +175,18 @@ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", "-"); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", "-"); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", "-"); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", "-"); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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()", "-"); @@ -198,7 +198,7 @@ extern "C"{ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -208,22 +208,22 @@ extern "C"{ f_delete_dynamic_string(allocation_status, data->buffer); } - if (data->remaining.used > 0){ - for (; counter < data->remaining.used; counter++){ + if (data->remaining.used > 0) { + for (; counter < data->remaining.used; counter++) { f_file file = f_file_initialize; status = f_file_open(&file, argv[data->remaining.array[counter]]); data->file_position.total_elements = original_size; - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { 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); @@ -234,13 +234,13 @@ extern "C"{ } // TODO: this file size set functionality might be turned into an fl_file (or f_file) function - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); data->file_position.total_elements = ftell(file.file); // skip past empty files - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { f_file_close(&file); continue; } @@ -252,18 +252,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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]]); @@ -275,7 +275,7 @@ extern "C"{ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -294,7 +294,7 @@ extern "C"{ return status; } - f_return_status fss_basic_read_main_process_file(const f_array_length argc, const f_string argv[], fss_basic_read_data *data, const f_string filename, const f_string_length target){ + f_return_status fss_basic_read_main_process_file(const f_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; @@ -310,15 +310,15 @@ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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){ + } 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)){ + } 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); @@ -336,16 +336,16 @@ extern "C"{ } // now that the file has been read, process the objects and contents - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none){ + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; - if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_none){ - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->contents.array[current].used > 0){ + if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); } else { @@ -354,8 +354,8 @@ extern "C"{ } } - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -363,14 +363,14 @@ extern "C"{ } } // for } else { - for (; current < data->objects.used; current++){ - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)){ + for (; current < data->objects.used; current++) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -385,21 +385,21 @@ extern "C"{ f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; - if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional){ + if (data->parameters[fss_basic_read_parameter_name].result == f_console_result_additional) { argv_length = strlen(argv[data->parameters[fss_basic_read_parameter_name].additional]); - if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ + if (data->parameters[fss_basic_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found) { total++; } else { - if (data->contents.array[current].used > 0){ + if (data->contents.array[current].used > 0) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[0]); fprintf(f_standard_output, "\n"); } else { @@ -409,8 +409,8 @@ extern "C"{ } } - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -420,25 +420,25 @@ extern "C"{ } } // for - if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none){ + if (data->parameters[fss_basic_read_parameter_total].result == f_console_result_found && data->parameters[fss_basic_read_parameter_count].result == f_console_result_none) { fprintf(f_standard_output, f_string_length_printf "\n", total); } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++){ - if (data->contents.array[current].used > 0){ + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > 0) { name_length = data->contents.array[current].array[0].stop - data->contents.array[current].array[0].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[0].start, argv[data->parameters[fss_basic_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_none || (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_basic_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -458,7 +458,7 @@ extern "C"{ #endif // _di_fss_basic_read_main_ #ifndef _di_fss_basic_read_delete_data_ - f_return_status fss_basic_read_delete_data(fss_basic_read_data *data){ + f_return_status fss_basic_read_delete_data(fss_basic_read_data *data) { f_status status = f_status_initialize; f_delete_fss_contents(status, data->contents); diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index 262da30..a7df3e9 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -1,9 +1,9 @@ #include -int main(const f_array_length argc, const f_string argv[]){ +int main(const f_array_length argc, const f_string argv[]) { fss_basic_read_data data = fss_basic_read_data_initialize; - if (f_pipe_exists()){ + if (f_pipe_exists()) { data.process_pipe = f_true; } 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 555fd62..7d4fbf4 100644 --- a/level_3/fss_extended_read/c/fss_extended_read.c +++ b/level_3/fss_extended_read/c/fss_extended_read.c @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_fss_extended_read_print_version_ - f_return_status fss_extended_read_print_version(const fss_extended_read_data data){ + f_return_status fss_extended_read_print_version(const fss_extended_read_data data) { printf("%s\n", fss_extended_read_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _fss_extended_read_print_version_ #ifndef _di_fss_extended_read_print_help_ - f_return_status fss_extended_read_print_help(const fss_extended_read_data data){ + f_return_status fss_extended_read_print_help(const fss_extended_read_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", fss_extended_read_name_long); @@ -124,17 +124,17 @@ extern "C"{ #ifndef _di_fss_extended_read_main_ f_return_status fss_extended_read_main_process_file(const f_array_length argc, const f_string argv[], fss_extended_read_data *data, const f_string filename, const f_string_length target, const f_string_length select) __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_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; 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){ + if (data->parameters[fss_extended_read_parameter_no_color].result == f_console_result_none) { fll_new_color_context(allocation_status, data->context); - if (allocation_status == f_none){ + if (allocation_status == f_none) { fll_colors_load_context(&data->context, data->parameters[fss_extended_read_parameter_light].result == f_console_result_found); } else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -143,15 +143,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()"); } else { 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); @@ -162,21 +162,21 @@ extern "C"{ } // execute parameter results - if (data->parameters[fss_extended_read_parameter_help].result == f_console_result_found){ + if (data->parameters[fss_extended_read_parameter_help].result == f_console_result_found) { fss_extended_read_print_help(*data); - } else if (data->parameters[fss_extended_read_parameter_version].result == f_console_result_found){ + } else if (data->parameters[fss_extended_read_parameter_version].result == f_console_result_found) { fss_extended_read_print_version(*data); - } else if (data->remaining.used > 0 || data->process_pipe){ + } else if (data->remaining.used > 0 || data->process_pipe) { f_string_length counter = f_string_length_initialize; f_string_length target = f_string_length_initialize; f_string_length select = f_string_length_initialize; f_string_length original_size = data->file_position.total_elements; - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { target = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_count].additional]); } - if (data->parameters[fss_extended_read_parameter_select].result == f_console_result_additional){ + if (data->parameters[fss_extended_read_parameter_select].result == f_console_result_additional) { select = (f_string_length) atoll(argv[data->parameters[fss_extended_read_parameter_select].additional]); } @@ -187,14 +187,14 @@ extern "C"{ status = fl_file_read_fifo(file, &data->buffer); - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", "-"); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", "-"); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", "-"); } else { 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); @@ -207,7 +207,7 @@ extern "C"{ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -217,21 +217,21 @@ extern "C"{ f_delete_dynamic_string(allocation_status, data->buffer); } - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { f_file file = f_file_initialize; status = f_file_open(&file, argv[data->remaining.array[counter]]); data->file_position.total_elements = original_size; - if (status != f_none){ - if (status == f_invalid_parameter){ + 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){ + } else if (status == f_file_not_found) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to find the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_open_error){ + } else if (status == f_file_open_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Unable to open the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_descriptor_error){ + } else if (status == f_file_descriptor_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: File descriptor error while trying to open the file '%s'", argv[data->remaining.array[counter]]); } else { 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); @@ -242,13 +242,13 @@ extern "C"{ } // TODO: this file size set functionality might be turned into an fl_file (or f_file) function - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { fseek(file.file, 0, SEEK_END); data->file_position.total_elements = ftell(file.file); // skip past empty files - if (data->file_position.total_elements == 0){ + if (data->file_position.total_elements == 0) { f_file_close(&file); continue; } @@ -260,18 +260,18 @@ extern "C"{ f_file_close(&file); - if (status != f_none && status != f_none_on_eof && status != f_none_on_eos){ - if (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { + if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_file_read()"); - } else if (status == f_overflow){ + } else if (status == f_overflow) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: Integer overflow while trying to buffer the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_not_open){ + } else if (status == f_file_not_open) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: The file '%s' is no longer open", argv[data->remaining.array[counter]]); - } else if (status == f_file_seek_error){ + } else if (status == f_file_seek_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A seek error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (status == f_file_read_error){ + } else if (status == f_file_read_error) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "ERROR: A read error occurred while accessing the file '%s'", argv[data->remaining.array[counter]]); - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory"); } else { 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); @@ -283,7 +283,7 @@ extern "C"{ 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 (status != f_none && status != f_none_on_eof && status != f_none_on_eos) { return status; } @@ -317,15 +317,15 @@ 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 (status == f_invalid_parameter){ + if (status != f_none && status != f_none_on_eos && status != f_none_on_stop && status != fl_fss_found_object_no_content) { + 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){ + } 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)){ + } 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); @@ -343,16 +343,16 @@ extern "C"{ } // now that all of the files have been read, process the objects and contents - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_name].result == f_console_result_none){ + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { fprintf(f_standard_output, "%u\n", (unsigned int) data->objects.used); } else { current = 0; - if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_none){ - if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->contents.array[current].used > select){ + if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_none) { + if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->contents.array[current].used > select) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); fprintf(f_standard_output, "\n"); } else { @@ -361,8 +361,8 @@ extern "C"{ } } - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -370,14 +370,14 @@ extern "C"{ } } // for } else { - for (; current < data->objects.used; current++){ - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)){ + for (; current < data->objects.used; current++) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -392,21 +392,21 @@ extern "C"{ f_string_length name_length = f_string_length_initialize; f_string_length argv_length = f_string_length_initialize; - if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional){ + if (data->parameters[fss_extended_read_parameter_name].result == f_console_result_additional) { argv_length = strlen(argv[data->parameters[fss_extended_read_parameter_name].additional]); - if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none){ - for (; current < data->objects.used; current++){ + if (data->parameters[fss_extended_read_parameter_object].result == f_console_result_none) { + for (; current < data->objects.used; current++) { name_length = data->objects.array[current].stop - data->objects.array[current].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->objects.array[current].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)){ - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found) { total++; } else { - if (data->contents.array[current].used > select){ + if (data->contents.array[current].used > select) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->contents.array[current].array[select]); fprintf(f_standard_output, "\n"); } else { @@ -416,8 +416,8 @@ extern "C"{ } } - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -427,25 +427,25 @@ extern "C"{ } } // for - if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_count].result == f_console_result_none){ + if (data->parameters[fss_extended_read_parameter_total].result == f_console_result_found && data->parameters[fss_extended_read_parameter_count].result == f_console_result_none) { fprintf(f_standard_output, f_string_length_printf "\n", total); } } else { // when and because the object parameter is specified, the name parameter refers to the content instead of the object // therefore, make the search on the content and display the object - for (; current < data->contents.used; current++){ - if (data->contents.array[current].used > select){ + for (; current < data->contents.used; current++) { + if (data->contents.array[current].used > select) { name_length = data->contents.array[current].array[select].stop - data->contents.array[current].array[select].start + 1; - if (name_length == argv_length){ - if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[select].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to){ - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)){ + if (name_length == argv_length) { + if (fl_compare_strings(data->buffer.string + data->contents.array[current].array[select].start, argv[data->parameters[fss_extended_read_parameter_name].additional], name_length, argv_length) == f_equal_to) { + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_none || (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional && found == target)) { f_print_partial_dynamic_string(f_standard_output, data->buffer, data->objects.array[current]); fprintf(f_standard_output, "\n"); } - if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional){ - if (found == target){ + if (data->parameters[fss_extended_read_parameter_count].result == f_console_result_additional) { + if (found == target) { break; } else { found++; @@ -465,7 +465,7 @@ extern "C"{ #endif // _di_fss_extended_read_main_ #ifndef _di_fss_extended_read_delete_data_ - f_return_status fss_extended_read_delete_data(fss_extended_read_data *data){ + f_return_status fss_extended_read_delete_data(fss_extended_read_data *data) { f_status status = f_status_initialize; f_delete_fss_contents(status, data->contents); diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index ef6ac18..0d69a85 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -1,9 +1,9 @@ #include -int main(const f_array_length argc, const f_string argv[]){ +int main(const f_array_length argc, const f_string argv[]) { fss_extended_read_data data = fss_extended_read_data_initialize; - if (f_pipe_exists()){ + if (f_pipe_exists()) { data.process_pipe = f_true; } 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 6949c6a..b1ce725 100644 --- a/level_3/fss_return_code/c/fss_return_code.c +++ b/level_3/fss_return_code/c/fss_return_code.c @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_fss_return_code_print_version_ - f_return_status fss_return_code_print_version(const fss_return_code_data data){ + f_return_status fss_return_code_print_version(const fss_return_code_data data) { printf("%s\n", fss_return_code_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _fss_return_code_print_version_ #ifndef _di_fss_return_code_print_help_ - f_return_status fss_return_code_print_help(const fss_return_code_data data){ + f_return_status fss_return_code_print_help(const fss_return_code_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", fss_return_code_name_long); @@ -109,17 +109,17 @@ extern "C"{ #endif // _di_fss_return_code_print_help_ #ifndef _di_fss_return_code_main_ - f_return_status fss_return_code_main(const f_array_length argc, const f_string argv[], fss_return_code_data *data){ + f_return_status fss_return_code_main(const f_array_length argc, const f_string argv[], fss_return_code_data *data) { f_status status = f_status_initialize; f_status allocation_status = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, fss_return_code_total_parameters, &data->remaining); // load colors when not told to show no colors - if (data->parameters[fss_return_code_parameter_no_color].result == f_console_result_none){ + 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){ + if (allocation_status == f_none) { fll_colors_load_context(&data->context, data->parameters[fss_return_code_parameter_light].result == f_console_result_found); } else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -128,15 +128,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); } else { 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); @@ -147,19 +147,19 @@ extern "C"{ } // execute parameter results - if (data->parameters[fss_return_code_parameter_help].result == f_console_result_found){ + if (data->parameters[fss_return_code_parameter_help].result == f_console_result_found) { fss_return_code_print_help(*data); - } else if (data->parameters[fss_return_code_parameter_version].result == f_console_result_found){ + } else if (data->parameters[fss_return_code_parameter_version].result == f_console_result_found) { fss_return_code_print_version(*data); - } else if (data->parameters[fss_return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0){ + } else if (data->parameters[fss_return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_error(code)){ + if (fll_fss_errors_is_error(code)) { fss_return_code_delete_data(data); return f_true; } @@ -167,15 +167,15 @@ extern "C"{ fss_return_code_delete_data(data); return f_false; - } else if (data->parameters[fss_return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0){ + } else if (data->parameters[fss_return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_warning(code)){ + if (fll_fss_errors_is_warning(code)) { fss_return_code_delete_data(data); return f_true; } @@ -183,15 +183,15 @@ extern "C"{ 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_okay].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fll_fss_errors_is_okay(code)){ + if (fll_fss_errors_is_okay(code)) { fss_return_code_delete_data(data); return f_true; } @@ -199,19 +199,19 @@ extern "C"{ fss_return_code_delete_data(data); return f_false; - } else if (data->remaining.used > 0 || data->process_pipe){ + } else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = f_array_length_initialize; if (data->process_pipe) { // TODO: how should this be done? } - if (data->remaining.used > 0){ - for (; counter < data->remaining.used; counter++){ + if (data->remaining.used > 0) { + for (; counter < data->remaining.used; counter++) { f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); f_string string = f_null; - if (fll_fss_errors_to_string(code, &string) == f_none){ + if (fll_fss_errors_to_string(code, &string) == f_none) { printf("%s\n", string); } } // for @@ -227,7 +227,7 @@ extern "C"{ #endif // _di_fss_return_code_main_ #ifndef _di_fss_return_code_delete_data_ - f_return_status fss_return_code_delete_data(fss_return_code_data *data){ + f_return_status fss_return_code_delete_data(fss_return_code_data *data) { f_status status = f_status_initialize; f_delete_string_lengths(status, data->remaining); diff --git a/level_3/fss_return_code/c/main.c b/level_3/fss_return_code/c/main.c index 72fc878..a450891 100644 --- a/level_3/fss_return_code/c/main.c +++ b/level_3/fss_return_code/c/main.c @@ -1,10 +1,10 @@ #include -int main(const f_array_length argc, const f_string argv[]){ +int main(const f_array_length argc, const f_string argv[]) { fss_return_code_data data = fss_return_code_data_initialize; /* - if (f_pipe_exists()){ + if (f_pipe_exists()) { data.process_pipe = f_true; } */ diff --git a/level_3/return_code/c/main.c b/level_3/return_code/c/main.c index 4c61c76..fba08ce 100644 --- a/level_3/return_code/c/main.c +++ b/level_3/return_code/c/main.c @@ -1,10 +1,10 @@ #include -int main(const f_array_length argc, const f_string argv[]){ +int main(const f_array_length argc, const f_string argv[]) { return_code_data data = return_code_data_initialize; /* - if (f_pipe_exists()){ + if (f_pipe_exists()) { data.process_pipe = f_true; } */ diff --git a/level_3/return_code/c/return_code.c b/level_3/return_code/c/return_code.c index d407ad0..9a6b917 100644 --- a/level_3/return_code/c/return_code.c +++ b/level_3/return_code/c/return_code.c @@ -12,7 +12,7 @@ extern "C"{ // version printed may be used by scripts, so this will only print the version number and a newline, no extra information or colors #ifndef _di_return_code_print_version_ - f_return_status return_code_print_version(const return_code_data data){ + f_return_status return_code_print_version(const return_code_data data) { printf("%s\n", return_code_version); return f_none; @@ -20,7 +20,7 @@ extern "C"{ #endif // _return_code_print_version_ #ifndef _di_return_code_print_help_ - f_return_status return_code_print_help(const return_code_data data){ + f_return_status return_code_print_help(const return_code_data data) { printf("\n"); fl_print_color(f_standard_output, data.context.title, data.context.reset, " %s", return_code_name_long); @@ -109,17 +109,17 @@ extern "C"{ #endif // _di_return_code_print_help_ #ifndef _di_return_code_main_ - f_return_status return_code_main(const f_array_length argc, const f_string argv[], return_code_data *data){ + f_return_status return_code_main(const f_array_length argc, const f_string argv[], return_code_data *data) { f_status status = f_status_initialize; f_status allocation_status = f_status_initialize; status = fl_process_parameters(argc, argv, data->parameters, return_code_total_parameters, &data->remaining); // load colors when not told to show no colors - if (data->parameters[return_code_parameter_no_color].result == f_console_result_none){ + 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){ + if (allocation_status == f_none) { fll_colors_load_context(&data->context, data->parameters[return_code_parameter_light].result == f_console_result_found); } else { fprintf(f_standard_error, "Critical Error: unable to allocate memory\n"); @@ -128,15 +128,15 @@ extern "C"{ } } - if (status != f_none){ - if (status == f_no_data){ + if (status != f_none) { + 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 // to do this, one must look for any "has_additional" and then see if the "additional" location is set to 0 // nothing can be 0 as that represents the program name, unless argv[] is improperly created - } else if (f_macro_test_for_allocation_errors(status)){ + } else if (f_macro_test_for_allocation_errors(status)) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "CRITICAL ERROR: unable to allocate memory."); - } else if (status == f_invalid_parameter){ + } else if (status == f_invalid_parameter) { fl_print_color_line(f_standard_error, data->context.error, data->context.reset, "INTERNAL ERROR: Invalid parameter when calling fl_process_parameters()."); } else { 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); @@ -147,19 +147,19 @@ extern "C"{ } // execute parameter results - if (data->parameters[return_code_parameter_help].result == f_console_result_found){ + if (data->parameters[return_code_parameter_help].result == f_console_result_found) { return_code_print_help(*data); - } else if (data->parameters[return_code_parameter_version].result == f_console_result_found){ + } else if (data->parameters[return_code_parameter_version].result == f_console_result_found) { return_code_print_version(*data); - } else if (data->parameters[return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0){ + } else if (data->parameters[return_code_parameter_is_error].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_error(code)){ + if (fl_errors_is_error(code)) { return_code_delete_data(data); return f_true; } @@ -167,15 +167,15 @@ extern "C"{ return_code_delete_data(data); return f_false; - } else if (data->parameters[return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0){ + } else if (data->parameters[return_code_parameter_is_warning].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_warning(code)){ + if (fl_errors_is_warning(code)) { return_code_delete_data(data); return f_true; } @@ -183,15 +183,15 @@ extern "C"{ 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_okay].result == f_console_result_found && data->remaining.used > 0) { f_array_length counter = f_array_length_initialize; f_status code = f_status_initialize; - for (; counter < data->remaining.used; counter++){ + for (; counter < data->remaining.used; counter++) { code = (f_status) atoll(argv[data->remaining.array[counter]]); - if (fl_errors_is_okay(code)){ + if (fl_errors_is_okay(code)) { return_code_delete_data(data); return f_true; } @@ -199,19 +199,19 @@ extern "C"{ return_code_delete_data(data); return f_false; - } else if (data->remaining.used > 0 || data->process_pipe){ + } else if (data->remaining.used > 0 || data->process_pipe) { f_array_length counter = f_array_length_initialize; if (data->process_pipe) { // TODO: how should this be done? } - if (data->remaining.used > 0){ - for (; counter < data->remaining.used; counter++){ + if (data->remaining.used > 0) { + for (; counter < data->remaining.used; counter++) { f_status code = (f_status) atoll(argv[data->remaining.array[counter]]); f_string string = f_null; - if (fl_errors_to_string(code, &string) == f_none){ + if (fl_errors_to_string(code, &string) == f_none) { printf("%s\n", string); } } // for @@ -227,7 +227,7 @@ extern "C"{ #endif // _di_return_code_main_ #ifndef _di_return_code_delete_data_ - f_return_status return_code_delete_data(return_code_data *data){ + f_return_status return_code_delete_data(return_code_data *data) { f_status status = f_status_initialize; f_delete_string_lengths(status, data->remaining); -- 1.8.3.1