* tuiWin.c, tui.c, tuiCommand.c: Use ansi prototype.
[deliverable/binutils-gdb.git] / gdb / tui / tuiCommand.c
1 /* Specific command window processing.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "tui.h"
24 #include "tuiData.h"
25 #include "tuiWin.h"
26 #include "tuiIO.h"
27
28
29 /*****************************************
30 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
31 ******************************************/
32
33
34
35 /*****************************************
36 ** PUBLIC FUNCTIONS **
37 ******************************************/
38
39 /*
40 ** tuiDispatchCtrlChar().
41 ** Dispatch the correct tui function based upon the control character.
42 */
43 unsigned int
44 tuiDispatchCtrlChar (unsigned int ch)
45 {
46 TuiWinInfoPtr winInfo = tuiWinWithFocus ();
47
48 /*
49 ** If the command window has the logical focus, or no-one does
50 ** assume it is the command window; in this case, pass the
51 ** character on through and do nothing here.
52 */
53 if (winInfo == (TuiWinInfoPtr) NULL || winInfo == cmdWin)
54 return ch;
55 else
56 {
57 unsigned int c = 0, chCopy = ch;
58 register int i;
59 char *term;
60
61 /* If this is an xterm, page next/prev keys aren't returned
62 ** by keypad as a single char, so we must handle them here.
63 ** Seems like a bug in the curses library?
64 */
65 term = (char *) getenv ("TERM");
66 for (i = 0; (term && term[i]); i++)
67 term[i] = toupper (term[i]);
68 if ((strcmp (term, "XTERM") == 0) && m_isStartSequence (ch))
69 {
70 unsigned int pageCh = 0, tmpChar;
71
72 tmpChar = 0;
73 while (!m_isEndSequence (tmpChar))
74 {
75 tmpChar = (int) wgetch (cmdWin->generic.handle);
76 if (!tmpChar)
77 break;
78 if (tmpChar == 53)
79 pageCh = KEY_PPAGE;
80 else if (tmpChar == 54)
81 pageCh = KEY_NPAGE;
82 }
83 chCopy = pageCh;
84 }
85
86 switch (chCopy)
87 {
88 case KEY_NPAGE:
89 tuiScrollForward (winInfo, 0);
90 break;
91 case KEY_PPAGE:
92 tuiScrollBackward (winInfo, 0);
93 break;
94 case KEY_DOWN:
95 case KEY_SF:
96 tuiScrollForward (winInfo, 1);
97 break;
98 case KEY_UP:
99 case KEY_SR:
100 tuiScrollBackward (winInfo, 1);
101 break;
102 case KEY_RIGHT:
103 tuiScrollLeft (winInfo, 1);
104 break;
105 case KEY_LEFT:
106 tuiScrollRight (winInfo, 1);
107 break;
108 case '\f':
109 tuiRefreshAll ();
110 break;
111 default:
112 c = chCopy;
113 break;
114 }
115 return c;
116 }
117 } /* tuiDispatchCtrlChar */
118
119
120 /*
121 ** tuiIncrCommandCharCountBy()
122 ** Increment the current character count in the command window,
123 ** checking for overflow. Returns the new value of the char count.
124 */
125 int
126 tuiIncrCommandCharCountBy (int count)
127 {
128 if (tui_version)
129 {
130 if ((count + cmdWin->detail.commandInfo.curch) >= cmdWin->generic.width)
131 cmdWin->detail.commandInfo.curch =
132 (count + cmdWin->detail.commandInfo.curch) - cmdWin->generic.width;
133 else
134 cmdWin->detail.commandInfo.curch += count;
135 }
136
137 return cmdWin->detail.commandInfo.curch;
138 } /* tuiIncrCommandCharCountBy */
139
140
141 /*
142 ** tuiDecrCommandCharCountBy()
143 ** Decrement the current character count in the command window,
144 ** checking for overflow. Returns the new value of the char count.
145 */
146 int
147 tuiDecrCommandCharCountBy (int count)
148 {
149 if (tui_version)
150 {
151 if ((cmdWin->detail.commandInfo.curch - count) < 0)
152 cmdWin->detail.commandInfo.curch =
153 cmdWin->generic.width + (cmdWin->detail.commandInfo.curch - count);
154 else
155 cmdWin->detail.commandInfo.curch -= count;
156 }
157
158 return cmdWin->detail.commandInfo.curch;
159 } /* tuiDecrCommandCharCountBy */
160
161
162 /*
163 ** tuiSetCommandCharCountTo()
164 ** Set the character count to count.
165 */
166 int
167 tuiSetCommandCharCountTo (int count)
168 {
169 if (tui_version)
170 {
171 if (count > cmdWin->generic.width - 1)
172 {
173 cmdWin->detail.commandInfo.curch = 0;
174 tuiIncrCommandCharCountBy (count);
175 }
176 else
177 cmdWin->detail.commandInfo.curch -= count;
178 }
179
180 return cmdWin->detail.commandInfo.curch;
181 } /* tuiSetCommandCharCountTo */
182
183
184
185 /*
186 ** tuiClearCommandCharCount()
187 ** Clear the character count to count.
188 */
189 int
190 tuiClearCommandCharCount (void)
191 {
192 if (tui_version)
193 cmdWin->detail.commandInfo.curch = 0;
194
195 return cmdWin->detail.commandInfo.curch;
196 } /* tuiClearCommandCharCount */
197
198
199
200 /*****************************************
201 ** STATIC LOCAL FUNCTIONS **
202 ******************************************/
This page took 0.032267 seconds and 4 git commands to generate.