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