lint, and others
[unix-history] / usr / src / usr.bin / window / ttinit.c
CommitLineData
11dcbb27 1#ifndef lint
edc20be7 2static char sccsid[] = "@(#)ttinit.c 3.13 %G%";
11dcbb27
EW
3#endif
4
5#include "ww.h"
e908bfac 6#include "tt.h"
11dcbb27 7
b27a9cfb
EW
8int tt_h19();
9int tt_h29();
10int tt_f100();
3ea27f21 11int tt_tvi925();
b27a9cfb
EW
12int tt_generic();
13struct tt_tab tt_tab[] = {
14 { "h19", 3, tt_h19 },
15 { "h29", 3, tt_h29 },
16 { "f100", 4, tt_f100 },
3ea27f21 17 { "tvi925", 6, tt_tvi925 },
b27a9cfb
EW
18 { "generic", 0, tt_generic },
19 0
20};
21
11dcbb27
EW
22ttinit()
23{
24 register struct tt_tab *tp;
078fe826
EW
25 register char *p, *q;
26 register char *t;
b27a9cfb 27 struct winsize winsize;
11dcbb27 28
4222244b
EW
29 tt_strp = tt_strings;
30
b1189050
EW
31 /*
32 * Set output buffer size to about 1 second of output time.
33 */
34 tt_obp = tt_ob;
35 tt_obe = tt_ob + MIN(wwbaud/10, sizeof tt_ob);
36
078fe826
EW
37 /*
38 * Use the standard name of the terminal (i.e. the second
39 * name in termcap).
40 */
41 for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++)
42 ;
43 if (*p == '|')
44 p++;
45 for (q = p; *q && *q != '|' && *q != ':'; q++)
46 ;
94c16993 47 if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) {
078fe826
EW
48 wwterm = t;
49 while (p < q)
50 *t++ = *p++;
51 *t = 0;
52 }
11dcbb27
EW
53 for (tp = tt_tab; tp->tt_name != 0; tp++)
54 if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0)
55 break;
03e75950
EW
56 if (tp->tt_name == 0) {
57 wwerrno = WWE_BADTERM;
11dcbb27 58 return -1;
03e75950
EW
59 }
60 if ((*tp->tt_func)() < 0) {
61 wwerrno = WWE_CANTDO;
62 return -1;
63 }
edc20be7
EW
64 if (ioctl(0, (int)TIOCGWINSZ, (char *)&winsize) >= 0 &&
65 winsize.ws_row != 0 && winsize.ws_col != 0) {
b27a9cfb
EW
66 tt.tt_nrow = winsize.ws_row;
67 tt.tt_ncol = winsize.ws_col;
68 }
03e75950 69 return 0;
11dcbb27 70}