xref: /csrg-svn/lib/libterm/tputs.c (revision 61368)
122074Sdist /*
2*61368Sbostic  * Copyright (c) 1980, 1993
3*61368Sbostic  *	The Regents of the University of California.  All rights reserved.
436499Sbostic  *
542660Sbostic  * %sccs.include.redist.c%
622074Sdist  */
722074Sdist 
813302Ssam #ifndef lint
9*61368Sbostic static char sccsid[] = "@(#)tputs.c	8.1 (Berkeley) 06/04/93";
1036499Sbostic #endif /* not lint */
1113302Ssam 
1213302Ssam #include <sgtty.h>
1313302Ssam #include <ctype.h>
1413302Ssam 
1513302Ssam /*
1613302Ssam  * The following array gives the number of tens of milliseconds per
1713302Ssam  * character for each speed as returned by gtty.  Thus since 300
1813302Ssam  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
1913302Ssam  */
2013302Ssam static
2113302Ssam short	tmspc10[] = {
2213302Ssam 	0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
2313302Ssam };
2413302Ssam 
2513302Ssam short	ospeed;
2613302Ssam char	PC;
2713302Ssam 
2813302Ssam /*
2913302Ssam  * Put the character string cp out, with padding.
3013302Ssam  * The number of affected lines is affcnt, and the routine
3113302Ssam  * used to output one character is outc.
3213302Ssam  */
tputs(cp,affcnt,outc)3313302Ssam tputs(cp, affcnt, outc)
3413302Ssam 	register char *cp;
3513302Ssam 	int affcnt;
3613302Ssam 	int (*outc)();
3713302Ssam {
3813302Ssam 	register int i = 0;
3913302Ssam 	register int mspc10;
4013302Ssam 
4113302Ssam 	if (cp == 0)
4213302Ssam 		return;
4313302Ssam 
4413302Ssam 	/*
4513302Ssam 	 * Convert the number representing the delay.
4613302Ssam 	 */
4713302Ssam 	if (isdigit(*cp)) {
4813302Ssam 		do
4913302Ssam 			i = i * 10 + *cp++ - '0';
5013302Ssam 		while (isdigit(*cp));
5113302Ssam 	}
5213302Ssam 	i *= 10;
5313302Ssam 	if (*cp == '.') {
5413302Ssam 		cp++;
5513302Ssam 		if (isdigit(*cp))
5613302Ssam 			i += *cp - '0';
5713302Ssam 		/*
5813302Ssam 		 * Only one digit to the right of the decimal point.
5913302Ssam 		 */
6013302Ssam 		while (isdigit(*cp))
6113302Ssam 			cp++;
6213302Ssam 	}
6313302Ssam 
6413302Ssam 	/*
6513302Ssam 	 * If the delay is followed by a `*', then
6613302Ssam 	 * multiply by the affected lines count.
6713302Ssam 	 */
6813302Ssam 	if (*cp == '*')
6913302Ssam 		cp++, i *= affcnt;
7013302Ssam 
7113302Ssam 	/*
7213302Ssam 	 * The guts of the string.
7313302Ssam 	 */
7413302Ssam 	while (*cp)
7513302Ssam 		(*outc)(*cp++);
7613302Ssam 
7713302Ssam 	/*
7813302Ssam 	 * If no delay needed, or output speed is
7913302Ssam 	 * not comprehensible, then don't try to delay.
8013302Ssam 	 */
8113302Ssam 	if (i == 0)
8213302Ssam 		return;
8313302Ssam 	if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
8413302Ssam 		return;
8513302Ssam 
8613302Ssam 	/*
8713302Ssam 	 * Round up by a half a character frame,
8813302Ssam 	 * and then do the delay.
8913302Ssam 	 * Too bad there are no user program accessible programmed delays.
9013302Ssam 	 * Transmitting pad characters slows many
9113302Ssam 	 * terminals down and also loads the system.
9213302Ssam 	 */
9313302Ssam 	mspc10 = tmspc10[ospeed];
9413302Ssam 	i += mspc10 / 2;
9513302Ssam 	for (i /= mspc10; i > 0; i--)
9613302Ssam 		(*outc)(PC);
9713302Ssam }
98