xref: /csrg-svn/libexec/bugfiler/redist.c (revision 33928)
130158Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
533416Sbostic  * Redistribution and use in source and binary forms are permitted
633416Sbostic  * provided that this notice is preserved and that due credit is given
733416Sbostic  * to the University of California at Berkeley. The name of the University
833416Sbostic  * may not be used to endorse or promote products derived from this
933416Sbostic  * software without specific prior written permission. This software
1033416Sbostic  * is provided ``as is'' without express or implied warranty.
1130158Sbostic  */
1230158Sbostic 
1330158Sbostic #ifndef lint
14*33928Skarels static char sccsid[] = "@(#)redist.c	5.7 (Berkeley) 04/01/88";
1533416Sbostic #endif /* not lint */
1630158Sbostic 
1730158Sbostic #include <sys/file.h>
1830158Sbostic #include <stdio.h>
1933024Sbostic #include <ctype.h>
2030158Sbostic #include <bug.h>
2130158Sbostic 
2230158Sbostic /*
2330158Sbostic  * redist --
2430158Sbostic  *	Redistribute a bug report to those people indicated in the
2530158Sbostic  *	redistribution list file.
2630158Sbostic  */
2730158Sbostic redist()
2830158Sbostic {
2930890Sbostic 	extern FILE	*dfp;		/* dist file fp */
3030890Sbostic 	extern char	pfile[];	/* permanent bug file */
3133024Sbostic 	register char	*C1, *C2;
3233024Sbostic 	FILE	*pf, *popen();
3333024Sbostic 	int	group;
3430890Sbostic 	char	*index();
3530158Sbostic 
3633024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
3730890Sbostic 	if (!freopen(bfr, "r", stdin))
3830158Sbostic 		return;
3933024Sbostic 	for (pf = NULL, group = 0; gets(bfr);) {
4033024Sbostic 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
4130158Sbostic 			continue;
4230158Sbostic 		*C1 = EOS;
4333024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
4433024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
4533024Sbostic 			if (!*C1)			/* if empty list */
4633024Sbostic 				continue;
4733024Sbostic 			if (!pf) {
4833024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
4933024Sbostic 					error("sendmail pipe failed.", CHN);
5033024Sbostic 				if (mailhead[SUBJ_TAG].found)
5133024Sbostic 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
5233024Sbostic 				else
5333024Sbostic 					fputs("Subject: Untitled Bug Report\n", pf);
54*33928Skarels 				if (!mailhead[TO_TAG].line) {
55*33928Skarels 					if (mailhead[APPAR_TO_TAG].line)
56*33928Skarels 					    fprintf(pf, "To%s",
57*33928Skarels 					      index(mailhead[APPAR_TO_TAG].line,
58*33928Skarels 					      ':'));
59*33928Skarels 					else
60*33928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
61*33928Skarels 				}
6233024Sbostic 				fputs("Resent-To: ", pf);
6333024Sbostic 			}
6433024Sbostic 			/*
6533024Sbostic 			 * write out first entry, then succeeding entries
6633024Sbostic 			 * backward compatible, handles back slashes at end
6733024Sbostic 			 * of line
6833024Sbostic 			 */
6933024Sbostic 			if (group++)
7033024Sbostic 				fputs(", ", pf);
7133024Sbostic 			for (;;) {
7233024Sbostic 				if (C2 = index(C1, '\\'))
7333024Sbostic 					*C2 = EOS;
7433024Sbostic 				fputs(C1, pf);
7533024Sbostic 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
7633024Sbostic 					break;
7733024Sbostic 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
7833024Sbostic 			}
7933024Sbostic 		}
8030158Sbostic 	}
8133024Sbostic 	if (!pf)
8230158Sbostic 		return;
8330158Sbostic 
8430890Sbostic 	putc('\n', pf);
8530158Sbostic 
8630890Sbostic 	rewind(dfp);
8733024Sbostic 	/* add Reference header and copy bug report out */
8833024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
8933024Sbostic 		fputs(bfr, pf);
9033024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
9133024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
9233024Sbostic 		fputs(bfr, pf);
9330890Sbostic 	(void)pclose(pf);
9430158Sbostic }
95