xref: /csrg-svn/libexec/bugfiler/redist.c (revision 33024)
130158Sbostic /*
230158Sbostic  * Copyright (c) 1986 Regents of the University of California.
330158Sbostic  * All rights reserved.  The Berkeley software License Agreement
430158Sbostic  * specifies the terms and conditions for redistribution.
530158Sbostic  */
630158Sbostic 
730158Sbostic #ifndef lint
8*33024Sbostic static char sccsid[] = "@(#)redist.c	5.5 (Berkeley) 87/12/12";
9*33024Sbostic #endif /* !lint */
1030158Sbostic 
1130158Sbostic #include <sys/file.h>
1230158Sbostic #include <stdio.h>
13*33024Sbostic #include <ctype.h>
1430158Sbostic #include <bug.h>
1530158Sbostic 
1630158Sbostic /*
1730158Sbostic  * redist --
1830158Sbostic  *	Redistribute a bug report to those people indicated in the
1930158Sbostic  *	redistribution list file.
2030158Sbostic  */
2130158Sbostic redist()
2230158Sbostic {
2330890Sbostic 	extern FILE	*dfp;		/* dist file fp */
2430890Sbostic 	extern char	pfile[];	/* permanent bug file */
25*33024Sbostic 	register char	*C1, *C2;
26*33024Sbostic 	FILE	*pf, *popen();
27*33024Sbostic 	int	group;
2830890Sbostic 	char	*index();
2930158Sbostic 
30*33024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
3130890Sbostic 	if (!freopen(bfr, "r", stdin))
3230158Sbostic 		return;
33*33024Sbostic 	for (pf = NULL, group = 0; gets(bfr);) {
34*33024Sbostic 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
3530158Sbostic 			continue;
3630158Sbostic 		*C1 = EOS;
37*33024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
38*33024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
39*33024Sbostic 			if (!*C1)			/* if empty list */
40*33024Sbostic 				continue;
41*33024Sbostic 			if (!pf) {
42*33024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
43*33024Sbostic 					error("sendmail pipe failed.", CHN);
44*33024Sbostic 				if (mailhead[SUBJ_TAG].found)
45*33024Sbostic 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
46*33024Sbostic 				else
47*33024Sbostic 					fputs("Subject: Untitled Bug Report\n", pf);
48*33024Sbostic 				if (!mailhead[TO_TAG].line && mailhead[APPAR_TO_TAG].line)
49*33024Sbostic 					fprintf(pf, "To%s", index(mailhead[APPAR_TO_TAG].line, ':'));
50*33024Sbostic 				fputs("Resent-To: ", pf);
51*33024Sbostic 			}
52*33024Sbostic 			/*
53*33024Sbostic 			 * write out first entry, then succeeding entries
54*33024Sbostic 			 * backward compatible, handles back slashes at end
55*33024Sbostic 			 * of line
56*33024Sbostic 			 */
57*33024Sbostic 			if (group++)
58*33024Sbostic 				fputs(", ", pf);
59*33024Sbostic 			for (;;) {
60*33024Sbostic 				if (C2 = index(C1, '\\'))
61*33024Sbostic 					*C2 = EOS;
62*33024Sbostic 				fputs(C1, pf);
63*33024Sbostic 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
64*33024Sbostic 					break;
65*33024Sbostic 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
66*33024Sbostic 			}
67*33024Sbostic 		}
6830158Sbostic 	}
69*33024Sbostic 	if (!pf)
7030158Sbostic 		return;
7130158Sbostic 
7230890Sbostic 	putc('\n', pf);
7330158Sbostic 
7430890Sbostic 	rewind(dfp);
75*33024Sbostic 	/* add Reference header and copy bug report out */
76*33024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
77*33024Sbostic 		fputs(bfr, pf);
78*33024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
79*33024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
80*33024Sbostic 		fputs(bfr, pf);
8130890Sbostic 	(void)pclose(pf);
8230158Sbostic }
83