]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/tui/tui-win.c
2005-11-01 Andrew Stubbs <andrew.stubbs@st.com>
[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 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
231 updated 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 int screenheight, screenwidth;
454
455 rl_get_screen_size (&screenheight, &screenwidth);
456 /* Set to TUI command window dimension or use readline values. */
457 sprintf (cmd, "set width %d",
458 tui_active ? TUI_CMD_WIN->generic.width : screenwidth);
459 execute_command (cmd, 0);
460 sprintf (cmd, "set height %d",
461 tui_active ? TUI_CMD_WIN->generic.height : screenheight);
462 execute_command (cmd, 0);
463 }
464
465
466 /* Set the logical focus to win_info. */
467 void
468 tui_set_win_focus_to (struct tui_win_info * win_info)
469 {
470 if (win_info != NULL)
471 {
472 struct tui_win_info * win_with_focus = tui_win_with_focus ();
473
474 if (win_with_focus != NULL
475 && win_with_focus->generic.type != CMD_WIN)
476 tui_unhighlight_win (win_with_focus);
477 tui_set_win_with_focus (win_info);
478 if (win_info->generic.type != CMD_WIN)
479 tui_highlight_win (win_info);
480 }
481 }
482
483
484 void
485 tui_scroll_forward (struct tui_win_info * win_to_scroll, int num_to_scroll)
486 {
487 if (win_to_scroll != TUI_CMD_WIN)
488 {
489 int _num_to_scroll = num_to_scroll;
490
491 if (num_to_scroll == 0)
492 _num_to_scroll = win_to_scroll->generic.height - 3;
493 /*
494 ** If we are scrolling the source or disassembly window, do a
495 ** "psuedo" scroll since not all of the source is in memory,
496 ** only what is in the viewport. If win_to_scroll is the
497 ** command window do nothing since the term should handle it.
498 */
499 if (win_to_scroll == TUI_SRC_WIN)
500 tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
501 else if (win_to_scroll == TUI_DISASM_WIN)
502 tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
503 else if (win_to_scroll == TUI_DATA_WIN)
504 tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
505 }
506 }
507
508 void
509 tui_scroll_backward (struct tui_win_info * win_to_scroll, int num_to_scroll)
510 {
511 if (win_to_scroll != TUI_CMD_WIN)
512 {
513 int _num_to_scroll = num_to_scroll;
514
515 if (num_to_scroll == 0)
516 _num_to_scroll = win_to_scroll->generic.height - 3;
517 /*
518 ** If we are scrolling the source or disassembly window, do a
519 ** "psuedo" scroll since not all of the source is in memory,
520 ** only what is in the viewport. If win_to_scroll is the
521 ** command window do nothing since the term should handle it.
522 */
523 if (win_to_scroll == TUI_SRC_WIN)
524 tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
525 else if (win_to_scroll == TUI_DISASM_WIN)
526 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
527 else if (win_to_scroll == TUI_DATA_WIN)
528 tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
529 }
530 }
531
532
533 void
534 tui_scroll_left (struct tui_win_info * win_to_scroll, int num_to_scroll)
535 {
536 if (win_to_scroll != TUI_CMD_WIN)
537 {
538 int _num_to_scroll = num_to_scroll;
539
540 if (_num_to_scroll == 0)
541 _num_to_scroll = 1;
542 /*
543 ** If we are scrolling the source or disassembly window, do a
544 ** "psuedo" scroll since not all of the source is in memory,
545 ** only what is in the viewport. If win_to_scroll is the
546 ** command window do nothing since the term should handle it.
547 */
548 if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN)
549 tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL, _num_to_scroll);
550 }
551 }
552
553
554 void
555 tui_scroll_right (struct tui_win_info * win_to_scroll, int num_to_scroll)
556 {
557 if (win_to_scroll != TUI_CMD_WIN)
558 {
559 int _num_to_scroll = num_to_scroll;
560
561 if (_num_to_scroll == 0)
562 _num_to_scroll = 1;
563 /*
564 ** If we are scrolling the source or disassembly window, do a
565 ** "psuedo" scroll since not all of the source is in memory,
566 ** only what is in the viewport. If win_to_scroll is the
567 ** command window do nothing since the term should handle it.
568 */
569 if (win_to_scroll == TUI_SRC_WIN || win_to_scroll == TUI_DISASM_WIN)
570 tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL, _num_to_scroll);
571 }
572 }
573
574
575 /* Scroll a window. Arguments are passed through a va_list. */
576 void
577 tui_scroll (enum tui_scroll_direction direction,
578 struct tui_win_info * win_to_scroll,
579 int num_to_scroll)
580 {
581 switch (direction)
582 {
583 case FORWARD_SCROLL:
584 tui_scroll_forward (win_to_scroll, num_to_scroll);
585 break;
586 case BACKWARD_SCROLL:
587 tui_scroll_backward (win_to_scroll, num_to_scroll);
588 break;
589 case LEFT_SCROLL:
590 tui_scroll_left (win_to_scroll, num_to_scroll);
591 break;
592 case RIGHT_SCROLL:
593 tui_scroll_right (win_to_scroll, num_to_scroll);
594 break;
595 default:
596 break;
597 }
598 }
599
600
601 void
602 tui_refresh_all_win (void)
603 {
604 enum tui_win_type type;
605
606 clearok (curscr, TRUE);
607 tui_refresh_all (tui_win_list);
608 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
609 {
610 if (tui_win_list[type] && tui_win_list[type]->generic.is_visible)
611 {
612 switch (type)
613 {
614 case SRC_WIN:
615 case DISASSEM_WIN:
616 tui_show_source_content (tui_win_list[type]);
617 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
618 tui_erase_exec_info_content (tui_win_list[type]);
619 tui_update_exec_info (tui_win_list[type]);
620 break;
621 case DATA_WIN:
622 tui_refresh_data_win ();
623 break;
624 default:
625 break;
626 }
627 }
628 }
629 tui_show_locator_content ();
630 }
631
632
633 /* Resize all the windows based on the the terminal size. This
634 function gets called from within the readline sinwinch handler. */
635 void
636 tui_resize_all (void)
637 {
638 int height_diff, width_diff;
639 int screenheight, screenwidth;
640
641 rl_get_screen_size (&screenheight, &screenwidth);
642 width_diff = screenwidth - tui_term_width ();
643 height_diff = screenheight - tui_term_height ();
644 if (height_diff || width_diff)
645 {
646 enum tui_layout_type cur_layout = tui_current_layout ();
647 struct tui_win_info * win_with_focus = tui_win_with_focus ();
648 struct tui_win_info *first_win;
649 struct tui_win_info *second_win;
650 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
651 enum tui_win_type win_type;
652 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
653
654 #ifdef HAVE_RESIZE_TERM
655 resize_term (screenheight, screenwidth);
656 #endif
657 /* turn keypad off while we resize */
658 if (win_with_focus != TUI_CMD_WIN)
659 keypad (TUI_CMD_WIN->generic.handle, FALSE);
660 tui_update_gdb_sizes ();
661 tui_set_term_height_to (screenheight);
662 tui_set_term_width_to (screenwidth);
663 if (cur_layout == SRC_DISASSEM_COMMAND ||
664 cur_layout == SRC_DATA_COMMAND || cur_layout == DISASSEM_DATA_COMMAND)
665 num_wins_displayed++;
666 split_diff = height_diff / num_wins_displayed;
667 cmd_split_diff = split_diff;
668 if (height_diff % num_wins_displayed)
669 {
670 if (height_diff < 0)
671 cmd_split_diff--;
672 else
673 cmd_split_diff++;
674 }
675 /* now adjust each window */
676 clear ();
677 refresh ();
678 switch (cur_layout)
679 {
680 case SRC_COMMAND:
681 case DISASSEM_COMMAND:
682 first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
683 first_win->generic.width += width_diff;
684 locator->width += width_diff;
685 /* check for invalid heights */
686 if (height_diff == 0)
687 new_height = first_win->generic.height;
688 else if ((first_win->generic.height + split_diff) >=
689 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
690 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
691 else if ((first_win->generic.height + split_diff) <= 0)
692 new_height = MIN_WIN_HEIGHT;
693 else
694 new_height = first_win->generic.height + split_diff;
695
696 make_invisible_and_set_new_height (first_win, new_height);
697 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
698 TUI_CMD_WIN->generic.width += width_diff;
699 new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
700 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
701 make_visible_with_new_height (first_win);
702 make_visible_with_new_height (TUI_CMD_WIN);
703 if (first_win->generic.content_size <= 0)
704 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
705 break;
706 default:
707 if (cur_layout == SRC_DISASSEM_COMMAND)
708 {
709 first_win = TUI_SRC_WIN;
710 first_win->generic.width += width_diff;
711 second_win = TUI_DISASM_WIN;
712 second_win->generic.width += width_diff;
713 }
714 else
715 {
716 first_win = TUI_DATA_WIN;
717 first_win->generic.width += width_diff;
718 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
719 second_win->generic.width += width_diff;
720 }
721 /* Change the first window's height/width */
722 /* check for invalid heights */
723 if (height_diff == 0)
724 new_height = first_win->generic.height;
725 else if ((first_win->generic.height +
726 second_win->generic.height + (split_diff * 2)) >=
727 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
728 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
729 else if ((first_win->generic.height + split_diff) <= 0)
730 new_height = MIN_WIN_HEIGHT;
731 else
732 new_height = first_win->generic.height + split_diff;
733 make_invisible_and_set_new_height (first_win, new_height);
734
735 locator->width += width_diff;
736
737 /* Change the second window's height/width */
738 /* check for invalid heights */
739 if (height_diff == 0)
740 new_height = second_win->generic.height;
741 else if ((first_win->generic.height +
742 second_win->generic.height + (split_diff * 2)) >=
743 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
744 {
745 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
746 if (new_height % 2)
747 new_height = (new_height / 2) + 1;
748 else
749 new_height /= 2;
750 }
751 else if ((second_win->generic.height + split_diff) <= 0)
752 new_height = MIN_WIN_HEIGHT;
753 else
754 new_height = second_win->generic.height + split_diff;
755 second_win->generic.origin.y = first_win->generic.height - 1;
756 make_invisible_and_set_new_height (second_win, new_height);
757
758 /* Change the command window's height/width */
759 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
760 make_invisible_and_set_new_height (
761 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + cmd_split_diff);
762 make_visible_with_new_height (first_win);
763 make_visible_with_new_height (second_win);
764 make_visible_with_new_height (TUI_CMD_WIN);
765 if (first_win->generic.content_size <= 0)
766 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
767 if (second_win->generic.content_size <= 0)
768 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
769 break;
770 }
771 /*
772 ** Now remove all invisible windows, and their content so that they get
773 ** created again when called for with the new size
774 */
775 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
776 {
777 if (win_type != CMD_WIN && (tui_win_list[win_type] != NULL)
778 && !tui_win_list[win_type]->generic.is_visible)
779 {
780 tui_free_window (tui_win_list[win_type]);
781 tui_win_list[win_type] = (struct tui_win_info *) NULL;
782 }
783 }
784 tui_set_win_resized_to (TRUE);
785 /* turn keypad back on, unless focus is in the command window */
786 if (win_with_focus != TUI_CMD_WIN)
787 keypad (TUI_CMD_WIN->generic.handle, TRUE);
788 }
789 }
790
791
792 /* SIGWINCH signal handler for the tui. This signal handler is always
793 called, even when the readline package clears signals because it is
794 set as the old_sigwinch() (TUI only). */
795 void
796 tui_sigwinch_handler (int signal)
797 {
798 /*
799 ** Say that a resize was done so that the readline can do it
800 ** later when appropriate.
801 */
802 tui_set_win_resized_to (TRUE);
803 }
804
805
806
807 /*************************
808 ** STATIC LOCAL FUNCTIONS
809 **************************/
810
811
812 static void
813 tui_scroll_forward_command (char *arg, int from_tty)
814 {
815 int num_to_scroll = 1;
816 struct tui_win_info * win_to_scroll;
817
818 /* Make sure the curses mode is enabled. */
819 tui_enable ();
820 if (arg == (char *) NULL)
821 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
822 else
823 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
824 tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
825 }
826
827
828 static void
829 tui_scroll_backward_command (char *arg, int from_tty)
830 {
831 int num_to_scroll = 1;
832 struct tui_win_info * win_to_scroll;
833
834 /* Make sure the curses mode is enabled. */
835 tui_enable ();
836 if (arg == (char *) NULL)
837 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
838 else
839 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
840 tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
841 }
842
843
844 static void
845 tui_scroll_left_command (char *arg, int from_tty)
846 {
847 int num_to_scroll;
848 struct tui_win_info * win_to_scroll;
849
850 /* Make sure the curses mode is enabled. */
851 tui_enable ();
852 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
853 tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
854 }
855
856
857 static void
858 tui_scroll_right_command (char *arg, int from_tty)
859 {
860 int num_to_scroll;
861 struct tui_win_info * win_to_scroll;
862
863 /* Make sure the curses mode is enabled. */
864 tui_enable ();
865 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
866 tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
867 }
868
869
870 /* Set focus to the window named by 'arg'. */
871 static void
872 tui_set_focus (char *arg, int from_tty)
873 {
874 if (arg != (char *) NULL)
875 {
876 char *buf_ptr = (char *) xstrdup (arg);
877 int i;
878 struct tui_win_info * win_info = (struct tui_win_info *) NULL;
879
880 for (i = 0; (i < strlen (buf_ptr)); i++)
881 buf_ptr[i] = toupper (arg[i]);
882
883 if (subset_compare (buf_ptr, "NEXT"))
884 win_info = tui_next_win (tui_win_with_focus ());
885 else if (subset_compare (buf_ptr, "PREV"))
886 win_info = tui_prev_win (tui_win_with_focus ());
887 else
888 win_info = tui_partial_win_by_name (buf_ptr);
889
890 if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible)
891 warning (_("Invalid window specified. \n\
892 The window name specified must be valid and visible.\n"));
893 else
894 {
895 tui_set_win_focus_to (win_info);
896 keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
897 }
898
899 if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
900 tui_refresh_data_win ();
901 xfree (buf_ptr);
902 printf_filtered (_("Focus set to %s window.\n"),
903 tui_win_name ((struct tui_gen_win_info *) tui_win_with_focus ()));
904 }
905 else
906 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
907 }
908
909 static void
910 tui_set_focus_command (char *arg, int from_tty)
911 {
912 /* Make sure the curses mode is enabled. */
913 tui_enable ();
914 tui_set_focus (arg, from_tty);
915 }
916
917
918 static void
919 tui_all_windows_info (char *arg, int from_tty)
920 {
921 enum tui_win_type type;
922 struct tui_win_info * win_with_focus = tui_win_with_focus ();
923
924 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
925 if (tui_win_list[type] && tui_win_list[type]->generic.is_visible)
926 {
927 if (win_with_focus == tui_win_list[type])
928 printf_filtered (" %s\t(%d lines) <has focus>\n",
929 tui_win_name (&tui_win_list[type]->generic),
930 tui_win_list[type]->generic.height);
931 else
932 printf_filtered (" %s\t(%d lines)\n",
933 tui_win_name (&tui_win_list[type]->generic),
934 tui_win_list[type]->generic.height);
935 }
936 }
937
938
939 static void
940 tui_refresh_all_command (char *arg, int from_tty)
941 {
942 /* Make sure the curses mode is enabled. */
943 tui_enable ();
944
945 tui_refresh_all_win ();
946 }
947
948
949 /* Set the height of the specified window. */
950 static void
951 tui_set_tab_width_command (char *arg, int from_tty)
952 {
953 /* Make sure the curses mode is enabled. */
954 tui_enable ();
955 if (arg != (char *) NULL)
956 {
957 int ts;
958
959 ts = atoi (arg);
960 if (ts > 0)
961 tui_set_default_tab_len (ts);
962 else
963 warning (_("Tab widths greater than 0 must be specified."));
964 }
965 }
966
967
968 /* Set the height of the specified window. */
969 static void
970 tui_set_win_height (char *arg, int from_tty)
971 {
972 /* Make sure the curses mode is enabled. */
973 tui_enable ();
974 if (arg != (char *) NULL)
975 {
976 char *buf = xstrdup (arg);
977 char *buf_ptr = buf;
978 char *wname = (char *) NULL;
979 int new_height, i;
980 struct tui_win_info * win_info;
981
982 wname = buf_ptr;
983 buf_ptr = strchr (buf_ptr, ' ');
984 if (buf_ptr != (char *) NULL)
985 {
986 *buf_ptr = (char) 0;
987
988 /*
989 ** Validate the window name
990 */
991 for (i = 0; i < strlen (wname); i++)
992 wname[i] = toupper (wname[i]);
993 win_info = tui_partial_win_by_name (wname);
994
995 if (win_info == (struct tui_win_info *) NULL || !win_info->generic.is_visible)
996 warning (_("Invalid window specified. \n\
997 The window name specified must be valid and visible.\n"));
998 else
999 {
1000 /* Process the size */
1001 while (*(++buf_ptr) == ' ')
1002 ;
1003
1004 if (*buf_ptr != (char) 0)
1005 {
1006 int negate = FALSE;
1007 int fixed_size = TRUE;
1008 int input_no;;
1009
1010 if (*buf_ptr == '+' || *buf_ptr == '-')
1011 {
1012 if (*buf_ptr == '-')
1013 negate = TRUE;
1014 fixed_size = FALSE;
1015 buf_ptr++;
1016 }
1017 input_no = atoi (buf_ptr);
1018 if (input_no > 0)
1019 {
1020 if (negate)
1021 input_no *= (-1);
1022 if (fixed_size)
1023 new_height = input_no;
1024 else
1025 new_height = win_info->generic.height + input_no;
1026 /*
1027 ** Now change the window's height, and adjust all
1028 ** other windows around it
1029 */
1030 if (tui_adjust_win_heights (win_info,
1031 new_height) == TUI_FAILURE)
1032 warning (_("Invalid window height specified.\n%s"),
1033 WIN_HEIGHT_USAGE);
1034 else
1035 tui_update_gdb_sizes ();
1036 }
1037 else
1038 warning (_("Invalid window height specified.\n%s"),
1039 WIN_HEIGHT_USAGE);
1040 }
1041 }
1042 }
1043 else
1044 printf_filtered (WIN_HEIGHT_USAGE);
1045
1046 if (buf != (char *) NULL)
1047 xfree (buf);
1048 }
1049 else
1050 printf_filtered (WIN_HEIGHT_USAGE);
1051 }
1052
1053 /* Set the height of the specified window, with va_list. */
1054 static void
1055 tui_set_win_height_command (char *arg, int from_tty)
1056 {
1057 /* Make sure the curses mode is enabled. */
1058 tui_enable ();
1059 tui_set_win_height (arg, from_tty);
1060 }
1061
1062
1063 /* XDB Compatibility command for setting the window height. This will
1064 increase or decrease the command window by the specified amount. */
1065 static void
1066 tui_xdb_set_win_height (char *arg, int from_tty)
1067 {
1068 /* Make sure the curses mode is enabled. */
1069 tui_enable ();
1070 if (arg != (char *) NULL)
1071 {
1072 int input_no = atoi (arg);
1073
1074 if (input_no > 0)
1075 { /* Add 1 for the locator */
1076 int new_height = tui_term_height () - (input_no + 1);
1077
1078 if (!new_height_ok (tui_win_list[CMD_WIN], new_height) ||
1079 tui_adjust_win_heights (tui_win_list[CMD_WIN],
1080 new_height) == TUI_FAILURE)
1081 warning (_("Invalid window height specified.\n%s"),
1082 XDBWIN_HEIGHT_USAGE);
1083 }
1084 else
1085 warning (_("Invalid window height specified.\n%s"),
1086 XDBWIN_HEIGHT_USAGE);
1087 }
1088 else
1089 warning (_("Invalid window height specified.\n%s"), XDBWIN_HEIGHT_USAGE);
1090 }
1091
1092 /* Set the height of the specified window, with va_list. */
1093 static void
1094 tui_xdb_set_win_height_command (char *arg, int from_tty)
1095 {
1096 tui_xdb_set_win_height (arg, from_tty);
1097 }
1098
1099
1100 /* Function to adjust all window heights around the primary. */
1101 static enum tui_status
1102 tui_adjust_win_heights (struct tui_win_info * primary_win_info, int new_height)
1103 {
1104 enum tui_status status = TUI_FAILURE;
1105
1106 if (new_height_ok (primary_win_info, new_height))
1107 {
1108 status = TUI_SUCCESS;
1109 if (new_height != primary_win_info->generic.height)
1110 {
1111 int diff;
1112 struct tui_win_info * win_info;
1113 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
1114 enum tui_layout_type cur_layout = tui_current_layout ();
1115
1116 diff = (new_height - primary_win_info->generic.height) * (-1);
1117 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1118 {
1119 struct tui_win_info * src_win_info;
1120
1121 make_invisible_and_set_new_height (primary_win_info, new_height);
1122 if (primary_win_info->generic.type == CMD_WIN)
1123 {
1124 win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
1125 src_win_info = win_info;
1126 }
1127 else
1128 {
1129 win_info = tui_win_list[CMD_WIN];
1130 src_win_info = primary_win_info;
1131 }
1132 make_invisible_and_set_new_height (win_info,
1133 win_info->generic.height + diff);
1134 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1135 make_visible_with_new_height (win_info);
1136 make_visible_with_new_height (primary_win_info);
1137 if (src_win_info->generic.content_size <= 0)
1138 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1139 }
1140 else
1141 {
1142 struct tui_win_info *first_win;
1143 struct tui_win_info *second_win;
1144
1145 if (cur_layout == SRC_DISASSEM_COMMAND)
1146 {
1147 first_win = TUI_SRC_WIN;
1148 second_win = TUI_DISASM_WIN;
1149 }
1150 else
1151 {
1152 first_win = TUI_DATA_WIN;
1153 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
1154 }
1155 if (primary_win_info == TUI_CMD_WIN)
1156 { /*
1157 ** Split the change in height accross the 1st & 2nd windows
1158 ** adjusting them as well.
1159 */
1160 int first_split_diff = diff / 2; /* subtract the locator */
1161 int second_split_diff = first_split_diff;
1162
1163 if (diff % 2)
1164 {
1165 if (first_win->generic.height >
1166 second_win->generic.height)
1167 if (diff < 0)
1168 first_split_diff--;
1169 else
1170 first_split_diff++;
1171 else
1172 {
1173 if (diff < 0)
1174 second_split_diff--;
1175 else
1176 second_split_diff++;
1177 }
1178 }
1179 /* make sure that the minimum hieghts are honored */
1180 while ((first_win->generic.height + first_split_diff) < 3)
1181 {
1182 first_split_diff++;
1183 second_split_diff--;
1184 }
1185 while ((second_win->generic.height + second_split_diff) < 3)
1186 {
1187 second_split_diff++;
1188 first_split_diff--;
1189 }
1190 make_invisible_and_set_new_height (
1191 first_win,
1192 first_win->generic.height + first_split_diff);
1193 second_win->generic.origin.y = first_win->generic.height - 1;
1194 make_invisible_and_set_new_height (
1195 second_win, second_win->generic.height + second_split_diff);
1196 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1197 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1198 }
1199 else
1200 {
1201 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1202 { /*
1203 ** If there is no way to increase the command window
1204 ** take real estate from the 1st or 2nd window.
1205 */
1206 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1207 {
1208 int i;
1209 for (i = TUI_CMD_WIN->generic.height + diff;
1210 (i < 1); i++)
1211 if (primary_win_info == first_win)
1212 second_win->generic.height--;
1213 else
1214 first_win->generic.height--;
1215 }
1216 }
1217 if (primary_win_info == first_win)
1218 make_invisible_and_set_new_height (first_win, new_height);
1219 else
1220 make_invisible_and_set_new_height (
1221 first_win,
1222 first_win->generic.height);
1223 second_win->generic.origin.y = first_win->generic.height - 1;
1224 if (primary_win_info == second_win)
1225 make_invisible_and_set_new_height (second_win, new_height);
1226 else
1227 make_invisible_and_set_new_height (
1228 second_win, second_win->generic.height);
1229 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1230 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1231 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1232 else
1233 make_invisible_and_set_new_height (
1234 TUI_CMD_WIN, TUI_CMD_WIN->generic.height + diff);
1235 }
1236 make_visible_with_new_height (TUI_CMD_WIN);
1237 make_visible_with_new_height (second_win);
1238 make_visible_with_new_height (first_win);
1239 if (first_win->generic.content_size <= 0)
1240 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1241 if (second_win->generic.content_size <= 0)
1242 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1243 }
1244 }
1245 }
1246
1247 return status;
1248 }
1249
1250
1251 /* Function make the target window (and auxillary windows associated
1252 with the targer) invisible, and set the new height and location. */
1253 static void
1254 make_invisible_and_set_new_height (struct tui_win_info * win_info, int height)
1255 {
1256 int i;
1257 struct tui_gen_win_info * gen_win_info;
1258
1259 tui_make_invisible (&win_info->generic);
1260 win_info->generic.height = height;
1261 if (height > 1)
1262 win_info->generic.viewport_height = height - 1;
1263 else
1264 win_info->generic.viewport_height = height;
1265 if (win_info != TUI_CMD_WIN)
1266 win_info->generic.viewport_height--;
1267
1268 /* Now deal with the auxillary windows associated with win_info */
1269 switch (win_info->generic.type)
1270 {
1271 case SRC_WIN:
1272 case DISASSEM_WIN:
1273 gen_win_info = win_info->detail.source_info.execution_info;
1274 tui_make_invisible (gen_win_info);
1275 gen_win_info->height = height;
1276 gen_win_info->origin.y = win_info->generic.origin.y;
1277 if (height > 1)
1278 gen_win_info->viewport_height = height - 1;
1279 else
1280 gen_win_info->viewport_height = height;
1281 if (win_info != TUI_CMD_WIN)
1282 gen_win_info->viewport_height--;
1283
1284 if (tui_win_has_locator (win_info))
1285 {
1286 gen_win_info = tui_locator_win_info_ptr ();
1287 tui_make_invisible (gen_win_info);
1288 gen_win_info->origin.y = win_info->generic.origin.y + height;
1289 }
1290 break;
1291 case DATA_WIN:
1292 /* delete all data item windows */
1293 for (i = 0; i < win_info->generic.content_size; i++)
1294 {
1295 gen_win_info = (struct tui_gen_win_info *) & ((struct tui_win_element *)
1296 win_info->generic.content[i])->which_element.data_window;
1297 tui_delete_win (gen_win_info->handle);
1298 gen_win_info->handle = (WINDOW *) NULL;
1299 }
1300 break;
1301 default:
1302 break;
1303 }
1304 }
1305
1306
1307 /* Function to make the windows with new heights visible. This means
1308 re-creating the windows' content since the window had to be
1309 destroyed to be made invisible. */
1310 static void
1311 make_visible_with_new_height (struct tui_win_info * win_info)
1312 {
1313 struct symtab *s;
1314
1315 tui_make_visible (&win_info->generic);
1316 tui_check_and_display_highlight_if_needed (win_info);
1317 switch (win_info->generic.type)
1318 {
1319 case SRC_WIN:
1320 case DISASSEM_WIN:
1321 tui_free_win_content (win_info->detail.source_info.execution_info);
1322 tui_make_visible (win_info->detail.source_info.execution_info);
1323 if (win_info->generic.content != NULL)
1324 {
1325 struct tui_line_or_address line_or_addr;
1326 struct symtab_and_line cursal
1327 = get_current_source_symtab_and_line ();
1328
1329 line_or_addr = win_info->detail.source_info.start_line_or_addr;
1330 tui_free_win_content (&win_info->generic);
1331 tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE);
1332 }
1333 else if (deprecated_selected_frame != (struct frame_info *) NULL)
1334 {
1335 struct tui_line_or_address line;
1336 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
1337
1338
1339 s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));
1340 if (win_info->generic.type == SRC_WIN)
1341 {
1342 line.loa = LOA_LINE;
1343 line.u.line_no = cursal.line;
1344 }
1345 else
1346 {
1347 line.loa = LOA_ADDRESS;
1348 find_line_pc (s, cursal.line, &line.u.addr);
1349 }
1350 tui_update_source_window (win_info, s, line, TRUE);
1351 }
1352 if (tui_win_has_locator (win_info))
1353 {
1354 tui_make_visible (tui_locator_win_info_ptr ());
1355 tui_show_locator_content ();
1356 }
1357 break;
1358 case DATA_WIN:
1359 tui_display_all_data ();
1360 break;
1361 case CMD_WIN:
1362 win_info->detail.command_info.cur_line = 0;
1363 win_info->detail.command_info.curch = 0;
1364 wmove (win_info->generic.handle,
1365 win_info->detail.command_info.cur_line,
1366 win_info->detail.command_info.curch);
1367 break;
1368 default:
1369 break;
1370 }
1371 }
1372
1373
1374 static int
1375 new_height_ok (struct tui_win_info * primary_win_info, int new_height)
1376 {
1377 int ok = (new_height < tui_term_height ());
1378
1379 if (ok)
1380 {
1381 int diff;
1382 enum tui_layout_type cur_layout = tui_current_layout ();
1383
1384 diff = (new_height - primary_win_info->generic.height) * (-1);
1385 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1386 {
1387 ok = ((primary_win_info->generic.type == CMD_WIN &&
1388 new_height <= (tui_term_height () - 4) &&
1389 new_height >= MIN_CMD_WIN_HEIGHT) ||
1390 (primary_win_info->generic.type != CMD_WIN &&
1391 new_height <= (tui_term_height () - 2) &&
1392 new_height >= MIN_WIN_HEIGHT));
1393 if (ok)
1394 { /* check the total height */
1395 struct tui_win_info * win_info;
1396
1397 if (primary_win_info == TUI_CMD_WIN)
1398 win_info = (struct tui_win_info *) (tui_source_windows ())->list[0];
1399 else
1400 win_info = TUI_CMD_WIN;
1401 ok = ((new_height +
1402 (win_info->generic.height + diff)) <= tui_term_height ());
1403 }
1404 }
1405 else
1406 {
1407 int cur_total_height, total_height, min_height = 0;
1408 struct tui_win_info *first_win;
1409 struct tui_win_info *second_win;
1410
1411 if (cur_layout == SRC_DISASSEM_COMMAND)
1412 {
1413 first_win = TUI_SRC_WIN;
1414 second_win = TUI_DISASM_WIN;
1415 }
1416 else
1417 {
1418 first_win = TUI_DATA_WIN;
1419 second_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
1420 }
1421 /*
1422 ** We could simply add all the heights to obtain the same result
1423 ** but below is more explicit since we subtract 1 for the
1424 ** line that the first and second windows share, and add one
1425 ** for the locator.
1426 */
1427 total_height = cur_total_height =
1428 (first_win->generic.height + second_win->generic.height - 1)
1429 + TUI_CMD_WIN->generic.height + 1 /*locator */ ;
1430 if (primary_win_info == TUI_CMD_WIN)
1431 {
1432 /* locator included since first & second win share a line */
1433 ok = ((first_win->generic.height +
1434 second_win->generic.height + diff) >=
1435 (MIN_WIN_HEIGHT * 2) &&
1436 new_height >= MIN_CMD_WIN_HEIGHT);
1437 if (ok)
1438 {
1439 total_height = new_height + (first_win->generic.height +
1440 second_win->generic.height + diff);
1441 min_height = MIN_CMD_WIN_HEIGHT;
1442 }
1443 }
1444 else
1445 {
1446 min_height = MIN_WIN_HEIGHT;
1447 /*
1448 ** First see if we can increase/decrease the command
1449 ** window. And make sure that the command window is
1450 ** at least 1 line
1451 */
1452 ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
1453 if (!ok)
1454 { /*
1455 ** Looks like we have to increase/decrease one of
1456 ** the other windows
1457 */
1458 if (primary_win_info == first_win)
1459 ok = (second_win->generic.height + diff) >= min_height;
1460 else
1461 ok = (first_win->generic.height + diff) >= min_height;
1462 }
1463 if (ok)
1464 {
1465 if (primary_win_info == first_win)
1466 total_height = new_height +
1467 second_win->generic.height +
1468 TUI_CMD_WIN->generic.height + diff;
1469 else
1470 total_height = new_height +
1471 first_win->generic.height +
1472 TUI_CMD_WIN->generic.height + diff;
1473 }
1474 }
1475 /*
1476 ** Now make sure that the proposed total height doesn't exceed
1477 ** the old total height.
1478 */
1479 if (ok)
1480 ok = (new_height >= min_height && total_height <= cur_total_height);
1481 }
1482 }
1483
1484 return ok;
1485 }
1486
1487
1488 static void
1489 parse_scrolling_args (char *arg, struct tui_win_info * * win_to_scroll,
1490 int *num_to_scroll)
1491 {
1492 if (num_to_scroll)
1493 *num_to_scroll = 0;
1494 *win_to_scroll = tui_win_with_focus ();
1495
1496 /*
1497 ** First set up the default window to scroll, in case there is no
1498 ** window name arg
1499 */
1500 if (arg != (char *) NULL)
1501 {
1502 char *buf, *buf_ptr;
1503
1504 /* process the number of lines to scroll */
1505 buf = buf_ptr = xstrdup (arg);
1506 if (isdigit (*buf_ptr))
1507 {
1508 char *num_str;
1509
1510 num_str = buf_ptr;
1511 buf_ptr = strchr (buf_ptr, ' ');
1512 if (buf_ptr != (char *) NULL)
1513 {
1514 *buf_ptr = (char) 0;
1515 if (num_to_scroll)
1516 *num_to_scroll = atoi (num_str);
1517 buf_ptr++;
1518 }
1519 else if (num_to_scroll)
1520 *num_to_scroll = atoi (num_str);
1521 }
1522
1523 /* process the window name if one is specified */
1524 if (buf_ptr != (char *) NULL)
1525 {
1526 char *wname;
1527 int i;
1528
1529 if (*buf_ptr == ' ')
1530 while (*(++buf_ptr) == ' ')
1531 ;
1532
1533 if (*buf_ptr != (char) 0)
1534 wname = buf_ptr;
1535 else
1536 wname = "?";
1537
1538 /* Validate the window name */
1539 for (i = 0; i < strlen (wname); i++)
1540 wname[i] = toupper (wname[i]);
1541 *win_to_scroll = tui_partial_win_by_name (wname);
1542
1543 if (*win_to_scroll == (struct tui_win_info *) NULL ||
1544 !(*win_to_scroll)->generic.is_visible)
1545 error (_("Invalid window specified. \n\
1546 The window name specified must be valid and visible.\n"));
1547 else if (*win_to_scroll == TUI_CMD_WIN)
1548 *win_to_scroll = (struct tui_win_info *) (tui_source_windows ())->list[0];
1549 }
1550 xfree (buf);
1551 }
1552 }