1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * wgetn_ws.c
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * XCurses Library
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef M_RCSID
39*7c478bd9Sstevel@tonic-gate #ifndef lint
40*7c478bd9Sstevel@tonic-gate static char rcsID[] =
41*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/wgetn_ws.c 1.7 1998/06/04 19:56:00 "
43*7c478bd9Sstevel@tonic-gate "cbates Exp $";
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #include <private.h>
48*7c478bd9Sstevel@tonic-gate #include <limits.h>
49*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
50*7c478bd9Sstevel@tonic-gate #include <m_wio.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate static wint_t	fld_key;
53*7c478bd9Sstevel@tonic-gate static int	fld_echo;	/* Software echo flag. */
54*7c478bd9Sstevel@tonic-gate static int	fld_index;	/* Number of characters in fld_buffer. */
55*7c478bd9Sstevel@tonic-gate static int	fld_bytes;	/* fld_index expressed in bytes. */
56*7c478bd9Sstevel@tonic-gate static int	fld_mb;		/* Field is a multibyte character string. */
57*7c478bd9Sstevel@tonic-gate static wint_t	*fld_buffer;	/* Wide character buffer. */
58*7c478bd9Sstevel@tonic-gate static int	fld_maxlength;	/* Character length of buffer. */
59*7c478bd9Sstevel@tonic-gate static WINDOW	*fld_window;
60*7c478bd9Sstevel@tonic-gate static int	fld_row, fld_col;	/* Start of field in fld_window. */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate static int	fld_done(void);
63*7c478bd9Sstevel@tonic-gate static int	fld_erase(void);
64*7c478bd9Sstevel@tonic-gate static int	fld_kill(void);
65*7c478bd9Sstevel@tonic-gate static int	fld_insert(void);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate typedef struct t_key_entry {
68*7c478bd9Sstevel@tonic-gate 	int	type;
69*7c478bd9Sstevel@tonic-gate 	wint_t	code;
70*7c478bd9Sstevel@tonic-gate 	int	(*func)(void);
71*7c478bd9Sstevel@tonic-gate } t_key_entry;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate #define	ERASE_KEY	0
74*7c478bd9Sstevel@tonic-gate #define	KILL_KEY	1
75*7c478bd9Sstevel@tonic-gate #define	EOF_KEY		2
76*7c478bd9Sstevel@tonic-gate #define	EOL_KEY		3
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate static t_key_entry	key_table[] = {
79*7c478bd9Sstevel@tonic-gate 	{ OK, 0, fld_erase },
80*7c478bd9Sstevel@tonic-gate 	{ OK, 0, fld_kill },
81*7c478bd9Sstevel@tonic-gate #if VEOF == VMIN
82*7c478bd9Sstevel@tonic-gate 	{ OK, '\x04', fld_done },
83*7c478bd9Sstevel@tonic-gate 	{ OK, '\r', fld_done },
84*7c478bd9Sstevel@tonic-gate #else
85*7c478bd9Sstevel@tonic-gate 	{ OK, 0, fld_done },
86*7c478bd9Sstevel@tonic-gate 	{ OK, 0, fld_done },
87*7c478bd9Sstevel@tonic-gate #endif
88*7c478bd9Sstevel@tonic-gate 	{ OK, '\n', fld_done },
89*7c478bd9Sstevel@tonic-gate 	{ OK, WEOF, fld_done },
90*7c478bd9Sstevel@tonic-gate 	{ KEY_CODE_YES, KEY_LEFT, fld_erase },
91*7c478bd9Sstevel@tonic-gate 	{ KEY_CODE_YES, KEY_BACKSPACE, fld_erase },
92*7c478bd9Sstevel@tonic-gate 	{ KEY_CODE_YES, KEY_ENTER, fld_done },
93*7c478bd9Sstevel@tonic-gate 	{ ERR, 0, fld_insert }
94*7c478bd9Sstevel@tonic-gate };
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate  * The effect of wgetnstr() is as though a series of calls to wgetch()
98*7c478bd9Sstevel@tonic-gate  * were made, until a <newline> or <return> are received.  The
99*7c478bd9Sstevel@tonic-gate  * resulting value is placed in the area pointed to by the character
100*7c478bd9Sstevel@tonic-gate  * pointer 's'.  wgetnstr() reads at most n characters, thus
101*7c478bd9Sstevel@tonic-gate  * preventing a possible overflow of the input buffer.  The user's
102*7c478bd9Sstevel@tonic-gate  * erase and kill characters are interpreted.
103*7c478bd9Sstevel@tonic-gate  *
104*7c478bd9Sstevel@tonic-gate  * If n < 0, wgetnstr() will read until a <newline> or <return> is
105*7c478bd9Sstevel@tonic-gate  * entered.  To accept functions keys, keypad() must be set for the
106*7c478bd9Sstevel@tonic-gate  * window.
107*7c478bd9Sstevel@tonic-gate  */
108*7c478bd9Sstevel@tonic-gate int
__m_wgetn_wstr(WINDOW * w,void * s,int n,int mb_flag)109*7c478bd9Sstevel@tonic-gate __m_wgetn_wstr(WINDOW *w, void *s, int n, int mb_flag)
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate 	int	type;
112*7c478bd9Sstevel@tonic-gate 	wchar_t	wc;
113*7c478bd9Sstevel@tonic-gate 	t_key_entry	*k;
114*7c478bd9Sstevel@tonic-gate 	struct termios	saved;
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	if (n == 0) {
117*7c478bd9Sstevel@tonic-gate 	    *(char *)s = '\0';
118*7c478bd9Sstevel@tonic-gate 	    return (OK);
119*7c478bd9Sstevel@tonic-gate 	}
120*7c478bd9Sstevel@tonic-gate 	fld_window = w;
121*7c478bd9Sstevel@tonic-gate 	fld_index = 0;
122*7c478bd9Sstevel@tonic-gate 	fld_bytes = 0;
123*7c478bd9Sstevel@tonic-gate 	fld_mb = mb_flag;
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	/* Read at most N bytes from the field. */
126*7c478bd9Sstevel@tonic-gate 	fld_maxlength = n < 0 ? LINE_MAX : n;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	/* Make sure there is enough to hold the largest characater. */
129*7c478bd9Sstevel@tonic-gate 	if (fld_mb && (fld_maxlength < (int)MB_CUR_MAX))
130*7c478bd9Sstevel@tonic-gate 		return (ERR);
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 	if (mb_flag) {
133*7c478bd9Sstevel@tonic-gate 		/*
134*7c478bd9Sstevel@tonic-gate 		 * Create a wint_t buffer, which makes it easier to
135*7c478bd9Sstevel@tonic-gate 		 * handle erasing characters from the line.
136*7c478bd9Sstevel@tonic-gate 		 */
137*7c478bd9Sstevel@tonic-gate 		fld_buffer = (wint_t *) calloc(fld_maxlength + 1,
138*7c478bd9Sstevel@tonic-gate 			sizeof (*fld_buffer));
139*7c478bd9Sstevel@tonic-gate 		if (fld_buffer == NULL)
140*7c478bd9Sstevel@tonic-gate 			return (ERR);
141*7c478bd9Sstevel@tonic-gate 	} else {
142*7c478bd9Sstevel@tonic-gate 		fld_buffer = (wint_t *) s;
143*7c478bd9Sstevel@tonic-gate 	}
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate #if VEOF != VMIN
146*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_wc(VEOL, &wc);
147*7c478bd9Sstevel@tonic-gate 	key_table[EOL_KEY].code = (wint_t) wc;
148*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_wc(VEOF, &wc);
149*7c478bd9Sstevel@tonic-gate 	key_table[EOF_KEY].code = (wint_t) wc;
150*7c478bd9Sstevel@tonic-gate #endif
151*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_wc(VKILL, &wc);
152*7c478bd9Sstevel@tonic-gate 	key_table[KILL_KEY].code = (wint_t) wc;
153*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_wc(VERASE, &wc);
154*7c478bd9Sstevel@tonic-gate 	key_table[ERASE_KEY].code = (wint_t) wc;
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	getyx(fld_window, fld_row, fld_col);
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 	/*
159*7c478bd9Sstevel@tonic-gate 	 * We remember if the user specified echo on or off, then disable it
160*7c478bd9Sstevel@tonic-gate 	 * so that wgetch() doesn't perform any echoing before we've had a
161*7c478bd9Sstevel@tonic-gate 	 * chance to process the key.  fld_insert() will handle the necessary
162*7c478bd9Sstevel@tonic-gate 	 * echoing of characters.
163*7c478bd9Sstevel@tonic-gate 	 */
164*7c478bd9Sstevel@tonic-gate 	fld_echo = __m_set_echo(0);
165*7c478bd9Sstevel@tonic-gate 	saved = *PTERMIOS(_prog);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	if (!(cur_term->_flags & __TERM_HALF_DELAY))
168*7c478bd9Sstevel@tonic-gate 		(void) cbreak();
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 	for (; ; ) {
171*7c478bd9Sstevel@tonic-gate 		if ((type = wget_wch(fld_window, &fld_key)) == ERR)
172*7c478bd9Sstevel@tonic-gate 			break;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 		for (k = key_table; k->type != ERR; ++k) {
175*7c478bd9Sstevel@tonic-gate 			if (k->type == type && k->code == fld_key) {
176*7c478bd9Sstevel@tonic-gate 				break;
177*7c478bd9Sstevel@tonic-gate 			}
178*7c478bd9Sstevel@tonic-gate 		}
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 		if (k->func != (int (*)(void)) NULL && !(*k->func)()) {
181*7c478bd9Sstevel@tonic-gate 			/* If the edit function returned false then quit. */
182*7c478bd9Sstevel@tonic-gate 			fld_buffer[fld_index] = '\0';
183*7c478bd9Sstevel@tonic-gate 			break;
184*7c478bd9Sstevel@tonic-gate 		}
185*7c478bd9Sstevel@tonic-gate 	}
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 	/* Restore the I/O settings. */
188*7c478bd9Sstevel@tonic-gate 	(void) __m_set_echo(fld_echo);
189*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_set(&saved);
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	if (mb_flag) {
192*7c478bd9Sstevel@tonic-gate 		(void) wistombs((char *) s, fld_buffer, fld_maxlength-1);
193*7c478bd9Sstevel@tonic-gate 		free(fld_buffer);
194*7c478bd9Sstevel@tonic-gate 	}
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate 	return ((type == ERR) ? ERR : OK);
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate static int
wint_len(wint_t wc)200*7c478bd9Sstevel@tonic-gate wint_len(wint_t wc)
201*7c478bd9Sstevel@tonic-gate {
202*7c478bd9Sstevel@tonic-gate 	int	len;
203*7c478bd9Sstevel@tonic-gate 	char	mb[MB_LEN_MAX];
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	if (wc == WEOF)
206*7c478bd9Sstevel@tonic-gate 		return (0);
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	len = wctomb(mb, (wchar_t) wc);
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	return ((len < 0) ? 0 : len);
211*7c478bd9Sstevel@tonic-gate }
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate static int
fld_done(void)214*7c478bd9Sstevel@tonic-gate fld_done(void)
215*7c478bd9Sstevel@tonic-gate {
216*7c478bd9Sstevel@tonic-gate 	cchar_t	cc;
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	if (fld_echo) {
219*7c478bd9Sstevel@tonic-gate 		(void) __m_wc_cc(fld_key, &cc);
220*7c478bd9Sstevel@tonic-gate 		(void) wadd_wch(fld_window, &cc);
221*7c478bd9Sstevel@tonic-gate 	}
222*7c478bd9Sstevel@tonic-gate 	return (0);
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate static int
fld_erase(void)226*7c478bd9Sstevel@tonic-gate fld_erase(void)
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate 	int	x, y, width;
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	if (fld_index <= 0) {
231*7c478bd9Sstevel@tonic-gate 		fld_buffer[fld_index-1] = 0;
232*7c478bd9Sstevel@tonic-gate 		return (1);
233*7c478bd9Sstevel@tonic-gate 	}
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate 	width = wcwidth(fld_buffer[--fld_index]);
236*7c478bd9Sstevel@tonic-gate 	fld_bytes -= wint_len(fld_buffer[fld_index]);
237*7c478bd9Sstevel@tonic-gate 	fld_buffer[fld_index] = '\0';
238*7c478bd9Sstevel@tonic-gate 	getyx(fld_window, y, x);
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	if (0 < x) {
241*7c478bd9Sstevel@tonic-gate 		/* Rubout previous character. */
242*7c478bd9Sstevel@tonic-gate 		x -= width;
243*7c478bd9Sstevel@tonic-gate 	} else if (0 < y) {
244*7c478bd9Sstevel@tonic-gate 		/* Reverse line wrap. */
245*7c478bd9Sstevel@tonic-gate 		--y;
246*7c478bd9Sstevel@tonic-gate 		x = fld_window->_maxx - 1;
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 		/*
249*7c478bd9Sstevel@tonic-gate 		 * Find end of previous character, skipping any background
250*7c478bd9Sstevel@tonic-gate 		 * character that may have been written by auto-wrap.
251*7c478bd9Sstevel@tonic-gate 		 */
252*7c478bd9Sstevel@tonic-gate 		while (fld_buffer[fld_index] != fld_window->_line[y][x]._wc[0])
253*7c478bd9Sstevel@tonic-gate 			--x;
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 		/* Find first column of character. */
256*7c478bd9Sstevel@tonic-gate 		x = __m_cc_first(fld_window, y, x);
257*7c478bd9Sstevel@tonic-gate 	}
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	(void) __m_cc_erase(fld_window, y, x, y, x);
260*7c478bd9Sstevel@tonic-gate 
261*7c478bd9Sstevel@tonic-gate 	fld_window->_cury = (short) y;
262*7c478bd9Sstevel@tonic-gate 	fld_window->_curx = (short) x;
263*7c478bd9Sstevel@tonic-gate 
264*7c478bd9Sstevel@tonic-gate 	return (1);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate static int
fld_kill(void)268*7c478bd9Sstevel@tonic-gate fld_kill(void)
269*7c478bd9Sstevel@tonic-gate {
270*7c478bd9Sstevel@tonic-gate 	int	y, x;
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 	getyx(fld_window, y, x);
273*7c478bd9Sstevel@tonic-gate 	(void) __m_cc_erase(fld_window, fld_row, fld_col, y, x);
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 	fld_window->_cury = (short) fld_row;
276*7c478bd9Sstevel@tonic-gate 	fld_window->_curx = (short) fld_col;
277*7c478bd9Sstevel@tonic-gate 	fld_index = fld_bytes = 0;
278*7c478bd9Sstevel@tonic-gate 	fld_buffer[0] = '\0';
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 	return (1);
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate static int
fld_insert(void)284*7c478bd9Sstevel@tonic-gate fld_insert(void)
285*7c478bd9Sstevel@tonic-gate {
286*7c478bd9Sstevel@tonic-gate 	cchar_t	cc;
287*7c478bd9Sstevel@tonic-gate 	t_wide_io	*wio;
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	if (fld_maxlength <= (fld_index + 1))
290*7c478bd9Sstevel@tonic-gate 		/* Completely full, terminate input. */
291*7c478bd9Sstevel@tonic-gate 		return (0);
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate 	wio = (t_wide_io *) __m_screen->_in;
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	/*
296*7c478bd9Sstevel@tonic-gate 	 * Don't exceed the byte length for the field.
297*7c478bd9Sstevel@tonic-gate 	 *
298*7c478bd9Sstevel@tonic-gate 	 * m_wio_get() called by wget_wch(), records the
299*7c478bd9Sstevel@tonic-gate 	 * number of bytes converted, when _next == _size.
300*7c478bd9Sstevel@tonic-gate 	 *
301*7c478bd9Sstevel@tonic-gate 	 * wget_wch() makes sure that _next == _size by
302*7c478bd9Sstevel@tonic-gate 	 * pushing invalid multibyte characters on to an
303*7c478bd9Sstevel@tonic-gate 	 * input stack.
304*7c478bd9Sstevel@tonic-gate 	 */
305*7c478bd9Sstevel@tonic-gate 	if (fld_mb && fld_maxlength < fld_bytes + wio->_size) {
306*7c478bd9Sstevel@tonic-gate 		/* Is there still room for single-byte characters? */
307*7c478bd9Sstevel@tonic-gate 		if (fld_bytes < fld_maxlength) {
308*7c478bd9Sstevel@tonic-gate 			(void) beep();
309*7c478bd9Sstevel@tonic-gate 			return (1);
310*7c478bd9Sstevel@tonic-gate 		}
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 		/* Completely full, terminate input. */
313*7c478bd9Sstevel@tonic-gate 		return (0);
314*7c478bd9Sstevel@tonic-gate 	}
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 	if (0 <= fld_key) {
317*7c478bd9Sstevel@tonic-gate 		fld_buffer[fld_index++] = fld_key;
318*7c478bd9Sstevel@tonic-gate 		fld_bytes += wio->_size;
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 		if (fld_echo) {
321*7c478bd9Sstevel@tonic-gate 			(void) __m_wc_cc(fld_key, &cc);
322*7c478bd9Sstevel@tonic-gate 			(void) wadd_wch(fld_window, &cc);
323*7c478bd9Sstevel@tonic-gate 		}
324*7c478bd9Sstevel@tonic-gate 	} else {
325*7c478bd9Sstevel@tonic-gate 		(void) beep();
326*7c478bd9Sstevel@tonic-gate 	}
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	return (1);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate int
wgetnstr(WINDOW * w,char * s,int n)332*7c478bd9Sstevel@tonic-gate wgetnstr(WINDOW *w, char *s, int n)
333*7c478bd9Sstevel@tonic-gate {
334*7c478bd9Sstevel@tonic-gate 	int	code;
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	code = __m_wgetn_wstr(w, (void *) s, n, 1);
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	return (code);
339*7c478bd9Sstevel@tonic-gate }
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate int
wgetn_wstr(WINDOW * w,wint_t * s,int n)342*7c478bd9Sstevel@tonic-gate wgetn_wstr(WINDOW *w, wint_t *s, int n)
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	int	code;
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 	code = __m_wgetn_wstr(w, (void *) s, n, 0);
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	return (code);
349*7c478bd9Sstevel@tonic-gate }
350