xref: /original-bsd/lib/libcurses/scanw.c (revision f8557398)
14fc3d3f8Sarnold /*
2*f8557398Sbostic  * Copyright (c) 1981, 1993, 1994
31dcb39f9Sbostic  *	The Regents of the University of California.  All rights reserved.
40c41a22eSbostic  *
5784468bbSbostic  * %sccs.include.redist.c%
686600d7eSdist  */
786600d7eSdist 
886600d7eSdist #ifndef lint
9*f8557398Sbostic static char sccsid[] = "@(#)scanw.c	8.3 (Berkeley) 05/04/94";
100c41a22eSbostic #endif	/* not lint */
1186600d7eSdist 
1286600d7eSdist /*
133ae5d7deSbostic  * scanw and friends.
144fc3d3f8Sarnold  */
154fc3d3f8Sarnold 
16221edb76Sbostic #ifdef __STDC__
1756d30a5aStorek #include <stdarg.h>
1856d30a5aStorek #else
1956d30a5aStorek #include <varargs.h>
2056d30a5aStorek #endif
214fc3d3f8Sarnold 
22*f8557398Sbostic #include "curses.h"
23*f8557398Sbostic 
244fc3d3f8Sarnold /*
253ae5d7deSbostic  * scanw --
263ae5d7deSbostic  *	Implement a scanf on the standard screen.
274fc3d3f8Sarnold  */
28200347d8Sbostic int
29221edb76Sbostic #ifdef __STDC__
scanw(const char * fmt,...)3056d30a5aStorek scanw(const char *fmt, ...)
3156d30a5aStorek #else
3256d30a5aStorek scanw(fmt, va_alist)
334fc3d3f8Sarnold 	char *fmt;
3456d30a5aStorek 	va_dcl
3556d30a5aStorek #endif
3656d30a5aStorek {
3756d30a5aStorek 	va_list ap;
3856d30a5aStorek 	int ret;
394fc3d3f8Sarnold 
40221edb76Sbostic #ifdef __STDC__
4156d30a5aStorek 	va_start(ap, fmt);
4256d30a5aStorek #else
4356d30a5aStorek 	va_start(ap);
4456d30a5aStorek #endif
450d0e39deSelan 	ret = vwscanw(stdscr, fmt, ap);
4656d30a5aStorek 	va_end(ap);
473ae5d7deSbostic 	return (ret);
484fc3d3f8Sarnold }
49a14d59f2Sbostic 
504fc3d3f8Sarnold /*
513ae5d7deSbostic  * wscanw --
523ae5d7deSbostic  *	Implements a scanf on the given window.
534fc3d3f8Sarnold  */
54200347d8Sbostic int
55221edb76Sbostic #ifdef __STDC__
wscanw(WINDOW * win,const char * fmt,...)5656d30a5aStorek wscanw(WINDOW *win, const char *fmt, ...)
5756d30a5aStorek #else
5856d30a5aStorek wscanw(win, fmt, va_alist)
594fc3d3f8Sarnold 	WINDOW *win;
604fc3d3f8Sarnold 	char *fmt;
6156d30a5aStorek 	va_dcl
6256d30a5aStorek #endif
6356d30a5aStorek {
6456d30a5aStorek 	va_list ap;
6556d30a5aStorek 	int ret;
664fc3d3f8Sarnold 
67221edb76Sbostic #ifdef __STDC__
6856d30a5aStorek 	va_start(ap, fmt);
6956d30a5aStorek #else
7056d30a5aStorek 	va_start(ap);
7156d30a5aStorek #endif
720d0e39deSelan 	ret = vwscanw(win, fmt, ap);
7356d30a5aStorek 	va_end(ap);
743ae5d7deSbostic 	return (ret);
75a14d59f2Sbostic }
76a14d59f2Sbostic 
774fc3d3f8Sarnold /*
78200347d8Sbostic  * mvscanw, mvwscanw --
79200347d8Sbostic  *	Implement the mvscanw commands.  Due to the variable number of
80200347d8Sbostic  *	arguments, they cannot be macros.  Another sigh....
81200347d8Sbostic  */
82200347d8Sbostic int
83221edb76Sbostic #ifdef __STDC__
mvscanw(register int y,register int x,const char * fmt,...)84200347d8Sbostic mvscanw(register int y, register int x, const char *fmt,...)
85200347d8Sbostic #else
86200347d8Sbostic mvscanw(y, x, fmt, va_alist)
87200347d8Sbostic 	register int y, x;
88200347d8Sbostic 	char *fmt;
89200347d8Sbostic 	va_dcl
90200347d8Sbostic #endif
91200347d8Sbostic {
92200347d8Sbostic 	va_list ap;
93200347d8Sbostic 	int ret;
94200347d8Sbostic 
952989bfcaSbostic 	if (move(y, x) != OK)
962989bfcaSbostic 		return (ERR);
97221edb76Sbostic #ifdef __STDC__
98200347d8Sbostic 	va_start(ap, fmt);
99200347d8Sbostic #else
100200347d8Sbostic 	va_start(ap);
101200347d8Sbostic #endif
1020d0e39deSelan 	ret = vwscanw(stdscr, fmt, ap);
103200347d8Sbostic 	va_end(ap);
104200347d8Sbostic 	return (ret);
105200347d8Sbostic }
106200347d8Sbostic 
107200347d8Sbostic int
108221edb76Sbostic #ifdef __STDC__
mvwscanw(register WINDOW * win,register int y,register int x,const char * fmt,...)109200347d8Sbostic mvwscanw(register WINDOW * win, register int y, register int x,
110200347d8Sbostic     const char *fmt, ...)
111200347d8Sbostic #else
112200347d8Sbostic mvwscanw(win, y, x, fmt, va_alist)
113200347d8Sbostic 	register WINDOW *win;
114200347d8Sbostic 	register int y, x;
115200347d8Sbostic 	char *fmt;
116200347d8Sbostic 	va_dcl
117200347d8Sbostic #endif
118200347d8Sbostic {
119200347d8Sbostic 	va_list ap;
120200347d8Sbostic 	int ret;
121200347d8Sbostic 
1222989bfcaSbostic 	if (move(y, x) != OK)
1232989bfcaSbostic 		return (ERR);
124221edb76Sbostic #ifdef __STDC__
125200347d8Sbostic 	va_start(ap, fmt);
126200347d8Sbostic #else
127200347d8Sbostic 	va_start(ap);
128200347d8Sbostic #endif
1290d0e39deSelan 	ret = vwscanw(win, fmt, ap);
130200347d8Sbostic 	va_end(ap);
131200347d8Sbostic 	return (ret);
132200347d8Sbostic }
133200347d8Sbostic 
134200347d8Sbostic /*
1350d0e39deSelan  * vwscanw --
1364fc3d3f8Sarnold  *	This routine actually executes the scanf from the window.
1374fc3d3f8Sarnold  */
1383b434c12Selan int
vwscanw(win,fmt,ap)1390d0e39deSelan vwscanw(win, fmt, ap)
1404fc3d3f8Sarnold 	WINDOW *win;
14147500aa6Selan 	const char *fmt;
142200347d8Sbostic 	va_list ap;
14347500aa6Selan {
14447500aa6Selan 
1453ae5d7deSbostic 	char buf[1024];
1464fc3d3f8Sarnold 
1472989bfcaSbostic 	return (wgetstr(win, buf) == OK ?
1482989bfcaSbostic 	    vsscanf(buf, fmt, ap) : ERR);
1494fc3d3f8Sarnold }
150