1 /*
2  * Copyright (c) 1981, 1993, 1994
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. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef lint
31 static char sccsid[] = "@(#)scanw.c	8.3 (Berkeley) 5/4/94";
32 #endif	/* not lint */
33 
34 /*
35  * scanw and friends.
36  */
37 
38 #include <stdarg.h>
39 
40 #include "curses.h"
41 
42 /*
43  * scanw --
44  *	Implement a scanf on the standard screen.
45  */
46 int
scanw(const char * fmt,...)47 scanw(const char *fmt, ...)
48 {
49 	va_list ap;
50 	int ret;
51 
52 	va_start(ap, fmt);
53 	ret = vwscanw(stdscr, fmt, ap);
54 	va_end(ap);
55 	return (ret);
56 }
57 
58 /*
59  * wscanw --
60  *	Implements a scanf on the given window.
61  */
62 int
wscanw(WINDOW * win,const char * fmt,...)63 wscanw(WINDOW *win, const char *fmt, ...)
64 {
65 	va_list ap;
66 	int ret;
67 
68 	va_start(ap, fmt);
69 	ret = vwscanw(win, fmt, ap);
70 	va_end(ap);
71 	return (ret);
72 }
73 
74 /*
75  * mvscanw, mvwscanw --
76  *	Implement the mvscanw commands.  Due to the variable number of
77  *	arguments, they cannot be macros.  Another sigh....
78  */
79 int
mvscanw(register int y,register int x,const char * fmt,...)80 mvscanw(register int y, register int x, const char *fmt,...)
81 {
82 	va_list ap;
83 	int ret;
84 
85 	if (move(y, x) != OK)
86 		return (ERR);
87 	va_start(ap, fmt);
88 	ret = vwscanw(stdscr, fmt, ap);
89 	va_end(ap);
90 	return (ret);
91 }
92 
93 int
mvwscanw(register WINDOW * win,register int y,register int x,const char * fmt,...)94 mvwscanw(register WINDOW * win, register int y, register int x,
95     const char *fmt, ...)
96 {
97 	va_list ap;
98 	int ret;
99 
100 	if (move(y, x) != OK)
101 		return (ERR);
102 	va_start(ap, fmt);
103 	ret = vwscanw(win, fmt, ap);
104 	va_end(ap);
105 	return (ret);
106 }
107 
108 /*
109  * vwscanw --
110  *	This routine actually executes the scanf from the window.
111  */
112 int
vwscanw(win,fmt,ap)113 vwscanw(win, fmt, ap)
114 	WINDOW *win;
115 	const char *fmt;
116 	va_list ap;
117 {
118 
119 	char buf[1024];
120 
121 	return (wgetstr(win, buf) == OK ?
122 	    vsscanf(buf, fmt, ap) : ERR);
123 }
124