diff options
author | Stefan Farfeleder <stefanf@FreeBSD.org> | 2005-10-28 18:37:09 +0000 |
---|---|---|
committer | Stefan Farfeleder <stefanf@FreeBSD.org> | 2005-10-28 18:37:09 +0000 |
commit | b2f153feaf51cf8568b124b2e3192aa25e50b30c (patch) | |
tree | 0e857bf6739f08f4e56d9fa1aee34ddce7a13452 /bin/sh/exec.c | |
parent | df19ed6a0231e3b825ce21ea2252a27fe18f9c2e (diff) | |
download | src-test2-b2f153feaf51cf8568b124b2e3192aa25e50b30c.tar.gz src-test2-b2f153feaf51cf8568b124b2e3192aa25e50b30c.zip |
Notes
Diffstat (limited to 'bin/sh/exec.c')
-rw-r--r-- | bin/sh/exec.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 55e3fec543c3..d983849ff631 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -705,11 +705,12 @@ unsetfunc(char *name) } /* - * Locate and print what a word is... + * Shared code for the following builtin commands: + * type, command -v, command -V */ int -typecmd(int argc, char **argv) +typecmd_impl(int argc, char **argv, int cmd) { struct cmdentry entry; struct tblentry *cmdp; @@ -720,20 +721,28 @@ typecmd(int argc, char **argv) extern char *const parsekwd[]; for (i = 1; i < argc; i++) { - out1str(argv[i]); + if (cmd != TYPECMD_SMALLV) + out1str(argv[i]); + /* First look at the keywords */ for (pp = (char **)parsekwd; *pp; pp++) if (**pp == *argv[i] && equal(*pp, argv[i])) break; if (*pp) { - out1str(" is a shell keyword\n"); + if (cmd == TYPECMD_SMALLV) + out1fmt("%s\n", argv[i]); + else + out1str(" is a shell keyword\n"); continue; } /* Then look at the aliases */ if ((ap = lookupalias(argv[i], 1)) != NULL) { - out1fmt(" is an alias for %s\n", ap->val); + if (cmd == TYPECMD_SMALLV) + out1fmt("alias %s='%s'\n", argv[i], ap->val); + else + out1fmt(" is an alias for %s\n", ap->val); continue; } @@ -756,29 +765,55 @@ typecmd(int argc, char **argv) name = padvance(&path, argv[i]); stunalloc(name); } while (--j >= 0); - out1fmt(" is%s %s\n", - cmdp ? " a tracked alias for" : "", name); + if (cmd == TYPECMD_SMALLV) + out1fmt("%s\n", name); + else + out1fmt(" is%s %s\n", + (cmdp && cmd == TYPECMD_TYPE) ? + " a tracked alias for" : "", + name); } else { - if (access(argv[i], X_OK) == 0) - out1fmt(" is %s\n", argv[i]); + if (access(argv[i], X_OK) == 0) { + if (cmd == TYPECMD_SMALLV) + out1fmt("%s\n", argv[i]); + else + out1fmt(" is %s\n", argv[i]); + } else out1fmt(": %s\n", strerror(errno)); } break; } case CMDFUNCTION: - out1str(" is a shell function\n"); + if (cmd == TYPECMD_SMALLV) + out1fmt("%s\n", argv[i]); + else + out1str(" is a shell function\n"); break; case CMDBUILTIN: - out1str(" is a shell builtin\n"); + if (cmd == TYPECMD_SMALLV) + out1fmt("%s\n", argv[i]); + else + out1str(" is a shell builtin\n"); break; default: - out1str(": not found\n"); + if (cmd != TYPECMD_SMALLV) + out1str(": not found\n"); error |= 127; break; } } return error; } + +/* + * Locate and print what a word is... + */ + +int +typecmd(int argc, char **argv) +{ + return typecmd_impl(argc, argv, TYPECMD_TYPE); +} |