]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_getstr.3x
ncurses 6.1 - patch 20191207
[ncurses.git] / man / curs_getstr.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
3 .\"                                                                          *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
5 .\" copy of this software and associated documentation files (the            *
6 .\" "Software"), to deal in the Software without restriction, including      *
7 .\" without limitation the rights to use, copy, modify, merge, publish,      *
8 .\" distribute, distribute with modifications, sublicense, and/or sell       *
9 .\" copies of the Software, and to permit persons to whom the Software is    *
10 .\" furnished to do so, subject to the following conditions:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 .\"                                                                          *
23 .\" Except as contained in this notice, the name(s) of the above copyright   *
24 .\" holders shall not be used in advertising or otherwise to promote the     *
25 .\" sale, use or other dealings in this Software without prior written       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" $Id: curs_getstr.3x,v 1.28 2019/07/20 19:14:56 tom Exp $
30 .TH curs_getstr 3X ""
31 .ie \n(.g .ds `` \(lq
32 .el       .ds `` ``
33 .ie \n(.g .ds '' \(rq
34 .el       .ds '' ''
35 .de bP
36 .ie n  .IP \(bu 4
37 .el    .IP \(bu 2
38 ..
39 .na
40 .hy 0
41 .SH NAME
42 \fBgetstr\fR,
43 \fBgetnstr\fR,
44 \fBwgetstr\fR,
45 \fBwgetnstr\fR,
46 \fBmvgetstr\fR,
47 \fBmvgetnstr\fR,
48 \fBmvwgetstr\fR,
49 \fBmvwgetnstr\fR \- accept character strings from \fBcurses\fR terminal keyboard
50 .ad
51 .hy
52 .SH SYNOPSIS
53 \fB#include <curses.h>\fR
54 .sp
55 \fBint getstr(char *str);\fR
56 .br
57 \fBint getnstr(char *str, int n);\fR
58 .br
59 \fBint wgetstr(WINDOW *win, char *str);\fR
60 .br
61 \fBint wgetnstr(WINDOW *win, char *str, int n);\fR
62 .br
63 \fBint mvgetstr(int y, int x, char *str);\fR
64 .br
65 \fBint mvwgetstr(WINDOW *win, int y, int x, char *str);\fR
66 .br
67 \fBint mvgetnstr(int y, int x, char *str, int n);\fR
68 .br
69 \fBint mvwgetnstr(WINDOW *, int y, int x, char *str, int n);\fR
70 .br
71 .SH DESCRIPTION
72 The function \fBgetstr\fR is equivalent to a series of calls to \fBgetch\fR,
73 until a newline or carriage return is received (the terminating character is
74 not included in the returned string).
75 .\" X/Open says also until EOf
76 .\" X/Open says then an EOS is added to the result
77 .\" X/Open doesn't mention n<0
78 The resulting value is placed in the
79 area pointed to by the character pointer \fIstr\fR,
80 followed by a NUL.
81 .PP
82 \fBwgetnstr\fR reads at most \fIn\fR characters, thus preventing a possible
83 overflow of the input buffer.
84 Any attempt to enter more characters (other
85 than the terminating newline or carriage return) causes a beep.
86 Function
87 keys also cause a beep and are ignored.
88 The \fBgetnstr\fR function reads
89 from the \fIstdscr\fR default window.
90 .PP
91 The user's erase and kill characters are interpreted.
92 If keypad
93 mode is on for the window, \fBKEY_LEFT\fR and \fBKEY_BACKSPACE\fR
94 are both considered equivalent to the user's kill character.
95 .PP
96 Characters input are echoed only if \fBecho\fR is currently on.
97 In that case,
98 backspace is echoed as deletion of the previous character (typically a left
99 motion).
100 .SH RETURN VALUE
101 All routines return the integer \fBERR\fR upon failure and an \fBOK\fR (SVr4
102 specifies only \*(``an integer value other than \fBERR\fR\*('') upon successful
103 completion.
104 .PP
105 X/Open defines no error conditions.
106 .PP
107 In this implementation,
108 these functions return an error
109 if the window pointer is null, or
110 if its timeout expires without having any data.
111 .PP
112 This implementation provides an extension as well.
113 If a \fBSIGWINCH\fP interrupts the function, it will return \fBKEY_RESIZE\fP
114 rather than \fBOK\fP or \fBERR\fP.
115 .PP
116 Functions with a \*(``mv\*('' prefix first perform a cursor movement using
117 \fBwmove\fP, and return an error if the position is outside the window,
118 or if the window pointer is null.
119 .SH NOTES
120 Note that \fBgetstr\fR, \fBmvgetstr\fR, and \fBmvwgetstr\fR may be macros.
121 .SH PORTABILITY
122 These functions are described in the XSI Curses standard, Issue 4.
123 They read single-byte characters only.
124 The standard does not define any error conditions.
125 This implementation returns \fBERR\fP if the window pointer is null,
126 or if the lower-level \fBwgetch\fR(3X) call returns an \fBERR\fP.
127 .PP
128 SVr3 and early SVr4 curses implementations did not reject function keys;
129 the SVr4.0 documentation claimed that \*(``special keys\*(''
130 (such as function keys,
131 \*(``home\*('' key,
132 \*(``clear\*('' key,
133 \fIetc\fR.) are \*(``interpreted\*('',
134 without giving details.
135 It lied.
136 In fact, the \*(``character\*('' value appended to the
137 string by those implementations was predictable but not useful
138 (being, in fact, the low-order eight bits of the key's KEY_ value).
139 .PP
140 The functions \fBgetnstr\fR, \fBmvgetnstr\fR, and \fBmvwgetnstr\fR were
141 present but not documented in SVr4.
142 .PP
143 X/Open Curses, Issue 5 (2007) stated that these functions
144 \*(``read at most \fIn\fP bytes\*(''
145 but did not state whether the terminating NUL is counted in that limit.
146 X/Open Curses, Issue 7 (2009) changed that to say they
147 \*(``read at most \fIn\fP\-1 bytes\*(''
148 to allow for the terminating NUL.
149 As of 2018, some implementations do, some do not count it:
150 .bP
151 ncurses 6.1 and PDCurses do not count the NUL in the given limit, while
152 .bP
153 Solaris SVr4 and NetBSD curses count the NUL as part of the limit.
154 .bP
155 Solaris xcurses provides both:
156 its wide-character \fBwget_nstr\fP reserves a NUL,
157 but its \fBwgetnstr\fP does not count the NUL consistently.
158 .PP
159 In SVr4 curses,
160 a negative value of \fIn\fP tells \fBwgetnstr\fP to assume that the
161 caller's buffer is large enough to hold the result,
162 i.e., to act like \fBwgetstr\fP.
163 X/Open Curses does not mention this
164 (or anything related to negative or zero values of \fIn\fP),
165 however most implementations
166 use the feature, with different limits:
167 .bP
168 Solaris SVr4 curses and PDCurses limit the result to 255 bytes.
169 Other Unix systems than Solaris are likely to use the same limit.
170 .bP
171 Solaris xcurses limits the result to \fBLINE_MAX\fP bytes.
172 .bP
173 NetBSD 7 assumes no particular limit for the result from \fBwgetstr\fP.
174 However, it limits the \fBwgetnstr\fP parameter \fIn\fP to ensure
175 that it is greater than zero.
176 .IP
177 A comment in NetBSD's source code states that this is specified in SUSv2.
178 .bP
179 ncurses (before 6.2) assumes no particular limit for the result
180 from \fBwgetstr\fP, and treats the \fIn\fP parameter of \fBwgetnstr\fP
181 like SVr4 curses.
182 .bP
183 ncurses 6.2 uses \fBLINE_MAX\fP,
184 or a larger (system-dependent) value
185 which the \fBsysconf\fP function may provide.
186 If neither \fBLINE_MAX\fP or \fBsysconf\fP is available,
187 ncurses uses the POSIX value for \fBLINE_MAX\fP (a 2048 byte limit).
188 In either case, it reserves a byte for the terminating NUL.
189 .SH SEE ALSO
190 \fBcurses\fR(3X),
191 \fBcurs_getch\fR(3X),
192 \fBcurs_variables\fR(3X).