1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * 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 3.26 (Berkeley) 06/06/90"; 13 #endif /* not lint */ 14 15 #include "ww.h" 16 #include "tt.h" 17 #ifdef POSIX_TTY 18 #include <sys/ioctl.h> 19 #endif 20 21 int tt_h19(); 22 int tt_h29(); 23 int tt_f100(); 24 int tt_tvi925(); 25 int tt_wyse75(); 26 int tt_wyse60(); 27 int tt_zapple(); 28 int tt_zentec(); 29 int tt_generic(); 30 struct tt_tab tt_tab[] = { 31 { "h19", 3, tt_h19 }, 32 { "h29", 3, tt_h29 }, 33 { "f100", 4, tt_f100 }, 34 { "tvi925", 6, tt_tvi925 }, 35 { "wyse75", 6, tt_wyse75 }, 36 { "wyse60", 6, tt_wyse60 }, 37 { "w60", 3, tt_wyse60 }, 38 { "zapple", 6, tt_zapple }, 39 { "zentec", 6, tt_zentec }, 40 { "generic", 0, tt_generic }, 41 0 42 }; 43 44 ttinit() 45 { 46 int i; 47 register struct tt_tab *tp; 48 register char *p, *q; 49 register char *t; 50 struct winsize winsize; 51 int ttflush(); 52 53 tt_strp = tt_strings; 54 55 /* 56 * Set output buffer size to about 1 second of output time. 57 */ 58 i = MIN(wwbaud/10, 512); 59 if ((tt_ob = malloc((unsigned) i)) == 0) { 60 wwerrno = WWE_NOMEM; 61 return -1; 62 } 63 tt_obp = tt_ob; 64 tt_obe = tt_ob + i; 65 66 /* 67 * Use the standard name of the terminal (i.e. the second 68 * name in termcap). 69 */ 70 for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++) 71 ; 72 if (*p == '|') 73 p++; 74 for (q = p; *q && *q != '|' && *q != ':'; q++) 75 ; 76 if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) { 77 wwterm = t; 78 while (p < q) 79 *t++ = *p++; 80 *t = 0; 81 } 82 for (tp = tt_tab; tp->tt_name != 0; tp++) 83 if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0) 84 break; 85 if (tp->tt_name == 0) { 86 wwerrno = WWE_BADTERM; 87 return -1; 88 } 89 if ((*tp->tt_func)() < 0) { 90 wwerrno = WWE_CANTDO; 91 return -1; 92 } 93 if (ioctl(0, TIOCGWINSZ, (char *)&winsize) >= 0) { 94 if (winsize.ws_row != 0) 95 tt.tt_nrow = winsize.ws_row; 96 if (winsize.ws_col != 0) 97 tt.tt_ncol = winsize.ws_col; 98 } 99 tt.tt_scroll_top = 0; 100 tt.tt_scroll_bot = tt.tt_nrow - 1; 101 tt.tt_flush = ttflush; 102 return 0; 103 } 104