+static char *SccsId = "@(#)lex.c 1.3 %G%";
+
+/*
+ * Set up editing on the given file name.
+ * If isedit is true, we are considered to be editing the file,
+ * otherwise we are reading our mail which has signficance for
+ * mbox and so forth.
+ */
+
+setfile(name, isedit)
+ char *name;
+{
+ FILE *ibuf;
+ int i;
+ static int shudclob;
+ static char efile[128];
+ extern char tempMesg[];
+ int (*sigs[2])();
+
+ if ((ibuf = fopen(name, "r")) == NULL) {
+ if (isedit)
+ perror(name);
+ else
+ printf("No mail for %s\n", myname);
+ return(-1);
+ }
+
+ /*
+ * Looks like all will be well. We must now relinquish our
+ * hold on the current set of stuff. Must ignore signals
+ * while we are reading the new file, else we will ruin
+ * the message[] data structure.
+ */
+
+ for (i = SIGINT; i <= SIGQUIT; i++)
+ sigs[i - SIGINT] = signal(i, SIG_IGN);
+ if (shudclob) {
+ if (edit)
+ edstop();
+ else
+ quit();
+ }
+
+ /*
+ * Copy the messages into /tmp
+ * and set pointers.
+ */
+
+ readonly = 0;
+ if ((i = open(name, 1)) < 0)
+ readonly++;
+ else
+ close(i);
+ if (shudclob) {
+ fclose(itf);
+ fclose(otf);
+ }
+ shudclob = 1;
+ edit = isedit;
+ strncpy(efile, name, 128);
+ editfile = efile;
+ mailsize = fsize(ibuf);
+ if ((otf = fopen(tempMesg, "w")) == NULL) {
+ perror(tempMesg);
+ exit(1);
+ }
+ if ((itf = fopen(tempMesg, "r")) == NULL) {
+ perror(tempMesg);
+ exit(1);
+ }
+ remove(tempMesg);
+ setptr(ibuf);
+ setmsize(msgCount);
+ fclose(ibuf);
+ for (i = SIGINT; i <= SIGQUIT; i++)
+ signal(i, sigs[i - SIGINT]);
+ printf("%s: ", name);
+ announce(!edit);
+ return(0);
+}