Wed Nov 4 21:51:12 2009 UTC ()
Read input from the correct FILE.


(dsl)
diff -r1.7 -r1.8 src/lib/libcurses/get_wch.c
diff -r1.53 -r1.54 src/lib/libcurses/getch.c

cvs diff -r1.7 -r1.8 src/lib/libcurses/get_wch.c (expand / switch to unified diff)

--- src/lib/libcurses/get_wch.c 2009/11/01 22:11:27 1.7
+++ src/lib/libcurses/get_wch.c 2009/11/04 21:51:11 1.8
@@ -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
51static short wstate; /* state of the wcinkey function */ 51static 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));

cvs diff -r1.53 -r1.54 src/lib/libcurses/getch.c (expand / switch to unified diff)

--- src/lib/libcurses/getch.c 2009/11/01 22:11:27 1.53
+++ src/lib/libcurses/getch.c 2009/11/04 21:51:11 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: getch.c,v 1.53 2009/11/01 22:11:27 dsl Exp $ */ 1/* $NetBSD: getch.c,v 1.54 2009/11/04 21:51:11 dsl Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1981, 1993, 1994 4 * Copyright (c) 1981, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -24,27 +24,27 @@ @@ -24,27 +24,27 @@
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94"; 35static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
36#else 36#else
37__RCSID("$NetBSD: getch.c,v 1.53 2009/11/01 22:11:27 dsl Exp $"); 37__RCSID("$NetBSD: getch.c,v 1.54 2009/11/04 21:51:11 dsl Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <string.h> 41#include <string.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <unistd.h> 43#include <unistd.h>
44#include <stdio.h> 44#include <stdio.h>
45#include "curses.h" 45#include "curses.h"
46#include "curses_private.h" 46#include "curses_private.h"
47#include "keymap.h" 47#include "keymap.h"
48 48
49short state; /* state of the inkey function */ 49short state; /* state of the inkey function */
50 50
@@ -547,27 +547,27 @@ inkey(int to, int delay) @@ -547,27 +547,27 @@ inkey(int to, int delay)
547 keymap_t *current = _cursesi_screen->base_keymap; 547 keymap_t *current = _cursesi_screen->base_keymap;
548 FILE *infd = _cursesi_screen->infd; 548 FILE *infd = _cursesi_screen->infd;
549 549
550 k = 0; /* XXX gcc -Wuninitialized */ 550 k = 0; /* XXX gcc -Wuninitialized */
551 551
552#ifdef DEBUG 552#ifdef DEBUG
553 __CTRACE(__CTRACE_INPUT, "inkey (%d, %d)\n", to, delay); 553 __CTRACE(__CTRACE_INPUT, "inkey (%d, %d)\n", to, delay);
554#endif 554#endif
555 for (;;) { /* loop until we get a complete key sequence */ 555 for (;;) { /* loop until we get a complete key sequence */
556reread: 556reread:
557 if (state == INKEY_NORM) { 557 if (state == INKEY_NORM) {
558 if (delay && __timeout(delay) == ERR) 558 if (delay && __timeout(delay) == ERR)
559 return ERR; 559 return ERR;
560 c = getchar(); 560 c = fgetc(infd);
561 if (c == EOF) { 561 if (c == EOF) {
562 clearerr(infd); 562 clearerr(infd);
563 return ERR; 563 return ERR;
564 } 564 }
565 565
566 if (delay && (__notimeout() == ERR)) 566 if (delay && (__notimeout() == ERR))
567 return ERR; 567 return ERR;
568 568
569 k = (wchar_t) c; 569 k = (wchar_t) c;
570#ifdef DEBUG 570#ifdef DEBUG
571 __CTRACE(__CTRACE_INPUT, 571 __CTRACE(__CTRACE_INPUT,
572 "inkey (state normal) got '%s'\n", unctrl(k)); 572 "inkey (state normal) got '%s'\n", unctrl(k));
573#endif 573#endif
@@ -589,27 +589,27 @@ reread: @@ -589,27 +589,27 @@ reread:
589 state = INKEY_ASSEMBLING; 589 state = INKEY_ASSEMBLING;
590 } 590 }
591 } else if (state == INKEY_ASSEMBLING) { 591 } else if (state == INKEY_ASSEMBLING) {
592 /* assembling a key sequence */ 592 /* assembling a key sequence */
593 if (delay) { 593 if (delay) {
594 if (__timeout(to ? (ESCDELAY / 100) : delay) 594 if (__timeout(to ? (ESCDELAY / 100) : delay)
595 == ERR) 595 == ERR)
596 return ERR; 596 return ERR;
597 } else { 597 } else {
598 if (to && (__timeout(ESCDELAY / 100) == ERR)) 598 if (to && (__timeout(ESCDELAY / 100) == ERR))
599 return ERR; 599 return ERR;
600 } 600 }
601 601
602 c = getchar(); 602 c = fgetc(infd);
603 if (ferror(infd)) { 603 if (ferror(infd)) {
604 clearerr(infd); 604 clearerr(infd);
605 return ERR; 605 return ERR;
606 } 606 }
607 607
608 if ((to || delay) && (__notimeout() == ERR)) 608 if ((to || delay) && (__notimeout() == ERR))
609 return ERR; 609 return ERR;
610 610
611#ifdef DEBUG 611#ifdef DEBUG
612 __CTRACE(__CTRACE_INPUT, 612 __CTRACE(__CTRACE_INPUT,
613 "inkey (state assembling) got '%s'\n", unctrl(k)); 613 "inkey (state assembling) got '%s'\n", unctrl(k));
614#endif 614#endif
615 if (feof(infd) || c == -1) { /* inter-char timeout, 615 if (feof(infd) || c == -1) { /* inter-char timeout,
@@ -859,27 +859,27 @@ wgetch(WINDOW *win) @@ -859,27 +859,27 @@ wgetch(WINDOW *win)
859 if (__delay() == ERR) 859 if (__delay() == ERR)
860 return ERR; 860 return ERR;
861 break; 861 break;
862 case 0: 862 case 0:
863 if (__nodelay() == ERR) 863 if (__nodelay() == ERR)
864 return ERR; 864 return ERR;
865 break; 865 break;
866 default: 866 default:
867 if (__timeout(win->delay) == ERR) 867 if (__timeout(win->delay) == ERR)
868 return ERR; 868 return ERR;
869 break; 869 break;
870 } 870 }
871 871
872 c = getchar(); 872 c = fgetc(infd);
873 if (feof(infd)) { 873 if (feof(infd)) {
874 clearerr(infd); 874 clearerr(infd);
875 __restore_termios(); 875 __restore_termios();
876 return ERR; /* we have timed out */ 876 return ERR; /* we have timed out */
877 } 877 }
878 878
879 if (ferror(infd)) { 879 if (ferror(infd)) {
880 clearerr(infd); 880 clearerr(infd);
881 inp = ERR; 881 inp = ERR;
882 } else { 882 } else {
883 inp = c; 883 inp = c;
884 } 884 }
885 } 885 }