]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/cli-out.c
Fix M68HC11_NUM_REGS
[thirdparty/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
349c5d5f 2
61baf725 3 Copyright (C) 1999-2017 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"
8b93c638 28
02a45ac0
PA
29/* These are the CLI output functions */
30
8b93c638
JM
31/* Mark beginning of a table */
32
112e8700
SM
33void
34cli_ui_out::do_table_begin (int nbrofcols, int nr_rows, const char *tblid)
8b93c638 35{
698384cd 36 if (nr_rows == 0)
112e8700 37 m_suppress_output = true;
698384cd 38 else
ce2826aa 39 /* Only the table suppresses the output and, fortunately, a table
30fdc99f 40 is not a recursive data structure. */
112e8700 41 gdb_assert (!m_suppress_output);
8b93c638
JM
42}
43
44/* Mark beginning of a table body */
45
112e8700
SM
46void
47cli_ui_out::do_table_body ()
8b93c638 48{
112e8700 49 if (m_suppress_output)
698384cd 50 return;
112e8700 51
8b93c638 52 /* first, close the table header line */
112e8700 53 text ("\n");
8b93c638
JM
54}
55
56/* Mark end of a table */
57
112e8700
SM
58void
59cli_ui_out::do_table_end ()
8b93c638 60{
112e8700 61 m_suppress_output = false;
8b93c638
JM
62}
63
64/* Specify table header */
65
112e8700
SM
66void
67cli_ui_out::do_table_header (int width, ui_align alignment,
68 const std::string &col_name,
69 const std::string &col_hdr)
8b93c638 70{
112e8700 71 if (m_suppress_output)
698384cd 72 return;
0a8fce9a 73
112e8700 74 do_field_string (0, width, alignment, 0, col_hdr.c_str ());
8b93c638
JM
75}
76
77/* Mark beginning of a list */
78
112e8700
SM
79void
80cli_ui_out::do_begin (ui_out_type type, const char *id)
8b93c638
JM
81{
82}
83
84/* Mark end of a list */
85
112e8700
SM
86void
87cli_ui_out::do_end (ui_out_type type)
8b93c638
JM
88{
89}
90
91/* output an int field */
92
112e8700
SM
93void
94cli_ui_out::do_field_int (int fldno, int width, ui_align alignment,
95 const char *fldname, int value)
8b93c638 96{
c5504eaf 97 char buffer[20]; /* FIXME: how many chars long a %d can become? */
c5504eaf 98
112e8700 99 if (m_suppress_output)
698384cd 100 return;
112e8700 101
08850b56 102 xsnprintf (buffer, sizeof (buffer), "%d", value);
0a8fce9a 103
112e8700 104 do_field_string (fldno, width, alignment, fldname, buffer);
8b93c638
JM
105}
106
112e8700 107/* used to omit a field */
8b93c638 108
112e8700
SM
109void
110cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
111 const char *fldname)
8b93c638 112{
112e8700 113 if (m_suppress_output)
698384cd 114 return;
0a8fce9a 115
112e8700 116 do_field_string (fldno, width, alignment, fldname, "");
8b93c638
JM
117}
118
119/* other specific cli_field_* end up here so alignment and field
120 separators are both handled by cli_field_string */
121
112e8700
SM
122void
123cli_ui_out::do_field_string (int fldno, int width, ui_align align,
124 const char *fldname, const char *string)
8b93c638
JM
125{
126 int before = 0;
127 int after = 0;
c5504eaf 128
112e8700 129 if (m_suppress_output)
698384cd
AC
130 return;
131
8b93c638
JM
132 if ((align != ui_noalign) && string)
133 {
134 before = width - strlen (string);
135 if (before <= 0)
136 before = 0;
137 else
138 {
139 if (align == ui_right)
140 after = 0;
141 else if (align == ui_left)
142 {
143 after = before;
144 before = 0;
145 }
146 else
147 /* ui_center */
148 {
149 after = before / 2;
150 before -= after;
151 }
152 }
153 }
154
155 if (before)
112e8700
SM
156 spaces (before);
157
8b93c638 158 if (string)
112e8700
SM
159 out_field_fmt (fldno, fldname, "%s", string);
160
8b93c638 161 if (after)
112e8700 162 spaces (after);
8b93c638
JM
163
164 if (align != ui_noalign)
165 field_separator ();
166}
167
30fdc99f 168/* This is the only field function that does not align. */
8b93c638 169
112e8700
SM
170void
171cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
172 const char *fldname, const char *format,
173 va_list args)
8b93c638 174{
112e8700 175 if (m_suppress_output)
698384cd
AC
176 return;
177
112e8700 178 vfprintf_filtered (m_streams.back (), format, args);
8b93c638
JM
179
180 if (align != ui_noalign)
181 field_separator ();
182}
183
112e8700
SM
184void
185cli_ui_out::do_spaces (int numspaces)
8b93c638 186{
112e8700 187 if (m_suppress_output)
698384cd 188 return;
14dba4b4 189
112e8700 190 print_spaces_filtered (numspaces, m_streams.back ());
8b93c638
JM
191}
192
112e8700
SM
193void
194cli_ui_out::do_text (const char *string)
8b93c638 195{
112e8700 196 if (m_suppress_output)
698384cd 197 return;
14dba4b4 198
112e8700 199 fputs_filtered (string, m_streams.back ());
8b93c638
JM
200}
201
112e8700
SM
202void
203cli_ui_out::do_message (const char *format, va_list args)
8b93c638 204{
112e8700 205 if (m_suppress_output)
698384cd 206 return;
14dba4b4 207
112e8700 208 vfprintf_unfiltered (m_streams.back (), format, args);
8b93c638
JM
209}
210
112e8700
SM
211void
212cli_ui_out::do_wrap_hint (const char *identstring)
8b93c638 213{
112e8700 214 if (m_suppress_output)
698384cd 215 return;
112e8700 216
8b93c638
JM
217 wrap_here (identstring);
218}
219
112e8700
SM
220void
221cli_ui_out::do_flush ()
8b93c638 222{
112e8700 223 gdb_flush (m_streams.back ());
8b93c638
JM
224}
225
14dba4b4
JK
226/* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
227 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
228 output stream; it is an internal error if it does not exist. */
229
7becfd03 230void
112e8700 231cli_ui_out::do_redirect (ui_file *outstream)
0fac0b41 232{
0fac0b41 233 if (outstream != NULL)
112e8700 234 m_streams.push_back (outstream);
14dba4b4 235 else
112e8700 236 m_streams.pop_back ();
0fac0b41
DJ
237}
238
8b93c638
JM
239/* local functions */
240
112e8700 241/* Like cli_ui_out::do_field_fmt, but takes a variable number of args
30fdc99f 242 and makes a va_list and does not insert a separator. */
8b93c638
JM
243
244/* VARARGS */
112e8700
SM
245void
246cli_ui_out::out_field_fmt (int fldno, const char *fldname,
247 const char *format, ...)
8b93c638 248{
8b93c638
JM
249 va_list args;
250
251 va_start (args, format);
112e8700 252 vfprintf_filtered (m_streams.back (), format, args);
8b93c638
JM
253
254 va_end (args);
255}
256
112e8700
SM
257void
258cli_ui_out::field_separator ()
8b93c638 259{
112e8700 260 fputc_filtered (' ', m_streams.back ());
8b93c638
JM
261}
262
112e8700 263/* Constructor for cli_ui_out. */
02a45ac0 264
112e8700
SM
265cli_ui_out::cli_ui_out (ui_file *stream, ui_out_flags flags)
266: ui_out (flags),
267 m_suppress_output (false)
0a8fce9a 268{
14dba4b4
JK
269 gdb_assert (stream != NULL);
270
112e8700
SM
271 m_streams.push_back (stream);
272}
14dba4b4 273
112e8700
SM
274cli_ui_out::~cli_ui_out ()
275{
0a8fce9a
PA
276}
277
278/* Initialize private members at startup. */
8b93c638 279
112e8700 280cli_ui_out *
8b93c638
JM
281cli_out_new (struct ui_file *stream)
282{
112e8700 283 return new cli_ui_out (stream, ui_source_list);
8b93c638
JM
284}
285
112e8700
SM
286ui_file *
287cli_ui_out::set_stream (struct ui_file *stream)
4389a95a 288{
112e8700 289 ui_file *old;
b9b118c3 290
112e8700
SM
291 old = m_streams.back ();
292 m_streams.back () = stream;
c5504eaf 293
4389a95a
AC
294 return old;
295}
b9b118c3 296
82083d6d
DE
297/* CLI interface to display tab-completion matches. */
298
299/* CLI version of displayer.crlf. */
300
301static void
302cli_mld_crlf (const struct match_list_displayer *displayer)
303{
304 rl_crlf ();
305}
306
307/* CLI version of displayer.putch. */
308
309static void
310cli_mld_putch (const struct match_list_displayer *displayer, int ch)
311{
312 putc (ch, rl_outstream);
313}
314
315/* CLI version of displayer.puts. */
316
317static void
318cli_mld_puts (const struct match_list_displayer *displayer, const char *s)
319{
320 fputs (s, rl_outstream);
321}
322
323/* CLI version of displayer.flush. */
324
325static void
326cli_mld_flush (const struct match_list_displayer *displayer)
327{
328 fflush (rl_outstream);
329}
330
56000a98
PA
331EXTERN_C void _rl_erase_entire_line (void);
332
82083d6d
DE
333/* CLI version of displayer.erase_entire_line. */
334
335static void
336cli_mld_erase_entire_line (const struct match_list_displayer *displayer)
337{
82083d6d
DE
338 _rl_erase_entire_line ();
339}
340
341/* CLI version of displayer.beep. */
342
343static void
344cli_mld_beep (const struct match_list_displayer *displayer)
345{
346 rl_ding ();
347}
348
349/* CLI version of displayer.read_key. */
350
351static int
352cli_mld_read_key (const struct match_list_displayer *displayer)
353{
354 return rl_read_key ();
355}
356
357/* CLI version of rl_completion_display_matches_hook.
358 See gdb_display_match_list for a description of the arguments. */
359
360void
361cli_display_match_list (char **matches, int len, int max)
362{
363 struct match_list_displayer displayer;
364
365 rl_get_screen_size (&displayer.height, &displayer.width);
366 displayer.crlf = cli_mld_crlf;
367 displayer.putch = cli_mld_putch;
368 displayer.puts = cli_mld_puts;
369 displayer.flush = cli_mld_flush;
370 displayer.erase_entire_line = cli_mld_erase_entire_line;
371 displayer.beep = cli_mld_beep;
372 displayer.read_key = cli_mld_read_key;
373
374 gdb_display_match_list (matches, len, max, &displayer);
375 rl_forced_update_display ();
376}