GCC Middle and Back End API Reference
diagnostic-color.cc File Reference
#include "config.h"
#include "system.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
#include "color-macros.h"
Include dependency graph for diagnostic-color.cc:

Data Structures

struct  color_cap
 

Functions

const charcolorize_start (bool show_color, const char *name, size_t name_len)
 
const charcolorize_stop (bool show_color)
 
static bool parse_gcc_colors (void)
 
static bool should_colorize (void)
 
bool colorize_init (diagnostic_color_rule_t rule)
 
static diagnostic_url_format parse_env_vars_for_urls ()
 
static bool auto_enable_urls ()
 
diagnostic_url_format determine_url_format (diagnostic_url_rule_t rule)
 

Variables

static struct color_cap color_dict []
 

Function Documentation

◆ auto_enable_urls()

static bool auto_enable_urls ( )
static
Return true if we should use urls when in auto mode, false otherwise.   

References ggc_alloc(), and should_colorize().

Referenced by determine_url_format().

◆ colorize_init()

◆ colorize_start()

◆ colorize_stop()

◆ determine_url_format()

diagnostic_url_format determine_url_format ( diagnostic_url_rule_t rule)
Determine if URLs should be enabled, based on RULE,
and, if so, which format to use.
This reuses the logic for colorization.   

References auto_enable_urls(), DIAGNOSTICS_URL_AUTO, DIAGNOSTICS_URL_NO, DIAGNOSTICS_URL_YES, gcc_unreachable, parse_env_vars_for_urls(), and URL_FORMAT_NONE.

Referenced by diagnostic_context::urls_init().

◆ parse_env_vars_for_urls()

static diagnostic_url_format parse_env_vars_for_urls ( )
static
Return URL_FORMAT_XXX which tells how we should emit urls
when in always mode.
We use GCC_URLS and if that is not defined TERM_URLS.
If neither is defined the feature is enabled by default.   

References ggc_alloc(), NULL, URL_FORMAT_BEL, URL_FORMAT_DEFAULT, URL_FORMAT_NONE, and URL_FORMAT_ST.

Referenced by determine_url_format().

◆ parse_gcc_colors()

static bool parse_gcc_colors ( void )
static
Parse GCC_COLORS.  The default would look like:
GCC_COLORS='error=01;31:warning=01;35:note=01;36:\
range1=32:range2=34:locus=01:quote=01:path=01;36:\
fixit-insert=32:fixit-delete=31:'\
diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\
type-diff=01;32'
No character escaping is needed or supported.   

References b, color_dict, CONST_CAST, free(), color_cap::free_val, ggc_alloc(), color_cap::name, color_cap::name_len, NULL, SGR_END, SGR_SEQ, SGR_START, and color_cap::val.

Referenced by colorize_init().

◆ should_colorize()

static bool should_colorize ( void )
static
Return true if we should use color when in auto mode, false otherwise.  

References ggc_alloc(), NULL, and STDERR_FILENO.

Referenced by auto_enable_urls(), and colorize_init().

Variable Documentation

◆ color_dict

struct color_cap color_dict[]
static
Initial value:
=
{
{ "error", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_RED), 5, false },
7, false },
{ "range1", SGR_SEQ (COLOR_FG_GREEN), 6, false },
{ "range2", SGR_SEQ (COLOR_FG_BLUE), 6, false },
{ "locus", SGR_SEQ (COLOR_BOLD), 5, false },
{ "quote", SGR_SEQ (COLOR_BOLD), 5, false },
{ "fnname", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 6, false },
{ "targs", SGR_SEQ (COLOR_FG_MAGENTA), 5, false },
{ "fixit-insert", SGR_SEQ (COLOR_FG_GREEN), 12, false },
{ "fixit-delete", SGR_SEQ (COLOR_FG_RED), 12, false },
{ "diff-filename", SGR_SEQ (COLOR_BOLD), 13, false },
{ "diff-hunk", SGR_SEQ (COLOR_FG_CYAN), 9, false },
{ "diff-delete", SGR_SEQ (COLOR_FG_RED), 11, false },
{ "diff-insert", SGR_SEQ (COLOR_FG_GREEN), 11, false },
{ "type-diff", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 9, false },
{ "invalid", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_RED), 7, false },
{ NULL, NULL, 0, false }
}
#define COLOR_FG_CYAN
Definition color-macros.h:93
#define COLOR_BOLD
Definition color-macros.h:83
#define COLOR_FG_GREEN
Definition color-macros.h:89
#define COLOR_FG_RED
Definition color-macros.h:88
#define SGR_SEQ(str)
Definition color-macros.h:121
#define COLOR_FG_MAGENTA
Definition color-macros.h:92
#define COLOR_FG_BLUE
Definition color-macros.h:91
#define COLOR_SEPARATOR
Definition color-macros.h:81
#define NULL
Definition system.h:50
For GCC_COLORS.   

Referenced by colorize_start(), and parse_gcc_colors().