xref: /titanic_41/usr/src/ucblib/libcurses/scanw.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*LINTLIBRARY*/
18 
19 #ifndef lint
20 static char
21 sccsid[] = "@(#)scanw.c 1.8 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
22 #endif	/* not lint */
23 
24 #include	<stdarg.h>
25 #include	<string.h>
26 
27 /*
28  * scanw and friends
29  */
30 
31 #include	"curses.ext"
32 
33 /*
34  *	This routine implements a scanf on the standard screen.
35  */
36 
37 int
scanw(char * fmt,...)38 scanw(char *fmt, ...)
39 {	int j;
40 	va_list ap;
41 
42 	va_start(ap, fmt);
43 	j = _sscans(stdscr, fmt, ap);
44 	va_end(ap);
45 	return (j);
46 }
47 
48 /*
49  *	This routine implements a scanf on the given window.
50  */
51 
52 int
wscanw(WINDOW * win,char * fmt,...)53 wscanw(WINDOW *win, char *fmt, ...)
54 {
55 	va_list ap;
56 	int j;
57 
58 	va_start(ap, fmt);
59 	j = _sscans(win, fmt, ap);
60 	va_end(ap);
61 	return (j);
62 }
63 /*
64  *	This routine actually executes the scanf from the window.
65  *
66  *	This is really a modified version of "sscanf".  As such,
67  * it assumes that sscanf interfaces with the other scanf functions
68  * in a certain way.  If this is not how your system works, you
69  * will have to modify this routine to use the interface that your
70  * "sscanf" uses.
71  */
72 
73 int
_sscans(WINDOW * win,char * fmt,va_list ap)74 _sscans(WINDOW *win, char *fmt, va_list	ap)
75 {
76 	char	buf[100];
77 	FILE	junk;
78 
79 	junk._flag = _IOREAD|_IOWRT;
80 	junk._base = junk._ptr = (unsigned char *)buf;
81 	if (wgetstr(win, buf) == ERR)
82 		return (ERR);
83 	junk._cnt = (ssize_t)strlen(buf);
84 	return (_doscan(&junk, fmt, ap));
85 }
86