]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-out.c
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / tui / tui-out.c
CommitLineData
2611b1a5 1/* Output generating routines for GDB CLI.
349c5d5f 2
8acc9f48 3 Copyright (C) 1999-2013 Free Software Foundation, Inc.
349c5d5f 4
2611b1a5
SC
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
2611b1a5
SC
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/>. */
2611b1a5
SC
22
23#include "defs.h"
24#include "ui-out.h"
0a8fce9a 25#include "cli-out.h"
2611b1a5
SC
26#include "tui.h"
27#include "gdb_string.h"
28#include "gdb_assert.h"
29
0a8fce9a 30struct tui_ui_out_data
2611b1a5 31 {
0a8fce9a
PA
32 struct cli_ui_out_data base;
33
2611b1a5
SC
34 int line;
35 int start_of_line;
36 };
0a8fce9a 37typedef struct tui_ui_out_data tui_out_data;
2611b1a5 38
0a8fce9a
PA
39/* This is the TUI ui-out implementation functions vector. It is
40 initialized below in _initialize_tui_out, inheriting the CLI
41 version, and overriding a few methods. */
2611b1a5 42
0a8fce9a 43static struct ui_out_impl tui_ui_out_impl;
2611b1a5 44
1cc6d956 45/* Output an int field. */
2611b1a5 46
0a8fce9a 47static void
08ef48c5
MS
48tui_field_int (struct ui_out *uiout,
49 int fldno, int width,
2611b1a5 50 enum ui_align alignment,
08ef48c5
MS
51 const char *fldname,
52 int value)
2611b1a5 53{
1248ede2 54 tui_out_data *data = ui_out_data (uiout);
1c5313c5 55
0a8fce9a 56 if (data->base.suppress_output)
2611b1a5
SC
57 return;
58
59 /* Don't print line number, keep it for later. */
60 if (data->start_of_line == 0 && strcmp (fldname, "line") == 0)
61 {
62 data->start_of_line ++;
63 data->line = value;
64 return;
65 }
66 data->start_of_line ++;
2611b1a5 67
0a8fce9a
PA
68 (*cli_ui_out_impl.field_int) (uiout, fldno,
69 width, alignment, fldname, value);
2611b1a5
SC
70}
71
0a8fce9a
PA
72/* Other cli_field_* end up here so alignment and field separators are
73 both handled by tui_field_string. */
2611b1a5 74
0a8fce9a 75static void
2611b1a5 76tui_field_string (struct ui_out *uiout,
08ef48c5 77 int fldno, int width,
2611b1a5
SC
78 enum ui_align align,
79 const char *fldname,
80 const char *string)
81{
1248ede2 82 tui_out_data *data = ui_out_data (uiout);
1c5313c5 83
0a8fce9a 84 if (data->base.suppress_output)
2611b1a5
SC
85 return;
86
87 if (fldname && data->line > 0 && strcmp (fldname, "file") == 0)
88 {
89 data->start_of_line ++;
90 if (data->line > 0)
91 {
92 tui_show_source (string, data->line);
93 }
94 return;
95 }
96
0a8fce9a 97 data->start_of_line++;
2611b1a5 98
0a8fce9a
PA
99 (*cli_ui_out_impl.field_string) (uiout, fldno,
100 width, align,
101 fldname, string);
2611b1a5
SC
102}
103
1cc6d956 104/* This is the only field function that does not align. */
2611b1a5 105
0a8fce9a 106static void
2611b1a5
SC
107tui_field_fmt (struct ui_out *uiout, int fldno,
108 int width, enum ui_align align,
109 const char *fldname,
110 const char *format,
111 va_list args)
112{
1248ede2 113 tui_out_data *data = ui_out_data (uiout);
1c5313c5 114
0a8fce9a 115 if (data->base.suppress_output)
2611b1a5
SC
116 return;
117
0a8fce9a 118 data->start_of_line++;
2611b1a5 119
0a8fce9a
PA
120 (*cli_ui_out_impl.field_fmt) (uiout, fldno,
121 width, align,
122 fldname, format, args);
2611b1a5
SC
123}
124
0a8fce9a 125static void
2611b1a5
SC
126tui_text (struct ui_out *uiout, const char *string)
127{
1248ede2 128 tui_out_data *data = ui_out_data (uiout);
1c5313c5 129
0a8fce9a 130 if (data->base.suppress_output)
2611b1a5
SC
131 return;
132 data->start_of_line ++;
133 if (data->line > 0)
134 {
135 if (strchr (string, '\n') != 0)
136 {
137 data->line = -1;
138 data->start_of_line = 0;
139 }
140 return;
141 }
142 if (strchr (string, '\n'))
143 data->start_of_line = 0;
2611b1a5 144
0a8fce9a 145 (*cli_ui_out_impl.text) (uiout, string);
2611b1a5
SC
146}
147
2611b1a5
SC
148struct ui_out *
149tui_out_new (struct ui_file *stream)
150{
151 int flags = 0;
152
1248ede2 153 tui_out_data *data = XMALLOC (tui_out_data);
0a8fce9a
PA
154
155 /* Initialize base "class". */
156 cli_out_data_ctor (&data->base, stream);
157
158 /* Initialize our fields. */
2611b1a5 159 data->line = -1;
27229e99 160 data->start_of_line = 0;
0a8fce9a 161
2611b1a5
SC
162 return ui_out_new (&tui_ui_out_impl, data, flags);
163}
164
1cc6d956 165/* Standard gdb initialization hook. */
0a8fce9a
PA
166
167extern void _initialize_tui_out (void);
168
2611b1a5
SC
169void
170_initialize_tui_out (void)
171{
1c5313c5 172 /* Inherit the CLI version. */
0a8fce9a
PA
173 tui_ui_out_impl = cli_ui_out_impl;
174
175 /* Override a few methods. */
176 tui_ui_out_impl.field_int = tui_field_int;
177 tui_ui_out_impl.field_string = tui_field_string;
178 tui_ui_out_impl.field_fmt = tui_field_fmt;
179 tui_ui_out_impl.text = tui_text;
2611b1a5 180}