Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
32d0add0 | 3 | Copyright (C) 1998-2015 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
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 | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 21 | |
96ec9981 DJ |
22 | #include "defs.h" |
23 | #include "symtab.h" | |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
26 | #include "tui/tui-wingeneral.h" | |
6a83354a | 27 | #include "gdb_curses.h" |
4e8f7a8b | 28 | |
c906108c SS |
29 | /**************************** |
30 | ** GLOBAL DECLARATIONS | |
31 | ****************************/ | |
6d012f14 | 32 | struct tui_win_info *(tui_win_list[MAX_MAJOR_WINDOWS]); |
c906108c | 33 | |
c906108c SS |
34 | /*************************** |
35 | ** Private data | |
36 | ****************************/ | |
6ba8e26f AC |
37 | static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; |
38 | static int term_height, term_width; | |
2a8854a7 | 39 | static struct tui_gen_win_info _locator; |
6ba8e26f | 40 | static struct tui_gen_win_info exec_info[2]; |
5b6fe301 | 41 | static struct tui_win_info *src_win_list[2]; |
96c1eda2 | 42 | static struct tui_list source_windows = {src_win_list, 0}; |
6ba8e26f | 43 | static int default_tab_len = DEFAULT_TAB_LEN; |
e65b5245 | 44 | static struct tui_win_info *win_with_focus = NULL; |
08ef48c5 MS |
45 | static struct tui_layout_def layout_def = { |
46 | SRC_WIN, /* DISPLAY_MODE */ | |
7bd0be3a | 47 | FALSE}; /* SPLIT */ |
08ef48c5 | 48 | |
6ba8e26f | 49 | static int win_resized = FALSE; |
c906108c SS |
50 | |
51 | ||
52 | /********************************* | |
53 | ** Static function forward decls | |
54 | **********************************/ | |
08ef48c5 MS |
55 | static void free_content (tui_win_content, |
56 | int, | |
57 | enum tui_win_type); | |
58 | static void free_content_elements (tui_win_content, | |
59 | int, | |
60 | enum tui_win_type); | |
c906108c SS |
61 | |
62 | ||
63 | ||
64 | /********************************* | |
65 | ** PUBLIC FUNCTIONS | |
66 | **********************************/ | |
67 | ||
6d012f14 AC |
68 | int |
69 | tui_win_is_source_type (enum tui_win_type win_type) | |
70 | { | |
71 | return (win_type == SRC_WIN || win_type == DISASSEM_WIN); | |
72 | } | |
73 | ||
74 | int | |
75 | tui_win_is_auxillary (enum tui_win_type win_type) | |
76 | { | |
77 | return (win_type > MAX_MAJOR_WINDOWS); | |
78 | } | |
79 | ||
80 | int | |
81 | tui_win_has_locator (struct tui_win_info *win_info) | |
82 | { | |
08ef48c5 | 83 | return (win_info != NULL |
6d012f14 AC |
84 | && win_info->detail.source_info.has_locator); |
85 | } | |
86 | ||
87 | void | |
08ef48c5 MS |
88 | tui_set_win_highlight (struct tui_win_info *win_info, |
89 | int highlight) | |
6d012f14 AC |
90 | { |
91 | if (win_info != NULL) | |
92 | win_info->is_highlighted = highlight; | |
93 | } | |
94 | ||
c906108c SS |
95 | /****************************************** |
96 | ** ACCESSORS & MUTATORS FOR PRIVATE DATA | |
97 | ******************************************/ | |
98 | ||
1cc6d956 | 99 | /* Answer a whether the terminal window has been resized or not. */ |
c906108c | 100 | int |
dd1abb8c | 101 | tui_win_resized (void) |
c906108c | 102 | { |
6ba8e26f | 103 | return win_resized; |
dd1abb8c | 104 | } |
c906108c SS |
105 | |
106 | ||
1cc6d956 | 107 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 108 | void |
dd1abb8c | 109 | tui_set_win_resized_to (int resized) |
c906108c | 110 | { |
6ba8e26f | 111 | win_resized = resized; |
dd1abb8c | 112 | } |
c906108c SS |
113 | |
114 | ||
1cc6d956 | 115 | /* Answer a pointer to the current layout definition. */ |
2a8854a7 | 116 | struct tui_layout_def * |
dd1abb8c | 117 | tui_layout_def (void) |
c906108c | 118 | { |
6ba8e26f | 119 | return &layout_def; |
dd1abb8c | 120 | } |
c906108c SS |
121 | |
122 | ||
1cc6d956 | 123 | /* Answer the window with the logical focus. */ |
2a8854a7 | 124 | struct tui_win_info * |
dd1abb8c | 125 | tui_win_with_focus (void) |
c906108c | 126 | { |
6ba8e26f | 127 | return win_with_focus; |
dd1abb8c | 128 | } |
c906108c SS |
129 | |
130 | ||
1cc6d956 | 131 | /* Set the window that has the logical focus. */ |
c906108c | 132 | void |
5b6fe301 | 133 | tui_set_win_with_focus (struct tui_win_info *win_info) |
c906108c | 134 | { |
6ba8e26f | 135 | win_with_focus = win_info; |
dd1abb8c | 136 | } |
c906108c SS |
137 | |
138 | ||
1cc6d956 | 139 | /* Answer the length in chars, of tabs. */ |
c906108c | 140 | int |
dd1abb8c | 141 | tui_default_tab_len (void) |
c906108c | 142 | { |
6ba8e26f | 143 | return default_tab_len; |
dd1abb8c | 144 | } |
c906108c SS |
145 | |
146 | ||
1cc6d956 | 147 | /* Set the length in chars, of tabs. */ |
c906108c | 148 | void |
dd1abb8c | 149 | tui_set_default_tab_len (int len) |
c906108c | 150 | { |
6ba8e26f | 151 | default_tab_len = len; |
dd1abb8c | 152 | } |
c906108c SS |
153 | |
154 | ||
6ba8e26f AC |
155 | /* Accessor for the current source window. Usually there is only one |
156 | source window (either source or disassembly), but both can be | |
157 | displayed at the same time. */ | |
2a8854a7 | 158 | struct tui_list * |
dd1abb8c | 159 | tui_source_windows (void) |
c906108c | 160 | { |
6ba8e26f | 161 | return &source_windows; |
dd1abb8c | 162 | } |
c906108c SS |
163 | |
164 | ||
dd1abb8c AC |
165 | /* Clear the list of source windows. Usually there is only one source |
166 | window (either source or disassembly), but both can be displayed at | |
167 | the same time. */ | |
c906108c | 168 | void |
dd1abb8c | 169 | tui_clear_source_windows (void) |
c906108c | 170 | { |
6ba8e26f AC |
171 | source_windows.list[0] = NULL; |
172 | source_windows.list[1] = NULL; | |
173 | source_windows.count = 0; | |
dd1abb8c | 174 | } |
c906108c SS |
175 | |
176 | ||
1cc6d956 | 177 | /* Clear the pertinant detail in the source windows. */ |
c906108c | 178 | void |
dd1abb8c | 179 | tui_clear_source_windows_detail (void) |
c906108c SS |
180 | { |
181 | int i; | |
182 | ||
dd1abb8c | 183 | for (i = 0; i < (tui_source_windows ())->count; i++) |
96c1eda2 | 184 | tui_clear_win_detail ((tui_source_windows ())->list[i]); |
dd1abb8c | 185 | } |
c906108c SS |
186 | |
187 | ||
dd1abb8c AC |
188 | /* Add a window to the list of source windows. Usually there is only |
189 | one source window (either source or disassembly), but both can be | |
190 | displayed at the same time. */ | |
c906108c | 191 | void |
5b6fe301 | 192 | tui_add_to_source_windows (struct tui_win_info *win_info) |
c906108c | 193 | { |
6ba8e26f AC |
194 | if (source_windows.count < 2) |
195 | source_windows.list[source_windows.count++] = (void *) win_info; | |
dd1abb8c | 196 | } |
c906108c SS |
197 | |
198 | ||
1cc6d956 | 199 | /* Clear the pertinant detail in the windows. */ |
c906108c | 200 | void |
5b6fe301 | 201 | tui_clear_win_detail (struct tui_win_info *win_info) |
c906108c | 202 | { |
6d012f14 | 203 | if (win_info != NULL) |
c906108c | 204 | { |
6d012f14 | 205 | switch (win_info->generic.type) |
c906108c SS |
206 | { |
207 | case SRC_WIN: | |
208 | case DISASSEM_WIN: | |
13274fc3 | 209 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
210 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
211 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
6d012f14 | 212 | win_info->detail.source_info.horizontal_offset = 0; |
c906108c SS |
213 | break; |
214 | case CMD_WIN: | |
6f1cb6ea | 215 | wmove (win_info->generic.handle, 0, 0); |
c906108c SS |
216 | break; |
217 | case DATA_WIN: | |
6d012f14 | 218 | win_info->detail.data_display_info.data_content = |
2a8854a7 | 219 | (tui_win_content) NULL; |
6d012f14 AC |
220 | win_info->detail.data_display_info.data_content_count = 0; |
221 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 222 | (tui_win_content) NULL; |
6d012f14 | 223 | win_info->detail.data_display_info.regs_content_count = 0; |
6d012f14 AC |
224 | win_info->detail.data_display_info.regs_column_count = 1; |
225 | win_info->detail.data_display_info.display_regs = FALSE; | |
c906108c SS |
226 | break; |
227 | default: | |
228 | break; | |
229 | } | |
230 | } | |
6ba8e26f | 231 | } |
c906108c SS |
232 | |
233 | ||
6ba8e26f | 234 | /* Accessor for the source execution info ptr. */ |
2a8854a7 | 235 | struct tui_gen_win_info * |
dd1abb8c | 236 | tui_source_exec_info_win_ptr (void) |
c906108c | 237 | { |
6ba8e26f AC |
238 | return &exec_info[0]; |
239 | } | |
c906108c SS |
240 | |
241 | ||
6ba8e26f | 242 | /* Accessor for the disassem execution info ptr. */ |
2a8854a7 | 243 | struct tui_gen_win_info * |
dd1abb8c | 244 | tui_disassem_exec_info_win_ptr (void) |
c906108c | 245 | { |
6ba8e26f AC |
246 | return &exec_info[1]; |
247 | } | |
c906108c SS |
248 | |
249 | ||
dd1abb8c AC |
250 | /* Accessor for the locator win info. Answers a pointer to the static |
251 | locator win info struct. */ | |
2a8854a7 | 252 | struct tui_gen_win_info * |
dd1abb8c | 253 | tui_locator_win_info_ptr (void) |
c906108c SS |
254 | { |
255 | return &_locator; | |
2a8854a7 | 256 | } |
c906108c SS |
257 | |
258 | ||
6ba8e26f | 259 | /* Accessor for the term_height. */ |
c906108c | 260 | int |
dd1abb8c | 261 | tui_term_height (void) |
c906108c | 262 | { |
6ba8e26f | 263 | return term_height; |
dd1abb8c | 264 | } |
c906108c SS |
265 | |
266 | ||
1cc6d956 | 267 | /* Mutator for the term height. */ |
c906108c | 268 | void |
dd1abb8c | 269 | tui_set_term_height_to (int h) |
c906108c | 270 | { |
6ba8e26f | 271 | term_height = h; |
dd1abb8c | 272 | } |
c906108c SS |
273 | |
274 | ||
1cc6d956 | 275 | /* Accessor for the term_width. */ |
c906108c | 276 | int |
dd1abb8c | 277 | tui_term_width (void) |
c906108c | 278 | { |
6ba8e26f | 279 | return term_width; |
dd1abb8c | 280 | } |
c906108c SS |
281 | |
282 | ||
6ba8e26f | 283 | /* Mutator for the term_width. */ |
c906108c | 284 | void |
dd1abb8c | 285 | tui_set_term_width_to (int w) |
c906108c | 286 | { |
6ba8e26f | 287 | term_width = w; |
dd1abb8c | 288 | } |
c906108c SS |
289 | |
290 | ||
1cc6d956 | 291 | /* Accessor for the current layout. */ |
2a8854a7 | 292 | enum tui_layout_type |
dd1abb8c | 293 | tui_current_layout (void) |
c906108c | 294 | { |
6ba8e26f | 295 | return current_layout; |
dd1abb8c | 296 | } |
c906108c SS |
297 | |
298 | ||
dd1abb8c | 299 | /* Mutator for the current layout. */ |
c906108c | 300 | void |
6ba8e26f | 301 | tui_set_current_layout_to (enum tui_layout_type new_layout) |
c906108c | 302 | { |
6ba8e26f | 303 | current_layout = new_layout; |
dd1abb8c | 304 | } |
c906108c SS |
305 | |
306 | ||
c906108c SS |
307 | /***************************** |
308 | ** OTHER PUBLIC FUNCTIONS | |
309 | *****************************/ | |
310 | ||
311 | ||
dd1abb8c AC |
312 | /* Answer the next window in the list, cycling back to the top if |
313 | necessary. */ | |
2a8854a7 | 314 | struct tui_win_info * |
5b6fe301 | 315 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 316 | { |
570dc176 | 317 | int type = cur_win->generic.type; |
e65b5245 | 318 | struct tui_win_info *next_win = NULL; |
c906108c | 319 | |
6ba8e26f | 320 | if (cur_win->generic.type == CMD_WIN) |
c906108c SS |
321 | type = SRC_WIN; |
322 | else | |
6ba8e26f AC |
323 | type = cur_win->generic.type + 1; |
324 | while (type != cur_win->generic.type && (next_win == NULL)) | |
c906108c | 325 | { |
e5908723 MS |
326 | if (tui_win_list[type] |
327 | && tui_win_list[type]->generic.is_visible) | |
6ba8e26f | 328 | next_win = tui_win_list[type]; |
c906108c SS |
329 | else |
330 | { | |
331 | if (type == CMD_WIN) | |
332 | type = SRC_WIN; | |
333 | else | |
334 | type++; | |
335 | } | |
336 | } | |
337 | ||
6ba8e26f AC |
338 | return next_win; |
339 | } | |
c906108c SS |
340 | |
341 | ||
dd1abb8c AC |
342 | /* Answer the prev window in the list, cycling back to the bottom if |
343 | necessary. */ | |
2a8854a7 | 344 | struct tui_win_info * |
5b6fe301 | 345 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 346 | { |
570dc176 | 347 | int type = cur_win->generic.type; |
e65b5245 | 348 | struct tui_win_info *prev = NULL; |
c906108c | 349 | |
6ba8e26f | 350 | if (cur_win->generic.type == SRC_WIN) |
c906108c SS |
351 | type = CMD_WIN; |
352 | else | |
6ba8e26f AC |
353 | type = cur_win->generic.type - 1; |
354 | while (type != cur_win->generic.type && (prev == NULL)) | |
c906108c | 355 | { |
37715c4c TJB |
356 | if (tui_win_list[type] |
357 | && tui_win_list[type]->generic.is_visible) | |
6d012f14 | 358 | prev = tui_win_list[type]; |
c906108c SS |
359 | else |
360 | { | |
361 | if (type == SRC_WIN) | |
362 | type = CMD_WIN; | |
363 | else | |
364 | type--; | |
365 | } | |
366 | } | |
367 | ||
368 | return prev; | |
cb50eddd | 369 | } |
c906108c SS |
370 | |
371 | ||
1cc6d956 | 372 | /* Answer the window represented by name. */ |
2a8854a7 | 373 | struct tui_win_info * |
dd1abb8c | 374 | tui_partial_win_by_name (char *name) |
c906108c | 375 | { |
e65b5245 | 376 | struct tui_win_info *win_info = NULL; |
c906108c SS |
377 | |
378 | if (name != (char *) NULL) | |
379 | { | |
380 | int i = 0; | |
381 | ||
6d012f14 | 382 | while (i < MAX_MAJOR_WINDOWS && win_info == NULL) |
c906108c | 383 | { |
6d012f14 | 384 | if (tui_win_list[i] != 0) |
a4b99e53 | 385 | { |
f41cbf58 AB |
386 | const char *cur_name = |
387 | tui_win_name (&tui_win_list[i]->generic); | |
1c5313c5 | 388 | |
e5908723 | 389 | if (strlen (name) <= strlen (cur_name) |
61012eef | 390 | && startswith (cur_name, name)) |
6d012f14 | 391 | win_info = tui_win_list[i]; |
a4b99e53 | 392 | } |
c906108c SS |
393 | i++; |
394 | } | |
395 | } | |
396 | ||
6d012f14 | 397 | return win_info; |
6ba8e26f | 398 | } |
c906108c SS |
399 | |
400 | ||
6ba8e26f | 401 | /* Answer the name of the window. */ |
f41cbf58 AB |
402 | const char * |
403 | tui_win_name (const struct tui_gen_win_info *win_info) | |
c906108c | 404 | { |
136765ea | 405 | const char *name = NULL; |
c906108c | 406 | |
6d012f14 | 407 | switch (win_info->type) |
c906108c SS |
408 | { |
409 | case SRC_WIN: | |
410 | name = SRC_NAME; | |
411 | break; | |
412 | case CMD_WIN: | |
413 | name = CMD_NAME; | |
414 | break; | |
415 | case DISASSEM_WIN: | |
416 | name = DISASSEM_NAME; | |
417 | break; | |
418 | case DATA_WIN: | |
419 | name = DATA_NAME; | |
420 | break; | |
421 | default: | |
422 | name = ""; | |
423 | break; | |
424 | } | |
425 | ||
426 | return name; | |
6ba8e26f | 427 | } |
c906108c SS |
428 | |
429 | ||
c906108c | 430 | void |
dd1abb8c | 431 | tui_initialize_static_data (void) |
c906108c | 432 | { |
dd1abb8c AC |
433 | tui_init_generic_part (tui_source_exec_info_win_ptr ()); |
434 | tui_init_generic_part (tui_disassem_exec_info_win_ptr ()); | |
435 | tui_init_generic_part (tui_locator_win_info_ptr ()); | |
436 | } | |
c906108c SS |
437 | |
438 | ||
2a8854a7 | 439 | struct tui_gen_win_info * |
dd1abb8c | 440 | tui_alloc_generic_win_info (void) |
c906108c | 441 | { |
8d749320 | 442 | struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info); |
c906108c | 443 | |
8d749320 | 444 | if (win != NULL) |
dd1abb8c | 445 | tui_init_generic_part (win); |
c906108c SS |
446 | |
447 | return win; | |
6ba8e26f | 448 | } |
c906108c SS |
449 | |
450 | ||
c906108c | 451 | void |
5b6fe301 | 452 | tui_init_generic_part (struct tui_gen_win_info *win) |
c906108c SS |
453 | { |
454 | win->width = | |
455 | win->height = | |
456 | win->origin.x = | |
457 | win->origin.y = | |
6d012f14 AC |
458 | win->viewport_height = |
459 | win->content_size = | |
460 | win->last_visible_line = 0; | |
e65b5245 | 461 | win->handle = NULL; |
22940a24 | 462 | win->content = NULL; |
6d012f14 AC |
463 | win->content_in_use = |
464 | win->is_visible = FALSE; | |
bc6b7f04 SC |
465 | win->title = 0; |
466 | } | |
c906108c SS |
467 | |
468 | ||
ef5eab5a | 469 | /* init_content_element(). |
c5aa993b | 470 | */ |
2c0b251b | 471 | static void |
08ef48c5 MS |
472 | init_content_element (struct tui_win_element *element, |
473 | enum tui_win_type type) | |
c906108c SS |
474 | { |
475 | element->highlight = FALSE; | |
476 | switch (type) | |
477 | { | |
478 | case SRC_WIN: | |
479 | case DISASSEM_WIN: | |
e65b5245 | 480 | element->which_element.source.line = NULL; |
362c05fe AS |
481 | element->which_element.source.line_or_addr.loa = LOA_LINE; |
482 | element->which_element.source.line_or_addr.u.line_no = 0; | |
6d012f14 AC |
483 | element->which_element.source.is_exec_point = FALSE; |
484 | element->which_element.source.has_break = FALSE; | |
c906108c SS |
485 | break; |
486 | case DATA_WIN: | |
6d012f14 AC |
487 | tui_init_generic_part (&element->which_element.data_window); |
488 | element->which_element.data_window.type = DATA_ITEM_WIN; | |
63ed8182 PP |
489 | element->which_element.data_window.content = |
490 | tui_alloc_content (1, DATA_ITEM_WIN); | |
491 | element->which_element.data_window.content_size = 1; | |
c906108c SS |
492 | break; |
493 | case CMD_WIN: | |
e65b5245 | 494 | element->which_element.command.line = NULL; |
c906108c SS |
495 | break; |
496 | case DATA_ITEM_WIN: | |
e65b5245 | 497 | element->which_element.data.name = NULL; |
6d012f14 AC |
498 | element->which_element.data.type = TUI_REGISTER; |
499 | element->which_element.data.item_no = UNDEFINED_ITEM; | |
500 | element->which_element.data.value = NULL; | |
501 | element->which_element.data.highlight = FALSE; | |
e65b5245 | 502 | element->which_element.data.content = NULL; |
c906108c SS |
503 | break; |
504 | case LOCATOR_WIN: | |
56d397a3 | 505 | element->which_element.locator.full_name[0] = |
6d012f14 AC |
506 | element->which_element.locator.proc_name[0] = (char) 0; |
507 | element->which_element.locator.line_no = 0; | |
508 | element->which_element.locator.addr = 0; | |
c906108c SS |
509 | break; |
510 | case EXEC_INFO_WIN: | |
6d012f14 AC |
511 | memset(element->which_element.simple_string, ' ', |
512 | sizeof(element->which_element.simple_string)); | |
c906108c SS |
513 | break; |
514 | default: | |
515 | break; | |
516 | } | |
6ba8e26f | 517 | } |
c906108c | 518 | |
2c0b251b | 519 | static void |
5b6fe301 | 520 | init_win_info (struct tui_win_info *win_info) |
c906108c | 521 | { |
6d012f14 AC |
522 | tui_init_generic_part (&win_info->generic); |
523 | win_info->can_highlight = | |
524 | win_info->is_highlighted = FALSE; | |
525 | switch (win_info->generic.type) | |
c906108c SS |
526 | { |
527 | case SRC_WIN: | |
528 | case DISASSEM_WIN: | |
9a2b4c1b MS |
529 | win_info->detail.source_info.execution_info |
530 | = (struct tui_gen_win_info *) NULL; | |
6d012f14 AC |
531 | win_info->detail.source_info.has_locator = FALSE; |
532 | win_info->detail.source_info.horizontal_offset = 0; | |
13274fc3 | 533 | win_info->detail.source_info.gdbarch = NULL; |
362c05fe AS |
534 | win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS; |
535 | win_info->detail.source_info.start_line_or_addr.u.addr = 0; | |
aa079c93 | 536 | win_info->detail.source_info.fullname = NULL; |
c906108c SS |
537 | break; |
538 | case DATA_WIN: | |
6d012f14 AC |
539 | win_info->detail.data_display_info.data_content = (tui_win_content) NULL; |
540 | win_info->detail.data_display_info.data_content_count = 0; | |
541 | win_info->detail.data_display_info.regs_content = (tui_win_content) NULL; | |
542 | win_info->detail.data_display_info.regs_content_count = 0; | |
6d012f14 AC |
543 | win_info->detail.data_display_info.regs_column_count = 1; |
544 | win_info->detail.data_display_info.display_regs = FALSE; | |
10f59415 | 545 | win_info->detail.data_display_info.current_group = 0; |
c906108c SS |
546 | break; |
547 | case CMD_WIN: | |
c906108c SS |
548 | break; |
549 | default: | |
6d012f14 | 550 | win_info->detail.opaque = NULL; |
c906108c SS |
551 | break; |
552 | } | |
6ba8e26f | 553 | } |
c906108c SS |
554 | |
555 | ||
2a8854a7 | 556 | struct tui_win_info * |
22940a24 | 557 | tui_alloc_win_info (enum tui_win_type type) |
c906108c | 558 | { |
8d749320 | 559 | struct tui_win_info *win_info = XNEW (struct tui_win_info); |
c906108c | 560 | |
c0645fb5 | 561 | if (win_info != NULL) |
c906108c | 562 | { |
6d012f14 | 563 | win_info->generic.type = type; |
6ba8e26f | 564 | init_win_info (win_info); |
c906108c SS |
565 | } |
566 | ||
6d012f14 | 567 | return win_info; |
6ba8e26f | 568 | } |
c906108c SS |
569 | |
570 | ||
6ba8e26f | 571 | /* Allocates the content and elements in a block. */ |
2a8854a7 | 572 | tui_win_content |
6ba8e26f | 573 | tui_alloc_content (int num_elements, enum tui_win_type type) |
c906108c | 574 | { |
c0645fb5 MS |
575 | tui_win_content content; |
576 | char *element_block_ptr; | |
c906108c SS |
577 | int i; |
578 | ||
8d749320 | 579 | content = XNEWVEC (struct tui_win_element *, num_elements); |
c0645fb5 MS |
580 | if (content != NULL) |
581 | { | |
582 | /* | |
583 | * All windows, except the data window, can allocate the | |
584 | * elements in a chunk. The data window cannot because items | |
585 | * can be added/removed from the data display by the user at any | |
586 | * time. | |
587 | */ | |
c906108c SS |
588 | if (type != DATA_WIN) |
589 | { | |
c0645fb5 MS |
590 | element_block_ptr = |
591 | xmalloc (sizeof (struct tui_win_element) * num_elements); | |
592 | if (element_block_ptr != NULL) | |
c906108c | 593 | { |
6ba8e26f | 594 | for (i = 0; i < num_elements; i++) |
c906108c | 595 | { |
6ba8e26f AC |
596 | content[i] = (struct tui_win_element *) element_block_ptr; |
597 | init_content_element (content[i], type); | |
598 | element_block_ptr += sizeof (struct tui_win_element); | |
c906108c SS |
599 | } |
600 | } | |
601 | else | |
602 | { | |
22940a24 | 603 | xfree (content); |
2a8854a7 | 604 | content = (tui_win_content) NULL; |
c906108c SS |
605 | } |
606 | } | |
607 | } | |
608 | ||
609 | return content; | |
6ba8e26f | 610 | } |
c906108c SS |
611 | |
612 | ||
dd1abb8c | 613 | /* Adds the input number of elements to the windows's content. If no |
6ba8e26f | 614 | content has been allocated yet, alloc_content() is called to do |
dd1abb8c AC |
615 | this. The index of the first element added is returned, unless |
616 | there is a memory allocation error, in which case, (-1) is | |
617 | returned. */ | |
c906108c | 618 | int |
08ef48c5 MS |
619 | tui_add_content_elements (struct tui_gen_win_info *win_info, |
620 | int num_elements) | |
c906108c | 621 | { |
5b6fe301 | 622 | struct tui_win_element *element_ptr; |
6ba8e26f | 623 | int i, index_start; |
c906108c | 624 | |
6d012f14 | 625 | if (win_info->content == NULL) |
c906108c | 626 | { |
63ed8182 | 627 | win_info->content = tui_alloc_content (num_elements, win_info->type); |
6ba8e26f | 628 | index_start = 0; |
c906108c SS |
629 | } |
630 | else | |
6ba8e26f | 631 | index_start = win_info->content_size; |
6d012f14 | 632 | if (win_info->content != NULL) |
c906108c | 633 | { |
6ba8e26f | 634 | for (i = index_start; (i < num_elements + index_start); i++) |
c906108c | 635 | { |
8d749320 SM |
636 | element_ptr = XNEW (struct tui_win_element); |
637 | if (element_ptr != NULL) | |
c906108c | 638 | { |
6ba8e26f AC |
639 | win_info->content[i] = (void *) element_ptr; |
640 | init_content_element (element_ptr, win_info->type); | |
6d012f14 | 641 | win_info->content_size++; |
c906108c | 642 | } |
1cc6d956 MS |
643 | else /* Things must be really hosed now! We ran out of |
644 | memory!? */ | |
c906108c SS |
645 | return (-1); |
646 | } | |
647 | } | |
648 | ||
6ba8e26f AC |
649 | return index_start; |
650 | } | |
c906108c SS |
651 | |
652 | ||
1cc6d956 MS |
653 | /* Delete all curses windows associated with win_info, leaving |
654 | everything else intact. */ | |
c906108c | 655 | void |
5b6fe301 | 656 | tui_del_window (struct tui_win_info *win_info) |
c906108c | 657 | { |
5b6fe301 | 658 | struct tui_gen_win_info *generic_win; |
c906108c | 659 | |
6d012f14 | 660 | switch (win_info->generic.type) |
c906108c SS |
661 | { |
662 | case SRC_WIN: | |
663 | case DISASSEM_WIN: | |
6ba8e26f AC |
664 | generic_win = tui_locator_win_info_ptr (); |
665 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 666 | { |
6ba8e26f | 667 | tui_delete_win (generic_win->handle); |
e65b5245 | 668 | generic_win->handle = NULL; |
6ba8e26f | 669 | generic_win->is_visible = FALSE; |
c906108c | 670 | } |
aa079c93 | 671 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 672 | { |
aa079c93 JK |
673 | xfree (win_info->detail.source_info.fullname); |
674 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 675 | } |
6ba8e26f AC |
676 | generic_win = win_info->detail.source_info.execution_info; |
677 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 678 | { |
6ba8e26f | 679 | tui_delete_win (generic_win->handle); |
e65b5245 | 680 | generic_win->handle = NULL; |
6ba8e26f | 681 | generic_win->is_visible = FALSE; |
c906108c SS |
682 | } |
683 | break; | |
684 | case DATA_WIN: | |
6d012f14 | 685 | if (win_info->generic.content != NULL) |
c906108c | 686 | { |
6d012f14 AC |
687 | tui_del_data_windows (win_info->detail.data_display_info.regs_content, |
688 | win_info->detail.data_display_info.regs_content_count); | |
689 | tui_del_data_windows (win_info->detail.data_display_info.data_content, | |
690 | win_info->detail.data_display_info.data_content_count); | |
c906108c SS |
691 | } |
692 | break; | |
693 | default: | |
694 | break; | |
695 | } | |
6d012f14 | 696 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 697 | { |
6d012f14 | 698 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 699 | win_info->generic.handle = NULL; |
6d012f14 | 700 | win_info->generic.is_visible = FALSE; |
c906108c | 701 | } |
bc6b7f04 | 702 | } |
c906108c SS |
703 | |
704 | ||
c906108c | 705 | void |
5b6fe301 | 706 | tui_free_window (struct tui_win_info *win_info) |
c906108c | 707 | { |
5b6fe301 | 708 | struct tui_gen_win_info *generic_win; |
c906108c | 709 | |
6d012f14 | 710 | switch (win_info->generic.type) |
c906108c SS |
711 | { |
712 | case SRC_WIN: | |
713 | case DISASSEM_WIN: | |
aa079c93 | 714 | if (win_info->detail.source_info.fullname) |
bc6b7f04 | 715 | { |
aa079c93 JK |
716 | xfree (win_info->detail.source_info.fullname); |
717 | win_info->detail.source_info.fullname = NULL; | |
bc6b7f04 | 718 | } |
6ba8e26f AC |
719 | generic_win = win_info->detail.source_info.execution_info; |
720 | if (generic_win != (struct tui_gen_win_info *) NULL) | |
c906108c | 721 | { |
6ba8e26f | 722 | tui_delete_win (generic_win->handle); |
e65b5245 | 723 | generic_win->handle = NULL; |
6ba8e26f | 724 | tui_free_win_content (generic_win); |
c906108c SS |
725 | } |
726 | break; | |
727 | case DATA_WIN: | |
6d012f14 | 728 | if (win_info->generic.content != NULL) |
c906108c | 729 | { |
6d012f14 AC |
730 | tui_free_data_content (win_info->detail.data_display_info.regs_content, |
731 | win_info->detail.data_display_info.regs_content_count); | |
732 | win_info->detail.data_display_info.regs_content = | |
2a8854a7 | 733 | (tui_win_content) NULL; |
6d012f14 AC |
734 | win_info->detail.data_display_info.regs_content_count = 0; |
735 | tui_free_data_content (win_info->detail.data_display_info.data_content, | |
736 | win_info->detail.data_display_info.data_content_count); | |
737 | win_info->detail.data_display_info.data_content = | |
2a8854a7 | 738 | (tui_win_content) NULL; |
6d012f14 | 739 | win_info->detail.data_display_info.data_content_count = 0; |
6d012f14 AC |
740 | win_info->detail.data_display_info.regs_column_count = 1; |
741 | win_info->detail.data_display_info.display_regs = FALSE; | |
742 | win_info->generic.content = NULL; | |
743 | win_info->generic.content_size = 0; | |
c906108c SS |
744 | } |
745 | break; | |
746 | default: | |
747 | break; | |
748 | } | |
6d012f14 | 749 | if (win_info->generic.handle != (WINDOW *) NULL) |
c906108c | 750 | { |
6d012f14 | 751 | tui_delete_win (win_info->generic.handle); |
e65b5245 | 752 | win_info->generic.handle = NULL; |
6d012f14 | 753 | tui_free_win_content (&win_info->generic); |
c906108c | 754 | } |
6d012f14 AC |
755 | if (win_info->generic.title) |
756 | xfree (win_info->generic.title); | |
757 | xfree (win_info); | |
bc6b7f04 | 758 | } |
c906108c SS |
759 | |
760 | ||
c906108c | 761 | void |
dd1abb8c | 762 | tui_free_all_source_wins_content (void) |
c906108c SS |
763 | { |
764 | int i; | |
765 | ||
dd1abb8c | 766 | for (i = 0; i < (tui_source_windows ())->count; i++) |
c906108c | 767 | { |
5b6fe301 | 768 | struct tui_win_info *win_info = (tui_source_windows ())->list[i]; |
c906108c | 769 | |
6d012f14 | 770 | if (win_info != NULL) |
c906108c | 771 | { |
6d012f14 AC |
772 | tui_free_win_content (&(win_info->generic)); |
773 | tui_free_win_content (win_info->detail.source_info.execution_info); | |
c906108c SS |
774 | } |
775 | } | |
dd1abb8c | 776 | } |
c906108c SS |
777 | |
778 | ||
c906108c | 779 | void |
5b6fe301 | 780 | tui_free_win_content (struct tui_gen_win_info *win_info) |
c906108c | 781 | { |
6d012f14 | 782 | if (win_info->content != NULL) |
c906108c | 783 | { |
6ba8e26f | 784 | free_content ((tui_win_content) win_info->content, |
6d012f14 AC |
785 | win_info->content_size, |
786 | win_info->type); | |
787 | win_info->content = NULL; | |
c906108c | 788 | } |
6d012f14 | 789 | win_info->content_size = 0; |
6ba8e26f | 790 | } |
c906108c SS |
791 | |
792 | ||
c906108c | 793 | void |
08ef48c5 MS |
794 | tui_del_data_windows (tui_win_content content, |
795 | int content_size) | |
c906108c SS |
796 | { |
797 | int i; | |
798 | ||
ef5eab5a MS |
799 | /* Remember that data window content elements are of type struct |
800 | tui_gen_win_info *, each of which whose single element is a data | |
801 | element. */ | |
6ba8e26f | 802 | for (i = 0; i < content_size; i++) |
c906108c | 803 | { |
9a2b4c1b MS |
804 | struct tui_gen_win_info *generic_win |
805 | = &content[i]->which_element.data_window; | |
c906108c | 806 | |
6ba8e26f | 807 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 808 | { |
6ba8e26f | 809 | tui_delete_win (generic_win->handle); |
e65b5245 | 810 | generic_win->handle = NULL; |
6ba8e26f | 811 | generic_win->is_visible = FALSE; |
c906108c SS |
812 | } |
813 | } | |
dd1abb8c | 814 | } |
c906108c SS |
815 | |
816 | ||
817 | void | |
08ef48c5 MS |
818 | tui_free_data_content (tui_win_content content, |
819 | int content_size) | |
c906108c SS |
820 | { |
821 | int i; | |
822 | ||
ef5eab5a MS |
823 | /* Remember that data window content elements are of type struct |
824 | tui_gen_win_info *, each of which whose single element is a data | |
825 | element. */ | |
6ba8e26f | 826 | for (i = 0; i < content_size; i++) |
c906108c | 827 | { |
9a2b4c1b MS |
828 | struct tui_gen_win_info *generic_win |
829 | = &content[i]->which_element.data_window; | |
c906108c | 830 | |
6ba8e26f | 831 | if (generic_win != (struct tui_gen_win_info *) NULL) |
c906108c | 832 | { |
6ba8e26f | 833 | tui_delete_win (generic_win->handle); |
e65b5245 | 834 | generic_win->handle = NULL; |
6ba8e26f | 835 | tui_free_win_content (generic_win); |
c906108c SS |
836 | } |
837 | } | |
6ba8e26f | 838 | free_content (content, |
08ef48c5 MS |
839 | content_size, |
840 | DATA_WIN); | |
6ba8e26f | 841 | } |
c906108c SS |
842 | |
843 | ||
844 | /********************************** | |
845 | ** LOCAL STATIC FUNCTIONS ** | |
846 | **********************************/ | |
847 | ||
848 | ||
c906108c | 849 | static void |
08ef48c5 MS |
850 | free_content (tui_win_content content, |
851 | int content_size, | |
852 | enum tui_win_type win_type) | |
c906108c | 853 | { |
2a8854a7 | 854 | if (content != (tui_win_content) NULL) |
c906108c | 855 | { |
6ba8e26f | 856 | free_content_elements (content, content_size, win_type); |
22940a24 | 857 | xfree (content); |
c906108c | 858 | } |
6ba8e26f | 859 | } |
c906108c SS |
860 | |
861 | ||
ef5eab5a | 862 | /* free_content_elements(). |
c5aa993b | 863 | */ |
c906108c | 864 | static void |
08ef48c5 MS |
865 | free_content_elements (tui_win_content content, |
866 | int content_size, | |
867 | enum tui_win_type type) | |
c906108c | 868 | { |
2a8854a7 | 869 | if (content != (tui_win_content) NULL) |
c906108c SS |
870 | { |
871 | int i; | |
872 | ||
873 | if (type == SRC_WIN || type == DISASSEM_WIN) | |
874 | { | |
1cc6d956 | 875 | /* Free whole source block. */ |
6d012f14 | 876 | xfree (content[0]->which_element.source.line); |
c906108c SS |
877 | } |
878 | else | |
879 | { | |
6ba8e26f | 880 | for (i = 0; i < content_size; i++) |
c906108c | 881 | { |
5b6fe301 | 882 | struct tui_win_element *element; |
c906108c SS |
883 | |
884 | element = content[i]; | |
2a8854a7 | 885 | if (element != (struct tui_win_element *) NULL) |
c906108c SS |
886 | { |
887 | switch (type) | |
888 | { | |
889 | case DATA_WIN: | |
22940a24 | 890 | xfree (element); |
c906108c SS |
891 | break; |
892 | case DATA_ITEM_WIN: | |
ef5eab5a MS |
893 | /* Note that data elements are not allocated in |
894 | a single block, but individually, as | |
895 | needed. */ | |
6d012f14 AC |
896 | if (element->which_element.data.type != TUI_REGISTER) |
897 | xfree ((void *)element->which_element.data.name); | |
898 | xfree (element->which_element.data.value); | |
10f59415 | 899 | xfree (element->which_element.data.content); |
22940a24 | 900 | xfree (element); |
c906108c SS |
901 | break; |
902 | case CMD_WIN: | |
6d012f14 | 903 | xfree (element->which_element.command.line); |
c906108c SS |
904 | break; |
905 | default: | |
906 | break; | |
907 | } | |
908 | } | |
909 | } | |
910 | } | |
911 | if (type != DATA_WIN && type != DATA_ITEM_WIN) | |
1cc6d956 | 912 | xfree (content[0]); /* Free the element block. */ |
c906108c | 913 | } |
6ba8e26f | 914 | } |