ANSI fixes, yank to rev 5.1, fix the copyright notices
[unix-history] / usr / src / libexec / bugfiler / redist.c
CommitLineData
0c4713c9 1/*
aec2eff2
KB
2 * Copyright (c) 1986, 1987 Regents of the University of California.
3 * All rights reserved.
4 *
1343342a 5 * %sccs.include.redist.c%
0c4713c9
KB
6 */
7
8#ifndef lint
1343342a 9static char sccsid[] = "@(#)redist.c 5.10 (Berkeley) %G%";
aec2eff2 10#endif /* not lint */
0c4713c9
KB
11
12#include <sys/file.h>
13#include <stdio.h>
defca596 14#include <ctype.h>
0c4713c9 15#include <bug.h>
435e8dff 16#include "pathnames.h"
0c4713c9 17
0c4713c9
KB
18/*
19 * redist --
20 * Redistribute a bug report to those people indicated in the
21 * redistribution list file.
22 */
23redist()
24{
d8336336
KB
25 extern FILE *dfp; /* dist file fp */
26 extern char pfile[]; /* permanent bug file */
defca596
KB
27 register char *C1, *C2;
28 FILE *pf, *popen();
29 int group;
d8336336 30 char *index();
0c4713c9 31
defca596 32 (void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
d8336336 33 if (!freopen(bfr, "r", stdin))
0c4713c9 34 return;
defca596
KB
35 for (pf = NULL, group = 0; gets(bfr);) {
36 if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
0c4713c9
KB
37 continue;
38 *C1 = EOS;
defca596
KB
39 if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
40 for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
41 if (!*C1) /* if empty list */
42 continue;
43 if (!pf) {
44 if (!(pf = popen(MAIL_CMD, "w")))
45 error("sendmail pipe failed.", CHN);
46 if (mailhead[SUBJ_TAG].found)
47 fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
48 else
49 fputs("Subject: Untitled Bug Report\n", pf);
194c0a19
MK
50 if (!mailhead[TO_TAG].line) {
51 if (mailhead[APPAR_TO_TAG].line)
52 fprintf(pf, "To%s",
53 index(mailhead[APPAR_TO_TAG].line,
54 ':'));
55 else
56 fprintf(pf, "To: %s\n", BUGS_ID);
57 }
defca596
KB
58 fputs("Resent-To: ", pf);
59 }
60 /*
61 * write out first entry, then succeeding entries
62 * backward compatible, handles back slashes at end
63 * of line
64 */
65 if (group++)
66 fputs(", ", pf);
67 for (;;) {
68 if (C2 = index(C1, '\\'))
69 *C2 = EOS;
70 fputs(C1, pf);
71 if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
72 break;
73 for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
74 }
75 }
0c4713c9 76 }
defca596 77 if (!pf)
0c4713c9
KB
78 return;
79
d8336336 80 putc('\n', pf);
0c4713c9 81
d8336336 82 rewind(dfp);
defca596
KB
83 /* add Reference header and copy bug report out */
84 while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
85 fputs(bfr, pf);
86 fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
87 while (fgets(bfr, sizeof(bfr), dfp))
88 fputs(bfr, pf);
d8336336 89 (void)pclose(pf);
0c4713c9 90}