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