xref: /csrg-svn/libexec/bugfiler/redist.c (revision 37887)
130158Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
533416Sbostic  * Redistribution and use in source and binary forms are permitted
634910Sbostic  * provided that the above copyright notice and this paragraph are
734910Sbostic  * duplicated in all such forms and that any documentation,
834910Sbostic  * advertising materials, and other materials related to such
934910Sbostic  * distribution and use acknowledge that the software was developed
1034910Sbostic  * by the University of California, Berkeley.  The name of the
1134910Sbostic  * University may not be used to endorse or promote products derived
1234910Sbostic  * from this software without specific prior written permission.
1334910Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434910Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534910Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1630158Sbostic  */
1730158Sbostic 
1830158Sbostic #ifndef lint
19*37887Sbostic static char sccsid[] = "@(#)redist.c	5.9 (Berkeley) 05/11/89";
2033416Sbostic #endif /* not lint */
2130158Sbostic 
2230158Sbostic #include <sys/file.h>
2330158Sbostic #include <stdio.h>
2433024Sbostic #include <ctype.h>
2530158Sbostic #include <bug.h>
26*37887Sbostic #include "pathnames.h"
2730158Sbostic 
2830158Sbostic /*
2930158Sbostic  * redist --
3030158Sbostic  *	Redistribute a bug report to those people indicated in the
3130158Sbostic  *	redistribution list file.
3230158Sbostic  */
3330158Sbostic redist()
3430158Sbostic {
3530890Sbostic 	extern FILE	*dfp;		/* dist file fp */
3630890Sbostic 	extern char	pfile[];	/* permanent bug file */
3733024Sbostic 	register char	*C1, *C2;
3833024Sbostic 	FILE	*pf, *popen();
3933024Sbostic 	int	group;
4030890Sbostic 	char	*index();
4130158Sbostic 
4233024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
4330890Sbostic 	if (!freopen(bfr, "r", stdin))
4430158Sbostic 		return;
4533024Sbostic 	for (pf = NULL, group = 0; gets(bfr);) {
4633024Sbostic 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
4730158Sbostic 			continue;
4830158Sbostic 		*C1 = EOS;
4933024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
5033024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
5133024Sbostic 			if (!*C1)			/* if empty list */
5233024Sbostic 				continue;
5333024Sbostic 			if (!pf) {
5433024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
5533024Sbostic 					error("sendmail pipe failed.", CHN);
5633024Sbostic 				if (mailhead[SUBJ_TAG].found)
5733024Sbostic 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
5833024Sbostic 				else
5933024Sbostic 					fputs("Subject: Untitled Bug Report\n", pf);
6033928Skarels 				if (!mailhead[TO_TAG].line) {
6133928Skarels 					if (mailhead[APPAR_TO_TAG].line)
6233928Skarels 					    fprintf(pf, "To%s",
6333928Skarels 					      index(mailhead[APPAR_TO_TAG].line,
6433928Skarels 					      ':'));
6533928Skarels 					else
6633928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
6733928Skarels 				}
6833024Sbostic 				fputs("Resent-To: ", pf);
6933024Sbostic 			}
7033024Sbostic 			/*
7133024Sbostic 			 * write out first entry, then succeeding entries
7233024Sbostic 			 * backward compatible, handles back slashes at end
7333024Sbostic 			 * of line
7433024Sbostic 			 */
7533024Sbostic 			if (group++)
7633024Sbostic 				fputs(", ", pf);
7733024Sbostic 			for (;;) {
7833024Sbostic 				if (C2 = index(C1, '\\'))
7933024Sbostic 					*C2 = EOS;
8033024Sbostic 				fputs(C1, pf);
8133024Sbostic 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
8233024Sbostic 					break;
8333024Sbostic 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
8433024Sbostic 			}
8533024Sbostic 		}
8630158Sbostic 	}
8733024Sbostic 	if (!pf)
8830158Sbostic 		return;
8930158Sbostic 
9030890Sbostic 	putc('\n', pf);
9130158Sbostic 
9230890Sbostic 	rewind(dfp);
9333024Sbostic 	/* add Reference header and copy bug report out */
9433024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
9533024Sbostic 		fputs(bfr, pf);
9633024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
9733024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
9833024Sbostic 		fputs(bfr, pf);
9930890Sbostic 	(void)pclose(pf);
10030158Sbostic }
101