1 /* $Id: ttyio.c,v 1.3 2000/11/16 14:21:32 amura Exp $ */
2 /* OS dependent code used by Ng for WinCE.
3 * Copyright (C) 1998 Eiichiro Ito
4 * Modified for Ng for Win32
5 * Copyright (C) 1999,2000 Toru Imai
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 * ree 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, Boston, MA 02111-1307, USA.
20 */
21 /*
22 * TTY I/O routine for win32
23 */
24
25 /*
26 * $Log: ttyio.c,v $
27 * Revision 1.3 2000/11/16 14:21:32 amura
28 * merge Ng for win32 0.5
29 *
30 * Revision 1.2 2000/10/23 16:52:51 amura
31 * add GPL copyright to header
32 *
33 * Revision 1.1.1.1 2000/06/27 01:48:00 amura
34 * import to CVS
35 *
36 */
37
38 #include <windows.h>
39 #include "config.h"
40 #include "def.h"
41 #include "winmain.h"
42 #include "tools.h"
43
44 int nrow ; /* Terminal size, rows. */
45 int ncol ; /* Terminal size, columns. */
46 BOOL bLastChar = FALSE ;
47 CHAR chLastChar = 0 ;
48
49 int
panic(char * s)50 panic( char *s )
51 {
52 TCHAR foo[256];
53
54 sjis2unicode(s, foo, sizeof(foo));
55 MessageBox( NULL, foo, TEXT(""), MB_ICONASTERISK|MB_OK ) ;
56 return 0 ;
57 }
58
59 int
ttopen()60 ttopen()
61 {
62 GetWH( &ncol, &nrow ) ;
63 if (NROW < nrow) {
64 nrow = NROW;
65 }
66 if (NCOL < ncol) {
67 ncol = NCOL;
68 }
69 return 0 ;
70 }
71
72 int
ttclose()73 ttclose()
74 {
75 return 0 ;
76 }
77
78 int
ttflush()79 ttflush()
80 {
81 Flush() ;
82 return 0 ;
83 }
84
85 /*
86 * typeahead returns TRUE if there are characters available to be read
87 * in.
88 */
89 int
typeahead()90 typeahead()
91 {
92 return Kbhit() ;
93 }
94
95 /*
96 * Write character to the display without ^C check.
97 */
98 int
ttputc(int c)99 ttputc( int c )
100 {
101 PutChar( (char) c ) ;
102 return 0 ;
103 }
104
105 /*
106 * Write character to the display without ^C check.
107 */
108 int
ttputkc(int c1,int c2)109 ttputkc( int c1, int c2 )
110 {
111 PutKChar((char)c1, (char)c2);
112 return 0;
113 }
114
115 /*
116 * Read character from terminal without ^C check.
117 * All 8 bits are returned, so that you can use
118 * a multi-national terminal.
119 */
120 int
ttgetc()121 ttgetc()
122 {
123 if ( bLastChar ) {
124 bLastChar = FALSE ;
125 return chLastChar ;
126 }
127 return GetChar() ;
128 }
129
130 /*
131 * Save pre-readed char to read again.
132 */
133 int
ttungetc(int c)134 ttungetc( int c )
135 {
136 bLastChar = TRUE ;
137 chLastChar = c ;
138 return 0 ;
139 }
140
141 /*
142 * A program to return TRUE if we wait for 1 seconds without anything
143 * happening, else return FALSE.
144 */
145 int
ttwait()146 ttwait()
147 {
148 return !KbhitSleep( 1 ) ;
149 }
150
151 /*
152 * set the tty size. Functionized for Win32
153 */
154 void
setttysize()155 setttysize()
156 {
157 GetWH(&ncol, &nrow);
158 if (NROW < nrow) {
159 nrow = NROW;
160 }
161 if (NCOL < ncol) {
162 ncol = NCOL;
163 }
164 }
165