Add self to write-after-approval list.
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638 1/* Output generating routines for GDB CLI.
b6ba6518 2 Copyright 1999, 2000 Free Software Foundation, Inc.
8b93c638
JM
3 Contributed by Cygnus Solutions.
4 Written by Fernando Nasser for Cygnus.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include "ui-out.h"
25#include "cli-out.h"
1d1358b6 26#include "gdb_string.h"
8b93c638
JM
27
28/* Convenience macro for allocting typesafe memory. */
29
30#ifndef XMALLOC
31#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
32#endif
33
34struct ui_out_data
35 {
36 struct ui_file *stream;
37 };
38
39/* These are the CLI output functions */
40
41static void cli_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid);
42static void cli_table_body (struct ui_out *uiout);
43static void cli_table_end (struct ui_out *uiout);
44static void cli_table_header (struct ui_out *uiout, int width,
45 enum ui_align alig, char *colhdr);
46static void cli_list_begin (struct ui_out *uiout, int list_flag, char *lstid);
47static void cli_list_end (struct ui_out *uiout, int list_flag);
48static void cli_field_int (struct ui_out *uiout, int fldno, int width,
49 enum ui_align alig, char *fldname, int value);
50static void cli_field_skip (struct ui_out *uiout, int fldno, int width,
51 enum ui_align alig, char *fldname);
52static void cli_field_string (struct ui_out *uiout, int fldno, int width,
53 enum ui_align alig, char *fldname,
54 const char *string);
55static void cli_field_fmt (struct ui_out *uiout, int fldno,
56 int width, enum ui_align align,
57 char *fldname, char *format, va_list args);
58static void cli_spaces (struct ui_out *uiout, int numspaces);
59static void cli_text (struct ui_out *uiout, char *string);
60static void cli_message (struct ui_out *uiout, int verbosity, char *format,
61 va_list args);
62static void cli_wrap_hint (struct ui_out *uiout, char *identstring);
63static void cli_flush (struct ui_out *uiout);
64
65/* This is the CLI ui-out implementation functions vector */
66
67/* FIXME: This can be initialized dynamically after default is set to
68 handle initial output in main.c */
69
70static struct ui_out_impl cli_ui_out_impl =
71{
72 cli_table_begin,
73 cli_table_body,
74 cli_table_end,
75 cli_table_header,
76 cli_list_begin,
77 cli_list_end,
78 cli_field_int,
79 cli_field_skip,
80 cli_field_string,
81 cli_field_fmt,
82 cli_spaces,
83 cli_text,
84 cli_message,
85 cli_wrap_hint,
86 cli_flush
87};
88
89/* Prototypes for local functions */
90
a14ed312 91extern void _initialize_cli_out (void);
8b93c638
JM
92
93static void field_separator (void);
94
95static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
96 char *format,...);
97
98/* local variables */
99
100/* (none yet) */
101
102/* Mark beginning of a table */
103
104void
fba45db2 105cli_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid)
8b93c638
JM
106{
107}
108
109/* Mark beginning of a table body */
110
111void
fba45db2 112cli_table_body (struct ui_out *uiout)
8b93c638
JM
113{
114 /* first, close the table header line */
115 cli_text (uiout, "\n");
116}
117
118/* Mark end of a table */
119
120void
fba45db2 121cli_table_end (struct ui_out *uiout)
8b93c638
JM
122{
123}
124
125/* Specify table header */
126
127void
fba45db2
KB
128cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
129 char *colhdr)
8b93c638
JM
130{
131 cli_field_string (uiout, 0, width, alignment, 0, colhdr);
132}
133
134/* Mark beginning of a list */
135
136void
fba45db2 137cli_list_begin (struct ui_out *uiout, int list_flag, char *lstid)
8b93c638
JM
138{
139}
140
141/* Mark end of a list */
142
143void
fba45db2 144cli_list_end (struct ui_out *uiout, int list_flag)
8b93c638
JM
145{
146}
147
148/* output an int field */
149
150void
fba45db2
KB
151cli_field_int (struct ui_out *uiout, int fldno, int width,
152 enum ui_align alignment, char *fldname, int value)
8b93c638
JM
153{
154 char buffer[20]; /* FIXME: how many chars long a %d can become? */
155
156 sprintf (buffer, "%d", value);
157 cli_field_string (uiout, fldno, width, alignment, fldname, buffer);
158}
159
160/* used to ommit a field */
161
162void
fba45db2
KB
163cli_field_skip (struct ui_out *uiout, int fldno, int width,
164 enum ui_align alignment, char *fldname)
8b93c638
JM
165{
166 cli_field_string (uiout, fldno, width, alignment, fldname, "");
167}
168
169/* other specific cli_field_* end up here so alignment and field
170 separators are both handled by cli_field_string */
171
172void
173cli_field_string (struct ui_out *uiout,
174 int fldno,
175 int width,
55555bbc 176 enum ui_align align,
8b93c638
JM
177 char *fldname,
178 const char *string)
179{
180 int before = 0;
181 int after = 0;
182
183 if ((align != ui_noalign) && string)
184 {
185 before = width - strlen (string);
186 if (before <= 0)
187 before = 0;
188 else
189 {
190 if (align == ui_right)
191 after = 0;
192 else if (align == ui_left)
193 {
194 after = before;
195 before = 0;
196 }
197 else
198 /* ui_center */
199 {
200 after = before / 2;
201 before -= after;
202 }
203 }
204 }
205
206 if (before)
207 ui_out_spaces (uiout, before);
208 if (string)
209 out_field_fmt (uiout, fldno, fldname, "%s", string);
210 if (after)
211 ui_out_spaces (uiout, after);
212
213 if (align != ui_noalign)
214 field_separator ();
215}
216
217/* This is the only field function that does not align */
218
219void
220cli_field_fmt (struct ui_out *uiout, int fldno,
221 int width, enum ui_align align,
222 char *fldname, char *format, va_list args)
223{
224 struct ui_out_data *data = ui_out_data (uiout);
225 vfprintf_filtered (data->stream, format, args);
226
227 if (align != ui_noalign)
228 field_separator ();
229}
230
231void
fba45db2 232cli_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
233{
234 struct ui_out_data *data = ui_out_data (uiout);
235 print_spaces_filtered (numspaces, data->stream);
236}
237
238void
fba45db2 239cli_text (struct ui_out *uiout, char *string)
8b93c638
JM
240{
241 struct ui_out_data *data = ui_out_data (uiout);
242 fputs_filtered (string, data->stream);
243}
244
245void
246cli_message (struct ui_out *uiout, int verbosity, char *format, va_list args)
247{
248 struct ui_out_data *data = ui_out_data (uiout);
249 if (ui_out_get_verblvl (uiout) >= verbosity)
250 vfprintf_unfiltered (data->stream, format, args);
251}
252
253void
fba45db2 254cli_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
255{
256 wrap_here (identstring);
257}
258
259void
fba45db2 260cli_flush (struct ui_out *uiout)
8b93c638
JM
261{
262 struct ui_out_data *data = ui_out_data (uiout);
263 gdb_flush (data->stream);
264}
265
266/* local functions */
267
268/* Like cli_field_fmt, but takes a variable number of args
269 and makes a va_list and does not insert a separator */
270
271/* VARARGS */
272static void
273out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
274 char *format,...)
275{
276 struct ui_out_data *data = ui_out_data (uiout);
277 va_list args;
278
279 va_start (args, format);
280 vfprintf_filtered (data->stream, format, args);
281
282 va_end (args);
283}
284
285/* access to ui_out format private members */
286
287static void
fba45db2 288field_separator (void)
8b93c638
JM
289{
290 struct ui_out_data *data = ui_out_data (uiout);
291 fputc_filtered (' ', data->stream);
292}
293
294/* initalize private members at startup */
295
296struct ui_out *
297cli_out_new (struct ui_file *stream)
298{
299 int flags = ui_source_list;
300
301 struct ui_out_data *data = XMALLOC (struct ui_out_data);
302 data->stream = stream;
303 return ui_out_new (&cli_ui_out_impl, data, flags);
304}
305
306/* standard gdb initialization hook */
307void
fba45db2 308_initialize_cli_out (void)
8b93c638
JM
309{
310 /* nothing needs to be done */
311}
This page took 0.102928 seconds and 4 git commands to generate.