1 /****************************************************************************
2  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28 
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33 
34 
35 
36 /*
37 **	lib_scanw.c
38 **
39 **	The routines scanw(), wscanw() and friends.
40 **
41 */
42 
43 #include <curses.priv.h>
44 
45 MODULE_ID("$Id: lib_scanw.c,v 1.8 1998/04/11 22:54:18 tom Exp $")
46 
47 #if !HAVE_VSSCANF
48 #if defined(__QNX__)
49 extern int vsscanf(const char *str, const char *format, __va_list __arg);
50 #else
51 extern int vsscanf(const char *str, const char *format, ...);
52 #endif
53 #endif
54 
55 int vwscanw(WINDOW *win, NCURSES_CONST char *fmt, va_list argp)
56 {
57 char buf[BUFSIZ];
58 
59 	if (wgetnstr(win, buf, sizeof(buf)-1) == ERR)
60 	    return(ERR);
61 
62 	return(vsscanf(buf, fmt, argp));
63 }
64 
65 int scanw(NCURSES_CONST char *fmt, ...)
66 {
67 int code;
68 va_list ap;
69 
70 	T(("scanw(\"%s\",...) called", fmt));
71 
72 	va_start(ap, fmt);
73 	code = vwscanw(stdscr, fmt, ap);
74 	va_end(ap);
75 	return (code);
76 }
77 
78 int wscanw(WINDOW *win, NCURSES_CONST char *fmt, ...)
79 {
80 int code;
81 va_list ap;
82 
83 	T(("wscanw(%p,\"%s\",...) called", win, fmt));
84 
85 	va_start(ap, fmt);
86 	code = vwscanw(win, fmt, ap);
87 	va_end(ap);
88 	return (code);
89 }
90 
91 int mvscanw(int y, int x, NCURSES_CONST char *fmt, ...)
92 {
93 int code;
94 va_list ap;
95 
96 	va_start(ap, fmt);
97 	code = (move(y, x) == OK) ? vwscanw(stdscr, fmt, ap) : ERR;
98 	va_end(ap);
99 	return (code);
100 }
101 
102 int mvwscanw(WINDOW *win, int y, int x, NCURSES_CONST char *fmt, ...)
103 {
104 int code;
105 va_list ap;
106 
107 	va_start(ap, fmt);
108 	code = (wmove(win, y, x) == OK) ? vwscanw(win, fmt, ap) : ERR;
109 	va_end(ap);
110 	return (code);
111 }
112