lib/colors.c
/* Colorized output: get user-defined colors from OVS_COLORS environment
 * variable. This must be a string of the form:
 *     ac=01;31:r=34:le=:pm=02;32:pr=01;30
 * (see color_dic[] in colors_init() function for all color names)
 * If a color is missing from this string, default value is used instead.
 * If a color name is assigned an empty or incorrect value (i.e. something
 * containing characters other than decimals and ';'), fields using this color
 * will not be highlighted.
 * If a color is assigned more than once, the last (rightmost) value appearing
 * in the string is kept.
 * Unknown color names are ignored so as to ensure forward compatibility.
 * (Feeling adventurous? Try combining markers: "ac=1;3;5;7;38;2;30;150;100".)
 */
Colorized output: get user-defined colors from OVS_COLORS environment
variable.
Colorized output : get user - defined colors from OVS_COLORS environment variable .
static void
colors_parse_from_env(const struct color_key color_dic[])
{
    const char *color_str = getenv("OVS_COLORS");
    if (color_str == NULL || *color_str == '\0') {
        return;
    }
    char *s = xstrdup(color_str);
    char *s_head = s;
    for (char *token = strsep(&s, ":");
         token != NULL;
         token = strsep(&s, ":")) {
        char *name = strsep(&token, "=");
        for (char *ptr = token; ptr != NULL && *ptr != '\0'; ptr++) {
            if (*ptr == ';' || (*ptr >= '0' && *ptr <= '9')) {
                continue;
            }
            name = NULL;
            break;
        }
        if (name != NULL) {
            char **color_var_ptr = get_color(color_dic, name);
            if (color_var_ptr != NULL) {
                *color_var_ptr = xasprintf("\33[%sm\33[K", token);
            }
        }
    }
    free(s_head);
}
static void colors_parse_from_env ( const struct color_key color_dic [ ] ) { const char * color_str = getenv ( " " ) ; if ( color_str == NULL || * color_str == ' \0 ' ) { return ; } char * s = xstrdup ( color_str ) ; char * s_head = s ; for ( char * token = strsep ( & s , " " ) ; token != NULL ; token = strsep ( & s , " " ) ) { char * name = strsep ( & token , " " ) ; for ( char * ptr = token ; ptr != NULL && * ptr != ' \0 ' ; ptr ++ ) { if ( * ptr == ' ' || ( * ptr >= ' ' && * ptr <= ' ' ) ) { continue ; } name = NULL ; break ; } if ( name != NULL ) { char * * color_var_ptr = get_color ( color_dic , name ) ; if ( color_var_ptr != NULL ) { * color_var_ptr = xasprintf ( " \33 \33 " , token ) ; } } } free ( s_head ) ; }
Colorized output: get user-defined colors from OVS_COLORS environment
 variable.
Colorized output : get user - defined colors from OVS_COLORS environment variable .
/* Loop on tokens: they are separated by columns ':' */ /* We accept only decimals and ';' for color marker. */ /* We found a name and marker contains only decimals and ';'.
             * Try to get a pointer to associated color variable. */ /* If we know that color, update its value. */