From: Kevin Day Date: Sat, 25 Dec 2021 22:38:31 +0000 (-0600) Subject: Feature: Add support for "context" IKI in Fakefiles. X-Git-Tag: 0.5.8~158 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=d14efd577f7a3f77404d0be0c8f5e723fdb70d9b;p=fll Feature: Add support for "context" IKI in Fakefiles. This updates the IKI-0002 specification to support "context". This allows for color context and ideally any future context to make software more accessible. Update the existing testfiles to utilize this context. --- diff --git a/level_0/f_iki/c/iki-common.c b/level_0/f_iki/c/iki-common.c index 6d9609b..90d6bf4 100644 --- a/level_0/f_iki/c/iki-common.c +++ b/level_0/f_iki/c/iki-common.c @@ -27,6 +27,7 @@ extern "C" { #endif // _di_iki_vocabulary_0001_s_ #ifndef _di_iki_vocabulary_0002_s_ + const f_string_t f_iki_vocabulary_0002_context_s = F_iki_vocabulary_0002_context_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_ diff --git a/level_0/f_iki/c/iki-common.h b/level_0/f_iki/c/iki-common.h index 4ec03d4..67160e7 100644 --- a/level_0/f_iki/c/iki-common.h +++ b/level_0/f_iki/c/iki-common.h @@ -75,12 +75,15 @@ extern "C" { #endif // _di_iki_vocabulary_0001_ #ifndef _di_iki_vocabulary_0002_ + #define F_iki_vocabulary_0002_context_s "context" #define F_iki_vocabulary_0002_define_s "define" #define F_iki_vocabulary_0002_parameter_s "parameter" + #define F_iki_vocabulary_0002_context_s_length 7 #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_context_s; 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_ diff --git a/level_0/f_memory/data/build/testfile b/level_0/f_memory/data/build/testfile index c9af589..81aa652 100644 --- a/level_0/f_memory/data/build/testfile +++ b/level_0/f_memory/data/build/testfile @@ -27,6 +27,6 @@ main: not_created: print - print Faled to test due to being unable to find either a shared or static test binary to perform tests. + print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" exit failure diff --git a/level_0/f_type_array/data/build/testfile b/level_0/f_type_array/data/build/testfile index f67d808..44898dd 100644 --- a/level_0/f_type_array/data/build/testfile +++ b/level_0/f_type_array/data/build/testfile @@ -27,6 +27,6 @@ main: not_created: print - print Faled to test due to being unable to find either a shared or static test binary to perform tests. + print context:"error"Failed to test due to being unable to find either a shared or static test binary to perform tests. context:"error" exit failure diff --git a/level_3/fake/c/private-common.c b/level_3/fake/c/private-common.c index 6c4c2ad..76063e3 100644 --- a/level_3/fake/c/private-common.c +++ b/level_3/fake/c/private-common.c @@ -257,6 +257,18 @@ extern "C" { const f_string_t fake_make_skeleton_content_settings_s = FAKE_make_skeleton_content_settings_s; #endif // _di_fake_skeleton_content_ +#ifndef _di_fake_make_context_ + const f_string_t fake_make_context_reset_s = FAKE_make_context_reset_s; + const f_string_t fake_make_context_warning_s = FAKE_make_context_warning_s; + const f_string_t fake_make_context_error_s = FAKE_make_context_error_s; + const f_string_t fake_make_context_title_s = FAKE_make_context_title_s; + const f_string_t fake_make_context_notable_s = FAKE_make_context_notable_s; + const f_string_t fake_make_context_important_s = FAKE_make_context_important_s; + const f_string_t fake_make_context_standout_s = FAKE_make_context_standout_s; + const f_string_t fake_make_context_success_s = FAKE_make_context_success_s; + const f_string_t fake_make_context_normal_s = FAKE_make_context_normal_s; +#endif // _di_fake_make_context_ + #ifndef _di_fake_signal_received_ f_status_t fake_signal_received(fake_main_t * const main) { diff --git a/level_3/fake/c/private-common.h b/level_3/fake/c/private-common.h index e45d32c..e2c9bca 100644 --- a/level_3/fake/c/private-common.h +++ b/level_3/fake/c/private-common.h @@ -1234,6 +1234,38 @@ extern "C" { extern const f_string_t fake_make_skeleton_content_settings_s; #endif // _di_fake_skeleton_content_ +#ifndef _di_fake_make_context_ + #define FAKE_make_context_reset_s "reset" + #define FAKE_make_context_warning_s "warning" + #define FAKE_make_context_error_s "error" + #define FAKE_make_context_title_s "title" + #define FAKE_make_context_notable_s "notable" + #define FAKE_make_context_important_s "important" + #define FAKE_make_context_standout_s "standout" + #define FAKE_make_context_success_s "success" + #define FAKE_make_context_normal_s "normal" + + #define fake_make_context_reset_s_length 5 + #define fake_make_context_warning_s_length 7 + #define fake_make_context_error_s_length 5 + #define fake_make_context_title_s_length 5 + #define fake_make_context_notable_s_length 7 + #define fake_make_context_important_s_length 9 + #define fake_make_context_standout_s_length 8 + #define fake_make_context_success_s_length 7 + #define fake_make_context_normal_s_length 5 + + extern const f_string_t fake_make_context_reset_s; + extern const f_string_t fake_make_context_warning_s; + extern const f_string_t fake_make_context_error_s; + extern const f_string_t fake_make_context_title_s; + extern const f_string_t fake_make_context_notable_s; + extern const f_string_t fake_make_context_important_s; + extern const f_string_t fake_make_context_standout_s; + extern const f_string_t fake_make_context_success_s; + extern const f_string_t fake_make_context_normal_s; +#endif // _di_fake_make_context_ + /** * Check to see if a process signal is received. * diff --git a/level_3/fake/c/private-make-operate.c b/level_3/fake/c/private-make-operate.c index 1351a9b..c401966 100644 --- a/level_3/fake/c/private-make-operate.c +++ b/level_3/fake/c/private-make-operate.c @@ -152,9 +152,11 @@ extern "C" { return; } + const f_string_static_t vocabulary_context = macro_f_string_static_t_initialize(F_iki_vocabulary_0002_context_s, F_iki_vocabulary_0002_context_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_context = macro_f_string_range_t_initialize(F_iki_vocabulary_0002_context_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); @@ -168,9 +170,10 @@ extern "C" { f_string_range_t range = f_string_range_t_initialize; f_string_map_multis_t *parameter = &data_make->setting_make.parameter; + // 1 = is parameter, 2 = is defined, 3 = is context. + uint8_t is = 0; + bool unmatched = F_true; - bool parameter_is = F_false; - bool define_is = F_false; f_array_length_t i = 0; f_array_length_t j = 0; @@ -334,8 +337,7 @@ extern "C" { for (j = 0, previous = iki_variable.array[0].start; j < iki_variable.used; ++j) { - parameter_is = F_false; - define_is = F_false; + is = 0; if (previous + 1 < iki_variable.array[j].start) { range.start = previous + 1; @@ -353,13 +355,20 @@ extern "C" { *status = fl_string_dynamic_partial_compare(vocabulary_define, data_make->buffer, range_define, iki_vocabulary.array[j]); if (*status == F_equal_to) { - define_is = F_true; + is = 2; } else if (*status == F_equal_to_not) { *status = fl_string_dynamic_partial_compare(vocabulary_parameter, data_make->buffer, range_parameter, iki_vocabulary.array[j]); if (*status == F_equal_to) { - parameter_is = F_true; + is = 1; + } + else if (*status == F_equal_to_not) { + *status = fl_string_dynamic_partial_compare(vocabulary_context, data_make->buffer, range_context, iki_vocabulary.array[j]); + + if (*status == F_equal_to) { + is = 3; + } } } @@ -369,7 +378,7 @@ extern "C" { break; } - if (parameter_is) { + if (is == 1) { unmatched = F_true; // Check against reserved parameter names and if matches use them instead. @@ -547,11 +556,22 @@ extern "C" { } } } - else if (define_is && data_make->setting_make.load_build) { - *status = fake_make_operate_expand_environment(data_make, quotes.array[i], iki_content.array[j], arguments); + else if (is == 2) { + if (data_make->setting_make.load_build) { + *status = fake_make_operate_expand_environment(data_make, quotes.array[i], iki_content.array[j], arguments); + + if (F_status_is_error(*status)) { + fll_error_print(data_make->error, F_status_set_fine(*status), "fake_make_operate_expand_environment", F_true); + + break; + } + } + } + else if (is == 3) { + *status = fake_make_operate_expand_context(data_make, quotes.array[i], iki_content.array[j], arguments); if (F_status_is_error(*status)) { - fll_error_print(data_make->error, F_status_set_fine(*status), "fake_make_operate_expand_environment", F_true); + fll_error_print(data_make->error, F_status_set_fine(*status), "fake_make_operate_expand_context", F_true); break; } @@ -960,14 +980,90 @@ extern "C" { macro_f_string_dynamic_t_delete_simple(value); - if (F_status_is_error_not(status)) { - return F_true; - } + if (F_status_is_error(status)) return status; - return status; + return F_true; } #endif // _di_fake_make_operate_expand_build_ +#ifndef _di_fake_make_operate_expand_context_ + f_status_t fake_make_operate_expand_context(fake_make_data_t * const data_make, const f_fss_quote_t quoted, const f_string_range_t range_name, f_string_dynamics_t *arguments) { + + f_status_t status = F_none; + const f_string_static_t *context = 0; + + const f_string_t context_name[] = { + fake_make_context_reset_s, + fake_make_context_warning_s, + fake_make_context_error_s, + fake_make_context_title_s, + fake_make_context_notable_s, + fake_make_context_important_s, + fake_make_context_standout_s, + fake_make_context_success_s, + fake_make_context_normal_s, + }; + + const f_array_length_t context_length[] = { + fake_make_context_reset_s_length, + fake_make_context_warning_s_length, + fake_make_context_error_s_length, + fake_make_context_title_s_length, + fake_make_context_notable_s_length, + fake_make_context_important_s_length, + fake_make_context_standout_s_length, + fake_make_context_success_s_length, + fake_make_context_normal_s_length, + }; + + const f_color_set_t context_value[] = { + data_make->main->context.set.reset, + data_make->main->context.set.warning, + data_make->main->context.set.error, + data_make->main->context.set.title, + data_make->main->context.set.notable, + data_make->main->context.set.important, + data_make->main->context.set.standout, + data_make->main->context.set.success, + data_make->main->context.set.normal, + }; + + for (f_array_length_t i = 0; i < 9; ++i) { + + if (fl_string_dynamic_partial_compare_string(context_name[i], data_make->buffer, context_length[i], range_name) == F_equal_to) { + context = context_value[i].before; + + break; + } + } // for + + if (context) { + if (quoted) { + status = f_string_dynamic_append_nulless(*context, &arguments->array[arguments->used]); + } + else { + status = f_string_dynamics_increase_by(F_memory_default_allocation_small_d, arguments); + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append_nulless(*context, &arguments->array[arguments->used]); + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_terminate_after(&arguments->array[arguments->used]); + + if (F_status_is_error_not(status)) { + ++arguments->used; + } + } + } + } + + if (F_status_is_error(status)) return status; + } + + return F_true; + } +#endif // _di_fake_make_operate_expand_context_ + #ifndef _di_fake_make_operate_expand_environment_ f_status_t fake_make_operate_expand_environment(fake_make_data_t * const data_make, const f_fss_quote_t quoted, const f_string_range_t range_name, f_string_dynamics_t *arguments) { @@ -1019,11 +1115,9 @@ extern "C" { macro_f_string_dynamic_t_delete_simple(value); - if (F_status_is_error_not(status)) { - return F_true; - } + if (F_status_is_error(status)) return status; - return status; + return F_true; } #endif // _di_fake_make_operate_expand_environment_ diff --git a/level_3/fake/c/private-make-operate.h b/level_3/fake/c/private-make-operate.h index 6c1d2d9..b9bc3dc 100644 --- a/level_3/fake/c/private-make-operate.h +++ b/level_3/fake/c/private-make-operate.h @@ -59,6 +59,30 @@ extern "C" { #endif // _di_fake_make_operate_expand_ /** + * Perform the expand operation, specifically for the context variables. + * + * Unknown or unsupported context variables are expanded into an empty string. + * + * @param data_make + * All make related setting data, including data from the fakefile and the build settings file. + * @param quoted + * The quoted associated with the content. + * @param range_name + * The range representing the variable content name string within the data_make->buffer. + * @param arguments + * The expanded arguments. + * + * @return + * F_true on success and match expanded. + * F_false on no matches to expand. + * + * Status codes (with error bit) are returned on any problem. + */ +#ifndef _di_fake_make_operate_expand_context_ + extern f_status_t fake_make_operate_expand_context(fake_make_data_t * const data_make, const f_fss_quote_t quoted, const f_string_range_t range_name, f_string_dynamics_t *arguments) F_attribute_visibility_internal_d; +#endif // _di_fake_make_operate_expand_context_ + +/** * Perform the expand operation, specifically for the environment variables. * * @param data_make diff --git a/level_3/fake/documents/fakefile.txt b/level_3/fake/documents/fakefile.txt index da10b2c..cca780b 100644 --- a/level_3/fake/documents/fakefile.txt +++ b/level_3/fake/documents/fakefile.txt @@ -402,14 +402,26 @@ Fakefile Documentation: The remaining Content must be a path to the file. The IKI vocabulary context is supported and is further clarified as follows\: + - context\: + The context Object represents a name representing simple context or complex combination of context. + Context should wrap some text such that if some text begins with some context, the context should be reset at the end. + The most basic context is color context, such as: context:"notice" This is emphasized text context:"reset". + + The use of IKI in this way is acceptable but it is not perfect. + IKI is not designed to be a replacement to markup. + The markup Example vs the IKI context:"notable" Example context:"notable" has obvious differences in the spaces. + The IKI by design cannot be used like this: context:"notable"Examplecontext:"notable". + + This context will respect the programs ++light, ++dark, and ++no_color parameters. + - define\: - The define object represents environment variables passed to the program or created by the program. + The define Object represents environment variables passed to the program or created by the program. The value represents the environment variable name and is case-sensitive. This IKI variable gets substituted with the environment variable's value or NULL if not defined. The "settings" list supports declaring custom environment variables (which overwrite any existing environment variable with the same name). - parameter\: - The parameter object represents a variable that is to be substituted. + The parameter Object represents a variable that is to be substituted. The value represents the variable name and is case-sensitive. This IKI variable gets substituted with the value defined in the "settings" list or NULL if not defined. The value may contain an additional ":option" or ":value" at the end of the name to designate getting only part of the parameter. diff --git a/level_3/fake/specifications/fakefile.txt b/level_3/fake/specifications/fakefile.txt index e0ec3da..e6d935d 100644 --- a/level_3/fake/specifications/fakefile.txt +++ b/level_3/fake/specifications/fakefile.txt @@ -17,8 +17,9 @@ Fakefile Specification: The reserved Settings Section does not support IKI variable substitution. The IKI-0002 vocabulary context is further clarified as follows\: - - define: the value must be a case-sensitive valid environment variable name (alpha-numeric or underscore, but no leading digits). - - parameter: the value is a case-sensitive variable name. + - context: The value is case-sensitive variable name. + - define: The value must be a case-sensitive valid environment variable name (alpha-numeric or underscore, but no leading digits). + - parameter: The value is a case-sensitive variable name. - Many parameters also support ":option" and ":value" appended at the end of the value. The reserved Section Objects are\: