diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-03-09 16:20:49 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-03-09 16:20:49 +0000 |
commit | 34684c50a88034a63d96b0b8f54c590094fdca6f (patch) | |
tree | c381c1c4c09f76b66de332fdb0243d1df4bdff9c /usr.bin/mg | |
parent | 51e684432edb921bd1a5233896eb5be1c3cdcdbb (diff) |
fix mg's behaviour with regards to files on which we do not have
write access. diff originally from vincent@ and forgotten for
a while.
ok rohee@, "toss it in, i'll bitch if it doesn't work" henning@
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/buffer.c | 16 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 5 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 25 | ||||
-rw-r--r-- | usr.bin/mg/fileio.c | 9 | ||||
-rw-r--r-- | usr.bin/mg/funmap.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/keymap.c | 4 | ||||
-rw-r--r-- | usr.bin/mg/main.c | 15 |
7 files changed, 52 insertions, 26 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index c67d801c828..0d533ffd1ba 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.34 2004/07/22 01:25:24 vincent Exp $ */ +/* $OpenBSD: buffer.c,v 1.35 2005/03/09 16:20:48 jfb Exp $ */ /* * Buffer handling. @@ -102,12 +102,9 @@ poptobuffer(int f, int n) */ /* ARGSUSED */ int -killbuffer(int f, int n) +killbuffer_cmd(int f, int n) { BUFFER *bp; - BUFFER *bp1; - BUFFER *bp2; - MGWIN *wp; char bufn[NBUFN], *bufp; if ((bufp = eread("Kill buffer: (default %s) ", bufn, NBUFN, EFNEW | EFBUF, @@ -117,6 +114,15 @@ killbuffer(int f, int n) bp = curbp; else if ((bp = bfind(bufn, FALSE)) == NULL) return FALSE; + return killbuffer(bp); +} + +int +killbuffer(BUFFER *bp) +{ + BUFFER *bp1; + BUFFER *bp2; + MGWIN *wp; /* * Find some other buffer to display. try the alternate buffer, diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 8a0853ed1b6..e7a6b67299a 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.56 2004/07/22 01:25:24 vincent Exp $ */ +/* $OpenBSD: def.h,v 1.57 2005/03/09 16:20:48 jfb Exp $ */ #include <sys/queue.h> @@ -379,7 +379,8 @@ MGWIN *wpopup(void); int togglereadonly(int, int); BUFFER *bfind(const char *, int); int poptobuffer(int, int); -int killbuffer(int, int); +int killbuffer(BUFFER *); +int killbuffer_cmd(int, int); int savebuffers(int, int); int listbuffers(int, int); int addlinef(BUFFER *, char *, ...); diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index 6043f47f195..755a0980c9f 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.29 2004/07/22 01:25:25 vincent Exp $ */ +/* $OpenBSD: file.c,v 1.30 2005/03/09 16:20:48 jfb Exp $ */ /* * File commands. @@ -54,8 +54,13 @@ filevisit(int f, int n) curbp = bp; if (showbuffer(bp, curwp, WFHARD) != TRUE) return FALSE; - if (bp->b_fname[0] == 0) - return readin(adjf); + if (bp->b_fname[0] == 0) { + int status; + + if ((status = readin(adjf)) != TRUE) + killbuffer(bp); + return status; + } return TRUE; } @@ -96,8 +101,13 @@ poptofile(int f, int n) return FALSE; curbp = bp; curwp = wp; - if (bp->b_fname[0] == 0) - return readin(adjf); + if (bp->b_fname[0] == 0) { + int status; + + if ((status = readin(adjf)) != TRUE) + killbuffer(bp); + return status; + } return TRUE; } @@ -140,7 +150,10 @@ readin(char *fname) /* might be old */ if (bclear(curbp) != TRUE) return TRUE; - status = insertfile(fname, fname, TRUE); + if ((status = insertfile(fname, fname, TRUE)) != TRUE) { + ewprintf("File is not readable: %s", fname); + return FALSE; + } /* * Call auto-executing function if we need to. diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index 73ded467d52..230da21c12d 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.45 2005/02/01 16:04:15 henning Exp $ */ +/* $OpenBSD: fileio.c,v 1.46 2005/03/09 16:20:48 jfb Exp $ */ /* * POSIX fileio.c @@ -24,8 +24,11 @@ ffropen(const char *fn, BUFFER *bp) { struct stat statbuf; - if ((ffp = fopen(fn, "r")) == NULL) - return (FIOFNF); + if ((ffp = fopen(fn, "r")) == NULL) { + if (errno == ENOENT) + return (FIOFNF); + return (FIOERR); + } if (bp && fstat(fileno(ffp), &statbuf) == 0) { /* set highorder bit to make sure this isn't all zero */ bp->b_fi.fi_mode = statbuf.st_mode | 0x8000; diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c index 83436798ae5..02698fe98a4 100644 --- a/usr.bin/mg/funmap.c +++ b/usr.bin/mg/funmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funmap.c,v 1.9 2002/05/29 12:41:42 vincent Exp $ */ +/* $OpenBSD: funmap.c,v 1.10 2005/03/09 16:20:48 jfb Exp $ */ /* * Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. All rights reserved. * @@ -137,7 +137,7 @@ static struct funmap functnames[] = { {forwisearch, "isearch-forward",}, {justone, "just-one-space",}, {ctrlg, "keyboard-quit",}, - {killbuffer, "kill-buffer",}, + {killbuffer_cmd, "kill-buffer",}, {killline, "kill-line",}, {killpara, "kill-paragraph",}, {killregion, "kill-region",}, diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c index 3541a1772ae..ae12e8393c7 100644 --- a/usr.bin/mg/keymap.c +++ b/usr.bin/mg/keymap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keymap.c,v 1.26 2002/12/09 08:20:46 deraadt Exp $ */ +/* $OpenBSD: keymap.c,v 1.27 2005/03/09 16:20:48 jfb Exp $ */ /* * Keyboard maps. This is character set dependent. The terminal specific @@ -130,7 +130,7 @@ static PF cXcar[] = { rescan, /* h */ fileinsert, /* i */ rescan, /* j */ - killbuffer, /* k */ + killbuffer_cmd, /* k */ rescan, /* l */ rescan, /* m */ nextwind, /* n */ diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c index a8bf7264bbb..abbee6b6395 100644 --- a/usr.bin/mg/main.c +++ b/usr.bin/mg/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.33 2004/07/19 12:14:08 vincent Exp $ */ +/* $OpenBSD: main.c,v 1.34 2005/03/09 16:20:48 jfb Exp $ */ /* * Mainline. @@ -31,7 +31,7 @@ main(int argc, char **argv) { char *cp, *init_fcn_name = NULL; PF init_fcn = NULL; - int o, i, nfiles; + int o, i, nfiles, status; while ((o = getopt(argc, argv, "f:")) != -1) switch (o) { @@ -105,10 +105,13 @@ notnum: } curbp = findbuffer(cp); (void)showbuffer(curbp, curwp, 0); - (void)readin(cp); - if (init_fcn_name) - init_fcn(0, 1); - nfiles++; + if ((status = readin(cp)) != TRUE) { + killbuffer(curbp); + } else { + if (init_fcn_name) + init_fcn(0, 1); + nfiles++; + } } } } |