]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_scanw.3x
f51d39b431a11bbe8e020b33494fac9a8145f36f
[ncurses.git] / man / curs_scanw.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 Thomas E. Dickey                                *
3 .\" Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_scanw.3x,v 1.41 2023/10/07 21:19:07 tom Exp $
31 .TH curs_scanw 3X 2023-10-07 "ncurses 6.4" "Library calls"
32 .ie \n(.g \{\
33 .ds `` \(lq
34 .ds '' \(rq
35 .\}
36 .el \{\
37 .ie t .ds `` ``
38 .el   .ds `` ""
39 .ie t .ds '' ''
40 .el   .ds '' ""
41 .\}
42 .
43 .de bP
44 .ie n  .IP \(bu 4
45 .el    .IP \(bu 2
46 ..
47 .SH NAME
48 \fB\%scanw\fP,
49 \fB\%wscanw\fP,
50 \fB\%mvscanw\fP,
51 \fB\%mvwscanw\fP,
52 \fB\%vwscanw\fP,
53 \fB\%vw_scanw\fP \-
54 read formatted input from a \fIcurses\fR window
55 .SH SYNOPSIS
56 .nf
57 \fB#include <curses.h>
58 .PP
59 \fBint scanw(const char *\fIfmt\fP, ...);
60 \fBint wscanw(WINDOW *\fIwin\fP, const char *\fIfmt\fP, ...);
61 \fBint mvscanw(int \fIy\fP, int \fIx\fP, const char *\fIfmt\fP, ...);
62 \fBint mvwscanw(WINDOW *\fIwin\fP, int \fIy\fP, int \fIx\fP, const char *\fIfmt\fP, ...);
63 .PP
64 \fBint vw_scanw(WINDOW *\fIwin\fP, const char *\fIfmt\fP, va_list \fIvarglist\fP);
65 .PP
66 \fI/* obsolete */\fP
67 \fBint vwscanw(WINDOW *\fIwin\fP, const char *\fIfmt\fP, va_list \fIvarglist\fP);
68 .fi
69 .SH DESCRIPTION
70 The \fBscanw\fP, \fBwscanw\fP and \fBmvscanw\fP routines are analogous to
71 \fBscanf\fP [see \fBscanf\fP(3)].
72 The effect of these routines is as though
73 \fBwgetstr\fP were called on the window, and the resulting line used as input
74 for \fBsscanf\fP(3).
75 Fields which do not map to a variable in the \fIfmt\fP
76 field are lost.
77 .PP
78 The \fBvwscanw\fP and \fBvw_scanw\fP routines are analogous to \fBvscanf\fP(3).
79 They perform a \fBwscanw\fP using a variable argument list.
80 The third argument is a \fBva_list\fP,
81 a pointer to a list of arguments, as defined in \fB<stdarg.h>\fP.
82 .SH RETURN VALUE
83 \fBvwscanw\fP returns \fBERR\fP on failure and an integer equal to the
84 number of fields scanned on success.
85 .PP
86 Applications may use the return value from the \fBscanw\fP, \fBwscanw\fP,
87 \fBmvscanw\fP and \fBmvwscanw\fP routines to determine the number of fields
88 which were mapped in the call.
89 .PP
90 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
91 \fBwmove\fP, and return an error if the position is outside the window,
92 or if the window pointer is null.
93 .SH HISTORY
94 While \fBscanw\fP was implemented in 4BSD,
95 none of the BSD releases used it until 4.4BSD (in a game).
96 That early version of curses was before the ANSI C standard.
97 It did not use <varargs.h>, though that was available.
98 In 1991 (a couple of years after SVr4 was generally available,
99 and after the C standard was published),
100 other developers updated the library,
101 using <stdarg.h> internally in 4.4BSD curses.
102 Even with this improvement,
103 BSD curses did not use function prototypes (or even declare
104 functions) in the <curses.h> header until 1992.
105 .PP
106 SVr2 documented
107 \fBscanw\fP,
108 \fBwscanw\fP
109 tersely as \*(``scanf through \fIstdscr\fP\*('' and
110 tersely as \*(``scanf through \fIwin\fP\*('', respectively.
111 .PP
112 SVr3 added
113 \fBmvscanw\fP, and
114 \fBmvwscanw\fP, with a three-line summary saying that they were analogous
115 to \fBscanf\fP(3),
116 explaining that the string which would be output from \fBscanf\fP(3) would
117 instead be output using \fBwaddstr\fP on the given window.
118 SVr3 also added \fBvwscanw\fP, saying that the third parameter
119 is a \fBva_list\fP, defined in <varargs.h>,
120 and referring the reader to the manual pages for \fIvarargs\fP and
121 \fBvprintf\fP for detailed descriptions.
122 (Because the SVr3 documentation does not mention \fBvscanf\fP,
123 that reference to \fBvprintf\fP may not be an error).
124 .PP
125 SVr4 added no new variations of \fBscanw\fP,
126 but provided for using <varargs.h> or <stdarg.h> to define the \fBva_list\fP
127 type.
128 .PP
129 X/Open Curses added \fBvw_scanw\fP to replace \fBvwscanw\fP,
130 stating that its \fBva_list\fP definition requires <stdarg.h>.
131 .SH PORTABILITY
132 In this implementation, \fBvw_scanw\fP and \fBvwscanw\fP are equivalent,
133 to support legacy applications.
134 However, the latter (\fBvwscanw\fP) is obsolete:
135 .bP
136 The XSI Curses standard, Issue 4 described these functions,
137 noting that the function
138 \fBvwscanw\fP is marked TO BE WITHDRAWN, and is to be replaced by a function
139 \fBvw_scanw\fP using the \fB<stdarg.h>\fP interface.
140 .bP
141 The Single Unix Specification, Version 2 states that
142 \fBvw_scanw\fP  is preferred to \fBvwscanw\fP since the latter requires
143 including \fB<varargs.h>\fP, which
144 cannot be used in the same file as \fB<stdarg.h>\fP.
145 This implementation uses \fB<stdarg.h>\fP for both, because that header
146 is included in \fB<curses.h\fP>.
147 .bP
148 X/Open Curses, Issue 5 (December 2007) marked \fBvwscanw\fP (along with
149 \fBvwprintw\fP and the termcap interface) as withdrawn.
150 .LP
151 Both XSI and The Single Unix Specification, Version 2 state that these
152 functions return \fBERR\fP or \fBOK\fP.
153 .bP
154 Since the underlying \fBscanf\fP(3) can return the number of items scanned,
155 and the SVr4 code was documented to use this feature,
156 this is probably an editing error which was introduced in XSI,
157 rather than being done intentionally.
158 .bP
159 This implementation returns the number of items scanned,
160 for compatibility with SVr4 curses.
161 As of 2018, NetBSD curses also returns the number of items scanned.
162 Both ncurses and NetBSD curses call \fBvsscanf\fP to scan the string,
163 which returns \fBEOF\fP on error.
164 .bP
165 Portable applications should only test if the return value is \fBERR\fP,
166 since the \fBOK\fP value (zero) is likely to be misleading.
167 .IP
168 One possible way to get useful results would be to use a "%n" conversion
169 at the end of the format string to ensure that something was processed.
170 .SH SEE ALSO
171 \fB\%curses\fP(3X),
172 \fB\%curs_getstr\fP(3X),
173 \fB\%curs_printw\fP(3X),
174 \fB\%curs_termcap\fP(3X),
175 \fB\%scanf\fP(3)