scanw.c revision 1.21 1 1.21 joerg /* $NetBSD: scanw.c,v 1.21 2011/07/17 20:54:34 joerg Exp $ */
2 1.8 mikel
3 1.1 cgd /*
4 1.7 cgd * Copyright (c) 1981, 1993, 1994
5 1.4 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.18 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.8 mikel #include <sys/cdefs.h>
33 1.1 cgd #ifndef lint
34 1.8 mikel #if 0
35 1.7 cgd static char sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94";
36 1.8 mikel #else
37 1.21 joerg __RCSID("$NetBSD: scanw.c,v 1.21 2011/07/17 20:54:34 joerg Exp $");
38 1.8 mikel #endif
39 1.10 mrg #endif /* not lint */
40 1.1 cgd
41 1.1 cgd /*
42 1.3 mycroft * scanw and friends.
43 1.1 cgd */
44 1.1 cgd
45 1.1 cgd #include <stdarg.h>
46 1.7 cgd
47 1.7 cgd #include "curses.h"
48 1.3 mycroft
49 1.1 cgd /*
50 1.3 mycroft * scanw --
51 1.3 mycroft * Implement a scanf on the standard screen.
52 1.1 cgd */
53 1.3 mycroft int
54 1.12 jdc scanw(const char *fmt,...)
55 1.1 cgd {
56 1.1 cgd va_list ap;
57 1.10 mrg int ret;
58 1.1 cgd
59 1.1 cgd va_start(ap, fmt);
60 1.20 joerg ret = vw_scanw(stdscr, fmt, ap);
61 1.1 cgd va_end(ap);
62 1.3 mycroft return (ret);
63 1.1 cgd }
64 1.1 cgd /*
65 1.3 mycroft * wscanw --
66 1.3 mycroft * Implements a scanf on the given window.
67 1.1 cgd */
68 1.3 mycroft int
69 1.14 blymn wscanw(WINDOW *win, const char *fmt,...)
70 1.1 cgd {
71 1.1 cgd va_list ap;
72 1.10 mrg int ret;
73 1.1 cgd
74 1.1 cgd va_start(ap, fmt);
75 1.20 joerg ret = vw_scanw(win, fmt, ap);
76 1.3 mycroft va_end(ap);
77 1.3 mycroft return (ret);
78 1.3 mycroft }
79 1.3 mycroft /*
80 1.10 mrg * mvscanw, mvwscanw --
81 1.3 mycroft * Implement the mvscanw commands. Due to the variable number of
82 1.3 mycroft * arguments, they cannot be macros. Another sigh....
83 1.3 mycroft */
84 1.3 mycroft int
85 1.12 jdc mvscanw(int y, int x, const char *fmt,...)
86 1.3 mycroft {
87 1.3 mycroft va_list ap;
88 1.10 mrg int ret;
89 1.3 mycroft
90 1.3 mycroft if (move(y, x) != OK)
91 1.3 mycroft return (ERR);
92 1.3 mycroft va_start(ap, fmt);
93 1.20 joerg ret = vw_scanw(stdscr, fmt, ap);
94 1.3 mycroft va_end(ap);
95 1.3 mycroft return (ret);
96 1.3 mycroft }
97 1.3 mycroft
98 1.3 mycroft int
99 1.13 simonb mvwscanw(WINDOW * win, int y, int x, const char *fmt,...)
100 1.3 mycroft {
101 1.3 mycroft va_list ap;
102 1.10 mrg int ret;
103 1.3 mycroft
104 1.3 mycroft if (move(y, x) != OK)
105 1.3 mycroft return (ERR);
106 1.3 mycroft va_start(ap, fmt);
107 1.20 joerg ret = vw_scanw(win, fmt, ap);
108 1.1 cgd va_end(ap);
109 1.3 mycroft return (ret);
110 1.1 cgd }
111 1.1 cgd /*
112 1.4 cgd * vwscanw --
113 1.1 cgd * This routine actually executes the scanf from the window.
114 1.1 cgd */
115 1.4 cgd int
116 1.21 joerg vw_scanw(WINDOW *win, const char *fmt, va_list ap)
117 1.1 cgd {
118 1.3 mycroft
119 1.10 mrg char buf[1024];
120 1.1 cgd
121 1.19 blymn return (wgetnstr(win, buf, (int) sizeof(buf)) == OK ?
122 1.4 cgd vsscanf(buf, fmt, ap) : ERR);
123 1.1 cgd }
124 1.20 joerg
125 1.20 joerg __strong_alias(vwscanw, vw_scanw)
126