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