- int prevCtrl = 1; /* This is 1 so we strip out leading spaces */
- int len;
-#ifdef MULTIBYTE_SUPPORT
- int char_len, w;
- wchar_t wide_char;
-#endif /* MULTIBYTE_SUPPORT */
-
- if (!str)
- return;
-
- len = strlen(str);
-
-#ifdef MULTIBYTE_SUPPORT
- mbtowc(NULL, NULL, 0); /* Reset shift state */
-#endif /* MULTIBYTE_SUPPORT */
-
- /*
- * Process each character at a time; if we have multibyte support
- * then deal with that here.
- */
-
- while (*str != '\0' && len > 0 && *dest < *end) {
-#ifdef MULTIBYTE_SUPPORT
- char_len = mbtowc(&wide_char, str, len);
- w = wcwidth(wide_char);
-
- /*
- * Account for multibyte characters, and increment the end pointer
- * by the number of "extra" bytes in this character. That's the
- * character length (char_len) minus the column width (w).
- */
- if (char_len > 1 && max - *end >= char_len - w) {
- *end += char_len - w;
- }
-
- if (char_len <= 0 || *dest + char_len > *end)
- break;
-
- len -= char_len;
+ static bool deja_vu;
+ static char oddchar[MB_LEN_MAX * 2];
+ static size_t oddlen;
+ static char spacechar[MB_LEN_MAX * 2];
+ static size_t spacelen;
+ char *end;
+ bool squash;
+ char *src;
+ int srclen;
+ wchar_t rune;
+ int w;