1 /* $NetBSD: termin.c,v 1.7 2002/06/13 23:41:18 wiz Exp $ */
4 * Copyright (c) 1988 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
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
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)termin.c 4.2 (Berkeley) 4/26/91";
37 __RCSID("$NetBSD: termin.c,v 1.7 2002/06/13 23:41:18 wiz Exp $");
41 /* this takes characters from the keyboard, and produces 3270 keystroke
48 #include "../general/general.h"
49 #include "../ctlr/function.h"
50 #include "../ctlr/declare.h"
51 #include "../sys_curses/telextrn.h"
53 #include "../api/astosc.h"
58 #include "../general/globals.h"
60 extern cc_t escape
; /* Escape to command mode */
62 #define IsControl(c) (!isprint((unsigned char)c) || (isspace((unsigned char)c) && ((c) != ' ')))
64 #define NextState(x) (x->next)
66 /* XXX temporary - hard code in the state table */
68 #define MATCH_ANY 0xff /* actually, match any character */
72 ourBuffer
[100], /* where we store stuff */
73 *ourPHead
= ourBuffer
, /* first character in buffer */
74 *ourPTail
= ourBuffer
, /* where next character goes */
75 *TransPointer
= 0; /* For transparent mode data */
78 static int WaitingForSynch
;
81 *spacePTR
= 0; /* Space is hard to enter */
84 *headOfControl
= 0; /* where we enter code state table */
86 #define FullChar ((ourPTail+5) >= ourBuffer+sizeof ourBuffer)
87 #define EmptyChar (ourPTail == ourPHead)
90 static void AddChar(int);
91 static void FlushChar(void);
97 * Initialize the keyboard variables.
103 ourPHead
= ourPTail
= ourBuffer
;
110 * Initialize the keyboard mapping file.
118 if (!headOfControl
) {
119 /* need to initialize */
120 headOfControl
= InitControl((char *)0, 0, ascii_to_index
);
121 if (!headOfControl
) { /* should not occur */
124 for (ptr
= &astosc
[0]; ptr
<= &astosc
[highestof(astosc
)]; ptr
++) {
125 if (ptr
->function
== FCN_SPACE
) {
133 /* AddChar - put a function index in our buffer */
142 RingBell("Typeahead buffer full");
146 /* FlushChar - put everything where it belongs */
151 ourPTail
= ourBuffer
;
152 ourPHead
= ourBuffer
;
157 TransInput(onoff
, mode
)
158 int mode
; /* Which KIND of transparent input */
159 int onoff
; /* Going in, or coming out */
162 /* Flush pending input */
164 TransPointer
= ourBuffer
;
172 /* send data from us to next link in stream */
176 while (!EmptyChar
) { /* send up the link */
177 if (*ourPHead
== ' ') {
180 ptr
= &astosc
[*ourPHead
];
182 if (AcceptKeystroke(ptr
->scancode
, ptr
->shiftstate
) == 1) {
193 /* return value answers question: "did we do anything useful?" */
198 DataFromTerminal(buffer
, count
)
199 char *buffer
; /* the data read in */
200 int count
; /* how many bytes in this buffer */
202 state
*regControlPointer
;
206 extern int bellwinup
;
207 static state
*controlPointer
;
212 if ((count
+TransPointer
) >= (ourBuffer
+sizeof ourBuffer
)) {
213 i
= ourBuffer
+sizeof ourBuffer
-TransPointer
;
218 c
= (*buffer
++)&0x7f;
219 *TransPointer
++ = c
|0x80;
221 SendTransparent((char *)ourBuffer
, TransPointer
-ourBuffer
);
222 TransPointer
= 0; /* Done */
240 if (count
&& (*buffer
&0x7f) == escape
) {
244 command(0, (char *)0, 0);
250 if (!InControl
&& !IsControl(c
)) {
251 AddChar(c
); /* add ascii character */
253 if (!InControl
) { /* first character of sequence */
255 controlPointer
= headOfControl
;
257 /* control pointer points to current position in state table */
258 for (regControlPointer
= controlPointer
; ;
259 regControlPointer
= NextState(regControlPointer
)) {
260 if (!regControlPointer
) { /* ran off end */
261 RingBell("Invalid control sequence");
262 regControlPointer
= headOfControl
;
264 count
= 0; /* Flush current input */
267 if ((regControlPointer
->match
== c
) /* hit this character */
268 || (regControlPointer
->match
== MATCH_ANY
)) {
269 result
= regControlPointer
->result
;
270 if (result
== STATE_GOTO
) {
271 regControlPointer
= regControlPointer
->address
;
272 break; /* go to next character */
274 if (WaitingForSynch
) {
275 if (astosc
[result
].function
== FCN_SYNCH
) {
278 RingBell("Need to type synch character");
281 else if (astosc
[result
].function
== FCN_FLINP
) {
282 FlushChar(); /* Don't add FLINP */
284 if (astosc
[result
].function
== FCN_MASTER_RESET
) {
287 AddChar(result
); /* add this code */
289 InControl
= 0; /* out of control now */
293 controlPointer
= regControlPointer
; /* save state */
296 (void) TerminalIn(); /* try to send data */
297 return(origCount
-count
);