xref: /csrg-svn/libexec/bugfiler/redist.c (revision 30890)
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*30890Sbostic static char sccsid[] = "@(#)redist.c	5.2 (Berkeley) 87/04/11";
930158Sbostic #endif not lint
1030158Sbostic 
1130158Sbostic #include <sys/file.h>
1230158Sbostic #include <stdio.h>
1330158Sbostic #include <bug.h>
1430158Sbostic 
1530158Sbostic /*
1630158Sbostic  * redist --
1730158Sbostic  *	Redistribute a bug report to those people indicated in the
1830158Sbostic  *	redistribution list file.
1930158Sbostic  */
2030158Sbostic redist()
2130158Sbostic {
22*30890Sbostic 	extern FILE	*dfp;		/* dist file fp */
23*30890Sbostic 	extern char	pfile[];	/* permanent bug file */
24*30890Sbostic 	register char	*C1,
2530158Sbostic 			*C2;
26*30890Sbostic 	register int	first;		/* if first blank line */
27*30890Sbostic 	FILE	*pf,
2830158Sbostic 		*popen();
29*30890Sbostic 	char	*index();
3030158Sbostic 
31*30890Sbostic 	sprintf(bfr, "%s/%s", dir, DIST_FILE);
32*30890Sbostic 	if (!freopen(bfr, "r", stdin))
3330158Sbostic 		return;
3430158Sbostic 	for (;;) {			/* get first part of entry */
3530158Sbostic 		if (!gets(bfr))
3630158Sbostic 			return;
37*30890Sbostic 		if (*bfr == COMMENT || *bfr == ' ' || *bfr == '\t' || !(C1 = index(bfr, ':')))
3830158Sbostic 			continue;
3930158Sbostic 		*C1 = EOS;
40*30890Sbostic 		if (!strcmp(bfr, folder))
4130158Sbostic 			break;
4230158Sbostic 	}
4330158Sbostic 	for (++C1;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
4430158Sbostic 	if (!*C1)			/* if empty */
4530158Sbostic 		return;
4630158Sbostic 
47*30890Sbostic 	if (!(pf = popen(MAIL_CMD, "w")))
48*30890Sbostic 		error("sendmail pipe failed.", CHN);
4930158Sbostic 
50*30890Sbostic 	fprintf(pf, "Reply-To: %s\n", BUGS_HOME);
5130158Sbostic 	if (mailhead[SUBJ_TAG].found)
52*30890Sbostic 		fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
5330158Sbostic 	else
54*30890Sbostic 		fputs("Subject: Untitled Bug Report\n", pf);
55*30890Sbostic 	fputs("Resent-To: ", pf);
5630158Sbostic 
5730158Sbostic 	/*
5830158Sbostic 	 * write out first entry, then succeeding entries
5930158Sbostic 	 * backward compatible, handles back slashes at end of line
6030158Sbostic 	 */
6130158Sbostic 	for (;;) {
62*30890Sbostic 		if (C2 = index(C1, '\\'))
6330158Sbostic 			*C2 = EOS;
64*30890Sbostic 		fputs(C1, pf);
6530158Sbostic 		if (!gets(bfr) || (*bfr != ' ' && *bfr != '\t'))
6630158Sbostic 			break;
6730158Sbostic 		for (C1 = bfr;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
6830158Sbostic 	}
69*30890Sbostic 	putc('\n', pf);
7030158Sbostic 
71*30890Sbostic 	rewind(dfp);
72*30890Sbostic 	for (first = YES;fgets(bfr, sizeof(bfr), dfp);)
7330158Sbostic 		if (*bfr == '\n' && first) {
7430158Sbostic 			first = NO;
75*30890Sbostic 			fprintf(pf, "\n%sReference: %s\n", mailhead[INDX_TAG].line, pfile);
7630158Sbostic 		}
7730158Sbostic 		else
78*30890Sbostic 			fputs(bfr, pf);
79*30890Sbostic 	(void)pclose(pf);
80*30890Sbostic 	(void)fclose(dfp);
8130158Sbostic }
82