SCCS munges %M%
[unix-history] / usr / src / libexec / getty / subr.c
index 29e20ea..920818b 100644 (file)
@@ -1,10 +1,18 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)subr.c     4.3 (Berkeley) 84/06/05";
-#endif
+static char sccsid[] = "@(#)subr.c     5.7 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Melbourne getty.
  */
 
 /*
  * Melbourne getty.
  */
+#define USE_OLD_TTY
 #include <sgtty.h>
 #include "gettytab.h"
 
 #include <sgtty.h>
 #include "gettytab.h"
 
@@ -110,7 +118,7 @@ setchars()
                if (p && *p)
                        *charvars[i] = *p;
                else
                if (p && *p)
                        *charvars[i] = *p;
                else
-                       *charvars[i] = '\0377';
+                       *charvars[i] = '\377';
        }
 }
 
        }
 }
 
@@ -183,6 +191,9 @@ setflags(n)
        if (XC)
                f |= CTLECH;
 
        if (XC)
                f |= CTLECH;
 
+       if (DX)
+               f |= DECCTQ;
+
        return (f);
 }
 
        return (f);
 }
 
@@ -325,7 +336,7 @@ speed(val)
        register struct speedtab *sp;
 
        if (val <= 15)
        register struct speedtab *sp;
 
        if (val <= 15)
-               return(val);
+               return (val);
 
        for (sp = speedtab; sp->speed; sp++)
                if (sp->speed == val)
 
        for (sp = speedtab; sp->speed; sp++)
                if (sp->speed == val)
@@ -379,6 +390,7 @@ struct      portselect {
        { "B2400",      "std.2400" },
        { "B4800",      "std.4800" },
        { "B9600",      "std.9600" },
        { "B2400",      "std.2400" },
        { "B4800",      "std.4800" },
        { "B9600",      "std.9600" },
+       { "B19200",     "std.19200" },
        { 0 }
 };
 
        { 0 }
 };
 
@@ -409,3 +421,56 @@ portselector()
        sleep(2);       /* wait for connection to complete */
        return (type);
 }
        sleep(2);       /* wait for connection to complete */
        return (type);
 }
+
+/*
+ * This auto-baud speed select mechanism is written for the Micom 600
+ * portselector. Selection is done by looking at how the character '\r'
+ * is garbled at the different speeds.
+ */
+#include <sys/time.h>
+
+char *
+autobaud()
+{
+       int rfds;
+       struct timeval timeout;
+       char c, *type = "9600-baud";
+       int null = 0;
+
+       ioctl(0, TIOCFLUSH, &null);
+       rfds = 1 << 0;
+       timeout.tv_sec = 5;
+       timeout.tv_usec = 0;
+       if (select(32, &rfds, (int *)0, (int *)0, &timeout) <= 0)
+               return (type);
+       if (read(0, &c, sizeof(char)) != sizeof(char))
+               return (type);
+       timeout.tv_sec = 0;
+       timeout.tv_usec = 20;
+       (void) select(32, (int *)0, (int *)0, (int *)0, &timeout);
+       ioctl(0, TIOCFLUSH, &null);
+       switch (c & 0377) {
+
+       case 0200:              /* 300-baud */
+               type = "300-baud";
+               break;
+
+       case 0346:              /* 1200-baud */
+               type = "1200-baud";
+               break;
+
+       case  015:              /* 2400-baud */
+       case 0215:
+               type = "2400-baud";
+               break;
+
+       default:                /* 4800-baud */
+               type = "4800-baud";
+               break;
+
+       case 0377:              /* 9600-baud */
+               type = "9600-baud";
+               break;
+       }
+       return (type);
+}