Use std::string for ui_out_hdr's text fields
[external/binutils.git] / gdb / ui-out.h
1 /* Output generating routines for GDB.
2
3    Copyright (C) 1999-2016 Free Software Foundation, Inc.
4
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
12    the Free Software Foundation; either version 3 of the License, or
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
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
23 #ifndef UI_OUT_H
24 #define UI_OUT_H 1
25
26 /* The ui_out structure */
27
28 struct ui_out;
29 struct ui_file;
30
31 /* the current ui_out */
32
33 /* FIXME: This should not be a global but something passed down from main.c
34    or top.c.  */
35 extern struct ui_out **current_ui_current_uiout_ptr (void);
36 #define current_uiout (*current_ui_current_uiout_ptr ())
37
38 /* alignment enum */
39 enum ui_align
40   {
41     ui_left = -1,
42     ui_center,
43     ui_right,
44     ui_noalign
45   };
46
47 /* flags enum */
48 enum ui_flags
49   {
50     ui_from_tty = 1,
51     ui_source_list = 2
52   };
53
54
55 /* Prototypes for ui-out API.  */
56
57 /* A result is a recursive data structure consisting of lists and
58    tuples.  */
59
60 enum ui_out_type
61   {
62     ui_out_type_tuple,
63     ui_out_type_list
64   };
65
66 extern void ui_out_begin (struct ui_out *uiout,
67                           enum ui_out_type level_type,
68                           const char *id);
69
70 extern void ui_out_end (struct ui_out *uiout, enum ui_out_type type);
71
72 /* A table can be considered a special tuple/list combination with the
73    implied structure: ``table = { hdr = { header, ... } , body = [ {
74    field, ... }, ... ] }''.  If NR_ROWS is negative then there is at
75    least one row.  */
76 extern void ui_out_table_header (struct ui_out *uiout, int width,
77                                  enum ui_align align,
78                                  const std::string &col_name,
79                                  const std::string &col_hdr);
80
81 extern void ui_out_table_body (struct ui_out *uiout);
82
83 extern struct cleanup *make_cleanup_ui_out_table_begin_end (struct ui_out *ui_out,
84                                                             int nr_cols,
85                                                             int nr_rows,
86                                                             const char *tblid);
87 /* Compatibility wrappers.  */
88
89 extern struct cleanup *make_cleanup_ui_out_list_begin_end (struct ui_out *uiout,
90                                                            const char *id);
91
92 extern struct cleanup *make_cleanup_ui_out_tuple_begin_end (struct ui_out *uiout,
93                                                             const char *id);
94
95 extern void ui_out_field_int (struct ui_out *uiout, const char *fldname,
96                               int value);
97
98 extern void ui_out_field_fmt_int (struct ui_out *uiout, int width,
99                                   enum ui_align align, const char *fldname, 
100                                   int value);
101
102 /* Output a field containing an address.  */
103
104 extern void ui_out_field_core_addr (struct ui_out *uiout, const char *fldname,
105                                     struct gdbarch *gdbarch, CORE_ADDR address);
106
107 extern void ui_out_field_string (struct ui_out * uiout, const char *fldname,
108                                  const char *string);
109
110 extern void ui_out_field_stream (struct ui_out *uiout, const char *fldname,
111                                  struct ui_file *stream);
112
113 extern void ui_out_field_fmt (struct ui_out *uiout, const char *fldname,
114                               const char *format, ...)
115      ATTRIBUTE_PRINTF (3, 4);
116
117 extern void ui_out_field_skip (struct ui_out *uiout, const char *fldname);
118
119 extern void ui_out_spaces (struct ui_out *uiout, int numspaces);
120
121 extern void ui_out_text (struct ui_out *uiout, const char *string);
122
123 extern void ui_out_message (struct ui_out *uiout, const char *format, ...)
124      ATTRIBUTE_PRINTF (2, 3);
125
126 extern void ui_out_wrap_hint (struct ui_out *uiout, const char *identstring);
127
128 extern void ui_out_flush (struct ui_out *uiout);
129
130 extern int ui_out_test_flags (struct ui_out *uiout, int mask);
131
132 extern int ui_out_query_field (struct ui_out *uiout, int colno,
133                                int *width, int *alignment,
134                                const char **col_name);
135
136 /* HACK: Code in GDB is currently checking to see the type of ui_out
137    builder when determining which output to produce.  This function is
138    a hack to encapsulate that test.  Once GDB manages to separate the
139    CLI/MI from the core of GDB the problem should just go away ....  */
140
141 extern int ui_out_is_mi_like_p (struct ui_out *uiout);
142
143 /* From here on we have things that are only needed by implementation
144    routines and main.c.   We should pehaps have a separate file for that,
145    like a  ui-out-impl.h  file.  */
146
147 /* User Interface Output Implementation Function Table */
148
149 /* Type definition of all implementation functions.  */
150
151 typedef void (table_begin_ftype) (struct ui_out * uiout,
152                                   int nbrofcols, int nr_rows,
153                                   const char *tblid);
154 typedef void (table_body_ftype) (struct ui_out * uiout);
155 typedef void (table_end_ftype) (struct ui_out * uiout);
156 typedef void (table_header_ftype) (struct ui_out * uiout, int width,
157                                    enum ui_align align,
158                                    const std::string &col_name,
159                                    const std::string &col_hdr);
160 /* Note: level 0 is the top-level so LEVEL is always greater than
161    zero.  */
162 typedef void (ui_out_begin_ftype) (struct ui_out *uiout,
163                                    enum ui_out_type type,
164                                    int level, const char *id);
165 typedef void (ui_out_end_ftype) (struct ui_out *uiout,
166                                  enum ui_out_type type,
167                                  int level);
168 typedef void (field_int_ftype) (struct ui_out * uiout, int fldno, int width,
169                                 enum ui_align align,
170                                 const char *fldname, int value);
171 typedef void (field_skip_ftype) (struct ui_out * uiout, int fldno, int width,
172                                  enum ui_align align,
173                                  const char *fldname);
174 typedef void (field_string_ftype) (struct ui_out * uiout, int fldno, int width,
175                                    enum ui_align align,
176                                    const char *fldname,
177                                    const char *string);
178 typedef void (field_fmt_ftype) (struct ui_out * uiout, int fldno, int width,
179                                 enum ui_align align,
180                                 const char *fldname,
181                                 const char *format,
182                                 va_list args) ATTRIBUTE_FPTR_PRINTF(6,0);
183 typedef void (spaces_ftype) (struct ui_out * uiout, int numspaces);
184 typedef void (text_ftype) (struct ui_out * uiout,
185                            const char *string);
186 typedef void (message_ftype) (struct ui_out * uiout,
187                               const char *format, va_list args)
188      ATTRIBUTE_FPTR_PRINTF(2,0);
189 typedef void (wrap_hint_ftype) (struct ui_out * uiout, const char *identstring);
190 typedef void (flush_ftype) (struct ui_out * uiout);
191 typedef int (redirect_ftype) (struct ui_out * uiout,
192                               struct ui_file * outstream);
193 typedef void (data_destroy_ftype) (struct ui_out *uiout);
194
195 /* ui-out-impl */
196
197 struct ui_out_impl
198   {
199     table_begin_ftype *table_begin;
200     table_body_ftype *table_body;
201     table_end_ftype *table_end;
202     table_header_ftype *table_header;
203     ui_out_begin_ftype *begin;
204     ui_out_end_ftype *end;
205     field_int_ftype *field_int;
206     field_skip_ftype *field_skip;
207     field_string_ftype *field_string;
208     field_fmt_ftype *field_fmt;
209     spaces_ftype *spaces;
210     text_ftype *text;
211     message_ftype *message;
212     wrap_hint_ftype *wrap_hint;
213     flush_ftype *flush;
214     redirect_ftype *redirect;
215     data_destroy_ftype *data_destroy;
216     int is_mi_like_p;
217   };
218
219 extern void *ui_out_data (struct ui_out *uiout);
220
221 extern void uo_field_string (struct ui_out *uiout, int fldno, int width,
222                              enum ui_align align, const char *fldname,
223                              const char *string);
224
225 /* Create a ui_out object */
226
227 extern struct ui_out *ui_out_new (const struct ui_out_impl *impl,
228                                   void *data,
229                                   int flags);
230
231 /* Redirect the ouptut of a ui_out object temporarily.  */
232
233 extern int ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream);
234
235 #endif /* UI_OUT_H */