BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / telnet / tn3270.c
index 9537163..a75cd1e 100644 (file)
@@ -1,17 +1,38 @@
 /*
 /*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * 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.
+ * 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.
+ *
+ * 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[] = "@(#)tn3270.c   1.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)tn3270.c   8.2 (Berkeley) 5/30/95";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -29,7 +50,15 @@ static char sccsid[] = "@(#)tn3270.c 1.10 (Berkeley) %G%";
 #include "../ctlr/screen.h"
 #include "../general/globals.h"
 
 #include "../ctlr/screen.h"
 #include "../general/globals.h"
 
+#include "../sys_curses/telextrn.h"
+#include "../ctlr/externs.h"
+
 #if    defined(unix)
 #if    defined(unix)
+int
+       HaveInput,              /* There is input available to scan */
+       cursesdata,             /* Do we dump curses data? */
+       sigiocount;             /* Number of times we got a SIGIO */
+
 char   tline[200];
 char   *transcom = 0;  /* transparent mode command (default: none) */
 #endif /* defined(unix) */
 char   tline[200];
 char   *transcom = 0;  /* transparent mode command (default: none) */
 #endif /* defined(unix) */
@@ -48,10 +77,14 @@ static int
 #endif /* defined(TN3270) */
 
 
 #endif /* defined(TN3270) */
 
 
-void
+    void
 init_3270()
 {
 #if    defined(TN3270)
 init_3270()
 {
 #if    defined(TN3270)
+#if    defined(unix)
+    HaveInput = 0;
+    sigiocount = 0;
+#endif /* defined(unix) */
     Sent3270TerminalType = 0;
     Ifrontp = Ibackp = Ibuf;
     init_ctlr();               /* Initialize some things */
     Sent3270TerminalType = 0;
     Ifrontp = Ibackp = Ibuf;
     init_ctlr();               /* Initialize some things */
@@ -73,11 +106,11 @@ init_3270()
  * only client needs for us to do that.
  */
 
  * only client needs for us to do that.
  */
 
-int
+    int
 DataToNetwork(buffer, count, done)
 DataToNetwork(buffer, count, done)
-register char  *buffer;        /* where the data is */
-register int   count;          /* how much to send */
-int            done;           /* is this the last of a logical block */
+    register char *buffer;     /* where the data is */
+    register int  count;       /* how much to send */
+    int                  done;         /* is this the last of a logical block */
 {
     register int loop, c;
     int origCount;
 {
     register int loop, c;
     int origCount;
@@ -130,17 +163,19 @@ int               done;           /* is this the last of a logical block */
 
 
 #if    defined(unix)
 
 
 #if    defined(unix)
-void
-inputAvailable()
+    void
+inputAvailable(signo)
+       int signo;
 {
     HaveInput = 1;
 {
     HaveInput = 1;
+    sigiocount++;
 }
 #endif /* defined(unix) */
 
 }
 #endif /* defined(unix) */
 
-void
+    void
 outputPurge()
 {
 outputPurge()
 {
-    ttyflush(1);
+    (void) ttyflush(1);
 }
 
 
 }
 
 
@@ -156,12 +191,12 @@ outputPurge()
  * *all* the data at one time (thus the select).
  */
 
  * *all* the data at one time (thus the select).
  */
 
-int
+    int
 DataToTerminal(buffer, count)
 DataToTerminal(buffer, count)
-register char  *buffer;                /* where the data is */
-register int   count;                  /* how much to send */
+    register char      *buffer;                /* where the data is */
+    register int       count;                  /* how much to send */
 {
 {
-    register int loop, c;
+    register int c;
     int origCount;
 
     origCount = count;
     int origCount;
 
     origCount = count;
@@ -173,14 +208,14 @@ register int      count;                  /* how much to send */
 
            FD_ZERO(&o);
 #endif /* defined(unix) */
 
            FD_ZERO(&o);
 #endif /* defined(unix) */
-           ttyflush();
+           (void) ttyflush(0);
            while (TTYROOM() == 0) {
 #if    defined(unix)
                FD_SET(tout, &o);
                (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
                                                (struct timeval *) 0);
 #endif /* defined(unix) */
            while (TTYROOM() == 0) {
 #if    defined(unix)
                FD_SET(tout, &o);
                (void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
                                                (struct timeval *) 0);
 #endif /* defined(unix) */
-               ttyflush();
+               (void) ttyflush(0);
            }
        }
        c = TTYROOM();
            }
        }
        c = TTYROOM();
@@ -193,45 +228,13 @@ register int      count;                  /* how much to send */
     }
     return(origCount);
 }
     }
     return(origCount);
 }
-
-/* EmptyTerminal - called to make sure that the terminal buffer is empty.
- *                     Note that we consider the buffer to run all the
- *                     way to the kernel (thus the select).
- */
-
-void
-EmptyTerminal()
-{
-#if    defined(unix)
-    fd_set     o;
-
-    FD_ZERO(&o);
-#endif /* defined(unix) */
-
-    if (TTYBYTES() == 0) {
-#if    defined(unix)
-       FD_SET(tout, &o);
-       (void) select(tout+1, (int *) 0, &o, (int *) 0,
-                       (struct timeval *) 0);  /* wait for TTLOWAT */
-#endif /* defined(unix) */
-    } else {
-       while (TTYBYTES()) {
-           ttyflush(0);
-#if    defined(unix)
-           FD_SET(tout, &o);
-           (void) select(tout+1, (int *) 0, &o, (int *) 0,
-                               (struct timeval *) 0);  /* wait for TTLOWAT */
-#endif /* defined(unix) */
-       }
-    }
-}
 \f
 
 /*
  * Push3270 - Try to send data along the 3270 output (to screen) direction.
  */
 
 \f
 
 /*
  * Push3270 - Try to send data along the 3270 output (to screen) direction.
  */
 
-int
+    int
 Push3270()
 {
     int save = ring_full_count(&netiring);
 Push3270()
 {
     int save = ring_full_count(&netiring);
@@ -239,13 +242,13 @@ Push3270()
     if (save) {
        if (Ifrontp+save > Ibuf+sizeof Ibuf) {
            if (Ibackp != Ibuf) {
     if (save) {
        if (Ifrontp+save > Ibuf+sizeof Ibuf) {
            if (Ibackp != Ibuf) {
-               memcpy(Ibuf, Ibackp, Ifrontp-Ibackp);
+               memmove(Ibuf, Ibackp, Ifrontp-Ibackp);
                Ifrontp -= (Ibackp-Ibuf);
                Ibackp = Ibuf;
            }
        }
        if (Ifrontp+save < Ibuf+sizeof Ibuf) {
                Ifrontp -= (Ibackp-Ibuf);
                Ibackp = Ibuf;
            }
        }
        if (Ifrontp+save < Ibuf+sizeof Ibuf) {
-           telrcv();
+           (void)telrcv();
        }
     }
     return save != ring_full_count(&netiring);
        }
     }
     return save != ring_full_count(&netiring);
@@ -257,7 +260,7 @@ Push3270()
  *             before quitting.
  */
 
  *             before quitting.
  */
 
-void
+    void
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
@@ -271,9 +274,9 @@ Finish3270()
 
 /* StringToTerminal - output a null terminated string to the terminal */
 
 
 /* StringToTerminal - output a null terminated string to the terminal */
 
-void
+    void
 StringToTerminal(s)
 StringToTerminal(s)
-char *s;
+    char *s;
 {
     int count;
 
 {
     int count;
 
@@ -289,11 +292,17 @@ char *s;
  *     curses(3x) can call us to send out data.
  */
 
  *     curses(3x) can call us to send out data.
  */
 
-void
+    void
 _putchar(c)
 _putchar(c)
-char c;
+    char c;
 {
 {
-    if (TTYBYTES()) {
+#if    defined(sun)            /* SunOS 4.0 bug */
+    c &= 0x7f;
+#endif /* defined(sun) */
+    if (cursesdata) {
+       Dump('>', &c, 1);
+    }
+    if (!TTYROOM()) {
        (void) DataToTerminal(&c, 1);
     } else {
        TTYADD(c);
        (void) DataToTerminal(&c, 1);
     } else {
        TTYADD(c);
@@ -301,69 +310,24 @@ char c;
 }
 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
 
 }
 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
 
-void
-SetForExit()
-{
-    setconnmode();
-    if (In3270) {
-       Finish3270();
-    }
-    setcommandmode();
-    fflush(stdout);
-    fflush(stderr);
-    if (In3270) {
-       StopScreen(1);
-    }
-    setconnmode();
-    setcommandmode();
-}
-
-void
-Exit(returnCode)
-int returnCode;
-{
-    SetForExit();
-    exit(returnCode);
-}
-
-void
-ExitString(string, returnCode)
-char *string;
-int returnCode;
-{
-    SetForExit();
-    fwrite(string, 1, strlen(string), stderr);
-    exit(returnCode);
-}
-
-void
-ExitPerror(string, returnCode)
-char *string;
-int returnCode;
-{
-    SetForExit();
-    perror(string);
-    exit(returnCode);
-}
-
-void
+    void
 SetIn3270()
 {
 SetIn3270()
 {
-    if (Sent3270TerminalType && myopts[TELOPT_BINARY]
-                           && hisopts[TELOPT_BINARY] && !donebinarytoggle) {
+    if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY)
+               && my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle) {
        if (!In3270) {
            In3270 = 1;
            Init3270();         /* Initialize 3270 functions */
            /* initialize terminal key mapping */
            InitTerminal();     /* Start terminal going */
        if (!In3270) {
            In3270 = 1;
            Init3270();         /* Initialize 3270 functions */
            /* initialize terminal key mapping */
            InitTerminal();     /* Start terminal going */
-           setconnmode();
+           setconnmode(0);
        }
     } else {
        if (In3270) {
            StopScreen(1);
            In3270 = 0;
            Stop3270();         /* Tell 3270 we aren't here anymore */
        }
     } else {
        if (In3270) {
            StopScreen(1);
            In3270 = 0;
            Stop3270();         /* Tell 3270 we aren't here anymore */
-           setconnmode();
+           setconnmode(0);
        }
     }
 }
        }
     }
 }
@@ -376,7 +340,7 @@ SetIn3270()
  *     Return '0' if no more responses to send; '1' if a response sent.
  */
 
  *     Return '0' if no more responses to send; '1' if a response sent.
  */
 
-int
+    int
 tn3270_ttype()
 {
     /*
 tn3270_ttype()
 {
     /*
@@ -412,7 +376,7 @@ tn3270_ttype()
                                                                1);
            /*NOTREACHED*/
        }
                                                                1);
            /*NOTREACHED*/
        }
-       printsub(">", sb_terminal+2, sizeof sb_terminal-2);
+       printsub('>', sb_terminal+2, sizeof sb_terminal-2);
        ring_supply_data(&netoring, sb_terminal, sizeof sb_terminal);
        return 1;
     } else {
        ring_supply_data(&netoring, sb_terminal, sizeof sb_terminal);
        return 1;
     } else {
@@ -421,20 +385,18 @@ tn3270_ttype()
 }
 
 #if    defined(unix)
 }
 
 #if    defined(unix)
+       int
 settranscom(argc, argv)
        int argc;
        char *argv[];
 {
 settranscom(argc, argv)
        int argc;
        char *argv[];
 {
-       int i, len = 0;
+       int i;
 
        if (argc == 1 && transcom) {
           transcom = 0;
        }
        if (argc == 1) {
 
        if (argc == 1 && transcom) {
           transcom = 0;
        }
        if (argc == 1) {
-          return;
-       }
-       for (i = 1; i < argc; ++i) {
-           len += 1 + strlen(argv[1]);
+          return 1;
        }
        transcom = tline;
        (void) strcpy(transcom, argv[1]);
        }
        transcom = tline;
        (void) strcpy(transcom, argv[1]);
@@ -442,6 +404,7 @@ settranscom(argc, argv)
            (void) strcat(transcom, " ");
            (void) strcat(transcom, argv[i]);
        }
            (void) strcat(transcom, " ");
            (void) strcat(transcom, argv[i]);
        }
+       return 1;
 }
 #endif /* defined(unix) */
 
 }
 #endif /* defined(unix) */