+ unsigned len = (unsigned) strlen(src);
+ NCURSES_CH_T *dst = typeMalloc(NCURSES_CH_T, len + 1);
+ size_t j, k;
+#if USE_WIDEC_SUPPORT
+ wchar_t wstr[CCHARW_MAX + 1];
+ wchar_t wch;
+ int l = 0;
+ size_t rc;
+ int width;
+#ifndef state_unused
+ mbstate_t state;
+#endif
+#endif /* USE_WIDEC_SUPPORT */
+
+#if USE_WIDEC_SUPPORT
+ reset_mbytes(state);
+#endif
+ for (j = k = 0; j < len; j++) {
+#if USE_WIDEC_SUPPORT
+ rc = (size_t) check_mbytes(wch, src + j, len - j, state);
+ if (rc == (size_t) -1 || rc == (size_t) -2) {
+ break;
+ }
+ j += rc - 1;
+ width = wcwidth(wch);
+ if (width == 0) {
+ if (l == 0) {
+ wstr[l++] = L' ';
+ }
+ } else if ((l > 0) || (l == CCHARW_MAX)) {
+ wstr[l] = L'\0';
+ l = 0;
+ if (setcchar(dst + k, wstr, 0, 0, NULL) != OK) {
+ break;
+ }
+ ++k;
+ }
+ wstr[l++] = wch;
+#else
+ dst[k++] = (chtype) UChar(src[j]);
+#endif
+ }
+#if USE_WIDEC_SUPPORT
+ if (l > 0) {
+ wstr[l] = L'\0';
+ if (setcchar(dst + k, wstr, 0, 0, NULL) == OK)
+ ++k;
+ }
+ wstr[0] = L'\0';
+ setcchar(dst + k, wstr, 0, 0, NULL);
+#else
+ dst[k] = 0;
+#endif
+ return dst;
+}
+
+int
+main(int argc, char *argv[])
+{
+ static const char *help[] =
+ {
+ "Commands:",
+ " q,^Q,ESC - quit this program",
+ "",
+ " p,<Up> - scroll the viewport up by one row",
+ " n,<Down> - scroll the viewport down by one row",
+ " l,<Left> - scroll the viewport left by one column",
+ " r,<Right> - scroll the viewport right by one column",
+ "",
+ " h,<Home> - scroll the viewport to top of file",
+ " e,<End> - scroll the viewport to end of file",
+ "",
+ " ^L - repaint using redrawwin()",
+ "",
+ " 0 through 9 - enter digits for count",
+ " s - use entered count for halfdelay() parameter",
+ " - if no entered count, stop nodelay()",
+ " <space> - begin nodelay()",
+ 0
+ };
+
+ int MAXLINES = 1000;
+ FILE *fp;
+ char buf[BUFSIZ];
+ int i;
+ int my_delay = 0;
+ NCURSES_CH_T **olptr;
+ int value = 0;
+ bool done = FALSE;
+ bool got_number = FALSE;
+ bool single_step = FALSE;