2000-03-30 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / cli-out.c
CommitLineData
8b93c638
JM
1/* Output generating routines for GDB CLI.
2 Copyright 1999-2000 Free Software Foundation, Inc.
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
91extern void _initialize_cli_out PARAMS ((void));
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
105cli_table_begin (uiout, nbrofcols, tblid)
106 struct ui_out *uiout;
107 int nbrofcols;
108 char *tblid;
109{
110}
111
112/* Mark beginning of a table body */
113
114void
115cli_table_body (uiout)
116 struct ui_out *uiout;
117{
118 /* first, close the table header line */
119 cli_text (uiout, "\n");
120}
121
122/* Mark end of a table */
123
124void
125cli_table_end (uiout)
126 struct ui_out *uiout;
127{
128}
129
130/* Specify table header */
131
132void
133cli_table_header (uiout, width, alignment, colhdr)
134 struct ui_out *uiout;
135 int width;
55555bbc 136 enum ui_align alignment;
8b93c638
JM
137 char *colhdr;
138{
139 cli_field_string (uiout, 0, width, alignment, 0, colhdr);
140}
141
142/* Mark beginning of a list */
143
144void
145cli_list_begin (uiout, list_flag, lstid)
146 struct ui_out *uiout;
147 int list_flag;
148 char *lstid;
149{
150}
151
152/* Mark end of a list */
153
154void
155cli_list_end (uiout, list_flag)
156 struct ui_out *uiout;
157 int list_flag;
158{
159}
160
161/* output an int field */
162
163void
164cli_field_int (uiout, fldno, width, alignment, fldname, value)
165 struct ui_out *uiout;
166 int fldno;
167 int width;
55555bbc 168 enum ui_align alignment;
8b93c638
JM
169 char *fldname;
170 int value;
171{
172 char buffer[20]; /* FIXME: how many chars long a %d can become? */
173
174 sprintf (buffer, "%d", value);
175 cli_field_string (uiout, fldno, width, alignment, fldname, buffer);
176}
177
178/* used to ommit a field */
179
180void
181cli_field_skip (uiout, fldno, width, alignment, fldname)
182 struct ui_out *uiout;
183 int fldno;
184 int width;
55555bbc 185 enum ui_align alignment;
8b93c638
JM
186 char *fldname;
187{
188 cli_field_string (uiout, fldno, width, alignment, fldname, "");
189}
190
191/* other specific cli_field_* end up here so alignment and field
192 separators are both handled by cli_field_string */
193
194void
195cli_field_string (struct ui_out *uiout,
196 int fldno,
197 int width,
55555bbc 198 enum ui_align align,
8b93c638
JM
199 char *fldname,
200 const char *string)
201{
202 int before = 0;
203 int after = 0;
204
205 if ((align != ui_noalign) && string)
206 {
207 before = width - strlen (string);
208 if (before <= 0)
209 before = 0;
210 else
211 {
212 if (align == ui_right)
213 after = 0;
214 else if (align == ui_left)
215 {
216 after = before;
217 before = 0;
218 }
219 else
220 /* ui_center */
221 {
222 after = before / 2;
223 before -= after;
224 }
225 }
226 }
227
228 if (before)
229 ui_out_spaces (uiout, before);
230 if (string)
231 out_field_fmt (uiout, fldno, fldname, "%s", string);
232 if (after)
233 ui_out_spaces (uiout, after);
234
235 if (align != ui_noalign)
236 field_separator ();
237}
238
239/* This is the only field function that does not align */
240
241void
242cli_field_fmt (struct ui_out *uiout, int fldno,
243 int width, enum ui_align align,
244 char *fldname, char *format, va_list args)
245{
246 struct ui_out_data *data = ui_out_data (uiout);
247 vfprintf_filtered (data->stream, format, args);
248
249 if (align != ui_noalign)
250 field_separator ();
251}
252
253void
254cli_spaces (uiout, numspaces)
255 struct ui_out *uiout;
256 int numspaces;
257{
258 struct ui_out_data *data = ui_out_data (uiout);
259 print_spaces_filtered (numspaces, data->stream);
260}
261
262void
263cli_text (uiout, string)
264 struct ui_out *uiout;
265 char *string;
266{
267 struct ui_out_data *data = ui_out_data (uiout);
268 fputs_filtered (string, data->stream);
269}
270
271void
272cli_message (struct ui_out *uiout, int verbosity, char *format, va_list args)
273{
274 struct ui_out_data *data = ui_out_data (uiout);
275 if (ui_out_get_verblvl (uiout) >= verbosity)
276 vfprintf_unfiltered (data->stream, format, args);
277}
278
279void
280cli_wrap_hint (uiout, identstring)
281 struct ui_out *uiout;
282 char *identstring;
283{
284 wrap_here (identstring);
285}
286
287void
288cli_flush (uiout)
289 struct ui_out *uiout;
290{
291 struct ui_out_data *data = ui_out_data (uiout);
292 gdb_flush (data->stream);
293}
294
295/* local functions */
296
297/* Like cli_field_fmt, but takes a variable number of args
298 and makes a va_list and does not insert a separator */
299
300/* VARARGS */
301static void
302out_field_fmt (struct ui_out *uiout, int fldno, char *fldname,
303 char *format,...)
304{
305 struct ui_out_data *data = ui_out_data (uiout);
306 va_list args;
307
308 va_start (args, format);
309 vfprintf_filtered (data->stream, format, args);
310
311 va_end (args);
312}
313
314/* access to ui_out format private members */
315
316static void
317field_separator ()
318{
319 struct ui_out_data *data = ui_out_data (uiout);
320 fputc_filtered (' ', data->stream);
321}
322
323/* initalize private members at startup */
324
325struct ui_out *
326cli_out_new (struct ui_file *stream)
327{
328 int flags = ui_source_list;
329
330 struct ui_out_data *data = XMALLOC (struct ui_out_data);
331 data->stream = stream;
332 return ui_out_new (&cli_ui_out_impl, data, flags);
333}
334
335/* standard gdb initialization hook */
336void
337_initialize_cli_out ()
338{
339 /* nothing needs to be done */
340}
This page took 0.041144 seconds and 4 git commands to generate.