aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-05-31 13:47:37 +0200
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-06-03 21:59:11 +0200
commit9303eb2fb1630678def10613c81215c2bd21d278 (patch)
treea2282608bb0422631678012ddfe7ee36c1c1fef4 /gdb/utils.c
parent79b377b3cf3a0e71e1e4710c4ee1e65e7a27a5d4 (diff)
downloadgdb-9303eb2fb1630678def10613c81215c2bd21d278.zip
gdb-9303eb2fb1630678def10613c81215c2bd21d278.tar.gz
gdb-9303eb2fb1630678def10613c81215c2bd21d278.tar.bz2
Add highlight style, title style, fputs_highlighted. Improve 'show style'
Have 'show style' and its subcommands using a style to style its output. This allows the GDB user or developer to use 'show style' to visually see with one command how all the current styles look like. Add 2 new styles highlight style, title style and fputs_highlighted function. Highlight style is used by fputs_highlighted to highlight the parts of its char *STR argument that match a HIGHLIGHT regexp. This (and the title style) will be used in a following patch.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 9686927..f556612 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1869,6 +1869,42 @@ fputs_styled (const char *linebuffer, const ui_file_style &style,
}
}
+/* See utils.h. */
+
+void
+fputs_highlighted (const char *str, const compiled_regex &highlight,
+ struct ui_file *stream)
+{
+ regmatch_t pmatch;
+
+ while (*str && highlight.exec (str, 1, &pmatch, 0) == 0)
+ {
+ size_t n_highlight = pmatch.rm_eo - pmatch.rm_so;
+
+ /* Output the part before pmatch with current style. */
+ while (pmatch.rm_so > 0)
+ {
+ fputc_filtered (*str, stream);
+ pmatch.rm_so--;
+ str++;
+ }
+
+ /* Output pmatch with the highlight style. */
+ set_output_style (stream, highlight_style.style ());
+ while (n_highlight > 0)
+ {
+ fputc_filtered (*str, stream);
+ n_highlight--;
+ str++;
+ }
+ set_output_style (stream, ui_file_style ());
+ }
+
+ /* Output the trailing part of STR not matching HIGHLIGHT. */
+ if (*str)
+ fputs_filtered (str, stream);
+}
+
int
putchar_unfiltered (int c)
{