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 { "length lines", 0 },
53 { "width columns", 0 },
55 { "sleep seconds", 0 },
65 { "digest list", -6 },
67 { "volume number", -6 },
69 { "issue number", -5 },
75 #define NOCOMPONENT 0x000001 /* don't show component name */
76 #define UPPERCASE 0x000002 /* display in all upper case */
77 #define CENTER 0x000004 /* center line */
78 #define CLEARTEXT 0x000008 /* cleartext */
79 #define EXTRA 0x000010 /* an "extra" component */
80 #define HDROUTPUT 0x000020 /* already output */
81 #define LEFTADJUST 0x000040 /* left justify multiple lines */
82 #define COMPRESS 0x000080 /* compress text */
83 #define ADDRFMT 0x000100 /* contains addresses */
84 #define DATEFMT 0x000200 /* contains dates */
85 #define FORMAT 0x000400 /* parse address/date/RFC-2047 field */
86 #define INIT 0x000800 /* initialize component */
87 #define SPLIT 0x001000 /* split headers (don't concatenate) */
88 #define NONEWLINE 0x002000 /* don't write trailing newline */
89 #define LBITS "\020\01NOCOMPONENT\02UPPERCASE\03CENTER\04CLEARTEXT\05EXTRA\06HDROUTPUT\07LEFTADJUST\010COMPRESS\011ADDRFMT\012DATEFMT\013FORMAT\014INIT\015SPLIT\016NONEWLINE"
90 #define GFLAGS (NOCOMPONENT | UPPERCASE | CENTER | LEFTADJUST | COMPRESS | SPLIT)
93 char *c_name; /* component name */
94 char *c_text; /* component text */
95 char *c_ovtxt; /* text overflow indicator */
96 char *c_nfs; /* iff FORMAT */
97 struct format *c_fmt; /* .. */
98 int c_offset; /* left margin indentation */
99 int c_ovoff; /* overflow indentation */
100 int c_width; /* width of field */
101 int c_cwidth; /* width of component */
102 int c_length; /* length in lines */
104 struct mcomp *c_next;
107 static struct mcomp *msghd = NULL;
108 static struct mcomp *msgtl = NULL;
109 static struct mcomp *fmthd = NULL;
110 static struct mcomp *fmttl = NULL;
112 static struct mcomp global = {
113 NULL, NULL, "", NULL, NULL, 0, -1, 80, -1, 40, 0, 0
116 static struct mcomp holder = {
117 NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, NOCOMPONENT, 0
125 static struct pair pairs[] = {
128 { "Sender", ADDRFMT },
129 { "Reply-To", ADDRFMT },
133 { "Resent-Date", DATEFMT },
134 { "Resent-From", ADDRFMT },
135 { "Resent-Sender", ADDRFMT },
136 { "Resent-Reply-To", ADDRFMT },
137 { "Resent-To", ADDRFMT },
138 { "Resent-Cc", ADDRFMT },
139 { "Resent-Bcc", ADDRFMT },
149 static struct triple triples[] = {
150 { "nocomponent", NOCOMPONENT, 0 },
151 { "uppercase", UPPERCASE, 0 },
152 { "nouppercase", 0, UPPERCASE },
153 { "center", CENTER, 0 },
154 { "nocenter", 0, CENTER },
155 { "leftadjust", LEFTADJUST, 0 },
156 { "noleftadjust", 0, LEFTADJUST },
157 { "compress", COMPRESS, 0 },
158 { "nocompress", 0, COMPRESS },
159 { "split", SPLIT, 0 },
160 { "nosplit", 0, SPLIT },
161 { "addrfield", ADDRFMT, DATEFMT },
162 { "datefield", DATEFMT, ADDRFMT },
163 { "newline", 0, NONEWLINE },
164 { "nonewline", NONEWLINE, 0 },
169 static int dobody = 1;
170 static int forwflg = 0;
171 static int forwall = 0;
173 static int sleepsw = NOTOK;
175 static char *digest = NULL;
176 static int volume = 0;
177 static int issue = 0;
179 static int exitstat = 0;
180 static int mhldebug = 0;
184 static int ontty = NOTTY;
197 static unsigned char *onelp;
201 static int num_ignores = 0;
202 static char *ignores[MAXARGS];
205 static jmp_buf mhlenv;
207 static char delim3[] =
208 "\n----------------------------------------------------------------------\n\n";
209 static char delim4[] = "\n------------------------------\n\n";
211 static FILE *(*mhl_action) () = (FILE *(*) ()) 0;
215 ** Redefine a couple of functions.
216 ** These are undefined later in the code.
218 #define adios mhladios
224 static void mhl_format(char *, int, int);
225 static int evalvar(struct mcomp *);
226 static int ptoi(char *, int *);
227 static int ptos(char *, char **);
228 static char *parse(void);
229 static void process(char *, char *, int, int);
230 static void mhlfile(FILE *, char *, int, int);
231 static int mcomp_flags(char *);
232 static char *mcomp_add(long, char *, char *);
233 static void mcomp_format(struct mcomp *, struct mcomp *);
234 static struct mcomp *add_queue(struct mcomp **, struct mcomp **,
235 char *, char *, int);
236 static void free_queue(struct mcomp **, struct mcomp **);
237 static void putcomp(struct mcomp *, struct mcomp *, int);
238 static char *oneline(char *, long);
239 static void putstr(char *);
240 static void putch(char);
241 static RETSIGTYPE intrser(int);
242 static RETSIGTYPE pipeser(int);
243 static RETSIGTYPE quitser(int);
244 static void mhladios(char *, char *, ...);
245 static void mhldone(int);
246 static void m_popen(char *);
250 int SOprintf(char *, ...); /* from termsbr.c */
251 int sc_width(void); /* from termsbr.c */
252 int sc_length(void); /* from termsbr.c */
256 main(int argc, char **argv)
259 int i, width = 0, vecp = 0;
260 char *cp, *folder = NULL, *form = NULL;
261 char buf[BUFSIZ], *files[MAXARGS];
262 char **argp, **arguments;
266 setlocale(LC_ALL, "");
269 invo_name = mhbasename(argv[0]);
271 /* read user profile/context */
274 arguments = getarguments(invo_name, argc, argv, 1);
277 if ((cp = getenv("MHLDEBUG")) && *cp)
280 while ((cp = *argp++)) {
282 switch (smatch(++cp, mhlswitches)) {
284 ambigsw(cp, mhlswitches);
287 adios(NULL, "-%s unknown\n", cp);
290 snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
291 print_help(buf, mhlswitches, 1);
294 print_version(invo_name);
298 if (!(folder = *argp++) || *folder == '-')
299 adios(NULL, "missing argument to %s",
303 if (!(form = *argp++) || *form == '-')
304 adios(NULL, "missing argument to %s",
309 if (!(cp = *argp++) || *cp == '-')
310 adios(NULL, "missing argument to %s",
312 sleepsw = atoi(cp); /* ZERO ok! */
316 if (!(progsw = *argp++) || *progsw == '-')
317 adios(NULL, "missing argument to %s",
322 if (!(cp = *argp++) || *cp == '-')
323 adios(NULL, "missing argument to %s",
325 if ((length = atoi(cp)) < 1)
326 adios(NULL, "bad argument %s %s",
330 if (!(cp = *argp++) || *cp == '-')
331 adios(NULL, "missing argument to %s",
333 if ((width = atoi(cp)) < 1)
334 adios(NULL, "bad argument %s %s",
339 if (!(digest = *argp++) ||
341 adios(NULL, "missing argument to %s",
345 if (!(cp = *argp++) || *cp == '-')
346 adios(NULL, "missing argument to %s",
348 if ((issue = atoi(cp)) < 1)
349 adios(NULL, "bad argument %s %s",
353 if (!(cp = *argp++) || *cp == '-')
354 adios(NULL, "missing argument to %s",
356 if ((volume = atoi(cp)) < 1)
357 adios(NULL, "bad argument %s %s",
362 forwall++; /* fall */
376 folder = getenv("mhfolder");
378 if (isatty(fileno(stdout))) {
380 SIGNAL(SIGINT, SIG_IGN);
381 SIGNAL2(SIGQUIT, quitser);
383 SIGNAL2(SIGPIPE, pipeser);
384 m_popen(progsw ? progsw : moreproc);
390 mhl_format(form ? form : mhlformat, length, width);
393 process(folder, NULL, 1, vecp = 1);
395 for (i = 0; i < vecp; i++)
396 process(folder, files[i], i + 1, vecp);
401 printf("%s", delim4);
403 snprintf(buf, sizeof(buf),
404 "End of %s Digest\n", digest);
406 snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue);
409 for (cp = buf + i; i > 1; i--)
415 printf("\n------- End of Forwarded Message%s\n\n",
416 vecp > 1 ? "s" : "");
420 if (ferror(stdout)) {
421 adios("output", "error writing");
432 mhl_format(char *file, int length, int width)
436 char *ap, buffer[BUFSIZ], name[NAMESZ];
440 static dev_t dev = 0;
441 static ino_t ino = 0;
442 static time_t mtime = 0;
445 if (stat(etcpath(file), &st) != NOTOK
446 && mtime == st.st_mtime
451 free_queue(&fmthd, &fmttl);
454 if ((fp = fopen(etcpath(file), "r")) == NULL)
455 adios(file, "unable to open format file");
457 if (fstat(fileno(fp), &st) != NOTOK) {
463 global.c_ovtxt = global.c_nfs = NULL;
467 if ((i = sc_width()) > 5)
469 global.c_cwidth = -1;
470 if ((i = sc_length()) > 5)
471 global.c_length = i - 1;
473 *(ip = ignores) = NULL;
475 while (vfgets(fp, &ap) == OK) {
480 if ((cp = strchr(bp, '\n')))
484 c1 = add_queue(&fmthd, &fmttl, NULL, bp + 1,
490 strncpy(name, parse(), sizeof(name));
496 ** Split this list of fields to ignore, and copy
497 ** it to the end of the current "ignores" list.
499 if (!mh_strcasecmp(name, "ignores")) {
500 char **tmparray, **p;
503 /* split the fields */
504 tmparray = brkstring(getcpy(++parptr), ",",
507 /* count number of fields split */
513 ** copy pointers to split fields
516 ip = copyip(tmparray, ip,
517 MAXARGS - num_ignores);
523 if (evalvar(&global))
524 adios(NULL, "format file syntax error: %s", bp);
531 c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT);
532 while (*parptr == ':' || *parptr == ',') {
535 adios(NULL, "format file syntax error: %s", bp);
537 if (!c1->c_nfs && global.c_nfs) {
538 if ((c1->c_flags & DATEFMT) &&
539 (global.c_flags & DATEFMT)) {
540 c1->c_nfs = getcpy(global.c_nfs);
541 } else if ((c1->c_flags & ADDRFMT) &&
542 (global.c_flags & ADDRFMT)) {
543 c1->c_nfs = getcpy(global.c_nfs);
549 adios(NULL, "format file syntax error: %s", bp);
555 for (c1 = fmthd; c1; c1 = c1->c_next) {
556 fprintf(stderr, "c1: name=\"%s\" text=\"%s\" ovtxt=\"%s\"\n", c1->c_name, c1->c_text, c1->c_ovtxt);
557 fprintf(stderr, "\tnfs=0x%x fmt=0x%x\n", (unsigned int)(unsigned long) c1->c_nfs, (unsigned int)(unsigned long) c1->c_fmt);
558 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);
559 fprintf (stderr, "\tflags=%s\n", snprintb(buffer, sizeof(buffer), (unsigned) c1->c_flags, LBITS));
565 global.c_length = length;
567 global.c_width = width;
568 if (global.c_length < 5)
569 global.c_length = 10000;
570 if (global.c_width < 5)
571 global.c_width = 10000;
576 evalvar(struct mcomp *c1)
578 char *cp, name[NAMESZ];
583 strncpy(name, parse(), sizeof(name));
585 if (!mh_strcasecmp(name, "component")) {
586 if (ptos(name, &c1->c_text))
588 c1->c_flags &= ~NOCOMPONENT;
592 if (!mh_strcasecmp(name, "overflowtext"))
593 return ptos(name, &c1->c_ovtxt);
595 if (!mh_strcasecmp(name, "formatfield")) {
600 cp = concat("=", cp, NULL);
601 nfs = new_fs(cp, NULL);
603 c1->c_nfs = getcpy(nfs);
604 c1->c_flags |= FORMAT;
608 if (!mh_strcasecmp(name, "decode")) {
611 nfs = new_fs("=%(decode{text})", NULL);
612 c1->c_nfs = getcpy(nfs);
613 c1->c_flags |= FORMAT;
617 if (!mh_strcasecmp(name, "offset"))
618 return ptoi(name, &c1->c_offset);
619 if (!mh_strcasecmp(name, "overflowoffset"))
620 return ptoi(name, &c1->c_ovoff);
621 if (!mh_strcasecmp(name, "width"))
622 return ptoi(name, &c1->c_width);
623 if (!mh_strcasecmp(name, "compwidth"))
624 return ptoi(name, &c1->c_cwidth);
625 if (!mh_strcasecmp(name, "length"))
626 return ptoi(name, &c1->c_length);
628 for (ap = triples; ap->t_name; ap++)
629 if (!mh_strcasecmp(ap->t_name, name)) {
630 c1->c_flags |= ap->t_on;
631 c1->c_flags &= ~ap->t_off;
640 ptoi(char *name, int *i)
644 if (*parptr++ != '=' || !*(cp = parse())) {
645 advise(NULL, "missing argument to variable %s", name);
655 ptos(char *name, char **s)
659 if (*parptr++ != '=') {
660 advise(NULL, "missing argument to variable %s", name);
664 if (*parptr != '"') {
665 for (cp = parptr; *parptr && *parptr != ':' && *parptr != ',';
669 for (cp = ++parptr; *parptr && *parptr != '"'; parptr++)
670 if (*parptr == QUOTE)
677 if ((*parptr = c) == '"')
688 static char result[NAMESZ];
690 for (cp = result; *parptr && (cp - result < NAMESZ); parptr++) {
709 process(char *folder, char *fname, int ofilen, int ofilec)
715 switch (setjmp(env)) {
718 fp = mhl_action ? (*mhl_action) (fname) :
721 advise(fname, "unable to open");
729 cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname);
731 SIGNAL(SIGINT, intrser);
732 mhlfile(fp, cp, ofilen, ofilec);
736 SIGNAL(SIGINT, SIG_IGN);
737 if (mhl_action == NULL && fp != stdin)
742 holder.c_text = NULL;
744 free_queue(&msghd, &msgtl);
745 for (c1 = fmthd; c1; c1 = c1->c_next)
746 c1->c_flags &= ~HDROUTPUT;
753 mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
756 struct mcomp *c1, *c2, *c3;
757 char **ip, name[NAMESZ], buf[BUFSIZ];
761 printf("%s", ofilen == 1 ? delim3 : delim4);
765 printf(" Forwarded Message%s",
766 ofilec > 1 ? "s" : "");
768 printf(" Message %d", ofilen);
771 } else if (ofilec > 1) {
775 printf(">>> %s\n\n", mname);
778 for (state = FLD;;) {
779 switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) {
782 for (ip = ignores; *ip; ip++)
783 if (!mh_strcasecmp(name, *ip)) {
784 while (state == FLDPLUS)
785 state = m_getfld(state, name, buf, sizeof(buf), fp);
791 for (c2 = fmthd; c2; c2 = c2->c_next)
792 if (!mh_strcasecmp(c2->c_name, name))
795 if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT))
796 for (c1 = msghd; c1; c1 = c1->c_next)
797 if (!mh_strcasecmp(c1->c_name,
799 c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text);
803 c1 = add_queue(&msghd, &msgtl, name, buf, 0);
804 while (state == FLDPLUS) {
805 state = m_getfld(state, name, buf,
807 c1->c_text = add(buf, c1->c_text);
810 c1->c_flags |= EXTRA;
816 for (c1 = fmthd; c1; c1 = c1->c_next) {
817 if (c1->c_flags & CLEARTEXT) {
818 putcomp(c1, c1, ONECOMP);
821 if (!mh_strcasecmp(c1->c_name, "messagename")) {
822 holder.c_text = concat("(Message ",
824 putcomp(c1, &holder, ONECOMP);
826 holder.c_text = NULL;
829 if (!mh_strcasecmp(c1->c_name, "extras")) {
830 for (c2 = msghd; c2; c2 = c2->c_next)
831 if (c2->c_flags & EXTRA)
832 putcomp(c1, c2, TWOCOMP);
835 if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
836 holder.c_text = mh_xmalloc(sizeof(buf));
837 strncpy(holder.c_text, buf, sizeof(buf));
838 while (state == BODY) {
839 putcomp(c1, &holder, BODYCOMP);
840 state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
843 holder.c_text = NULL;
846 for (c2 = msghd; c2; c2 = c2->c_next)
847 if (!mh_strcasecmp(c2->c_name,
849 putcomp(c1, c2, ONECOMP);
850 if (!(c1->c_flags & SPLIT))
858 advise(NULL, "format error in message %s", mname);
863 adios(NULL, "getfld() returned %d", state);
870 mcomp_flags(char *name)
874 for (ap = pairs; ap->p_name; ap++)
875 if (!mh_strcasecmp(ap->p_name, name))
876 return (ap->p_flags);
883 mcomp_add(long flags, char *s1, char *s2)
887 if (!(flags & ADDRFMT))
890 if (s2 && *(dp = s2 + strlen(s2) - 1) == '\n')
893 return add(s1, add(",\n", s2));
900 struct pqpair *pq_next;
905 mcomp_format(struct mcomp *c1, struct mcomp *c2)
909 char buffer[BUFSIZ], error[BUFSIZ];
911 struct pqpair *p, *q;
920 dat[3] = sizeof(buffer) - 1;
922 fmt_compile(c1->c_nfs, &c1->c_fmt);
924 if (!(c1->c_flags & ADDRFMT)) {
925 FINDCOMP(cptr, "text");
928 if ((cp = strrchr(ap, '\n'))) /* drop ending newline */
932 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
933 /* Don't need to append a newline, dctime() already did */
934 c2->c_text = getcpy(buffer);
940 (q = &pq)->pq_next = NULL;
941 while ((cp = getname(ap))) {
942 if ((p = (struct pqpair *)
943 calloc((size_t) 1, sizeof(*p))) == NULL)
944 adios(NULL, "unable to allocate pqpair memory");
946 if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
947 p->pq_text = getcpy(cp);
948 p->pq_error = getcpy(error);
950 p->pq_text = getcpy(mp->m_text);
953 q = (q->pq_next = p);
956 for (p = pq.pq_next; p; p = q) {
957 FINDCOMP(cptr, "text");
959 cptr->c_text = p->pq_text;
960 FINDCOMP(cptr, "error");
962 cptr->c_text = p->pq_error;
964 fmt_scan(c1->c_fmt, buffer, sizeof(buffer) - 1, dat);
967 c2->c_text = add(",\n", c2->c_text);
968 if (*(cp = buffer + strlen(buffer) - 1) == '\n')
970 c2->c_text = add(buffer, c2->c_text);
980 c2->c_text = add("\n", c2->c_text);
985 static struct mcomp *
986 add_queue(struct mcomp **head, struct mcomp **tail, char *name,
987 char *text, int flags)
991 if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
992 adios(NULL, "unable to allocate comp memory");
994 c1->c_flags = flags & ~INIT;
995 if ((c1->c_name = name ? getcpy(name) : NULL))
996 c1->c_flags |= mcomp_flags(c1->c_name);
997 c1->c_text = text ? getcpy(text) : NULL;
1000 c1->c_ovtxt = getcpy(global.c_ovtxt);
1001 c1->c_offset = global.c_offset;
1002 c1->c_ovoff = global. c_ovoff;
1003 c1->c_width = c1->c_length = 0;
1004 c1->c_cwidth = global.c_cwidth;
1005 c1->c_flags |= global.c_flags & GFLAGS;
1010 (*tail)->c_next = c1;
1018 free_queue(struct mcomp **head, struct mcomp **tail)
1020 struct mcomp *c1, *c2;
1022 for (c1 = *head; c1; c1 = c2) {
1033 free((char *) c1->c_fmt);
1037 *head = *tail = NULL;
1042 putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
1049 llim = c1->c_length ? c1->c_length : -1;
1050 wid = c1->c_width ? c1->c_width : global.c_width;
1051 ovoff = (c1->c_ovoff >= 0 ? c1->c_ovoff : global.c_ovoff)
1053 if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
1055 if (wid < ovoff + strlen(ovtxt) + 5)
1056 adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
1059 if (c1->c_flags & CLEARTEXT) {
1065 if (c1->c_nfs && (c1->c_flags & (ADDRFMT | DATEFMT | FORMAT)))
1066 mcomp_format(c1, c2);
1068 if (c1->c_flags & CENTER) {
1069 count = (c1->c_width ? c1->c_width : global.c_width)
1070 - c1->c_offset - strlen(c2->c_text);
1071 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT))
1072 count -= strlen(c1->c_text ? c1->c_text : c1->c_name)
1074 lm = c1->c_offset + (count / 2);
1080 if (!(c1->c_flags & HDROUTPUT) && !(c1->c_flags & NOCOMPONENT)) {
1081 if (c1->c_flags & UPPERCASE) /* uppercase component also */
1082 for (cp = (c1->c_text ? c1->c_text : c1->c_name); *cp; cp++)
1085 putstr(c1->c_text ? c1->c_text : c1->c_name);
1086 if (flag != BODYCOMP) {
1088 if (!(c1->c_flags & SPLIT))
1089 c1->c_flags |= HDROUTPUT;
1092 if ((count = c1->c_cwidth -
1093 strlen(c1->c_text ? c1->c_text : c1->c_name) - 2) > 0)
1097 c1->c_flags |= HDROUTPUT; /* for BODYCOMP */
1100 if (flag == TWOCOMP && !(c2->c_flags & HDROUTPUT)
1101 && !(c2->c_flags & NOCOMPONENT)) {
1102 if (c1->c_flags & UPPERCASE)
1103 for (cp = c2->c_name; *cp; cp++)
1108 if (!(c1->c_flags & SPLIT))
1109 c2->c_flags |= HDROUTPUT;
1112 if ((count = c1->c_cwidth - strlen(c2->c_name) - 2) > 0)
1116 if (c1->c_flags & UPPERCASE)
1117 for (cp = c2->c_text; *cp; cp++)
1123 if (flag == TWOCOMP)
1124 count = (c1->c_cwidth >= 0) ?
1125 c1->c_cwidth : strlen(c2->c_name) + 2;
1127 count = (c1->c_cwidth >= 0) ?
1128 c1->c_cwidth : strlen(c1->c_text ?
1129 c1->c_text : c1->c_name) + 2;
1131 count += c1->c_offset;
1133 if ((cp = oneline(c2->c_text, c1->c_flags)))
1137 while ((cp = oneline(c2->c_text, c1->c_flags))) {
1139 if (flag == BODYCOMP && !(c1->c_flags & NOCOMPONENT))
1140 putstr(c1->c_text ? c1->c_text : c1->c_name);
1146 if (flag == BODYCOMP && term == '\n')
1147 c1->c_flags &= ~HDROUTPUT; /* Buffer ended on a newline */
1152 oneline(char *stuff, long flags)
1160 return (onelp = NULL);
1164 if (flags & COMPRESS) {
1165 for (spc = 1, cp = ret; *onelp; onelp++)
1166 if (isspace(*onelp)) {
1167 if (*onelp == '\n' &&
1169 (flags & ADDRFMT))) {
1184 while (*onelp && *onelp != '\n')
1186 if (*onelp == '\n') {
1190 if (flags & LEFTADJUST)
1191 while (*ret == ' ' || *ret == '\t')
1194 if (*onelp == 0 && term == '\n' && (flags & NONEWLINE))
1202 putstr(char *string)
1204 if (!column && lm > 0) {
1234 if (row != global.c_length)
1238 read(fileno(stdout), buf, sizeof(buf));
1239 if (strchr(buf, '\n')) {
1243 row = global.c_length / 3;
1262 ** If we are forwarding this message, and the first
1263 ** column contains a dash, then add a dash and a space.
1265 if (column == 0 && forwflg && ch == '-') {
1274 if (column >= wid) {
1278 putstr(ovtxt ? ovtxt : "");
1290 #ifndef RELIABLE_SIGNALS
1291 SIGNAL(SIGINT, intrser);
1303 #ifndef RELIABLE_SIGNALS
1304 SIGNAL(SIGPIPE, pipeser);
1314 #ifndef RELIABLE_SIGNALS
1315 SIGNAL(SIGQUIT, quitser);
1328 mhladios(char *what, char *fmt, ...)
1333 advertise(what, NULL, fmt, ap);
1344 longjmp(mhlenv, DONE);
1350 static int m_pid = NOTOK;
1351 static int sd = NOTOK;
1358 if (mhl_action && (sd = dup(fileno(stdout))) == NOTOK)
1359 adios("standard output", "unable to dup()");
1361 if (pipe(pd) == NOTOK)
1362 adios("pipe", "unable to");
1364 switch (m_pid = fork()) {
1366 adios("fork", "unable to");
1369 SIGNAL(SIGINT, SIG_DFL);
1370 SIGNAL(SIGQUIT, SIG_DFL);
1373 if (pd[0] != fileno(stdin)) {
1374 dup2(pd[0], fileno(stdin));
1377 execlp(name, mhbasename(name), NULL);
1378 fprintf(stderr, "unable to exec ");
1384 if (pd[1] != fileno(stdout)) {
1385 dup2(pd[1], fileno(stdout));
1400 if (dup2(sd, fileno(stdout)) == NOTOK)
1401 adios("standard output", "unable to dup2()");