1 /* 2 * Copyright (c) 1981, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 #ifndef lint 35 static char sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94"; 36 #endif /* not lint */ 37 38 #ifdef __STDC__ 39 #include <stdarg.h> 40 #else 41 #include <varargs.h> 42 #endif 43 44 #include "curses.h" 45 46 /* 47 * printw and friends. 48 * 49 * These routines make nonportable assumptions about varargs if __STDC__ 50 * is not in effect. 51 */ 52 53 static int __winwrite __P((void *, const char *, int)); 54 55 /* 56 * printw -- 57 * Printf on the standard screen. 58 */ 59 int 60 #ifdef __STDC__ 61 printw(const char *fmt, ...) 62 #else 63 printw(fmt, va_alist) 64 char *fmt; 65 va_dcl 66 #endif 67 { 68 va_list ap; 69 int ret; 70 71 #ifdef __STDC__ 72 va_start(ap, fmt); 73 #else 74 va_start(ap); 75 #endif 76 ret = vwprintw(stdscr, fmt, ap); 77 va_end(ap); 78 return (ret); 79 } 80 81 /* 82 * wprintw -- 83 * Printf on the given window. 84 */ 85 int 86 #ifdef __STDC__ 87 wprintw(WINDOW * win, const char *fmt, ...) 88 #else 89 wprintw(win, fmt, va_alist) 90 WINDOW *win; 91 char *fmt; 92 va_dcl 93 #endif 94 { 95 va_list ap; 96 int ret; 97 98 #ifdef __STDC__ 99 va_start(ap, fmt); 100 #else 101 va_start(ap); 102 #endif 103 ret = vwprintw(win, fmt, ap); 104 va_end(ap); 105 return (ret); 106 } 107 108 /* 109 * mvprintw, mvwprintw -- 110 * Implement the mvprintw commands. Due to the variable number of 111 * arguments, they cannot be macros. Sigh.... 112 */ 113 int 114 #ifdef __STDC__ 115 mvprintw(register int y, register int x, const char *fmt, ...) 116 #else 117 mvprintw(y, x, fmt, va_alist) 118 register int y, x; 119 char *fmt; 120 va_dcl 121 #endif 122 { 123 va_list ap; 124 int ret; 125 126 #ifdef __STDC__ 127 va_start(ap, fmt); 128 #else 129 va_start(ap); 130 #endif 131 if (move(y, x) != OK) 132 return (ERR); 133 ret = vwprintw(stdscr, fmt, ap); 134 va_end(ap); 135 return (ret); 136 } 137 138 int 139 #ifdef __STDC__ 140 mvwprintw(register WINDOW * win, register int y, register int x, 141 const char *fmt, ...) 142 #else 143 mvwprintw(win, y, x, fmt, va_alist) 144 register WINDOW *win; 145 register int y, x; 146 char *fmt; 147 va_dcl 148 #endif 149 { 150 va_list ap; 151 int ret; 152 153 #ifdef __STDC__ 154 va_start(ap, fmt); 155 #else 156 va_start(ap); 157 #endif 158 if (wmove(win, y, x) != OK) 159 return (ERR); 160 161 ret = vwprintw(win, fmt, ap); 162 va_end(ap); 163 return (ret); 164 } 165 166 /* 167 * Internal write-buffer-to-window function. 168 */ 169 static int 170 __winwrite(cookie, buf, n) 171 void *cookie; 172 register const char *buf; 173 int n; 174 { 175 register WINDOW *win; 176 register int c; 177 178 for (c = n, win = cookie; --c >= 0;) 179 if (waddch(win, *buf++) == ERR) 180 return (-1); 181 return (n); 182 } 183 184 /* 185 * vwprintw -- 186 * This routine actually executes the printf and adds it to the window. 187 */ 188 int 189 vwprintw(win, fmt, ap) 190 WINDOW *win; 191 const char *fmt; 192 va_list ap; 193 { 194 FILE *f; 195 196 if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL) 197 return (ERR); 198 (void)vfprintf(f, fmt, ap); 199 return (fclose(f) ? ERR : OK); 200 } 201