BSD 4_3_Reno release
[unix-history] / usr / src / libexec / getty / subr.c
index 9361808..c423948 100644 (file)
@@ -1,10 +1,30 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)subr.c     4.2 (Berkeley) 83/07/07";
-#endif
+static char sccsid[] = "@(#)subr.c     5.7 (Berkeley) 6/1/90";
+#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 +130,7 @@ setchars()
                if (p && *p)
                        *charvars[i] = *p;
                else
                if (p && *p)
                        *charvars[i] = *p;
                else
-                       *charvars[i] = '\0377';
+                       *charvars[i] = '\377';
        }
 }
 
        }
 }
 
@@ -171,6 +191,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 +203,9 @@ setflags(n)
        if (XC)
                f |= CTLECH;
 
        if (XC)
                f |= CTLECH;
 
+       if (DX)
+               f |= DECCTQ;
+
        return (f);
 }
 
        return (f);
 }
 
@@ -322,7 +348,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)
@@ -376,6 +402,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 }
 };
 
@@ -406,3 +433,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);
+}