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 "label-text.h"
#include "color-macros.h"
#include "selftest.h"
Include dependency graph for diagnostic-color.cc:

Data Structures

struct  color_default
 
class  diagnostic_color_dict
 
struct  diagnostic_color_dict::entry
 

Macros

#define INCLUDE_VECTOR
 

Functions

const char * colorize_start (bool show_color, const char *name, size_t name_len)
 
const char * colorize_stop (bool show_color)
 
static bool parse_gcc_colors ()
 
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 const color_default gcc_color_defaults []
 
static diagnostic_color_dictg_color_dict
 

Macro Definition Documentation

◆ INCLUDE_VECTOR

#define INCLUDE_VECTOR
Output colorization.
Copyright (C) 2011-2024 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA.   

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 NULL, 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 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 ( )
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'.   

References g_color_dict, and diagnostic_color_dict::parse_envvar_value().

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 NULL, and STDERR_FILENO.

Referenced by auto_enable_urls(), and colorize_init().

Variable Documentation

◆ g_color_dict

diagnostic_color_dict* g_color_dict
static

◆ gcc_color_defaults

const color_default gcc_color_defaults[]
static
Initial value:
=
{
{ "range1", SGR_SEQ (COLOR_FG_GREEN) },
{ "range2", SGR_SEQ (COLOR_FG_BLUE) },
{ "locus", SGR_SEQ (COLOR_BOLD) },
{ "quote", SGR_SEQ (COLOR_BOLD) },
{ "targs", SGR_SEQ (COLOR_FG_MAGENTA) },
{ "fixit-insert", SGR_SEQ (COLOR_FG_GREEN) },
{ "fixit-delete", SGR_SEQ (COLOR_FG_RED) },
{ "diff-filename", SGR_SEQ (COLOR_BOLD) },
{ "diff-hunk", SGR_SEQ (COLOR_FG_CYAN) },
{ "diff-delete", SGR_SEQ (COLOR_FG_RED) },
{ "diff-insert", SGR_SEQ (COLOR_FG_GREEN) },
}
#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
For GCC_COLORS.   

Referenced by colorize_init().