2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
31 #include <curses.priv.h>
33 #include <term.h> /* padding_baud_rate, xon_xoff */
36 MODULE_ID("$Id: lib_tputs.c,v 1.18 1997/02/02 01:52:39 tom Exp $")
38 int delay_output(int ms)
40 T((T_CALLED("delay_output(%d)"), ms));
42 if (SP == 0 || SP->_baudrate <= 0)
47 #endif /* no_pad_char */
49 register int nullcount;
57 for (nullcount = ms * 1000 / SP->_baudrate; nullcount > 0; nullcount--)
59 (void) fflush(SP->_ofp);
78 int putp(const char *string)
80 return tputs(string, 1, _nc_outch);
83 int tputs(const char *string, int affcnt, int (*outc)(int))
88 #endif /* BSD_TPUTS */
93 if (_nc_tracing & TRACE_TPUTS)
95 if (outc == _nc_outch)
96 (void) strcpy(addrbuf, "_nc_outch");
98 (void) sprintf(addrbuf, "%p", outc);
100 TR(TRACE_MAXIMUM, ("tputs(%s = %s, %d, %s) called", _nc_tputs_trace, _nc_visbuf(string), affcnt, addrbuf));
102 TR(TRACE_MAXIMUM, ("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf));
103 _nc_tputs_trace = (char *)NULL;
107 if (string == ABSENT_STRING || string == CANCELLED_STRING)
112 * This ugly kluge deals with the fact that some ancient BSD programs
113 * (like nethack) actually do the likes of tputs("50") to get delays.
118 while (isdigit(*string)) {
119 trailpad = trailpad * 10 + *string - '0';
123 if (*string == '.') {
125 if (isdigit(*string)) {
126 trailpad += (float) (*string - '0') / 10.;
129 while (isdigit(*string))
133 if (*string == '*') {
137 #endif /* BSD_TPUTS */
144 if (*string != '<') {
154 if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) {
159 while (isdigit(*string)) {
160 number = number * 10 + *string - '0';
164 if (*string == '.') {
166 if (isdigit(*string)) {
167 number += (float) (*string - '0') / 10.;
170 while (isdigit(*string))
174 mandatory = !xon_xoff;
175 while (*string == '*' || *string == '/')
177 if (*string == '*') {
181 else /* if (*string == '/') */ {
187 #ifdef padding_baud_rate
188 if (mandatory && number > 0 && padding_baud_rate && (!SP || SP->_baudrate >= padding_baud_rate))
189 delay_output(number);
190 #endif /* padding_baud_rate */
193 } /* endelse (*string == '<') */
194 } /* endelse (*string == '$') */
204 * Emit any BSD-style prefix padding that we've accumulated now.
206 #ifdef padding_baud_rate
207 if (trailpad > 0 && !xon_xoff && padding_baud_rate && (!SP || SP->_baudrate >= padding_baud_rate))
208 delay_output(number);
209 #endif /* padding_baud_rate */
210 #endif /* BSD_TPUTS */