SCCS munges %M%
[unix-history] / usr / src / libexec / getty / subr.c
index de3c8e1..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.1 (Berkeley) 83/07/06";
-#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';
        }
 }
 
        }
 }
 
@@ -171,6 +179,9 @@ setflags(n)
        if (CE)
                f |= CRTERA;
 
        if (CE)
                f |= CRTERA;
 
+       if (CK)
+               f |= CRTKIL;
+
        if (PE)
                f |= PRTERA;
 
        if (PE)
                f |= PRTERA;
 
@@ -180,6 +191,9 @@ setflags(n)
        if (XC)
                f |= CTLECH;
 
        if (XC)
                f |= CTLECH;
 
+       if (DX)
+               f |= DECCTQ;
+
        return (f);
 }
 
        return (f);
 }
 
@@ -193,31 +207,38 @@ struct delayval {
  */
 
 struct delayval        crdelay[] = {
  */
 
 struct delayval        crdelay[] = {
-       20,             CR1,
-       30,             CR2,
-       40,             CR3,
+       1,              CR1,
+       2,              CR2,
+       3,              CR3,
+       83,             CR1,
+       166,            CR2,
        0,              CR3,
 };
 
 struct delayval nldelay[] = {
        1,              NL1,            /* special, calculated */
        0,              CR3,
 };
 
 struct delayval nldelay[] = {
        1,              NL1,            /* special, calculated */
-       16,             NL2,
-       30,             NL3,
+       2,              NL2,
+       3,              NL3,
+       100,            NL2,
        0,              NL3,
 };
 
 struct delayval        bsdelay[] = {
        0,              NL3,
 };
 
 struct delayval        bsdelay[] = {
+       1,              BS1,
        0,              0,
 };
 
 struct delayval        ffdelay[] = {
        0,              0,
 };
 
 struct delayval        ffdelay[] = {
+       1,              FF1,
        1750,           FF1,
        0,              FF1,
 };
 
 struct delayval        tbdelay[] = {
        1750,           FF1,
        0,              FF1,
 };
 
 struct delayval        tbdelay[] = {
-       10,             TAB1,
-       20,             TAB2,
+       1,              TAB1,
+       2,              TAB2,
+       3,              XTABS,          /* this is expand tabs */
+       100,            TAB1,
        0,              TAB2,
 };
 
        0,              TAB2,
 };
 
@@ -315,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)
@@ -369,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 }
 };
 
@@ -399,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);
+}