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