1 /****************************************************************************
2 * Copyright (c) 1998-2002,2003 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 ****************************************************************************/
42 #include <curses.priv.h>
44 #include <term.h> /* padding_baud_rate, xon_xoff */
45 #include <termcap.h> /* ospeed */
48 MODULE_ID("$Id: lib_tputs.c,v 1.62 2003/08/23 21:39:20 tom Exp $")
50 NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */
51 NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */
53 NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */
55 static int (*my_outch) (int c) = _nc_outch;
60 T((T_CALLED("delay_output(%d)"), ms));
66 register int nullcount;
68 nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000);
69 for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
71 if (my_outch == _nc_outch)
81 (void) fflush(NC_OUTPUT);
93 * POSIX says write() is safe in a signal handler, but the
94 * buffered I/O is not.
96 write(fileno(NC_OUTPUT), &tmp, 1);
104 putp(const char *string)
106 return tputs(string, 1, _nc_outch);
110 tputs(const char *string, int affcnt, int (*outc) (int))
117 #endif /* BSD_TPUTS */
122 if (_nc_tracing & TRACE_TPUTS) {
123 if (outc == _nc_outch)
124 (void) strcpy(addrbuf, "_nc_outch");
126 (void) sprintf(addrbuf, "%p", outc);
127 if (_nc_tputs_trace) {
128 _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
129 _nc_visbuf(string), affcnt, addrbuf);
131 _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf);
133 _nc_tputs_trace = (char *) NULL;
137 if (!VALID_STRING(string))
141 always_delay = FALSE;
144 always_delay = (string == bell) || (string == flash_screen);
148 #if NCURSES_NO_PADDING
149 && (SP == 0 || !(SP->_no_padding))
151 && (_nc_baudrate(ospeed) >= padding_baud_rate);
156 * This ugly kluge deals with the fact that some ancient BSD programs
157 * (like nethack) actually do the likes of tputs("50") to get delays.
160 if (isdigit(UChar(*string))) {
161 while (isdigit(UChar(*string))) {
162 trailpad = trailpad * 10 + (*string - '0');
166 if (*string == '.') {
168 if (isdigit(UChar(*string))) {
169 trailpad += (*string - '0');
172 while (isdigit(UChar(*string)))
176 if (*string == '*') {
181 #endif /* BSD_TPUTS */
183 my_outch = outc; /* redirect delay_output() */
189 if (*string != '<') {
197 if ((!isdigit(UChar(*string)) && *string != '.')
198 || !strchr(string, '>')) {
205 while (isdigit(UChar(*string))) {
206 number = number * 10 + (*string - '0');
210 if (*string == '.') {
212 if (isdigit(UChar(*string))) {
213 number += (*string - '0');
216 while (isdigit(UChar(*string)))
221 while (*string == '*' || *string == '/') {
222 if (*string == '*') {
225 } else { /* if (*string == '/') */
235 delay_output(number / 10);
237 } /* endelse (*string == '<') */
238 } /* endelse (*string == '$') */
248 * Emit any BSD-style prefix padding that we've accumulated now.
251 && (always_delay || normal_delay))
252 delay_output(trailpad / 10);
253 #endif /* BSD_TPUTS */
255 my_outch = _nc_outch;