aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acme/look.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-21 22:39:37 +0000
committerrsc <devnull@localhost>2004-04-21 22:39:37 +0000
commit99f40290902d69956f7ef57b33599c4092021d01 (patch)
tree593bdc0cf0b5c4caec76799e925c74e5e7cbf2ac /src/cmd/acme/look.c
parentb9403fe70a539ab5a6d174e5a800082c542ea06b (diff)
downloadplan9port-99f40290902d69956f7ef57b33599c4092021d01.tar.gz
plan9port-99f40290902d69956f7ef57b33599c4092021d01.tar.bz2
plan9port-99f40290902d69956f7ef57b33599c4092021d01.zip
$foo in tags - here only for reference.
Diffstat (limited to 'src/cmd/acme/look.c')
-rw-r--r--src/cmd/acme/look.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c
index f892640a..ce2f772f 100644
--- a/src/cmd/acme/look.c
+++ b/src/cmd/acme/look.c
@@ -15,6 +15,8 @@
#include "dat.h"
#include "fns.h"
+#define debug 0
+
FsFid *plumbsendfid;
FsFid *plumbeditfid;
@@ -456,10 +458,12 @@ dirname(Text *t, Rune *r, int n)
b = nil;
if(t==nil || t->w==nil)
goto Rescue;
+ if(n>=1 && r[0]=='$')
+ expandenv(&r, &n);
nt = t->w->tag.file->b.nc;
if(nt == 0)
goto Rescue;
- if(n>=1 && r[0]=='/')
+ if(n>=1 && r[0]=='/')
goto Rescue;
b = runemalloc(nt+n+1);
bufread(&t->w->tag.file->b, 0, b, nt);
@@ -473,9 +477,12 @@ dirname(Text *t, Rune *r, int n)
}
if(slash < 0)
goto Rescue;
- runemove(b+slash+1, r, n);
+ slash++;
+ if(expandenv(&b, &slash))
+ b = runerealloc(b, slash+n);
+ runemove(b+slash, r, n);
free(r);
- return cleanrname(runestr(b, slash+1+n));
+ return cleanrname(runestr(b, slash+n));
Rescue:
free(b);
@@ -535,9 +542,11 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
n = q1-q0;
if(n == 0)
return FALSE;
+
/* see if it's a file name */
- r = runemalloc(n);
+ r = runemalloc(n+1); /* +1 for $ below */
bufread(&t->file->b, q0, r, n);
+
/* first, does it have bad chars? */
nname = -1;
for(i=0; i<n; i++){
@@ -552,9 +561,13 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
}
if(nname == -1)
nname = n;
- for(i=0; i<nname; i++)
+ for(i=0; i<nname; i++){
+ if(i==0 && r[0]=='$')
+ continue;
if(!isfilec(r[i]))
goto Isntfile;
+ }
+
/*
* See if it's a file name in <>, and turn that into an include
* file name if so. Should probably do it for "" too, but that's not
@@ -569,10 +582,18 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
else if(amin == q0)
goto Isfile;
else{
- rs = dirname(t, r, nname);
- r = rs.r;
- nname = rs.nr;
+ if(debug) fprint(2, "x1 %.*S\n", nname, r);
+ if(r[0] != '$'){
+ rs = dirname(t, r, nname);
+ r = rs.r;
+ nname = rs.nr;
+ if(debug) fprint(2, "x1.5 %.*S\n", nname, r);
+ }
+ if(r[0]=='$')
+ expandenv(&r, &nname);
+ if(debug) fprint(2, "x2 %.*S\n", nname, r);
}
+
e->bname = runetobyte(r, nname);
/* if it's already a window name, it's a file */
w = lookfile(r, nname);