- for (;;) {
- T(("reading %d of %d", count + 1, sizeof(buffer)));
- code = _nc_wgetch(win, &value, TRUE);
- if (code == ERR) {
- break;
- } else if (code == KEY_CODE_YES) {
- /*
- * If we were processing an incomplete multibyte character, return
- * an error since we have a KEY_xxx code which interrupts it. For
- * some cases, we could improve this by writing a new version of
- * lib_getch.c(!), but it is not clear whether the improvement
- * would be worth the effort.
- */
- if (count != 0) {
- ungetch(value);
- code = ERR;
- }
- break;
- } else if (count + 1 >= sizeof(buffer)) {
- ungetch(value);
- code = ERR;
- break;
- } else {
- buffer[count++] = UChar(value);
- memset(&state, 0, sizeof(state));
- status = mbrlen(buffer, count, &state);
- if (status >= 0) {
- memset(&state, 0, sizeof(state));
- if ((int) mbrtowc(&wch, buffer, count, &state) != status) {
- code = ERR; /* the two calls should match */
+ _nc_lock_global(curses);
+ sp = _nc_screen_of(win);
+
+ if (sp != 0) {
+ size_t count = 0;
+
+ for (;;) {
+ char buffer[(MB_LEN_MAX * 9) + 1]; /* allow some redundant shifts */
+
+ T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
+ code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist
+ *) 0));
+ if (code == ERR) {
+ break;
+ } else if (code == KEY_CODE_YES) {
+ /*
+ * If we were processing an incomplete multibyte character,
+ * return an error since we have a KEY_xxx code which
+ * interrupts it. For some cases, we could improve this by
+ * writing a new version of lib_getch.c(!), but it is not clear
+ * whether the improvement would be worth the effort.
+ */
+ if (count != 0) {
+ safe_ungetch(SP_PARM, value);
+ code = ERR;