From 2eacc1066664430eb7ffb4d8af460a697bf2605a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 17 Dec 2021 20:11:34 -0600 Subject: [PATCH] Update: IKI improvements, cleanups, and bugfixes. The IKI project has fallen behind in some of the practices and is more consistent. - Expose the delimit array to the caller rather than operating on it internally. - This makes IKI more consistent with FSS and improves extensibility. - Fix the global string names and macro need to follow the appropriate naming structure. - Use strings rather than characters in the defines. - Get rid of some macros, replacing them with functions. - Use the *_increase() and *_increase_by() functions. The FSS projects are now passing the delimit management to the callers. IKI is now updated to do the same. New data types, such as f_iki_delimit_t, are provided to achieve this. When there are multiple separators, a colon ':', a valid IKI data might be skipped. This is happening for two reasons: 1) Incorrect increment of the location after identifying a non-IKI defining colon. 2) The seek function is not stopping on special characters like a colon. The iki_read program is updated to reflect these changes. A new structure, called iki_data_t, is provided to simplify the arguments being passed around. The iki_write program is updated to reflect these changes. The make program is updated to reflect these changes. --- level_0/f_iki/c/iki-common.c | 32 ++-- level_0/f_iki/c/iki-common.h | 292 ++++++++++++++------------------ level_0/f_iki/c/iki.c | 256 ++++++++++++---------------- level_0/f_iki/c/iki.h | 4 +- level_0/f_iki/c/private-iki.c | 44 ++++- level_0/f_iki/c/private-iki.h | 25 +++ level_1/fl_iki/c/iki.c | 4 +- level_1/fl_iki/c/iki.h | 10 +- level_2/fll_iki/c/iki.c | 8 +- level_2/fll_iki/c/private-iki.c | 16 +- level_3/fake/c/private-make.c | 17 +- level_3/iki_read/c/private-common.h | 32 ++++ level_3/iki_read/c/private-iki_read.c | 139 ++++++++------- level_3/iki_read/c/private-iki_read.h | 38 ++--- level_3/iki_write/c/iki_write.c | 6 +- level_3/iki_write/c/private-iki_write.c | 2 +- specifications/fss-000C.txt | 62 ++----- specifications/iki.txt | 18 +- 18 files changed, 497 insertions(+), 508 deletions(-) diff --git a/level_0/f_iki/c/iki-common.c b/level_0/f_iki/c/iki-common.c index 5d58c37..6d9609b 100644 --- a/level_0/f_iki/c/iki-common.c +++ b/level_0/f_iki/c/iki-common.c @@ -5,22 +5,30 @@ extern "C" { #endif +#ifndef _di_f_iki_syntax_ + const f_string_t f_iki_syntax_separator_s = F_iki_syntax_separator_s; + const f_string_t f_iki_syntax_placeholder_s = F_iki_syntax_placeholder_s; + const f_string_t f_iki_syntax_quote_double_s = F_iki_syntax_quote_double_s; + const f_string_t f_iki_syntax_quote_single_s = F_iki_syntax_quote_single_s; + const f_string_t f_iki_syntax_slash_s = F_iki_syntax_slash_s; +#endif //_di_f_iki_syntax_ + #ifndef _di_iki_vocabulary_0001_s_ - const f_string_t iki_vocabulary_0001_address_s = IKI_vocabulary_0001_address_s; - const f_string_t iki_vocabulary_0001_code_s = IKI_vocabulary_0001_code_s; - const f_string_t iki_vocabulary_0001_email_s = IKI_vocabulary_0001_email_s; - const f_string_t iki_vocabulary_0001_name_s = IKI_vocabulary_0001_name_s; - const f_string_t iki_vocabulary_0001_phone_s = IKI_vocabulary_0001_phone_s; - const f_string_t iki_vocabulary_0001_quote_s = IKI_vocabulary_0001_quote_s; - const f_string_t iki_vocabulary_0001_uri_s = IKI_vocabulary_0001_uri_s; - const f_string_t iki_vocabulary_0001_url_s = IKI_vocabulary_0001_url_s; - const f_string_t iki_vocabulary_0001_urn_s = IKI_vocabulary_0001_urn_s; - const f_string_t iki_vocabulary_0001_variable_s = IKI_vocabulary_0001_variable_s; + const f_string_t f_iki_vocabulary_0001_address_s = F_iki_vocabulary_0001_address_s; + const f_string_t f_iki_vocabulary_0001_code_s = F_iki_vocabulary_0001_code_s; + const f_string_t f_iki_vocabulary_0001_email_s = F_iki_vocabulary_0001_email_s; + const f_string_t f_iki_vocabulary_0001_name_s = F_iki_vocabulary_0001_name_s; + const f_string_t f_iki_vocabulary_0001_phone_s = F_iki_vocabulary_0001_phone_s; + const f_string_t f_iki_vocabulary_0001_quote_s = F_iki_vocabulary_0001_quote_s; + const f_string_t f_iki_vocabulary_0001_uri_s = F_iki_vocabulary_0001_uri_s; + const f_string_t f_iki_vocabulary_0001_url_s = F_iki_vocabulary_0001_url_s; + const f_string_t f_iki_vocabulary_0001_urn_s = F_iki_vocabulary_0001_urn_s; + const f_string_t f_iki_vocabulary_0001_variable_s = F_iki_vocabulary_0001_variable_s; #endif // _di_iki_vocabulary_0001_s_ #ifndef _di_iki_vocabulary_0002_s_ - const f_string_t iki_vocabulary_0002_define_s = IKI_vocabulary_0002_define_s; - const f_string_t iki_vocabulary_0002_parameter_s = IKI_vocabulary_0002_parameter_s; + const f_string_t f_iki_vocabulary_0002_define_s = F_iki_vocabulary_0002_define_s; + const f_string_t f_iki_vocabulary_0002_parameter_s = F_iki_vocabulary_0002_parameter_s; #endif // _di_iki_vocabulary_0002_s_ #ifdef __cplusplus diff --git a/level_0/f_iki/c/iki-common.h b/level_0/f_iki/c/iki-common.h index a51578d..4ec03d4 100644 --- a/level_0/f_iki/c/iki-common.h +++ b/level_0/f_iki/c/iki-common.h @@ -20,62 +20,134 @@ extern "C" { * IKI-specific syntax. */ #ifndef _di_f_iki_syntax_ - #define F_iki_syntax_separator_s ':' - #define F_iki_syntax_placeholder_s 0 - #define F_iki_syntax_quote_double_s '"' - #define F_iki_syntax_quote_single_s '\'' - #define F_iki_syntax_slash_s '\\' + #define F_iki_syntax_separator_s ":" + #define F_iki_syntax_placeholder_s "" + #define F_iki_syntax_quote_double_s "\"" + #define F_iki_syntax_quote_single_s "\'" + #define F_iki_syntax_slash_s "\\" + + #define F_iki_syntax_separator_s_length 1 + #define F_iki_syntax_placeholder_s_length 1 + #define F_iki_syntax_quote_double_s_length 1 + #define F_iki_syntax_quote_single_s_length 1 + #define F_iki_syntax_slash_s_length 1 + + extern const f_string_t f_iki_syntax_separator_s; + extern const f_string_t f_iki_syntax_placeholder_s; + extern const f_string_t f_iki_syntax_quote_double_s; + extern const f_string_t f_iki_syntax_quote_single_s; + extern const f_string_t f_iki_syntax_slash_s; #endif //_di_f_iki_syntax_ -#ifndef _di_iki_vocabulary_0001_s_ - #define IKI_vocabulary_0001_address_s "address" - #define IKI_vocabulary_0001_code_s "code" - #define IKI_vocabulary_0001_email_s "email" - #define IKI_vocabulary_0001_name_s "name" - #define IKI_vocabulary_0001_phone_s "phone" - #define IKI_vocabulary_0001_quote_s "quote" - #define IKI_vocabulary_0001_uri_s "uri" - #define IKI_vocabulary_0001_url_s "url" - #define IKI_vocabulary_0001_urn_s "urn" - #define IKI_vocabulary_0001_variable_s "var" - - #define IKI_vocabulary_0001_address_s_length 7 - #define IKI_vocabulary_0001_code_s_length 4 - #define IKI_vocabulary_0001_email_s_length 5 - #define IKI_vocabulary_0001_name_s_length 4 - #define IKI_vocabulary_0001_phone_s_length 5 - #define IKI_vocabulary_0001_quote_s_length 5 - #define IKI_vocabulary_0001_uri_s_length 3 - #define IKI_vocabulary_0001_url_s_length 3 - #define IKI_vocabulary_0001_urn_s_length 3 - #define IKI_vocabulary_0001_variable_s_length 3 - - extern const f_string_t iki_vocabulary_0001_address_s; - extern const f_string_t iki_vocabulary_0001_code_s; - extern const f_string_t iki_vocabulary_0001_email_s; - extern const f_string_t iki_vocabulary_0001_name_s; - extern const f_string_t iki_vocabulary_0001_phone_s; - extern const f_string_t iki_vocabulary_0001_quote_s; - extern const f_string_t iki_vocabulary_0001_uri_s; - extern const f_string_t iki_vocabulary_0001_url_s; - extern const f_string_t iki_vocabulary_0001_urn_s; - extern const f_string_t iki_vocabulary_0001_variable_s; -#endif // _di_iki_vocabulary_0001_s_ - -#ifndef _di_iki_vocabulary_0002_s_ - #define IKI_vocabulary_0002_define_s "define" - #define IKI_vocabulary_0002_parameter_s "parameter" - - #define IKI_vocabulary_0002_define_s_length 6 - #define IKI_vocabulary_0002_parameter_s_length 9 - - extern const f_string_t iki_vocabulary_0002_define_s; - extern const f_string_t iki_vocabulary_0002_parameter_s; -#endif // _di_iki_vocabulary_0002_s_ +#ifndef _di_iki_vocabulary_0001_ + #define F_iki_vocabulary_0001_address_s "address" + #define F_iki_vocabulary_0001_code_s "code" + #define F_iki_vocabulary_0001_email_s "email" + #define F_iki_vocabulary_0001_name_s "name" + #define F_iki_vocabulary_0001_phone_s "phone" + #define F_iki_vocabulary_0001_quote_s "quote" + #define F_iki_vocabulary_0001_uri_s "uri" + #define F_iki_vocabulary_0001_url_s "url" + #define F_iki_vocabulary_0001_urn_s "urn" + #define F_iki_vocabulary_0001_variable_s "var" + + #define F_iki_vocabulary_0001_address_s_length 7 + #define F_iki_vocabulary_0001_code_s_length 4 + #define F_iki_vocabulary_0001_email_s_length 5 + #define F_iki_vocabulary_0001_name_s_length 4 + #define F_iki_vocabulary_0001_phone_s_length 5 + #define F_iki_vocabulary_0001_quote_s_length 5 + #define F_iki_vocabulary_0001_uri_s_length 3 + #define F_iki_vocabulary_0001_url_s_length 3 + #define F_iki_vocabulary_0001_urn_s_length 3 + #define F_iki_vocabulary_0001_variable_s_length 3 + + extern const f_string_t f_iki_vocabulary_0001_address_s; + extern const f_string_t f_iki_vocabulary_0001_code_s; + extern const f_string_t f_iki_vocabulary_0001_email_s; + extern const f_string_t f_iki_vocabulary_0001_name_s; + extern const f_string_t f_iki_vocabulary_0001_phone_s; + extern const f_string_t f_iki_vocabulary_0001_quote_s; + extern const f_string_t f_iki_vocabulary_0001_uri_s; + extern const f_string_t f_iki_vocabulary_0001_url_s; + extern const f_string_t f_iki_vocabulary_0001_urn_s; + extern const f_string_t f_iki_vocabulary_0001_variable_s; +#endif // _di_iki_vocabulary_0001_ + +#ifndef _di_iki_vocabulary_0002_ + #define F_iki_vocabulary_0002_define_s "define" + #define F_iki_vocabulary_0002_parameter_s "parameter" + + #define F_iki_vocabulary_0002_define_s_length 6 + #define F_iki_vocabulary_0002_parameter_s_length 9 + + extern const f_string_t f_iki_vocabulary_0002_define_s; + extern const f_string_t f_iki_vocabulary_0002_parameter_s; +#endif // _di_iki_vocabulary_0002_ // @todo consider IKI-0003 = vocabulary based on context from HTML5 and accessibility-related? /** + * Designate an iki delimit location. + */ +#ifndef _di_f_iki_delimit_t_ + typedef f_array_length_t f_iki_delimit_t; +#endif // _di_f_iki_delimit_t_ + +/** + * An array of f_iki_delimit_t. + * + * array: The array of iki quote. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_iki_delimits_t_ + typedef f_array_lengths_t f_iki_delimits_t; + + #define f_iki_delimits_t_initialize f_array_lengths_t_initialize + + #define macro_f_iki_delimits_t_clear(delimits) macro_f_array_lengths_t_clear(delimits) + + #define macro_f_iki_delimits_t_resize(status, delimits, length) macro_f_array_lengths_t_resize(status, delimits, length) + #define macro_f_iki_delimits_t_adjust(status, delimits, length) macro_f_array_lengths_t_adjust(status, delimits, length) + + #define macro_f_iki_delimits_t_delete_simple(delimits) macro_f_array_lengths_t_delete_simple(delimits) + #define macro_f_iki_delimits_t_destroy_simple(delimits) macro_f_array_lengths_t_destroy_simple(delimits) + + #define macro_f_iki_delimits_t_increase(status, step, delimits) macro_f_array_lengths_t_increase(status, step, delimits) + #define macro_f_iki_delimits_t_increase_by(status, delimits, amount) macro_f_array_lengths_t_increase_by(status, delimits, amount) + #define macro_f_iki_delimits_t_decrease_by(status, delimits, amount) macro_f_array_lengths_t_decrease_by(status, delimits, amount) + #define macro_f_iki_delimits_t_decimate_by(status, delimits, amount) macro_f_array_lengths_t_decimate_by(status, delimits, amount) +#endif // _di_f_iki_delimits_t_ + +/** + * An array of f_iki_delimits_t. + * + * array: The array of iki quotes. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_f_iki_delimitss_t_ + typedef f_array_lengthss_t f_iki_delimitss_t; + + #define f_iki_delimitss_t_initialize f_array_lengthss_t_initialize + + #define macro_f_iki_delimitss_t_clear(delimitss) macro_f_array_lengthss_t_clear(delimitss) + + #define macro_f_iki_delimitss_t_resize(status, delimitss, length) macro_f_array_lengthss_t_resize(status, delimitss, length) + #define macro_f_iki_delimitss_t_adjust(status, delimitss, length) macro_f_array_lengthss_t_adjust(status, delimitss, length) + + #define macro_f_iki_delimitss_t_delete_simple(delimitss) macro_f_array_lengthss_t_delete_simple(delimitss) + #define macro_f_iki_delimitss_t_destroy_simple(delimitss) macro_f_array_lengthss_t_destroy_simple(delimitss) + + #define macro_f_iki_delimitss_t_increase(status, step, delimitss) macro_f_array_lengthss_t_increase(status, step, delimitss) + #define macro_f_iki_delimitss_t_increase_by(status, delimitss, amount) macro_f_array_lengthss_t_increase_by(status, delimitss, amount) + #define macro_f_iki_delimitss_t_decrease_by(status, delimitss, amount) macro_f_array_lengthss_t_decrease_by(status, delimitss, amount) + #define macro_f_iki_delimitss_t_decimate_by(status, delimitss, amount) macro_f_array_lengthss_t_decimate_by(status, delimitss, amount) +#endif // _di_f_iki_delimitss_t_ + + +/** * This holds an array of string ranges that represent the entire vocabulary name, content, and syntax. * * array: The array of variable. @@ -94,6 +166,7 @@ extern "C" { #define macro_f_iki_variable_t_delete_simple(variable) macro_f_string_ranges_t_delete_simple(variable) #define macro_f_iki_variable_t_destroy_simple(variable) macro_f_string_ranges_t_destroy_simple(variable) + #endif // _di_iki_variable_t_ /** @@ -191,125 +264,6 @@ extern "C" { #define F_iki_default_allocation_step_d 4 #endif // _di_f_iki_default_allocation_step_ -/** - * Reallocate delimits array if necessary for appending a new delimit. - * - * state: The state. - * status: The return status to use. - * delimits: The delimit array to conditionally reallocate. - */ -#ifndef _di_macro_f_iki_allocate_delimits_if_necessary_ - #define macro_f_iki_allocate_delimits_if_necessary(state, status, delimits) \ - status = F_none; \ - if (delimits.used == delimits.size) { \ - if (delimits.used + state.step_small > F_array_length_t_size_d) { \ - if (delimits.used == F_array_length_t_size_d) { \ - status = F_status_set_error(F_string_too_large); \ - } \ - else { \ - macro_f_array_lengths_t_resize(status, delimits, delimits.size + 1); \ - } \ - } \ - else { \ - macro_f_array_lengths_t_resize(status, delimits, delimits.size + state.step_small); \ - } \ - } -#endif // _di_macro_f_iki_allocate_delimits_if_necessary_ - -/** - * Reallocate delimits array if necessary for appending a new ranges. - * - * state: The state. - * status: The return status to use. - * ranges: The delimit array to conditionally reallocate. - */ -#ifndef _di_macro_f_iki_allocate_ranges_if_necessary_ - #define macro_f_iki_allocate_ranges_if_necessary(state, status, ranges) \ - status = F_none; \ - if (ranges.used == ranges.size) { \ - if (ranges.used + state.step_small > F_array_length_t_size_d) { \ - if (ranges.used == F_array_length_t_size_d) { \ - status = F_status_set_error(F_string_too_large); \ - } \ - else { \ - macro_f_string_ranges_t_resize(status, ranges, ranges.size + 1); \ - } \ - } \ - else { \ - macro_f_string_ranges_t_resize(status, ranges, ranges.size + state.step_small); \ - } \ - } -#endif // _di_macro_f_iki_allocate_ranges_if_necessary_ - -/** - * Determine what the max width is based on the buffer and the range. - * - * buffer: (A pointer) The buffer to determine width against. - * range: (A pointer) The range within that buffer to determine against. - * width_max: The determined width max. - */ -#ifndef _di_macro_f_iki_determine_width_max_ - #define macro_f_iki_determine_width_max(buffer, range, width_max) \ - width_max = (range->stop - range->start) + 1; \ - if (width_max > buffer->used - range->start) { \ - width_max = buffer->used - range->start; \ - } -#endif // _di_macro_f_iki_determine_width_max_ - -/** - * Seek until whitespace is found or not found. - * - * This will ignore the delimit placeholder. - * - * status: The return status to use. - * buffer: (A pointer) The buffer to seek through. - * range: (A pointer) The range within that buffer to seek through. - * width_max: The width_max variable to use fo calculating width_max. - * condition: Set to TRUE to seek until whitespace is found and FALSE to seek until non-whitespace. - */ -#ifndef _di_macro_f_iki_seek_whitespace_ - #define macro_f_iki_seek_whitespace(status, buffer, range, width_max, condition) \ - while (range->start <= range->stop && range->start < buffer->used) { \ - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { \ - ++range->start; \ - continue; \ - } \ - macro_f_iki_determine_width_max(buffer, range, width_max); \ - status = f_utf_is_whitespace(buffer->string + range->start, width_max); \ - if (status == condition) break; \ - else if (F_status_is_error(status)) break; \ - status = f_utf_buffer_increment(*buffer, range, 1); \ - if (F_status_is_error(status)) break; \ - } -#endif // _di_macro_f_iki_seek_whitespace_ - -/** - * Seek until a word, dash, or plus is found or not found. - * - * This will ignore the delimit placeholder. - * - * status: The return status to use. - * buffer: (A pointer) The buffer to seek through. - * range: (A pointer) The range within that buffer to seek through. - * width_max: The width_max variable to use fo calculating width_max. - * condition: Set to TRUE to seek until a word character, dash character, or plus character is found and FALSE to seek until the opposite is found. - */ -#ifndef _di_macro_f_iki_seek_word_dash_plus_ - #define macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, condition) \ - while (range->start <= range->stop && range->start < buffer->used) { \ - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { \ - ++range->start; \ - continue; \ - } \ - macro_f_iki_determine_width_max(buffer, range, width_max); \ - status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); \ - if (status == condition) break; \ - else if (F_status_is_error(status)) break; \ - status = f_utf_buffer_increment(*buffer, range, 1); \ - if (F_status_is_error(status)) break; \ - } -#endif // _di_macro_f_iki_seek_word_dash_plus_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_iki/c/iki.c b/level_0/f_iki/c/iki.c index be5e1f3..30bd888 100644 --- a/level_0/f_iki/c/iki.c +++ b/level_0/f_iki/c/iki.c @@ -9,7 +9,7 @@ extern "C" { f_status_t f_iki_content_is(const f_string_static_t content, const uint8_t quote) { #ifndef _di_level_0_parameter_checking_ if (content.used > content.size) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != f_iki_syntax_quote_single_s[0] && quote != f_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ const f_string_range_t range = macro_f_string_range_t_initialize(content.used); @@ -24,7 +24,7 @@ extern "C" { if (content.used > content.size) return F_status_set_error(F_parameter); if (range.start > range.stop) return F_status_set_error(F_parameter); if (range.start >= content.used) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != f_iki_syntax_quote_single_s[0] && quote != f_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ return private_f_iki_content_partial_is(content, range, quote); @@ -56,13 +56,14 @@ extern "C" { #endif // _di_f_iki_object_partial_is_ #ifndef _di_f_iki_read_ - f_status_t f_iki_read(f_state_t state, f_string_static_t *buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content) { + f_status_t f_iki_read(f_state_t state, f_string_static_t * const buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_iki_delimits_t *delimits) { #ifndef _di_level_0_parameter_checking_ if (!buffer) return F_status_set_error(F_parameter); if (!range) return F_status_set_error(F_parameter); if (!variable) return F_status_set_error(F_parameter); if (!vocabulary) return F_status_set_error(F_parameter); if (!content) return F_status_set_error(F_parameter); + if (!delimits) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (!buffer->used) { @@ -78,44 +79,41 @@ extern "C" { } f_status_t status = F_none; - f_array_length_t width_max = 0; if (width_max > buffer->used - range->start) { width_max = buffer->used - range->start; } - // skip past all initial non-word, non-dash, and non-plus. - macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, F_true); + status = private_f_iki_seek_special(*buffer, range); if (F_status_is_error(status)) { return status; } - else if (range->start > range->stop) { + + if (range->start > range->stop) { return F_data_not_stop; } - else if (range->start >= buffer->used) { + + if (range->start >= buffer->used) { return F_data_not_eos; } f_string_range_t found_vocabulary = f_string_range_t_initialize; f_array_length_t found_content = 0; - - found_vocabulary.start = range->start; - f_array_length_t vocabulary_slash_first = range->start; + const f_array_length_t delimits_used = delimits->used; uint8_t quote = 0; bool vocabulary_delimited = F_false; bool find_next = F_false; - // delimits must only be applied once a valid object is found. - f_array_lengths_t delimits = f_array_lengths_t_initialize; + found_vocabulary.start = range->start; do { - // find the start and end of the vocabulary name. + // Find the start and end of the vocabulary name. while (range->start <= range->stop && range->start < buffer->used) { if (state.interrupt) { @@ -123,18 +121,20 @@ extern "C" { if (F_status_set_fine(status) == F_interrupt) { status = F_status_set_error(F_interrupt); + break; } } - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { + if (buffer->string[range->start] == f_iki_syntax_placeholder_s[0]) { ++range->start; + continue; } - if (buffer->string[range->start] == F_iki_syntax_separator_s) { + if (buffer->string[range->start] == f_iki_syntax_separator_s[0]) { if (range->start == found_vocabulary.start) { - status = f_utf_buffer_increment(*buffer, range, 1); + ++range->start; break; } @@ -144,55 +144,53 @@ extern "C" { do { status = f_utf_buffer_increment(*buffer, range, 1); - } while (F_status_is_fine(status) && buffer->string[range->start] == F_iki_syntax_placeholder_s); + } while (F_status_is_fine(status) && buffer->string[range->start] == f_iki_syntax_placeholder_s[0]); if (F_status_is_error(status)) break; - // found a valid vocabulary name. - if (buffer->string[range->start] == F_iki_syntax_quote_single_s || buffer->string[range->start] == F_iki_syntax_quote_double_s) { - quote = buffer->string[range->start]; - ++range->start; + // Found a valid vocabulary name. + if (buffer->string[range->start] == f_iki_syntax_quote_single_s[0] || buffer->string[range->start] == f_iki_syntax_quote_double_s[0]) { + quote = buffer->string[range->start++]; break; } - // this is not a valid vocabulary name so seek until a non-word, non-dash, or non-plus character. - macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, F_false); - if (F_status_is_error(status)) break; - break; } - else if (buffer->string[range->start] == F_iki_syntax_slash_s) { + + if (buffer->string[range->start] == f_iki_syntax_slash_s[0]) { bool separator_found = F_false; vocabulary_slash_first = range->start; - // the slash only needs to be delimited if it were to otherwise be a valid vocabulary name. + // The slash only needs to be delimited if it were to otherwise be a valid vocabulary name. while (range->start <= range->stop && range->start < buffer->used) { - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { + if (buffer->string[range->start] == f_iki_syntax_placeholder_s[0]) { ++range->start; + continue; } if (separator_found) { - if (buffer->string[range->start] == F_iki_syntax_quote_single_s || buffer->string[range->start] == F_iki_syntax_quote_double_s) { + if (buffer->string[range->start] == f_iki_syntax_quote_single_s[0] || buffer->string[range->start] == f_iki_syntax_quote_double_s[0]) { vocabulary_delimited = F_true; + quote = buffer->string[range->start++]; - quote = buffer->string[range->start]; - ++range->start; break; } else { find_next = F_true; + break; } } - else if (buffer->string[range->start] == F_iki_syntax_separator_s) { + else if (buffer->string[range->start] == f_iki_syntax_separator_s[0]) { separator_found = F_true; } - else if (buffer->string[range->start] != F_iki_syntax_slash_s) { + else if (buffer->string[range->start] != f_iki_syntax_slash_s[0]) { find_next = F_true; + break; } @@ -202,32 +200,34 @@ extern "C" { break; } - else { - macro_f_iki_determine_width_max(buffer, range, width_max); - status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); - if (F_status_is_error(status)) break; + width_max = (range->stop - range->start) + 1; - // current word-dash-plus block is not a valid variable name, try again. - if (status == F_false) { - macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, F_true); + if (width_max > buffer->used - range->start) { + width_max = buffer->used - range->start; + } - if (F_status_is_error(status)) { - break; - } - else if (range->start > range->stop) { - macro_f_array_lengths_t_delete_simple(delimits); + status = f_utf_is_word_dash_plus(buffer->string + range->start, width_max, F_false); + if (F_status_is_error(status)) break; - return F_data_not_stop; - } - else if (range->start >= buffer->used) { - macro_f_array_lengths_t_delete_simple(delimits); + // Current word-dash-plus block is not a valid variable name, try again. + if (status == F_false) { + status = private_f_iki_seek_special(*buffer, range); + if (F_status_is_error(status)) break; - return F_data_not_eos; - } + if (range->start > range->stop) { + delimits->used = delimits_used; + + return F_data_not_stop; + } - found_vocabulary.start = range->start; + if (range->start >= buffer->used) { + delimits->used = delimits_used; + + return F_data_not_eos; } + + found_vocabulary.start = range->start; } status = f_utf_buffer_increment(*buffer, range, 1); @@ -235,12 +235,12 @@ extern "C" { } // while if (F_status_is_error(status)) { - macro_f_array_lengths_t_delete_simple(delimits); + delimits->used = delimits_used; return status; } - // process potentially valid content. + // Process potentially valid content. if (quote) { found_content = range->start; @@ -251,11 +251,12 @@ extern "C" { if (F_status_set_fine(status) == F_interrupt) { status = F_status_set_error(F_interrupt); + break; } } - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { + if (buffer->string[range->start] == f_iki_syntax_placeholder_s[0]) { ++range->start; continue; @@ -263,13 +264,12 @@ extern "C" { if (buffer->string[range->start] == quote) { - // this is a valid vocabulary name and content, but if it is delimited, save the delimit and ignore. + // This is a valid vocabulary name and content, but if it is delimited, save the delimit and ignore. if (vocabulary_delimited) { - macro_f_iki_allocate_delimits_if_necessary(state, status, delimits); + status = f_type_array_lengths_increase(state.step_small, delimits); if (F_status_is_error(status)) break; - delimits.array[delimits.used] = vocabulary_slash_first; - ++delimits.used; + delimits->array[delimits->used++] = vocabulary_slash_first; find_next = F_true; vocabulary_delimited = F_false; @@ -278,58 +278,42 @@ extern "C" { ++range->start; break; } - else { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*variable)); - if (F_status_is_fine(status)) { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*vocabulary)); - } - - if (F_status_is_fine(status)) { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*content)); - } - - if (F_status_is_error(status)) break; - - variable->array[variable->used].start = found_vocabulary.start; - variable->array[variable->used].stop = range->start; - ++variable->used; + status = f_string_ranges_increase(state.step_small, variable); + if (F_status_is_error(status)) break; - vocabulary->array[vocabulary->used].start = found_vocabulary.start; - vocabulary->array[vocabulary->used].stop = found_vocabulary.stop; - ++vocabulary->used; + status = f_string_ranges_increase(state.step_small, vocabulary); + if (F_status_is_error(status)) break; - content->array[content->used].start = found_content; - content->array[content->used].stop = range->start - 1; - ++content->used; + status = f_string_ranges_increase(state.step_small, content); + if (F_status_is_error(status)) break; - for (f_array_length_t i = 0; i < delimits.used; ++i) { - buffer->string[delimits.array[i]] = F_iki_syntax_placeholder_s; - } // for + variable->array[variable->used].start = found_vocabulary.start; + variable->array[variable->used++].stop = range->start; - macro_f_array_lengths_t_delete_simple(delimits); - if (F_status_is_error(status)) return status; + vocabulary->array[vocabulary->used].start = found_vocabulary.start; + vocabulary->array[vocabulary->used++].stop = found_vocabulary.stop; - ++range->start; + content->array[content->used].start = found_content; + content->array[content->used++].stop = range->start - 1; - if (range->start > range->stop) { - return F_none_stop; - } - - if (range->start >= buffer->used) { - return F_none_eos; - } + if (++range->start > range->stop) { + return F_none_stop; + } - return F_none; + if (range->start >= buffer->used) { + return F_none_eos; } + + return F_none; } - else if (buffer->string[range->start] == F_iki_syntax_slash_s) { + else if (buffer->string[range->start] == f_iki_syntax_slash_s[0]) { f_array_length_t content_slash_first = range->start; f_array_length_t content_slash_total = 0; while (range->start <= range->stop && range->start < buffer->used) { - if (buffer->string[range->start] == F_iki_syntax_placeholder_s) { + if (buffer->string[range->start] == f_iki_syntax_placeholder_s[0]) { ++range->start; continue; @@ -344,26 +328,16 @@ extern "C" { ++content_slash_delimits; } - if (delimits.used + content_slash_delimits > delimits.size) { - if (delimits.used + content_slash_delimits > F_array_length_t_size_d) { - status = F_status_set_error(F_string_too_large); - } - else { - macro_f_array_lengths_t_resize(status, delimits, delimits.used + content_slash_delimits); - } - - if (F_status_is_error(status)) break; - } + status = f_type_array_lengths_increase_by(content_slash_delimits, delimits); + if (F_status_is_error(status)) break; content_range.start = content_slash_first; content_range.stop = range->stop; while (i < content_slash_delimits) { - if (buffer->string[content_range.start] == F_iki_syntax_slash_s) { - delimits.array[delimits.used] = content_range.start; - ++delimits.used; - + if (buffer->string[content_range.start] == f_iki_syntax_slash_s[0]) { + delimits->array[delimits->used++] = content_range.start; ++i; } @@ -373,62 +347,46 @@ extern "C" { if (F_status_is_error(status)) break; - // valid content's ending quote is not delimited, save and return. + // Valid content's ending quote is not delimited, save and return. if (content_slash_total % 2 == 0) { - // this is a valid vocabulary name and content, but if it is delimited, save the delimit and ignore. + // This is a valid vocabulary name and content, but if it is delimited, save the delimit and ignore. if (vocabulary_delimited) { - macro_f_iki_allocate_delimits_if_necessary(state, status, delimits); + status = f_type_array_lengths_increase(state.step_small, delimits); if (F_status_is_error(status)) break; - delimits.array[delimits.used] = vocabulary_slash_first; - ++delimits.used; + delimits->array[delimits->used++] = vocabulary_slash_first; vocabulary_delimited = F_false; quote = 0; ++range->start; - // skip past all initial non-word, non-dash, and non-plus. - macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, F_true); + // Skip past all initial non-word, non-dash, and non-plus. + status = private_f_iki_seek_special(*buffer, range); found_vocabulary.start = range->start; } else { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*variable)); - - if (F_status_is_fine(status)) { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*vocabulary)); - } + status = f_string_ranges_increase(state.step_small, variable); + if (F_status_is_error(status)) break; - if (F_status_is_fine(status)) { - macro_f_iki_allocate_ranges_if_necessary(state, status, (*content)); - } + status = f_string_ranges_increase(state.step_small, vocabulary); + if (F_status_is_error(status)) break; + status = f_string_ranges_increase(state.step_small, content); if (F_status_is_error(status)) break; variable->array[variable->used].start = found_vocabulary.start; - variable->array[variable->used].stop = range->start; - ++variable->used; + variable->array[variable->used++].stop = range->start; vocabulary->array[vocabulary->used].start = found_vocabulary.start; - vocabulary->array[vocabulary->used].stop = found_vocabulary.stop; - ++vocabulary->used; + vocabulary->array[vocabulary->used++].stop = found_vocabulary.stop; content->array[content->used].start = found_content; - content->array[content->used].stop = range->start - 1; - ++content->used; - - for (f_array_length_t i = 0; i < delimits.used; ++i) { - buffer->string[delimits.array[i]] = F_iki_syntax_placeholder_s; - } // for - - macro_f_array_lengths_t_delete_simple(delimits); - if (F_status_is_error(status)) return status; - - ++range->start; + content->array[content->used++].stop = range->start - 1; - if (range->start > range->stop) { + if (++range->start > range->stop) { return F_none_stop; } @@ -442,7 +400,8 @@ extern "C" { break; } - else if (buffer->string[range->start] != F_iki_syntax_slash_s) { + + if (buffer->string[range->start] != f_iki_syntax_slash_s[0]) { break; } @@ -465,13 +424,13 @@ extern "C" { } if (F_status_is_error(status)) { - macro_f_array_lengths_t_delete_simple(delimits); + delimits->used = delimits_used; return status; } if (find_next) { - macro_f_iki_seek_word_dash_plus(status, buffer, range, width_max, F_true); + status = private_f_iki_seek_special(*buffer, range); found_vocabulary.start = range->start; find_next = F_false; @@ -479,13 +438,6 @@ extern "C" { } while (range->start <= range->stop && range->start < buffer->used); - for (f_array_length_t i = 0; i < delimits.used; ++i) { - buffer->string[delimits.array[i]] = F_iki_syntax_placeholder_s; - } // for - - macro_f_array_lengths_t_delete_simple(delimits); - if (F_status_is_error(status)) return status; - if (range->start > range->stop) { return F_data_not_stop; } diff --git a/level_0/f_iki/c/iki.h b/level_0/f_iki/c/iki.h index be3157f..6db37cd 100644 --- a/level_0/f_iki/c/iki.h +++ b/level_0/f_iki/c/iki.h @@ -142,6 +142,8 @@ extern "C" { * The vocabulary name list to store the found vocabulary name. * @param content * The content list to store the content associated with the found vocabulary name. + * @param delimits + * A delimits array representing where delimits exist within the buffer. * * @return * F_none on success and an IKI vocabulary name was found. @@ -157,7 +159,7 @@ extern "C" { * F_string_too_large (with error bit) if a string length is too large to store in the buffer. */ #ifndef _di_f_iki_read_ - extern f_status_t f_iki_read(f_state_t state, f_string_static_t *buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content); + extern f_status_t f_iki_read(f_state_t state, f_string_static_t * const buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_iki_delimits_t *delimits); #endif // _di_f_iki_read_ #ifdef __cplusplus diff --git a/level_0/f_iki/c/private-iki.c b/level_0/f_iki/c/private-iki.c index 3395ab8..0adbdc8 100644 --- a/level_0/f_iki/c/private-iki.c +++ b/level_0/f_iki/c/private-iki.c @@ -5,6 +5,48 @@ extern "C" { #endif +#if !defined(_di_f_iki_read_) + f_status_t private_f_iki_seek_special(const f_string_static_t buffer, f_string_range_t *range) { + + f_status_t status = F_none; + f_array_length_t width_max = 0; + + while (range->start <= range->stop && range->start < buffer.used) { + + if (buffer.string[range->start] == f_iki_syntax_separator_s[0]) { + break; + } + + if (buffer.string[range->start] == F_iki_syntax_quote_double_s[0]) { + break; + } + + if (buffer.string[range->start] == F_iki_syntax_quote_single_s[0]) { + break; + } + + if (buffer.string[range->start] == F_iki_syntax_slash_s[0]) { + break; + } + + width_max = (range->stop - range->start) + 1; + + if (width_max > buffer.used - range->start) { + width_max = buffer.used - range->start; + } + + status = f_utf_is_word_dash_plus(buffer.string + range->start, width_max, F_false); + if (F_status_is_error(status)) return status; + if (status == F_true) return status; + + status = f_utf_buffer_increment(buffer, range, 1); + if (F_status_is_error(status)) return status; + } // while + + return F_false; + } +#endif // !defined(_di_f_iki_read_) + #if !defined(_di_f_iki_content_is_) || !defined(_di_f_iki_content_partial_is_) f_status_t private_f_iki_content_partial_is(const f_string_static_t buffer, const f_string_range_t range, const uint8_t quote) { @@ -21,7 +63,7 @@ extern "C" { return F_false; } - else if (buffer.string[i] == F_iki_syntax_slash_s) { + else if (buffer.string[i] == f_iki_syntax_slash_s[0]) { ++delimits; } else { diff --git a/level_0/f_iki/c/private-iki.h b/level_0/f_iki/c/private-iki.h index 42046b2..62bd6ac 100644 --- a/level_0/f_iki/c/private-iki.h +++ b/level_0/f_iki/c/private-iki.h @@ -64,6 +64,31 @@ extern "C" { extern f_status_t private_f_iki_object_partial_is(const f_string_static_t buffer, const f_string_range_t range) F_attribute_visibility_internal_d; #endif // !defined(_di_f_iki_object_is_) || !defined(_di_f_iki_object_partial_is_) +/** + * Seek until a word, a dash, or a plus is found or is not found. + * + * This will ignore the delimit placeholder. + * This will stop at any special characters, such as a colon, a single quote, a double quote, or a backslash. + * + * @param buffer + * The string to process. + * @param range + * The range within the buffer that represents the current position being processed. + * + * @return + * F_true if stopped on a word, a dash, or a plus. + * F_false if stopped on a plus scolon, single quote, double quote, and backslash or stopped on something other than a word, a dash, or a plus. + * + * Errors (with error bit) from: f_utf_buffer_increment(). + * Errors (with error bit) from: f_utf_is_word_dash_plus(). + * + * @see f_utf_buffer_increment() + * @see f_utf_is_word_dash_plus() + */ +#if !defined(_di_f_iki_read_) + extern f_status_t private_f_iki_seek_special(const f_string_static_t buffer, f_string_range_t *range) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_iki_read_) + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_iki/c/iki.c b/level_1/fl_iki/c/iki.c index a002dc2..6d4f156 100644 --- a/level_1/fl_iki/c/iki.c +++ b/level_1/fl_iki/c/iki.c @@ -5,7 +5,7 @@ extern "C" { #endif #ifndef _di_fl_iki_read_ - f_status_t fl_iki_read(f_state_t state, f_string_static_t *buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content) { + f_status_t fl_iki_read(f_state_t state, f_string_static_t * const buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_iki_delimits_t *delimits) { #ifndef _di_level_1_parameter_checking_ if (!buffer) return F_status_set_error(F_parameter); if (!range) return F_status_set_error(F_parameter); @@ -14,7 +14,7 @@ extern "C" { f_status_t status = F_none; do { - status = f_iki_read(state, buffer, range, variable, vocabulary, content); + status = f_iki_read(state, buffer, range, variable, vocabulary, content, delimits); if (F_status_is_error(status)) return status; if (status == F_data_not_eos || status == F_data_not_stop) { diff --git a/level_1/fl_iki/c/iki.h b/level_1/fl_iki/c/iki.h index c31084a..15bdd58 100644 --- a/level_1/fl_iki/c/iki.h +++ b/level_1/fl_iki/c/iki.h @@ -57,6 +57,8 @@ extern "C" { * The vocabulary name list to store the found vocabulary names. * @param content * The content list to store the content associated with the found vocabulary names. + * @param delimits + * A delimits array representing where delimits exist within the buffer. * * @return * F_none on success and an IKI vocabulary name was found. @@ -65,15 +67,15 @@ extern "C" { * F_data_not_eos on success and EOS was reached, but there were no IKI vocabularie names found. * F_data_not_stop on success and stop point was reached, but there were no IKI vocabularie names found. * - * F_interrupt (with error bit) if stopping due to an interrupt. - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. - * F_string_too_large (with error bit) if a string length is too large to store in the buffer. * + * Success from: f_iki_read(). * Errors (with error bit) from: f_iki_read(). + * + * @see f_iki_read() */ #ifndef _di_fl_iki_read_ - extern f_status_t fl_iki_read(f_state_t state, f_string_static_t *buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content); + extern f_status_t fl_iki_read(f_state_t state, f_string_static_t * const buffer, f_string_range_t *range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_iki_delimits_t *delimits); #endif // _di_fl_iki_read_ #ifdef __cplusplus diff --git a/level_2/fll_iki/c/iki.c b/level_2/fll_iki/c/iki.c index f9b6d05..3919c32 100644 --- a/level_2/fll_iki/c/iki.c +++ b/level_2/fll_iki/c/iki.c @@ -9,7 +9,7 @@ extern "C" { f_status_t fll_iki_content_escape(const f_string_static_t content, const uint8_t quote, f_string_dynamic_t *escaped) { #ifndef _di_level_2_parameter_checking_ if (content.used > content.size) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != F_iki_syntax_quote_single_s[0] && quote != F_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); if (escaped->used > escaped->size) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ @@ -25,7 +25,7 @@ extern "C" { if (content.used > content.size) return F_status_set_error(F_parameter); if (range.start > range.stop) return F_status_set_error(F_parameter); if (range.start >= content.used) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != F_iki_syntax_quote_single_s[0] && quote != F_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); if (escaped->used > escaped->size) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ @@ -39,7 +39,7 @@ extern "C" { if (content.used > content.size) return F_status_set_error(F_parameter); if (range.start > range.stop) return F_status_set_error(F_parameter); if (range.start >= content.used) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != F_iki_syntax_quote_single_s[0] && quote != F_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); if (unescaped->used > unescaped->size) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ @@ -51,7 +51,7 @@ extern "C" { f_status_t fll_iki_content_unescape(const f_string_static_t content, const uint8_t quote, f_string_dynamic_t *unescaped) { #ifndef _di_level_2_parameter_checking_ if (content.used > content.size) return F_status_set_error(F_parameter); - if (quote != F_iki_syntax_quote_single_s && quote != F_iki_syntax_quote_double_s) return F_status_set_error(F_parameter); + if (quote != F_iki_syntax_quote_single_s[0] && quote != F_iki_syntax_quote_double_s[0]) return F_status_set_error(F_parameter); if (unescaped->used > unescaped->size) return F_status_set_error(F_parameter); #endif // _di_level_2_parameter_checking_ diff --git a/level_2/fll_iki/c/private-iki.c b/level_2/fll_iki/c/private-iki.c index a7aeaba..d0d687f 100644 --- a/level_2/fll_iki/c/private-iki.c +++ b/level_2/fll_iki/c/private-iki.c @@ -28,10 +28,10 @@ extern "C" { } for (j = 0; j < delimits; ++j) { - escaped->string[escaped->used++] = F_iki_syntax_slash_s; + escaped->string[escaped->used++] = F_iki_syntax_slash_s[0]; } // for - escaped->string[escaped->used++] = F_iki_syntax_slash_s; + escaped->string[escaped->used++] = F_iki_syntax_slash_s[0]; escaped->string[escaped->used++] = quote; delimits = 0; @@ -42,7 +42,7 @@ extern "C" { if (F_status_is_error(status)) return status; } - if (content.string[i] == F_iki_syntax_slash_s) { + if (content.string[i] == F_iki_syntax_slash_s[0]) { ++delimits; } else { @@ -61,7 +61,7 @@ extern "C" { } for (j = 0; j < delimits; ++j) { - escaped->string[escaped->used++] = F_iki_syntax_slash_s; + escaped->string[escaped->used++] = F_iki_syntax_slash_s[0]; } // for } @@ -94,7 +94,7 @@ extern "C" { return F_status_set_error(F_syntax); } - else if (content.string[i] == F_iki_syntax_slash_s) { + else if (content.string[i] == F_iki_syntax_slash_s[0]) { delimits = 1; if (i + 1 < content.used) { @@ -118,14 +118,14 @@ extern "C" { } for (j = 0; j < delimits; ++j) { - unescaped->string[unescaped->used++] = F_iki_syntax_slash_s; + unescaped->string[unescaped->used++] = F_iki_syntax_slash_s[0]; } // for delimits = 0; unescaped->string[unescaped->used++] = quote; break; } - else if (content.string[j] == F_iki_syntax_slash_s) { + else if (content.string[j] == F_iki_syntax_slash_s[0]) { ++delimits; } else if (content.string[j]) { @@ -165,7 +165,7 @@ extern "C" { } for (j = 0; j < delimits; ++j) { - unescaped->string[unescaped->used++] = F_iki_syntax_slash_s; + unescaped->string[unescaped->used++] = F_iki_syntax_slash_s[0]; } // for break; diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 4c0d1f8..c3ddee5 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -1233,15 +1233,16 @@ extern "C" { } } - const f_string_static_t vocabulary_define = macro_f_string_static_t_initialize(iki_vocabulary_0002_define_s, IKI_vocabulary_0002_define_s_length); - const f_string_static_t vocabulary_parameter = macro_f_string_static_t_initialize(iki_vocabulary_0002_parameter_s, IKI_vocabulary_0002_parameter_s_length); + const f_string_static_t vocabulary_define = macro_f_string_static_t_initialize(F_iki_vocabulary_0002_define_s, F_iki_vocabulary_0002_define_s_length); + const f_string_static_t vocabulary_parameter = macro_f_string_static_t_initialize(F_iki_vocabulary_0002_parameter_s, F_iki_vocabulary_0002_parameter_s_length); - const f_string_range_t range_define = macro_f_string_range_t_initialize(IKI_vocabulary_0002_define_s_length); - const f_string_range_t range_parameter = macro_f_string_range_t_initialize(IKI_vocabulary_0002_parameter_s_length); + const f_string_range_t range_define = macro_f_string_range_t_initialize(F_iki_vocabulary_0002_define_s_length); + const f_string_range_t range_parameter = macro_f_string_range_t_initialize(F_iki_vocabulary_0002_parameter_s_length); f_iki_variable_t iki_variable = f_iki_variable_t_initialize; f_iki_vocabulary_t iki_vocabulary = f_iki_vocabulary_t_initialize; f_iki_content_t iki_content = f_iki_content_t_initialize; + f_iki_delimits_t iki_delimits = f_iki_delimits_t_initialize; f_state_t state = macro_f_state_t_initialize(fake_common_allocation_large_d, fake_common_allocation_small_d, 0, &fake_signal_state_interrupt_iki, 0, (void *) &main, 0); @@ -1312,7 +1313,7 @@ extern "C" { used_arguments = arguments->used; - *status = fl_iki_read(state, &data_make->buffer, &range, &iki_variable, &iki_vocabulary, &iki_content); + *status = fl_iki_read(state, &data_make->buffer, &range, &iki_variable, &iki_vocabulary, &iki_content, &iki_delimits); if (F_status_is_error(*status)) { if (F_status_set_fine(*status) != F_interrupt) { @@ -1322,6 +1323,10 @@ extern "C" { break; } + for (k = 0; k < iki_delimits.used; ++k) { + data_make->buffer.string[iki_delimits.array[k]] = f_iki_syntax_placeholder_s[0]; + } // for + if (arguments->used >= arguments->size) { *status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); @@ -1593,11 +1598,13 @@ extern "C" { macro_f_iki_variable_t_delete_simple(iki_variable); macro_f_iki_vocabulary_t_delete_simple(iki_vocabulary); macro_f_iki_content_t_delete_simple(iki_content); + macro_f_iki_delimits_t_delete_simple(iki_delimits); } // for macro_f_iki_variable_t_delete_simple(iki_variable); macro_f_iki_vocabulary_t_delete_simple(iki_vocabulary); macro_f_iki_content_t_delete_simple(iki_content); + macro_f_iki_delimits_t_delete_simple(iki_delimits); } #endif // _di_fake_make_operate_expand_ diff --git a/level_3/iki_read/c/private-common.h b/level_3/iki_read/c/private-common.h index 97a8d17..3ca90d2 100644 --- a/level_3/iki_read/c/private-common.h +++ b/level_3/iki_read/c/private-common.h @@ -25,6 +25,38 @@ extern "C" { #endif // _di_iki_read_common_ /** + * Provide a structure for containing processed IKI data. + * + * variable: The variable ranges. + * vocabulary: The vocabulary ranges. + * content: The content ranges. + * delimits: The delimited locations. + */ +#ifndef _di_iki_data_ + typedef struct { + f_iki_variable_t variable; + f_iki_vocabulary_t vocabulary; + f_iki_content_t content; + f_iki_delimits_t delimits; + } iki_data_t; + + #define iki_data_t_initialize \ + { \ + f_iki_variable_t_initialize, \ + f_iki_vocabulary_t_initialize, \ + f_iki_content_t_initialize, \ + f_iki_delimits_t_initialize, \ + } + + #define macro_iki_data_t_delete_simple(data) \ + macro_f_iki_variable_t_delete_simple(data.variable) \ + macro_f_iki_vocabulary_t_delete_simple(data.vocabulary) \ + macro_f_iki_content_t_delete_simple(data.content) \ + macro_f_iki_delimits_t_delete_simple(data.delimits) + +#endif // _di_iki_data_ + +/** * Print a message about a process signal being recieved, such as an interrupt signal. * * @param main diff --git a/level_3/iki_read/c/private-iki_read.c b/level_3/iki_read/c/private-iki_read.c index 276c98a..b0354a8 100644 --- a/level_3/iki_read/c/private-iki_read.c +++ b/level_3/iki_read/c/private-iki_read.c @@ -38,10 +38,7 @@ extern "C" { f_status_t iki_read_process_buffer(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name) { f_status_t status = F_none; - - f_iki_variable_t variable = f_iki_variable_t_initialize; - f_iki_vocabulary_t vocabulary = f_iki_vocabulary_t_initialize; - f_iki_content_t content = f_iki_content_t_initialize; + iki_data_t iki_data = iki_data_t_initialize; if (main->parameters[iki_read_parameter_whole].result == f_console_result_found) { f_string_range_t buffer_range = macro_f_string_range_t_initialize(main->buffer.used); @@ -58,52 +55,48 @@ extern "C" { } if (main->mode == iki_read_mode_content) { - status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &variable, &vocabulary, &content, &content); + status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &iki_data, &iki_data.content); } else if (main->mode == iki_read_mode_literal) { - status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &variable, &vocabulary, &content, &variable); + status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &iki_data, &iki_data.variable); } else if (main->mode == iki_read_mode_object) { - status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &variable, &vocabulary, &content, &vocabulary); + status = iki_read_process_buffer_ranges_whole(main, arguments, file_name, buffer_range, &iki_data, &iki_data.vocabulary); } } else if (main->mode == iki_read_mode_total) { - status = iki_read_process_buffer_total(main, arguments, file_name, &variable, &vocabulary, &content); + status = iki_read_process_buffer_total(main, arguments, file_name, &iki_data); } else { f_string_range_t buffer_range = macro_f_string_range_t_initialize(main->buffer.used); status = iki_read_process_at(main, file_name, &buffer_range); - if (status == F_true) { - if (buffer_range.start > main->buffer.used) { - return F_data_not; - } - } - else if (status == F_data_not) { + if (status == F_true && buffer_range.start > main->buffer.used || status == F_data_not) { + macro_iki_data_t_delete_simple(iki_data); + return F_data_not; } if (main->mode == iki_read_mode_content) { - status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &variable, &vocabulary, &content, &content); + status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &iki_data, &iki_data.content); } else if (main->mode == iki_read_mode_literal) { - status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &variable, &vocabulary, &content, &variable); + status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &iki_data, &iki_data.variable); } else if (main->mode == iki_read_mode_object) { - status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &variable, &vocabulary, &content, &vocabulary); + status = iki_read_process_buffer_ranges(main, arguments, file_name, &buffer_range, &iki_data, &iki_data.vocabulary); } } - macro_f_iki_variable_t_delete_simple(variable); - macro_f_iki_vocabulary_t_delete_simple(vocabulary); - macro_f_iki_content_t_delete_simple(content); + macro_iki_data_t_delete_simple(iki_data); + return status; } #endif // _di_iki_read_process_buffer_ #ifndef _di_iki_read_process_buffer_ranges_ - f_status_t iki_read_process_buffer_ranges(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_string_range_t *buffer_range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_string_ranges_t *ranges) { + f_status_t iki_read_process_buffer_ranges(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_string_range_t *buffer_range, iki_data_t *iki_data, f_string_ranges_t *ranges) { f_status_t status = F_none; @@ -112,7 +105,7 @@ extern "C" { { f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, 0, 0, 0); - status = fl_iki_read(state, &main->buffer, buffer_range, variable, vocabulary, content); + status = fl_iki_read(state, &main->buffer, buffer_range, &iki_data->variable, &iki_data->vocabulary, &iki_data->content, &iki_data->delimits); } if (F_status_is_error(status)) { @@ -121,19 +114,23 @@ extern "C" { return status; } + for (f_array_length_t i = 0; i < iki_data->delimits.used; ++i) { + main->buffer.string[iki_data->delimits.array[i]] = f_iki_syntax_placeholder_s[0]; + } // for + const bool content_only = main->mode == iki_read_mode_content; - iki_read_substitutions_t substitutionss[variable->used]; + iki_read_substitutions_t substitutionss[iki_data->variable.used]; - memset(substitutionss, 0, sizeof(iki_read_substitutions_t) * variable->used); + memset(substitutionss, 0, sizeof(iki_read_substitutions_t) * iki_data->variable.used); if (main->mode == iki_read_mode_literal || main->mode == iki_read_mode_content) { - status = iki_read_substitutions_identify(main, arguments, file_name, vocabulary, substitutionss); + status = iki_read_substitutions_identify(main, arguments, file_name, &iki_data->vocabulary, substitutionss); if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "iki_read_substitutions_identify", F_true); - for (f_array_length_t i = 0; i < variable->used; ++i) { + for (f_array_length_t i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for @@ -160,7 +157,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_string_append_nulless", F_true); - for (f_array_length_t i = 0; i < variable->used; ++i) { + for (f_array_length_t i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for @@ -172,9 +169,9 @@ extern "C" { flockfile(main->output.to.stream); - for (j = 0; j < vocabulary->used; ++j) { + for (j = 0; j < iki_data->vocabulary.used; ++j) { - status = fl_string_dynamic_partial_compare(name, main->buffer, *buffer_range, vocabulary->array[j]); + status = fl_string_dynamic_partial_compare(name, main->buffer, *buffer_range, iki_data->vocabulary.array[j]); if (status == F_equal_to) { unmatched = F_false; @@ -184,7 +181,7 @@ extern "C" { } if (substitutionss[j].used) { - iki_read_substitutions_print(main, *variable, *content, *ranges, substitutionss[j], j, content_only); + iki_read_substitutions_print(main, *iki_data, *ranges, substitutionss[j], j, content_only); } else { f_print_dynamic_partial(main->buffer, ranges->array[j], main->output.to.stream); @@ -208,7 +205,7 @@ extern "C" { flockfile(main->output.to.stream); if (substitutionss[main->at].used) { - iki_read_substitutions_print(main, *variable, *content, *ranges, substitutionss[main->at], main->at, content_only); + iki_read_substitutions_print(main, *iki_data, *ranges, substitutionss[main->at], main->at, content_only); } else { f_print_dynamic_partial(main->buffer, ranges->array[main->at], main->output.to.stream); @@ -230,7 +227,7 @@ extern "C" { for (f_array_length_t i = 0; i < ranges->used; ++i) { if (substitutionss[i].used) { - iki_read_substitutions_print(main, *variable, *content, *ranges, substitutionss[i], i, content_only); + iki_read_substitutions_print(main, *iki_data, *ranges, substitutionss[i], i, content_only); } else { f_print_dynamic_partial(main->buffer, ranges->array[i], main->output.to.stream); @@ -248,7 +245,7 @@ extern "C" { status = F_data_not; } - for (f_array_length_t i = 0; i < variable->used; ++i) { + for (f_array_length_t i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for @@ -257,7 +254,7 @@ extern "C" { #endif // _di_iki_read_process_buffer_ranges_ #ifndef _di_iki_read_process_buffer_ranges_whole_ - f_status_t iki_read_process_buffer_ranges_whole(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, const f_string_range_t buffer_range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_string_ranges_t *ranges) { + f_status_t iki_read_process_buffer_ranges_whole(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, const f_string_range_t buffer_range, iki_data_t *iki_data, f_string_ranges_t *ranges) { f_status_t status = F_none; f_string_range_t range = buffer_range; @@ -265,7 +262,7 @@ extern "C" { { f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, 0, 0, 0); - status = fl_iki_read(state, &main->buffer, &range, variable, vocabulary, content); + status = fl_iki_read(state, &main->buffer, &range, &iki_data->variable, &iki_data->vocabulary, &iki_data->content, &iki_data->delimits); } if (F_status_is_error(status)) { @@ -274,7 +271,11 @@ extern "C" { return status; } - if (!variable->used) { + for (f_array_length_t i = 0; i < iki_data->delimits.used; ++i) { + main->buffer.string[iki_data->delimits.array[i]] = f_iki_syntax_placeholder_s[0]; + } // for + + if (!iki_data->variable.used) { fll_print_dynamic_partial(main->buffer, buffer_range, main->output.to.stream); return F_none; @@ -282,17 +283,17 @@ extern "C" { const bool content_only = main->mode == iki_read_mode_content; - iki_read_substitutions_t substitutionss[variable->used]; + iki_read_substitutions_t substitutionss[iki_data->variable.used]; - memset(substitutionss, 0, sizeof(iki_read_substitutions_t) * variable->used); + memset(substitutionss, 0, sizeof(iki_read_substitutions_t) * iki_data->variable.used); if (main->mode == iki_read_mode_literal || main->mode == iki_read_mode_content) { - status = iki_read_substitutions_identify(main, arguments, file_name, vocabulary, substitutionss); + status = iki_read_substitutions_identify(main, arguments, file_name, &iki_data->vocabulary, substitutionss); if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "iki_read_substitutions_identify", F_true); - for (f_array_length_t i = 0; i < variable->used; ++i) { + for (f_array_length_t i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for @@ -324,6 +325,7 @@ extern "C" { if (status == F_equal_to) { name_missed = F_false; + break; } } // for @@ -332,7 +334,8 @@ extern "C" { macro_f_memory_structure_increment(status, names, 1, F_iki_default_allocation_step_d, macro_f_string_dynamics_t_resize, F_array_too_large); if (F_status_is_error(status)) { - fll_error_print(main->error, F_status_set_fine(status), "iki_read_process_buffer_ranges_whole", F_true); + fll_error_print(main->error, F_status_set_fine(status), "macro_f_memory_structure_increment", F_true); + break; } @@ -340,6 +343,7 @@ extern "C" { if (F_status_is_error(status)) { fll_error_print(main->error, F_status_set_fine(status), "f_string_append_nulless", F_true); + break; } @@ -348,7 +352,7 @@ extern "C" { } // for if (F_status_is_error(status)) { - for (i = 0; i < variable->used; ++i) { + for (i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for @@ -361,7 +365,7 @@ extern "C" { f_array_length_t i = buffer_range.start; f_array_length_t j = 0; f_array_length_t k = 0; - f_array_length_t stop = variable->used; + f_array_length_t stop = iki_data->variable.used; range = buffer_range; name_range.start = 0; @@ -370,16 +374,16 @@ extern "C" { while (i <= range.stop && j < stop) { - if (i < variable->array[j].start) { + if (i < iki_data->variable.array[j].start) { range.start = i; - range.stop = variable->array[j].start - 1; + range.stop = iki_data->variable.array[j].start - 1; f_print_dynamic_partial(main->buffer, range, main->output.to.stream); - range.start = variable->array[j].stop + 1; + range.start = iki_data->variable.array[j].stop + 1; range.stop = buffer_range.stop; - i = variable->array[j].start; + i = iki_data->variable.array[j].start; } if (names.used) { @@ -388,7 +392,7 @@ extern "C" { for (k = 0; k < names.used; ++k) { name_range.stop = names.array[k].used - 1; - status = fl_string_dynamic_partial_compare(main->buffer, names.array[k], vocabulary->array[j], name_range); + status = fl_string_dynamic_partial_compare(main->buffer, names.array[k], iki_data->vocabulary.array[j], name_range); if (status == F_equal_to) { name_missed = F_false; @@ -398,15 +402,15 @@ extern "C" { if (name_missed) { if (substitutionss[j].used) { - iki_read_substitutions_print(main, *variable, *content, *variable, substitutionss[j], j, F_false); + iki_read_substitutions_print(main, *iki_data, iki_data->variable, substitutionss[j], j, F_false); } else { - f_print_dynamic_partial(main->buffer, variable->array[j], main->output.to.stream); + f_print_dynamic_partial(main->buffer, iki_data->variable.array[j], main->output.to.stream); } } else { if (substitutionss[j].used) { - iki_read_substitutions_print(main, *variable, *content, *ranges, substitutionss[j], j, content_only); + iki_read_substitutions_print(main, *iki_data, *ranges, substitutionss[j], j, content_only); } else { f_print_dynamic_partial(main->buffer, ranges->array[j], main->output.to.stream); @@ -415,14 +419,14 @@ extern "C" { } else { if (substitutionss[j].used) { - iki_read_substitutions_print(main, *variable, *content, *ranges, substitutionss[j], j, content_only); + iki_read_substitutions_print(main, *iki_data, *ranges, substitutionss[j], j, content_only); } else { f_print_dynamic_partial(main->buffer, ranges->array[j], main->output.to.stream); } } - i = variable->array[j].stop + 1; + i = iki_data->variable.array[j].stop + 1; ++j; } // while @@ -434,17 +438,18 @@ extern "C" { funlockfile(main->output.to.stream); } - for (f_array_length_t i = 0; i < variable->used; ++i) { + for (f_array_length_t i = 0; i < iki_data->variable.used; ++i) { macro_iki_read_substitutions_t_delete_simple(substitutionss[i]); } // for macro_f_string_dynamics_t_delete_simple(names); + return F_none; } #endif // _di_iki_read_process_buffer_ranges_whole_ #ifndef _di_iki_read_process_buffer_total_ - f_status_t iki_read_process_buffer_total(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content) { + f_status_t iki_read_process_buffer_total(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, iki_data_t *iki_data) { f_status_t status = F_none; f_string_range_t range = macro_f_string_range_t_initialize(main->buffer.used); @@ -467,7 +472,7 @@ extern "C" { { f_state_t state = macro_f_state_t_initialize(iki_read_common_allocation_large_d, iki_read_common_allocation_small_d, 0, 0, 0, 0, 0); - status = fl_iki_read(state, &main->buffer, &range, variable, vocabulary, content); + status = fl_iki_read(state, &main->buffer, &range, &iki_data->variable, &iki_data->vocabulary, &iki_data->content, &iki_data->delimits); } if (F_status_is_error(status)) { @@ -476,6 +481,10 @@ extern "C" { return status; } + for (f_array_length_t i = 0; i < iki_data->delimits.used; ++i) { + main->buffer.string[iki_data->delimits.array[i]] = f_iki_syntax_placeholder_s[0]; + } // for + f_array_length_t total = 0; if (main->parameters[iki_read_parameter_name].result == f_console_result_additional) { @@ -513,9 +522,9 @@ extern "C" { range.stop = name.used - 1; - for (j = 0; j < vocabulary->used; ++j) { + for (j = 0; j < iki_data->vocabulary.used; ++j) { - status = fl_string_dynamic_partial_compare(name, main->buffer, range, vocabulary->array[j]); + status = fl_string_dynamic_partial_compare(name, main->buffer, range, iki_data->vocabulary.array[j]); if (status == F_equal_to) ++total; } // for @@ -524,7 +533,7 @@ extern "C" { macro_f_string_dynamic_t_delete_simple(name); } else { - total = variable->used; + total = iki_data->variable.used; } // if that at position is within the actual total, then the total at the given position is 1, otherwise is 0. @@ -596,7 +605,7 @@ extern "C" { #endif // _di_iki_read_substitutions_identify_ #ifndef _di_iki_read_substitutions_print_ - void iki_read_substitutions_print(iki_read_main_t * const main, const f_iki_variable_t variable, const f_iki_content_t content, const f_string_ranges_t ranges, const iki_read_substitutions_t substitutions, const f_array_length_t index, const bool content_only) { + void iki_read_substitutions_print(iki_read_main_t * const main, const iki_data_t iki_data, const f_string_ranges_t ranges, const iki_read_substitutions_t substitutions, const f_array_length_t index, const bool content_only) { f_status_t status = F_none; @@ -609,7 +618,7 @@ extern "C" { range.stop = substitutions.array[i].replace.used - 1; - status = fl_string_dynamic_partial_compare(substitutions.array[i].replace, main->buffer, range, content.array[index]); + status = fl_string_dynamic_partial_compare(substitutions.array[i].replace, main->buffer, range, iki_data.content.array[index]); if (status == F_equal_to) break; } // for @@ -618,15 +627,15 @@ extern "C" { f_print_dynamic(substitutions.array[i].with, main->output.to.stream); } else { - range.start = variable.array[index].start; - range.stop = content.array[index].start - 1; + range.start = iki_data.variable.array[index].start; + range.stop = iki_data.content.array[index].start - 1; f_print_dynamic_partial(main->buffer, range, main->output.to.stream); f_print_dynamic(substitutions.array[i].with, main->output.to.stream); - range.start = content.array[index].stop + 1; - range.stop = variable.array[index].stop; + range.start = iki_data.content.array[index].stop + 1; + range.stop = iki_data.variable.array[index].stop; f_print_dynamic_partial(main->buffer, range, main->output.to.stream); } diff --git a/level_3/iki_read/c/private-iki_read.h b/level_3/iki_read/c/private-iki_read.h index 4f01d69..ec1aa50 100644 --- a/level_3/iki_read/c/private-iki_read.h +++ b/level_3/iki_read/c/private-iki_read.h @@ -67,12 +67,8 @@ extern "C" { * The name of the file being processed. * @param buffer_range * The range within the buffer to process. - * @param variable - * The ranges representing a variable. - * @param vocabulary - * The ranges representing a vocabulary. - * @param content - * The ranges representing content. + * @param iki_data + * The IKI data. * @param ranges * The ranges to print when matched. * Should be one of: variable, vocabulary, or content. @@ -84,7 +80,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_iki_read_process_buffer_ranges_ - extern f_status_t iki_read_process_buffer_ranges(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_string_range_t *buffer_range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_string_ranges_t *ranges) F_attribute_visibility_internal_d; + extern f_status_t iki_read_process_buffer_ranges(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_string_range_t *buffer_range, iki_data_t *iki_data, f_string_ranges_t *ranges) F_attribute_visibility_internal_d; #endif // _di_iki_read_process_buffer_ranges_ /** @@ -100,12 +96,8 @@ extern "C" { * The name of the file being processed. * @param buffer_range * The range within the buffer to process. - * @param variable - * The ranges representing a variable. - * @param vocabulary - * The ranges representing a vocabulary. - * @param content - * The ranges representing content. + * @param iki_data + * The IKI data. * @param ranges * The ranges to print when matched. * Should be one of: variable, vocabulary, or content. @@ -117,7 +109,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_iki_read_process_buffer_ranges_whole_ - extern f_status_t iki_read_process_buffer_ranges_whole(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, const f_string_range_t buffer_range, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content, f_string_ranges_t *ranges) F_attribute_visibility_internal_d; + extern f_status_t iki_read_process_buffer_ranges_whole(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, const f_string_range_t buffer_range, iki_data_t *iki_data, f_string_ranges_t *ranges) F_attribute_visibility_internal_d; #endif // _di_iki_read_process_buffer_ranges_whole_ /** @@ -129,12 +121,8 @@ extern "C" { * The console arguments passed to the program. * @param file_name * The name of the file being processed. - * @param variable - * The ranges representing a variable. - * @param vocabulary - * The ranges representing a vocabulary. - * @param content - * The ranges representing content. + * @param iki_data + * The IKI data. * * @return * F_none on success. @@ -142,7 +130,7 @@ extern "C" { * Status codes (with error bit) are returned on any problem. */ #ifndef _di_iki_read_process_buffer_total_ - extern f_status_t iki_read_process_buffer_total(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, f_iki_variable_t *variable, f_iki_vocabulary_t *vocabulary, f_iki_content_t *content) F_attribute_visibility_internal_d; + extern f_status_t iki_read_process_buffer_total(iki_read_main_t * const main, const f_console_arguments_t *arguments, const f_string_t file_name, iki_data_t *iki_data) F_attribute_visibility_internal_d; #endif // _di_iki_read_process_buffer_total_ /** @@ -173,10 +161,8 @@ extern "C" { * * @param main * The main program data. - * @param variable - * The ranges representing a variable. - * @param content - * The ranges representing a content. + * @param iki_data + * The IKI data. * @param ranges * The ranges containing the desired range to print as specified by index. * @param substitutions @@ -188,7 +174,7 @@ extern "C" { * Set to FALSE to print the entire variable when printing substituted text. */ #ifndef _di_iki_read_substitutions_print_ - extern void iki_read_substitutions_print(iki_read_main_t * const main, const f_iki_variable_t variable, const f_iki_content_t content, const f_string_ranges_t ranges, const iki_read_substitutions_t substitutions, const f_array_length_t index, const bool content_only) F_attribute_visibility_internal_d; + extern void iki_read_substitutions_print(iki_read_main_t * const main, const iki_data_t iki_data, const f_string_ranges_t ranges, const iki_read_substitutions_t substitutions, const f_array_length_t index, const bool content_only) F_attribute_visibility_internal_d; #endif // _di_iki_read_substitutions_print_ #ifdef __cplusplus diff --git a/level_3/iki_write/c/iki_write.c b/level_3/iki_write/c/iki_write.c index a906ce0..ce54389 100644 --- a/level_3/iki_write/c/iki_write.c +++ b/level_3/iki_write/c/iki_write.c @@ -261,18 +261,18 @@ extern "C" { } } - uint8_t quote = F_iki_syntax_quote_double_s; + uint8_t quote = f_iki_syntax_quote_double_s[0]; if (F_status_is_error_not(status)) { if (main->parameters[iki_write_parameter_double].result == f_console_result_found) { if (main->parameters[iki_write_parameter_single].result == f_console_result_found) { if (main->parameters[iki_write_parameter_double].location < main->parameters[iki_write_parameter_single].location) { - quote = F_iki_syntax_quote_single_s; + quote = f_iki_syntax_quote_single_s[0]; } } } else if (main->parameters[iki_write_parameter_single].result == f_console_result_found) { - quote = F_iki_syntax_quote_single_s; + quote = f_iki_syntax_quote_single_s[0]; } } diff --git a/level_3/iki_write/c/private-iki_write.c b/level_3/iki_write/c/private-iki_write.c index c07c395..ac5b3b2 100644 --- a/level_3/iki_write/c/private-iki_write.c +++ b/level_3/iki_write/c/private-iki_write.c @@ -56,7 +56,7 @@ extern "C" { return F_status_set_error(F_failure); } - fl_print_format("%Q%c%c%Q%c", output.stream, object, F_iki_syntax_separator_s, quote, *escaped, quote); + fl_print_format("%Q%c%c%Q%c", output.stream, object, f_iki_syntax_separator_s[0], quote, *escaped, quote); return F_none; } diff --git a/specifications/fss-000C.txt b/specifications/fss-000C.txt index 8359b56..9b79377 100644 --- a/specifications/fss-000C.txt +++ b/specifications/fss-000C.txt @@ -1,62 +1,20 @@ # fss-0002 -Featureless Settings Specification: 000C - Iki Text: - IKI is an unstructured WIKI-like syntax meant to be simpler than WIKI syntax. - This FSS specification represents a plain text file not following any special FSS structure but instead supports the IKI syntax. - The IKI syntax may be used in any FSS specification and the specific vocabulary is defined by appending +Featureless Settings Specification: 000C - IKI Text: + The IKI specifications are separate specifications from the FSS specification. + This is simply a more formal way to designate that this format utilizes IKI syntax. - For compatibility with the FSS terminology, the Vocabulary Name is to be considered the Object and the Vocabulary value is to be considered the Content. - The Content column, therefore, exists as a single Column (which is the entire Vocabulary value). + The IKI syntax may be used in any FSS specification. + The IKI format may be added to the. - There is no requirement for any specific IKI vocabulary by this standard only that the given syntax is supported. - To specify the IKI vocabulary being used append the IKI vocabulary header immediately after the fss header like such: "# fss-000c iki-0001". - - The IKI syntax provides a vocabulary name with specific context associated with it followed by quoted code that is represented by the given vocabulary name. - The vocabulary represents a list of allowed object names that may also have specific contextual meaning defined by a given IKI specification. - - When IKI is encapsulated inside any FSS format, the parent FSS format rules apply and must take precedence. - Therefore additional escaping may be required. - As for this FSS format (FSS-000C), there is no structure and therefore only the IKI syntax rules apply. - - The IKI format will use IKI-0000 to represent an IKI with no explicitly defined vocabulary. - Whereas IKI-0001 and beyond represent a specific IKI vocabulary. - - Whitespace, non-word (and non "_", "-", "+") character punctuations, or the start of file must exist before any valid variable name. - Whitespace and non-word (and non "_", "-", "+") character punctuations may not exist as part of the variable name. - The only Unicode dash-like characters allowed as a "dash" are those intended to connect, such as the Unicode hyphens (U+2010 and U+2011). - - Unicode punctuation connector characters are supported just like "_", except when they connect outside the current line (such as U+FE33 "︳"). - Unicode invisible punctuations (such as invisible plus: U+2064) are not considered a punctuations in this standard (because they a zero-width characters), therefore they are not to be considered a valid '_', '-', or '+' Unicode equivalents. - - Key\: - \o = any printable word character, including "_", "-", "+" (and Unicode equivalents). - \c = any character, including whitespace and non-printing, and any delimited quote (used as the opening quote) or a any quote (undelimited) not used as the opening quote. - \q = either a single quote (') or a double quote ("). - \x = any character. - \W = any non-word character, discluding "_", "-", "+" (and Unicode equivalents). - * = 0 or more occurrences. - ~ = one or more occurrences, or 0 if at start of file. - - Structure\: - \x*\W~\o:\q\c\q + See the iki.txt specification for details on the IKI specifications. Example\: # fss-000c iki-0000 - This is my sentence, anything can go here but sometimes I want to emphasis:"emphasize some text". - - Other times I want to render a url such as this example url: url:'http://www.example.com/url with space/'. - - There are no comments, except for maybe the FSS header (which would not resolve to any IKI syntax anyway). + This is a emphasis:"formal example" utilizing the FSS headers. - Quotes may be included, such as: code:"const char *string = \"My \\\"quoted\\\" C string.\";". - - Objects would be\: - 1) emphasis - 2) url - 3) code + Example\: + # iki-0000 - Contents would be\: - 1.1) emphasize some text - 2.1) http://www.example.com/url with space/ - 3.1) const char *string = "My \"quoted\" C string."; + This is a emphasis:"informal example" utilizing the IKI headers. diff --git a/specifications/iki.txt b/specifications/iki.txt index edee1ac..8b7ff86 100644 --- a/specifications/iki.txt +++ b/specifications/iki.txt @@ -1,10 +1,12 @@ # fss-0002 IKI Specifications: - IKI is an unstructured WIKI-like syntax meant to be simpler than WIKI syntax. + IKI is a minimally structured WIKI-like syntax meant to be simpler than WIKI syntax. - The IKI syntax provides a vocabulary name with specific context associated with it followed by quoted code that is represented by the given vocabulary name. + The IKI syntax provides a vocabulary name (with specific context associated with it) followed by quoted code that is associated with the given vocabulary name. The vocabulary represents a list of allowed object names that may also have specific contextual meaning defined by a given IKI specification. + The variable name is considered the "Object". + The variable variable is considered the "Content". The IKI format will use IKI-0000 to represent an IKI with no explicitly defined vocabulary. Whereas IKI-0001 and beyond represent a specific IKI vocabulary. @@ -13,6 +15,8 @@ IKI Specifications: Whitespace and non-word (and non "_", "-", "+") character punctuations may not exist as part of the variable name. The only Unicode dash-like characters allowed as a "dash" are those intended to connect, such as the Unicode hyphens (U+2010 and U+2011). + Any valid IKI data may be escaped to make it treated as non-IKI data by prepending a backslash "\" before the colon ":" that is before the opening quote (single or double). + Unicode punctuation connector characters are supported just like "_", except when they connect outside the current line (such as U+FE33 "︳"). Unicode invisible punctuations (such as invisible plus: U+2064) are not considered a punctuations in this standard (because they a zero-width characters), therefore they are not to be considered a valid '_', '-', or '+' Unicode equivalents. @@ -22,11 +26,17 @@ IKI Specifications: \q = either a single quote (') or a double quote ("). \x = any character. \W = any non-word character, discluding "_", "-", "+" (and Unicode equivalents). + \e = an optional escape sequence of any number of backslashes, such as "\". * = 0 or more occurrences. ~ = one or more occurrences, or 0 if at start of file. + Before Structure\: + \x*\W~\*:* + Structure\: - \x*\W~\o:\q\c\q + \o\e:\q\c\q + + After Structure\: Example\: # fss-000c iki-0000 @@ -39,6 +49,8 @@ IKI Specifications: Quotes may be included, such as: code:"const char *string = \"My \\\"quoted\\\" C string.\";". + The following emphasis\:"is escaped to not be treated as IKI data". + Objects would be\: 1) emphasis 2) url -- 1.8.3.1