1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
43 #include <curses.priv.h>
45 #include <term.h> /* padding_baud_rate, xon_xoff */
46 #include <termcap.h> /* ospeed */
49 MODULE_ID("$Id: lib_tputs.c,v 1.66 2008/06/28 13:12:15 tom Exp $")
51 NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */
52 NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */
54 NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */
56 #if NCURSES_NO_PADDING
58 _nc_set_no_padding(SCREEN *sp)
60 bool no_padding = (getenv("NCURSES_NO_PADDING") != 0);
63 sp->_no_padding = no_padding;
65 _nc_prescreen._no_padding = no_padding;
67 TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used",
68 GetNoPadding(sp) ? " not" : ""));
72 static int (*my_outch) (int c) = _nc_outch;
77 T((T_CALLED("delay_output(%d)"), ms));
83 register int nullcount;
85 nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000);
86 for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
88 if (my_outch == _nc_outch)
98 (void) fflush(NC_OUTPUT);
110 * POSIX says write() is safe in a signal handler, but the
111 * buffered I/O is not.
113 write(fileno(NC_OUTPUT), &tmp, 1);
121 putp(const char *string)
123 return tputs(string, 1, _nc_outch);
127 tputs(const char *string, int affcnt, int (*outc) (int))
134 #endif /* BSD_TPUTS */
139 if (USE_TRACEF(TRACE_TPUTS)) {
140 if (outc == _nc_outch)
141 (void) strcpy(addrbuf, "_nc_outch");
143 (void) sprintf(addrbuf, "%p", outc);
144 if (_nc_tputs_trace) {
145 _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
146 _nc_visbuf(string), affcnt, addrbuf);
148 _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf);
151 _nc_unlock_global(tracef);
155 if (!VALID_STRING(string))
159 always_delay = FALSE;
162 always_delay = (string == bell) || (string == flash_screen);
166 #if NCURSES_NO_PADDING
169 && (_nc_baudrate(ospeed) >= padding_baud_rate);
174 * This ugly kluge deals with the fact that some ancient BSD programs
175 * (like nethack) actually do the likes of tputs("50") to get delays.
178 if (isdigit(UChar(*string))) {
179 while (isdigit(UChar(*string))) {
180 trailpad = trailpad * 10 + (*string - '0');
184 if (*string == '.') {
186 if (isdigit(UChar(*string))) {
187 trailpad += (*string - '0');
190 while (isdigit(UChar(*string)))
194 if (*string == '*') {
199 #endif /* BSD_TPUTS */
201 my_outch = outc; /* redirect delay_output() */
207 if (*string != '<') {
215 if ((!isdigit(UChar(*string)) && *string != '.')
216 || !strchr(string, '>')) {
223 while (isdigit(UChar(*string))) {
224 number = number * 10 + (*string - '0');
228 if (*string == '.') {
230 if (isdigit(UChar(*string))) {
231 number += (*string - '0');
234 while (isdigit(UChar(*string)))
239 while (*string == '*' || *string == '/') {
240 if (*string == '*') {
243 } else { /* if (*string == '/') */
253 delay_output(number / 10);
255 } /* endelse (*string == '<') */
256 } /* endelse (*string == '$') */
266 * Emit any BSD-style prefix padding that we've accumulated now.
269 && (always_delay || normal_delay))
270 delay_output(trailpad / 10);
271 #endif /* BSD_TPUTS */
273 my_outch = _nc_outch;