From: Kevin Day Date: Thu, 17 Feb 2022 03:52:16 +0000 (-0600) Subject: Update: Move hardcoded strings into a const static string for f_color. X-Git-Tag: 0.5.8~38 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=af25e2ebc37e52e0d3aca8fb446aebe9163d11e6;p=fll Update: Move hardcoded strings into a const static string for f_color. --- diff --git a/level_0/f_color/c/color.c b/level_0/f_color/c/color.c index 34eea15..6433c35 100644 --- a/level_0/f_color/c/color.c +++ b/level_0/f_color/c/color.c @@ -12,9 +12,9 @@ extern "C" { // Switch to the appropriate terminal color mode. { - char *environment = getenv("TERM"); // @todo make these strings static! + char *environment = getenv(f_color_terminal_name_s.string); - if (!environment || strncmp(environment, "linux", 6) == 0) { + if (!environment || strncmp(environment, f_color_terminal_value_linux_s.string, f_color_terminal_value_linux_s.used) == 0) { macro_f_color_t_set_linux(context->list); } else { diff --git a/level_0/f_color/c/color/common.c b/level_0/f_color/c/color/common.c index bf7c137..1a81e38 100644 --- a/level_0/f_color/c/color/common.c +++ b/level_0/f_color/c/color/common.c @@ -49,6 +49,11 @@ extern "C" { const f_string_static_t f_color_string_code_bright_white_bg_s = macro_f_string_static_t_initialize(F_color_string_code_bright_white_bg_s, 0, F_color_string_code_bright_white_bg_s_length); #endif // _di_f_color_strings_s_ +#ifndef _di_f_color_terminal_s_ + const f_string_static_t f_color_terminal_name_s = macro_f_string_static_t_initialize(F_color_terminal_name_s, 0, F_color_terminal_name_s_length); + const f_string_static_t f_color_terminal_value_linux_s = macro_f_string_static_t_initialize(F_color_terminal_value_linux_s, 0, F_color_terminal_value_linux_s_length); +#endif // _di_f_color_terminal_s_ + #ifndef _di_f_color_set_string_empty_s_ const f_color_set_t f_color_set_empty_s = macro_f_color_set_t_initialize(&f_string_empty_s, &f_string_empty_s); #endif // _di_f_color_set_string_empty_s_ diff --git a/level_0/f_color/c/color/common.h b/level_0/f_color/c/color/common.h index bd56468..24a399a 100644 --- a/level_0/f_color/c/color/common.h +++ b/level_0/f_color/c/color/common.h @@ -45,6 +45,24 @@ extern "C" { #endif // _di_f_color_code_t_ /** + * Terminal environment variable strings that may relate to color processing. + * + * f_color_terminal_*: + * - name: The standard terminal environment variable name. + * - value_linux: The value representing the Linux terminal. + */ +#ifndef _di_f_color_terminal_s_ + #define F_color_terminal_name_s "TERM" + #define F_color_terminal_value_linux_s "linux" + + #define F_color_terminal_name_s_length 4 + #define F_color_terminal_value_linux_s_length 5 + + extern const f_string_static_t f_color_terminal_name_s; + extern const f_string_static_t f_color_terminal_value_linux_s; +#endif // _di_f_color_terminal_s_ + +/** * Provide a global color related strings. * * F_color_string_*: