If you C-x C-c out of emacs and there are unsaved buffers, emacs asks
if you want to save them (mg behaves the same). If there is a write
error (permissions or non-existant parent directory) emacs stops
exiting.  This allows the user to decide what to do with these
buffers. In mg, the contents of these buffers are lost while mg
continues to exit. 

This diff bring mg more into line with emacs. ok?

-lum

Index: buffer.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/buffer.c,v
retrieving revision 1.78
diff -u -p -r1.78 buffer.c
--- buffer.c    14 Mar 2012 13:56:35 -0000      1.78
+++ buffer.c    28 Aug 2012 14:54:26 -0000
@@ -449,7 +449,7 @@ int
 anycb(int f)
 {
        struct buffer   *bp;
-       int              s = FALSE, save = FALSE, ret;
+       int              s = FALSE, save = FALSE, save2 = FALSE, ret;
        char             pbuf[NFILEN + 11];
 
        for (bp = bheadp; bp != NULL; bp = bp->b_bufp) {
@@ -462,11 +462,14 @@ anycb(int f)
                                return (ABORT);
                        }
                        if ((f == TRUE || (save = eyorn(pbuf)) == TRUE) &&
-                           buffsave(bp) == TRUE) {
+                           (save2 = buffsave(bp)) == TRUE) {
                                bp->b_flag &= ~BFCHG;
                                upmodes(bp);
-                       } else
+                       } else {
+                               if (save2 == FIOERR)
+                                       return (save2);
                                s = TRUE;
+                       }
                        if (save == ABORT)
                                return (save);
                        save = TRUE;
Index: file.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/file.c,v
retrieving revision 1.82
diff -u -p -r1.82 file.c
--- file.c      28 Aug 2012 11:37:49 -0000      1.82
+++ file.c      28 Aug 2012 14:54:26 -0000
@@ -662,8 +662,23 @@ makebkfile(int f, int n)
 int
 writeout(FILE ** ffp, struct buffer *bp, char *fn)
 {
+       struct stat     statbuf;
        int      s;
+       char    *dp;
 
+       dp = dirname(fn);
+
+       if (stat(fn, &statbuf) == -1 && errno == ENOENT) {
+               if (access(dp, W_OK) && errno == EACCES) {
+                       ewprintf("Directory %s%s write-protected", dp,
+                           (dp[0] == '/' && dp[1] == '\0') ? "" : "/");
+                       return (FIOERR);
+               } else if (errno == ENOENT) {
+                        ewprintf("%s%s: no such directory", dp,
+                            (dp[0] == '/' && dp[1] == '\0') ? "" : "/");
+                       return (FIOERR);
+               }
+        }
        /* open writes message */
        if ((s = ffwopen(ffp, fn, bp)) != FIOSUC)
                return (FALSE);
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/main.c,v
retrieving revision 1.67
diff -u -p -r1.67 main.c
--- main.c      29 May 2012 06:08:48 -0000      1.67
+++ main.c      28 Aug 2012 14:54:26 -0000
@@ -224,6 +224,8 @@ quit(int f, int n)
 
        if ((s = anycb(FALSE)) == ABORT)
                return (ABORT);
+       if (s == FIOERR)
+               return (FALSE);
        if (s == FALSE
            || eyesno("Modified buffers exist; really exit") == TRUE) {
                vttidy();

Reply via email to