* config/tc-arm.c (arm_cpus): Add entry for ARM Cortex-M0.
[binutils-gdb.git] / gdb / tui / tui-win.c
blobb101cdd5333e08860896b252270a8054dff6be31
1 /* TUI window generic functions.
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008,
4 2009 Free Software Foundation, Inc.
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 /* This module contains procedures for handling tui window functions
24 like resize, scrolling, scrolling, changing focus, etc.
26 Author: Susan B. Macchia */
28 #include "defs.h"
29 #include "command.h"
30 #include "symtab.h"
31 #include "breakpoint.h"
32 #include "frame.h"
33 #include "cli/cli-cmds.h"
34 #include "top.h"
35 #include "source.h"
37 #include "tui/tui.h"
38 #include "tui/tui-data.h"
39 #include "tui/tui-wingeneral.h"
40 #include "tui/tui-stack.h"
41 #include "tui/tui-regs.h"
42 #include "tui/tui-disasm.h"
43 #include "tui/tui-source.h"
44 #include "tui/tui-winsource.h"
45 #include "tui/tui-windata.h"
46 #include "tui/tui-win.h"
48 #include "gdb_curses.h"
50 #include "gdb_string.h"
51 #include <ctype.h>
52 #include "readline/readline.h"
54 #include <signal.h>
56 /*******************************
57 ** Static Local Decls
58 ********************************/
59 static void make_visible_with_new_height (struct tui_win_info *);
60 static void make_invisible_and_set_new_height (struct tui_win_info *,
61 int);
62 static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
63 int);
64 static int new_height_ok (struct tui_win_info *, int);
65 static void tui_set_tab_width_command (char *, int);
66 static void tui_refresh_all_command (char *, int);
67 static void tui_set_win_height_command (char *, int);
68 static void tui_xdb_set_win_height_command (char *, int);
69 static void tui_all_windows_info (char *, int);
70 static void tui_set_focus_command (char *, int);
71 static void tui_scroll_forward_command (char *, int);
72 static void tui_scroll_backward_command (char *, int);
73 static void tui_scroll_left_command (char *, int);
74 static void tui_scroll_right_command (char *, int);
75 static void parse_scrolling_args (char *,
76 struct tui_win_info **,
77 int *);
80 /***************************************
81 ** DEFINITIONS
82 ***************************************/
83 #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n"
84 #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n"
85 #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n"
87 /***************************************
88 ** PUBLIC FUNCTIONS
89 ***************************************/
91 #ifndef ACS_LRCORNER
92 # define ACS_LRCORNER '+'
93 #endif
94 #ifndef ACS_LLCORNER
95 # define ACS_LLCORNER '+'
96 #endif
97 #ifndef ACS_ULCORNER
98 # define ACS_ULCORNER '+'
99 #endif
100 #ifndef ACS_URCORNER
101 # define ACS_URCORNER '+'
102 #endif
103 #ifndef ACS_HLINE
104 # define ACS_HLINE '-'
105 #endif
106 #ifndef ACS_VLINE
107 # define ACS_VLINE '|'
108 #endif
110 /* Possible values for tui-border-kind variable. */
111 static const char *tui_border_kind_enums[] = {
112 "space",
113 "ascii",
114 "acs",
115 NULL
118 /* Possible values for tui-border-mode and tui-active-border-mode. */
119 static const char *tui_border_mode_enums[] = {
120 "normal",
121 "standout",
122 "reverse",
123 "half",
124 "half-standout",
125 "bold",
126 "bold-standout",
127 NULL
130 struct tui_translate
132 const char *name;
133 int value;
136 /* Translation table for border-mode variables.
137 The list of values must be terminated by a NULL.
138 After the NULL value, an entry defines the default. */
139 struct tui_translate tui_border_mode_translate[] = {
140 { "normal", A_NORMAL },
141 { "standout", A_STANDOUT },
142 { "reverse", A_REVERSE },
143 { "half", A_DIM },
144 { "half-standout", A_DIM | A_STANDOUT },
145 { "bold", A_BOLD },
146 { "bold-standout", A_BOLD | A_STANDOUT },
147 { 0, 0 },
148 { "normal", A_NORMAL }
151 /* Translation tables for border-kind, one for each border
152 character (see wborder, border curses operations).
153 -1 is used to indicate the ACS because ACS characters
154 are determined at run time by curses (depends on terminal). */
155 struct tui_translate tui_border_kind_translate_vline[] = {
156 { "space", ' ' },
157 { "ascii", '|' },
158 { "acs", -1 },
159 { 0, 0 },
160 { "ascii", '|' }
163 struct tui_translate tui_border_kind_translate_hline[] = {
164 { "space", ' ' },
165 { "ascii", '-' },
166 { "acs", -1 },
167 { 0, 0 },
168 { "ascii", '-' }
171 struct tui_translate tui_border_kind_translate_ulcorner[] = {
172 { "space", ' ' },
173 { "ascii", '+' },
174 { "acs", -1 },
175 { 0, 0 },
176 { "ascii", '+' }
179 struct tui_translate tui_border_kind_translate_urcorner[] = {
180 { "space", ' ' },
181 { "ascii", '+' },
182 { "acs", -1 },
183 { 0, 0 },
184 { "ascii", '+' }
187 struct tui_translate tui_border_kind_translate_llcorner[] = {
188 { "space", ' ' },
189 { "ascii", '+' },
190 { "acs", -1 },
191 { 0, 0 },
192 { "ascii", '+' }
195 struct tui_translate tui_border_kind_translate_lrcorner[] = {
196 { "space", ' ' },
197 { "ascii", '+' },
198 { "acs", -1 },
199 { 0, 0 },
200 { "ascii", '+' }
204 /* Tui configuration variables controlled with set/show command. */
205 const char *tui_active_border_mode = "bold-standout";
206 static void
207 show_tui_active_border_mode (struct ui_file *file,
208 int from_tty,
209 struct cmd_list_element *c,
210 const char *value)
212 fprintf_filtered (file, _("\
213 The attribute mode to use for the active TUI window border is \"%s\".\n"),
214 value);
217 const char *tui_border_mode = "normal";
218 static void
219 show_tui_border_mode (struct ui_file *file,
220 int from_tty,
221 struct cmd_list_element *c,
222 const char *value)
224 fprintf_filtered (file, _("\
225 The attribute mode to use for the TUI window borders is \"%s\".\n"),
226 value);
229 const char *tui_border_kind = "acs";
230 static void
231 show_tui_border_kind (struct ui_file *file,
232 int from_tty,
233 struct cmd_list_element *c,
234 const char *value)
236 fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
237 value);
241 /* Tui internal configuration variables. These variables are updated
242 by tui_update_variables to reflect the tui configuration
243 variables. */
244 chtype tui_border_vline;
245 chtype tui_border_hline;
246 chtype tui_border_ulcorner;
247 chtype tui_border_urcorner;
248 chtype tui_border_llcorner;
249 chtype tui_border_lrcorner;
251 int tui_border_attrs;
252 int tui_active_border_attrs;
254 /* Identify the item in the translation table.
255 When the item is not recognized, use the default entry. */
256 static struct tui_translate *
257 translate (const char *name, struct tui_translate *table)
259 while (table->name)
261 if (name && strcmp (table->name, name) == 0)
262 return table;
263 table++;
266 /* Not found, return default entry. */
267 table++;
268 return table;
271 /* Update the tui internal configuration according to gdb settings.
272 Returns 1 if the configuration has changed and the screen should
273 be redrawn. */
275 tui_update_variables (void)
277 int need_redraw = 0;
278 struct tui_translate *entry;
280 entry = translate (tui_border_mode, tui_border_mode_translate);
281 if (tui_border_attrs != entry->value)
283 tui_border_attrs = entry->value;
284 need_redraw = 1;
286 entry = translate (tui_active_border_mode, tui_border_mode_translate);
287 if (tui_active_border_attrs != entry->value)
289 tui_active_border_attrs = entry->value;
290 need_redraw = 1;
293 /* If one corner changes, all characters are changed.
294 Only check the first one. The ACS characters are determined at
295 run time by curses terminal management. */
296 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
297 if (tui_border_lrcorner != (chtype) entry->value)
299 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
300 need_redraw = 1;
302 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
303 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
305 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
306 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
308 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
309 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
311 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
312 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
314 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
315 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
317 return need_redraw;
320 static void
321 set_tui_cmd (char *args, int from_tty)
325 static void
326 show_tui_cmd (char *args, int from_tty)
330 static struct cmd_list_element *tuilist;
332 static void
333 tui_command (char *args, int from_tty)
335 printf_unfiltered (_("\"tui\" must be followed by the name of a "
336 "tui command.\n"));
337 help_list (tuilist, "tui ", -1, gdb_stdout);
340 struct cmd_list_element **
341 tui_get_cmd_list (void)
343 if (tuilist == 0)
344 add_prefix_cmd ("tui", class_tui, tui_command,
345 _("Text User Interface commands."),
346 &tuilist, "tui ", 0, &cmdlist);
347 return &tuilist;
350 /* Function to initialize gdb commands, for tui window
351 manipulation. */
353 /* Provide a prototype to silence -Wmissing-prototypes. */
354 extern initialize_file_ftype _initialize_tui_win;
356 void
357 _initialize_tui_win (void)
359 struct cmd_list_element *c;
360 static struct cmd_list_element *tui_setlist;
361 static struct cmd_list_element *tui_showlist;
363 /* Define the classes of commands.
364 They will appear in the help list in the reverse of this order. */
365 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
366 _("TUI configuration variables"),
367 &tui_setlist, "set tui ",
368 0 /* allow-unknown */, &setlist);
369 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
370 _("TUI configuration variables"),
371 &tui_showlist, "show tui ",
372 0 /* allow-unknown */, &showlist);
374 add_com ("refresh", class_tui, tui_refresh_all_command,
375 _("Refresh the terminal display.\n"));
376 if (xdb_commands)
377 add_com_alias ("U", "refresh", class_tui, 0);
378 add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
379 Set the width (in characters) of tab stops.\n\
380 Usage: tabset <n>\n"));
381 add_com ("winheight", class_tui, tui_set_win_height_command, _("\
382 Set the height of a specified window.\n\
383 Usage: winheight <win_name> [+ | -] <#lines>\n\
384 Window names are:\n\
385 src : the source window\n\
386 cmd : the command window\n\
387 asm : the disassembly window\n\
388 regs : the register display\n"));
389 add_com_alias ("wh", "winheight", class_tui, 0);
390 add_info ("win", tui_all_windows_info,
391 _("List of all displayed windows.\n"));
392 add_com ("focus", class_tui, tui_set_focus_command, _("\
393 Set focus to named window or next/prev window.\n\
394 Usage: focus {<win> | next | prev}\n\
395 Valid Window names are:\n\
396 src : the source window\n\
397 asm : the disassembly window\n\
398 regs : the register display\n\
399 cmd : the command window\n"));
400 add_com_alias ("fs", "focus", class_tui, 0);
401 add_com ("+", class_tui, tui_scroll_forward_command, _("\
402 Scroll window forward.\n\
403 Usage: + [win] [n]\n"));
404 add_com ("-", class_tui, tui_scroll_backward_command, _("\
405 Scroll window backward.\n\
406 Usage: - [win] [n]\n"));
407 add_com ("<", class_tui, tui_scroll_left_command, _("\
408 Scroll window forward.\n\
409 Usage: < [win] [n]\n"));
410 add_com (">", class_tui, tui_scroll_right_command, _("\
411 Scroll window backward.\n\
412 Usage: > [win] [n]\n"));
413 if (xdb_commands)
414 add_com ("w", class_xdb, tui_xdb_set_win_height_command, _("\
415 XDB compatibility command for setting the height of a command window.\n\
416 Usage: w <#lines>\n"));
418 /* Define the tui control variables. */
419 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
420 &tui_border_kind, _("\
421 Set the kind of border for TUI windows."), _("\
422 Show the kind of border for TUI windows."), _("\
423 This variable controls the border of TUI windows:\n\
424 space use a white space\n\
425 ascii use ascii characters + - | for the border\n\
426 acs use the Alternate Character Set"),
427 NULL,
428 show_tui_border_kind,
429 &tui_setlist, &tui_showlist);
431 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
432 &tui_border_mode, _("\
433 Set the attribute mode to use for the TUI window borders."), _("\
434 Show the attribute mode to use for the TUI window borders."), _("\
435 This variable controls the attributes to use for the window borders:\n\
436 normal normal display\n\
437 standout use highlight mode of terminal\n\
438 reverse use reverse video mode\n\
439 half use half bright\n\
440 half-standout use half bright and standout mode\n\
441 bold use extra bright or bold\n\
442 bold-standout use extra bright or bold with standout mode"),
443 NULL,
444 show_tui_border_mode,
445 &tui_setlist, &tui_showlist);
447 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
448 &tui_active_border_mode, _("\
449 Set the attribute mode to use for the active TUI window border."), _("\
450 Show the attribute mode to use for the active TUI window border."), _("\
451 This variable controls the attributes to use for the active window border:\n\
452 normal normal display\n\
453 standout use highlight mode of terminal\n\
454 reverse use reverse video mode\n\
455 half use half bright\n\
456 half-standout use half bright and standout mode\n\
457 bold use extra bright or bold\n\
458 bold-standout use extra bright or bold with standout mode"),
459 NULL,
460 show_tui_active_border_mode,
461 &tui_setlist, &tui_showlist);
464 /* Update gdb's knowledge of the terminal size. */
465 void
466 tui_update_gdb_sizes (void)
468 char cmd[50];
470 /* Set to TUI command window dimension or use readline values. */
471 sprintf (cmd, "set width %d",
472 tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
473 execute_command (cmd, 0);
474 sprintf (cmd, "set height %d",
475 tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
476 execute_command (cmd, 0);
480 /* Set the logical focus to win_info. */
481 void
482 tui_set_win_focus_to (struct tui_win_info *win_info)
484 if (win_info != NULL)
486 struct tui_win_info *win_with_focus = tui_win_with_focus ();
488 if (win_with_focus != NULL
489 && win_with_focus->generic.type != CMD_WIN)
490 tui_unhighlight_win (win_with_focus);
491 tui_set_win_with_focus (win_info);
492 if (win_info->generic.type != CMD_WIN)
493 tui_highlight_win (win_info);
498 void
499 tui_scroll_forward (struct tui_win_info *win_to_scroll,
500 int num_to_scroll)
502 if (win_to_scroll != TUI_CMD_WIN)
504 int _num_to_scroll = num_to_scroll;
506 if (num_to_scroll == 0)
507 _num_to_scroll = win_to_scroll->generic.height - 3;
509 /* If we are scrolling the source or disassembly window, do a
510 "psuedo" scroll since not all of the source is in memory,
511 only what is in the viewport. If win_to_scroll is the
512 command window do nothing since the term should handle
513 it. */
514 if (win_to_scroll == TUI_SRC_WIN)
515 tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
516 else if (win_to_scroll == TUI_DISASM_WIN)
517 tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
518 else if (win_to_scroll == TUI_DATA_WIN)
519 tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
523 void
524 tui_scroll_backward (struct tui_win_info *win_to_scroll,
525 int num_to_scroll)
527 if (win_to_scroll != TUI_CMD_WIN)
529 int _num_to_scroll = num_to_scroll;
531 if (num_to_scroll == 0)
532 _num_to_scroll = win_to_scroll->generic.height - 3;
534 /* If we are scrolling the source or disassembly window, do a
535 "psuedo" scroll since not all of the source is in memory,
536 only what is in the viewport. If win_to_scroll is the
537 command window do nothing since the term should handle
538 it. */
539 if (win_to_scroll == TUI_SRC_WIN)
540 tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
541 else if (win_to_scroll == TUI_DISASM_WIN)
542 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
543 else if (win_to_scroll == TUI_DATA_WIN)
544 tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
549 void
550 tui_scroll_left (struct tui_win_info *win_to_scroll,
551 int num_to_scroll)
553 if (win_to_scroll != TUI_CMD_WIN)
555 int _num_to_scroll = num_to_scroll;
557 if (_num_to_scroll == 0)
558 _num_to_scroll = 1;
560 /* If we are scrolling the source or disassembly window, do a
561 "psuedo" scroll since not all of the source is in memory,
562 only what is in the viewport. If win_to_scroll is the command
563 window do nothing since the term should handle it. */
564 if (win_to_scroll == TUI_SRC_WIN
565 || win_to_scroll == TUI_DISASM_WIN)
566 tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL, _num_to_scroll);
571 void
572 tui_scroll_right (struct tui_win_info *win_to_scroll,
573 int num_to_scroll)
575 if (win_to_scroll != TUI_CMD_WIN)
577 int _num_to_scroll = num_to_scroll;
579 if (_num_to_scroll == 0)
580 _num_to_scroll = 1;
582 /* If we are scrolling the source or disassembly window, do a
583 "psuedo" scroll since not all of the source is in memory,
584 only what is in the viewport. If win_to_scroll is the command
585 window do nothing since the term should handle it. */
586 if (win_to_scroll == TUI_SRC_WIN
587 || win_to_scroll == TUI_DISASM_WIN)
588 tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL, _num_to_scroll);
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)
599 switch (direction)
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;
619 void
620 tui_refresh_all_win (void)
622 enum tui_win_type type;
624 clearok (curscr, TRUE);
625 tui_refresh_all (tui_win_list);
626 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
628 if (tui_win_list[type]
629 && tui_win_list[type]->generic.is_visible)
631 switch (type)
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;
648 tui_show_locator_content ();
652 /* Resize all the windows based on the the terminal size. This
653 function gets called from within the readline sinwinch handler. */
654 void
655 tui_resize_all (void)
657 int height_diff, width_diff;
658 int screenheight, screenwidth;
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)
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;
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)
690 if (height_diff < 0)
691 cmd_split_diff--;
692 else
693 cmd_split_diff++;
695 /* Now adjust each window. */
696 clear ();
697 refresh ();
698 switch (cur_layout)
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;
716 make_invisible_and_set_new_height (first_win, new_height);
717 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
718 TUI_CMD_WIN->generic.width += width_diff;
719 new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
720 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
721 make_visible_with_new_height (first_win);
722 make_visible_with_new_height (TUI_CMD_WIN);
723 if (first_win->generic.content_size <= 0)
724 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
725 break;
726 default:
727 if (cur_layout == SRC_DISASSEM_COMMAND)
729 first_win = TUI_SRC_WIN;
730 first_win->generic.width += width_diff;
731 second_win = TUI_DISASM_WIN;
732 second_win->generic.width += width_diff;
734 else
736 first_win = TUI_DATA_WIN;
737 first_win->generic.width += width_diff;
738 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
739 second_win->generic.width += width_diff;
741 /* Change the first window's height/width. */
742 /* Check for invalid heights. */
743 if (height_diff == 0)
744 new_height = first_win->generic.height;
745 else if ((first_win->generic.height +
746 second_win->generic.height + (split_diff * 2)) >=
747 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
748 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
749 else if ((first_win->generic.height + split_diff) <= 0)
750 new_height = MIN_WIN_HEIGHT;
751 else
752 new_height = first_win->generic.height + split_diff;
753 make_invisible_and_set_new_height (first_win, new_height);
755 locator->width += width_diff;
757 /* Change the second window's height/width. */
758 /* Check for invalid heights. */
759 if (height_diff == 0)
760 new_height = second_win->generic.height;
761 else if ((first_win->generic.height +
762 second_win->generic.height + (split_diff * 2)) >=
763 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
765 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
766 if (new_height % 2)
767 new_height = (new_height / 2) + 1;
768 else
769 new_height /= 2;
771 else if ((second_win->generic.height + split_diff) <= 0)
772 new_height = MIN_WIN_HEIGHT;
773 else
774 new_height = second_win->generic.height + split_diff;
775 second_win->generic.origin.y = first_win->generic.height - 1;
776 make_invisible_and_set_new_height (second_win, new_height);
778 /* Change the command window's height/width. */
779 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
780 make_invisible_and_set_new_height (
781 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + cmd_split_diff);
782 make_visible_with_new_height (first_win);
783 make_visible_with_new_height (second_win);
784 make_visible_with_new_height (TUI_CMD_WIN);
785 if (first_win->generic.content_size <= 0)
786 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
787 if (second_win->generic.content_size <= 0)
788 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
789 break;
791 /* Now remove all invisible windows, and their content so that
792 they get created again when called for with the new size. */
793 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
795 if (win_type != CMD_WIN
796 && (tui_win_list[win_type] != NULL)
797 && !tui_win_list[win_type]->generic.is_visible)
799 tui_free_window (tui_win_list[win_type]);
800 tui_win_list[win_type] = (struct tui_win_info *) NULL;
803 tui_set_win_resized_to (TRUE);
804 /* Turn keypad back on, unless focus is in the command
805 window. */
806 if (win_with_focus != TUI_CMD_WIN)
807 keypad (TUI_CMD_WIN->generic.handle, TRUE);
811 #ifdef SIGWINCH
812 /* SIGWINCH signal handler for the tui. This signal handler is always
813 called, even when the readline package clears signals because it is
814 set as the old_sigwinch() (TUI only). */
815 static void
816 tui_sigwinch_handler (int signal)
818 /* Say that a resize was done so that the readline can do it later
819 when appropriate. */
820 tui_set_win_resized_to (TRUE);
822 #endif
824 /* Initializes SIGWINCH signal handler for the tui. */
825 void
826 tui_initialize_win (void)
828 #ifdef SIGWINCH
829 #ifdef HAVE_SIGACTION
830 struct sigaction old_winch;
831 memset (&old_winch, 0, sizeof (old_winch));
832 old_winch.sa_handler = &tui_sigwinch_handler;
833 sigaction (SIGWINCH, &old_winch, NULL);
834 #else
835 signal (SIGWINCH, &tui_sigwinch_handler);
836 #endif
837 #endif
841 /*************************
842 ** STATIC LOCAL FUNCTIONS
843 **************************/
846 static void
847 tui_scroll_forward_command (char *arg, int from_tty)
849 int num_to_scroll = 1;
850 struct tui_win_info *win_to_scroll;
852 /* Make sure the curses mode is enabled. */
853 tui_enable ();
854 if (arg == (char *) NULL)
855 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
856 else
857 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
858 tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
862 static void
863 tui_scroll_backward_command (char *arg, int from_tty)
865 int num_to_scroll = 1;
866 struct tui_win_info *win_to_scroll;
868 /* Make sure the curses mode is enabled. */
869 tui_enable ();
870 if (arg == (char *) NULL)
871 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
872 else
873 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
874 tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
878 static void
879 tui_scroll_left_command (char *arg, int from_tty)
881 int num_to_scroll;
882 struct tui_win_info *win_to_scroll;
884 /* Make sure the curses mode is enabled. */
885 tui_enable ();
886 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
887 tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
891 static void
892 tui_scroll_right_command (char *arg, int from_tty)
894 int num_to_scroll;
895 struct tui_win_info *win_to_scroll;
897 /* Make sure the curses mode is enabled. */
898 tui_enable ();
899 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
900 tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
904 /* Set focus to the window named by 'arg'. */
905 static void
906 tui_set_focus (char *arg, int from_tty)
908 if (arg != (char *) NULL)
910 char *buf_ptr = (char *) xstrdup (arg);
911 int i;
912 struct tui_win_info *win_info = (struct tui_win_info *) NULL;
914 for (i = 0; (i < strlen (buf_ptr)); i++)
915 buf_ptr[i] = toupper (arg[i]);
917 if (subset_compare (buf_ptr, "NEXT"))
918 win_info = tui_next_win (tui_win_with_focus ());
919 else if (subset_compare (buf_ptr, "PREV"))
920 win_info = tui_prev_win (tui_win_with_focus ());
921 else
922 win_info = tui_partial_win_by_name (buf_ptr);
924 if (win_info == (struct tui_win_info *) NULL
925 || !win_info->generic.is_visible)
926 warning (_("Invalid window specified. \n\
927 The window name specified must be valid and visible.\n"));
928 else
930 tui_set_win_focus_to (win_info);
931 keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
934 if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
935 tui_refresh_data_win ();
936 xfree (buf_ptr);
937 printf_filtered (_("Focus set to %s window.\n"),
938 tui_win_name ((struct tui_gen_win_info *) tui_win_with_focus ()));
940 else
941 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
944 static void
945 tui_set_focus_command (char *arg, int from_tty)
947 /* Make sure the curses mode is enabled. */
948 tui_enable ();
949 tui_set_focus (arg, from_tty);
953 static void
954 tui_all_windows_info (char *arg, int from_tty)
956 enum tui_win_type type;
957 struct tui_win_info *win_with_focus = tui_win_with_focus ();
959 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
960 if (tui_win_list[type]
961 && tui_win_list[type]->generic.is_visible)
963 if (win_with_focus == tui_win_list[type])
964 printf_filtered (" %s\t(%d lines) <has focus>\n",
965 tui_win_name (&tui_win_list[type]->generic),
966 tui_win_list[type]->generic.height);
967 else
968 printf_filtered (" %s\t(%d lines)\n",
969 tui_win_name (&tui_win_list[type]->generic),
970 tui_win_list[type]->generic.height);
975 static void
976 tui_refresh_all_command (char *arg, int from_tty)
978 /* Make sure the curses mode is enabled. */
979 tui_enable ();
981 tui_refresh_all_win ();
985 /* Set the height of the specified window. */
986 static void
987 tui_set_tab_width_command (char *arg, int from_tty)
989 /* Make sure the curses mode is enabled. */
990 tui_enable ();
991 if (arg != (char *) NULL)
993 int ts;
995 ts = atoi (arg);
996 if (ts > 0)
997 tui_set_default_tab_len (ts);
998 else
999 warning (_("Tab widths greater than 0 must be specified."));
1004 /* Set the height of the specified window. */
1005 static void
1006 tui_set_win_height (char *arg, int from_tty)
1008 /* Make sure the curses mode is enabled. */
1009 tui_enable ();
1010 if (arg != (char *) NULL)
1012 char *buf = xstrdup (arg);
1013 char *buf_ptr = buf;
1014 char *wname = (char *) NULL;
1015 int new_height, i;
1016 struct tui_win_info *win_info;
1018 wname = buf_ptr;
1019 buf_ptr = strchr (buf_ptr, ' ');
1020 if (buf_ptr != (char *) NULL)
1022 *buf_ptr = (char) 0;
1024 /* Validate the window name. */
1025 for (i = 0; i < strlen (wname); i++)
1026 wname[i] = toupper (wname[i]);
1027 win_info = tui_partial_win_by_name (wname);
1029 if (win_info == (struct tui_win_info *) NULL
1030 || !win_info->generic.is_visible)
1031 warning (_("Invalid window specified. \n\
1032 The window name specified must be valid and visible.\n"));
1033 else
1035 /* Process the size. */
1036 while (*(++buf_ptr) == ' ')
1039 if (*buf_ptr != (char) 0)
1041 int negate = FALSE;
1042 int fixed_size = TRUE;
1043 int input_no;;
1045 if (*buf_ptr == '+' || *buf_ptr == '-')
1047 if (*buf_ptr == '-')
1048 negate = TRUE;
1049 fixed_size = FALSE;
1050 buf_ptr++;
1052 input_no = atoi (buf_ptr);
1053 if (input_no > 0)
1055 if (negate)
1056 input_no *= (-1);
1057 if (fixed_size)
1058 new_height = input_no;
1059 else
1060 new_height = win_info->generic.height + input_no;
1062 /* Now change the window's height, and adjust
1063 all other windows around it. */
1064 if (tui_adjust_win_heights (win_info,
1065 new_height) == TUI_FAILURE)
1066 warning (_("Invalid window height specified.\n%s"),
1067 WIN_HEIGHT_USAGE);
1068 else
1069 tui_update_gdb_sizes ();
1071 else
1072 warning (_("Invalid window height specified.\n%s"),
1073 WIN_HEIGHT_USAGE);
1077 else
1078 printf_filtered (WIN_HEIGHT_USAGE);
1080 if (buf != (char *) NULL)
1081 xfree (buf);
1083 else
1084 printf_filtered (WIN_HEIGHT_USAGE);
1087 /* Set the height of the specified window, with va_list. */
1088 static void
1089 tui_set_win_height_command (char *arg, int from_tty)
1091 /* Make sure the curses mode is enabled. */
1092 tui_enable ();
1093 tui_set_win_height (arg, from_tty);
1097 /* XDB Compatibility command for setting the window height. This will
1098 increase or decrease the command window by the specified
1099 amount. */
1100 static void
1101 tui_xdb_set_win_height (char *arg, int from_tty)
1103 /* Make sure the curses mode is enabled. */
1104 tui_enable ();
1105 if (arg != (char *) NULL)
1107 int input_no = atoi (arg);
1109 if (input_no > 0)
1110 { /* Add 1 for the locator. */
1111 int new_height = tui_term_height () - (input_no + 1);
1113 if (!new_height_ok (tui_win_list[CMD_WIN], new_height)
1114 || tui_adjust_win_heights (tui_win_list[CMD_WIN],
1115 new_height) == TUI_FAILURE)
1116 warning (_("Invalid window height specified.\n%s"),
1117 XDBWIN_HEIGHT_USAGE);
1119 else
1120 warning (_("Invalid window height specified.\n%s"),
1121 XDBWIN_HEIGHT_USAGE);
1123 else
1124 warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
1127 /* Set the height of the specified window, with va_list. */
1128 static void
1129 tui_xdb_set_win_height_command (char *arg, int from_tty)
1131 tui_xdb_set_win_height (arg, from_tty);
1135 /* Function to adjust all window heights around the primary. */
1136 static enum tui_status
1137 tui_adjust_win_heights (struct tui_win_info *primary_win_info,
1138 int new_height)
1140 enum tui_status status = TUI_FAILURE;
1142 if (new_height_ok (primary_win_info, new_height))
1144 status = TUI_SUCCESS;
1145 if (new_height != primary_win_info->generic.height)
1147 int diff;
1148 struct tui_win_info *win_info;
1149 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
1150 enum tui_layout_type cur_layout = tui_current_layout ();
1152 diff = (new_height - primary_win_info->generic.height) * (-1);
1153 if (cur_layout == SRC_COMMAND
1154 || cur_layout == DISASSEM_COMMAND)
1156 struct tui_win_info *src_win_info;
1158 make_invisible_and_set_new_height (primary_win_info, new_height);
1159 if (primary_win_info->generic.type == CMD_WIN)
1161 win_info = (tui_source_windows ())->list[0];
1162 src_win_info = win_info;
1164 else
1166 win_info = tui_win_list[CMD_WIN];
1167 src_win_info = primary_win_info;
1169 make_invisible_and_set_new_height (win_info,
1170 win_info->generic.height + diff);
1171 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1172 make_visible_with_new_height (win_info);
1173 make_visible_with_new_height (primary_win_info);
1174 if (src_win_info->generic.content_size <= 0)
1175 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1177 else
1179 struct tui_win_info *first_win;
1180 struct tui_win_info *second_win;
1182 if (cur_layout == SRC_DISASSEM_COMMAND)
1184 first_win = TUI_SRC_WIN;
1185 second_win = TUI_DISASM_WIN;
1187 else
1189 first_win = TUI_DATA_WIN;
1190 second_win = (tui_source_windows ())->list[0];
1192 if (primary_win_info == TUI_CMD_WIN)
1193 { /* Split the change in height accross the 1st & 2nd
1194 windows, adjusting them as well. */
1195 /* Subtract the locator. */
1196 int first_split_diff = diff / 2;
1197 int second_split_diff = first_split_diff;
1199 if (diff % 2)
1201 if (first_win->generic.height >
1202 second_win->generic.height)
1203 if (diff < 0)
1204 first_split_diff--;
1205 else
1206 first_split_diff++;
1207 else
1209 if (diff < 0)
1210 second_split_diff--;
1211 else
1212 second_split_diff++;
1215 /* Make sure that the minimum hieghts are
1216 honored. */
1217 while ((first_win->generic.height + first_split_diff) < 3)
1219 first_split_diff++;
1220 second_split_diff--;
1222 while ((second_win->generic.height + second_split_diff) < 3)
1224 second_split_diff++;
1225 first_split_diff--;
1227 make_invisible_and_set_new_height (
1228 first_win,
1229 first_win->generic.height + first_split_diff);
1230 second_win->generic.origin.y = first_win->generic.height - 1;
1231 make_invisible_and_set_new_height (
1232 second_win, second_win->generic.height + second_split_diff);
1233 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1234 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1236 else
1238 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1239 { /* If there is no way to increase the command
1240 window take real estate from the 1st or 2nd
1241 window. */
1242 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1244 int i;
1245 for (i = TUI_CMD_WIN->generic.height + diff;
1246 (i < 1); i++)
1247 if (primary_win_info == first_win)
1248 second_win->generic.height--;
1249 else
1250 first_win->generic.height--;
1253 if (primary_win_info == first_win)
1254 make_invisible_and_set_new_height (first_win, new_height);
1255 else
1256 make_invisible_and_set_new_height (
1257 first_win,
1258 first_win->generic.height);
1259 second_win->generic.origin.y = first_win->generic.height - 1;
1260 if (primary_win_info == second_win)
1261 make_invisible_and_set_new_height (second_win, new_height);
1262 else
1263 make_invisible_and_set_new_height (
1264 second_win, second_win->generic.height);
1265 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1266 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1267 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1268 else
1269 make_invisible_and_set_new_height (
1270 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + diff);
1272 make_visible_with_new_height (TUI_CMD_WIN);
1273 make_visible_with_new_height (second_win);
1274 make_visible_with_new_height (first_win);
1275 if (first_win->generic.content_size <= 0)
1276 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1277 if (second_win->generic.content_size <= 0)
1278 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1283 return status;
1287 /* Function make the target window (and auxillary windows associated
1288 with the targer) invisible, and set the new height and
1289 location. */
1290 static void
1291 make_invisible_and_set_new_height (struct tui_win_info *win_info,
1292 int height)
1294 int i;
1295 struct tui_gen_win_info *gen_win_info;
1297 tui_make_invisible (&win_info->generic);
1298 win_info->generic.height = height;
1299 if (height > 1)
1300 win_info->generic.viewport_height = height - 1;
1301 else
1302 win_info->generic.viewport_height = height;
1303 if (win_info != TUI_CMD_WIN)
1304 win_info->generic.viewport_height--;
1306 /* Now deal with the auxillary windows associated with win_info. */
1307 switch (win_info->generic.type)
1309 case SRC_WIN:
1310 case DISASSEM_WIN:
1311 gen_win_info = win_info->detail.source_info.execution_info;
1312 tui_make_invisible (gen_win_info);
1313 gen_win_info->height = height;
1314 gen_win_info->origin.y = win_info->generic.origin.y;
1315 if (height > 1)
1316 gen_win_info->viewport_height = height - 1;
1317 else
1318 gen_win_info->viewport_height = height;
1319 if (win_info != TUI_CMD_WIN)
1320 gen_win_info->viewport_height--;
1322 if (tui_win_has_locator (win_info))
1324 gen_win_info = tui_locator_win_info_ptr ();
1325 tui_make_invisible (gen_win_info);
1326 gen_win_info->origin.y = win_info->generic.origin.y + height;
1328 break;
1329 case DATA_WIN:
1330 /* Delete all data item windows. */
1331 for (i = 0; i < win_info->generic.content_size; i++)
1333 gen_win_info = (struct tui_gen_win_info *) & ((struct tui_win_element *)
1334 win_info->generic.content[i])->which_element.data_window;
1335 tui_delete_win (gen_win_info->handle);
1336 gen_win_info->handle = (WINDOW *) NULL;
1338 break;
1339 default:
1340 break;
1345 /* Function to make the windows with new heights visible. This means
1346 re-creating the windows' content since the window had to be
1347 destroyed to be made invisible. */
1348 static void
1349 make_visible_with_new_height (struct tui_win_info *win_info)
1351 struct symtab *s;
1353 tui_make_visible (&win_info->generic);
1354 tui_check_and_display_highlight_if_needed (win_info);
1355 switch (win_info->generic.type)
1357 case SRC_WIN:
1358 case DISASSEM_WIN:
1359 tui_free_win_content (win_info->detail.source_info.execution_info);
1360 tui_make_visible (win_info->detail.source_info.execution_info);
1361 if (win_info->generic.content != NULL)
1363 struct tui_line_or_address line_or_addr;
1364 struct symtab_and_line cursal
1365 = get_current_source_symtab_and_line ();
1367 line_or_addr = win_info->detail.source_info.start_line_or_addr;
1368 tui_free_win_content (&win_info->generic);
1369 tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE);
1371 else if (deprecated_safe_get_selected_frame () != NULL)
1373 struct tui_line_or_address line;
1374 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
1375 struct frame_info *frame = deprecated_safe_get_selected_frame ();
1377 s = find_pc_symtab (get_frame_pc (frame));
1378 if (win_info->generic.type == SRC_WIN)
1380 line.loa = LOA_LINE;
1381 line.u.line_no = cursal.line;
1383 else
1385 line.loa = LOA_ADDRESS;
1386 find_line_pc (s, cursal.line, &line.u.addr);
1388 tui_update_source_window (win_info, s, line, TRUE);
1390 if (tui_win_has_locator (win_info))
1392 tui_make_visible (tui_locator_win_info_ptr ());
1393 tui_show_locator_content ();
1395 break;
1396 case DATA_WIN:
1397 tui_display_all_data ();
1398 break;
1399 case CMD_WIN:
1400 win_info->detail.command_info.cur_line = 0;
1401 win_info->detail.command_info.curch = 0;
1402 wmove (win_info->generic.handle,
1403 win_info->detail.command_info.cur_line,
1404 win_info->detail.command_info.curch);
1405 break;
1406 default:
1407 break;
1412 static int
1413 new_height_ok (struct tui_win_info *primary_win_info,
1414 int new_height)
1416 int ok = (new_height < tui_term_height ());
1418 if (ok)
1420 int diff;
1421 enum tui_layout_type cur_layout = tui_current_layout ();
1423 diff = (new_height - primary_win_info->generic.height) * (-1);
1424 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1426 ok = ((primary_win_info->generic.type == CMD_WIN
1427 && new_height <= (tui_term_height () - 4)
1428 && new_height >= MIN_CMD_WIN_HEIGHT)
1429 || (primary_win_info->generic.type != CMD_WIN
1430 && new_height <= (tui_term_height () - 2)
1431 && new_height >= MIN_WIN_HEIGHT));
1432 if (ok)
1433 { /* Check the total height. */
1434 struct tui_win_info *win_info;
1436 if (primary_win_info == TUI_CMD_WIN)
1437 win_info = (tui_source_windows ())->list[0];
1438 else
1439 win_info = TUI_CMD_WIN;
1440 ok = ((new_height +
1441 (win_info->generic.height + diff)) <= tui_term_height ());
1444 else
1446 int cur_total_height, total_height, min_height = 0;
1447 struct tui_win_info *first_win;
1448 struct tui_win_info *second_win;
1450 if (cur_layout == SRC_DISASSEM_COMMAND)
1452 first_win = TUI_SRC_WIN;
1453 second_win = TUI_DISASM_WIN;
1455 else
1457 first_win = TUI_DATA_WIN;
1458 second_win = (tui_source_windows ())->list[0];
1460 /* We could simply add all the heights to obtain the same
1461 result but below is more explicit since we subtract 1 for
1462 the line that the first and second windows share, and add
1463 one for the locator. */
1464 total_height = cur_total_height =
1465 (first_win->generic.height + second_win->generic.height - 1)
1466 + TUI_CMD_WIN->generic.height + 1; /* Locator. */
1467 if (primary_win_info == TUI_CMD_WIN)
1469 /* Locator included since first & second win share a line. */
1470 ok = ((first_win->generic.height +
1471 second_win->generic.height + diff) >=
1472 (MIN_WIN_HEIGHT * 2)
1473 && new_height >= MIN_CMD_WIN_HEIGHT);
1474 if (ok)
1476 total_height = new_height +
1477 (first_win->generic.height +
1478 second_win->generic.height + diff);
1479 min_height = MIN_CMD_WIN_HEIGHT;
1482 else
1484 min_height = MIN_WIN_HEIGHT;
1486 /* First see if we can increase/decrease the command
1487 window. And make sure that the command window is at
1488 least 1 line. */
1489 ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
1490 if (!ok)
1491 { /* Looks like we have to increase/decrease one of
1492 the other windows. */
1493 if (primary_win_info == first_win)
1494 ok = (second_win->generic.height + diff) >= min_height;
1495 else
1496 ok = (first_win->generic.height + diff) >= min_height;
1498 if (ok)
1500 if (primary_win_info == first_win)
1501 total_height = new_height +
1502 second_win->generic.height +
1503 TUI_CMD_WIN->generic.height + diff;
1504 else
1505 total_height = new_height +
1506 first_win->generic.height +
1507 TUI_CMD_WIN->generic.height + diff;
1510 /* Now make sure that the proposed total height doesn't
1511 exceed the old total height. */
1512 if (ok)
1513 ok = (new_height >= min_height
1514 && total_height <= cur_total_height);
1518 return ok;
1522 static void
1523 parse_scrolling_args (char *arg,
1524 struct tui_win_info **win_to_scroll,
1525 int *num_to_scroll)
1527 if (num_to_scroll)
1528 *num_to_scroll = 0;
1529 *win_to_scroll = tui_win_with_focus ();
1531 /* First set up the default window to scroll, in case there is no
1532 window name arg. */
1533 if (arg != (char *) NULL)
1535 char *buf, *buf_ptr;
1537 /* Process the number of lines to scroll. */
1538 buf = buf_ptr = xstrdup (arg);
1539 if (isdigit (*buf_ptr))
1541 char *num_str;
1543 num_str = buf_ptr;
1544 buf_ptr = strchr (buf_ptr, ' ');
1545 if (buf_ptr != (char *) NULL)
1547 *buf_ptr = (char) 0;
1548 if (num_to_scroll)
1549 *num_to_scroll = atoi (num_str);
1550 buf_ptr++;
1552 else if (num_to_scroll)
1553 *num_to_scroll = atoi (num_str);
1556 /* Process the window name if one is specified. */
1557 if (buf_ptr != (char *) NULL)
1559 char *wname;
1560 int i;
1562 if (*buf_ptr == ' ')
1563 while (*(++buf_ptr) == ' ')
1566 if (*buf_ptr != (char) 0)
1567 wname = buf_ptr;
1568 else
1569 wname = "?";
1571 /* Validate the window name. */
1572 for (i = 0; i < strlen (wname); i++)
1573 wname[i] = toupper (wname[i]);
1574 *win_to_scroll = tui_partial_win_by_name (wname);
1576 if (*win_to_scroll == (struct tui_win_info *) NULL
1577 || !(*win_to_scroll)->generic.is_visible)
1578 error (_("Invalid window specified. \n\
1579 The window name specified must be valid and visible.\n"));
1580 else if (*win_to_scroll == TUI_CMD_WIN)
1581 *win_to_scroll = (tui_source_windows ())->list[0];
1583 xfree (buf);