|
|
1.1 root 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: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)gethead.c 5.8 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include <bug.h>
25: #include <sys/stat.h>
26: #include <stdio.h>
27: #include "pathnames.h"
28:
29: static int chk1(), pbuf();
30:
31: #define ENT(X) sizeof(X) - 1, X
32: HEADER mailhead[] = { /* mail headers */
33: { NO, YES, NULL, ENT("Date:"), },
34: { NO, NO, NULL, ENT("From "), },
35: { NO, YES, NULL, ENT("From:"), },
36: { NO, NO, chk1, ENT("Index:"), },
37: { NO, YES, NULL, ENT("Message-Id:"), },
38: { NO, YES, NULL, ENT("Reply-To:"), },
39: { NO, YES, NULL, ENT("Return-Path:"), },
40: { NO, NO, pbuf, ENT("Subject:"), },
41: { NO, YES, NULL, ENT("To:"), },
42: { NO, NO, NULL, ENT("Apparently-To:"), },
43: { ERR, }
44: };
45:
46: FILE *dfp; /* distf file pointer */
47: char dir[MAXNAMLEN], /* subject and folder */
48: folder[MAXNAMLEN];
49:
50: /*
51: * gethead --
52: * read mail and bug headers from bug report, construct redist headers
53: */
54: gethead(redist)
55: int redist;
56: {
57: register HEADER *hp; /* mail header pointer */
58: char *strcpy(), *malloc();
59:
60: if (redist) {
61: int fd;
62: char *distf;
63:
64: distf = _PATH_TMP;
65: if (!(fd = mkstemp(distf)) || !(dfp = fdopen(fd, "w+")))
66: error("can't create redistribution file %s.", distf);
67: /* disappear after last reference is closed */
68: (void)unlink(distf);
69: }
70: if (!freopen(tmpname, "r", stdin))
71: error("can't read temporary bug file %s.", tmpname);
72:
73: while (fgets(bfr, sizeof(bfr), stdin)) {
74: for (hp = mailhead; hp->found != ERR; ++hp)
75: if (!hp->found)
76: if (!strncmp(hp->tag, bfr, hp->len)) {
77: if (hp->valid && !((*(hp->valid))(bfr)))
78: break;
79: if (!(hp->line = malloc((u_int)(strlen(bfr) + 1))))
80: error("malloc failed.", CHN);
81: (void)strcpy(hp->line, bfr);
82: hp->found = YES;
83: break;
84: }
85: if ((hp->found == ERR || hp->redist) && redist)
86: fputs(bfr, dfp);
87: }
88:
89: if (!mailhead[INDX_TAG].found)
90: error("no readable \"Index:\" header in bug report.", CHN);
91: }
92:
93: /*
94: * chk1 --
95: * parse the "Index:" line into folder and directory
96: */
97: static
98: chk1(line)
99: char *line;
100: {
101: register char *C; /* tmp pointer */
102: struct stat sbuf; /* existence check */
103: char *index();
104:
105: if (sscanf(line, " Index: %s %s ", folder, dir) != 2)
106: return(NO);
107: if (C = index(folder, '/')) { /* deal with "bin/from.c" */
108: if (C == folder)
109: return(NO);
110: *C = EOS;
111: }
112: if (stat(dir, &sbuf) || (sbuf.st_mode & S_IFMT) != S_IFDIR)
113: return(NO);
114: (void)pbuf(line);
115: return(YES);
116: }
117:
118: /*
119: * pbuf --
120: * kludge so that summary file looks pretty
121: */
122: static
123: pbuf(line)
124: char *line;
125: {
126: register char *rp, /* tmp pointers */
127: *wp;
128:
129: for (rp = line; *rp == ' ' || *rp == '\t'; ++rp);
130: for (wp = line; *rp; ++wp) {
131: if ((*wp = *rp++) != ' ' && *wp != '\t')
132: continue;
133: *wp = ' ';
134: while (*rp == ' ' || *rp == '\t')
135: ++rp;
136: }
137: if (wp[-1] == ' ') /* wp can't == line */
138: --wp;
139: *wp = EOS;
140: return(YES);
141: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.