PR/3888: Chris Demetriou: type command-with-slash prints
$PATH[0]/command-with-slash...
This commit is contained in:
parent
25b23032f5
commit
c996803cad
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: eval.c,v 1.37 1997/07/15 17:49:15 christos Exp $ */
|
||||
/* $NetBSD: eval.c,v 1.38 1997/07/20 21:27:35 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: eval.c,v 1.37 1997/07/15 17:49:15 christos Exp $");
|
||||
__RCSID("$NetBSD: eval.c,v 1.38 1997/07/20 21:27:35 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -685,7 +685,7 @@ evalcommand(cmd, flags, backcmd)
|
|||
if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0)
|
||||
path = sp->text + sizeof(PATH) - 1;
|
||||
|
||||
find_command(argv[0], &cmdentry, 1, path);
|
||||
find_command(argv[0], &cmdentry, DO_ERR, path);
|
||||
if (cmdentry.cmdtype == CMDUNKNOWN) { /* command not found */
|
||||
exitstatus = 127;
|
||||
flushout(&errout);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: exec.c,v 1.23 1997/07/04 21:01:59 christos Exp $ */
|
||||
/* $NetBSD: exec.c,v 1.24 1997/07/20 21:27:36 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: exec.c,v 1.23 1997/07/04 21:01:59 christos Exp $");
|
||||
__RCSID("$NetBSD: exec.c,v 1.24 1997/07/20 21:27:36 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -359,7 +359,7 @@ hashcmd(argc, argv)
|
|||
&& (cmdp->cmdtype == CMDNORMAL
|
||||
|| (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
|
||||
delete_cmd_entry();
|
||||
find_command(name, &entry, 1, pathval());
|
||||
find_command(name, &entry, DO_ERR, pathval());
|
||||
if (verbose) {
|
||||
if (entry.cmdtype != CMDUNKNOWN) { /* if no error msg */
|
||||
cmdp = cmdlookup(name, 0);
|
||||
|
@ -420,10 +420,10 @@ printentry(cmdp, verbose)
|
|||
*/
|
||||
|
||||
void
|
||||
find_command(name, entry, printerr, path)
|
||||
find_command(name, entry, act, path)
|
||||
char *name;
|
||||
struct cmdentry *entry;
|
||||
int printerr;
|
||||
int act;
|
||||
char *path;
|
||||
{
|
||||
struct tblentry *cmdp;
|
||||
|
@ -436,6 +436,22 @@ find_command(name, entry, printerr, path)
|
|||
|
||||
/* If name contains a slash, don't use the hash table */
|
||||
if (strchr(name, '/') != NULL) {
|
||||
if (act & DO_ABS) {
|
||||
while (stat(name, &statb) < 0) {
|
||||
#ifdef SYSV
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
e = errno;
|
||||
entry->cmdtype = CMDUNKNOWN;
|
||||
entry->u.index = -1;
|
||||
return;
|
||||
}
|
||||
entry->cmdtype = CMDNORMAL;
|
||||
entry->u.index = -1;
|
||||
return;
|
||||
}
|
||||
entry->cmdtype = CMDNORMAL;
|
||||
entry->u.index = 0;
|
||||
return;
|
||||
|
@ -537,7 +553,7 @@ loop:
|
|||
/* We failed. If there was an entry for this command, delete it */
|
||||
if (cmdp)
|
||||
delete_cmd_entry();
|
||||
if (printerr)
|
||||
if (act & DO_ERR)
|
||||
outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
|
||||
entry->cmdtype = CMDUNKNOWN;
|
||||
return;
|
||||
|
@ -888,17 +904,21 @@ typecmd(argc, argv)
|
|||
}
|
||||
else {
|
||||
/* Finally use brute force */
|
||||
find_command(argv[i], &entry, 0, pathval());
|
||||
find_command(argv[i], &entry, DO_ABS, pathval());
|
||||
}
|
||||
|
||||
switch (entry.cmdtype) {
|
||||
case CMDNORMAL: {
|
||||
int j = entry.u.index;
|
||||
char *path = pathval(), *name;
|
||||
do {
|
||||
name = padvance(&path, argv[i]);
|
||||
stunalloc(name);
|
||||
} while (--j >= 0);
|
||||
if (j == -1)
|
||||
name = argv[i];
|
||||
else {
|
||||
do {
|
||||
name = padvance(&path, argv[i]);
|
||||
stunalloc(name);
|
||||
} while (--j >= 0);
|
||||
}
|
||||
out1fmt(" is%s %s\n",
|
||||
cmdp ? " a tracked alias for" : "", name);
|
||||
break;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: exec.h,v 1.12 1997/02/06 23:24:53 christos Exp $ */
|
||||
/* $NetBSD: exec.h,v 1.13 1997/07/20 21:27:37 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
|
@ -54,6 +54,9 @@ struct cmdentry {
|
|||
};
|
||||
|
||||
|
||||
#define DO_ERR 1 /* find_command prints errors */
|
||||
#define DO_ABS 2 /* find_command checks absolute paths */
|
||||
|
||||
extern char *pathopt; /* set by padvance */
|
||||
extern int exerrno; /* last exec error */
|
||||
|
||||
|
|
Loading…
Reference in New Issue