Commit | Line | Data |
---|---|---|
87c6fcf8 | 1 | /* |
fd88f5c5 | 2 | * Copyright (c) 1981, 1993, 1994 |
c8a0275f | 3 | * The Regents of the University of California. All rights reserved. |
2f14f200 | 4 | * |
ad787160 C |
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. | |
87c6fcf8 DF |
32 | */ |
33 | ||
34 | #ifndef lint | |
fd88f5c5 | 35 | static char sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94"; |
17120706 KB |
36 | #endif /* not lint */ |
37 | ||
ed554bc5 | 38 | #ifdef __STDC__ |
17120706 KB |
39 | #include <stdarg.h> |
40 | #else | |
41 | #include <varargs.h> | |
42 | #endif | |
87c6fcf8 | 43 | |
fd88f5c5 C |
44 | #include "curses.h" |
45 | ||
113386fd | 46 | /* |
3b111079 | 47 | * printw and friends. |
113386fd | 48 | * |
3b111079 CT |
49 | * These routines make nonportable assumptions about varargs if __STDC__ |
50 | * is not in effect. | |
113386fd KA |
51 | */ |
52 | ||
17120706 | 53 | static int __winwrite __P((void *, const char *, int)); |
113386fd KA |
54 | |
55 | /* | |
17120706 KB |
56 | * printw -- |
57 | * Printf on the standard screen. | |
113386fd | 58 | */ |
e8cfc1d0 | 59 | int |
ed554bc5 | 60 | #ifdef __STDC__ |
3b111079 CT |
61 | printw(const char *fmt, ...) |
62 | #else | |
63 | printw(fmt, va_alist) | |
64 | char *fmt; | |
65 | va_dcl | |
66 | #endif | |
67 | { | |
17120706 KB |
68 | va_list ap; |
69 | int ret; | |
8543fbf9 | 70 | |
ed554bc5 | 71 | #ifdef __STDC__ |
3b111079 CT |
72 | va_start(ap, fmt); |
73 | #else | |
3a8b9a26 | 74 | va_start(ap); |
3b111079 | 75 | #endif |
b67f22a0 | 76 | ret = vwprintw(stdscr, fmt, ap); |
3a8b9a26 CT |
77 | va_end(ap); |
78 | return (ret); | |
113386fd KA |
79 | } |
80 | ||
81 | /* | |
17120706 KB |
82 | * wprintw -- |
83 | * Printf on the given window. | |
113386fd | 84 | */ |
e8cfc1d0 | 85 | int |
ed554bc5 | 86 | #ifdef __STDC__ |
17120706 | 87 | wprintw(WINDOW * win, const char *fmt, ...) |
3b111079 CT |
88 | #else |
89 | wprintw(win, fmt, va_alist) | |
90 | WINDOW *win; | |
91 | char *fmt; | |
92 | va_dcl | |
93 | #endif | |
94 | { | |
17120706 KB |
95 | va_list ap; |
96 | int ret; | |
3a8b9a26 | 97 | |
3b111079 CT |
98 | #ifdef __STDC__ |
99 | va_start(ap, fmt); | |
100 | #else | |
5e2f9f86 | 101 | va_start(ap); |
3b111079 | 102 | #endif |
b67f22a0 | 103 | ret = vwprintw(win, fmt, ap); |
e8cfc1d0 KB |
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 | |
ed554bc5 | 114 | #ifdef __STDC__ |
e8cfc1d0 KB |
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 | ||
ed554bc5 | 126 | #ifdef __STDC__ |
e8cfc1d0 KB |
127 | va_start(ap, fmt); |
128 | #else | |
129 | va_start(ap); | |
130 | #endif | |
79ec5a07 KB |
131 | if (move(y, x) != OK) |
132 | return (ERR); | |
b67f22a0 | 133 | ret = vwprintw(stdscr, fmt, ap); |
e8cfc1d0 KB |
134 | va_end(ap); |
135 | return (ret); | |
136 | } | |
137 | ||
138 | int | |
ed554bc5 | 139 | #ifdef __STDC__ |
e8cfc1d0 KB |
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 | ||
ed554bc5 | 153 | #ifdef __STDC__ |
e8cfc1d0 KB |
154 | va_start(ap, fmt); |
155 | #else | |
156 | va_start(ap); | |
157 | #endif | |
79ec5a07 KB |
158 | if (wmove(win, y, x) != OK) |
159 | return (ERR); | |
205a3106 | 160 | |
b67f22a0 | 161 | ret = vwprintw(win, fmt, ap); |
3a8b9a26 CT |
162 | va_end(ap); |
163 | return (ret); | |
164 | } | |
165 | ||
166 | /* | |
17120706 | 167 | * Internal write-buffer-to-window function. |
3a8b9a26 CT |
168 | */ |
169 | static int | |
17120706 | 170 | __winwrite(cookie, buf, n) |
3b111079 | 171 | void *cookie; |
17120706 | 172 | register const char *buf; |
3b111079 CT |
173 | int n; |
174 | { | |
17120706 KB |
175 | register WINDOW *win; |
176 | register int c; | |
3a8b9a26 | 177 | |
17120706 | 178 | for (c = n, win = cookie; --c >= 0;) |
79ec5a07 | 179 | if (waddch(win, *buf++) == ERR) |
3a8b9a26 | 180 | return (-1); |
17120706 | 181 | return (n); |
3a8b9a26 CT |
182 | } |
183 | ||
184 | /* | |
b67f22a0 | 185 | * vwprintw -- |
3a8b9a26 | 186 | * This routine actually executes the printf and adds it to the window. |
3a8b9a26 | 187 | */ |
4f43bb07 | 188 | int |
b67f22a0 | 189 | vwprintw(win, fmt, ap) |
e8cfc1d0 | 190 | WINDOW *win; |
205a3106 | 191 | const char *fmt; |
e8cfc1d0 | 192 | va_list ap; |
205a3106 | 193 | { |
3b111079 | 194 | FILE *f; |
113386fd | 195 | |
17120706 | 196 | if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL) |
79ec5a07 | 197 | return (ERR); |
17120706 | 198 | (void)vfprintf(f, fmt, ap); |
79ec5a07 | 199 | return (fclose(f) ? ERR : OK); |
113386fd | 200 | } |