mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/1] process_escape_sequence: add support to \$?
Date: Tue, 17 Sep 2013 09:50:04 +0200	[thread overview]
Message-ID: <1379404204-6450-1-git-send-email-plagnioj@jcrosoft.com> (raw)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/hush.c                 |  6 ++++++
 common/parser.c               |  9 +++++++++
 include/shell.h               | 12 ++++++++++++
 lib/process_escape_sequence.c |  7 +++++++
 4 files changed, 34 insertions(+)
 create mode 100644 include/shell.h

diff --git a/common/hush.c b/common/hush.c
index a3235ba..bf1d9e6 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 4d993df..d390fb6 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 0000000..b98cac3
--- /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 be77792..47a7e5c 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);
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2013-09-17  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-17  7:50 Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-09-18  6:54 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379404204-6450-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox