ash: implement type -p, costs less than 10 bytes

(patch by Mats Erik Andersson <mats.andersson64@comhem.se>)
This commit is contained in:
Denis Vlasenko 2007-05-20 13:08:31 +00:00
parent 38ec147a18
commit 46846e25a4

View File

@ -6892,14 +6892,8 @@ findkwd(const char *s)
/* /*
* Locate and print what a word is... * Locate and print what a word is...
*/ */
#if ENABLE_ASH_CMDCMD
static int static int
describe_command(char *command, int describe_command_verbose) describe_command(char *command, int describe_command_verbose)
#else
#define describe_command_verbose 1
static int
describe_command(char *command)
#endif
{ {
struct cmdentry entry; struct cmdentry entry;
struct tblentry *cmdp; struct tblentry *cmdp;
@ -6922,13 +6916,12 @@ describe_command(char *command)
/* Then look at the aliases */ /* Then look at the aliases */
ap = lookupalias(command, 0); ap = lookupalias(command, 0);
if (ap != NULL) { if (ap != NULL) {
if (describe_command_verbose) { if (!describe_command_verbose) {
out1fmt(" is an alias for %s", ap->val);
} else {
out1str("alias "); out1str("alias ");
printalias(ap); printalias(ap);
return 0; return 0;
} }
out1fmt(" is an alias for %s", ap->val);
goto out; goto out;
} }
#endif #endif
@ -6997,15 +6990,17 @@ describe_command(char *command)
static int static int
typecmd(int argc, char **argv) typecmd(int argc, char **argv)
{ {
int i; int i = 1;
int err = 0; int err = 0;
int verbose = 1;
for (i = 1; i < argc; i++) { /* type -p ... ? (we don't bother checking for 'p') */
#if ENABLE_ASH_CMDCMD if (argv[1][0] == '-') {
err |= describe_command(argv[i], 1); i++;
#else verbose = 0;
err |= describe_command(argv[i]); }
#endif while (i < argc) {
err |= describe_command(argv[i++], verbose);
} }
return err; return err;
} }