From 594f05fa5fde1f94ee9d943cf691a42a29d4922b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 30 May 2021 13:09:51 -0500 Subject: [PATCH] Progress: FLL/FSS related changes, populate more ASCII characters. It occurred to me that I should follow the same practices as the FSS process where I use range for the FLL/FSS Identifier processing. Change the behavior to do so. It also occurred to me that I should try to avoid processing both a dynamic string's used as well as the range. The FLL/FSS Identifier code only accepts a string for this reason. It will likely be a good idea to change the other FSS code to accept a f_string_t instead of a f_string_static_t. Add the initial support for FSS header processing with support for multiple FLL/FSS Identifiers. Add and use the FSS specific default memory allocators. Complete more of the hardcoded ASCII strings. Unless I missed something, all that is left now is to consider adding the extended ASCII. --- build/level_0/settings | 2 +- build/monolithic/settings | 2 +- level_0/f_fss/c/fss-common.c | 10 + level_0/f_fss/c/fss-common.h | 387 ++++++++++++++++----- level_0/f_fss/c/fss.c | 15 - level_0/f_fss/data/build/settings | 2 +- level_0/f_string/c/string-common.c | 68 +++- level_0/f_string/c/string-common.h | 155 +++++++-- level_1/fl_fss/c/fss_status.h | 2 - level_1/fl_string/c/string.c | 218 +++++++++--- level_1/fl_string/c/string.h | 24 +- level_2/fll_fss/c/fss.c | 208 +++++++++-- level_2/fll_fss/c/fss.h | 68 ++-- level_2/fll_fss/c/fss_basic.c | 12 +- level_2/fll_fss/c/fss_basic_list.c | 4 +- level_2/fll_fss/c/fss_extended.c | 14 +- level_2/fll_fss/c/fss_extended_list.c | 4 +- level_2/fll_fss/c/fss_status.c | 18 - level_2/fll_fss/c/fss_status.h | 6 - level_2/fll_fss/c/private-fss.c | 131 ------- level_2/fll_fss/c/private-fss.h | 27 -- level_3/controller/c/private-rule.c | 2 +- .../c/private-fss_basic_list_write.c | 2 +- .../fss_basic_write/c/private-fss_basic_write.c | 2 +- .../c/private-fss_embedded_list_write.c | 2 +- .../c/private-fss_extended_list_write.c | 2 +- .../c/private-fss_extended_write.c | 2 +- 27 files changed, 916 insertions(+), 473 deletions(-) create mode 100644 level_0/f_fss/c/fss-common.c diff --git a/build/level_0/settings b/build/level_0/settings index fedcc2b..b31ed83 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -21,7 +21,7 @@ build_language c build_libraries -lc -lcap build_libraries-level build_libraries-level_threadless -build_sources_library account.c private-account.c capability.c color.c color-common.c console.c console-common.c control_group.c control_group-common.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c file-common.c private-file.c fss.c private-fss.c fss_named.c fss_nest.c fss_set.c iki.c iki-common.c private-iki.c limit.c memory.c memory_structure.c private-memory.c path.c path-common.c private-path.c pipe.c print.c private-print.c serialize.c serialize-common.c private-serialize.c signal.c socket.c string.c string-common.c private-string.c string_dynamic.c string_map.c string_quantity.c string_range.c string_triple.c type_array.c private-type_array.c utf.c utf-common.c private-utf.c utf_dynamic.c utf_map.c utf_quantity.c utf_range.c utf_triple.c +build_sources_library account.c private-account.c capability.c color.c color-common.c console.c console-common.c control_group.c control_group-common.c conversion.c directory.c private-directory.c environment.c private-environment.c file.c file-common.c private-file.c fss.c private-fss.c fss-common.c fss_named.c fss_nest.c fss_set.c iki.c iki-common.c private-iki.c limit.c memory.c memory_structure.c private-memory.c path.c path-common.c private-path.c pipe.c print.c private-print.c serialize.c serialize-common.c private-serialize.c signal.c socket.c string.c string-common.c private-string.c string_dynamic.c string_map.c string_quantity.c string_range.c string_triple.c type_array.c private-type_array.c utf.c utf-common.c private-utf.c utf_dynamic.c utf_map.c utf_quantity.c utf_range.c utf_triple.c build_sources_library-level thread.c private-thread.c build_sources_program build_sources_headers account.h account-common.h capability.h capability-common.h color.h color-common.h console.h console-common.h control_group.h control_group-common.h conversion.h conversion-common.h directory.h directory_type.h directory-common.h environment.h environment-common.h execute.h execute-common.h file.h file-common.h fss.h private-fss.h fss-common.h fss_comment.h fss_delimit.h fss_named.h fss_nest.h fss_quote.h fss_set.h iki.h iki-common.h limit.h limit-common.h memory.h memory_structure.h memory-common.h path.h path-common.h pipe.h print.h serialize.h serialize-common.h signal.h signal-common.h socket.h socket-common.h status.h string.h string-common.h private-string.h string_dynamic.h string_map.h string_quantity.h string_range.h string_triple.h type.h type_array.h private-type_array.h type_array-common.h utf.h utf-common.h utf_dynamic.h utf_map.h utf_quantity.h utf_range.h utf_triple.h diff --git a/build/monolithic/settings b/build/monolithic/settings index dc08117..da83767 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -21,7 +21,7 @@ build_language c build_libraries -lc -lcap build_libraries-monolithic build_libraries-monolithic_threadless -build_sources_library level_0/account.c level_0/private-account.c level_0/capability.c level_0/color.c level_0/color-common.c level_0/console.c level_0/console-common.c level_0/control_group.c level_0/control_group-common.c level_0/conversion.c level_0/directory.c level_0/private-directory.c level_0/environment.c level_0/private-environment.c level_0/file.c level_0/file-common.c level_0/private-file.c level_0/fss.c level_0/private-fss.c level_0/fss_named.c level_0/fss_nest.c level_0/fss_set.c level_0/iki.c level_0/iki-common.c level_0/private-iki.c level_0/limit.c level_0/memory.c level_0/memory_structure.c level_0/private-memory.c level_0/path.c level_0/path-common.c level_0/private-path.c level_0/pipe.c level_0/print.c level_0/private-print.c level_0/serialize.c level_0/serialize-common.c level_0/private-serialize.c level_0/signal.c level_0/socket.c level_0/string.c level_0/string-common.c level_0/private-string.c level_0/string_dynamic.c level_0/string_map.c level_0/string_quantity.c level_0/string_range.c level_0/string_triple.c level_0/type_array.c level_0/private-type_array.c level_0/utf.c level_0/utf-common.c level_0/private-utf.c level_0/utf_dynamic.c level_0/utf_map.c level_0/utf_quantity.c level_0/utf_range.c level_0/utf_triple.c level_1/console.c level_1/control_group.c level_1/conversion.c level_1/directory.c level_1/private-directory.c level_1/environment.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_embedded_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/iki.c level_1/print.c level_1/private-print.c level_1/signal.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/control_group.c level_2/error.c level_2/error-common.c level_2/private-error.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/private-file.c level_2/fss.c level_2/private-fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_embedded_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/iki.c level_2/private-iki.c level_2/path.c level_2/program.c level_2/status.c +build_sources_library level_0/account.c level_0/private-account.c level_0/capability.c level_0/color.c level_0/color-common.c level_0/console.c level_0/console-common.c level_0/control_group.c level_0/control_group-common.c level_0/conversion.c level_0/directory.c level_0/private-directory.c level_0/environment.c level_0/private-environment.c level_0/file.c level_0/file-common.c level_0/private-file.c level_0/fss.c level_0/private-fss.c level_0/fss-common.c level_0/fss_named.c level_0/fss_nest.c level_0/fss_set.c level_0/iki.c level_0/iki-common.c level_0/private-iki.c level_0/limit.c level_0/memory.c level_0/memory_structure.c level_0/private-memory.c level_0/path.c level_0/path-common.c level_0/private-path.c level_0/pipe.c level_0/print.c level_0/private-print.c level_0/serialize.c level_0/serialize-common.c level_0/private-serialize.c level_0/signal.c level_0/socket.c level_0/string.c level_0/string-common.c level_0/private-string.c level_0/string_dynamic.c level_0/string_map.c level_0/string_quantity.c level_0/string_range.c level_0/string_triple.c level_0/type_array.c level_0/private-type_array.c level_0/utf.c level_0/utf-common.c level_0/private-utf.c level_0/utf_dynamic.c level_0/utf_map.c level_0/utf_quantity.c level_0/utf_range.c level_0/utf_triple.c level_1/console.c level_1/control_group.c level_1/conversion.c level_1/directory.c level_1/private-directory.c level_1/environment.c level_1/private-fss.c level_1/fss_basic.c level_1/fss_basic_list.c level_1/fss_embedded_list.c level_1/fss_extended.c level_1/fss_extended_list.c level_1/iki.c level_1/print.c level_1/private-print.c level_1/signal.c level_1/status.c level_1/string.c level_1/private-string.c level_1/utf.c level_1/private-utf.c level_1/utf_file.c level_1/private-utf_file.c level_2/control_group.c level_2/error.c level_2/error-common.c level_2/private-error.c level_2/execute.c level_2/private-execute.c level_2/file.c level_2/private-file.c level_2/fss.c level_2/private-fss.c level_2/fss_basic.c level_2/fss_basic_list.c level_2/fss_embedded_list.c level_2/fss_extended.c level_2/fss_extended_list.c level_2/fss_status.c level_2/iki.c level_2/private-iki.c level_2/path.c level_2/program.c level_2/status.c build_sources_library-monolithic level_0/thread.c level_0/private-thread.c build_sources_program build_sources_headers level_0/account.h level_0/account-common.h level_0/capability.h level_0/capability-common.h level_0/color.h level_0/color-common.h level_0/console.h level_0/console-common.h level_0/control_group.h level_0/control_group-common.h level_0/conversion.h level_0/conversion-common.h level_0/directory.h level_0/directory_type.h level_0/directory-common.h level_0/environment.h level_0/environment-common.h level_0/execute.h level_0/execute-common.h level_0/file.h level_0/file-common.h level_0/fss.h level_0/private-fss.h level_0/fss-common.h level_0/fss_comment.h level_0/fss_delimit.h level_0/fss_named.h level_0/fss_nest.h level_0/fss_quote.h level_0/fss_set.h level_0/iki.h level_0/iki-common.h level_0/limit.h level_0/limit-common.h level_0/memory.h level_0/memory_structure.h level_0/memory-common.h level_0/path.h level_0/path-common.h level_0/pipe.h level_0/print.h level_0/serialize.h level_0/serialize-common.h level_0/signal.h level_0/signal-common.h level_0/socket.h level_0/socket-common.h level_0/status.h level_0/string.h level_0/string-common.h level_0/private-string.h level_0/string_dynamic.h level_0/string_map.h level_0/string_quantity.h level_0/string_range.h level_0/string_triple.h level_0/type.h level_0/type_array.h level_0/private-type_array.h level_0/type_array-common.h level_0/utf.h level_0/utf-common.h level_0/utf_dynamic.h level_0/utf_map.h level_0/utf_quantity.h level_0/utf_range.h level_0/utf_triple.h level_1/console.h level_1/control_group.h level_1/conversion.h level_1/directory.h level_1/environment.h level_1/execute.h level_1/execute-common.h level_1/fss.h level_1/fss_basic.h level_1/fss_basic_list.h level_1/fss_embedded_list.h level_1/fss_extended.h level_1/fss_extended_list.h level_1/fss_status.h level_1/iki.h level_1/print.h level_1/signal.h level_1/signal-common.h level_1/status.h level_1/string.h level_1/utf.h level_1/utf_file.h level_2/control_group.h level_2/error.h level_2/error-common.h level_2/execute.h level_2/file.h level_2/fss.h level_2/fss_basic.h level_2/fss_basic_list.h level_2/fss_embedded_list.h level_2/fss_extended.h level_2/fss_extended_list.h level_2/fss_status.h level_2/iki.h level_2/path.h level_2/program.h level_2/status.h diff --git a/level_0/f_fss/c/fss-common.c b/level_0/f_fss/c/fss-common.c new file mode 100644 index 0000000..be126fd --- /dev/null +++ b/level_0/f_fss/c/fss-common.c @@ -0,0 +1,10 @@ +#include "fss.h" +#include "private-fss.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_fss/c/fss-common.h b/level_0/f_fss/c/fss-common.h index 6c2d021..c2d3cf1 100644 --- a/level_0/f_fss/c/fss-common.h +++ b/level_0/f_fss/c/fss-common.h @@ -20,18 +20,18 @@ extern "C" { * FSS-specific types. */ #ifndef _di_f_fss_types_t_ - extern const f_string_t f_fss_brace_left_s; - extern const f_string_t f_fss_brace_right_s; - extern const f_string_t f_fss_colon_s; - extern const f_string_t f_fss_dash_s; - extern const f_string_t f_fss_f_s; - extern const f_string_t f_fss_pound_s; - extern const f_string_t f_fss_quote_single_s; - extern const f_string_t f_fss_quote_double_s; - extern const f_string_t f_fss_s_s; - extern const f_string_t f_fss_slash_s; - extern const f_string_t f_fss_space_s; - extern const f_string_t f_fss_underscore_s; + #define f_fss_brace_close_s f_string_ascii_brace_close_s + #define f_fss_brace_open_s f_string_ascii_brace_open_s + #define f_fss_colon_s f_string_ascii_colon_s + #define f_fss_dash_s f_string_ascii_minus_s + #define f_fss_f_s f_string_ascii_f_s + #define f_fss_pound_s f_string_ascii_pound_s + #define f_fss_quote_double_s f_string_ascii_quote_double_s + #define f_fss_quote_single_s f_string_ascii_quote_single_s + #define f_fss_s_s f_string_ascii_s_s + #define f_fss_slash_s f_string_ascii_slash_backward_s + #define f_fss_space_s f_string_ascii_space_s + #define f_fss_underscore_s f_string_ascii_underscore_s #define f_fss_comment f_fss_pound_s[0] #define f_fss_eol f_string_eol_s[0] @@ -45,13 +45,13 @@ extern "C" { #define f_fss_basic_list_open f_fss_colon_s[0] #define f_fss_basic_list_open_end f_string_eol_s[0] #define f_fss_basic_list_close f_string_eol_s[0] - #define f_fss_extended_list_open f_fss_brace_left_s[0] + #define f_fss_extended_list_open f_fss_brace_open_s[0] #define f_fss_extended_list_open_end f_string_eol_s[0] - #define f_fss_extended_list_close f_fss_brace_right_s[0] + #define f_fss_extended_list_close f_fss_brace_close_s[0] #define f_fss_extended_list_close_end f_string_eol_s[0] - #define f_fss_embedded_list_open f_fss_brace_left_s[0] + #define f_fss_embedded_list_open f_fss_brace_open_s[0] #define f_fss_embedded_list_open_end f_string_eol_s[0] - #define f_fss_embedded_list_close f_fss_brace_right_s[0] + #define f_fss_embedded_list_close f_fss_brace_close_s[0] #define f_fss_embedded_list_close_end f_string_eol_s[0] #define f_fss_type_header_open f_fss_pound_s[0] #define f_fss_type_header_part1 f_fss_space_s[0] @@ -60,15 +60,13 @@ extern "C" { #define f_fss_type_header_part4 f_fss_s_s[0] #define f_fss_type_header_part5 f_fss_dash_s[0] #define f_fss_type_header_close f_string_eol_s[0] - - typedef uint64_t f_fss_id_t; #endif // _di_f_fss_types_t_ /** * FSS-specific delimiters. */ #ifndef _di_f_fss_delimiters_ - #define f_fss_delimit_placeholder f_string_placeholder[0] + #define f_fss_delimit_placeholder f_string_placeholder_s[0] #define f_fss_delimit_quote_single f_fss_quote_single_s[0] #define f_fss_delimit_quote_double f_fss_quote_double_s[0] #define f_fss_delimit_slash f_fss_slash_s[0] @@ -125,78 +123,17 @@ extern "C" { #endif // _di_f_fss_complete_ /** - * Max size of a FSS header. - * - * The standard FSS character header is: "# fss-0000\n\0", which is 10 characters + newline + EOS = 12. - * - * The UTF-8 BOM is not supported because it is not an actual thing (only a suggestion according to rfc3629). - * The UTF-8 BOM sequence is actually a different character called "zero-width non-breaking space". - * Because it already has a use, this project considers the existence of UTF-8 BOM bad practice in all cases. - * After all, if your file begins with a "zero-width non breaking space", you may want to actually use a space and not a "BOM". - */ -#ifndef _di_f_fss_max_header_length_ - #define f_fss_max_header_length 12 -#endif // _di_f_fss_max_header_length_ - -/** * Default allocation steps. * * Recommended to be set to at least 4 to be UTF-8 friendlier. */ #ifndef _di_f_fss_default_allocation_step_ #define f_fss_default_allocation_step f_memory_default_allocation_small + #define f_fss_default_allocation_step_small f_memory_default_allocation_small + #define f_fss_default_allocation_step_large f_memory_default_allocation_large #endif // _di_f_fss_default_allocation_step_ /** - * Stores information about a particular fss file, otherwise known as its header. - * - * @todo change this to use a range instead if a length to support multiple sub-headers. - * - * type: The kind of fss file is this. - * length: Total length of the header. - */ -#ifndef _di_f_fss_header_t_ - typedef struct { - f_fss_id_t type; - - f_array_length_t length; - } f_fss_header_t; - - #define f_fss_header_initialize { 0, 0 } -#endif // _di_f_fss_header_t_ - -/** - * This holds an array of fss_headers. - * - * array: The array of headers. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. - */ -#ifndef _di_f_fss_headers_t_ - typedef struct { - f_fss_header_t *array; - - f_array_length_t size; - f_array_length_t used; - } f_fss_headers_t; - - #define f_fss_headers_t_initialize { 0, 0, 0 } - - #define macro_f_fss_headers_t_clear(headers) macro_f_memory_structure_clear(headers) - - #define macro_f_fss_headers_t_resize(status, headers, length) macro_f_memory_structure_resize(status, headers, f_fss_header_t, length) - #define macro_f_fss_headers_t_adjust(status, headers, length) macro_f_memory_structure_adjust(status, headers, f_fss_header_t, length) - - #define macro_f_fss_headers_t_delete_simple(headers) macro_f_memory_structure_delete_simple(headers, f_fss_header_t) - #define macro_f_fss_headers_t_destroy_simple(headers) macro_f_memory_structure_destroy_simple(headers, f_fss_header_t) - - #define macro_f_fss_headers_t_increase(status, step, headers) macro_f_memory_structure_increase(status, step, headers, f_fss_header_t) - #define macro_f_fss_headers_t_increase_by(status, headers, amount) macro_f_memory_structure_increase_by(status, headers, f_fss_header_t, amount) - #define macro_f_fss_headers_t_decrease_by(status, headers, amount) macro_f_memory_structure_decrease_by(status, headers, f_fss_header_t, amount) - #define macro_f_fss_headers_t_decimate_by(status, headers, amount) macro_f_memory_structure_decimate_by(status, headers, f_fss_header_t, amount) -#endif // _di_f_fss_headers_t_ - -/** * This is a range that represents an object. */ #ifndef _di_fss_object_t_ @@ -287,6 +224,292 @@ extern "C" { #define macro_f_fss_contents_t_decimate_by(status, contents, amount) macro_f_string_rangess_t_decimate_by(status, contents, amount) #endif // _di_f_fss_contents_t_ +/** + * Resize the string quantitys array. + * + * @param length + * The new size to use. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_adjust_ + extern f_status_t f_string_quantitys_adjust(const f_array_length_t length, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_adjust_ + +/** + * Append the source quantitys onto the destination. + * + * @param source + * The source quantitys to append. + * @param destination + * The destination quantitys the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_append_ + extern f_status_t f_string_quantitys_append(const f_string_quantitys_t source, f_string_quantitys_t *destination); +#endif // _di_f_string_quantitys_append_ + +/** + * Resize the string quantitys array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_decimate_by_ + extern f_status_t f_string_quantitys_decimate_by(const f_array_length_t amount, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_decimate_by_ + +/** + * Resize the string quantitys array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_decrease_by_ + extern f_status_t f_string_quantitys_decrease_by(const f_array_length_t amount, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_decrease_by_ + +/** + * Increase the size of the string quantitys array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_increase_ + extern f_status_t f_string_quantitys_increase(const uint16_t step, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_increase_ + +/** + * Resize the string quantitys array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param quantitys + * The string quantitys array to resize. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_increase_by_ + extern f_status_t f_string_quantitys_increase_by(const f_array_length_t amount, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_increase_by_ + +/** + * Resize the string quantitys array. + * + * @param length + * The new size to use. + * @param quantitys + * The string quantitys array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantitys_resize_ + extern f_status_t f_string_quantitys_resize(const f_array_length_t length, f_string_quantitys_t *quantitys); +#endif // _di_f_string_quantitys_resize_ + +/** + * Resize the string quantityss array. + * + * @param length + * The new size to use. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_adjust_ + extern f_status_t f_string_quantityss_adjust(const f_array_length_t length, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_adjust_ + +/** + * Resize the string quantityss array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_decimate_by_ + extern f_status_t f_string_quantityss_decimate_by(const f_array_length_t amount, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_decimate_by_ + +/** + * Resize the string quantityss array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_decrease_by_ + extern f_status_t f_string_quantityss_decrease_by(const f_array_length_t amount, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_decrease_by_ + +/** + * Increase the size of the string quantityss array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_increase_ + extern f_status_t f_string_quantityss_increase(const uint16_t step, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_increase_ + +/** + * Resize the string quantityss array to a larger size. + * + * This will resize making the string larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (f_array_length_t_size). + * If already set to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param quantityss + * The string quantityss array to resize. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_increase_by_ + extern f_status_t f_string_quantityss_increase_by(const f_array_length_t amount, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_increase_by_ + +/** + * Resize the string quantityss array. + * + * @param length + * The new size to use. + * @param quantityss + * The string quantityss array to adjust. + * + * @return + * F_none on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_resize(). + */ +#ifndef _di_f_string_quantityss_resize_ + extern f_status_t f_string_quantityss_resize(const f_array_length_t length, f_string_quantityss_t *quantityss); +#endif // _di_f_string_quantityss_resize_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_fss/c/fss.c b/level_0/f_fss/c/fss.c index 1b1fcd2..c3ac5ec 100644 --- a/level_0/f_fss/c/fss.c +++ b/level_0/f_fss/c/fss.c @@ -5,21 +5,6 @@ extern "C" { #endif -#ifndef _di_f_fss_types_t_ - const f_string_t f_fss_brace_left_s = "{"; - const f_string_t f_fss_brace_right_s = "}"; - const f_string_t f_fss_colon_s = ":"; - const f_string_t f_fss_dash_s = "-"; - const f_string_t f_fss_f_s = "f"; - const f_string_t f_fss_pound_s = "#"; - const f_string_t f_fss_quote_single_s = "'"; - const f_string_t f_fss_quote_double_s = "\""; - const f_string_t f_fss_s_s = "s"; - const f_string_t f_fss_slash_s = "\\"; - const f_string_t f_fss_space_s = " "; - const f_string_t f_fss_underscore_s = "_"; -#endif // _di_f_fss_types_t_ - #ifndef _di_fl_fss_apply_delimit_ f_status_t fl_fss_apply_delimit(const f_fss_delimits_t delimits, f_string_static_t *buffer) { #ifndef _di_level_0_parameter_checking_ diff --git a/level_0/f_fss/data/build/settings b/level_0/f_fss/data/build/settings index 1442b44..58dab1f 100644 --- a/level_0/f_fss/data/build/settings +++ b/level_0/f_fss/data/build/settings @@ -20,7 +20,7 @@ build_indexer ar build_language c build_libraries -lc build_libraries-individual -lf_memory -lf_string -lf_type_array -lf_utf -build_sources_library fss.c private-fss.c fss_named.c fss_nest.c fss_set.c +build_sources_library fss.c private-fss.c fss-common.c fss_named.c fss_nest.c fss_set.c build_sources_program build_sources_headers fss.h private-fss.h fss-common.h fss_comment.h fss_delimit.h fss_named.h fss_nest.h fss_quote.h fss_set.h build_sources_script diff --git a/level_0/f_string/c/string-common.c b/level_0/f_string/c/string-common.c index 9e0987b..298b36d 100644 --- a/level_0/f_string/c/string-common.c +++ b/level_0/f_string/c/string-common.c @@ -5,22 +5,10 @@ extern "C" { #endif -#ifndef _di_f_string_eol_s_ - const f_string_t f_string_eol_s = f_string_eol; -#endif // _di_f_string_eol_s_ - #ifndef _di_f_string_empty_s_ const f_string_t f_string_empty_s = ""; #endif // _di_f_string_empty_s_ -#ifndef _di_f_string_placeholder_s_ - const f_string_t f_string_placeholder_s = f_string_placeholder; -#endif // _di_f_string_placeholder_s_ - -#ifndef _di_f_string_space_s_ - const f_string_t f_string_space_s = f_string_space; -#endif // _di_f_string_space_s_ - #ifndef _di_string_format_s_ const f_string_t f_string_format_string_s = f_string_format_string; const f_string_t f_string_format_character_s = f_string_format_character; @@ -105,16 +93,72 @@ extern "C" { const f_string_t f_string_ascii_Y_s = f_string_ascii_Y; const f_string_t f_string_ascii_Z_s = f_string_ascii_Z; + const f_string_t f_string_ascii_ampersand_s = f_string_ascii_ampersand; + const f_string_t f_string_ascii_asterisk_s = f_string_ascii_asterisk; + const f_string_t f_string_ascii_brace_close_s = f_string_ascii_brace_close; + const f_string_t f_string_ascii_brace_open_s = f_string_ascii_brace_open; + const f_string_t f_string_ascii_bracket_close_s = f_string_ascii_bracket_close; + const f_string_t f_string_ascii_bracket_open_s = f_string_ascii_bracket_open; + const f_string_t f_string_ascii_caret_s = f_string_ascii_caret; const f_string_t f_string_ascii_comma_s = f_string_ascii_comma; const f_string_t f_string_ascii_colon_s = f_string_ascii_colon; const f_string_t f_string_ascii_colon_semi_s = f_string_ascii_colon_semi; + const f_string_t f_string_ascii_dollar_s = f_string_ascii_dollar; const f_string_t f_string_ascii_equal_s = f_string_ascii_equal; + const f_string_t f_string_ascii_exclamation_s = f_string_ascii_exclamation; + const f_string_t f_string_ascii_grave_s = f_string_ascii_grave; + const f_string_t f_string_ascii_mark_question_s = f_string_ascii_mark_question; const f_string_t f_string_ascii_minus_s = f_string_ascii_minus; + const f_string_t f_string_ascii_parenthesis_open_s = f_string_ascii_parenthesis_open; + const f_string_t f_string_ascii_parenthesis_close_s = f_string_ascii_parenthesis_close; + const f_string_t f_string_ascii_percent_s = f_string_ascii_percent; const f_string_t f_string_ascii_period_s = f_string_ascii_period; + const f_string_t f_string_ascii_pipe_s = f_string_ascii_pipe; const f_string_t f_string_ascii_plus_s = f_string_ascii_plus; + const f_string_t f_string_ascii_pound_s = f_string_ascii_pound; + const f_string_t f_string_ascii_quote_double_s = f_string_ascii_quote_double; + const f_string_t f_string_ascii_quote_single_s = f_string_ascii_quote_single; + const f_string_t f_string_ascii_sign_at_s = f_string_ascii_sign_at; + const f_string_t f_string_ascii_sign_greater_than_s = f_string_ascii_sign_greater_than; + const f_string_t f_string_ascii_sign_less_than_s = f_string_ascii_sign_less_than; const f_string_t f_string_ascii_slash_forward_s = f_string_ascii_slash_forward; const f_string_t f_string_ascii_slash_backward_s = f_string_ascii_slash_backward; const f_string_t f_string_ascii_tilde_s = f_string_ascii_tilde; + const f_string_t f_string_ascii_underscore_s = f_string_ascii_underscore; + + const f_string_t f_string_ascii_acknowledge_s = f_string_ascii_acknowledge; + const f_string_t f_string_ascii_acknowledge_negative_s = f_string_ascii_acknowledge_negative; + const f_string_t f_string_ascii_bell_s = f_string_ascii_bell; + const f_string_t f_string_ascii_cancel_s = f_string_ascii_cancel; + const f_string_t f_string_ascii_data_link_escape_s = f_string_ascii_data_link_escape; + const f_string_t f_string_ascii_device_control_one_s = f_string_ascii_device_control_one; + const f_string_t f_string_ascii_device_control_two_s = f_string_ascii_device_control_two; + const f_string_t f_string_ascii_device_control_three_s = f_string_ascii_device_control_three; + const f_string_t f_string_ascii_device_control_four_s = f_string_ascii_device_control_four; + const f_string_t f_string_ascii_enquiry_s = f_string_ascii_enquiry; + const f_string_t f_string_ascii_escape_s = f_string_ascii_escape; + const f_string_t f_string_ascii_feed_form_s = f_string_ascii_feed_form; + const f_string_t f_string_ascii_feed_line_s = f_string_ascii_feed_line; + const f_string_t f_string_ascii_header_start_s = f_string_ascii_header_start; + const f_string_t f_string_ascii_medium_stop_s = f_string_ascii_medium_stop; + const f_string_t f_string_ascii_null_s = f_string_ascii_null; + const f_string_t f_string_ascii_return_carriage_s = f_string_ascii_return_carriage; + const f_string_t f_string_ascii_separator_file_s = f_string_ascii_separator_file; + const f_string_t f_string_ascii_separator_group_s = f_string_ascii_separator_group; + const f_string_t f_string_ascii_separator_record_s = f_string_ascii_separator_record; + const f_string_t f_string_ascii_separator_unit_s = f_string_ascii_separator_unit; + const f_string_t f_string_ascii_shift_in_s = f_string_ascii_shift_in; + const f_string_t f_string_ascii_shift_out_s = f_string_ascii_shift_out; + const f_string_t f_string_ascii_space_s = f_string_ascii_space; + const f_string_t f_string_ascii_space_back_s = f_string_ascii_space_back; + const f_string_t f_string_ascii_substitute_s = f_string_ascii_substitute; + const f_string_t f_string_ascii_synchronous_idle_s = f_string_ascii_synchronous_idle; + const f_string_t f_string_ascii_tab_horizontal_s = f_string_ascii_tab_horizontal; + const f_string_t f_string_ascii_tab_vertical_s = f_string_ascii_tab_vertical; + const f_string_t f_string_ascii_text_start_s = f_string_ascii_text_start; + const f_string_t f_string_ascii_text_stop_s = f_string_ascii_text_stop; + const f_string_t f_string_ascii_transmission_stop_s = f_string_ascii_transmission_stop; + const f_string_t f_string_ascii_transmission_block_end_s = f_string_ascii_transmission_block_end; #endif // _di_string_ascii_s_ #ifdef __cplusplus diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h index 795766e..de0adfe 100644 --- a/level_0/f_string/c/string-common.h +++ b/level_0/f_string/c/string-common.h @@ -69,10 +69,8 @@ extern "C" { * FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored. */ #ifndef _di_f_string_eol_s_ - #define f_string_eol "\n" - #define f_string_eol_length 1 - - const extern f_string_t f_string_eol_s; + #define f_string_eol_s f_string_ascii_feed_line_s + #define f_string_eol_s_length 1 #endif // _di_f_string_eol_s_ #ifndef _di_f_string_empty_s_ @@ -80,17 +78,13 @@ extern "C" { #endif // _di_f_string_empty_s_ #ifndef _di_f_string_placeholder_s_ - #define f_string_placeholder "" - #define f_string_placeholder_length 1 - - const extern f_string_t f_string_placeholder_s; + #define f_string_placeholder_s f_string_empty_s + #define f_string_placeholder_s_length 1 #endif // _di_f_string_placeholder_s_ #ifndef _di_f_string_space_s_ - #define f_string_space " " - #define f_string_space_length 1 - - const extern f_string_t f_string_space_s; + #define f_string_space_s f_string_ascii_space_s + #define f_string_space_s_length 1 #endif // _di_f_string_space_s_ #ifndef _di_string_format_s_ @@ -140,7 +134,10 @@ extern "C" { * Instead, this is for very common uses such as converting a hex-digit string into a number. * These are standardized not be the language, per-say, but instead by the specific standard (such as hexidecimal). * - * @todo provide most (printable) ASCII-characters. + * The NULL ASCII string can be represented by the integer 0; however, given that these are all NULL-terminated strings the NULL character is represented with a NULL termination as well. + * The NULL ASCII string therefore has two NULLs, first the NULL represents the NULL and the second represents the NULL termination. + * + * @todo provide extended ASCII-characters. */ #ifndef _di_string_ascii_s_ #define f_string_ascii_0 "0" @@ -208,16 +205,72 @@ extern "C" { #define f_string_ascii_Y "Y" #define f_string_ascii_Z "Z" - #define f_string_ascii_comma "," - #define f_string_ascii_colon ":" - #define f_string_ascii_colon_semi ";" - #define f_string_ascii_equal "=" - #define f_string_ascii_minus "-" - #define f_string_ascii_period "." - #define f_string_ascii_plus "+" - #define f_string_ascii_slash_forward "/" - #define f_string_ascii_slash_backward "\\" - #define f_string_ascii_tilde "~" + #define f_string_ascii_ampersand "&" + #define f_string_ascii_asterisk "*" + #define f_string_ascii_brace_close "}" + #define f_string_ascii_brace_open "{" + #define f_string_ascii_bracket_close "]" + #define f_string_ascii_bracket_open "[" + #define f_string_ascii_caret "^" + #define f_string_ascii_comma "," + #define f_string_ascii_colon ":" + #define f_string_ascii_colon_semi ";" + #define f_string_ascii_dollar "$" + #define f_string_ascii_equal "=" + #define f_string_ascii_exclamation "!" + #define f_string_ascii_grave "`" + #define f_string_ascii_mark_question "?" + #define f_string_ascii_minus "-" + #define f_string_ascii_parenthesis_open "(" + #define f_string_ascii_parenthesis_close ")" + #define f_string_ascii_percent "%" + #define f_string_ascii_period "." + #define f_string_ascii_pipe "|" + #define f_string_ascii_plus "+" + #define f_string_ascii_pound "#" + #define f_string_ascii_quote_double "\"" + #define f_string_ascii_quote_single "'" + #define f_string_ascii_sign_at "@" + #define f_string_ascii_sign_greater_than ">" + #define f_string_ascii_sign_less_than "<" + #define f_string_ascii_slash_forward "/" + #define f_string_ascii_slash_backward "\\" + #define f_string_ascii_tilde "~" + #define f_string_ascii_underscore "_" + + #define f_string_ascii_acknowledge "" + #define f_string_ascii_acknowledge_negative "" + #define f_string_ascii_bell "" + #define f_string_ascii_cancel "" + #define f_string_ascii_data_link_escape "" + #define f_string_ascii_device_control_one "" + #define f_string_ascii_device_control_two "" + #define f_string_ascii_device_control_three "" + #define f_string_ascii_device_control_four "" + #define f_string_ascii_enquiry "" + #define f_string_ascii_escape "" + #define f_string_ascii_feed_form "\f" + #define f_string_ascii_feed_line "\n" + #define f_string_ascii_header_start "" + #define f_string_ascii_medium_stop "" + #define f_string_ascii_null "\0" + #define f_string_ascii_return_carriage "\r" + #define f_string_ascii_separator_file "" + #define f_string_ascii_separator_group "" + #define f_string_ascii_separator_record "" + #define f_string_ascii_separator_unit "" + #define f_string_ascii_shift_in "" + #define f_string_ascii_shift_out "" + #define f_string_ascii_space " " + #define f_string_ascii_space_back "" + #define f_string_ascii_substitute "" + #define f_string_ascii_synchronous_idle "" + #define f_string_ascii_tab_horizontal "\t" + #define f_string_ascii_tab_vertical "\v" + #define f_string_ascii_text_start "" + #define f_string_ascii_text_stop "" + #define f_string_ascii_transmission_stop "" + #define f_string_ascii_transmission_block_end "" extern const f_string_t f_string_ascii_0_s; extern const f_string_t f_string_ascii_1_s; @@ -284,16 +337,72 @@ extern "C" { extern const f_string_t f_string_ascii_Y_s; extern const f_string_t f_string_ascii_Z_s; + extern const f_string_t f_string_ascii_ampersand_s; + extern const f_string_t f_string_ascii_asterisk_s; + extern const f_string_t f_string_ascii_brace_close_s; + extern const f_string_t f_string_ascii_brace_open_s; + extern const f_string_t f_string_ascii_bracket_close_s; + extern const f_string_t f_string_ascii_bracket_open_s; + extern const f_string_t f_string_ascii_caret_s; extern const f_string_t f_string_ascii_comma_s; extern const f_string_t f_string_ascii_colon_s; extern const f_string_t f_string_ascii_colon_semi_s; + extern const f_string_t f_string_ascii_dollar_s; extern const f_string_t f_string_ascii_equal_s; + extern const f_string_t f_string_ascii_exclamation_s; + extern const f_string_t f_string_ascii_grave_s; + extern const f_string_t f_string_ascii_mark_question_s; extern const f_string_t f_string_ascii_minus_s; + extern const f_string_t f_string_ascii_parenthesis_open_s; + extern const f_string_t f_string_ascii_parenthesis_close_s; + extern const f_string_t f_string_ascii_percent_s; extern const f_string_t f_string_ascii_period_s; + extern const f_string_t f_string_ascii_pipe_s; extern const f_string_t f_string_ascii_plus_s; + extern const f_string_t f_string_ascii_pound_s; + extern const f_string_t f_string_ascii_quote_double_s; + extern const f_string_t f_string_ascii_quote_single_s; + extern const f_string_t f_string_ascii_sign_at_s; + extern const f_string_t f_string_ascii_sign_greater_than_s; + extern const f_string_t f_string_ascii_sign_less_than_s; extern const f_string_t f_string_ascii_slash_forward_s; extern const f_string_t f_string_ascii_slash_backward_s; extern const f_string_t f_string_ascii_tilde_s; + extern const f_string_t f_string_ascii_underscore_s; + + extern const f_string_t f_string_ascii_acknowledge_s; + extern const f_string_t f_string_ascii_acknowledge_negative_s; + extern const f_string_t f_string_ascii_bell_s; + extern const f_string_t f_string_ascii_cancel_s; + extern const f_string_t f_string_ascii_data_link_escape_s; + extern const f_string_t f_string_ascii_device_control_one_s; + extern const f_string_t f_string_ascii_device_control_two_s; + extern const f_string_t f_string_ascii_device_control_three_s; + extern const f_string_t f_string_ascii_device_control_four_s; + extern const f_string_t f_string_ascii_enquiry_s; + extern const f_string_t f_string_ascii_escape_s; + extern const f_string_t f_string_ascii_feed_form_s; + extern const f_string_t f_string_ascii_feed_line_s; + extern const f_string_t f_string_ascii_header_start_s; + extern const f_string_t f_string_ascii_medium_stop_s; + extern const f_string_t f_string_ascii_null_s; + extern const f_string_t f_string_ascii_return_carriage_s; + extern const f_string_t f_string_ascii_separator_file_s; + extern const f_string_t f_string_ascii_separator_group_s; + extern const f_string_t f_string_ascii_separator_record_s; + extern const f_string_t f_string_ascii_separator_unit_s; + extern const f_string_t f_string_ascii_shift_in_s; + extern const f_string_t f_string_ascii_shift_out_s; + extern const f_string_t f_string_ascii_space_s; + extern const f_string_t f_string_ascii_space_back_s; + extern const f_string_t f_string_ascii_substitute_s; + extern const f_string_t f_string_ascii_synchronous_idle_s; + extern const f_string_t f_string_ascii_tab_horizontal_s; + extern const f_string_t f_string_ascii_tab_vertical_s; + extern const f_string_t f_string_ascii_text_start_s; + extern const f_string_t f_string_ascii_text_stop_s; + extern const f_string_t f_string_ascii_transmission_stop_s; + extern const f_string_t f_string_ascii_transmission_block_end_s; #endif // _di_string_ascii_s_ #ifdef __cplusplus diff --git a/level_1/fl_fss/c/fss_status.h b/level_1/fl_fss/c/fss_status.h index dc0053a..9d64870 100644 --- a/level_1/fl_fss/c/fss_status.h +++ b/level_1/fl_fss/c/fss_status.h @@ -31,8 +31,6 @@ enum { #ifndef _di_FL_fss_status_warning_ FL_fss_accepted_invalid, FL_fss_accepted_invalid_eos, - FL_fss_header_not, - FL_fss_header_not_eos, #endif // _di_FL_fss_status_warning_ #ifndef _di_FL_fss_status_success_ diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index b1a8263..dfbd933 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -547,9 +547,9 @@ extern "C" { #endif // _di_fl_string_dynamic_seek_to_utf_character_ #ifndef _di_fl_string_fll_identify_ - f_status_t fl_string_fll_identify(const f_string_t buffer, const f_array_length_t length, f_fll_id_t *id) { + f_status_t fl_string_fll_identify(const f_string_t buffer, f_string_range_t *range, f_fll_id_t *id) { #ifndef _di_level_1_parameter_checking_ - if (!length) return F_status_set_error(F_parameter); + if (!range) return F_status_set_error(F_parameter); #endif // _di_level_1_parameter_checking_ if (id) { @@ -557,18 +557,38 @@ extern "C" { id->used = 0; } - // The FLL identifier is always at least 6 characters ("X-0000"). - if (length < 6) { - return F_false; + // skip past all leading NULLs. + for (; range->start <= range->stop; ++range->start) { + if (buffer[range->start]) break; + } + + if (range->start > range->stop) { + return F_data_not; + } + + // The FLL Identifier is always at least 6 characters ("X-0000"). + if (range->stop - range->start < 5) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + + return F_found_not; } f_status_t status = F_none; - f_array_length_t i = 0; - f_array_length_t remaining = length; - for (; i < length; ) { + for (; range->start <= range->stop; ) { - status = f_utf_is_whitespace(buffer + i, remaining); + status = f_utf_is_whitespace(buffer + range->start, (range->stop - range->start) + 1); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_maybe) { @@ -579,96 +599,173 @@ extern "C" { } if (status == F_false) { - if (buffer[i] == 0) { - ++i; - --remaining; + if (!buffer[range->start]) { + ++range->start; + continue; } break; } - i += macro_f_utf_byte_width(buffer[i]); - remaining -= macro_f_utf_byte_width(buffer[i]); + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + return F_found_not; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); } // for - if (remaining < 6) { - return F_false; + if (range->start > range->stop) { + return F_found_not; + } + + if (range->stop - range->start < 5) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + + return F_found_not; } - f_array_length_t j = i; + f_array_length_t i = range->start; - for (; i < length; ) { + for (; range->start <= range->stop; ) { - status = f_utf_is_word(buffer + i, remaining, F_true); + status = f_utf_is_word(buffer + range->start, (range->stop - range->start) + 1, F_true); if (F_status_is_error(status)) return status; if (status == F_false) { - if (buffer[i] == 0) { - ++i; - --remaining; + if (!buffer[range->start]) { + ++range->start; + continue; } break; } - i += macro_f_utf_byte_width(buffer[i]); - remaining -= macro_f_utf_byte_width(buffer[i]); + range->start += macro_f_utf_byte_width(buffer[range->start]); } // for - if (i > length || buffer[i] != f_string_ascii_minus[0]) { - return F_false; + if (range->start > range->stop || buffer[range->start] != f_string_ascii_minus[0]) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + + return F_found_not; } { - f_array_length_t k = 0; + f_array_length_t j = 0; - for (; i < length && k < 5; ++i, --remaining, ++k) { + for (; range->start <= range->stop && j < 5; ++range->start, ++j) { // The hexidecimal representing the number may only be ASCII. - if (macro_f_utf_byte_width_is(buffer[i])) { + if (macro_f_utf_byte_width_is(buffer[range->start])) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + if (id) { id->type = 0; } - return F_false; + return F_found_not; } - if (isxdigit(buffer[i])) { + if (isxdigit(buffer[range->start])) { if (id) { - if (k) { + if (j) { id->type *= 16; - id->type += strtol(buffer + i, 0, 16); + id->type += strtol(buffer + range->start, 0, 16); } else { - id->type = strtol(buffer + i, 0, 16); + id->type = strtol(buffer + range->start, 0, 16); } } } else { - if (buffer[i] == 0) continue; + if (!buffer[range->start]) continue; + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for if (id) { id->type = 0; } - return F_false; + return F_found_not; } } // for - if (i > length || k > 4) { + if (j != 5) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + if (id) { id->type = 0; } - return F_false; + return F_found_not; } } - // The end of line, string, or end of length are the only valid stop points. - if (i < length && buffer[i] != f_string_eol_s[0]) { - status = f_utf_is_whitespace(buffer + i, remaining); + // skip past all NULLs. + for (; range->start <= range->stop; ++range->start) { + if (buffer[range->start]) break; + } + + // The end of line, whitespace, or range stop point are the only valid stop points. + if (range->start <= range->stop) { + status = f_utf_is_whitespace(buffer + range->start, (range->stop - range->start) + 1); if (F_status_is_error(status)) { if (id) { @@ -678,33 +775,50 @@ extern "C" { return status; } - if (status == F_false) { + if (status == F_true) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + if (id) { id->type = 0; } - return F_none; + return F_found_not; } } + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + } + if (id) { - for (i = j, j = 0; i < length; ++i) { + for (f_array_length_t j = i, i = 0; j <= range->stop; ++j) { - if (buffer[i] == 0) continue; - if (buffer[i] == f_string_ascii_minus[0]) break; + if (!buffer[j]) continue; + if (buffer[j] == f_string_ascii_minus[0]) break; - id->name[j] = buffer[i]; - ++j; + id->name[i] = buffer[j]; + ++i; } // for - if (j < 64) { - id->name[j] = 0; + if (i < 64) { + id->name[i] = 0; } - id->used = j; + id->used = i; } - return F_true; + return F_found; } #endif // _di_fl_string_fll_identify_ diff --git a/level_1/fl_string/c/string.h b/level_1/fl_string/c/string.h index 71ecad7..3c165ff 100644 --- a/level_1/fl_string/c/string.h +++ b/level_1/fl_string/c/string.h @@ -924,24 +924,34 @@ extern "C" { * This will always change the FLL Identifier used and type codes, if a FLL Identifier is provided. * * Whitespace may be before and after the FLL Identifier and will be ignored. + * NULLs will be ignored. * Anything else will result in treating the character as a possible FLL Identifier. * * A valid FLL Identifier must terminate on either whitespace, EOL, or the stop point (length). * - * The id.name may not be NULL terminated and this function will skip over NULLs in the buffer when processing. + * The id.name might not be NULL terminated. + * An id.name using all 64-bytes will not be NULL terminated. + * + * If a newline ("\n") is encountered, range->start will be set to 1 byte after the newline. * * @param buffer * The string to process. - * @param length - * The number of bytes within the buffer to process. - * Must be greater than 0. + * @param range + * A range within the buffer representing the start and stop locations. + * The caller must ensure that the stop point does not exceed the buffer size. + * + * The range->start will be updated by this function. + * On error, the range->start may represent the last position looked at. + * On success, the range->start should be after the last valid position (for example for "fss-1234", the ast valid position would be the byte after the "4"). + * Be aware that if a UTF-8 character exists at the end of the string but extends beyond the range stop, the stop position may be after the UTF-8 byte and not 1 byte after the stop point. * @param id * (optional) The FLL Identifier found. * Set to NULL to not use. * * @return - * F_false if the buffer does not represent a valid FLL Identifier. - * F_true if the buffer does represent a valid FLL Identifier. + * F_data_not if length is 0. + * F_found if the buffer does represent a valid FLL Identifier. + * F_found_not if the buffer does not represent a valid FLL Identifier. * * F_complete_not_utf (with error bit) if a character is an incomplete UTF-8 fragment. * F_maybe (with error bit) if a character could be a whitespace but width is not long enough. (This is only returned for an otherwise valid FLL Identifier.) @@ -957,7 +967,7 @@ extern "C" { * @see f_utf_is_word() */ #ifndef _di_fl_string_fll_identify_ - extern f_status_t fl_string_fll_identify(const f_string_t buffer, const f_array_length_t length, f_fll_id_t *id); + extern f_status_t fl_string_fll_identify(const f_string_t buffer, f_string_range_t *range, f_fll_id_t *id); #endif // _di_fl_string_fll_identify_ /** diff --git a/level_2/fll_fss/c/fss.c b/level_2/fll_fss/c/fss.c index 78e961b..1f51a13 100644 --- a/level_2/fll_fss/c/fss.c +++ b/level_2/fll_fss/c/fss.c @@ -6,45 +6,179 @@ extern "C" { #endif #ifndef _di_fll_fss_identify_ - f_status_t fll_fss_identify(const f_string_static_t buffer, f_fss_header_t *header) { + f_status_t fll_fss_identify(const f_string_t buffer, f_string_range_t *range, f_fll_ids_t *ids) { #ifndef _di_level_2_parameter_checking_ - if (!header) return F_status_set_error(F_parameter); - if (!buffer.used) return F_status_set_error(F_parameter); + if (!range) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ - return private_fll_fss_identify(buffer, header); - } -#endif // _di_fll_fss_identify_ + // skip past all NULLs. + for (; range->start <= range->stop; ++range->start) { + if (buffer[range->start]) break; + } -#ifndef _di_fll_fss_identify_file_ - f_status_t fll_fss_identify_file(f_file_t *file, f_fss_header_t *header) { - #ifndef _di_level_2_parameter_checking_ - if (!file) return F_status_set_error(F_parameter); - if (!header) return F_status_set_error(F_parameter); - if (!file->id) return F_status_set_error(F_file_closed); - if (file->id < 0) return F_status_set_error(F_file); - #endif // _di_level_2_parameter_checking_ + if (range->start > range->stop) { + return F_data_not; + } + + // The first character must be a '#'. + if (buffer[range->start] != f_fss_pound_s[0]) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } - { - f_array_length_t seeked = 0; + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for - if (F_status_is_error(f_file_seek(file->id, SEEK_SET, 0, &seeked))) { - return F_status_set_error(F_file_seek); + if (ids) { + ids->used = 0; } + + return F_found_not; } - f_status_t status = F_none; - f_string_dynamic_t buffer = f_string_dynamic_t_initialize; + // skip past all NULLs after the '#'. + for (++range->start; range->start <= range->stop; ++range->start) { + if (buffer[range->start]) break; + } + + if (range->start > range->stop) { + if (ids) { + ids->used = 0; + } + + return F_found_not; + } + + // The minimum requirement for a valid FLL/FSS Identifier for the entire line is 7 characters after the '#' ("# X-FFFF"). + if (range->stop - range->start < 6) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } + + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + + if (ids) { + ids->used = 0; + } + + return F_found_not; + } + + f_status_t status = f_utf_is_whitespace(buffer + range->start, (range->stop - range->start) + 1); + + if (F_status_is_error(status)) { + if (F_status_set_fine(status) == F_maybe) { + return F_status_set_error(F_complete_not_utf); + } + + return status; + } + + if (status == F_false) { + + // Increment until stop, while taking into consideration UTF-8 character widths. + for (; range->start <= range->stop; ) { + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + break; + } - macro_f_string_dynamic_t_resize(status, buffer, f_fss_max_header_length + 1); - if (F_status_is_error(status)) return status; + range->start += macro_f_utf_byte_width(buffer[range->start]); + } // for + + return F_found_not; + } + + if (buffer[range->start] == f_string_eol_s[0]) { + ++range->start; + + if (ids) { + ids->used = 0; + } + + return F_found_not; + } + + // in order to determine if a valid FLL Identifier represents a valid FSS identifier, the data must be saved. + f_fll_id_t id = f_fll_id_t_initialize; + bool found_fss = F_false; + + do { + + status = fl_string_fll_identify(buffer, range, ids ? &ids->array[ids->used] : &id); + + if (F_status_is_error(status) || status == F_found_not) { + if (ids) { + ids->used = 0; + } + + return status; + } + + if (!found_fss) { + if (ids) { + if (ids->array[ids->used].used == 3 && ids->array[ids->used].name[0] == f_fss_f_s[0] && ids->array[ids->used].name[0] == f_fss_s_s[0] && ids->array[ids->used].name[0] == f_fss_s_s[0]) { + found_fss = F_true; + } + } + else { + if (id.used == 3 && id.name[0] == f_fss_f_s[0] && id.name[0] == f_fss_s_s[0] && id.name[0] == f_fss_s_s[0]) { + found_fss = F_true; + } + } + } + + if (ids) { + status = f_type_fll_ids_increase(f_fss_default_allocation_step_small, ids); + + if (F_status_is_error(status)) { + if (ids) { + ids->used = 0; + } + + return status; + } + + ++ids->used; + } + + } while (range->start <= range->stop); + + if (ids) { + if (ids->used) { + if (found_fss) { + return F_found; + } + + return F_maybe; + } + } + else if (id.used) { + if (found_fss) { + return F_found; + } - status = f_file_read_until(*file, f_fss_max_header_length + 1, &buffer); - if (F_status_is_error(status)) return status; + return F_maybe; + } - return private_fll_fss_identify(buffer, header); + return F_found_not; } -#endif // _di_fll_fss_identify_file_ +#endif // _di_fll_fss_identify_ #ifndef _di_fll_fss_snatch_ f_status_t fll_fss_snatch(const f_string_static_t buffer, const f_fss_objects_t objects, const f_fss_contents_t contents, const f_string_t names[], const f_array_length_t lengths[], const f_array_length_t size, f_string_dynamic_t *values[], f_array_length_t *indexs[]) { @@ -331,11 +465,11 @@ extern "C" { if (F_status_is_error(status)) return status; if (status == F_equal_to_not) continue; - status = f_string_map_multis_increase(f_memory_default_allocation_small, values[j]); + status = f_string_map_multis_increase(f_fss_default_allocation_step_small, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_increase(status, f_memory_default_allocation_small, (*indexs[j])); + macro_f_array_lengths_t_increase(status, f_fss_default_allocation_step_small, (*indexs[j])); if (F_status_is_error(status)) return status; } @@ -403,11 +537,11 @@ extern "C" { if (F_status_is_error(status)) return status; if (status == F_equal_to_not) continue; - status = f_string_maps_increase(f_memory_default_allocation_small, values[j]); + status = f_string_maps_increase(f_fss_default_allocation_step_small, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_increase(status, f_memory_default_allocation_small, (*indexs[j])); + macro_f_array_lengths_t_increase(status, f_fss_default_allocation_step_small, (*indexs[j])); if (F_status_is_error(status)) return status; } @@ -505,11 +639,11 @@ extern "C" { map_multi = &values[j]->array[k]; } else { - status = f_string_map_multis_increase(f_memory_default_allocation_small, values[j]); + status = f_string_map_multis_increase(f_fss_default_allocation_step_small, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_increase(status, f_memory_default_allocation_small, (*indexs[j])); + macro_f_array_lengths_t_increase(status, f_fss_default_allocation_step_small, (*indexs[j])); if (F_status_is_error(status)) return status; } @@ -530,7 +664,7 @@ extern "C" { if (contents.array[i].used == 1) continue; } - status = f_string_dynamics_increase(f_memory_default_allocation_small, &map_multi->value); + status = f_string_dynamics_increase(f_fss_default_allocation_step_small, &map_multi->value); if (F_status_is_error(status)) return status; for (k = 1; k < contents.array[i].used; k++) { @@ -617,11 +751,11 @@ extern "C" { map = &values[j]->array[k]; } else { - status = f_string_maps_increase(f_memory_default_allocation_small, values[j]); + status = f_string_maps_increase(f_fss_default_allocation_step_small, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_increase(status, f_memory_default_allocation_small, (*indexs[j])); + macro_f_array_lengths_t_increase(status, f_fss_default_allocation_step_small, (*indexs[j])); if (F_status_is_error(status)) return status; } @@ -740,11 +874,11 @@ extern "C" { if (F_status_is_error(status)) return status; if (status == F_equal_to_not) continue; - status = f_string_dynamics_increase(f_memory_default_allocation_small, values[j]); + status = f_string_dynamics_increase(f_fss_default_allocation_step_small, values[j]); if (F_status_is_error(status)) return status; if (indexs) { - macro_f_array_lengths_t_increase(status, f_memory_default_allocation_small, (*indexs[j])); + macro_f_array_lengths_t_increase(status, f_fss_default_allocation_step_small, (*indexs[j])); if (F_status_is_error(status)) return status; } diff --git a/level_2/fll_fss/c/fss.h b/level_2/fll_fss/c/fss.h index 2e83f1b..f4667b9 100644 --- a/level_2/fll_fss/c/fss.h +++ b/level_2/fll_fss/c/fss.h @@ -33,52 +33,50 @@ extern "C" { /** * Identify FSS type from a buffered string. * - * @param buffer - * The string to process. - * @param header - * The header data to populate with results of this function. + * The operates on the assumption that the first character provided is the start of the line. + * This will process until the stop point or the end of the line. + * This stop point should always be after the end of the line, except when there is an error. * - * @return - * F_none on success - * FL_fss_header_not if no header is found. + * This expects there to be at least a single "fss-XXXX" FSS Identifier. + * If one is not found but the line contains valid FLL Identifiers, then this returns F_maybe. * - * FL_fss_accepted_invalid (with warning bit) if header is technically invalid but can be identified. + * See the fl_string_fll_identify() function for details on individual FLL/FSS Identifier processing. * - * FL_fss_header_not (with error bit) if the an error occurred prior to identifying a valid header. + * @param buffer + * The string to process. + * @param range + * A range within the buffer representing the start and stop locations. + * The caller must ensure that the stop point does not exceed the buffer size. * - * Errors (with error bit) from: fl_conversion_string_to_hexidecimal_unsigned(). - */ -#ifndef _di_fll_fss_identify_ - extern f_status_t fll_fss_identify(const f_string_static_t buffer, f_fss_header_t *header); -#endif // _di_fll_fss_identify_ - -/** - * Identify FSS type from a file. + * The range->start may be updated by this function. + * On failure, the range->start may represent the last position looked at. + * On success, the range->start should be after the last valid position (for example for "# fss-1234 fss-4321\n", the ast valid position would be the byte after the "\n"). + * @param ids + * (optional) The FLL Identifiers to populate with results of this function. + * Set to NULL to not use. * - * @param file - * The file information. - * @param header - * The header data to populate with results of this function. + * When non-NULL, this will have its length reset to 0. + * FLL/FSS Identifiers will then be appended to this array. * * @return - * F_none on success. - * FL_fss_header_not if no header is found. + * F_data_not if length is 0. + * F_found if the buffer does represent a valid FSS Identifier. + * F_found_not if the buffer does not represent a valid FSS Identifier. + * F_maybe if the buffer is a valid FLL Identifier but does not have an FSS Identifier ("fss-XXXX"). * - * FL_fss_accepted_invalid (with warning bit) if header is technically invalid but can be identified. + * F_complete_not_utf (with error bit) if character is an incomplete UTF-8 fragment. * - * F_memory_not (with error bit) on out of memory. - * F_parameter (with error bit) if a parameter is invalid. - * FL_fss_header_not (with error bit) if the an error occurred prior to identifying a valid header. + * Errors (with error bit) from: f_type_fll_ids_increase(). + * Errors (with error bit) from: f_utf_is_whitespace(). + * Errors (with error bit) from: fl_string_fll_identify(). * - * Errors (with error bit) from: fl_conversion_string_to_hexidecimal_unsigned(). - * Errors (with error bit) from: f_file_read_until(). - * Errors (with error bit) from: f_file_seek(). - * - * @see f_file_read_until() + * @see f_type_fll_ids_increase() + * @see f_utf_is_whitespace() + * @see fl_string_fll_identify() */ -#ifndef _di_fll_fss_identify_file_ - extern f_status_t fll_fss_identify_file(f_file_t *file, f_fss_header_t *header); -#endif // _di_fll_fss_identify_file_ +#ifndef _di_fll_fss_identify_ + extern f_status_t fll_fss_identify(const f_string_t buffer, f_string_range_t *range, f_fll_ids_t *ids); +#endif // _di_fll_fss_identify_ /** * Perform simple search through all objects against the given set, saving all values when matched. diff --git a/level_2/fll_fss/c/fss_basic.c b/level_2/fll_fss/c/fss_basic.c index ef4dfde..fbf8079 100644 --- a/level_2/fll_fss/c/fss_basic.c +++ b/level_2/fll_fss/c/fss_basic.c @@ -23,14 +23,14 @@ extern "C" { do { if (objects->used == objects->size) { - macro_f_fss_objects_t_increase(status2, f_memory_default_allocation_small, (*objects)) + macro_f_fss_objects_t_increase(status2, f_fss_default_allocation_step_small, (*objects)) if (F_status_is_error(status2)) return status2; - macro_f_fss_contents_t_increase(status2, f_memory_default_allocation_small, (*contents)) + macro_f_fss_contents_t_increase(status2, f_fss_default_allocation_step_small, (*contents)) if (F_status_is_error(status2)) return status2; if (objects_quoted) { - macro_f_fss_quotes_t_increase(status2, f_memory_default_allocation_small, (*objects_quoted)) + macro_f_fss_quotes_t_increase(status2, f_fss_default_allocation_step_small, (*objects_quoted)) if (F_status_is_error(status2)) return status2; } } @@ -51,7 +51,7 @@ extern "C" { objects_quoted->used++; } - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; contents->used++; @@ -86,7 +86,7 @@ extern "C" { else if (status == FL_fss_found_object_content_not) { found_data = F_true; - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; break; @@ -177,7 +177,7 @@ extern "C" { if (F_status_is_error(status)) return status; } else { - status = f_string_dynamic_increase(f_memory_default_allocation_small, destination); + status = f_string_dynamic_increase(f_fss_default_allocation_step_small, destination); if (F_status_is_error(status)) return status; destination->string[destination->used++] = f_string_eol_s[0]; diff --git a/level_2/fll_fss/c/fss_basic_list.c b/level_2/fll_fss/c/fss_basic_list.c index aeb4595..eac9b57 100644 --- a/level_2/fll_fss/c/fss_basic_list.c +++ b/level_2/fll_fss/c/fss_basic_list.c @@ -36,7 +36,7 @@ extern "C" { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { objects->used++; - macro_f_fss_delimits_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; contents->used++; @@ -71,7 +71,7 @@ extern "C" { else if (status == FL_fss_found_object_content_not) { found_data = F_true; - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; break; diff --git a/level_2/fll_fss/c/fss_extended.c b/level_2/fll_fss/c/fss_extended.c index fd20be5..9e9bd96 100644 --- a/level_2/fll_fss/c/fss_extended.c +++ b/level_2/fll_fss/c/fss_extended.c @@ -24,19 +24,19 @@ extern "C" { do { if (objects->used == objects->size) { - macro_f_fss_objects_t_increase(status2, f_memory_default_allocation_small, (*objects)); + macro_f_fss_objects_t_increase(status2, f_fss_default_allocation_step_small, (*objects)); if (F_status_is_error(status2)) return status2; - macro_f_fss_contents_t_increase(status2, f_memory_default_allocation_small, (*contents)); + macro_f_fss_contents_t_increase(status2, f_fss_default_allocation_step_small, (*contents)); if (F_status_is_error(status2)) return status2; if (objects_quoted) { - macro_f_fss_quotes_t_increase(status2, f_memory_default_allocation_small, (*objects_quoted)); + macro_f_fss_quotes_t_increase(status2, f_fss_default_allocation_step_small, (*objects_quoted)); if (F_status_is_error(status2)) return status2; } if (contents_quoted) { - macro_f_fss_quotess_t_increase(status2, f_memory_default_allocation_small, (*contents_quoted)); + macro_f_fss_quotess_t_increase(status2, f_fss_default_allocation_step_small, (*contents_quoted)); if (F_status_is_error(status2)) return status2; } } @@ -57,13 +57,13 @@ extern "C" { objects_quoted->used++; } - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; contents->used++; if (contents_quoted) { - macro_f_fss_quotes_t_increase(status2, f_memory_default_allocation_small, contents_quoted->array[contents_quoted->used]) + macro_f_fss_quotes_t_increase(status2, f_fss_default_allocation_step_small, contents_quoted->array[contents_quoted->used]) if (F_status_is_error(status2)) return status2; contents_quoted->used++; @@ -91,7 +91,7 @@ extern "C" { found_data = F_true; if (contents_quoted) { - macro_f_fss_quotes_t_increase(status2, f_memory_default_allocation_small, contents_quoted->array[contents_quoted->used]) + macro_f_fss_quotes_t_increase(status2, f_fss_default_allocation_step_small, contents_quoted->array[contents_quoted->used]) if (F_status_is_error(status2)) return status2; quoted_content = &contents_quoted->array[contents_quoted->used]; diff --git a/level_2/fll_fss/c/fss_extended_list.c b/level_2/fll_fss/c/fss_extended_list.c index 816ae78..5769800 100644 --- a/level_2/fll_fss/c/fss_extended_list.c +++ b/level_2/fll_fss/c/fss_extended_list.c @@ -36,7 +36,7 @@ extern "C" { if (status == FL_fss_found_object || status == FL_fss_found_object_content_not) { objects->used++; - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; contents->used++; @@ -71,7 +71,7 @@ extern "C" { else if (status == FL_fss_found_object_content_not) { found_data = F_true; - macro_f_fss_content_t_increase(status2, f_memory_default_allocation_small, contents->array[contents->used]) + macro_f_fss_content_t_increase(status2, f_fss_default_allocation_step_small, contents->array[contents->used]) if (F_status_is_error(status2)) return status2; break; diff --git a/level_2/fll_fss/c/fss_status.c b/level_2/fll_fss/c/fss_status.c index f67771c..81b7a11 100644 --- a/level_2/fll_fss/c/fss_status.c +++ b/level_2/fll_fss/c/fss_status.c @@ -43,24 +43,12 @@ extern "C" { #endif // _di_fll_fss_status_error_ #ifndef _di_fll_fss_status_warning_ - if (fl_string_compare(string, fll_fss_status_string_header_not, length, fll_fss_status_string_header_not_length) == F_equal_to) { - *code = FL_fss_header_not; - - return F_none; - } - if (fl_string_compare(string, fll_fss_status_string_accepted_invalid, length, fll_fss_status_string_accepted_invalid_length) == F_equal_to) { *code = FL_fss_accepted_invalid; return F_none; } - if (fl_string_compare(string, fll_fss_status_string_header_not_eos, length, fll_fss_status_string_header_not_eos_length) == F_equal_to) { - *code = FL_fss_header_not_eos; - - return F_none; - } - if (fl_string_compare(string, fll_fss_status_string_accepted_invalid_eos, length, fll_fss_status_string_accepted_invalid_eos_length) == F_equal_to) { *code = FL_fss_accepted_invalid_eos; @@ -143,15 +131,9 @@ extern "C" { #endif // _di_fll_fss_status_error_ #ifndef _di_fll_fss_status_warning_ - case FL_fss_header_not: - *string = fll_fss_status_string_header_not; - break; case FL_fss_accepted_invalid: *string = fll_fss_status_string_accepted_invalid; break; - case FL_fss_header_not_eos: - *string = fll_fss_status_string_header_not_eos; - break; case FL_fss_accepted_invalid_eos: *string = fll_fss_status_string_accepted_invalid_eos; break; diff --git a/level_2/fll_fss/c/fss_status.h b/level_2/fll_fss/c/fss_status.h index 2c0aced..c2becf3 100644 --- a/level_2/fll_fss/c/fss_status.h +++ b/level_2/fll_fss/c/fss_status.h @@ -39,15 +39,9 @@ extern "C" { #endif // _di_fll_fss_status_error_ #ifndef _di_fll_fss_status_warning_ - #define fll_fss_status_string_header_not "FL_fss_header_not" - #define fll_fss_status_string_header_not_length 17 - #define fll_fss_status_string_accepted_invalid "FL_fss_accepted_invalid" #define fll_fss_status_string_accepted_invalid_length 23 - #define fll_fss_status_string_header_not_eos "FL_fss_header_not_eos" - #define fll_fss_status_string_header_not_eos_length 21 - #define fll_fss_status_string_accepted_invalid_eos "FL_fss_accepted_invalid_eos" #define fll_fss_status_string_accepted_invalid_eos_length 27 #endif // _di_fll_fss_status_warning_ diff --git a/level_2/fll_fss/c/private-fss.c b/level_2/fll_fss/c/private-fss.c index 9ecf4b7..be126fd 100644 --- a/level_2/fll_fss/c/private-fss.c +++ b/level_2/fll_fss/c/private-fss.c @@ -5,137 +5,6 @@ extern "C" { #endif -#if !defined(_di_fll_fss_identify_) || !defined(_di_fll_fss_identify_file_) - f_status_t private_fll_fss_identify(const f_string_static_t buffer, f_fss_header_t *header) { - - register f_array_length_t i = 0; - - if (buffer.used < 10) { - - // "# fss-0000" is always at least 10 characters. - return FL_fss_header_not; - } - - // If this correctly follows the FSS specification, then this should be all that needs to be done (as well as atoh for ascii to hex). - // All characters used in the identifier are only in the ascii equivalents of the characters, any similarly looking character or number representing in UTF-8 is considered invalid. - if (buffer.string[i] == f_fss_type_header_open) { - i++; - - if (buffer.string[i] == f_fss_type_header_part1) { - i++; - - if (buffer.string[i] == f_fss_type_header_part2) { - i++; - - if (buffer.string[i] == f_fss_type_header_part3) { - i++; - - if (buffer.string[i] == f_fss_type_header_part4) { - i++; - - if (buffer.string[i] == f_fss_type_header_part5) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - f_string_range_t range = f_string_range_t_initialize; - - range.start = i - 4; - range.stop = i; - - // 1: A possibly valid header type was found, now convert it into its proper format and save the header type. - const f_status_t status = fl_conversion_string_to_hexidecimal_unsigned(buffer.string, range, &header->type); - if (F_status_is_error(status)) return status; - - if (status == F_none) { - // 2: At this point, we can still know the proper format for the file and still have a invalid header, handle accordingly. - if (buffer.string[i] == f_fss_type_header_close) { - header->length = i + 1; - - return F_none; - } - else { - // @todo this needs to be changed to support sub-headers (maybe something like FL_fss_accepted_additional). - // 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_set_warning(FL_fss_accepted_invalid); - } - } - } - } - } - } - } - } - } - } - } - // people can miss spaces, so lets accept in an attempt to interpret the file anyway, but return values at this point are to be flagged as invalid. - else if (buffer.string[i] == f_fss_type_header_part2) { - i++; - - if (buffer.string[i] == f_fss_type_header_part3) { - i++; - - if (buffer.string[i] == f_fss_type_header_part4) { - i++; - - if (buffer.string[i] == f_fss_type_header_part5) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - i++; - - if (f_conversion_character_is_hexidecimal(buffer.string[i]) == F_true) { - - // @todo this needs to be changed to support sub-headers (maybe something like FL_fss_accepted_additional). - i++; - - f_string_range_t range = f_string_range_t_initialize; - - range.start = i - 4; - range.stop = i; - - const f_status_t status = fl_conversion_string_to_hexidecimal_unsigned(buffer.string, range, &header->type); - if (F_status_is_error(status)) return status; - - header->length = i + 1; - - return F_status_set_warning(FL_fss_accepted_invalid); - } - } - } - } - } - } - } - } - } - - // @todo At some point add checksum and compressions checks here, but the above statements will have to be adjusted accordingly. - // 3: eventually this will be processing the checksum and 4: will be processing the compression. - - return FL_fss_header_not; - } -#endif // !defined(_di_fll_fss_identify_) || !defined(_di_fll_fss_identify_file_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_2/fll_fss/c/private-fss.h b/level_2/fll_fss/c/private-fss.h index a85921c..b311bfe 100644 --- a/level_2/fll_fss/c/private-fss.h +++ b/level_2/fll_fss/c/private-fss.h @@ -15,33 +15,6 @@ extern "C" { #endif -/** - * Private implementation of fll_fss_identify(). - * - * Intended to be shared to each of the different implementation variations. - * - * @param buffer - * The string to process. - * @param header - * The header data to populate with results of this function. - * - * @return - * F_none on success - * FL_fss_header_not if no header is found. - * - * FL_fss_accepted_invalid (with warning bit) if header is technically invalid but can be identified. - * - * FL_fss_header_not (with error bit) if the an error occurred prior to identifying a valid header. - * - * Errors (with error bit) from: fl_conversion_string_to_hexidecimal_unsigned(). - * - * @see fll_fss_identify() - * @see fll_fss_identify_file() - */ -#if !defined(_di_fll_fss_identify_) || !defined(_di_fll_fss_identify_file_) - extern f_status_t private_fll_fss_identify(const f_string_static_t buffer, f_fss_header_t *header) f_attribute_visibility_internal; -#endif // !defined(_di_fll_fss_identify_) || !defined(_di_fll_fss_identify_file_) - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index c0778ba..9af6a07 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -401,7 +401,7 @@ extern "C" { for (f_array_length_t i = 0; i < cache->content_action.used; ++i) { - status = f_string_dynamic_partial_mash_nulless(f_string_space_s, f_string_space_length, cache->buffer_item, cache->content_action.array[i], &actions->array[actions->used].parameters.array[0]); + status = f_string_dynamic_partial_mash_nulless(f_string_space_s, f_string_space_s_length, cache->buffer_item, cache->content_action.array[i], &actions->array[actions->used].parameters.array[0]); if (F_status_is_error(status)) break; } // for diff --git a/level_3/fss_basic_list_write/c/private-fss_basic_list_write.c b/level_3/fss_basic_list_write/c/private-fss_basic_list_write.c index 93e5cf8..14bd62f 100644 --- a/level_3/fss_basic_list_write/c/private-fss_basic_list_write.c +++ b/level_3/fss_basic_list_write/c/private-fss_basic_list_write.c @@ -109,7 +109,7 @@ extern "C" { } if (!object || !content) { - status = f_string_append(f_string_eol, 1, buffer); + status = f_string_append(f_string_eol_s, 1, buffer); if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); diff --git a/level_3/fss_basic_write/c/private-fss_basic_write.c b/level_3/fss_basic_write/c/private-fss_basic_write.c index 53ab66e..c5f0b4c 100644 --- a/level_3/fss_basic_write/c/private-fss_basic_write.c +++ b/level_3/fss_basic_write/c/private-fss_basic_write.c @@ -121,7 +121,7 @@ extern "C" { } if (!object || !content) { - status = f_string_append(f_string_eol, 1, buffer); + status = f_string_append(f_string_eol_s, 1, buffer); if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); diff --git a/level_3/fss_embedded_list_write/c/private-fss_embedded_list_write.c b/level_3/fss_embedded_list_write/c/private-fss_embedded_list_write.c index 88ea763..66bbca3 100644 --- a/level_3/fss_embedded_list_write/c/private-fss_embedded_list_write.c +++ b/level_3/fss_embedded_list_write/c/private-fss_embedded_list_write.c @@ -109,7 +109,7 @@ extern "C" { } if (!object || !content) { - status = f_string_append(f_string_eol, 1, buffer); + status = f_string_append(f_string_eol_s, 1, buffer); if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); diff --git a/level_3/fss_extended_list_write/c/private-fss_extended_list_write.c b/level_3/fss_extended_list_write/c/private-fss_extended_list_write.c index 460bef8..f09688b 100644 --- a/level_3/fss_extended_list_write/c/private-fss_extended_list_write.c +++ b/level_3/fss_extended_list_write/c/private-fss_extended_list_write.c @@ -109,7 +109,7 @@ extern "C" { } if (!object || !content) { - status = f_string_append(f_string_eol, 1, buffer); + status = f_string_append(f_string_eol_s, 1, buffer); if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); diff --git a/level_3/fss_extended_write/c/private-fss_extended_write.c b/level_3/fss_extended_write/c/private-fss_extended_write.c index e09251a..0dd2c6c 100644 --- a/level_3/fss_extended_write/c/private-fss_extended_write.c +++ b/level_3/fss_extended_write/c/private-fss_extended_write.c @@ -125,7 +125,7 @@ extern "C" { } } else if (!object) { - status = f_string_append(f_string_eol, 1, buffer); + status = f_string_append(f_string_eol_s, 1, buffer); if (F_status_is_error(status)) { fll_error_print(main.error, F_status_set_fine(status), "f_string_append", F_true); -- 1.8.3.1