diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2013-09-17 09:50:04 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-18 09:17:13 +0200 |
commit | 56ee5d3aac2d73dbe1e699000cb83eea18278e68 (patch) | |
tree | fd1d1e1251ff657b813b9273c22efdc113a8025b | |
parent | 179ed619f428da8a86ddabe3033f0acdf5159236 (diff) | |
download | barebox-56ee5d3aac2d73dbe1e699000cb83eea18278e68.tar.gz barebox-56ee5d3aac2d73dbe1e699000cb83eea18278e68.tar.xz |
process_escape_sequence: add support to \$?
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/hush.c | 6 | ||||
-rw-r--r-- | common/parser.c | 9 | ||||
-rw-r--r-- | include/shell.h | 12 | ||||
-rw-r--r-- | lib/process_escape_sequence.c | 7 |
4 files changed, 34 insertions, 0 deletions
diff --git a/common/hush.c b/common/hush.c index a3235ba19f..bf1d9e6fd7 100644 --- a/common/hush.c +++ b/common/hush.c @@ -123,6 +123,7 @@ #include <linux/list.h> #include <binfmt.h> #include <init.h> +#include <shell.h> /*cmd_boot.c*/ extern int do_bootd(int flag, int argc, char *argv[]); /* do_bootd */ @@ -226,6 +227,11 @@ static char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */ * the first three support $?, $#, and $1 */ static unsigned int last_return_code; +int shell_get_last_return_code(void) +{ + return last_return_code; +} + /* "globals" within this file */ static uchar *ifs; static char map[256]; diff --git a/common/parser.c b/common/parser.c index 4d993dfd35..d390fb6afe 100644 --- a/common/parser.c +++ b/common/parser.c @@ -1,6 +1,15 @@ #include <common.h> #include <command.h> #include <environment.h> +#include <shell.h> + +/* + * not yet supported + */ +int shell_get_last_return_code(void) +{ + return 0; +} static int parse_line (char *line, char *argv[]) { diff --git a/include/shell.h b/include/shell.h new file mode 100644 index 0000000000..b98cac3dc5 --- /dev/null +++ b/include/shell.h @@ -0,0 +1,12 @@ +/* + * (C) Copyright 2013 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> + * + * Under GPLv2 only + */ + +#ifndef __SHELL_H__ +#define __SHELL_H__ + +int shell_get_last_return_code(void); + +#endif /* __SHELL_H__ */ diff --git a/lib/process_escape_sequence.c b/lib/process_escape_sequence.c index be77792787..47a7e5cd92 100644 --- a/lib/process_escape_sequence.c +++ b/lib/process_escape_sequence.c @@ -19,6 +19,7 @@ #include <common.h> #include <fs.h> #include <libbb.h> +#include <shell.h> int process_escape_sequence(const char *source, char *dest, int destlen) { @@ -59,6 +60,12 @@ int process_escape_sequence(const char *source, char *dest, int destlen) case 'w': i += snprintf(dest + i, destlen - i, "%s", getcwd()); break; + case '$': + if (*(source + 2) == '?') { + i += snprintf(dest + i, destlen - i, "%d", shell_get_last_return_code()); + source++; + break; + } default: dest[i++] = '\\'; dest[i++] = *(source + 1); |