1 /** $MirOS: src/usr.bin/window/tttermcap.c,v 1.2 2005/03/13 18:34:06 tg Exp $ */
2 /* $OpenBSD: tttermcap.c,v 1.6 2003/08/01 22:01:37 david Exp $ */
3 /* $NetBSD: tttermcap.c,v 1.3 1995/09/28 10:34:52 tls Exp $ */
4
5 /*
6 * Copyright (c) 1983, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Edward Wang at The University of California, Berkeley.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37 #include "tt.h"
38 #include <curses.h>
39 #include <term.h>
40 #include <string.h>
41
42 __SCCSID("@(#)tttermcap.c 8.1 (Berkeley) 6/6/93");
43 __RCSID("$MirOS: src/usr.bin/window/tttermcap.c,v 1.2 2005/03/13 18:34:06 tg Exp $");
44
tttputc(c)45 tttputc(c)
46 {
47 ttputc(c);
48 }
49
ttxputc(c)50 ttxputc(c)
51 {
52 *tt_strp++ = c;
53 }
54
55 struct tt_str *
tttgetstr(str)56 tttgetstr(str)
57 char *str;
58 {
59 struct tt_str *s;
60
61 if ((str = tgetstr(str, &tt_strp)) == 0)
62 return 0;
63 if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
64 return 0;
65 s->ts_str = str;
66 s->ts_n = tt_strp - s->ts_str - 1;
67 return s;
68 }
69
70 struct tt_str *
ttxgetstr(str)71 ttxgetstr(str)
72 char *str;
73 {
74 struct tt_str *s;
75 char buf[100];
76 char *bufp = buf;
77
78 if (tgetstr(str, &bufp) == 0)
79 return 0;
80 if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
81 return 0;
82 s->ts_str = tt_strp;
83 tputs(buf, 1, ttxputc);
84 s->ts_n = tt_strp - s->ts_str;
85 *tt_strp++ = 0;
86 return s;
87 }
88
89 tttgoto(s, col, row)
90 struct tt_str *s;
91 {
92 char *p = s->ts_str;
93
94 ttputs(tgoto(p, col, row));
95 for (p += s->ts_n; *--p == 0;)
96 ttputc(0);
97 }
98
99 ttpgoto(s, col, row, n)
100 struct tt_str *s;
101 {
102
103 tputs(tgoto(s->ts_str, col, row), n, tttputc);
104 }
105
106 ttstrcmp(a, b)
107 struct tt_str *a, *b;
108 {
109 int n, r;
110
111 if (r = memcmp(a->ts_str, b->ts_str,
112 (n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))
113 return r;
114 return n;
115 }
116