1 /* 2 * Copyright (c) 1981 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)printw.c 5.8 (Berkeley) 04/15/91"; 10 #endif /* not lint */ 11 12 /* 13 * printw and friends. 14 * 15 * These routines make nonportable assumptions about varargs if __STDC__ 16 * is not in effect. 17 */ 18 19 #if __STDC__ 20 #include <stdarg.h> 21 #else 22 #include <varargs.h> 23 #endif 24 #include "curses.ext" 25 26 /* 27 * This routine implements a printf on the standard screen. 28 */ 29 #if __STDC__ 30 printw(const char *fmt, ...) 31 #else 32 printw(fmt, va_alist) 33 char *fmt; 34 va_dcl 35 #endif 36 { 37 va_list ap; 38 int ret; 39 40 #if __STDC__ 41 va_start(ap, fmt); 42 #else 43 va_start(ap); 44 #endif 45 ret = _sprintw(stdscr, fmt, ap); 46 va_end(ap); 47 return (ret); 48 } 49 50 /* 51 * This routine implements a printf on the given window. 52 */ 53 #if __STDC__ 54 wprintw(WINDOW *win, const char *fmt, ...) 55 #else 56 wprintw(win, fmt, va_alist) 57 WINDOW *win; 58 char *fmt; 59 va_dcl 60 #endif 61 { 62 va_list ap; 63 int ret; 64 65 #ifdef __STDC__ 66 va_start(ap, fmt); 67 #else 68 va_start(ap); 69 #endif 70 ret = _sprintw(win, fmt, ap); 71 va_end(ap); 72 return (ret); 73 } 74 75 /* 76 * Internal write-buffer-to-window function. 77 */ 78 static int 79 _winwrite(cookie, buf, n) 80 void *cookie; 81 register char *buf; 82 int n; 83 { 84 register WINDOW *win = (WINDOW *)cookie; 85 register int c = n; 86 87 while (--c >= 0) { 88 if (waddch(win, *buf++) == ERR) 89 return (-1); 90 } 91 return n; 92 } 93 94 /* 95 * This routine actually executes the printf and adds it to the window. 96 * It must not be declared static as it is used in mvprintw.c. 97 * THIS SHOULD BE RENAMED vwprintw AND EXPORTED 98 */ 99 _sprintw(win, fmt, ap) 100 WINDOW *win; 101 #if __STDC__ 102 const char *fmt; 103 #else 104 char *fmt; 105 #endif 106 va_list ap; 107 { 108 FILE *f; 109 110 if ((f = fwopen((void *)win, _winwrite)) == NULL) 111 return ERR; 112 (void) vfprintf(f, fmt, ap); 113 return fclose(f) ? ERR : OK; 114 } 115