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