1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 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 * and: Juergen Pfeifer 2009 *
34 ****************************************************************************/
44 #include <curses.priv.h>
46 #include <term.h> /* padding_baud_rate, xon_xoff */
47 #include <termcap.h> /* ospeed */
50 MODULE_ID("$Id: lib_tputs.c,v 1.68 2009/02/28 21:08:18 tom Exp $")
52 NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */
53 NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */
55 NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */
57 #if NCURSES_NO_PADDING
59 _nc_set_no_padding(SCREEN *sp)
61 bool no_padding = (getenv("NCURSES_NO_PADDING") != 0);
64 sp->_no_padding = no_padding;
66 _nc_prescreen._no_padding = no_padding;
68 TR(TRACE_CHARPUT | TRACE_MOVE, ("padding will%s be used",
69 GetNoPadding(sp) ? " not" : ""));
73 static int (*my_outch) (int c) = _nc_outch;
76 NCURSES_SP_NAME(delay_output) (NCURSES_SP_DCLx int ms)
78 T((T_CALLED("delay_output(%d)"), ms));
84 register int nullcount;
86 nullcount = (ms * _nc_baudrate(ospeed)) / (BAUDBYTE * 1000);
87 for (_nc_nulls_sent += nullcount; nullcount > 0; nullcount--)
89 if (my_outch == _nc_outch)
100 return NCURSES_SP_NAME(delay_output) (CURRENT_SCREEN, ms);
105 NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_DCL0)
107 (void) fflush(NC_OUTPUT);
114 NCURSES_SP_NAME(_nc_flush) (CURRENT_SCREEN);
119 NCURSES_SP_NAME(_nc_outch) (NCURSES_SP_DCLx int ch)
124 && SP_PARM->_cleanup) {
127 * POSIX says write() is safe in a signal handler, but the
128 * buffered I/O is not.
130 write(fileno(NC_OUTPUT), &tmp, 1);
141 return NCURSES_SP_NAME(_nc_outch) (CURRENT_SCREEN, ch);
146 putp(const char *string)
148 return tputs(string, 1, _nc_outch);
152 tputs(const char *string, int affcnt, int (*outc) (int))
159 #endif /* BSD_TPUTS */
164 if (USE_TRACEF(TRACE_TPUTS)) {
165 if (outc == _nc_outch)
166 (void) strcpy(addrbuf, "_nc_outch");
168 (void) sprintf(addrbuf, "%p", outc);
169 if (_nc_tputs_trace) {
170 _tracef("tputs(%s = %s, %d, %s) called", _nc_tputs_trace,
171 _nc_visbuf(string), affcnt, addrbuf);
173 _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf);
176 _nc_unlock_global(tracef);
180 if (!VALID_STRING(string))
184 always_delay = FALSE;
187 always_delay = (string == bell) || (string == flash_screen);
191 #if NCURSES_NO_PADDING
194 && (_nc_baudrate(ospeed) >= padding_baud_rate);
199 * This ugly kluge deals with the fact that some ancient BSD programs
200 * (like nethack) actually do the likes of tputs("50") to get delays.
203 if (isdigit(UChar(*string))) {
204 while (isdigit(UChar(*string))) {
205 trailpad = trailpad * 10 + (*string - '0');
209 if (*string == '.') {
211 if (isdigit(UChar(*string))) {
212 trailpad += (*string - '0');
215 while (isdigit(UChar(*string)))
219 if (*string == '*') {
224 #endif /* BSD_TPUTS */
226 my_outch = outc; /* redirect delay_output() */
232 if (*string != '<') {
240 if ((!isdigit(UChar(*string)) && *string != '.')
241 || !strchr(string, '>')) {
248 while (isdigit(UChar(*string))) {
249 number = number * 10 + (*string - '0');
253 if (*string == '.') {
255 if (isdigit(UChar(*string))) {
256 number += (*string - '0');
259 while (isdigit(UChar(*string)))
264 while (*string == '*' || *string == '/') {
265 if (*string == '*') {
268 } else { /* if (*string == '/') */
278 delay_output(number / 10);
280 } /* endelse (*string == '<') */
281 } /* endelse (*string == '$') */
291 * Emit any BSD-style prefix padding that we've accumulated now.
294 && (always_delay || normal_delay))
295 delay_output(trailpad / 10);
296 #endif /* BSD_TPUTS */
298 my_outch = _nc_outch;