xref: /csrg-svn/libexec/bugfiler/redist.c (revision 47694)
130158Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
542663Sbostic  * %sccs.include.redist.c%
630158Sbostic  */
730158Sbostic 
830158Sbostic #ifndef lint
9*47694Sbostic static char sccsid[] = "@(#)redist.c	5.12 (Berkeley) 04/01/91";
1033416Sbostic #endif /* not lint */
1130158Sbostic 
1246667Sbostic #include <sys/param.h>
1346667Sbostic #include <dirent.h>
1430158Sbostic #include <stdio.h>
1533024Sbostic #include <ctype.h>
1646667Sbostic #include <string.h>
1746667Sbostic #include "bug.h"
1837887Sbostic #include "pathnames.h"
1930158Sbostic 
2030158Sbostic /*
2130158Sbostic  * redist --
2230158Sbostic  *	Redistribute a bug report to those people indicated in the
2330158Sbostic  *	redistribution list file.
2430158Sbostic  */
2530158Sbostic redist()
2630158Sbostic {
2730890Sbostic 	extern FILE	*dfp;		/* dist file fp */
2830890Sbostic 	extern char	pfile[];	/* permanent bug file */
2933024Sbostic 	register char	*C1, *C2;
3033024Sbostic 	FILE	*pf, *popen();
3133024Sbostic 	int	group;
32*47694Sbostic 	char	*p, *index();
3330158Sbostic 
3433024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
3530890Sbostic 	if (!freopen(bfr, "r", stdin))
3630158Sbostic 		return;
37*47694Sbostic 	for (pf = NULL, group = 0; fgets(bfr, sizeof(bfr), stdin);) {
38*47694Sbostic 		if (C1 = index(bfr, '\n'))
39*47694Sbostic 			*C1 = '\0';
40*47694Sbostic nextline:	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)
51*47694Sbostic 					fprintf(pf,
52*47694Sbostic 					    "%s", mailhead[SUBJ_TAG].line);
5333024Sbostic 				else
54*47694Sbostic 					fprintf(pf,
55*47694Sbostic 					    "Subject: Untitled Bug Report\n");
5633928Skarels 				if (!mailhead[TO_TAG].line) {
5733928Skarels 					if (mailhead[APPAR_TO_TAG].line)
5833928Skarels 					    fprintf(pf, "To%s",
5933928Skarels 					      index(mailhead[APPAR_TO_TAG].line,
6033928Skarels 					      ':'));
6133928Skarels 					else
6233928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
6333928Skarels 				}
6433024Sbostic 				fputs("Resent-To: ", pf);
6533024Sbostic 			}
6633024Sbostic 			/*
6733024Sbostic 			 * write out first entry, then succeeding entries
6833024Sbostic 			 * backward compatible, handles back slashes at end
6933024Sbostic 			 * of line
7033024Sbostic 			 */
7133024Sbostic 			if (group++)
7233024Sbostic 				fputs(", ", pf);
7333024Sbostic 			for (;;) {
7433024Sbostic 				if (C2 = index(C1, '\\'))
7533024Sbostic 					*C2 = EOS;
7633024Sbostic 				fputs(C1, pf);
77*47694Sbostic 				if (!fgets(bfr, sizeof(bfr), stdin))
7833024Sbostic 					break;
79*47694Sbostic 				if (C1 = index(bfr, '\n'))
80*47694Sbostic 					*C1 = '\0';
81*47694Sbostic 				if (*bfr != ' ' && *bfr != '\t')
82*47694Sbostic 					goto nextline;
83*47694Sbostic 				for (C1 = bfr;
84*47694Sbostic 				    *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
8533024Sbostic 			}
8633024Sbostic 		}
8730158Sbostic 	}
8833024Sbostic 	if (!pf)
8930158Sbostic 		return;
9030158Sbostic 
9130890Sbostic 	putc('\n', pf);
9230158Sbostic 
9330890Sbostic 	rewind(dfp);
9433024Sbostic 	/* add Reference header and copy bug report out */
9533024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
9633024Sbostic 		fputs(bfr, pf);
9733024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
9833024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
9933024Sbostic 		fputs(bfr, pf);
10030890Sbostic 	(void)pclose(pf);
10130158Sbostic }
102