xref: /original-bsd/usr.bin/window/tttermcap.c (revision 57124d5e)
1 #ifndef lint
2 static char sccsid[] = "@(#)tttermcap.c	3.7 08/05/86";
3 #endif
4 
5 /*
6  * Copyright (c) 1983 Regents of the University of California,
7  * All rights reserved.  Redistribution permitted subject to
8  * the terms of the Berkeley Software License Agreement.
9  */
10 
11 #include "tt.h"
12 
13 char *tgetstr();
14 char *tgoto();
15 char *malloc();
16 
17 tttputc(c)
18 {
19 	ttputc(c);
20 }
21 
22 ttxputc(c)
23 {
24 	*tt_strp++ = c;
25 }
26 
27 struct tt_str *
28 tttgetstr(str)
29 	char *str;
30 {
31 	register struct tt_str *s;
32 
33 	if ((str = tgetstr(str, &tt_strp)) == 0)
34 		return 0;
35 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
36 		return 0;
37 	s->ts_str = str;
38 	s->ts_n = tt_strp - s->ts_str - 1;
39 	return s;
40 }
41 
42 struct tt_str *
43 ttxgetstr(str)
44 	char *str;
45 {
46 	register struct tt_str *s;
47 	char buf[100];
48 	char *bufp = buf;
49 
50 	if (tgetstr(str, &bufp) == 0)
51 		return 0;
52 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
53 		return 0;
54 	s->ts_str = tt_strp;
55 	tputs(buf, 1, ttxputc);
56 	s->ts_n = tt_strp - s->ts_str;
57 	*tt_strp++ = 0;
58 	return s;
59 }
60 
61 tttgoto(s, col, row)
62 	struct tt_str *s;
63 {
64 	register char *p = s->ts_str;
65 
66 	ttputs(tgoto(p, col, row));
67 	for (p += s->ts_n; *--p == 0;)
68 		ttputc(0);
69 }
70 
71 ttstrcmp(a, b)
72 	register struct tt_str *a, *b;
73 {
74 	int n, r;
75 
76 	if (r = bcmp(a->ts_str, b->ts_str,
77 			(n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))
78 		return r;
79 	return n;
80 }
81