Make work with new split telnet.
[unix-history] / usr / src / usr.bin / tn3270 / sys_curses / termout.c
index cdd88d4..c6e7ec0 100644 (file)
@@ -1,28 +1,18 @@
 /*
 /*
- *     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 this notice is preserved and that due credit is given
+ * to the University of California at 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'' without express or implied warranty.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
-#endif /* lint */
-
+static char sccsid[] = "@(#)termout.c  3.4 (Berkeley) %G%";
+#endif /* not lint */
 
 #if defined(unix)
 #include <signal.h>
 
 #if defined(unix)
 #include <signal.h>
@@ -31,35 +21,36 @@ static      char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
 #include <stdio.h>
 #include <curses.h>
 
 #include <stdio.h>
 #include <curses.h>
 
-#include "../general.h"
+#include "../general/general.h"
 
 #include "terminal.h"
 
 #include "../telnet.ext"
 
 
 #include "terminal.h"
 
 #include "../telnet.ext"
 
+#include "../api/disp_asc.h"
+
 #include "../ctlr/hostctlr.h"
 #include "../ctlr/inbound.ext"
 #include "../ctlr/hostctlr.h"
 #include "../ctlr/inbound.ext"
+#include "../ctlr/oia.h"
 #include "../ctlr/options.ext"
 #include "../ctlr/outbound.ext"
 #include "../ctlr/screen.h"
 
 #include "../ctlr/options.ext"
 #include "../ctlr/outbound.ext"
 #include "../ctlr/screen.h"
 
-#include "../keyboard/map3270.ext"
+#include "../ascii/map3270.ext"
 
 
-#include "../system/globals.h"
+#include "../general/globals.h"
 
 extern void EmptyTerminal();
 
 #define CorrectTerminalCursor() ((TransparentClock == OutputClock)? \
 
 extern void EmptyTerminal();
 
 #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
@@ -73,10 +64,8 @@ static char *KS, *KE;
 #endif /* defined(unix) */
 
 
 #endif /* defined(unix) */
 
 
-#if    defined(SLOWSCREEN)
 static int inHighlightMode = 0;
 ScreenImage Terminal[MAXSCREENSIZE];
 static int inHighlightMode = 0;
 ScreenImage Terminal[MAXSCREENSIZE];
-#endif /* defined(SLOWSCREEN) */
 
 /* Variables for transparent mode */
 #if    defined(unix)
 
 /* Variables for transparent mode */
 #if    defined(unix)
@@ -84,10 +73,6 @@ 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) */
-
-
-#include "disp_asc.out"
-
 \f
 
 /*
 \f
 
 /*
@@ -100,10 +85,8 @@ void
 init_screen()
 {
     bellwinup = 0;
 init_screen()
 {
     bellwinup = 0;
-#if    defined(SLOWSCREEN)
     inHighlightMode = 0;
     ClearArray(Terminal);
     inHighlightMode = 0;
     ClearArray(Terminal);
-#endif /* defined(SLOWSCREEN) */
 }
 
 
 }
 
 
@@ -147,7 +130,6 @@ int where;          /* cursor address */
        /* 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
@@ -167,7 +149,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.
@@ -187,7 +168,6 @@ register int        p;
  */
 
 
  */
 
 
-#if defined(SLOWSCREEN)
 #if    defined(NOT43)
 static int
 #else  /* defined(NOT43) */
 #if    defined(NOT43)
 static int
 #else  /* defined(NOT43) */
@@ -266,7 +246,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()) {
@@ -335,8 +315,8 @@ SlowScreen()
                        columnsleft = NumberColumns;
                    }
                    SetHighlightMode(pointer);  /* Turn on highlighting */
                        columnsleft = NumberColumns;
                    }
                    SetHighlightMode(pointer);  /* Turn on highlighting */
-                   while (!IsStartField(pointer) &&
-                               !TermIsStartField(pointer)) {
+                   while ((!IsStartField(pointer)) &&
+                               (!TermIsStartField(pointer))) {
                        c = GetHost(pointer);
                        DoCharacterAt(c,pointer);       /* MACRO */
                        pointer = ScreenInc(pointer);
                        c = GetHost(pointer);
                        DoCharacterAt(c,pointer);       /* MACRO */
                        pointer = ScreenInc(pointer);
@@ -383,6 +363,10 @@ SlowScreen()
                         * the end of the screen.
                         */
                    if (j > pointer) {
                         * the end of the screen.
                         */
                    if (j > pointer) {
+                       /*
+                        * pointer is guaranteed to be higher than Highest...
+                        */
+                       pointer = Highest+1;    /* We did the highest thing */
                        break;
                    }
                } else {
                        break;
                    }
                } else {
@@ -441,7 +425,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
@@ -450,11 +433,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(); \
@@ -481,11 +464,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 */
@@ -498,7 +481,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(disp_asc[GetTerminalPointer(p)]);
            } else {
                addch(' ');                     /* Display a blank */
            }
            } else {
                addch(' ');                     /* Display a blank */
            }
@@ -540,7 +524,7 @@ FastScreen()
            } 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++ = ' ';
                }
@@ -593,6 +577,13 @@ void
 #endif /* defined(NOT43) */
        (*TryToSend)() = FastScreen;
 \f
 #endif /* defined(NOT43) */
        (*TryToSend)() = FastScreen;
 \f
+void
+ScreenOIA(oia)
+OIA *oia;
+{
+}
+
+
 /* InitTerminal - called to initialize the screen, etc. */
 
 void
 /* InitTerminal - called to initialize the screen, etc. */
 
 void
@@ -613,16 +604,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;
@@ -634,7 +629,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),
@@ -666,7 +661,6 @@ InitTerminal()
        screenInitd = 1;
        screenStopped = 0;              /* Not stopped */
     }
        screenInitd = 1;
        screenStopped = 0;              /* Not stopped */
     }
-    Initialized = 1;
 }
 
 
 }
 
 
@@ -679,9 +673,7 @@ 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();
        DoARefresh();
        setcommandmode();
        endwin();
@@ -734,9 +726,7 @@ LocalClearScreen()
 {
     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;
@@ -750,11 +740,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();
     }
@@ -804,7 +789,7 @@ 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) {
+    if (!(screenInitd||screenStopped)) {
        return 1;               /* No output if not initialized */
     }
     if ((Lowest <= Highest) || needToRing ||
        return 1;               /* No output if not initialized */
     }
     if ((Lowest <= Highest) || needToRing ||
@@ -844,9 +829,11 @@ 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;
@@ -903,6 +890,11 @@ int                count;
     }
 #endif /* defined(unix) */
     (void) DataToTerminal(buffer, count);
     }
 #endif /* defined(unix) */
     (void) DataToTerminal(buffer, count);
+    if (control && (kind == 0)) {              /* Send in AID byte */
+       SendToIBM();
+    } else {
+       TransInput(1, kind);                    /* Go get some data */
+    }
 }
 
 
 }