blob: 56528f6bc7a7c050153701ed0d906e26e0890f38 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +01002 * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05303 * *
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/****************************************************************************
Steve Kondikae271bc2015-11-15 02:50:53 +010030 * Author: Thomas E. Dickey 1997-on *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053031 ****************************************************************************/
32
33/*
34** lib_printw.c
35**
36** The routines printw(), wprintw() and friends.
37**
38*/
39
40#include <curses.priv.h>
41
Steve Kondikae271bc2015-11-15 02:50:53 +010042MODULE_ID("$Id: lib_printw.c,v 1.23 2012/09/03 17:55:28 tom Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053043
44NCURSES_EXPORT(int)
45printw(const char *fmt,...)
46{
47 va_list argp;
48 int code;
49
50#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +010051 va_list argq;
52 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053053 T((T_CALLED("printw(%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +010054 _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
55 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056#endif
57
58 va_start(argp, fmt);
59 code = vwprintw(stdscr, fmt, argp);
60 va_end(argp);
61
62 returnCode(code);
63}
64
65NCURSES_EXPORT(int)
66wprintw(WINDOW *win, const char *fmt,...)
67{
68 va_list argp;
69 int code;
70
71#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +010072 va_list argq;
73 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053074 T((T_CALLED("wprintw(%p,%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +010075 (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
76 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053077#endif
78
79 va_start(argp, fmt);
80 code = vwprintw(win, fmt, argp);
81 va_end(argp);
82
83 returnCode(code);
84}
85
86NCURSES_EXPORT(int)
87mvprintw(int y, int x, const char *fmt,...)
88{
89 va_list argp;
90 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) {
101 va_start(argp, fmt);
102 code = vwprintw(stdscr, fmt, argp);
103 va_end(argp);
104 }
105 returnCode(code);
106}
107
108NCURSES_EXPORT(int)
109mvwprintw(WINDOW *win, int y, int x, const char *fmt,...)
110{
111 va_list argp;
112 int code;
113
114#ifdef TRACE
Steve Kondikae271bc2015-11-15 02:50:53 +0100115 va_list argq;
116 va_start(argq, fmt);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530117 T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"),
Steve Kondikae271bc2015-11-15 02:50:53 +0100118 y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq)));
119 va_end(argq);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120#endif
121
122 if ((code = wmove(win, y, x)) != ERR) {
123 va_start(argp, fmt);
124 code = vwprintw(win, fmt, argp);
125 va_end(argp);
126 }
127 returnCode(code);
128}
129
130NCURSES_EXPORT(int)
131vwprintw(WINDOW *win, const char *fmt, va_list argp)
132{
133 char *buf;
134 int code = ERR;
Steve Kondikae271bc2015-11-15 02:50:53 +0100135#if NCURSES_SP_FUNCS
136 SCREEN *sp = _nc_screen_of(win);
137#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530138
Steve Kondikae271bc2015-11-15 02:50:53 +0100139 T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530140
Steve Kondikae271bc2015-11-15 02:50:53 +0100141 buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp);
142 if (buf != 0) {
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530143 code = waddstr(win, buf);
144 }
145 returnCode(code);
146}