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 /*LINTLIBRARY*/
16
17 #ifndef lint
18 static char
19 sccsid[] = "@(#)scanw.c 1.8 88/02/08 SMI"; /* from UCB 5.1 85/06/07 */
20 #endif /* not lint */
21
22 #include <stdarg.h>
23 #include <string.h>
24
25 /*
26 * scanw and friends
27 */
28
29 #include "curses.ext"
30
31 /*
32 * This routine implements a scanf on the standard screen.
33 */
34
35 int
scanw(char * fmt,...)36 scanw(char *fmt, ...)
37 { int j;
38 va_list ap;
39
40 va_start(ap, fmt);
41 j = _sscans(stdscr, fmt, ap);
42 va_end(ap);
43 return (j);
44 }
45
46 /*
47 * This routine implements a scanf on the given window.
48 */
49
50 int
wscanw(WINDOW * win,char * fmt,...)51 wscanw(WINDOW *win, char *fmt, ...)
52 {
53 va_list ap;
54 int j;
55
56 va_start(ap, fmt);
57 j = _sscans(win, fmt, ap);
58 va_end(ap);
59 return (j);
60 }
61 /*
62 * This routine actually executes the scanf from the window.
63 *
64 * This is really a modified version of "sscanf". As such,
65 * it assumes that sscanf interfaces with the other scanf functions
66 * in a certain way. If this is not how your system works, you
67 * will have to modify this routine to use the interface that your
68 * "sscanf" uses.
69 */
70
71 int
_sscans(WINDOW * win,char * fmt,va_list ap)72 _sscans(WINDOW *win, char *fmt, va_list ap)
73 {
74 char buf[100];
75 FILE junk;
76
77 junk._flag = _IOREAD|_IOWRT;
78 junk._base = junk._ptr = (unsigned char *)buf;
79 if (wgetstr(win, buf) == ERR)
80 return (ERR);
81 junk._cnt = (ssize_t)strlen(buf);
82 return (_doscan(&junk, fmt, ap));
83 }
84