Remove more unnecessary casts of NULL
[binutils-gdb.git] / gdb / tui / tui-windata.c
1 /* Data/register window display.
2
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
4
5 Contributed by Hewlett-Packard Company.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "tui/tui.h"
24 #include "tui/tui-data.h"
25 #include "tui/tui-wingeneral.h"
26 #include "tui/tui-regs.h"
27 #include "tui/tui-windata.h"
28 #include "gdb_curses.h"
29
30
31 /*****************************************
32 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
33 ******************************************/
34
35
36
37 /*****************************************
38 ** PUBLIC FUNCTIONS **
39 ******************************************/
40
41
42 /* Answer the index first element displayed. If none are displayed,
43 then return (-1). */
44 int
45 tui_first_data_item_displayed (void)
46 {
47 int element_no = (-1);
48 int i;
49
50 for (i = 0;
51 i < TUI_DATA_WIN->generic.content_size && element_no < 0;
52 i++)
53 {
54 struct tui_gen_win_info *data_item_win;
55
56 data_item_win
57 = &TUI_DATA_WIN->generic.content[i]->which_element.data_window;
58 if (data_item_win->handle != NULL
59 && data_item_win->is_visible)
60 element_no = i;
61 }
62
63 return element_no;
64 }
65
66
67 /* Answer the index of the first element in line_no. If line_no is
68 past the data area (-1) is returned. */
69 int
70 tui_first_data_element_no_in_line (int line_no)
71 {
72 int first_element_no = (-1);
73
74 /* First see if there is a register on line_no, and if so, set the
75 first element number. */
76 if ((first_element_no = tui_first_reg_element_no_inline (line_no)) == -1)
77 { /* Looking at the general data, the 1st element on line_no. */
78 }
79
80 return first_element_no;
81 }
82
83
84 /* Function to delete all the item windows in the data window. This
85 is usually done when the data window is scrolled. */
86 void
87 tui_delete_data_content_windows (void)
88 {
89 int i;
90 struct tui_gen_win_info *data_item_win_ptr;
91
92 for (i = 0; (i < TUI_DATA_WIN->generic.content_size); i++)
93 {
94 data_item_win_ptr
95 = &TUI_DATA_WIN->generic.content[i]->which_element.data_window;
96 tui_delete_win (data_item_win_ptr->handle);
97 data_item_win_ptr->handle = NULL;
98 data_item_win_ptr->is_visible = FALSE;
99 }
100 }
101
102
103 void
104 tui_erase_data_content (const char *prompt)
105 {
106 werase (TUI_DATA_WIN->generic.handle);
107 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
108 if (prompt != NULL)
109 {
110 int half_width = (TUI_DATA_WIN->generic.width - 2) / 2;
111 int x_pos;
112
113 if (strlen (prompt) >= half_width)
114 x_pos = 1;
115 else
116 x_pos = half_width - strlen (prompt);
117 mvwaddstr (TUI_DATA_WIN->generic.handle,
118 (TUI_DATA_WIN->generic.height / 2),
119 x_pos,
120 (char *) prompt);
121 }
122 wrefresh (TUI_DATA_WIN->generic.handle);
123 }
124
125
126 /* This function displays the data that is in the data window's
127 content. It does not set the content. */
128 void
129 tui_display_all_data (void)
130 {
131 if (TUI_DATA_WIN->generic.content_size <= 0)
132 tui_erase_data_content (NO_DATA_STRING);
133 else
134 {
135 tui_erase_data_content (NULL);
136 tui_delete_data_content_windows ();
137 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
138 tui_display_registers_from (0);
139
140 /* Then display the other data. */
141 if (TUI_DATA_WIN->detail.data_display_info.data_content != NULL
142 && TUI_DATA_WIN->detail.data_display_info.data_content_count > 0)
143 {
144 }
145 }
146 }
147
148
149 /* Function to display the data starting at line, line_no, in the data
150 window. */
151 void
152 tui_display_data_from_line (int line_no)
153 {
154 int _line_no = line_no;
155
156 if (line_no < 0)
157 _line_no = 0;
158
159 tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
160
161 /* There is no general data, force regs to display (if there are
162 any). */
163 if (TUI_DATA_WIN->detail.data_display_info.data_content_count <= 0)
164 tui_display_registers_from_line (_line_no, TRUE);
165 else
166 {
167 int regs_last_line = tui_last_regs_line_no ();
168
169
170 /* Display regs if we can. */
171 if (tui_display_registers_from_line (_line_no, FALSE) < 0)
172 { /* _line_no is past the regs display, so calc where the
173 start data element is. */
174 if (regs_last_line < _line_no)
175 { /* Figure out how many lines each element is to obtain
176 the start element_no. */
177 }
178 }
179 else
180 { /* Calculate the starting element of the data display, given
181 regs_last_line and how many lines each element is, up to
182 _line_no. */
183 }
184 /* Now display the data , starting at element_no. */
185 }
186 }
187
188
189 /* Display data starting at element element_no. */
190 void
191 tui_display_data_from (int element_no, int reuse_windows)
192 {
193 int first_line = (-1);
194
195 if (element_no < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
196 first_line = tui_line_from_reg_element_no (element_no);
197 else
198 { /* Calculate the first_line from the element number. */
199 }
200
201 if (first_line >= 0)
202 {
203 tui_erase_data_content (NULL);
204 if (!reuse_windows)
205 tui_delete_data_content_windows ();
206 tui_display_data_from_line (first_line);
207 }
208 }
209
210
211 /* Function to redisplay the contents of the data window. */
212 void
213 tui_refresh_data_win (void)
214 {
215 tui_erase_data_content (NULL);
216 if (TUI_DATA_WIN->generic.content_size > 0)
217 {
218 int first_element = tui_first_data_item_displayed ();
219
220 if (first_element >= 0) /* Re-use existing windows. */
221 tui_display_data_from (first_element, TRUE);
222 }
223 }
224
225
226 /* Function to check the data values and hilite any that have
227 changed. */
228 void
229 tui_check_data_values (struct frame_info *frame)
230 {
231 tui_check_register_values (frame);
232
233 /* Now check any other data values that there are. */
234 if (TUI_DATA_WIN != NULL && TUI_DATA_WIN->generic.is_visible)
235 {
236 int i;
237
238 for (i = 0;
239 TUI_DATA_WIN->detail.data_display_info.data_content_count;
240 i++)
241 {
242 #ifdef LATER
243 tui_data_element_ptr data_element_ptr;
244 struct tui_gen_win_info *data_item_win_ptr;
245 Opaque new_value;
246
247 data_item_ptr = &TUI_DATA_WIN->detail.data_display_info.
248 data_content[i]->which_element.data_window;
249 data_element_ptr = &((tui_win_content)
250 data_item_win_ptr->content)[0]->which_element.data;
251 if value
252 has changed (data_element_ptr, frame, &new_value)
253 {
254 data_element_ptr->value = new_value;
255 update the display with the newobj value, hiliting it.
256 }
257 #endif
258 }
259 }
260 }
261
262
263 /* Scroll the data window vertically forward or backward. */
264 void
265 tui_vertical_data_scroll (enum tui_scroll_direction scroll_direction,
266 int num_to_scroll)
267 {
268 int first_element_no;
269 int first_line = (-1);
270
271 first_element_no = tui_first_data_item_displayed ();
272 if (first_element_no
273 < TUI_DATA_WIN->detail.data_display_info.regs_content_count)
274 first_line = tui_line_from_reg_element_no (first_element_no);
275 else
276 { /* Calculate the first line from the element number which is in
277 the general data content. */
278 }
279
280 if (first_line >= 0)
281 {
282 if (scroll_direction == FORWARD_SCROLL)
283 first_line += num_to_scroll;
284 else
285 first_line -= num_to_scroll;
286 tui_erase_data_content (NULL);
287 tui_delete_data_content_windows ();
288 tui_display_data_from_line (first_line);
289 }
290 }
291
292
293 /*****************************************
294 ** STATIC LOCAL FUNCTIONS **
295 ******************************************/