* Copyright (c) 1984, 1985, 1986 by the Regents of the
* University of California and by Gregory Glenn Minshall.
* Permission to use, copy, modify, and distribute these
* programs and their documentation for any purpose and
* without fee is hereby granted, provided that this
* copyright and permission appear on all copies and
* supporting documentation, the name of the Regents of
* the University of California not be used in advertising
* or publicity pertaining to distribution of the programs
* without specific prior permission, and notice be given in
* supporting documentation that copying and distribution is
* by permission of the Regents of the University of California
* and by Gregory Glenn Minshall. Neither the Regents of the
* University of California nor Gregory Glenn Minshall make
* representations about the suitability of this software
* for any purpose. It is provided "as is" without
* express or implied warranty.
static char sccsid
[] = "@(#)termin.c 3.1 10/29/86";
/* this takes characters from the keyboard, and produces 3270 keystroke
#include "../general/general.h"
#include "../ctlr/function.h"
#include "../ctlr/inbound.ext"
#include "../ctlr/outbound.ext"
#include "../apilib/astosc.h"
#include "../general/globals.h"
#define IsControl(c) (!isprint(c) || (isspace(c) && ((c) != ' ')))
#define NextState(x) (x->next)
/* XXX temporary - hard code in the state table */
#define MATCH_ANY 0xff /* actually, match any character */
ourBuffer
[100], /* where we store stuff */
*ourPHead
= ourBuffer
, /* first character in buffer */
*ourPTail
= ourBuffer
, /* where next character goes */
*TransPointer
= 0; /* For transparent mode data */
static int WaitingForSynch
;
*spacePTR
= 0; /* Space is hard to enter */
*headOfControl
= 0; /* where we enter code state table */
#define FullChar ((ourPTail+5) >= ourBuffer+sizeof ourBuffer)
#define EmptyChar (ourPTail == ourPHead)
* Initialize the keyboard variables.
ourPHead
= ourPTail
= ourBuffer
;
* Initialize the keyboard mapping file.
extern state
*InitControl();
register struct astosc
*ptr
;
headOfControl
= InitControl((char *)0, 0, ascii_to_index
);
if (!headOfControl
) { /* should not occur */
for (ptr
= &astosc
[0]; ptr
<= &astosc
[highestof(astosc
)]; ptr
++) {
if (ptr
->function
== FCN_SPACE
) {
/* AddChar - put a function index in our buffer */
RingBell("Typeahead buffer full");
/* FlushChar - put everything where it belongs */
int mode
; /* Which KIND of transparent input */
int onoff
; /* Going in, or coming out */
/* Flush pending input */
TransPointer
= ourBuffer
;
/* send data from us to next link in stream */
register struct astosc
*ptr
;
while (!EmptyChar
) { /* send up the link */
ptr
= &astosc
[*ourPHead
];
if (AcceptKeystroke(ptr
->scancode
, ptr
->shiftstate
) == 1) {
/* return value answers question: "did we do anything useful?" */
DataFromTerminal(buffer
, count
)
register char *buffer
; /* the data read in */
register int count
; /* how many bytes in this buffer */
register state
*regControlPointer
;
static state
*controlPointer
;
if ((count
+TransPointer
) >= (ourBuffer
+sizeof ourBuffer
)) {
i
= ourBuffer
+sizeof ourBuffer
-TransPointer
;
*TransPointer
++ = c
|0x80;
SendTransparent(ourBuffer
, TransPointer
-ourBuffer
);
TransPointer
= 0; /* Done */
if (!InControl
&& !IsControl(c
)) {
AddChar(c
); /* add ascii character */
if (!InControl
) { /* first character of sequence */
controlPointer
= headOfControl
;
/* control pointer points to current position in state table */
for (regControlPointer
= controlPointer
; ;
regControlPointer
= NextState(regControlPointer
)) {
if (!regControlPointer
) { /* ran off end */
RingBell("Invalid control sequence");
regControlPointer
= headOfControl
;
count
= 0; /* Flush current input */
if ((regControlPointer
->match
== c
) /* hit this character */
|| (regControlPointer
->match
== MATCH_ANY
)) {
result
= regControlPointer
->result
;
if (result
== STATE_GOTO
) {
regControlPointer
= regControlPointer
->address
;
break; /* go to next character */
if (astosc
[result
].function
== FCN_SYNCH
) {
RingBell("Need to type synch character");
else if (astosc
[result
].function
== FCN_FLINP
) {
FlushChar(); /* Don't add FLINP */
if (astosc
[result
].function
== FCN_MASTER_RESET
) {
AddChar(result
); /* add this code */
InControl
= 0; /* out of control now */
controlPointer
= regControlPointer
; /* save state */
(void) TerminalIn(); /* try to send data */