]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_printw.c
ncurses 5.9 - patch 20120825
[ncurses.git] / ncurses / base / lib_printw.c
1 /****************************************************************************
2  * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc.              *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
31  ****************************************************************************/
32
33 /*
34 **      lib_printw.c
35 **
36 **      The routines printw(), wprintw() and friends.
37 **
38 */
39
40 #include <curses.priv.h>
41
42 MODULE_ID("$Id: lib_printw.c,v 1.22 2012/03/10 20:47:33 tom Exp $")
43
44 NCURSES_EXPORT(int)
45 printw(const char *fmt,...)
46 {
47     va_list argp;
48     int code;
49
50 #ifdef TRACE
51     va_list argq;
52     begin_va_copy(argq, argp);
53     va_start(argq, fmt);
54     T((T_CALLED("printw(%s%s)"),
55        _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
56     end_va_copy(argq);
57 #endif
58
59     va_start(argp, fmt);
60     code = vwprintw(stdscr, fmt, argp);
61     va_end(argp);
62
63     returnCode(code);
64 }
65
66 NCURSES_EXPORT(int)
67 wprintw(WINDOW *win, const char *fmt,...)
68 {
69     va_list argp;
70     int code;
71
72 #ifdef TRACE
73     va_list argq;
74     begin_va_copy(argq, argp);
75     va_start(argq, fmt);
76     T((T_CALLED("wprintw(%p,%s%s)"),
77        (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
78     end_va_copy(argq);
79 #endif
80
81     va_start(argp, fmt);
82     code = vwprintw(win, fmt, argp);
83     va_end(argp);
84
85     returnCode(code);
86 }
87
88 NCURSES_EXPORT(int)
89 mvprintw(int y, int x, const char *fmt,...)
90 {
91     va_list argp;
92     int code;
93
94 #ifdef TRACE
95     va_list argq;
96     begin_va_copy(argq, argp);
97     va_start(argq, fmt);
98     T((T_CALLED("mvprintw(%d,%d,%s%s)"),
99        y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
100     end_va_copy(argq);
101 #endif
102
103     if ((code = move(y, x)) != ERR) {
104         va_start(argp, fmt);
105         code = vwprintw(stdscr, fmt, argp);
106         va_end(argp);
107     }
108     returnCode(code);
109 }
110
111 NCURSES_EXPORT(int)
112 mvwprintw(WINDOW *win, int y, int x, const char *fmt,...)
113 {
114     va_list argp;
115     int code;
116
117 #ifdef TRACE
118     va_list argq;
119     begin_va_copy(argq, argp);
120     va_start(argq, fmt);
121     T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
122        y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
123     end_va_copy(argq);
124 #endif
125
126     if ((code = wmove(win, y, x)) != ERR) {
127         va_start(argp, fmt);
128         code = vwprintw(win, fmt, argp);
129         va_end(argp);
130     }
131     returnCode(code);
132 }
133
134 NCURSES_EXPORT(int)
135 vwprintw(WINDOW *win, const char *fmt, va_list argp)
136 {
137     char *buf;
138     int code = ERR;
139 #if NCURSES_SP_FUNCS
140     SCREEN *sp = _nc_screen_of(win);
141 #endif
142
143     T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
144
145     buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
146     if (buf != 0) {
147         code = waddstr(win, buf);
148     }
149     returnCode(code);
150 }