]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_scanw.c
b05bfde153af5621de51211f55576372b64d678c
[ncurses.git] / ncurses / base / lib_scanw.c
1 /****************************************************************************
2  * Copyright (c) 1998-2011,2018 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 **      lib_scanw.c
36 **
37 **      The routines scanw(), wscanw() and friends.
38 **
39 */
40
41 #include <curses.priv.h>
42
43 MODULE_ID("$Id: lib_scanw.c,v 1.17 2018/06/09 20:19:20 tom Exp $")
44
45 NCURSES_EXPORT(int)
46 vwscanw(WINDOW *win, const char *fmt, va_list argp)
47 {
48     char buf[BUFSIZ];
49     int code = ERR;
50
51     if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
52         if ((code = vsscanf(buf, fmt, argp)) == EOF) {
53             code = ERR;
54         }
55     }
56
57     return code;
58 }
59
60 NCURSES_EXPORT(int)
61 vw_scanw(WINDOW *win, const char *fmt, va_list argp)
62 {
63     char buf[BUFSIZ];
64     int code = ERR;
65
66     if (wgetnstr(win, buf, (int) sizeof(buf) - 1) != ERR) {
67         if ((code = vsscanf(buf, fmt, argp)) == EOF) {
68             code = ERR;
69         }
70     }
71
72     return code;
73 }
74
75 NCURSES_EXPORT(int)
76 scanw(const char *fmt,...)
77 {
78     int code;
79     va_list ap;
80
81     T(("scanw(\"%s\",...) called", fmt));
82
83     va_start(ap, fmt);
84     code = vw_scanw(stdscr, fmt, ap);
85     va_end(ap);
86     return (code);
87 }
88
89 NCURSES_EXPORT(int)
90 wscanw(WINDOW *win, const char *fmt,...)
91 {
92     int code;
93     va_list ap;
94
95     T(("wscanw(%p,\"%s\",...) called", (void *) win, fmt));
96
97     va_start(ap, fmt);
98     code = vw_scanw(win, fmt, ap);
99     va_end(ap);
100     return (code);
101 }
102
103 NCURSES_EXPORT(int)
104 mvscanw(int y, int x, const char *fmt,...)
105 {
106     int code;
107     va_list ap;
108
109     va_start(ap, fmt);
110     code = (move(y, x) == OK) ? vw_scanw(stdscr, fmt, ap) : ERR;
111     va_end(ap);
112     return (code);
113 }
114
115 NCURSES_EXPORT(int)
116 mvwscanw(WINDOW *win, int y, int x, const char *fmt,...)
117 {
118     int code;
119     va_list ap;
120
121     va_start(ap, fmt);
122     code = (wmove(win, y, x) == OK) ? vw_scanw(win, fmt, ap) : ERR;
123     va_end(ap);
124     return (code);
125 }