xref: /csrg-svn/usr.bin/window/tttermcap.c (revision 42835)
118740Sedward /*
233514Sbostic  * Copyright (c) 1983 Regents of the University of California.
333514Sbostic  * All rights reserved.
433514Sbostic  *
5*42835Sbostic  * %sccs.include.redist.c%
618740Sedward  */
718740Sedward 
833514Sbostic #ifndef lint
9*42835Sbostic static char sccsid[] = "@(#)tttermcap.c	3.11 (Berkeley) 06/02/90";
1033514Sbostic #endif /* not lint */
1133514Sbostic 
1214691Sedward #include "tt.h"
1314691Sedward 
1414691Sedward char *tgetstr();
1524975Sedward char *tgoto();
1624975Sedward char *malloc();
1714691Sedward 
1816123Sedward tttputc(c)
1914691Sedward {
2016123Sedward 	ttputc(c);
2114691Sedward }
2214691Sedward 
2316123Sedward ttxputc(c)
2414691Sedward {
2514691Sedward 	*tt_strp++ = c;
2614691Sedward }
2714691Sedward 
2824975Sedward struct tt_str *
2924975Sedward tttgetstr(str)
3024975Sedward 	char *str;
3124975Sedward {
3224975Sedward 	register struct tt_str *s;
3324975Sedward 
3424975Sedward 	if ((str = tgetstr(str, &tt_strp)) == 0)
3524975Sedward 		return 0;
3624975Sedward 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
3724975Sedward 		return 0;
3824975Sedward 	s->ts_str = str;
3924975Sedward 	s->ts_n = tt_strp - s->ts_str - 1;
4024975Sedward 	return s;
4124975Sedward }
4224975Sedward 
4324975Sedward struct tt_str *
4416123Sedward ttxgetstr(str)
4524975Sedward 	char *str;
4614691Sedward {
4724975Sedward 	register struct tt_str *s;
4814691Sedward 	char buf[100];
4914691Sedward 	char *bufp = buf;
5014691Sedward 
5124975Sedward 	if (tgetstr(str, &bufp) == 0)
5214691Sedward 		return 0;
5324975Sedward 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
5424975Sedward 		return 0;
5524975Sedward 	s->ts_str = tt_strp;
5616123Sedward 	tputs(buf, 1, ttxputc);
5724975Sedward 	s->ts_n = tt_strp - s->ts_str;
5824975Sedward 	*tt_strp++ = 0;
5924975Sedward 	return s;
6014691Sedward }
6124975Sedward 
6224975Sedward tttgoto(s, col, row)
6324975Sedward 	struct tt_str *s;
6424975Sedward {
6524975Sedward 	register char *p = s->ts_str;
6624975Sedward 
6724975Sedward 	ttputs(tgoto(p, col, row));
6824975Sedward 	for (p += s->ts_n; *--p == 0;)
6924975Sedward 		ttputc(0);
7024975Sedward }
7129722Sedward 
7237998Sedward ttpgoto(s, col, row, n)
7337998Sedward 	struct tt_str *s;
7437998Sedward {
7537998Sedward 
7637998Sedward 	tputs(tgoto(s->ts_str, col, row), n, tttputc);
7737998Sedward }
7837998Sedward 
7929722Sedward ttstrcmp(a, b)
8029722Sedward 	register struct tt_str *a, *b;
8129722Sedward {
8229722Sedward 	int n, r;
8329722Sedward 
8429722Sedward 	if (r = bcmp(a->ts_str, b->ts_str,
8529722Sedward 			(n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))
8629722Sedward 		return r;
8729722Sedward 	return n;
8829722Sedward }
89