Commit | Line | Data |
---|---|---|
2611b1a5 | 1 | /* Output generating routines for GDB CLI. |
349c5d5f | 2 | |
c5a57081 JB |
3 | Copyright (C) 1999-2003, 2005, 2007-2012 Free Software Foundation, |
4 | Inc. | |
349c5d5f | 5 | |
2611b1a5 SC |
6 | Contributed by Cygnus Solutions. |
7 | Written by Fernando Nasser for Cygnus. | |
8 | ||
9 | This file is part of GDB. | |
10 | ||
11 | This program is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
2611b1a5 SC |
14 | (at your option) any later version. |
15 | ||
16 | This program is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2611b1a5 SC |
23 | |
24 | #include "defs.h" | |
25 | #include "ui-out.h" | |
0a8fce9a | 26 | #include "cli-out.h" |
2611b1a5 SC |
27 | #include "tui.h" |
28 | #include "gdb_string.h" | |
29 | #include "gdb_assert.h" | |
30 | ||
0a8fce9a | 31 | struct tui_ui_out_data |
2611b1a5 | 32 | { |
0a8fce9a PA |
33 | struct cli_ui_out_data base; |
34 | ||
2611b1a5 SC |
35 | int line; |
36 | int start_of_line; | |
37 | }; | |
0a8fce9a | 38 | typedef struct tui_ui_out_data tui_out_data; |
2611b1a5 | 39 | |
0a8fce9a PA |
40 | /* This is the TUI ui-out implementation functions vector. It is |
41 | initialized below in _initialize_tui_out, inheriting the CLI | |
42 | version, and overriding a few methods. */ | |
2611b1a5 | 43 | |
0a8fce9a | 44 | static struct ui_out_impl tui_ui_out_impl; |
2611b1a5 | 45 | |
1cc6d956 | 46 | /* Output an int field. */ |
2611b1a5 | 47 | |
0a8fce9a | 48 | static void |
08ef48c5 MS |
49 | tui_field_int (struct ui_out *uiout, |
50 | int fldno, int width, | |
2611b1a5 | 51 | enum ui_align alignment, |
08ef48c5 MS |
52 | const char *fldname, |
53 | int value) | |
2611b1a5 | 54 | { |
1248ede2 | 55 | tui_out_data *data = ui_out_data (uiout); |
1c5313c5 | 56 | |
0a8fce9a | 57 | if (data->base.suppress_output) |
2611b1a5 SC |
58 | return; |
59 | ||
60 | /* Don't print line number, keep it for later. */ | |
61 | if (data->start_of_line == 0 && strcmp (fldname, "line") == 0) | |
62 | { | |
63 | data->start_of_line ++; | |
64 | data->line = value; | |
65 | return; | |
66 | } | |
67 | data->start_of_line ++; | |
2611b1a5 | 68 | |
0a8fce9a PA |
69 | (*cli_ui_out_impl.field_int) (uiout, fldno, |
70 | width, alignment, fldname, value); | |
2611b1a5 SC |
71 | } |
72 | ||
0a8fce9a PA |
73 | /* Other cli_field_* end up here so alignment and field separators are |
74 | both handled by tui_field_string. */ | |
2611b1a5 | 75 | |
0a8fce9a | 76 | static void |
2611b1a5 | 77 | tui_field_string (struct ui_out *uiout, |
08ef48c5 | 78 | int fldno, int width, |
2611b1a5 SC |
79 | enum ui_align align, |
80 | const char *fldname, | |
81 | const char *string) | |
82 | { | |
1248ede2 | 83 | tui_out_data *data = ui_out_data (uiout); |
1c5313c5 | 84 | |
0a8fce9a | 85 | if (data->base.suppress_output) |
2611b1a5 SC |
86 | return; |
87 | ||
88 | if (fldname && data->line > 0 && strcmp (fldname, "file") == 0) | |
89 | { | |
90 | data->start_of_line ++; | |
91 | if (data->line > 0) | |
92 | { | |
93 | tui_show_source (string, data->line); | |
94 | } | |
95 | return; | |
96 | } | |
97 | ||
0a8fce9a | 98 | data->start_of_line++; |
2611b1a5 | 99 | |
0a8fce9a PA |
100 | (*cli_ui_out_impl.field_string) (uiout, fldno, |
101 | width, align, | |
102 | fldname, string); | |
2611b1a5 SC |
103 | } |
104 | ||
1cc6d956 | 105 | /* This is the only field function that does not align. */ |
2611b1a5 | 106 | |
0a8fce9a | 107 | static void |
2611b1a5 SC |
108 | tui_field_fmt (struct ui_out *uiout, int fldno, |
109 | int width, enum ui_align align, | |
110 | const char *fldname, | |
111 | const char *format, | |
112 | va_list args) | |
113 | { | |
1248ede2 | 114 | tui_out_data *data = ui_out_data (uiout); |
1c5313c5 | 115 | |
0a8fce9a | 116 | if (data->base.suppress_output) |
2611b1a5 SC |
117 | return; |
118 | ||
0a8fce9a | 119 | data->start_of_line++; |
2611b1a5 | 120 | |
0a8fce9a PA |
121 | (*cli_ui_out_impl.field_fmt) (uiout, fldno, |
122 | width, align, | |
123 | fldname, format, args); | |
2611b1a5 SC |
124 | } |
125 | ||
0a8fce9a | 126 | static void |
2611b1a5 SC |
127 | tui_text (struct ui_out *uiout, const char *string) |
128 | { | |
1248ede2 | 129 | tui_out_data *data = ui_out_data (uiout); |
1c5313c5 | 130 | |
0a8fce9a | 131 | if (data->base.suppress_output) |
2611b1a5 SC |
132 | return; |
133 | data->start_of_line ++; | |
134 | if (data->line > 0) | |
135 | { | |
136 | if (strchr (string, '\n') != 0) | |
137 | { | |
138 | data->line = -1; | |
139 | data->start_of_line = 0; | |
140 | } | |
141 | return; | |
142 | } | |
143 | if (strchr (string, '\n')) | |
144 | data->start_of_line = 0; | |
2611b1a5 | 145 | |
0a8fce9a | 146 | (*cli_ui_out_impl.text) (uiout, string); |
2611b1a5 SC |
147 | } |
148 | ||
2611b1a5 SC |
149 | struct ui_out * |
150 | tui_out_new (struct ui_file *stream) | |
151 | { | |
152 | int flags = 0; | |
153 | ||
1248ede2 | 154 | tui_out_data *data = XMALLOC (tui_out_data); |
0a8fce9a PA |
155 | |
156 | /* Initialize base "class". */ | |
157 | cli_out_data_ctor (&data->base, stream); | |
158 | ||
159 | /* Initialize our fields. */ | |
2611b1a5 | 160 | data->line = -1; |
27229e99 | 161 | data->start_of_line = 0; |
0a8fce9a | 162 | |
2611b1a5 SC |
163 | return ui_out_new (&tui_ui_out_impl, data, flags); |
164 | } | |
165 | ||
1cc6d956 | 166 | /* Standard gdb initialization hook. */ |
0a8fce9a PA |
167 | |
168 | extern void _initialize_tui_out (void); | |
169 | ||
2611b1a5 SC |
170 | void |
171 | _initialize_tui_out (void) | |
172 | { | |
1c5313c5 | 173 | /* Inherit the CLI version. */ |
0a8fce9a PA |
174 | tui_ui_out_impl = cli_ui_out_impl; |
175 | ||
176 | /* Override a few methods. */ | |
177 | tui_ui_out_impl.field_int = tui_field_int; | |
178 | tui_ui_out_impl.field_string = tui_field_string; | |
179 | tui_ui_out_impl.field_fmt = tui_field_fmt; | |
180 | tui_ui_out_impl.text = tui_text; | |
2611b1a5 | 181 | } |