1 /* $NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry 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.22 2005/02/04 15:52:08 perry Exp $");
47 #include "termcap_private.h"
50 /* internal functions */
51 int _tputws_convert(const wchar_t **, int);
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.
62 _tputws_convert(const wchar_t **ptr
, int affcnt
)
66 _DIAGASSERT(ptr
!= NULL
);
67 _DIAGASSERT(*ptr
!= NULL
);
70 * Convert the number representing the delay.
72 if (iswdigit(**ptr
)) {
74 i
= i
* 10 + *(*ptr
)++ - '0';
75 while (iswdigit(**ptr
));
83 * Only one digit to the right of the decimal point.
85 while (iswdigit(**ptr
))
90 * If the delay is followed by a `*', then
91 * multiply by the affected lines count.
94 (*ptr
)++, i
*= affcnt
;
100 t_putws(struct tinfo
*info
, const wchar_t *cp
, int affcnt
,
101 void (*outc
)(wchar_t, void *), void *args
)
109 /* XXX: info may be NULL ? */
110 /* cp is handled below */
111 _DIAGASSERT(outc
!= NULL
);
112 _DIAGASSERT(args
!= NULL
);
116 * if we have info then get the pad char from the
117 * termcap entry if it exists, otherwise use the
122 pc
= t_getstr(info
, "pc", &pptr
, &limit
);
132 /* scan and convert delay digits (if any) */
133 i
= _tputws_convert(&cp
, affcnt
);
136 * The guts of the string.
139 (*outc
)(*cp
++, args
);
142 * If no delay needed, or output speed is
143 * not comprehensible, then don't try to delay.
147 if (ospeed
<= 0 || ospeed
>= TMSPC10SIZE
)
151 * Round up by a half a character frame,
152 * and then do the delay.
153 * Too bad there are no user program accessible programmed delays.
154 * Transmitting pad characters slows many
155 * terminals down and also loads the system.
157 mspc10
= __tmspc10
[ospeed
];
159 for (i
/= mspc10
; i
> 0; i
--)
160 (*outc
)(pad
[0], args
);