char **copyip (char **, char **, int);
void cpydata (int, int, char *, char *);
void cpydgst (int, int, char *, char *);
+char *cpytrim (const char *);
int decode_rfc2047 (char *, char *, size_t);
void discard (FILE *);
int default_done (int);
*/
#include <h/mh.h>
+#include <h/utils.h>
char *
/* now return a copy */
return getcpy(cp);
}
+
+
+/*
+ * cpytrim() -- return a copy of the argument with:
+ * -- stripped leading and trailing whitespace, and
+ * -- internal whitespace replaced with spaces.
+ *
+ * This code is Copyright (c) 2013, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+char *
+cpytrim (const char *sp) {
+ char *dp;
+ char *cp;
+
+ /* skip over leading whitespace */
+ while (isspace ((unsigned char) *sp)) ++sp;
+
+ dp = add (sp, NULL);
+
+ /* start at the end and zap trailing whitespace */
+ for (cp = dp + strlen (dp) - 1;
+ cp >= dp && isspace ((unsigned char) *cp);
+ *cp-- = '\0') continue;
+
+ /* replace remaining whitespace with spaces */
+ for (cp = dp; *cp; ++cp) {
+ if (isspace ((unsigned char) *cp)) *cp = ' ';
+ }
+
+ return dp;
+}
if (ct->c_descr) {
char *dp;
- dp = trimcpy (cp = add (ct->c_descr, NULL));
- free (cp);
+ dp = cpytrim (ct->c_descr);
printf (LSTFMT2d1, dp);
free (dp);
}
if (ci->ci_comment) {
char *dp;
- dp = trimcpy (cp = add (ci->ci_comment, NULL));
- free (cp);
+ dp = cpytrim (ci->ci_comment);
snprintf (buffer, sizeof(buffer), "(%s)", dp);
free (dp);
printf (LSTFMT2d2, buffer);