summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2006-06-01 05:34:53 +0000
committerJason Wright <jason@cvs.openbsd.org>2006-06-01 05:34:53 +0000
commit2c614c2317802965476fd24c0aa1a301afa994f7 (patch)
tree390f7efe10a48baad872898049ed2f40b35b5ecf /usr.bin/mg
parentc5d658f862d9540dd3a7dc79f73be9da88737fce (diff)
make // /~ path rewriting optional in adjustname() and use it everywhere
except for the command line specified files. ok kjell,cloder
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/def.h4
-rw-r--r--usr.bin/mg/dired.c4
-rw-r--r--usr.bin/mg/extend.c4
-rw-r--r--usr.bin/mg/file.c12
-rw-r--r--usr.bin/mg/fileio.c25
-rw-r--r--usr.bin/mg/grep.c4
-rw-r--r--usr.bin/mg/main.c4
7 files changed, 36 insertions, 21 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 111de7dfc7a..20fe10a947c 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.90 2006/05/29 00:02:23 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.91 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -420,7 +420,7 @@ int ffclose(struct buffer *);
int ffputbuf(struct buffer *);
int ffgetline(char *, int, int *);
int fbackupfile(const char *);
-char *adjustname(const char *);
+char *adjustname(const char *, int);
char *startupfile(char *);
int copy(char *, char *);
struct list *make_file_list(char *);
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index b6d51a66d7f..8fcf444d080 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.37 2006/05/28 23:30:16 kjell Exp $ */
+/* $OpenBSD: dired.c,v 1.38 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -593,7 +593,7 @@ dired_(char *dname)
char line[256];
int len, ret;
- if ((dname = adjustname(dname)) == NULL) {
+ if ((dname = adjustname(dname, FALSE)) == NULL) {
ewprintf("Bad directory name");
return (NULL);
}
diff --git a/usr.bin/mg/extend.c b/usr.bin/mg/extend.c
index 492fd89bd32..07d9637c56f 100644
--- a/usr.bin/mg/extend.c
+++ b/usr.bin/mg/extend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: extend.c,v 1.45 2006/03/30 18:32:07 kjell Exp $ */
+/* $OpenBSD: extend.c,v 1.46 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -662,7 +662,7 @@ load(const char *fname)
int nbytes = 0;
char excbuf[128];
- if ((fname = adjustname(fname)) == NULL)
+ if ((fname = adjustname(fname, TRUE)) == NULL)
/* just to be careful */
return (FALSE);
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 0adff5bf369..fa2c79b04dc 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.57 2006/06/01 05:07:39 kjell Exp $ */
+/* $OpenBSD: file.c,v 1.58 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -28,7 +28,7 @@ fileinsert(int f, int n)
return (ABORT);
else if (bufp[0] == '\0')
return (FALSE);
- adjf = adjustname(bufp);
+ adjf = adjustname(bufp, TRUE);
if (adjf == NULL)
return (FALSE);
return (insertfile(adjf, NULL, FALSE));
@@ -56,7 +56,7 @@ filevisit(int f, int n)
return (ABORT);
else if (bufp[0] == '\0')
return (FALSE);
- adjf = adjustname(fname);
+ adjf = adjustname(fname, TRUE);
if (adjf == NULL)
return (FALSE);
if ((bp = findbuffer(adjf)) == NULL)
@@ -99,7 +99,7 @@ filevisitalt(int f, int n)
if (status == ABORT || status == FALSE)
return (ABORT);
- adjf = adjustname(fname);
+ adjf = adjustname(fname, TRUE);
if (adjf == NULL)
return (FALSE);
if ((bp = findbuffer(adjf)) == NULL)
@@ -147,7 +147,7 @@ poptofile(int f, int n)
return (ABORT);
else if (bufp[0] == '\0')
return (FALSE);
- adjf = adjustname(fname);
+ adjf = adjustname(fname, TRUE);
if (adjf == NULL)
return (FALSE);
if ((bp = findbuffer(adjf)) == NULL)
@@ -482,7 +482,7 @@ filewrite(int f, int n)
else if (bufp[0] == '\0')
return (FALSE);
- adjfname = adjustname(fname);
+ adjfname = adjustname(fname, TRUE);
if (adjfname == NULL)
return (FALSE);
/* old attributes are no longer current */
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index decbf946a95..d051c0ffc46 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.73 2006/05/03 22:25:34 kjell Exp $ */
+/* $OpenBSD: fileio.c,v 1.74 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -239,14 +239,29 @@ fbackupfile(const char *fn)
* and remove all occurences of /./ and /../
*/
char *
-adjustname(const char *fn)
+adjustname(const char *fn, int slashslash)
{
static char fnb[MAXPATHLEN];
- const char *cp;
+ const char *cp, *ep = NULL;
char user[LOGIN_NAME_MAX], path[MAXPATHLEN];
size_t ulen, plen;
path[0] = '\0';
+
+ if (slashslash) {
+ cp = fn + strlen(fn) - 1;
+ for (; cp >= fn; cp--) {
+ if (ep && (*cp == '/')) {
+ fn = ep;
+ break;
+ }
+ if (*cp == '/' || *cp == '~')
+ ep = cp;
+ else
+ ep = NULL;
+ }
+ }
+
/* first handle tilde expansion */
if (fn[0] == '~') {
struct passwd *pw;
@@ -427,10 +442,10 @@ make_file_list(char *buf)
len = strlen(buf);
if (len && buf[len - 1] == '.') {
buf[len - 1] = 'x';
- dir = adjustname(buf);
+ dir = adjustname(buf, TRUE);
buf[len - 1] = '.';
} else
- dir = adjustname(buf);
+ dir = adjustname(buf, TRUE);
if (dir == NULL)
return (NULL);
/*
diff --git a/usr.bin/mg/grep.c b/usr.bin/mg/grep.c
index 7060f544731..2270f6b6078 100644
--- a/usr.bin/mg/grep.c
+++ b/usr.bin/mg/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.29 2006/05/27 21:22:45 kjell Exp $ */
+/* $OpenBSD: grep.c,v 1.30 2006/06/01 05:34:52 jason Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>.
* Copyright (c) 2005 Kjell Wooding <kjell@openbsd.org>.
@@ -321,7 +321,7 @@ compile_goto_error(int f, int n)
goto fail;
adjf = path;
} else {
- adjf = adjustname(fname);
+ adjf = adjustname(fname, TRUE);
}
free(line);
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index 4500c461283..aedd3315c73 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.51 2006/05/28 23:30:16 kjell Exp $ */
+/* $OpenBSD: main.c,v 1.52 2006/06/01 05:34:52 jason Exp $ */
/* This file is in the public domain. */
@@ -108,7 +108,7 @@ main(int argc, char **argv)
startrow = lval;
} else {
notnum:
- cp = adjustname(argv[i]);
+ cp = adjustname(argv[i], FALSE);
if (cp != NULL) {
if (nfiles == 1)
splitwind(0, 1);