1 /****************************************************************************
2 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
4 * *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
27 * authorization. *
28 ****************************************************************************/
29
30 /****************************************************************************
31 * Author: Thomas E. Dickey 1997-on *
32 ****************************************************************************/
33
34 /*
35 ** lib_printw.c
36 **
37 ** The routines printw(), wprintw() and friends.
38 **
39 */
40
41 #include <curses.priv.h>
42
43 MODULE_ID("$Id: lib_printw.c,v 1.28 2020/02/02 23:34:34 tom Exp $")
44
NCURSES_EXPORT(int)45 NCURSES_EXPORT(int)
46 printw(const char *fmt, ...)
47 {
48 va_list argp;
49 int code;
50
51 #ifdef TRACE
52 va_list argq;
53 va_start(argq, fmt);
54 T((T_CALLED("printw(%s%s)"),
55 _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
56 va_end(argq);
57 #endif
58
59 va_start(argp, fmt);
60 code = vw_printw(stdscr, fmt, argp);
61 va_end(argp);
62
63 returnCode(code);
64 }
65
66 NCURSES_EXPORT(int)
wprintw(WINDOW * win,const char * fmt,...)67 wprintw(WINDOW *win, const char *fmt, ...)
68 {
69 va_list argp;
70 int code;
71
72 #ifdef TRACE
73 va_list argq;
74 va_start(argq, fmt);
75 T((T_CALLED("wprintw(%p,%s%s)"),
76 (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
77 va_end(argq);
78 #endif
79
80 va_start(argp, fmt);
81 code = vw_printw(win, fmt, argp);
82 va_end(argp);
83
84 returnCode(code);
85 }
86
87 NCURSES_EXPORT(int)
mvprintw(int y,int x,const char * fmt,...)88 mvprintw(int y, int x, const char *fmt, ...)
89 {
90 int code;
91
92 #ifdef TRACE
93 va_list argq;
94 va_start(argq, fmt);
95 T((T_CALLED("mvprintw(%d,%d,%s%s)"),
96 y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
97 va_end(argq);
98 #endif
99
100 if ((code = move(y, x)) != ERR) {
101 va_list argp;
102
103 va_start(argp, fmt);
104 code = vw_printw(stdscr, fmt, argp);
105 va_end(argp);
106 }
107 returnCode(code);
108 }
109
110 NCURSES_EXPORT(int)
mvwprintw(WINDOW * win,int y,int x,const char * fmt,...)111 mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
112 {
113 int code;
114
115 #ifdef TRACE
116 va_list argq;
117 va_start(argq, fmt);
118 T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
119 y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
120 va_end(argq);
121 #endif
122
123 if ((code = wmove(win, y, x)) != ERR) {
124 va_list argp;
125
126 va_start(argp, fmt);
127 code = vw_printw(win, fmt, argp);
128 va_end(argp);
129 }
130 returnCode(code);
131 }
132
133 NCURSES_EXPORT(int)
vwprintw(WINDOW * win,const char * fmt,va_list argp)134 vwprintw(WINDOW *win, const char *fmt, va_list argp)
135 {
136 char *buf;
137 int code = ERR;
138 #if NCURSES_SP_FUNCS
139 SCREEN *sp = _nc_screen_of(win);
140 #endif
141
142 T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
143
144 buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
145 if (buf != 0) {
146 code = waddstr(win, buf);
147 }
148 returnCode(code);
149 }
150
151 NCURSES_EXPORT(int)
vw_printw(WINDOW * win,const char * fmt,va_list argp)152 vw_printw(WINDOW *win, const char *fmt, va_list argp)
153 {
154 char *buf;
155 int code = ERR;
156 #if NCURSES_SP_FUNCS
157 SCREEN *sp = _nc_screen_of(win);
158 #endif
159
160 T((T_CALLED("vw_printw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
161
162 buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
163 if (buf != 0) {
164 code = waddstr(win, buf);
165 }
166 returnCode(code);
167 }
168