xref: /csrg-svn/libexec/bugfiler/redist.c (revision 30158)
1*30158Sbostic /*
2*30158Sbostic  * Copyright (c) 1986 Regents of the University of California.
3*30158Sbostic  * All rights reserved.  The Berkeley software License Agreement
4*30158Sbostic  * specifies the terms and conditions for redistribution.
5*30158Sbostic  */
6*30158Sbostic 
7*30158Sbostic #ifndef lint
8*30158Sbostic static char sccsid[] = "@(#)redist.c	5.1 (Berkeley) 86/11/25";
9*30158Sbostic #endif not lint
10*30158Sbostic 
11*30158Sbostic #include <sys/file.h>
12*30158Sbostic #include <stdio.h>
13*30158Sbostic #include <bug.h>
14*30158Sbostic 
15*30158Sbostic extern HEADER	mailhead[];			/* mail headers */
16*30158Sbostic extern char	*distf,				/* redist temp file */
17*30158Sbostic 		pfile[],			/* permanent bug file */
18*30158Sbostic 		folder[];			/* system name */
19*30158Sbostic 
20*30158Sbostic /*
21*30158Sbostic  * redist --
22*30158Sbostic  *	Redistribute a bug report to those people indicated in the
23*30158Sbostic  *	redistribution list file.
24*30158Sbostic  */
25*30158Sbostic redist()
26*30158Sbostic {
27*30158Sbostic 	register char	*C1,		/* traveling chars */
28*30158Sbostic 			*C2;
29*30158Sbostic 	register int	first = YES;	/* if first blank line */
30*30158Sbostic 	FILE	*pf,			/* pipe pointer */
31*30158Sbostic 		*dfp,			/* dist file fp */
32*30158Sbostic 		*popen();
33*30158Sbostic 	char	*index(), *mktemp();
34*30158Sbostic 
35*30158Sbostic 	if (!freopen(DIST_FILE,"r",stdin))
36*30158Sbostic 		return;
37*30158Sbostic 
38*30158Sbostic 	for (;;) {			/* get first part of entry */
39*30158Sbostic 		if (!gets(bfr))
40*30158Sbostic 			return;
41*30158Sbostic 		if (*bfr == COMMENT || *bfr == ' ' || *bfr == '\t' || !(C1 = index(bfr,':')))
42*30158Sbostic 			continue;
43*30158Sbostic 		*C1 = EOS;
44*30158Sbostic 		if (!strcmp(bfr,folder))
45*30158Sbostic 			break;
46*30158Sbostic 	}
47*30158Sbostic 	for (++C1;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
48*30158Sbostic 	if (!*C1)			/* if empty */
49*30158Sbostic 		return;
50*30158Sbostic 
51*30158Sbostic 	if (!(pf = popen(MAIL_CMD,"w")))
52*30158Sbostic 		error("sendmail pipe failed.",CHN);
53*30158Sbostic 
54*30158Sbostic 	fprintf(pf,"Reply-To: %s\n",BUGS_HOME);
55*30158Sbostic 	if (mailhead[SUBJ_TAG].found)
56*30158Sbostic 		fprintf(pf,"%s",mailhead[SUBJ_TAG].line);
57*30158Sbostic 	else
58*30158Sbostic 		fputs("Subject: Untitled Bug Report\n",pf);
59*30158Sbostic 	fputs("Resent-To: ",pf);
60*30158Sbostic 
61*30158Sbostic 	/*
62*30158Sbostic 	 * write out first entry, then succeeding entries
63*30158Sbostic 	 * backward compatible, handles back slashes at end of line
64*30158Sbostic 	 */
65*30158Sbostic 	for (;;) {
66*30158Sbostic 		if (C2 = index(C1,'\\'))
67*30158Sbostic 			*C2 = EOS;
68*30158Sbostic 		fputs(C1,pf);
69*30158Sbostic 		if (!gets(bfr) || (*bfr != ' ' && *bfr != '\t'))
70*30158Sbostic 			break;
71*30158Sbostic 		for (C1 = bfr;*C1 && (*C1 == ' ' || *C1 == '\t');++C1);
72*30158Sbostic 	}
73*30158Sbostic 	fputs("\n",pf);
74*30158Sbostic 
75*30158Sbostic 	if (!(dfp = fopen(distf,"r")))
76*30158Sbostic 		error("unable to read temporary file %s.",distf);
77*30158Sbostic 	while (fgets(bfr,sizeof(bfr),dfp))
78*30158Sbostic 		if (*bfr == '\n' && first) {
79*30158Sbostic 			first = NO;
80*30158Sbostic 			fprintf(pf,"\n%sReference: %s\n",mailhead[INDX_TAG].line,pfile);
81*30158Sbostic 		}
82*30158Sbostic 		else
83*30158Sbostic 			fputs(bfr,pf);
84*30158Sbostic 	fclose(dfp);
85*30158Sbostic 	pclose(pf);
86*30158Sbostic 	unlink(distf);
87*30158Sbostic }
88