xref: /csrg-svn/libexec/bugfiler/redist.c (revision 46667)
130158Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
542663Sbostic  * %sccs.include.redist.c%
630158Sbostic  */
730158Sbostic 
830158Sbostic #ifndef lint
9*46667Sbostic static char sccsid[] = "@(#)redist.c	5.11 (Berkeley) 02/25/91";
1033416Sbostic #endif /* not lint */
1130158Sbostic 
12*46667Sbostic #include <sys/param.h>
13*46667Sbostic #include <dirent.h>
1430158Sbostic #include <stdio.h>
1533024Sbostic #include <ctype.h>
16*46667Sbostic #include <string.h>
17*46667Sbostic #include "bug.h"
1837887Sbostic #include "pathnames.h"
1930158Sbostic 
2030158Sbostic /*
2130158Sbostic  * redist --
2230158Sbostic  *	Redistribute a bug report to those people indicated in the
2330158Sbostic  *	redistribution list file.
2430158Sbostic  */
2530158Sbostic redist()
2630158Sbostic {
2730890Sbostic 	extern FILE	*dfp;		/* dist file fp */
2830890Sbostic 	extern char	pfile[];	/* permanent bug file */
2933024Sbostic 	register char	*C1, *C2;
3033024Sbostic 	FILE	*pf, *popen();
3133024Sbostic 	int	group;
3230890Sbostic 	char	*index();
3330158Sbostic 
3433024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
3530890Sbostic 	if (!freopen(bfr, "r", stdin))
3630158Sbostic 		return;
3733024Sbostic 	for (pf = NULL, group = 0; gets(bfr);) {
3833024Sbostic 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
3930158Sbostic 			continue;
4030158Sbostic 		*C1 = EOS;
4133024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
4233024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
4333024Sbostic 			if (!*C1)			/* if empty list */
4433024Sbostic 				continue;
4533024Sbostic 			if (!pf) {
4633024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
4733024Sbostic 					error("sendmail pipe failed.", CHN);
4833024Sbostic 				if (mailhead[SUBJ_TAG].found)
4933024Sbostic 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
5033024Sbostic 				else
5133024Sbostic 					fputs("Subject: Untitled Bug Report\n", pf);
5233928Skarels 				if (!mailhead[TO_TAG].line) {
5333928Skarels 					if (mailhead[APPAR_TO_TAG].line)
5433928Skarels 					    fprintf(pf, "To%s",
5533928Skarels 					      index(mailhead[APPAR_TO_TAG].line,
5633928Skarels 					      ':'));
5733928Skarels 					else
5833928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
5933928Skarels 				}
6033024Sbostic 				fputs("Resent-To: ", pf);
6133024Sbostic 			}
6233024Sbostic 			/*
6333024Sbostic 			 * write out first entry, then succeeding entries
6433024Sbostic 			 * backward compatible, handles back slashes at end
6533024Sbostic 			 * of line
6633024Sbostic 			 */
6733024Sbostic 			if (group++)
6833024Sbostic 				fputs(", ", pf);
6933024Sbostic 			for (;;) {
7033024Sbostic 				if (C2 = index(C1, '\\'))
7133024Sbostic 					*C2 = EOS;
7233024Sbostic 				fputs(C1, pf);
7333024Sbostic 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
7433024Sbostic 					break;
7533024Sbostic 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
7633024Sbostic 			}
7733024Sbostic 		}
7830158Sbostic 	}
7933024Sbostic 	if (!pf)
8030158Sbostic 		return;
8130158Sbostic 
8230890Sbostic 	putc('\n', pf);
8330158Sbostic 
8430890Sbostic 	rewind(dfp);
8533024Sbostic 	/* add Reference header and copy bug report out */
8633024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
8733024Sbostic 		fputs(bfr, pf);
8833024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
8933024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
9033024Sbostic 		fputs(bfr, pf);
9130890Sbostic 	(void)pclose(pf);
9230158Sbostic }
93