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[] = {
49 { "folder +folder", 0 },
51 { "form formfile", 0 },
53 { "moreproc program", 0 },
55 { "length lines", 0 },
57 { "width columns", 0 },
59 { "sleep seconds", 0 },
69 { "digest list", -6 },
71 { "volume number", -6 },
73 { "issue number", -5 },
79 #define NOCOMPONENT 0x000001 /* don't show component name */
80 #define UPPERCASE 0x000002 /* display in all upper case */
81 #define CENTER 0x000004 /* center line */
82 #define CLEARTEXT 0x000008 /* cleartext */
83 #define EXTRA 0x000010 /* an "extra" component */
84 #define HDROUTPUT 0x000020 /* already output */
85 #define CLEARSCR 0x000040 /* clear screen */
86 #define LEFTADJUST 0x000080 /* left justify multiple lines */
87 #define COMPRESS 0x000100 /* compress text */
88 #define ADDRFMT 0x000200 /* contains addresses */
89 #define DATEFMT 0x000400 /* contains dates */
90 #define FORMAT 0x000800 /* parse address/date/RFC-2047 field */
91 #define INIT 0x001000 /* initialize component */
92 #define SPLIT 0x002000 /* split headers (don't concatenate) */
93 #define NONEWLINE 0x004000 /* don't write trailing newline */
94 #define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07CLEARSCR\010LEFTADJUST\011COMPRESS\012ADDRFMT\013DATEFMT\014FORMAT\015INIT\016SPLIT\017NONEWLINE"
95 #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
98 char *c_name; /* component name */
99 char *c_text; /* component text */
100 char *c_ovtxt; /* text overflow indicator */
101 char *c_nfs; /* iff FORMAT */
102 struct format *c_fmt; /* .. */
103 int c_offset; /* left margin indentation */
104 int c_ovoff; /* overflow indentation */
105 int c_width; /* width of field */
106 int c_cwidth; /* width of component */
107 int c_length; /* length in lines */
109 struct mcomp *c_next;
112 static struct mcomp *msghd = NULL;
113 static struct mcomp *msgtl = NULL;
114 static struct mcomp *fmthd = NULL;
115 static struct mcomp *fmttl = NULL;
117 static struct mcomp global = {
118 NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 40, 0, 0
121 static struct mcomp holder = {
122 NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NOCOMPONENT, 0
130 static struct pair pairs[] = {
133 { "Sender", ADDRFMT },
134 { "Reply-To", ADDRFMT },
138 { "Resent-Date", DATEFMT },
139 { "Resent-From", ADDRFMT },
140 { "Resent-Sender", ADDRFMT },
141 { "Resent-Reply-To", ADDRFMT },
142 { "Resent-To", ADDRFMT },
143 { "Resent-Cc", ADDRFMT },
144 { "Resent-Bcc", ADDRFMT },
154 static struct triple triples[] = {
155 { "nocomponent", NOCOMPONENT, 0 },
156 { "uppercase", UPPERCASE, 0 },
157 { "nouppercase", 0, UPPERCASE },
158 { "center", CENTER, 0 },
159 { "nocenter", 0, CENTER },
160 { "clearscreen", CLEARSCR, 0 },
161 { "noclearscreen", 0, CLEARSCR },
162 { "noclear", 0, CLEARSCR },
163 { "leftadjust", LEFTADJUST, 0 },
164 { "noleftadjust", 0, LEFTADJUST },
165 { "compress", COMPRESS, 0 },
166 { "nocompress", 0, COMPRESS },
167 { "split", SPLIT, 0 },
168 { "nosplit", 0, SPLIT },
169 { "addrfield", ADDRFMT, DATEFMT },
170 { "datefield", DATEFMT, ADDRFMT },
171 { "newline", 0, NONEWLINE },
172 { "nonewline", NONEWLINE, 0 },
177 static int clearflg = 0;
178 static int dobody = 1;
179 static int forwflg = 0;
180 static int forwall = 0;
182 static int sleepsw = NOTOK;
184 static char *digest = NULL;
185 static int volume = 0;
186 static int issue = 0;
188 static int exitstat = 0;
189 static int mhldebug = 0;
193 static int ontty = NOTTY;
206 static unsigned char *onelp;
210 static int num_ignores = 0;
211 static char *ignores[MAXARGS];
214 static jmp_buf mhlenv;
216 static char delim3[] =
217 "\n----------------------------------------------------------------------\n\n";
218 static char delim4[] = "\n------------------------------\n\n";
220 static FILE *(*mhl_action) () = (FILE *(*) ()) 0;
224 ** Redefine a couple of functions.
225 ** These are undefined later in the code.
227 #define adios mhladios
233 static void mhl_format(char *, int, int);
234 static int evalvar(struct mcomp *);
235 static int ptoi(char *, int *);
236 static int ptos(char *, char **);
237 static char *parse(void);
238 static void process(char *, char *, int, int);
239 static void mhlfile(FILE *, char *, int, int);
240 static int mcomp_flags(char *);
241 static char *mcomp_add(long, char *, char *);
242 static void mcomp_format(struct mcomp *, struct mcomp *);
243 static struct mcomp *add_queue(struct mcomp **, struct mcomp **,
244 char *, char *, int);
245 static void free_queue(struct mcomp **, struct mcomp **);
246 static void putcomp(struct mcomp *, struct mcomp *, int);
247 static char *oneline(char *, long);
248 static void putstr(char *);
249 static void putch(char);
250 static RETSIGTYPE intrser(int);
251 static RETSIGTYPE pipeser(int);
252 static RETSIGTYPE quitser(int);
253 static void mhladios(char *, char *, ...);
254 static void mhldone(int);
255 static void m_popen(char *);
259 void clear_screen(void); /* from termsbr.c */
260 int SOprintf(char *, ...); /* from termsbr.c */
261 int sc_width(void); /* from termsbr.c */
262 int sc_length(void); /* from termsbr.c */
266 main(int argc, char **argv)
269 int i, width = 0, vecp = 0;
270 char *cp, *folder = NULL, *form = NULL;
271 char buf[BUFSIZ], *files[MAXARGS];
272 char **argp, **arguments;
276 setlocale(LC_ALL, "");
279 invo_name = mhbasename(argv[0]);
281 /* read user profile/context */
284 arguments = getarguments(invo_name, argc, argv, 1);
287 if ((cp = getenv("MHLDEBUG")) && *cp)
290 while ((cp = *argp++)) {
292 switch (smatch(++cp, mhlswitches)) {
294 ambigsw(cp, mhlswitches);
297 adios(NULL, "-%s unknown\n", cp);
300 snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
301 print_help(buf, mhlswitches, 1);
304 print_version(invo_name);
315 if (!(folder = *argp++) || *folder == '-')
316 adios(NULL, "missing argument to %s",
320 if (!(form = *argp++) || *form == '-')
321 adios(NULL, "missing argument to %s",
326 if (!(cp = *argp++) || *cp == '-')
327 adios(NULL, "missing argument to %s",
329 sleepsw = atoi(cp); /* ZERO ok! */
333 if (!(progsw = *argp++) || *progsw == '-')
334 adios(NULL, "missing argument to %s",
339 if (!(cp = *argp++) || *cp == '-')
340 adios(NULL, "missing argument to %s",
342 if ((length = atoi(cp)) < 1)
343 adios(NULL, "bad argument %s %s",
347 if (!(cp = *argp++) || *cp == '-')
348 adios(NULL, "missing argument to %s",
350 if ((width = atoi(cp)) < 1)
351 adios(NULL, "bad argument %s %s",
356 if (!(digest = *argp++) ||
358 adios(NULL, "missing argument to %s",
362 if (!(cp = *argp++) || *cp == '-')
363 adios(NULL, "missing argument to %s",
365 if ((issue = atoi(cp)) < 1)
366 adios(NULL, "bad argument %s %s",
370 if (!(cp = *argp++) || *cp == '-')
371 adios(NULL, "missing argument to %s",
373 if ((volume = atoi(cp)) < 1)
374 adios(NULL, "bad argument %s %s",
379 forwall++; /* fall */
382 clearflg = -1;/* XXX */
394 folder = getenv("mhfolder");
396 if (isatty(fileno(stdout))) {
398 SIGNAL(SIGINT, SIG_IGN);
399 SIGNAL2(SIGQUIT, quitser);
401 SIGNAL2(SIGPIPE, pipeser);
402 m_popen(progsw ? progsw : moreproc);
408 mhl_format(form ? form : mhlformat, length, width);
411 process(folder, NULL, 1, vecp = 1);
413 for (i = 0; i < vecp; i++)
414 process(folder, files[i], i + 1, vecp);
419 printf("%s", delim4);
421 snprintf(buf, sizeof(buf),
422 "End of %s Digest\n", digest);
424 snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
427 for (cp = buf + i; i > 1; i--)
433 printf("\n------- End of Forwarded Message%s\n\n",
434 vecp > 1 ? "s" : "");
438 if (ferror(stdout)) {
439 adios("output", "error writing");
442 if (clearflg > 0 && ontty == NOTTY)
453 mhl_format(char *file, int length, int width)
457 char *ap, buffer[BUFSIZ], name[NAMESZ];
461 static dev_t dev = 0;
462 static ino_t ino = 0;
463 static time_t mtime = 0;
466 if (stat(etcpath(file), &st) != NOTOK
467 && mtime == st.st_mtime
472 free_queue(&fmthd, &fmttl);
475 if ((fp = fopen(etcpath(file), "r")) == NULL)
476 adios(file, "unable to open format file");
478 if (fstat(fileno(fp), &st) != NOTOK) {
484 global.c_ovtxt = global.c_nfs = NULL;
488 if ((i = sc_width()) > 5)
490 global.c_cwidth = -1;
491 if ((i = sc_length()) > 5)
492 global.c_length = i - 1;
494 *(ip = ignores) = NULL;
496 while (vfgets(fp, &ap) == OK) {
501 if ((cp = strchr(bp, '\n')))
505 c1 = add_queue(&fmthd, &fmttl, NULL, bp + 1,
511 strncpy(name, parse(), sizeof(name));
517 ** Split this list of fields to ignore, and copy
518 ** it to the end of the current "ignores" list.
520 if (!mh_strcasecmp(name, "ignores")) {
521 char **tmparray, **p;
524 /* split the fields */
525 tmparray = brkstring(getcpy(++parptr), ",",
528 /* count number of fields split */
534 ** copy pointers to split fields
537 ip = copyip(tmparray, ip,
538 MAXARGS - num_ignores);
544 if (evalvar(&global))
545 adios(NULL, "format file syntax error: %s", bp);
552 c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT);
553 while (*parptr == ':' || *parptr == ',') {
556 adios(NULL, "format file syntax error: %s", bp);
558 if (!c1->c_nfs && global.c_nfs) {
559 if ((c1->c_flags & DATEFMT) &&
560 (global.c_flags & DATEFMT)) {
561 c1->c_nfs = getcpy(global.c_nfs);
562 } else if ((c1->c_flags & ADDRFMT) &&
563 (global.c_flags & ADDRFMT)) {
564 c1->c_nfs = getcpy(global.c_nfs);
570 adios(NULL, "format file syntax error: %s", bp);
576 for (c1 = fmthd; c1; c1 = c1->c_next) {
577 fprintf(stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", c1->c_name, c1->c_text, c1->c_ovtxt);
578 fprintf(stderr, "\tnfs=0x%x fmt=0x%x\n", (unsigned int)(unsigned long) c1->c_nfs, (unsigned int)(unsigned long) c1->c_fmt);
579 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);
580 fprintf (stderr, "\tflags=%s\n", snprintb(buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS));
586 global.c_flags |= CLEARSCR;
589 global.c_flags &= ~CLEARSCR;
593 global.c_length = length;
595 global.c_width = width;
596 if (global.c_length < 5)
597 global.c_length = 10000;
598 if (global.c_width < 5)
599 global.c_width = 10000;
604 evalvar(struct mcomp *c1)
606 char *cp, name[NAMESZ];
611 strncpy(name, parse(), sizeof(name));
613 if (!mh_strcasecmp(name, "component")) {
614 if (ptos(name, &c1->c_text))
616 c1->c_flags &= ~NOCOMPONENT;
620 if (!mh_strcasecmp(name, "overflowtext"))
621 return ptos(name, &c1->c_ovtxt);
623 if (!mh_strcasecmp(name, "formatfield")) {
628 cp = concat("=", cp, NULL);
629 nfs = new_fs(cp, NULL);
631 c1->c_nfs = getcpy(nfs);
632 c1->c_flags |= FORMAT;
636 if (!mh_strcasecmp(name, "decode")) {
639 nfs = new_fs("=%(decode{text})", NULL);
640 c1->c_nfs = getcpy(nfs);
641 c1->c_flags |= FORMAT;
645 if (!mh_strcasecmp(name, "offset"))
646 return ptoi(name, &c1->c_offset);
647 if (!mh_strcasecmp(name, "overflowoffset"))
648 return ptoi(name, &c1->c_ovoff);
649 if (!mh_strcasecmp(name, "width"))
650 return ptoi(name, &c1->c_width);
651 if (!mh_strcasecmp(name, "compwidth"))
652 return ptoi(name, &c1->c_cwidth);
653 if (!mh_strcasecmp(name, "length"))
654 return ptoi(name, &c1->c_length);
656 for (ap = triples; ap->t_name; ap++)
657 if (!mh_strcasecmp(ap->t_name, name)) {
658 c1->c_flags |= ap->t_on;
659 c1->c_flags &= ~ap->t_off;
668 ptoi(char *name, int *i)
672 if (*parptr++ != '=' || !*(cp = parse())) {
673 advise(NULL, "missing argument to variable %s", name);
683 ptos(char *name, char **s)
687 if (*parptr++ != '=') {
688 advise(NULL, "missing argument to variable %s", name);
692 if (*parptr != '"') {
693 for (cp = parptr; *parptr && *parptr != ':' && *parptr != ',';
697 for (cp = ++parptr; *parptr && *parptr != '"'; parptr++)
698 if (*parptr == QUOTE)
705 if ((*parptr = c) == '"')
716 static char result[NAMESZ];
718 for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
737 process(char *folder, char *fname, int ofilen, int ofilec)
743 switch (setjmp(env)) {
746 fp = mhl_action ? (*mhl_action) (fname) :
749 advise(fname, "unable to open");
757 cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname);
759 SIGNAL(SIGINT, intrser);
760 mhlfile(fp, cp, ofilen, ofilec);
764 SIGNAL(SIGINT, SIG_IGN);
765 if (mhl_action == NULL && fp != stdin)
770 holder.c_text = NULL;
772 free_queue(&msghd, &msgtl);
773 for (c1 = fmthd; c1; c1 = c1->c_next)
774 c1->c_flags &= ~HDROUTPUT;
781 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
784 struct mcomp *c1, *c2, *c3;
785 char **ip, name[NAMESZ], buf[BUFSIZ];
789 printf("%s", ofilen == 1 ? delim3 : delim4);
793 printf(" Forwarded Message%s",
794 ofilec > 1 ? "s" : "");
796 printf(" Message %d", ofilen);
804 if ((global.c_flags & CLEARSCR))
809 printf(">>> %s\n\n", mname);
820 printf(">>> %s\n\n", mname);
826 for (state = FLD;;) {
827 switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
830 for (ip = ignores; *ip; ip++)
831 if (!mh_strcasecmp(name, *ip)) {
832 while (state == FLDPLUS)
833 state = m_getfld(state, name, buf, sizeof(buf), fp);
839 for (c2 = fmthd; c2; c2 = c2->c_next)
840 if (!mh_strcasecmp(c2->c_name, name))
843 if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
844 for (c1 = msghd; c1; c1 = c1->c_next)
845 if (!mh_strcasecmp(c1->c_name,
847 c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
851 c1 = add_queue(&msghd, &msgtl, name, buf, 0);
852 while (state == FLDPLUS) {
853 state = m_getfld(state, name, buf,
855 c1->c_text = add(buf, c1->c_text);
858 c1->c_flags |= EXTRA;
864 for (c1 = fmthd; c1; c1 = c1->c_next) {
865 if (c1->c_flags & CLEARTEXT) {
866 putcomp(c1, c1, ONECOMP);
869 if (!mh_strcasecmp(c1->c_name, "messagename")) {
870 holder.c_text = concat("(Message ",
872 putcomp(c1, &holder, ONECOMP);
874 holder.c_text = NULL;
877 if (!mh_strcasecmp(c1->c_name, "extras")) {
878 for (c2 = msghd; c2; c2 = c2->c_next)
879 if (c2->c_flags & EXTRA)
880 putcomp(c1, c2, TWOCOMP);
883 if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
884 holder.c_text = mh_xmalloc(sizeof(buf));
885 strncpy(holder.c_text, buf, sizeof(buf));
886 while (state == BODY) {
887 putcomp(c1, &holder, BODYCOMP);
888 state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
891 holder.c_text = NULL;
894 for (c2 = msghd; c2; c2 = c2->c_next)
895 if (!mh_strcasecmp(c2->c_name,
897 putcomp(c1, c2, ONECOMP);
898 if (!(c1->c_flags & SPLIT))
906 advise(NULL, "format error in message %s", mname);
911 adios(NULL, "getfld() returned %d", state);
918 mcomp_flags(char *name)
922 for (ap = pairs; ap->p_name; ap++)
923 if (!mh_strcasecmp(ap->p_name, name))
924 return (ap->p_flags);
931 mcomp_add(long flags, char *s1, char *s2)
935 if (!(flags & ADDRFMT))
938 if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
941 return add(s1, add(",\n", s2));
948 struct pqpair *pq_next;
953 mcomp_format(struct mcomp *c1, struct mcomp *c2)
957 char buffer[BUFSIZ], error[BUFSIZ];
959 struct pqpair *p, *q;
968 dat[3] = sizeof(buffer) - 1;
970 fmt_compile(c1->c_nfs, &c1->c_fmt);
972 if (!(c1->c_flags & ADDRFMT)) {
973 FINDCOMP(cptr, "text");
976 if ((cp = strrchr(ap, '\n'))) /* drop ending newline */
980 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
981 /* Don't need to append a newline, dctime() already did */
982 c2->c_text = getcpy(buffer);
988 (q = &pq)->pq_next = NULL;
989 while ((cp = getname(ap))) {
990 if ((p = (struct pqpair *)
991 calloc((size_t) 1, sizeof(*p))) == NULL)
992 adios(NULL, "unable to allocate pqpair memory");
994 if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
995 p->pq_text = getcpy(cp);
996 p->pq_error = getcpy(error);
998 p->pq_text = getcpy(mp->m_text);
1001 q = (q->pq_next = p);
1004 for (p = pq.pq_next; p; p = q) {
1005 FINDCOMP(cptr, "text");
1007 cptr->c_text = p->pq_text;
1008 FINDCOMP(cptr, "error");
1010 cptr->c_text = p->pq_error;
1012 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
1015 c2->c_text = add(",\n", c2->c_text);
1016 if (*(cp = buffer + strlen(buffer) - 1) == '\n')
1018 c2->c_text = add(buffer, c2->c_text);
1028 c2->c_text = add("\n", c2->c_text);
1033 static struct mcomp *
1034 add_queue(struct mcomp **head, struct mcomp **tail, char *name,
1035 char *text, int flags)
1039 if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
1040 adios(NULL, "unable to allocate comp memory");
1042 c1->c_flags = flags & ~INIT;
1043 if ((c1->c_name = name ? getcpy(name) : NULL))
1044 c1->c_flags |= mcomp_flags(c1->c_name);
1045 c1->c_text = text ? getcpy(text) : NULL;
1048 c1->c_ovtxt = getcpy(global.c_ovtxt);
1049 c1->c_offset = global.c_offset;
1050 c1->c_ovoff = global. c_ovoff;
1051 c1->c_width = c1->c_length = 0;
1052 c1->c_cwidth = global.c_cwidth;
1053 c1->c_flags |= global.c_flags & GFLAGS;
1058 (*tail)->c_next = c1;
1066 free_queue(struct mcomp **head, struct mcomp **tail)
1068 struct mcomp *c1, *c2;
1070 for (c1 = *head; c1; c1 = c2) {
1081 free((char *) c1->c_fmt);
1085 *head = *tail = NULL;
1090 putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
1097 llim = c1->c_length ? c1->c_length : -1;
1098 wid = c1->c_width ? c1->c_width : global.c_width;
1099 ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff)
1101 if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
1103 if (wid < ovoff + strlen(ovtxt) + 5)
1104 adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
1107 if (c1->c_flags & CLEARTEXT) {
1113 if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT)))
1114 mcomp_format(c1, c2);
1116 if (c1->c_flags & CENTER) {
1117 count = (c1->c_width ? c1->c_width : global.c_width)
1118 - c1->c_offset - strlen(c2->c_text);
1119 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT))
1120 count -= strlen(c1->c_text ? c1->c_text : c1->c_name)
1122 lm = c1->c_offset + (count / 2);
1128 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
1129 if (c1->c_flags & UPPERCASE) /* uppercase component also */
1130 for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
1133 putstr(c1->c_text ? c1->c_text : c1->c_name);
1134 if (flag != BODYCOMP) {
1136 if (!(c1->c_flags & SPLIT))
1137 c1->c_flags |= HDROUTPUT;
1140 if ((count = c1->c_cwidth -
1141 strlen(c1->c_text ? c1->c_text : c1->c_name) - 2) > 0)
1145 c1->c_flags |= HDROUTPUT; /* for BODYCOMP */
1148 if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT)
1149 && !(c2->c_flags & NOCOMPONENT)) {
1150 if (c1->c_flags & UPPERCASE)
1151 for (cp = c2->c_name; *cp; cp++)
1156 if (!(c1->c_flags & SPLIT))
1157 c2->c_flags |= HDROUTPUT;
1160 if ((count = c1->c_cwidth - strlen(c2->c_name) - 2) > 0)
1164 if (c1->c_flags & UPPERCASE)
1165 for (cp = c2->c_text; *cp; cp++)
1171 if (flag == TWOCOMP)
1172 count = (c1->c_cwidth >= 0) ?
1173 c1->c_cwidth : strlen(c2->c_name) + 2;
1175 count = (c1->c_cwidth >= 0) ?
1176 c1->c_cwidth : strlen(c1->c_text ?
1177 c1->c_text : c1->c_name) + 2;
1179 count += c1->c_offset;
1181 if ((cp = oneline(c2->c_text, c1->c_flags)))
1185 while ((cp = oneline(c2->c_text, c1->c_flags))) {
1187 if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT))
1188 putstr(c1->c_text ? c1->c_text : c1->c_name);
1194 if (flag == BODYCOMP && term == '\n')
1195 c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
1200 oneline(char *stuff, long flags)
1208 return (onelp = NULL);
1212 if (flags & COMPRESS) {
1213 for (spc = 1, cp = ret; *onelp; onelp++)
1214 if (isspace(*onelp)) {
1215 if (*onelp == '\n' &&
1217 (flags & ADDRFMT))) {
1232 while (*onelp && *onelp != '\n')
1234 if (*onelp == '\n') {
1238 if (flags & LEFTADJUST)
1239 while (*ret == ' ' || *ret == '\t')
1242 if (*onelp == 0 && term == '\n' && (flags & NONEWLINE))
1250 putstr(char *string)
1252 if (!column && lm > 0) {
1282 if (row != global.c_length)
1286 read(fileno(stdout), buf, sizeof(buf));
1287 if (strchr(buf, '\n')) {
1288 if (global.c_flags & CLEARSCR)
1293 row = global.c_length / 3;
1312 ** If we are forwarding this message, and the first
1313 ** column contains a dash, then add a dash and a space.
1315 if (column == 0 && forwflg && ch == '-') {
1324 if (column >= wid) {
1328 putstr(ovtxt ? ovtxt : "");
1340 #ifndef RELIABLE_SIGNALS
1341 SIGNAL(SIGINT, intrser);
1353 #ifndef RELIABLE_SIGNALS
1354 SIGNAL(SIGPIPE, pipeser);
1364 #ifndef RELIABLE_SIGNALS
1365 SIGNAL(SIGQUIT, quitser);
1378 mhladios(char *what, char *fmt, ...)
1383 advertise(what, NULL, fmt, ap);
1394 longjmp(mhlenv, DONE);
1400 static int m_pid = NOTOK;
1401 static int sd = NOTOK;
1408 if (mhl_action && (sd = dup(fileno(stdout))) == NOTOK)
1409 adios("standard output", "unable to dup()");
1411 if (pipe(pd) == NOTOK)
1412 adios("pipe", "unable to");
1414 switch (m_pid = fork()) {
1416 adios("fork", "unable to");
1419 SIGNAL(SIGINT, SIG_DFL);
1420 SIGNAL(SIGQUIT, SIG_DFL);
1423 if (pd[0] != fileno(stdin)) {
1424 dup2(pd[0], fileno(stdin));
1427 execlp(name, mhbasename(name), NULL);
1428 fprintf(stderr, "unable to exec ");
1434 if (pd[1] != fileno(stdout)) {
1435 dup2(pd[1], fileno(stdout));
1450 if (dup2(sd, fileno(stdout)) == NOTOK)
1451 adios("standard output", "unable to dup2()");