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