4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / mail / edit.c
index ad076da..6f5889c 100644 (file)
@@ -1,26 +1,17 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The 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.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edit.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)edit.c     8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
-#include <sys/stat.h>
+#include <fcntl.h>
+#include "extern.h"
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -31,7 +22,7 @@ static char sccsid[] = "@(#)edit.c    5.11 (Berkeley) %G%";
 /*
  * Edit a message list.
  */
 /*
  * Edit a message list.
  */
-
+int
 editor(msgvec)
        int *msgvec;
 {
 editor(msgvec)
        int *msgvec;
 {
@@ -42,7 +33,7 @@ editor(msgvec)
 /*
  * Invoke the visual editor on a message list.
  */
 /*
  * Invoke the visual editor on a message list.
  */
-
+int
 visual(msgvec)
        int *msgvec;
 {
 visual(msgvec)
        int *msgvec;
 {
@@ -55,9 +46,10 @@ visual(msgvec)
  * (which should not exist) and forking an editor on it.
  * We get the editor from the stuff above.
  */
  * (which should not exist) and forking an editor on it.
  * We get the editor from the stuff above.
  */
+int
 edit1(msgvec, type)
        int *msgvec;
 edit1(msgvec, type)
        int *msgvec;
-       char type;
+       int type;
 {
        register int c;
        int i;
 {
        register int c;
        int i;
@@ -69,7 +61,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];
@@ -90,7 +82,7 @@ edit1(msgvec, type)
                sigint = signal(SIGINT, SIG_IGN);
                fp = run_editor(setinput(mp), mp->m_size, type, readonly);
                if (fp != NULL) {
                sigint = signal(SIGINT, SIG_IGN);
                fp = run_editor(setinput(mp), mp->m_size, type, readonly);
                if (fp != NULL) {
-                       (void) fseek(otf, (long) 0, 2);
+                       (void) fseek(otf, 0L, 2);
                        size = ftell(otf);
                        mp->m_block = blockof(size);
                        mp->m_offset = offsetof(size);
                        size = ftell(otf);
                        mp->m_block = blockof(size);
                        mp->m_offset = offsetof(size);
@@ -106,7 +98,7 @@ 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);
        }
@@ -117,13 +109,13 @@ 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)
        register FILE *fp;
        off_t size;
  */
 FILE *
 run_editor(fp, size, type, readonly)
        register FILE *fp;
        off_t size;
-       char type;
+       int type, readonly;
 {
        register FILE *nf = NULL;
        register int t;
 {
        register FILE *nf = NULL;
        register int t;
@@ -136,7 +128,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;
@@ -152,7 +144,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;
@@ -160,8 +159,8 @@ 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;
-       if (run_command(edit, 0, -1, -1, tempEdit, NOSTR) < 0) {
+               edit = type == 'e' ? _PATH_EX : _PATH_VI;
+       if (run_command(edit, 0, -1, -1, tempEdit, NOSTR, NOSTR) < 0) {
                (void) unlink(tempEdit);
                goto out;
        }
                (void) unlink(tempEdit);
                goto out;
        }
@@ -184,7 +183,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;