This is a discussion on mg dired, part II within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Here is the second dired diff (2/2) First, check whether the insertion is into a new buffer, or an ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Here is the second dired diff (2/2) First, check whether the insertion is into a new buffer, or an insertion into an existing buffer, as the dired behavior makes no sense in the second case. Second, move the dired invocation out of fileio.c, since we don't really need (or want) to do it there. It is late, but as far as I can tell, this does what Han intended, and (with part I) works much better than what was there before. Index: def.h ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/def.h,v retrieving revision 1.67 diff -u -r1.67 def.h --- def.h 11 Oct 2005 01:08:53 -0000 1.67 +++ def.h 11 Oct 2005 09:24:57 -0000 @@ -65,6 +65,9 @@ #define FIOEOF 2 /* End of file. */ #define FIOERR 3 /* Error. */ #define FIOLONG 4 /* long line partially read */ +#ifndef NO_DIRED +# define FIODIR 5 /* File is a directory */ +#endif /* !NO_DIRED */ /* * Directory I/O. Index: file.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/file.c,v retrieving revision 1.38 diff -u -r1.38 file.c --- file.c 9 Aug 2005 00:53:48 -0000 1.38 +++ file.c 11 Oct 2005 09:27:20 -0000 @@ -305,6 +307,21 @@ else ewprintf("(File not found)"); goto out; +#ifndef NO_DIRED + } else if (s == FIODIR) { + /* file was a directory */ + if (replacebuf == FALSE) { + ewprintf("Cannot insert: file is a directory, %s", + fname); + goto cleanup; + } + killbuffer(bp); + if ((bp = dired_(fname)) == NULL) + return (FALSE); + undo_enable(x); + curbp = bp; + return (showbuffer(bp, curwp, WFHARD | WFMODE)); +#endif /* !NO_DIRED */ } opos = curwp->w_doto; @@ -431,7 +431,8 @@ } } } +cleanup: undo_enable(x); /* return FALSE if error */ return (s != FIOERR); Index: fileio.c ================================================== ================= RCS file: /usr/local/ocvs/src/usr.bin/mg/fileio.c,v retrieving revision 1.50 diff -u -r1.50 fileio.c --- fileio.c 14 Jun 2005 18:14:40 -0000 1.50 +++ fileio.c 11 Oct 2005 09:23:57 -0000 @@ -7,6 +7,11 @@ */ #include "def.h" +#ifndef NO_DIRED +#include <sys/wait.h> +#include "kbd.h" +#endif /* !NO_DIRED */ + #include <sys/types.h> #include <limits.h> #include <sys/stat.h> @@ -31,12 +36,22 @@ return (FIOFNF); return (FIOERR); } + + /* If 'fn' is a directory open it with dired. */ + if ((stat(fn, &statbuf) == 0) && S_ISDIR(statbuf.st_mode)) +#ifdef NO_DIRED + return (FIOERR); +#else + return (FIODIR); +#endif /* NO_DIRED */ + 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; bp->b_fi.fi_uid = statbuf.st_uid; bp->b_fi.fi_gid = statbuf.st_gid; } + return (FIOSUC); } @@ -336,8 +351,6 @@ #endif #ifndef NO_DIRED -#include <sys/wait.h> -#include "kbd.h" int copy(char *frname, char *toname) |