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