1 /* $NetBSD: tputs.c,v 1.23 2005/05/15 21:11:13 christos Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)tputs.c 8.1 (Berkeley) 6/4/93";
37 __RCSID("$NetBSD: tputs.c,v 1.23 2005/05/15 21:11:13 christos Exp $");
46 #include "termcap_private.h"
49 /* internal functions */
50 int _tputs_convert(const char **, int);
53 * The following array gives the number of tens of milliseconds per
54 * character for each speed as returned by gtty. Thus since 300
55 * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
57 const short __tmspc10
[TMSPC10SIZE
] = {
58 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
65 _tputs_convert(const char **ptr
, int affcnt
)
69 _DIAGASSERT(ptr
!= NULL
);
70 _DIAGASSERT(*ptr
!= NULL
);
73 * Convert the number representing the delay.
75 if (isdigit(*(const unsigned char *)(*ptr
))) {
77 i
= i
* 10 + *(*ptr
)++ - '0';
78 while (isdigit(*(const unsigned char *)(*ptr
)));
83 if (isdigit(*(const unsigned char *)(*ptr
)))
86 * Only one digit to the right of the decimal point.
88 while (isdigit(*(const unsigned char *)(*ptr
)))
93 * If the delay is followed by a `*', then
94 * multiply by the affected lines count.
97 (*ptr
)++, i
*= affcnt
;
103 * Put the character string cp out, with padding.
104 * The number of affected lines is affcnt, and the routine
105 * used to output one character is outc.
108 tputs(const char *cp
, int affcnt
, int (*outc
)(int))
113 _DIAGASSERT(outc
!= 0);
118 /* scan and convert delay digits (if any) */
119 i
= _tputs_convert(&cp
, affcnt
);
122 * The guts of the string.
125 (void)(*outc
)(*cp
++);
128 * If no delay needed, or output speed is
129 * not comprehensible, then don't try to delay.
133 if (ospeed
<= 0 || ospeed
>= TMSPC10SIZE
)
137 * Round up by a half a character frame,
138 * and then do the delay.
139 * Too bad there are no user program accessible programmed delays.
140 * Transmitting pad characters slows many
141 * terminals down and also loads the system.
143 mspc10
= __tmspc10
[ospeed
];
145 for (i
/= mspc10
; i
> 0; i
--)
152 t_puts(struct tinfo
*info
, const char *cp
, int affcnt
,
153 void (*outc
)(char, void *), void *args
)
161 /* XXX: info may be NULL ? */
162 /* cp is handled below */
163 _DIAGASSERT(outc
!= NULL
);
164 _DIAGASSERT(args
!= NULL
);
168 * if we have info then get the pad char from the
169 * termcap entry if it exists, otherwise use the
174 pc
= t_getstr(info
, "pc", &pptr
, &limit
);
184 /* scan and convert delay digits (if any) */
185 i
= _tputs_convert(&cp
, affcnt
);
188 * The guts of the string.
191 (*outc
)(*cp
++, args
);
194 * If no delay needed, or output speed is
195 * not comprehensible, then don't try to delay.
199 if (ospeed
<= 0 || ospeed
>= TMSPC10SIZE
)
203 * Round up by a half a character frame,
204 * and then do the delay.
205 * Too bad there are no user program accessible programmed delays.
206 * Transmitting pad characters slows many
207 * terminals down and also loads the system.
209 mspc10
= __tmspc10
[ospeed
];
211 for (i
/= mspc10
; i
> 0; i
--)
212 (*outc
)(pad
[0], args
);