2 ** mhl.c -- the nmh message listing program
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 #include <h/signals.h>
11 #include <h/addrsbr.h>
12 #include <h/fmt_scan.h>
20 ** for a component containing addresses, ADDRFMT, if COMPRESS is also
21 ** set, then addresses get split wrong (not at the spaces between commas).
22 ** To fix this correctly, putstr() should know about "atomic" strings that
23 ** must NOT be broken across lines. That's too difficult for right now
24 ** (it turns out that there are a number of degernate cases), so in
25 ** oneline(), instead of
27 ** (*onelp == '\n' && !onelp[1])
29 ** being a terminating condition,
31 ** (*onelp == '\n' && (!onelp[1] || (flags & ADDRFMT)))
33 ** is used instead. This cuts the line prematurely, and gives us a much
34 ** better chance of getting things right.
43 static struct swit mhlswitches[] = {
45 { "folder +folder", 0 },
47 { "form formfile", 0 },
49 { "moreproc program", 0 },
51 { "width columns", 0 },
53 { "sleep seconds", 0 },
63 { "digest list", -6 },
65 { "volume number", -6 },
67 { "issue number", -5 },
73 #define NOCOMPONENT 0x000001 /* don't show component name */
74 #define UPPERCASE 0x000002 /* display in all upper case */
75 #define CENTER 0x000004 /* center line */
76 #define CLEARTEXT 0x000008 /* cleartext */
77 #define EXTRA 0x000010 /* an "extra" component */
78 #define HDROUTPUT 0x000020 /* already output */
79 #define LEFTADJUST 0x000040 /* left justify multiple lines */
80 #define COMPRESS 0x000080 /* compress text */
81 #define ADDRFMT 0x000100 /* contains addresses */
82 #define DATEFMT 0x000200 /* contains dates */
83 #define FORMAT 0x000400 /* parse address/date/RFC-2047 field */
84 #define INIT 0x000800 /* initialize component */
85 #define SPLIT 0x001000 /* split headers (don't concatenate) */
86 #define NONEWLINE 0x002000 /* don't write trailing newline */
87 #define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE"
88 #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
91 char *c_name; /* component name */
92 char *c_text; /* component text */
93 char *c_ovtxt; /* text overflow indicator */
94 char *c_nfs; /* iff FORMAT */
95 struct format *c_fmt; /* .. */
96 int c_offset; /* left margin indentation */
97 int c_ovoff; /* overflow indentation */
98 int c_width; /* width of field */
99 int c_cwidth; /* width of component */
101 struct mcomp *c_next;
104 static struct mcomp *msghd = NULL;
105 static struct mcomp *msgtl = NULL;
106 static struct mcomp *fmthd = NULL;
107 static struct mcomp *fmttl = NULL;
109 static struct mcomp global = {
110 NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 0, 0
113 static struct mcomp holder = {
114 NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, NOCOMPONENT, 0
122 static struct pair pairs[] = {
125 { "Sender", ADDRFMT },
126 { "Reply-To", ADDRFMT },
130 { "Resent-Date", DATEFMT },
131 { "Resent-From", ADDRFMT },
132 { "Resent-Sender", ADDRFMT },
133 { "Resent-Reply-To", ADDRFMT },
134 { "Resent-To", ADDRFMT },
135 { "Resent-Cc", ADDRFMT },
136 { "Resent-Bcc", ADDRFMT },
146 static struct triple triples[] = {
147 { "nocomponent", NOCOMPONENT, 0 },
148 { "uppercase", UPPERCASE, 0 },
149 { "nouppercase", 0, UPPERCASE },
150 { "center", CENTER, 0 },
151 { "nocenter", 0, CENTER },
152 { "leftadjust", LEFTADJUST, 0 },
153 { "noleftadjust", 0, LEFTADJUST },
154 { "compress", COMPRESS, 0 },
155 { "nocompress", 0, COMPRESS },
156 { "split", SPLIT, 0 },
157 { "nosplit", 0, SPLIT },
158 { "addrfield", ADDRFMT, DATEFMT },
159 { "datefield", DATEFMT, ADDRFMT },
160 { "newline", 0, NONEWLINE },
161 { "nonewline", NONEWLINE, 0 },
166 static int dobody = 1;
167 static int forwflg = 0;
168 static int forwall = 0;
170 static int sleepsw = NOTOK;
172 static char *digest = NULL;
173 static int volume = 0;
174 static int issue = 0;
176 static int exitstat = 0;
177 static int mhldebug = 0;
181 static int ontty = NOTTY;
192 static unsigned char *onelp;
196 static int num_ignores = 0;
197 static char *ignores[MAXARGS];
200 static jmp_buf mhlenv;
202 static char delim3[] =
203 "\n----------------------------------------------------------------------\n\n";
204 static char delim4[] = "\n------------------------------\n\n";
206 static FILE *(*mhl_action) () = (FILE *(*) ()) 0;
210 ** Redefine a couple of functions.
211 ** These are undefined later in the code.
213 #define adios mhladios
219 static void mhl_format(char *, int);
220 static int evalvar(struct mcomp *);
221 static int ptoi(char *, int *);
222 static int ptos(char *, char **);
223 static char *parse(void);
224 static void process(char *, char *, int, int);
225 static void mhlfile(FILE *, char *, int, int);
226 static int mcomp_flags(char *);
227 static char *mcomp_add(long, char *, char *);
228 static void mcomp_format(struct mcomp *, struct mcomp *);
229 static struct mcomp *add_queue(struct mcomp **, struct mcomp **,
230 char *, char *, int);
231 static void free_queue(struct mcomp **, struct mcomp **);
232 static void putcomp(struct mcomp *, struct mcomp *, int);
233 static char *oneline(char *, long);
234 static void putstr(char *);
235 static void putch(char);
236 static RETSIGTYPE intrser(int);
237 static RETSIGTYPE pipeser(int);
238 static RETSIGTYPE quitser(int);
239 static void mhladios(char *, char *, ...);
240 static void mhldone(int);
241 static void m_popen(char *);
245 int SOprintf(char *, ...); /* from termsbr.c */
246 int sc_width(void); /* from termsbr.c */
250 main(int argc, char **argv)
252 int i, width = 0, vecp = 0;
253 char *cp, *folder = NULL, *form = NULL;
254 char buf[BUFSIZ], *files[MAXARGS];
255 char **argp, **arguments;
259 setlocale(LC_ALL, "");
262 invo_name = mhbasename(argv[0]);
264 /* read user profile/context */
267 arguments = getarguments(invo_name, argc, argv, 1);
270 if ((cp = getenv("MHLDEBUG")) && *cp)
273 while ((cp = *argp++)) {
275 switch (smatch(++cp, mhlswitches)) {
277 ambigsw(cp, mhlswitches);
280 adios(NULL, "-%s unknown\n", cp);
283 snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
284 print_help(buf, mhlswitches, 1);
287 print_version(invo_name);
291 if (!(folder = *argp++) || *folder == '-')
292 adios(NULL, "missing argument to %s",
296 if (!(form = *argp++) || *form == '-')
297 adios(NULL, "missing argument to %s",
302 if (!(cp = *argp++) || *cp == '-')
303 adios(NULL, "missing argument to %s",
305 sleepsw = atoi(cp); /* ZERO ok! */
309 if (!(progsw = *argp++) || *progsw == '-')
310 adios(NULL, "missing argument to %s",
315 if (!(cp = *argp++) || *cp == '-')
316 adios(NULL, "missing argument to %s",
318 if ((width = atoi(cp)) < 1)
319 adios(NULL, "bad argument %s %s",
324 if (!(digest = *argp++) ||
326 adios(NULL, "missing argument to %s",
330 if (!(cp = *argp++) || *cp == '-')
331 adios(NULL, "missing argument to %s",
333 if ((issue = atoi(cp)) < 1)
334 adios(NULL, "bad argument %s %s",
338 if (!(cp = *argp++) || *cp == '-')
339 adios(NULL, "missing argument to %s",
341 if ((volume = atoi(cp)) < 1)
342 adios(NULL, "bad argument %s %s",
347 forwall++; /* fall */
361 folder = getenv("mhfolder");
363 if (isatty(fileno(stdout))) {
365 SIGNAL(SIGINT, SIG_IGN);
366 SIGNAL2(SIGQUIT, quitser);
368 SIGNAL2(SIGPIPE, pipeser);
369 m_popen(progsw ? progsw : moreproc);
375 mhl_format(form ? form : mhlformat, width);
378 process(folder, NULL, 1, vecp = 1);
380 for (i = 0; i < vecp; i++)
381 process(folder, files[i], i + 1, vecp);
386 printf("%s", delim4);
388 snprintf(buf, sizeof(buf),
389 "End of %s Digest\n", digest);
391 snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
394 for (cp = buf + i; i > 1; i--)
400 printf("\n------- End of Forwarded Message%s\n\n",
401 vecp > 1 ? "s" : "");
405 if (ferror(stdout)) {
406 adios("output", "error writing");
417 mhl_format(char *file, int width)
421 char *ap, buffer[BUFSIZ], name[NAMESZ];
425 static dev_t dev = 0;
426 static ino_t ino = 0;
427 static time_t mtime = 0;
430 if (stat(etcpath(file), &st) != NOTOK
431 && mtime == st.st_mtime
436 free_queue(&fmthd, &fmttl);
439 if ((fp = fopen(etcpath(file), "r")) == NULL)
440 adios(file, "unable to open format file");
442 if (fstat(fileno(fp), &st) != NOTOK) {
448 global.c_ovtxt = global.c_nfs = NULL;
452 if ((i = sc_width()) > 5)
454 global.c_cwidth = -1;
456 *(ip = ignores) = NULL;
458 while (vfgets(fp, &ap) == OK) {
463 if ((cp = strchr(bp, '\n')))
467 c1 = add_queue(&fmthd, &fmttl, NULL, bp + 1,
473 strncpy(name, parse(), sizeof(name));
479 ** Split this list of fields to ignore, and copy
480 ** it to the end of the current "ignores" list.
482 if (!mh_strcasecmp(name, "ignores")) {
483 char **tmparray, **p;
486 /* split the fields */
487 tmparray = brkstring(getcpy(++parptr), ",",
490 /* count number of fields split */
496 ** copy pointers to split fields
499 ip = copyip(tmparray, ip,
500 MAXARGS - num_ignores);
506 if (evalvar(&global))
507 adios(NULL, "format file syntax error: %s", bp);
514 c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT);
515 while (*parptr == ':' || *parptr == ',') {
518 adios(NULL, "format file syntax error: %s", bp);
520 if (!c1->c_nfs && global.c_nfs) {
521 if ((c1->c_flags & DATEFMT) &&
522 (global.c_flags & DATEFMT)) {
523 c1->c_nfs = getcpy(global.c_nfs);
524 } else if ((c1->c_flags & ADDRFMT) &&
525 (global.c_flags & ADDRFMT)) {
526 c1->c_nfs = getcpy(global.c_nfs);
532 adios(NULL, "format file syntax error: %s", bp);
538 for (c1 = fmthd; c1; c1 = c1->c_next) {
539 fprintf(stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", c1->c_name, c1->c_text, c1->c_ovtxt);
540 fprintf(stderr, "\tnfs=0x%x fmt=0x%x\n", (unsigned int)(unsigned long) c1->c_nfs, (unsigned int)(unsigned long) c1->c_fmt);
541 fprintf(stderr, "\toffset=%d ovoff=%d width=%d cwidth=%d\n", c1->c_offset, c1->c_ovoff, c1->c_width, c1->c_cwidth);
542 fprintf (stderr, "\tflags=%s\n", snprintb(buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS));
548 global.c_width = width;
549 if (global.c_width < 5)
550 global.c_width = 10000;
555 evalvar(struct mcomp *c1)
557 char *cp, name[NAMESZ];
562 strncpy(name, parse(), sizeof(name));
564 if (!mh_strcasecmp(name, "component")) {
565 if (ptos(name, &c1->c_text))
567 c1->c_flags &= ~NOCOMPONENT;
571 if (!mh_strcasecmp(name, "overflowtext"))
572 return ptos(name, &c1->c_ovtxt);
574 if (!mh_strcasecmp(name, "formatfield")) {
579 cp = concat("=", cp, NULL);
580 nfs = new_fs(cp, NULL);
582 c1->c_nfs = getcpy(nfs);
583 c1->c_flags |= FORMAT;
587 if (!mh_strcasecmp(name, "decode")) {
590 nfs = new_fs("=%(decode{text})", NULL);
591 c1->c_nfs = getcpy(nfs);
592 c1->c_flags |= FORMAT;
596 if (!mh_strcasecmp(name, "offset"))
597 return ptoi(name, &c1->c_offset);
598 if (!mh_strcasecmp(name, "overflowoffset"))
599 return ptoi(name, &c1->c_ovoff);
600 if (!mh_strcasecmp(name, "width"))
601 return ptoi(name, &c1->c_width);
602 if (!mh_strcasecmp(name, "compwidth"))
603 return ptoi(name, &c1->c_cwidth);
605 for (ap = triples; ap->t_name; ap++)
606 if (!mh_strcasecmp(ap->t_name, name)) {
607 c1->c_flags |= ap->t_on;
608 c1->c_flags &= ~ap->t_off;
617 ptoi(char *name, int *i)
621 if (*parptr++ != '=' || !*(cp = parse())) {
622 advise(NULL, "missing argument to variable %s", name);
632 ptos(char *name, char **s)
636 if (*parptr++ != '=') {
637 advise(NULL, "missing argument to variable %s", name);
641 if (*parptr != '"') {
642 for (cp = parptr; *parptr && *parptr != ':' && *parptr != ',';
646 for (cp = ++parptr; *parptr && *parptr != '"'; parptr++)
647 if (*parptr == QUOTE)
654 if ((*parptr = c) == '"')
665 static char result[NAMESZ];
667 for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
686 process(char *folder, char *fname, int ofilen, int ofilec)
692 switch (setjmp(env)) {
695 fp = mhl_action ? (*mhl_action) (fname) :
698 advise(fname, "unable to open");
706 cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname);
708 SIGNAL(SIGINT, intrser);
709 mhlfile(fp, cp, ofilen, ofilec);
713 SIGNAL(SIGINT, SIG_IGN);
714 if (mhl_action == NULL && fp != stdin)
719 holder.c_text = NULL;
721 free_queue(&msghd, &msgtl);
722 for (c1 = fmthd; c1; c1 = c1->c_next)
723 c1->c_flags &= ~HDROUTPUT;
730 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
733 struct mcomp *c1, *c2, *c3;
734 char **ip, name[NAMESZ], buf[BUFSIZ];
738 printf("%s", ofilen == 1 ? delim3 : delim4);
742 printf(" Forwarded Message%s",
743 ofilec > 1 ? "s" : "");
745 printf(" Message %d", ofilen);
748 } else if (ofilec > 1) {
752 printf(">>> %s\n\n", mname);
755 for (state = FLD;;) {
756 switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
759 for (ip = ignores; *ip; ip++)
760 if (!mh_strcasecmp(name, *ip)) {
761 while (state == FLDPLUS)
762 state = m_getfld(state, name, buf, sizeof(buf), fp);
768 for (c2 = fmthd; c2; c2 = c2->c_next)
769 if (!mh_strcasecmp(c2->c_name, name))
772 if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
773 for (c1 = msghd; c1; c1 = c1->c_next)
774 if (!mh_strcasecmp(c1->c_name,
776 c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
780 c1 = add_queue(&msghd, &msgtl, name, buf, 0);
781 while (state == FLDPLUS) {
782 state = m_getfld(state, name, buf,
784 c1->c_text = add(buf, c1->c_text);
787 c1->c_flags |= EXTRA;
793 for (c1 = fmthd; c1; c1 = c1->c_next) {
794 if (c1->c_flags & CLEARTEXT) {
795 putcomp(c1, c1, ONECOMP);
798 if (!mh_strcasecmp(c1->c_name, "messagename")) {
799 holder.c_text = concat("(Message ",
801 putcomp(c1, &holder, ONECOMP);
803 holder.c_text = NULL;
806 if (!mh_strcasecmp(c1->c_name, "extras")) {
807 for (c2 = msghd; c2; c2 = c2->c_next)
808 if (c2->c_flags & EXTRA)
809 putcomp(c1, c2, TWOCOMP);
812 if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
813 holder.c_text = mh_xmalloc(sizeof(buf));
814 strncpy(holder.c_text, buf, sizeof(buf));
815 while (state == BODY) {
816 putcomp(c1, &holder, BODYCOMP);
817 state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
820 holder.c_text = NULL;
823 for (c2 = msghd; c2; c2 = c2->c_next)
824 if (!mh_strcasecmp(c2->c_name,
826 putcomp(c1, c2, ONECOMP);
827 if (!(c1->c_flags & SPLIT))
835 advise(NULL, "format error in message %s", mname);
840 adios(NULL, "getfld() returned %d", state);
847 mcomp_flags(char *name)
851 for (ap = pairs; ap->p_name; ap++)
852 if (!mh_strcasecmp(ap->p_name, name))
853 return (ap->p_flags);
860 mcomp_add(long flags, char *s1, char *s2)
864 if (!(flags & ADDRFMT))
867 if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
870 return add(s1, add(",\n", s2));
877 struct pqpair *pq_next;
882 mcomp_format(struct mcomp *c1, struct mcomp *c2)
886 char buffer[BUFSIZ], error[BUFSIZ];
888 struct pqpair *p, *q;
897 dat[3] = sizeof(buffer) - 1;
899 fmt_compile(c1->c_nfs, &c1->c_fmt);
901 if (!(c1->c_flags & ADDRFMT)) {
902 FINDCOMP(cptr, "text");
905 if ((cp = strrchr(ap, '\n'))) /* drop ending newline */
909 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
910 /* Don't need to append a newline, dctime() already did */
911 c2->c_text = getcpy(buffer);
917 (q = &pq)->pq_next = NULL;
918 while ((cp = getname(ap))) {
919 if ((p = (struct pqpair *)
920 calloc((size_t) 1, sizeof(*p))) == NULL)
921 adios(NULL, "unable to allocate pqpair memory");
923 if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
924 p->pq_text = getcpy(cp);
925 p->pq_error = getcpy(error);
927 p->pq_text = getcpy(mp->m_text);
930 q = (q->pq_next = p);
933 for (p = pq.pq_next; p; p = q) {
934 FINDCOMP(cptr, "text");
936 cptr->c_text = p->pq_text;
937 FINDCOMP(cptr, "error");
939 cptr->c_text = p->pq_error;
941 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
944 c2->c_text = add(",\n", c2->c_text);
945 if (*(cp = buffer + strlen(buffer) - 1) == '\n')
947 c2->c_text = add(buffer, c2->c_text);
957 c2->c_text = add("\n", c2->c_text);
962 static struct mcomp *
963 add_queue(struct mcomp **head, struct mcomp **tail, char *name,
964 char *text, int flags)
968 if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
969 adios(NULL, "unable to allocate comp memory");
971 c1->c_flags = flags & ~INIT;
972 if ((c1->c_name = name ? getcpy(name) : NULL))
973 c1->c_flags |= mcomp_flags(c1->c_name);
974 c1->c_text = text ? getcpy(text) : NULL;
977 c1->c_ovtxt = getcpy(global.c_ovtxt);
978 c1->c_offset = global.c_offset;
979 c1->c_ovoff = global. c_ovoff;
981 c1->c_cwidth = global.c_cwidth;
982 c1->c_flags |= global.c_flags & GFLAGS;
987 (*tail)->c_next = c1;
995 free_queue(struct mcomp **head, struct mcomp **tail)
997 struct mcomp *c1, *c2;
999 for (c1 = *head; c1; c1 = c2) {
1010 free((char *) c1->c_fmt);
1014 *head = *tail = NULL;
1019 putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
1026 wid = c1->c_width ? c1->c_width : global.c_width;
1027 ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff)
1029 if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
1031 if (wid < ovoff + strlen(ovtxt) + 5)
1032 adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
1035 if (c1->c_flags & CLEARTEXT) {
1041 if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT)))
1042 mcomp_format(c1, c2);
1044 if (c1->c_flags & CENTER) {
1045 count = (c1->c_width ? c1->c_width : global.c_width)
1046 - c1->c_offset - strlen(c2->c_text);
1047 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT))
1048 count -= strlen(c1->c_text ? c1->c_text : c1->c_name)
1050 lm = c1->c_offset + (count / 2);
1056 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
1057 if (c1->c_flags & UPPERCASE) /* uppercase component also */
1058 for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
1061 putstr(c1->c_text ? c1->c_text : c1->c_name);
1062 if (flag != BODYCOMP) {
1064 if (!(c1->c_flags & SPLIT))
1065 c1->c_flags |= HDROUTPUT;
1068 if ((count = c1->c_cwidth -
1069 strlen(c1->c_text ? c1->c_text : c1->c_name) - 2) > 0)
1073 c1->c_flags |= HDROUTPUT; /* for BODYCOMP */
1076 if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT)
1077 && !(c2->c_flags & NOCOMPONENT)) {
1078 if (c1->c_flags & UPPERCASE)
1079 for (cp = c2->c_name; *cp; cp++)
1084 if (!(c1->c_flags & SPLIT))
1085 c2->c_flags |= HDROUTPUT;
1088 if ((count = c1->c_cwidth - strlen(c2->c_name) - 2) > 0)
1092 if (c1->c_flags & UPPERCASE)
1093 for (cp = c2->c_text; *cp; cp++)
1099 if (flag == TWOCOMP)
1100 count = (c1->c_cwidth >= 0) ?
1101 c1->c_cwidth : strlen(c2->c_name) + 2;
1103 count = (c1->c_cwidth >= 0) ?
1104 c1->c_cwidth : strlen(c1->c_text ?
1105 c1->c_text : c1->c_name) + 2;
1107 count += c1->c_offset;
1109 if ((cp = oneline(c2->c_text, c1->c_flags)))
1113 while ((cp = oneline(c2->c_text, c1->c_flags))) {
1115 if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT))
1116 putstr(c1->c_text ? c1->c_text : c1->c_name);
1122 if (flag == BODYCOMP && term == '\n')
1123 c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
1128 oneline(char *stuff, long flags)
1136 return (onelp = NULL);
1140 if (flags & COMPRESS) {
1141 for (spc = 1, cp = ret; *onelp; onelp++)
1142 if (isspace(*onelp)) {
1143 if (*onelp == '\n' &&
1145 (flags & ADDRFMT))) {
1160 while (*onelp && *onelp != '\n')
1162 if (*onelp == '\n') {
1166 if (flags & LEFTADJUST)
1167 while (*ret == ' ' || *ret == '\t')
1170 if (*onelp == 0 && term == '\n' && (flags & NONEWLINE))
1178 putstr(char *string)
1180 if (!column && lm > 0) {
1216 ** If we are forwarding this message, and the first
1217 ** column contains a dash, then add a dash and a space.
1219 if (column == 0 && forwflg && ch == '-') {
1228 if (column >= wid) {
1232 putstr(ovtxt ? ovtxt : "");
1244 #ifndef RELIABLE_SIGNALS
1245 SIGNAL(SIGINT, intrser);
1257 #ifndef RELIABLE_SIGNALS
1258 SIGNAL(SIGPIPE, pipeser);
1268 #ifndef RELIABLE_SIGNALS
1269 SIGNAL(SIGQUIT, quitser);
1282 mhladios(char *what, char *fmt, ...)
1287 advertise(what, NULL, fmt, ap);
1298 longjmp(mhlenv, DONE);
1304 static int m_pid = NOTOK;
1305 static int sd = NOTOK;
1312 if (mhl_action && (sd = dup(fileno(stdout))) == NOTOK)
1313 adios("standard output", "unable to dup()");
1315 if (pipe(pd) == NOTOK)
1316 adios("pipe", "unable to");
1318 switch (m_pid = fork()) {
1320 adios("fork", "unable to");
1323 SIGNAL(SIGINT, SIG_DFL);
1324 SIGNAL(SIGQUIT, SIG_DFL);
1327 if (pd[0] != fileno(stdin)) {
1328 dup2(pd[0], fileno(stdin));
1331 execlp(name, mhbasename(name), NULL);
1332 fprintf(stderr, "unable to exec ");
1338 if (pd[1] != fileno(stdout)) {
1339 dup2(pd[1], fileno(stdout));
1354 if (dup2(sd, fileno(stdout)) == NOTOK)
1355 adios("standard output", "unable to dup2()");