scanw.c revision 1.4 1 /*
2 * Copyright (c) 1981, 1993
3 * The Regents of the University of California. All rights reserved.
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
35 static char sccsid[] = "@(#)scanw.c 8.1 (Berkeley) 6/4/93";
36 #endif /* not lint */
37
38 /*
39 * scanw and friends.
40 */
41
42 #include <curses.h>
43
44 #if __STDC__
45 #include <stdarg.h>
46 #else
47 #include <varargs.h>
48 #endif
49
50 /*
51 * scanw --
52 * Implement a scanf on the standard screen.
53 */
54 int
55 #if __STDC__
56 scanw(const char *fmt, ...)
57 #else
58 scanw(fmt, va_alist)
59 char *fmt;
60 va_dcl
61 #endif
62 {
63 va_list ap;
64 int ret;
65
66 #if __STDC__
67 va_start(ap, fmt);
68 #else
69 va_start(ap);
70 #endif
71 ret = vwscanw(stdscr, fmt, ap);
72 va_end(ap);
73 return (ret);
74 }
75
76 /*
77 * wscanw --
78 * Implements a scanf on the given window.
79 */
80 int
81 #if __STDC__
82 wscanw(WINDOW *win, const char *fmt, ...)
83 #else
84 wscanw(win, fmt, va_alist)
85 WINDOW *win;
86 char *fmt;
87 va_dcl
88 #endif
89 {
90 va_list ap;
91 int ret;
92
93 #if __STDC__
94 va_start(ap, fmt);
95 #else
96 va_start(ap);
97 #endif
98 ret = vwscanw(win, fmt, ap);
99 va_end(ap);
100 return (ret);
101 }
102
103 /*
104 * mvscanw, mvwscanw --
105 * Implement the mvscanw commands. Due to the variable number of
106 * arguments, they cannot be macros. Another sigh....
107 */
108 int
109 #if __STDC__
110 mvscanw(register int y, register int x, const char *fmt,...)
111 #else
112 mvscanw(y, x, fmt, va_alist)
113 register int y, x;
114 char *fmt;
115 va_dcl
116 #endif
117 {
118 va_list ap;
119 int ret;
120
121 if (move(y, x) != OK)
122 return (ERR);
123 #if __STDC__
124 va_start(ap, fmt);
125 #else
126 va_start(ap);
127 #endif
128 ret = vwscanw(stdscr, fmt, ap);
129 va_end(ap);
130 return (ret);
131 }
132
133 int
134 #if __STDC__
135 mvwscanw(register WINDOW * win, register int y, register int x,
136 const char *fmt, ...)
137 #else
138 mvwscanw(win, y, x, fmt, va_alist)
139 register WINDOW *win;
140 register int y, x;
141 char *fmt;
142 va_dcl
143 #endif
144 {
145 va_list ap;
146 int ret;
147
148 if (move(y, x) != OK)
149 return (ERR);
150 #if __STDC__
151 va_start(ap, fmt);
152 #else
153 va_start(ap);
154 #endif
155 ret = vwscanw(win, fmt, ap);
156 va_end(ap);
157 return (ret);
158 }
159
160 /*
161 * vwscanw --
162 * This routine actually executes the scanf from the window.
163 */
164 int
165 vwscanw(win, fmt, ap)
166 WINDOW *win;
167 const char *fmt;
168 va_list ap;
169 {
170
171 char buf[1024];
172
173 return (wgetstr(win, buf) == OK ?
174 vsscanf(buf, fmt, ap) : ERR);
175 }
176