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