make escape escape force escape
[unix-history] / usr / src / usr.bin / tip / tip.c
index 5f95728..5b80ffc 100644 (file)
@@ -1,4 +1,4 @@
-/*     tip.c   4.3     81/05/18        */
+/*     tip.c   4.7     81/08/16        */
 /*
  * tip - Unix link to other systems
  *  tip [-v] [-speed] system-name
 /*
  * tip - Unix link to other systems
  *  tip [-v] [-speed] system-name
@@ -43,6 +43,9 @@
  * honor uucp locks
  * rewrite remote file stuff for DN-11 like acu's and just to clean
  *   it up
  * honor uucp locks
  * rewrite remote file stuff for DN-11 like acu's and just to clean
  *   it up
+ *
+ * sjl                 6-16-81
+ * real working setup for DN-11's
  */
 
 #include "tip.h"
  */
 
 #include "tip.h"
@@ -55,6 +58,10 @@ int bauds[] = {
        1200, 1800, 2400, 4800, 9600, 19200, -1
 };
 
        1200, 1800, 2400, 4800, 9600, 19200, -1
 };
 
+#ifdef VMUNIX
+int    disc = OTTYDISC;                /* tip normally runs this way */
+#endif
+
 int    intprompt();
 int    timeout();
 static int cleanup();
 int    intprompt();
 int    timeout();
 static int cleanup();
@@ -64,9 +71,6 @@ char *argv[];
 {
        char *system = NOSTR;
        register int i;
 {
        char *system = NOSTR;
        register int i;
-#ifdef VMUNIX
-       int disc;
-#endif
        char *p;
 
        if (argc > 4) {
        char *p;
 
        if (argc > 4) {
@@ -83,6 +87,7 @@ char *argv[];
        signal(SIGQUIT, cleanup);
        signal(SIGHUP, cleanup);
        signal(SIGTERM, cleanup);
        signal(SIGQUIT, cleanup);
        signal(SIGHUP, cleanup);
        signal(SIGTERM, cleanup);
+
        if ((i = hunt(system)) == 0) {
                printf("all ports busy\n");
                exit(3);
        if ((i = hunt(system)) == 0) {
                printf("all ports busy\n");
                exit(3);
@@ -119,44 +124,52 @@ char *argv[];
                        else
                                printf("%s: unknown option\n", argv[i]);
                }
                        else
                                printf("%s: unknown option\n", argv[i]);
                }
-       if ((arg.sg_ispeed = speed(number(value(BAUDRATE)))) == NULL) {
+       if ((i = speed(number(value(BAUDRATE)))) == NULL) {
                printf("tip: bad baud rate %d\n", number(value(BAUDRATE)));
                delock(uucplock);
                exit(3);
        }
                printf("tip: bad baud rate %d\n", number(value(BAUDRATE)));
                delock(uucplock);
                exit(3);
        }
-       arg.sg_ospeed = arg.sg_ispeed;
+
        /*
        /*
-        * NOTE that remote side runs in TANDEM mode,
-        *  if the host doesn't honor X-ON/X-OFF with default
-        *  start/stop chars, the remote description must be
-        *  extended and tchars will have to be set up here.
-        * If the host doesn't honor TANDEM mode, then watch
-        *  out, as you'll get garbage.
+        * Hardwired connections require the
+        *  line speed set before they make any transmissions
+        *  (this is particularly true of things like a DF03-AC)
         */
         */
-       arg.sg_flags = RAW | TANDEM;
-       ioctl(FD, TIOCSETP, &arg);
-
-       ioctl(0, TIOCGETP, &defarg);    /* store initial status */
-       ioctl(0, TIOCGETC, &defchars);
-       arg = defarg;
-       arg.sg_flags = ANYP | CBREAK;
-       tchars = defchars;
-       tchars.t_intrc = tchars.t_quitc = -1;
-
+       if (HW)
+               ttysetup(i);
        if (p = connect()) {
                printf("\07%s\n[EOT]\n", p);
                delock(uucplock);
                exit(1);
        }
        if (p = connect()) {
                printf("\07%s\n[EOT]\n", p);
                delock(uucplock);
                exit(1);
        }
-       write(1, "\07connected\n", 11);
-       raw();
+       if (!HW)
+               ttysetup(i);
+
+       /*
+        * Set up local tty state
+        */
+       ioctl(0, TIOCGETP, (char *)&defarg);
+       ioctl(0, TIOCGETC, (char *)&defchars);
 #ifdef VMUNIX
        ioctl(0, TIOCGETD, (char *)&odisc);
 #ifdef VMUNIX
        ioctl(0, TIOCGETD, (char *)&odisc);
-       disc = OTTYDISC;
-       ioctl(0, TIOCSETD, (char *)&disc);
 #endif
 #endif
+       arg = defarg;
+       arg.sg_flags = ANYP | CBREAK;
+       tchars = defchars;
+       tchars.t_intrc = tchars.t_quitc = -1;
+       raw();
+
        pipe(fildes); pipe(repdes);
        signal(SIGALRM, timeout);
        pipe(fildes); pipe(repdes);
        signal(SIGALRM, timeout);
+
+       /*
+        * Everything's set up now:
+        *      connection established (hardwired or diaulup)
+        *      line conditioned (baud rate, mode, etc.)
+        *      internal data structures (variables)
+        * so, fork one process for local side and one for remote.
+        */
+       write(1, "\07connected\r\n", 12);
        if (pid = fork())
                tipin();
        else
        if (pid = fork())
                tipin();
        else
@@ -168,6 +181,10 @@ static
 cleanup()
 {
        delock(uucplock);
 cleanup()
 {
        delock(uucplock);
+#ifdef VMUNIX
+       if (odisc)
+               ioctl(0, TIOCSETD, (char *)&odisc);
+#endif
        exit(0);
 }
 
        exit(0);
 }
 
@@ -178,6 +195,9 @@ raw()
 {
        ioctl(0, TIOCSETP, &arg);
        ioctl(0, TIOCSETC, &tchars);
 {
        ioctl(0, TIOCSETP, &arg);
        ioctl(0, TIOCSETC, &tchars);
+#ifdef VMUNIX
+       ioctl(0, TIOCSETD, (char *)&disc);
+#endif
 }
 
 
 }
 
 
@@ -186,8 +206,11 @@ raw()
  */
 unraw()
 {
  */
 unraw()
 {
-       ioctl(0, TIOCSETP, &defarg);
-       ioctl(0, TIOCSETC, &defchars);
+#ifdef VMUNIX
+       ioctl(0, TIOCSETD, (char *)&odisc);
+#endif
+       ioctl(0, TIOCSETP, (char *)&defarg);
+       ioctl(0, TIOCSETC, (char *)&defchars);
 }
 
 /*
 }
 
 /*
@@ -292,8 +315,9 @@ escape()
                        (*p->e_func)(gch);
                        return(0);
                }
                        (*p->e_func)(gch);
                        return(0);
                }
-
-       write(FD, &c, 1);
+       /* ESCAPE ESCAPE forces ESCAPE */
+       if (c != gch)
+               write(FD, &c, 1);
        return(gch);
 }
 
        return(gch);
 }
 
@@ -386,3 +410,21 @@ help(c)
                        p->e_flags&EXP ? '*': ' ', p->e_help);
        }
 }
                        p->e_flags&EXP ? '*': ' ', p->e_help);
        }
 }
+
+/*
+ * Set up the "remote" tty's state
+ */
+static
+ttysetup(speed)
+{
+#ifdef VMUNIX
+       unsigned bits = LDECCTQ;
+#endif
+
+       arg.sg_ispeed = arg.sg_ospeed = speed;
+       arg.sg_flags = TANDEM|RAW;
+       ioctl(FD, TIOCSETP, (char *)&arg);
+#ifdef VMUNIX
+       ioctl(FD, TIOCLBIS, (char *)&bits);
+#endif
+}