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