]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/tui/tui-command.c
2004-02-07 Andrew Cagney <cagney@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / tui / tui-command.c
1 /* Specific command window processing.
2
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
4 Foundation, Inc.
5
6 Contributed by Hewlett-Packard Company.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 #include "defs.h"
26 #include <ctype.h>
27 #include "tui/tui.h"
28 #include "tui/tui-data.h"
29 #include "tui/tui-win.h"
30 #include "tui/tui-io.h"
31
32 #ifdef HAVE_NCURSES_H
33 #include <ncurses.h>
34 #else
35 #ifdef HAVE_CURSES_H
36 #include <curses.h>
37 #endif
38 #endif
39
40
41 /*****************************************
42 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
43 ******************************************/
44
45
46
47 /*****************************************
48 ** PUBLIC FUNCTIONS **
49 ******************************************/
50
51 /* Dispatch the correct tui function based upon the control character. */
52 unsigned int
53 tui_dispatch_ctrl_char (unsigned int ch)
54 {
55 struct tui_win_info *win_info = tui_win_with_focus ();
56 WINDOW *w = TUI_CMD_WIN->generic.handle;
57
58 /*
59 ** If the command window has the logical focus, or no-one does
60 ** assume it is the command window; in this case, pass the
61 ** character on through and do nothing here.
62 */
63 if (win_info == NULL || win_info == TUI_CMD_WIN)
64 return ch;
65 else
66 {
67 unsigned int c = 0, chCopy = ch;
68 register int i;
69 char *term;
70
71 /* If this is an xterm, page next/prev keys aren't returned
72 ** by keypad as a single char, so we must handle them here.
73 ** Seems like a bug in the curses library?
74 */
75 term = (char *) getenv ("TERM");
76 for (i = 0; (term && term[i]); i++)
77 term[i] = toupper (term[i]);
78 if ((strcmp (term, "XTERM") == 0) && key_is_start_sequence (ch))
79 {
80 unsigned int pageCh = 0, tmpChar;
81
82 tmpChar = 0;
83 while (!key_is_end_sequence (tmpChar))
84 {
85 tmpChar = (int) wgetch (w);
86 if (tmpChar == ERR)
87 {
88 return ch;
89 }
90 if (!tmpChar)
91 break;
92 if (tmpChar == 53)
93 pageCh = KEY_PPAGE;
94 else if (tmpChar == 54)
95 pageCh = KEY_NPAGE;
96 else
97 {
98 return 0;
99 }
100 }
101 chCopy = pageCh;
102 }
103
104 switch (chCopy)
105 {
106 case KEY_NPAGE:
107 tui_scroll_forward (win_info, 0);
108 break;
109 case KEY_PPAGE:
110 tui_scroll_backward (win_info, 0);
111 break;
112 case KEY_DOWN:
113 case KEY_SF:
114 tui_scroll_forward (win_info, 1);
115 break;
116 case KEY_UP:
117 case KEY_SR:
118 tui_scroll_backward (win_info, 1);
119 break;
120 case KEY_RIGHT:
121 tui_scroll_left (win_info, 1);
122 break;
123 case KEY_LEFT:
124 tui_scroll_right (win_info, 1);
125 break;
126 case '\f':
127 tui_refresh_all_win ();
128 break;
129 default:
130 c = chCopy;
131 break;
132 }
133 return c;
134 }
135 }