4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / libexec / getty / subr.c
index 51c8a32..1508596 100644 (file)
@@ -1,18 +1,26 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)subr.c     5.1 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)subr.c     8.1 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Melbourne getty.
  */
 
 /*
  * Melbourne getty.
  */
+#define USE_OLD_TTY
+#include <stdlib.h>
 #include <sgtty.h>
 #include <sgtty.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "gettytab.h"
 #include "gettytab.h"
+#include "extern.h"
+#include "pathnames.h"
 
 extern struct sgttyb tmode;
 extern struct tchars tc;
 
 extern struct sgttyb tmode;
 extern struct tchars tc;
@@ -21,23 +29,25 @@ extern      struct ltchars ltc;
 /*
  * Get a table entry.
  */
 /*
  * Get a table entry.
  */
-gettable(name, buf, area)
-       char *name, *buf, *area;
+void
+gettable(name, buf)
+       char *name, *buf;
 {
        register struct gettystrs *sp;
        register struct gettynums *np;
        register struct gettyflags *fp;
 {
        register struct gettystrs *sp;
        register struct gettynums *np;
        register struct gettyflags *fp;
-       register n;
+       long n;
+       char *dba[2];
+       dba[0] = _PATH_GETTYTAB;
+       dba[1] = 0;
 
 
-       hopcount = 0;           /* new lookup, start fresh */
-       if (getent(buf, name) != 1)
+       if (cgetent(&buf, dba, name) != 0)
                return;
 
                return;
 
-       for (sp = gettystrs; sp->field; sp++)
-               sp->value = getstr(sp->field, &area);
+       for (sp = gettystrs; sp->field; sp++) 
+               cgetstr(buf, sp->field, &sp->value);
        for (np = gettynums; np->field; np++) {
        for (np = gettynums; np->field; np++) {
-               n = getnum(np->field);
-               if (n == -1)
+               if (cgetnum(buf, np->field, &n) == -1)
                        np->set = 0;
                else {
                        np->set = 1;
                        np->set = 0;
                else {
                        np->set = 1;
@@ -45,16 +55,27 @@ gettable(name, buf, area)
                }
        }
        for (fp = gettyflags; fp->field; fp++) {
                }
        }
        for (fp = gettyflags; fp->field; fp++) {
-               n = getflag(fp->field);
-               if (n == -1)
+               if (cgetcap(buf, fp->field, ':') == NULL)
                        fp->set = 0;
                else {
                        fp->set = 1;
                        fp->set = 0;
                else {
                        fp->set = 1;
-                       fp->value = n ^ fp->invrt;
+                       fp->value = 1 ^ fp->invrt;
                }
        }
                }
        }
+#ifdef DEBUG
+       printf("name=\"%s\", buf=\"%s\"\n", name, buf);
+       for (sp = gettystrs; sp->field; sp++)
+               printf("cgetstr: %s=%s\n", sp->field, sp->value);
+       for (np = gettynums; np->field; np++)
+               printf("cgetnum: %s=%d\n", np->field, np->value);
+       for (fp = gettyflags; fp->field; fp++)
+               printf("cgetflags: %s='%c' set='%c'\n", fp->field, 
+                      fp->value + '0', fp->set + '0');
+       exit(1);
+#endif /* DEBUG */
 }
 
 }
 
+void
 gendefaults()
 {
        register struct gettystrs *sp;
 gendefaults()
 {
        register struct gettystrs *sp;
@@ -74,6 +95,7 @@ gendefaults()
                        fp->defalt = fp->invrt;
 }
 
                        fp->defalt = fp->invrt;
 }
 
+void
 setdefaults()
 {
        register struct gettystrs *sp;
 setdefaults()
 {
        register struct gettystrs *sp;
@@ -106,6 +128,7 @@ charvars[] = {
        &ltc.t_werasc, &ltc.t_lnextc, 0
 };
 
        &ltc.t_werasc, &ltc.t_lnextc, 0
 };
 
+void
 setchars()
 {
        register int i;
 setchars()
 {
        register int i;
@@ -116,12 +139,13 @@ setchars()
                if (p && *p)
                        *charvars[i] = *p;
                else
                if (p && *p)
                        *charvars[i] = *p;
                else
-                       *charvars[i] = '\0377';
+                       *charvars[i] = '\377';
        }
 }
 
 long
 setflags(n)
        }
 }
 
 long
 setflags(n)
+       int n;
 {
        register long f;
 
 {
        register long f;
 
@@ -189,6 +213,9 @@ setflags(n)
        if (XC)
                f |= CTLECH;
 
        if (XC)
                f |= CTLECH;
 
+       if (DX)
+               f |= DECCTQ;
+
        return (f);
 }
 
        return (f);
 }
 
@@ -202,44 +229,45 @@ struct delayval {
  */
 
 struct delayval        crdelay[] = {
  */
 
 struct delayval        crdelay[] = {
-       1,              CR1,
-       2,              CR2,
-       3,              CR3,
-       83,             CR1,
-       166,            CR2,
-       0,              CR3,
+       { 1,            CR1 },
+       { 2,            CR2 },
+       { 3,            CR3 },
+       { 83,           CR1 },
+       { 166,          CR2 },
+       { 0,            CR3 },
 };
 
 struct delayval nldelay[] = {
 };
 
 struct delayval nldelay[] = {
-       1,              NL1,            /* special, calculated */
-       2,              NL2,
-       3,              NL3,
-       100,            NL2,
-       0,              NL3,
+       { 1,            NL1 },          /* special, calculated */
+       { 2,            NL2 },
+       { 3,            NL3 },
+       { 100,          NL2 },
+       { 0,            NL3 },
 };
 
 struct delayval        bsdelay[] = {
 };
 
 struct delayval        bsdelay[] = {
-       1,              BS1,
-       0,              0,
+       { 1,            BS1 },
+       { 0,            0 },
 };
 
 struct delayval        ffdelay[] = {
 };
 
 struct delayval        ffdelay[] = {
-       1,              FF1,
-       1750,           FF1,
-       0,              FF1,
+       { 1,            FF1 },
+       { 1750,         FF1 },
+       { 0,            FF1 },
 };
 
 struct delayval        tbdelay[] = {
 };
 
 struct delayval        tbdelay[] = {
-       1,              TAB1,
-       2,              TAB2,
-       3,              XTABS,          /* this is expand tabs */
-       100,            TAB1,
-       0,              TAB2,
+       { 1,             TAB1 },
+       { 2,             TAB2 },
+       { 3,            XTABS },        /* this is expand tabs */
+       { 100,           TAB1 },
+       { 0,             TAB2 },
 };
 
 };
 
+int
 delaybits()
 {
 delaybits()
 {
-       register f;
+       register int f;
 
        f  = adelay(CD, crdelay);
        f |= adelay(ND, nldelay);
 
        f  = adelay(CD, crdelay);
        f |= adelay(ND, nldelay);
@@ -249,6 +277,7 @@ delaybits()
        return (f);
 }
 
        return (f);
 }
 
+int
 adelay(ms, dp)
        register ms;
        register struct delayval *dp;
 adelay(ms, dp)
        register ms;
        register struct delayval *dp;
@@ -262,6 +291,7 @@ adelay(ms, dp)
 
 char   editedhost[32];
 
 
 char   editedhost[32];
 
+void
 edithost(pat)
        register char *pat;
 {
 edithost(pat)
        register char *pat;
 {
@@ -305,28 +335,30 @@ struct speedtab {
        int     speed;
        int     uxname;
 } speedtab[] = {
        int     speed;
        int     uxname;
 } speedtab[] = {
-       50,     B50,
-       75,     B75,
-       110,    B110,
-       134,    B134,
-       150,    B150,
-       200,    B200,
-       300,    B300,
-       600,    B600,
-       1200,   B1200,
-       1800,   B1800,
-       2400,   B2400,
-       4800,   B4800,
-       9600,   B9600,
-       19200,  EXTA,
-       19,     EXTA,           /* for people who say 19.2K */
-       38400,  EXTB,
-       38,     EXTB,
-       7200,   EXTB,           /* alternative */
-       0
+       { 50,     B50 },
+       { 75,     B75 },
+       { 110,   B110 },
+       { 134,   B134 },
+       { 150,   B150 },
+       { 200,   B200 },
+       { 300,   B300 },
+       { 600,   B600 },
+       { 1200, B1200 },
+       { 1800, B1800 },
+       { 2400, B2400 },
+       { 4800, B4800 },
+       { 9600, B9600 },
+       { 19200, EXTA },
+       { 19,    EXTA },        /* for people who say 19.2K */
+       { 38400, EXTB },
+       { 38,    EXTB },
+       { 7200,  EXTB },        /* alternative */
+       { 0 }
 };
 
 };
 
+int
 speed(val)
 speed(val)
+       int val;
 {
        register struct speedtab *sp;
 
 {
        register struct speedtab *sp;
 
@@ -340,13 +372,13 @@ speed(val)
        return (B300);          /* default in impossible cases */
 }
 
        return (B300);          /* default in impossible cases */
 }
 
+void
 makeenv(env)
        char *env[];
 {
        static char termbuf[128] = "TERM=";
        register char *p, *q;
        register char **ep;
 makeenv(env)
        char *env[];
 {
        static char termbuf[128] = "TERM=";
        register char *p, *q;
        register char **ep;
-       char *index();
 
        ep = env;
        if (TT && *TT) {
 
        ep = env;
        if (TT && *TT) {
@@ -355,7 +387,7 @@ makeenv(env)
        }
        if (p = EV) {
                q = p;
        }
        if (p = EV) {
                q = p;
-               while (q = index(q, ',')) {
+               while (q = strchr(q, ',')) {
                        *q++ = '\0';
                        *ep++ = p;
                        p = q;
                        *q++ = '\0';
                        *ep++ = p;
                        p = q;
@@ -385,6 +417,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 }
 };
 
@@ -397,7 +430,7 @@ portselector()
 
        alarm(5*60);
        for (len = 0; len < sizeof (baud) - 1; len++) {
 
        alarm(5*60);
        for (len = 0; len < sizeof (baud) - 1; len++) {
-               if (read(0, &c, 1) <= 0)
+               if (read(STDIN_FILENO, &c, 1) <= 0)
                        break;
                c &= 0177;
                if (c == '\n' || c == '\r')
                        break;
                c &= 0177;
                if (c == '\n' || c == '\r')
@@ -435,13 +468,15 @@ autobaud()
        rfds = 1 << 0;
        timeout.tv_sec = 5;
        timeout.tv_usec = 0;
        rfds = 1 << 0;
        timeout.tv_sec = 5;
        timeout.tv_usec = 0;
-       if (select(32, &rfds, (int *)0, (int *)0, &timeout) <= 0)
+       if (select(32, (fd_set *)&rfds, (fd_set *)NULL,
+           (fd_set *)NULL, &timeout) <= 0)
                return (type);
                return (type);
-       if (read(0, &c, sizeof(char)) != sizeof(char))
+       if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char))
                return (type);
        timeout.tv_sec = 0;
        timeout.tv_usec = 20;
                return (type);
        timeout.tv_sec = 0;
        timeout.tv_usec = 20;
-       (void) select(32, (int *)0, (int *)0, (int *)0, &timeout);
+       (void) select(32, (fd_set *)NULL, (fd_set *)NULL,
+           (fd_set *)NULL, &timeout);
        ioctl(0, TIOCFLUSH, &null);
        switch (c & 0377) {
 
        ioctl(0, TIOCFLUSH, &null);
        switch (c & 0377) {