rc: skip searchpath for "", "." and ".."
This commit is contained in:
parent
d17a049c5b
commit
d81f4d4866
1 changed files with 14 additions and 16 deletions
|
@ -96,16 +96,16 @@ doredir(redir *rp)
|
||||||
word*
|
word*
|
||||||
searchpath(char *w, char *v)
|
searchpath(char *w, char *v)
|
||||||
{
|
{
|
||||||
|
static struct word nullpath = { "", 0 };
|
||||||
word *path;
|
word *path;
|
||||||
if(strncmp(w, "/", 1)==0
|
|
||||||
|| strncmp(w, "#", 1)==0
|
if(w[0] && w[0] != '/' && w[0] != '#' &&
|
||||||
|| strncmp(w, "./", 2)==0
|
(w[0] != '.' || (w[1] && w[1] != '/' && (w[1] != '.' || w[2] && w[2] != '/')))){
|
||||||
|| strncmp(w, "../", 3)==0
|
path = vlook(v)->val;
|
||||||
|| (path = vlook(v)->val)==0){
|
if(path)
|
||||||
static struct word nullpath = { "", 0};
|
return path;
|
||||||
path=&nullpath;
|
|
||||||
}
|
}
|
||||||
return path;
|
return &nullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -159,16 +159,14 @@ execcd(void)
|
||||||
pfmt(err, "Usage: cd [directory]\n");
|
pfmt(err, "Usage: cd [directory]\n");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
for(cdpath = searchpath(a->next->word, "cdpath"); cdpath; cdpath = cdpath->next){
|
a = a->next;
|
||||||
|
for(cdpath = searchpath(a->word, "cdpath"); cdpath; cdpath = cdpath->next){
|
||||||
if(cdpath->word[0] != '\0')
|
if(cdpath->word[0] != '\0')
|
||||||
dir = smprint("%s/%s", cdpath->word,
|
dir = smprint("%s/%s", cdpath->word, a->word);
|
||||||
a->next->word);
|
|
||||||
else
|
else
|
||||||
dir = estrdup(a->next->word);
|
dir = estrdup(a->word);
|
||||||
|
|
||||||
if(dochdir(dir) >= 0){
|
if(dochdir(dir) >= 0){
|
||||||
if(cdpath->word[0] != '\0' &&
|
if(cdpath->word[0] != '\0' && strcmp(cdpath->word, ".") != 0)
|
||||||
strcmp(cdpath->word, ".") != 0)
|
|
||||||
pfmt(err, "%s\n", dir);
|
pfmt(err, "%s\n", dir);
|
||||||
free(dir);
|
free(dir);
|
||||||
setstatus("");
|
setstatus("");
|
||||||
|
@ -177,7 +175,7 @@ execcd(void)
|
||||||
free(dir);
|
free(dir);
|
||||||
}
|
}
|
||||||
if(cdpath==0)
|
if(cdpath==0)
|
||||||
pfmt(err, "Can't cd %s: %r\n", a->next->word);
|
pfmt(err, "Can't cd %s: %r\n", a->word);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
a = vlook("home")->val;
|
a = vlook("home")->val;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue