scanw.c revision 1.9 1 /* $NetBSD: scanw.c,v 1.9 1998/02/03 19:12:33 perry Exp $ */
2
3 /*
4 * Copyright (c) 1981, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94";
40 #else
41 __RCSID("$NetBSD: scanw.c,v 1.9 1998/02/03 19:12:33 perry Exp $");
42 #endif
43 #endif /* not lint */
44
45 /*
46 * scanw and friends.
47 */
48
49 #ifdef __STDC__
50 #include <stdarg.h>
51 #else
52 #include <varargs.h>
53 #endif
54
55 #include "curses.h"
56
57 /*
58 * scanw --
59 * Implement a scanf on the standard screen.
60 */
61 int
62 #ifdef __STDC__
63 scanw(const char *fmt, ...)
64 #else
65 scanw(fmt, va_alist)
66 char *fmt;
67 va_dcl
68 #endif
69 {
70 va_list ap;
71 int ret;
72
73 #ifdef __STDC__
74 va_start(ap, fmt);
75 #else
76 va_start(ap);
77 #endif
78 ret = vwscanw(stdscr, fmt, ap);
79 va_end(ap);
80 return (ret);
81 }
82
83 /*
84 * wscanw --
85 * Implements a scanf on the given window.
86 */
87 int
88 #ifdef __STDC__
89 wscanw(WINDOW *win, const char *fmt, ...)
90 #else
91 wscanw(win, fmt, va_alist)
92 WINDOW *win;
93 char *fmt;
94 va_dcl
95 #endif
96 {
97 va_list ap;
98 int ret;
99
100 #ifdef __STDC__
101 va_start(ap, fmt);
102 #else
103 va_start(ap);
104 #endif
105 ret = vwscanw(win, fmt, ap);
106 va_end(ap);
107 return (ret);
108 }
109
110 /*
111 * mvscanw, mvwscanw --
112 * Implement the mvscanw commands. Due to the variable number of
113 * arguments, they cannot be macros. Another sigh....
114 */
115 int
116 #ifdef __STDC__
117 mvscanw(int y, int x, const char *fmt,...)
118 #else
119 mvscanw(y, x, fmt, va_alist)
120 int y, x;
121 char *fmt;
122 va_dcl
123 #endif
124 {
125 va_list ap;
126 int ret;
127
128 if (move(y, x) != OK)
129 return (ERR);
130 #ifdef __STDC__
131 va_start(ap, fmt);
132 #else
133 va_start(ap);
134 #endif
135 ret = vwscanw(stdscr, fmt, ap);
136 va_end(ap);
137 return (ret);
138 }
139
140 int
141 #ifdef __STDC__
142 mvwscanw(WINDOW * win, int y, int x,
143 const char *fmt, ...)
144 #else
145 mvwscanw(win, y, x, fmt, va_alist)
146 WINDOW *win;
147 int y, x;
148 char *fmt;
149 va_dcl
150 #endif
151 {
152 va_list ap;
153 int ret;
154
155 if (move(y, x) != OK)
156 return (ERR);
157 #ifdef __STDC__
158 va_start(ap, fmt);
159 #else
160 va_start(ap);
161 #endif
162 ret = vwscanw(win, fmt, ap);
163 va_end(ap);
164 return (ret);
165 }
166
167 /*
168 * vwscanw --
169 * This routine actually executes the scanf from the window.
170 */
171 int
172 vwscanw(win, fmt, ap)
173 WINDOW *win;
174 const char *fmt;
175 va_list ap;
176 {
177
178 char buf[1024];
179
180 return (wgetstr(win, buf) == OK ?
181 vsscanf(buf, fmt, ap) : ERR);
182 }
183