diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2007-09-24 01:40:06 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2007-09-24 01:40:06 +0200 |
commit | 14b5c2a647924440444977806c72b8ee6f586e26 (patch) | |
tree | 66dbf1b77d7ed2222db20a7a13ac9a7461d16a69 /common | |
parent | d97304aef21a7f3ac5a6699e3549e30507c760a3 (diff) | |
download | barebox-14b5c2a647924440444977806c72b8ee6f586e26.tar.gz barebox-14b5c2a647924440444977806c72b8ee6f586e26.tar.xz |
- teach hush to honour PATH variable
- remove common/main.c. This is now handled in the different shells.
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 17 | ||||
-rw-r--r-- | common/Makefile | 5 | ||||
-rw-r--r-- | common/command.c | 2 | ||||
-rw-r--r-- | common/hush.c | 73 | ||||
-rw-r--r-- | common/main.c | 91 | ||||
-rw-r--r-- | common/parser.c | 31 | ||||
-rw-r--r-- | common/startup.c | 7 |
7 files changed, 93 insertions, 133 deletions
diff --git a/common/Kconfig b/common/Kconfig index 7672ebffff..18788368b7 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -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 "> " diff --git a/common/Makefile b/common/Makefile index b83c437f03..b0df09a7c9 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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 diff --git a/common/command.c b/common/command.c index 45847eb07e..de0f83b9af 100644 --- a/common/command.c +++ b/common/command.c @@ -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[]) diff --git a/common/hush.c b/common/hush.c index 0d772b0330..7301d8aa5c 100644 --- a/common/hush.c +++ b/common/hush.c @@ -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 - 1; - ctx.global_argv = argv + 1; + ctx.global_argc = argc; + ctx.global_argv = argv; - 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"; diff --git a/common/main.c b/common/main.c deleted file mode 100644 index ad13109455..0000000000 --- a/common/main.c +++ /dev/null @@ -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*/ -} diff --git a/common/parser.c b/common/parser.c index 5e6bf3cde2..d5308d90d9 100644 --- a/common/parser.c +++ b/common/parser.c @@ -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; +} + diff --git a/common/startup.c b/common/startup.c index a8f20fb103..7867bd1a50 100644 --- a/common/startup.c +++ b/common/startup.c @@ -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 */ } |