BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / telnet / tn3270.c
index 3ef2908..a75cd1e 100644 (file)
@@ -1,22 +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 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.
+ * 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.17 (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>
@@ -34,12 +50,13 @@ static char sccsid[] = "@(#)tn3270.c        1.17 (Berkeley) %G%";
 #include "../ctlr/screen.h"
 #include "../general/globals.h"
 
 #include "../ctlr/screen.h"
 #include "../general/globals.h"
 
-#include "../telextrn.h"
+#include "../sys_curses/telextrn.h"
 #include "../ctlr/externs.h"
 
 #if    defined(unix)
 int
        HaveInput,              /* There is input available to scan */
 #include "../ctlr/externs.h"
 
 #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];
        sigiocount;             /* Number of times we got a SIGIO */
 
 char   tline[200];
@@ -60,7 +77,7 @@ static int
 #endif /* defined(TN3270) */
 
 
 #endif /* defined(TN3270) */
 
 
-void
+    void
 init_3270()
 {
 #if    defined(TN3270)
 init_3270()
 {
 #if    defined(TN3270)
@@ -89,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;
@@ -146,18 +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;
     sigiocount++;
 }
 #endif /* defined(unix) */
 
 {
     HaveInput = 1;
     sigiocount++;
 }
 #endif /* defined(unix) */
 
-void
+    void
 outputPurge()
 {
 outputPurge()
 {
-    ttyflush(1);
+    (void) ttyflush(1);
 }
 
 
 }
 
 
@@ -173,10 +191,10 @@ 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 c;
     int origCount;
 {
     register int c;
     int origCount;
@@ -190,14 +208,14 @@ register int      count;                  /* how much to send */
 
            FD_ZERO(&o);
 #endif /* defined(unix) */
 
            FD_ZERO(&o);
 #endif /* defined(unix) */
-           ttyflush(0);
+           (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(0);
+               (void) ttyflush(0);
            }
        }
        c = TTYROOM();
            }
        }
        c = TTYROOM();
@@ -216,7 +234,7 @@ register int        count;                  /* how much to send */
  * Push3270 - Try to send data along the 3270 output (to screen) direction.
  */
 
  * 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);
@@ -224,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);
@@ -242,7 +260,7 @@ Push3270()
  *             before quitting.
  */
 
  *             before quitting.
  */
 
-void
+    void
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
@@ -256,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;
 
@@ -274,13 +292,16 @@ 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    defined(sun)            /* SunOS 4.0 bug */
     c &= 0x7f;
 #endif /* defined(sun) */
 {
 #if    defined(sun)            /* SunOS 4.0 bug */
     c &= 0x7f;
 #endif /* defined(sun) */
+    if (cursesdata) {
+       Dump('>', &c, 1);
+    }
     if (!TTYROOM()) {
        (void) DataToTerminal(&c, 1);
     } else {
     if (!TTYROOM()) {
        (void) DataToTerminal(&c, 1);
     } else {
@@ -289,24 +310,24 @@ char c;
 }
 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
 
 }
 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
 
-void
+    void
 SetIn3270()
 {
 SetIn3270()
 {
-    if (Sent3270TerminalType && should_I(TELOPT_BINARY)
-                           && should_he(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);
        }
     }
 }
        }
     }
 }
@@ -319,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()
 {
     /*
@@ -355,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 {
@@ -364,6 +385,7 @@ tn3270_ttype()
 }
 
 #if    defined(unix)
 }
 
 #if    defined(unix)
+       int
 settranscom(argc, argv)
        int argc;
        char *argv[];
 settranscom(argc, argv)
        int argc;
        char *argv[];
@@ -374,7 +396,7 @@ settranscom(argc, argv)
           transcom = 0;
        }
        if (argc == 1) {
           transcom = 0;
        }
        if (argc == 1) {
-          return;
+          return 1;
        }
        transcom = tline;
        (void) strcpy(transcom, argv[1]);
        }
        transcom = tline;
        (void) strcpy(transcom, argv[1]);
@@ -382,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) */