]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_scanw.3x
ncurses 6.4 - patch 20231125
[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.43 2023/11/25 11:31:06 tom Exp $
31 .TH curs_scanw 3X 2023-11-25 "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 PORTABILITY
94 In this implementation, \fBvw_scanw\fP and \fBvwscanw\fP are equivalent,
95 to support legacy applications.
96 However, the latter (\fBvwscanw\fP) is obsolete:
97 .bP
98 The XSI Curses standard, Issue 4 described these functions,
99 noting that the function
100 \fBvwscanw\fP is marked TO BE WITHDRAWN, and is to be replaced by a function
101 \fBvw_scanw\fP using the \fB<stdarg.h>\fP interface.
102 .bP
103 The Single Unix Specification, Version 2 states that
104 \fBvw_scanw\fP  is preferred to \fBvwscanw\fP since the latter requires
105 including \fB<varargs.h>\fP, which
106 cannot be used in the same file as \fB<stdarg.h>\fP.
107 This implementation uses \fB<stdarg.h>\fP for both, because that header
108 is included in \fB<curses.h\fP>.
109 .bP
110 X/Open Curses, Issue 5 (December 2007) marked \fBvwscanw\fP (along with
111 \fBvwprintw\fP and the termcap interface) as withdrawn.
112 .LP
113 Both XSI and The Single Unix Specification, Version 2 state that these
114 functions return \fBERR\fP or \fBOK\fP.
115 .bP
116 Since the underlying \fBscanf\fP(3) can return the number of items scanned,
117 and the SVr4 code was documented to use this feature,
118 this is probably an editing error which was introduced in XSI,
119 rather than being done intentionally.
120 .bP
121 This implementation returns the number of items scanned,
122 for compatibility with SVr4 curses.
123 As of 2018, NetBSD curses also returns the number of items scanned.
124 Both ncurses and NetBSD curses call \fBvsscanf\fP to scan the string,
125 which returns \fBEOF\fP on error.
126 .bP
127 Portable applications should only test if the return value is \fBERR\fP,
128 since the \fBOK\fP value (zero) is likely to be misleading.
129 .IP
130 One possible way to get useful results would be to use a "%n" conversion
131 at the end of the format string to ensure that something was processed.
132 .SH HISTORY
133 While \fBscanw\fP was implemented in 4BSD,
134 none of the BSD releases used it until 4.4BSD (in a game).
135 That early version of curses was before the ANSI C standard.
136 It did not use <varargs.h>, though that was available.
137 In 1991 (a couple of years after SVr4 was generally available,
138 and after the C standard was published),
139 other developers updated the library,
140 using <stdarg.h> internally in 4.4BSD curses.
141 Even with this improvement,
142 BSD curses did not use function prototypes (or even declare
143 functions) in the <curses.h> header until 1992.
144 .PP
145 SVr2 documented
146 \fBscanw\fP,
147 \fBwscanw\fP
148 tersely as \*(``scanf through \fIstdscr\fP\*('' and
149 tersely as \*(``scanf through \fIwin\fP\*('', respectively.
150 .PP
151 SVr3 added
152 \fBmvscanw\fP, and
153 \fBmvwscanw\fP, with a three-line summary saying that they were analogous
154 to \fBscanf\fP(3),
155 explaining that the string which would be output from \fBscanf\fP(3) would
156 instead be output using \fBwaddstr\fP on the given window.
157 SVr3 also added \fBvwscanw\fP, saying that the third parameter
158 is a \fBva_list\fP, defined in <varargs.h>,
159 and referring the reader to the manual pages for \fIvarargs\fP and
160 \fBvprintf\fP for detailed descriptions.
161 (Because the SVr3 documentation does not mention \fBvscanf\fP,
162 that reference to \fBvprintf\fP may not be an error).
163 .PP
164 SVr4 added no new variations of \fBscanw\fP,
165 but provided for using <varargs.h> or <stdarg.h> to define the \fBva_list\fP
166 type.
167 .PP
168 X/Open Curses added \fBvw_scanw\fP to replace \fBvwscanw\fP,
169 stating that its \fBva_list\fP definition requires <stdarg.h>.
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)