BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / mail / edit.c
index 37d94cd..8af0437 100644 (file)
@@ -2,21 +2,37 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edit.c     5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)edit.c     5.15 (Berkeley) 6/25/90";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -59,7 +75,6 @@ edit1(msgvec, type)
        int *msgvec;
        char type;
 {
        int *msgvec;
        char type;
 {
-       int (*sigcont)() = signal(SIGCONT, SIG_DFL);
        register int c;
        int i;
        FILE *fp;
        register int c;
        int i;
        FILE *fp;
@@ -70,7 +85,7 @@ edit1(msgvec, type)
         * Deal with each message to be edited . . .
         */
        for (i = 0; msgvec[i] && i < msgCount; i++) {
         * Deal with each message to be edited . . .
         */
        for (i = 0; msgvec[i] && i < msgCount; i++) {
-               int (*sigint)();
+               sig_t sigint;
 
                if (i > 0) {
                        char buf[100];
 
                if (i > 0) {
                        char buf[100];
@@ -107,11 +122,10 @@ edit1(msgvec, type)
                        }
                        if (ferror(otf))
                                perror("/tmp");
                        }
                        if (ferror(otf))
                                perror("/tmp");
-                       (void) fclose(fp);
+                       (void) Fclose(fp);
                }
                (void) signal(SIGINT, sigint);
        }
                }
                (void) signal(SIGINT, sigint);
        }
-       (void) signal(SIGCONT, sigcont);
        return 0;
 }
 
        return 0;
 }
 
@@ -119,7 +133,7 @@ edit1(msgvec, type)
  * Run an editor on the file at "fpp" of "size" bytes,
  * and return a new file pointer.
  * Signals must be handled by the caller.
  * Run an editor on the file at "fpp" of "size" bytes,
  * and return a new file pointer.
  * Signals must be handled by the caller.
- * "Type" is 'e' for EDITOR, 'v' for VISUAL.
+ * "Type" is 'e' for _PATH_EX, 'v' for _PATH_VI.
  */
 FILE *
 run_editor(fp, size, type, readonly)
  */
 FILE *
 run_editor(fp, size, type, readonly)
@@ -138,7 +152,7 @@ run_editor(fp, size, type, readonly)
                perror(tempEdit);
                goto out;
        }
                perror(tempEdit);
                goto out;
        }
-       if ((nf = fdopen(t, "w")) == NULL) {
+       if ((nf = Fdopen(t, "w")) == NULL) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
@@ -154,7 +168,14 @@ run_editor(fp, size, type, readonly)
                modtime = 0;
        else
                modtime = statb.st_mtime;
                modtime = 0;
        else
                modtime = statb.st_mtime;
-       if (ferror(nf) || fclose(nf) < 0) {
+       if (ferror(nf)) {
+               (void) Fclose(nf);
+               perror(tempEdit);
+               (void) unlink(tempEdit);
+               nf = NULL;
+               goto out;
+       }
+       if (Fclose(nf) < 0) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                nf = NULL;
                perror(tempEdit);
                (void) unlink(tempEdit);
                nf = NULL;
@@ -162,7 +183,7 @@ run_editor(fp, size, type, readonly)
        }
        nf = NULL;
        if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NOSTR)
        }
        nf = NULL;
        if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NOSTR)
-               edit = type == 'e' ? EDITOR : VISUAL;
+               edit = type == 'e' ? _PATH_EX : _PATH_VI;
        if (run_command(edit, 0, -1, -1, tempEdit, NOSTR) < 0) {
                (void) unlink(tempEdit);
                goto out;
        if (run_command(edit, 0, -1, -1, tempEdit, NOSTR) < 0) {
                (void) unlink(tempEdit);
                goto out;
@@ -186,7 +207,7 @@ run_editor(fp, size, type, readonly)
        /*
         * Now switch to new file.
         */
        /*
         * Now switch to new file.
         */
-       if ((nf = fopen(tempEdit, "a+")) == NULL) {
+       if ((nf = Fopen(tempEdit, "a+")) == NULL) {
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;
                perror(tempEdit);
                (void) unlink(tempEdit);
                goto out;