Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2018-2019,2020 Thomas E. Dickey * |
| 3 | * Copyright 1998-2012,2016 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | /**************************************************************************** |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 31 | * Author: Thomas E. Dickey 1997-on * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 32 | ****************************************************************************/ |
| 33 | |
| 34 | /* |
| 35 | ** lib_printw.c |
| 36 | ** |
| 37 | ** The routines printw(), wprintw() and friends. |
| 38 | ** |
| 39 | */ |
| 40 | |
| 41 | #include <curses.priv.h> |
| 42 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 43 | MODULE_ID("$Id: lib_printw.c,v 1.28 2020/02/02 23:34:34 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 44 | |
| 45 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 46 | printw(const char *fmt, ...) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 47 | { |
| 48 | va_list argp; |
| 49 | int code; |
| 50 | |
| 51 | #ifdef TRACE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 52 | va_list argq; |
| 53 | va_start(argq, fmt); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 54 | T((T_CALLED("printw(%s%s)"), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 55 | _nc_visbuf(fmt), _nc_varargs(fmt, argq))); |
| 56 | va_end(argq); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 57 | #endif |
| 58 | |
| 59 | va_start(argp, fmt); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 60 | code = vw_printw(stdscr, fmt, argp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 61 | va_end(argp); |
| 62 | |
| 63 | returnCode(code); |
| 64 | } |
| 65 | |
| 66 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 67 | wprintw(WINDOW *win, const char *fmt, ...) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 68 | { |
| 69 | va_list argp; |
| 70 | int code; |
| 71 | |
| 72 | #ifdef TRACE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 73 | va_list argq; |
| 74 | va_start(argq, fmt); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 75 | T((T_CALLED("wprintw(%p,%s%s)"), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 76 | (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq))); |
| 77 | va_end(argq); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 78 | #endif |
| 79 | |
| 80 | va_start(argp, fmt); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 81 | code = vw_printw(win, fmt, argp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 82 | va_end(argp); |
| 83 | |
| 84 | returnCode(code); |
| 85 | } |
| 86 | |
| 87 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 88 | mvprintw(int y, int x, const char *fmt, ...) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 89 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 90 | int code; |
| 91 | |
| 92 | #ifdef TRACE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 93 | va_list argq; |
| 94 | va_start(argq, fmt); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 95 | T((T_CALLED("mvprintw(%d,%d,%s%s)"), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 96 | y, x, _nc_visbuf(fmt), _nc_varargs(fmt, argq))); |
| 97 | va_end(argq); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | if ((code = move(y, x)) != ERR) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 101 | va_list argp; |
| 102 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | va_start(argp, fmt); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 104 | code = vw_printw(stdscr, fmt, argp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 105 | va_end(argp); |
| 106 | } |
| 107 | returnCode(code); |
| 108 | } |
| 109 | |
| 110 | NCURSES_EXPORT(int) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 111 | mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 112 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 113 | int code; |
| 114 | |
| 115 | #ifdef TRACE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 116 | va_list argq; |
| 117 | va_start(argq, fmt); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 118 | T((T_CALLED("mvwprintw(%d,%d,%p,%s%s)"), |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 119 | y, x, (void *) win, _nc_visbuf(fmt), _nc_varargs(fmt, argq))); |
| 120 | va_end(argq); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 121 | #endif |
| 122 | |
| 123 | if ((code = wmove(win, y, x)) != ERR) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 124 | va_list argp; |
| 125 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 126 | va_start(argp, fmt); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 127 | code = vw_printw(win, fmt, argp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 128 | va_end(argp); |
| 129 | } |
| 130 | returnCode(code); |
| 131 | } |
| 132 | |
| 133 | NCURSES_EXPORT(int) |
| 134 | vwprintw(WINDOW *win, const char *fmt, va_list argp) |
| 135 | { |
| 136 | char *buf; |
| 137 | int code = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 138 | #if NCURSES_SP_FUNCS |
| 139 | SCREEN *sp = _nc_screen_of(win); |
| 140 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 141 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 142 | T((T_CALLED("vwprintw(%p,%s,va_list)"), (void *) win, _nc_visbuf(fmt))); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 143 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 144 | buf = NCURSES_SP_NAME(_nc_printf_string) (NCURSES_SP_ARGx fmt, argp); |
| 145 | if (buf != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 146 | code = waddstr(win, buf); |
| 147 | } |
| 148 | returnCode(code); |
| 149 | } |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 150 | |
| 151 | NCURSES_EXPORT(int) |
| 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 | } |