Home | History | Annotate | Line # | Download | only in tui
tui-win.c revision 1.3
      1  1.1  christos /* TUI window generic functions.
      2  1.1  christos 
      3  1.3  christos    Copyright (C) 1998-2015 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    Contributed by Hewlett-Packard Company.
      6  1.1  christos 
      7  1.1  christos    This file is part of GDB.
      8  1.1  christos 
      9  1.1  christos    This program is free software; you can redistribute it and/or modify
     10  1.1  christos    it under the terms of the GNU General Public License as published by
     11  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12  1.1  christos    (at your option) any later version.
     13  1.1  christos 
     14  1.1  christos    This program is distributed in the hope that it will be useful,
     15  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  1.1  christos    GNU General Public License for more details.
     18  1.1  christos 
     19  1.1  christos    You should have received a copy of the GNU General Public License
     20  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21  1.1  christos 
     22  1.1  christos /* This module contains procedures for handling tui window functions
     23  1.1  christos    like resize, scrolling, scrolling, changing focus, etc.
     24  1.1  christos 
     25  1.1  christos    Author: Susan B. Macchia  */
     26  1.1  christos 
     27  1.1  christos #include "defs.h"
     28  1.1  christos #include "command.h"
     29  1.1  christos #include "symtab.h"
     30  1.1  christos #include "breakpoint.h"
     31  1.1  christos #include "frame.h"
     32  1.1  christos #include "cli/cli-cmds.h"
     33  1.1  christos #include "top.h"
     34  1.1  christos #include "source.h"
     35  1.1  christos 
     36  1.1  christos #include "tui/tui.h"
     37  1.1  christos #include "tui/tui-data.h"
     38  1.1  christos #include "tui/tui-wingeneral.h"
     39  1.1  christos #include "tui/tui-stack.h"
     40  1.1  christos #include "tui/tui-regs.h"
     41  1.1  christos #include "tui/tui-disasm.h"
     42  1.1  christos #include "tui/tui-source.h"
     43  1.1  christos #include "tui/tui-winsource.h"
     44  1.1  christos #include "tui/tui-windata.h"
     45  1.1  christos #include "tui/tui-win.h"
     46  1.1  christos 
     47  1.1  christos #include "gdb_curses.h"
     48  1.1  christos #include <ctype.h>
     49  1.1  christos #include "readline/readline.h"
     50  1.1  christos 
     51  1.1  christos #include <signal.h>
     52  1.1  christos 
     53  1.1  christos /*******************************
     54  1.1  christos ** Static Local Decls
     55  1.1  christos ********************************/
     56  1.1  christos static void make_visible_with_new_height (struct tui_win_info *);
     57  1.1  christos static void make_invisible_and_set_new_height (struct tui_win_info *,
     58  1.1  christos 					       int);
     59  1.1  christos static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
     60  1.1  christos 					       int);
     61  1.1  christos static int new_height_ok (struct tui_win_info *, int);
     62  1.1  christos static void tui_set_tab_width_command (char *, int);
     63  1.1  christos static void tui_refresh_all_command (char *, int);
     64  1.1  christos static void tui_set_win_height_command (char *, int);
     65  1.1  christos static void tui_xdb_set_win_height_command (char *, int);
     66  1.1  christos static void tui_all_windows_info (char *, int);
     67  1.1  christos static void tui_set_focus_command (char *, int);
     68  1.1  christos static void tui_scroll_forward_command (char *, int);
     69  1.1  christos static void tui_scroll_backward_command (char *, int);
     70  1.1  christos static void tui_scroll_left_command (char *, int);
     71  1.1  christos static void tui_scroll_right_command (char *, int);
     72  1.1  christos static void parse_scrolling_args (char *,
     73  1.1  christos 				  struct tui_win_info **,
     74  1.1  christos 				  int *);
     75  1.1  christos 
     76  1.1  christos 
     77  1.1  christos /***************************************
     78  1.1  christos ** DEFINITIONS
     79  1.1  christos ***************************************/
     80  1.1  christos #define WIN_HEIGHT_USAGE    "Usage: winheight <win_name> [+ | -] <#lines>\n"
     81  1.1  christos #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
     82  1.1  christos #define FOCUS_USAGE         "Usage: focus {<win> | next | prev}\n"
     83  1.1  christos 
     84  1.1  christos /***************************************
     85  1.1  christos ** PUBLIC FUNCTIONS
     86  1.1  christos ***************************************/
     87  1.1  christos 
     88  1.1  christos #ifndef ACS_LRCORNER
     89  1.1  christos #  define ACS_LRCORNER '+'
     90  1.1  christos #endif
     91  1.1  christos #ifndef ACS_LLCORNER
     92  1.1  christos #  define ACS_LLCORNER '+'
     93  1.1  christos #endif
     94  1.1  christos #ifndef ACS_ULCORNER
     95  1.1  christos #  define ACS_ULCORNER '+'
     96  1.1  christos #endif
     97  1.1  christos #ifndef ACS_URCORNER
     98  1.1  christos #  define ACS_URCORNER '+'
     99  1.1  christos #endif
    100  1.1  christos #ifndef ACS_HLINE
    101  1.1  christos #  define ACS_HLINE '-'
    102  1.1  christos #endif
    103  1.1  christos #ifndef ACS_VLINE
    104  1.1  christos #  define ACS_VLINE '|'
    105  1.1  christos #endif
    106  1.1  christos 
    107  1.1  christos /* Possible values for tui-border-kind variable.  */
    108  1.1  christos static const char *const tui_border_kind_enums[] = {
    109  1.1  christos   "space",
    110  1.1  christos   "ascii",
    111  1.1  christos   "acs",
    112  1.1  christos   NULL
    113  1.1  christos };
    114  1.1  christos 
    115  1.1  christos /* Possible values for tui-border-mode and tui-active-border-mode.  */
    116  1.1  christos static const char *const tui_border_mode_enums[] = {
    117  1.1  christos   "normal",
    118  1.1  christos   "standout",
    119  1.1  christos   "reverse",
    120  1.1  christos   "half",
    121  1.1  christos   "half-standout",
    122  1.1  christos   "bold",
    123  1.1  christos   "bold-standout",
    124  1.1  christos   NULL
    125  1.1  christos };
    126  1.1  christos 
    127  1.1  christos struct tui_translate
    128  1.1  christos {
    129  1.1  christos   const char *name;
    130  1.1  christos   int value;
    131  1.1  christos };
    132  1.1  christos 
    133  1.1  christos /* Translation table for border-mode variables.
    134  1.1  christos    The list of values must be terminated by a NULL.
    135  1.1  christos    After the NULL value, an entry defines the default.  */
    136  1.1  christos struct tui_translate tui_border_mode_translate[] = {
    137  1.1  christos   { "normal",		A_NORMAL },
    138  1.1  christos   { "standout",		A_STANDOUT },
    139  1.1  christos   { "reverse",		A_REVERSE },
    140  1.1  christos   { "half",		A_DIM },
    141  1.1  christos   { "half-standout",	A_DIM | A_STANDOUT },
    142  1.1  christos   { "bold",		A_BOLD },
    143  1.1  christos   { "bold-standout",	A_BOLD | A_STANDOUT },
    144  1.1  christos   { 0, 0 },
    145  1.1  christos   { "normal",		A_NORMAL }
    146  1.1  christos };
    147  1.1  christos 
    148  1.1  christos /* Translation tables for border-kind, one for each border
    149  1.1  christos    character (see wborder, border curses operations).
    150  1.1  christos    -1 is used to indicate the ACS because ACS characters
    151  1.1  christos    are determined at run time by curses (depends on terminal).  */
    152  1.1  christos struct tui_translate tui_border_kind_translate_vline[] = {
    153  1.1  christos   { "space",    ' ' },
    154  1.1  christos   { "ascii",    '|' },
    155  1.1  christos   { "acs",      -1 },
    156  1.1  christos   { 0, 0 },
    157  1.1  christos   { "ascii",    '|' }
    158  1.1  christos };
    159  1.1  christos 
    160  1.1  christos struct tui_translate tui_border_kind_translate_hline[] = {
    161  1.1  christos   { "space",    ' ' },
    162  1.1  christos   { "ascii",    '-' },
    163  1.1  christos   { "acs",      -1 },
    164  1.1  christos   { 0, 0 },
    165  1.1  christos   { "ascii",    '-' }
    166  1.1  christos };
    167  1.1  christos 
    168  1.1  christos struct tui_translate tui_border_kind_translate_ulcorner[] = {
    169  1.1  christos   { "space",    ' ' },
    170  1.1  christos   { "ascii",    '+' },
    171  1.1  christos   { "acs",      -1 },
    172  1.1  christos   { 0, 0 },
    173  1.1  christos   { "ascii",    '+' }
    174  1.1  christos };
    175  1.1  christos 
    176  1.1  christos struct tui_translate tui_border_kind_translate_urcorner[] = {
    177  1.1  christos   { "space",    ' ' },
    178  1.1  christos   { "ascii",    '+' },
    179  1.1  christos   { "acs",      -1 },
    180  1.1  christos   { 0, 0 },
    181  1.1  christos   { "ascii",    '+' }
    182  1.1  christos };
    183  1.1  christos 
    184  1.1  christos struct tui_translate tui_border_kind_translate_llcorner[] = {
    185  1.1  christos   { "space",    ' ' },
    186  1.1  christos   { "ascii",    '+' },
    187  1.1  christos   { "acs",      -1 },
    188  1.1  christos   { 0, 0 },
    189  1.1  christos   { "ascii",    '+' }
    190  1.1  christos };
    191  1.1  christos 
    192  1.1  christos struct tui_translate tui_border_kind_translate_lrcorner[] = {
    193  1.1  christos   { "space",    ' ' },
    194  1.1  christos   { "ascii",    '+' },
    195  1.1  christos   { "acs",      -1 },
    196  1.1  christos   { 0, 0 },
    197  1.1  christos   { "ascii",    '+' }
    198  1.1  christos };
    199  1.1  christos 
    200  1.1  christos 
    201  1.1  christos /* Tui configuration variables controlled with set/show command.  */
    202  1.1  christos const char *tui_active_border_mode = "bold-standout";
    203  1.1  christos static void
    204  1.1  christos show_tui_active_border_mode (struct ui_file *file,
    205  1.1  christos 			     int from_tty,
    206  1.1  christos 			     struct cmd_list_element *c,
    207  1.1  christos 			     const char *value)
    208  1.1  christos {
    209  1.1  christos   fprintf_filtered (file, _("\
    210  1.1  christos The attribute mode to use for the active TUI window border is \"%s\".\n"),
    211  1.1  christos 		    value);
    212  1.1  christos }
    213  1.1  christos 
    214  1.1  christos const char *tui_border_mode = "normal";
    215  1.1  christos static void
    216  1.1  christos show_tui_border_mode (struct ui_file *file,
    217  1.1  christos 		      int from_tty,
    218  1.1  christos 		      struct cmd_list_element *c,
    219  1.1  christos 		      const char *value)
    220  1.1  christos {
    221  1.1  christos   fprintf_filtered (file, _("\
    222  1.1  christos The attribute mode to use for the TUI window borders is \"%s\".\n"),
    223  1.1  christos 		    value);
    224  1.1  christos }
    225  1.1  christos 
    226  1.1  christos const char *tui_border_kind = "acs";
    227  1.1  christos static void
    228  1.1  christos show_tui_border_kind (struct ui_file *file,
    229  1.1  christos 		      int from_tty,
    230  1.1  christos 		      struct cmd_list_element *c,
    231  1.1  christos 		      const char *value)
    232  1.1  christos {
    233  1.1  christos   fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
    234  1.1  christos 		    value);
    235  1.1  christos }
    236  1.1  christos 
    237  1.1  christos 
    238  1.1  christos /* Tui internal configuration variables.  These variables are updated
    239  1.1  christos    by tui_update_variables to reflect the tui configuration
    240  1.1  christos    variables.  */
    241  1.1  christos chtype tui_border_vline;
    242  1.1  christos chtype tui_border_hline;
    243  1.1  christos chtype tui_border_ulcorner;
    244  1.1  christos chtype tui_border_urcorner;
    245  1.1  christos chtype tui_border_llcorner;
    246  1.1  christos chtype tui_border_lrcorner;
    247  1.1  christos 
    248  1.1  christos int tui_border_attrs;
    249  1.1  christos int tui_active_border_attrs;
    250  1.1  christos 
    251  1.1  christos /* Identify the item in the translation table.
    252  1.1  christos    When the item is not recognized, use the default entry.  */
    253  1.1  christos static struct tui_translate *
    254  1.1  christos translate (const char *name, struct tui_translate *table)
    255  1.1  christos {
    256  1.1  christos   while (table->name)
    257  1.1  christos     {
    258  1.1  christos       if (name && strcmp (table->name, name) == 0)
    259  1.1  christos         return table;
    260  1.1  christos       table++;
    261  1.1  christos     }
    262  1.1  christos 
    263  1.1  christos   /* Not found, return default entry.  */
    264  1.1  christos   table++;
    265  1.1  christos   return table;
    266  1.1  christos }
    267  1.1  christos 
    268  1.1  christos /* Update the tui internal configuration according to gdb settings.
    269  1.1  christos    Returns 1 if the configuration has changed and the screen should
    270  1.1  christos    be redrawn.  */
    271  1.1  christos int
    272  1.1  christos tui_update_variables (void)
    273  1.1  christos {
    274  1.1  christos   int need_redraw = 0;
    275  1.1  christos   struct tui_translate *entry;
    276  1.1  christos 
    277  1.1  christos   entry = translate (tui_border_mode, tui_border_mode_translate);
    278  1.1  christos   if (tui_border_attrs != entry->value)
    279  1.1  christos     {
    280  1.1  christos       tui_border_attrs = entry->value;
    281  1.1  christos       need_redraw = 1;
    282  1.1  christos     }
    283  1.1  christos   entry = translate (tui_active_border_mode, tui_border_mode_translate);
    284  1.1  christos   if (tui_active_border_attrs != entry->value)
    285  1.1  christos     {
    286  1.1  christos       tui_active_border_attrs = entry->value;
    287  1.1  christos       need_redraw = 1;
    288  1.1  christos     }
    289  1.1  christos 
    290  1.1  christos   /* If one corner changes, all characters are changed.
    291  1.1  christos      Only check the first one.  The ACS characters are determined at
    292  1.1  christos      run time by curses terminal management.  */
    293  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
    294  1.1  christos   if (tui_border_lrcorner != (chtype) entry->value)
    295  1.1  christos     {
    296  1.1  christos       tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
    297  1.1  christos       need_redraw = 1;
    298  1.1  christos     }
    299  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
    300  1.1  christos   tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
    301  1.1  christos 
    302  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
    303  1.1  christos   tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
    304  1.1  christos 
    305  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
    306  1.1  christos   tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
    307  1.1  christos 
    308  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_hline);
    309  1.1  christos   tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
    310  1.1  christos 
    311  1.1  christos   entry = translate (tui_border_kind, tui_border_kind_translate_vline);
    312  1.1  christos   tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
    313  1.1  christos 
    314  1.1  christos   return need_redraw;
    315  1.1  christos }
    316  1.1  christos 
    317  1.1  christos static void
    318  1.1  christos set_tui_cmd (char *args, int from_tty)
    319  1.1  christos {
    320  1.1  christos }
    321  1.1  christos 
    322  1.1  christos static void
    323  1.1  christos show_tui_cmd (char *args, int from_tty)
    324  1.1  christos {
    325  1.1  christos }
    326  1.1  christos 
    327  1.1  christos static struct cmd_list_element *tuilist;
    328  1.1  christos 
    329  1.1  christos static void
    330  1.1  christos tui_command (char *args, int from_tty)
    331  1.1  christos {
    332  1.1  christos   printf_unfiltered (_("\"tui\" must be followed by the name of a "
    333  1.1  christos                      "tui command.\n"));
    334  1.3  christos   help_list (tuilist, "tui ", all_commands, gdb_stdout);
    335  1.1  christos }
    336  1.1  christos 
    337  1.1  christos struct cmd_list_element **
    338  1.1  christos tui_get_cmd_list (void)
    339  1.1  christos {
    340  1.1  christos   if (tuilist == 0)
    341  1.1  christos     add_prefix_cmd ("tui", class_tui, tui_command,
    342  1.1  christos                     _("Text User Interface commands."),
    343  1.1  christos                     &tuilist, "tui ", 0, &cmdlist);
    344  1.1  christos   return &tuilist;
    345  1.1  christos }
    346  1.1  christos 
    347  1.3  christos /* The set_func hook of "set tui ..." commands that affect the window
    348  1.3  christos    borders on the TUI display.  */
    349  1.3  christos void
    350  1.3  christos tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c)
    351  1.3  christos {
    352  1.3  christos   if (tui_update_variables () && tui_active)
    353  1.3  christos     tui_rehighlight_all ();
    354  1.3  christos }
    355  1.3  christos 
    356  1.1  christos /* Function to initialize gdb commands, for tui window
    357  1.1  christos    manipulation.  */
    358  1.1  christos 
    359  1.1  christos /* Provide a prototype to silence -Wmissing-prototypes.  */
    360  1.1  christos extern initialize_file_ftype _initialize_tui_win;
    361  1.1  christos 
    362  1.1  christos void
    363  1.1  christos _initialize_tui_win (void)
    364  1.1  christos {
    365  1.1  christos   static struct cmd_list_element *tui_setlist;
    366  1.1  christos   static struct cmd_list_element *tui_showlist;
    367  1.1  christos 
    368  1.1  christos   /* Define the classes of commands.
    369  1.1  christos      They will appear in the help list in the reverse of this order.  */
    370  1.1  christos   add_prefix_cmd ("tui", class_tui, set_tui_cmd,
    371  1.1  christos                   _("TUI configuration variables"),
    372  1.1  christos 		  &tui_setlist, "set tui ",
    373  1.1  christos 		  0 /* allow-unknown */, &setlist);
    374  1.1  christos   add_prefix_cmd ("tui", class_tui, show_tui_cmd,
    375  1.1  christos                   _("TUI configuration variables"),
    376  1.1  christos 		  &tui_showlist, "show tui ",
    377  1.1  christos 		  0 /* allow-unknown */, &showlist);
    378  1.1  christos 
    379  1.1  christos   add_com ("refresh", class_tui, tui_refresh_all_command,
    380  1.1  christos            _("Refresh the terminal display.\n"));
    381  1.1  christos   if (xdb_commands)
    382  1.1  christos     add_com_alias ("U", "refresh", class_tui, 0);
    383  1.1  christos   add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
    384  1.1  christos Set the width (in characters) of tab stops.\n\
    385  1.1  christos Usage: tabset <n>\n"));
    386  1.1  christos   add_com ("winheight", class_tui, tui_set_win_height_command, _("\
    387  1.1  christos Set the height of a specified window.\n\
    388  1.1  christos Usage: winheight <win_name> [+ | -] <#lines>\n\
    389  1.1  christos Window names are:\n\
    390  1.1  christos src  : the source window\n\
    391  1.1  christos cmd  : the command window\n\
    392  1.1  christos asm  : the disassembly window\n\
    393  1.1  christos regs : the register display\n"));
    394  1.1  christos   add_com_alias ("wh", "winheight", class_tui, 0);
    395  1.1  christos   add_info ("win", tui_all_windows_info,
    396  1.1  christos 	    _("List of all displayed windows.\n"));
    397  1.1  christos   add_com ("focus", class_tui, tui_set_focus_command, _("\
    398  1.1  christos Set focus to named window or next/prev window.\n\
    399  1.1  christos Usage: focus {<win> | next | prev}\n\
    400  1.1  christos Valid Window names are:\n\
    401  1.1  christos src  : the source window\n\
    402  1.1  christos asm  : the disassembly window\n\
    403  1.1  christos regs : the register display\n\
    404  1.1  christos cmd  : the command window\n"));
    405  1.1  christos   add_com_alias ("fs", "focus", class_tui, 0);
    406  1.1  christos   add_com ("+", class_tui, tui_scroll_forward_command, _("\
    407  1.1  christos Scroll window forward.\n\
    408  1.1  christos Usage: + [win] [n]\n"));
    409  1.1  christos   add_com ("-", class_tui, tui_scroll_backward_command, _("\
    410  1.1  christos Scroll window backward.\n\
    411  1.1  christos Usage: - [win] [n]\n"));
    412  1.1  christos   add_com ("<", class_tui, tui_scroll_left_command, _("\
    413  1.3  christos Scroll window text to the left.\n\
    414  1.1  christos Usage: < [win] [n]\n"));
    415  1.1  christos   add_com (">", class_tui, tui_scroll_right_command, _("\
    416  1.3  christos Scroll window text to the right.\n\
    417  1.1  christos Usage: > [win] [n]\n"));
    418  1.1  christos   if (xdb_commands)
    419  1.1  christos     add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\
    420  1.1  christos XDB compatibility command for setting the height of a command window.\n\
    421  1.1  christos Usage: w <#lines>\n"));
    422  1.1  christos 
    423  1.1  christos   /* Define the tui control variables.  */
    424  1.1  christos   add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
    425  1.1  christos 			&tui_border_kind, _("\
    426  1.1  christos Set the kind of border for TUI windows."), _("\
    427  1.1  christos Show the kind of border for TUI windows."), _("\
    428  1.1  christos This variable controls the border of TUI windows:\n\
    429  1.1  christos space           use a white space\n\
    430  1.1  christos ascii           use ascii characters + - | for the border\n\
    431  1.1  christos acs             use the Alternate Character Set"),
    432  1.3  christos 			tui_set_var_cmd,
    433  1.1  christos 			show_tui_border_kind,
    434  1.1  christos 			&tui_setlist, &tui_showlist);
    435  1.1  christos 
    436  1.1  christos   add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
    437  1.1  christos 			&tui_border_mode, _("\
    438  1.1  christos Set the attribute mode to use for the TUI window borders."), _("\
    439  1.1  christos Show the attribute mode to use for the TUI window borders."), _("\
    440  1.1  christos This variable controls the attributes to use for the window borders:\n\
    441  1.1  christos normal          normal display\n\
    442  1.1  christos standout        use highlight mode of terminal\n\
    443  1.1  christos reverse         use reverse video mode\n\
    444  1.1  christos half            use half bright\n\
    445  1.1  christos half-standout   use half bright and standout mode\n\
    446  1.1  christos bold            use extra bright or bold\n\
    447  1.1  christos bold-standout   use extra bright or bold with standout mode"),
    448  1.3  christos 			tui_set_var_cmd,
    449  1.1  christos 			show_tui_border_mode,
    450  1.1  christos 			&tui_setlist, &tui_showlist);
    451  1.1  christos 
    452  1.1  christos   add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
    453  1.1  christos 			&tui_active_border_mode, _("\
    454  1.1  christos Set the attribute mode to use for the active TUI window border."), _("\
    455  1.1  christos Show the attribute mode to use for the active TUI window border."), _("\
    456  1.1  christos This variable controls the attributes to use for the active window border:\n\
    457  1.1  christos normal          normal display\n\
    458  1.1  christos standout        use highlight mode of terminal\n\
    459  1.1  christos reverse         use reverse video mode\n\
    460  1.1  christos half            use half bright\n\
    461  1.1  christos half-standout   use half bright and standout mode\n\
    462  1.1  christos bold            use extra bright or bold\n\
    463  1.1  christos bold-standout   use extra bright or bold with standout mode"),
    464  1.3  christos 			tui_set_var_cmd,
    465  1.1  christos 			show_tui_active_border_mode,
    466  1.1  christos 			&tui_setlist, &tui_showlist);
    467  1.1  christos }
    468  1.1  christos 
    469  1.1  christos /* Update gdb's knowledge of the terminal size.  */
    470  1.1  christos void
    471  1.1  christos tui_update_gdb_sizes (void)
    472  1.1  christos {
    473  1.1  christos   char cmd[50];
    474  1.1  christos 
    475  1.1  christos   /* Set to TUI command window dimension or use readline values.  */
    476  1.1  christos   xsnprintf (cmd, sizeof (cmd), "set width %d",
    477  1.1  christos            tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
    478  1.1  christos   execute_command (cmd, 0);
    479  1.1  christos   xsnprintf (cmd, sizeof (cmd), "set height %d",
    480  1.1  christos            tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
    481  1.1  christos   execute_command (cmd, 0);
    482  1.1  christos }
    483  1.1  christos 
    484  1.1  christos 
    485  1.1  christos /* Set the logical focus to win_info.  */
    486  1.1  christos void
    487  1.1  christos tui_set_win_focus_to (struct tui_win_info *win_info)
    488  1.1  christos {
    489  1.1  christos   if (win_info != NULL)
    490  1.1  christos     {
    491  1.1  christos       struct tui_win_info *win_with_focus = tui_win_with_focus ();
    492  1.1  christos 
    493  1.1  christos       if (win_with_focus != NULL
    494  1.1  christos 	  && win_with_focus->generic.type != CMD_WIN)
    495  1.1  christos 	tui_unhighlight_win (win_with_focus);
    496  1.1  christos       tui_set_win_with_focus (win_info);
    497  1.1  christos       if (win_info->generic.type != CMD_WIN)
    498  1.1  christos 	tui_highlight_win (win_info);
    499  1.1  christos     }
    500  1.1  christos }
    501  1.1  christos 
    502  1.1  christos 
    503  1.1  christos void
    504  1.1  christos tui_scroll_forward (struct tui_win_info *win_to_scroll,
    505  1.1  christos 		    int num_to_scroll)
    506  1.1  christos {
    507  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    508  1.1  christos     {
    509  1.1  christos       int _num_to_scroll = num_to_scroll;
    510  1.1  christos 
    511  1.1  christos       if (num_to_scroll == 0)
    512  1.1  christos 	_num_to_scroll = win_to_scroll->generic.height - 3;
    513  1.1  christos 
    514  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    515  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    516  1.1  christos          only what is in the viewport.  If win_to_scroll is the
    517  1.1  christos          command window do nothing since the term should handle
    518  1.1  christos          it.  */
    519  1.1  christos       if (win_to_scroll == TUI_SRC_WIN)
    520  1.1  christos 	tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
    521  1.1  christos       else if (win_to_scroll == TUI_DISASM_WIN)
    522  1.1  christos 	tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
    523  1.1  christos       else if (win_to_scroll == TUI_DATA_WIN)
    524  1.1  christos 	tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
    525  1.1  christos     }
    526  1.1  christos }
    527  1.1  christos 
    528  1.1  christos void
    529  1.1  christos tui_scroll_backward (struct tui_win_info *win_to_scroll,
    530  1.1  christos 		     int num_to_scroll)
    531  1.1  christos {
    532  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    533  1.1  christos     {
    534  1.1  christos       int _num_to_scroll = num_to_scroll;
    535  1.1  christos 
    536  1.1  christos       if (num_to_scroll == 0)
    537  1.1  christos 	_num_to_scroll = win_to_scroll->generic.height - 3;
    538  1.1  christos 
    539  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    540  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    541  1.1  christos          only what is in the viewport.  If win_to_scroll is the
    542  1.1  christos          command window do nothing since the term should handle
    543  1.1  christos          it.  */
    544  1.1  christos       if (win_to_scroll == TUI_SRC_WIN)
    545  1.1  christos 	tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
    546  1.1  christos       else if (win_to_scroll == TUI_DISASM_WIN)
    547  1.1  christos 	tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
    548  1.1  christos       else if (win_to_scroll == TUI_DATA_WIN)
    549  1.1  christos 	tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
    550  1.1  christos     }
    551  1.1  christos }
    552  1.1  christos 
    553  1.1  christos 
    554  1.1  christos void
    555  1.1  christos tui_scroll_left (struct tui_win_info *win_to_scroll,
    556  1.1  christos 		 int num_to_scroll)
    557  1.1  christos {
    558  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    559  1.1  christos     {
    560  1.1  christos       int _num_to_scroll = num_to_scroll;
    561  1.1  christos 
    562  1.1  christos       if (_num_to_scroll == 0)
    563  1.1  christos 	_num_to_scroll = 1;
    564  1.1  christos 
    565  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    566  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    567  1.1  christos          only what is in the viewport. If win_to_scroll is the command
    568  1.1  christos          window do nothing since the term should handle it.  */
    569  1.1  christos       if (win_to_scroll == TUI_SRC_WIN
    570  1.1  christos 	  || win_to_scroll == TUI_DISASM_WIN)
    571  1.1  christos 	tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL,
    572  1.1  christos 				      _num_to_scroll);
    573  1.1  christos     }
    574  1.1  christos }
    575  1.1  christos 
    576  1.1  christos 
    577  1.1  christos void
    578  1.1  christos tui_scroll_right (struct tui_win_info *win_to_scroll,
    579  1.1  christos 		  int num_to_scroll)
    580  1.1  christos {
    581  1.1  christos   if (win_to_scroll != TUI_CMD_WIN)
    582  1.1  christos     {
    583  1.1  christos       int _num_to_scroll = num_to_scroll;
    584  1.1  christos 
    585  1.1  christos       if (_num_to_scroll == 0)
    586  1.1  christos 	_num_to_scroll = 1;
    587  1.1  christos 
    588  1.1  christos       /* If we are scrolling the source or disassembly window, do a
    589  1.1  christos          "psuedo" scroll since not all of the source is in memory,
    590  1.1  christos          only what is in the viewport. If win_to_scroll is the command
    591  1.1  christos          window do nothing since the term should handle it.  */
    592  1.1  christos       if (win_to_scroll == TUI_SRC_WIN
    593  1.1  christos 	  || win_to_scroll == TUI_DISASM_WIN)
    594  1.1  christos 	tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL,
    595  1.1  christos 				      _num_to_scroll);
    596  1.1  christos     }
    597  1.1  christos }
    598  1.1  christos 
    599  1.1  christos 
    600  1.1  christos /* Scroll a window.  Arguments are passed through a va_list.  */
    601  1.1  christos void
    602  1.1  christos tui_scroll (enum tui_scroll_direction direction,
    603  1.1  christos 	    struct tui_win_info *win_to_scroll,
    604  1.1  christos 	    int num_to_scroll)
    605  1.1  christos {
    606  1.1  christos   switch (direction)
    607  1.1  christos     {
    608  1.1  christos     case FORWARD_SCROLL:
    609  1.1  christos       tui_scroll_forward (win_to_scroll, num_to_scroll);
    610  1.1  christos       break;
    611  1.1  christos     case BACKWARD_SCROLL:
    612  1.1  christos       tui_scroll_backward (win_to_scroll, num_to_scroll);
    613  1.1  christos       break;
    614  1.1  christos     case LEFT_SCROLL:
    615  1.1  christos       tui_scroll_left (win_to_scroll, num_to_scroll);
    616  1.1  christos       break;
    617  1.1  christos     case RIGHT_SCROLL:
    618  1.1  christos       tui_scroll_right (win_to_scroll, num_to_scroll);
    619  1.1  christos       break;
    620  1.1  christos     default:
    621  1.1  christos       break;
    622  1.1  christos     }
    623  1.1  christos }
    624  1.1  christos 
    625  1.1  christos 
    626  1.1  christos void
    627  1.1  christos tui_refresh_all_win (void)
    628  1.1  christos {
    629  1.1  christos   enum tui_win_type type;
    630  1.1  christos 
    631  1.1  christos   clearok (curscr, TRUE);
    632  1.1  christos   tui_refresh_all (tui_win_list);
    633  1.1  christos   for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
    634  1.1  christos     {
    635  1.1  christos       if (tui_win_list[type]
    636  1.1  christos 	  && tui_win_list[type]->generic.is_visible)
    637  1.1  christos 	{
    638  1.1  christos 	  switch (type)
    639  1.1  christos 	    {
    640  1.1  christos 	    case SRC_WIN:
    641  1.1  christos 	    case DISASSEM_WIN:
    642  1.1  christos 	      tui_show_source_content (tui_win_list[type]);
    643  1.1  christos 	      tui_check_and_display_highlight_if_needed (tui_win_list[type]);
    644  1.1  christos 	      tui_erase_exec_info_content (tui_win_list[type]);
    645  1.1  christos 	      tui_update_exec_info (tui_win_list[type]);
    646  1.1  christos 	      break;
    647  1.1  christos 	    case DATA_WIN:
    648  1.1  christos 	      tui_refresh_data_win ();
    649  1.1  christos 	      break;
    650  1.1  christos 	    default:
    651  1.1  christos 	      break;
    652  1.1  christos 	    }
    653  1.1  christos 	}
    654  1.1  christos     }
    655  1.1  christos   tui_show_locator_content ();
    656  1.1  christos }
    657  1.1  christos 
    658  1.3  christos void
    659  1.3  christos tui_rehighlight_all (void)
    660  1.3  christos {
    661  1.3  christos   enum tui_win_type type;
    662  1.3  christos 
    663  1.3  christos   for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
    664  1.3  christos     tui_check_and_display_highlight_if_needed (tui_win_list[type]);
    665  1.3  christos }
    666  1.1  christos 
    667  1.1  christos /* Resize all the windows based on the terminal size.  This function
    668  1.1  christos    gets called from within the readline sinwinch handler.  */
    669  1.1  christos void
    670  1.1  christos tui_resize_all (void)
    671  1.1  christos {
    672  1.1  christos   int height_diff, width_diff;
    673  1.1  christos   int screenheight, screenwidth;
    674  1.1  christos 
    675  1.1  christos   rl_get_screen_size (&screenheight, &screenwidth);
    676  1.1  christos   width_diff = screenwidth - tui_term_width ();
    677  1.1  christos   height_diff = screenheight - tui_term_height ();
    678  1.1  christos   if (height_diff || width_diff)
    679  1.1  christos     {
    680  1.1  christos       enum tui_layout_type cur_layout = tui_current_layout ();
    681  1.1  christos       struct tui_win_info *win_with_focus = tui_win_with_focus ();
    682  1.1  christos       struct tui_win_info *first_win;
    683  1.1  christos       struct tui_win_info *second_win;
    684  1.1  christos       struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
    685  1.1  christos       enum tui_win_type win_type;
    686  1.1  christos       int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
    687  1.1  christos 
    688  1.1  christos #ifdef HAVE_RESIZE_TERM
    689  1.1  christos       resize_term (screenheight, screenwidth);
    690  1.1  christos #endif
    691  1.1  christos       /* Turn keypad off while we resize.  */
    692  1.1  christos       if (win_with_focus != TUI_CMD_WIN)
    693  1.1  christos 	keypad (TUI_CMD_WIN->generic.handle, FALSE);
    694  1.1  christos       tui_update_gdb_sizes ();
    695  1.1  christos       tui_set_term_height_to (screenheight);
    696  1.1  christos       tui_set_term_width_to (screenwidth);
    697  1.1  christos       if (cur_layout == SRC_DISASSEM_COMMAND
    698  1.1  christos 	  || cur_layout == SRC_DATA_COMMAND
    699  1.1  christos 	  || cur_layout == DISASSEM_DATA_COMMAND)
    700  1.1  christos 	num_wins_displayed++;
    701  1.1  christos       split_diff = height_diff / num_wins_displayed;
    702  1.1  christos       cmd_split_diff = split_diff;
    703  1.1  christos       if (height_diff % num_wins_displayed)
    704  1.1  christos 	{
    705  1.1  christos 	  if (height_diff < 0)
    706  1.1  christos 	    cmd_split_diff--;
    707  1.1  christos 	  else
    708  1.1  christos            cmd_split_diff++;
    709  1.1  christos        }
    710  1.1  christos       /* Now adjust each window.  */
    711  1.1  christos       /* erase + clearok are used instead of a straightforward clear as
    712  1.1  christos          AIX 5.3 does not define clear.  */
    713  1.1  christos       erase ();
    714  1.1  christos       clearok (curscr, TRUE);
    715  1.1  christos       refresh ();
    716  1.1  christos       switch (cur_layout)
    717  1.1  christos        {
    718  1.1  christos 	case SRC_COMMAND:
    719  1.1  christos 	case DISASSEM_COMMAND:
    720  1.1  christos 	  first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
    721  1.1  christos 	  first_win->generic.width += width_diff;
    722  1.1  christos 	  locator->width += width_diff;
    723  1.1  christos 	  /* Check for invalid heights.  */
    724  1.1  christos 	  if (height_diff == 0)
    725  1.1  christos 	    new_height = first_win->generic.height;
    726  1.1  christos 	  else if ((first_win->generic.height + split_diff) >=
    727  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    728  1.1  christos 	    new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
    729  1.1  christos 	  else if ((first_win->generic.height + split_diff) <= 0)
    730  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    731  1.1  christos 	  else
    732  1.1  christos 	    new_height = first_win->generic.height + split_diff;
    733  1.1  christos 
    734  1.1  christos 	  locator->origin.y = new_height + 1;
    735  1.1  christos 	  make_invisible_and_set_new_height (first_win, new_height);
    736  1.1  christos 	  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
    737  1.1  christos 	  TUI_CMD_WIN->generic.width += width_diff;
    738  1.1  christos 	  new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
    739  1.1  christos 	  make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
    740  1.1  christos 	  make_visible_with_new_height (first_win);
    741  1.1  christos 	  make_visible_with_new_height (TUI_CMD_WIN);
    742  1.1  christos 	  if (first_win->generic.content_size <= 0)
    743  1.1  christos 	    tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
    744  1.1  christos 	  break;
    745  1.1  christos 	default:
    746  1.1  christos 	  if (cur_layout == SRC_DISASSEM_COMMAND)
    747  1.1  christos 	    {
    748  1.1  christos 	      first_win = TUI_SRC_WIN;
    749  1.1  christos 	      first_win->generic.width += width_diff;
    750  1.1  christos 	      second_win = TUI_DISASM_WIN;
    751  1.1  christos 	      second_win->generic.width += width_diff;
    752  1.1  christos 	    }
    753  1.1  christos 	  else
    754  1.1  christos 	    {
    755  1.1  christos 	      first_win = TUI_DATA_WIN;
    756  1.1  christos 	      first_win->generic.width += width_diff;
    757  1.1  christos 	      second_win = (struct tui_win_info *)
    758  1.1  christos 		(tui_source_windows ())->list[0];
    759  1.1  christos 	      second_win->generic.width += width_diff;
    760  1.1  christos 	    }
    761  1.1  christos 	  /* Change the first window's height/width.  */
    762  1.1  christos 	  /* Check for invalid heights.  */
    763  1.1  christos 	  if (height_diff == 0)
    764  1.1  christos 	    new_height = first_win->generic.height;
    765  1.1  christos 	  else if ((first_win->generic.height +
    766  1.1  christos 		    second_win->generic.height + (split_diff * 2)) >=
    767  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    768  1.1  christos 	    new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
    769  1.1  christos 	  else if ((first_win->generic.height + split_diff) <= 0)
    770  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    771  1.1  christos 	  else
    772  1.1  christos 	    new_height = first_win->generic.height + split_diff;
    773  1.1  christos 	  make_invisible_and_set_new_height (first_win, new_height);
    774  1.1  christos 
    775  1.1  christos 	  locator->width += width_diff;
    776  1.1  christos 
    777  1.1  christos 	  /* Change the second window's height/width.  */
    778  1.1  christos 	  /* Check for invalid heights.  */
    779  1.1  christos 	  if (height_diff == 0)
    780  1.1  christos 	    new_height = second_win->generic.height;
    781  1.1  christos 	  else if ((first_win->generic.height +
    782  1.1  christos 		    second_win->generic.height + (split_diff * 2)) >=
    783  1.1  christos 		   (screenheight - MIN_CMD_WIN_HEIGHT - 1))
    784  1.1  christos 	    {
    785  1.1  christos 	      new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
    786  1.1  christos 	      if (new_height % 2)
    787  1.1  christos 		new_height = (new_height / 2) + 1;
    788  1.1  christos 	      else
    789  1.1  christos 		new_height /= 2;
    790  1.1  christos 	    }
    791  1.1  christos 	  else if ((second_win->generic.height + split_diff) <= 0)
    792  1.1  christos 	    new_height = MIN_WIN_HEIGHT;
    793  1.1  christos 	  else
    794  1.1  christos 	    new_height = second_win->generic.height + split_diff;
    795  1.1  christos 	  second_win->generic.origin.y = first_win->generic.height - 1;
    796  1.1  christos 	  make_invisible_and_set_new_height (second_win, new_height);
    797  1.1  christos 
    798  1.1  christos 	  /* Change the command window's height/width.  */
    799  1.1  christos 	  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
    800  1.1  christos 	  make_invisible_and_set_new_height (TUI_CMD_WIN,
    801  1.1  christos 					     TUI_CMD_WIN->generic.height
    802  1.1  christos 					     + cmd_split_diff);
    803  1.1  christos 	  make_visible_with_new_height (first_win);
    804  1.1  christos 	  make_visible_with_new_height (second_win);
    805  1.1  christos 	  make_visible_with_new_height (TUI_CMD_WIN);
    806  1.1  christos 	  if (first_win->generic.content_size <= 0)
    807  1.1  christos 	    tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
    808  1.1  christos 	  if (second_win->generic.content_size <= 0)
    809  1.1  christos 	    tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
    810  1.1  christos 	  break;
    811  1.1  christos 	}
    812  1.1  christos       /* Now remove all invisible windows, and their content so that
    813  1.1  christos          they get created again when called for with the new size.  */
    814  1.1  christos       for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
    815  1.1  christos 	{
    816  1.1  christos 	  if (win_type != CMD_WIN
    817  1.1  christos 	      && (tui_win_list[win_type] != NULL)
    818  1.1  christos 	      && !tui_win_list[win_type]->generic.is_visible)
    819  1.1  christos 	    {
    820  1.1  christos 	      tui_free_window (tui_win_list[win_type]);
    821  1.1  christos 	      tui_win_list[win_type] = (struct tui_win_info *) NULL;
    822  1.1  christos 	    }
    823  1.1  christos 	}
    824  1.1  christos       /* Turn keypad back on, unless focus is in the command
    825  1.1  christos 	 window.  */
    826  1.1  christos       if (win_with_focus != TUI_CMD_WIN)
    827  1.1  christos 	keypad (TUI_CMD_WIN->generic.handle, TRUE);
    828  1.1  christos     }
    829  1.1  christos }
    830  1.1  christos 
    831  1.1  christos #ifdef SIGWINCH
    832  1.1  christos /* SIGWINCH signal handler for the tui.  This signal handler is always
    833  1.1  christos    called, even when the readline package clears signals because it is
    834  1.1  christos    set as the old_sigwinch() (TUI only).  */
    835  1.1  christos static void
    836  1.1  christos tui_sigwinch_handler (int signal)
    837  1.1  christos {
    838  1.1  christos   /* Say that a resize was done so that the readline can do it later
    839  1.1  christos      when appropriate.  */
    840  1.1  christos   tui_set_win_resized_to (TRUE);
    841  1.1  christos }
    842  1.1  christos #endif
    843  1.1  christos 
    844  1.1  christos /* Initializes SIGWINCH signal handler for the tui.  */
    845  1.1  christos void
    846  1.1  christos tui_initialize_win (void)
    847  1.1  christos {
    848  1.1  christos #ifdef SIGWINCH
    849  1.1  christos #ifdef HAVE_SIGACTION
    850  1.1  christos   struct sigaction old_winch;
    851  1.1  christos 
    852  1.1  christos   memset (&old_winch, 0, sizeof (old_winch));
    853  1.1  christos   old_winch.sa_handler = &tui_sigwinch_handler;
    854  1.3  christos #ifdef SA_RESTART
    855  1.3  christos   old_winch.sa_flags = SA_RESTART;
    856  1.3  christos #endif
    857  1.1  christos   sigaction (SIGWINCH, &old_winch, NULL);
    858  1.1  christos #else
    859  1.1  christos   signal (SIGWINCH, &tui_sigwinch_handler);
    860  1.1  christos #endif
    861  1.1  christos #endif
    862  1.1  christos }
    863  1.1  christos 
    864  1.1  christos 
    865  1.1  christos /*************************
    866  1.1  christos ** STATIC LOCAL FUNCTIONS
    867  1.1  christos **************************/
    868  1.1  christos 
    869  1.1  christos 
    870  1.1  christos static void
    871  1.1  christos tui_scroll_forward_command (char *arg, int from_tty)
    872  1.1  christos {
    873  1.1  christos   int num_to_scroll = 1;
    874  1.1  christos   struct tui_win_info *win_to_scroll;
    875  1.1  christos 
    876  1.1  christos   /* Make sure the curses mode is enabled.  */
    877  1.1  christos   tui_enable ();
    878  1.1  christos   if (arg == (char *) NULL)
    879  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
    880  1.1  christos   else
    881  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    882  1.1  christos   tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
    883  1.1  christos }
    884  1.1  christos 
    885  1.1  christos 
    886  1.1  christos static void
    887  1.1  christos tui_scroll_backward_command (char *arg, int from_tty)
    888  1.1  christos {
    889  1.1  christos   int num_to_scroll = 1;
    890  1.1  christos   struct tui_win_info *win_to_scroll;
    891  1.1  christos 
    892  1.1  christos   /* Make sure the curses mode is enabled.  */
    893  1.1  christos   tui_enable ();
    894  1.1  christos   if (arg == (char *) NULL)
    895  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
    896  1.1  christos   else
    897  1.1  christos     parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    898  1.1  christos   tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
    899  1.1  christos }
    900  1.1  christos 
    901  1.1  christos 
    902  1.1  christos static void
    903  1.1  christos tui_scroll_left_command (char *arg, int from_tty)
    904  1.1  christos {
    905  1.1  christos   int num_to_scroll;
    906  1.1  christos   struct tui_win_info *win_to_scroll;
    907  1.1  christos 
    908  1.1  christos   /* Make sure the curses mode is enabled.  */
    909  1.1  christos   tui_enable ();
    910  1.1  christos   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    911  1.1  christos   tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
    912  1.1  christos }
    913  1.1  christos 
    914  1.1  christos 
    915  1.1  christos static void
    916  1.1  christos tui_scroll_right_command (char *arg, int from_tty)
    917  1.1  christos {
    918  1.1  christos   int num_to_scroll;
    919  1.1  christos   struct tui_win_info *win_to_scroll;
    920  1.1  christos 
    921  1.1  christos   /* Make sure the curses mode is enabled.  */
    922  1.1  christos   tui_enable ();
    923  1.1  christos   parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
    924  1.1  christos   tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
    925  1.1  christos }
    926  1.1  christos 
    927  1.1  christos 
    928  1.1  christos /* Set focus to the window named by 'arg'.  */
    929  1.1  christos static void
    930  1.1  christos tui_set_focus (char *arg, int from_tty)
    931  1.1  christos {
    932  1.1  christos   if (arg != (char *) NULL)
    933  1.1  christos     {
    934  1.1  christos       char *buf_ptr = (char *) xstrdup (arg);
    935  1.1  christos       int i;
    936  1.1  christos       struct tui_win_info *win_info = (struct tui_win_info *) NULL;
    937  1.1  christos 
    938  1.1  christos       for (i = 0; (i < strlen (buf_ptr)); i++)
    939  1.1  christos 	buf_ptr[i] = toupper (arg[i]);
    940  1.1  christos 
    941  1.1  christos       if (subset_compare (buf_ptr, "NEXT"))
    942  1.1  christos 	win_info = tui_next_win (tui_win_with_focus ());
    943  1.1  christos       else if (subset_compare (buf_ptr, "PREV"))
    944  1.1  christos 	win_info = tui_prev_win (tui_win_with_focus ());
    945  1.1  christos       else
    946  1.1  christos 	win_info = tui_partial_win_by_name (buf_ptr);
    947  1.1  christos 
    948  1.1  christos       if (win_info == (struct tui_win_info *) NULL
    949  1.1  christos 	  || !win_info->generic.is_visible)
    950  1.1  christos 	warning (_("Invalid window specified. \n\
    951  1.1  christos The window name specified must be valid and visible.\n"));
    952  1.1  christos       else
    953  1.1  christos 	{
    954  1.1  christos 	  tui_set_win_focus_to (win_info);
    955  1.1  christos 	  keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
    956  1.1  christos 	}
    957  1.1  christos 
    958  1.1  christos       if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
    959  1.1  christos 	tui_refresh_data_win ();
    960  1.1  christos       xfree (buf_ptr);
    961  1.1  christos       printf_filtered (_("Focus set to %s window.\n"),
    962  1.1  christos 		       tui_win_name ((struct tui_gen_win_info *)
    963  1.1  christos 				     tui_win_with_focus ()));
    964  1.1  christos     }
    965  1.1  christos   else
    966  1.1  christos     warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
    967  1.1  christos }
    968  1.1  christos 
    969  1.1  christos static void
    970  1.1  christos tui_set_focus_command (char *arg, int from_tty)
    971  1.1  christos {
    972  1.1  christos   /* Make sure the curses mode is enabled.  */
    973  1.1  christos   tui_enable ();
    974  1.1  christos   tui_set_focus (arg, from_tty);
    975  1.1  christos }
    976  1.1  christos 
    977  1.1  christos 
    978  1.1  christos static void
    979  1.1  christos tui_all_windows_info (char *arg, int from_tty)
    980  1.1  christos {
    981  1.1  christos   enum tui_win_type type;
    982  1.1  christos   struct tui_win_info *win_with_focus = tui_win_with_focus ();
    983  1.1  christos 
    984  1.1  christos   for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
    985  1.1  christos     if (tui_win_list[type]
    986  1.1  christos 	&& tui_win_list[type]->generic.is_visible)
    987  1.1  christos       {
    988  1.1  christos 	if (win_with_focus == tui_win_list[type])
    989  1.1  christos 	  printf_filtered ("        %s\t(%d lines)  <has focus>\n",
    990  1.1  christos 			   tui_win_name (&tui_win_list[type]->generic),
    991  1.1  christos 			   tui_win_list[type]->generic.height);
    992  1.1  christos 	else
    993  1.1  christos 	  printf_filtered ("        %s\t(%d lines)\n",
    994  1.1  christos 			   tui_win_name (&tui_win_list[type]->generic),
    995  1.1  christos 			   tui_win_list[type]->generic.height);
    996  1.1  christos       }
    997  1.1  christos }
    998  1.1  christos 
    999  1.1  christos 
   1000  1.1  christos static void
   1001  1.1  christos tui_refresh_all_command (char *arg, int from_tty)
   1002  1.1  christos {
   1003  1.1  christos   /* Make sure the curses mode is enabled.  */
   1004  1.1  christos   tui_enable ();
   1005  1.1  christos 
   1006  1.1  christos   tui_refresh_all_win ();
   1007  1.1  christos }
   1008  1.1  christos 
   1009  1.1  christos 
   1010  1.1  christos /* Set the height of the specified window.  */
   1011  1.1  christos static void
   1012  1.1  christos tui_set_tab_width_command (char *arg, int from_tty)
   1013  1.1  christos {
   1014  1.1  christos   /* Make sure the curses mode is enabled.  */
   1015  1.1  christos   tui_enable ();
   1016  1.1  christos   if (arg != (char *) NULL)
   1017  1.1  christos     {
   1018  1.1  christos       int ts;
   1019  1.1  christos 
   1020  1.1  christos       ts = atoi (arg);
   1021  1.1  christos       if (ts > 0)
   1022  1.3  christos 	{
   1023  1.3  christos 	  tui_set_default_tab_len (ts);
   1024  1.3  christos 	  /* We don't really change the height of any windows, but
   1025  1.3  christos 	     calling these 2 functions causes a complete regeneration
   1026  1.3  christos 	     and redisplay of the window's contents, which will take
   1027  1.3  christos 	     the new tab width into account.  */
   1028  1.3  christos 	  if (tui_win_list[SRC_WIN]
   1029  1.3  christos 	      && tui_win_list[SRC_WIN]->generic.is_visible)
   1030  1.3  christos 	    {
   1031  1.3  christos 	      make_invisible_and_set_new_height (TUI_SRC_WIN,
   1032  1.3  christos 						 TUI_SRC_WIN->generic.height);
   1033  1.3  christos 	      make_visible_with_new_height (TUI_SRC_WIN);
   1034  1.3  christos 	    }
   1035  1.3  christos 	  if (tui_win_list[DISASSEM_WIN]
   1036  1.3  christos 	      && tui_win_list[DISASSEM_WIN]->generic.is_visible)
   1037  1.3  christos 	    {
   1038  1.3  christos 	      make_invisible_and_set_new_height (TUI_DISASM_WIN,
   1039  1.3  christos 						 TUI_DISASM_WIN->generic.height);
   1040  1.3  christos 	      make_visible_with_new_height (TUI_DISASM_WIN);
   1041  1.3  christos 	    }
   1042  1.3  christos 	}
   1043  1.1  christos       else
   1044  1.1  christos 	warning (_("Tab widths greater than 0 must be specified."));
   1045  1.1  christos     }
   1046  1.1  christos }
   1047  1.1  christos 
   1048  1.1  christos 
   1049  1.1  christos /* Set the height of the specified window.  */
   1050  1.1  christos static void
   1051  1.1  christos tui_set_win_height (char *arg, int from_tty)
   1052  1.1  christos {
   1053  1.1  christos   /* Make sure the curses mode is enabled.  */
   1054  1.1  christos   tui_enable ();
   1055  1.1  christos   if (arg != (char *) NULL)
   1056  1.1  christos     {
   1057  1.1  christos       char *buf = xstrdup (arg);
   1058  1.1  christos       char *buf_ptr = buf;
   1059  1.1  christos       char *wname = (char *) NULL;
   1060  1.1  christos       int new_height, i;
   1061  1.1  christos       struct tui_win_info *win_info;
   1062  1.1  christos 
   1063  1.1  christos       wname = buf_ptr;
   1064  1.1  christos       buf_ptr = strchr (buf_ptr, ' ');
   1065  1.1  christos       if (buf_ptr != (char *) NULL)
   1066  1.1  christos 	{
   1067  1.1  christos 	  *buf_ptr = (char) 0;
   1068  1.1  christos 
   1069  1.1  christos 	  /* Validate the window name.  */
   1070  1.1  christos 	  for (i = 0; i < strlen (wname); i++)
   1071  1.1  christos 	    wname[i] = toupper (wname[i]);
   1072  1.1  christos 	  win_info = tui_partial_win_by_name (wname);
   1073  1.1  christos 
   1074  1.1  christos 	  if (win_info == (struct tui_win_info *) NULL
   1075  1.1  christos 	      || !win_info->generic.is_visible)
   1076  1.1  christos 	    warning (_("Invalid window specified. \n\
   1077  1.1  christos The window name specified must be valid and visible.\n"));
   1078  1.1  christos 	  else
   1079  1.1  christos 	    {
   1080  1.1  christos 	      /* Process the size.  */
   1081  1.1  christos 	      while (*(++buf_ptr) == ' ')
   1082  1.1  christos 		;
   1083  1.1  christos 
   1084  1.1  christos 	      if (*buf_ptr != (char) 0)
   1085  1.1  christos 		{
   1086  1.1  christos 		  int negate = FALSE;
   1087  1.1  christos 		  int fixed_size = TRUE;
   1088  1.1  christos 		  int input_no;;
   1089  1.1  christos 
   1090  1.1  christos 		  if (*buf_ptr == '+' || *buf_ptr == '-')
   1091  1.1  christos 		    {
   1092  1.1  christos 		      if (*buf_ptr == '-')
   1093  1.1  christos 			negate = TRUE;
   1094  1.1  christos 		      fixed_size = FALSE;
   1095  1.1  christos 		      buf_ptr++;
   1096  1.1  christos 		    }
   1097  1.1  christos 		  input_no = atoi (buf_ptr);
   1098  1.1  christos 		  if (input_no > 0)
   1099  1.1  christos 		    {
   1100  1.1  christos 		      if (negate)
   1101  1.1  christos 			input_no *= (-1);
   1102  1.1  christos 		      if (fixed_size)
   1103  1.1  christos 			new_height = input_no;
   1104  1.1  christos 		      else
   1105  1.1  christos 			new_height = win_info->generic.height + input_no;
   1106  1.1  christos 
   1107  1.1  christos 		      /* Now change the window's height, and adjust
   1108  1.1  christos 		         all other windows around it.  */
   1109  1.1  christos 		      if (tui_adjust_win_heights (win_info,
   1110  1.1  christos 						new_height) == TUI_FAILURE)
   1111  1.1  christos 			warning (_("Invalid window height specified.\n%s"),
   1112  1.1  christos 				 WIN_HEIGHT_USAGE);
   1113  1.1  christos 		      else
   1114  1.1  christos                         tui_update_gdb_sizes ();
   1115  1.1  christos 		    }
   1116  1.1  christos 		  else
   1117  1.1  christos 		    warning (_("Invalid window height specified.\n%s"),
   1118  1.1  christos 			     WIN_HEIGHT_USAGE);
   1119  1.1  christos 		}
   1120  1.1  christos 	    }
   1121  1.1  christos 	}
   1122  1.1  christos       else
   1123  1.1  christos 	printf_filtered (WIN_HEIGHT_USAGE);
   1124  1.1  christos 
   1125  1.1  christos       if (buf != (char *) NULL)
   1126  1.1  christos 	xfree (buf);
   1127  1.1  christos     }
   1128  1.1  christos   else
   1129  1.1  christos     printf_filtered (WIN_HEIGHT_USAGE);
   1130  1.1  christos }
   1131  1.1  christos 
   1132  1.1  christos /* Set the height of the specified window, with va_list.  */
   1133  1.1  christos static void
   1134  1.1  christos tui_set_win_height_command (char *arg, int from_tty)
   1135  1.1  christos {
   1136  1.1  christos   /* Make sure the curses mode is enabled.  */
   1137  1.1  christos   tui_enable ();
   1138  1.1  christos   tui_set_win_height (arg, from_tty);
   1139  1.1  christos }
   1140  1.1  christos 
   1141  1.1  christos 
   1142  1.1  christos /* XDB Compatibility command for setting the window height.  This will
   1143  1.1  christos    increase or decrease the command window by the specified
   1144  1.1  christos    amount.  */
   1145  1.1  christos static void
   1146  1.1  christos tui_xdb_set_win_height (char *arg, int from_tty)
   1147  1.1  christos {
   1148  1.1  christos   /* Make sure the curses mode is enabled.  */
   1149  1.1  christos   tui_enable ();
   1150  1.1  christos   if (arg != (char *) NULL)
   1151  1.1  christos     {
   1152  1.1  christos       int input_no = atoi (arg);
   1153  1.1  christos 
   1154  1.1  christos       if (input_no > 0)
   1155  1.1  christos 	{			/* Add 1 for the locator.  */
   1156  1.1  christos 	  int new_height = tui_term_height () - (input_no + 1);
   1157  1.1  christos 
   1158  1.1  christos 	  if (!new_height_ok (tui_win_list[CMD_WIN], new_height)
   1159  1.1  christos 	      || tui_adjust_win_heights (tui_win_list[CMD_WIN],
   1160  1.1  christos 					 new_height) == TUI_FAILURE)
   1161  1.1  christos 	    warning (_("Invalid window height specified.\n%s"),
   1162  1.1  christos 		     XDBWIN_HEIGHT_USAGE);
   1163  1.1  christos 	}
   1164  1.1  christos       else
   1165  1.1  christos 	warning (_("Invalid window height specified.\n%s"),
   1166  1.1  christos 		 XDBWIN_HEIGHT_USAGE);
   1167  1.1  christos     }
   1168  1.1  christos   else
   1169  1.1  christos     warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
   1170  1.1  christos }
   1171  1.1  christos 
   1172  1.1  christos /* Set the height of the specified window, with va_list.  */
   1173  1.1  christos static void
   1174  1.1  christos tui_xdb_set_win_height_command (char *arg, int from_tty)
   1175  1.1  christos {
   1176  1.1  christos   tui_xdb_set_win_height (arg, from_tty);
   1177  1.1  christos }
   1178  1.1  christos 
   1179  1.1  christos 
   1180  1.1  christos /* Function to adjust all window heights around the primary.   */
   1181  1.1  christos static enum tui_status
   1182  1.1  christos tui_adjust_win_heights (struct tui_win_info *primary_win_info,
   1183  1.1  christos 			int new_height)
   1184  1.1  christos {
   1185  1.1  christos   enum tui_status status = TUI_FAILURE;
   1186  1.1  christos 
   1187  1.1  christos   if (new_height_ok (primary_win_info, new_height))
   1188  1.1  christos     {
   1189  1.1  christos       status = TUI_SUCCESS;
   1190  1.1  christos       if (new_height != primary_win_info->generic.height)
   1191  1.1  christos 	{
   1192  1.1  christos 	  int diff;
   1193  1.1  christos 	  struct tui_win_info *win_info;
   1194  1.1  christos 	  struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
   1195  1.1  christos 	  enum tui_layout_type cur_layout = tui_current_layout ();
   1196  1.1  christos 
   1197  1.1  christos 	  diff = (new_height - primary_win_info->generic.height) * (-1);
   1198  1.1  christos 	  if (cur_layout == SRC_COMMAND
   1199  1.1  christos 	      || cur_layout == DISASSEM_COMMAND)
   1200  1.1  christos 	    {
   1201  1.1  christos 	      struct tui_win_info *src_win_info;
   1202  1.1  christos 
   1203  1.1  christos 	      make_invisible_and_set_new_height (primary_win_info, new_height);
   1204  1.1  christos 	      if (primary_win_info->generic.type == CMD_WIN)
   1205  1.1  christos 		{
   1206  1.1  christos 		  win_info = (tui_source_windows ())->list[0];
   1207  1.1  christos 		  src_win_info = win_info;
   1208  1.1  christos 		}
   1209  1.1  christos 	      else
   1210  1.1  christos 		{
   1211  1.1  christos 		  win_info = tui_win_list[CMD_WIN];
   1212  1.1  christos 		  src_win_info = primary_win_info;
   1213  1.1  christos 		}
   1214  1.1  christos 	      make_invisible_and_set_new_height (win_info,
   1215  1.1  christos 					     win_info->generic.height + diff);
   1216  1.1  christos 	      TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1217  1.1  christos 	      make_visible_with_new_height (win_info);
   1218  1.1  christos 	      make_visible_with_new_height (primary_win_info);
   1219  1.1  christos 	      if (src_win_info->generic.content_size <= 0)
   1220  1.1  christos 		tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
   1221  1.1  christos 	    }
   1222  1.1  christos 	  else
   1223  1.1  christos 	    {
   1224  1.1  christos 	      struct tui_win_info *first_win;
   1225  1.1  christos 	      struct tui_win_info *second_win;
   1226  1.1  christos 
   1227  1.1  christos 	      if (cur_layout == SRC_DISASSEM_COMMAND)
   1228  1.1  christos 		{
   1229  1.1  christos 		  first_win = TUI_SRC_WIN;
   1230  1.1  christos 		  second_win = TUI_DISASM_WIN;
   1231  1.1  christos 		}
   1232  1.1  christos 	      else
   1233  1.1  christos 		{
   1234  1.1  christos 		  first_win = TUI_DATA_WIN;
   1235  1.1  christos 		  second_win = (tui_source_windows ())->list[0];
   1236  1.1  christos 		}
   1237  1.1  christos 	      if (primary_win_info == TUI_CMD_WIN)
   1238  1.1  christos 		{ /* Split the change in height accross the 1st & 2nd
   1239  1.1  christos 		     windows, adjusting them as well.  */
   1240  1.1  christos 		  /* Subtract the locator.  */
   1241  1.1  christos 		  int first_split_diff = diff / 2;
   1242  1.1  christos 		  int second_split_diff = first_split_diff;
   1243  1.1  christos 
   1244  1.1  christos 		  if (diff % 2)
   1245  1.1  christos 		    {
   1246  1.1  christos 		      if (first_win->generic.height >
   1247  1.1  christos 			  second_win->generic.height)
   1248  1.1  christos 			if (diff < 0)
   1249  1.1  christos 			  first_split_diff--;
   1250  1.1  christos 			else
   1251  1.1  christos 			  first_split_diff++;
   1252  1.1  christos 		      else
   1253  1.1  christos 			{
   1254  1.1  christos 			  if (diff < 0)
   1255  1.1  christos 			    second_split_diff--;
   1256  1.1  christos 			  else
   1257  1.1  christos 			    second_split_diff++;
   1258  1.1  christos 			}
   1259  1.1  christos 		    }
   1260  1.1  christos 		  /* Make sure that the minimum hieghts are
   1261  1.1  christos 		     honored.  */
   1262  1.1  christos 		  while ((first_win->generic.height + first_split_diff) < 3)
   1263  1.1  christos 		    {
   1264  1.1  christos 		      first_split_diff++;
   1265  1.1  christos 		      second_split_diff--;
   1266  1.1  christos 		    }
   1267  1.1  christos 		  while ((second_win->generic.height + second_split_diff) < 3)
   1268  1.1  christos 		    {
   1269  1.1  christos 		      second_split_diff++;
   1270  1.1  christos 		      first_split_diff--;
   1271  1.1  christos 		    }
   1272  1.1  christos 		  make_invisible_and_set_new_height (
   1273  1.1  christos 						  first_win,
   1274  1.1  christos 				 first_win->generic.height + first_split_diff);
   1275  1.1  christos 		  second_win->generic.origin.y = first_win->generic.height - 1;
   1276  1.1  christos 		  make_invisible_and_set_new_height (second_win,
   1277  1.1  christos 						     second_win->generic.height
   1278  1.1  christos 						     + second_split_diff);
   1279  1.1  christos 		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1280  1.1  christos 		  make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
   1281  1.1  christos 		}
   1282  1.1  christos 	      else
   1283  1.1  christos 		{
   1284  1.1  christos 		  if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1285  1.1  christos 		    { /* If there is no way to increase the command
   1286  1.1  christos 			 window take real estate from the 1st or 2nd
   1287  1.1  christos 			 window.  */
   1288  1.1  christos 		      if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1289  1.1  christos 			{
   1290  1.1  christos 			  int i;
   1291  1.1  christos 
   1292  1.1  christos 			  for (i = TUI_CMD_WIN->generic.height + diff;
   1293  1.1  christos 			       (i < 1); i++)
   1294  1.1  christos 			    if (primary_win_info == first_win)
   1295  1.1  christos 			      second_win->generic.height--;
   1296  1.1  christos 			    else
   1297  1.1  christos 			      first_win->generic.height--;
   1298  1.1  christos 			}
   1299  1.1  christos 		    }
   1300  1.1  christos 		  if (primary_win_info == first_win)
   1301  1.1  christos 		    make_invisible_and_set_new_height (first_win, new_height);
   1302  1.1  christos 		  else
   1303  1.1  christos 		    make_invisible_and_set_new_height (
   1304  1.1  christos 						    first_win,
   1305  1.1  christos 						  first_win->generic.height);
   1306  1.1  christos 		  second_win->generic.origin.y = first_win->generic.height - 1;
   1307  1.1  christos 		  if (primary_win_info == second_win)
   1308  1.1  christos 		    make_invisible_and_set_new_height (second_win, new_height);
   1309  1.1  christos 		  else
   1310  1.1  christos 		    make_invisible_and_set_new_height (
   1311  1.1  christos 				      second_win, second_win->generic.height);
   1312  1.1  christos 		  TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
   1313  1.1  christos 		  if ((TUI_CMD_WIN->generic.height + diff) < 1)
   1314  1.1  christos 		    make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
   1315  1.1  christos 		  else
   1316  1.1  christos 		    make_invisible_and_set_new_height (TUI_CMD_WIN,
   1317  1.1  christos 						       TUI_CMD_WIN->generic.height + diff);
   1318  1.1  christos 		}
   1319  1.1  christos 	      make_visible_with_new_height (TUI_CMD_WIN);
   1320  1.1  christos 	      make_visible_with_new_height (second_win);
   1321  1.1  christos 	      make_visible_with_new_height (first_win);
   1322  1.1  christos 	      if (first_win->generic.content_size <= 0)
   1323  1.1  christos 		tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
   1324  1.1  christos 	      if (second_win->generic.content_size <= 0)
   1325  1.1  christos 		tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
   1326  1.1  christos 	    }
   1327  1.1  christos 	}
   1328  1.1  christos     }
   1329  1.1  christos 
   1330  1.1  christos   return status;
   1331  1.1  christos }
   1332  1.1  christos 
   1333  1.1  christos 
   1334  1.1  christos /* Function make the target window (and auxillary windows associated
   1335  1.1  christos    with the targer) invisible, and set the new height and
   1336  1.1  christos    location.  */
   1337  1.1  christos static void
   1338  1.1  christos make_invisible_and_set_new_height (struct tui_win_info *win_info,
   1339  1.1  christos 				   int height)
   1340  1.1  christos {
   1341  1.1  christos   int i;
   1342  1.1  christos   struct tui_gen_win_info *gen_win_info;
   1343  1.1  christos 
   1344  1.1  christos   tui_make_invisible (&win_info->generic);
   1345  1.1  christos   win_info->generic.height = height;
   1346  1.1  christos   if (height > 1)
   1347  1.1  christos     win_info->generic.viewport_height = height - 1;
   1348  1.1  christos   else
   1349  1.1  christos     win_info->generic.viewport_height = height;
   1350  1.1  christos   if (win_info != TUI_CMD_WIN)
   1351  1.1  christos     win_info->generic.viewport_height--;
   1352  1.1  christos 
   1353  1.1  christos   /* Now deal with the auxillary windows associated with win_info.  */
   1354  1.1  christos   switch (win_info->generic.type)
   1355  1.1  christos     {
   1356  1.1  christos     case SRC_WIN:
   1357  1.1  christos     case DISASSEM_WIN:
   1358  1.1  christos       gen_win_info = win_info->detail.source_info.execution_info;
   1359  1.1  christos       tui_make_invisible (gen_win_info);
   1360  1.1  christos       gen_win_info->height = height;
   1361  1.1  christos       gen_win_info->origin.y = win_info->generic.origin.y;
   1362  1.1  christos       if (height > 1)
   1363  1.1  christos 	gen_win_info->viewport_height = height - 1;
   1364  1.1  christos       else
   1365  1.1  christos 	gen_win_info->viewport_height = height;
   1366  1.1  christos       if (win_info != TUI_CMD_WIN)
   1367  1.1  christos 	gen_win_info->viewport_height--;
   1368  1.1  christos 
   1369  1.1  christos       if (tui_win_has_locator (win_info))
   1370  1.1  christos 	{
   1371  1.1  christos 	  gen_win_info = tui_locator_win_info_ptr ();
   1372  1.1  christos 	  tui_make_invisible (gen_win_info);
   1373  1.1  christos 	  gen_win_info->origin.y = win_info->generic.origin.y + height;
   1374  1.1  christos 	}
   1375  1.1  christos       break;
   1376  1.1  christos     case DATA_WIN:
   1377  1.1  christos       /* Delete all data item windows.  */
   1378  1.1  christos       for (i = 0; i < win_info->generic.content_size; i++)
   1379  1.1  christos 	{
   1380  1.1  christos 	  gen_win_info = (struct tui_gen_win_info *)
   1381  1.1  christos 	    &((struct tui_win_element *)
   1382  1.1  christos 	      win_info->generic.content[i])->which_element.data_window;
   1383  1.1  christos 	  tui_delete_win (gen_win_info->handle);
   1384  1.1  christos 	  gen_win_info->handle = (WINDOW *) NULL;
   1385  1.1  christos 	}
   1386  1.1  christos       break;
   1387  1.1  christos     default:
   1388  1.1  christos       break;
   1389  1.1  christos     }
   1390  1.1  christos }
   1391  1.1  christos 
   1392  1.1  christos 
   1393  1.1  christos /* Function to make the windows with new heights visible.  This means
   1394  1.1  christos    re-creating the windows' content since the window had to be
   1395  1.1  christos    destroyed to be made invisible.  */
   1396  1.1  christos static void
   1397  1.1  christos make_visible_with_new_height (struct tui_win_info *win_info)
   1398  1.1  christos {
   1399  1.1  christos   struct symtab *s;
   1400  1.1  christos 
   1401  1.1  christos   tui_make_visible (&win_info->generic);
   1402  1.1  christos   tui_check_and_display_highlight_if_needed (win_info);
   1403  1.1  christos   switch (win_info->generic.type)
   1404  1.1  christos     {
   1405  1.1  christos     case SRC_WIN:
   1406  1.1  christos     case DISASSEM_WIN:
   1407  1.1  christos       tui_free_win_content (win_info->detail.source_info.execution_info);
   1408  1.1  christos       tui_make_visible (win_info->detail.source_info.execution_info);
   1409  1.1  christos       if (win_info->generic.content != NULL)
   1410  1.1  christos 	{
   1411  1.1  christos 	  struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
   1412  1.1  christos 	  struct tui_line_or_address line_or_addr;
   1413  1.1  christos 	  struct symtab_and_line cursal
   1414  1.1  christos 	    = get_current_source_symtab_and_line ();
   1415  1.1  christos 
   1416  1.1  christos 	  line_or_addr = win_info->detail.source_info.start_line_or_addr;
   1417  1.1  christos 	  tui_free_win_content (&win_info->generic);
   1418  1.1  christos 	  tui_update_source_window (win_info, gdbarch,
   1419  1.1  christos 				    cursal.symtab, line_or_addr, TRUE);
   1420  1.1  christos 	}
   1421  1.1  christos       else if (deprecated_safe_get_selected_frame () != NULL)
   1422  1.1  christos 	{
   1423  1.1  christos 	  struct tui_line_or_address line;
   1424  1.1  christos 	  struct symtab_and_line cursal
   1425  1.1  christos 	    = get_current_source_symtab_and_line ();
   1426  1.1  christos 	  struct frame_info *frame = deprecated_safe_get_selected_frame ();
   1427  1.1  christos 	  struct gdbarch *gdbarch = get_frame_arch (frame);
   1428  1.1  christos 
   1429  1.3  christos 	  s = find_pc_line_symtab (get_frame_pc (frame));
   1430  1.1  christos 	  if (win_info->generic.type == SRC_WIN)
   1431  1.1  christos 	    {
   1432  1.1  christos 	      line.loa = LOA_LINE;
   1433  1.1  christos 	      line.u.line_no = cursal.line;
   1434  1.1  christos 	    }
   1435  1.1  christos 	  else
   1436  1.1  christos 	    {
   1437  1.1  christos 	      line.loa = LOA_ADDRESS;
   1438  1.1  christos 	      find_line_pc (s, cursal.line, &line.u.addr);
   1439  1.1  christos 	    }
   1440  1.1  christos 	  tui_update_source_window (win_info, gdbarch, s, line, TRUE);
   1441  1.1  christos 	}
   1442  1.1  christos       if (tui_win_has_locator (win_info))
   1443  1.1  christos 	{
   1444  1.1  christos 	  tui_make_visible (tui_locator_win_info_ptr ());
   1445  1.1  christos 	  tui_show_locator_content ();
   1446  1.1  christos 	}
   1447  1.1  christos       break;
   1448  1.1  christos     case DATA_WIN:
   1449  1.1  christos       tui_display_all_data ();
   1450  1.1  christos       break;
   1451  1.1  christos     case CMD_WIN:
   1452  1.1  christos       win_info->detail.command_info.cur_line = 0;
   1453  1.1  christos       win_info->detail.command_info.curch = 0;
   1454  1.1  christos #ifdef HAVE_WRESIZE
   1455  1.1  christos       wresize (TUI_CMD_WIN->generic.handle,
   1456  1.1  christos 	       TUI_CMD_WIN->generic.height,
   1457  1.1  christos 	       TUI_CMD_WIN->generic.width);
   1458  1.1  christos #endif
   1459  1.1  christos       mvwin (TUI_CMD_WIN->generic.handle,
   1460  1.1  christos 	     TUI_CMD_WIN->generic.origin.y,
   1461  1.1  christos 	     TUI_CMD_WIN->generic.origin.x);
   1462  1.1  christos       wmove (win_info->generic.handle,
   1463  1.1  christos 	     win_info->detail.command_info.cur_line,
   1464  1.1  christos 	     win_info->detail.command_info.curch);
   1465  1.1  christos       break;
   1466  1.1  christos     default:
   1467  1.1  christos       break;
   1468  1.1  christos     }
   1469  1.1  christos }
   1470  1.1  christos 
   1471  1.1  christos 
   1472  1.1  christos static int
   1473  1.1  christos new_height_ok (struct tui_win_info *primary_win_info,
   1474  1.1  christos 	       int new_height)
   1475  1.1  christos {
   1476  1.1  christos   int ok = (new_height < tui_term_height ());
   1477  1.1  christos 
   1478  1.1  christos   if (ok)
   1479  1.1  christos     {
   1480  1.1  christos       int diff;
   1481  1.1  christos       enum tui_layout_type cur_layout = tui_current_layout ();
   1482  1.1  christos 
   1483  1.1  christos       diff = (new_height - primary_win_info->generic.height) * (-1);
   1484  1.1  christos       if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
   1485  1.1  christos 	{
   1486  1.1  christos 	  ok = ((primary_win_info->generic.type == CMD_WIN
   1487  1.1  christos 		 && new_height <= (tui_term_height () - 4)
   1488  1.1  christos 		 && new_height >= MIN_CMD_WIN_HEIGHT)
   1489  1.1  christos 		|| (primary_win_info->generic.type != CMD_WIN
   1490  1.1  christos 		    && new_height <= (tui_term_height () - 2)
   1491  1.1  christos 		    && new_height >= MIN_WIN_HEIGHT));
   1492  1.1  christos 	  if (ok)
   1493  1.1  christos 	    {			/* Check the total height.  */
   1494  1.1  christos 	      struct tui_win_info *win_info;
   1495  1.1  christos 
   1496  1.1  christos 	      if (primary_win_info == TUI_CMD_WIN)
   1497  1.1  christos 		win_info = (tui_source_windows ())->list[0];
   1498  1.1  christos 	      else
   1499  1.1  christos 		win_info = TUI_CMD_WIN;
   1500  1.1  christos 	      ok = ((new_height +
   1501  1.1  christos 		     (win_info->generic.height + diff)) <= tui_term_height ());
   1502  1.1  christos 	    }
   1503  1.1  christos 	}
   1504  1.1  christos       else
   1505  1.1  christos 	{
   1506  1.1  christos 	  int cur_total_height, total_height, min_height = 0;
   1507  1.1  christos 	  struct tui_win_info *first_win;
   1508  1.1  christos 	  struct tui_win_info *second_win;
   1509  1.1  christos 
   1510  1.1  christos 	  if (cur_layout == SRC_DISASSEM_COMMAND)
   1511  1.1  christos 	    {
   1512  1.1  christos 	      first_win = TUI_SRC_WIN;
   1513  1.1  christos 	      second_win = TUI_DISASM_WIN;
   1514  1.1  christos 	    }
   1515  1.1  christos 	  else
   1516  1.1  christos 	    {
   1517  1.1  christos 	      first_win = TUI_DATA_WIN;
   1518  1.1  christos 	      second_win = (tui_source_windows ())->list[0];
   1519  1.1  christos 	    }
   1520  1.1  christos 	  /* We could simply add all the heights to obtain the same
   1521  1.1  christos 	     result but below is more explicit since we subtract 1 for
   1522  1.1  christos 	     the line that the first and second windows share, and add
   1523  1.1  christos 	     one for the locator.  */
   1524  1.1  christos 	  total_height = cur_total_height =
   1525  1.1  christos 	    (first_win->generic.height + second_win->generic.height - 1)
   1526  1.1  christos 	    + TUI_CMD_WIN->generic.height + 1;	/* Locator. */
   1527  1.1  christos 	  if (primary_win_info == TUI_CMD_WIN)
   1528  1.1  christos 	    {
   1529  1.1  christos 	      /* Locator included since first & second win share a line.  */
   1530  1.1  christos 	      ok = ((first_win->generic.height +
   1531  1.1  christos 		     second_win->generic.height + diff) >=
   1532  1.1  christos 		    (MIN_WIN_HEIGHT * 2)
   1533  1.1  christos 		    && new_height >= MIN_CMD_WIN_HEIGHT);
   1534  1.1  christos 	      if (ok)
   1535  1.1  christos 		{
   1536  1.1  christos 		  total_height = new_height +
   1537  1.1  christos 		    (first_win->generic.height +
   1538  1.1  christos 		     second_win->generic.height + diff);
   1539  1.1  christos 		  min_height = MIN_CMD_WIN_HEIGHT;
   1540  1.1  christos 		}
   1541  1.1  christos 	    }
   1542  1.1  christos 	  else
   1543  1.1  christos 	    {
   1544  1.1  christos 	      min_height = MIN_WIN_HEIGHT;
   1545  1.1  christos 
   1546  1.1  christos 	      /* First see if we can increase/decrease the command
   1547  1.1  christos 	         window.  And make sure that the command window is at
   1548  1.1  christos 	         least 1 line.  */
   1549  1.1  christos 	      ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
   1550  1.1  christos 	      if (!ok)
   1551  1.1  christos 		{ /* Looks like we have to increase/decrease one of
   1552  1.1  christos 		     the other windows.  */
   1553  1.1  christos 		  if (primary_win_info == first_win)
   1554  1.1  christos 		    ok = (second_win->generic.height + diff) >= min_height;
   1555  1.1  christos 		  else
   1556  1.1  christos 		    ok = (first_win->generic.height + diff) >= min_height;
   1557  1.1  christos 		}
   1558  1.1  christos 	      if (ok)
   1559  1.1  christos 		{
   1560  1.1  christos 		  if (primary_win_info == first_win)
   1561  1.1  christos 		    total_height = new_height +
   1562  1.1  christos 		      second_win->generic.height +
   1563  1.1  christos 		      TUI_CMD_WIN->generic.height + diff;
   1564  1.1  christos 		  else
   1565  1.1  christos 		    total_height = new_height +
   1566  1.1  christos 		      first_win->generic.height +
   1567  1.1  christos 		      TUI_CMD_WIN->generic.height + diff;
   1568  1.1  christos 		}
   1569  1.1  christos 	    }
   1570  1.1  christos 	  /* Now make sure that the proposed total height doesn't
   1571  1.1  christos 	     exceed the old total height.  */
   1572  1.1  christos 	  if (ok)
   1573  1.1  christos 	    ok = (new_height >= min_height
   1574  1.1  christos 		  && total_height <= cur_total_height);
   1575  1.1  christos 	}
   1576  1.1  christos     }
   1577  1.1  christos 
   1578  1.1  christos   return ok;
   1579  1.1  christos }
   1580  1.1  christos 
   1581  1.1  christos 
   1582  1.1  christos static void
   1583  1.1  christos parse_scrolling_args (char *arg,
   1584  1.1  christos 		      struct tui_win_info **win_to_scroll,
   1585  1.1  christos 		      int *num_to_scroll)
   1586  1.1  christos {
   1587  1.1  christos   if (num_to_scroll)
   1588  1.1  christos     *num_to_scroll = 0;
   1589  1.1  christos   *win_to_scroll = tui_win_with_focus ();
   1590  1.1  christos 
   1591  1.1  christos   /* First set up the default window to scroll, in case there is no
   1592  1.1  christos      window name arg.  */
   1593  1.1  christos   if (arg != (char *) NULL)
   1594  1.1  christos     {
   1595  1.1  christos       char *buf, *buf_ptr;
   1596  1.1  christos 
   1597  1.1  christos       /* Process the number of lines to scroll.  */
   1598  1.1  christos       buf = buf_ptr = xstrdup (arg);
   1599  1.1  christos       if (isdigit (*buf_ptr))
   1600  1.1  christos 	{
   1601  1.1  christos 	  char *num_str;
   1602  1.1  christos 
   1603  1.1  christos 	  num_str = buf_ptr;
   1604  1.1  christos 	  buf_ptr = strchr (buf_ptr, ' ');
   1605  1.1  christos 	  if (buf_ptr != (char *) NULL)
   1606  1.1  christos 	    {
   1607  1.1  christos 	      *buf_ptr = (char) 0;
   1608  1.1  christos 	      if (num_to_scroll)
   1609  1.1  christos 		*num_to_scroll = atoi (num_str);
   1610  1.1  christos 	      buf_ptr++;
   1611  1.1  christos 	    }
   1612  1.1  christos 	  else if (num_to_scroll)
   1613  1.1  christos 	    *num_to_scroll = atoi (num_str);
   1614  1.1  christos 	}
   1615  1.1  christos 
   1616  1.1  christos       /* Process the window name if one is specified.  */
   1617  1.1  christos       if (buf_ptr != (char *) NULL)
   1618  1.1  christos 	{
   1619  1.1  christos 	  char *wname;
   1620  1.1  christos 	  int i;
   1621  1.1  christos 
   1622  1.1  christos 	  if (*buf_ptr == ' ')
   1623  1.1  christos 	    while (*(++buf_ptr) == ' ')
   1624  1.1  christos 	      ;
   1625  1.1  christos 
   1626  1.1  christos 	  if (*buf_ptr != (char) 0)
   1627  1.1  christos 	    {
   1628  1.1  christos 	      wname = buf_ptr;
   1629  1.1  christos 
   1630  1.1  christos 	      /* Validate the window name.  */
   1631  1.1  christos 	      for (i = 0; i < strlen (wname); i++)
   1632  1.1  christos 		wname[i] = toupper (wname[i]);
   1633  1.1  christos 	    }
   1634  1.1  christos 	  else
   1635  1.1  christos 	    wname = "?";
   1636  1.1  christos 
   1637  1.1  christos 	  *win_to_scroll = tui_partial_win_by_name (wname);
   1638  1.1  christos 
   1639  1.1  christos 	  if (*win_to_scroll == (struct tui_win_info *) NULL
   1640  1.1  christos 	      || !(*win_to_scroll)->generic.is_visible)
   1641  1.1  christos 	    error (_("Invalid window specified. \n\
   1642  1.1  christos The window name specified must be valid and visible.\n"));
   1643  1.1  christos 	  else if (*win_to_scroll == TUI_CMD_WIN)
   1644  1.1  christos 	    *win_to_scroll = (tui_source_windows ())->list[0];
   1645  1.1  christos 	}
   1646  1.1  christos       xfree (buf);
   1647  1.1  christos     }
   1648  1.1  christos }
   1649