summaryrefslogtreecommitdiff
path: root/lib/libcurses/get_wch.c
blob: 0e69334a4cae7500a07faabc46a42bcb7b9626c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/*   $NetBSD: get_wch.c,v 1.10 2012/06/29 10:40:29 blymn Exp $ */

/*
 * Copyright (c) 2005 The NetBSD Foundation Inc.
 * All rights reserved.
 *
 * This code is derived from code donated to the NetBSD Foundation
 * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *	notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *	notice, this list of conditions and the following disclaimer in the
 *	documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the NetBSD Foundation nor the names of its
 *	contributors may be used to endorse or promote products derived
 *	from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: get_wch.c,v 1.10 2012/06/29 10:40:29 blymn Exp $");
#endif						  /* not lint */

#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "curses.h"
#include "curses_private.h"
#include "keymap.h"

#ifdef HAVE_WCHAR
static short   wstate;		  /* state of the wcinkey function */
#endif /* HAVE_WCHAR */
extern short state;		/* storage declared in getch.c */

/* prototypes for private functions */
#ifdef HAVE_WCHAR
static int inkey(wchar_t *wc, int to, int delay);
#endif /* HAVE_WCHAR */

#ifdef HAVE_WCHAR
/*
 * __init_get_wch - initialise all the pointers & structures needed to make
 * get_wch work in keypad mode.
 *
 */
void
__init_get_wch(SCREEN *screen)
{
	wstate = INKEY_NORM;
	memset( &screen->cbuf, 0, sizeof(screen->cbuf));
	screen->cbuf_head = screen->cbuf_tail = screen->cbuf_cur = 0;
}
#endif /* HAVE_WCHAR */


#ifdef HAVE_WCHAR
/*
 * inkey - do the work to process keyboard input, check for multi-key
 * sequences and return the appropriate symbol if we get a match.
 *
 */
static int
inkey(wchar_t *wc, int to, int delay)
{
	wchar_t		 k = 0;
	int		  c, mapping, ret = 0;
	size_t	  mlen = 0;
	keymap_t	*current = _cursesi_screen->base_keymap;
	FILE		*infd = _cursesi_screen->infd;
	int		 *start = &_cursesi_screen->cbuf_head,
				*working = &_cursesi_screen->cbuf_cur,
				*end = &_cursesi_screen->cbuf_tail;
	char		*inbuf = &_cursesi_screen->cbuf[ 0 ];

#ifdef DEBUG
	__CTRACE(__CTRACE_INPUT, "inkey (%p, %d, %d)\n", wc, to, delay);
#endif
	for (;;) { /* loop until we get a complete key sequence */
		if (wstate == INKEY_NORM) {
			if (delay && __timeout(delay) == ERR)
				return ERR;
			c = fgetc(infd);
			if (c == WEOF) {
				clearerr(infd);
				return ERR;
			}

			if (delay && (__notimeout() == ERR))
				return ERR;

			k = (wchar_t) c;
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey (wstate normal) got '%s'\n", unctrl(k));
#endif

			inbuf[ *end ] = k;
			*end = ( *end + 1 ) % MAX_CBUF_SIZE;
			*working = *start;
			wstate = INKEY_ASSEMBLING; /* go to assembling state */
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey: NORM=>ASSEMBLING: start(%d), "
			    "current(%d), end(%d)\n", *start, *working, *end);
#endif /* DEBUG */
		} else if (wstate == INKEY_BACKOUT) {
			k = inbuf[*working];
			*working = ( *working + 1 ) % MAX_CBUF_SIZE;
			if (*working == *end) {	/* see if run out of keys */
				/* if so, switch to assembling */
				wstate = INKEY_ASSEMBLING;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: BACKOUT=>ASSEMBLING, start(%d), "
				    "current(%d), end(%d)\n",
				    *start, *working, *end);
#endif /* DEBUG */
			}
		} else if (wstate == INKEY_ASSEMBLING) {
			/* assembling a key sequence */
			if (delay) {
				if (__timeout(to ? (ESCDELAY / 100) : delay)
						== ERR)
					return ERR;
			} else {
				if (to && (__timeout(ESCDELAY / 100) == ERR))
					return ERR;
			}

			c = fgetc(infd);
			if (ferror(infd)) {
				clearerr(infd);
				return ERR;
			}

			if ((to || delay) && (__notimeout() == ERR))
				return ERR;

			k = (wchar_t) c;
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey (wstate assembling) got '%s'\n", unctrl(k));
#endif /* DEBUG */
			if (feof(infd)) { /* inter-char T/O, start backout */
				clearerr(infd);
				if (*start == *end)
					/* no chars in the buffer, restart */
					continue;

				k = inbuf[*start];
				wstate = INKEY_TIMEOUT;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: ASSEMBLING=>TIMEOUT, start(%d), "
				    "current(%d), end(%d)\n",
				    *start, *working, *end);
#endif /* DEBUG */
			} else {
				inbuf[ *end ] = k;
				*working = *end;
				*end = ( *end + 1 ) % MAX_CBUF_SIZE;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: ASSEMBLING: start(%d), "
				    "current(%d), end(%d)",
				    *start, *working, *end);
#endif /* DEBUG */
			}
		} else if (wstate == INKEY_WCASSEMBLING) {
			/* assembling a wide-char sequence */
			if (delay) {
				if (__timeout(to ? (ESCDELAY / 100) : delay)
						== ERR)
					return ERR;
			} else {
				if (to && (__timeout(ESCDELAY / 100) == ERR))
					return ERR;
			}

			c = fgetc(infd);
			if (ferror(infd)) {
				clearerr(infd);
				return ERR;
			}

			if ((to || delay) && (__notimeout() == ERR))
				return ERR;

			k = (wchar_t) c;
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey (wstate wcassembling) got '%s'\n",
				unctrl(k));
#endif
			if (feof(infd)) { /* inter-char T/O, start backout */
				clearerr(infd);
				if (*start == *end)
					/* no chars in the buffer, restart */
					continue;

				*wc = inbuf[*start];
				*working = *start
					= ( *start + 1 ) % MAX_CBUF_SIZE;
				if (*start == *end) {
					state = wstate = INKEY_NORM;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: WCASSEMBLING=>NORM, "
					    "start(%d), current(%d), end(%d)",
					    *start, *working, *end);
#endif /* DEBUG */
				} else {
					state = wstate = INKEY_BACKOUT;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: WCASSEMBLING=>BACKOUT, "
					    "start(%d), current(%d), end(%d)",
					    *start, *working, *end);
#endif /* DEBUG */
				}
				return OK;
			} else {
				/* assembling wide characters */
				inbuf[ *end ] = k;
				*working = *end;
				*end = ( *end + 1 ) % MAX_CBUF_SIZE;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: WCASSEMBLING[head(%d), "
				    "urrent(%d), tail(%d)]\n",
				    *start, *working, *end);
#endif /* DEBUG */
				ret = (int) mbrtowc( wc, inbuf + (*working), 1,
					&_cursesi_screen->sp );
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: mbrtowc returns %d, wc(%x)\n",
				    ret, *wc );
#endif /* DEBUG */
				if ( ret == -2 ) {
					*working = (*working + 1)
						% MAX_CBUF_SIZE;
					continue;
				}
				if ( ret == 0 )
					ret = 1;
				if ( ret == -1 ) {
					/* return the 1st character we know */
					*wc = inbuf[ *start ];
					*working = *start = ( *start + 1 ) % MAX_CBUF_SIZE;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: Invalid wide char(%x) "
					    "[head(%d), current(%d), "
					    "tail(%d)]\n",
					    *wc, *start, *working, *end);
#endif /* DEBUG */
				} else { /* > 0 */
					/* return the wide character */
					*start = *working
					       = (*working + ret)%MAX_CBUF_SIZE;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: Wide char found(%x) "
					    "[head(%d), current(%d), "
					    "tail(%d)]\n",
					    *wc, *start, *working, *end);
#endif /* DEBUG */
				}

				if (*start == *end) {	/* only one char processed */
					state = wstate = INKEY_NORM;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: WCASSEMBLING=>NORM, "
					    "start(%d), current(%d), end(%d)",
					    *start, *working, *end);
#endif /* DEBUG */
				} else {
					/* otherwise we must have more than one char to backout */
					state = wstate = INKEY_BACKOUT;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "inkey: WCASSEMBLING=>BACKOUT, "
					    "start(%d), current(%d), end(%d)",
					    *start, *working, *end);
#endif /* DEBUG */
				}
				return OK;
			}
		} else {
			fprintf(stderr, "Inkey wstate screwed - exiting!!!");
			exit(2);
		}

		/*
		 * Check key has no special meaning and we have not
		 * timed out and the key has not been disabled
		 */
		mapping = current->mapping[k];
		if (((wstate == INKEY_TIMEOUT) || (mapping < 0))
				|| ((current->key[mapping]->type
					== KEYMAP_LEAF)
				&& (current->key[mapping]->enable == FALSE))) {
			/* wide-character specific code */
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey: Checking for wide char\n");
#endif /* DEBUG */
			mbrtowc( NULL, NULL, 1, &_cursesi_screen->sp );
			*working = *start;
			mlen = *end > *working ?
				*end - *working : MAX_CBUF_SIZE - *working;
			if ( !mlen )
				return ERR;
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey: Check wide char[head(%d), "
			    "current(%d), tail(%d), mlen(%ld)]\n",
			    *start, *working, *end, (long) mlen);
#endif /* DEBUG */
			ret = (int) mbrtowc( wc, inbuf + (*working), mlen,
				&_cursesi_screen->sp );
#ifdef DEBUG
			__CTRACE(__CTRACE_INPUT,
			    "inkey: mbrtowc returns %d, wc(%x)\n", ret, *wc);
#endif /* DEBUG */
			if ( ret == -2 && *end < *working ) {
				/* second half of a wide character */
				*working = 0;
				mlen = *end;
				if ( mlen )
					ret = (int) mbrtowc( wc, inbuf, mlen,
						&_cursesi_screen->sp );
			}
			if ( ret == -2 && wstate != INKEY_TIMEOUT ) {
				*working = (*working + (int) mlen)
					% MAX_CBUF_SIZE;
				wstate = INKEY_WCASSEMBLING;
				continue;
			}
			if ( ret == 0 )
				ret = 1;
			if ( ret == -1 ) {
				/* return the first key we know about */
				*wc = inbuf[ *start ];
				*working = *start
					= ( *start + 1 ) % MAX_CBUF_SIZE;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: Invalid wide char(%x)[head(%d), "
				    "current(%d), tail(%d)]\n",
				    *wc, *start, *working, *end);
#endif /* DEBUG */
			} else { /* > 0 */
				/* return the wide character */
				*start = *working
					= ( *working + ret ) % MAX_CBUF_SIZE;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: Wide char found(%x)[head(%d), "
				    "current(%d), tail(%d)]\n",
				    *wc, *start, *working, *end);
#endif /* DEBUG */
			}

			if (*start == *end) {	/* only one char processed */
				state = wstate = INKEY_NORM;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: Empty cbuf=>NORM, "
				    "start(%d), current(%d), end(%d)\n",
				    *start, *working, *end);
#endif /* DEBUG */
			} else {
				/* otherwise we must have more than one char to backout */
				state = wstate = INKEY_BACKOUT;
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: Non-empty cbuf=>BACKOUT, "
				    "start(%d), current(%d), end(%d)\n",
				    *start, *working, *end);
#endif /* DEBUG */
			}
			return OK;
		} else {	/* must be part of a multikey sequence */
					/* check for completed key sequence */
			if (current->key[current->mapping[k]]->type
					== KEYMAP_LEAF) {
				/* eat the key sequence in cbuf */
				*start = *working = ( *working + 1 ) % MAX_CBUF_SIZE;

				/* check if inbuf empty now */
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
				    "inkey: Key found(%s)\n",
				    key_name(current->key[mapping]->value.symbol));
#endif /* DEBUG */
				if (*start == *end) {
					/* if it is go back to normal */
					state = wstate = INKEY_NORM;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "[inkey]=>NORM, start(%d), "
					    "current(%d), end(%d)",
					    *start, *working, *end);
#endif /* DEBUG */
				} else {
					/* otherwise go to backout state */
					state = wstate = INKEY_BACKOUT;
#ifdef DEBUG
					__CTRACE(__CTRACE_INPUT,
					    "[inkey]=>BACKOUT, start(%d), "
					    "current(%d), end(%d)",
					    *start, *working, *end );
#endif /* DEBUG */
				}

				/* return the symbol */
				*wc = current->key[mapping]->value.symbol;
				return KEY_CODE_YES;
			} else {
				/* Step to next part of multi-key sequence */
				current = current->key[current->mapping[k]]->value.next;
			}
		}
	}
}
#endif /* HAVE_WCHAR */

/*
 * get_wch --
 *	Read in a wide character from stdscr.
 */
int
get_wch(wint_t *ch)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	return wget_wch(stdscr, ch);
#endif /* HAVE_WCHAR */
}

/*
 * mvget_wch --
 *	  Read in a character from stdscr at the given location.
 */
int
mvget_wch(int y, int x, wint_t *ch)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	return mvwget_wch(stdscr, y, x, ch);
#endif /* HAVE_WCHAR */
}

/*
 * mvwget_wch --
 *	  Read in a character from stdscr at the given location in the
 *	  given window.
 */
int
mvwget_wch(WINDOW *win, int y, int x, wint_t *ch)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	if (wmove(win, y, x) == ERR)
		return ERR;

	return wget_wch(win, ch);
#endif /* HAVE_WCHAR */
}

/*
 * wget_wch --
 *	Read in a wide character from the window.
 */
int
wget_wch(WINDOW *win, wint_t *ch)
{
#ifndef HAVE_WCHAR
	return ERR;
#else
	int ret, weset;
	int c;
	FILE *infd = _cursesi_screen->infd;
	cchar_t wc;
	wchar_t inp, ws[ 2 ];

	if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN)
			&& win->curx == win->maxx - 1
			&& win->cury == win->maxy - 1
			&& __echoit)
		return (ERR);

	if (is_wintouched(win))
		wrefresh(win);
#ifdef DEBUG
	__CTRACE(__CTRACE_INPUT, "wget_wch: __echoit = %d, "
	    "__rawmode = %d, __nl = %d, flags = %#.4x\n",
	    __echoit, __rawmode, _cursesi_screen->nl, win->flags);
#endif
	if (_cursesi_screen->resized) {
		_cursesi_screen->resized = 0;
		*ch = KEY_RESIZE;
		return KEY_CODE_YES;
	}
	if (_cursesi_screen->unget_pos) {
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT, "wget_wch returning char at %d\n",
		    _cursesi_screen->unget_pos);
#endif
		_cursesi_screen->unget_pos--;
		*ch = _cursesi_screen->unget_list[_cursesi_screen->unget_pos];
		if (__echoit) {
			ws[0] = *ch, ws[1] = L'\0';
			setcchar(&wc, ws, win->wattr, 0, NULL);
			wadd_wch(win, &wc);
		}
		return KEY_CODE_YES;
	}
	if (__echoit && !__rawmode) {
		cbreak();
		weset = 1;
	} else
		weset = 0;

	__save_termios();

	if (win->flags & __KEYPAD) {
		switch (win->delay) {
			case -1:
				ret = inkey(&inp,
					win->flags & __NOTIMEOUT ? 0 : 1, 0);
				break;
			case 0:
				if (__nodelay() == ERR)
					return ERR;
				ret = inkey(&inp, 0, 0);
				break;
			default:
				ret = inkey(&inp,
					win->flags & __NOTIMEOUT ? 0 : 1,
					win->delay);
				break;
		}
		if ( ret == ERR )
			return ERR;
	} else {
		switch (win->delay) {
			case -1:
				break;
			case 0:
				if (__nodelay() == ERR)
					return ERR;
				break;
			default:
				if (__timeout(win->delay) == ERR)
					return ERR;
				break;
		}

		c = getwchar();
		if (feof(infd)) {
			clearerr(infd);
			__restore_termios();
			return ERR;	/* we have timed out */
		}

		if (ferror(infd)) {
			clearerr(infd);
			return ERR;
		} else {
			ret = c;
			inp = c;
		}
	}
#ifdef DEBUG
	if (inp > 255)
		/* we have a key symbol - treat it differently */
		/* XXXX perhaps __unctrl should be expanded to include
		 * XXXX the keysyms in the table....
		 */
		__CTRACE(__CTRACE_INPUT, "wget_wch assembled keysym 0x%x\n",
		    inp);
	else
		__CTRACE(__CTRACE_INPUT, "wget_wch got '%s'\n", unctrl(inp));
#endif
	if (win->delay > -1) {
		if (__delay() == ERR)
			return ERR;
	}

	__restore_termios();

	if (__echoit) {
		if ( ret == KEY_CODE_YES ) {
			/* handle [DEL], [BS], and [LEFT] */
			if ( win->curx &&
					( inp == KEY_DC ||
					  inp == KEY_BACKSPACE ||
					  inp == KEY_LEFT )) {
				wmove( win, win->cury, win->curx - 1 );
				wdelch( win );
			}
		} else {
			ws[ 0 ] = inp, ws[ 1 ] = L'\0';
			setcchar( &wc, ws, win->wattr, 0, NULL );
			wadd_wch( win, &wc );
		}
	}

	if (weset)
		nocbreak();

	if (_cursesi_screen->nl && inp == 13)
		inp = 10;

	*ch = inp;

	if ( ret == KEY_CODE_YES )
		return KEY_CODE_YES;
	return ( inp < 0 ? ERR : OK );
#endif /* HAVE_WCHAR */
}

/*
 * unget_wch --
 *	 Put the wide character back into the input queue.
 */
int
unget_wch(const wchar_t c)
{
	return __unget((wint_t) c);
}