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 | |
3de934b4 | 8 | static char sccsid[] = "@(#)process.c 5.4 (Berkeley) 87/04/23"; |
10236a65 KB |
9 | #endif not lint |
10 | ||
11 | #include <bug.h> | |
12 | #include <sys/file.h> | |
f36776a7 | 13 | #include <sys/time.h> |
10236a65 | 14 | #include <stdio.h> |
d8336336 | 15 | #include <ctype.h> |
10236a65 KB |
16 | |
17 | char pfile[MAXPATHLEN]; /* permanent file name */ | |
18 | ||
19 | /* | |
20 | * process -- | |
d8336336 KB |
21 | * copy report to permanent file, |
22 | * update summary file. | |
10236a65 KB |
23 | */ |
24 | process() | |
25 | { | |
26 | register int rval; /* read return value */ | |
f36776a7 | 27 | struct timeval tp; /* time of day */ |
d8336336 | 28 | int lfd; /* lock file descriptor */ |
f36776a7 | 29 | char *ctime(); |
10236a65 | 30 | |
d8336336 KB |
31 | if (access(LOCK_FILE, R_OK) || (lfd = open(LOCK_FILE, O_RDONLY, 0)) < 0) |
32 | error("can't find lock file %s.", LOCK_FILE); | |
33 | if (flock(lfd, LOCK_EX)) | |
34 | error("can't get lock.", CHN); | |
35 | sprintf(pfile, "%s/%s/%d", dir, folder, getnext()); | |
36 | fprintf(stderr, "\t%s\n", pfile); | |
37 | if (!(freopen(pfile, "w", stdout))) | |
38 | error("can't create %s.", pfile); | |
10236a65 | 39 | rewind(stdin); |
d8336336 KB |
40 | while ((rval = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && rval) |
41 | if (write(fileno(stdout), bfr, rval) != rval) | |
42 | error("write to %s failed.", pfile); | |
10236a65 KB |
43 | |
44 | /* append information to the summary file */ | |
d8336336 KB |
45 | sprintf(bfr, "%s/%s", dir, SUMMARY_FILE); |
46 | if (!(freopen(bfr, "a", stdout))) | |
47 | error("can't append to summary file %s.", bfr); | |
48 | if (gettimeofday(&tp, (struct timezone *)NULL)) | |
49 | error("can't get time of day.", CHN); | |
3de934b4 | 50 | printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tStatus: Received\n", pfile, ctime(&tp.tv_sec), mailhead[INDX_TAG].line, mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n"); |
d8336336 KB |
51 | (void)flock(lfd, LOCK_UN); |
52 | (void)fclose(stdout); | |
10236a65 KB |
53 | } |
54 | ||
55 | /* | |
56 | * getnext -- | |
57 | * get next file name (number) | |
58 | */ | |
59 | static | |
60 | getnext() | |
61 | { | |
62 | register struct direct *d; /* directory structure */ | |
63 | register DIR *dirp; /* directory pointer */ | |
d8336336 KB |
64 | register int highval, |
65 | newval; | |
66 | register char *C; | |
10236a65 | 67 | |
d8336336 KB |
68 | sprintf(bfr, "%s/%s", dir, folder); |
69 | if (!(dirp = opendir(bfr))) | |
70 | error("can't read folder directory %s.", bfr); | |
71 | for (highval = 0;d = readdir(dirp);) | |
72 | for (C = d->d_name;;++C) | |
73 | if (!*C) { | |
74 | if ((newval = atoi(d->d_name)) > highval) | |
75 | highval = newval; | |
76 | break; | |
77 | } | |
78 | else if (!isdigit(*C)) | |
79 | break; | |
10236a65 | 80 | closedir(dirp); |
d8336336 | 81 | return(++highval); |
10236a65 | 82 | } |