1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
7 *
8 * %sccs.include.redist.c%
9 */
10
11 #ifndef lint
12 static char sccsid[] = "@(#)ttinit.c 8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14
15 #include "ww.h"
16 #include "tt.h"
17
18 int tt_h19();
19 int tt_h29();
20 int tt_f100();
21 int tt_tvi925();
22 int tt_wyse75();
23 int tt_wyse60();
24 int tt_zapple();
25 int tt_zentec();
26 int tt_generic();
27 struct tt_tab tt_tab[] = {
28 { "h19", 3, tt_h19 },
29 { "h29", 3, tt_h29 },
30 { "f100", 4, tt_f100 },
31 { "tvi925", 6, tt_tvi925 },
32 { "wyse75", 6, tt_wyse75 },
33 { "wyse60", 6, tt_wyse60 },
34 { "w60", 3, tt_wyse60 },
35 { "zapple", 6, tt_zapple },
36 { "zentec", 6, tt_zentec },
37 { "generic", 0, tt_generic },
38 0
39 };
40
ttinit()41 ttinit()
42 {
43 int i;
44 register struct tt_tab *tp;
45 register char *p, *q;
46 register char *t;
47
48 tt_strp = tt_strings;
49
50 /*
51 * Set output buffer size to about 1 second of output time.
52 */
53 i = MIN(wwbaud/10, 512);
54 if ((tt_ob = malloc((unsigned) i)) == 0) {
55 wwerrno = WWE_NOMEM;
56 return -1;
57 }
58 tt_obp = tt_ob;
59 tt_obe = tt_ob + i;
60
61 /*
62 * Use the standard name of the terminal (i.e. the second
63 * name in termcap).
64 */
65 for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++)
66 ;
67 if (*p == '|')
68 p++;
69 for (q = p; *q && *q != '|' && *q != ':'; q++)
70 ;
71 if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) {
72 wwterm = t;
73 while (p < q)
74 *t++ = *p++;
75 *t = 0;
76 }
77 for (tp = tt_tab; tp->tt_name != 0; tp++)
78 if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0)
79 break;
80 if (tp->tt_name == 0) {
81 wwerrno = WWE_BADTERM;
82 return -1;
83 }
84 if ((*tp->tt_func)() < 0) {
85 wwerrno = WWE_CANTDO;
86 return -1;
87 }
88 if (wwgetttysize(0, &tt.tt_nrow, &tt.tt_ncol) < 0)
89 return -1;
90 tt.tt_scroll_top = 0;
91 tt.tt_scroll_bot = tt.tt_nrow - 1;
92 return 0;
93 }
94