1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)ttinit.c 3.21 (Berkeley) 04/20/89"; 20 #endif /* not lint */ 21 22 #include "ww.h" 23 #include "tt.h" 24 25 int tt_h19(); 26 int tt_h29(); 27 int tt_f100(); 28 int tt_tvi925(); 29 int tt_wyse75(); 30 int tt_wyse60(); 31 int tt_zapple(); 32 int tt_zentec(); 33 int tt_generic(); 34 struct tt_tab tt_tab[] = { 35 { "h19", 3, tt_h19 }, 36 { "h29", 3, tt_h29 }, 37 { "f100", 4, tt_f100 }, 38 { "tvi925", 6, tt_tvi925 }, 39 { "wyse75", 6, tt_wyse75 }, 40 { "wyse60", 6, tt_wyse60 }, 41 { "w60", 3, tt_wyse60 }, 42 { "zapple", 6, tt_zapple }, 43 { "zentec", 6, tt_zentec }, 44 { "generic", 0, tt_generic }, 45 0 46 }; 47 48 ttinit() 49 { 50 register struct tt_tab *tp; 51 register char *p, *q; 52 register char *t; 53 struct winsize winsize; 54 55 tt_strp = tt_strings; 56 57 /* 58 * Set output buffer size to about 1 second of output time. 59 */ 60 tt_obp = tt_ob; 61 tt_obe = tt_ob + MIN(wwbaud/10, sizeof tt_ob); 62 63 /* 64 * Use the standard name of the terminal (i.e. the second 65 * name in termcap). 66 */ 67 for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++) 68 ; 69 if (*p == '|') 70 p++; 71 for (q = p; *q && *q != '|' && *q != ':'; q++) 72 ; 73 if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) { 74 wwterm = t; 75 while (p < q) 76 *t++ = *p++; 77 *t = 0; 78 } 79 for (tp = tt_tab; tp->tt_name != 0; tp++) 80 if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0) 81 break; 82 if (tp->tt_name == 0) { 83 wwerrno = WWE_BADTERM; 84 return -1; 85 } 86 if ((*tp->tt_func)() < 0) { 87 wwerrno = WWE_CANTDO; 88 return -1; 89 } 90 tt.tt_scroll_top = 0; 91 tt.tt_scroll_bot = tt.tt_nrow - 1; 92 if (ioctl(0, TIOCGWINSZ, (char *)&winsize) >= 0 && 93 winsize.ws_row != 0 && winsize.ws_col != 0) { 94 tt.tt_nrow = winsize.ws_row; 95 tt.tt_ncol = winsize.ws_col; 96 } 97 return 0; 98 } 99