diff options
Diffstat (limited to 'usr.bin/mg/buffer.c')
-rw-r--r-- | usr.bin/mg/buffer.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 5f3330c3ee1..c81c50dfce8 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.83 2012/10/22 08:22:04 florian Exp $ */ +/* $OpenBSD: buffer.c,v 1.84 2012/10/22 08:31:42 florian Exp $ */ /* This file is in the public domain. */ @@ -856,11 +856,18 @@ checkdirty(struct buffer *bp) bp->b_flag |= BFDIRTY; if ((bp->b_flag & (BFDIRTY | BFIGNDIRTY)) == BFDIRTY) { - if ((s = eyorn("File changed on disk; really edit the buffer")) - != TRUE) + s = eynorr("File changed on disk; really edit the buffer"); + switch (s) { + case TRUE: + bp->b_flag &= ~BFDIRTY; + bp->b_flag |= BFIGNDIRTY; + return (TRUE); + case REVERT: + dorevert(); + return (FALSE); + default: return (s); - bp->b_flag &= ~BFDIRTY; - bp->b_flag |= BFIGNDIRTY; + } } return (TRUE); @@ -873,10 +880,8 @@ checkdirty(struct buffer *bp) int revertbuffer(int f, int n) { - struct mgwin *wp = wheadp; - struct buffer *bp = wp->w_bufp; + struct buffer *bp = wheadp->w_bufp; char fbuf[NFILEN + 32]; - int lineno; if (bp->b_fname[0] == 0) { ewprintf("Cannot revert buffer not associated with any files."); @@ -885,26 +890,36 @@ revertbuffer(int f, int n) snprintf(fbuf, sizeof(fbuf), "Revert buffer from file %s", bp->b_fname); - if (eyorn(fbuf)) { - if (access(bp->b_fname, F_OK|R_OK) != 0) { - if (errno == ENOENT) - ewprintf("File %s no longer exists!", - bp->b_fname); - else - ewprintf("File %s is no longer readable!", - bp->b_fname); - return (FALSE); - } + if (eyorn(fbuf)) + return dorevert(); - /* Save our current line, so we can go back after reloading. */ - lineno = wp->w_dotline; + return (FALSE); +} - /* Prevent readin from asking if we want to kill the buffer. */ - curbp->b_flag &= ~BFCHG; +int +dorevert() +{ + struct mgwin *wp = wheadp; + struct buffer *bp = wp->w_bufp; + int lineno; - if (readin(bp->b_fname)) - return(setlineno(lineno)); + if (access(bp->b_fname, F_OK|R_OK) != 0) { + if (errno == ENOENT) + ewprintf("File %s no longer exists!", + bp->b_fname); + else + ewprintf("File %s is no longer readable!", + bp->b_fname); + return (FALSE); } + /* Save our current line, so we can go back after reloading. */ + lineno = wp->w_dotline; + + /* Prevent readin from asking if we want to kill the buffer. */ + curbp->b_flag &= ~BFCHG; + + if (readin(bp->b_fname)) + return(setlineno(lineno)); return (FALSE); } |