Unix Technical Forum

mg dired, part II

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 08:06 AM
kjell@pintday.org
 
Posts: n/a
Default mg dired, part II

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)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com