Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 7u83 1
/*
2
 * This code contains changes by
3
 *      Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
4
 *
5
 * Conditions 1, 2, and 4 and the no-warranty notice below apply
6
 * to these changes.
7
 *
8
 *
9
 * Copyright (c) 1980, 1993
10
 *	The Regents of the University of California.  All rights reserved.
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. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgement:
22
 *	This product includes software developed by the University of
23
 *	California, Berkeley and its contributors.
24
 * 4. Neither the name of the University nor the names of its contributors
25
 *    may be used to endorse or promote products derived from this software
26
 *    without specific prior written permission.
27
 *
28
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
 * SUCH DAMAGE.
39
 */
40
 
41
#ifndef	lint
42
#ifdef	DOSCCS
43
static char *sccsid = "@(#)tputs.c	1.4 (gritter) 11/23/04";
44
#endif
45
#endif
46
 
47
/* from tputs.c	5.1 (Berkeley) 6/5/85 */
48
 
49
#include <ctype.h>
50
 
51
#include "libterm.h"
52
 
53
/*
54
 * The following array gives the number of tens of milliseconds per
55
 * character for each speed as returned by gtty.  Thus since 300
56
 * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
57
 */
58
static
59
short	tmspc10[] = {
60
	0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
61
};
62
 
63
short	ospeed;
64
char	PC;
65
 
66
/*
67
 * Put the character string cp out, with padding.
68
 * The number of affected lines is affcnt, and the routine
69
 * used to output one character is outc.
70
 */
71
int
72
tputs(const char *cp, int affcnt, int (*outc)(int))
73
{
74
	register int i = 0;
75
	register int mspc10;
76
 
77
	if (cp == 0)
78
		return 1;
79
 
80
	/*
81
	 * Convert the number representing the delay.
82
	 */
83
	if (isdigit(*cp & 0377)) {
84
		do
85
			i = i * 10 + *cp++ - '0';
86
		while (isdigit(*cp & 0377));
87
	}
88
	i *= 10;
89
	if (*cp == '.') {
90
		cp++;
91
		if (isdigit(*cp & 0377))
92
			i += *cp - '0';
93
		/*
94
		 * Only one digit to the right of the decimal point.
95
		 */
96
		while (isdigit(*cp & 0377))
97
			cp++;
98
	}
99
 
100
	/*
101
	 * If the delay is followed by a `*', then
102
	 * multiply by the affected lines count.
103
	 */
104
	if (*cp == '*')
105
		cp++, i *= affcnt;
106
 
107
	/*
108
	 * The guts of the string.
109
	 */
110
	while (*cp)
111
		(*outc)(*cp++);
112
 
113
	/*
114
	 * If no delay needed, or output speed is
115
	 * not comprehensible, then don't try to delay.
116
	 */
117
	if (i == 0)
118
		return 1;
119
	if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
120
		return 1;
121
 
122
	/*
123
	 * Round up by a half a character frame,
124
	 * and then do the delay.
125
	 * Too bad there are no user program accessible programmed delays.
126
	 * Transmitting pad characters slows many
127
	 * terminals down and also loads the system.
128
	 */
129
	mspc10 = tmspc10[ospeed];
130
	i += mspc10 / 2;
131
	for (i /= mspc10; i > 0; i--)
132
		(*outc)(PC);
133
	return 1;
134
}