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