Fix undefined behavior in TUI's TAB expansion
[deliverable/binutils-gdb.git] / gdb / tui / tui-command.c
CommitLineData
f377b406 1/* Specific command window processing.
f33c6cbf 2
32d0add0 3 Copyright (C) 1998-2015 Free Software Foundation, Inc.
f33c6cbf 4
f377b406
SC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
96ec9981
DJ
22#include "defs.h"
23#include <ctype.h>
d7b2e967
AC
24#include "tui/tui.h"
25#include "tui/tui-data.h"
26#include "tui/tui-win.h"
27#include "tui/tui-io.h"
2c0b251b 28#include "tui/tui-command.h"
f33c6cbf 29
6a83354a 30#include "gdb_curses.h"
c906108c
SS
31/*****************************************
32** STATIC LOCAL FUNCTIONS FORWARD DECLS **
33******************************************/
34
35
36
37/*****************************************
38** PUBLIC FUNCTIONS **
39******************************************/
40
1cc6d956
MS
41/* Dispatch the correct tui function based upon the control
42 character. */
c906108c 43unsigned int
b0a30fce 44tui_dispatch_ctrl_char (unsigned int ch)
c906108c 45{
6d012f14 46 struct tui_win_info *win_info = tui_win_with_focus ();
c906108c 47
ca9d4aea
SC
48 /* Handle the CTRL-L refresh for each window. */
49 if (ch == '\f')
50 tui_refresh_all_win ();
51
52 /* If the command window has the logical focus, or no-one does
1cc6d956
MS
53 assume it is the command window; in this case, pass the character
54 on through and do nothing here. */
6d012f14 55 if (win_info == NULL || win_info == TUI_CMD_WIN)
c906108c
SS
56 return ch;
57 else
58 {
6ba8e26f 59 unsigned int c = 0, ch_copy = ch;
d02c80cd 60 int i;
c906108c
SS
61 char *term;
62
ef5eab5a
MS
63 /* If this is an xterm, page next/prev keys aren't returned by
64 keypad as a single char, so we must handle them here. Seems
65 like a bug in the curses library? */
c906108c 66 term = (char *) getenv ("TERM");
bbe6b987 67 if (term)
c906108c 68 {
bbe6b987
AS
69 for (i = 0; term[i]; i++)
70 term[i] = toupper (term[i]);
e5908723
MS
71 if ((strcmp (term, "XTERM") == 0)
72 && key_is_start_sequence (ch))
c906108c 73 {
bbe6b987
AS
74 unsigned int page_ch = 0;
75 unsigned int tmp_char;
ca9d4aea 76 WINDOW *w = TUI_CMD_WIN->generic.handle;
bbe6b987
AS
77
78 tmp_char = 0;
79 while (!key_is_end_sequence (tmp_char))
9b2d6cca 80 {
bbe6b987
AS
81 tmp_char = (int) wgetch (w);
82 if (tmp_char == ERR)
83 {
84 return ch;
85 }
86 if (!tmp_char)
87 break;
88 if (tmp_char == 53)
89 page_ch = KEY_PPAGE;
90 else if (tmp_char == 54)
91 page_ch = KEY_NPAGE;
92 else
93 {
94 return 0;
95 }
9b2d6cca 96 }
bbe6b987 97 ch_copy = page_ch;
c906108c 98 }
c906108c
SS
99 }
100
6ba8e26f 101 switch (ch_copy)
c906108c
SS
102 {
103 case KEY_NPAGE:
6d012f14 104 tui_scroll_forward (win_info, 0);
c906108c
SS
105 break;
106 case KEY_PPAGE:
6d012f14 107 tui_scroll_backward (win_info, 0);
c906108c
SS
108 break;
109 case KEY_DOWN:
110 case KEY_SF:
6d012f14 111 tui_scroll_forward (win_info, 1);
c906108c
SS
112 break;
113 case KEY_UP:
114 case KEY_SR:
6d012f14 115 tui_scroll_backward (win_info, 1);
c906108c
SS
116 break;
117 case KEY_RIGHT:
6d012f14 118 tui_scroll_left (win_info, 1);
c906108c
SS
119 break;
120 case KEY_LEFT:
6d012f14 121 tui_scroll_right (win_info, 1);
c906108c
SS
122 break;
123 case '\f':
ca9d4aea 124 break;
c906108c 125 default:
6ba8e26f 126 c = ch_copy;
c906108c
SS
127 break;
128 }
129 return c;
130 }
9b2d6cca 131}
518be979
DE
132
133/* See tui-command.h. */
134
135void
136tui_refresh_cmd_win (void)
137{
138 WINDOW *w = TUI_CMD_WIN->generic.handle;
139
140 wrefresh (w);
141
142 /* FIXME: It's not clear why this is here.
143 It was present in the original tui_puts code and is kept in order to
144 not introduce some subtle breakage. */
145 fflush (stdout);
146}
This page took 1.526519 seconds and 4 git commands to generate.