From 0f8c519eb4e090321ed95e7aebaa6a05d5c66d82 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 31 Mar 2012 18:04:56 -0500 Subject: [PATCH] Update: rework delimit management to ensure delimits are only applied when valid. This unfortunately increases the complexity slightly as deallocation must occur before functions exist. On the other hand doing so avoids overly complicated loops that would probably make the code less readable. --- level_1/fl_fss/c/fss_basic.c | 108 +++++++++++++++--- level_1/fl_fss/c/fss_basic_list.c | 77 ++++++++++--- level_1/fl_fss/c/fss_extended.c | 163 ++++++++++++++++++++++----- level_1/fl_fss/c/fss_macro.h | 218 +++++++++++++++++++++++++++++++++++-- level_2/fll_fss/c/fss_basic.c | 20 +++- level_2/fll_fss/c/fss_basic_list.c | 20 +++- level_2/fll_fss/c/fss_extended.c | 20 +++- 7 files changed, 549 insertions(+), 77 deletions(-) diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index c98017e..f5d84d1 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -22,8 +22,11 @@ extern "C"{ if (input->start >= buffer->used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders if (buffer->string[input->start] == f_fss_basic_close) { @@ -40,7 +43,7 @@ extern "C"{ // ignore all comment lines if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -70,10 +73,22 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, 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) { - buffer->string[last_slash] = f_fss_delimit_placeholder; + if (delimits.used >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + + delimits.array[delimits.used] = last_slash; + delimits.used++; input->start++; } } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { @@ -86,12 +101,14 @@ extern "C"{ 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) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (isspace(buffer->string[input->start])) { found->stop = input->start - 1; + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_object_no_content; @@ -119,7 +136,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) if (buffer->string[input->start] == quoted) { f_string_length location = input->start; @@ -127,10 +144,22 @@ extern "C"{ input->start = first_slash; if (slash_count % 2 == 0) { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -142,32 +171,54 @@ extern "C"{ input->start = location + 1; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) if (isgraph(buffer->string[input->start])) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + { + f_status allocation_status = f_status_initialize; + + f_delete_string_lengths(allocation_status, delimits); + } input->start++; return fl_fss_found_no_object; } else if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = input->start - 1; input->start++; return fl_fss_found_object_no_content; } + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = input->start - 1; input->start++; return fl_fss_found_object; } else { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -185,9 +236,11 @@ extern "C"{ while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); input->start++; return fl_fss_found_object_no_content; } else if (isspace(buffer->string[input->start])) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); input->start++; return fl_fss_found_object; } else if (buffer->string[input->start] != f_fss_delimit_placeholder) { @@ -195,7 +248,13 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + { + f_status allocation_status = f_status_initialize; + + f_delete_string_lengths(allocation_status, delimits); + } input->start++; return fl_fss_found_no_object; @@ -204,8 +263,14 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else if (buffer->string[input->start] == f_eol) { + { + f_status allocation_status = f_status_initialize; + + f_delete_string_lengths(allocation_status, delimits); + } + input->start++; return fl_fss_found_no_object; } @@ -213,7 +278,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) } // seek to the end of the line when no valid object is found @@ -221,7 +286,13 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) + + { + f_status allocation_status = f_status_initialize; + + f_delete_string_lengths(allocation_status, delimits); + } input->start++; return fl_fss_found_no_object; @@ -241,8 +312,11 @@ extern "C"{ if (found->used > found->size) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + 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) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, 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) { @@ -250,13 +324,13 @@ extern "C"{ return fl_fss_found_no_content; } - fl_macro_fss_allocate_content_if_necessary((*found)); + fl_macro_fss_allocate_content_if_necessary((*found), delimits); found->array[found->used].start = input->start; // search for valid content 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) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) if (buffer->string[input->start] == f_fss_basic_close) break; diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 5cea3ff..3643b61 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -22,8 +22,11 @@ extern "C"{ if (input->start >= buffer->used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders if (buffer->string[input->start] == f_eol) { @@ -36,7 +39,7 @@ extern "C"{ // ignore all comment lines if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -58,7 +61,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) if (buffer->string[input->start] == f_fss_basic_list_open) { f_string_length stop_point = input->start - 1; @@ -73,18 +76,30 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) if (buffer->string[input->start] == f_eol) { f_string_length location = input->start; input->start = first_slash; + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + if (slash_count % 2 == 0) { while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -93,6 +108,8 @@ extern "C"{ input->start++; } // while + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = stop_point; input->start = location + 1; @@ -118,9 +135,11 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = stop_point; input->start++; @@ -138,7 +157,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -157,10 +176,13 @@ extern "C"{ if (input->start >= buffer->used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + 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) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) - fl_macro_fss_allocate_content_if_necessary((*found)); + fl_macro_fss_allocate_content_if_necessary((*found), delimits); found->array[found->used].start = input->start; f_string_length last_newline = input->start; @@ -190,9 +212,9 @@ extern "C"{ } // while if (found_newline) { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } if (buffer->string[input->start] == f_fss_basic_list_open) { @@ -209,9 +231,9 @@ extern "C"{ } // while if (found_newline) { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } if (buffer->string[input->start] == f_eol) { @@ -220,7 +242,10 @@ extern "C"{ input->start = first_slash; if (slash_count % 2 == 0) { + // FIXME: apply delimits?? if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->array[found->used].stop = last_newline; input->start = last_newline + 1; found->used++; @@ -231,10 +256,22 @@ extern "C"{ return fl_fss_found_no_content; } + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -261,13 +298,15 @@ extern "C"{ } // while if (found_newline) { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) } if (buffer->string[input->start] == f_eol) { if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->array[found->used].stop = last_newline; input->start = last_newline + 1; found->used++; @@ -285,16 +324,18 @@ extern "C"{ } // while if (found_newline) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->array[found->used].stop = last_newline - 1; input->start = last_newline + 1; found->used++; - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) return fl_fss_found_content; } - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) return fl_fss_found_no_content; } diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index 56b4970..2ae99a4 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -22,8 +22,11 @@ extern "C"{ if (input->start >= buffer->used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + fl_macro_fss_skip_past_whitespace((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) // return found nothing if this line only contains whitespace and delimit placeholders if (buffer->string[input->start] == f_fss_extended_close) { @@ -40,7 +43,7 @@ extern "C"{ // ignore all comment lines if (buffer->string[input->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*input), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_seek_till_newline((*buffer), (*input), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -70,10 +73,22 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, 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) { - buffer->string[last_slash] = f_fss_delimit_placeholder; + if (delimits.used >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + + delimits.array[delimits.used] = last_slash; + delimits.used++; input->start++; } } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { @@ -86,12 +101,14 @@ extern "C"{ 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) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (isspace(buffer->string[input->start])) { found->stop = input->start - 1; + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_object_no_content; @@ -119,18 +136,30 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) if (buffer->string[input->start] == quoted) { f_string_length location = input->start; input->start = first_slash; + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + if (slash_count % 2 == 0) { while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -142,32 +171,48 @@ extern "C"{ input->start = location + 1; fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*input)) - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) if (isgraph(buffer->string[input->start])) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; } else if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = input->start - 1; input->start++; return fl_fss_found_object_no_content; } + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->stop = input->start - 1; input->start++; return fl_fss_found_object; } else { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -185,9 +230,13 @@ extern "C"{ while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + input->start++; return fl_fss_found_object_no_content; } else if (isspace(buffer->string[input->start])) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + input->start++; return fl_fss_found_object; } else if (buffer->string[input->start] != f_fss_delimit_placeholder) { @@ -195,7 +244,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -204,7 +253,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else if (buffer->string[input->start] == f_eol) { input->start++; return fl_fss_found_no_object; @@ -213,7 +262,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) } // seek to the end of the line when no valid object is found @@ -221,7 +270,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), f_no_data_on_eos, f_no_data_on_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*input), (*found), delimits, f_no_data_on_eos, f_no_data_on_stop) input->start++; return fl_fss_found_no_object; @@ -240,8 +289,11 @@ extern "C"{ if (input->start >= buffer->used) return f_invalid_parameter; #endif // _di_level_1_parameter_checking_ + // delimits must only be applied once a valid object is found + f_string_lengths delimits = f_string_lengths_initialize; + 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) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, 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_fss_extended_close) { @@ -264,7 +316,12 @@ extern "C"{ if (found->used >= found->size) { f_resize_fss_content(status, (*found), found->size + f_fss_default_allocation_step); - if (f_macro_test_for_allocation_errors(status)) return status; + if (f_macro_test_for_allocation_errors(status)){ + f_status allocation_status = f_status_initialize; + f_delete_string_lengths(allocation_status, delimits); + + return status; + } } // begin the search @@ -287,6 +344,8 @@ extern "C"{ found->used++; if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + return fl_fss_found_content; } @@ -305,10 +364,22 @@ extern "C"{ continue; } - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, 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) { - buffer->string[last_slash] = f_fss_delimit_placeholder; + if (delimits.used >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + + delimits.array[delimits.used] = last_slash; + delimits.used++; input->start++; } } else if (buffer->string[input->start] == f_fss_delimit_single_quote || buffer->string[input->start] == f_fss_delimit_double_quote) { @@ -321,7 +392,7 @@ extern "C"{ if (quoted == f_eos) { while (isgraph(buffer->string[input->start]) || buffer->string[input->start] == f_fss_delimit_placeholder) { input->start++; - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } // while if (isspace(buffer->string[input->start])) { @@ -329,6 +400,8 @@ extern "C"{ found->used++; if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + input->start++; return fl_fss_found_content; } @@ -355,17 +428,29 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) if (buffer->string[input->start] == quoted) { location = input->start; input->start = first_slash; if (slash_count % 2 == 0) { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -377,18 +462,20 @@ extern "C"{ input->start = location + 1; 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) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) if (isgraph(buffer->string[input->start])) { while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) input->start++; return f_unterminated_group; } else if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->array[found->used].stop = input->start - 1; input->start++; found->used++; @@ -401,10 +488,22 @@ extern "C"{ found->used++; continue; } else { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_status allocation_status = f_status_initialize; + + f_resize_string_lengths(allocation_status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(allocation_status)) { + f_delete_string_lengths(allocation_status, delimits); + return allocation_status; + } + } + while (slash_count > 0) { if (buffer->string[input->start] == f_fss_delimit_slash) { if (slash_count % 2 != 0) { - buffer->string[input->start] = f_fss_delimit_placeholder; + delimits.array[delimits.used] = input->start; + delimits.used++; } slash_count--; @@ -422,6 +521,8 @@ extern "C"{ while (input->start <= input->stop && input->start < buffer->used) { if (buffer->string[input->start] == f_eol) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + input->start++; found->used++; @@ -436,7 +537,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) input->start++; return f_unterminated_group; @@ -449,13 +550,15 @@ extern "C"{ break; } - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) } else if (buffer->string[input->start] == f_eol) { if (found->used == already_used) { input->start++; return fl_fss_found_no_content; } else { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + found->array[found->used].stop = input->start - 1; input->start++; found->used++; @@ -467,7 +570,7 @@ extern "C"{ input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_unterminated_group_on_eos, f_unterminated_group_on_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), delimits, f_unterminated_group_on_eos, f_unterminated_group_on_stop) } if (continue_main_loop) { @@ -478,20 +581,22 @@ extern "C"{ break; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) // seek to the end of the line when no valid content is found while (input->start < buffer->used && input->start <= input->stop && buffer->string[input->start] != f_eol) { input->start++; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*input), (*found), f_none_on_eos, f_none_on_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*input), (*found), delimits, f_none_on_eos, f_none_on_stop) if (found->used == already_used) { input->start++; return fl_fss_found_no_content; } + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + input->start++; return fl_fss_found_content; } diff --git a/level_1/fl_fss/c/fss_macro.h b/level_1/fl_fss/c/fss_macro.h index 570d53c..34bd531 100644 --- a/level_1/fl_fss/c/fss_macro.h +++ b/level_1/fl_fss/c/fss_macro.h @@ -14,6 +14,22 @@ extern "C"{ #endif +#ifndef _di_fl_macro_fss_apply_delimit_placeholders_ + #define fl_macro_fss_apply_delimit_placeholders(buffer, delimits) \ + { \ + f_status allocation_status = f_status_initialize; \ + \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + \ + f_delete_string_lengths(allocation_status, delimits); \ + } +#endif // _di_fl_macro_fss_apply_delimit_placeholders_ + #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) { \ @@ -47,78 +63,266 @@ extern "C"{ #endif // _di_fl_macro_fss_skip_past_delimit_placeholders_ #ifndef _di_fl_macro_fss_object_return_on_overflow_ - #define fl_macro_fss_object_return_on_overflow(buffer, input, found, eos_status, stop_status) \ + #define fl_macro_fss_object_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.stop = buffer.used - 1; \ return eos_status; \ } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.stop = input.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_object_return_on_overflow_ +#ifndef _di_fl_macro_fss_object_delimited_return_on_overflow_ + #define fl_macro_fss_object_delimited_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ + if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.stop = buffer.used - 1; \ + return eos_status; \ + } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.stop = input.stop; \ + return stop_status; \ + } +#endif // _di_fl_macro_fss_object_delimited_return_on_overflow_ + #ifndef _di_fl_macro_fss_content_return_on_overflow_ - #define fl_macro_fss_content_return_on_overflow(buffer, input, found, eos_status, stop_status) \ + #define fl_macro_fss_content_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.array[found.used].stop = buffer.used - 1; \ return eos_status; \ } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.array[found.used].stop = input.stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_content_return_on_overflow_ +#ifndef _di_fl_macro_fss_content_delimited_return_on_overflow_ + #define fl_macro_fss_content_delimited_return_on_overflow(buffer, input, found, delimits, eos_status, stop_status) \ + if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.array[found.used].stop = buffer.used - 1; \ + return eos_status; \ + } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.array[found.used].stop = input.stop; \ + return stop_status; \ + } +#endif // _di_fl_macro_fss_content_delimited_return_on_overflow_ + #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) \ + #define fl_macro_fss_content_return_on_overflow_reset(buffer, input, found, delimits, eos_status, stop_status, set_stop) \ if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return eos_status; \ } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ input.start = set_stop; \ found.array[found.used].stop = set_stop; \ return stop_status; \ } #endif // _di_fl_macro_fss_content_return_on_overflow_reset_ +#ifndef _di_fl_macro_fss_content_delimited_return_on_overflow_reset_ + #define fl_macro_fss_content_delimited_return_on_overflow_reset(buffer, input, found, delimits, eos_status, stop_status, set_stop) \ + if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + input.start = set_stop; \ + found.array[found.used].stop = set_stop; \ + return eos_status; \ + } else if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + input.start = set_stop; \ + found.array[found.used].stop = set_stop; \ + return stop_status; \ + } +#endif // _di_fl_macro_fss_content_delimited_return_on_overflow_reset_ + #ifndef _di_fl_macro_fss_allocate_content_if_necessary_ - #define fl_macro_fss_allocate_content_if_necessary(content) \ + #define fl_macro_fss_allocate_content_if_necessary(content, delimits) \ if (content.used >= content.size) { \ f_status status = f_status_initialize; \ \ f_resize_fss_content(status, content, content.size + f_fss_default_allocation_step); \ - if (f_macro_test_for_allocation_errors(status)) return status; \ + if (f_macro_test_for_allocation_errors(status)) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + return status; \ + } \ } #endif // _di_fl_macro_fss_allocate_content_if_necessary_ #ifndef _di_fl_macro_fss_object_seek_till_newline_ - #define fl_macro_fss_object_seek_till_newline(buffer, input, eos_status, stop_status) \ + #define fl_macro_fss_object_seek_till_newline(buffer, input, delimits, eos_status, stop_status) \ while (buffer.string[input.start] != f_eol) { \ ++input.start; \ if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ return eos_status; \ } \ if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ return stop_status; \ } \ } // while #endif // _di_fl_macro_fss_object_seek_till_newline_ +#ifndef _di_fl_macro_fss_object_delimited_seek_till_newline_ + #define fl_macro_fss_object_delimited_seek_till_newline(buffer, input, delimits, eos_status, stop_status) \ + while (buffer.string[input.start] != f_eol) { \ + ++input.start; \ + if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + return eos_status; \ + } \ + if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + return stop_status; \ + } \ + } // while +#endif // _di_fl_macro_fss_object_delimited_seek_till_newline_ + #ifndef _di_fl_macro_fss_content_seek_till_newline_ - #define fl_macro_fss_content_seek_till_newline(buffer, input, found, eos_status, stop_status) \ + #define fl_macro_fss_content_seek_till_newline(buffer, input, found, delimits, eos_status, stop_status) \ while (buffer.string[input.start] != f_eol) { \ ++input.start; \ if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.array[found.used].stop = input.stop; \ return eos_status; \ } \ if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_delete_string_lengths(allocation_status, delimits); \ + \ found.array[found.used].stop = input.stop; \ return stop_status; \ } \ } // while #endif // _di_fl_macro_fss_content_seek_till_newline_ +#ifndef _di_fl_macro_fss_content_delimited_seek_till_newline_ + #define fl_macro_fss_content_delimited_seek_till_newline(buffer, input, found, delimits, eos_status, stop_status) \ + while (buffer.string[input.start] != f_eol) { \ + ++input.start; \ + if (input.start >= buffer.used) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.array[found.used].stop = input.stop; \ + return eos_status; \ + } \ + if (input.start > input.stop) { \ + f_status allocation_status = f_status_initialize; \ + f_string_length i = 0; \ + \ + while (i < delimits.used) { \ + buffer.string[delimits.array[i]] = f_fss_delimit_placeholder; \ + i++; \ + } \ + f_delete_string_lengths(allocation_status, delimits); \ + \ + found.array[found.used].stop = input.stop; \ + return stop_status; \ + } \ + } // while +#endif // _di_fl_macro_fss_content_delimited_seek_till_newline_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index 38adae2..eb02e88 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -44,7 +44,15 @@ extern "C"{ 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]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } contents->used++; @@ -74,7 +82,15 @@ extern "C"{ } else if (status == fl_fss_found_object_no_content) { found_data = f_true; - fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } break; } diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 50688c1..ef97455 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -44,7 +44,15 @@ extern "C"{ 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]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } contents->used++; @@ -74,7 +82,15 @@ extern "C"{ } else if (status == fl_fss_found_object_no_content) { found_data = f_true; - fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } break; } diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index 8792e0d..ff2573b 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -44,7 +44,15 @@ extern "C"{ 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]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } contents->used++; @@ -74,7 +82,15 @@ extern "C"{ } else if (status == fl_fss_found_object_no_content) { found_data = f_true; - fl_macro_fss_allocate_content_if_necessary(contents->array[contents->used]); + if (contents->array[contents->used].used >= contents->array[contents->used].size) { + f_status status = f_status_initialize; + + f_resize_fss_content(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + + if (f_macro_test_for_allocation_errors(status)) { + return status; + } + } break; } -- 1.8.3.1