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