| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: get_wch.c,v 1.7 2009/11/01 22:11:27 dsl Exp $ */ | | 1 | /* $NetBSD: get_wch.c,v 1.8 2009/11/04 21:51:11 dsl Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2005 The NetBSD Foundation Inc. | | 4 | * Copyright (c) 2005 The NetBSD Foundation Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from code donated to the NetBSD Foundation | | 7 | * This code is derived from code donated to the NetBSD Foundation |
8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. | | 8 | * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>. |
9 | * | | 9 | * |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -26,27 +26,27 @@ | | | @@ -26,27 +26,27 @@ |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | * SUCH DAMAGE. | | 34 | * SUCH DAMAGE. |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | __RCSID("$NetBSD: get_wch.c,v 1.7 2009/11/01 22:11:27 dsl Exp $"); | | 39 | __RCSID("$NetBSD: get_wch.c,v 1.8 2009/11/04 21:51:11 dsl Exp $"); |
40 | #endif /* not lint */ | | 40 | #endif /* not lint */ |
41 | | | 41 | |
42 | #include <string.h> | | 42 | #include <string.h> |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
44 | #include <unistd.h> | | 44 | #include <unistd.h> |
45 | #include <stdio.h> | | 45 | #include <stdio.h> |
46 | #include "curses.h" | | 46 | #include "curses.h" |
47 | #include "curses_private.h" | | 47 | #include "curses_private.h" |
48 | #include "keymap.h" | | 48 | #include "keymap.h" |
49 | | | 49 | |
50 | #ifdef HAVE_WCHAR | | 50 | #ifdef HAVE_WCHAR |
51 | static short wstate; /* state of the wcinkey function */ | | 51 | static short wstate; /* state of the wcinkey function */ |
52 | #endif /* HAVE_WCHAR */ | | 52 | #endif /* HAVE_WCHAR */ |
| @@ -89,27 +89,27 @@ inkey(wchar_t *wc, int to, int delay) | | | @@ -89,27 +89,27 @@ inkey(wchar_t *wc, int to, int delay) |
89 | FILE *infd = _cursesi_screen->infd; | | 89 | FILE *infd = _cursesi_screen->infd; |
90 | int *start = &_cursesi_screen->cbuf_head, | | 90 | int *start = &_cursesi_screen->cbuf_head, |
91 | *working = &_cursesi_screen->cbuf_cur, | | 91 | *working = &_cursesi_screen->cbuf_cur, |
92 | *end = &_cursesi_screen->cbuf_tail; | | 92 | *end = &_cursesi_screen->cbuf_tail; |
93 | char *inbuf = &_cursesi_screen->cbuf[ 0 ]; | | 93 | char *inbuf = &_cursesi_screen->cbuf[ 0 ]; |
94 | | | 94 | |
95 | #ifdef DEBUG | | 95 | #ifdef DEBUG |
96 | __CTRACE(__CTRACE_INPUT, "inkey (%p, %d, %d)\n", wc, to, delay); | | 96 | __CTRACE(__CTRACE_INPUT, "inkey (%p, %d, %d)\n", wc, to, delay); |
97 | #endif | | 97 | #endif |
98 | for (;;) { /* loop until we get a complete key sequence */ | | 98 | for (;;) { /* loop until we get a complete key sequence */ |
99 | if (wstate == INKEY_NORM) { | | 99 | if (wstate == INKEY_NORM) { |
100 | if (delay && __timeout(delay) == ERR) | | 100 | if (delay && __timeout(delay) == ERR) |
101 | return ERR; | | 101 | return ERR; |
102 | c = getchar(); | | 102 | c = fgetc(infd); |
103 | if (c == WEOF) { | | 103 | if (c == WEOF) { |
104 | clearerr(infd); | | 104 | clearerr(infd); |
105 | return ERR; | | 105 | return ERR; |
106 | } | | 106 | } |
107 | | | 107 | |
108 | if (delay && (__notimeout() == ERR)) | | 108 | if (delay && (__notimeout() == ERR)) |
109 | return ERR; | | 109 | return ERR; |
110 | | | 110 | |
111 | k = (wchar_t) c; | | 111 | k = (wchar_t) c; |
112 | #ifdef DEBUG | | 112 | #ifdef DEBUG |
113 | __CTRACE(__CTRACE_INPUT, | | 113 | __CTRACE(__CTRACE_INPUT, |
114 | "inkey (wstate normal) got '%s'\n", unctrl(k)); | | 114 | "inkey (wstate normal) got '%s'\n", unctrl(k)); |
115 | #endif | | 115 | #endif |
| @@ -137,27 +137,27 @@ inkey(wchar_t *wc, int to, int delay) | | | @@ -137,27 +137,27 @@ inkey(wchar_t *wc, int to, int delay) |
137 | #endif /* DEBUG */ | | 137 | #endif /* DEBUG */ |
138 | } | | 138 | } |
139 | } else if (wstate == INKEY_ASSEMBLING) { | | 139 | } else if (wstate == INKEY_ASSEMBLING) { |
140 | /* assembling a key sequence */ | | 140 | /* assembling a key sequence */ |
141 | if (delay) { | | 141 | if (delay) { |
142 | if (__timeout(to ? (ESCDELAY / 100) : delay) | | 142 | if (__timeout(to ? (ESCDELAY / 100) : delay) |
143 | == ERR) | | 143 | == ERR) |
144 | return ERR; | | 144 | return ERR; |
145 | } else { | | 145 | } else { |
146 | if (to && (__timeout(ESCDELAY / 100) == ERR)) | | 146 | if (to && (__timeout(ESCDELAY / 100) == ERR)) |
147 | return ERR; | | 147 | return ERR; |
148 | } | | 148 | } |
149 | | | 149 | |
150 | c = getchar(); | | 150 | c = fgetc(infd); |
151 | if (ferror(infd)) { | | 151 | if (ferror(infd)) { |
152 | clearerr(infd); | | 152 | clearerr(infd); |
153 | return ERR; | | 153 | return ERR; |
154 | } | | 154 | } |
155 | | | 155 | |
156 | if ((to || delay) && (__notimeout() == ERR)) | | 156 | if ((to || delay) && (__notimeout() == ERR)) |
157 | return ERR; | | 157 | return ERR; |
158 | | | 158 | |
159 | k = (wchar_t) c; | | 159 | k = (wchar_t) c; |
160 | #ifdef DEBUG | | 160 | #ifdef DEBUG |
161 | __CTRACE(__CTRACE_INPUT, | | 161 | __CTRACE(__CTRACE_INPUT, |
162 | "inkey (wstate assembling) got '%s'\n", unctrl(k)); | | 162 | "inkey (wstate assembling) got '%s'\n", unctrl(k)); |
163 | #endif /* DEBUG */ | | 163 | #endif /* DEBUG */ |
| @@ -187,27 +187,27 @@ inkey(wchar_t *wc, int to, int delay) | | | @@ -187,27 +187,27 @@ inkey(wchar_t *wc, int to, int delay) |
187 | #endif /* DEBUG */ | | 187 | #endif /* DEBUG */ |
188 | } | | 188 | } |
189 | } else if (wstate == INKEY_WCASSEMBLING) { | | 189 | } else if (wstate == INKEY_WCASSEMBLING) { |
190 | /* assembling a wide char sequence */ | | 190 | /* assembling a wide char sequence */ |
191 | if (delay) { | | 191 | if (delay) { |
192 | if (__timeout(to ? (ESCDELAY / 100) : delay) | | 192 | if (__timeout(to ? (ESCDELAY / 100) : delay) |
193 | == ERR) | | 193 | == ERR) |
194 | return ERR; | | 194 | return ERR; |
195 | } else { | | 195 | } else { |
196 | if (to && (__timeout(ESCDELAY / 100) == ERR)) | | 196 | if (to && (__timeout(ESCDELAY / 100) == ERR)) |
197 | return ERR; | | 197 | return ERR; |
198 | } | | 198 | } |
199 | | | 199 | |
200 | c = getchar(); | | 200 | c = fgetc(infd); |
201 | if (ferror(infd)) { | | 201 | if (ferror(infd)) { |
202 | clearerr(infd); | | 202 | clearerr(infd); |
203 | return ERR; | | 203 | return ERR; |
204 | } | | 204 | } |
205 | | | 205 | |
206 | if ((to || delay) && (__notimeout() == ERR)) | | 206 | if ((to || delay) && (__notimeout() == ERR)) |
207 | return ERR; | | 207 | return ERR; |
208 | | | 208 | |
209 | k = (wchar_t) c; | | 209 | k = (wchar_t) c; |
210 | #ifdef DEBUG | | 210 | #ifdef DEBUG |
211 | __CTRACE(__CTRACE_INPUT, | | 211 | __CTRACE(__CTRACE_INPUT, |
212 | "inkey (wstate wcassembling) got '%s'\n", | | 212 | "inkey (wstate wcassembling) got '%s'\n", |
213 | unctrl(k)); | | 213 | unctrl(k)); |