1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
43 #include <curses.priv.h>
45 #include <term.h> /* padding_baud_rate, xon_xoff */
48 MODULE_ID("$Id: lib_tputs.c,v 1.30 1998/02/11 12:14:00 tom Exp $")
50 #define OUTPUT ((SP != 0) ? SP->_ofp : stdout)
52 int _nc_nulls_sent; /* used by 'tack' program */
54 static int (*my_outch)(int c) = _nc_outch;
56 int delay_output(int ms)
58 T((T_CALLED("delay_output(%d)"), ms));
60 if (cur_term == 0 || cur_term->_baudrate <= 0) {
61 (void) fflush(OUTPUT);
62 _nc_timed_wait(0, ms, (int *)0);
67 #endif /* no_pad_char */
69 register int nullcount;
77 nullcount = ms * cur_term->_baudrate / 10000;
78 for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
80 if (my_outch == _nc_outch)
81 (void) fflush(OUTPUT);
97 int putp(const char *string)
99 return tputs(string, 1, _nc_outch);
102 int tputs(const char *string, int affcnt, int (*outc)(int))
109 #endif /* BSD_TPUTS */
114 if (_nc_tracing & TRACE_TPUTS)
116 if (outc == _nc_outch)
117 (void) strcpy(addrbuf, "_nc_outch");
119 (void) sprintf(addrbuf, "%p", outc);
121 TR(TRACE_MAXIMUM, ("tputs(%s = %s, %d, %s) called", _nc_tputs_trace, _nc_visbuf(string), affcnt, addrbuf));
123 TR(TRACE_MAXIMUM, ("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf));
124 _nc_tputs_trace = (char *)NULL;
128 if (string == ABSENT_STRING || string == CANCELLED_STRING)
132 always_delay = FALSE;
135 always_delay = (string == bell) || (string == flash_screen);
138 #ifdef padding_baud_rate
140 && (!cur_term || cur_term->_baudrate >= padding_baud_rate)
147 * This ugly kluge deals with the fact that some ancient BSD programs
148 * (like nethack) actually do the likes of tputs("50") to get delays.
151 while (isdigit(*string)) {
152 trailpad = trailpad * 10 + (*string - '0');
156 if (*string == '.') {
158 if (isdigit(*string)) {
159 trailpad += (*string - '0');
162 while (isdigit(*string))
166 if (*string == '*') {
170 #endif /* BSD_TPUTS */
172 my_outch = outc; /* redirect delay_output() */
178 if (*string != '<') {
186 if ((!isdigit(*string) && *string != '.') || !strchr(string, '>')) {
193 while (isdigit(*string)) {
194 number = number * 10 + (*string - '0');
198 if (*string == '.') {
200 if (isdigit(*string)) {
201 number += (*string - '0');
204 while (isdigit(*string))
209 while (*string == '*' || *string == '/')
211 if (*string == '*') {
215 else /* if (*string == '/') */ {
225 delay_output(number/10);
227 } /* endelse (*string == '<') */
228 } /* endelse (*string == '$') */
238 * Emit any BSD-style prefix padding that we've accumulated now.
241 && (always_delay || normal_delay))
242 delay_output(trailpad/10);
243 #endif /* BSD_TPUTS */
245 my_outch = _nc_outch;