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