1 /* $OpenBSD: ttinit.c,v 1.10 2003/06/03 02:56:23 millert Exp $ */
2 /* $NetBSD: ttinit.c,v 1.3 1995/09/28 10:34:50 tls Exp $ */
3
4 /*
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)ttinit.c 8.1 (Berkeley) 6/6/93";
39 #else
40 static char rcsid[] = "$OpenBSD: ttinit.c,v 1.10 2003/06/03 02:56:23 millert Exp $";
41 #endif
42 #endif /* not lint */
43
44 #include <stdlib.h>
45 #include <string.h>
46 #include "ww.h"
47 #include "tt.h"
48
49 int tt_h19();
50 int tt_h29();
51 int tt_f100();
52 int tt_tvi925();
53 int tt_wyse75();
54 int tt_wyse60();
55 int tt_zapple();
56 int tt_zentec();
57 int tt_generic();
58 struct tt_tab tt_tab[] = {
59 { "h19", 3, tt_h19 },
60 { "h29", 3, tt_h29 },
61 { "f100", 4, tt_f100 },
62 { "tvi925", 6, tt_tvi925 },
63 { "wyse75", 6, tt_wyse75 },
64 { "wyse60", 6, tt_wyse60 },
65 { "w60", 3, tt_wyse60 },
66 { "zapple", 6, tt_zapple },
67 { "zentec", 6, tt_zentec },
68 { "generic", 0, tt_generic },
69 0
70 };
71
ttinit()72 ttinit()
73 {
74 int i;
75 struct tt_tab *tp;
76 char *p, *q;
77 char *t;
78
79 tt_strp = tt_strings;
80
81 /*
82 * Set output buffer size to about 1 second of output time.
83 */
84 i = MIN(wwbaud/10, 512);
85 if ((tt_ob = malloc(i)) == 0) {
86 wwerrno = WWE_NOMEM;
87 return -1;
88 }
89 tt_obp = tt_ob;
90 tt_obe = tt_ob + i;
91
92 /*
93 * Use the standard name of the terminal (i.e. the first
94 * non-two letter name in termcap).
95 */
96 #ifdef NCURSES_VERSION
97 wwterm = strdup(_nc_first_name(cur_term->type.term_names));
98 #elif !defined(TERMINFO)
99 if ((p = strchr(wwtermcap, '|')) && (int)(p - wwtermcap) == 2) {
100 /* Skip the two-character short name. */
101 for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++)
102 ;
103 if (*p == '|')
104 p++;
105 } else
106 p = wwtermcap;
107 for (q = p; *q && *q != '|' && *q != ':'; q++)
108 ;
109 if (q != p && (t = malloc(q - p + 1)) != 0) {
110 wwterm = t;
111 while (p < q)
112 *t++ = *p++;
113 *t = 0;
114 }
115 #endif
116 for (tp = tt_tab; tp->tt_name != 0; tp++)
117 if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0)
118 break;
119 if (tp->tt_name == 0) {
120 wwerrno = WWE_BADTERM;
121 return -1;
122 }
123 if ((*tp->tt_func)() < 0) {
124 wwerrno = WWE_CANTDO;
125 return -1;
126 }
127 if (wwgetttysize(0, &tt.tt_nrow, &tt.tt_ncol) < 0)
128 return -1;
129 tt.tt_scroll_top = 0;
130 tt.tt_scroll_bot = tt.tt_nrow - 1;
131 return 0;
132 }
133