-#else /* LOCALE */
-#define PUTSF(cp, str, wid, fill) {\
- ljust = 0;\
- if ((i = (wid)) < 0) {\
- i = -i;\
- ljust++;\
- }\
- if (sp = (str)) {\
- if (ljust) {\
- c = strlen(sp);\
- if (c > i)\
- sp += c - i;\
- else {\
- while( --i >= c && cp < ep)\
- *cp++ = fill;\
- i++;\
- }\
- } else {\
- while ((c = *sp) && c <= 32)\
- sp++;\
- }\
- while ((c = *sp++) && --i >= 0 && cp < ep)\
- if (c > 32) \
- *cp++ = c;\
- else {\
- while ((c = *sp) && c <= 32)\
- sp++;\
- *cp++ = ' ';\
- }\
- }\
- if (!ljust)\
- while( --i >= 0 && cp < ep)\
- *cp++ = fill;\
- }
+static void
+cpstripped (char **dest, char **end, char *max, char *str)
+{
+ 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;
+ char *altstr = NULL;
+#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;
+ }