1 /* 2 * Copyright (c) 1981 Regents of the University of California. 3 * 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 5.8 (Berkeley) 4/15/91"; 36 #endif /* not lint */ 37 38 /* 39 * printw and friends. 40 * 41 * These routines make nonportable assumptions about varargs if __STDC__ 42 * is not in effect. 43 */ 44 45 #if __STDC__ 46 #include <stdarg.h> 47 #else 48 #include <varargs.h> 49 #endif 50 #include "curses.ext" 51 52 /* 53 * This routine implements a printf on the standard screen. 54 */ 55 #if __STDC__ 56 printw(const char *fmt, ...) 57 #else 58 printw(fmt, va_alist) 59 char *fmt; 60 va_dcl 61 #endif 62 { 63 va_list ap; 64 int ret; 65 66 #if __STDC__ 67 va_start(ap, fmt); 68 #else 69 va_start(ap); 70 #endif 71 ret = _sprintw(stdscr, fmt, ap); 72 va_end(ap); 73 return (ret); 74 } 75 76 /* 77 * This routine implements a printf on the given window. 78 */ 79 #if __STDC__ 80 wprintw(WINDOW *win, const char *fmt, ...) 81 #else 82 wprintw(win, fmt, va_alist) 83 WINDOW *win; 84 char *fmt; 85 va_dcl 86 #endif 87 { 88 va_list ap; 89 int ret; 90 91 #ifdef __STDC__ 92 va_start(ap, fmt); 93 #else 94 va_start(ap); 95 #endif 96 ret = _sprintw(win, fmt, ap); 97 va_end(ap); 98 return (ret); 99 } 100 101 /* 102 * Internal write-buffer-to-window function. 103 */ 104 static int 105 _winwrite(cookie, buf, n) 106 void *cookie; 107 register char *buf; 108 int n; 109 { 110 register WINDOW *win = (WINDOW *)cookie; 111 register int c = n; 112 113 while (--c >= 0) { 114 if (waddch(win, (unsigned char) *buf++) == ERR) 115 return (-1); 116 } 117 return n; 118 } 119 120 /* 121 * This routine actually executes the printf and adds it to the window. 122 * It must not be declared static as it is used in mvprintw.c. 123 * THIS SHOULD BE RENAMED vwprintw AND EXPORTED 124 */ 125 _sprintw(win, fmt, ap) 126 WINDOW *win; 127 #if __STDC__ 128 const char *fmt; 129 #else 130 char *fmt; 131 #endif 132 va_list ap; 133 { 134 FILE *f; 135 136 if ((f = fwopen((void *)win, _winwrite)) == NULL) 137 return ERR; 138 (void) vfprintf(f, fmt, ap); 139 return fclose(f) ? ERR : OK; 140 } 141