79 |
/* If nonzero, use grep_color marker. */ |
/* If nonzero, use grep_color marker. */ |
80 |
static int color_option; |
static int color_option; |
81 |
|
|
|
/* If nonzero, do pseudo-markup instead of actual colors. */ |
|
|
static int pseudo_markup; |
|
|
|
|
82 |
/* If nonzero, show only the part of a line matching the expression. */ |
/* If nonzero, show only the part of a line matching the expression. */ |
83 |
static int only_matching; |
static int only_matching; |
84 |
|
|
221 |
static const char * |
static const char * |
222 |
color_cap_ne_fct(void) |
color_cap_ne_fct(void) |
223 |
{ |
{ |
|
if (pseudo_markup) |
|
|
return "makes no sense after the \"xm\" capability; ignored"; |
|
|
|
|
224 |
sgr_start = "\33[%sm"; |
sgr_start = "\33[%sm"; |
225 |
sgr_end = "\33[m"; |
sgr_end = "\33[m"; |
226 |
|
|
227 |
return NULL; |
return NULL; |
228 |
} |
} |
229 |
|
|
|
static const char * |
|
|
color_cap_xm_fct(void) |
|
|
{ |
|
|
/* This experimental feature should stay undocumented for now. */ |
|
|
pseudo_markup = 1; |
|
|
|
|
|
sgr_start = "<grep:%s>"; |
|
|
sgr_end = "</grep:%s>"; |
|
|
|
|
|
/* The user can just redefine them to the empty string afterwards. */ |
|
|
grep_color = "matched-text"; |
|
|
filename_color = "filename"; |
|
|
line_num_color = "line-number"; |
|
|
byte_num_color = "byte-offset"; |
|
|
sep_color = "separator"; |
|
|
mlines_color = "matching-line"; |
|
|
context_color = "context-line"; |
|
|
|
|
|
return NULL; |
|
|
} |
|
|
|
|
230 |
/* For GREP_COLORS. */ |
/* For GREP_COLORS. */ |
231 |
static struct color_cap color_dict[] = |
static struct color_cap color_dict[] = |
232 |
{ |
{ |
238 |
{ "ml", &mlines_color, NULL }, /* matching lines */ |
{ "ml", &mlines_color, NULL }, /* matching lines */ |
239 |
{ "cx", &context_color, NULL }, /* context lines */ |
{ "cx", &context_color, NULL }, /* context lines */ |
240 |
{ "ne", NULL, color_cap_ne_fct }, /* no EL on SGR_* */ |
{ "ne", NULL, color_cap_ne_fct }, /* no EL on SGR_* */ |
|
{ "xm", NULL, color_cap_xm_fct }, /* pseudo-markup */ |
|
241 |
{ NULL, NULL, NULL } |
{ NULL, NULL, NULL } |
242 |
}; |
}; |
243 |
|
|
790 |
print_line_head(b, lim, SEP_CHAR_MATCH); |
print_line_head(b, lim, SEP_CHAR_MATCH); |
791 |
else |
else |
792 |
{ |
{ |
793 |
if (pseudo_markup >= 0) |
PR_SGR_START(mlines_color); |
|
{ |
|
|
PR_SGR_START(mlines_color); |
|
|
if (pseudo_markup) |
|
|
pseudo_markup = -1; |
|
|
} |
|
794 |
fwrite (beg, sizeof (char), match_offset, stdout); |
fwrite (beg, sizeof (char), match_offset, stdout); |
795 |
} |
} |
796 |
|
|
824 |
|
|
825 |
if (tail_size > 0) |
if (tail_size > 0) |
826 |
{ |
{ |
827 |
if (pseudo_markup >= 0) |
PR_SGR_START(color); |
|
PR_SGR_START(color); |
|
828 |
fwrite(beg, 1, tail_size, stdout); |
fwrite(beg, 1, tail_size, stdout); |
829 |
beg += tail_size; |
beg += tail_size; |
830 |
|
PR_SGR_END(color); |
831 |
} |
} |
832 |
|
|
|
if (tail_size > 0 || pseudo_markup < 0) |
|
|
PR_SGR_END(color); |
|
|
|
|
833 |
return beg; |
return beg; |
834 |
} |
} |
835 |
|
|
852 |
|
|
853 |
if (!only_matching && *line_color); |
if (!only_matching && *line_color); |
854 |
beg = print_line_tail(beg, lim, line_color); |
beg = print_line_tail(beg, lim, line_color); |
|
|
|
|
/* This global is modified by print_line_middle() |
|
|
and checked by print_line_tail(). Now reset it. */ |
|
|
if (pseudo_markup < 0) |
|
|
pseudo_markup = 1; |
|
855 |
} |
} |
856 |
|
|
857 |
if (!only_matching && lim > beg) |
if (!only_matching && lim > beg) |