Deal with backslashed quotes.
[unix-history] / usr / src / usr.bin / tn3270 / telnet.c
index a2a7bca..33bb503 100644 (file)
@@ -43,8 +43,6 @@ static char sccsid[] = "@(#)telnet.c  3.1  10/29/86";
  *
  *     TN3270          -       This is to be linked with tn3270.
  *
  *
  *     TN3270          -       This is to be linked with tn3270.
  *
- *     DEBUG           -       Allow for some extra debugging operations.
- *
  *     NOT43           -       Allows the program to compile and run on
  *                             a 4.2BSD system.
  *
  *     NOT43           -       Allows the program to compile and run on
  *                             a 4.2BSD system.
  *
@@ -116,13 +114,15 @@ extern char       *inet_ntoa();
 #endif /* defined(unix) */
 
 #if    defined(TN3270)
 #endif /* defined(unix) */
 
 #if    defined(TN3270)
+#include "ascii/termin.ext"
 #include "ctlr/screen.h"
 #include "ctlr/screen.h"
-#include "general/globals.h"
-#include "telnet.ext"
+#include "ctlr/oia.h"
 #include "ctlr/options.ext"
 #include "ctlr/outbound.ext"
 #include "ctlr/options.ext"
 #include "ctlr/outbound.ext"
-#include "ascii/termin.ext"
+#include "general/globals.h"
+#include "telnet.ext"
 #endif /* defined(TN3270) */
 #endif /* defined(TN3270) */
+
 #include "general/general.h"
 
 
 #include "general/general.h"
 
 
@@ -212,6 +212,7 @@ static int
        debug = 0,
        crmod,
        netdata,
        debug = 0,
        crmod,
        netdata,
+       noasynch = 0,   /* User specified "-noasynch" on command line */
        askedSGA = 0,   /* We have talked about suppress go ahead */
        telnetport = 1;
 
        askedSGA = 0,   /* We have talked about suppress go ahead */
        telnetport = 1;
 
@@ -550,9 +551,11 @@ register int f;
     ioctl(tin, FIONBIO, (char *)&onoff);
     ioctl(tout, FIONBIO, (char *)&onoff);
 #endif /* (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) */
     ioctl(tin, FIONBIO, (char *)&onoff);
     ioctl(tout, FIONBIO, (char *)&onoff);
 #endif /* (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) */
-#if    defined(TN3270) && !defined(DEBUG)
-    ioctl(tin, FIOASYNC, (char *)&onoff);
-#endif /* defined(TN3270) && !defined(DEBUG) */
+#if    defined(TN3270)
+    if (noasynch == 0) {
+       ioctl(tin, FIOASYNC, (char *)&onoff);
+    }
+#endif /* defined(TN3270) */
 
     if (MODE_LINE(f)) {
        void doescape();
 
     if (MODE_LINE(f)) {
        void doescape();
@@ -1016,24 +1019,30 @@ tninit()
 static void
 makeargv()
 {
 static void
 makeargv()
 {
-       register char *cp;
-       register char **argp = margv;
+    register char *cp;
+    register char **argp = margv;
 
 
-       margc = 0;
-       for (cp = line; *cp;) {
-               while (isspace(*cp))
-                       cp++;
-               if (*cp == '\0')
-                       break;
-               *argp++ = cp;
-               margc += 1;
-               while (*cp != '\0' && !isspace(*cp))
-                       cp++;
-               if (*cp == '\0')
-                       break;
-               *cp++ = '\0';
-       }
-       *argp++ = 0;
+    margc = 0;
+    cp = line;
+    if (*cp == '!') {          /* Special case shell escape */
+       *argp++ = "!";          /* No room in string to get this */
+       margc++;
+       cp++;
+    }
+    while (*cp) {
+       while (isspace(*cp))
+           cp++;
+       if (*cp == '\0')
+           break;
+       *argp++ = cp;
+       margc += 1;
+       while (*cp != '\0' && !isspace(*cp))
+           cp++;
+       if (*cp == '\0')
+           break;
+       *cp++ = '\0';
+    }
+    *argp++ = 0;
 }
 
 static char *ambiguous;                /* special return value */
 }
 
 static char *ambiguous;                /* special return value */
@@ -1890,6 +1899,7 @@ SetIn3270()
        if (In3270) {
            StopScreen(1);
            In3270 = 0;
        if (In3270) {
            StopScreen(1);
            In3270 = 0;
+           Stop3270();         /* Tell 3270 we aren't here anymore */
            setconnmode();
        }
     }
            setconnmode();
        }
     }
@@ -2288,6 +2298,9 @@ static void
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
 Finish3270()
 {
     while (Push3270() || !DoTerminalOutput()) {
+#if    defined(unix)
+       HaveInput = 0;
+#endif /* defined(unix) */
        ;
     }
 }
        ;
     }
 }
@@ -2374,7 +2387,17 @@ int returnCode;
 
 #endif /* defined(TN3270) */
 \f
 
 #endif /* defined(TN3270) */
 \f
-static
+/*
+ * Scheduler()
+ *
+ * Try to do something.
+ *
+ * If we do something useful, return 1; else return 0.
+ *
+ */
+
+
+int
 Scheduler(block)
 int    block;                  /* should we block in the select ? */
 {
 Scheduler(block)
 int    block;                  /* should we block in the select ? */
 {
@@ -2398,7 +2421,7 @@ int       block;                  /* should we block in the select ? */
     if (TTYBYTES()) {
        FD_SET(tout, &obits);
     }
     if (TTYBYTES()) {
        FD_SET(tout, &obits);
     }
-    if ((tcc == 0) && NETROOM()) {
+    if ((tcc == 0) && NETROOM() && (shell_active == 0)) {
        FD_SET(tin, &ibits);
     }
 #endif /* !defined(MSDOS) */
        FD_SET(tin, &ibits);
     }
 #endif /* !defined(MSDOS) */
@@ -2550,7 +2573,7 @@ int       block;                  /* should we block in the select ? */
      * Something to read from the tty...
      */
 #if    defined(MSDOS)
      * Something to read from the tty...
      */
 #if    defined(MSDOS)
-    if ((tcc == 0) && NETROOM() && TerminalCanRead())
+    if ((tcc == 0) && NETROOM() && (shell_active == 0) && TerminalCanRead())
 #else  /* defined(MSDOS) */
     if (FD_ISSET(tin, &ibits))
 #endif /* defined(MSDOS) */
 #else  /* defined(MSDOS) */
     if (FD_ISSET(tin, &ibits))
 #endif /* defined(MSDOS) */
@@ -2706,10 +2729,9 @@ telnet()
     NetNonblockingIO(net, 1);
 
 #if    defined(TN3270)
     NetNonblockingIO(net, 1);
 
 #if    defined(TN3270)
-#if    !defined(DEBUG)         /* DBX can't handle! */
-    NetSigIO(net, 1);
-#endif /* !defined(DEBUG) */
-
+    if (noasynch == 0) {                       /* DBX can't handle! */
+       NetSigIO(net, 1);
+    }
     NetSetPgrp(net);
 #endif /* defined(TN3270) */
 
     NetSetPgrp(net);
 #endif /* defined(TN3270) */
 
@@ -2759,9 +2781,30 @@ telnet()
        if (tfrontp-tbackp) {
            schedValue = 1;
        } else {
        if (tfrontp-tbackp) {
            schedValue = 1;
        } else {
-           schedValue = DoTerminalOutput();
+           if (shell_active) {
+#if    defined(MSDOS)
+               static int haventstopped = 1;
+
+               setcommandmode();
+               if (haventstopped) {
+                   StopScreen(1);
+                   haventstopped = 0;
+               }
+#endif /* defined(MSDOS) */
+               if (shell_continue() == 0) {
+                   ConnectScreen();
+#if    defined(MSDOS)
+                   haventstopped = 1;
+#endif /* defined(MSDOS) */
+               }
+#if    defined(MSDOS)
+               setconnmode();
+#endif /* defined(MSDOS) */
+           } else {
+               schedValue = DoTerminalOutput();
+           }
        }
        }
-       if (schedValue) {
+       if (schedValue && (shell_active == 0)) {
            if (Scheduler(SCHED_BLOCK) == -1) {
                setcommandmode();
                return;
            if (Scheduler(SCHED_BLOCK) == -1) {
                setcommandmode();
                return;
@@ -3391,9 +3434,10 @@ suspend()
        setcommandmode();
 #if    defined(unix)
        kill(0, SIGTSTP);
        setcommandmode();
 #if    defined(unix)
        kill(0, SIGTSTP);
+#endif /* defined(unix) */
        /* reget parameters in case they were changed */
        TerminalSaveState();
        /* reget parameters in case they were changed */
        TerminalSaveState();
-#endif /* defined(unix) */
+       setconnmode();
        return 1;
 }
 
        return 1;
 }
 
@@ -3642,9 +3686,9 @@ static char
 #if    defined(unix)
        zhelp[] =       "suspend telnet",
 #endif /* defined(unix */
 #if    defined(unix)
        zhelp[] =       "suspend telnet",
 #endif /* defined(unix */
-#if    defined(MSDOS)
+#if    defined(TN3270)
        shellhelp[] =   "invoke a subshell",
        shellhelp[] =   "invoke a subshell",
-#endif /* defined(MSDOS) */
+#endif /* defined(TN3270) */
        modehelp[] = "try to enter line-by-line or character-at-a-time mode";
 
 extern int     help(), shell();
        modehelp[] = "try to enter line-by-line or character-at-a-time mode";
 
 extern int     help(), shell();
@@ -3665,9 +3709,9 @@ static struct cmd cmdtab[] = {
 #if    defined(unix)
        { "z",          zhelp,          suspend,        1, 0 },
 #endif /* defined(unix) */
 #if    defined(unix)
        { "z",          zhelp,          suspend,        1, 0 },
 #endif /* defined(unix) */
-#if    defined(MSDOS)
-       { "!",          shellhelp,      shell,          1, 0 },
-#endif /* defined(MSDOS) */
+#if    defined(TN3270)
+       { "!",          shellhelp,      shell,          1, 1 },
+#endif /* defined(TN3270) */
        { "?",          helphelp,       help,           1, 0 },
        0
 };
        { "?",          helphelp,       help,           1, 0 },
        0
 };
@@ -3725,51 +3769,53 @@ void
 command(top)
        int top;
 {
 command(top)
        int top;
 {
-       register struct cmd *c;
+    register struct cmd *c;
 
 
-       setcommandmode();
-       if (!top) {
-               putchar('\n');
-       } else {
+    setcommandmode();
+    if (!top) {
+       putchar('\n');
+    } else {
 #if    defined(unix)
 #if    defined(unix)
-               signal(SIGINT, SIG_DFL);
-               signal(SIGQUIT, SIG_DFL);
+       signal(SIGINT, SIG_DFL);
+       signal(SIGQUIT, SIG_DFL);
 #endif /* defined(unix) */
 #endif /* defined(unix) */
+    }
+    for (;;) {
+       printf("%s> ", prompt);
+       if (gets(line) == NULL) {
+           if (feof(stdin) || ferror(stdin))
+               quit();
+           break;
        }
        }
-       for (;;) {
-               printf("%s> ", prompt);
-               if (gets(line) == NULL) {
-                       if (feof(stdin) || ferror(stdin))
-                               quit();
-                       break;
-               }
-               if (line[0] == 0)
-                       break;
-               makeargv();
-               c = getcmd(margv[0]);
-               if (c == Ambiguous(struct cmd *)) {
-                       printf("?Ambiguous command\n");
-                       continue;
-               }
-               if (c == 0) {
-                       printf("?Invalid command\n");
-                       continue;
-               }
-               if (c->needconnect && !connected) {
-                       printf("?Need to be connected first.\n");
-                       continue;
-               }
-               if ((*c->handler)(margc, margv)) {
-                       break;
-               }
+       if (line[0] == 0)
+           break;
+       makeargv();
+       c = getcmd(margv[0]);
+       if (c == Ambiguous(struct cmd *)) {
+           printf("?Ambiguous command\n");
+           continue;
        }
        }
-       if (!top) {
-               if (!connected) {
-                       longjmp(toplevel, 1);
-                       /*NOTREACHED*/
-               }
-               setconnmode();
+       if (c == 0) {
+           printf("?Invalid command\n");
+           continue;
+       }
+       if (c->needconnect && !connected) {
+           printf("?Need to be connected first.\n");
+           continue;
+       }
+       if ((*c->handler)(margc, margv)) {
+           break;
        }
        }
+    }
+    if (!top) {
+       if (!connected) {
+           longjmp(toplevel, 1);
+           /*NOTREACHED*/
+       }
+       if (shell_active == 0) {
+           setconnmode();
+       }
+    }
 }
 \f
 /*
 }
 \f
 /*
@@ -3822,41 +3868,55 @@ main(argc, argv)
     autoflush = TerminalAutoFlush();
 
     prompt = argv[0];
     autoflush = TerminalAutoFlush();
 
     prompt = argv[0];
-    if (argc > 1 && !strcmp(argv[1], "-d")) {
-       debug = 1;
-       argv++;
-       argc--;
-    }
-    if (argc > 1 && !strcmp(argv[1], "-n")) {
-       argv++;
-       argc--;
-       if (argc > 1) {         /* get file name */
-           NetTrace = fopen(argv[1], "w");
-           argv++;
-           argc--;
-           if (NetTrace == NULL) {
-               NetTrace = stdout;
+    while ((argc > 1) && (argv[1][0] == '-')) {
+       if (!strcmp(argv[1], "-d")) {
+           debug = 1;
+       } else if (!strcmp(argv[1], "-n")) {
+           if ((argc > 1) && (argv[2][0] != '-')) {    /* get file name */
+               NetTrace = fopen(argv[2], "w");
+               argv++;
+               argc--;
+               if (NetTrace == NULL) {
+                   NetTrace = stdout;
+               }
            }
            }
-       }
-    }
+       } else {
 #if    defined(TN3270) && defined(unix)
 #if    defined(TN3270) && defined(unix)
-    if (argc > 1 && !strcmp(argv[1], "-t")) {
-       argv++;
-       argc--;
-       if (argc > 1) {         /* get command name */
-           transcom = tline;
-           (void) strcpy(transcom, argv[1]);
-           argv++;
-           argc--;
+           if (!strcmp(argv[1], "-t")) {
+               if ((argc > 1) && (argv[1][0] != '-')) { /* get file name */
+                   transcom = tline;
+                   (void) strcpy(transcom, argv[1]);
+                   argv++;
+                   argc--;
+               }
+           } else if (!strcmp(argv[1], "-noasynch")) {
+               noasynch = 1;
+           } else
+#endif /* defined(TN3270) && defined(unix) */
+           if (argv[1][1] != '\0') {
+               fprintf(stderr, "Unknown option *%s*.\n", argv[1]);
+           }
        }
        }
+       argc--;
+       argv++;
     }
     }
-#endif /* defined(TN3270) && defined(unix) */
     if (argc != 1) {
        if (setjmp(toplevel) != 0)
            Exit(0);
        tn(argc, argv);
     }
     setjmp(toplevel);
     if (argc != 1) {
        if (setjmp(toplevel) != 0)
            Exit(0);
        tn(argc, argv);
     }
     setjmp(toplevel);
-    for (;;)
+    for (;;) {
+#if    !defined(TN3270)
        command(1);
        command(1);
+#else  /* !defined(TN3270) */
+       if (!shell_active) {
+           command(1);
+       } else {
+#if    defined(TN3270)
+           shell_continue();
+#endif /* defined(TN3270) */
+       }
+#endif /* !defined(TN3270) */
+    }
 }
 }