* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
[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 #ifdef __STDC__
45 tuiDispatchCtrlChar (
46 unsigned int ch)
47 #else
48 tuiDispatchCtrlChar (ch)
49 unsigned int ch;
50 #endif
51 {
52 TuiWinInfoPtr winInfo = tuiWinWithFocus ();
53
54 /*
55 ** If the command window has the logical focus, or no-one does
56 ** assume it is the command window; in this case, pass the
57 ** character on through and do nothing here.
58 */
59 if (winInfo == (TuiWinInfoPtr) NULL || winInfo == cmdWin)
60 return ch;
61 else
62 {
63 unsigned int c = 0, chCopy = ch;
64 register int i;
65 char *term;
66
67 /* If this is an xterm, page next/prev keys aren't returned
68 ** by keypad as a single char, so we must handle them here.
69 ** Seems like a bug in the curses library?
70 */
71 term = (char *) getenv ("TERM");
72 for (i = 0; (term && term[i]); i++)
73 term[i] = toupper (term[i]);
74 if ((strcmp (term, "XTERM") == 0) && m_isStartSequence (ch))
75 {
76 unsigned int pageCh = 0, tmpChar;
77
78 tmpChar = 0;
79 while (!m_isEndSequence (tmpChar))
80 {
81 tmpChar = (int) wgetch (cmdWin->generic.handle);
82 if (!tmpChar)
83 break;
84 if (tmpChar == 53)
85 pageCh = KEY_PPAGE;
86 else if (tmpChar == 54)
87 pageCh = KEY_NPAGE;
88 }
89 chCopy = pageCh;
90 }
91
92 switch (chCopy)
93 {
94 case KEY_NPAGE:
95 tuiScrollForward (winInfo, 0);
96 break;
97 case KEY_PPAGE:
98 tuiScrollBackward (winInfo, 0);
99 break;
100 case KEY_DOWN:
101 case KEY_SF:
102 tuiScrollForward (winInfo, 1);
103 break;
104 case KEY_UP:
105 case KEY_SR:
106 tuiScrollBackward (winInfo, 1);
107 break;
108 case KEY_RIGHT:
109 tuiScrollLeft (winInfo, 1);
110 break;
111 case KEY_LEFT:
112 tuiScrollRight (winInfo, 1);
113 break;
114 case '\f':
115 tuiRefreshAll ();
116 break;
117 default:
118 c = chCopy;
119 break;
120 }
121 return c;
122 }
123 } /* tuiDispatchCtrlChar */
124
125
126 /*
127 ** tuiIncrCommandCharCountBy()
128 ** Increment the current character count in the command window,
129 ** checking for overflow. Returns the new value of the char count.
130 */
131 int
132 #ifdef __STDC__
133 tuiIncrCommandCharCountBy (
134 int count)
135 #else
136 tuiIncrCommandCharCountBy (count)
137 int count;
138 #endif
139 {
140 if (tui_version)
141 {
142 if ((count + cmdWin->detail.commandInfo.curch) >= cmdWin->generic.width)
143 cmdWin->detail.commandInfo.curch =
144 (count + cmdWin->detail.commandInfo.curch) - cmdWin->generic.width;
145 else
146 cmdWin->detail.commandInfo.curch += count;
147 }
148
149 return cmdWin->detail.commandInfo.curch;
150 } /* tuiIncrCommandCharCountBy */
151
152
153 /*
154 ** tuiDecrCommandCharCountBy()
155 ** Decrement the current character count in the command window,
156 ** checking for overflow. Returns the new value of the char count.
157 */
158 int
159 #ifdef __STDC__
160 tuiDecrCommandCharCountBy (
161 int count)
162 #else
163 tuiDecrCommandCharCountBy (count)
164 int count;
165 #endif
166 {
167 if (tui_version)
168 {
169 if ((cmdWin->detail.commandInfo.curch - count) < 0)
170 cmdWin->detail.commandInfo.curch =
171 cmdWin->generic.width + (cmdWin->detail.commandInfo.curch - count);
172 else
173 cmdWin->detail.commandInfo.curch -= count;
174 }
175
176 return cmdWin->detail.commandInfo.curch;
177 } /* tuiDecrCommandCharCountBy */
178
179
180 /*
181 ** tuiSetCommandCharCountTo()
182 ** Set the character count to count.
183 */
184 int
185 #ifdef __STDC__
186 tuiSetCommandCharCountTo (
187 int count)
188 #else
189 tuiSetCommandCharCountTo (count)
190 int count;
191 #endif
192 {
193 if (tui_version)
194 {
195 if (count > cmdWin->generic.width - 1)
196 {
197 cmdWin->detail.commandInfo.curch = 0;
198 tuiIncrCommandCharCountBy (count);
199 }
200 else
201 cmdWin->detail.commandInfo.curch -= count;
202 }
203
204 return cmdWin->detail.commandInfo.curch;
205 } /* tuiSetCommandCharCountTo */
206
207
208
209 /*
210 ** tuiClearCommandCharCount()
211 ** Clear the character count to count.
212 */
213 int
214 #ifdef __STDC__
215 tuiClearCommandCharCount (void)
216 #else
217 tuiClearCommandCharCount ()
218 #endif
219 {
220 if (tui_version)
221 cmdWin->detail.commandInfo.curch = 0;
222
223 return cmdWin->detail.commandInfo.curch;
224 } /* tuiClearCommandCharCount */
225
226
227
228 /*****************************************
229 ** STATIC LOCAL FUNCTIONS **
230 ******************************************/
This page took 0.045398 seconds and 4 git commands to generate.