15796c8dcSSimon Schubert /* TUI data manipulation routines.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1998-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by Hewlett-Packard Company.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This file is part of GDB.
85796c8dcSSimon Schubert
95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert (at your option) any later version.
135796c8dcSSimon Schubert
145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175796c8dcSSimon Schubert GNU General Public License for more details.
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
215796c8dcSSimon Schubert
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "symtab.h"
245796c8dcSSimon Schubert #include "tui/tui.h"
255796c8dcSSimon Schubert #include "tui/tui-data.h"
265796c8dcSSimon Schubert #include "tui/tui-wingeneral.h"
275796c8dcSSimon Schubert
285796c8dcSSimon Schubert #include "gdb_string.h"
295796c8dcSSimon Schubert #include "gdb_curses.h"
305796c8dcSSimon Schubert
315796c8dcSSimon Schubert /****************************
325796c8dcSSimon Schubert ** GLOBAL DECLARATIONS
335796c8dcSSimon Schubert ****************************/
345796c8dcSSimon Schubert struct tui_win_info *(tui_win_list[MAX_MAJOR_WINDOWS]);
355796c8dcSSimon Schubert
365796c8dcSSimon Schubert /***************************
375796c8dcSSimon Schubert ** Private data
385796c8dcSSimon Schubert ****************************/
395796c8dcSSimon Schubert static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
405796c8dcSSimon Schubert static int term_height, term_width;
415796c8dcSSimon Schubert static struct tui_gen_win_info _locator;
425796c8dcSSimon Schubert static struct tui_gen_win_info exec_info[2];
435796c8dcSSimon Schubert static struct tui_win_info *src_win_list[2];
445796c8dcSSimon Schubert static struct tui_list source_windows = {src_win_list, 0};
455796c8dcSSimon Schubert static int default_tab_len = DEFAULT_TAB_LEN;
465796c8dcSSimon Schubert static struct tui_win_info *win_with_focus = (struct tui_win_info *) NULL;
475796c8dcSSimon Schubert static struct tui_layout_def layout_def = {
485796c8dcSSimon Schubert SRC_WIN, /* DISPLAY_MODE */
495796c8dcSSimon Schubert FALSE, /* SPLIT */
505796c8dcSSimon Schubert TUI_UNDEFINED_REGS, /* REGS_DISPLAY_TYPE */
515796c8dcSSimon Schubert TUI_SFLOAT_REGS}; /* FLOAT_REGS_DISPLAY_TYPE */
525796c8dcSSimon Schubert
535796c8dcSSimon Schubert static int win_resized = FALSE;
545796c8dcSSimon Schubert
555796c8dcSSimon Schubert
565796c8dcSSimon Schubert /*********************************
575796c8dcSSimon Schubert ** Static function forward decls
585796c8dcSSimon Schubert **********************************/
595796c8dcSSimon Schubert static void free_content (tui_win_content,
605796c8dcSSimon Schubert int,
615796c8dcSSimon Schubert enum tui_win_type);
625796c8dcSSimon Schubert static void free_content_elements (tui_win_content,
635796c8dcSSimon Schubert int,
645796c8dcSSimon Schubert enum tui_win_type);
655796c8dcSSimon Schubert
665796c8dcSSimon Schubert
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert /*********************************
695796c8dcSSimon Schubert ** PUBLIC FUNCTIONS
705796c8dcSSimon Schubert **********************************/
715796c8dcSSimon Schubert
725796c8dcSSimon Schubert int
tui_win_is_source_type(enum tui_win_type win_type)735796c8dcSSimon Schubert tui_win_is_source_type (enum tui_win_type win_type)
745796c8dcSSimon Schubert {
755796c8dcSSimon Schubert return (win_type == SRC_WIN || win_type == DISASSEM_WIN);
765796c8dcSSimon Schubert }
775796c8dcSSimon Schubert
785796c8dcSSimon Schubert int
tui_win_is_auxillary(enum tui_win_type win_type)795796c8dcSSimon Schubert tui_win_is_auxillary (enum tui_win_type win_type)
805796c8dcSSimon Schubert {
815796c8dcSSimon Schubert return (win_type > MAX_MAJOR_WINDOWS);
825796c8dcSSimon Schubert }
835796c8dcSSimon Schubert
845796c8dcSSimon Schubert int
tui_win_has_locator(struct tui_win_info * win_info)855796c8dcSSimon Schubert tui_win_has_locator (struct tui_win_info *win_info)
865796c8dcSSimon Schubert {
875796c8dcSSimon Schubert return (win_info != NULL
885796c8dcSSimon Schubert && win_info->detail.source_info.has_locator);
895796c8dcSSimon Schubert }
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert void
tui_set_win_highlight(struct tui_win_info * win_info,int highlight)925796c8dcSSimon Schubert tui_set_win_highlight (struct tui_win_info *win_info,
935796c8dcSSimon Schubert int highlight)
945796c8dcSSimon Schubert {
955796c8dcSSimon Schubert if (win_info != NULL)
965796c8dcSSimon Schubert win_info->is_highlighted = highlight;
975796c8dcSSimon Schubert }
985796c8dcSSimon Schubert
995796c8dcSSimon Schubert /******************************************
1005796c8dcSSimon Schubert ** ACCESSORS & MUTATORS FOR PRIVATE DATA
1015796c8dcSSimon Schubert ******************************************/
1025796c8dcSSimon Schubert
1035796c8dcSSimon Schubert /* Answer a whether the terminal window has been resized or not. */
1045796c8dcSSimon Schubert int
tui_win_resized(void)1055796c8dcSSimon Schubert tui_win_resized (void)
1065796c8dcSSimon Schubert {
1075796c8dcSSimon Schubert return win_resized;
1085796c8dcSSimon Schubert }
1095796c8dcSSimon Schubert
1105796c8dcSSimon Schubert
1115796c8dcSSimon Schubert /* Set a whether the terminal window has been resized or not. */
1125796c8dcSSimon Schubert void
tui_set_win_resized_to(int resized)1135796c8dcSSimon Schubert tui_set_win_resized_to (int resized)
1145796c8dcSSimon Schubert {
1155796c8dcSSimon Schubert win_resized = resized;
1165796c8dcSSimon Schubert }
1175796c8dcSSimon Schubert
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert /* Answer a pointer to the current layout definition. */
1205796c8dcSSimon Schubert struct tui_layout_def *
tui_layout_def(void)1215796c8dcSSimon Schubert tui_layout_def (void)
1225796c8dcSSimon Schubert {
1235796c8dcSSimon Schubert return &layout_def;
1245796c8dcSSimon Schubert }
1255796c8dcSSimon Schubert
1265796c8dcSSimon Schubert
1275796c8dcSSimon Schubert /* Answer the window with the logical focus. */
1285796c8dcSSimon Schubert struct tui_win_info *
tui_win_with_focus(void)1295796c8dcSSimon Schubert tui_win_with_focus (void)
1305796c8dcSSimon Schubert {
1315796c8dcSSimon Schubert return win_with_focus;
1325796c8dcSSimon Schubert }
1335796c8dcSSimon Schubert
1345796c8dcSSimon Schubert
1355796c8dcSSimon Schubert /* Set the window that has the logical focus. */
1365796c8dcSSimon Schubert void
tui_set_win_with_focus(struct tui_win_info * win_info)1375796c8dcSSimon Schubert tui_set_win_with_focus (struct tui_win_info *win_info)
1385796c8dcSSimon Schubert {
1395796c8dcSSimon Schubert win_with_focus = win_info;
1405796c8dcSSimon Schubert }
1415796c8dcSSimon Schubert
1425796c8dcSSimon Schubert
1435796c8dcSSimon Schubert /* Answer the length in chars, of tabs. */
1445796c8dcSSimon Schubert int
tui_default_tab_len(void)1455796c8dcSSimon Schubert tui_default_tab_len (void)
1465796c8dcSSimon Schubert {
1475796c8dcSSimon Schubert return default_tab_len;
1485796c8dcSSimon Schubert }
1495796c8dcSSimon Schubert
1505796c8dcSSimon Schubert
1515796c8dcSSimon Schubert /* Set the length in chars, of tabs. */
1525796c8dcSSimon Schubert void
tui_set_default_tab_len(int len)1535796c8dcSSimon Schubert tui_set_default_tab_len (int len)
1545796c8dcSSimon Schubert {
1555796c8dcSSimon Schubert default_tab_len = len;
1565796c8dcSSimon Schubert }
1575796c8dcSSimon Schubert
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert /* Accessor for the current source window. Usually there is only one
1605796c8dcSSimon Schubert source window (either source or disassembly), but both can be
1615796c8dcSSimon Schubert displayed at the same time. */
1625796c8dcSSimon Schubert struct tui_list *
tui_source_windows(void)1635796c8dcSSimon Schubert tui_source_windows (void)
1645796c8dcSSimon Schubert {
1655796c8dcSSimon Schubert return &source_windows;
1665796c8dcSSimon Schubert }
1675796c8dcSSimon Schubert
1685796c8dcSSimon Schubert
1695796c8dcSSimon Schubert /* Clear the list of source windows. Usually there is only one source
1705796c8dcSSimon Schubert window (either source or disassembly), but both can be displayed at
1715796c8dcSSimon Schubert the same time. */
1725796c8dcSSimon Schubert void
tui_clear_source_windows(void)1735796c8dcSSimon Schubert tui_clear_source_windows (void)
1745796c8dcSSimon Schubert {
1755796c8dcSSimon Schubert source_windows.list[0] = NULL;
1765796c8dcSSimon Schubert source_windows.list[1] = NULL;
1775796c8dcSSimon Schubert source_windows.count = 0;
1785796c8dcSSimon Schubert }
1795796c8dcSSimon Schubert
1805796c8dcSSimon Schubert
1815796c8dcSSimon Schubert /* Clear the pertinant detail in the source windows. */
1825796c8dcSSimon Schubert void
tui_clear_source_windows_detail(void)1835796c8dcSSimon Schubert tui_clear_source_windows_detail (void)
1845796c8dcSSimon Schubert {
1855796c8dcSSimon Schubert int i;
1865796c8dcSSimon Schubert
1875796c8dcSSimon Schubert for (i = 0; i < (tui_source_windows ())->count; i++)
1885796c8dcSSimon Schubert tui_clear_win_detail ((tui_source_windows ())->list[i]);
1895796c8dcSSimon Schubert }
1905796c8dcSSimon Schubert
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert /* Add a window to the list of source windows. Usually there is only
1935796c8dcSSimon Schubert one source window (either source or disassembly), but both can be
1945796c8dcSSimon Schubert displayed at the same time. */
1955796c8dcSSimon Schubert void
tui_add_to_source_windows(struct tui_win_info * win_info)1965796c8dcSSimon Schubert tui_add_to_source_windows (struct tui_win_info *win_info)
1975796c8dcSSimon Schubert {
1985796c8dcSSimon Schubert if (source_windows.count < 2)
1995796c8dcSSimon Schubert source_windows.list[source_windows.count++] = (void *) win_info;
2005796c8dcSSimon Schubert }
2015796c8dcSSimon Schubert
2025796c8dcSSimon Schubert
2035796c8dcSSimon Schubert /* Clear the pertinant detail in the windows. */
2045796c8dcSSimon Schubert void
tui_clear_win_detail(struct tui_win_info * win_info)2055796c8dcSSimon Schubert tui_clear_win_detail (struct tui_win_info *win_info)
2065796c8dcSSimon Schubert {
2075796c8dcSSimon Schubert if (win_info != NULL)
2085796c8dcSSimon Schubert {
2095796c8dcSSimon Schubert switch (win_info->generic.type)
2105796c8dcSSimon Schubert {
2115796c8dcSSimon Schubert case SRC_WIN:
2125796c8dcSSimon Schubert case DISASSEM_WIN:
2135796c8dcSSimon Schubert win_info->detail.source_info.gdbarch = NULL;
2145796c8dcSSimon Schubert win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
2155796c8dcSSimon Schubert win_info->detail.source_info.start_line_or_addr.u.addr = 0;
2165796c8dcSSimon Schubert win_info->detail.source_info.horizontal_offset = 0;
2175796c8dcSSimon Schubert break;
2185796c8dcSSimon Schubert case CMD_WIN:
2195796c8dcSSimon Schubert win_info->detail.command_info.cur_line =
2205796c8dcSSimon Schubert win_info->detail.command_info.curch = 0;
2215796c8dcSSimon Schubert break;
2225796c8dcSSimon Schubert case DATA_WIN:
2235796c8dcSSimon Schubert win_info->detail.data_display_info.data_content =
2245796c8dcSSimon Schubert (tui_win_content) NULL;
2255796c8dcSSimon Schubert win_info->detail.data_display_info.data_content_count = 0;
2265796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content =
2275796c8dcSSimon Schubert (tui_win_content) NULL;
2285796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content_count = 0;
2295796c8dcSSimon Schubert win_info->detail.data_display_info.regs_display_type =
2305796c8dcSSimon Schubert TUI_UNDEFINED_REGS;
2315796c8dcSSimon Schubert win_info->detail.data_display_info.regs_column_count = 1;
2325796c8dcSSimon Schubert win_info->detail.data_display_info.display_regs = FALSE;
2335796c8dcSSimon Schubert break;
2345796c8dcSSimon Schubert default:
2355796c8dcSSimon Schubert break;
2365796c8dcSSimon Schubert }
2375796c8dcSSimon Schubert }
2385796c8dcSSimon Schubert }
2395796c8dcSSimon Schubert
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert /* Accessor for the source execution info ptr. */
2425796c8dcSSimon Schubert struct tui_gen_win_info *
tui_source_exec_info_win_ptr(void)2435796c8dcSSimon Schubert tui_source_exec_info_win_ptr (void)
2445796c8dcSSimon Schubert {
2455796c8dcSSimon Schubert return &exec_info[0];
2465796c8dcSSimon Schubert }
2475796c8dcSSimon Schubert
2485796c8dcSSimon Schubert
2495796c8dcSSimon Schubert /* Accessor for the disassem execution info ptr. */
2505796c8dcSSimon Schubert struct tui_gen_win_info *
tui_disassem_exec_info_win_ptr(void)2515796c8dcSSimon Schubert tui_disassem_exec_info_win_ptr (void)
2525796c8dcSSimon Schubert {
2535796c8dcSSimon Schubert return &exec_info[1];
2545796c8dcSSimon Schubert }
2555796c8dcSSimon Schubert
2565796c8dcSSimon Schubert
2575796c8dcSSimon Schubert /* Accessor for the locator win info. Answers a pointer to the static
2585796c8dcSSimon Schubert locator win info struct. */
2595796c8dcSSimon Schubert struct tui_gen_win_info *
tui_locator_win_info_ptr(void)2605796c8dcSSimon Schubert tui_locator_win_info_ptr (void)
2615796c8dcSSimon Schubert {
2625796c8dcSSimon Schubert return &_locator;
2635796c8dcSSimon Schubert }
2645796c8dcSSimon Schubert
2655796c8dcSSimon Schubert
2665796c8dcSSimon Schubert /* Accessor for the term_height. */
2675796c8dcSSimon Schubert int
tui_term_height(void)2685796c8dcSSimon Schubert tui_term_height (void)
2695796c8dcSSimon Schubert {
2705796c8dcSSimon Schubert return term_height;
2715796c8dcSSimon Schubert }
2725796c8dcSSimon Schubert
2735796c8dcSSimon Schubert
2745796c8dcSSimon Schubert /* Mutator for the term height. */
2755796c8dcSSimon Schubert void
tui_set_term_height_to(int h)2765796c8dcSSimon Schubert tui_set_term_height_to (int h)
2775796c8dcSSimon Schubert {
2785796c8dcSSimon Schubert term_height = h;
2795796c8dcSSimon Schubert }
2805796c8dcSSimon Schubert
2815796c8dcSSimon Schubert
2825796c8dcSSimon Schubert /* Accessor for the term_width. */
2835796c8dcSSimon Schubert int
tui_term_width(void)2845796c8dcSSimon Schubert tui_term_width (void)
2855796c8dcSSimon Schubert {
2865796c8dcSSimon Schubert return term_width;
2875796c8dcSSimon Schubert }
2885796c8dcSSimon Schubert
2895796c8dcSSimon Schubert
2905796c8dcSSimon Schubert /* Mutator for the term_width. */
2915796c8dcSSimon Schubert void
tui_set_term_width_to(int w)2925796c8dcSSimon Schubert tui_set_term_width_to (int w)
2935796c8dcSSimon Schubert {
2945796c8dcSSimon Schubert term_width = w;
2955796c8dcSSimon Schubert }
2965796c8dcSSimon Schubert
2975796c8dcSSimon Schubert
2985796c8dcSSimon Schubert /* Accessor for the current layout. */
2995796c8dcSSimon Schubert enum tui_layout_type
tui_current_layout(void)3005796c8dcSSimon Schubert tui_current_layout (void)
3015796c8dcSSimon Schubert {
3025796c8dcSSimon Schubert return current_layout;
3035796c8dcSSimon Schubert }
3045796c8dcSSimon Schubert
3055796c8dcSSimon Schubert
3065796c8dcSSimon Schubert /* Mutator for the current layout. */
3075796c8dcSSimon Schubert void
tui_set_current_layout_to(enum tui_layout_type new_layout)3085796c8dcSSimon Schubert tui_set_current_layout_to (enum tui_layout_type new_layout)
3095796c8dcSSimon Schubert {
3105796c8dcSSimon Schubert current_layout = new_layout;
3115796c8dcSSimon Schubert }
3125796c8dcSSimon Schubert
3135796c8dcSSimon Schubert
3145796c8dcSSimon Schubert /*****************************
3155796c8dcSSimon Schubert ** OTHER PUBLIC FUNCTIONS
3165796c8dcSSimon Schubert *****************************/
3175796c8dcSSimon Schubert
3185796c8dcSSimon Schubert
3195796c8dcSSimon Schubert /* Answer the next window in the list, cycling back to the top if
3205796c8dcSSimon Schubert necessary. */
3215796c8dcSSimon Schubert struct tui_win_info *
tui_next_win(struct tui_win_info * cur_win)3225796c8dcSSimon Schubert tui_next_win (struct tui_win_info *cur_win)
3235796c8dcSSimon Schubert {
3245796c8dcSSimon Schubert enum tui_win_type type = cur_win->generic.type;
3255796c8dcSSimon Schubert struct tui_win_info *next_win = (struct tui_win_info *) NULL;
3265796c8dcSSimon Schubert
3275796c8dcSSimon Schubert if (cur_win->generic.type == CMD_WIN)
3285796c8dcSSimon Schubert type = SRC_WIN;
3295796c8dcSSimon Schubert else
3305796c8dcSSimon Schubert type = cur_win->generic.type + 1;
3315796c8dcSSimon Schubert while (type != cur_win->generic.type && (next_win == NULL))
3325796c8dcSSimon Schubert {
3335796c8dcSSimon Schubert if (tui_win_list[type]
3345796c8dcSSimon Schubert && tui_win_list[type]->generic.is_visible)
3355796c8dcSSimon Schubert next_win = tui_win_list[type];
3365796c8dcSSimon Schubert else
3375796c8dcSSimon Schubert {
3385796c8dcSSimon Schubert if (type == CMD_WIN)
3395796c8dcSSimon Schubert type = SRC_WIN;
3405796c8dcSSimon Schubert else
3415796c8dcSSimon Schubert type++;
3425796c8dcSSimon Schubert }
3435796c8dcSSimon Schubert }
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert return next_win;
3465796c8dcSSimon Schubert }
3475796c8dcSSimon Schubert
3485796c8dcSSimon Schubert
3495796c8dcSSimon Schubert /* Answer the prev window in the list, cycling back to the bottom if
3505796c8dcSSimon Schubert necessary. */
3515796c8dcSSimon Schubert struct tui_win_info *
tui_prev_win(struct tui_win_info * cur_win)3525796c8dcSSimon Schubert tui_prev_win (struct tui_win_info *cur_win)
3535796c8dcSSimon Schubert {
3545796c8dcSSimon Schubert enum tui_win_type type = cur_win->generic.type;
3555796c8dcSSimon Schubert struct tui_win_info *prev = (struct tui_win_info *) NULL;
3565796c8dcSSimon Schubert
3575796c8dcSSimon Schubert if (cur_win->generic.type == SRC_WIN)
3585796c8dcSSimon Schubert type = CMD_WIN;
3595796c8dcSSimon Schubert else
3605796c8dcSSimon Schubert type = cur_win->generic.type - 1;
3615796c8dcSSimon Schubert while (type != cur_win->generic.type && (prev == NULL))
3625796c8dcSSimon Schubert {
3635796c8dcSSimon Schubert if (tui_win_list[type]
3645796c8dcSSimon Schubert && tui_win_list[type]->generic.is_visible)
3655796c8dcSSimon Schubert prev = tui_win_list[type];
3665796c8dcSSimon Schubert else
3675796c8dcSSimon Schubert {
3685796c8dcSSimon Schubert if (type == SRC_WIN)
3695796c8dcSSimon Schubert type = CMD_WIN;
3705796c8dcSSimon Schubert else
3715796c8dcSSimon Schubert type--;
3725796c8dcSSimon Schubert }
3735796c8dcSSimon Schubert }
3745796c8dcSSimon Schubert
3755796c8dcSSimon Schubert return prev;
3765796c8dcSSimon Schubert }
3775796c8dcSSimon Schubert
3785796c8dcSSimon Schubert
3795796c8dcSSimon Schubert /* Answer the window represented by name. */
3805796c8dcSSimon Schubert struct tui_win_info *
tui_partial_win_by_name(char * name)3815796c8dcSSimon Schubert tui_partial_win_by_name (char *name)
3825796c8dcSSimon Schubert {
3835796c8dcSSimon Schubert struct tui_win_info *win_info = (struct tui_win_info *) NULL;
3845796c8dcSSimon Schubert
3855796c8dcSSimon Schubert if (name != (char *) NULL)
3865796c8dcSSimon Schubert {
3875796c8dcSSimon Schubert int i = 0;
3885796c8dcSSimon Schubert
3895796c8dcSSimon Schubert while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
3905796c8dcSSimon Schubert {
3915796c8dcSSimon Schubert if (tui_win_list[i] != 0)
3925796c8dcSSimon Schubert {
3935796c8dcSSimon Schubert char *cur_name = tui_win_name (&tui_win_list[i]->generic);
394cf7f2e2dSJohn Marino
3955796c8dcSSimon Schubert if (strlen (name) <= strlen (cur_name)
3965796c8dcSSimon Schubert && strncmp (name, cur_name, strlen (name)) == 0)
3975796c8dcSSimon Schubert win_info = tui_win_list[i];
3985796c8dcSSimon Schubert }
3995796c8dcSSimon Schubert i++;
4005796c8dcSSimon Schubert }
4015796c8dcSSimon Schubert }
4025796c8dcSSimon Schubert
4035796c8dcSSimon Schubert return win_info;
4045796c8dcSSimon Schubert }
4055796c8dcSSimon Schubert
4065796c8dcSSimon Schubert
4075796c8dcSSimon Schubert /* Answer the name of the window. */
4085796c8dcSSimon Schubert char *
tui_win_name(struct tui_gen_win_info * win_info)4095796c8dcSSimon Schubert tui_win_name (struct tui_gen_win_info *win_info)
4105796c8dcSSimon Schubert {
4115796c8dcSSimon Schubert char *name = (char *) NULL;
4125796c8dcSSimon Schubert
4135796c8dcSSimon Schubert switch (win_info->type)
4145796c8dcSSimon Schubert {
4155796c8dcSSimon Schubert case SRC_WIN:
4165796c8dcSSimon Schubert name = SRC_NAME;
4175796c8dcSSimon Schubert break;
4185796c8dcSSimon Schubert case CMD_WIN:
4195796c8dcSSimon Schubert name = CMD_NAME;
4205796c8dcSSimon Schubert break;
4215796c8dcSSimon Schubert case DISASSEM_WIN:
4225796c8dcSSimon Schubert name = DISASSEM_NAME;
4235796c8dcSSimon Schubert break;
4245796c8dcSSimon Schubert case DATA_WIN:
4255796c8dcSSimon Schubert name = DATA_NAME;
4265796c8dcSSimon Schubert break;
4275796c8dcSSimon Schubert default:
4285796c8dcSSimon Schubert name = "";
4295796c8dcSSimon Schubert break;
4305796c8dcSSimon Schubert }
4315796c8dcSSimon Schubert
4325796c8dcSSimon Schubert return name;
4335796c8dcSSimon Schubert }
4345796c8dcSSimon Schubert
4355796c8dcSSimon Schubert
4365796c8dcSSimon Schubert void
tui_initialize_static_data(void)4375796c8dcSSimon Schubert tui_initialize_static_data (void)
4385796c8dcSSimon Schubert {
4395796c8dcSSimon Schubert tui_init_generic_part (tui_source_exec_info_win_ptr ());
4405796c8dcSSimon Schubert tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
4415796c8dcSSimon Schubert tui_init_generic_part (tui_locator_win_info_ptr ());
4425796c8dcSSimon Schubert }
4435796c8dcSSimon Schubert
4445796c8dcSSimon Schubert
4455796c8dcSSimon Schubert struct tui_gen_win_info *
tui_alloc_generic_win_info(void)4465796c8dcSSimon Schubert tui_alloc_generic_win_info (void)
4475796c8dcSSimon Schubert {
4485796c8dcSSimon Schubert struct tui_gen_win_info *win;
4495796c8dcSSimon Schubert
4505796c8dcSSimon Schubert if ((win = XMALLOC (struct tui_gen_win_info)) != NULL)
4515796c8dcSSimon Schubert tui_init_generic_part (win);
4525796c8dcSSimon Schubert
4535796c8dcSSimon Schubert return win;
4545796c8dcSSimon Schubert }
4555796c8dcSSimon Schubert
4565796c8dcSSimon Schubert
4575796c8dcSSimon Schubert void
tui_init_generic_part(struct tui_gen_win_info * win)4585796c8dcSSimon Schubert tui_init_generic_part (struct tui_gen_win_info *win)
4595796c8dcSSimon Schubert {
4605796c8dcSSimon Schubert win->width =
4615796c8dcSSimon Schubert win->height =
4625796c8dcSSimon Schubert win->origin.x =
4635796c8dcSSimon Schubert win->origin.y =
4645796c8dcSSimon Schubert win->viewport_height =
4655796c8dcSSimon Schubert win->content_size =
4665796c8dcSSimon Schubert win->last_visible_line = 0;
4675796c8dcSSimon Schubert win->handle = (WINDOW *) NULL;
4685796c8dcSSimon Schubert win->content = NULL;
4695796c8dcSSimon Schubert win->content_in_use =
4705796c8dcSSimon Schubert win->is_visible = FALSE;
4715796c8dcSSimon Schubert win->title = 0;
4725796c8dcSSimon Schubert }
4735796c8dcSSimon Schubert
4745796c8dcSSimon Schubert
4755796c8dcSSimon Schubert /* init_content_element().
4765796c8dcSSimon Schubert */
4775796c8dcSSimon Schubert static void
init_content_element(struct tui_win_element * element,enum tui_win_type type)4785796c8dcSSimon Schubert init_content_element (struct tui_win_element *element,
4795796c8dcSSimon Schubert enum tui_win_type type)
4805796c8dcSSimon Schubert {
4815796c8dcSSimon Schubert element->highlight = FALSE;
4825796c8dcSSimon Schubert switch (type)
4835796c8dcSSimon Schubert {
4845796c8dcSSimon Schubert case SRC_WIN:
4855796c8dcSSimon Schubert case DISASSEM_WIN:
4865796c8dcSSimon Schubert element->which_element.source.line = (char *) NULL;
4875796c8dcSSimon Schubert element->which_element.source.line_or_addr.loa = LOA_LINE;
4885796c8dcSSimon Schubert element->which_element.source.line_or_addr.u.line_no = 0;
4895796c8dcSSimon Schubert element->which_element.source.is_exec_point = FALSE;
4905796c8dcSSimon Schubert element->which_element.source.has_break = FALSE;
4915796c8dcSSimon Schubert break;
4925796c8dcSSimon Schubert case DATA_WIN:
4935796c8dcSSimon Schubert tui_init_generic_part (&element->which_element.data_window);
4945796c8dcSSimon Schubert element->which_element.data_window.type = DATA_ITEM_WIN;
495c50c785cSJohn Marino ((struct tui_gen_win_info *)
496c50c785cSJohn Marino &element->which_element.data_window)->content =
4975796c8dcSSimon Schubert (void **) tui_alloc_content (1, DATA_ITEM_WIN);
4985796c8dcSSimon Schubert ((struct tui_gen_win_info *)
4995796c8dcSSimon Schubert & element->which_element.data_window)->content_size = 1;
5005796c8dcSSimon Schubert break;
5015796c8dcSSimon Schubert case CMD_WIN:
5025796c8dcSSimon Schubert element->which_element.command.line = (char *) NULL;
5035796c8dcSSimon Schubert break;
5045796c8dcSSimon Schubert case DATA_ITEM_WIN:
5055796c8dcSSimon Schubert element->which_element.data.name = (char *) NULL;
5065796c8dcSSimon Schubert element->which_element.data.type = TUI_REGISTER;
5075796c8dcSSimon Schubert element->which_element.data.item_no = UNDEFINED_ITEM;
5085796c8dcSSimon Schubert element->which_element.data.value = NULL;
5095796c8dcSSimon Schubert element->which_element.data.highlight = FALSE;
5105796c8dcSSimon Schubert element->which_element.data.content = (char*) NULL;
5115796c8dcSSimon Schubert break;
5125796c8dcSSimon Schubert case LOCATOR_WIN:
513*ef5ccd6cSJohn Marino element->which_element.locator.full_name[0] =
5145796c8dcSSimon Schubert element->which_element.locator.proc_name[0] = (char) 0;
5155796c8dcSSimon Schubert element->which_element.locator.line_no = 0;
5165796c8dcSSimon Schubert element->which_element.locator.addr = 0;
5175796c8dcSSimon Schubert break;
5185796c8dcSSimon Schubert case EXEC_INFO_WIN:
5195796c8dcSSimon Schubert memset(element->which_element.simple_string, ' ',
5205796c8dcSSimon Schubert sizeof(element->which_element.simple_string));
5215796c8dcSSimon Schubert break;
5225796c8dcSSimon Schubert default:
5235796c8dcSSimon Schubert break;
5245796c8dcSSimon Schubert }
5255796c8dcSSimon Schubert }
5265796c8dcSSimon Schubert
5275796c8dcSSimon Schubert static void
init_win_info(struct tui_win_info * win_info)5285796c8dcSSimon Schubert init_win_info (struct tui_win_info *win_info)
5295796c8dcSSimon Schubert {
5305796c8dcSSimon Schubert tui_init_generic_part (&win_info->generic);
5315796c8dcSSimon Schubert win_info->can_highlight =
5325796c8dcSSimon Schubert win_info->is_highlighted = FALSE;
5335796c8dcSSimon Schubert switch (win_info->generic.type)
5345796c8dcSSimon Schubert {
5355796c8dcSSimon Schubert case SRC_WIN:
5365796c8dcSSimon Schubert case DISASSEM_WIN:
537c50c785cSJohn Marino win_info->detail.source_info.execution_info
538c50c785cSJohn Marino = (struct tui_gen_win_info *) NULL;
5395796c8dcSSimon Schubert win_info->detail.source_info.has_locator = FALSE;
5405796c8dcSSimon Schubert win_info->detail.source_info.horizontal_offset = 0;
5415796c8dcSSimon Schubert win_info->detail.source_info.gdbarch = NULL;
5425796c8dcSSimon Schubert win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
5435796c8dcSSimon Schubert win_info->detail.source_info.start_line_or_addr.u.addr = 0;
544*ef5ccd6cSJohn Marino win_info->detail.source_info.fullname = NULL;
5455796c8dcSSimon Schubert break;
5465796c8dcSSimon Schubert case DATA_WIN:
5475796c8dcSSimon Schubert win_info->detail.data_display_info.data_content = (tui_win_content) NULL;
5485796c8dcSSimon Schubert win_info->detail.data_display_info.data_content_count = 0;
5495796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content = (tui_win_content) NULL;
5505796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content_count = 0;
5515796c8dcSSimon Schubert win_info->detail.data_display_info.regs_display_type =
5525796c8dcSSimon Schubert TUI_UNDEFINED_REGS;
5535796c8dcSSimon Schubert win_info->detail.data_display_info.regs_column_count = 1;
5545796c8dcSSimon Schubert win_info->detail.data_display_info.display_regs = FALSE;
5555796c8dcSSimon Schubert win_info->detail.data_display_info.current_group = 0;
5565796c8dcSSimon Schubert break;
5575796c8dcSSimon Schubert case CMD_WIN:
5585796c8dcSSimon Schubert win_info->detail.command_info.cur_line = 0;
5595796c8dcSSimon Schubert win_info->detail.command_info.curch = 0;
5605796c8dcSSimon Schubert break;
5615796c8dcSSimon Schubert default:
5625796c8dcSSimon Schubert win_info->detail.opaque = NULL;
5635796c8dcSSimon Schubert break;
5645796c8dcSSimon Schubert }
5655796c8dcSSimon Schubert }
5665796c8dcSSimon Schubert
5675796c8dcSSimon Schubert
5685796c8dcSSimon Schubert struct tui_win_info *
tui_alloc_win_info(enum tui_win_type type)5695796c8dcSSimon Schubert tui_alloc_win_info (enum tui_win_type type)
5705796c8dcSSimon Schubert {
5715796c8dcSSimon Schubert struct tui_win_info *win_info;
5725796c8dcSSimon Schubert
5735796c8dcSSimon Schubert win_info = XMALLOC (struct tui_win_info);
5745796c8dcSSimon Schubert if (win_info != NULL)
5755796c8dcSSimon Schubert {
5765796c8dcSSimon Schubert win_info->generic.type = type;
5775796c8dcSSimon Schubert init_win_info (win_info);
5785796c8dcSSimon Schubert }
5795796c8dcSSimon Schubert
5805796c8dcSSimon Schubert return win_info;
5815796c8dcSSimon Schubert }
5825796c8dcSSimon Schubert
5835796c8dcSSimon Schubert
5845796c8dcSSimon Schubert /* Allocates the content and elements in a block. */
5855796c8dcSSimon Schubert tui_win_content
tui_alloc_content(int num_elements,enum tui_win_type type)5865796c8dcSSimon Schubert tui_alloc_content (int num_elements, enum tui_win_type type)
5875796c8dcSSimon Schubert {
5885796c8dcSSimon Schubert tui_win_content content;
5895796c8dcSSimon Schubert char *element_block_ptr;
5905796c8dcSSimon Schubert int i;
5915796c8dcSSimon Schubert
5925796c8dcSSimon Schubert content = xmalloc (sizeof (struct tui_win_element *) *num_elements);
5935796c8dcSSimon Schubert if (content != NULL)
5945796c8dcSSimon Schubert {
5955796c8dcSSimon Schubert /*
5965796c8dcSSimon Schubert * All windows, except the data window, can allocate the
5975796c8dcSSimon Schubert * elements in a chunk. The data window cannot because items
5985796c8dcSSimon Schubert * can be added/removed from the data display by the user at any
5995796c8dcSSimon Schubert * time.
6005796c8dcSSimon Schubert */
6015796c8dcSSimon Schubert if (type != DATA_WIN)
6025796c8dcSSimon Schubert {
6035796c8dcSSimon Schubert element_block_ptr =
6045796c8dcSSimon Schubert xmalloc (sizeof (struct tui_win_element) * num_elements);
6055796c8dcSSimon Schubert if (element_block_ptr != NULL)
6065796c8dcSSimon Schubert {
6075796c8dcSSimon Schubert for (i = 0; i < num_elements; i++)
6085796c8dcSSimon Schubert {
6095796c8dcSSimon Schubert content[i] = (struct tui_win_element *) element_block_ptr;
6105796c8dcSSimon Schubert init_content_element (content[i], type);
6115796c8dcSSimon Schubert element_block_ptr += sizeof (struct tui_win_element);
6125796c8dcSSimon Schubert }
6135796c8dcSSimon Schubert }
6145796c8dcSSimon Schubert else
6155796c8dcSSimon Schubert {
6165796c8dcSSimon Schubert xfree (content);
6175796c8dcSSimon Schubert content = (tui_win_content) NULL;
6185796c8dcSSimon Schubert }
6195796c8dcSSimon Schubert }
6205796c8dcSSimon Schubert }
6215796c8dcSSimon Schubert
6225796c8dcSSimon Schubert return content;
6235796c8dcSSimon Schubert }
6245796c8dcSSimon Schubert
6255796c8dcSSimon Schubert
6265796c8dcSSimon Schubert /* Adds the input number of elements to the windows's content. If no
6275796c8dcSSimon Schubert content has been allocated yet, alloc_content() is called to do
6285796c8dcSSimon Schubert this. The index of the first element added is returned, unless
6295796c8dcSSimon Schubert there is a memory allocation error, in which case, (-1) is
6305796c8dcSSimon Schubert returned. */
6315796c8dcSSimon Schubert int
tui_add_content_elements(struct tui_gen_win_info * win_info,int num_elements)6325796c8dcSSimon Schubert tui_add_content_elements (struct tui_gen_win_info *win_info,
6335796c8dcSSimon Schubert int num_elements)
6345796c8dcSSimon Schubert {
6355796c8dcSSimon Schubert struct tui_win_element *element_ptr;
6365796c8dcSSimon Schubert int i, index_start;
6375796c8dcSSimon Schubert
6385796c8dcSSimon Schubert if (win_info->content == NULL)
6395796c8dcSSimon Schubert {
640c50c785cSJohn Marino win_info->content = (void **) tui_alloc_content (num_elements,
641c50c785cSJohn Marino win_info->type);
6425796c8dcSSimon Schubert index_start = 0;
6435796c8dcSSimon Schubert }
6445796c8dcSSimon Schubert else
6455796c8dcSSimon Schubert index_start = win_info->content_size;
6465796c8dcSSimon Schubert if (win_info->content != NULL)
6475796c8dcSSimon Schubert {
6485796c8dcSSimon Schubert for (i = index_start; (i < num_elements + index_start); i++)
6495796c8dcSSimon Schubert {
6505796c8dcSSimon Schubert if ((element_ptr = XMALLOC (struct tui_win_element)) != NULL)
6515796c8dcSSimon Schubert {
6525796c8dcSSimon Schubert win_info->content[i] = (void *) element_ptr;
6535796c8dcSSimon Schubert init_content_element (element_ptr, win_info->type);
6545796c8dcSSimon Schubert win_info->content_size++;
6555796c8dcSSimon Schubert }
6565796c8dcSSimon Schubert else /* Things must be really hosed now! We ran out of
6575796c8dcSSimon Schubert memory!? */
6585796c8dcSSimon Schubert return (-1);
6595796c8dcSSimon Schubert }
6605796c8dcSSimon Schubert }
6615796c8dcSSimon Schubert
6625796c8dcSSimon Schubert return index_start;
6635796c8dcSSimon Schubert }
6645796c8dcSSimon Schubert
6655796c8dcSSimon Schubert
6665796c8dcSSimon Schubert /* Delete all curses windows associated with win_info, leaving
6675796c8dcSSimon Schubert everything else intact. */
6685796c8dcSSimon Schubert void
tui_del_window(struct tui_win_info * win_info)6695796c8dcSSimon Schubert tui_del_window (struct tui_win_info *win_info)
6705796c8dcSSimon Schubert {
6715796c8dcSSimon Schubert struct tui_gen_win_info *generic_win;
6725796c8dcSSimon Schubert
6735796c8dcSSimon Schubert switch (win_info->generic.type)
6745796c8dcSSimon Schubert {
6755796c8dcSSimon Schubert case SRC_WIN:
6765796c8dcSSimon Schubert case DISASSEM_WIN:
6775796c8dcSSimon Schubert generic_win = tui_locator_win_info_ptr ();
6785796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
6795796c8dcSSimon Schubert {
6805796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
6815796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
6825796c8dcSSimon Schubert generic_win->is_visible = FALSE;
6835796c8dcSSimon Schubert }
684*ef5ccd6cSJohn Marino if (win_info->detail.source_info.fullname)
6855796c8dcSSimon Schubert {
686*ef5ccd6cSJohn Marino xfree (win_info->detail.source_info.fullname);
687*ef5ccd6cSJohn Marino win_info->detail.source_info.fullname = NULL;
6885796c8dcSSimon Schubert }
6895796c8dcSSimon Schubert generic_win = win_info->detail.source_info.execution_info;
6905796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
6915796c8dcSSimon Schubert {
6925796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
6935796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
6945796c8dcSSimon Schubert generic_win->is_visible = FALSE;
6955796c8dcSSimon Schubert }
6965796c8dcSSimon Schubert break;
6975796c8dcSSimon Schubert case DATA_WIN:
6985796c8dcSSimon Schubert if (win_info->generic.content != NULL)
6995796c8dcSSimon Schubert {
7005796c8dcSSimon Schubert tui_del_data_windows (win_info->detail.data_display_info.regs_content,
7015796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content_count);
7025796c8dcSSimon Schubert tui_del_data_windows (win_info->detail.data_display_info.data_content,
7035796c8dcSSimon Schubert win_info->detail.data_display_info.data_content_count);
7045796c8dcSSimon Schubert }
7055796c8dcSSimon Schubert break;
7065796c8dcSSimon Schubert default:
7075796c8dcSSimon Schubert break;
7085796c8dcSSimon Schubert }
7095796c8dcSSimon Schubert if (win_info->generic.handle != (WINDOW *) NULL)
7105796c8dcSSimon Schubert {
7115796c8dcSSimon Schubert tui_delete_win (win_info->generic.handle);
7125796c8dcSSimon Schubert win_info->generic.handle = (WINDOW *) NULL;
7135796c8dcSSimon Schubert win_info->generic.is_visible = FALSE;
7145796c8dcSSimon Schubert }
7155796c8dcSSimon Schubert }
7165796c8dcSSimon Schubert
7175796c8dcSSimon Schubert
7185796c8dcSSimon Schubert void
tui_free_window(struct tui_win_info * win_info)7195796c8dcSSimon Schubert tui_free_window (struct tui_win_info *win_info)
7205796c8dcSSimon Schubert {
7215796c8dcSSimon Schubert struct tui_gen_win_info *generic_win;
7225796c8dcSSimon Schubert
7235796c8dcSSimon Schubert switch (win_info->generic.type)
7245796c8dcSSimon Schubert {
7255796c8dcSSimon Schubert case SRC_WIN:
7265796c8dcSSimon Schubert case DISASSEM_WIN:
7275796c8dcSSimon Schubert generic_win = tui_locator_win_info_ptr ();
7285796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
7295796c8dcSSimon Schubert {
7305796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
7315796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
7325796c8dcSSimon Schubert }
7335796c8dcSSimon Schubert tui_free_win_content (generic_win);
734*ef5ccd6cSJohn Marino if (win_info->detail.source_info.fullname)
7355796c8dcSSimon Schubert {
736*ef5ccd6cSJohn Marino xfree (win_info->detail.source_info.fullname);
737*ef5ccd6cSJohn Marino win_info->detail.source_info.fullname = NULL;
7385796c8dcSSimon Schubert }
7395796c8dcSSimon Schubert generic_win = win_info->detail.source_info.execution_info;
7405796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
7415796c8dcSSimon Schubert {
7425796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
7435796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
7445796c8dcSSimon Schubert tui_free_win_content (generic_win);
7455796c8dcSSimon Schubert }
7465796c8dcSSimon Schubert break;
7475796c8dcSSimon Schubert case DATA_WIN:
7485796c8dcSSimon Schubert if (win_info->generic.content != NULL)
7495796c8dcSSimon Schubert {
7505796c8dcSSimon Schubert tui_free_data_content (win_info->detail.data_display_info.regs_content,
7515796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content_count);
7525796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content =
7535796c8dcSSimon Schubert (tui_win_content) NULL;
7545796c8dcSSimon Schubert win_info->detail.data_display_info.regs_content_count = 0;
7555796c8dcSSimon Schubert tui_free_data_content (win_info->detail.data_display_info.data_content,
7565796c8dcSSimon Schubert win_info->detail.data_display_info.data_content_count);
7575796c8dcSSimon Schubert win_info->detail.data_display_info.data_content =
7585796c8dcSSimon Schubert (tui_win_content) NULL;
7595796c8dcSSimon Schubert win_info->detail.data_display_info.data_content_count = 0;
7605796c8dcSSimon Schubert win_info->detail.data_display_info.regs_display_type =
7615796c8dcSSimon Schubert TUI_UNDEFINED_REGS;
7625796c8dcSSimon Schubert win_info->detail.data_display_info.regs_column_count = 1;
7635796c8dcSSimon Schubert win_info->detail.data_display_info.display_regs = FALSE;
7645796c8dcSSimon Schubert win_info->generic.content = NULL;
7655796c8dcSSimon Schubert win_info->generic.content_size = 0;
7665796c8dcSSimon Schubert }
7675796c8dcSSimon Schubert break;
7685796c8dcSSimon Schubert default:
7695796c8dcSSimon Schubert break;
7705796c8dcSSimon Schubert }
7715796c8dcSSimon Schubert if (win_info->generic.handle != (WINDOW *) NULL)
7725796c8dcSSimon Schubert {
7735796c8dcSSimon Schubert tui_delete_win (win_info->generic.handle);
7745796c8dcSSimon Schubert win_info->generic.handle = (WINDOW *) NULL;
7755796c8dcSSimon Schubert tui_free_win_content (&win_info->generic);
7765796c8dcSSimon Schubert }
7775796c8dcSSimon Schubert if (win_info->generic.title)
7785796c8dcSSimon Schubert xfree (win_info->generic.title);
7795796c8dcSSimon Schubert xfree (win_info);
7805796c8dcSSimon Schubert }
7815796c8dcSSimon Schubert
7825796c8dcSSimon Schubert
7835796c8dcSSimon Schubert void
tui_free_all_source_wins_content(void)7845796c8dcSSimon Schubert tui_free_all_source_wins_content (void)
7855796c8dcSSimon Schubert {
7865796c8dcSSimon Schubert int i;
7875796c8dcSSimon Schubert
7885796c8dcSSimon Schubert for (i = 0; i < (tui_source_windows ())->count; i++)
7895796c8dcSSimon Schubert {
7905796c8dcSSimon Schubert struct tui_win_info *win_info = (tui_source_windows ())->list[i];
7915796c8dcSSimon Schubert
7925796c8dcSSimon Schubert if (win_info != NULL)
7935796c8dcSSimon Schubert {
7945796c8dcSSimon Schubert tui_free_win_content (&(win_info->generic));
7955796c8dcSSimon Schubert tui_free_win_content (win_info->detail.source_info.execution_info);
7965796c8dcSSimon Schubert }
7975796c8dcSSimon Schubert }
7985796c8dcSSimon Schubert }
7995796c8dcSSimon Schubert
8005796c8dcSSimon Schubert
8015796c8dcSSimon Schubert void
tui_free_win_content(struct tui_gen_win_info * win_info)8025796c8dcSSimon Schubert tui_free_win_content (struct tui_gen_win_info *win_info)
8035796c8dcSSimon Schubert {
8045796c8dcSSimon Schubert if (win_info->content != NULL)
8055796c8dcSSimon Schubert {
8065796c8dcSSimon Schubert free_content ((tui_win_content) win_info->content,
8075796c8dcSSimon Schubert win_info->content_size,
8085796c8dcSSimon Schubert win_info->type);
8095796c8dcSSimon Schubert win_info->content = NULL;
8105796c8dcSSimon Schubert }
8115796c8dcSSimon Schubert win_info->content_size = 0;
8125796c8dcSSimon Schubert }
8135796c8dcSSimon Schubert
8145796c8dcSSimon Schubert
8155796c8dcSSimon Schubert void
tui_del_data_windows(tui_win_content content,int content_size)8165796c8dcSSimon Schubert tui_del_data_windows (tui_win_content content,
8175796c8dcSSimon Schubert int content_size)
8185796c8dcSSimon Schubert {
8195796c8dcSSimon Schubert int i;
8205796c8dcSSimon Schubert
8215796c8dcSSimon Schubert /* Remember that data window content elements are of type struct
8225796c8dcSSimon Schubert tui_gen_win_info *, each of which whose single element is a data
8235796c8dcSSimon Schubert element. */
8245796c8dcSSimon Schubert for (i = 0; i < content_size; i++)
8255796c8dcSSimon Schubert {
826c50c785cSJohn Marino struct tui_gen_win_info *generic_win
827c50c785cSJohn Marino = &content[i]->which_element.data_window;
8285796c8dcSSimon Schubert
8295796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
8305796c8dcSSimon Schubert {
8315796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
8325796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
8335796c8dcSSimon Schubert generic_win->is_visible = FALSE;
8345796c8dcSSimon Schubert }
8355796c8dcSSimon Schubert }
8365796c8dcSSimon Schubert }
8375796c8dcSSimon Schubert
8385796c8dcSSimon Schubert
8395796c8dcSSimon Schubert void
tui_free_data_content(tui_win_content content,int content_size)8405796c8dcSSimon Schubert tui_free_data_content (tui_win_content content,
8415796c8dcSSimon Schubert int content_size)
8425796c8dcSSimon Schubert {
8435796c8dcSSimon Schubert int i;
8445796c8dcSSimon Schubert
8455796c8dcSSimon Schubert /* Remember that data window content elements are of type struct
8465796c8dcSSimon Schubert tui_gen_win_info *, each of which whose single element is a data
8475796c8dcSSimon Schubert element. */
8485796c8dcSSimon Schubert for (i = 0; i < content_size; i++)
8495796c8dcSSimon Schubert {
850c50c785cSJohn Marino struct tui_gen_win_info *generic_win
851c50c785cSJohn Marino = &content[i]->which_element.data_window;
8525796c8dcSSimon Schubert
8535796c8dcSSimon Schubert if (generic_win != (struct tui_gen_win_info *) NULL)
8545796c8dcSSimon Schubert {
8555796c8dcSSimon Schubert tui_delete_win (generic_win->handle);
8565796c8dcSSimon Schubert generic_win->handle = (WINDOW *) NULL;
8575796c8dcSSimon Schubert tui_free_win_content (generic_win);
8585796c8dcSSimon Schubert }
8595796c8dcSSimon Schubert }
8605796c8dcSSimon Schubert free_content (content,
8615796c8dcSSimon Schubert content_size,
8625796c8dcSSimon Schubert DATA_WIN);
8635796c8dcSSimon Schubert }
8645796c8dcSSimon Schubert
8655796c8dcSSimon Schubert
8665796c8dcSSimon Schubert /**********************************
8675796c8dcSSimon Schubert ** LOCAL STATIC FUNCTIONS **
8685796c8dcSSimon Schubert **********************************/
8695796c8dcSSimon Schubert
8705796c8dcSSimon Schubert
8715796c8dcSSimon Schubert static void
free_content(tui_win_content content,int content_size,enum tui_win_type win_type)8725796c8dcSSimon Schubert free_content (tui_win_content content,
8735796c8dcSSimon Schubert int content_size,
8745796c8dcSSimon Schubert enum tui_win_type win_type)
8755796c8dcSSimon Schubert {
8765796c8dcSSimon Schubert if (content != (tui_win_content) NULL)
8775796c8dcSSimon Schubert {
8785796c8dcSSimon Schubert free_content_elements (content, content_size, win_type);
8795796c8dcSSimon Schubert xfree (content);
8805796c8dcSSimon Schubert }
8815796c8dcSSimon Schubert }
8825796c8dcSSimon Schubert
8835796c8dcSSimon Schubert
8845796c8dcSSimon Schubert /* free_content_elements().
8855796c8dcSSimon Schubert */
8865796c8dcSSimon Schubert static void
free_content_elements(tui_win_content content,int content_size,enum tui_win_type type)8875796c8dcSSimon Schubert free_content_elements (tui_win_content content,
8885796c8dcSSimon Schubert int content_size,
8895796c8dcSSimon Schubert enum tui_win_type type)
8905796c8dcSSimon Schubert {
8915796c8dcSSimon Schubert if (content != (tui_win_content) NULL)
8925796c8dcSSimon Schubert {
8935796c8dcSSimon Schubert int i;
8945796c8dcSSimon Schubert
8955796c8dcSSimon Schubert if (type == SRC_WIN || type == DISASSEM_WIN)
8965796c8dcSSimon Schubert {
8975796c8dcSSimon Schubert /* Free whole source block. */
8985796c8dcSSimon Schubert xfree (content[0]->which_element.source.line);
8995796c8dcSSimon Schubert }
9005796c8dcSSimon Schubert else
9015796c8dcSSimon Schubert {
9025796c8dcSSimon Schubert for (i = 0; i < content_size; i++)
9035796c8dcSSimon Schubert {
9045796c8dcSSimon Schubert struct tui_win_element *element;
9055796c8dcSSimon Schubert
9065796c8dcSSimon Schubert element = content[i];
9075796c8dcSSimon Schubert if (element != (struct tui_win_element *) NULL)
9085796c8dcSSimon Schubert {
9095796c8dcSSimon Schubert switch (type)
9105796c8dcSSimon Schubert {
9115796c8dcSSimon Schubert case DATA_WIN:
9125796c8dcSSimon Schubert xfree (element);
9135796c8dcSSimon Schubert break;
9145796c8dcSSimon Schubert case DATA_ITEM_WIN:
9155796c8dcSSimon Schubert /* Note that data elements are not allocated in
9165796c8dcSSimon Schubert a single block, but individually, as
9175796c8dcSSimon Schubert needed. */
9185796c8dcSSimon Schubert if (element->which_element.data.type != TUI_REGISTER)
9195796c8dcSSimon Schubert xfree ((void *)element->which_element.data.name);
9205796c8dcSSimon Schubert xfree (element->which_element.data.value);
9215796c8dcSSimon Schubert xfree (element->which_element.data.content);
9225796c8dcSSimon Schubert xfree (element);
9235796c8dcSSimon Schubert break;
9245796c8dcSSimon Schubert case CMD_WIN:
9255796c8dcSSimon Schubert xfree (element->which_element.command.line);
9265796c8dcSSimon Schubert break;
9275796c8dcSSimon Schubert default:
9285796c8dcSSimon Schubert break;
9295796c8dcSSimon Schubert }
9305796c8dcSSimon Schubert }
9315796c8dcSSimon Schubert }
9325796c8dcSSimon Schubert }
9335796c8dcSSimon Schubert if (type != DATA_WIN && type != DATA_ITEM_WIN)
9345796c8dcSSimon Schubert xfree (content[0]); /* Free the element block. */
9355796c8dcSSimon Schubert }
9365796c8dcSSimon Schubert }
937