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