needed sccs id's
[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 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
0c4713c9
KB
16 */
17
18#ifndef lint
435e8dff 19static char sccsid[] = "@(#)redist.c 5.9 (Berkeley) %G%";
aec2eff2 20#endif /* not lint */
0c4713c9
KB
21
22#include <sys/file.h>
23#include <stdio.h>
defca596 24#include <ctype.h>
0c4713c9 25#include <bug.h>
435e8dff 26#include "pathnames.h"
0c4713c9 27
0c4713c9
KB
28/*
29 * redist --
30 * Redistribute a bug report to those people indicated in the
31 * redistribution list file.
32 */
33redist()
34{
d8336336
KB
35 extern FILE *dfp; /* dist file fp */
36 extern char pfile[]; /* permanent bug file */
defca596
KB
37 register char *C1, *C2;
38 FILE *pf, *popen();
39 int group;
d8336336 40 char *index();
0c4713c9 41
defca596 42 (void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
d8336336 43 if (!freopen(bfr, "r", stdin))
0c4713c9 44 return;
defca596
KB
45 for (pf = NULL, group = 0; gets(bfr);) {
46 if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
0c4713c9
KB
47 continue;
48 *C1 = EOS;
defca596
KB
49 if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
50 for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
51 if (!*C1) /* if empty list */
52 continue;
53 if (!pf) {
54 if (!(pf = popen(MAIL_CMD, "w")))
55 error("sendmail pipe failed.", CHN);
56 if (mailhead[SUBJ_TAG].found)
57 fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
58 else
59 fputs("Subject: Untitled Bug Report\n", pf);
194c0a19
MK
60 if (!mailhead[TO_TAG].line) {
61 if (mailhead[APPAR_TO_TAG].line)
62 fprintf(pf, "To%s",
63 index(mailhead[APPAR_TO_TAG].line,
64 ':'));
65 else
66 fprintf(pf, "To: %s\n", BUGS_ID);
67 }
defca596
KB
68 fputs("Resent-To: ", pf);
69 }
70 /*
71 * write out first entry, then succeeding entries
72 * backward compatible, handles back slashes at end
73 * of line
74 */
75 if (group++)
76 fputs(", ", pf);
77 for (;;) {
78 if (C2 = index(C1, '\\'))
79 *C2 = EOS;
80 fputs(C1, pf);
81 if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
82 break;
83 for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
84 }
85 }
0c4713c9 86 }
defca596 87 if (!pf)
0c4713c9
KB
88 return;
89
d8336336 90 putc('\n', pf);
0c4713c9 91
d8336336 92 rewind(dfp);
defca596
KB
93 /* add Reference header and copy bug report out */
94 while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
95 fputs(bfr, pf);
96 fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
97 while (fgets(bfr, sizeof(bfr), dfp))
98 fputs(bfr, pf);
d8336336 99 (void)pclose(pf);
0c4713c9 100}