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