Style variable names
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
e2882c85 3 Copyright (C) 1999-2018 Free Software Foundation, Inc.
349c5d5f 4
8b93c638
JM
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
8b93c638
JM
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b93c638
JM
22
23#include "defs.h"
24#include "ui-out.h"
25#include "cli-out.h"
82083d6d 26#include "completer.h"
82083d6d 27#include "readline/readline.h"
cbe56571 28#include "cli/cli-style.h"
8b93c638 29
02a45ac0
PA
30/* These are the CLI output functions */
31
8b93c638
JM
32/* Mark beginning of a table */
33
112e8700
SM
34void
35cli_ui_out::do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
8b93c638 36{
698384cd 37 if (nr_rows == 0)
112e8700 38 m_suppress_output = true;
698384cd 39 else
ce2826aa 40 /* Only the table suppresses the output and, fortunately, a table
30fdc99f 41 is not a recursive data structure. */
112e8700 42 gdb_assert (!m_suppress_output);
8b93c638
JM
43}
44
45/* Mark beginning of a table body */
46
112e8700
SM
47void
48cli_ui_out::do_table_body ()
8b93c638 49{
112e8700 50 if (m_suppress_output)
698384cd 51 return;
112e8700 52
8b93c638 53 /* first, close the table header line */
112e8700 54 text ("\n");
8b93c638
JM
55}
56
57/* Mark end of a table */
58
112e8700
SM
59void
60cli_ui_out::do_table_end ()
8b93c638 61{
112e8700 62 m_suppress_output = false;
8b93c638
JM
63}
64
65/* Specify table header */
66
112e8700
SM
67void
68cli_ui_out::do_table_header (int width, ui_align alignment,
69 const std::string &col_name,
70 const std::string &col_hdr)
8b93c638 71{
112e8700 72 if (m_suppress_output)
698384cd 73 return;
0a8fce9a 74
cbe56571
TT
75 do_field_string (0, width, alignment, 0, col_hdr.c_str (),
76 ui_out_style_kind::DEFAULT);
8b93c638
JM
77}
78
79/* Mark beginning of a list */
80
112e8700
SM
81void
82cli_ui_out::do_begin (ui_out_type type, const char *id)
8b93c638
JM
83{
84}
85
86/* Mark end of a list */
87
112e8700
SM
88void
89cli_ui_out::do_end (ui_out_type type)
8b93c638
JM
90{
91}
92
93/* output an int field */
94
112e8700
SM
95void
96cli_ui_out::do_field_int (int fldno, int width, ui_align alignment,
97 const char *fldname, int value)
8b93c638 98{
112e8700 99 if (m_suppress_output)
698384cd 100 return;
112e8700 101
d63095c4 102 std::string str = string_printf ("%d", value);
0a8fce9a 103
cbe56571
TT
104 do_field_string (fldno, width, alignment, fldname, str.c_str (),
105 ui_out_style_kind::DEFAULT);
8b93c638
JM
106}
107
112e8700 108/* used to omit a field */
8b93c638 109
112e8700
SM
110void
111cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
112 const char *fldname)
8b93c638 113{
112e8700 114 if (m_suppress_output)
698384cd 115 return;
0a8fce9a 116
cbe56571
TT
117 do_field_string (fldno, width, alignment, fldname, "",
118 ui_out_style_kind::DEFAULT);
8b93c638
JM
119}
120
121/* other specific cli_field_* end up here so alignment and field
122 separators are both handled by cli_field_string */
123
112e8700
SM
124void
125cli_ui_out::do_field_string (int fldno, int width, ui_align align,
cbe56571
TT
126 const char *fldname, const char *string,
127 ui_out_style_kind style)
8b93c638
JM
128{
129 int before = 0;
130 int after = 0;
c5504eaf 131
112e8700 132 if (m_suppress_output)
698384cd
AC
133 return;
134
8b93c638
JM
135 if ((align != ui_noalign) && string)
136 {
137 before = width - strlen (string);
138 if (before <= 0)
139 before = 0;
140 else
141 {
142 if (align == ui_right)
143 after = 0;
144 else if (align == ui_left)
145 {
146 after = before;
147 before = 0;
148 }
149 else
150 /* ui_center */
151 {
152 after = before / 2;
153 before -= after;
154 }
155 }
156 }
157
158 if (before)
112e8700
SM
159 spaces (before);
160
8b93c638 161 if (string)
cbe56571
TT
162 {
163 ui_file_style fstyle;
164 switch (style)
165 {
166 case ui_out_style_kind::DEFAULT:
167 /* Nothing. */
168 break;
169 case ui_out_style_kind::FILE:
170 /* Nothing. */
171 fstyle = file_name_style.style ();
172 break;
173 case ui_out_style_kind::FUNCTION:
174 fstyle = function_name_style.style ();
175 break;
80ae2043
TT
176 case ui_out_style_kind::VARIABLE:
177 fstyle = variable_name_style.style ();
178 break;
cbe56571
TT
179 default:
180 gdb_assert_not_reached ("missing case");
181 }
182 fputs_styled (string, fstyle, m_streams.back ());
183 }
112e8700 184
8b93c638 185 if (after)
112e8700 186 spaces (after);
8b93c638
JM
187
188 if (align != ui_noalign)
189 field_separator ();
190}
191
1871a62d 192/* Output field containing ARGS using printf formatting in FORMAT. */
8b93c638 193
112e8700
SM
194void
195cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
196 const char *fldname, const char *format,
197 va_list args)
8b93c638 198{
112e8700 199 if (m_suppress_output)
698384cd
AC
200 return;
201
1871a62d 202 std::string str = string_vprintf (format, args);
8b93c638 203
cbe56571
TT
204 do_field_string (fldno, width, align, fldname, str.c_str (),
205 ui_out_style_kind::DEFAULT);
8b93c638
JM
206}
207
112e8700
SM
208void
209cli_ui_out::do_spaces (int numspaces)
8b93c638 210{
112e8700 211 if (m_suppress_output)
698384cd 212 return;
14dba4b4 213
112e8700 214 print_spaces_filtered (numspaces, m_streams.back ());
8b93c638
JM
215}
216
112e8700
SM
217void
218cli_ui_out::do_text (const char *string)
8b93c638 219{
112e8700 220 if (m_suppress_output)
698384cd 221 return;
14dba4b4 222
112e8700 223 fputs_filtered (string, m_streams.back ());
8b93c638
JM
224}
225
112e8700
SM
226void
227cli_ui_out::do_message (const char *format, va_list args)
8b93c638 228{
112e8700 229 if (m_suppress_output)
698384cd 230 return;
14dba4b4 231
112e8700 232 vfprintf_unfiltered (m_streams.back (), format, args);
8b93c638
JM
233}
234
112e8700
SM
235void
236cli_ui_out::do_wrap_hint (const char *identstring)
8b93c638 237{
112e8700 238 if (m_suppress_output)
698384cd 239 return;
112e8700 240
8b93c638
JM
241 wrap_here (identstring);
242}
243
112e8700
SM
244void
245cli_ui_out::do_flush ()
8b93c638 246{
112e8700 247 gdb_flush (m_streams.back ());
8b93c638
JM
248}
249
14dba4b4
JK
250/* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
251 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
252 output stream; it is an internal error if it does not exist. */
253
7becfd03 254void
112e8700 255cli_ui_out::do_redirect (ui_file *outstream)
0fac0b41 256{
0fac0b41 257 if (outstream != NULL)
112e8700 258 m_streams.push_back (outstream);
14dba4b4 259 else
112e8700 260 m_streams.pop_back ();
0fac0b41
DJ
261}
262
8b93c638
JM
263/* local functions */
264
112e8700
SM
265void
266cli_ui_out::field_separator ()
8b93c638 267{
112e8700 268 fputc_filtered (' ', m_streams.back ());
8b93c638
JM
269}
270
112e8700 271/* Constructor for cli_ui_out. */
02a45ac0 272
112e8700
SM
273cli_ui_out::cli_ui_out (ui_file *stream, ui_out_flags flags)
274: ui_out (flags),
275 m_suppress_output (false)
0a8fce9a 276{
14dba4b4
JK
277 gdb_assert (stream != NULL);
278
112e8700
SM
279 m_streams.push_back (stream);
280}
14dba4b4 281
112e8700
SM
282cli_ui_out::~cli_ui_out ()
283{
0a8fce9a
PA
284}
285
286/* Initialize private members at startup. */
8b93c638 287
112e8700 288cli_ui_out *
8b93c638
JM
289cli_out_new (struct ui_file *stream)
290{
112e8700 291 return new cli_ui_out (stream, ui_source_list);
8b93c638
JM
292}
293
112e8700
SM
294ui_file *
295cli_ui_out::set_stream (struct ui_file *stream)
4389a95a 296{
112e8700 297 ui_file *old;
b9b118c3 298
112e8700
SM
299 old = m_streams.back ();
300 m_streams.back () = stream;
c5504eaf 301
4389a95a
AC
302 return old;
303}
b9b118c3 304
82083d6d
DE
305/* CLI interface to display tab-completion matches. */
306
307/* CLI version of displayer.crlf. */
308
309static void
310cli_mld_crlf (const struct match_list_displayer *displayer)
311{
312 rl_crlf ();
313}
314
315/* CLI version of displayer.putch. */
316
317static void
318cli_mld_putch (const struct match_list_displayer *displayer, int ch)
319{
320 putc (ch, rl_outstream);
321}
322
323/* CLI version of displayer.puts. */
324
325static void
326cli_mld_puts (const struct match_list_displayer *displayer, const char *s)
327{
328 fputs (s, rl_outstream);
329}
330
331/* CLI version of displayer.flush. */
332
333static void
334cli_mld_flush (const struct match_list_displayer *displayer)
335{
336 fflush (rl_outstream);
337}
338
56000a98
PA
339EXTERN_C void _rl_erase_entire_line (void);
340
82083d6d
DE
341/* CLI version of displayer.erase_entire_line. */
342
343static void
344cli_mld_erase_entire_line (const struct match_list_displayer *displayer)
345{
82083d6d
DE
346 _rl_erase_entire_line ();
347}
348
349/* CLI version of displayer.beep. */
350
351static void
352cli_mld_beep (const struct match_list_displayer *displayer)
353{
354 rl_ding ();
355}
356
357/* CLI version of displayer.read_key. */
358
359static int
360cli_mld_read_key (const struct match_list_displayer *displayer)
361{
362 return rl_read_key ();
363}
364
365/* CLI version of rl_completion_display_matches_hook.
366 See gdb_display_match_list for a description of the arguments. */
367
368void
369cli_display_match_list (char **matches, int len, int max)
370{
371 struct match_list_displayer displayer;
372
373 rl_get_screen_size (&displayer.height, &displayer.width);
374 displayer.crlf = cli_mld_crlf;
375 displayer.putch = cli_mld_putch;
376 displayer.puts = cli_mld_puts;
377 displayer.flush = cli_mld_flush;
378 displayer.erase_entire_line = cli_mld_erase_entire_line;
379 displayer.beep = cli_mld_beep;
380 displayer.read_key = cli_mld_read_key;
381
382 gdb_display_match_list (matches, len, max, &displayer);
383 rl_forced_update_display ();
384}
This page took 1.229728 seconds and 4 git commands to generate.