From: Kevin Day Date: Sat, 20 Jun 2020 16:46:24 +0000 (-0500) Subject: Progress: update FSS code, including zero-width updates X-Git-Tag: 0.5.0~149 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=bcdbeabfb50664967e803da7b149f480eaf0fd6d;p=fll Progress: update FSS code, including zero-width updates Update FSS to consider the recent zero-width improvements. Making the changes reminded me on how I still need to go through and clean the FSS code up. As noted in previous commits, the changes into supporting UTF really put the code into an unideal and not well tested state. This needs extensive review and fixes. To that end, I felt compelled to fix problems and perform cleanups that I observed. At least to a small extent. The basic and extended object reads are identical so move the code into a shared private function. One behavioral change is to better support fail-through practice. For FSS Extended, the contents are always terminated by a newline. However, if there is an unterminated quote, then the entire process would previously fail. This time, do no accept content for that line and continue on to next content. --- diff --git a/level_0/f_fss/c/fss.c b/level_0/f_fss/c/fss.c index 9f5cb2e..157fc1f 100644 --- a/level_0/f_fss/c/fss.c +++ b/level_0/f_fss/c/fss.c @@ -156,20 +156,58 @@ extern "C" { if (range.start >= buffer.used) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ + f_status status = F_none; + f_string_length width_max = (range.stop - range.start) + 1; if (width_max > buffer.used - range.start) { width_max = buffer.used - range.start; } - return f_utf_is_whitespace(buffer.string + range.start, width_max); + // Handle (ASCII) zero-width spaces and control characters (isspace() or iscntrl() might consider some of these spaces). + status = f_utf_is_zero_width(buffer.string + range.start, width_max); + + if (status != F_false) { + if (status == F_true) { + return F_false; + } + + return status; + } + + status = f_utf_is_whitespace(buffer.string + range.start, width_max); + + if (status == F_false) { + return f_utf_is_control(buffer.string + range.start, width_max); + } + + return status; } #endif // _di_f_fss_is_space_ +#ifndef _di_f_fss_is_zero_width_ + f_return_status f_fss_is_zero_width(const f_string_static buffer, const f_string_range range) { + #ifndef _di_level_0_parameter_checking_ + if (buffer.used <= 0) return F_status_set_error(F_parameter); + if (range.start < 0) return F_status_set_error(F_parameter); + if (range.stop < range.start) return F_status_set_error(F_parameter); + if (range.start >= buffer.used) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + f_string_length width_max = (range.stop - range.start) + 1; + + if (width_max > buffer.used - range.start) { + width_max = buffer.used - range.start; + } + + return f_utf_is_zero_width(buffer.string + range.start, width_max); + } +#endif // _di_f_fss_is_zero_width_ + #ifndef _di_f_fss_shift_delimiters_ f_return_status f_fss_shift_delimiters(f_string_dynamic *buffer, const f_string_range range) { #ifndef _di_level_0_parameter_checking_ - if (buffer->used <= 0) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); if (range.start < 0) return F_status_set_error(F_parameter); if (range.stop < range.start) return F_status_set_error(F_parameter); if (range.start >= buffer->used) return F_status_set_error(F_parameter); @@ -193,6 +231,7 @@ extern "C" { } utf_width = f_macro_utf_byte_width_is(buffer->string[position]); + if (utf_width > 1) { // not enough space in buffer or in range range to process UTF-8 character. if (position + utf_width >= buffer->used || position + utf_width > range.stop) { @@ -238,7 +277,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ f_status status = F_none; - unsigned short width = 0; + uint8_t width = 0; f_string_length width_max = (range->stop - range->start) + 1; @@ -247,63 +286,31 @@ extern "C" { } for (;;) { - if (buffer.string[range->start] != f_fss_delimit_placeholder) { - status = f_utf_is_whitespace(buffer.string + range->start, width_max); + if (buffer.string[range->start] == f_string_eol[0]) { + return F_none_eol; + } - if (status == F_false) { - status = f_utf_is_control(buffer.string + range->start, width_max); + if (buffer.string[range->start] == f_fss_delimit_placeholder) { + range->start++; - if (status == F_false) { - status = f_utf_is_zero_width(buffer.string + range->start, width_max); + if (range->start >= buffer.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; - if (status == F_true) { - f_string_length next_width_max = 0; + continue; + } - for (f_string_length next = range->start + 1; next < buffer.used && next <= range->stop; next += f_macro_utf_byte_width_is(buffer.string[next])) { - next_width_max = (range->stop - next) + 1; + status = f_utf_is_whitespace(buffer.string + range->start, width_max); + if (F_status_is_error(status)) return status; - status = f_utf_is_whitespace(buffer.string + next, width_max); - if (status == F_true) { - // treat zero-width before a space like a space. - break; - } - else if (status == F_false) { - status = f_utf_is_control(buffer.string + next, width_max); - - if (status == F_true) { - // treat zero-width before a control character like a space. - break; - } - else if (status == F_false) { - status = f_utf_is_zero_width(buffer.string + next, width_max); - - if (status == F_true) { - // seek until a non-zero-width is reached. - continue; - } - else if (status == F_false) { - // treat zero-width as a non-whitespace non-control character when preceding a non-whitespace non-control character. - return F_none; - } - } - else if (F_status_is_error(status)) return status; - } - else if (F_status_is_error(status)) return status; - } // for - } - else if (status == F_false) { - // treat zero-width as a graph when preceding a non-whitespace non-control (that is not a zero-width). - return F_none; - } - else if (F_status_is_error(status)) return status; - } - else if (F_status_is_error(status)) return status; + if (status == F_false) { + status = f_utf_is_zero_width(buffer.string + range->start, width_max); + if (F_status_is_error(status)) return status; + + if (status == F_false) { + return F_none; } - else if (F_status_is_error(status)) return status; } - if (buffer.string[range->start] == f_string_eol[0]) return F_none_eol; - width = f_macro_utf_byte_width_is(buffer.string[range->start]); if (width == 0) { @@ -330,8 +337,6 @@ extern "C" { } } // for - if (F_status_is_error(status)) return status; - return F_none; } #endif // _di_f_fss_skip_past_space_ diff --git a/level_0/f_fss/c/fss.h b/level_0/f_fss/c/fss.h index 0983667..7e8261c 100644 --- a/level_0/f_fss/c/fss.h +++ b/level_0/f_fss/c/fss.h @@ -157,7 +157,7 @@ extern "C" { #endif // _di_f_fss_is_graph_ /** - * Identify whether or not a character in the buffer is a space (ASCII or UTF-8) character. + * Identify whether or not a character in the buffer is a non-zero-width whitespace or control (ASCII or UTF-8) character. * * @param buffer * The string to process. @@ -171,15 +171,41 @@ extern "C" { * F_false if the character in the buffer is not a space character. * F_parameter (with error bit) if a parameter is invalid. * - * Errors from (with error bit): f_utf_is_space(). + * Errors from (with error bit): f_utf_is_control(). + * Errors from (with error bit): f_utf_is_whitespace(). * - * @see f_utf_is_space() + * @see f_utf_is_control() + * @see f_utf_is_whitespace() */ #ifndef _di_f_fss_is_space_ extern f_return_status f_fss_is_space(const f_string_static buffer, const f_string_range range); #endif // _di_f_fss_is_space_ /** + * Identify whether or not a character in the buffer is a non-zero-width whitespace or control (ASCII or UTF-8) character. + * + * @param buffer + * The string to process. + * @param range + * The character at the start position will be checked against the graph. + * @param header + * The header data to populate with results of this function. + * + * @return + * F_true if the character in the buffer is a space character. + * F_false if the character in the buffer is not a space character. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors from (with error bit): f_utf_is_control(). + * Errors from (with error bit): f_utf_is_whitespace(). + * + * @see f_utf_is_zero_width() + */ +#ifndef _di_f_fss_is_zero_width_ + extern f_return_status f_fss_is_zero_width(const f_string_static buffer, const f_string_range range); +#endif // _di_f_fss_is_zero_width_ + +/** * Shift all of the delimiters to the end of the used buffer. * * This allows one to do a printf on the dynamic string without the delimiters arbitrarily stopping the output. diff --git a/level_1/fl_fss/c/fss.h b/level_1/fl_fss/c/fss.h index 8658ec8..01d09ea 100644 --- a/level_1/fl_fss/c/fss.h +++ b/level_1/fl_fss/c/fss.h @@ -23,6 +23,7 @@ // fll-1 includes #include +#include #ifdef __cplusplus extern "C" { diff --git a/level_1/fl_fss/c/fss_basic.c b/level_1/fl_fss/c/fss_basic.c index a23db51..74740bd 100644 --- a/level_1/fl_fss/c/fss_basic.c +++ b/level_1/fl_fss/c/fss_basic.c @@ -1,410 +1,74 @@ #include +#include "private-fss.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_object_read_ - f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found) { + f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status status = F_none; - - // delimits must only be applied once a valid object is found - f_string_lengths delimits = f_string_lengths_initialize; - - status = f_fss_skip_past_space(*buffer, location); - if (F_status_is_error(status)) return status; - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[location->start] == f_fss_basic_close) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - // when handling delimits, the only time they should be applied is when a valid object would exist - // however, the delimits will appear before a valid object, so remember their positions and only apply them after a would be valid object is confirmed - bool has_delimit = F_false; - - // begin the search - found->start = location->start; - - // ignore all comment lines - if (buffer->string[location->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, F_data_not_eos, F_data_not_stop) - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - // handle quote support - int8_t quoted = 0; - - // identify where the object begins - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length last_slash = location->start; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - continue; - } - else { - status = f_fss_is_graph(*buffer, *location); - if (status == F_false) { - found->stop = location->start - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] != f_fss_delimit_slash) { - break; - } - } - - last_slash = location->start; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - - if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { - if (delimits.used >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - delimits.array[delimits.used] = last_slash; - delimits.used++; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } - } - else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[location->start]; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - found->start = location->start; - } - - // identify where the object ends - if (quoted == 0) { - status = F_none; - while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = f_fss_is_space(*buffer, *location)) == F_false) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - } // while - - if (F_status_is_error(status)) return status; - - status = f_fss_is_space(*buffer, *location); - if (status == F_true) { - found->stop = location->start - 1; - - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - if (buffer->string[location->start] == f_string_eol[0]) { - location->start++; - return FL_fss_found_object_content_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - } - else { - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; - f_string_length slash_count = 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - continue; - } - else if (buffer->string[location->start] != f_fss_delimit_slash) { - break; - } - - slash_count++; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) - - if (buffer->string[location->start] == quoted) { - f_string_length length = location->start; - - location->start = first_slash; - - if (slash_count % 2 == 0) { - if (delimits.used + (slash_count / 2) >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; - delimits.used++; - } - - slash_count--; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - location->start = length + 1; - - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - - if ((status = f_fss_is_graph(*buffer, *location)) == F_true) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - f_macro_string_lengths_delete_simple(delimits); - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] == f_string_eol[0]) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - found->stop = length - 1; - location->start++; - return FL_fss_found_object_content_not; - } - - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - found->stop = length - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else { - if (delimits.used + (slash_count / 2) >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; - delimits.used++; - } - - slash_count--; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - location->start = length; - } - } - } - else if (buffer->string[location->start] == quoted) { - found->stop = location->start - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_string_eol[0]) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - location->start++; - return FL_fss_found_object_content_not; - } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] != f_fss_delimit_placeholder) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - f_macro_string_lengths_delete_simple(delimits); - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - } - else if (buffer->string[location->start] == f_string_eol[0]) { - f_macro_string_lengths_delete_simple(delimits); - - location->start++; - return FL_fss_found_object_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) - } - - // seek to the end of the line when no valid object is found - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - f_macro_string_lengths_delete_simple(delimits); - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; + return private_fl_fss_basic_object_read(F_true, buffer, range, found); } #endif // _di_fl_fss_basic_object_read_ #ifndef _di_fl_fss_basic_content_read_ - f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_content *found) { + f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; - // delimits must only be applied once a valid object is found + // delimits must only be applied once a valid object is found. f_string_lengths delimits = f_string_lengths_initialize; - f_fss_skip_past_space(*buffer, location); + status = f_fss_skip_past_space(*buffer, range); if (F_status_is_error(status)) return status; - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - - // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[location->start] == f_string_eol[0]) { - location->start++; + // return found nothing if this line only contains whitespace and delimit placeholders. + if (status == F_none_eol) { + range->start++; return FL_fss_found_content_not; } + else if (status == F_none_eos) { + return F_data_not_eos; + } + else if (status == F_none_stop) { + return F_data_not_stop; + } fl_macro_fss_allocate_content_if_necessary((*found), delimits); - found->array[found->used].start = location->start; + found->array[found->used].start = range->start; - // search for valid content + // search for valid content. for (;;) { - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) - if (buffer->string[location->start] == f_fss_basic_close) break; + if (buffer->string[range->start] == f_fss_basic_close) break; - location->start++; + range->start++; } // for - // Save the stop length - found->array[found->used].stop = location->start - 1; + // Save the stop length/ + found->array[found->used].stop = range->start - 1; found->used++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_content; @@ -412,7 +76,7 @@ extern "C" { #endif // _di_fl_fss_basic_content_read_ #ifndef _di_fl_fss_basic_object_write_ - f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_static object, f_string_range *location) { + f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_static object, f_string_range *range) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -424,15 +88,15 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)); - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= object.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= object.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 3 to ensure that there is room for the start and stop quotes or a slash delimit and the object open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 3 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 3 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -442,26 +106,26 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - if (object.string[location->start] == f_fss_delimit_slash) { - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + if (object.string[range->start] == f_fss_delimit_slash) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (object.string[location->start] != f_fss_delimit_slash) { + else if (object.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { + if (object.string[range->start] == f_fss_delimit_single_quote || object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -470,14 +134,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[location->start]; + buffer->string[buffer_position.stop + 1] = object.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } } - else if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { + else if (object.string[range->start] == f_fss_delimit_single_quote || object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -487,24 +151,24 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[location->start]; + buffer->string[buffer_position.stop + 1] = object.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } - else if (object.string[location->start] == f_fss_comment) { + else if (object.string[range->start] == f_fss_comment) { quoted = F_true; } - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -515,7 +179,7 @@ extern "C" { return F_none_eol; } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true || quoted) { + else if ((status = f_fss_is_space(*buffer, *range)) == F_true || quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -524,20 +188,20 @@ extern "C" { } // restart the loop searching for f_fss_delimit_double_quote. - location->start = start_position; + range->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (object.string[location->start] == f_fss_delimit_double_quote) { + else if (object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -548,24 +212,24 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; } - else if (object.string[location->start] == f_fss_delimit_slash) { + else if (object.string[range->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; for (;;) { - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; slash_count++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)); + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)); - if (location->start > location->stop || location->start >= object.used) { + if (range->start > range->stop || range->start >= object.used) { break; } - if (object.string[location->start] == f_fss_delimit_double_quote) { + if (object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -575,7 +239,7 @@ extern "C" { break; } - else if (object.string[location->start] != f_fss_delimit_slash) { + else if (object.string[range->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -589,7 +253,7 @@ extern "C" { continue; } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -599,9 +263,9 @@ extern "C" { return F_none_eol; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; buffer_position.stop++; @@ -616,9 +280,9 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; buffer_position.stop++; @@ -629,15 +293,15 @@ extern "C" { buffer->used = buffer_position.stop + 1; } - if (location->start > location->stop) return F_none_stop; - else if (location->start >= object.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= object.used) return F_none_eos; return F_none; } #endif // _di_fl_fss_basic_object_write_ #ifndef _di_fl_fss_basic_content_write_ - f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_static content, f_string_range *location) { + f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_static content, f_string_range *range) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -648,10 +312,10 @@ extern "C" { f_string_range buffer_position = f_string_range_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= content.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= content.used) return F_data_not_eos; // add an additional 1 to ensure that there is room for the terminating newline. pre_allocate_size = buffer->used + (content.used) + 1 + f_fss_default_allocation_step_string; @@ -664,27 +328,27 @@ extern "C" { if (F_status_is_error(status)) return status; } - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_string_eol[0]) { + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_string_eol[0]) { buffer->string[buffer_position.stop] = f_string_eol[0]; buffer->used = buffer_position.stop + 1; return F_none_eos; } - if (content.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[location->start]; + if (content.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while buffer->string[buffer_position.stop] = f_string_eol[0]; buffer->used = buffer_position.stop + 1; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= content.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= content.used) return F_none_eos; return F_none; } diff --git a/level_1/fl_fss/c/fss_basic.h b/level_1/fl_fss/c/fss_basic.h index b4255b4..06f2ec2 100644 --- a/level_1/fl_fss/c/fss_basic.h +++ b/level_1/fl_fss/c/fss_basic.h @@ -40,7 +40,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -70,7 +70,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_basic_object_read_ - extern f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found); + extern f_return_status fl_fss_basic_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found); #endif // _di_fl_fss_basic_object_read_ /** @@ -82,7 +82,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -112,7 +112,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_basic_content_read_ - extern f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_content *found); + extern f_return_status fl_fss_basic_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found); #endif // _di_fl_fss_basic_content_read_ /** @@ -124,7 +124,7 @@ extern "C" { * * @param object * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the object string to write as an object. * @param buffer * The buffer where the object is written to. @@ -144,7 +144,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_basic_object_write_ - extern f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_static object, f_string_range *location); + extern f_return_status fl_fss_basic_object_write(f_string_dynamic *buffer, const f_string_static object, f_string_range *range); #endif // _di_fl_fss_basic_object_write_ /** @@ -155,7 +155,7 @@ extern "C" { * * @param content * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the content string to write as an content. * @param buffer * The buffer where the content is written to. @@ -175,7 +175,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_basic_content_write_ - extern f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_static content, f_string_range *location); + extern f_return_status fl_fss_basic_content_write(f_string_dynamic *buffer, const f_string_static content, f_string_range *range); #endif // _di_fl_fss_basic_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_basic_list.c b/level_1/fl_fss/c/fss_basic_list.c index 4216c67..56ad5ec 100644 --- a/level_1/fl_fss/c/fss_basic_list.c +++ b/level_1/fl_fss/c/fss_basic_list.c @@ -1,19 +1,19 @@ #include +#include "private-fss.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_basic_list_object_read_ - f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found) { + f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; @@ -21,71 +21,78 @@ extern "C" { // delimits must only be applied once a valid object is found. f_string_lengths delimits = f_string_lengths_initialize; - f_fss_skip_past_space(*buffer, location); - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + status = f_fss_skip_past_space(*buffer, range); + if (F_status_is_error(status)) return status; // return found nothing if this line only contains whitespace and delimit placeholders. - if (buffer->string[location->start] == f_string_eol[0]) { - location->start++; + if (status == F_none_eol) { + range->start++; return FL_fss_found_object_not; } + else if (status == F_none_eos) { + return F_data_not_eos; + } + else if (status == F_none_stop) { + return F_data_not_stop; + } // begin the search. - found->start = location->start; + found->start = range->start; // ignore all comment lines. - if (buffer->string[location->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, F_data_not_eos, F_data_not_stop) + if (buffer->string[range->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*range), delimits, F_data_not_eos, F_data_not_stop) - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object_not; } // identify where the object ends. - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; f_string_length slash_count = 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + if (buffer->string[range->start] == f_fss_delimit_slash) { slash_count++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - if (buffer->string[location->start] == f_fss_basic_list_open) { - f_string_length stop_point = location->start - 1; + if (buffer->string[range->start] == f_fss_basic_list_open) { + f_string_length stop_point = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - break; - } + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - if (buffer->string[location->start] == f_string_eol[0]) { - f_string_length start = location->start; + if (buffer->string[range->start] == f_string_eol[0]) { + f_string_length start = range->start; - location->start = first_slash; + range->start = first_slash; if (delimits.used + (slash_count / 2) >= delimits.size) { f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); @@ -98,59 +105,60 @@ extern "C" { if (slash_count % 2 == 0) { while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } slash_count--; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - location->start = start + 1; + range->start = start + 1; return FL_fss_found_object; } - location->start = start + 1; + range->start = start + 1; return FL_fss_found_object_not; } } continue; } - else if (buffer->string[location->start] == f_fss_basic_list_open) { - f_string_length stop_point = location->start - 1; + else if (buffer->string[range->start] == f_fss_basic_list_open) { + f_string_length stop_point = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - break; - } + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object; @@ -159,19 +167,19 @@ extern "C" { continue; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while // seek to the end of the line when no valid object is found. - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object_not; @@ -179,15 +187,14 @@ 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_string_dynamic *buffer, f_string_range *location, f_fss_content *found) { + f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; @@ -195,87 +202,88 @@ extern "C" { // 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), (*location)) - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) fl_macro_fss_allocate_content_if_necessary((*found), delimits); - found->array[found->used].start = location->start; + found->array[found->used].start = range->start; - f_string_length last_newline = location->start; + f_string_length last_newline = range->start; bool found_newline = F_false; // identify where the content ends. - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) { found_newline = F_true; - last_newline = location->start; + last_newline = range->start; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) continue; } - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; f_string_length slash_count = 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + if (buffer->string[range->start] == f_fss_delimit_slash) { slash_count++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) } - if (buffer->string[location->start] == f_fss_basic_list_open) { - f_string_length stop_point = location->start - 1; + if (buffer->string[range->start] == f_fss_basic_list_open) { + f_string_length stop_point = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - break; - } + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) } - if (buffer->string[location->start] == f_string_eol[0]) { - f_string_length start = location->start; + if (buffer->string[range->start] == f_string_eol[0]) { + f_string_length start = range->start; - location->start = first_slash; + range->start = first_slash; if (slash_count % 2 == 0) { if (found_newline) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline; - location->start = last_newline + 1; + range->start = last_newline + 1; found->used++; return FL_fss_found_content; @@ -294,61 +302,62 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } slash_count--; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while found_newline = F_true; - location->start = start + 1; + range->start = start + 1; } } continue; } - else if (buffer->string[location->start] == f_fss_basic_list_open) { - status = f_fss_increment_buffer(*buffer, location, 1); + else if (buffer->string[range->start] == f_fss_basic_list_open) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - break; - } + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while if (found_newline) { - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) } else { - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) } - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { if (found_newline) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline; - location->start = last_newline + 1; + range->start = last_newline + 1; found->used++; return FL_fss_found_content; } if (!found_newline) { - location->start = last_newline; + range->start = last_newline; } return FL_fss_found_content_not; @@ -357,7 +366,7 @@ extern "C" { continue; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while @@ -365,22 +374,22 @@ extern "C" { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->array[found->used].stop = last_newline - 1; - location->start = last_newline + 1; + range->start = last_newline + 1; found->used++; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) return FL_fss_found_content; } - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop) return FL_fss_found_content_not; } #endif // _di_fl_fss_basic_list_content_read_ #ifndef _di_fl_fss_basic_list_object_write_ - f_return_status fl_fss_basic_list_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_basic_list_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -392,15 +401,15 @@ extern "C" { f_string_length pre_allocate_size = 0; f_string_length start_buffer = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= object.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= object.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 2 to ensure that there is room for the slash delimit and the object open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -410,57 +419,57 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_comment) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_comment) { // comments are not allowed and this format has no way of "wrapping" a comment. return F_status_set_error(FL_fss_found_comment); } - else if ((status = f_fss_is_graph(object, *location)) == F_true) { + else if ((status = f_fss_is_graph(object, *range)) == F_true) { break; } else if (F_status_is_error(status)) { return status; } - if (object.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[location->start]; + if (object.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; } // while - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_slash) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_slash) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(object, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; continue; - } else if (object.string[location->start] != f_fss_delimit_slash) { + } else if (object.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; slash_count++; } // while - if (location->start > location->stop || location->start >= object.used) { + if (range->start > range->stop || range->start >= object.used) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -477,7 +486,7 @@ extern "C" { break; } } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { if (buffer_position.stop == buffer_position.start) { return F_data_not_eol; } @@ -485,12 +494,12 @@ extern "C" { break; } - if (object.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[location->start]; + if (object.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; } // while @@ -498,15 +507,15 @@ extern "C" { buffer->string[buffer_position.stop + 1] = f_string_eol[0]; buffer->used = buffer_position.stop + 2; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= object.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= object.used) return F_none_eos; return F_none; } #endif // _di_fl_fss_basic_list_object_write_ #ifndef _di_fl_fss_basic_list_content_write_ - f_return_status fl_fss_basic_list_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_basic_list_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -519,15 +528,15 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= content.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= content.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 2 to ensure that there is room for the slash delimit and the content open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -538,55 +547,56 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_slash && !is_comment) { + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_slash && !is_comment) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; has_graph = F_true; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(content, location, 1); + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (content.string[location->start] != f_fss_delimit_slash) { + else if (content.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; slash_count++; } // while - if (content.string[location->start] == f_fss_basic_list_open) { - f_string_length start = location->start; + if (content.string[range->start] == f_fss_basic_list_open) { + f_string_length start = range->start; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start < content.used && location->start <= location->stop) { - if (content.string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *location)) == F_true) { - break; - } + while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(content, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while - if (content.string[location->start] == f_string_eol[0] || location->start >= content.used || location->start > location->stop) { + if (content.string[range->start] == f_string_eol[0] || range->start >= content.used || range->start > range->stop) { pre_allocate_size += slash_count + 1; if (pre_allocate_size > buffer->size) { @@ -608,30 +618,31 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_basic_list_open; buffer_position.stop++; - location->start = start + 1; + range->start = start + 1; continue; } } - else if (content.string[location->start] == f_fss_basic_list_open && !is_comment) { - f_string_length start = location->start; + else if (content.string[range->start] == f_fss_basic_list_open && !is_comment) { + f_string_length start = range->start; has_graph = F_true; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start < content.used && location->start <= location->stop) { - if (content.string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *location)) == F_true) { - break; - } + while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(content, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while - if (content.string[location->start] == f_string_eol[0] || location->start >= content.used || location->start > location->stop) { + if (content.string[range->start] == f_string_eol[0] || range->start >= content.used || range->start > range->stop) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -647,37 +658,37 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_basic_list_open; buffer_position.stop++; - location->start = start + 1; + range->start = start + 1; continue; } - else if (content.string[location->start] == f_fss_comment && !has_graph) { + else if (content.string[range->start] == f_fss_comment && !has_graph) { is_comment = F_true; } - else if (content.string[location->start] == f_string_eol[0]) { + else if (content.string[range->start] == f_string_eol[0]) { has_graph = F_false; is_comment = F_false; } - else if ((status = f_fss_is_graph(content, *location)) == F_true) { + else if ((status = f_fss_is_graph(content, *range)) == F_true) { has_graph = F_true; } else if (F_status_is_error(status)) { return status; } - if (content.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[location->start]; + if (content.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while buffer->string[buffer_position.stop] = f_string_eol[0]; buffer->used = buffer_position.stop + 1; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= content.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= content.used) return F_none_eos; return F_none; } diff --git a/level_1/fl_fss/c/fss_basic_list.h b/level_1/fl_fss/c/fss_basic_list.h index 7ef2007..3bc800a 100644 --- a/level_1/fl_fss/c/fss_basic_list.h +++ b/level_1/fl_fss/c/fss_basic_list.h @@ -41,7 +41,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -71,7 +71,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_basic_list_object_read_ - extern f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found); + extern f_return_status fl_fss_basic_list_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found); #endif // _di_fl_fss_basic_list_object_read_ /** @@ -83,7 +83,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -113,7 +113,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_basic_list_content_read_ - extern f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_content *found); + extern f_return_status fl_fss_basic_list_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found); #endif // _di_fl_fss_basic_list_content_read_ /** @@ -125,7 +125,7 @@ extern "C" { * * @param object * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the object string to write as an object. * @param buffer * The buffer where the object is written to. @@ -145,7 +145,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_basic_list_object_write_ - extern f_return_status fl_fss_basic_list_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_basic_list_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_basic_list_object_write_ /** @@ -156,7 +156,7 @@ extern "C" { * * @param content * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the content string to write as an content. * @param buffer * The buffer where the content is written to. @@ -176,7 +176,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_basic_list_content_write_ - extern f_return_status fl_fss_basic_list_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_basic_list_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_basic_list_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_extended.c b/level_1/fl_fss/c/fss_extended.c index a3d5621..f0d004c 100644 --- a/level_1/fl_fss/c/fss_extended.c +++ b/level_1/fl_fss/c/fss_extended.c @@ -1,382 +1,65 @@ #include +#include "private-fss.h" #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_extended_object_read_ - f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found) { + f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ - f_status status = F_none; - - // delimits must only be applied once a valid object is found - f_string_lengths delimits = f_string_lengths_initialize; - - f_fss_skip_past_space(*buffer, location); - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[location->start] == f_fss_extended_close) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - // when handling delimits, the only time they should be applied is when a valid object would exist - // however, the delimits will appear before a valid object, so remember their positions and only apply them after a would be valid object is confirmed - bool has_delimit = F_false; - - // begin the search - found->start = location->start; - - // ignore all comment lines - if (buffer->string[location->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, F_data_not_eos, F_data_not_stop) - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - // handle quote support - int8_t quoted = 0; - - // identify where the object begins - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length last_slash = location->start; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - continue; - } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - found->stop = location->start - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] != f_fss_delimit_slash) { - break; - } - - last_slash = location->start; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - - if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { - if (delimits.used >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - delimits.array[delimits.used] = last_slash; - delimits.used++; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } - } - else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[location->start]; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - found->start = location->start; - } - - // identify where the object ends - if (quoted == 0) { - status = F_none; - while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - } // while - - if (F_status_is_error(status)) return status; - - if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - found->stop = location->start - 1; - - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - if (buffer->string[location->start] == f_string_eol[0]) { - location->start++; - return FL_fss_found_object_content_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - } - else { - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; - f_string_length slash_count = 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - continue; - } - else if (buffer->string[location->start] != f_fss_delimit_slash) { - break; - } - - slash_count++; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) - - if (buffer->string[location->start] == quoted) { - f_string_length length = location->start; - - location->start = first_slash; - - if (delimits.used + (slash_count / 2) >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - if (slash_count % 2 == 0) { - while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; - delimits.used++; - } - - slash_count--; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - location->start = length + 1; - - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) - - if ((status = f_fss_is_graph(*buffer, *location)) == F_true) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] == f_string_eol[0]) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - found->stop = length - 1; - location->start++; - return FL_fss_found_object_content_not; - } - - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - found->stop = length - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else { - if (delimits.used + (slash_count / 2) >= delimits.size) { - f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - f_macro_string_lengths_delete_simple(delimits); - return status; - } - } - - while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; - delimits.used++; - } - - slash_count--; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - location->start = length; - } - } - } - else if (buffer->string[location->start] == quoted) { - found->stop = location->start - 1; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_string_eol[0]) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - location->start++; - return FL_fss_found_object_content_not; - } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object; - } - else if (F_status_is_error(status)) { - return status; - } - else if (buffer->string[location->start] != f_fss_delimit_placeholder) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - } - else if (buffer->string[location->start] == f_string_eol[0]) { - location->start++; - return FL_fss_found_object_not; - } - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) - } - - // seek to the end of the line when no valid object is found - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - } // while - - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - - return FL_fss_found_object_not; + return private_fl_fss_basic_object_read(F_false, buffer, range, found); } #endif // _di_fl_fss_extended_object_read_ #ifndef _di_fl_fss_extended_content_read_ - f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_content *found) { + f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; - // delimits must only be applied once a valid object is found + // delimits must only be applied once a valid object is found. f_string_lengths delimits = f_string_lengths_initialize; - f_fss_skip_past_space(*buffer, location); - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - - // return found nothing if this line only contains whitespace and delimit placeholders - if (buffer->string[location->start] == f_fss_extended_close) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_skip_past_space(*buffer, range); + if (F_status_is_error(status)) return status; + // return found nothing if this line only contains whitespace and delimit placeholders. + if (status == F_none_eol) { + range->start++; return FL_fss_found_content_not; } + else if (status == F_none_eos) { + return F_data_not_eos; + } + else if (status == F_none_stop) { + return F_data_not_stop; + } bool has_delimit = F_false; int8_t quoted = 0; bool continue_main_loop = F_false; - f_string_length length = 0; + f_string_length location = 0; f_array_length already_used = found->used; - while (location->start <= location->stop && location->start < buffer->used) { + while (range->start <= range->stop && range->start < buffer->used) { quoted = 0; if (found->used >= found->size) { @@ -388,35 +71,48 @@ extern "C" { } } - // begin the search - found->array[found->used].start = location->start; + // begin the search. + found->array[found->used].start = range->start; found->array[found->used].stop = 0; - // identify where the content begins - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length last_slash = location->start; - - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + // identify where the content begins. + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length last_slash = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + // @fixme: count each slash. + while (range->start <= range->stop && range->start < buffer->used) { + if (buffer->string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } continue; } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - found->array[found->used].stop = location->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_is_space(*buffer, *range); + + if (status == F_true) { + found->array[found->used].stop = range->start - 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } found->used++; - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_fss_extended_close) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + return FL_fss_found_content; } @@ -426,13 +122,13 @@ extern "C" { else if (F_status_is_error(status)) { return status; } - else if (buffer->string[location->start] != f_fss_delimit_slash) { + else if (buffer->string[range->start] != f_fss_delimit_slash) { break; } - last_slash = location->start; + last_slash = range->start; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while @@ -441,9 +137,10 @@ extern "C" { continue; } - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) - if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { + if (buffer->string[range->start] == f_fss_delimit_single_quote || buffer->string[range->start] == f_fss_delimit_double_quote) { + // @fixme: use slash count to determine if a slash needs to be delimited and if this quote is escaped or not. if (delimits.used >= delimits.size) { f_macro_string_lengths_resize(status, delimits, delimits.size + f_fss_default_allocation_step); @@ -456,82 +153,106 @@ extern "C" { delimits.array[delimits.used] = last_slash; delimits.used++; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } } - else if (buffer->string[location->start] == f_fss_delimit_single_quote || buffer->string[location->start] == f_fss_delimit_double_quote) { - quoted = buffer->string[location->start]; + else if (buffer->string[range->start] == f_fss_delimit_single_quote || buffer->string[range->start] == f_fss_delimit_double_quote) { + quoted = buffer->string[range->start]; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - found->array[found->used].start = location->start; + found->array[found->used].start = range->start; } - // identify where the content ends + // identify where the content ends. if (quoted == 0) { status = F_none; - while (buffer->string[location->start] == f_fss_delimit_placeholder || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) - } // while + for (;;) { + status = f_fss_is_space(*buffer, *range); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - if (F_status_is_error(status)) return status; + if (status == F_true) break; - if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - found->array[found->used].stop = location->start - 1; - found->used++; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - if (buffer->string[location->start] == f_string_eol[0]) { - fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) + } // for - location->start++; - return FL_fss_found_content; - } + found->array[found->used].stop = range->start - 1; + found->used++; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + if (buffer->string[range->start] == f_fss_extended_close) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - continue; + range->start++; + return FL_fss_found_content; } - else if (F_status_is_error(status)) { + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); return status; } + + continue; } else { - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; + while (range->start <= range->stop && range->start < buffer->used) { + + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; f_string_length slash_count = 1; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + while (range->start <= range->stop && range->start < buffer->used) { + if (buffer->string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } continue; } - else if (buffer->string[location->start] != f_fss_delimit_slash) { + else if (buffer->string[range->start] != f_fss_delimit_slash) { break; } slash_count++; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_unterminated_group_eos, F_unterminated_group_stop) - if (buffer->string[location->start] == quoted) { - length = location->start; - location->start = first_slash; + if (buffer->string[range->start] == quoted) { + location = range->start; + range->start = first_slash; if (slash_count % 2 == 0) { if (delimits.used + (slash_count / 2) >= delimits.size) { @@ -544,54 +265,69 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } slash_count--; } - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - location->start = length + 1; + range->start = location + 1; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) - if ((status = f_fss_is_graph(*buffer, *location)) == F_true) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_is_graph(*buffer, *range); + + if (status == F_true) { + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_unterminated_group_eos, F_unterminated_group_stop) - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - return F_status_is_warning(F_unterminated_group); + return F_unterminated_group; } else if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); return status; } - else if (buffer->string[location->start] == f_string_eol[0]) { + else if (buffer->string[range->start] == f_fss_extended_close) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = length - 1; + found->array[found->used].stop = location - 1; - location->start++; + range->start++; found->used++; return FL_fss_found_content; } - found->array[found->used].stop = length - 1; + found->array[found->used].stop = location - 1; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } found->used++; continue; @@ -607,82 +343,114 @@ extern "C" { } while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } slash_count--; } - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - location->start = length; + range->start = location; } } } - else if (buffer->string[location->start] == quoted) { - found->array[found->used].stop = location->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + else if (buffer->string[range->start] == quoted) { + found->array[found->used].stop = range->start - 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + while (range->start <= range->stop && range->start < buffer->used) { - while (location->start <= location->stop && location->start < buffer->used) { - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_fss_extended_close) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - location->start++; + range->start++; found->used++; return FL_fss_found_content; } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + + status = f_fss_is_space(*buffer, *range); + + if (status == F_true) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } found->used++; continue_main_loop = F_true; break; } else if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); return status; } - else if (buffer->string[location->start] != f_fss_delimit_placeholder) { - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + else if (buffer->string[range->start] != f_fss_delimit_placeholder) { + + while (range->start < buffer->used && range->start <= range->stop) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_unterminated_group_eos, F_unterminated_group_stop) + + if (buffer->string[range->start] == f_string_eol[0]) break; } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + return F_unterminated_group; + } - return F_status_is_warning(F_unterminated_group); + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; } - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) } // while if (continue_main_loop) break; - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) } - else if (buffer->string[location->start] == f_string_eol[0]) { + else if (buffer->string[range->start] == f_fss_extended_close) { if (found->used == already_used) { - location->start++; + range->start++; return FL_fss_found_content_not; } else { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - found->array[found->used].stop = location->start - 1; + found->array[found->used].stop = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } found->used++; @@ -690,11 +458,14 @@ extern "C" { } } - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - fl_macro_fss_content_return_on_overflow((*buffer), (*location), (*found), delimits, F_status_is_warning(F_unterminated_group_eos), F_status_is_warning(F_unterminated_group_stop)) + fl_macro_fss_content_return_on_overflow((*buffer), (*range), (*found), delimits, F_unterminated_group_eos, F_unterminated_group_stop) } if (continue_main_loop) { @@ -705,34 +476,43 @@ extern "C" { break; } // while - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) // seek to the end of the line when no valid content is found - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } } // while - fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_content_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop) if (found->used == already_used) { - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } return FL_fss_found_content_not; } fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - status = f_fss_increment_buffer(*buffer, location, 1); - if (F_status_is_error(status)) return status; + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } return FL_fss_found_content; } #endif // _di_fl_fss_extended_content_read_ #ifndef _di_fl_fss_extended_object_write_ - f_return_status fl_fss_extended_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -744,15 +524,15 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= object.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= object.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 3 to ensure that there is room for the start and stop quotes or a slash delimit and the object open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 3 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 3 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -762,25 +542,25 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - if (object.string[location->start] == f_fss_delimit_slash) { - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + if (object.string[range->start] == f_fss_delimit_slash) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; - } else if (object.string[location->start] != f_fss_delimit_slash) { + } else if (object.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { + if (object.string[range->start] == f_fss_delimit_single_quote || object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -790,14 +570,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[location->start]; + buffer->string[buffer_position.stop + 1] = object.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } } - else if (object.string[location->start] == f_fss_delimit_single_quote || object.string[location->start] == f_fss_delimit_double_quote) { + else if (object.string[range->start] == f_fss_delimit_single_quote || object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -806,24 +586,24 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = object.string[location->start]; + buffer->string[buffer_position.stop + 1] = object.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } - else if (object.string[location->start] == f_fss_comment) { + else if (object.string[range->start] == f_fss_comment) { quoted = F_true; } - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { if (quoted) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -834,19 +614,19 @@ extern "C" { return F_none_eol; } - else if ((status = f_fss_is_space(*buffer, *location)) == F_true || quoted) { - f_string_length first_space = location->start; + else if ((status = f_fss_is_space(*buffer, *range)) == F_true || quoted) { + f_string_length first_space = range->start; if (!quoted) { - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < object.used && isspace(object.string[location->start])) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < object.used && isspace(object.string[range->start])) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - if (location->start > location->stop || location->start >= object.used) { + if (range->start > range->stop || range->start >= object.used) { buffer->string[first_space] = f_fss_extended_open; buffer->used = buffer_position.stop + 1; break; @@ -862,20 +642,20 @@ extern "C" { } // restart the loop searching for f_fss_delimit_double_quote. - location->start = start_position; + range->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (object.string[location->start] == f_fss_delimit_double_quote) { + else if (object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -887,24 +667,24 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; } - else if (object.string[location->start] == f_fss_delimit_slash) { + else if (object.string[range->start] == f_fss_delimit_slash) { f_string_length slash_count = 0; for (;;) { - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; slash_count++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)); + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)); - if (location->start > location->stop || location->start >= object.used) { + if (range->start > range->stop || range->start >= object.used) { break; } - if (object.string[location->start] == f_fss_delimit_double_quote) { + if (object.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -914,7 +694,7 @@ extern "C" { break; } - else if (object.string[location->start] != f_fss_delimit_slash) { + else if (object.string[range->start] != f_fss_delimit_slash) { slash_count = 0; break; } @@ -928,7 +708,7 @@ extern "C" { continue; } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -938,9 +718,9 @@ extern "C" { return F_none_eol; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; buffer_position.stop++; @@ -955,9 +735,9 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; buffer_position.stop++; @@ -968,15 +748,15 @@ extern "C" { buffer->used = buffer_position.stop + 1; } - if (location->start > location->stop) return F_none_stop; - else if (location->start >= object.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= object.used) return F_none_eos; return F_none; } #endif // _di_fl_fss_extended_object_write_ #ifndef _di_fl_fss_extended_content_write_ - f_return_status fl_fss_extended_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -988,10 +768,10 @@ extern "C" { f_string_length start_position = 0; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= content.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= content.used) return F_data_not_eos; // add an additional 1 to ensure that there is room for the terminating newline. pre_allocate_size = buffer->used + (content.used) + 1 + f_fss_default_allocation_step_string; @@ -1004,47 +784,47 @@ extern "C" { if (F_status_is_error(status)) return status; } - start_position = location->start; + start_position = range->start; // if this first slash is followed by a quote, then that quote must be delimited. - if (content.string[location->start] == f_fss_delimit_slash) { + if (content.string[range->start] == f_fss_delimit_slash) { buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - if (content.string[location->start] != f_fss_delimit_slash) { + if (content.string[range->start] != f_fss_delimit_slash) { break; } buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - if (location->start > location->stop) { + if (range->start > range->stop) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return F_none_stop; } - else if (location->start >= content.used) { + else if (range->start >= content.used) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return F_none_eos; } - if (content.string[location->start] == f_fss_delimit_single_quote || content.string[location->start] == f_fss_delimit_double_quote) { + if (content.string[range->start] == f_fss_delimit_single_quote || content.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1053,14 +833,14 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = content.string[location->start]; + buffer->string[buffer_position.stop + 1] = content.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } } - else if (content.string[location->start] == f_fss_delimit_single_quote || content.string[location->start] == f_fss_delimit_double_quote) { + else if (content.string[range->start] == f_fss_delimit_single_quote || content.string[range->start] == f_fss_delimit_double_quote) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1069,21 +849,21 @@ extern "C" { } buffer->string[buffer_position.stop] = f_fss_delimit_slash; - buffer->string[buffer_position.stop + 1] = content.string[location->start]; + buffer->string[buffer_position.stop + 1] = content.string[range->start]; buffer_position.stop += 2; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_string_eol[0]) { + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_string_eol[0]) { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; return F_none_eol; } - if (content.string[location->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *location)) == F_true) { + if (content.string[range->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *range)) == F_true) { quoted = f_fss_delimit_double_quote; pre_allocate_size += 2; @@ -1093,7 +873,7 @@ extern "C" { if (F_status_is_error(status)) return status; } - location->start = start_position; + range->start = start_position; buffer_position.stop = buffer_position.start; buffer->string[buffer_position.stop] = f_fss_delimit_double_quote; buffer_position.stop++; @@ -1103,33 +883,33 @@ extern "C" { return status; } - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while if (quoted != 0) { - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_slash) { + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_slash) { f_string_length slash_count = 1; buffer->string[buffer_position.stop] = f_fss_delimit_slash; buffer_position.stop++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; continue; } - if (content.string[location->start] != f_fss_delimit_slash) { + if (content.string[range->start] != f_fss_delimit_slash) { break; } @@ -1137,11 +917,11 @@ extern "C" { buffer_position.stop++; slash_count++; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - if (content.string[location->start] == quoted || location->start > location->stop || location->start >= content.used) { + if (content.string[range->start] == quoted || range->start > range->stop || range->start >= content.used) { pre_allocate_size += slash_count + 1; if (pre_allocate_size > buffer->size) { @@ -1155,7 +935,7 @@ extern "C" { slash_count--; } // while - if (location->start > location->stop || location->start >= content.used) { + if (range->start > range->stop || range->start >= content.used) { break; } @@ -1164,11 +944,11 @@ extern "C" { buffer_position.stop += 2; } else { - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; } } - else if (content.string[location->start] == quoted) { + else if (content.string[range->start] == quoted) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1180,18 +960,18 @@ extern "C" { buffer->string[buffer_position.stop + 1] = quoted; buffer_position.stop += 2; } - else if (content.string[location->start] == f_string_eol[0]) { + else if (content.string[range->start] == f_string_eol[0]) { buffer->string[buffer_position.stop] = quoted; buffer->string[buffer_position.stop + 1] = ' '; buffer->used = buffer_position.stop + 2; return F_none_eol; } - else if (content.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[location->start]; + else if (content.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while @@ -1202,8 +982,8 @@ extern "C" { buffer->string[buffer_position.stop] = ' '; buffer->used = buffer_position.stop + 1; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= content.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= content.used) return F_none_eos; return F_none; } diff --git a/level_1/fl_fss/c/fss_extended.h b/level_1/fl_fss/c/fss_extended.h index 6b548ab..4adbd8f 100644 --- a/level_1/fl_fss/c/fss_extended.h +++ b/level_1/fl_fss/c/fss_extended.h @@ -40,7 +40,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -70,7 +70,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_extended_object_read_ - extern f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found); + extern f_return_status fl_fss_extended_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found); #endif // _di_fl_fss_extended_object_read_ /** @@ -82,7 +82,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -112,7 +112,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_extended_content_read_ - extern f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_content *found); + extern f_return_status fl_fss_extended_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_content *found); #endif // _di_fl_fss_extended_content_read_ /** @@ -124,7 +124,7 @@ extern "C" { * * @param object * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the object string to write as an object. * @param buffer * The buffer where the object is written to. @@ -144,7 +144,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_extended_object_write_ - extern f_return_status fl_fss_extended_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_object_write_ /** @@ -155,7 +155,7 @@ extern "C" { * * @param content * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the content string to write as an content. * @param buffer * The buffer where the content is written to. @@ -175,7 +175,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_extended_content_write_ - extern f_return_status fl_fss_extended_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_extended_list.c b/level_1/fl_fss/c/fss_extended_list.c index daf5e21..4cc6bd3 100644 --- a/level_1/fl_fss/c/fss_extended_list.c +++ b/level_1/fl_fss/c/fss_extended_list.c @@ -1,19 +1,19 @@ -#include -#include +#include +#include "private-fss.h" + #ifdef __cplusplus extern "C" { #endif #ifndef _di_fl_fss_extended_list_object_read_ - f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found) { + f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; @@ -21,73 +21,85 @@ extern "C" { // delimits must only be applied once a valid object is found. f_string_lengths delimits = f_string_lengths_initialize; - f_fss_skip_past_space(*buffer, location); - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + status = f_fss_skip_past_space(*buffer, range); + if (F_status_is_error(status)) return status; // return found nothing if this line only contains whitespace and delimit placeholders. - if (buffer->string[location->start] == f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); + if (status == F_none_eol) { + range->start++; + return FL_fss_found_object_not; + } + else if (status == F_none_eos) { + return F_data_not_eos; + } + else if (status == F_none_stop) { + return F_data_not_stop; + } + + // return found nothing if this line only contains whitespace and delimit placeholders. + if (buffer->string[range->start] == f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object_not; } // begin the search. - found->start = location->start; + found->start = range->start; // ignore all comment lines. - if (buffer->string[location->start] == f_fss_comment) { - fl_macro_fss_object_seek_till_newline((*buffer), (*location), delimits, F_data_not_eos, F_data_not_stop) + if (buffer->string[range->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*range), delimits, F_data_not_eos, F_data_not_stop) - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object_not; } // identify where the object ends. - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length first_slash = location->start; + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; f_string_length slash_count = 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + if (buffer->string[range->start] == f_fss_delimit_slash) { slash_count++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - if (buffer->string[location->start] == f_fss_extended_list_open) { - f_string_length stop_point = location->start - 1; + if (buffer->string[range->start] == f_fss_extended_list_open) { + f_string_length stop_point = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *range)) == F_true) { break; } if (F_status_is_error(status)) return status; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - if (buffer->string[location->start] == f_string_eol[0]) { - f_string_length start = location->start; + if (buffer->string[range->start] == f_string_eol[0]) { + f_string_length start = range->start; - location->start = first_slash; + range->start = first_slash; if (delimits.used + (slash_count / 2) >= delimits.size) { f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); @@ -100,59 +112,60 @@ extern "C" { if (slash_count % 2 == 0) { while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } slash_count--; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - location->start = start + 1; + range->start = start + 1; return FL_fss_found_object; } - location->start = start + 1; + range->start = start + 1; return FL_fss_found_object_not; } } continue; } - else if (buffer->string[location->start] == f_fss_extended_list_open) { - f_string_length stop_point = location->start - 1; + else if (buffer->string[range->start] == f_fss_extended_list_open) { + f_string_length stop_point = range->start - 1; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(*buffer, *location)) == F_true) { - break; - } + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) break; + + status = f_fss_is_space(*buffer, *range); if (F_status_is_error(status)) return status; + if (status == F_false) break; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, F_none_eos, F_none_stop) + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); found->stop = stop_point; - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object; @@ -161,19 +174,19 @@ extern "C" { continue; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while // seek to the end of the line when no valid object is found. - while (location->start < buffer->used && location->start <= location->stop && buffer->string[location->start] != f_string_eol[0]) { - status = f_fss_increment_buffer(*buffer, location, 1); + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; } // while - fl_macro_fss_object_return_on_overflow((*buffer), (*location), (*found), delimits, F_data_not_eos, F_data_not_stop) + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) return status; return FL_fss_found_object_not; @@ -181,15 +194,14 @@ extern "C" { #endif // _di_fl_fss_extended_list_object_read_ #ifndef _di_fl_fss_extended_list_content_read_ - f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_nest *found) { + f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_nest *found) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (found == 0) return F_status_set_error(F_parameter); - if (location->start < 0) return F_status_set_error(F_parameter); - if (location->stop < location->start) return F_status_set_error(F_parameter); - if (buffer->used <= 0) return F_status_set_error(F_parameter); - if (location->start >= buffer->used) return F_status_set_error(F_parameter); + if (range->stop < range->start) return F_status_set_error(F_parameter); + if (buffer->used == 0) return F_status_set_error(F_parameter); + if (range->start >= buffer->used) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ f_status status = F_none; @@ -199,8 +211,8 @@ extern "C" { f_string_lengths positions_start = f_string_lengths_initialize; f_fss_objects objects = f_fss_objects_initialize; - fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*location)) - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), positions_start, delimits, objects, F_none_eos, F_none_stop) + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), positions_start, delimits, objects, F_none_eos, F_none_stop) if (found->used + 1 >= found->size) { f_macro_fss_nest_resize(status, (*found), found->size + f_fss_default_allocation_step + 1); @@ -212,9 +224,9 @@ extern "C" { } f_array_length depth = 0; - f_string_length position_previous = location->start; - f_string_length line_start = location->start; - f_string_length last_newline = location->start; + f_string_length position_previous = range->start; + f_string_length line_start = range->start; + f_string_length last_newline = range->start; f_macro_string_lengths_new(status, positions_start, f_fss_default_allocation_step); if (F_status_is_error(status)) { @@ -233,33 +245,33 @@ extern "C" { // initialize depth 1 start position. // positions_start.used is used as a max depth (such that positions_start.used == max depth + 1). - positions_start.array[0] = location->start; + positions_start.array[0] = range->start; positions_start.used = 1; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - position_previous = location->start; - location->start++; + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + position_previous = range->start; + range->start++; if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_none_eos, F_none_stop) + fl_macro_fss_nest_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_none_eos, F_none_stop) } - line_start = location->start; + line_start = range->start; continue; } - if (buffer->string[location->start] == f_fss_delimit_slash) { - f_string_length slash_first = location->start; - f_string_length slash_last = location->start; + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length slash_first = range->start; + f_string_length slash_last = range->start; f_string_length slash_count = 1; - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -268,15 +280,15 @@ extern "C" { return status; } - while (location->start < buffer->used && location->start <= location->stop && (buffer->string[location->start] == f_fss_delimit_placeholder || buffer->string[location->start] == f_fss_delimit_slash)) { - position_previous = location->start; + while (range->start < buffer->used && range->start <= range->stop && (buffer->string[range->start] == f_fss_delimit_placeholder || buffer->string[range->start] == f_fss_delimit_slash)) { + position_previous = range->start; - if (buffer->string[location->start] == f_fss_delimit_slash) { - slash_last = location->start; + if (buffer->string[range->start] == f_fss_delimit_slash) { + slash_last = range->start; slash_count++; } - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -287,10 +299,10 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } // All slashes for an open are delimited (because it could represent a slash in the object name). @@ -298,31 +310,31 @@ extern "C" { // Only the first slash before a close is delimited, all others are maintained. // for example '}' = valid close, '\}' represents '}', '\\}' represents '\}', '\\\}' represents '\\}', '\\\\}' represents '\\\}', and so on.. // When slash is odd and a (delimited) valid open/close is found, then save delimited positions and continue. - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - position_previous = location->start; - location->start++; - line_start = location->start; + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + position_previous = range->start; + range->start++; + line_start = range->start; } - else if (buffer->string[location->start] == f_fss_extended_list_open || buffer->string[location->start] == f_fss_extended_list_close) { + else if (buffer->string[range->start] == f_fss_extended_list_open || buffer->string[range->start] == f_fss_extended_list_close) { f_string_length before_list_open = position_previous; bool is_open = F_false; - if (buffer->string[location->start] == f_fss_extended_list_open) { + if (buffer->string[range->start] == f_fss_extended_list_open) { is_open = F_true; } - position_previous = location->start; - location->start++; + position_previous = range->start; + range->start++; - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - line_start = location->start + 1; + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + line_start = range->start + 1; break; } - if (buffer->string[location->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *location)) == F_false) { + if (buffer->string[range->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *range)) == F_false) { break; } @@ -334,8 +346,8 @@ extern "C" { return status; } - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -346,16 +358,16 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } // this is a valid object open/close that has been delimited, save the slash delimit positions. - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - line_start = location->start + 1; + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + line_start = range->start + 1; if (is_open) { bool is_object = F_false; @@ -364,13 +376,13 @@ extern "C" { is_object = F_true; } - location->start = slash_first; + range->start = slash_first; if (delimits.used + (slash_count / 2) >= delimits.size) { f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); if (F_status_is_error(status)) { - location->start = last_newline; + range->start = last_newline; f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -382,9 +394,9 @@ extern "C" { // apply slash delimits, only slashes and placeholders should be present. while (slash_count > 0) { - if (buffer->string[location->start] == f_fss_delimit_slash) { + if (buffer->string[range->start] == f_fss_delimit_slash) { if (slash_count % 2 == 1) { - delimits.array[delimits.used] = location->start; + delimits.array[delimits.used] = range->start; delimits.used++; } @@ -392,8 +404,8 @@ extern "C" { } // Delimit slashes and placeholders are required to be in the ASCII range. - position_previous = location->start; - location->start++; + position_previous = range->start; + range->start++; } // while // when slashes are even, the object is valid and needs to be processed. @@ -404,7 +416,7 @@ extern "C" { f_macro_string_lengths_resize(status, positions_start, positions_start.size + f_fss_default_allocation_step); if (F_status_is_error(status)) { - location->start = last_newline; + range->start = last_newline; f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -429,7 +441,7 @@ extern "C" { f_macro_string_lengths_resize(status, delimits, delimits.size + f_fss_default_allocation_step); if (F_status_is_error(status)) { - location->start = last_newline; + range->start = last_newline; f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -443,15 +455,15 @@ extern "C" { delimits.used++; } - location->start = last_newline; + range->start = last_newline; } } } - else if (buffer->string[location->start] == f_fss_extended_list_open) { + else if (buffer->string[range->start] == f_fss_extended_list_open) { f_string_length before_list_open = position_previous; - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -460,13 +472,13 @@ extern "C" { return status; } - while (location->start < buffer->used && location->start <= location->stop) { + while (range->start < buffer->used && range->start <= range->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { break; } - if (buffer->string[location->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *location)) == F_false) { + if (buffer->string[range->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *range)) == F_false) { break; } @@ -478,8 +490,8 @@ extern "C" { return status; } - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -490,13 +502,13 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { depth++; if (depth >= positions_start.size) { @@ -525,25 +537,25 @@ extern "C" { positions_start.used = depth + 1; } - positions_start.array[depth] = location->start + 1; + positions_start.array[depth] = range->start + 1; objects.array[depth].start = line_start; objects.array[depth].stop = before_list_open; - last_newline = location->start; - line_start = location->start + 1; + last_newline = range->start; + line_start = range->start + 1; } // No valid object open found, seek until EOL. else { - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - line_start = location->start + 1; + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + line_start = range->start + 1; break; } - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -554,17 +566,17 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } } } - else if (buffer->string[location->start] == f_fss_extended_list_close) { - while (location->start < buffer->used && location->start <= location->stop) { - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + else if (buffer->string[range->start] == f_fss_extended_list_close) { + while (range->start < buffer->used && range->start <= range->stop) { + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -573,11 +585,11 @@ extern "C" { return status; } - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { break; } - if (buffer->string[location->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *location)) == F_false) { + if (buffer->string[range->start] != f_fss_delimit_placeholder && (status = f_fss_is_space(*buffer, *range)) == F_false) { break; } @@ -591,13 +603,13 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } - if (buffer->string[location->start] == f_string_eol[0]) { + if (buffer->string[range->start] == f_string_eol[0]) { if (depth + 1 >= found->size) { f_macro_fss_nest_resize(status, (*found), found->size + f_fss_default_allocation_step); @@ -654,11 +666,11 @@ extern "C" { found->used = depth + 1; } - last_newline = location->start; - line_start = location->start + 1; + last_newline = range->start; + line_start = range->start + 1; if (depth == 0) { - status = f_fss_increment_buffer(*buffer, location, 1); + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -668,7 +680,7 @@ extern "C" { } fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); - fl_macro_fss_nest_delimited_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_none_eos, F_none_stop) + fl_macro_fss_nest_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_none_eos, F_none_stop) f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -681,15 +693,15 @@ extern "C" { } // No valid object close found, seek until EOL. else { - while (location->start < buffer->used && location->start <= location->stop) { - if (buffer->string[location->start] == f_string_eol[0]) { - last_newline = location->start; - line_start = location->start + 1; + while (range->start < buffer->used && range->start <= range->stop) { + if (buffer->string[range->start] == f_string_eol[0]) { + last_newline = range->start; + line_start = range->start + 1; break; } - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -700,16 +712,16 @@ extern "C" { } // while if (depth > 0) { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_unterminated_nest_eos, F_unterminated_nest_stop) } else { - fl_macro_fss_nest_return_on_overflow((*buffer), (*location), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) + fl_macro_fss_nest_return_on_overflow((*buffer), (*range), (*found), delimits, positions_start, objects, F_data_not_eos, F_data_not_stop) } } } - else if (buffer->string[location->start] != f_string_eol[0]) { - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + else if (buffer->string[range->start] != f_string_eol[0]) { + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -718,15 +730,15 @@ extern "C" { return status; } - if (location->start >= buffer->used || location->start > location->stop) { + if (range->start >= buffer->used || range->start > range->stop) { break; } continue; } - position_previous = location->start; - status = f_fss_increment_buffer(*buffer, location, 1); + position_previous = range->start; + status = f_fss_increment_buffer(*buffer, range, 1); if (F_status_is_error(status)) { f_macro_string_lengths_delete_simple(delimits); f_macro_string_lengths_delete_simple(positions_start); @@ -740,7 +752,7 @@ extern "C" { f_macro_string_lengths_delete_simple(positions_start); f_macro_fss_objects_delete_simple(objects); - if (location->start > location->stop) { + if (range->start > range->stop) { if (depth == 0) return F_status_set_error(F_unterminated_stop); return F_status_set_error(F_unterminated_nest_stop); @@ -753,7 +765,7 @@ extern "C" { #endif // _di_fl_fss_extended_list_content_read_ #ifndef _di_fl_fss_extended_list_object_write_ - f_return_status fl_fss_extended_list_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_list_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -765,15 +777,15 @@ extern "C" { f_string_length pre_allocate_size = 0; f_string_length start_buffer = 0; - fl_macro_fss_skip_past_delimit_placeholders(object, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(object, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= object.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= object.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 2 to ensure that there is room for the slash delimit and the object open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -784,57 +796,57 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_comment) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_comment) { // comments are not allowed and this format has no way of "wrapping" a comment. return F_status_set_error(FL_fss_found_comment); } - else if ((status = f_fss_is_graph(object, *location)) == F_true) { + else if ((status = f_fss_is_graph(object, *range)) == F_true) { break; } else if (F_status_is_error(status)) { return status; } - if (object.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[location->start]; + if (object.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; } // while - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_slash) { + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_slash) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < object.used) { - if (object.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(object, location, 1); + while (range->start <= range->stop && range->start < object.used) { + if (object.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; continue; - } else if (object.string[location->start] != f_fss_delimit_slash) { + } else if (object.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = object.string[location->start]; + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; slash_count++; } // while - if (location->start > location->stop || location->start >= object.used) { + if (range->start > range->stop || range->start >= object.used) { pre_allocate_size += slash_count; if (pre_allocate_size > buffer->size) { @@ -851,18 +863,18 @@ extern "C" { break; } } - else if (object.string[location->start] == f_string_eol[0]) { + else if (object.string[range->start] == f_string_eol[0]) { if (buffer_position.stop == buffer_position.start) return F_data_not_eol; break; } - if (object.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = object.string[location->start]; + if (object.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = object.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(object, location, 1); + status = f_fss_increment_buffer(object, range, 1); if (F_status_is_error(status)) return status; } // while @@ -870,15 +882,15 @@ extern "C" { buffer->string[buffer_position.stop + 1] = f_string_eol[0]; buffer->used = buffer_position.stop + 2; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= object.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= object.used) return F_none_eos; return F_none; } #endif // _di_fl_fss_extended_list_object_write_ #ifndef _di_fl_fss_extended_list_content_write_ - f_return_status fl_fss_extended_list_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer) { + f_return_status fl_fss_extended_list_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer) { #ifndef _di_level_1_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ @@ -893,15 +905,15 @@ extern "C" { f_string_length start_position = f_string_initialize; f_string_length pre_allocate_size = 0; - fl_macro_fss_skip_past_delimit_placeholders(content, (*location)) + fl_macro_fss_skip_past_delimit_placeholders(content, (*range)) - if (location->start > location->stop) return F_data_not_stop; - else if (location->start >= content.used) return F_data_not_eos; + if (range->start > range->stop) return F_data_not_stop; + else if (range->start >= content.used) return F_data_not_eos; - start_position = location->start; + start_position = range->start; // add an additional 2 to ensure that there is room for the slash delimit and the content open character. - pre_allocate_size = buffer->used + (location->stop - location->start) + 2 + f_fss_default_allocation_step_string; + pre_allocate_size = buffer->used + (range->stop - range->start) + 2 + f_fss_default_allocation_step_string; if (pre_allocate_size > buffer->size) { f_macro_string_dynamic_resize(status, (*buffer), pre_allocate_size); @@ -911,55 +923,55 @@ extern "C" { buffer_position.start = buffer->used; buffer_position.stop = buffer->used; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_slash && !is_comment) { + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_slash && !is_comment) { f_string_length slash_count = 1; - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; has_graph = F_true; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start <= location->stop && location->start < content.used) { - if (content.string[location->start] == f_fss_delimit_placeholder) { - status = f_fss_increment_buffer(content, location, 1); + while (range->start <= range->stop && range->start < content.used) { + if (content.string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; continue; } - else if (content.string[location->start] != f_fss_delimit_slash) { + else if (content.string[range->start] != f_fss_delimit_slash) { break; } - buffer->string[buffer_position.stop] = content.string[location->start]; + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; slash_count++; } // while - if (content.string[location->start] == f_fss_extended_list_open) { - f_string_length start = location->start; + if (content.string[range->start] == f_fss_extended_list_open) { + f_string_length start = range->start; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start < content.used && location->start <= location->stop) { - if (content.string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *location)) == F_true) { + while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *range)) == F_true) { break; } if (F_status_is_error(status)) return status; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while - if (content.string[location->start] == f_string_eol[0] || location->start >= content.used || location->start > location->stop) { + if (content.string[range->start] == f_string_eol[0] || range->start >= content.used || range->start > range->stop) { pre_allocate_size += slash_count + 1; if (pre_allocate_size > buffer->size) { @@ -981,30 +993,30 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_extended_list_open; buffer_position.stop++; - location->start = start + 1; + range->start = start + 1; continue; } } - else if (content.string[location->start] == f_fss_extended_list_open && !is_comment) { - f_string_length start = location->start; + else if (content.string[range->start] == f_fss_extended_list_open && !is_comment) { + f_string_length start = range->start; has_graph = F_true; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; - while (location->start < content.used && location->start <= location->stop) { - if (content.string[location->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *location)) == F_true) { + while (range->start < content.used && range->start <= range->stop) { + if (content.string[range->start] == f_string_eol[0] || (status = f_fss_is_graph(content, *range)) == F_true) { break; } if (F_status_is_error(status)) return status; - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while - if (content.string[location->start] == f_string_eol[0] || location->start >= content.used || location->start > location->stop) { + if (content.string[range->start] == f_string_eol[0] || range->start >= content.used || range->start > range->stop) { pre_allocate_size++; if (pre_allocate_size > buffer->size) { @@ -1021,37 +1033,37 @@ extern "C" { buffer->string[buffer_position.stop] = f_fss_extended_list_open; buffer_position.stop++; - location->start = start + 1; + range->start = start + 1; continue; } - else if (content.string[location->start] == f_fss_comment && !has_graph) { + else if (content.string[range->start] == f_fss_comment && !has_graph) { is_comment = F_true; } - else if (content.string[location->start] == f_string_eol[0]) { + else if (content.string[range->start] == f_string_eol[0]) { has_graph = F_false; is_comment = F_false; } - else if ((status = f_fss_is_graph(content, *location)) == F_true) { + else if ((status = f_fss_is_graph(content, *range)) == F_true) { has_graph = F_true; } else if (F_status_is_error(status)) { return status; } - if (content.string[location->start] != f_fss_delimit_placeholder) { - buffer->string[buffer_position.stop] = content.string[location->start]; + if (content.string[range->start] != f_fss_delimit_placeholder) { + buffer->string[buffer_position.stop] = content.string[range->start]; buffer_position.stop++; } - status = f_fss_increment_buffer(content, location, 1); + status = f_fss_increment_buffer(content, range, 1); if (F_status_is_error(status)) return status; } // while buffer->string[buffer_position.stop] = f_string_eol[0]; buffer->used = buffer_position.stop + 1; - if (location->start > location->stop) return F_none_stop; - else if (location->start >= content.used) return F_none_eos; + if (range->start > range->stop) return F_none_stop; + else if (range->start >= content.used) return F_none_eos; */ return F_none; diff --git a/level_1/fl_fss/c/fss_extended_list.h b/level_1/fl_fss/c/fss_extended_list.h index d0e58f1..cd16321 100644 --- a/level_1/fl_fss/c/fss_extended_list.h +++ b/level_1/fl_fss/c/fss_extended_list.h @@ -41,7 +41,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -71,7 +71,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_extended_list_object_read_ - extern f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_range *location, f_fss_object *found); + extern f_return_status fl_fss_extended_list_object_read(f_string_dynamic *buffer, f_string_range *range, f_fss_object *found); #endif // _di_fl_fss_extended_list_object_read_ /** @@ -87,7 +87,7 @@ extern "C" { * @param buffer * The buffer to read from. * This will be updated with delimit placeholders as it is being processed. - * @param location + * @param range * The start/stop location within the buffer to be processed. * The start location will be updated as the buffer is being processed. * The start location will represent where the read stopped on return. @@ -117,7 +117,7 @@ extern "C" { * Errors from (with error bit): f_fss_skip_past_space(). */ #ifndef _di_fl_fss_extended_list_content_read_ - extern f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_range *location, f_fss_nest *found); + extern f_return_status fl_fss_extended_list_content_read(f_string_dynamic *buffer, f_string_range *range, f_fss_nest *found); #endif // _di_fl_fss_extended_list_content_read_ /** @@ -129,7 +129,7 @@ extern "C" { * * @param object * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the object string to write as an object. * @param buffer * The buffer where the object is written to. @@ -149,7 +149,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_extended_list_object_write_ - extern f_return_status fl_fss_extended_list_object_write(const f_string_static object, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_list_object_write(const f_string_static object, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_list_object_write_ /** @@ -160,7 +160,7 @@ extern "C" { * * @param content * The string to write as (does not stop at NULLS, they are ignored and not written). - * @param location + * @param range * The start/stop location within the content string to write as an content. * @param buffer * The buffer where the content is written to. @@ -180,7 +180,7 @@ extern "C" { * Errors from (with error bit): f_fss_increment_buffer(). */ #ifndef _di_fl_fss_extended_list_content_write_ - extern f_return_status fl_fss_extended_list_content_write(const f_string_static content, f_string_range *location, f_string_dynamic *buffer); + extern f_return_status fl_fss_extended_list_content_write(const f_string_static content, f_string_range *range, f_string_dynamic *buffer); #endif // _di_fl_fss_extended_list_content_write_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index 51f1863..ad3ec4a 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -66,7 +66,7 @@ extern "C" { // if "# fss-0000" is there, regardless of whats next, we can guess this to be of fss-0000, even if its fss-00001 (this is a guess afterall). header->length = i + 1; - return F_status_is_warning(FL_fss_accepted_invalid); + return F_status_set_warning(FL_fss_accepted_invalid); } } } @@ -113,7 +113,7 @@ extern "C" { header->length = i + 1; - return F_status_is_warning(FL_fss_accepted_invalid); + return F_status_set_warning(FL_fss_accepted_invalid); } } } @@ -131,6 +131,432 @@ extern "C" { } #endif // !defined(_di_fl_fss_identify_) || !defined(_di_fl_fss_identify_file_) +#if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) + f_return_status private_fl_fss_basic_object_read(const bool is_basic, f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) { + f_status status = F_none; + + // delimits must only be applied once a valid object is found. + f_string_lengths delimits = f_string_lengths_initialize; + + status = f_fss_skip_past_space(*buffer, range); + if (F_status_is_error(status)) return status; + + // return found nothing if this line only contains whitespace and delimit placeholders. + if (status == F_none_eol) { + range->start++; + return FL_fss_found_object_not; + } + else if (status == F_none_eos) { + return F_data_not_eos; + } + else if (status == F_none_stop) { + return F_data_not_stop; + } + + // when handling delimits, the only time they should be applied is when a valid object would exist. + // however, the delimits will appear before a valid object, so remember their positions and only apply them after a would be valid object is confirmed. + bool has_delimit = F_false; + + // begin the search. + found->start = range->start; + + // ignore all comment lines. + if (buffer->string[range->start] == f_fss_comment) { + fl_macro_fss_object_seek_till_newline((*buffer), (*range), delimits, F_data_not_eos, F_data_not_stop); + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object_not; + } + + // handle quote support. + int8_t quoted = 0; + + // identify where the object begins. + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; + f_string_length slash_count = 1; + + found->start = range->start; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + while (range->start <= range->stop && range->start < buffer->used) { + status = f_fss_is_zero_width(*buffer, *range); + if (F_status_is_error(status)) return status; + + if (status == F_true) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + continue; + } + + if (buffer->string[range->start] != f_fss_delimit_slash) { + status = f_fss_is_space(*buffer, *range); + + // found the end of the object while processing the slash for potential delimits. + if (status == F_true) { + found->stop = range->start - 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + if (buffer->string[range->start] == f_string_eol[0]) { + return FL_fss_found_object_content_not; + } + + return FL_fss_found_object; + } + else if (F_status_is_error(status)) { + return status; + } + + break; + } + + slash_count++; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + return status; + } + } // while + + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); + + if (buffer->string[range->start] == f_fss_delimit_single_quote || buffer->string[range->start] == f_fss_delimit_double_quote) { + f_string_length location_last = range->start; + + quoted = buffer->string[range->start]; + + range->start = first_slash; + + // when slash count is odd, then the quote is escaped. + if (slash_count % 2 != 0) { + quoted = 0; + } + + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + if (F_status_is_error(status)) return status; + } + + while (slash_count > 0) { + if (buffer->string[range->start] == f_fss_delimit_slash) { + if (slash_count % 2 == 1) { + delimits.array[delimits.used] = range->start; + delimits.used++; + } + + slash_count--; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + range->start = location_last; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } + } + else if (buffer->string[range->start] == f_fss_delimit_single_quote || buffer->string[range->start] == f_fss_delimit_double_quote) { + quoted = buffer->string[range->start]; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + found->start = range->start; + } + + // identify where the object ends + if (quoted == 0) { + status = F_none; + + while (range->start <= range->stop && range->start < buffer->used) { + status = f_fss_is_space(*buffer, *range); + + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + if (status == F_true) break; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + found->stop = range->start - 1; + + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + if (buffer->string[range->start] == f_string_eol[0]) { + range->start++; + return FL_fss_found_object_content_not; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + return FL_fss_found_object; + } + else { + + while (range->start <= range->stop && range->start < buffer->used) { + + if (buffer->string[range->start] == f_fss_delimit_slash) { + f_string_length first_slash = range->start; + f_string_length slash_count = 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + while (range->start <= range->stop && range->start < buffer->used) { + + if (buffer->string[range->start] == f_fss_delimit_placeholder) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + continue; + } + else if (buffer->string[range->start] != f_fss_delimit_slash) { + break; + } + + slash_count++; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_status_set_warning(F_unterminated_group_eos), F_status_set_warning(F_unterminated_group_stop)); + + if (buffer->string[range->start] == quoted) { + f_string_length length = range->start; + + range->start = first_slash; + + if (slash_count % 2 == 0) { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } + + while (slash_count > 0) { + if (buffer->string[range->start] == f_fss_delimit_slash) { + if (slash_count % 2 == 1) { + delimits.array[delimits.used] = range->start; + delimits.used++; + } + + slash_count--; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + range->start = length + 1; + + fl_macro_fss_skip_past_delimit_placeholders((*buffer), (*range)); + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); + + if ((status = f_fss_is_graph(*buffer, *range)) == F_true) { + + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); + + f_macro_string_lengths_delete_simple(delimits); + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object_not; + } + else if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + else if (buffer->string[range->start] == f_string_eol[0]) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->stop = length - 1; + range->start++; + return FL_fss_found_object_content_not; + } + + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + found->stop = length - 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object; + } + else { + if (delimits.used + (slash_count / 2) >= delimits.size) { + f_macro_string_lengths_resize(status, delimits, delimits.size + (slash_count / 2) + f_fss_default_allocation_step); + + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } + + while (slash_count > 0) { + if (buffer->string[range->start] == f_fss_delimit_slash) { + if (slash_count % 2 == 1) { + delimits.array[delimits.used] = range->start; + delimits.used++; + } + + slash_count--; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + range->start = length; + } + } + } + else if (buffer->string[range->start] == quoted) { + found->stop = range->start - 1; + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + while (range->start <= range->stop && range->start < buffer->used) { + if (buffer->string[range->start] == f_string_eol[0]) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + range->start++; + return FL_fss_found_object_content_not; + } + else if ((status = f_fss_is_space(*buffer, *range)) == F_true) { + fl_macro_fss_apply_delimit_placeholders((*buffer), delimits); + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object; + } + else if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + else if (buffer->string[range->start] != f_fss_delimit_placeholder) { + + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); + + f_macro_string_lengths_delete_simple(delimits); + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object_not; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + } // while + + fl_macro_fss_object_delimited_return_on_overflow((*buffer), (*range), (*found), delimits, F_none_eos, F_none_stop); + } + else if (buffer->string[range->start] == f_string_eol[0]) { + f_macro_string_lengths_delete_simple(delimits); + + range->start++; + return FL_fss_found_object_not; + } + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_status_set_warning(F_unterminated_group_eos), F_status_set_warning(F_unterminated_group_stop)); + } + + // seek to the end of the line when no valid object is found + while (range->start < buffer->used && range->start <= range->stop && buffer->string[range->start] != f_string_eol[0]) { + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) { + f_macro_string_lengths_delete_simple(delimits); + return status; + } + } // while + + fl_macro_fss_object_return_on_overflow((*buffer), (*range), (*found), delimits, F_data_not_eos, F_data_not_stop); + + f_macro_string_lengths_delete_simple(delimits); + + status = f_fss_increment_buffer(*buffer, range, 1); + if (F_status_is_error(status)) return status; + + return FL_fss_found_object_not; + } +#endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/c/private-fss.h b/level_1/fl_fss/c/private-fss.h index f81be10..b4e5977 100644 --- a/level_1/fl_fss/c/private-fss.h +++ b/level_1/fl_fss/c/private-fss.h @@ -40,6 +40,53 @@ extern "C" { extern f_return_status private_fl_fss_identify(const f_string_static buffer, f_fss_header *header) f_gcc_attribute_visibility_internal; #endif // !defined(_di_fl_fss_identify_) || !defined(_di_fl_fss_identify_file_) +/** + * Private implementation of fl_fss_basic_object_read(). + * + * Intended to be shared to each of the different implementation variations. + * + * @param is_basic + * Set to TRUE if this is a basic read. + * Set to FALSE if this is an extended read. + * @param buffer + * The buffer to read from. + * This will be updated with delimit placeholders as it is being processed. + * @param range + * The start/stop location within the buffer to be processed. + * The start location will be updated as the buffer is being processed. + * The start location will represent where the read stopped on return. + * A start location past the stop location or buffer used means that the entire range was processed. + * @param found + * A set of all locations where a valid object was found. + * + * @return + * FL_fss_found_object on success and object was found (start location is at end of object). + * FL_fss_found_object_not on success and no object was found (start location is after character designating this is not an object). + * F_none_eos on success after reaching the end of the buffer (a valid object is not yet confirmed). + * F_none_stop on success after reaching stopping point (a valid object is not yet confirmed). + * F_data_not_eos no objects found after reaching the end of the buffer (essentially only comments are found). + * F_data_not_stop no data found after reaching stopping point (essentially only comments are found). + * F_unterminated_group_eos (with warning bit) if EOS was reached before the a group termination was reached. + * F_unterminated_group_stop (with warning bit) if stop point was reached before the a group termination was reached. + * F_incomplete_utf (with error bit) is returned on failure to read/process a UTF-8 character due to the character being potentially incomplete. + * F_incomplete_utf_eos (with error bit) if the end of buffer is reached before the complete UTF-8 character can be processed. + * F_incomplete_utf_stop (with error bit) if the stop location is reached before the complete UTF-8 character can be processed. + * F_memory_reallocation (with error bit) on reallocation error. + * F_parameter (with error bit) if a parameter is invalid. + * F_utf (with error bit) is returned on failure to read/process a UTF-8 character. + * + * Errors from (with error bit): f_fss_increment_buffer(). + * Errors from (with error bit): f_fss_is_graph(). + * Errors from (with error bit): f_fss_is_space(). + * Errors from (with error bit): f_fss_skip_past_space(). + * + * @see fl_fss_basic_object_read() + * @see fl_fss_extended_object_read() + */ +#if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) + extern f_return_status private_fl_fss_basic_object_read(const bool is_basic, f_string_dynamic *buffer, f_string_range *range, f_fss_object *found) f_gcc_attribute_visibility_internal; +#endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_extended_object_read_) + #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 89f045c..9b236a0 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -14,43 +14,30 @@ extern "C" { #endif // _di_level_2_parameter_checking_ f_status status = F_none; + f_status status2 = F_none; f_string_length initial_used = objects->used; bool found_data = F_false; do { if (objects->used >= objects->size) { - f_macro_fss_objects_resize(status, (*objects), objects->used + f_fss_default_allocation_step); + f_macro_fss_objects_resize(status2, (*objects), objects->used + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; - if (F_status_is_error(status)) { - return status; - } - - f_macro_fss_contents_resize(status, (*contents), contents->used + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_contents_resize(status2, (*contents), contents->used + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } do { status = fl_fss_basic_object_read(buffer, range, &objects->array[objects->used]); - - if (F_status_is_error(status)) { - return status; - } + if (F_status_is_error(status)) return status; if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { objects->used++; if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } contents->used++; @@ -76,11 +63,9 @@ extern "C" { if (status == FL_fss_found_object) { found_data = F_true; - status = fl_fss_basic_content_read(buffer, range, &contents->array[contents->used]); - if (F_status_is_error(status)) { - return status; - } + status = fl_fss_basic_content_read(buffer, range, &contents->array[contents->used]); + if (F_status_is_error(status)) return status; break; } @@ -88,13 +73,8 @@ extern "C" { found_data = F_true; if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } break; diff --git a/level_2/fll_fss/c/fss_basic.h b/level_2/fll_fss/c/fss_basic.h index 4382e4d..55a30b9 100644 --- a/level_2/fll_fss/c/fss_basic.h +++ b/level_2/fll_fss/c/fss_basic.h @@ -33,8 +33,8 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param location - * The location within the buffer that is currently being read. + * @param range + * The range within the buffer that is currently being read. * @param objects * This will be populated with all valid objects found. * @param contents @@ -54,7 +54,7 @@ extern "C" { * F_utf (with error bit) is returned on failure to read/process a UTF-8 character. */ #ifndef _di_fll_fss_basic_read_ - extern f_return_status fll_fss_basic_read(f_string_dynamic *buffer, f_string_range *location, f_fss_objects *objects, f_fss_contents *contents); + extern f_return_status fll_fss_basic_read(f_string_dynamic *buffer, f_string_range *range, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_read_ /** diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index 988dcf7..50265cb 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -5,27 +5,28 @@ extern "C" { #endif #ifndef _di_fll_fss_basic_list_read_ - f_return_status fll_fss_basic_list_read(f_string_dynamic *buffer, f_string_range *location, f_fss_objects *objects, f_fss_contents *contents) { + f_return_status fll_fss_basic_list_read(f_string_dynamic *buffer, f_string_range *range, f_fss_objects *objects, f_fss_contents *contents) { #ifndef _di_level_2_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (objects == 0) return F_status_set_error(F_parameter); if (contents == 0) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ f_status status = F_none; + f_status status2 = F_none; f_string_length initial_used = objects->used; bool found_data = F_false; do { if (objects->used >= objects->size) { - f_macro_fss_objects_resize(status, (*objects), objects->used + f_fss_default_allocation_step); + f_macro_fss_objects_resize(status2, (*objects), objects->used + f_fss_default_allocation_step); if (F_status_is_error(status)) { return status; } - f_macro_fss_contents_resize(status, (*contents), contents->used + f_fss_default_allocation_step); + f_macro_fss_contents_resize(status2, (*contents), contents->used + f_fss_default_allocation_step); if (F_status_is_error(status)) { return status; @@ -33,24 +34,19 @@ extern "C" { } do { - status = fl_fss_basic_list_object_read(buffer, location, &objects->array[objects->used]); + status = fl_fss_basic_list_object_read(buffer, range, &objects->array[objects->used]); if (F_status_is_error(status)) { return status; } - if (location->start >= location->stop || location->start >= buffer->used) { + if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { objects->used++; if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } contents->used++; @@ -59,15 +55,15 @@ extern "C" { } if (found_data) { - if (location->start >= buffer->used) { - return F_none_eos; + if (range->start >= buffer->used) { + return F_none_eos; } return F_none_stop; } else { - if (location->start >= buffer->used) { - return F_data_not_eos; + if (range->start >= buffer->used) { + return F_data_not_eos; } return F_data_not_stop; @@ -76,7 +72,7 @@ extern "C" { if (status == FL_fss_found_object) { found_data = F_true; - status = fl_fss_basic_list_content_read(buffer, location, &contents->array[contents->used]); + status = fl_fss_basic_list_content_read(buffer, range, &contents->array[contents->used]); if (F_status_is_error(status)) { return status; @@ -88,13 +84,8 @@ extern "C" { found_data = F_true; if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } break; @@ -120,14 +111,14 @@ extern "C" { else if (status != FL_fss_found_object && status != FL_fss_found_content && status != FL_fss_found_content_not && status != FL_fss_found_object_content_not) { return status; } - // When content is found, the location->start is incremented, if content is found at location->stop, then location->start will be > location.stop. - else if (location->start >= location->stop || location->start >= buffer->used) { + // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. + else if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_content || status == FL_fss_found_content_not || status == FL_fss_found_object_content_not) { objects->used++; contents->used++; } - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { return F_none_eos; } @@ -136,7 +127,7 @@ extern "C" { objects->used++; contents->used++; - } while (location->start < f_string_length_size); + } while (range->start < f_string_length_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_basic_list.h b/level_2/fll_fss/c/fss_basic_list.h index 48001ae..6b603d5 100644 --- a/level_2/fll_fss/c/fss_basic_list.h +++ b/level_2/fll_fss/c/fss_basic_list.h @@ -32,8 +32,8 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param location - * The location within the buffer that is currently being read. + * @param range + * The range within the buffer that is currently being read. * @param objects * This will be populated with all valid objects found. * @param contents @@ -53,7 +53,7 @@ extern "C" { * F_utf (with error bit) is returned on failure to read/process a UTF-8 character. */ #ifndef _di_fll_fss_basic_list_read_ - extern f_return_status fll_fss_basic_list_read(f_string_dynamic *buffer, f_string_range *location, f_fss_objects *objects, f_fss_contents *contents); + extern f_return_status fll_fss_basic_list_read(f_string_dynamic *buffer, f_string_range *range, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_basic_list_read_ /** diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index d0c6258..ba011b1 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -5,52 +5,39 @@ extern "C" { #endif #ifndef _di_fll_fss_extended_read_ - f_return_status fll_fss_extended_read(f_string_dynamic *buffer, f_string_range *location, f_fss_objects *objects, f_fss_contents *contents) { + f_return_status fll_fss_extended_read(f_string_dynamic *buffer, f_string_range *range, f_fss_objects *objects, f_fss_contents *contents) { #ifndef _di_level_2_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (objects == 0) return F_status_set_error(F_parameter); if (contents == 0) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ f_status status = F_none; + f_status status2 = F_none; f_string_length initial_used = objects->used; bool found_data = F_false; do { if (objects->used >= objects->size) { - f_macro_fss_objects_resize(status, (*objects), objects->used + f_fss_default_allocation_step); + f_macro_fss_objects_resize(status2, (*objects), objects->used + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; - if (F_status_is_error(status)) { - return status; - } - - f_macro_fss_contents_resize(status, (*contents), contents->used + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_contents_resize(status2, (*contents), contents->used + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } do { - status = fl_fss_extended_object_read(buffer, location, &objects->array[objects->used]); - - if (F_status_is_error(status)) { - return status; - } + status = fl_fss_extended_object_read(buffer, range, &objects->array[objects->used]); + if (F_status_is_error(status)) return status; - if (location->start >= location->stop || location->start >= buffer->used) { + if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { objects->used++; - if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + if (contents->array[contents->used].used == contents->array[contents->used].size) { + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } contents->used++; @@ -59,14 +46,14 @@ extern "C" { } if (found_data) { - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { return F_none_eos; } return F_none_stop; } else { - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { return F_data_not_eos; } @@ -76,29 +63,23 @@ extern "C" { if (status == FL_fss_found_object) { found_data = F_true; - status = fl_fss_extended_content_read(buffer, location, &contents->array[contents->used]); - if (F_status_is_error(status)) { - return status; - } + status = fl_fss_extended_content_read(buffer, range, &contents->array[contents->used]); + if (F_status_is_error(status)) return status; break; } else if (status == FL_fss_found_object_content_not) { found_data = F_true; - if (contents->array[contents->used].used >= contents->array[contents->used].size) { - f_status status = F_none; - - f_macro_fss_content_resize(status, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + if (contents->array[contents->used].used == contents->array[contents->used].size) { + f_macro_fss_content_resize(status2, contents->array[contents->used], contents->array[contents->used].size + f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } break; } + } while (status == FL_fss_found_object_not); if (status == F_none_eos || status == F_none_stop) { @@ -107,7 +88,7 @@ extern "C" { contents->used++; return status; } - else if (status == F_data_not_eos || status == F_data_not_stop) { + else if (status == F_data_not_eos || status == F_data_not_stop || status == F_unterminated_group_eos || status == F_unterminated_group_stop) { // If at least some valid object was found, then return F_none equivelents. if (objects->used > initial_used) { @@ -117,26 +98,30 @@ extern "C" { return status; } - else if (status != FL_fss_found_object && status != FL_fss_found_content && status != FL_fss_found_content_not && status != FL_fss_found_object_content_not) { + else if (status != FL_fss_found_object && status != FL_fss_found_content && status != FL_fss_found_content_not && status != FL_fss_found_object_content_not && status != F_unterminated_group) { return status; } - // When content is found, the location->start is incremented, if content is found at location->stop, then location->start will be > location.stop. - else if (location->start >= location->stop || location->start >= buffer->used) { - if (status == FL_fss_found_object || status == FL_fss_found_content || status == FL_fss_found_content_not || status == FL_fss_found_object_content_not) { + // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. + else if (range->start >= range->stop || range->start >= buffer->used) { + if (status == FL_fss_found_object || status == FL_fss_found_content || status == FL_fss_found_content_not || status == FL_fss_found_object_content_not || status == F_unterminated_group) { objects->used++; contents->used++; } - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { + if (status == F_unterminated_group) return F_unterminated_group_eos; + return F_none_eos; } + if (status == F_unterminated_group) return F_unterminated_group_stop; + return F_none_stop; } objects->used++; contents->used++; - } while (location->start < f_string_length_size); + } while (range->start < f_string_length_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_extended.h b/level_2/fll_fss/c/fss_extended.h index dfecd02..24690c1 100644 --- a/level_2/fll_fss/c/fss_extended.h +++ b/level_2/fll_fss/c/fss_extended.h @@ -32,8 +32,8 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param location - * The location within the buffer that is currently being read. + * @param range + * The range within the buffer that is currently being read. * @param objects * This will be populated with all valid objects found. * @param contents @@ -53,7 +53,7 @@ extern "C" { * F_number_overflow (with error bit) if the maximimum buffer size is reached. */ #ifndef _di_fll_fss_extended_read_ - extern f_return_status fll_fss_extended_read(f_string_dynamic *buffer, f_string_range *location, f_fss_objects *objects, f_fss_contents *contents); + extern f_return_status fll_fss_extended_read(f_string_dynamic *buffer, f_string_range *range, f_fss_objects *objects, f_fss_contents *contents); #endif // _di_fll_fss_extended_read_ /** diff --git a/level_2/fll_fss/c/fss_extended_list.c b/level_2/fll_fss/c/fss_extended_list.c index be3aab2..0a7ead2 100644 --- a/level_2/fll_fss/c/fss_extended_list.c +++ b/level_2/fll_fss/c/fss_extended_list.c @@ -5,19 +5,21 @@ extern "C" { #endif #ifndef _di_fll_fss_extended_list_read_ - f_return_status fll_fss_extended_list_read(f_string_dynamic *buffer, f_string_range *location, f_fss_nest *nest) { + f_return_status fll_fss_extended_list_read(f_string_dynamic *buffer, f_string_range *range, f_fss_nest *nest) { #ifndef _di_level_3_parameter_checking_ if (buffer == 0) return F_status_set_error(F_parameter); - if (location == 0) return F_status_set_error(F_parameter); + if (range == 0) return F_status_set_error(F_parameter); if (nest == 0) return F_status_set_error(F_parameter); #endif // _di_level_3_parameter_checking_ f_status status = F_none; + f_status status2 = F_none; f_string_length initial_used = 0; bool found_data = F_false; if (nest->used == 0) { - f_macro_fss_nest_resize(status, (*nest), f_fss_default_allocation_step); + f_macro_fss_nest_resize(status2, (*nest), f_fss_default_allocation_step); + if (F_status_is_error(status2)) return status2; } else { initial_used = nest->depth[0].used; @@ -26,34 +28,28 @@ extern "C" { do { do { if (nest->depth[0].used >= nest->depth[0].size) { - f_macro_fss_items_resize(status, nest->depth[0], nest->depth[0].used + f_fss_default_allocation_step); - - if (F_status_is_error(status)) { - return status; - } + f_macro_fss_items_resize(status2, nest->depth[0], nest->depth[0].used + f_fss_default_allocation_step); + if (F_status_is_error(status)) return status; } - status = fl_fss_extended_list_object_read(buffer, location, &nest->depth[0].array[nest->depth[0].used].object); - - if (F_status_is_error(status)) { - return status; - } + status = fl_fss_extended_list_object_read(buffer, range, &nest->depth[0].array[nest->depth[0].used].object); + if (F_status_is_error(status)) return status; - if (location->start >= location->stop || location->start >= buffer->used) { + if (range->start >= range->stop || range->start >= buffer->used) { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { // extended list requires content closure, so this could be an error. return FL_fss_found_object_content_not; } if (found_data) { - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { return F_none_eos; } return F_none_stop; } else { - if (location->start >= buffer->used) { + if (range->start >= buffer->used) { return F_data_not_eos; } @@ -63,7 +59,7 @@ extern "C" { if (status == FL_fss_found_object) { found_data = F_true; - status = fl_fss_extended_list_content_read(buffer, location, nest); + status = fl_fss_extended_list_content_read(buffer, range, nest); break; } @@ -97,15 +93,15 @@ extern "C" { else if (status != FL_fss_found_object && status != FL_fss_found_content && status != FL_fss_found_content_not && status != FL_fss_found_object_content_not) { return status; } - // When content is found, the location->start is incremented, if content is found at location->stop, then location->start will be > location.stop. - else if (location->start >= location->stop || location->start >= buffer->used) { - if (location->start >= buffer->used) { + // When content is found, the range->start is incremented, if content is found at range->stop, then range->start will be > range.stop. + else if (range->start >= range->stop || range->start >= buffer->used) { + if (range->start >= buffer->used) { return F_none_eos; } return F_none_stop; } - } while (location->start < f_string_length_size); + } while (range->start < f_string_length_size); return F_status_is_error(F_number_overflow); } diff --git a/level_2/fll_fss/c/fss_extended_list.h b/level_2/fll_fss/c/fss_extended_list.h index 2615c00..d8eac5c 100644 --- a/level_2/fll_fss/c/fss_extended_list.h +++ b/level_2/fll_fss/c/fss_extended_list.h @@ -32,8 +32,8 @@ extern "C" { * * @param buffer * The buffer to read from. - * @param location - * The location within the buffer that is currently being read. + * @param range + * The range within the buffer that is currently being read. * @param nest * An nested set of all objects and content. * @@ -58,7 +58,7 @@ extern "C" { * FL_fss_found_object_content_not on success and object was found but no content was found (start location is at end of object). */ #ifndef _di_fll_fss_extended_list_read_ - extern f_return_status fll_fss_extended_list_read(f_string_dynamic *buffer, f_string_range *location, f_fss_nest *nest); + extern f_return_status fll_fss_extended_list_read(f_string_dynamic *buffer, f_string_range *range, f_fss_nest *nest); #endif // _di_fll_fss_extended_list_read_ /**