1 /* $NetBSD: tputs.c,v 1.3 2013/06/07 13:16:18 roy Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
6 * This code is derived from software contributed to The NetBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: tputs.c,v 1.3 2013/06/07 13:16:18 roy Exp $");
37 #include <term_private.h>
41 * The following array gives the number of tens of milliseconds per
42 * character for each speed as returned by gtty. Thus since 300
43 * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
45 static const short tmspc10
[] = {
46 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
53 _ti_calcdelay(const char **str
, int affcnt
, int *mand
)
58 /* Convert the delay */
59 while (isdigit(*(const unsigned char *)*str
))
60 i
= i
* 10 + *(*str
)++ - '0';
64 if (isdigit(*(const unsigned char *)*str
))
66 while (isdigit(*(const unsigned char *)*str
))
72 } else if (*(*str
) == '/') {
81 _ti_outputdelay(int delay
, short os
, char pc
,
82 int (*outc
)(int, void *), void *args
)
86 if (delay
< 1 || os
< 1 || (size_t)os
>= __arraycount(tmspc10
))
91 for (delay
/= mspc10
; delay
> 0; delay
--)
96 _ti_puts(int dodelay
, int os
, int pc
,
97 const char *str
, int affcnt
, int (*outc
)(int, void *), void *args
)
99 int taildelay
, delay
, mand
;
104 taildelay
= _ti_calcdelay(&str
, affcnt
, NULL
);
106 /* Output the string with embedded delays */
107 for (; *str
!= '\0'; str
++) {
110 !(isdigit((const unsigned char)str
[2]) || str
[2] == '.') ||
111 strchr(str
+ 3, '>') == NULL
)
117 delay
= _ti_calcdelay(&str
, affcnt
, &mand
);
118 if (dodelay
!= 0 || mand
!= 0)
119 _ti_outputdelay(delay
, os
, pc
, outc
, args
);
123 /* Delay if needed */
125 _ti_outputdelay(taildelay
, os
, pc
, outc
, args
);
131 ti_puts(const TERMINAL
*term
, const char *str
, int affcnt
,
132 int (*outc
)(int, void *), void *args
)
137 _DIAGASSERT(term
!= NULL
);
138 _DIAGASSERT(str
!= NULL
);
139 _DIAGASSERT(outc
!= NULL
);
141 dodelay
= (str
== t_bell(term
) ||
142 str
== t_flash_screen(term
) ||
143 (t_xon_xoff(term
) == 0 && t_padding_baud_rate(term
) != 0));
145 if (t_pad_char(term
) == NULL
)
148 pc
= *t_pad_char(term
);
149 return _ti_puts(dodelay
, term
->_ospeed
, pc
,
150 str
, affcnt
, outc
, args
);
154 ti_putp(const TERMINAL
*term
, const char *str
)
157 _DIAGASSERT(term
!= NULL
);
158 _DIAGASSERT(str
!= NULL
);
159 return ti_puts(term
, str
, 1, (int (*)(int, void *))putchar
, NULL
);
163 tputs(const char *str
, int affcnt
, int (*outc
)(int))
166 _DIAGASSERT(str
!= NULL
);
167 _DIAGASSERT(outc
!= NULL
);
168 return _ti_puts(1, ospeed
, PC
, str
, affcnt
,
169 (int (*)(int, void *))outc
, NULL
);
173 putp(const char *str
)
176 _DIAGASSERT(str
!= NULL
);
177 return tputs(str
, 1, putchar
);