blob: d901b727a91c0a04486c9de9367bce9ff7982515 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +010031 * Author: Thomas E. Dickey 1997-on *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053032 ****************************************************************************/
33
34/*
35** lib_printw.c
36**
37** The routines printw(), wprintw() and friends.
38**
39*/
40
41#include <curses.priv.h>
42
micky3879b9f5e72025-07-08 18:04:53 -040043MODULE_ID("$Id: lib_printw.c,v 1.28 2020/02/02 23:34:34 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053044
45NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040046printw(const char *fmt, ...)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047{
48 va_list argp;
49 int code;
50
51#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +010052 va_list argq;
53 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053054 T((T_CALLED("printw(%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +010055 _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
56 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053057#endif
58
59 va_start(argp, fmt);
micky3879b9f5e72025-07-08 18:04:53 -040060 code = vw_printw(stdscr, fmt, argp);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053061 va_end(argp);
62
63 returnCode(code);
64}
65
66NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040067wprintw(WINDOW *win, const char *fmt, ...)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053068{
69 va_list argp;
70 int code;
71
72#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +010073 va_list argq;
74 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053075 T((T_CALLED("wprintw(%p,%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +010076 (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
77 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053078#endif
79
80 va_start(argp, fmt);
micky3879b9f5e72025-07-08 18:04:53 -040081 code = vw_printw(win, fmt, argp);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053082 va_end(argp);
83
84 returnCode(code);
85}
86
87NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -040088mvprintw(int y, int x, const char *fmt, ...)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053089{
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090 int code;
91
92#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +010093 va_list argq;
94 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053095 T((T_CALLED("mvprintw(%d,%d,%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +010096 y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
97 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053098#endif
99
100 if ((code = move(y, x)) != ERR) {
micky3879b9f5e72025-07-08 18:04:53 -0400101 va_list argp;
102
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103 va_start(argp, fmt);
micky3879b9f5e72025-07-08 18:04:53 -0400104 code = vw_printw(stdscr, fmt, argp);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530105 va_end(argp);
106 }
107 returnCode(code);
108}
109
110NCURSES_EXPORT(int)
micky3879b9f5e72025-07-08 18:04:53 -0400111mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530112{
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530113 int code;
114
115#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +0100116 va_list argq;
117 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530118 T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +0100119 y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
120 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530121#endif
122
123 if ((code = wmove(win, y, x)) != ERR) {
micky3879b9f5e72025-07-08 18:04:53 -0400124 va_list argp;
125
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530126 va_start(argp, fmt);
micky3879b9f5e72025-07-08 18:04:53 -0400127 code = vw_printw(win, fmt, argp);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530128 va_end(argp);
129 }
130 returnCode(code);
131}
132
133NCURSES_EXPORT(int)
134vwprintw(WINDOW *win, const char *fmt, va_list argp)
135{
136 char *buf;
137 int code = ERR;
Steve Kondikae271bc2015-11-15 02:50:53 +0100138#if NCURSES_SP_FUNCS
139 SCREEN *sp = _nc_screen_of(win);
140#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530141
Steve Kondikae271bc2015-11-15 02:50:53 +0100142 T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530143
Steve Kondikae271bc2015-11-15 02:50:53 +0100144 buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
145 if (buf != 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530146 code = waddstr(win, buf);
147 }
148 returnCode(code);
149}
micky3879b9f5e72025-07-08 18:04:53 -0400150
151NCURSES_EXPORT(int)
152vw_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}