xref: /csrg-svn/libexec/bugfiler/redist.c (revision 61420)
130158Sbostic /*
2*61420Sbostic  * Copyright (c) 1986, 1987, 1993
3*61420Sbostic  *	The Regents of the University of California.  All rights reserved.
433416Sbostic  *
542663Sbostic  * %sccs.include.redist.c%
630158Sbostic  */
730158Sbostic 
830158Sbostic #ifndef lint
9*61420Sbostic static char sccsid[] = "@(#)redist.c	8.1 (Berkeley) 06/04/93";
1033416Sbostic #endif /* not lint */
1130158Sbostic 
1246667Sbostic #include <sys/param.h>
1360083Sbostic 
1460083Sbostic #include <ctype.h>
1546667Sbostic #include <dirent.h>
1630158Sbostic #include <stdio.h>
1746667Sbostic #include <string.h>
1860083Sbostic 
1946667Sbostic #include "bug.h"
2037887Sbostic #include "pathnames.h"
2160083Sbostic #include "extern.h"
2230158Sbostic 
2330158Sbostic /*
2430158Sbostic  * redist --
2530158Sbostic  *	Redistribute a bug report to those people indicated in the
2630158Sbostic  *	redistribution list file.
2730158Sbostic  */
2860083Sbostic void
redist()2930158Sbostic redist()
3030158Sbostic {
3130890Sbostic 	extern FILE	*dfp;		/* dist file fp */
3230890Sbostic 	extern char	pfile[];	/* permanent bug file */
3333024Sbostic 	register char	*C1, *C2;
3460083Sbostic 	FILE	*pf;
3533024Sbostic 	int	group;
3630158Sbostic 
3733024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
3830890Sbostic 	if (!freopen(bfr, "r", stdin))
3930158Sbostic 		return;
4047694Sbostic 	for (pf = NULL, group = 0; fgets(bfr, sizeof(bfr), stdin);) {
4160083Sbostic 		if (C1 = strchr(bfr, '\n'))
4247694Sbostic 			*C1 = '\0';
4360083Sbostic nextline:	if (*bfr == COMMENT ||
4460083Sbostic 		    isspace(*bfr) || !(C1 = index(bfr, ':')))
4530158Sbostic 			continue;
4630158Sbostic 		*C1 = EOS;
4733024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
4833024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
4933024Sbostic 			if (!*C1)			/* if empty list */
5033024Sbostic 				continue;
5133024Sbostic 			if (!pf) {
5233024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
5333024Sbostic 					error("sendmail pipe failed.", CHN);
5433024Sbostic 				if (mailhead[SUBJ_TAG].found)
5547694Sbostic 					fprintf(pf,
5647694Sbostic 					    "%s", mailhead[SUBJ_TAG].line);
5733024Sbostic 				else
5847694Sbostic 					fprintf(pf,
5947694Sbostic 					    "Subject: Untitled Bug Report\n");
6033928Skarels 				if (!mailhead[TO_TAG].line) {
6133928Skarels 					if (mailhead[APPAR_TO_TAG].line)
6233928Skarels 					    fprintf(pf, "To%s",
6360083Sbostic 				      strchr(mailhead[APPAR_TO_TAG].line,
6433928Skarels 					      ':'));
6533928Skarels 					else
6633928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
6733928Skarels 				}
6833024Sbostic 				fputs("Resent-To: ", pf);
6933024Sbostic 			}
7033024Sbostic 			/*
7133024Sbostic 			 * write out first entry, then succeeding entries
7233024Sbostic 			 * backward compatible, handles back slashes at end
7333024Sbostic 			 * of line
7433024Sbostic 			 */
7533024Sbostic 			if (group++)
7633024Sbostic 				fputs(", ", pf);
7733024Sbostic 			for (;;) {
7860083Sbostic 				if (C2 = strchr(C1, '\\'))
7933024Sbostic 					*C2 = EOS;
8033024Sbostic 				fputs(C1, pf);
8147694Sbostic 				if (!fgets(bfr, sizeof(bfr), stdin))
8233024Sbostic 					break;
8360083Sbostic 				if (C1 = strchr(bfr, '\n'))
8447694Sbostic 					*C1 = '\0';
8547694Sbostic 				if (*bfr != ' ' && *bfr != '\t')
8647694Sbostic 					goto nextline;
8747694Sbostic 				for (C1 = bfr;
8847694Sbostic 				    *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
8933024Sbostic 			}
9033024Sbostic 		}
9130158Sbostic 	}
9233024Sbostic 	if (!pf)
9330158Sbostic 		return;
9430158Sbostic 
9530890Sbostic 	putc('\n', pf);
9630158Sbostic 
9730890Sbostic 	rewind(dfp);
9833024Sbostic 	/* add Reference header and copy bug report out */
9933024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
10033024Sbostic 		fputs(bfr, pf);
10133024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
10233024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
10333024Sbostic 		fputs(bfr, pf);
10430890Sbostic 	(void)pclose(pf);
10530158Sbostic }
106