| 1 |
<!-- |
| 2 |
**************************************************************************** |
| 3 |
* Copyright 2018-2024,2025 Thomas E. Dickey * |
| 4 |
* Copyright 1998-2010,2017 Free Software Foundation, Inc. * |
| 5 |
* * |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a * |
| 7 |
* copy of this software and associated documentation files (the * |
| 8 |
* "Software"), to deal in the Software without restriction, including * |
| 9 |
* without limitation the rights to use, copy, modify, merge, publish, * |
| 10 |
* distribute, distribute with modifications, sublicense, and/or sell * |
| 11 |
* copies of the Software, and to permit persons to whom the Software is * |
| 12 |
* furnished to do so, subject to the following conditions: * |
| 13 |
* * |
| 14 |
* The above copyright notice and this permission notice shall be included * |
| 15 |
* in all copies or substantial portions of the Software. * |
| 16 |
* * |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 19 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 20 |
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 21 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 22 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 23 |
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 24 |
* * |
| 25 |
* Except as contained in this notice, the name(s) of the above copyright * |
| 26 |
* holders shall not be used in advertising or otherwise to promote the * |
| 27 |
* sale, use or other dealings in this Software without prior written * |
| 28 |
* authorization. * |
| 29 |
**************************************************************************** |
| 30 |
* @Id: curs_scanw.3x,v 1.62 2025/07/05 13:03:05 tom Exp @ |
| 31 |
--> |
| 32 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> |
| 33 |
<HTML> |
| 34 |
<HEAD> |
| 35 |
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> |
| 36 |
<meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts"> |
| 37 |
<TITLE>curs_scanw 3x 2025-07-05 ncurses 6.6 Library calls</TITLE> |
| 38 |
<link rel="author" href="mailto:[email protected]"> |
| 39 |
|
| 40 |
</HEAD> |
| 41 |
<BODY> |
| 42 |
<H1 class="no-header">curs_scanw 3x 2025-07-05 ncurses 6.6 Library calls</H1> |
| 43 |
<PRE> |
| 44 |
<STRONG><A HREF="curs_scanw.3x.html">curs_scanw(3x)</A></STRONG> Library calls <STRONG><A HREF="curs_scanw.3x.html">curs_scanw(3x)</A></STRONG> |
| 45 |
|
| 46 |
|
| 47 |
</PRE><H2><a name="h2-NAME">NAME</a></H2><PRE> |
| 48 |
<STRONG>scanw</STRONG>, <STRONG>wscanw</STRONG>, <STRONG>mvscanw</STRONG>, <STRONG>mvwscanw</STRONG>, <STRONG>vwscanw</STRONG>, <STRONG>vw_scanw</STRONG> - read formatted |
| 49 |
input from a <EM>curses</EM> window |
| 50 |
|
| 51 |
|
| 52 |
</PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE> |
| 53 |
<STRONG>#include</STRONG> <STRONG><curses.h></STRONG> |
| 54 |
|
| 55 |
<STRONG>int</STRONG> <STRONG>scanw(const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>...);</STRONG> |
| 56 |
<STRONG>int</STRONG> <STRONG>wscanw(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>...);</STRONG> |
| 57 |
<STRONG>int</STRONG> <STRONG>mvscanw(int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>...);</STRONG> |
| 58 |
<STRONG>int</STRONG> <STRONG>mvwscanw(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>...);</STRONG> |
| 59 |
|
| 60 |
<STRONG>int</STRONG> <STRONG>vw_scanw(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>va_list</STRONG> <EM>varglist</EM><STRONG>);</STRONG> |
| 61 |
|
| 62 |
<EM>/*</EM> <EM>obsolete</EM> <EM>*/</EM> |
| 63 |
<STRONG>int</STRONG> <STRONG>vwscanw(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>const</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>fmt</EM><STRONG>,</STRONG> <STRONG>va_list</STRONG> <EM>varglist</EM><STRONG>);</STRONG> |
| 64 |
|
| 65 |
|
| 66 |
</PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE> |
| 67 |
<STRONG>scanw</STRONG>, <STRONG>wscanw</STRONG>, <STRONG>mvscanw</STRONG>, and <STRONG>mvwscanw</STRONG> are analogous to <STRONG>scanf(3)</STRONG>. In |
| 68 |
effect, they call <STRONG><A HREF="curs_getstr.3x.html">wgetstr(3x)</A></STRONG> with <EM>win</EM> (or <STRONG>stdscr</STRONG>) as its first |
| 69 |
argument, then attempt conversion of the resulting string with |
| 70 |
<STRONG>vsscanf(3)</STRONG>. Fields in the string that do not map to a variable in the |
| 71 |
<EM>fmt</EM> parameter are discarded. |
| 72 |
|
| 73 |
<STRONG>vwscanw</STRONG> and <STRONG>vw_scanw</STRONG> are analogous to <STRONG>vscanf(3)</STRONG>, and perform a <STRONG>wscanw</STRONG> |
| 74 |
using a variable argument list. The third argument is a <EM>va</EM><STRONG>_</STRONG><EM>list</EM>, a |
| 75 |
pointer to a list of arguments, as defined in <EM>stdarg.h</EM>. |
| 76 |
|
| 77 |
|
| 78 |
</PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE> |
| 79 |
These functions return <STRONG>ERR</STRONG> upon failure and otherwise a count of |
| 80 |
successful conversions; this quantity may be zero. |
| 81 |
|
| 82 |
In <EM>ncurses</EM>, failure occurs if <STRONG>vsscanf(3)</STRONG> returns <STRONG>EOF</STRONG>, or if the window |
| 83 |
pointer <EM>win</EM> is null. |
| 84 |
|
| 85 |
Functions prefixed with "mv" first perform cursor movement and fail if |
| 86 |
the position (<EM>y</EM>, <EM>x</EM>) is outside the window boundaries. |
| 87 |
|
| 88 |
|
| 89 |
</PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE> |
| 90 |
No wide character counterpart functions are defined by the "wide" |
| 91 |
<EM>ncurses</EM> configuration nor by any standard. They are unnecessary: to |
| 92 |
retrieve and convert a wide-character string from a <EM>curses</EM> terminal |
| 93 |
keyboard, use these functions with the <STRONG>scanf(3)</STRONG> conversions "%lc" and |
| 94 |
"%ls" for wide characters and strings, respectively. |
| 95 |
|
| 96 |
<EM>ncurses</EM> implements <STRONG>vsscanf(3)</STRONG> internally if it is unavailable when the |
| 97 |
library is configured. |
| 98 |
|
| 99 |
|
| 100 |
</PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE> |
| 101 |
X/Open Curses Issue 4 describes these functions. It specifies no error |
| 102 |
conditions for them. |
| 103 |
|
| 104 |
<EM>ncurses</EM> defines <STRONG>vw_scanw</STRONG> and <STRONG>vwscanw</STRONG> identically to support legacy |
| 105 |
applications. However, the latter is obsolete. |
| 106 |
|
| 107 |
<STRONG>o</STRONG> X/Open Curses Issue 4 Version 2 (1996), marked <STRONG>vwscanw</STRONG> as requiring |
| 108 |
<EM>varargs.h</EM> and "TO BE WITHDRAWN", and specified <STRONG>vw_scanw</STRONG> using the |
| 109 |
<EM>stdarg.h</EM> interface. |
| 110 |
|
| 111 |
<STRONG>o</STRONG> X/Open Curses Issue 5, Draft 2 (December 2007) marked <STRONG>vwscanw</STRONG> |
| 112 |
(along with <STRONG>vwscanw</STRONG> and the <EM>termcap</EM> interface) as withdrawn. After |
| 113 |
incorporating review comments, this became X/Open Curses Issue 7 |
| 114 |
(2009). |
| 115 |
|
| 116 |
<STRONG>o</STRONG> <EM>ncurses</EM> provides <STRONG>vwscanw</STRONG>, but marks it as deprecated. |
| 117 |
|
| 118 |
X/Open Curses Issues 4 and 7 both state that these functions return <STRONG>ERR</STRONG> |
| 119 |
or <STRONG>OK</STRONG>. This is likely an erratum. |
| 120 |
|
| 121 |
<STRONG>o</STRONG> Since the underlying <STRONG>scanf(3)</STRONG> returns the number of successful |
| 122 |
conversions, and SVr4 <EM>curses</EM> was documented to use this feature, |
| 123 |
this may have been an editorial solecism introduced by X/Open, |
| 124 |
rather than an intentional change. |
| 125 |
|
| 126 |
<STRONG>o</STRONG> This implementation retains compatibility with SVr4 <EM>curses</EM>. As of |
| 127 |
2018, NetBSD <EM>curses</EM> also returns the number of successful |
| 128 |
conversions. Both <EM>ncurses</EM> and NetBSD <EM>curses</EM> call <STRONG>vsscanf(3)</STRONG> to |
| 129 |
scan the string, which returns <STRONG>EOF</STRONG> on error. |
| 130 |
|
| 131 |
<STRONG>o</STRONG> Portable applications should test only if the return value is <STRONG>ERR</STRONG>, |
| 132 |
and not compare it to <STRONG>OK</STRONG>, since that value (zero) might be |
| 133 |
misleading. |
| 134 |
|
| 135 |
One portable way to get useful results would be to use a "%n" |
| 136 |
conversion at the end of the format string, and check the value of |
| 137 |
the corresponding variable to determine how many conversions |
| 138 |
succeeded. |
| 139 |
|
| 140 |
|
| 141 |
</PRE><H2><a name="h2-HISTORY">HISTORY</a></H2><PRE> |
| 142 |
4BSD (1980) introduced <EM>wscanw</EM> and its variants. It implemented all as |
| 143 |
functions, not macros; this initial distribution of <EM>curses</EM> preceded the |
| 144 |
ANSI C standard of 1989, prior to which a variadic macro facility was |
| 145 |
not widely available. <EM>scanw</EM> went unused in Berkeley distributions |
| 146 |
until 4.3BSD-Reno (1990), which employed it in a game. 4BSD's <EM>wscanw</EM> |
| 147 |
did not use <EM>varargs.h</EM>, which had been available since Seventh Edition |
| 148 |
Unix (1979). In 1991 (a couple of years after SVr4 was generally |
| 149 |
available, and after the C standard was published), other developers |
| 150 |
updated the library, using <EM>stdarg.h</EM> internally in 4.4BSD <EM>curses</EM>. Even |
| 151 |
with this improvement, BSD <EM>curses</EM> did not use function prototypes (nor |
| 152 |
even declare functions) in <EM>curses.h</EM> until 1992. |
| 153 |
|
| 154 |
4BSD documented <EM>scanw</EM> and <EM>wscanw</EM> tersely as "scanf through <EM>stdscr</EM>" and |
| 155 |
"scanf through <EM>win</EM>", respectively. SVr3 (1987) stated |
| 156 |
|
| 157 |
[t]hese routines correspond to <STRONG>scanf(3S)</STRONG>, as do their arguments |
| 158 |
and return values. <EM>wgetstr</EM>() is called on the window, and the |
| 159 |
resulting line is used as input for the scan. |
| 160 |
|
| 161 |
SVr3 added <EM>vwscanw</EM>, describing its third parameter as a <EM>va</EM><STRONG>_</STRONG><EM>list</EM>, |
| 162 |
defined in <EM>varargs.h</EM>, and referred the reader to the manual pages for |
| 163 |
<EM>varargs</EM> and <EM>vprintf</EM> for detailed descriptions. (Because SVr3 |
| 164 |
documentation does not mention <EM>vscanf</EM>, the reference to <EM>vprintf</EM> might |
| 165 |
not be an error). |
| 166 |
|
| 167 |
SVr4 (1989) introduced no new variations of <EM>scanw</EM>, but provided for |
| 168 |
using either <EM>varargs.h</EM> or <EM>stdarg.h</EM> to define the <EM>va</EM><STRONG>_</STRONG><EM>list</EM> type. |
| 169 |
|
| 170 |
X/Open Curses Issue 4 (1995) defined <EM>vw</EM><STRONG>_</STRONG><EM>scanw</EM> to replace <EM>vwscanw</EM>, |
| 171 |
stating that its <EM>va</EM><STRONG>_</STRONG><EM>list</EM> type is defined in <EM>stdarg.h</EM>. |
| 172 |
|
| 173 |
|
| 174 |
</PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE> |
| 175 |
<STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>, <STRONG><A HREF="curs_printw.3x.html">curs_printw(3x)</A></STRONG>, <STRONG>scanf(3)</STRONG>, <STRONG>vscanf(3)</STRONG> |
| 176 |
|
| 177 |
ncurses 6.6 2025-07-05 <STRONG><A HREF="curs_scanw.3x.html">curs_scanw(3x)</A></STRONG> |
| 178 |
</PRE> |
| 179 |
<div class="nav"> |
| 180 |
<ul> |
| 181 |
<li><a href="#h2-NAME">NAME</a></li> |
| 182 |
<li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li> |
| 183 |
<li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li> |
| 184 |
<li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li> |
| 185 |
<li><a href="#h2-NOTES">NOTES</a></li> |
| 186 |
<li><a href="#h2-PORTABILITY">PORTABILITY</a></li> |
| 187 |
<li><a href="#h2-HISTORY">HISTORY</a></li> |
| 188 |
<li><a href="#h2-SEE-ALSO">SEE ALSO</a></li> |
| 189 |
</ul> |
| 190 |
</div> |
| 191 |
</BODY> |
| 192 |
</HTML> |