+/*
+ * Copyright (c) 1986 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)process.c 5.1 (Berkeley) 86/11/25";
+#endif not lint
+
+#include <bug.h>
+#include <sys/file.h>
+#include <sys/dir.h>
+#include <stdio.h>
+
+extern HEADER mailhead[]; /* mail headers */
+extern int lfd; /* lock file descriptor */
+extern char dir[], /* directory */
+ folder[]; /* sub-directory */
+
+char pfile[MAXPATHLEN]; /* permanent file name */
+
+/*
+ * process --
+ * process a bug report
+ */
+process()
+{
+ register int rval; /* read return value */
+
+ /* copy report to permanent file */
+ sprintf(pfile,"%s/%s/%d",dir,folder,getnext());
+ fprintf(stderr,"\t%s\n",pfile);
+ if (!(freopen(pfile,"w",stdout)))
+ error("unable to create permanent bug file %s.",pfile);
+ rewind(stdin);
+ while ((rval = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && rval)
+ write(fileno(stdout),bfr,rval);
+ REL_LOCK;
+
+ /* append information to the summary file */
+ sprintf(bfr,"%s/%s",dir,SUMMARY_FILE);
+ GET_LOCK;
+ if (!(freopen(bfr,"a",stdout)))
+ error("unable to append to summary file %s.",bfr);
+ else
+ 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");
+ REL_LOCK;
+ fclose(stdout);
+}
+
+/*
+ * getnext --
+ * get next file name (number)
+ */
+static
+getnext()
+{
+ register struct direct *d; /* directory structure */
+ register DIR *dirp; /* directory pointer */
+ register int n; /* number values */
+
+ GET_LOCK;
+ sprintf(bfr,"%s/%s",dir,folder);
+ if (!(dirp = opendir(bfr))) {
+ REL_LOCK;
+ error("unable to read folder directory %s.",bfr);
+ }
+ for (n = 0;d = readdir(dirp);)
+ n = MAX(n,atoi(d->d_name));
+ closedir(dirp);
+ return(++n);
+}