xref: /csrg-svn/usr.bin/window/tttermcap.c (revision 33514)
118740Sedward /*
2*33514Sbostic  * Copyright (c) 1983 Regents of the University of California.
3*33514Sbostic  * All rights reserved.
4*33514Sbostic  *
5*33514Sbostic  * Redistribution and use in source and binary forms are permitted
6*33514Sbostic  * provided that this notice is preserved and that due credit is given
7*33514Sbostic  * to the University of California at Berkeley. The name of the University
8*33514Sbostic  * may not be used to endorse or promote products derived from this
9*33514Sbostic  * software without specific prior written permission. This software
10*33514Sbostic  * is provided ``as is'' without express or implied warranty.
1118740Sedward  */
1218740Sedward 
13*33514Sbostic #ifndef lint
14*33514Sbostic static char sccsid[] = "@(#)tttermcap.c	3.8 (Berkeley) 02/21/88";
15*33514Sbostic #endif /* not lint */
16*33514Sbostic 
1714691Sedward #include "tt.h"
1814691Sedward 
1914691Sedward char *tgetstr();
2024975Sedward char *tgoto();
2124975Sedward char *malloc();
2214691Sedward 
2316123Sedward tttputc(c)
2414691Sedward {
2516123Sedward 	ttputc(c);
2614691Sedward }
2714691Sedward 
2816123Sedward ttxputc(c)
2914691Sedward {
3014691Sedward 	*tt_strp++ = c;
3114691Sedward }
3214691Sedward 
3324975Sedward struct tt_str *
3424975Sedward tttgetstr(str)
3524975Sedward 	char *str;
3624975Sedward {
3724975Sedward 	register struct tt_str *s;
3824975Sedward 
3924975Sedward 	if ((str = tgetstr(str, &tt_strp)) == 0)
4024975Sedward 		return 0;
4124975Sedward 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
4224975Sedward 		return 0;
4324975Sedward 	s->ts_str = str;
4424975Sedward 	s->ts_n = tt_strp - s->ts_str - 1;
4524975Sedward 	return s;
4624975Sedward }
4724975Sedward 
4824975Sedward struct tt_str *
4916123Sedward ttxgetstr(str)
5024975Sedward 	char *str;
5114691Sedward {
5224975Sedward 	register struct tt_str *s;
5314691Sedward 	char buf[100];
5414691Sedward 	char *bufp = buf;
5514691Sedward 
5624975Sedward 	if (tgetstr(str, &bufp) == 0)
5714691Sedward 		return 0;
5824975Sedward 	if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
5924975Sedward 		return 0;
6024975Sedward 	s->ts_str = tt_strp;
6116123Sedward 	tputs(buf, 1, ttxputc);
6224975Sedward 	s->ts_n = tt_strp - s->ts_str;
6324975Sedward 	*tt_strp++ = 0;
6424975Sedward 	return s;
6514691Sedward }
6624975Sedward 
6724975Sedward tttgoto(s, col, row)
6824975Sedward 	struct tt_str *s;
6924975Sedward {
7024975Sedward 	register char *p = s->ts_str;
7124975Sedward 
7224975Sedward 	ttputs(tgoto(p, col, row));
7324975Sedward 	for (p += s->ts_n; *--p == 0;)
7424975Sedward 		ttputc(0);
7524975Sedward }
7629722Sedward 
7729722Sedward ttstrcmp(a, b)
7829722Sedward 	register struct tt_str *a, *b;
7929722Sedward {
8029722Sedward 	int n, r;
8129722Sedward 
8229722Sedward 	if (r = bcmp(a->ts_str, b->ts_str,
8329722Sedward 			(n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))
8429722Sedward 		return r;
8529722Sedward 	return n;
8629722Sedward }
87