# 2.11BSD#431 - /usr/src/lib/libc/gen/getttyent.c

##### Functions

    endttyent         X
    getttyent         X
    setttyent         X

##### Macros

    LINE              X
    QUOTED            X
    space             X

       1: /*
       2:  * Copyright (c) 1985 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #if defined(LIBC_SCCS) && !defined(lint)
       8: static char sccsid[] = "@(#)getttyent.c	5.4 (Berkeley) 5/19/86";
       9: #endif LIBC_SCCS and not lint
      10:
      11: #include <stdio.h>
      12: #include <strings.h>
      13: #include <ttyent.h>
      14:
      15: static char TTYFILE[] = "/etc/ttys";
      16: static char zapchar;
      17: static FILE *tf = NULL;
      18: #define LINE 256
      19: static char line[LINE];
      20: static struct ttyent tty;
      21:
      22: setttyent()
      23: {
      24:     if (tf == NULL)
      25:         tf = fopen(TTYFILE, "r");
      26:     else
      27:         rewind(tf);
      28: }
      29:
      30: endttyent()
      31: {
      32:     if (tf != NULL) {
      33:         (void) fclose(tf);
      34:         tf = NULL;
      35:     }
      36: }
      37:
      38: #define QUOTED  1
      39:
      40: /*
      41:  * Skip over the current field, removing quotes,
      42:  * and return a pointer to the next field.
      43:  */
      44: static char *
      45: skip(p)
      46:     register char *p;
      47: {
      48:     register char *t = p;
      49:     register int c;
      50:     register int q = 0;
      51:
      52:     for (; (c = *p) != '\0'; p++) {
      53:         if (c == '"') {
      54:             q ^= QUOTED;    /* obscure, but nice */
      55:             continue;
      56:         }
      57:         if (q == QUOTED && *p == '\\' && *(p+1) == '"')
      58:             p++;
      59:         *t++ = *p;
      60:         if (q == QUOTED)
      61:             continue;
      62:         if (c == '#') {
      63:             zapchar = c;
      64:             *p = 0;
      65:             break;
      66:         }
      67:         if (c == '\t' || c == ' ' || c == '\n') {
      68:             zapchar = c;
      69:             *p++ = 0;
      70:             while ((c = *p) == '\t' || c == ' ' || c == '\n')
      71:                 p++;
      72:             break;
      73:         }
      74:     }
      75:     *--t = '\0';
      76:     return (p);
      77: }
      78:
      79: static char *
      80: value(p)
      81:     register char *p;
      82: {
      83:     if ((p = index(p,'=')) == 0)
      84:         return(NULL);
      85:     p++;            /* get past the = sign */
      86:     return(p);
      87: }
      88:
      89: struct ttyent *
      90: getttyent()
      91: {
      92:     register char *p;
      93:     register int c;
      94:
      95:     if (tf == NULL) {
      96:         if ((tf = fopen(TTYFILE, "r")) == NULL)
      97:             return (NULL);
      98:     }
      99:     do {
     100:         p = fgets(line, LINE, tf);
     101:         if (p == NULL)
     102:             return (NULL);
     103:         while ((c = *p) == '\t' || c == ' ' || c == '\n')
     104:             p++;
     105:     } while (c == '\0' || c == '#');
     106:     zapchar = 0;
     107:     tty.ty_name = p;
     108:     p = skip(p);
     109:     tty.ty_getty = p;
     110:     p = skip(p);
     111:     tty.ty_type = p;
     112:     p = skip(p);
     113:     tty.ty_status = 0;
     114:     tty.ty_window = NULL;
     115:     for (; *p; p = skip(p)) {
     116: #define space(x) ((c = p[x]) == ' ' || c == '\t' || c == '\n')
     117:         if (strncmp(p, "on", 2) == 0 && space(2))
     118:             tty.ty_status |= TTY_ON;
     119:         else if (strncmp(p, "off", 3) == 0 && space(3))
     120:             tty.ty_status &= ~TTY_ON;
     121:         else if (strncmp(p, "secure", 6) == 0 && space(6))
     122:             tty.ty_status |= TTY_SECURE;
     123:         else if (strncmp(p, "window=", 7) == 0)
     124:             tty.ty_window = value(p);
     125:         else
     126:             break;
     127:     }
     128:     if (zapchar == '#' || *p == '#')
     129:         while ((c = *++p) == ' ' || c == '\t')
     130:             ;
     131:     tty.ty_comment = p;
     132:     if (*p == 0)
     133:         tty.ty_comment = 0;
     134:     if (p = index(p, '\n'))
     135:         *p = '\0';
     136:     return(&tty);
     137: }

#### Defined functions

endttyent defined in line 30; used 4 times

- in /usr/src/lib/libc/gen/getttynam.c line 24
- in /usr/src/lib/libc/gen/ttyslot.c line 42-46(2)
- in /usr/src/sbin/init/init.c line 474

getttyent defined in line 89; used 5 times

- in /usr/include/ttyent.h line 21
- in /usr/src/include/ttyent.h line 21
- in /usr/src/lib/libc/gen/getttynam.c line 20
- in /usr/src/lib/libc/gen/ttyslot.c line 39
- in /usr/src/sbin/init/init.c line 427

setttyent defined in line 22; used 3 times

- in /usr/src/lib/libc/gen/getttynam.c line 19
- in /usr/src/lib/libc/gen/ttyslot.c line 37
- in /usr/src/sbin/init/init.c line 426

skip defined in line 44; used 4 times

- in line 108-115(4)

value defined in line 79; used 1 times

- in line 124

#### Defined variables

TTYFILE defined in line 15; used 2 times

- in line 25, 96

line defined in line 19; used 1 times

- in line 100

sccsid defined in line 8; never used
tty defined in line 20; used 12 times

- in line 107-124(9), 131-136(3)

zapchar defined in line 16; used 4 times

- in line 63-68(2), 106, 128

#### Defined macros

LINE defined in line 18; used 2 times

- in line 19, 100

QUOTED defined in line 38; used 3 times

- in line 54-60(3)

space defined in line 116; used 3 times

- in line 117-121(3)

Last modified: 1986-05-20 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 738 |