1
1
/****************************************************************************
2
* Copyright (c) 2002-2004,2005 Free Software Foundation, Inc. *
2
* Copyright (c) 2002-2007,2008 Free Software Foundation, Inc. *
4
4
* Permission is hereby granted, free of charge, to any person obtaining a *
5
5
* copy of this software and associated documentation files (the *
40
40
#include <curses.priv.h>
43
MODULE_ID("$Id: lib_get_wch.c,v 1.12 2005/08/13 18:51:43 tom Exp $")
43
MODULE_ID("$Id: lib_get_wch.c,v 1.17 2008/08/16 19:22:55 tom Exp $")
45
45
#if HAVE_MBTOWC && HAVE_MBLEN
46
46
#define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
76
77
* We can get a stream of single-byte characters and KEY_xxx codes from
77
78
* _nc_wgetch(), while we want to return a wide character or KEY_xxx code.
80
T(("reading %d of %d", count + 1, sizeof(buffer)));
81
code = _nc_wgetch(win, &value, TRUE);
84
} else if (code == KEY_CODE_YES) {
86
* If we were processing an incomplete multibyte character, return
87
* an error since we have a KEY_xxx code which interrupts it. For
88
* some cases, we could improve this by writing a new version of
89
* lib_getch.c(!), but it is not clear whether the improvement
90
* would be worth the effort.
80
_nc_lock_global(curses);
81
sp = _nc_screen_of(win);
84
T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
85
code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist
89
} else if (code == KEY_CODE_YES) {
91
* If we were processing an incomplete multibyte character,
92
* return an error since we have a KEY_xxx code which
93
* interrupts it. For some cases, we could improve this by
94
* writing a new version of lib_getch.c(!), but it is not clear
95
* whether the improvement would be worth the effort.
98
_nc_ungetch(sp, (int) value);
102
} else if (count + 1 >= sizeof(buffer)) {
103
_nc_ungetch(sp, (int) value);
97
} else if (count + 1 >= sizeof(buffer)) {
102
buffer[count++] = UChar(value);
104
status = count_mbytes(buffer, count, state);
107
buffer[count++] = (char) UChar(value);
106
108
reset_mbytes(state);
107
if (check_mbytes(wch, buffer, count, state) != status) {
108
code = ERR; /* the two calls should match */
109
ungetch((int) value);
109
status = count_mbytes(buffer, count, state);
112
if (check_mbytes(wch, buffer, count, state) != status) {
113
code = ERR; /* the two calls should match */
114
_nc_ungetch(sp, (int) value);
125
_nc_unlock_global(curses);
117
126
T(("result %#lo", value));
118
127
returnCode(code);