Commit | Line | Data |
---|---|---|
172f65b6 BJ |
1 | #include <stdio.h> |
2 | /* | |
3 | * typeof - return a 2 character teletype type code from /etc/ttywhere | |
4 | * Bill Joy UCB September 24, 1977 | |
5 | */ | |
6 | char ttytype[] "/etc/ttytype"; | |
7 | ||
8 | typeof(tty) | |
9 | char tty; | |
10 | { | |
11 | register int c, c2; | |
12 | FILE *ibuf; | |
13 | ||
14 | if ((ibuf = fopen(ttytype, "r")) == NULL) | |
15 | goto unknown; | |
16 | for (;;) { | |
17 | c = getc(ibuf); | |
18 | if (c == '\n' || c == -1) { | |
19 | unknown: | |
20 | fclose(ibuf); | |
21 | return('uk'); | |
22 | } | |
23 | if (c == tty) { | |
24 | c = getc(ibuf); | |
25 | if (c == '\n' || c == -1) | |
26 | goto unknown; | |
27 | c2 = getc(ibuf); | |
28 | if (c2 == '\n' || c2 == -1) | |
29 | goto unknown; | |
30 | fclose(ibuf); | |
31 | return (c2 << 8 | c); | |
32 | } | |
33 | do | |
34 | c = getc(ibuf); | |
35 | while (c != '\n' && c != -1); | |
36 | } | |
37 | } | |
38 | ||
39 | stypeof(tty) | |
40 | int tty; | |
41 | { | |
42 | static char stype[3]; | |
43 | ||
44 | tty = typeof(tty); | |
45 | stype[0] = tty& 0377; | |
46 | stype[1] = (tty >> 8) & 0377; | |
47 | return (stype); | |
48 | } |