summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/def.h5
-rw-r--r--usr.bin/mg/dir.c22
-rw-r--r--usr.bin/mg/dired.c4
-rw-r--r--usr.bin/mg/file.c8
4 files changed, 24 insertions, 15 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index ccd79e0b604..15cc5cf1eb2 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.140 2014/03/22 11:05:37 lum Exp $ */
+/* $OpenBSD: def.h,v 1.141 2014/04/03 20:17:12 lum Exp $ */
/* This file is in the public domain. */
@@ -336,7 +336,8 @@ int changedir(int, int);
int showcwdir(int, int);
int getcwdir(char *, size_t);
int makedir(int, int);
-int do_makedir(void);
+int do_makedir(char *);
+int ask_makedir(void);
/* dired.c */
struct buffer *dired_(char *);
diff --git a/usr.bin/mg/dir.c b/usr.bin/mg/dir.c
index b48888a8291..dbe68e06619 100644
--- a/usr.bin/mg/dir.c
+++ b/usr.bin/mg/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.26 2014/03/31 18:00:58 lum Exp $ */
+/* $OpenBSD: dir.c,v 1.27 2014/04/03 20:17:12 lum Exp $ */
/* This file is in the public domain. */
@@ -84,18 +84,15 @@ getcwdir(char *buf, size_t len)
int
makedir(int f, int n)
{
- return (do_makedir());
+ return (ask_makedir());
}
int
-do_makedir(void)
+ask_makedir(void)
{
- struct stat sb;
- int finished, ishere;
- mode_t dir_mode, mode, oumask;
char bufc[NFILEN];
- char *slash, *path;
+ char *path;
if (getbufcwd(bufc, sizeof(bufc)) != TRUE)
return (ABORT);
@@ -105,6 +102,17 @@ do_makedir(void)
else if (path[0] == '\0')
return (FALSE);
+ return (do_makedir(path));
+}
+
+int
+do_makedir(char *path)
+{
+ struct stat sb;
+ int finished, ishere;
+ mode_t dir_mode, mode, oumask;
+ char *slash;
+
if ((path = adjustname(path, TRUE)) == NULL)
return (FALSE);
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index aeb22a4d6d1..3e7576301c8 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.66 2014/03/20 07:47:29 lum Exp $ */
+/* $OpenBSD: dired.c,v 1.67 2014/04/03 20:17:12 lum Exp $ */
/* This file is in the public domain. */
@@ -648,7 +648,7 @@ d_create_directory(int f, int n)
int ret;
struct buffer *bp;
- ret = do_makedir();
+ ret = ask_makedir();
if (ret != TRUE)
return(ret);
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 81cf944cdca..de8be3dc085 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.93 2014/03/31 21:29:59 lum Exp $ */
+/* $OpenBSD: file.c,v 1.94 2014/04/03 20:17:12 lum Exp $ */
/* This file is in the public domain. */
@@ -231,10 +231,10 @@ readin(char *fname)
(void)xdirname(dp, fname, sizeof(dp));
(void)strlcat(dp, "/", sizeof(dp));
+ /* Missing directory; keep buffer read-write, like emacs */
if (stat(dp, &statbuf) == -1 && errno == ENOENT) {
- /* not read-only; like emacs */
- ewprintf("Use M-x make-directory RET RET to create the"
- " directory and its parents");
+ if (eyorn("Missing directory, create") == TRUE)
+ (void)do_makedir(dp);
} else if (access(dp, W_OK) == -1 && errno == EACCES) {
ewprintf("File not found and directory"
" write-protected");