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