printw.c revision 1.22 1 1.22 joerg /* $NetBSD: printw.c,v 1.22 2011/07/17 20:54:34 joerg Exp $ */
2 1.9 mikel
3 1.1 cgd /*
4 1.8 cgd * Copyright (c) 1981, 1993, 1994
5 1.5 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.19 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.9 mikel #include <sys/cdefs.h>
33 1.1 cgd #ifndef lint
34 1.9 mikel #if 0
35 1.8 cgd static char sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94";
36 1.9 mikel #else
37 1.22 joerg __RCSID("$NetBSD: printw.c,v 1.22 2011/07/17 20:54:34 joerg Exp $");
38 1.9 mikel #endif
39 1.11 mrg #endif /* not lint */
40 1.1 cgd
41 1.4 mycroft #include <stdarg.h>
42 1.8 cgd
43 1.8 cgd #include "curses.h"
44 1.12 blymn #include "curses_private.h"
45 1.4 mycroft
46 1.1 cgd /*
47 1.1 cgd * printw and friends.
48 1.1 cgd */
49 1.1 cgd
50 1.4 mycroft static int __winwrite __P((void *, const char *, int));
51 1.1 cgd
52 1.1 cgd /*
53 1.4 mycroft * printw --
54 1.4 mycroft * Printf on the standard screen.
55 1.1 cgd */
56 1.4 mycroft int
57 1.13 jdc printw(const char *fmt,...)
58 1.1 cgd {
59 1.4 mycroft va_list ap;
60 1.11 mrg int ret;
61 1.1 cgd
62 1.1 cgd va_start(ap, fmt);
63 1.21 joerg ret = vw_printw(stdscr, fmt, ap);
64 1.1 cgd va_end(ap);
65 1.1 cgd return (ret);
66 1.1 cgd }
67 1.1 cgd /*
68 1.4 mycroft * wprintw --
69 1.4 mycroft * Printf on the given window.
70 1.1 cgd */
71 1.4 mycroft int
72 1.15 blymn wprintw(WINDOW *win, const char *fmt,...)
73 1.1 cgd {
74 1.4 mycroft va_list ap;
75 1.11 mrg int ret;
76 1.1 cgd
77 1.1 cgd va_start(ap, fmt);
78 1.21 joerg ret = vw_printw(win, fmt, ap);
79 1.4 mycroft va_end(ap);
80 1.4 mycroft return (ret);
81 1.4 mycroft }
82 1.4 mycroft /*
83 1.4 mycroft * mvprintw, mvwprintw --
84 1.4 mycroft * Implement the mvprintw commands. Due to the variable number of
85 1.4 mycroft * arguments, they cannot be macros. Sigh....
86 1.4 mycroft */
87 1.4 mycroft int
88 1.13 jdc mvprintw(int y, int x, const char *fmt,...)
89 1.4 mycroft {
90 1.4 mycroft va_list ap;
91 1.11 mrg int ret;
92 1.4 mycroft
93 1.17 wiz if (move(y, x) != OK)
94 1.17 wiz return (ERR);
95 1.4 mycroft va_start(ap, fmt);
96 1.21 joerg ret = vw_printw(stdscr, fmt, ap);
97 1.4 mycroft va_end(ap);
98 1.4 mycroft return (ret);
99 1.4 mycroft }
100 1.4 mycroft
101 1.4 mycroft int
102 1.14 simonb mvwprintw(WINDOW * win, int y, int x, const char *fmt,...)
103 1.4 mycroft {
104 1.4 mycroft va_list ap;
105 1.11 mrg int ret;
106 1.4 mycroft
107 1.17 wiz if (wmove(win, y, x) != OK)
108 1.17 wiz return (ERR);
109 1.17 wiz
110 1.4 mycroft va_start(ap, fmt);
111 1.21 joerg ret = vw_printw(win, fmt, ap);
112 1.1 cgd va_end(ap);
113 1.1 cgd return (ret);
114 1.1 cgd }
115 1.1 cgd /*
116 1.4 mycroft * Internal write-buffer-to-window function.
117 1.1 cgd */
118 1.1 cgd static int
119 1.4 mycroft __winwrite(cookie, buf, n)
120 1.11 mrg void *cookie;
121 1.10 perry const char *buf;
122 1.11 mrg int n;
123 1.1 cgd {
124 1.10 perry WINDOW *win;
125 1.11 mrg int c;
126 1.1 cgd
127 1.4 mycroft for (c = n, win = cookie; --c >= 0;)
128 1.12 blymn {
129 1.12 blymn #ifdef DEBUG
130 1.20 jdc __CTRACE(__CTRACE_MISC, "__winwrite: %c\n", *buf);
131 1.12 blymn #endif
132 1.12 blymn if (waddch(win, (chtype) (*buf++ & __CHARTEXT)) == ERR)
133 1.1 cgd return (-1);
134 1.12 blymn }
135 1.4 mycroft return (n);
136 1.1 cgd }
137 1.1 cgd /*
138 1.21 joerg * vw_printw --
139 1.1 cgd * This routine actually executes the printf and adds it to the window.
140 1.1 cgd */
141 1.5 cgd int
142 1.22 joerg vw_printw(WINDOW *win, const char *fmt, va_list ap)
143 1.1 cgd {
144 1.11 mrg FILE *f;
145 1.1 cgd
146 1.4 mycroft if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL)
147 1.4 mycroft return (ERR);
148 1.11 mrg (void) vfprintf(f, fmt, ap);
149 1.4 mycroft return (fclose(f) ? ERR : OK);
150 1.1 cgd }
151 1.21 joerg
152 1.21 joerg __strong_alias(vwprintw, vw_printw)
153