document LOG_LPR facility
[unix-history] / usr / src / lib / libc / gen / getttyent.c
index 670e80f..f25b1f1 100644 (file)
@@ -1,12 +1,22 @@
-/* @(#)getttyent.c     4.1 (Berkeley) %G% */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getttyent.c        5.1 (Berkeley) %G%";
+#endif not lint
 
 #include <stdio.h>
 
 #include <stdio.h>
+#include <strings.h>
 #include <ttyent.h>
 
 static char TTYFILE[] = "/etc/ttys";
 static char EMPTY[] = "";
 static FILE *tf = NULL;
 #include <ttyent.h>
 
 static char TTYFILE[] = "/etc/ttys";
 static char EMPTY[] = "";
 static FILE *tf = NULL;
-static char line[BUFSIZ+1];
+#define LINE 256
+static char line[LINE];
 static struct ttyent tty;
 
 setttyent()
 static struct ttyent tty;
 
 setttyent()
@@ -25,13 +35,26 @@ endttyent()
        }
 }
 
        }
 }
 
+#define QUOTED 1
+
+/*
+ * Skip over the current field and 
+ * return a pointer to the next field.
+ */
 static char *
 skip(p)
 static char *
 skip(p)
-register char *p;
+       register char *p;
 {
        register int c;
 {
        register int c;
+       register int q = 0;
 
 
-       while ((c = *p) != '\0') {
+       for (; (c = *p) != '\0'; p++) {
+               if (c == '"') {
+                       q ^= QUOTED;    /* obscure, but nice */
+                       continue;
+               }
+               if (q == QUOTED)
+                       continue;
                if (c == '#') {
                        *p = '\0';
                        break;
                if (c == '#') {
                        *p = '\0';
                        break;
@@ -42,15 +65,38 @@ register char *p;
                                p++;
                        break;
                }
                                p++;
                        break;
                }
-               p++;
        }
        return (p);
 }
 
        }
        return (p);
 }
 
+static char *
+value(p)
+       register char *p;
+{
+       if ((p = index(p,'=')) == 0)
+               return(NULL);
+       p++;                    /* get past the = sign */
+       return(p);
+}
+
+/* get rid of quotes. */
+
+static
+qremove(p)
+       register char *p;
+{
+       register char *t;
+
+       for (t = p; *p; p++)
+               if (*p != '"')
+                       *t++ = *p;
+       *t = '\0';
+}
+
 struct ttyent *
 getttyent()
 {
 struct ttyent *
 getttyent()
 {
-       register char *p, *cp;
+       register char *p;
        register int c;
 
        if (tf == NULL) {
        register int c;
 
        if (tf == NULL) {
@@ -58,7 +104,7 @@ getttyent()
                        return (NULL);
        }
        do {
                        return (NULL);
        }
        do {
-               p = fgets(line, BUFSIZ, tf);
+               p = fgets(line, LINE, tf);
                if (p == NULL)
                        return (NULL);
                while ((c = *p) == '\t' || c == ' ' || c == '\n')
                if (p == NULL)
                        return (NULL);
                while ((c = *p) == '\t' || c == ' ' || c == '\n')
@@ -69,16 +115,27 @@ getttyent()
        tty.ty_getty = p;
        p = skip(p);
        tty.ty_type = p;
        tty.ty_getty = p;
        p = skip(p);
        tty.ty_type = p;
+       p = skip(p);
        tty.ty_status = 0;
        tty.ty_status = 0;
-       for (p = skip(p); *p; p = cp) {
-               cp = skip(p);
-               if (strcmp(p, "on") == 0)
+       tty.ty_window = EMPTY;
+       for (; *p; p = skip(p)) {
+               if (strncmp(p, "on", 2) == 0)
                        tty.ty_status |= TTY_ON;
                        tty.ty_status |= TTY_ON;
-               else if (strcmp(p, "off") == 0)
+               else if (strncmp(p, "off", 3) == 0)
                        tty.ty_status &= ~TTY_ON;
                        tty.ty_status &= ~TTY_ON;
-               else if (strcmp(p, "secure") == 0)
+               else if (strncmp(p, "secure", 6) == 0)
                        tty.ty_status |= TTY_SECURE;
                        tty.ty_status |= TTY_SECURE;
+               else if (strncmp(p, "window", 6) == 0) {
+                       if ((tty.ty_window = value(p)) == NULL)
+                               tty.ty_window = EMPTY;
+               } else
+                       break;
        }
        }
-       tty.ty_comment = EMPTY;
-       return (&tty);
+       tty.ty_comment = p;
+       if (p = index(p, '\n'))
+               *p = '\0';
+       qremove(tty.ty_getty);
+       qremove(tty.ty_window);
+       qremove(tty.ty_comment);
+       return(&tty);
 }
 }