summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/buffer.c7
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/dir.c16
-rw-r--r--usr.bin/mg/display.c14
-rw-r--r--usr.bin/mg/funmap.c3
-rw-r--r--usr.bin/mg/grep.c25
6 files changed, 48 insertions, 20 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index 2e5ee8b1ce8..9d7b89e3af0 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.66 2006/11/19 16:51:19 deraadt Exp $ */
+/* $OpenBSD: buffer.c,v 1.67 2007/05/28 17:52:17 kjell Exp $ */
/* This file is in the public domain. */
@@ -15,6 +15,9 @@
static struct buffer *makelist(void);
static struct buffer *bnew(const char *);
+/* Flag for global working dir */
+extern int globalwd;
+
/* ARGSUSED */
int
togglereadonly(int f, int n)
@@ -782,7 +785,7 @@ getbufcwd(char *path, size_t plen)
if (plen == 0)
return (FALSE);
- if (curbp->b_cwd[0] != '\0') {
+ if (globalwd == FALSE && curbp->b_cwd[0] != '\0') {
(void)strlcpy(path, curbp->b_cwd, plen);
} else {
if (getcwdir(cwd, sizeof(cwd)) == FALSE)
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 163e59b8c47..232c15fd77a 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.99 2007/02/21 23:33:12 deanna Exp $ */
+/* $OpenBSD: def.h,v 1.100 2007/05/28 17:52:17 kjell Exp $ */
/* This file is in the public domain. */
@@ -619,6 +619,7 @@ void mail_init(void);
/* grep.c X */
int next_error(int, int);
+int globalwdtoggle(int, int);
/*
* Externals.
diff --git a/usr.bin/mg/dir.c b/usr.bin/mg/dir.c
index 9f82d5f3fd0..e96e8e2049d 100644
--- a/usr.bin/mg/dir.c
+++ b/usr.bin/mg/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.17 2006/05/02 17:10:25 kjell Exp $ */
+/* $OpenBSD: dir.c,v 1.18 2007/05/28 17:52:17 kjell Exp $ */
/* This file is in the public domain. */
@@ -38,19 +38,21 @@ changedir(int f, int n)
(void)strlcpy(bufc, mgcwd, sizeof(bufc));
if ((bufp = eread("Change default directory: ", bufc, NFILEN,
- EFDEF | EFNEW | EFCR)) == NULL)
+ EFDEF | EFNEW | EFCR | EFFILE)) == NULL)
return (ABORT);
else if (bufp[0] == '\0')
return (FALSE);
+ /* Append trailing slash */
if (chdir(bufc) == -1) {
ewprintf("Can't change dir to %s", bufc);
return (FALSE);
- } else {
- if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == NULL)
- panic("Can't get current directory!");
- ewprintf("Current directory is now %s", bufp);
- return (TRUE);
}
+ if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == NULL)
+ panic("Can't get current directory!");
+ if (mgcwd[strlen(mgcwd) - 1] != '/')
+ (void)strlcat(mgcwd, "/", sizeof(mgcwd));
+ ewprintf("Current directory is now %s", bufp);
+ return (TRUE);
}
/*
diff --git a/usr.bin/mg/display.c b/usr.bin/mg/display.c
index 3ac9a52a313..5f00d4aa078 100644
--- a/usr.bin/mg/display.c
+++ b/usr.bin/mg/display.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: display.c,v 1.34 2007/03/29 17:37:15 kjell Exp $ */
+/* $OpenBSD: display.c,v 1.35 2007/05/28 17:52:17 kjell Exp $ */
/* This file is in the public domain. */
@@ -108,10 +108,12 @@ static int linenos = LINENOMODE;
/* Is macro recording enabled? */
extern int macrodef;
+/* Is working directory global? */
+extern int globalwd;
/*
- * Since we don't have variables (we probably should) this is a command
- * processor for changing the value of the line number mode flag.
+ * Since we don't have variables (we probably should) these are command
+ * processors for changing the values of mode flags.
*/
/* ARGSUSED */
int
@@ -127,8 +129,6 @@ linenotoggle(int f, int n)
return (TRUE);
}
-
-
/*
* Reinit the display data structures, this is called when the terminal
* size changes.
@@ -826,9 +826,11 @@ modeline(struct mgwin *wp)
vtputc('-');
++n;
}
- /* XXX This should eventually move to a real mode */
+ /* XXX These should eventually move to a real mode */
if (macrodef == TRUE)
n += vtputs("-def");
+ if (globalwd == TRUE)
+ n += vtputs("-gwd");
vtputc(')');
++n;
diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
index df46ed3fdad..f7e232886f4 100644
--- a/usr.bin/mg/funmap.c
+++ b/usr.bin/mg/funmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funmap.c,v 1.26 2006/12/21 18:06:02 kjell Exp $ */
+/* $OpenBSD: funmap.c,v 1.27 2007/05/28 17:52:17 kjell Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>. All rights reserved.
*
@@ -89,6 +89,7 @@ static struct funmap functnames[] = {
#ifndef NO_MACRO
{finishmacro, "end-kbd-macro",},
#endif /* !NO_MACRO */
+ {globalwdtoggle, "global-wd-mode",},
{gotoeob, "end-of-buffer",},
{gotoeol, "end-of-line",},
{enlargewind, "enlarge-window",},
diff --git a/usr.bin/mg/grep.c b/usr.bin/mg/grep.c
index 0b580163f17..adb71932a43 100644
--- a/usr.bin/mg/grep.c
+++ b/usr.bin/mg/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.33 2006/11/19 16:51:19 deraadt Exp $ */
+/* $OpenBSD: grep.c,v 1.34 2007/05/28 17:52:17 kjell Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>.
* Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>.
@@ -34,6 +34,7 @@
#include <libgen.h>
#include <time.h>
+int globalwd = FALSE;
static int compile_goto_error(int, int);
int next_error(int, int);
static int grep(int, int);
@@ -41,7 +42,6 @@ static int compile(int, int);
static int gid(int, int);
static struct buffer *compile_mode(const char *, const char *);
static int xlint(int, int);
-
void grep_init(void);
static char compile_last_command[NFILEN] = "make ";
@@ -316,7 +316,8 @@ compile_goto_error(int f, int n)
goto fail;
if (fname && fname[0] != '/') {
- (void)strlcpy(path, curbp->b_cwd, sizeof(path));
+ if (getbufcwd(path, sizeof(path)) == FALSE)
+ goto fail;
if (strlcat(path, fname, sizeof(path)) >= sizeof(path))
goto fail;
adjf = path;
@@ -368,3 +369,21 @@ next_error(int f, int n)
return (compile_goto_error(f, n));
}
+
+/*
+ * Since we don't have variables (we probably should) these are command
+ * processors for changing the values of mode flags.
+ */
+/* ARGSUSED */
+int
+globalwdtoggle(int f, int n)
+{
+ if (f & FFARG)
+ globalwd = n > 0;
+ else
+ globalwd = !globalwd;
+
+ sgarbf = TRUE;
+
+ return (TRUE);
+}