|
|
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[] = "@(#)process.c 5.8 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <bug.h> ! 25: #include <sys/file.h> ! 26: #include <sys/time.h> ! 27: #include <stdio.h> ! 28: #include <ctype.h> ! 29: ! 30: char pfile[MAXPATHLEN]; /* permanent file name */ ! 31: ! 32: /* ! 33: * process -- ! 34: * copy report to permanent file, ! 35: * update summary file. ! 36: */ ! 37: process() ! 38: { ! 39: register int rval; /* read return value */ ! 40: struct timeval tp; /* time of day */ ! 41: int lfd; /* lock file descriptor */ ! 42: char *ctime(); ! 43: ! 44: if (access(LOCK_FILE, R_OK) || (lfd = open(LOCK_FILE, O_RDONLY, 0)) < 0) ! 45: error("can't find lock file %s.", LOCK_FILE); ! 46: if (flock(lfd, LOCK_EX)) ! 47: error("can't get lock.", CHN); ! 48: sprintf(pfile, "%s/%s/%d", dir, folder, getnext()); ! 49: fprintf(stderr, "\t%s\n", pfile); ! 50: if (!(freopen(pfile, "w", stdout))) ! 51: error("can't create %s.", pfile); ! 52: rewind(stdin); ! 53: while ((rval = read(fileno(stdin), bfr, sizeof(bfr))) != ERR && rval) ! 54: if (write(fileno(stdout), bfr, rval) != rval) ! 55: error("write to %s failed.", pfile); ! 56: ! 57: /* append information to the summary file */ ! 58: sprintf(bfr, "%s/%s", dir, SUMMARY_FILE); ! 59: if (!(freopen(bfr, "a", stdout))) ! 60: error("can't append to summary file %s.", bfr); ! 61: if (gettimeofday(&tp, (struct timezone *)NULL)) ! 62: error("can't get time of day.", CHN); ! 63: 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"); ! 64: (void)flock(lfd, LOCK_UN); ! 65: (void)fclose(stdout); ! 66: } ! 67: ! 68: /* ! 69: * getnext -- ! 70: * get next file name (number) ! 71: */ ! 72: static ! 73: getnext() ! 74: { ! 75: register struct direct *d; /* directory structure */ ! 76: register DIR *dirp; /* directory pointer */ ! 77: register int highval, newval; ! 78: register char *p; ! 79: ! 80: (void)sprintf(bfr, "%s/%s", dir, folder); ! 81: if (!(dirp = opendir(bfr))) ! 82: error("can't read folder directory %s.", bfr); ! 83: for (highval = -1; d = readdir(dirp);) { ! 84: for (p = d->d_name; *p && isdigit(*p); ++p); ! 85: if (!*p && (newval = atoi(d->d_name)) > highval) ! 86: highval = newval; ! 87: } ! 88: closedir(dirp); ! 89: return(++highval); ! 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.