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.7 (Berkeley) 04/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) { 55 if (mailhead[APPAR_TO_TAG].line) 56 fprintf(pf, "To%s", 57 index(mailhead[APPAR_TO_TAG].line, 58 ':')); 59 else 60 fprintf(pf, "To: %s\n", BUGS_ID); 61 } 62 fputs("Resent-To: ", pf); 63 } 64 /* 65 * write out first entry, then succeeding entries 66 * backward compatible, handles back slashes at end 67 * of line 68 */ 69 if (group++) 70 fputs(", ", pf); 71 for (;;) { 72 if (C2 = index(C1, '\\')) 73 *C2 = EOS; 74 fputs(C1, pf); 75 if (!gets(bfr) || *bfr != ' ' && *bfr != '\t') 76 break; 77 for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1); 78 } 79 } 80 } 81 if (!pf) 82 return; 83 84 putc('\n', pf); 85 86 rewind(dfp); 87 /* add Reference header and copy bug report out */ 88 while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n') 89 fputs(bfr, pf); 90 fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile); 91 while (fgets(bfr, sizeof(bfr), dfp)) 92 fputs(bfr, pf); 93 (void)pclose(pf); 94 } 95