# 2.11BSD#431 - /usr/src/ucb/tn3270/termin.c

##### Functions

    DataFromTerminal  X
    TerminalIn        X

##### Macros

    EmptyChar         X
    FullChar          X
    IsControl         X
    MATCH_ANY         X
    NextState         X

       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: #if defined(DOSCCS) && !defined(lint)
      28: static  char    sccsid[] = "@(#)termin.c	2.2	1/1/94";
      29: #endif
      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

AddChar defined in line 59; used 2 times

- in line 130, 165

DataFromTerminal defined in line 99; used 2 times

- in /usr/src/ucb/tn3270/tn3270.c line 615, 1028

FlushChar defined in line 72; used 3 times

- in line 92, 160-163(2)

TerminalIn defined in line 80; used 2 times

- in line 174
- in /usr/src/ucb/tn3270/datastream.c line 806

#### Defined variables

ourBuffer defined in line 46; used 6 times

- in line 47-53(4), 75-76(2)

ourPHead defined in line 47; used 5 times

- in line 54, 76, 89-90(3)

sccsid defined in line 28; never used

#### Defined macros

EmptyChar defined in line 54; used 2 times

- in line 88-91(2)

FullChar defined in line 53; used 1 times

- in line 63

IsControl defined in line 36; used 1 times

- in line 129

MATCH_ANY defined in line 42; used 1 times

- in line 146

NextState defined in line 38; used 1 times

- in line 138

Last modified: 1994-01-01 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1044 |