* 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 "m4.out" /* output of termcodes.m4 */
#include "../system/globals.h"
#include "../ctlr/function.h"
#include "../ctlr/inbound.ext"
#include "../ctlr/outbound.ext"
#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 */
static int WaitingForSynch
;
*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();
headOfControl
= InitControl((char *)0, 0);
if (!headOfControl
) { /* should not occur */
/* AddChar - put a character in our buffer */
if ((c
>= numberof(asctosc
)) || (c
< 0)) {
"Unable to locate function in termout.c, AddChar()\n", 1);
switch (asctosc
[c
].shift
) {
*ourPTail
++ = asctosc
[TC_SPACE
].scancode
;
RingBell("Keyboard not capable of function.");
*ourPTail
++ = asctosc
[c
].scancode
;
*ourPTail
++ = asctosc
[TC_MAKE_SHIFT
].scancode
;
*ourPTail
++ = asctosc
[c
].scancode
;
*ourPTail
++ = asctosc
[TC_BREAK_SHIFT
].scancode
;
*ourPTail
++ = asctosc
[TC_MAKE_ALT
].scancode
;
*ourPTail
++ = asctosc
[c
].scancode
;
*ourPTail
++ = asctosc
[TC_BREAK_ALT
].scancode
;
*ourPTail
++ = asctosc
[TC_MAKE_SHIFT
].scancode
;
*ourPTail
++ = asctosc
[TC_MAKE_ALT
].scancode
;
*ourPTail
++ = asctosc
[c
].scancode
;
*ourPTail
++ = asctosc
[TC_BREAK_ALT
].scancode
;
*ourPTail
++ = asctosc
[TC_BREAK_SHIFT
].scancode
;
"Illegal 'shift' to AddChar() in termin.c\n", 1);
RingBell("Typeahead buffer full");
/* FlushChar - put everything where it belongs */
/* send data from us to next link in stream */
if (!EmptyChar
) { /* send up the link */
count
+= DataFrom3270(ourPHead
, ourPTail
-ourPHead
);
/* 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 (!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
;
if ((regControlPointer
->match
== c
) /* hit this character */
|| (regControlPointer
->match
== MATCH_ANY
)) {
result
= regControlPointer
->result
;
regControlPointer
= regControlPointer
->address
;
break; /* go to next character */
if (result
== TC_SYNCH
) {
RingBell("Need to type synch character");
else if (result
== TC_FLINP
) {
FlushChar(); /* Don't add FLINP */
if (result
== TC_MASTER_RESET
) {
AddChar(result
); /* add this code */
InControl
= 0; /* out of control now */
controlPointer
= regControlPointer
; /* save state */
(void) TerminalIn(); /* try to send data */