]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_getstr.3x
ncurses 6.2 - patch 20201031
[ncurses.git] / man / curs_getstr.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_getstr.3x,v 1.31 2020/10/18 00:27:44 tom Exp $
31 .TH curs_getstr 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 .na
41 .hy 0
42 .SH NAME
43 \fBgetstr\fR,
44 \fBgetnstr\fR,
45 \fBwgetstr\fR,
46 \fBwgetnstr\fR,
47 \fBmvgetstr\fR,
48 \fBmvgetnstr\fR,
49 \fBmvwgetstr\fR,
50 \fBmvwgetnstr\fR \- accept character strings from \fBcurses\fR terminal keyboard
51 .ad
52 .hy
53 .SH SYNOPSIS
54 \fB#include <curses.h>\fR
55 .sp
56 \fBint getstr(char *\fP\fIstr\fP\fB);\fR
57 .br
58 \fBint getnstr(char *\fP\fIstr\fP\fB, int \fP\fIn\fP\fB);\fR
59 .br
60 \fBint wgetstr(WINDOW *\fP\fIwin\fP\fB, char *\fP\fIstr\fP\fB);\fR
61 .br
62 \fBint wgetnstr(WINDOW *\fP\fIwin\fP\fB, char *\fP\fIstr\fP\fB, int \fP\fIn\fP\fB);\fR
63 .sp
64 \fBint mvgetstr(int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, char *\fP\fIstr\fP\fB);\fR
65 .br
66 \fBint mvwgetstr(WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, char *\fP\fIstr\fP\fB);\fR
67 .br
68 \fBint mvgetnstr(int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, char *\fP\fIstr\fP\fB, int \fP\fIn\fP\fB);\fR
69 .br
70 \fBint mvwgetnstr(WINDOW *\fP\fIwin\fP\fB, int \fP\fIy\fP\fB, int \fP\fIx\fP\fB, char *\fP\fIstr\fP\fB, int \fP\fIn\fP\fB);\fR
71 .br
72 .SH DESCRIPTION
73 The function \fBgetstr\fR is equivalent to a series of calls to \fBgetch\fR,
74 until a newline or carriage return is received (the terminating character is
75 not included in the returned string).
76 .\" X/Open says also until EOf
77 .\" X/Open says then an EOS is added to the result
78 .\" X/Open doesn't mention n<0
79 The resulting value is placed in the
80 area pointed to by the character pointer \fIstr\fR,
81 followed by a NUL.
82 .PP
83 \fBwgetnstr\fR reads at most \fIn\fR characters, thus preventing a possible
84 overflow of the input buffer.
85 Any attempt to enter more characters (other
86 than the terminating newline or carriage return) causes a beep.
87 Function
88 keys also cause a beep and are ignored.
89 The \fBgetnstr\fR function reads
90 from the \fIstdscr\fR default window.
91 .PP
92 The user's erase and kill characters are interpreted.
93 If keypad
94 mode is on for the window, \fBKEY_LEFT\fR and \fBKEY_BACKSPACE\fR
95 are both considered equivalent to the user's kill character.
96 .PP
97 Characters input are echoed only if \fBecho\fR is currently on.
98 In that case,
99 backspace is echoed as deletion of the previous character (typically a left
100 motion).
101 .SH RETURN VALUE
102 All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4
103 specifies only \*(``an integer value other than \fBERR\fR\*('') upon successful
104 completion.
105 .PP
106 X/Open defines no error conditions.
107 .PP
108 In this implementation,
109 these functions return an error
110 if the window pointer is null, or
111 if its timeout expires without having any data.
112 .PP
113 This implementation provides an extension as well.
114 If a \fBSIGWINCH\fP interrupts the function, it will return \fBKEY_RESIZE\fP
115 rather than \fBOK\fP or \fBERR\fP.
116 .PP
117 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
118 \fBwmove\fP, and return an error if the position is outside the window,
119 or if the window pointer is null.
120 .SH NOTES
121 Note that \fBgetstr\fR, \fBmvgetstr\fR, and \fBmvwgetstr\fR may be macros.
122 .SH PORTABILITY
123 These functions are described in the XSI Curses standard, Issue 4.
124 They read single-byte characters only.
125 The standard does not define any error conditions.
126 This implementation returns \fBERR\fP if the window pointer is null,
127 or if the lower-level \fBwgetch\fR(3X) call returns an \fBERR\fP.
128 .PP
129 SVr3 and early SVr4 curses implementations did not reject function keys;
130 the SVr4.0 documentation claimed that \*(``special keys\*(''
131 (such as function keys,
132 \*(``home\*('' key,
133 \*(``clear\*('' key,
134 \fIetc\fR.) are \*(``interpreted\*('',
135 without giving details.
136 It lied.
137 In fact, the \*(``character\*('' value appended to the
138 string by those implementations was predictable but not useful
139 (being, in fact, the low-order eight bits of the key's KEY_ value).
140 .PP
141 The functions \fBgetnstr\fR, \fBmvgetnstr\fR, and \fBmvwgetnstr\fR were
142 present but not documented in SVr4.
143 .PP
144 X/Open Curses, Issue 5 (2007) stated that these functions
145 \*(``read at most \fIn\fP bytes\*(''
146 but did not state whether the terminating NUL is counted in that limit.
147 X/Open Curses, Issue 7 (2009) changed that to say they
148 \*(``read at most \fIn\fP\-1 bytes\*(''
149 to allow for the terminating NUL.
150 As of 2018, some implementations do, some do not count it:
151 .bP
152 ncurses 6.1 and PDCurses do not count the NUL in the given limit, while
153 .bP
154 Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
155 .bP
156 Solaris xcurses provides both:
157 its wide-character \fBwget_nstr\fP reserves a NUL,
158 but its \fBwgetnstr\fP does not count the NUL consistently.
159 .PP
160 In SVr4 curses,
161 a negative value of \fIn\fP tells \fBwgetnstr\fP to assume that the
162 caller's buffer is large enough to hold the result,
163 i.e., to act like \fBwgetstr\fP.
164 X/Open Curses does not mention this
165 (or anything related to negative or zero values of \fIn\fP),
166 however most implementations
167 use the feature, with different limits:
168 .bP
169 Solaris SVr4 curses and PDCurses limit the result to 255 bytes.
170 Other Unix systems than Solaris are likely to use the same limit.
171 .bP
172 Solaris xcurses limits the result to \fBLINE_MAX\fP bytes.
173 .bP
174 NetBSD 7 assumes no particular limit for the result from \fBwgetstr\fP.
175 However, it limits the \fBwgetnstr\fP parameter \fIn\fP to ensure
176 that it is greater than zero.
177 .IP
178 A comment in NetBSD's source code states that this is specified in SUSv2.
179 .bP
180 ncurses (before 6.2) assumes no particular limit for the result
181 from \fBwgetstr\fP, and treats the \fIn\fP parameter of \fBwgetnstr\fP
182 like SVr4 curses.
183 .bP
184 ncurses 6.2 uses \fBLINE_MAX\fP,
185 or a larger (system-dependent) value
186 which the \fBsysconf\fP function may provide.
187 If neither \fBLINE_MAX\fP or \fBsysconf\fP is available,
188 ncurses uses the POSIX value for \fBLINE_MAX\fP (a 2048 byte limit).
189 In either case, it reserves a byte for the terminating NUL.
190 .SH SEE ALSO
191 \fBcurses\fR(3X),
192 \fBcurs_getch\fR(3X),
193 \fBcurs_variables\fR(3X).