9
0
Fork 0

- teach hush to honour PATH variable

- remove common/main.c. This is now handled in the different shells.
This commit is contained in:
Sascha Hauer 2007-09-24 01:40:06 +02:00
parent d97304aef2
commit 14b5c2a647
11 changed files with 97 additions and 141 deletions

View File

@ -10,6 +10,7 @@ config CMD_EDIT
prompt "edit"
config CMD_EXEC
depends on !SHELL_HUSH
bool
prompt "exec"
@ -231,7 +232,7 @@ config CMD_PARTITION
config CMD_TEST
bool
depends on HUSH_PARSER
depends on SHELL_HUSH
default y
prompt "test"
help

View File

@ -29,10 +29,6 @@
#include <malloc.h>
#include <xfuncs.h>
#ifdef CONFIG_HUSH_PARSER
#include <hush.h>
#endif
static int do_exec(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
int i;

View File

@ -65,18 +65,21 @@ config MAXARGS
prompt "max. Number of arguments accepted for monitor commands"
default 16
config HUSH_PARSER
bool
prompt "Use hush parser"
choice
prompt "Select your shell"
config SIMPLE_PARSER
bool
config SHELL_HUSH
bool "hush parser"
default y
depends on !HUSH_PARSER
config SHELL_SIMPLE
bool "Simple parser"
endchoice
config PROMPT_HUSH_PS2
string
depends on HUSH_PARSER
depends on SHELL_HUSH
prompt "hush PS2"
default "> "

View File

@ -1,9 +1,8 @@
obj-$(CONFIG_HUSH_PARSER) += hush.o
obj-$(CONFIG_SIMPLE_PARSER) += parser.o
obj-$(CONFIG_SHELL_HUSH) += hush.o
obj-$(CONFIG_SHELL_SIMPLE) += parser.o
obj-$(CONFIG_GREGORIAN_CALENDER) += date.o
obj-$(CONFIG_OF_FLAT_TREE) += ft_build.o
obj-y += main.o
obj-y += dlmalloc.o
obj-y += clock.o
obj-y += command.o

View File

@ -69,7 +69,7 @@ U_BOOT_CMD_START(false)
.usage = "do nothing, unsuccessfully",
U_BOOT_CMD_END
#ifdef CONFIG_HUSH_PARSER
#ifdef CONFIG_SHELL_HUSH
int
do_readline (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

View File

@ -97,6 +97,7 @@
#include <driver.h>
#include <errno.h>
#include <fs.h>
#include <libbb.h>
/*cmd_boot.c*/
extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); /* do_bootd */
@ -180,6 +181,7 @@ struct pipe {
};
static char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
/* globals, connect us to the outside world
* the first three support $?, $#, and $1 */
@ -269,6 +271,7 @@ static char **make_list_in(char **inp, char *name);
static char *insert_var_value(char *inp);
static const char *get_local_var(const char *var);
static int set_local_var(const char *s, int flg_export);
static int execute_script(const char *path, int argc, char *argv[]);
static int b_check_space(o_string *o, int len)
@ -468,6 +471,8 @@ static int run_pipe_real(struct pipe *pi)
struct child_prog *child;
cmd_tbl_t *cmdtp;
char *p;
char *path;
int ret;
# if __GNUC__
/* Avoid longjmp clobbering */
(void) &i;
@ -529,11 +534,17 @@ static int run_pipe_real(struct pipe *pi)
free(str);
return last_return_code;
}
if (strchr(child->argv[i], '/')) {
return execute_script(child->argv[i], child->argc-i,&child->argv[i]);
}
if ((path = find_execable(child->argv[i]))) {
printf("path: %s\n", path);
ret = execute_script(path, child->argc-i,&child->argv[i]);
free(path);
return ret;
}
/* Look up command in command table */
if ((cmdtp = find_cmd(child->argv[i])) == NULL) {
printf ("Unknown command '%s' - try 'help'\n", child->argv[i]);
return -1; /* give up after bad command */
} else {
if ((cmdtp = find_cmd(child->argv[i]))) {
int rcode;
#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
@ -562,6 +573,9 @@ static int run_pipe_real(struct pipe *pi)
child->argv-=i; /* XXX restore hack so free() can work right */
return rcode;
} else {
printf ("Unknown command '%s' - try 'help'\n", child->argv[i]);
return -1; /* give up after bad command */
}
}
return -1;
@ -1320,18 +1334,6 @@ static int parse_string_outer(struct p_context *ctx, const char *s, int flag)
}
}
int parse_file_outer(void)
{
int rcode;
struct in_str input;
struct p_context ctx;
setup_file_in_str(&input);
rcode = parse_stream_outer(&ctx, &input, FLAG_PARSE_SEMICOLON);
return rcode;
}
static char *insert_var_value(char *inp)
{
int res_str_len = 0;
@ -1442,21 +1444,16 @@ int run_command (const char *cmd, int flag)
return parse_string_outer(&ctx, cmd, FLAG_PARSE_SEMICOLON);
}
static int do_sh (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
static int execute_script(const char *path, int argc, char *argv[])
{
int ret;
char *script;
struct p_context ctx;
char *script;
int ret;
if (argc < 2) {
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
ctx.global_argc = argc;
ctx.global_argv = argv;
ctx.global_argc = argc - 1;
ctx.global_argv = argv + 1;
script = read_file(argv[1]);
script = read_file(path);
if (!script)
return 1;
@ -1465,9 +1462,31 @@ static int do_sh (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
env_pop_context();
free(script);
return ret;
}
int run_shell(void)
{
int rcode;
struct in_str input;
struct p_context ctx;
setup_file_in_str(&input);
rcode = parse_stream_outer(&ctx, &input, FLAG_PARSE_SEMICOLON);
return rcode;
}
static int do_sh(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
if (argc < 2) {
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
return execute_script(argv[1], argc - 1, argv + 1);
}
static __maybe_unused char cmd_sh_help[] =
"write me\n";

View File

@ -1,91 +0,0 @@
/*
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* Add to readline cmdline-editing by
* (C) Copyright 2005
* JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/* #define DEBUG */
#include <common.h>
#include <environment.h>
#include <watchdog.h>
#include <command.h>
#ifdef CONFIG_HUSH_PARSER
#include <hush.h>
#endif
extern int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
#define MAX_DELAY_STOP_STR 32
#undef DEBUG_PARSER
char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
/****************************************************************************/
void main_loop (void)
{
#ifndef CONFIG_HUSH_PARSER
static char lastcommand[CONFIG_CBSIZE] = { 0, };
int len;
int rc = 1;
int flag;
#endif
#ifdef CONFIG_AUTO_COMPLETE
install_auto_complete();
#endif
/*
* Main Loop for Monitor Command Processing
*/
#ifdef CONFIG_HUSH_PARSER
parse_file_outer();
/* This point is never reached */
for (;;);
#else
for (;;) {
len = readline (CONFIG_PROMPT, console_buffer, CONFIG_CBSIZE);
flag = 0; /* assume no special flags for now */
if (len > 0)
strcpy (lastcommand, console_buffer);
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
if (len == -1)
puts ("<INTERRUPT>\n");
else
rc = run_command (lastcommand, flag);
if (rc <= 0) {
/* invalid command or not repeatable, forget it */
lastcommand[0] = 0;
}
}
#endif /*CONFIG_HUSH_PARSER*/
}

View File

@ -289,4 +289,33 @@ int run_command (const char *cmd, int flag)
return rc;
}
/****************************************************************************/
static char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
int run_shell(void)
{
static char lastcommand[CONFIG_CBSIZE] = { 0, };
int len;
int rc = 1;
int flag;
for (;;) {
len = readline (CONFIG_PROMPT, console_buffer, CONFIG_CBSIZE);
flag = 0; /* assume no special flags for now */
if (len > 0)
strcpy (lastcommand, console_buffer);
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
if (len == -1)
puts ("<INTERRUPT>\n");
else
rc = run_command (lastcommand, flag);
if (rc <= 0) {
/* invalid command or not repeatable, forget it */
lastcommand[0] = 0;
}
}
return 0;
}

View File

@ -130,21 +130,22 @@ void start_uboot (void)
mkdir("/env");
mount("none", "devfs", "/dev");
#ifdef CONFIG_CMD_ENVIRONMENT
if (envfs_load("/dev/env0", "/env")) {
#ifdef CONFIG_DEFAULT_ENVIRONMENT
printf("using default environment\n");
envfs_load("/dev/defaultenv", "/env");
#endif
}
#endif
if (!stat("/env/init", &s)) {
printf("running /env/init\n");
run_command("exec /env/init", 0);
run_command("sh /env/init", 0);
}
/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;)
main_loop ();
run_shell();
/* NOTREACHED - no way out of command loop except booting */
}

View File

@ -168,4 +168,6 @@ void start_uboot(void);
int arch_execute(unsigned long address, int argc, char *argv[]);
int run_shell(void);
#endif /* __COMMON_H_ */

View File

@ -28,7 +28,4 @@
#define FLAG_PARSE_SEMICOLON (1 << 1) /* symbol ';' is special for parser */
#define FLAG_REPARSING (1 << 2) /* >=2nd pass */
extern int parse_string_outer(const char *, int);
extern int parse_file_outer(void);
#endif