Release 4.1
[unix-history] / usr / src / usr.bin / tn3270 / ascii / termin.c
index ea98a14..ff563ed 100644 (file)
@@ -1,42 +1,40 @@
 /*
 /*
- *     Copyright (c) 1984, 1985, 1986 by the Regents of the
- *     University of California and by Gregory Glenn Minshall.
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
  *
  *
- *     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.
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
-#ifndef        lint
-static char    sccsid[] = "@(#)termin.c        3.1  10/29/86";
-#endif /* ndef lint */
+#ifndef lint
+static char sccsid[] = "@(#)termin.c   4.1 (Berkeley) %G%";
+#endif /* not lint */
 
 /* this takes characters from the keyboard, and produces 3270 keystroke
        codes
  */
 
 
 /* this takes characters from the keyboard, and produces 3270 keystroke
        codes
  */
 
+#include <stdio.h>
 #include <ctype.h>
 
 #include <ctype.h>
 
-#include "m4.out"              /* output of termcodes.m4 */
+#include "../general/general.h"
+#include "../ctlr/function.h"
+#include "../ctlr/externs.h"
+#include "../ctlr/declare.h"
+
+#include "../api/astosc.h"
 #include "state.h"
 
 #include "state.h"
 
-#include "globals.h"
-#include "inbound.ext"
-#include "outbound.ext"
-#include "telnet.ext"
-#include "termin.ext"
+#include "../general/globals.h"
 
 #define IsControl(c)   (!isprint(c) || (isspace(c) && ((c) != ' ')))
 
 
 #define IsControl(c)   (!isprint(c) || (isspace(c) && ((c) != ' ')))
 
@@ -47,28 +45,75 @@ static      char    sccsid[] = "@(#)termin.c        3.1  10/29/86";
 #define MATCH_ANY 0xff                 /* actually, match any character */
 
 \f
 #define MATCH_ANY 0xff                 /* actually, match any character */
 
 \f
-static char
+static unsigned char
        ourBuffer[100],         /* where we store stuff */
        *ourPHead = ourBuffer,  /* first character in buffer */
        ourBuffer[100],         /* where we store stuff */
        *ourPHead = ourBuffer,  /* first character in buffer */
-       *ourPTail = ourBuffer;  /* where next character goes */
+       *ourPTail = ourBuffer,  /* where next character goes */
+       *TransPointer = 0;      /* For transparent mode data */
+
+static int InControl;
+static int WaitingForSynch;
+
+static struct astosc
+       *spacePTR = 0;          /* Space is hard to enter */
 
 static state
        *headOfControl = 0;     /* where we enter code state table */
 
 
 static state
        *headOfControl = 0;     /* where we enter code state table */
 
-#define FullChar       (ourPTail == ourBuffer+sizeof ourBuffer)
+#define FullChar       ((ourPTail+5) >= ourBuffer+sizeof ourBuffer)
 #define EmptyChar      (ourPTail == ourPHead)
 
 \f
 #define EmptyChar      (ourPTail == ourPHead)
 
 \f
-/* AddChar - put a character in our buffer */
+/*
+ * init_keyboard()
+ *
+ * Initialize the keyboard variables.
+ */
+
+void
+init_keyboard()
+{
+    ourPHead = ourPTail = ourBuffer;
+    InControl = 0;
+    WaitingForSynch = 0;
+}
+
+
+/*
+ * Initialize the keyboard mapping file.
+ */
+
+void
+InitMapping()
+{
+    extern state *InitControl();
+    register struct astosc *ptr;
+
+    if (!headOfControl) {
+       /* need to initialize */
+       headOfControl = InitControl((char *)0, 0, ascii_to_index);
+       if (!headOfControl) {           /* should not occur */
+           quit();
+       }
+       for (ptr = &astosc[0]; ptr <= &astosc[highestof(astosc)]; ptr++) {
+           if (ptr->function == FCN_SPACE) {
+               spacePTR = ptr;
+           }
+       }
+    }
+}
+
+
+/* AddChar - put a function index in our buffer */
 
 static void
 AddChar(c)
 int    c;
 {
     if (!FullChar) {
 
 static void
 AddChar(c)
 int    c;
 {
     if (!FullChar) {
-       *ourPTail++ = (char) c;
+       *ourPTail++ = c;
     } else {
     } else {
-       RingBell();
+       RingBell("Typeahead buffer full");
     }
 }
 
     }
 }
 
@@ -81,24 +126,46 @@ FlushChar()
     ourPHead = ourBuffer;
 }
 
     ourPHead = ourBuffer;
 }
 
+/*ARGSUSED*/
+void
+TransInput(onoff, mode)
+int    mode;                   /* Which KIND of transparent input */
+int    onoff;                  /* Going in, or coming out */
+{
+    if (onoff) {
+       /* Flush pending input */
+       FlushChar();
+       TransPointer = ourBuffer;
+    } else {
+    }
+}
 
 int
 TerminalIn()
 {
     /* send data from us to next link in stream */
 
 int
 TerminalIn()
 {
     /* send data from us to next link in stream */
-    int count;
-
-    count = 0;
+    int work = 0;
+    register struct astosc *ptr;
 
 
-    if (!EmptyChar) {                  /* send up the link */
-       count += DataFrom3270(ourPHead, ourPTail-ourPHead);
-       ourPHead += count;
-       if (EmptyChar) {
-           FlushChar();
+    while (!EmptyChar) {                       /* send up the link */
+       if (*ourPHead == ' ') {
+           ptr = spacePTR;
+       } else {
+           ptr = &astosc[*ourPHead];
+       }
+       if (AcceptKeystroke(ptr->scancode, ptr->shiftstate) == 1) {
+           ourPHead++;
+           work = 1;
+       } else {
+           break;
        }
     }
        }
     }
+
+    if (EmptyChar) {
+       FlushChar();
+    }
        /* return value answers question: "did we do anything useful?" */
        /* return value answers question: "did we do anything useful?" */
-    return(count? 1:0);
+    return work;
 }
 
 int
 }
 
 int
@@ -110,20 +177,34 @@ register int      count;                  /* how many bytes in this buffer */
     register char c;
     register int result;
     int origCount;
     register char c;
     register int result;
     int origCount;
-
-    static int InControl = 0;
-    static int WaitingForSynch = 0;
+    extern int bellwinup;
     static state *controlPointer;
     static state *controlPointer;
-    extern state *InitControl();
 
 
-    if (!headOfControl) {
-       /* need to initialize */
-       headOfControl = InitControl((char *)0, 0);
-       if (!headOfControl) {           /* should not occur */
-           quit();
+    if (TransPointer) {
+       int i;
+
+       if ((count+TransPointer) >= (ourBuffer+sizeof ourBuffer)) {
+           i = ourBuffer+sizeof ourBuffer-TransPointer;
+       } else {
+           i = count;
+       }
+       while (i--) {
+           c = (*buffer++)&0x7f;
+           *TransPointer++ = c|0x80;
+           if (c == '\r') {
+               SendTransparent((char *)ourBuffer, TransPointer-ourBuffer);
+               TransPointer = 0;               /* Done */
+               break;
+           }
        }
        }
+       return count;
     }
 
     }
 
+    if (bellwinup) {
+       void BellOff();
+
+       BellOff();
+    }
 
     origCount = count;
 
 
     origCount = count;
 
@@ -142,29 +223,32 @@ register int      count;                  /* how many bytes in this buffer */
            for (regControlPointer = controlPointer; ;
                        regControlPointer = NextState(regControlPointer)) {
                if (!regControlPointer) {       /* ran off end */
            for (regControlPointer = controlPointer; ;
                        regControlPointer = NextState(regControlPointer)) {
                if (!regControlPointer) {       /* ran off end */
-                   RingBell();
+                   RingBell("Invalid control sequence");
                    regControlPointer = headOfControl;
                    InControl = 0;
                    regControlPointer = headOfControl;
                    InControl = 0;
+                   count = 0;          /* Flush current input */
                    break;
                }
                if ((regControlPointer->match == c) /* hit this character */
                        || (regControlPointer->match == MATCH_ANY)) {
                    result = regControlPointer->result;
                    break;
                }
                if ((regControlPointer->match == c) /* hit this character */
                        || (regControlPointer->match == MATCH_ANY)) {
                    result = regControlPointer->result;
-                   if (result == TC_GOTO) {
+                   if (result == STATE_GOTO) {
                        regControlPointer = regControlPointer->address;
                        break;                  /* go to next character */
                    }
                    if (WaitingForSynch) {
                        regControlPointer = regControlPointer->address;
                        break;                  /* go to next character */
                    }
                    if (WaitingForSynch) {
-                       if (result == TC_SYNCH) {
+                       if (astosc[result].function == FCN_SYNCH) {
                            WaitingForSynch = 0;
                        } else {
                            WaitingForSynch = 0;
                        } else {
-                           RingBell();
+                           void RingBell();
+
+                           RingBell("Need to type synch character");
                        }
                    }
                        }
                    }
-                   else if (result == TC_FLINP) {
+                   else if (astosc[result].function == FCN_FLINP) {
                        FlushChar();            /* Don't add FLINP */
                    } else {
                        FlushChar();            /* Don't add FLINP */
                    } else {
-                       if (result == TC_MASTER_RESET) {
+                       if (astosc[result].function == FCN_MASTER_RESET) {
                            FlushChar();
                        }
                        AddChar(result);                /* add this code */
                            FlushChar();
                        }
                        AddChar(result);                /* add this code */