Commit | Line | Data |
---|---|---|
2611b1a5 | 1 | /* Output generating routines for GDB CLI. |
349c5d5f | 2 | |
6aba47ca | 3 | Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2007 |
bee0189a | 4 | Free Software Foundation, 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 | |
13 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
22 | along with this program; if not, write to the Free Software | |
88d83552 EZ |
23 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | Boston, MA 02110-1301, USA. */ | |
2611b1a5 SC |
25 | |
26 | #include "defs.h" | |
27 | #include "ui-out.h" | |
28 | #include "tui.h" | |
29 | #include "gdb_string.h" | |
30 | #include "gdb_assert.h" | |
31 | ||
2611b1a5 SC |
32 | struct ui_out_data |
33 | { | |
34 | struct ui_file *stream; | |
35 | int suppress_output; | |
36 | int line; | |
37 | int start_of_line; | |
38 | }; | |
d1dab75a | 39 | typedef struct ui_out_data tui_out_data; |
2611b1a5 | 40 | |
1cc6d956 | 41 | /* These are the CLI output functions. */ |
2611b1a5 | 42 | |
08ef48c5 MS |
43 | static void tui_table_begin (struct ui_out *uiout, |
44 | int nbrofcols, int nr_rows, | |
45 | const char *tblid); | |
2611b1a5 SC |
46 | static void tui_table_body (struct ui_out *uiout); |
47 | static void tui_table_end (struct ui_out *uiout); | |
08ef48c5 MS |
48 | static void tui_table_header (struct ui_out *uiout, |
49 | int width, enum ui_align alig, | |
50 | const char *col_name, | |
2611b1a5 | 51 | const char *colhdr); |
08ef48c5 MS |
52 | static void tui_begin (struct ui_out *uiout, |
53 | enum ui_out_type type, | |
2611b1a5 | 54 | int level, const char *lstid); |
08ef48c5 MS |
55 | static void tui_end (struct ui_out *uiout, |
56 | enum ui_out_type type, int level); | |
57 | static void tui_field_int (struct ui_out *uiout, | |
58 | int fldno, int width, | |
59 | enum ui_align alig, | |
60 | const char *fldname, int value); | |
61 | static void tui_field_skip (struct ui_out *uiout, | |
62 | int fldno, int width, | |
63 | enum ui_align alig, | |
64 | const char *fldname); | |
65 | static void tui_field_string (struct ui_out *uiout, | |
66 | int fldno, int width, | |
67 | enum ui_align alig, | |
68 | const char *fldname, | |
2611b1a5 SC |
69 | const char *string); |
70 | static void tui_field_fmt (struct ui_out *uiout, int fldno, | |
71 | int width, enum ui_align align, | |
08ef48c5 MS |
72 | const char *fldname, |
73 | const char *format, | |
74 | va_list args) | |
75 | ATTR_FORMAT (printf, 6, 0); | |
2611b1a5 SC |
76 | static void tui_spaces (struct ui_out *uiout, int numspaces); |
77 | static void tui_text (struct ui_out *uiout, const char *string); | |
78 | static void tui_message (struct ui_out *uiout, int verbosity, | |
bee0189a DJ |
79 | const char *format, va_list args) |
80 | ATTR_FORMAT (printf, 3, 0); | |
08ef48c5 MS |
81 | static void tui_wrap_hint (struct ui_out *uiout, |
82 | char *identstring); | |
2611b1a5 SC |
83 | static void tui_flush (struct ui_out *uiout); |
84 | ||
1cc6d956 | 85 | /* This is the CLI ui-out implementation functions vector. */ |
2611b1a5 SC |
86 | |
87 | /* FIXME: This can be initialized dynamically after default is set to | |
1cc6d956 | 88 | handle initial output in main.c. */ |
2611b1a5 | 89 | |
08ef48c5 | 90 | static struct ui_out_impl tui_ui_out_impl = { |
2611b1a5 SC |
91 | tui_table_begin, |
92 | tui_table_body, | |
93 | tui_table_end, | |
94 | tui_table_header, | |
95 | tui_begin, | |
96 | tui_end, | |
97 | tui_field_int, | |
98 | tui_field_skip, | |
99 | tui_field_string, | |
100 | tui_field_fmt, | |
101 | tui_spaces, | |
102 | tui_text, | |
103 | tui_message, | |
104 | tui_wrap_hint, | |
105 | tui_flush, | |
0fac0b41 | 106 | NULL, |
2611b1a5 SC |
107 | 0, /* Does not need MI hacks (i.e. needs CLI hacks). */ |
108 | }; | |
109 | ||
1cc6d956 | 110 | /* Prototypes for local functions. */ |
2611b1a5 SC |
111 | |
112 | extern void _initialize_tui_out (void); | |
113 | ||
114 | static void field_separator (void); | |
115 | ||
08ef48c5 MS |
116 | static void out_field_fmt (struct ui_out *uiout, |
117 | int fldno, | |
2611b1a5 | 118 | const char *fldname, |
08ef48c5 MS |
119 | const char *format,...) |
120 | ATTR_FORMAT (printf, 4, 5); | |
2611b1a5 SC |
121 | |
122 | /* local variables */ | |
123 | ||
124 | /* (none yet) */ | |
125 | ||
1cc6d956 | 126 | /* Mark beginning of a table. */ |
2611b1a5 SC |
127 | |
128 | void | |
08ef48c5 MS |
129 | tui_table_begin (struct ui_out *uiout, |
130 | int nbrofcols, | |
2611b1a5 SC |
131 | int nr_rows, |
132 | const char *tblid) | |
133 | { | |
1248ede2 | 134 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
135 | if (nr_rows == 0) |
136 | data->suppress_output = 1; | |
137 | else | |
ce2826aa | 138 | /* Only the table suppresses the output and, fortunately, a table |
1cc6d956 | 139 | is not a recursive data structure. */ |
2611b1a5 SC |
140 | gdb_assert (data->suppress_output == 0); |
141 | } | |
142 | ||
1cc6d956 | 143 | /* Mark beginning of a table body. */ |
2611b1a5 SC |
144 | |
145 | void | |
146 | tui_table_body (struct ui_out *uiout) | |
147 | { | |
1248ede2 | 148 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
149 | if (data->suppress_output) |
150 | return; | |
1cc6d956 | 151 | /* First, close the table header line. */ |
2611b1a5 SC |
152 | tui_text (uiout, "\n"); |
153 | } | |
154 | ||
1cc6d956 | 155 | /* Mark end of a table. */ |
2611b1a5 SC |
156 | |
157 | void | |
158 | tui_table_end (struct ui_out *uiout) | |
159 | { | |
1248ede2 | 160 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
161 | data->suppress_output = 0; |
162 | } | |
163 | ||
1cc6d956 | 164 | /* Specify table header. */ |
2611b1a5 SC |
165 | |
166 | void | |
08ef48c5 MS |
167 | tui_table_header (struct ui_out *uiout, |
168 | int width, | |
169 | enum ui_align alignment, | |
2611b1a5 SC |
170 | const char *col_name, |
171 | const char *colhdr) | |
172 | { | |
1248ede2 | 173 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
174 | if (data->suppress_output) |
175 | return; | |
176 | tui_field_string (uiout, 0, width, alignment, 0, colhdr); | |
177 | } | |
178 | ||
1cc6d956 | 179 | /* Mark beginning of a list. */ |
2611b1a5 SC |
180 | |
181 | void | |
182 | tui_begin (struct ui_out *uiout, | |
183 | enum ui_out_type type, | |
184 | int level, | |
185 | const char *id) | |
186 | { | |
1248ede2 | 187 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
188 | if (data->suppress_output) |
189 | return; | |
190 | } | |
191 | ||
1cc6d956 | 192 | /* Mark end of a list. */ |
2611b1a5 SC |
193 | |
194 | void | |
195 | tui_end (struct ui_out *uiout, | |
196 | enum ui_out_type type, | |
197 | int level) | |
198 | { | |
1248ede2 | 199 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
200 | if (data->suppress_output) |
201 | return; | |
202 | } | |
203 | ||
1cc6d956 | 204 | /* Output an int field. */ |
2611b1a5 SC |
205 | |
206 | void | |
08ef48c5 MS |
207 | tui_field_int (struct ui_out *uiout, |
208 | int fldno, int width, | |
2611b1a5 | 209 | enum ui_align alignment, |
08ef48c5 MS |
210 | const char *fldname, |
211 | int value) | |
2611b1a5 | 212 | { |
1cc6d956 | 213 | char buffer[20]; /* FIXME: how many chars long a %d can become? */ |
2611b1a5 | 214 | |
1248ede2 | 215 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
216 | if (data->suppress_output) |
217 | return; | |
218 | ||
219 | /* Don't print line number, keep it for later. */ | |
220 | if (data->start_of_line == 0 && strcmp (fldname, "line") == 0) | |
221 | { | |
222 | data->start_of_line ++; | |
223 | data->line = value; | |
224 | return; | |
225 | } | |
226 | data->start_of_line ++; | |
227 | sprintf (buffer, "%d", value); | |
228 | tui_field_string (uiout, fldno, width, alignment, fldname, buffer); | |
229 | } | |
230 | ||
1cc6d956 | 231 | /* Used to ommit a field. */ |
2611b1a5 SC |
232 | |
233 | void | |
08ef48c5 MS |
234 | tui_field_skip (struct ui_out *uiout, |
235 | int fldno, int width, | |
2611b1a5 SC |
236 | enum ui_align alignment, |
237 | const char *fldname) | |
238 | { | |
1248ede2 | 239 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
240 | if (data->suppress_output) |
241 | return; | |
242 | tui_field_string (uiout, fldno, width, alignment, fldname, ""); | |
243 | } | |
244 | ||
1cc6d956 MS |
245 | /* Other specific tui_field_* end up here so alignment and field |
246 | separators are both handled by tui_field_string. */ | |
2611b1a5 SC |
247 | |
248 | void | |
249 | tui_field_string (struct ui_out *uiout, | |
08ef48c5 | 250 | int fldno, int width, |
2611b1a5 SC |
251 | enum ui_align align, |
252 | const char *fldname, | |
253 | const char *string) | |
254 | { | |
255 | int before = 0; | |
256 | int after = 0; | |
257 | ||
1248ede2 | 258 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
259 | if (data->suppress_output) |
260 | return; | |
261 | ||
262 | if (fldname && data->line > 0 && strcmp (fldname, "file") == 0) | |
263 | { | |
264 | data->start_of_line ++; | |
265 | if (data->line > 0) | |
266 | { | |
267 | tui_show_source (string, data->line); | |
268 | } | |
269 | return; | |
270 | } | |
271 | ||
272 | data->start_of_line ++; | |
273 | if ((align != ui_noalign) && string) | |
274 | { | |
275 | before = width - strlen (string); | |
276 | if (before <= 0) | |
277 | before = 0; | |
278 | else | |
279 | { | |
280 | if (align == ui_right) | |
281 | after = 0; | |
282 | else if (align == ui_left) | |
283 | { | |
284 | after = before; | |
285 | before = 0; | |
286 | } | |
287 | else | |
288 | /* ui_center */ | |
289 | { | |
290 | after = before / 2; | |
291 | before -= after; | |
292 | } | |
293 | } | |
294 | } | |
295 | ||
296 | if (before) | |
297 | ui_out_spaces (uiout, before); | |
298 | if (string) | |
299 | out_field_fmt (uiout, fldno, fldname, "%s", string); | |
300 | if (after) | |
301 | ui_out_spaces (uiout, after); | |
302 | ||
303 | if (align != ui_noalign) | |
304 | field_separator (); | |
305 | } | |
306 | ||
1cc6d956 | 307 | /* This is the only field function that does not align. */ |
2611b1a5 SC |
308 | |
309 | void | |
310 | tui_field_fmt (struct ui_out *uiout, int fldno, | |
311 | int width, enum ui_align align, | |
312 | const char *fldname, | |
313 | const char *format, | |
314 | va_list args) | |
315 | { | |
1248ede2 | 316 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
317 | if (data->suppress_output) |
318 | return; | |
319 | ||
320 | data->start_of_line ++; | |
321 | vfprintf_filtered (data->stream, format, args); | |
322 | ||
323 | if (align != ui_noalign) | |
324 | field_separator (); | |
325 | } | |
326 | ||
327 | void | |
328 | tui_spaces (struct ui_out *uiout, int numspaces) | |
329 | { | |
1248ede2 | 330 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
331 | if (data->suppress_output) |
332 | return; | |
333 | print_spaces_filtered (numspaces, data->stream); | |
334 | } | |
335 | ||
336 | void | |
337 | tui_text (struct ui_out *uiout, const char *string) | |
338 | { | |
1248ede2 | 339 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
340 | if (data->suppress_output) |
341 | return; | |
342 | data->start_of_line ++; | |
343 | if (data->line > 0) | |
344 | { | |
345 | if (strchr (string, '\n') != 0) | |
346 | { | |
347 | data->line = -1; | |
348 | data->start_of_line = 0; | |
349 | } | |
350 | return; | |
351 | } | |
352 | if (strchr (string, '\n')) | |
353 | data->start_of_line = 0; | |
354 | fputs_filtered (string, data->stream); | |
355 | } | |
356 | ||
357 | void | |
08ef48c5 MS |
358 | tui_message (struct ui_out *uiout, |
359 | int verbosity, | |
360 | const char *format, | |
361 | va_list args) | |
2611b1a5 | 362 | { |
1248ede2 | 363 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
364 | if (data->suppress_output) |
365 | return; | |
366 | if (ui_out_get_verblvl (uiout) >= verbosity) | |
367 | vfprintf_unfiltered (data->stream, format, args); | |
368 | } | |
369 | ||
370 | void | |
371 | tui_wrap_hint (struct ui_out *uiout, char *identstring) | |
372 | { | |
1248ede2 | 373 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
374 | if (data->suppress_output) |
375 | return; | |
376 | wrap_here (identstring); | |
377 | } | |
378 | ||
379 | void | |
380 | tui_flush (struct ui_out *uiout) | |
381 | { | |
1248ede2 | 382 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
383 | gdb_flush (data->stream); |
384 | } | |
385 | ||
1cc6d956 | 386 | /* Local functions. */ |
2611b1a5 | 387 | |
1cc6d956 MS |
388 | /* Like tui_field_fmt, but takes a variable number of args and makes a |
389 | va_list and does not insert a separator. */ | |
2611b1a5 SC |
390 | |
391 | /* VARARGS */ | |
392 | static void | |
08ef48c5 MS |
393 | out_field_fmt (struct ui_out *uiout, |
394 | int fldno, | |
2611b1a5 SC |
395 | const char *fldname, |
396 | const char *format,...) | |
397 | { | |
1248ede2 | 398 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
399 | va_list args; |
400 | ||
401 | va_start (args, format); | |
402 | vfprintf_filtered (data->stream, format, args); | |
403 | ||
404 | va_end (args); | |
405 | } | |
406 | ||
1cc6d956 | 407 | /* Access to ui_out format private members. */ |
2611b1a5 SC |
408 | |
409 | static void | |
410 | field_separator (void) | |
411 | { | |
1248ede2 | 412 | tui_out_data *data = ui_out_data (uiout); |
2611b1a5 SC |
413 | fputc_filtered (' ', data->stream); |
414 | } | |
415 | ||
1cc6d956 | 416 | /* Initalize private members at startup. */ |
2611b1a5 SC |
417 | |
418 | struct ui_out * | |
419 | tui_out_new (struct ui_file *stream) | |
420 | { | |
421 | int flags = 0; | |
422 | ||
1248ede2 | 423 | tui_out_data *data = XMALLOC (tui_out_data); |
2611b1a5 SC |
424 | data->stream = stream; |
425 | data->suppress_output = 0; | |
426 | data->line = -1; | |
27229e99 | 427 | data->start_of_line = 0; |
2611b1a5 SC |
428 | return ui_out_new (&tui_ui_out_impl, data, flags); |
429 | } | |
430 | ||
1cc6d956 | 431 | /* Standard gdb initialization hook. */ |
2611b1a5 SC |
432 | void |
433 | _initialize_tui_out (void) | |
434 | { | |
1cc6d956 | 435 | /* Nothing needs to be done. */ |
2611b1a5 | 436 | } |