-#define PUTS(cp, str) {\
- if ((sp = (str))) {\
- while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
- sp++;\
- while((c = (unsigned char) *sp++) && cp < ep)\
- if (!iscntrl(c) && !isspace(c)) \
- *cp++ = c;\
- else {\
- while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
- sp++;\
- *cp++ = ' ';\
- }\
- }\
+static void
+cpstripped (char **start, char *end, char *str)
+{
+ int c;
+ char *s = str;
+
+ if (!s)
+ return;
+
+ /* skip any initial control characters or spaces */
+ while ((c = (unsigned char) *s) &&
+#ifdef LOCALE
+ (iscntrl(c) || isspace(c)))
+#else
+ (c <= 32))
+#endif
+ s++;
+
+ /* compact repeated control characters and spaces into a single space */
+ while((c = (unsigned char) *s++) && *start < end)
+ if (!iscntrl(c) && !isspace(c))
+ *(*start)++ = c;
+ else {
+ while ((c = (unsigned char) *s) &&
+#ifdef LOCALE
+ (iscntrl(c) || isspace(c)))
+#else
+ (c <= 32))
+#endif
+ s++;
+ *(*start)++ = ' ';