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[] = "@(#)tttermcap.c 8.1 (Berkeley) 06/06/93"; 13 #endif /* not lint */ 14 15 #include "tt.h" 16 17 char *tgetstr(); 18 char *tgoto(); 19 char *malloc(); 20 21 tttputc(c) 22 { 23 ttputc(c); 24 } 25 26 ttxputc(c) 27 { 28 *tt_strp++ = c; 29 } 30 31 struct tt_str * 32 tttgetstr(str) 33 char *str; 34 { 35 register struct tt_str *s; 36 37 if ((str = tgetstr(str, &tt_strp)) == 0) 38 return 0; 39 if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) 40 return 0; 41 s->ts_str = str; 42 s->ts_n = tt_strp - s->ts_str - 1; 43 return s; 44 } 45 46 struct tt_str * 47 ttxgetstr(str) 48 char *str; 49 { 50 register struct tt_str *s; 51 char buf[100]; 52 char *bufp = buf; 53 54 if (tgetstr(str, &bufp) == 0) 55 return 0; 56 if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) 57 return 0; 58 s->ts_str = tt_strp; 59 tputs(buf, 1, ttxputc); 60 s->ts_n = tt_strp - s->ts_str; 61 *tt_strp++ = 0; 62 return s; 63 } 64 65 tttgoto(s, col, row) 66 struct tt_str *s; 67 { 68 register char *p = s->ts_str; 69 70 ttputs(tgoto(p, col, row)); 71 for (p += s->ts_n; *--p == 0;) 72 ttputc(0); 73 } 74 75 ttpgoto(s, col, row, n) 76 struct tt_str *s; 77 { 78 79 tputs(tgoto(s->ts_str, col, row), n, tttputc); 80 } 81 82 ttstrcmp(a, b) 83 register struct tt_str *a, *b; 84 { 85 int n, r; 86 87 if (r = bcmp(a->ts_str, b->ts_str, 88 (n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n)) 89 return r; 90 return n; 91 } 92