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_fstr; /* 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 sc_width(void); /* from termsbr.c */
249 main(int argc, char **argv)
251 int i, width = 0, vecp = 0;
252 char *cp, *folder = NULL, *form = NULL;
253 char buf[BUFSIZ], *files[MAXARGS];
254 char **argp, **arguments;
258 setlocale(LC_ALL, "");
261 invo_name = mhbasename(argv[0]);
263 /* read user profile/context */
266 arguments = getarguments(invo_name, argc, argv, 1);
269 if ((cp = getenv("MHLDEBUG")) && *cp)
272 while ((cp = *argp++)) {
274 switch (smatch(++cp, mhlswitches)) {
276 ambigsw(cp, mhlswitches);
279 adios(NULL, "-%s unknown\n", cp);
282 snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
283 print_help(buf, mhlswitches, 1);
286 print_version(invo_name);
290 if (!(folder = *argp++) || *folder == '-')
291 adios(NULL, "missing argument to %s",
295 if (!(form = *argp++) || *form == '-')
296 adios(NULL, "missing argument to %s",
301 if (!(cp = *argp++) || *cp == '-')
302 adios(NULL, "missing argument to %s",
304 sleepsw = atoi(cp); /* ZERO ok! */
308 if (!(progsw = *argp++) || *progsw == '-')
309 adios(NULL, "missing argument to %s",
314 if (!(cp = *argp++) || *cp == '-')
315 adios(NULL, "missing argument to %s",
317 if ((width = atoi(cp)) < 1)
318 adios(NULL, "bad argument %s %s",
323 if (!(digest = *argp++) ||
325 adios(NULL, "missing argument to %s",
329 if (!(cp = *argp++) || *cp == '-')
330 adios(NULL, "missing argument to %s",
332 if ((issue = atoi(cp)) < 1)
333 adios(NULL, "bad argument %s %s",
337 if (!(cp = *argp++) || *cp == '-')
338 adios(NULL, "missing argument to %s",
340 if ((volume = atoi(cp)) < 1)
341 adios(NULL, "bad argument %s %s",
346 forwall++; /* fall */
360 folder = getenv("mhfolder");
362 if (isatty(fileno(stdout))) {
364 SIGNAL(SIGINT, SIG_IGN);
365 SIGNAL2(SIGQUIT, quitser);
367 SIGNAL2(SIGPIPE, pipeser);
368 m_popen(progsw ? progsw : moreproc);
374 mhl_format(form ? form : mhlformat, width);
377 process(folder, NULL, 1, vecp = 1);
379 for (i = 0; i < vecp; i++)
380 process(folder, files[i], i + 1, vecp);
385 printf("%s", delim4);
387 snprintf(buf, sizeof(buf),
388 "End of %s Digest\n", digest);
390 snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
393 for (cp = buf + i; i > 1; i--)
399 printf("\n------- End of Forwarded Message%s\n\n",
400 vecp > 1 ? "s" : "");
404 if (ferror(stdout)) {
405 adios("output", "error writing");
416 mhl_format(char *file, int width)
420 char *ap, buffer[BUFSIZ], name[NAMESZ];
424 static dev_t dev = 0;
425 static ino_t ino = 0;
426 static time_t mtime = 0;
429 if (stat(etcpath(file), &st) != NOTOK
430 && mtime == st.st_mtime
435 free_queue(&fmthd, &fmttl);
438 if ((fp = fopen(etcpath(file), "r")) == NULL)
439 adios(file, "unable to open format file");
441 if (fstat(fileno(fp), &st) != NOTOK) {
447 global.c_ovtxt = global.c_fstr = NULL;
451 if ((i = sc_width()) > 5)
453 global.c_cwidth = -1;
455 *(ip = ignores) = NULL;
457 while (vfgets(fp, &ap) == OK) {
462 if ((cp = strchr(bp, '\n')))
466 c1 = add_queue(&fmthd, &fmttl, NULL, bp + 1,
472 strncpy(name, parse(), sizeof(name));
478 ** Split this list of fields to ignore, and copy
479 ** it to the end of the current "ignores" list.
481 if (!mh_strcasecmp(name, "ignores")) {
482 char **tmparray, **p;
485 /* split the fields */
486 tmparray = brkstring(getcpy(++parptr), ",",
489 /* count number of fields split */
495 ** copy pointers to split fields
498 ip = copyip(tmparray, ip,
499 MAXARGS - num_ignores);
505 if (evalvar(&global))
506 adios(NULL, "format file syntax error: %s", bp);
513 c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT);
514 while (*parptr == ':' || *parptr == ',') {
517 adios(NULL, "format file syntax error: %s", bp);
519 if (!c1->c_fstr && global.c_fstr) {
520 if ((c1->c_flags & DATEFMT) &&
521 (global.c_flags & DATEFMT)) {
522 c1->c_fstr = getcpy(global.c_fstr);
523 } else if ((c1->c_flags & ADDRFMT) &&
524 (global.c_flags & ADDRFMT)) {
525 c1->c_fstr = getcpy(global.c_fstr);
531 adios(NULL, "format file syntax error: %s", bp);
537 for (c1 = fmthd; c1; c1 = c1->c_next) {
538 fprintf(stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", c1->c_name, c1->c_text, c1->c_ovtxt);
539 fprintf(stderr, "\tfstr=0x%x fmt=0x%x\n", (unsigned int)(unsigned long) c1->c_fstr, (unsigned int)(unsigned long) c1->c_fmt);
540 fprintf(stderr, "\toffset=%d ovoff=%d width=%d cwidth=%d\n", c1->c_offset, c1->c_ovoff, c1->c_width, c1->c_cwidth);
541 fprintf (stderr, "\tflags=%s\n", snprintb(buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS));
547 global.c_width = width;
548 if (global.c_width < 5)
549 global.c_width = 10000;
554 evalvar(struct mcomp *c1)
556 char *cp, name[NAMESZ];
561 strncpy(name, parse(), sizeof(name));
563 if (!mh_strcasecmp(name, "component")) {
564 if (ptos(name, &c1->c_text))
566 c1->c_flags &= ~NOCOMPONENT;
570 if (!mh_strcasecmp(name, "overflowtext"))
571 return ptos(name, &c1->c_ovtxt);
573 if (!mh_strcasecmp(name, "formatfield")) {
578 cp = concat("=", cp, NULL);
579 fmtstr = new_fs(cp, NULL);
581 c1->c_fstr = getcpy(fmtstr);
582 c1->c_flags |= FORMAT;
586 if (!mh_strcasecmp(name, "decode")) {
589 fmtstr = new_fs("=%(decode{text})", NULL);
590 c1->c_fstr = getcpy(fmtstr);
591 c1->c_flags |= FORMAT;
595 if (!mh_strcasecmp(name, "offset"))
596 return ptoi(name, &c1->c_offset);
597 if (!mh_strcasecmp(name, "overflowoffset"))
598 return ptoi(name, &c1->c_ovoff);
599 if (!mh_strcasecmp(name, "width"))
600 return ptoi(name, &c1->c_width);
601 if (!mh_strcasecmp(name, "compwidth"))
602 return ptoi(name, &c1->c_cwidth);
604 for (ap = triples; ap->t_name; ap++)
605 if (!mh_strcasecmp(ap->t_name, name)) {
606 c1->c_flags |= ap->t_on;
607 c1->c_flags &= ~ap->t_off;
616 ptoi(char *name, int *i)
620 if (*parptr++ != '=' || !*(cp = parse())) {
621 advise(NULL, "missing argument to variable %s", name);
631 ptos(char *name, char **s)
635 if (*parptr++ != '=') {
636 advise(NULL, "missing argument to variable %s", name);
640 if (*parptr != '"') {
641 for (cp = parptr; *parptr && *parptr != ':' && *parptr != ',';
645 for (cp = ++parptr; *parptr && *parptr != '"'; parptr++)
646 if (*parptr == QUOTE)
653 if ((*parptr = c) == '"')
664 static char result[NAMESZ];
666 for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
685 process(char *folder, char *fname, int ofilen, int ofilec)
691 switch (setjmp(env)) {
694 fp = mhl_action ? (*mhl_action) (fname) :
697 advise(fname, "unable to open");
705 cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname);
707 SIGNAL(SIGINT, intrser);
708 mhlfile(fp, cp, ofilen, ofilec);
712 SIGNAL(SIGINT, SIG_IGN);
713 if (mhl_action == NULL && fp != stdin)
718 holder.c_text = NULL;
720 free_queue(&msghd, &msgtl);
721 for (c1 = fmthd; c1; c1 = c1->c_next)
722 c1->c_flags &= ~HDROUTPUT;
729 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
732 struct mcomp *c1, *c2, *c3;
733 char **ip, name[NAMESZ], buf[BUFSIZ];
737 printf("%s", ofilen == 1 ? delim3 : delim4);
741 printf(" Forwarded Message%s",
742 ofilec > 1 ? "s" : "");
744 printf(" Message %d", ofilen);
747 } else if (ofilec > 1) {
751 printf(">>> %s\n\n", mname);
754 for (state = FLD;;) {
755 switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
758 for (ip = ignores; *ip; ip++)
759 if (!mh_strcasecmp(name, *ip)) {
760 while (state == FLDPLUS)
761 state = m_getfld(state, name, buf, sizeof(buf), fp);
767 for (c2 = fmthd; c2; c2 = c2->c_next)
768 if (!mh_strcasecmp(c2->c_name, name))
771 if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
772 for (c1 = msghd; c1; c1 = c1->c_next)
773 if (!mh_strcasecmp(c1->c_name,
775 c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
779 c1 = add_queue(&msghd, &msgtl, name, buf, 0);
780 while (state == FLDPLUS) {
781 state = m_getfld(state, name, buf,
783 c1->c_text = add(buf, c1->c_text);
786 c1->c_flags |= EXTRA;
792 for (c1 = fmthd; c1; c1 = c1->c_next) {
793 if (c1->c_flags & CLEARTEXT) {
794 putcomp(c1, c1, ONECOMP);
797 if (!mh_strcasecmp(c1->c_name, "messagename")) {
798 holder.c_text = concat("(Message ",
800 putcomp(c1, &holder, ONECOMP);
802 holder.c_text = NULL;
805 if (!mh_strcasecmp(c1->c_name, "extras")) {
806 for (c2 = msghd; c2; c2 = c2->c_next)
807 if (c2->c_flags & EXTRA)
808 putcomp(c1, c2, TWOCOMP);
811 if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
812 holder.c_text = mh_xmalloc(sizeof(buf));
813 strncpy(holder.c_text, buf, sizeof(buf));
814 while (state == BODY) {
815 putcomp(c1, &holder, BODYCOMP);
816 state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
819 holder.c_text = NULL;
822 for (c2 = msghd; c2; c2 = c2->c_next)
823 if (!mh_strcasecmp(c2->c_name,
825 putcomp(c1, c2, ONECOMP);
826 if (!(c1->c_flags & SPLIT))
834 advise(NULL, "format error in message %s", mname);
839 adios(NULL, "getfld() returned %d", state);
846 mcomp_flags(char *name)
850 for (ap = pairs; ap->p_name; ap++)
851 if (!mh_strcasecmp(ap->p_name, name))
852 return (ap->p_flags);
859 mcomp_add(long flags, char *s1, char *s2)
863 if (!(flags & ADDRFMT))
866 if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
869 return add(s1, add(",\n", s2));
876 struct pqpair *pq_next;
881 mcomp_format(struct mcomp *c1, struct mcomp *c2)
885 char buffer[BUFSIZ], error[BUFSIZ];
887 struct pqpair *p, *q;
896 dat[3] = sizeof(buffer) - 1;
898 fmt_compile(c1->c_fstr, &c1->c_fmt);
900 if (!(c1->c_flags & ADDRFMT)) {
901 FINDCOMP(cptr, "text");
904 if ((cp = strrchr(ap, '\n'))) /* drop ending newline */
908 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
909 /* Don't need to append a newline, dctime() already did */
910 c2->c_text = getcpy(buffer);
916 (q = &pq)->pq_next = NULL;
917 while ((cp = getname(ap))) {
918 if ((p = (struct pqpair *)
919 calloc((size_t) 1, sizeof(*p))) == NULL)
920 adios(NULL, "unable to allocate pqpair memory");
922 if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
923 p->pq_text = getcpy(cp);
924 p->pq_error = getcpy(error);
926 p->pq_text = getcpy(mp->m_text);
929 q = (q->pq_next = p);
932 for (p = pq.pq_next; p; p = q) {
933 FINDCOMP(cptr, "text");
935 cptr->c_text = p->pq_text;
936 FINDCOMP(cptr, "error");
938 cptr->c_text = p->pq_error;
940 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
943 c2->c_text = add(",\n", c2->c_text);
944 if (*(cp = buffer + strlen(buffer) - 1) == '\n')
946 c2->c_text = add(buffer, c2->c_text);
956 c2->c_text = add("\n", c2->c_text);
961 static struct mcomp *
962 add_queue(struct mcomp **head, struct mcomp **tail, char *name,
963 char *text, int flags)
967 if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
968 adios(NULL, "unable to allocate comp memory");
970 c1->c_flags = flags & ~INIT;
971 if ((c1->c_name = name ? getcpy(name) : NULL))
972 c1->c_flags |= mcomp_flags(c1->c_name);
973 c1->c_text = text ? getcpy(text) : NULL;
976 c1->c_ovtxt = getcpy(global.c_ovtxt);
977 c1->c_offset = global.c_offset;
978 c1->c_ovoff = global. c_ovoff;
980 c1->c_cwidth = global.c_cwidth;
981 c1->c_flags |= global.c_flags & GFLAGS;
986 (*tail)->c_next = c1;
994 free_queue(struct mcomp **head, struct mcomp **tail)
996 struct mcomp *c1, *c2;
998 for (c1 = *head; c1; c1 = c2) {
1009 free((char *) c1->c_fmt);
1013 *head = *tail = NULL;
1018 putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
1025 wid = c1->c_width ? c1->c_width : global.c_width;
1026 ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff)
1028 if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
1030 if (wid < ovoff + strlen(ovtxt) + 5)
1031 adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
1034 if (c1->c_flags & CLEARTEXT) {
1040 if (c1->c_fstr && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT)))
1041 mcomp_format(c1, c2);
1043 if (c1->c_flags & CENTER) {
1044 count = (c1->c_width ? c1->c_width : global.c_width)
1045 - c1->c_offset - strlen(c2->c_text);
1046 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT))
1047 count -= strlen(c1->c_text ? c1->c_text : c1->c_name)
1049 lm = c1->c_offset + (count / 2);
1055 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
1056 if (c1->c_flags & UPPERCASE) /* uppercase component also */
1057 for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
1060 putstr(c1->c_text ? c1->c_text : c1->c_name);
1061 if (flag != BODYCOMP) {
1063 if (!(c1->c_flags & SPLIT))
1064 c1->c_flags |= HDROUTPUT;
1067 if ((count = c1->c_cwidth -
1068 strlen(c1->c_text ? c1->c_text : c1->c_name) - 2) > 0)
1072 c1->c_flags |= HDROUTPUT; /* for BODYCOMP */
1075 if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT)
1076 && !(c2->c_flags & NOCOMPONENT)) {
1077 if (c1->c_flags & UPPERCASE)
1078 for (cp = c2->c_name; *cp; cp++)
1083 if (!(c1->c_flags & SPLIT))
1084 c2->c_flags |= HDROUTPUT;
1087 if ((count = c1->c_cwidth - strlen(c2->c_name) - 2) > 0)
1091 if (c1->c_flags & UPPERCASE)
1092 for (cp = c2->c_text; *cp; cp++)
1098 if (flag == TWOCOMP)
1099 count = (c1->c_cwidth >= 0) ?
1100 c1->c_cwidth : strlen(c2->c_name) + 2;
1102 count = (c1->c_cwidth >= 0) ?
1103 c1->c_cwidth : strlen(c1->c_text ?
1104 c1->c_text : c1->c_name) + 2;
1106 count += c1->c_offset;
1108 if ((cp = oneline(c2->c_text, c1->c_flags)))
1112 while ((cp = oneline(c2->c_text, c1->c_flags))) {
1114 if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT))
1115 putstr(c1->c_text ? c1->c_text : c1->c_name);
1121 if (flag == BODYCOMP && term == '\n')
1122 c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
1127 oneline(char *stuff, long flags)
1135 return (onelp = NULL);
1139 if (flags & COMPRESS) {
1140 for (spc = 1, cp = ret; *onelp; onelp++)
1141 if (isspace(*onelp)) {
1142 if (*onelp == '\n' &&
1144 (flags & ADDRFMT))) {
1159 while (*onelp && *onelp != '\n')
1161 if (*onelp == '\n') {
1165 if (flags & LEFTADJUST)
1166 while (*ret == ' ' || *ret == '\t')
1169 if (*onelp == 0 && term == '\n' && (flags & NONEWLINE))
1177 putstr(char *string)
1179 if (!column && lm > 0) {
1215 ** If we are forwarding this message, and the first
1216 ** column contains a dash, then add a dash and a space.
1218 if (column == 0 && forwflg && ch == '-') {
1227 if (column >= wid) {
1231 putstr(ovtxt ? ovtxt : "");
1243 #ifndef RELIABLE_SIGNALS
1244 SIGNAL(SIGINT, intrser);
1256 #ifndef RELIABLE_SIGNALS
1257 SIGNAL(SIGPIPE, pipeser);
1267 #ifndef RELIABLE_SIGNALS
1268 SIGNAL(SIGQUIT, quitser);
1281 mhladios(char *what, char *fmt, ...)
1286 advertise(what, NULL, fmt, ap);
1297 longjmp(mhlenv, DONE);
1303 static int m_pid = NOTOK;
1304 static int sd = NOTOK;
1311 if (mhl_action && (sd = dup(fileno(stdout))) == NOTOK)
1312 adios("standard output", "unable to dup()");
1314 if (pipe(pd) == NOTOK)
1315 adios("pipe", "unable to");
1317 switch (m_pid = fork()) {
1319 adios("fork", "unable to");
1322 SIGNAL(SIGINT, SIG_DFL);
1323 SIGNAL(SIGQUIT, SIG_DFL);
1326 if (pd[0] != fileno(stdin)) {
1327 dup2(pd[0], fileno(stdin));
1330 execlp(name, mhbasename(name), NULL);
1331 fprintf(stderr, "unable to exec ");
1337 if (pd[1] != fileno(stdout)) {
1338 dup2(pd[1], fileno(stdout));
1353 if (dup2(sd, fileno(stdout)) == NOTOK)
1354 adios("standard output", "unable to dup2()");