]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_scanw.3x
ncurses 6.2 - patch 20201205
[ncurses.git] / man / curs_scanw.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 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.28 2020/10/24 09:29:26 tom Exp $
31 .TH curs_scanw 3X ""
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .SH NAME
41 \fBscanw\fR,
42 \fBwscanw\fR,
43 \fBmvscanw\fR,
44 \fBmvwscanw\fR,
45 \fBvwscanw\fR, \fBvw_scanw\fR \- convert formatted input from a \fBcurses\fR window
46 .SH SYNOPSIS
47 \fB#include <curses.h>\fR
48 .sp
49 \fBint scanw(const char *\fP\fIfmt\fP\fB, ...);\fR
50 .br
51 \fBint wscanw(WINDOW *\fP\fIwin\fP\fB, const char *\fP\fIfmt\fP\fB, ...);\fR
52 .br
53 \fBint mvscanw(int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, const char *\fP\fIfmt\fP\fB, ...);\fR
54 .br
55 \fBint mvwscanw(WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, const char *\fP\fIfmt\fP\fB, ...);\fR
56 .sp
57 \fBint vw_scanw(WINDOW *\fP\fIwin\fP\fB, const char *\fP\fIfmt\fP\fB, va_list \fP\fIvarglist\fP\fB);\fR
58 .sp
59 /* obsolete */
60 .br
61 \fBint vwscanw(WINDOW *\fP\fIwin\fP\fB, const char *\fP\fIfmt\fP\fB, va_list \fP\fIvarglist\fP\fB);\fR
62 .SH DESCRIPTION
63 The \fBscanw\fR, \fBwscanw\fR and \fBmvscanw\fR routines are analogous to
64 \fBscanf\fR [see \fBscanf\fR(3)].
65 The effect of these routines is as though
66 \fBwgetstr\fR were called on the window, and the resulting line used as input
67 for \fBsscanf\fR(3).
68 Fields which do not map to a variable in the \fIfmt\fR
69 field are lost.
70 .PP
71 The \fBvwscanw\fR and \fBvw_scanw\fR routines are analogous to \fBvscanf\fR(3).
72 They perform a \fBwscanw\fR using a variable argument list.
73 The third argument is a \fIva_list\fR,
74 a pointer to a list of arguments, as defined in \fB<stdarg.h>\fR.
75 .SH RETURN VALUE
76 \fBvwscanw\fR returns \fBERR\fR on failure and an integer equal to the
77 number of fields scanned on success.
78 .PP
79 Applications may use the return value from the \fBscanw\fR, \fBwscanw\fR,
80 \fBmvscanw\fR and \fBmvwscanw\fR routines to determine the number of fields
81 which were mapped in the call.
82 .PP
83 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
84 \fBwmove\fP, and return an error if the position is outside the window,
85 or if the window pointer is null.
86 .SH HISTORY
87 While \fBscanw\fP was implemented in 4BSD,
88 none of the BSD releases used it until 4.4BSD (in a game).
89 That early version of curses was before the ANSI C standard.
90 It did not use <varargs.h>, though that was available.
91 In 1991 (a couple of years after SVr4 was generally available,
92 and after the C standard was published),
93 other developers updated the library,
94 using <stdarg.h> internally in 4.4BSD curses.
95 Even with this improvement,
96 BSD curses did not use function prototypes (or even declare
97 functions) in the <curses.h> header until 1992.
98 .PP
99 SVr2 documented
100 \fBscanw\fP,
101 \fBwscanw\fP
102 tersely as \*(``scanf through \fIstdscr\fP\*('' and
103 tersely as \*(``scanf through \fIwin\fP\*('', respectively.
104 .PP
105 SVr3 added
106 \fBmvscanw\fP, and
107 \fBmvwscanw\fP, with a three-line summary saying that they were analogous
108 to \fBscanf\fP(3),
109 explaining that the string which would be output from \fBscanf\fP(3) would
110 instead be output using \fBwaddstr\fP on the given window.
111 SVr3 also added \fBvwscanw\fP, saying that the third parameter
112 is a \fBva_list\fP, defined in <varargs.h>,
113 and referring the reader to the manual pages for \fIvarargs\fP and
114 \fIvprintf\fP for detailed descriptions.
115 (Because the SVr3 documentation does not mention \fIvscanf\fP,
116 that reference to \fIvprintf\fP may not be an error).
117 .PP
118 SVr4 added no new variations of \fBscanw\fP,
119 but provided for using <varargs.h> or <stdarg.h> to define the \fBva_list\fP
120 type.
121 .PP
122 X/Open Curses added \fBvw_scanw\fP to replace \fBvwscanw\fP,
123 stating that its \fBva_list\fP definition requires <stdarg.h>.
124 .SH PORTABILITY
125 In this implementation, \fBvw_scanw\fP and \fBvwscanw\fP are equivalent,
126 to support legacy applications.
127 However, the latter (\fBvwscanw\fP) is obsolete:
128 .bP
129 The XSI Curses standard, Issue 4 described these functions,
130 noting that the function
131 \fBvwscanw\fR is marked TO BE WITHDRAWN, and is to be replaced by a function
132 \fBvw_scanw\fR using the \fB<stdarg.h>\fR interface.
133 .bP
134 The Single Unix Specification, Version 2 states that
135 \fBvw_scanw\fR  is preferred to \fBvwscanw\fR since the latter requires
136 including \fB<varargs.h>\fR, which
137 cannot be used in the same file as \fB<stdarg.h>\fR.
138 This implementation uses \fB<stdarg.h>\fR for both, because that header
139 is included in \fB<curses.h\fR>.
140 .bP
141 X/Open Curses, Issue 5 (December 2007) marked \fBvwscanw\fP (along with
142 \fBvwprintw\fP and the termcap interface) as withdrawn.
143 .LP
144 Both XSI and The Single Unix Specification, Version 2 state that these
145 functions return \fBERR\fP or \fBOK\fP.
146 .bP
147 Since the underlying \fBscanf\fR(3) can return the number of items scanned,
148 and the SVr4 code was documented to use this feature,
149 this is probably an editing error which was introduced in XSI,
150 rather than being done intentionally.
151 .bP
152 This implementation returns the number of items scanned,
153 for compatibility with SVr4 curses.
154 As of 2018, NetBSD curses also returns the number of items scanned.
155 Both ncurses and NetBSD curses call \fBvsscanf\fP to scan the string,
156 which returns \fBEOF\fP on error.
157 .bP
158 Portable applications should only test if the return value is \fBERR\fP,
159 since the \fBOK\fP value (zero) is likely to be misleading.
160 .IP
161 One possible way to get useful results would be to use a "%n" conversion
162 at the end of the format string to ensure that something was processed.
163 .SH SEE ALSO
164 .na
165 \fBcurses\fR(3X),
166 \fBcurs_getstr\fR(3X),
167 \fBcurs_printw\fR(3X),
168 \fBcurs_termcap\fP(3X),
169 \fBscanf\fR(3).