xref: /csrg-svn/libexec/bugfiler/redist.c (revision 33416)
1 /*
2  * Copyright (c) 1986, 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)redist.c	5.6 (Berkeley) 02/01/88";
15 #endif /* not lint */
16 
17 #include <sys/file.h>
18 #include <stdio.h>
19 #include <ctype.h>
20 #include <bug.h>
21 
22 /*
23  * redist --
24  *	Redistribute a bug report to those people indicated in the
25  *	redistribution list file.
26  */
27 redist()
28 {
29 	extern FILE	*dfp;		/* dist file fp */
30 	extern char	pfile[];	/* permanent bug file */
31 	register char	*C1, *C2;
32 	FILE	*pf, *popen();
33 	int	group;
34 	char	*index();
35 
36 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
37 	if (!freopen(bfr, "r", stdin))
38 		return;
39 	for (pf = NULL, group = 0; gets(bfr);) {
40 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
41 			continue;
42 		*C1 = EOS;
43 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
44 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
45 			if (!*C1)			/* if empty list */
46 				continue;
47 			if (!pf) {
48 				if (!(pf = popen(MAIL_CMD, "w")))
49 					error("sendmail pipe failed.", CHN);
50 				if (mailhead[SUBJ_TAG].found)
51 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
52 				else
53 					fputs("Subject: Untitled Bug Report\n", pf);
54 				if (!mailhead[TO_TAG].line && mailhead[APPAR_TO_TAG].line)
55 					fprintf(pf, "To%s", index(mailhead[APPAR_TO_TAG].line, ':'));
56 				fputs("Resent-To: ", pf);
57 			}
58 			/*
59 			 * write out first entry, then succeeding entries
60 			 * backward compatible, handles back slashes at end
61 			 * of line
62 			 */
63 			if (group++)
64 				fputs(", ", pf);
65 			for (;;) {
66 				if (C2 = index(C1, '\\'))
67 					*C2 = EOS;
68 				fputs(C1, pf);
69 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
70 					break;
71 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
72 			}
73 		}
74 	}
75 	if (!pf)
76 		return;
77 
78 	putc('\n', pf);
79 
80 	rewind(dfp);
81 	/* add Reference header and copy bug report out */
82 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
83 		fputs(bfr, pf);
84 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
85 	while (fgets(bfr, sizeof(bfr), dfp))
86 		fputs(bfr, pf);
87 	(void)pclose(pf);
88 }
89