BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / tn3270 / ctlr / outbound.c
index c1f62b3..3a59e11 100644 (file)
@@ -1,28 +1,39 @@
-/*
- *     Copyright (c) 1984, 1985, 1986 by the Regents of the
- *     University of California and by Gregory Glenn Minshall.
+/*-
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     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.
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
-#endif /* lint */
-
+static char sccsid[] = "@(#)outbound.c 4.3 (Berkeley) 4/26/91";
+#endif /* not lint */
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
@@ -31,14 +42,11 @@ static      char    sccsid[] = "@(#)outbound.c      3.1  10/29/86";
 #include "hostctlr.h"
 #include "oia.h"
 #include "screen.h"
 #include "hostctlr.h"
 #include "oia.h"
 #include "screen.h"
-#include "ebc_disp.h"
+#include "../api/ebc_disp.h"
 
 #include "../general/globals.h"
 
 #include "../general/globals.h"
-#include "options.ext"
-#include "../telnet.ext"
-#include "inbound.ext"
-#include "outbound.ext"
-#include "../general/bsubs.ext"
+#include "externs.h"
+#include "declare.h"
 
 #define SetHighestLowest(position) { \
                                        if (position < Lowest) { \
 
 #define SetHighestLowest(position) { \
                                        if (position < Lowest) { \
@@ -82,9 +90,6 @@ void
 init_ctlr()
 {
     LastWasTerminated = 1;
 init_ctlr()
 {
     LastWasTerminated = 1;
-#if    !defined(PURE3274)
-    OutputClock = TransparentClock = 0;
-#endif /* !defined(PURE3274) */
     init_inbound();
     init_oia();
 }
     init_inbound();
     init_oia();
 }
@@ -150,7 +155,6 @@ AddHost(position, character)
 int    position;
 char   character;
 {
 int    position;
 char   character;
 {
-#if    defined(SLOWSCREEN)
 #   define     AddHostA(p,c)                                   \
     {                                                          \
        if (IsStartField(p)) {                                  \
 #   define     AddHostA(p,c)                                   \
     {                                                          \
        if (IsStartField(p)) {                                  \
@@ -168,32 +172,19 @@ char      character;
        }                                                       \
        AddHostA(p,c);                                          \
     }  /* end of macro of AddHost */
        }                                                       \
        AddHostA(p,c);                                          \
     }  /* end of macro of AddHost */
-#else  /* defined(SLOWSCREEN) */
-#   define     AddHost(p,c)                                    \
-    {                                                          \
-       if (IsStartField(p)) {                                  \
-           DeleteField(p);                                     \
-           Highest = HighestScreen();                          \
-           Lowest = LowestScreen();                            \
-           SetHost(p, c);                                      \
-       } else {                                                \
-           SetHost(p, c);                                      \
-           SetHighestLowest(p);                                \
-       }                                                       \
-    }  /* end of macro of AddHost */
-#endif /* defined(SLOWSCREEN) */
 
     AddHost(position, character);
 }
 \f
 /* returns the number of characters consumed */
 int
 
     AddHost(position, character);
 }
 \f
 /* returns the number of characters consumed */
 int
-DataFromNetwork(buffer, count, control)
-register unsigned char *buffer;                /* what the data is */
+DataFromNetwork(Buffer, count, control)
+char   *Buffer;                                /* what the data is */
 register int   count;                          /* and how much there is */
 int    control;                                /* this buffer ended block? */
 {
     int origCount;
 register int   count;                          /* and how much there is */
 int    control;                                /* this buffer ended block? */
 {
     int origCount;
+    register unsigned char *buffer = (unsigned char *)Buffer;
     register int c;
     register int i;
     static int Command;
     register int c;
     register int i;
     static int Command;
@@ -201,11 +192,15 @@ int       control;                                /* this buffer ended block? */
 
     origCount = count;
 
 
     origCount = count;
 
+    /*
+     * If this is the start of a new data stream, then look
+     * for an op-code and (possibly) a WCC.
+     */
     if (LastWasTerminated) {
 
        if (count < 2) {
            if (count == 0) {
     if (LastWasTerminated) {
 
        if (count < 2) {
            if (count == 0) {
-               ExitString(stderr, "Short count received from host!\n", 1);
+               ExitString("Short count received from host!\n", 1);
                return(count);
            }
            Command = buffer[0];
                return(count);
            }
            Command = buffer[0];
@@ -225,12 +220,12 @@ int       control;                                /* this buffer ended block? */
                break;
            default:
                {
                break;
            default:
                {
-                   char buffer[100];
+                   char s_buffer[100];
 
 
-                   sprintf(buffer,
+                   sprintf(s_buffer,
                        "Unexpected read command code 0x%x received.\n",
                                                                    Command);
                        "Unexpected read command code 0x%x received.\n",
                                                                    Command);
-                   ExitString(stderr, buffer, 1);
+                   ExitString(s_buffer, 1);
                    break;
                }
            }
                    break;
                }
            }
@@ -324,12 +319,12 @@ int       control;                                /* this buffer ended block? */
            break;
        default:
            {
            break;
        default:
            {
-               char buffer[100];
+               char s_buffer[100];
 
 
-               sprintf(buffer,
+               sprintf(s_buffer,
                        "Unexpected write command code 0x%x received.\n",
                                                                Command);
                        "Unexpected write command code 0x%x received.\n",
                                                                Command);
-               ExitString(stderr, buffer, 1);
+               ExitString(s_buffer, 1);
                break;
            }
        }
                break;
            }
        }
@@ -337,6 +332,13 @@ int        control;                                /* this buffer ended block? */
        count -= 2;                     /* strip off command and wcc */
        buffer += 2;
 
        count -= 2;                     /* strip off command and wcc */
        buffer += 2;
 
+    } else {
+#if    !defined(PURE3274)
+       if (TransparentClock == OutputClock) {
+           TransOut(buffer, count, -1, control);
+           count = 0;
+       }
+#endif /* !defined(PURE3274) */
     }
     LastWasTerminated = 0;             /* then, reset at end... */
 
     }
     LastWasTerminated = 0;             /* then, reset at end... */
 
@@ -371,17 +373,12 @@ int       control;                                /* this buffer ended block? */
                i = buffer[0];
                c = buffer[1];
 #if    !defined(PURE3274)
                i = buffer[0];
                c = buffer[1];
 #if    !defined(PURE3274)
-               if (!i && !c) { /* transparent write */
-                   if (!control) {
-                       return(origCount-(count+1));
-                   } else {
-                       TransparentClock = OutputClock;         /* clock next */
-                       TransOut(buffer+2, count-2);            /* output */
-                       SendToIBM();                            /* ack block */
-                       TransparentClock = OutputClock+1;       /* clock next */
-                       buffer += count;
-                       count -= count;
-                   }
+               /* Check for transparent write */
+               if ((i == 0) && ((c == 0) || (c == 1) || (c == 5))) {
+                   TransparentClock = OutputClock+1;
+                   TransOut(buffer+2, count-2, c, control);
+                   buffer += count;
+                   count -= count;
                    break;
                }
 #endif /* !defined(PURE3274) */
                    break;
                }
 #endif /* !defined(PURE3274) */
@@ -411,6 +408,20 @@ int        control;                                /* this buffer ended block? */
            case ORDER_RA:
                Ensure(3);
                i = Addr3270(buffer[0], buffer[1]);
            case ORDER_RA:
                Ensure(3);
                i = Addr3270(buffer[0], buffer[1]);
+               if ((i < 0) || (i > HighestScreen())) {
+                   char s_buffer[200];
+
+                   sprintf(s_buffer, "tn3270:  %s%d.\n\t%s%d%s%d%s\n",
+                       "Invalid 3270 order 'Repeat to Address' to address ",
+                       i,
+                       "(Screen currently set to ",
+                       NumberLines,
+                       " by ",
+                       NumberColumns,
+                       ".)");
+                   ExitString(s_buffer, 1);
+                   /*NOTREACHED*/
+               }
                c = buffer[2];
                if (c == ORDER_GE) {
                    Ensure(4);
                c = buffer[2];
                if (c == ORDER_GE) {
                    Ensure(4);
@@ -434,22 +445,37 @@ int       control;                                /* this buffer ended block? */
                 */
                i = WhereAttrByte(BufferAddress);
                c = FieldAttributes(i);
                 */
                i = WhereAttrByte(BufferAddress);
                c = FieldAttributes(i);
-               for (i = Addr3270(buffer[0], buffer[1]); i != BufferAddress;
-                               BufferAddress = ScreenInc(BufferAddress)) {
+               i = Addr3270(buffer[0], buffer[1]);
+               if ((i < 0) || (i > HighestScreen())) {
+                   char s_buffer[200];
+
+                   sprintf(s_buffer, "tn3270:  %s%d.\n\t%s%d%s%d%s\n",
+                       "Invalid 3270 order 'Erase Unprotected to Address' to address ",
+                       i,
+                       "(Screen currently set to ",
+                       NumberLines,
+                       " by ",
+                       NumberColumns,
+                       ".)");
+                   ExitString(s_buffer, 1);
+                   /*NOTREACHED*/
+               }
+               do {
                    if (IsStartField(BufferAddress)) {
                        c = FieldAttributes(BufferAddress);
                    } else if (!IsProtectedAttr(BufferAddress, c)) {
                        AddHost(BufferAddress, 0);
                    }
                    if (IsStartField(BufferAddress)) {
                        c = FieldAttributes(BufferAddress);
                    } else if (!IsProtectedAttr(BufferAddress, c)) {
                        AddHost(BufferAddress, 0);
                    }
-               }
+                   BufferAddress = ScreenInc(BufferAddress);
+               } while (i != BufferAddress);
                buffer += 2;
                count -= 2;
                break;
            case ORDER_GE:
                Ensure(2);
                /* XXX Should do SOMETHING! */
                buffer += 2;
                count -= 2;
                break;
            case ORDER_GE:
                Ensure(2);
                /* XXX Should do SOMETHING! */
-               buffer += 0;
-               count -= 0;             /* For now, just use this character */
+               /* XXX buffer += 0; */
+               /* XXX count -= 0; *//* For now, just use this character */
                break;
            case ORDER_YALE:            /* special YALE defined order */
                Ensure(2);      /* need at least two characters */
                break;
            case ORDER_YALE:            /* special YALE defined order */
                Ensure(2);      /* need at least two characters */
@@ -465,22 +491,22 @@ int       control;                                /* this buffer ended block? */
                break;
            default:
                {
                break;
            default:
                {
-                   char buffer[100];
+                   char s_buffer[100];
                    static struct orders_def unk_order
                                                = { 0, "??", "(unknown)" };
                    struct orders_def *porder = &unk_order;
                    static struct orders_def unk_order
                                                = { 0, "??", "(unknown)" };
                    struct orders_def *porder = &unk_order;
-                   int i;
+                   int s_i;
 
 
-                   for (i = 0; i <= highestof(orders_def); i++) {
-                       if (orders_def[i].code == c) {
-                           porder = &orders_def[i];
+                   for (s_i = 0; s_i <= highestof(orders_def); s_i++) {
+                       if (orders_def[s_i].code == c) {
+                           porder = &orders_def[s_i];
                            break;
                        }
                    }
                            break;
                        }
                    }
-                   sprintf(buffer,
+                   sprintf(s_buffer,
                        "Unsupported order '%s' (%s, 0x%x) received.\n",
                        porder->long_name, porder->short_name, c);
                        "Unsupported order '%s' (%s, 0x%x) received.\n",
                        porder->long_name, porder->short_name, c);
-                   ExitString(stderr, buffer, 1);
+                   ExitString(s_buffer, 1);
                    /*NOTREACHED*/
                }
            }
                    /*NOTREACHED*/
                }
            }
@@ -490,41 +516,29 @@ int       control;                                /* this buffer ended block? */
        } else {
            /* Data comes in large clumps - take it all */
            i = BufferAddress;
        } else {
            /* Data comes in large clumps - take it all */
            i = BufferAddress;
-#if    !defined(SLOWSCREEN)
-           AddHost(i, ebc_disp[c]);
-#else  /* !defined(SLOWSCREEN) */
            AddHostA(i, ebc_disp[c]);
            SetHighestLowest(i);
            AddHostA(i, ebc_disp[c]);
            SetHighestLowest(i);
-#endif /* !defined(SLOWSCREEN) */
            i = ScreenInc(i);
            c = *buffer;
            while (count && !IsOrder(c)) {
            i = ScreenInc(i);
            c = *buffer;
            while (count && !IsOrder(c)) {
-#if    !defined(SLOWSCREEN)
-               AddHost(i, ebc_disp[c]);
-#else  /* !defined(SLOWSCREEN) */
                AddHostA(i, ebc_disp[c]);
                AddHostA(i, ebc_disp[c]);
-#endif /* !defined(SLOWSCREEN) */
                i = ScreenInc(i);
                i = ScreenInc(i);
-#if    defined(SLOWSCREEN)
                if (i == LowestScreen()) {
                    SetHighestLowest(HighestScreen());
                }
                if (i == LowestScreen()) {
                    SetHighestLowest(HighestScreen());
                }
-#endif /* defined(SLOWSCREEN) */
                count--;
                buffer++;
                c = *buffer;
            }
                count--;
                buffer++;
                c = *buffer;
            }
-#if    defined(SLOWSCREEN)
            SetHighestLowest(i);
            SetHighestLowest(i);
-#endif /* defined(SLOWSCREEN) */
            BufferAddress = i;
        }
     }
     if (count == 0) {
            BufferAddress = i;
        }
     }
     if (count == 0) {
+       if (control) {
 #if    !defined(PURE3274)
 #if    !defined(PURE3274)
-       OutputClock++;          /* time rolls on */
+           OutputClock++;              /* time rolls on */
 #endif /* !defined(PURE3274) */
 #endif /* !defined(PURE3274) */
-       if (control) {
            if (Wcc & WCC_RESTORE) {
 #if    !defined(PURE3274)
                if (TransparentClock != OutputClock) {
            if (Wcc & WCC_RESTORE) {
 #if    !defined(PURE3274)
                if (TransparentClock != OutputClock) {
@@ -540,7 +554,7 @@ int control;                                /* this buffer ended block? */
                TerminalIn();
            }
            if (Wcc & WCC_ALARM) {
                TerminalIn();
            }
            if (Wcc & WCC_ALARM) {
-               RingBell(0);
+               RingBell((char *)0);
            }
        }
        LastWasTerminated = control;    /* state for next time */
            }
        }
        LastWasTerminated = control;    /* state for next time */
@@ -576,8 +590,10 @@ Init3270()
     Highest = LowestScreen()-1;
     CursorAddress = BufferAddress = SetBufferAddress(0,0);
     UnLocked = 1;
     Highest = LowestScreen()-1;
     CursorAddress = BufferAddress = SetBufferAddress(0,0);
     UnLocked = 1;
+#if    !defined(PURE3274)
     OutputClock = 1;
     TransparentClock = -1;
     OutputClock = 1;
     TransparentClock = -1;
+#endif /* !defined(PURE3274) */
     SetOiaReady3274(&OperatorInformationArea);
 }
 
     SetOiaReady3274(&OperatorInformationArea);
 }