118740Sedward /*
2*62467Sbostic * Copyright (c) 1983, 1993
3*62467Sbostic * The Regents of the University of California. All rights reserved.
433514Sbostic *
542954Sbostic * This code is derived from software contributed to Berkeley by
642954Sbostic * Edward Wang at The University of California, Berkeley.
742954Sbostic *
842835Sbostic * %sccs.include.redist.c%
918740Sedward */
1018740Sedward
1133514Sbostic #ifndef lint
12*62467Sbostic static char sccsid[] = "@(#)tttermcap.c 8.1 (Berkeley) 06/06/93";
1333514Sbostic #endif /* not lint */
1433514Sbostic
1514691Sedward #include "tt.h"
1614691Sedward
1714691Sedward char *tgetstr();
1824975Sedward char *tgoto();
1924975Sedward char *malloc();
2014691Sedward
tttputc(c)2116123Sedward tttputc(c)
2214691Sedward {
2316123Sedward ttputc(c);
2414691Sedward }
2514691Sedward
ttxputc(c)2616123Sedward ttxputc(c)
2714691Sedward {
2814691Sedward *tt_strp++ = c;
2914691Sedward }
3014691Sedward
3124975Sedward struct tt_str *
tttgetstr(str)3224975Sedward tttgetstr(str)
3324975Sedward char *str;
3424975Sedward {
3524975Sedward register struct tt_str *s;
3624975Sedward
3724975Sedward if ((str = tgetstr(str, &tt_strp)) == 0)
3824975Sedward return 0;
3924975Sedward if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
4024975Sedward return 0;
4124975Sedward s->ts_str = str;
4224975Sedward s->ts_n = tt_strp - s->ts_str - 1;
4324975Sedward return s;
4424975Sedward }
4524975Sedward
4624975Sedward struct tt_str *
ttxgetstr(str)4716123Sedward ttxgetstr(str)
4824975Sedward char *str;
4914691Sedward {
5024975Sedward register struct tt_str *s;
5114691Sedward char buf[100];
5214691Sedward char *bufp = buf;
5314691Sedward
5424975Sedward if (tgetstr(str, &bufp) == 0)
5514691Sedward return 0;
5624975Sedward if ((s = (struct tt_str *) malloc(sizeof *s)) == 0)
5724975Sedward return 0;
5824975Sedward s->ts_str = tt_strp;
5916123Sedward tputs(buf, 1, ttxputc);
6024975Sedward s->ts_n = tt_strp - s->ts_str;
6124975Sedward *tt_strp++ = 0;
6224975Sedward return s;
6314691Sedward }
6424975Sedward
6524975Sedward tttgoto(s, col, row)
6624975Sedward struct tt_str *s;
6724975Sedward {
6824975Sedward register char *p = s->ts_str;
6924975Sedward
7024975Sedward ttputs(tgoto(p, col, row));
7124975Sedward for (p += s->ts_n; *--p == 0;)
7224975Sedward ttputc(0);
7324975Sedward }
7429722Sedward
7537998Sedward ttpgoto(s, col, row, n)
7637998Sedward struct tt_str *s;
7737998Sedward {
7837998Sedward
7937998Sedward tputs(tgoto(s->ts_str, col, row), n, tttputc);
8037998Sedward }
8137998Sedward
ttstrcmp(a,b)8229722Sedward ttstrcmp(a, b)
8329722Sedward register struct tt_str *a, *b;
8429722Sedward {
8529722Sedward int n, r;
8629722Sedward
8729722Sedward if (r = bcmp(a->ts_str, b->ts_str,
8829722Sedward (n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))
8929722Sedward return r;
9029722Sedward return n;
9129722Sedward }
92