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