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