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[] = {
53 { "folder +folder", 0 },
55 { "form formfile", 0 },
57 { "moreproc program", 0 },
59 { "length lines", 0 },
61 { "width columns", 0 },
63 { "sleep seconds", 0 },
73 { "digest list", -6 },
75 { "volume number", -6 },
77 { "issue number", -5 },
83 #define NOCOMPONENT 0x000001 /* don't show component name */
84 #define UPPERCASE 0x000002 /* display in all upper case */
85 #define CENTER 0x000004 /* center line */
86 #define CLEARTEXT 0x000008 /* cleartext */
87 #define EXTRA 0x000010 /* an "extra" component */
88 #define HDROUTPUT 0x000020 /* already output */
89 #define CLEARSCR 0x000040 /* clear screen */
90 #define LEFTADJUST 0x000080 /* left justify multiple lines */
91 #define COMPRESS 0x000100 /* compress text */
92 #define ADDRFMT 0x000200 /* contains addresses */
93 #define BELL 0x000400 /* sound bell at EOP */
94 #define DATEFMT 0x000800 /* contains dates */
95 #define FORMAT 0x001000 /* parse address/date/RFC-2047 field */
96 #define INIT 0x002000 /* initialize component */
97 #define SPLIT 0x004000 /* split headers (don't concatenate) */
98 #define NONEWLINE 0x008000 /* don't write trailing newline */
99 #define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013BELL\014DATEFMT\015FORMAT\016INIT\017SPLIT\020NONEWLINE"
100 #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
103 char *c_name; /* component name */
104 char *c_text; /* component text */
105 char *c_ovtxt; /* text overflow indicator */
106 char *c_nfs; /* iff FORMAT */
107 struct format *c_fmt; /* .. */
108 int c_offset; /* left margin indentation */
109 int c_ovoff; /* overflow indentation */
110 int c_width; /* width of field */
111 int c_cwidth; /* width of component */
112 int c_length; /* length in lines */
114 struct mcomp *c_next;
117 static struct mcomp *msghd = NULL;
118 static struct mcomp *msgtl = NULL;
119 static struct mcomp *fmthd = NULL;
120 static struct mcomp *fmttl = NULL;
122 static struct mcomp global = {
123 NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 40, BELL, 0
126 static struct mcomp holder = {
127 NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NOCOMPONENT, 0
135 static struct pair pairs[] = {
138 { "Sender", ADDRFMT },
139 { "Reply-To", ADDRFMT },
143 { "Resent-Date", DATEFMT },
144 { "Resent-From", ADDRFMT },
145 { "Resent-Sender", ADDRFMT },
146 { "Resent-Reply-To", ADDRFMT },
147 { "Resent-To", ADDRFMT },
148 { "Resent-Cc", ADDRFMT },
149 { "Resent-Bcc", ADDRFMT },
159 static struct triple triples[] = {
160 { "nocomponent", NOCOMPONENT, 0 },
161 { "uppercase", UPPERCASE, 0 },
162 { "nouppercase", 0, UPPERCASE },
163 { "center", CENTER, 0 },
164 { "nocenter", 0, CENTER },
165 { "clearscreen", CLEARSCR, 0 },
166 { "noclearscreen", 0, CLEARSCR },
167 { "noclear", 0, CLEARSCR },
168 { "leftadjust", LEFTADJUST, 0 },
169 { "noleftadjust", 0, LEFTADJUST },
170 { "compress", COMPRESS, 0 },
171 { "nocompress", 0, COMPRESS },
172 { "split", SPLIT, 0 },
173 { "nosplit", 0, SPLIT },
174 { "addrfield", ADDRFMT, DATEFMT },
176 { "nobell", 0, BELL },
177 { "datefield", DATEFMT, ADDRFMT },
178 { "newline", 0, NONEWLINE },
179 { "nonewline", NONEWLINE, 0 },
184 static int bellflg = 0;
185 static int clearflg = 0;
186 static int dobody = 1;
187 static int forwflg = 0;
188 static int forwall = 0;
190 static int sleepsw = NOTOK;
192 static char *digest = NULL;
193 static int volume = 0;
194 static int issue = 0;
196 static int exitstat = 0;
197 static int mhldebug = 0;
201 static int ontty = NOTTY;
214 static unsigned char *onelp;
218 static int num_ignores = 0;
219 static char *ignores[MAXARGS];
222 static jmp_buf mhlenv;
224 static char delim3[] =
225 "\n----------------------------------------------------------------------\n\n";
226 static char delim4[] = "\n------------------------------\n\n";
228 static FILE *(*mhl_action) () = (FILE *(*) ()) 0;
232 ** Redefine a couple of functions.
233 ** These are undefined later in the code.
235 #define adios mhladios
241 static void mhl_format(char *, int, int);
242 static int evalvar(struct mcomp *);
243 static int ptoi(char *, int *);
244 static int ptos(char *, char **);
245 static char *parse(void);
246 static void process(char *, char *, int, int);
247 static void mhlfile(FILE *, char *, int, int);
248 static int mcomp_flags(char *);
249 static char *mcomp_add(long, char *, char *);
250 static void mcomp_format(struct mcomp *, struct mcomp *);
251 static struct mcomp *add_queue(struct mcomp **, struct mcomp **,
252 char *, char *, int);
253 static void free_queue(struct mcomp **, struct mcomp **);
254 static void putcomp(struct mcomp *, struct mcomp *, int);
255 static char *oneline(char *, long);
256 static void putstr(char *);
257 static void putch(char);
258 static RETSIGTYPE intrser(int);
259 static RETSIGTYPE pipeser(int);
260 static RETSIGTYPE quitser(int);
261 static void mhladios(char *, char *, ...);
262 static void mhldone(int);
263 static void m_popen(char *);
267 void clear_screen(void); /* from termsbr.c */
268 int SOprintf(char *, ...); /* from termsbr.c */
269 int sc_width(void); /* from termsbr.c */
270 int sc_length(void); /* from termsbr.c */
274 main(int argc, char **argv)
277 int i, width = 0, vecp = 0;
278 char *cp, *folder = NULL, *form = NULL;
279 char buf[BUFSIZ], *files[MAXARGS];
280 char **argp, **arguments;
284 setlocale(LC_ALL, "");
287 invo_name = mhbasename(argv[0]);
289 /* read user profile/context */
292 arguments = getarguments(invo_name, argc, argv, 1);
295 if ((cp = getenv("MHLDEBUG")) && *cp)
298 while ((cp = *argp++)) {
300 switch (smatch(++cp, mhlswitches)) {
302 ambigsw(cp, mhlswitches);
305 adios(NULL, "-%s unknown\n", cp);
308 snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
309 print_help(buf, mhlswitches, 1);
312 print_version(invo_name);
330 if (!(folder = *argp++) || *folder == '-')
331 adios(NULL, "missing argument to %s",
335 if (!(form = *argp++) || *form == '-')
336 adios(NULL, "missing argument to %s",
341 if (!(cp = *argp++) || *cp == '-')
342 adios(NULL, "missing argument to %s",
344 sleepsw = atoi(cp); /* ZERO ok! */
348 if (!(progsw = *argp++) || *progsw == '-')
349 adios(NULL, "missing argument to %s",
354 if (!(cp = *argp++) || *cp == '-')
355 adios(NULL, "missing argument to %s",
357 if ((length = atoi(cp)) < 1)
358 adios(NULL, "bad argument %s %s",
362 if (!(cp = *argp++) || *cp == '-')
363 adios(NULL, "missing argument to %s",
365 if ((width = atoi(cp)) < 1)
366 adios(NULL, "bad argument %s %s",
371 if (!(digest = *argp++) ||
373 adios(NULL, "missing argument to %s",
377 if (!(cp = *argp++) || *cp == '-')
378 adios(NULL, "missing argument to %s",
380 if ((issue = atoi(cp)) < 1)
381 adios(NULL, "bad argument %s %s",
385 if (!(cp = *argp++) || *cp == '-')
386 adios(NULL, "missing argument to %s",
388 if ((volume = atoi(cp)) < 1)
389 adios(NULL, "bad argument %s %s",
394 forwall++; /* fall */
397 clearflg = -1;/* XXX */
409 folder = getenv("mhfolder");
411 if (isatty(fileno(stdout))) {
413 SIGNAL(SIGINT, SIG_IGN);
414 SIGNAL2(SIGQUIT, quitser);
416 SIGNAL2(SIGPIPE, pipeser);
417 m_popen(progsw ? progsw : moreproc);
423 mhl_format(form ? form : mhlformat, length, width);
426 process(folder, NULL, 1, vecp = 1);
428 for (i = 0; i < vecp; i++)
429 process(folder, files[i], i + 1, vecp);
434 printf("%s", delim4);
436 snprintf(buf, sizeof(buf),
437 "End of %s Digest\n", digest);
439 snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
442 for (cp = buf + i; i > 1; i--)
448 printf("\n------- End of Forwarded Message%s\n\n",
449 vecp > 1 ? "s" : "");
453 if (ferror(stdout)) {
454 adios("output", "error writing");
457 if (clearflg > 0 && ontty == NOTTY)
468 mhl_format(char *file, int length, int width)
472 char *ap, buffer[BUFSIZ], name[NAMESZ];
476 static dev_t dev = 0;
477 static ino_t ino = 0;
478 static time_t mtime = 0;
481 if (stat(etcpath(file), &st) != NOTOK
482 && mtime == st.st_mtime
487 free_queue(&fmthd, &fmttl);
490 if ((fp = fopen(etcpath(file), "r")) == NULL)
491 adios(file, "unable to open format file");
493 if (fstat(fileno(fp), &st) != NOTOK) {
499 global.c_ovtxt = global.c_nfs = NULL;
503 if ((i = sc_width()) > 5)
505 global.c_cwidth = -1;
506 if ((i = sc_length()) > 5)
507 global.c_length = i - 1;
508 global.c_flags = BELL; /* BELL is default */
509 *(ip = ignores) = NULL;
511 while (vfgets(fp, &ap) == OK) {
516 if ((cp = strchr(bp, '\n')))
520 c1 = add_queue(&fmthd, &fmttl, NULL, bp + 1,
526 strncpy(name, parse(), sizeof(name));
532 ** Split this list of fields to ignore, and copy
533 ** it to the end of the current "ignores" list.
535 if (!mh_strcasecmp(name, "ignores")) {
536 char **tmparray, **p;
539 /* split the fields */
540 tmparray = brkstring(getcpy(++parptr), ",",
543 /* count number of fields split */
549 ** copy pointers to split fields
552 ip = copyip(tmparray, ip,
553 MAXARGS - num_ignores);
559 if (evalvar(&global))
560 adios(NULL, "format file syntax error: %s", bp);
567 c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT);
568 while (*parptr == ':' || *parptr == ',') {
571 adios(NULL, "format file syntax error: %s", bp);
573 if (!c1->c_nfs && global.c_nfs) {
574 if ((c1->c_flags & DATEFMT) &&
575 (global.c_flags & DATEFMT)) {
576 c1->c_nfs = getcpy(global.c_nfs);
577 } else if ((c1->c_flags & ADDRFMT) &&
578 (global.c_flags & ADDRFMT)) {
579 c1->c_nfs = getcpy(global.c_nfs);
585 adios(NULL, "format file syntax error: %s", bp);
591 for (c1 = fmthd; c1; c1 = c1->c_next) {
592 fprintf(stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", c1->c_name, c1->c_text, c1->c_ovtxt);
593 fprintf(stderr, "\tnfs=0x%x fmt=0x%x\n", (unsigned int)(unsigned long) c1->c_nfs, (unsigned int)(unsigned long) c1->c_fmt);
594 fprintf(stderr, "\toffset=%d ovoff=%d width=%d cwidth=%d length=%d\n", c1->c_offset, c1->c_ovoff, c1->c_width, c1->c_cwidth, c1->c_length);
595 fprintf (stderr, "\tflags=%s\n", snprintb(buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS));
601 global.c_flags |= CLEARSCR;
604 global.c_flags &= ~CLEARSCR;
607 switch (bellflg) { /* command line may override format file */
609 global.c_flags |= BELL;
612 global.c_flags &= ~BELL;
617 global.c_length = length;
619 global.c_width = width;
620 if (global.c_length < 5)
621 global.c_length = 10000;
622 if (global.c_width < 5)
623 global.c_width = 10000;
628 evalvar(struct mcomp *c1)
630 char *cp, name[NAMESZ];
635 strncpy(name, parse(), sizeof(name));
637 if (!mh_strcasecmp(name, "component")) {
638 if (ptos(name, &c1->c_text))
640 c1->c_flags &= ~NOCOMPONENT;
644 if (!mh_strcasecmp(name, "overflowtext"))
645 return ptos(name, &c1->c_ovtxt);
647 if (!mh_strcasecmp(name, "formatfield")) {
652 cp = concat("=", cp, NULL);
653 nfs = new_fs(cp, NULL);
655 c1->c_nfs = getcpy(nfs);
656 c1->c_flags |= FORMAT;
660 if (!mh_strcasecmp(name, "decode")) {
663 nfs = new_fs("=%(decode{text})", NULL);
664 c1->c_nfs = getcpy(nfs);
665 c1->c_flags |= FORMAT;
669 if (!mh_strcasecmp(name, "offset"))
670 return ptoi(name, &c1->c_offset);
671 if (!mh_strcasecmp(name, "overflowoffset"))
672 return ptoi(name, &c1->c_ovoff);
673 if (!mh_strcasecmp(name, "width"))
674 return ptoi(name, &c1->c_width);
675 if (!mh_strcasecmp(name, "compwidth"))
676 return ptoi(name, &c1->c_cwidth);
677 if (!mh_strcasecmp(name, "length"))
678 return ptoi(name, &c1->c_length);
680 for (ap = triples; ap->t_name; ap++)
681 if (!mh_strcasecmp(ap->t_name, name)) {
682 c1->c_flags |= ap->t_on;
683 c1->c_flags &= ~ap->t_off;
692 ptoi(char *name, int *i)
696 if (*parptr++ != '=' || !*(cp = parse())) {
697 advise(NULL, "missing argument to variable %s", name);
707 ptos(char *name, char **s)
711 if (*parptr++ != '=') {
712 advise(NULL, "missing argument to variable %s", name);
716 if (*parptr != '"') {
717 for (cp = parptr; *parptr && *parptr != ':' && *parptr != ',';
721 for (cp = ++parptr; *parptr && *parptr != '"'; parptr++)
722 if (*parptr == QUOTE)
729 if ((*parptr = c) == '"')
740 static char result[NAMESZ];
742 for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
761 process(char *folder, char *fname, int ofilen, int ofilec)
767 switch (setjmp(env)) {
770 fp = mhl_action ? (*mhl_action) (fname) :
773 advise(fname, "unable to open");
781 cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname);
783 SIGNAL(SIGINT, intrser);
784 mhlfile(fp, cp, ofilen, ofilec);
788 SIGNAL(SIGINT, SIG_IGN);
789 if (mhl_action == NULL && fp != stdin)
794 holder.c_text = NULL;
796 free_queue(&msghd, &msgtl);
797 for (c1 = fmthd; c1; c1 = c1->c_next)
798 c1->c_flags &= ~HDROUTPUT;
805 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
808 struct mcomp *c1, *c2, *c3;
809 char **ip, name[NAMESZ], buf[BUFSIZ];
813 printf("%s", ofilen == 1 ? delim3 : delim4);
817 printf(" Forwarded Message%s",
818 ofilec > 1 ? "s" : "");
820 printf(" Message %d", ofilen);
828 if ((global.c_flags & CLEARSCR))
833 printf(">>> %s\n\n", mname);
844 printf(">>> %s\n\n", mname);
850 for (state = FLD;;) {
851 switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
854 for (ip = ignores; *ip; ip++)
855 if (!mh_strcasecmp(name, *ip)) {
856 while (state == FLDPLUS)
857 state = m_getfld(state, name, buf, sizeof(buf), fp);
863 for (c2 = fmthd; c2; c2 = c2->c_next)
864 if (!mh_strcasecmp(c2->c_name, name))
867 if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
868 for (c1 = msghd; c1; c1 = c1->c_next)
869 if (!mh_strcasecmp(c1->c_name,
871 c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
875 c1 = add_queue(&msghd, &msgtl, name, buf, 0);
876 while (state == FLDPLUS) {
877 state = m_getfld(state, name, buf,
879 c1->c_text = add(buf, c1->c_text);
882 c1->c_flags |= EXTRA;
888 for (c1 = fmthd; c1; c1 = c1->c_next) {
889 if (c1->c_flags & CLEARTEXT) {
890 putcomp(c1, c1, ONECOMP);
893 if (!mh_strcasecmp(c1->c_name, "messagename")) {
894 holder.c_text = concat("(Message ",
896 putcomp(c1, &holder, ONECOMP);
898 holder.c_text = NULL;
901 if (!mh_strcasecmp(c1->c_name, "extras")) {
902 for (c2 = msghd; c2; c2 = c2->c_next)
903 if (c2->c_flags & EXTRA)
904 putcomp(c1, c2, TWOCOMP);
907 if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
908 holder.c_text = mh_xmalloc(sizeof(buf));
909 strncpy(holder.c_text, buf, sizeof(buf));
910 while (state == BODY) {
911 putcomp(c1, &holder, BODYCOMP);
912 state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
915 holder.c_text = NULL;
918 for (c2 = msghd; c2; c2 = c2->c_next)
919 if (!mh_strcasecmp(c2->c_name,
921 putcomp(c1, c2, ONECOMP);
922 if (!(c1->c_flags & SPLIT))
930 advise(NULL, "format error in message %s", mname);
935 adios(NULL, "getfld() returned %d", state);
942 mcomp_flags(char *name)
946 for (ap = pairs; ap->p_name; ap++)
947 if (!mh_strcasecmp(ap->p_name, name))
948 return (ap->p_flags);
955 mcomp_add(long flags, char *s1, char *s2)
959 if (!(flags & ADDRFMT))
962 if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
965 return add(s1, add(",\n", s2));
972 struct pqpair *pq_next;
977 mcomp_format(struct mcomp *c1, struct mcomp *c2)
981 char buffer[BUFSIZ], error[BUFSIZ];
983 struct pqpair *p, *q;
992 dat[3] = sizeof(buffer) - 1;
994 fmt_compile(c1->c_nfs, &c1->c_fmt);
996 if (!(c1->c_flags & ADDRFMT)) {
997 FINDCOMP(cptr, "text");
1000 if ((cp = strrchr(ap, '\n'))) /* drop ending newline */
1004 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
1005 /* Don't need to append a newline, dctime() already did */
1006 c2->c_text = getcpy(buffer);
1012 (q = &pq)->pq_next = NULL;
1013 while ((cp = getname(ap))) {
1014 if ((p = (struct pqpair *)
1015 calloc((size_t) 1, sizeof(*p))) == NULL)
1016 adios(NULL, "unable to allocate pqpair memory");
1018 if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
1019 p->pq_text = getcpy(cp);
1020 p->pq_error = getcpy(error);
1022 p->pq_text = getcpy(mp->m_text);
1025 q = (q->pq_next = p);
1028 for (p = pq.pq_next; p; p = q) {
1029 FINDCOMP(cptr, "text");
1031 cptr->c_text = p->pq_text;
1032 FINDCOMP(cptr, "error");
1034 cptr->c_text = p->pq_error;
1036 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
1039 c2->c_text = add(",\n", c2->c_text);
1040 if (*(cp = buffer + strlen(buffer) - 1) == '\n')
1042 c2->c_text = add(buffer, c2->c_text);
1052 c2->c_text = add("\n", c2->c_text);
1057 static struct mcomp *
1058 add_queue(struct mcomp **head, struct mcomp **tail, char *name,
1059 char *text, int flags)
1063 if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
1064 adios(NULL, "unable to allocate comp memory");
1066 c1->c_flags = flags & ~INIT;
1067 if ((c1->c_name = name ? getcpy(name) : NULL))
1068 c1->c_flags |= mcomp_flags(c1->c_name);
1069 c1->c_text = text ? getcpy(text) : NULL;
1072 c1->c_ovtxt = getcpy(global.c_ovtxt);
1073 c1->c_offset = global.c_offset;
1074 c1->c_ovoff = global. c_ovoff;
1075 c1->c_width = c1->c_length = 0;
1076 c1->c_cwidth = global.c_cwidth;
1077 c1->c_flags |= global.c_flags & GFLAGS;
1082 (*tail)->c_next = c1;
1090 free_queue(struct mcomp **head, struct mcomp **tail)
1092 struct mcomp *c1, *c2;
1094 for (c1 = *head; c1; c1 = c2) {
1105 free((char *) c1->c_fmt);
1109 *head = *tail = NULL;
1114 putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
1121 llim = c1->c_length ? c1->c_length : -1;
1122 wid = c1->c_width ? c1->c_width : global.c_width;
1123 ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff)
1125 if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
1127 if (wid < ovoff + strlen(ovtxt) + 5)
1128 adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
1131 if (c1->c_flags & CLEARTEXT) {
1137 if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT)))
1138 mcomp_format(c1, c2);
1140 if (c1->c_flags & CENTER) {
1141 count = (c1->c_width ? c1->c_width : global.c_width)
1142 - c1->c_offset - strlen(c2->c_text);
1143 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT))
1144 count -= strlen(c1->c_text ? c1->c_text : c1->c_name)
1146 lm = c1->c_offset + (count / 2);
1152 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
1153 if (c1->c_flags & UPPERCASE) /* uppercase component also */
1154 for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
1157 putstr(c1->c_text ? c1->c_text : c1->c_name);
1158 if (flag != BODYCOMP) {
1160 if (!(c1->c_flags & SPLIT))
1161 c1->c_flags |= HDROUTPUT;
1164 if ((count = c1->c_cwidth -
1165 strlen(c1->c_text ? c1->c_text : c1->c_name) - 2) > 0)
1169 c1->c_flags |= HDROUTPUT; /* for BODYCOMP */
1172 if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT)
1173 && !(c2->c_flags & NOCOMPONENT)) {
1174 if (c1->c_flags & UPPERCASE)
1175 for (cp = c2->c_name; *cp; cp++)
1180 if (!(c1->c_flags & SPLIT))
1181 c2->c_flags |= HDROUTPUT;
1184 if ((count = c1->c_cwidth - strlen(c2->c_name) - 2) > 0)
1188 if (c1->c_flags & UPPERCASE)
1189 for (cp = c2->c_text; *cp; cp++)
1195 if (flag == TWOCOMP)
1196 count = (c1->c_cwidth >= 0) ?
1197 c1->c_cwidth : strlen(c2->c_name) + 2;
1199 count = (c1->c_cwidth >= 0) ?
1200 c1->c_cwidth : strlen(c1->c_text ?
1201 c1->c_text : c1->c_name) + 2;
1203 count += c1->c_offset;
1205 if ((cp = oneline(c2->c_text, c1->c_flags)))
1209 while ((cp = oneline(c2->c_text, c1->c_flags))) {
1211 if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT))
1212 putstr(c1->c_text ? c1->c_text : c1->c_name);
1218 if (flag == BODYCOMP && term == '\n')
1219 c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
1224 oneline(char *stuff, long flags)
1232 return (onelp = NULL);
1236 if (flags & COMPRESS) {
1237 for (spc = 1, cp = ret; *onelp; onelp++)
1238 if (isspace(*onelp)) {
1239 if (*onelp == '\n' &&
1241 (flags & ADDRFMT))) {
1256 while (*onelp && *onelp != '\n')
1258 if (*onelp == '\n') {
1262 if (flags & LEFTADJUST)
1263 while (*ret == ' ' || *ret == '\t')
1266 if (*onelp == 0 && term == '\n' && (flags & NONEWLINE))
1274 putstr(char *string)
1276 if (!column && lm > 0) {
1306 if (row != global.c_length)
1308 if (global.c_flags & BELL)
1312 read(fileno(stdout), buf, sizeof(buf));
1313 if (strchr(buf, '\n')) {
1314 if (global.c_flags & CLEARSCR)
1319 row = global.c_length / 3;
1338 ** If we are forwarding this message, and the first
1339 ** column contains a dash, then add a dash and a space.
1341 if (column == 0 && forwflg && ch == '-') {
1350 if (column >= wid) {
1354 putstr(ovtxt ? ovtxt : "");
1366 #ifndef RELIABLE_SIGNALS
1367 SIGNAL(SIGINT, intrser);
1379 #ifndef RELIABLE_SIGNALS
1380 SIGNAL(SIGPIPE, pipeser);
1390 #ifndef RELIABLE_SIGNALS
1391 SIGNAL(SIGQUIT, quitser);
1404 mhladios(char *what, char *fmt, ...)
1409 advertise(what, NULL, fmt, ap);
1420 longjmp(mhlenv, DONE);
1426 static int m_pid = NOTOK;
1427 static int sd = NOTOK;
1434 if (mhl_action && (sd = dup(fileno(stdout))) == NOTOK)
1435 adios("standard output", "unable to dup()");
1437 if (pipe(pd) == NOTOK)
1438 adios("pipe", "unable to");
1440 switch (m_pid = fork()) {
1442 adios("fork", "unable to");
1445 SIGNAL(SIGINT, SIG_DFL);
1446 SIGNAL(SIGQUIT, SIG_DFL);
1449 if (pd[0] != fileno(stdin)) {
1450 dup2(pd[0], fileno(stdin));
1453 execlp(name, mhbasename(name), NULL);
1454 fprintf(stderr, "unable to exec ");
1460 if (pd[1] != fileno(stdout)) {
1461 dup2(pd[1], fileno(stdout));
1476 if (dup2(sd, fileno(stdout)) == NOTOK)
1477 adios("standard output", "unable to dup2()");