Replace ui_out_list_{begin,end}() with ui_out_{begin,end}().
[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);
631ec795
AC
46static void cli_begin (struct ui_out *uiout, enum ui_out_type type,
47 int level, const char *lstid);
48static void cli_end (struct ui_out *uiout, enum ui_out_type type, int level);
8b93c638
JM
49static void cli_field_int (struct ui_out *uiout, int fldno, int width,
50 enum ui_align alig, char *fldname, int value);
51static void cli_field_skip (struct ui_out *uiout, int fldno, int width,
52 enum ui_align alig, char *fldname);
53static void cli_field_string (struct ui_out *uiout, int fldno, int width,
54 enum ui_align alig, char *fldname,
55 const char *string);
56static void cli_field_fmt (struct ui_out *uiout, int fldno,
57 int width, enum ui_align align,
58 char *fldname, char *format, va_list args);
59static void cli_spaces (struct ui_out *uiout, int numspaces);
60static void cli_text (struct ui_out *uiout, char *string);
61static void cli_message (struct ui_out *uiout, int verbosity, char *format,
62 va_list args);
63static void cli_wrap_hint (struct ui_out *uiout, char *identstring);
64static void cli_flush (struct ui_out *uiout);
65
66/* This is the CLI ui-out implementation functions vector */
67
68/* FIXME: This can be initialized dynamically after default is set to
69 handle initial output in main.c */
70
71static struct ui_out_impl cli_ui_out_impl =
72{
73 cli_table_begin,
74 cli_table_body,
75 cli_table_end,
76 cli_table_header,
631ec795
AC
77 cli_begin,
78 cli_end,
8b93c638
JM
79 cli_field_int,
80 cli_field_skip,
81 cli_field_string,
82 cli_field_fmt,
83 cli_spaces,
84 cli_text,
85 cli_message,
86 cli_wrap_hint,
87 cli_flush
88};
89
90/* Prototypes for local functions */
91
a14ed312 92extern void _initialize_cli_out (void);
8b93c638
JM
93
94static void field_separator (void);
95
96static void out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
97 char *format,...);
98
99/* local variables */
100
101/* (none yet) */
102
103/* Mark beginning of a table */
104
105void
fba45db2 106cli_table_begin (struct ui_out *uiout, int nbrofcols, char *tblid)
8b93c638
JM
107{
108}
109
110/* Mark beginning of a table body */
111
112void
fba45db2 113cli_table_body (struct ui_out *uiout)
8b93c638
JM
114{
115 /* first, close the table header line */
116 cli_text (uiout, "\n");
117}
118
119/* Mark end of a table */
120
121void
fba45db2 122cli_table_end (struct ui_out *uiout)
8b93c638
JM
123{
124}
125
126/* Specify table header */
127
128void
fba45db2
KB
129cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
130 char *colhdr)
8b93c638
JM
131{
132 cli_field_string (uiout, 0, width, alignment, 0, colhdr);
133}
134
135/* Mark beginning of a list */
136
137void
631ec795
AC
138cli_begin (struct ui_out *uiout,
139 enum ui_out_type type,
140 int level,
141 const char *id)
8b93c638
JM
142{
143}
144
145/* Mark end of a list */
146
147void
631ec795
AC
148cli_end (struct ui_out *uiout,
149 enum ui_out_type type,
150 int level)
8b93c638
JM
151{
152}
153
154/* output an int field */
155
156void
fba45db2
KB
157cli_field_int (struct ui_out *uiout, int fldno, int width,
158 enum ui_align alignment, char *fldname, int value)
8b93c638
JM
159{
160 char buffer[20]; /* FIXME: how many chars long a %d can become? */
161
162 sprintf (buffer, "%d", value);
163 cli_field_string (uiout, fldno, width, alignment, fldname, buffer);
164}
165
166/* used to ommit a field */
167
168void
fba45db2
KB
169cli_field_skip (struct ui_out *uiout, int fldno, int width,
170 enum ui_align alignment, char *fldname)
8b93c638
JM
171{
172 cli_field_string (uiout, fldno, width, alignment, fldname, "");
173}
174
175/* other specific cli_field_* end up here so alignment and field
176 separators are both handled by cli_field_string */
177
178void
179cli_field_string (struct ui_out *uiout,
180 int fldno,
181 int width,
55555bbc 182 enum ui_align align,
8b93c638
JM
183 char *fldname,
184 const char *string)
185{
186 int before = 0;
187 int after = 0;
188
189 if ((align != ui_noalign) && string)
190 {
191 before = width - strlen (string);
192 if (before <= 0)
193 before = 0;
194 else
195 {
196 if (align == ui_right)
197 after = 0;
198 else if (align == ui_left)
199 {
200 after = before;
201 before = 0;
202 }
203 else
204 /* ui_center */
205 {
206 after = before / 2;
207 before -= after;
208 }
209 }
210 }
211
212 if (before)
213 ui_out_spaces (uiout, before);
214 if (string)
215 out_field_fmt (uiout, fldno, fldname, "%s", string);
216 if (after)
217 ui_out_spaces (uiout, after);
218
219 if (align != ui_noalign)
220 field_separator ();
221}
222
223/* This is the only field function that does not align */
224
225void
226cli_field_fmt (struct ui_out *uiout, int fldno,
227 int width, enum ui_align align,
228 char *fldname, char *format, va_list args)
229{
230 struct ui_out_data *data = ui_out_data (uiout);
231 vfprintf_filtered (data->stream, format, args);
232
233 if (align != ui_noalign)
234 field_separator ();
235}
236
237void
fba45db2 238cli_spaces (struct ui_out *uiout, int numspaces)
8b93c638
JM
239{
240 struct ui_out_data *data = ui_out_data (uiout);
241 print_spaces_filtered (numspaces, data->stream);
242}
243
244void
fba45db2 245cli_text (struct ui_out *uiout, char *string)
8b93c638
JM
246{
247 struct ui_out_data *data = ui_out_data (uiout);
248 fputs_filtered (string, data->stream);
249}
250
251void
252cli_message (struct ui_out *uiout, int verbosity, char *format, va_list args)
253{
254 struct ui_out_data *data = ui_out_data (uiout);
255 if (ui_out_get_verblvl (uiout) >= verbosity)
256 vfprintf_unfiltered (data->stream, format, args);
257}
258
259void
fba45db2 260cli_wrap_hint (struct ui_out *uiout, char *identstring)
8b93c638
JM
261{
262 wrap_here (identstring);
263}
264
265void
fba45db2 266cli_flush (struct ui_out *uiout)
8b93c638
JM
267{
268 struct ui_out_data *data = ui_out_data (uiout);
269 gdb_flush (data->stream);
270}
271
272/* local functions */
273
274/* Like cli_field_fmt, but takes a variable number of args
275 and makes a va_list and does not insert a separator */
276
277/* VARARGS */
278static void
279out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
280 char *format,...)
281{
282 struct ui_out_data *data = ui_out_data (uiout);
283 va_list args;
284
285 va_start (args, format);
286 vfprintf_filtered (data->stream, format, args);
287
288 va_end (args);
289}
290
291/* access to ui_out format private members */
292
293static void
fba45db2 294field_separator (void)
8b93c638
JM
295{
296 struct ui_out_data *data = ui_out_data (uiout);
297 fputc_filtered (' ', data->stream);
298}
299
300/* initalize private members at startup */
301
302struct ui_out *
303cli_out_new (struct ui_file *stream)
304{
305 int flags = ui_source_list;
306
307 struct ui_out_data *data = XMALLOC (struct ui_out_data);
308 data->stream = stream;
309 return ui_out_new (&cli_ui_out_impl, data, flags);
310}
311
312/* standard gdb initialization hook */
313void
fba45db2 314_initialize_cli_out (void)
8b93c638
JM
315{
316 /* nothing needs to be done */
317}
This page took 0.08383 seconds and 4 git commands to generate.