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