TUI: avoid calling strcpy() on identical string objects
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
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 ********************************/
58 static void make_visible_with_new_height (struct tui_win_info *);
59 static void make_invisible_and_set_new_height (struct tui_win_info *,
60 int);
61 static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
62 int);
63 static int new_height_ok (struct tui_win_info *, int);
64 static void tui_set_tab_width_command (char *, int);
65 static void tui_refresh_all_command (char *, int);
66 static void tui_set_win_height_command (char *, int);
67 static void tui_all_windows_info (char *, int);
68 static void tui_set_focus_command (char *, int);
69 static void tui_scroll_forward_command (char *, int);
70 static void tui_scroll_backward_command (char *, int);
71 static void tui_scroll_left_command (char *, int);
72 static void tui_scroll_right_command (char *, int);
73 static 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. */
109 static 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. */
117 static 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
128 struct 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. */
137 struct 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). */
153 struct tui_translate tui_border_kind_translate_vline[] = {
154 { "space", ' ' },
155 { "ascii", '|' },
156 { "acs", -1 },
157 { 0, 0 },
158 { "ascii", '|' }
159 };
160
161 struct tui_translate tui_border_kind_translate_hline[] = {
162 { "space", ' ' },
163 { "ascii", '-' },
164 { "acs", -1 },
165 { 0, 0 },
166 { "ascii", '-' }
167 };
168
169 struct tui_translate tui_border_kind_translate_ulcorner[] = {
170 { "space", ' ' },
171 { "ascii", '+' },
172 { "acs", -1 },
173 { 0, 0 },
174 { "ascii", '+' }
175 };
176
177 struct tui_translate tui_border_kind_translate_urcorner[] = {
178 { "space", ' ' },
179 { "ascii", '+' },
180 { "acs", -1 },
181 { 0, 0 },
182 { "ascii", '+' }
183 };
184
185 struct tui_translate tui_border_kind_translate_llcorner[] = {
186 { "space", ' ' },
187 { "ascii", '+' },
188 { "acs", -1 },
189 { 0, 0 },
190 { "ascii", '+' }
191 };
192
193 struct 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. */
203 const char *tui_active_border_mode = "bold-standout";
204 static void
205 show_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, _("\
211 The attribute mode to use for the active TUI window border is \"%s\".\n"),
212 value);
213 }
214
215 const char *tui_border_mode = "normal";
216 static void
217 show_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, _("\
223 The attribute mode to use for the TUI window borders is \"%s\".\n"),
224 value);
225 }
226
227 const char *tui_border_kind = "acs";
228 static void
229 show_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. */
242 chtype tui_border_vline;
243 chtype tui_border_hline;
244 chtype tui_border_ulcorner;
245 chtype tui_border_urcorner;
246 chtype tui_border_llcorner;
247 chtype tui_border_lrcorner;
248
249 int tui_border_attrs;
250 int tui_active_border_attrs;
251
252 /* Identify the item in the translation table.
253 When the item is not recognized, use the default entry. */
254 static struct tui_translate *
255 translate (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. */
272 int
273 tui_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
318 static void
319 set_tui_cmd (char *args, int from_tty)
320 {
321 }
322
323 static void
324 show_tui_cmd (char *args, int from_tty)
325 {
326 }
327
328 static struct cmd_list_element *tuilist;
329
330 static void
331 tui_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
338 struct cmd_list_element **
339 tui_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. */
350 void
351 tui_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. */
361 extern initialize_file_ftype _initialize_tui_win;
362
363 void
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, _("\
383 Set the width (in characters) of tab stops.\n\
384 Usage: tabset <n>\n"));
385 add_com ("winheight", class_tui, tui_set_win_height_command, _("\
386 Set the height of a specified window.\n\
387 Usage: winheight <win_name> [+ | -] <#lines>\n\
388 Window names are:\n\
389 src : the source window\n\
390 cmd : the command window\n\
391 asm : the disassembly window\n\
392 regs : 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, _("\
397 Set focus to named window or next/prev window.\n\
398 Usage: focus {<win> | next | prev}\n\
399 Valid Window names are:\n\
400 src : the source window\n\
401 asm : the disassembly window\n\
402 regs : the register display\n\
403 cmd : the command window\n"));
404 add_com_alias ("fs", "focus", class_tui, 0);
405 add_com ("+", class_tui, tui_scroll_forward_command, _("\
406 Scroll window forward.\n\
407 Usage: + [win] [n]\n"));
408 add_com ("-", class_tui, tui_scroll_backward_command, _("\
409 Scroll window backward.\n\
410 Usage: - [win] [n]\n"));
411 add_com ("<", class_tui, tui_scroll_left_command, _("\
412 Scroll window text to the left.\n\
413 Usage: < [win] [n]\n"));
414 add_com (">", class_tui, tui_scroll_right_command, _("\
415 Scroll window text to the right.\n\
416 Usage: > [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, _("\
421 Set the kind of border for TUI windows."), _("\
422 Show the kind of border for TUI windows."), _("\
423 This variable controls the border of TUI windows:\n\
424 space use a white space\n\
425 ascii use ascii characters + - | for the border\n\
426 acs 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, _("\
433 Set the attribute mode to use for the TUI window borders."), _("\
434 Show the attribute mode to use for the TUI window borders."), _("\
435 This variable controls the attributes to use for the window borders:\n\
436 normal normal display\n\
437 standout use highlight mode of terminal\n\
438 reverse use reverse video mode\n\
439 half use half bright\n\
440 half-standout use half bright and standout mode\n\
441 bold use extra bright or bold\n\
442 bold-standout use extra bright or bold with standout mode"),
443 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, _("\
449 Set the attribute mode to use for the active TUI window border."), _("\
450 Show the attribute mode to use for the active TUI window border."), _("\
451 This variable controls the attributes to use for the active window border:\n\
452 normal normal display\n\
453 standout use highlight mode of terminal\n\
454 reverse use reverse video mode\n\
455 half use half bright\n\
456 half-standout use half bright and standout mode\n\
457 bold use extra bright or bold\n\
458 bold-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. */
465 void
466 tui_update_gdb_sizes (void)
467 {
468 char cmd[50];
469
470 /* Set to TUI command window dimension or use readline values. */
471 xsnprintf (cmd, sizeof (cmd), "set width %d",
472 tui_active ? TUI_CMD_WIN->generic.width : tui_term_width());
473 execute_command (cmd, 0);
474 xsnprintf (cmd, sizeof (cmd), "set height %d",
475 tui_active ? TUI_CMD_WIN->generic.height : tui_term_height());
476 execute_command (cmd, 0);
477 }
478
479
480 /* Set the logical focus to win_info. */
481 void
482 tui_set_win_focus_to (struct tui_win_info *win_info)
483 {
484 if (win_info != NULL)
485 {
486 struct tui_win_info *win_with_focus = tui_win_with_focus ();
487
488 if (win_with_focus != NULL
489 && win_with_focus->generic.type != CMD_WIN)
490 tui_unhighlight_win (win_with_focus);
491 tui_set_win_with_focus (win_info);
492 if (win_info->generic.type != CMD_WIN)
493 tui_highlight_win (win_info);
494 }
495 }
496
497
498 void
499 tui_scroll_forward (struct tui_win_info *win_to_scroll,
500 int num_to_scroll)
501 {
502 if (win_to_scroll != TUI_CMD_WIN)
503 {
504 int _num_to_scroll = num_to_scroll;
505
506 if (num_to_scroll == 0)
507 _num_to_scroll = win_to_scroll->generic.height - 3;
508
509 /* If we are scrolling the source or disassembly window, do a
510 "psuedo" scroll since not all of the source is in memory,
511 only what is in the viewport. If win_to_scroll is the
512 command window do nothing since the term should handle
513 it. */
514 if (win_to_scroll == TUI_SRC_WIN)
515 tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll);
516 else if (win_to_scroll == TUI_DISASM_WIN)
517 tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll);
518 else if (win_to_scroll == TUI_DATA_WIN)
519 tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll);
520 }
521 }
522
523 void
524 tui_scroll_backward (struct tui_win_info *win_to_scroll,
525 int num_to_scroll)
526 {
527 if (win_to_scroll != TUI_CMD_WIN)
528 {
529 int _num_to_scroll = num_to_scroll;
530
531 if (num_to_scroll == 0)
532 _num_to_scroll = win_to_scroll->generic.height - 3;
533
534 /* If we are scrolling the source or disassembly window, do a
535 "psuedo" scroll since not all of the source is in memory,
536 only what is in the viewport. If win_to_scroll is the
537 command window do nothing since the term should handle
538 it. */
539 if (win_to_scroll == TUI_SRC_WIN)
540 tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll);
541 else if (win_to_scroll == TUI_DISASM_WIN)
542 tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll);
543 else if (win_to_scroll == TUI_DATA_WIN)
544 tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll);
545 }
546 }
547
548
549 void
550 tui_scroll_left (struct tui_win_info *win_to_scroll,
551 int num_to_scroll)
552 {
553 if (win_to_scroll != TUI_CMD_WIN)
554 {
555 int _num_to_scroll = num_to_scroll;
556
557 if (_num_to_scroll == 0)
558 _num_to_scroll = 1;
559
560 /* If we are scrolling the source or disassembly window, do a
561 "psuedo" scroll since not all of the source is in memory,
562 only what is in the viewport. If win_to_scroll is the command
563 window do nothing since the term should handle it. */
564 if (win_to_scroll == TUI_SRC_WIN
565 || win_to_scroll == TUI_DISASM_WIN)
566 tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL,
567 _num_to_scroll);
568 }
569 }
570
571
572 void
573 tui_scroll_right (struct tui_win_info *win_to_scroll,
574 int num_to_scroll)
575 {
576 if (win_to_scroll != TUI_CMD_WIN)
577 {
578 int _num_to_scroll = num_to_scroll;
579
580 if (_num_to_scroll == 0)
581 _num_to_scroll = 1;
582
583 /* If we are scrolling the source or disassembly window, do a
584 "psuedo" scroll since not all of the source is in memory,
585 only what is in the viewport. If win_to_scroll is the command
586 window do nothing since the term should handle it. */
587 if (win_to_scroll == TUI_SRC_WIN
588 || win_to_scroll == TUI_DISASM_WIN)
589 tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL,
590 _num_to_scroll);
591 }
592 }
593
594
595 /* Scroll a window. Arguments are passed through a va_list. */
596 void
597 tui_scroll (enum tui_scroll_direction direction,
598 struct tui_win_info *win_to_scroll,
599 int num_to_scroll)
600 {
601 switch (direction)
602 {
603 case FORWARD_SCROLL:
604 tui_scroll_forward (win_to_scroll, num_to_scroll);
605 break;
606 case BACKWARD_SCROLL:
607 tui_scroll_backward (win_to_scroll, num_to_scroll);
608 break;
609 case LEFT_SCROLL:
610 tui_scroll_left (win_to_scroll, num_to_scroll);
611 break;
612 case RIGHT_SCROLL:
613 tui_scroll_right (win_to_scroll, num_to_scroll);
614 break;
615 default:
616 break;
617 }
618 }
619
620
621 void
622 tui_refresh_all_win (void)
623 {
624 int type;
625
626 clearok (curscr, TRUE);
627 tui_refresh_all (tui_win_list);
628 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
629 {
630 if (tui_win_list[type]
631 && tui_win_list[type]->generic.is_visible)
632 {
633 switch (type)
634 {
635 case SRC_WIN:
636 case DISASSEM_WIN:
637 tui_show_source_content (tui_win_list[type]);
638 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
639 tui_erase_exec_info_content (tui_win_list[type]);
640 tui_update_exec_info (tui_win_list[type]);
641 break;
642 case DATA_WIN:
643 tui_refresh_data_win ();
644 break;
645 default:
646 break;
647 }
648 }
649 }
650 tui_show_locator_content ();
651 }
652
653 void
654 tui_rehighlight_all (void)
655 {
656 int type;
657
658 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
659 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
660 }
661
662 /* Resize all the windows based on the terminal size. This function
663 gets called from within the readline sinwinch handler. */
664 void
665 tui_resize_all (void)
666 {
667 int height_diff, width_diff;
668 int screenheight, screenwidth;
669
670 rl_get_screen_size (&screenheight, &screenwidth);
671 width_diff = screenwidth - tui_term_width ();
672 height_diff = screenheight - tui_term_height ();
673 if (height_diff || width_diff)
674 {
675 enum tui_layout_type cur_layout = tui_current_layout ();
676 struct tui_win_info *win_with_focus = tui_win_with_focus ();
677 struct tui_win_info *first_win;
678 struct tui_win_info *second_win;
679 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
680 int win_type;
681 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
682
683 #ifdef HAVE_RESIZE_TERM
684 resize_term (screenheight, screenwidth);
685 #endif
686 /* Turn keypad off while we resize. */
687 if (win_with_focus != TUI_CMD_WIN)
688 keypad (TUI_CMD_WIN->generic.handle, FALSE);
689 tui_update_gdb_sizes ();
690 tui_set_term_height_to (screenheight);
691 tui_set_term_width_to (screenwidth);
692 if (cur_layout == SRC_DISASSEM_COMMAND
693 || cur_layout == SRC_DATA_COMMAND
694 || cur_layout == DISASSEM_DATA_COMMAND)
695 num_wins_displayed++;
696 split_diff = height_diff / num_wins_displayed;
697 cmd_split_diff = split_diff;
698 if (height_diff % num_wins_displayed)
699 {
700 if (height_diff < 0)
701 cmd_split_diff--;
702 else
703 cmd_split_diff++;
704 }
705 /* Now adjust each window. */
706 /* erase + clearok are used instead of a straightforward clear as
707 AIX 5.3 does not define clear. */
708 erase ();
709 clearok (curscr, TRUE);
710 refresh ();
711 switch (cur_layout)
712 {
713 case SRC_COMMAND:
714 case DISASSEM_COMMAND:
715 first_win = (struct tui_win_info *) (tui_source_windows ())->list[0];
716 first_win->generic.width += width_diff;
717 locator->width += width_diff;
718 /* Check for invalid heights. */
719 if (height_diff == 0)
720 new_height = first_win->generic.height;
721 else if ((first_win->generic.height + split_diff) >=
722 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
723 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
724 else if ((first_win->generic.height + split_diff) <= 0)
725 new_height = MIN_WIN_HEIGHT;
726 else
727 new_height = first_win->generic.height + split_diff;
728
729 locator->origin.y = new_height + 1;
730 make_invisible_and_set_new_height (first_win, new_height);
731 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
732 TUI_CMD_WIN->generic.width += width_diff;
733 new_height = screenheight - TUI_CMD_WIN->generic.origin.y;
734 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
735 make_visible_with_new_height (first_win);
736 make_visible_with_new_height (TUI_CMD_WIN);
737 if (first_win->generic.content_size <= 0)
738 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
739 break;
740 default:
741 if (cur_layout == SRC_DISASSEM_COMMAND)
742 {
743 first_win = TUI_SRC_WIN;
744 first_win->generic.width += width_diff;
745 second_win = TUI_DISASM_WIN;
746 second_win->generic.width += width_diff;
747 }
748 else
749 {
750 first_win = TUI_DATA_WIN;
751 first_win->generic.width += width_diff;
752 second_win = (struct tui_win_info *)
753 (tui_source_windows ())->list[0];
754 second_win->generic.width += width_diff;
755 }
756 /* Change the first window's height/width. */
757 /* Check for invalid heights. */
758 if (height_diff == 0)
759 new_height = first_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 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
764 else if ((first_win->generic.height + split_diff) <= 0)
765 new_height = MIN_WIN_HEIGHT;
766 else
767 new_height = first_win->generic.height + split_diff;
768 make_invisible_and_set_new_height (first_win, new_height);
769
770 locator->width += width_diff;
771
772 /* Change the second window's height/width. */
773 /* Check for invalid heights. */
774 if (height_diff == 0)
775 new_height = second_win->generic.height;
776 else if ((first_win->generic.height +
777 second_win->generic.height + (split_diff * 2)) >=
778 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
779 {
780 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
781 if (new_height % 2)
782 new_height = (new_height / 2) + 1;
783 else
784 new_height /= 2;
785 }
786 else if ((second_win->generic.height + split_diff) <= 0)
787 new_height = MIN_WIN_HEIGHT;
788 else
789 new_height = second_win->generic.height + split_diff;
790 second_win->generic.origin.y = first_win->generic.height - 1;
791 make_invisible_and_set_new_height (second_win, new_height);
792
793 /* Change the command window's height/width. */
794 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
795 make_invisible_and_set_new_height (TUI_CMD_WIN,
796 TUI_CMD_WIN->generic.height
797 + cmd_split_diff);
798 make_visible_with_new_height (first_win);
799 make_visible_with_new_height (second_win);
800 make_visible_with_new_height (TUI_CMD_WIN);
801 if (first_win->generic.content_size <= 0)
802 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
803 if (second_win->generic.content_size <= 0)
804 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
805 break;
806 }
807 /* Now remove all invisible windows, and their content so that
808 they get created again when called for with the new size. */
809 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
810 {
811 if (win_type != CMD_WIN
812 && (tui_win_list[win_type] != NULL)
813 && !tui_win_list[win_type]->generic.is_visible)
814 {
815 tui_free_window (tui_win_list[win_type]);
816 tui_win_list[win_type] = (struct tui_win_info *) NULL;
817 }
818 }
819 /* Turn keypad back on, unless focus is in the command
820 window. */
821 if (win_with_focus != TUI_CMD_WIN)
822 keypad (TUI_CMD_WIN->generic.handle, TRUE);
823 }
824 }
825
826 #ifdef SIGWINCH
827 /* Token for use by TUI's asynchronous SIGWINCH handler. */
828 static struct async_signal_handler *tui_sigwinch_token;
829
830 /* TUI's SIGWINCH signal handler. */
831 static void
832 tui_sigwinch_handler (int signal)
833 {
834 /* Set win_resized to TRUE and asynchronously invoke our resize callback. If
835 the callback is invoked while TUI is active then it ought to successfully
836 resize the screen, resetting win_resized to FALSE. Of course, if the
837 callback is invoked while TUI is inactive then it will do nothing; in that
838 case, win_resized will remain TRUE until we get a chance to synchronously
839 resize the screen from tui_enable(). */
840 mark_async_signal_handler (tui_sigwinch_token);
841 tui_set_win_resized_to (TRUE);
842 }
843
844 /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
845 static void
846 tui_async_resize_screen (gdb_client_data arg)
847 {
848 if (!tui_active)
849 return;
850
851 rl_resize_terminal ();
852 tui_resize_all ();
853 tui_refresh_all_win ();
854 tui_update_gdb_sizes ();
855 tui_set_win_resized_to (FALSE);
856 tui_redisplay_readline ();
857 }
858 #endif
859
860 /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
861 uninstalled when we exit TUI, so the handler should not assume that TUI is
862 always active. */
863 void
864 tui_initialize_win (void)
865 {
866 #ifdef SIGWINCH
867 tui_sigwinch_token
868 = create_async_signal_handler (tui_async_resize_screen, NULL);
869
870 {
871 #ifdef HAVE_SIGACTION
872 struct sigaction old_winch;
873
874 memset (&old_winch, 0, sizeof (old_winch));
875 old_winch.sa_handler = &tui_sigwinch_handler;
876 #ifdef SA_RESTART
877 old_winch.sa_flags = SA_RESTART;
878 #endif
879 sigaction (SIGWINCH, &old_winch, NULL);
880 #else
881 signal (SIGWINCH, &tui_sigwinch_handler);
882 #endif
883 }
884 #endif
885 }
886
887
888 /*************************
889 ** STATIC LOCAL FUNCTIONS
890 **************************/
891
892
893 static void
894 tui_scroll_forward_command (char *arg, int from_tty)
895 {
896 int num_to_scroll = 1;
897 struct tui_win_info *win_to_scroll;
898
899 /* Make sure the curses mode is enabled. */
900 tui_enable ();
901 if (arg == (char *) NULL)
902 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
903 else
904 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
905 tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll);
906 }
907
908
909 static void
910 tui_scroll_backward_command (char *arg, int from_tty)
911 {
912 int num_to_scroll = 1;
913 struct tui_win_info *win_to_scroll;
914
915 /* Make sure the curses mode is enabled. */
916 tui_enable ();
917 if (arg == (char *) NULL)
918 parse_scrolling_args (arg, &win_to_scroll, (int *) NULL);
919 else
920 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
921 tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll);
922 }
923
924
925 static void
926 tui_scroll_left_command (char *arg, int from_tty)
927 {
928 int num_to_scroll;
929 struct tui_win_info *win_to_scroll;
930
931 /* Make sure the curses mode is enabled. */
932 tui_enable ();
933 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
934 tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll);
935 }
936
937
938 static void
939 tui_scroll_right_command (char *arg, int from_tty)
940 {
941 int num_to_scroll;
942 struct tui_win_info *win_to_scroll;
943
944 /* Make sure the curses mode is enabled. */
945 tui_enable ();
946 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
947 tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll);
948 }
949
950
951 /* Set focus to the window named by 'arg'. */
952 static void
953 tui_set_focus (char *arg, int from_tty)
954 {
955 if (arg != (char *) NULL)
956 {
957 char *buf_ptr = (char *) xstrdup (arg);
958 int i;
959 struct tui_win_info *win_info = (struct tui_win_info *) NULL;
960
961 for (i = 0; (i < strlen (buf_ptr)); i++)
962 buf_ptr[i] = toupper (arg[i]);
963
964 if (subset_compare (buf_ptr, "NEXT"))
965 win_info = tui_next_win (tui_win_with_focus ());
966 else if (subset_compare (buf_ptr, "PREV"))
967 win_info = tui_prev_win (tui_win_with_focus ());
968 else
969 win_info = tui_partial_win_by_name (buf_ptr);
970
971 if (win_info == (struct tui_win_info *) NULL
972 || !win_info->generic.is_visible)
973 warning (_("Invalid window specified. \n\
974 The window name specified must be valid and visible.\n"));
975 else
976 {
977 tui_set_win_focus_to (win_info);
978 keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
979 }
980
981 if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
982 tui_refresh_data_win ();
983 xfree (buf_ptr);
984 printf_filtered (_("Focus set to %s window.\n"),
985 tui_win_name ((struct tui_gen_win_info *)
986 tui_win_with_focus ()));
987 }
988 else
989 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
990 }
991
992 static void
993 tui_set_focus_command (char *arg, int from_tty)
994 {
995 /* Make sure the curses mode is enabled. */
996 tui_enable ();
997 tui_set_focus (arg, from_tty);
998 }
999
1000
1001 static void
1002 tui_all_windows_info (char *arg, int from_tty)
1003 {
1004 int type;
1005 struct tui_win_info *win_with_focus = tui_win_with_focus ();
1006
1007 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
1008 if (tui_win_list[type]
1009 && tui_win_list[type]->generic.is_visible)
1010 {
1011 if (win_with_focus == tui_win_list[type])
1012 printf_filtered (" %s\t(%d lines) <has focus>\n",
1013 tui_win_name (&tui_win_list[type]->generic),
1014 tui_win_list[type]->generic.height);
1015 else
1016 printf_filtered (" %s\t(%d lines)\n",
1017 tui_win_name (&tui_win_list[type]->generic),
1018 tui_win_list[type]->generic.height);
1019 }
1020 }
1021
1022
1023 static void
1024 tui_refresh_all_command (char *arg, int from_tty)
1025 {
1026 /* Make sure the curses mode is enabled. */
1027 tui_enable ();
1028
1029 tui_refresh_all_win ();
1030 }
1031
1032
1033 /* Set the tab width of the specified window. */
1034 static void
1035 tui_set_tab_width_command (char *arg, int from_tty)
1036 {
1037 /* Make sure the curses mode is enabled. */
1038 tui_enable ();
1039 if (arg != (char *) NULL)
1040 {
1041 int ts;
1042
1043 ts = atoi (arg);
1044 if (ts > 0)
1045 {
1046 tui_set_default_tab_len (ts);
1047 /* We don't really change the height of any windows, but
1048 calling these 2 functions causes a complete regeneration
1049 and redisplay of the window's contents, which will take
1050 the new tab width into account. */
1051 if (tui_win_list[SRC_WIN]
1052 && tui_win_list[SRC_WIN]->generic.is_visible)
1053 {
1054 make_invisible_and_set_new_height (TUI_SRC_WIN,
1055 TUI_SRC_WIN->generic.height);
1056 make_visible_with_new_height (TUI_SRC_WIN);
1057 }
1058 if (tui_win_list[DISASSEM_WIN]
1059 && tui_win_list[DISASSEM_WIN]->generic.is_visible)
1060 {
1061 make_invisible_and_set_new_height (TUI_DISASM_WIN,
1062 TUI_DISASM_WIN->generic.height);
1063 make_visible_with_new_height (TUI_DISASM_WIN);
1064 }
1065 }
1066 else
1067 warning (_("Tab widths greater than 0 must be specified."));
1068 }
1069 }
1070
1071
1072 /* Set the height of the specified window. */
1073 static void
1074 tui_set_win_height (char *arg, int from_tty)
1075 {
1076 /* Make sure the curses mode is enabled. */
1077 tui_enable ();
1078 if (arg != (char *) NULL)
1079 {
1080 char *buf = xstrdup (arg);
1081 char *buf_ptr = buf;
1082 char *wname = (char *) NULL;
1083 int new_height, i;
1084 struct tui_win_info *win_info;
1085
1086 wname = buf_ptr;
1087 buf_ptr = strchr (buf_ptr, ' ');
1088 if (buf_ptr != (char *) NULL)
1089 {
1090 *buf_ptr = (char) 0;
1091
1092 /* Validate the window name. */
1093 for (i = 0; i < strlen (wname); i++)
1094 wname[i] = toupper (wname[i]);
1095 win_info = tui_partial_win_by_name (wname);
1096
1097 if (win_info == (struct tui_win_info *) NULL
1098 || !win_info->generic.is_visible)
1099 warning (_("Invalid window specified. \n\
1100 The window name specified must be valid and visible.\n"));
1101 else
1102 {
1103 /* Process the size. */
1104 while (*(++buf_ptr) == ' ')
1105 ;
1106
1107 if (*buf_ptr != (char) 0)
1108 {
1109 int negate = FALSE;
1110 int fixed_size = TRUE;
1111 int input_no;;
1112
1113 if (*buf_ptr == '+' || *buf_ptr == '-')
1114 {
1115 if (*buf_ptr == '-')
1116 negate = TRUE;
1117 fixed_size = FALSE;
1118 buf_ptr++;
1119 }
1120 input_no = atoi (buf_ptr);
1121 if (input_no > 0)
1122 {
1123 if (negate)
1124 input_no *= (-1);
1125 if (fixed_size)
1126 new_height = input_no;
1127 else
1128 new_height = win_info->generic.height + input_no;
1129
1130 /* Now change the window's height, and adjust
1131 all other windows around it. */
1132 if (tui_adjust_win_heights (win_info,
1133 new_height) == TUI_FAILURE)
1134 warning (_("Invalid window height specified.\n%s"),
1135 WIN_HEIGHT_USAGE);
1136 else
1137 tui_update_gdb_sizes ();
1138 }
1139 else
1140 warning (_("Invalid window height specified.\n%s"),
1141 WIN_HEIGHT_USAGE);
1142 }
1143 }
1144 }
1145 else
1146 printf_filtered (WIN_HEIGHT_USAGE);
1147
1148 if (buf != (char *) NULL)
1149 xfree (buf);
1150 }
1151 else
1152 printf_filtered (WIN_HEIGHT_USAGE);
1153 }
1154
1155 /* Set the height of the specified window, with va_list. */
1156 static void
1157 tui_set_win_height_command (char *arg, int from_tty)
1158 {
1159 /* Make sure the curses mode is enabled. */
1160 tui_enable ();
1161 tui_set_win_height (arg, from_tty);
1162 }
1163
1164 /* Function to adjust all window heights around the primary. */
1165 static enum tui_status
1166 tui_adjust_win_heights (struct tui_win_info *primary_win_info,
1167 int new_height)
1168 {
1169 enum tui_status status = TUI_FAILURE;
1170
1171 if (new_height_ok (primary_win_info, new_height))
1172 {
1173 status = TUI_SUCCESS;
1174 if (new_height != primary_win_info->generic.height)
1175 {
1176 int diff;
1177 struct tui_win_info *win_info;
1178 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
1179 enum tui_layout_type cur_layout = tui_current_layout ();
1180
1181 diff = (new_height - primary_win_info->generic.height) * (-1);
1182 if (cur_layout == SRC_COMMAND
1183 || cur_layout == DISASSEM_COMMAND)
1184 {
1185 struct tui_win_info *src_win_info;
1186
1187 make_invisible_and_set_new_height (primary_win_info, new_height);
1188 if (primary_win_info->generic.type == CMD_WIN)
1189 {
1190 win_info = (tui_source_windows ())->list[0];
1191 src_win_info = win_info;
1192 }
1193 else
1194 {
1195 win_info = tui_win_list[CMD_WIN];
1196 src_win_info = primary_win_info;
1197 }
1198 make_invisible_and_set_new_height (win_info,
1199 win_info->generic.height + diff);
1200 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1201 make_visible_with_new_height (win_info);
1202 make_visible_with_new_height (primary_win_info);
1203 if (src_win_info->generic.content_size <= 0)
1204 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1205 }
1206 else
1207 {
1208 struct tui_win_info *first_win;
1209 struct tui_win_info *second_win;
1210
1211 if (cur_layout == SRC_DISASSEM_COMMAND)
1212 {
1213 first_win = TUI_SRC_WIN;
1214 second_win = TUI_DISASM_WIN;
1215 }
1216 else
1217 {
1218 first_win = TUI_DATA_WIN;
1219 second_win = (tui_source_windows ())->list[0];
1220 }
1221 if (primary_win_info == TUI_CMD_WIN)
1222 { /* Split the change in height accross the 1st & 2nd
1223 windows, adjusting them as well. */
1224 /* Subtract the locator. */
1225 int first_split_diff = diff / 2;
1226 int second_split_diff = first_split_diff;
1227
1228 if (diff % 2)
1229 {
1230 if (first_win->generic.height >
1231 second_win->generic.height)
1232 if (diff < 0)
1233 first_split_diff--;
1234 else
1235 first_split_diff++;
1236 else
1237 {
1238 if (diff < 0)
1239 second_split_diff--;
1240 else
1241 second_split_diff++;
1242 }
1243 }
1244 /* Make sure that the minimum hieghts are
1245 honored. */
1246 while ((first_win->generic.height + first_split_diff) < 3)
1247 {
1248 first_split_diff++;
1249 second_split_diff--;
1250 }
1251 while ((second_win->generic.height + second_split_diff) < 3)
1252 {
1253 second_split_diff++;
1254 first_split_diff--;
1255 }
1256 make_invisible_and_set_new_height (
1257 first_win,
1258 first_win->generic.height + first_split_diff);
1259 second_win->generic.origin.y = first_win->generic.height - 1;
1260 make_invisible_and_set_new_height (second_win,
1261 second_win->generic.height
1262 + second_split_diff);
1263 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1264 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1265 }
1266 else
1267 {
1268 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1269 { /* If there is no way to increase the command
1270 window take real estate from the 1st or 2nd
1271 window. */
1272 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1273 {
1274 int i;
1275
1276 for (i = TUI_CMD_WIN->generic.height + diff;
1277 (i < 1); i++)
1278 if (primary_win_info == first_win)
1279 second_win->generic.height--;
1280 else
1281 first_win->generic.height--;
1282 }
1283 }
1284 if (primary_win_info == first_win)
1285 make_invisible_and_set_new_height (first_win, new_height);
1286 else
1287 make_invisible_and_set_new_height (
1288 first_win,
1289 first_win->generic.height);
1290 second_win->generic.origin.y = first_win->generic.height - 1;
1291 if (primary_win_info == second_win)
1292 make_invisible_and_set_new_height (second_win, new_height);
1293 else
1294 make_invisible_and_set_new_height (
1295 second_win, second_win->generic.height);
1296 TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1;
1297 if ((TUI_CMD_WIN->generic.height + diff) < 1)
1298 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1299 else
1300 make_invisible_and_set_new_height (TUI_CMD_WIN,
1301 TUI_CMD_WIN->generic.height + diff);
1302 }
1303 make_visible_with_new_height (TUI_CMD_WIN);
1304 make_visible_with_new_height (second_win);
1305 make_visible_with_new_height (first_win);
1306 if (first_win->generic.content_size <= 0)
1307 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1308 if (second_win->generic.content_size <= 0)
1309 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1310 }
1311 }
1312 }
1313
1314 return status;
1315 }
1316
1317
1318 /* Function make the target window (and auxillary windows associated
1319 with the targer) invisible, and set the new height and
1320 location. */
1321 static void
1322 make_invisible_and_set_new_height (struct tui_win_info *win_info,
1323 int height)
1324 {
1325 int i;
1326 struct tui_gen_win_info *gen_win_info;
1327
1328 tui_make_invisible (&win_info->generic);
1329 win_info->generic.height = height;
1330 if (height > 1)
1331 win_info->generic.viewport_height = height - 1;
1332 else
1333 win_info->generic.viewport_height = height;
1334 if (win_info != TUI_CMD_WIN)
1335 win_info->generic.viewport_height--;
1336
1337 /* Now deal with the auxillary windows associated with win_info. */
1338 switch (win_info->generic.type)
1339 {
1340 case SRC_WIN:
1341 case DISASSEM_WIN:
1342 gen_win_info = win_info->detail.source_info.execution_info;
1343 tui_make_invisible (gen_win_info);
1344 gen_win_info->height = height;
1345 gen_win_info->origin.y = win_info->generic.origin.y;
1346 if (height > 1)
1347 gen_win_info->viewport_height = height - 1;
1348 else
1349 gen_win_info->viewport_height = height;
1350 if (win_info != TUI_CMD_WIN)
1351 gen_win_info->viewport_height--;
1352
1353 if (tui_win_has_locator (win_info))
1354 {
1355 gen_win_info = tui_locator_win_info_ptr ();
1356 tui_make_invisible (gen_win_info);
1357 gen_win_info->origin.y = win_info->generic.origin.y + height;
1358 }
1359 break;
1360 case DATA_WIN:
1361 /* Delete all data item windows. */
1362 for (i = 0; i < win_info->generic.content_size; i++)
1363 {
1364 gen_win_info = (struct tui_gen_win_info *)
1365 &((struct tui_win_element *)
1366 win_info->generic.content[i])->which_element.data_window;
1367 tui_delete_win (gen_win_info->handle);
1368 gen_win_info->handle = (WINDOW *) NULL;
1369 }
1370 break;
1371 default:
1372 break;
1373 }
1374 }
1375
1376
1377 /* Function to make the windows with new heights visible. This means
1378 re-creating the windows' content since the window had to be
1379 destroyed to be made invisible. */
1380 static void
1381 make_visible_with_new_height (struct tui_win_info *win_info)
1382 {
1383 struct symtab *s;
1384
1385 tui_make_visible (&win_info->generic);
1386 tui_check_and_display_highlight_if_needed (win_info);
1387 switch (win_info->generic.type)
1388 {
1389 case SRC_WIN:
1390 case DISASSEM_WIN:
1391 tui_free_win_content (win_info->detail.source_info.execution_info);
1392 tui_make_visible (win_info->detail.source_info.execution_info);
1393 if (win_info->generic.content != NULL)
1394 {
1395 struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
1396 struct tui_line_or_address line_or_addr;
1397 struct symtab_and_line cursal
1398 = get_current_source_symtab_and_line ();
1399
1400 line_or_addr = win_info->detail.source_info.start_line_or_addr;
1401 tui_free_win_content (&win_info->generic);
1402 tui_update_source_window (win_info, gdbarch,
1403 cursal.symtab, line_or_addr, TRUE);
1404 }
1405 else if (deprecated_safe_get_selected_frame () != NULL)
1406 {
1407 struct tui_line_or_address line;
1408 struct symtab_and_line cursal
1409 = get_current_source_symtab_and_line ();
1410 struct frame_info *frame = deprecated_safe_get_selected_frame ();
1411 struct gdbarch *gdbarch = get_frame_arch (frame);
1412
1413 s = find_pc_line_symtab (get_frame_pc (frame));
1414 if (win_info->generic.type == SRC_WIN)
1415 {
1416 line.loa = LOA_LINE;
1417 line.u.line_no = cursal.line;
1418 }
1419 else
1420 {
1421 line.loa = LOA_ADDRESS;
1422 find_line_pc (s, cursal.line, &line.u.addr);
1423 }
1424 tui_update_source_window (win_info, gdbarch, s, line, TRUE);
1425 }
1426 if (tui_win_has_locator (win_info))
1427 {
1428 tui_make_visible (tui_locator_win_info_ptr ());
1429 tui_show_locator_content ();
1430 }
1431 break;
1432 case DATA_WIN:
1433 tui_display_all_data ();
1434 break;
1435 case CMD_WIN:
1436 win_info->detail.command_info.cur_line = 0;
1437 win_info->detail.command_info.curch = 0;
1438 #ifdef HAVE_WRESIZE
1439 wresize (TUI_CMD_WIN->generic.handle,
1440 TUI_CMD_WIN->generic.height,
1441 TUI_CMD_WIN->generic.width);
1442 #endif
1443 mvwin (TUI_CMD_WIN->generic.handle,
1444 TUI_CMD_WIN->generic.origin.y,
1445 TUI_CMD_WIN->generic.origin.x);
1446 wmove (win_info->generic.handle,
1447 win_info->detail.command_info.cur_line,
1448 win_info->detail.command_info.curch);
1449 break;
1450 default:
1451 break;
1452 }
1453 }
1454
1455
1456 static int
1457 new_height_ok (struct tui_win_info *primary_win_info,
1458 int new_height)
1459 {
1460 int ok = (new_height < tui_term_height ());
1461
1462 if (ok)
1463 {
1464 int diff;
1465 enum tui_layout_type cur_layout = tui_current_layout ();
1466
1467 diff = (new_height - primary_win_info->generic.height) * (-1);
1468 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1469 {
1470 ok = ((primary_win_info->generic.type == CMD_WIN
1471 && new_height <= (tui_term_height () - 4)
1472 && new_height >= MIN_CMD_WIN_HEIGHT)
1473 || (primary_win_info->generic.type != CMD_WIN
1474 && new_height <= (tui_term_height () - 2)
1475 && new_height >= MIN_WIN_HEIGHT));
1476 if (ok)
1477 { /* Check the total height. */
1478 struct tui_win_info *win_info;
1479
1480 if (primary_win_info == TUI_CMD_WIN)
1481 win_info = (tui_source_windows ())->list[0];
1482 else
1483 win_info = TUI_CMD_WIN;
1484 ok = ((new_height +
1485 (win_info->generic.height + diff)) <= tui_term_height ());
1486 }
1487 }
1488 else
1489 {
1490 int cur_total_height, total_height, min_height = 0;
1491 struct tui_win_info *first_win;
1492 struct tui_win_info *second_win;
1493
1494 if (cur_layout == SRC_DISASSEM_COMMAND)
1495 {
1496 first_win = TUI_SRC_WIN;
1497 second_win = TUI_DISASM_WIN;
1498 }
1499 else
1500 {
1501 first_win = TUI_DATA_WIN;
1502 second_win = (tui_source_windows ())->list[0];
1503 }
1504 /* We could simply add all the heights to obtain the same
1505 result but below is more explicit since we subtract 1 for
1506 the line that the first and second windows share, and add
1507 one for the locator. */
1508 total_height = cur_total_height =
1509 (first_win->generic.height + second_win->generic.height - 1)
1510 + TUI_CMD_WIN->generic.height + 1; /* Locator. */
1511 if (primary_win_info == TUI_CMD_WIN)
1512 {
1513 /* Locator included since first & second win share a line. */
1514 ok = ((first_win->generic.height +
1515 second_win->generic.height + diff) >=
1516 (MIN_WIN_HEIGHT * 2)
1517 && new_height >= MIN_CMD_WIN_HEIGHT);
1518 if (ok)
1519 {
1520 total_height = new_height +
1521 (first_win->generic.height +
1522 second_win->generic.height + diff);
1523 min_height = MIN_CMD_WIN_HEIGHT;
1524 }
1525 }
1526 else
1527 {
1528 min_height = MIN_WIN_HEIGHT;
1529
1530 /* First see if we can increase/decrease the command
1531 window. And make sure that the command window is at
1532 least 1 line. */
1533 ok = ((TUI_CMD_WIN->generic.height + diff) > 0);
1534 if (!ok)
1535 { /* Looks like we have to increase/decrease one of
1536 the other windows. */
1537 if (primary_win_info == first_win)
1538 ok = (second_win->generic.height + diff) >= min_height;
1539 else
1540 ok = (first_win->generic.height + diff) >= min_height;
1541 }
1542 if (ok)
1543 {
1544 if (primary_win_info == first_win)
1545 total_height = new_height +
1546 second_win->generic.height +
1547 TUI_CMD_WIN->generic.height + diff;
1548 else
1549 total_height = new_height +
1550 first_win->generic.height +
1551 TUI_CMD_WIN->generic.height + diff;
1552 }
1553 }
1554 /* Now make sure that the proposed total height doesn't
1555 exceed the old total height. */
1556 if (ok)
1557 ok = (new_height >= min_height
1558 && total_height <= cur_total_height);
1559 }
1560 }
1561
1562 return ok;
1563 }
1564
1565
1566 static void
1567 parse_scrolling_args (char *arg,
1568 struct tui_win_info **win_to_scroll,
1569 int *num_to_scroll)
1570 {
1571 if (num_to_scroll)
1572 *num_to_scroll = 0;
1573 *win_to_scroll = tui_win_with_focus ();
1574
1575 /* First set up the default window to scroll, in case there is no
1576 window name arg. */
1577 if (arg != (char *) NULL)
1578 {
1579 char *buf, *buf_ptr;
1580
1581 /* Process the number of lines to scroll. */
1582 buf = buf_ptr = xstrdup (arg);
1583 if (isdigit (*buf_ptr))
1584 {
1585 char *num_str;
1586
1587 num_str = buf_ptr;
1588 buf_ptr = strchr (buf_ptr, ' ');
1589 if (buf_ptr != (char *) NULL)
1590 {
1591 *buf_ptr = (char) 0;
1592 if (num_to_scroll)
1593 *num_to_scroll = atoi (num_str);
1594 buf_ptr++;
1595 }
1596 else if (num_to_scroll)
1597 *num_to_scroll = atoi (num_str);
1598 }
1599
1600 /* Process the window name if one is specified. */
1601 if (buf_ptr != (char *) NULL)
1602 {
1603 char *wname;
1604 int i;
1605
1606 if (*buf_ptr == ' ')
1607 while (*(++buf_ptr) == ' ')
1608 ;
1609
1610 if (*buf_ptr != (char) 0)
1611 {
1612 wname = buf_ptr;
1613
1614 /* Validate the window name. */
1615 for (i = 0; i < strlen (wname); i++)
1616 wname[i] = toupper (wname[i]);
1617 }
1618 else
1619 wname = "?";
1620
1621 *win_to_scroll = tui_partial_win_by_name (wname);
1622
1623 if (*win_to_scroll == (struct tui_win_info *) NULL
1624 || !(*win_to_scroll)->generic.is_visible)
1625 error (_("Invalid window specified. \n\
1626 The window name specified must be valid and visible.\n"));
1627 else if (*win_to_scroll == TUI_CMD_WIN)
1628 *win_to_scroll = (tui_source_windows ())->list[0];
1629 }
1630 xfree (buf);
1631 }
1632 }
This page took 0.064407 seconds and 4 git commands to generate.