xref: /openbsd-src/lib/libcurses/base/lib_printw.c (revision 92dd1ec0a89df25171bc5d61a3d95ea1a68cef0b)
1 /*	$OpenBSD: lib_printw.c,v 1.1 1999/01/18 19:09:56 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Thomas E. Dickey <dickey@clark.net> 1997                        *
33  ****************************************************************************/
34 
35 /*
36 **	lib_printw.c
37 **
38 **	The routines printw(), wprintw() and friends.
39 **
40 */
41 
42 #include <curses.priv.h>
43 
44 MODULE_ID("$From: lib_printw.c,v 1.7 1998/04/11 22:53:44 tom Exp $")
45 
46 int printw(NCURSES_CONST char *fmt, ...)
47 {
48 	va_list argp;
49 	int code;
50 
51 	T(("printw(%s,...) called", _nc_visbuf(fmt)));
52 
53 	va_start(argp, fmt);
54 	code = vwprintw(stdscr, fmt, argp);
55 	va_end(argp);
56 
57 	return code;
58 }
59 
60 int wprintw(WINDOW *win, NCURSES_CONST char *fmt, ...)
61 {
62 	va_list argp;
63 	int code;
64 
65 	T(("wprintw(%p,%s,...) called", win, _nc_visbuf(fmt)));
66 
67 	va_start(argp, fmt);
68 	code = vwprintw(win, fmt, argp);
69 	va_end(argp);
70 
71 	return code;
72 }
73 
74 int mvprintw(int y, int x, NCURSES_CONST char *fmt, ...)
75 {
76 	va_list argp;
77 	int code = move(y, x);
78 
79 	if (code != ERR) {
80 		va_start(argp, fmt);
81 		code = vwprintw(stdscr, fmt, argp);
82 		va_end(argp);
83 	}
84 	return code;
85 }
86 
87 int mvwprintw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...)
88 {
89 	va_list argp;
90 	int code = wmove(win, y, x);
91 
92 	if (code != ERR) {
93 		va_start(argp, fmt);
94 		code = vwprintw(win, fmt, argp);
95 		va_end(argp);
96 	}
97 	return code;
98 }
99 
100 int vwprintw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
101 {
102 	char *buf = _nc_printf_string(fmt, argp);
103 	int code = ERR;
104 
105 	if (buf != 0) {
106 		code = waddstr(win, buf);
107 #if USE_SAFE_SPRINTF
108 		free(buf);
109 #endif
110 	}
111 	return code;
112 }
113