There is already trimcpy(), which does a bit more work, but adding trim()
appears to be a useful investment.
The static function trim() in slocal needed to be renamed to not collide.
char *snprintb(char *, size_t, unsigned, char *);
int stringdex(char *, char *);
char *toabsdir(char *);
char *snprintb(char *, size_t, unsigned, char *);
int stringdex(char *, char *);
char *toabsdir(char *);
+char *trim(unsigned char *);
char *trimcpy(unsigned char *);
int unputenv(char *);
int uprf(char *, char *);
char *trimcpy(unsigned char *);
int unputenv(char *);
int uprf(char *, char *);
seq_print.c seq_read.c seq_save.c seq_setcur.c \
seq_setprev.c seq_setunseen.c signals.c \
smatch.c snprintb.c strcasecmp.c \
seq_print.c seq_read.c seq_save.c seq_setcur.c \
seq_setprev.c seq_setunseen.c signals.c \
smatch.c snprintb.c strcasecmp.c \
- strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c \
+ strindex.c trim.c trimcpy.c uprf.c vfgets.c fmt_def.c \
mf.c utils.c m_mktemp.c
OBJS = $(SRCS:.c=.o)
mf.c utils.c m_mktemp.c
OBJS = $(SRCS:.c=.o)
--- /dev/null
+/*
+** trim.c -- strip leading and trailing whitespace ... inplace!
+**
+** This code is Copyright (c) 2002, by the authors of nmh. See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
+
+#include <h/mh.h>
+
+
+char *
+trim(unsigned char *cp)
+{
+ unsigned char *sp;
+
+ /* skip over leading whitespace */
+ while (isspace(*cp)) {
+ cp++;
+ }
+
+ /* start at the end and zap trailing whitespace */
+ for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) {
+ if (isspace(*sp)) {
+ *sp = '\0';
+ } else {
+ break;
+ }
+ }
+
+ return cp;
+}
static void verbose_printf(char *fmt, ...);
static void adorn(char *, char *, ...);
static void debug_printf(char *fmt, ...);
static void verbose_printf(char *fmt, ...);
static void adorn(char *, char *, ...);
static void debug_printf(char *fmt, ...);
-static char *trim(char *);
+static char *trimstr(char *);
- debug_printf("addr=\"%s\"\n", trim(addr));
- debug_printf("user=\"%s\"\n", trim(user));
- debug_printf("info=\"%s\"\n", trim(info));
- debug_printf("sender=\"%s\"\n", trim(sender));
+ debug_printf("addr=\"%s\"\n", trimstr(addr));
+ debug_printf("user=\"%s\"\n", trimstr(user));
+ debug_printf("info=\"%s\"\n", trimstr(info));
+ debug_printf("sender=\"%s\"\n", trimstr(sender));
debug_printf("envelope=\"%s\"\n",
debug_printf("envelope=\"%s\"\n",
- envelope ? trim(envelope) : "");
- debug_printf("mbox=\"%s\"\n", trim(mbox));
- debug_printf("home=\"%s\"\n", trim(home));
- debug_printf("ddate=\"%s\"\n", trim(ddate));
+ envelope ? trimstr(envelope) : "");
+ debug_printf("mbox=\"%s\"\n", trimstr(mbox));
+ debug_printf("home=\"%s\"\n", trimstr(home));
+ debug_printf("ddate=\"%s\"\n", trimstr(ddate));
debug_printf("now=%02d:%02d\n\n", now->tw_hour, now->tw_min);
}
debug_printf("now=%02d:%02d\n\n", now->tw_hour, now->tw_min);
}
if (debug) {
for (i = 0; vec[i]; i++) {
debug_printf("vec[%d]: \"%s\"\n",
if (debug) {
for (i = 0; vec[i]; i++) {
debug_printf("vec[%d]: \"%s\"\n",
p->p_flags &= ~P_CHK;
if (debug) {
debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
p->p_flags &= ~P_CHK;
if (debug) {
debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
- p - vars, p->p_name, trim(p->p_value));
+ p - vars, p->p_name, trimstr(p->p_value));
}
}
if (debug) {
for (p = hdrs; p->p_name; p++) {
debug_printf("hdrs[%d]: name=\"%s\" value=\"%s\"\n",
p - hdrs, p->p_name,
}
}
if (debug) {
for (p = hdrs; p->p_name; p++) {
debug_printf("hdrs[%d]: name=\"%s\" value=\"%s\"\n",
p - hdrs, p->p_name,
- p->p_value ? trim(p->p_value) : "");
+ p->p_value ? trimstr(p->p_value) : "");
if (debug) {
for (p = vars; p->p_name; p++) {
debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
if (debug) {
for (p = vars; p->p_name; p++) {
debug_printf("vars[%d]: name=\"%s\" value=\"%s\"\n",
- p - vars, p->p_name, trim(p->p_value));
+ p - vars, p->p_name, trimstr(p->p_value));
** Trim strings for pretty printing of debugging output
*/
static char *
** Trim strings for pretty printing of debugging output
*/
static char *
{
char buffer[BUFSIZ*4];
unsigned char *bp, *sp;
{
char buffer[BUFSIZ*4];
unsigned char *bp, *sp;