Replace int with enum block_enum where appropriate.
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
42a4f53d 3 Copyright (C) 1999-2019 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"
4de283e4 24#include "ui-out.h"
8b93c638 25#include "cli-out.h"
82083d6d 26#include "completer.h"
82083d6d 27#include "readline/readline.h"
4de283e4 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 95void
381befee
TT
96cli_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
97 const char *fldname, LONGEST value)
8b93c638 98{
112e8700 99 if (m_suppress_output)
698384cd 100 return;
112e8700 101
381befee 102 do_field_string (fldno, width, alignment, fldname, plongest (value),
cbe56571 103 ui_out_style_kind::DEFAULT);
8b93c638
JM
104}
105
1f77b012
TT
106/* output an unsigned field */
107
108void
109cli_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
110 const char *fldname, ULONGEST value)
111{
112 if (m_suppress_output)
113 return;
114
115 do_field_string (fldno, width, alignment, fldname, pulongest (value),
116 ui_out_style_kind::DEFAULT);
117}
118
112e8700 119/* used to omit a field */
8b93c638 120
112e8700
SM
121void
122cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
123 const char *fldname)
8b93c638 124{
112e8700 125 if (m_suppress_output)
698384cd 126 return;
0a8fce9a 127
cbe56571
TT
128 do_field_string (fldno, width, alignment, fldname, "",
129 ui_out_style_kind::DEFAULT);
8b93c638
JM
130}
131
132/* other specific cli_field_* end up here so alignment and field
133 separators are both handled by cli_field_string */
134
112e8700
SM
135void
136cli_ui_out::do_field_string (int fldno, int width, ui_align align,
cbe56571
TT
137 const char *fldname, const char *string,
138 ui_out_style_kind style)
8b93c638
JM
139{
140 int before = 0;
141 int after = 0;
c5504eaf 142
112e8700 143 if (m_suppress_output)
698384cd
AC
144 return;
145
8b93c638
JM
146 if ((align != ui_noalign) && string)
147 {
148 before = width - strlen (string);
149 if (before <= 0)
150 before = 0;
151 else
152 {
153 if (align == ui_right)
154 after = 0;
155 else if (align == ui_left)
156 {
157 after = before;
158 before = 0;
159 }
160 else
161 /* ui_center */
162 {
163 after = before / 2;
164 before -= after;
165 }
166 }
167 }
168
169 if (before)
112e8700
SM
170 spaces (before);
171
8b93c638 172 if (string)
cbe56571
TT
173 {
174 ui_file_style fstyle;
175 switch (style)
176 {
177 case ui_out_style_kind::DEFAULT:
178 /* Nothing. */
179 break;
180 case ui_out_style_kind::FILE:
181 /* Nothing. */
182 fstyle = file_name_style.style ();
183 break;
184 case ui_out_style_kind::FUNCTION:
185 fstyle = function_name_style.style ();
186 break;
80ae2043
TT
187 case ui_out_style_kind::VARIABLE:
188 fstyle = variable_name_style.style ();
189 break;
35fb8261
TT
190 case ui_out_style_kind::ADDRESS:
191 fstyle = address_style.style ();
192 break;
cbe56571
TT
193 default:
194 gdb_assert_not_reached ("missing case");
195 }
196 fputs_styled (string, fstyle, m_streams.back ());
197 }
112e8700 198
8b93c638 199 if (after)
112e8700 200 spaces (after);
8b93c638
JM
201
202 if (align != ui_noalign)
203 field_separator ();
204}
205
1871a62d 206/* Output field containing ARGS using printf formatting in FORMAT. */
8b93c638 207
112e8700
SM
208void
209cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
210 const char *fldname, const char *format,
211 va_list args)
8b93c638 212{
112e8700 213 if (m_suppress_output)
698384cd
AC
214 return;
215
1871a62d 216 std::string str = string_vprintf (format, args);
8b93c638 217
cbe56571
TT
218 do_field_string (fldno, width, align, fldname, str.c_str (),
219 ui_out_style_kind::DEFAULT);
8b93c638
JM
220}
221
112e8700
SM
222void
223cli_ui_out::do_spaces (int numspaces)
8b93c638 224{
112e8700 225 if (m_suppress_output)
698384cd 226 return;
14dba4b4 227
112e8700 228 print_spaces_filtered (numspaces, m_streams.back ());
8b93c638
JM
229}
230
112e8700
SM
231void
232cli_ui_out::do_text (const char *string)
8b93c638 233{
112e8700 234 if (m_suppress_output)
698384cd 235 return;
14dba4b4 236
112e8700 237 fputs_filtered (string, m_streams.back ());
8b93c638
JM
238}
239
112e8700
SM
240void
241cli_ui_out::do_message (const char *format, va_list args)
8b93c638 242{
112e8700 243 if (m_suppress_output)
698384cd 244 return;
14dba4b4 245
112e8700 246 vfprintf_unfiltered (m_streams.back (), format, args);
8b93c638
JM
247}
248
112e8700
SM
249void
250cli_ui_out::do_wrap_hint (const char *identstring)
8b93c638 251{
112e8700 252 if (m_suppress_output)
698384cd 253 return;
112e8700 254
8b93c638
JM
255 wrap_here (identstring);
256}
257
112e8700
SM
258void
259cli_ui_out::do_flush ()
8b93c638 260{
112e8700 261 gdb_flush (m_streams.back ());
8b93c638
JM
262}
263
14dba4b4
JK
264/* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
265 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
266 output stream; it is an internal error if it does not exist. */
267
7becfd03 268void
112e8700 269cli_ui_out::do_redirect (ui_file *outstream)
0fac0b41 270{
0fac0b41 271 if (outstream != NULL)
112e8700 272 m_streams.push_back (outstream);
14dba4b4 273 else
112e8700 274 m_streams.pop_back ();
0fac0b41
DJ
275}
276
8b93c638
JM
277/* local functions */
278
112e8700
SM
279void
280cli_ui_out::field_separator ()
8b93c638 281{
112e8700 282 fputc_filtered (' ', m_streams.back ());
8b93c638
JM
283}
284
112e8700 285/* Constructor for cli_ui_out. */
02a45ac0 286
112e8700
SM
287cli_ui_out::cli_ui_out (ui_file *stream, ui_out_flags flags)
288: ui_out (flags),
289 m_suppress_output (false)
0a8fce9a 290{
14dba4b4
JK
291 gdb_assert (stream != NULL);
292
112e8700
SM
293 m_streams.push_back (stream);
294}
14dba4b4 295
112e8700
SM
296cli_ui_out::~cli_ui_out ()
297{
0a8fce9a
PA
298}
299
300/* Initialize private members at startup. */
8b93c638 301
112e8700 302cli_ui_out *
8b93c638
JM
303cli_out_new (struct ui_file *stream)
304{
112e8700 305 return new cli_ui_out (stream, ui_source_list);
8b93c638
JM
306}
307
112e8700
SM
308ui_file *
309cli_ui_out::set_stream (struct ui_file *stream)
4389a95a 310{
112e8700 311 ui_file *old;
b9b118c3 312
112e8700
SM
313 old = m_streams.back ();
314 m_streams.back () = stream;
c5504eaf 315
4389a95a
AC
316 return old;
317}
b9b118c3 318
82083d6d
DE
319/* CLI interface to display tab-completion matches. */
320
321/* CLI version of displayer.crlf. */
322
323static void
324cli_mld_crlf (const struct match_list_displayer *displayer)
325{
326 rl_crlf ();
327}
328
329/* CLI version of displayer.putch. */
330
331static void
332cli_mld_putch (const struct match_list_displayer *displayer, int ch)
333{
334 putc (ch, rl_outstream);
335}
336
337/* CLI version of displayer.puts. */
338
339static void
340cli_mld_puts (const struct match_list_displayer *displayer, const char *s)
341{
342 fputs (s, rl_outstream);
343}
344
345/* CLI version of displayer.flush. */
346
347static void
348cli_mld_flush (const struct match_list_displayer *displayer)
349{
350 fflush (rl_outstream);
351}
352
56000a98
PA
353EXTERN_C void _rl_erase_entire_line (void);
354
82083d6d
DE
355/* CLI version of displayer.erase_entire_line. */
356
357static void
358cli_mld_erase_entire_line (const struct match_list_displayer *displayer)
359{
82083d6d
DE
360 _rl_erase_entire_line ();
361}
362
363/* CLI version of displayer.beep. */
364
365static void
366cli_mld_beep (const struct match_list_displayer *displayer)
367{
368 rl_ding ();
369}
370
371/* CLI version of displayer.read_key. */
372
373static int
374cli_mld_read_key (const struct match_list_displayer *displayer)
375{
376 return rl_read_key ();
377}
378
379/* CLI version of rl_completion_display_matches_hook.
380 See gdb_display_match_list for a description of the arguments. */
381
382void
383cli_display_match_list (char **matches, int len, int max)
384{
385 struct match_list_displayer displayer;
386
387 rl_get_screen_size (&displayer.height, &displayer.width);
388 displayer.crlf = cli_mld_crlf;
389 displayer.putch = cli_mld_putch;
390 displayer.puts = cli_mld_puts;
391 displayer.flush = cli_mld_flush;
392 displayer.erase_entire_line = cli_mld_erase_entire_line;
393 displayer.beep = cli_mld_beep;
394 displayer.read_key = cli_mld_read_key;
395
396 gdb_display_match_list (matches, len, max, &displayer);
397 rl_forced_update_display ();
398}
This page took 1.458897 seconds and 4 git commands to generate.