]> ncurses.scripts.mit.edu Git - ncurses.git/blob - doc/html/man/curs_getstr.3x.html
ncurses 6.2 - patch 20201017
[ncurses.git] / doc / html / man / curs_getstr.3x.html
1 <!-- 
2   ****************************************************************************
3   * Copyright 2018-2019,2020 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_getstr.3x,v 1.31 2020/10/18 00:27:44 tom Exp @
31   * X/Open says also until EOf
32   * X/Open says then an EOS is added to the result
33   * X/Open doesn't mention n&lt;0
34 -->
35 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
36 <HTML>
37 <HEAD>
38 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
39 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
40 <TITLE>curs_getstr 3x</TITLE>
41 <link rel="author" href="mailto:bug-ncurses@gnu.org">
42 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
43 </HEAD>
44 <BODY>
45 <H1 class="no-header">curs_getstr 3x</H1>
46 <PRE>
47 <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>                                                <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
48
49
50
51
52 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
53        <STRONG>getstr</STRONG>, <STRONG>getnstr</STRONG>, <STRONG>wgetstr</STRONG>, <STRONG>wgetnstr</STRONG>, <STRONG>mvgetstr</STRONG>, <STRONG>mvgetnstr</STRONG>, <STRONG>mvwgetstr</STRONG>,
54        <STRONG>mvwgetnstr</STRONG> - accept character strings from <STRONG>curses</STRONG> terminal keyboard
55
56
57 </PRE><H2><a name="h2-SYNOPSIS">SYNOPSIS</a></H2><PRE>
58        <STRONG>#include</STRONG> <STRONG>&lt;curses.h&gt;</STRONG>
59
60        <STRONG>int</STRONG> <STRONG>getstr(char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
61        <STRONG>int</STRONG> <STRONG>getnstr(char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
62        <STRONG>int</STRONG> <STRONG>wgetstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
63        <STRONG>int</STRONG> <STRONG>wgetnstr(WINDOW</STRONG> <STRONG>*</STRONG><EM>win</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
64
65        <STRONG>int</STRONG> <STRONG>mvgetstr(int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
66        <STRONG>int</STRONG> <STRONG>mvwgetstr(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>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>);</STRONG>
67        <STRONG>int</STRONG> <STRONG>mvgetnstr(int</STRONG> <EM>y</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>x</EM><STRONG>,</STRONG> <STRONG>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
68        <STRONG>int</STRONG> <STRONG>mvwgetnstr(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>char</STRONG> <STRONG>*</STRONG><EM>str</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>n</EM><STRONG>);</STRONG>
69
70
71 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
72        The function <STRONG>getstr</STRONG> is equivalent to a series of calls to <STRONG>getch</STRONG>,  until
73        a  newline or carriage return is received (the terminating character is
74        not included in the returned string).  The resulting value is placed in
75        the area pointed to by the character pointer <EM>str</EM>, followed by a NUL.
76
77        <STRONG>wgetnstr</STRONG>  reads  at most <EM>n</EM> characters, thus preventing a possible over-
78        flow of the input buffer.  Any attempt to enter more characters  (other
79        than  the terminating newline or carriage return) causes a beep.  Func-
80        tion keys also cause a beep and  are  ignored.   The  <STRONG>getnstr</STRONG>  function
81        reads from the <EM>stdscr</EM> default window.
82
83        The  user's  erase and kill characters are interpreted.  If keypad mode
84        is on for the window, <STRONG>KEY_LEFT</STRONG> and <STRONG>KEY_BACKSPACE</STRONG>  are  both  considered
85        equivalent to the user's kill character.
86
87        Characters  input  are  echoed  only  if <STRONG>echo</STRONG> is currently on.  In that
88        case, backspace is echoed as deletion of the previous character  (typi-
89        cally a left motion).
90
91
92 </PRE><H2><a name="h2-RETURN-VALUE">RETURN VALUE</a></H2><PRE>
93        All routines return the integer <STRONG>ERR</STRONG> upon failure and an <STRONG>OK</STRONG> (SVr4 speci-
94        fies only "an integer value other than <STRONG>ERR</STRONG>")  upon  successful  comple-
95        tion.
96
97        X/Open defines no error conditions.
98
99        In  this  implementation, these functions return an error if the window
100        pointer is null, or if its timeout expires without having any data.
101
102        This implementation provides an extension as well.  If a  <STRONG>SIGWINCH</STRONG>  in-
103        terrupts the function, it will return <STRONG>KEY_RESIZE</STRONG> rather than <STRONG>OK</STRONG> or <STRONG>ERR</STRONG>.
104
105        Functions  with  a  "mv"  prefix  first perform a cursor movement using
106        <STRONG>wmove</STRONG>, and return an error if the position is outside the window, or if
107        the window pointer is null.
108
109
110 </PRE><H2><a name="h2-NOTES">NOTES</a></H2><PRE>
111        Note that <STRONG>getstr</STRONG>, <STRONG>mvgetstr</STRONG>, and <STRONG>mvwgetstr</STRONG> may be macros.
112
113
114 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
115        These  functions  are  described  in  the XSI Curses standard, Issue 4.
116        They read single-byte characters only.  The standard  does  not  define
117        any  error  conditions.   This implementation returns <STRONG>ERR</STRONG> if the window
118        pointer is null, or if the lower-level <STRONG><A HREF="curs_getch.3x.html">wgetch(3x)</A></STRONG> call returns an <STRONG>ERR</STRONG>.
119
120        SVr3 and early SVr4 curses  implementations  did  not  reject  function
121        keys;  the  SVr4.0  documentation  claimed that "special keys" (such as
122        function keys, "home" key, "clear" key, <EM>etc</EM>.) are "interpreted",  with-
123        out  giving details.  It lied.  In fact, the "character" value appended
124        to the string by those implementations was predictable but  not  useful
125        (being, in fact, the low-order eight bits of the key's KEY_ value).
126
127        The  functions  <STRONG>getnstr</STRONG>, <STRONG>mvgetnstr</STRONG>, and <STRONG>mvwgetnstr</STRONG> were present but not
128        documented in SVr4.
129
130        X/Open Curses, Issue 5 (2007) stated that these functions "read at most
131        <EM>n</EM>  bytes"  but  did not state whether the terminating NUL is counted in
132        that limit.  X/Open Curses, Issue 7 (2009) changed  that  to  say  they
133        "read at most <EM>n</EM>-1 bytes" to allow for the terminating NUL.  As of 2018,
134        some implementations do, some do not count it:
135
136        <STRONG>o</STRONG>   ncurses 6.1 and PDCurses do not count the NUL in the  given  limit,
137            while
138
139        <STRONG>o</STRONG>   Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
140
141        <STRONG>o</STRONG>   Solaris  xcurses  provides  both:  its wide-character <STRONG>wget_nstr</STRONG> re-
142            serves a NUL, but its <STRONG>wgetnstr</STRONG> does not count the NUL consistently.
143
144        In SVr4 curses, a negative value of <EM>n</EM> tells <STRONG>wgetnstr</STRONG> to assume that the
145        caller's  buffer  is large enough to hold the result, i.e., to act like
146        <STRONG>wgetstr</STRONG>.  X/Open Curses does not mention this (or anything  related  to
147        negative  or  zero  values  of <EM>n</EM>), however most implementations use the
148        feature, with different limits:
149
150        <STRONG>o</STRONG>   Solaris SVr4 curses and PDCurses limit the  result  to  255  bytes.
151            Other Unix systems than Solaris are likely to use the same limit.
152
153        <STRONG>o</STRONG>   Solaris xcurses limits the result to <STRONG>LINE_MAX</STRONG> bytes.
154
155        <STRONG>o</STRONG>   NetBSD  7  assumes no particular limit for the result from <STRONG>wgetstr</STRONG>.
156            However, it limits the <STRONG>wgetnstr</STRONG> parameter <EM>n</EM> to ensure  that  it  is
157            greater than zero.
158
159            A  comment in NetBSD's source code states that this is specified in
160            SUSv2.
161
162        <STRONG>o</STRONG>   ncurses (before 6.2) assumes no particular  limit  for  the  result
163            from  <STRONG>wgetstr</STRONG>,  and  treats  the  <EM>n</EM> parameter of <STRONG>wgetnstr</STRONG> like SVr4
164            curses.
165
166        <STRONG>o</STRONG>   ncurses 6.2 uses <STRONG>LINE_MAX</STRONG>, or  a  larger  (system-dependent)  value
167            which  the  <STRONG>sysconf</STRONG>  function  may provide.  If neither <STRONG>LINE_MAX</STRONG> or
168            <STRONG>sysconf</STRONG> is available, ncurses uses the POSIX value for <STRONG>LINE_MAX</STRONG>  (a
169            2048  byte limit).  In either case, it reserves a byte for the ter-
170            minating NUL.
171
172
173 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
174        <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_getch.3x.html">curs_getch(3x)</A></STRONG>, <STRONG><A HREF="curs_variables.3x.html">curs_variables(3x)</A></STRONG>.
175
176
177
178                                                                <STRONG><A HREF="curs_getstr.3x.html">curs_getstr(3x)</A></STRONG>
179 </PRE>
180 <div class="nav">
181 <ul>
182 <li><a href="#h2-NAME">NAME</a></li>
183 <li><a href="#h2-SYNOPSIS">SYNOPSIS</a></li>
184 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a></li>
185 <li><a href="#h2-RETURN-VALUE">RETURN VALUE</a></li>
186 <li><a href="#h2-NOTES">NOTES</a></li>
187 <li><a href="#h2-PORTABILITY">PORTABILITY</a></li>
188 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>
189 </ul>
190 </div>
191 </BODY>
192 </HTML>