BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / tn3270 / sys_curses / termout.c
index 1cfe9b9..0accd56 100644 (file)
@@ -1,28 +1,23 @@
 /*
 /*
- *     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
  */
 
 #ifndef lint
-static char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
-#endif /* lint */
-
+static char sccsid[] = "@(#)termout.c  4.2 (Berkeley) 5/30/89";
+#endif /* not lint */
 
 #if defined(unix)
 #include <signal.h>
 
 #if defined(unix)
 #include <signal.h>
@@ -30,34 +25,41 @@ static      char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
 #endif
 #include <stdio.h>
 #include <curses.h>
 #endif
 #include <stdio.h>
 #include <curses.h>
+#if    defined(ultrix)
+/* Some version of this OS has a bad definition for nonl() */
+#undef nl
+#undef nonl
+
+#define nl()    (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
+#define nonl()  (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
+#endif /* defined(ultrix) */
+
+#include "../general/general.h"
 
 #include "terminal.h"
 
 
 #include "terminal.h"
 
-#include "../telnet.ext"
+#include "../api/disp_asc.h"
 
 #include "../ctlr/hostctlr.h"
 
 #include "../ctlr/hostctlr.h"
-#include "../ctlr/inbound.ext"
-#include "../ctlr/options.ext"
-#include "../ctlr/outbound.ext"
+#include "../ctlr/externs.h"
+#include "../ctlr/declare.h"
+#include "../ctlr/oia.h"
 #include "../ctlr/screen.h"
 #include "../ctlr/screen.h"
+#include "../ctlr/scrnctlr.h"
 
 
-#include "../keyboard/map3270.ext"
+#include "../general/globals.h"
 
 
-#include "../system/globals.h"
-
-extern void EmptyTerminal();
+#include "../telextrn.h"
 
 #define CorrectTerminalCursor() ((TransparentClock == OutputClock)? \
 
 #define CorrectTerminalCursor() ((TransparentClock == OutputClock)? \
-               terminalCursorAddress:UnLocked? CursorAddress: HighestScreen())
+               CursorAddress:UnLocked? CursorAddress: HighestScreen())
 
 
 static int terminalCursorAddress;      /* where the cursor is on term */
 static int screenInitd;                /* the screen has been initialized */
 static int screenStopped;              /* the screen has been stopped */
 
 
 static int terminalCursorAddress;      /* where the cursor is on term */
 static int screenInitd;                /* the screen has been initialized */
 static int screenStopped;              /* the screen has been stopped */
-#if    defined(SLOWSCREEN)
 static int max_changes_before_poll;    /* how many characters before looking */
                                        /* at terminal and net again */
 static int max_changes_before_poll;    /* how many characters before looking */
                                        /* at terminal and net again */
-#endif /* defined(SLOWSCREEN) */
 
 static int needToRing;                 /* need to ring terinal bell */
 static char *bellSequence = "\07";     /* bell sequence (may be replaced by
 
 static int needToRing;                 /* need to ring terinal bell */
 static char *bellSequence = "\07";     /* bell sequence (may be replaced by
@@ -67,13 +69,12 @@ static WINDOW *bellwin = 0;         /* The window the bell message is in */
 int    bellwinup = 0;                  /* Are we up with it or not */
 
 #if    defined(unix)
 int    bellwinup = 0;                  /* Are we up with it or not */
 
 #if    defined(unix)
-static char *KS, *KE;
+static char *myKS, *myKE;
 #endif /* defined(unix) */
 
 
 #endif /* defined(unix) */
 
 
-#if    defined(SLOWSCREEN)
 static int inHighlightMode = 0;
 static int inHighlightMode = 0;
-#endif /* defined(SLOWSCREEN) */
+ScreenImage Terminal[MAXSCREENSIZE];
 
 /* Variables for transparent mode */
 #if    defined(unix)
 
 /* Variables for transparent mode */
 #if    defined(unix)
@@ -81,16 +82,27 @@ static int tcflag = -1;                     /* transparent mode command flag */
 static int savefd[2];                  /* for storing fds during transcom */
 extern int     tin, tout;              /* file descriptors */
 #endif /* defined(unix) */
 static int savefd[2];                  /* for storing fds during transcom */
 extern int     tin, tout;              /* file descriptors */
 #endif /* defined(unix) */
+\f
 
 
+/*
+ * init_screen()
+ *
+ * Initialize variables used by screen.
+ */
+
+void
+init_screen()
+{
+    bellwinup = 0;
+    inHighlightMode = 0;
+    ClearArray(Terminal);
+}
 
 
-#include "disp_asc.out"
 
 
-\f
 /* OurExitString - designed to keep us from going through infinite recursion */
 
 static void
 /* OurExitString - designed to keep us from going through infinite recursion */
 
 static void
-OurExitString(file, string, value)
-FILE   *file;
+OurExitString(string, value)
 char   *string;
 int    value;
 {
 char   *string;
 int    value;
 {
@@ -98,7 +110,7 @@ int  value;
 
     if (!recursion) {
        recursion = 1;
 
     if (!recursion) {
        recursion = 1;
-       ExitString(file, string, value);
+       ExitString(string, value);
     }
 }
 
     }
 }
 
@@ -109,7 +121,7 @@ static void
 DoARefresh()
 {
     if (ERR == refresh()) {
 DoARefresh()
 {
     if (ERR == refresh()) {
-       OurExitString(stderr, "ERR from refresh\n", 1);
+       OurExitString("ERR from refresh\n", 1);
     }
 }
 
     }
 }
 
@@ -122,11 +134,10 @@ int       where;          /* cursor address */
 
        sprintf(foo, "ERR from %s at %d (%d, %d)\n",
                from, where, ScreenLine(where), ScreenLineOffset(where));
 
        sprintf(foo, "ERR from %s at %d (%d, %d)\n",
                from, where, ScreenLine(where), ScreenLineOffset(where));
-       OurExitString(stderr, foo, 1);
+       OurExitString(foo, 1);
        /* NOTREACHED */
 }
 \f
        /* NOTREACHED */
 }
 \f
-#if    defined(SLOWSCREEN)
 /* What is the screen address of the attribute byte for the terminal */
 
 static int
 /* What is the screen address of the attribute byte for the terminal */
 
 static int
@@ -146,7 +157,6 @@ register int        p;
 
     return(LowestScreen());    /* unformatted screen... */
 }
 
     return(LowestScreen());    /* unformatted screen... */
 }
-#endif /* defined(SLOWSCREEN) */
 \f
 /*
  *     There are two algorithms for updating the screen.
 \f
 /*
  *     There are two algorithms for updating the screen.
@@ -166,7 +176,6 @@ register int        p;
  */
 
 
  */
 
 
-#if defined(SLOWSCREEN)
 #if    defined(NOT43)
 static int
 #else  /* defined(NOT43) */
 #if    defined(NOT43)
 static int
 #else  /* defined(NOT43) */
@@ -174,15 +183,34 @@ static void
 #endif /* defined(NOT43) */
 SlowScreen()
 {
 #endif /* defined(NOT43) */
 SlowScreen()
 {
+    register int is, shouldbe, isattr, shouldattr;
     register int pointer;
     register int pointer;
-    register int c;
-    register int fieldattr;
+    register int fieldattr, termattr;
     register int columnsleft;
 
     register int columnsleft;
 
-#   define  SetHighlightMode(p) { \
-               if (!IsStartField(p) && IsHighlightedAttr(fieldattr)) { \
+#define        NORMAL          0               
+#define        HIGHLIGHT       1               /* Mask bits */
+#define        NONDISPLAY      4               /* Mask bits */
+#define        UNDETERMINED    8               /* Mask bits */
+
+#define        DoAttributes(x) \
+           switch (x&ATTR_DSPD_MASK) { \
+           case ATTR_DSPD_NONDISPLAY: \
+               x = NONDISPLAY; \
+               break; \
+           case ATTR_DSPD_HIGH: \
+               x = HIGHLIGHT; \
+               break; \
+           default: \
+               x = 0; \
+               break; \
+           }
+
+#   define  SetHighlightMode(x) \
+           { \
+               if ((x)&HIGHLIGHT) { \
                    if (!inHighlightMode) { \
                    if (!inHighlightMode) { \
-                       inHighlightMode = 1; \
+                       inHighlightMode = HIGHLIGHT; \
                        standout(); \
                    } \
                } else { \
                        standout(); \
                    } \
                } else { \
@@ -194,10 +222,8 @@ SlowScreen()
            }
 
 #   define  DoCharacterAt(c,p) { \
            }
 
 #   define  DoCharacterAt(c,p) { \
-               SetTerminal(p, c); \
                if (p != HighestScreen()) { \
                if (p != HighestScreen()) { \
-                   c = TerminalCharacterAttr(disp_asc[c&0xff], p, \
-                                                               fieldattr); \
+                   c = disp_asc[c&0xff]; \
                    if (terminalCursorAddress != p) { \
                        if (ERR == mvaddch(ScreenLine(p), \
                                                ScreenLineOffset(p), c)) {\
                    if (terminalCursorAddress != p) { \
                        if (ERR == mvaddch(ScreenLine(p), \
                                                ScreenLineOffset(p), c)) {\
@@ -245,7 +271,7 @@ SlowScreen()
      * decide when the output has caught up.
      */
 
      * decide when the output has caught up.
      */
 
-    if (Highest == HighestScreen()) {
+    if (Highest >= HighestScreen()) {  /* Could be > if screen shrunk... */
        Highest = ScreenDec(Highest);   /* else, while loop will never end */
     }
     if (Lowest < LowestScreen()) {
        Highest = ScreenDec(Highest);   /* else, while loop will never end */
     }
     if (Lowest < LowestScreen()) {
@@ -263,7 +289,8 @@ SlowScreen()
            pointer += (bunequal(Host+pointer, Terminal+pointer,
                        (Highest-pointer+1)*sizeof Host[0])/sizeof Host[0]);
 
            pointer += (bunequal(Host+pointer, Terminal+pointer,
                        (Highest-pointer+1)*sizeof Host[0])/sizeof Host[0]);
 
-               /* how many characters to change until the end of the
+               /*
+                * How many characters to change until the end of the
                 * current line
                 */
            columnsleft = NumberColumns - ScreenLineOffset(pointer);
                 * current line
                 */
            columnsleft = NumberColumns - ScreenLineOffset(pointer);
@@ -273,133 +300,131 @@ SlowScreen()
            move(ScreenLine(pointer), ScreenLineOffset(pointer));
 
                /* what is the field attribute of the current position */
            move(ScreenLine(pointer), ScreenLineOffset(pointer));
 
                /* what is the field attribute of the current position */
-           fieldattr = FieldAttributes(WhereAttrByte(pointer));
+           if (FormattedScreen()) {
+               fieldattr = FieldAttributes(pointer);
+               DoAttributes(fieldattr);
+           } else {
+               fieldattr = NORMAL;
+           }
+           if (TerminalFormattedScreen()) {
+               termattr = TermAttributes(pointer);
+               DoAttributes(termattr);
+           } else {
+               termattr = NORMAL;
+           }
 
 
-           if ((IsStartField(pointer) != TermIsStartField(pointer)) ||
-                   (IsStartField(pointer) &&
-                       fieldattr != TermAttributes(pointer))) {
+           SetHighlightMode(fieldattr);
+           /*
+            * The following will terminate at least when we get back
+            * to the original 'pointer' location (since we force
+            * things to be equal).
+            */
+           for (;;) {
+               if (IsStartField(pointer)) {
+                   shouldbe = DISP_BLANK;
+                   shouldattr = 0;
+                   fieldattr = GetHost(pointer);
+                   DoAttributes(fieldattr);
+               } else {
+                   if (fieldattr&NONDISPLAY) {
+                       shouldbe = DISP_BLANK;
+                   } else {
+                       shouldbe = GetHost(pointer);
+                   }
+                   shouldattr = fieldattr;
+               }
+               if (TermIsStartField(pointer)) {
+                   is = DISP_BLANK;
+                   isattr = 0;
+                   termattr = UNDETERMINED; /* Need to find out AFTER update */
+               } else {
+                   if (termattr&NONDISPLAY) {
+                       is = DISP_BLANK;
+                   } else {
+                       is = GetTerminal(pointer);
+                   }
+                   isattr = termattr;
+               }
+               if ((shouldbe == is) && (shouldattr == isattr)
+                       && (GetHost(pointer) == GetTerminal(pointer))
+                       && (GetHost(ScreenInc(pointer))
+                                       == GetTerminal(ScreenInc(pointer)))) {
+                   break;
+               }
 
 
-               int oldterm;
+               if (shouldattr^inHighlightMode) {
+                   SetHighlightMode(shouldattr);
+               }
 
 
-               oldterm = TermAttributes(pointer);
+               DoCharacterAt(shouldbe, pointer);
                if (IsStartField(pointer)) {
                if (IsStartField(pointer)) {
-                   TermNewField(pointer, fieldattr);
-                   SetTerminal(pointer, 0);
+                   TermNewField(pointer, FieldAttributes(pointer));
+                   termattr = GetTerminal(pointer);
+                   DoAttributes(termattr);
                } else {
                } else {
-                   TermDeleteField(pointer);
-               }
-                   /* We always do the first character in a divergent
-                    * field, since otherwise the start of a field in
-                    * the Host structure may leave a highlighted blank
-                    * on the screen, and the start of a field in the
-                    * Terminal structure may leave a non-highlighted
-                    * something in the middle of a highlighted field
-                    * on the screen.
+                   SetTerminal(pointer, GetHost(pointer));
+                   /*
+                    * If this USED to be a start field location,
+                    * recompute the terminal attributes.
                     */
                     */
-               SetHighlightMode(pointer);
-               c = GetHost(pointer);
-               DoCharacterAt(c,pointer);               /* MACRO */
-
-               if (NotVisuallyCompatibleAttributes
-                               (pointer, fieldattr, oldterm)) {
-                   int j;
-
-                   j = pointer;
-
-                   pointer = ScreenInc(pointer);
-                   if (!(--columnsleft)) {
-                       DoARefresh();
-                       EmptyTerminal();
-                       move(ScreenLine(pointer), 0);
-                       columnsleft = NumberColumns;
-                   }
-                   SetHighlightMode(pointer);  /* Turn on highlighting */
-                   while (!IsStartField(pointer) &&
-                               !TermIsStartField(pointer)) {
-                       c = GetHost(pointer);
-                       DoCharacterAt(c,pointer);       /* MACRO */
-                       pointer = ScreenInc(pointer);
-                       if (!(--columnsleft)) {
-                           DoARefresh();
-                           EmptyTerminal();
-                           move(ScreenLine(pointer), 0);
-                           columnsleft = NumberColumns;
-                               /* We don't look at HaveInput here, since
-                                * if we leave this loop before the end of
-                                * the 3270 field, we could have pointer
-                                * higher than Highest.  This would cause
-                                * us to end the highest "while" loop,
-                                * but we may, in fact, need to go around the
-                                * screen once again.
-                                */
-                       }
-                       /*              The loop needs to be protected
-                        *      from the situation where there had been only
-                        *      one field on the Terminal, and none on the Host.
-                        *      In this case, we have just deleted our last
-                        *      field.  Hence, the break.
-                        */
-                       if (j == pointer) {
-                           break;
+                   if (termattr == UNDETERMINED) {
+                       termattr = WhereTermAttrByte(pointer);
+                       if ((termattr != 0) || TermIsStartField(0)) {
+                           termattr = GetTerminal(termattr);
+                           DoAttributes(termattr);
+                       } else {        /* Unformatted screen */
+                           termattr = NORMAL;
                        }
                    }
                        }
                    }
-                   if (IsStartField(pointer) && !TermIsStartField(pointer)) {
-                           /* Remember what the terminal looked like */
-                       TermNewField(pointer, oldterm);
+               }
+               pointer = ScreenInc(pointer);
+               if (!(--columnsleft)) {
+                   DoARefresh();
+                   EmptyTerminal();
+                   if (HaveInput) {    /* if input came in, take it */
+                       int c, j;
+
+                       /*
+                        * We need to start a new terminal field
+                        * at this location iff the terminal attributes
+                        * of this location are not what we have had
+                        * them as (ie: we've overwritten the terminal
+                        * start field, a the previous field had different
+                        * display characteristics).
+                        */
+
+                       isattr = TermAttributes(pointer);
+                       DoAttributes(isattr);
+                       if ((!TermIsStartField(pointer)) &&
+                                       (isattr != termattr)) {
                            /*
                            /*
-                            * The danger here is that the current position may
-                            * be the start of a Host field.  If so, and the
-                            * field is highlighted, and our terminal was
-                            * highlighted, then we will leave a highlighted
-                            * blank at this position.
+                            * Since we are going to leave a new field
+                            * at this terminal position, we
+                            * need to make sure that we get an actual
+                            * non-highlighted blank on the screen.
                             */
                             */
-                       SetHighlightMode(pointer);
-                       c = GetHost(pointer);
-                       DoCharacterAt(c,pointer);
-                   }
-                       /* We could be in the situation of needing to exit.
-                        * This could happen if the current field wrapped around
-                        * the end of the screen.
-                        */
-                   if (j > pointer) {
-                       break;
-                   }
-               } else {
-                   c = GetHost(pointer);
-                       /* We always do the first character in a divergent
-                        * field, since otherwise the start of a field in
-                        * the Host structure may leave a highlighted blank
-                        * on the screen, and the start of a field in the
-                        * Terminal structure may leave a non-highlighted
-                        * something in the middle of a highlighted field
-                        * on the screen.
-                        */
-                   SetHighlightMode(pointer);
-                   DoCharacterAt(c,pointer);
-               }
-           } else {
-               SetHighlightMode(pointer);
-               /*
-                * The following will terminate at least when we get back
-                * to the original 'pointer' location (since we force
-                * things to be equal).
-                */
-               while (((c = GetHost(pointer)) != GetTerminal(pointer)) &&
-                       !IsStartField(pointer) && !TermIsStartField(pointer)) {
-                   DoCharacterAt(c, pointer);
-                   pointer = ScreenInc(pointer);
-                   if (!(--columnsleft)) {
-                       DoARefresh();
-                       EmptyTerminal();
-                       if (HaveInput) {        /* if input came in, take it */
-                           break;
+                           if ((is != DISP_BLANK) || (termattr&HIGHLIGHT)) {
+                               SetHighlightMode(0);    /* Turn off highlight */
+                               c = ScreenInc(pointer);
+                               j = DISP_BLANK;
+                               DoCharacterAt(j, c);
+                           }
+                           if (termattr&HIGHLIGHT) {
+                               termattr = ATTR_DSPD_HIGH;
+                           } else if (termattr&NONDISPLAY) {
+                               termattr = ATTR_DSPD_NONDISPLAY;
+                           } else {
+                               termattr = 0;
+                           }
+                           TermNewField(pointer, termattr);
                        }
                        }
-                       move(ScreenLine(pointer), 0);
-                       columnsleft = NumberColumns;
+                       break;
                    }
                    }
+                   move(ScreenLine(pointer), 0);
+                   columnsleft = NumberColumns;
                }
                }
-           }
-       }
+           }   /* end of for (;;) */
+       } /* end of while (...) */
     }
     DoARefresh();
     Lowest = pointer;
     }
     DoARefresh();
     Lowest = pointer;
@@ -420,7 +445,6 @@ SlowScreen()
     EmptyTerminal();                   /* move data along */
     return;
 }
     EmptyTerminal();                   /* move data along */
     return;
 }
-#endif /* defined(SLOWSCREEN) */
 \f
 #if    defined(NOT43)
 static int
 \f
 #if    defined(NOT43)
 static int
@@ -429,11 +453,11 @@ static void
 #endif /* defined(NOT43) */
 FastScreen()
 {
 #endif /* defined(NOT43) */
 FastScreen()
 {
-#if    defined(msdos)
+#if    defined(MSDOS)
 #define        SaveCorner      0
 #define        SaveCorner      0
-#else  /* defined(msdos) */
+#else  /* defined(MSDOS) */
 #define        SaveCorner      1
 #define        SaveCorner      1
-#endif /* defined(msdos) */
+#endif /* defined(MSDOS) */
 
 #define        DoAttribute(a)      if (IsHighlightedAttr(a)) { \
                                standout(); \
 
 #define        DoAttribute(a)      if (IsHighlightedAttr(a)) { \
                                standout(); \
@@ -460,11 +484,11 @@ FastScreen()
 
        move(ScreenLine(Lowest), ScreenLineOffset(Lowest));
        p = &Host[Lowest];
 
        move(ScreenLine(Lowest), ScreenLineOffset(Lowest));
        p = &Host[Lowest];
-#if    !defined(msdos)
+#if    !defined(MSDOS)
        if (Highest == HighestScreen()) {
            Highest = ScreenDec(Highest);
        }
        if (Highest == HighestScreen()) {
            Highest = ScreenDec(Highest);
        }
-#endif /* !defined(msdos) */
+#endif /* !defined(MSDOS) */
        upper = &Host[Highest];
        fieldattr = FieldAttributes(Lowest);
        DoAttribute(fieldattr); /* Set standout, non-display status */
        upper = &Host[Highest];
        fieldattr = FieldAttributes(Lowest);
        DoAttribute(fieldattr); /* Set standout, non-display status */
@@ -477,7 +501,8 @@ FastScreen()
                FastScreen();           /* Recurse */
                return;
            } else if (fieldattr) {     /* Should we display? */
                FastScreen();           /* Recurse */
                return;
            } else if (fieldattr) {     /* Should we display? */
-               addch(disp_asc[p->data]);       /* Display translated data */
+                           /* Display translated data */
+               addch((char)disp_asc[GetTerminalPointer(p)]);
            } else {
                addch(' ');                     /* Display a blank */
            }
            } else {
                addch(' ');                     /* Display a blank */
            }
@@ -509,17 +534,18 @@ FastScreen()
            if (IsStartFieldPointer(p)) {       /* New field? */
                if (tmp != tmpbuf) {
                    *tmp++ = 0;                 /* close out */
            if (IsStartFieldPointer(p)) {       /* New field? */
                if (tmp != tmpbuf) {
                    *tmp++ = 0;                 /* close out */
-                   addstr(tmpbuf);
+                   addstr((char *)tmpbuf);
                    tmp = tmpbuf;
                    tmp = tmpbuf;
-                   tmpend = tmpbuf + NumberColumns - ScreenLineOffset(p-Host);
+                   tmpend = tmpbuf+NumberColumns-ScreenLineOffset(p-Host)-1;
                }
                }
+               standend();
+               addch(' ');
                fieldattr = FieldAttributesPointer(p);  /* Get attributes */
                DoAttribute(fieldattr); /* Set standout, non-display */
                fieldattr = FieldAttributesPointer(p);  /* Get attributes */
                DoAttribute(fieldattr); /* Set standout, non-display */
-               *tmp++ = ' ';
            } else {
                if (fieldattr) {        /* Should we display? */
                                /* Display translated data */
            } else {
                if (fieldattr) {        /* Should we display? */
                                /* Display translated data */
-                   *tmp++ = disp_asc[p->data];
+                   *tmp++ = disp_asc[GetTerminalPointer(p)];
                } else {
                    *tmp++ = ' ';
                }
                } else {
                    *tmp++ = ' ';
                }
@@ -534,7 +560,7 @@ FastScreen()
                int i = p-Host;         /* Be sure the "p++" happened first! */
 
                *tmp++ = 0;
                int i = p-Host;         /* Be sure the "p++" happened first! */
 
                *tmp++ = 0;
-               addstr(tmpbuf);
+               addstr((char *)tmpbuf);
                tmp = tmpbuf;
                move(ScreenLine(i), 0);
                tmpend = tmpbuf + NumberColumns;
                tmp = tmpbuf;
                move(ScreenLine(i), 0);
                tmpend = tmpbuf + NumberColumns;
@@ -542,7 +568,7 @@ FastScreen()
        }
        if (tmp != tmpbuf) {
            *tmp++ = 0;
        }
        if (tmp != tmpbuf) {
            *tmp++ = 0;
-           addstr(tmpbuf);
+           addstr((char *)tmpbuf);
            tmp = tmpbuf;
        }
     }
            tmp = tmpbuf;
        }
     }
@@ -572,6 +598,14 @@ void
 #endif /* defined(NOT43) */
        (*TryToSend)() = FastScreen;
 \f
 #endif /* defined(NOT43) */
        (*TryToSend)() = FastScreen;
 \f
+/*ARGSUSED*/
+void
+ScreenOIA(oia)
+OIA *oia;
+{
+}
+
+
 /* InitTerminal - called to initialize the screen, etc. */
 
 void
 /* InitTerminal - called to initialize the screen, etc. */
 
 void
@@ -582,6 +616,7 @@ InitTerminal()
     static int speeds[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
                2400, 4800, 9600 };
 #endif
     static int speeds[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
                2400, 4800, 9600 };
 #endif
+    extern void InitMapping();
     
     InitMapping();             /* Go do mapping file (MAP3270) first */
     if (!screenInitd) {        /* not initialized */
     
     InitMapping();             /* Go do mapping file (MAP3270) first */
     if (!screenInitd) {        /* not initialized */
@@ -592,16 +627,20 @@ InitTerminal()
        extern char *tgetstr();
 #endif /* defined(unix) */
 
        extern char *tgetstr();
 #endif /* defined(unix) */
 
-#if    defined(SLOWSCREEN)
-       bzero((char *)Terminal, sizeof Terminal);
-#endif /* defined(SLOWSCREEN) */
+       if (initscr() == ERR) { /* Initialize curses to get line size */
+           ExitString("InitTerminal:  Error initializing curses", 1);
+           /*NOTREACHED*/
+       }
+       MaxNumberLines = LINES;
+       MaxNumberColumns = COLS;
+       ClearArray(Terminal);
        terminalCursorAddress = SetBufferAddress(0,0);
 #if defined(unix)
        signal(SIGHUP, abort);
 #endif
 
        TryToSend = FastScreen;
        terminalCursorAddress = SetBufferAddress(0,0);
 #if defined(unix)
        signal(SIGHUP, abort);
 #endif
 
        TryToSend = FastScreen;
-#if defined(unix) && defined(SLOWSCREEN)
+#if defined(unix)
        ioctl(1, TIOCGETP, (char *) &ourttyb);
        if ((ourttyb.sg_ospeed < 0) || (ourttyb.sg_ospeed > B9600)) {
            max_changes_before_poll = 1920;
        ioctl(1, TIOCGETP, (char *) &ourttyb);
        if ((ourttyb.sg_ospeed < 0) || (ourttyb.sg_ospeed > B9600)) {
            max_changes_before_poll = 1920;
@@ -613,7 +652,7 @@ InitTerminal()
            TryToSend = SlowScreen;
            HaveInput = 1;              /* get signals going */
        }
            TryToSend = SlowScreen;
            HaveInput = 1;              /* get signals going */
        }
-#endif /* defined(unix) && defined(SLOWSCREEN) */
+#endif /* defined(unix) */
        setcommandmode();
        /*
         * By now, initscr() (in curses) has been called (from telnet.c),
        setcommandmode();
        /*
         * By now, initscr() (in curses) has been called (from telnet.c),
@@ -625,12 +664,12 @@ InitTerminal()
                         * be nice, but it messes us up.
                         */
        signal(SIGTSTP, SIG_DFL);
                         * be nice, but it messes us up.
                         */
        signal(SIGTSTP, SIG_DFL);
-       if ((KS = tgetstr("ks", &lotsofspace)) != 0) {
-           KS = strsave(KS);
-           StringToTerminal(KS);
+       if ((myKS = tgetstr("ks", &lotsofspace)) != 0) {
+           myKS = strsave(myKS);
+           StringToTerminal(myKS);
        }
        }
-       if ((KE = tgetstr("ke", &lotsofspace)) != 0) {
-           KE = strsave(KE);
+       if ((myKE = tgetstr("ke", &lotsofspace)) != 0) {
+           myKE = strsave(myKE);
        }
        if (tgetstr("md", &lotsofspace) && tgetstr("me", &lotsofspace)) {
           SO = strsave(tgetstr("md", &lotsofspace));
        }
        if (tgetstr("md", &lotsofspace) && tgetstr("me", &lotsofspace)) {
           SO = strsave(tgetstr("md", &lotsofspace));
@@ -645,7 +684,6 @@ InitTerminal()
        screenInitd = 1;
        screenStopped = 0;              /* Not stopped */
     }
        screenInitd = 1;
        screenStopped = 0;              /* Not stopped */
     }
-    Initialized = 1;
 }
 
 
 }
 
 
@@ -658,16 +696,14 @@ int doNewLine;
     if (screenInitd && !screenStopped) {
        move(NumberLines-1, 1);
        standend();
     if (screenInitd && !screenStopped) {
        move(NumberLines-1, 1);
        standend();
-#if    defined(SLOWSCREEN)
        inHighlightMode = 0;
        inHighlightMode = 0;
-#endif /* defined(SLOWSCREEN) */
        DoARefresh();
        setcommandmode();
        endwin();
        setconnmode();
 #if    defined(unix)
        DoARefresh();
        setcommandmode();
        endwin();
        setconnmode();
 #if    defined(unix)
-       if (KE) {
-           StringToTerminal(KE);
+       if (myKE) {
+           StringToTerminal(myKE);
        }
 #endif /* defined(unix) */
        if (doNewLine) {
        }
 #endif /* defined(unix) */
        if (doNewLine) {
@@ -696,8 +732,8 @@ ConnectScreen()
 {
     if (screenInitd) {
 #if    defined(unix)
 {
     if (screenInitd) {
 #if    defined(unix)
-       if (KS) {
-           StringToTerminal(KS);
+       if (myKS) {
+           StringToTerminal(myKS);
        }
 #endif /* defined(unix) */
        RefreshScreen();
        }
 #endif /* defined(unix) */
        RefreshScreen();
@@ -711,11 +747,11 @@ ConnectScreen()
 void
 LocalClearScreen()
 {
 void
 LocalClearScreen()
 {
+    extern void Clear3270();
+
     outputPurge();             /* flush all data to terminal */
     clear();                   /* clear in curses */
     outputPurge();             /* flush all data to terminal */
     clear();                   /* clear in curses */
-#if    defined(SLOWSCREEN)
-    bzero((char *)Terminal, sizeof Terminal);
-#endif /* defined(SLOWSCREEN) */
+    ClearArray(Terminal);
     Clear3270();
     Lowest = HighestScreen()+1; /* everything in sync... */
     Highest = LowestScreen()+1;
     Clear3270();
     Lowest = HighestScreen()+1; /* everything in sync... */
     Highest = LowestScreen()+1;
@@ -729,11 +765,6 @@ BellOff()
        delwin(bellwin);
        bellwin = 0;
        bellwinup = 0;
        delwin(bellwin);
        bellwin = 0;
        bellwinup = 0;
-       Lowest = MIN(Lowest, LINES/2);
-       Highest = MAX(Highest, (LINES/2)+3);
-#if    defined(SLOWSCREEN)
-       bzero(Terminal+LINES/2, (sizeof Terminal[0])*(3*COLS));
-#endif /* defined(SLOWSCREEN) */
        touchwin(stdscr);
        DoARefresh();
     }
        touchwin(stdscr);
        DoARefresh();
     }
@@ -752,22 +783,22 @@ char *s;
            len = COLS-2;
        }
        if ((bellwin = newwin(3, len+2, LINES/2, 0)) == NULL) {
            len = COLS-2;
        }
        if ((bellwin = newwin(3, len+2, LINES/2, 0)) == NULL) {
-           OurExitString(stderr, "Error from newwin in RingBell", 1);
+           OurExitString("Error from newwin in RingBell", 1);
        }
        werase(bellwin);
        wstandout(bellwin);
        box(bellwin, '|', '-');
        if (wmove(bellwin, 1, 1) == ERR) {
        }
        werase(bellwin);
        wstandout(bellwin);
        box(bellwin, '|', '-');
        if (wmove(bellwin, 1, 1) == ERR) {
-           OurExitString(stderr, "Error from wmove in RingBell", 1);
+           OurExitString("Error from wmove in RingBell", 1);
        }
        while (len--) {
            if (waddch(bellwin, *s++) == ERR) {
        }
        while (len--) {
            if (waddch(bellwin, *s++) == ERR) {
-               OurExitString(stderr, "Error from waddch in RingBell", 1);
+               OurExitString("Error from waddch in RingBell", 1);
            }
        }
        wstandend(bellwin);
        if (wrefresh(bellwin) == ERR) {
            }
        }
        wstandend(bellwin);
        if (wrefresh(bellwin) == ERR) {
-           OurExitString(stderr, "Error from wrefresh in RingBell", 1);
+           OurExitString("Error from wrefresh in RingBell", 1);
        }
        bellwinup = 1;
     }
        }
        bellwinup = 1;
     }
@@ -783,15 +814,17 @@ int
 DoTerminalOutput()
 {
        /* called just before a select to conserve IO to terminal */
 DoTerminalOutput()
 {
        /* called just before a select to conserve IO to terminal */
-    if (Initialized &&
-           ((Lowest <= Highest) || needToRing ||
-                       (terminalCursorAddress != CorrectTerminalCursor()))) {
+    if (!(screenInitd||screenStopped)) {
+       return 1;               /* No output if not initialized */
+    }
+    if ((Lowest <= Highest) || needToRing ||
+                       (terminalCursorAddress != CorrectTerminalCursor())) {
        (*TryToSend)();
     }
     if (Lowest > Highest) {
        (*TryToSend)();
     }
     if (Lowest > Highest) {
-       return(1);              /* no more output now */
+       return 1;               /* no more output now */
     } else {
     } else {
-       return(0);              /* more output for future */
+       return 0;               /* more output for future */
     }
 }
 \f
     }
 }
 \f
@@ -821,13 +854,15 @@ TransStop()
 }
 
 void
 }
 
 void
-TransOut(buffer, count)
+TransOut(buffer, count, kind, control)
 unsigned char  *buffer;
 int            count;
 unsigned char  *buffer;
 int            count;
+int            kind;           /* 0 or 5 */
+int            control;        /* To see if we are done */
 {
 #if    defined(unix)
     extern char *transcom;
 {
 #if    defined(unix)
     extern char *transcom;
-    int inpipefd[2], outpipefd[2], savemode;
+    int inpipefd[2], outpipefd[2];
     void aborttc();
 #endif /* defined(unix) */
 
     void aborttc();
 #endif /* defined(unix) */
 
@@ -869,7 +904,7 @@ int         count;
             setcommandmode();
             tin = inpipefd[0];
             tout = outpipefd[1];
             setcommandmode();
             tin = inpipefd[0];
             tout = outpipefd[1];
-            (void) signal(SIGCHLD, aborttc);
+            (void) signal(SIGCHLD, (int (*)())aborttc);
             setconnmode();
             tcflag = 1;
             break;
             setconnmode();
             tcflag = 1;
             break;
@@ -879,7 +914,14 @@ int                count;
        }
     }
 #endif /* defined(unix) */
        }
     }
 #endif /* defined(unix) */
-    (void) DataToTerminal(buffer, count);
+    (void) DataToTerminal((char *)buffer, count);
+    if (control && (kind == 0)) {              /* Send in AID byte */
+       SendToIBM();
+    } else {
+       extern void TransInput();
+
+       TransInput(1, kind);                    /* Go get some data */
+    }
 }
 
 
 }
 
 
@@ -887,8 +929,6 @@ int         count;
 static void
 aborttc()
 {
 static void
 aborttc()
 {
-       int savemode;
-
        setcommandmode();
        (void) close(tin);
        (void) close(tout);
        setcommandmode();
        (void) close(tin);
        (void) close(tout);