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