#define DATEFMT 0x000800 /* contains dates */
#define FORMAT 0x001000 /* parse address/date/RFC-2047 field */
#define INIT 0x002000 /* initialize component */
+#define RTRIM 0x004000 /* trim trailing whitespace */
#define SPLIT 0x010000 /* split headers (don't concatenate) */
#define NONEWLINE 0x020000 /* don't write trailing newline */
#define NOWRAP 0x040000 /* Don't wrap lines ever */
#define FMTFILTER 0x080000 /* Filter through format filter */
-#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER"
+#define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017RTRIM\021SPLIT\022NONEWLINE\023NOWRAP\024FMTFILTER"
#define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT | NOWRAP)
/*
{ "nocompress", 0, COMPRESS },
{ "split", SPLIT, 0 },
{ "nosplit", 0, SPLIT },
+ { "rtrim", RTRIM, 0 },
+ { "nortrim", 0, RTRIM },
{ "addrfield", ADDRFMT, DATEFMT },
{ "bell", BELL, 0 },
{ "nobell", 0, BELL },
case SLEEPSW:
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
- sleepsw = atoi (cp);/* ZERO ok! */
+ else
+ sleepsw = atoi (cp);/* ZERO ok! */
continue;
case PROGSW:
case LENSW:
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
- if ((length = atoi (cp)) < 1)
+ else if ((length = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
case WIDTHSW:
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
- if ((width = atoi (cp)) < 1)
+ else if ((width = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
case ISSUESW:
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
- if ((issue = atoi (cp)) < 1)
+ else if ((issue = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
case VOLUMSW:
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
- if ((volume = atoi (cp)) < 1)
+ else if ((volume = atoi (cp)) < 1)
adios (NULL, "bad argument %s %s", argp[-2], cp);
continue;
*cp = 0;
if (*bp == ':') {
- c1 = add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
+ (void) add_queue (&fmthd, &fmttl, NULL, bp + 1, CLEARTEXT);
continue;
}
return 1;
}
- args = (struct arglist *) calloc((size_t) 1, sizeof(struct arglist));
+ args = (struct arglist *) mh_xcalloc ((size_t) 1, sizeof(struct arglist));
if (arglist_tail)
arglist_tail->a_next = args;
}
fflush (stdout);
buf[0] = 0;
- read (fileno (stdout), buf, sizeof(buf));
+ if (read (fileno (stdout), buf, sizeof(buf)) < 0) {
+ advise ("stdout", "read");
+ }
}
if (strchr(buf, '\n')) {
if ((global.c_flags & CLEARSCR))
(q = &pq)->pq_next = NULL;
while ((cp = getname (ap))) {
- if ((p = (struct pqpair *) calloc ((size_t) 1, sizeof(*p))) == NULL)
+ if ((p = (struct pqpair *) mh_xcalloc ((size_t) 1, sizeof(*p))) == NULL)
adios (NULL, "unable to allocate pqpair memory");
-
- if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
- p->pq_text = getcpy (cp);
- p->pq_error = getcpy (error);
- } else {
- p->pq_text = getcpy (mp->m_text);
- mnfree (mp);
+ else {
+ if ((mp = getm (cp, NULL, 0, error, sizeof(error))) == NULL) {
+ p->pq_text = getcpy (cp);
+ p->pq_error = getcpy (error);
+ } else {
+ p->pq_text = getcpy (mp->m_text);
+ mnfree (mp);
+ }
+ q = (q->pq_next = p);
}
- q = (q->pq_next = p);
}
for (p = pq.pq_next; p; p = q) {
{
struct mcomp *c1;
- if ((c1 = (struct mcomp *) calloc ((size_t) 1, sizeof(*c1))) == NULL)
+ if ((c1 = (struct mcomp *) mh_xcalloc ((size_t) 1, sizeof(*c1))) == NULL)
adios (NULL, "unable to allocate comp memory");
-
- c1->c_flags = flags & ~INIT;
- if ((c1->c_name = name ? getcpy (name) : NULL))
- c1->c_flags |= mcomp_flags (c1->c_name);
- c1->c_text = text ? getcpy (text) : NULL;
- if (flags & INIT) {
- if (global.c_ovtxt)
- c1->c_ovtxt = getcpy (global.c_ovtxt);
- c1->c_offset = global.c_offset;
- c1->c_ovoff = global. c_ovoff;
- c1->c_width = c1->c_length = 0;
- c1->c_cwidth = global.c_cwidth;
- c1->c_flags |= global.c_flags & GFLAGS;
+ else {
+ c1->c_flags = flags & ~INIT;
+ if ((c1->c_name = name ? getcpy (name) : NULL))
+ c1->c_flags |= mcomp_flags (c1->c_name);
+ c1->c_text = text ? getcpy (text) : NULL;
+ if (flags & INIT) {
+ if (global.c_ovtxt)
+ c1->c_ovtxt = getcpy (global.c_ovtxt);
+ c1->c_offset = global.c_offset;
+ c1->c_ovoff = global. c_ovoff;
+ c1->c_width = c1->c_length = 0;
+ c1->c_cwidth = global.c_cwidth;
+ c1->c_flags |= global.c_flags & GFLAGS;
+ }
}
if (*head == NULL)
*head = c1;
{
int count, cchdr;
char *cp;
+ /*
+ * Create a copy of c1->c_text with trailing whitespace
+ * trimmed, for use with blank lines.
+ */
+ char *trimmed_prefix =
+ rtrim (add (c1->c_text ? c1->c_text : c1->c_name, NULL));
cchdr = 0;
lm = 0;
onelp = NULL;
if (c1->c_flags & CLEARTEXT) {
- putstr (c1->c_text, c1->c_flags);
+ putstr (c1->c_flags & RTRIM ? rtrim (c1->c_text) : c1->c_text,
+ c1->c_flags);
putstr ("\n", c1->c_flags);
return;
}
count += c1->c_offset;
if ((cp = oneline (c2->c_text, c1->c_flags)))
- putstr(cp, c1->c_flags);
+ /* Output line, trimming trailing whitespace if requested. */
+ putstr (c1->c_flags & RTRIM ? rtrim (cp) : cp, c1->c_flags);
if (term == '\n')
putstr ("\n", c1->c_flags);
while ((cp = oneline (c2->c_text, c1->c_flags))) {
lm = count;
if (flag == BODYCOMP
- && !(c1->c_flags & NOCOMPONENT))
- putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags);
- if (*cp)
- putstr (cp, c1->c_flags);
+ && !(c1->c_flags & NOCOMPONENT)) {
+ /* Output component, trimming trailing whitespace if there
+ is no text on the line. */
+ if (*cp) {
+ putstr (c1->c_text ? c1->c_text : c1->c_name, c1->c_flags);
+ } else {
+ putstr (trimmed_prefix, c1->c_flags);
+ }
+ }
+ if (*cp) {
+ /* Output line, trimming trailing whitespace if requested. */
+ putstr (c1->c_flags & RTRIM ? rtrim (cp) : cp, c1->c_flags);
+ }
if (term == '\n')
putstr ("\n", c1->c_flags);
}
if (flag == BODYCOMP && term == '\n')
c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
+
+ free (trimmed_prefix);
}
putchar ('\007');
fflush (stdout);
buf[0] = 0;
- read (fileno (stdout), buf, sizeof(buf));
+ if (read (fileno (stdout), buf, sizeof(buf)) < 0) {
+ advise ("stdout", "read");
+ }
if (strchr(buf, '\n')) {
if (global.c_flags & CLEARSCR)
nmh_clear_screen ();
while (state == BODY) {
int bufsz2 = bufsz;
- write(fdinput[1], buf, strlen(buf));
+ if (write(fdinput[1], buf, strlen(buf)) < 0) {
+ advise ("pipe output", "write");
+ }
state = m_getfld (&gstate, name, buf, &bufsz2, fp);
}