hush: optimize type builtin a bit
function old new delta builtin_type 130 125 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b9f2bb36ea
commit
dd6b211921
21
shell/hush.c
21
shell/hush.c
@ -6766,32 +6766,31 @@ static int builtin_trap(char **argv)
|
|||||||
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/type.html */
|
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/type.html */
|
||||||
static int builtin_type(char **argv)
|
static int builtin_type(char **argv)
|
||||||
{
|
{
|
||||||
int i, ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
for (i = 1; argv[i]; ++i) {
|
while (*++argv) {
|
||||||
void *path;
|
char *path;
|
||||||
const void *find_ret;
|
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
||||||
type = path = NULL;
|
type = path = NULL;
|
||||||
|
|
||||||
if (0) {} /* make conditional compile easier below */
|
if (0) {} /* make conditional compile easier below */
|
||||||
/*else if ((find_ret = find_alias(argv[i])))
|
/*else if (find_alias(*argv))
|
||||||
type = "an alias";*/
|
type = "an alias";*/
|
||||||
#if ENABLE_HUSH_FUNCTIONS
|
#if ENABLE_HUSH_FUNCTIONS
|
||||||
else if ((find_ret = find_function(argv[i])))
|
else if (find_function(*argv))
|
||||||
type = "a function";
|
type = "a function";
|
||||||
#endif
|
#endif
|
||||||
else if ((find_ret = find_builtin(argv[i])))
|
else if (find_builtin(*argv))
|
||||||
type = "a shell builtin";
|
type = "a shell builtin";
|
||||||
else if ((find_ret = path = find_in_path(argv[i])))
|
else if ((path = find_in_path(*argv)) != NULL)
|
||||||
type = find_ret;
|
type = path;
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
bb_error_msg("type: %s: not found", argv[i]);
|
bb_error_msg("type: %s: not found", *argv);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
} else
|
} else
|
||||||
printf("%s is %s\n", argv[i], type);
|
printf("%s is %s\n", *argv, type);
|
||||||
|
|
||||||
if (path)
|
if (path)
|
||||||
free(path);
|
free(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user