Commit | Line | Data |
---|---|---|
10236a65 KB |
1 | /* |
2 | * Copyright (c) 1986 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
7 | #ifndef lint | |
8 | static char sccsid[] = "@(#)process.c 5.1 (Berkeley) 86/11/25"; | |
9 | #endif not lint | |
10 | ||
11 | #include <bug.h> | |
12 | #include <sys/file.h> | |
13 | #include <sys/dir.h> | |
14 | #include <stdio.h> | |
15 | ||
16 | extern HEADER mailhead[]; /* mail headers */ | |
17 | extern int lfd; /* lock file descriptor */ | |
18 | extern char dir[], /* directory */ | |
19 | folder[]; /* sub-directory */ | |
20 | ||
21 | char pfile[MAXPATHLEN]; /* permanent file name */ | |
22 | ||
23 | /* | |
24 | * process -- | |
25 | * process a bug report | |
26 | */ | |
27 | process() | |
28 | { | |
29 | register int rval; /* read return value */ | |
30 | ||
31 | /* copy report to permanent file */ | |
32 | sprintf(pfile,"%s/%s/%d",dir,folder,getnext()); | |
33 | fprintf(stderr,"\t%s\n",pfile); | |
34 | if (!(freopen(pfile,"w",stdout))) | |
35 | error("unable to create permanent bug file %s.",pfile); | |
36 | rewind(stdin); | |
37 | while ((rval = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && rval) | |
38 | write(fileno(stdout),bfr,rval); | |
39 | REL_LOCK; | |
40 | ||
41 | /* append information to the summary file */ | |
42 | sprintf(bfr,"%s/%s",dir,SUMMARY_FILE); | |
43 | GET_LOCK; | |
44 | if (!(freopen(bfr,"a",stdout))) | |
45 | error("unable to append to summary file %s.",bfr); | |
46 | else | |
47 | printf("\n%s\n\t%s\t%s\tOwner: Bugs Bunny\n\tStatus: Received\n",pfile,mailhead[INDX_TAG].line,mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n"); | |
48 | REL_LOCK; | |
49 | fclose(stdout); | |
50 | } | |
51 | ||
52 | /* | |
53 | * getnext -- | |
54 | * get next file name (number) | |
55 | */ | |
56 | static | |
57 | getnext() | |
58 | { | |
59 | register struct direct *d; /* directory structure */ | |
60 | register DIR *dirp; /* directory pointer */ | |
61 | register int n; /* number values */ | |
62 | ||
63 | GET_LOCK; | |
64 | sprintf(bfr,"%s/%s",dir,folder); | |
65 | if (!(dirp = opendir(bfr))) { | |
66 | REL_LOCK; | |
67 | error("unable to read folder directory %s.",bfr); | |
68 | } | |
69 | for (n = 0;d = readdir(dirp);) | |
70 | n = MAX(n,atoi(d->d_name)); | |
71 | closedir(dirp); | |
72 | return(++n); | |
73 | } |