1: /*
2: * Copyright 1984, 1985 by the Regents of the University of
3: * California and by Gregory Glenn Minshall.
4: *
5: * Permission to use, copy, modify, and distribute these
6: * programs and their documentation for any purpose and
7: * without fee is hereby granted, provided that this
8: * copyright and permission appear on all copies and
9: * supporting documentation, the name of the Regents of
10: * the University of California not be used in advertising
11: * or publicity pertaining to distribution of the programs
12: * without specific prior permission, and notice be given in
13: * supporting documentation that copying and distribution is
14: * by permission of the Regents of the University of California
15: * and by Gregory Glenn Minshall. Neither the Regents of the
16: * University of California nor Gregory Glenn Minshall make
17: * representations about the suitability of this software
18: * for any purpose. It is provided "as is" without
19: * express or implied warranty.
20: */
21:
22:
23: /* this takes characters from the keyboard, and produces 3270 keystroke
24: codes
25: */
26:
27: #ifndef lint
28: static char sccsid[] = "@(#)termin.c 2.1 4/11/85";
29: #endif /* ndef lint */
30:
31: #include <ctype.h>
32:
33: #include "m4.out" /* output of termcodes.m4 */
34: #include "state.h"
35:
36: #define IsControl(c) (!isprint(c) && ((c) != ' '))
37:
38: #define NextState(x) (x->next)
39:
40: /* XXX temporary - hard code in the state table */
41:
42: #define MATCH_ANY 0xff /* actually, match any character */
43:
44:
45: static char
46: ourBuffer[100], /* where we store stuff */
47: *ourPHead = ourBuffer, /* first character in buffer */
48: *ourPTail = ourBuffer; /* where next character goes */
49:
50: static state
51: *headOfControl = 0; /* where we enter code state table */
52:
53: #define FullChar (ourPTail == ourBuffer+sizeof ourBuffer)
54: #define EmptyChar (ourPTail == ourPHead)
55:
56:
57: /* AddChar - put a character in our buffer */
58:
59: static
60: AddChar(c)
61: int c;
62: {
63: if (!FullChar) {
64: *ourPTail++ = (char) c;
65: } else {
66: RingBell();
67: }
68: }
69:
70: /* FlushChar - put everything where it belongs */
71:
72: static
73: FlushChar()
74: {
75: ourPTail = ourBuffer;
76: ourPHead = ourBuffer;
77: }
78:
79:
80: int
81: TerminalIn()
82: {
83: /* send data from us to next link in stream */
84: int count;
85:
86: count = 0;
87:
88: if (!EmptyChar) { /* send up the link */
89: count += DataFrom3270(ourPHead, ourPTail-ourPHead);
90: ourPHead += count;
91: if (EmptyChar) {
92: FlushChar();
93: }
94: }
95: /* return value answers question: "did we do anything useful?" */
96: return(count? 1:0);
97: }
98:
99: int
100: DataFromTerminal(buffer, count)
101: register char *buffer; /* the data read in */
102: register int count; /* how many bytes in this buffer */
103: {
104: register state *regControlPointer;
105: register char c;
106: register int result;
107: int origCount;
108:
109: static int InControl;
110: static int WaitingForSynch = 0;
111: static state *controlPointer;
112: extern state *InitControl();
113:
114: if (!headOfControl) {
115: /* need to initialize */
116: headOfControl = InitControl();
117: if (!headOfControl) { /* should not occur */
118: quit();
119: }
120: }
121:
122:
123: origCount = count;
124:
125: while (count) {
126: c = *buffer++&0x7f;
127: count--;
128:
129: if (!InControl && !IsControl(c)) {
130: AddChar(c); /* add ascii character */
131: } else {
132: if (!InControl) { /* first character of sequence */
133: InControl = 1;
134: controlPointer = headOfControl;
135: }
136: /* control pointer points to current position in state table */
137: for (regControlPointer = controlPointer; ;
138: regControlPointer = NextState(regControlPointer)) {
139: if (!regControlPointer) { /* ran off end */
140: RingBell();
141: regControlPointer = headOfControl;
142: InControl = 0;
143: break;
144: }
145: if ((regControlPointer->match == c) /* hit this character */
146: || (regControlPointer->match == MATCH_ANY)) {
147: result = regControlPointer->result;
148: if (result == TC_GOTO) {
149: regControlPointer = regControlPointer->address;
150: break; /* go to next character */
151: }
152: if (WaitingForSynch) {
153: if (result == TC_SYNCH) {
154: WaitingForSynch = 0;
155: } else {
156: RingBell();
157: }
158: }
159: else if (result == TC_FLINP) {
160: FlushChar(); /* Don't add FLINP */
161: } else {
162: if (result == TC_MASTER_RESET) {
163: FlushChar();
164: }
165: AddChar(result); /* add this code */
166: }
167: InControl = 0; /* out of control now */
168: break;
169: }
170: }
171: controlPointer = regControlPointer; /* save state */
172: }
173: }
174: (void) TerminalIn(); /* try to send data */
175: return(origCount-count);
176: }
Defined functions
Defined variables
Defined macros