Skip to contentSkip to conversation

process_escape_sequence: add support to \$?

PATCH Applied Jean-Christophe PLAGNIOL-VILLARD 2 participants 2 messages Sep 17, 2013 – Sep 18, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 process_escape_sequence: add support to \$?

---
 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
common/hush.c +6 -0
index a3235ba..bf1d9e6 100644
@@ -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];
common/parser.c +9 -0
index 4d993df..d390fb6 100644
@@ -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[])
 {
include/shell.h new file +12 -0
new file mode 100644
index 0000000..b98cac3
@@ -0,0 +1,12 @@
+/*
+ * (C) Copyright 2013 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ */
+
+#ifndef __SHELL_H__
+#define __SHELL_H__
+
+int shell_get_last_return_code(void);
+
+#endif /* __SHELL_H__ */
lib/process_escape_sequence.c +7 -0
index be77792..47a7e5c 100644
@@ -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);
Signature · 7 lines
1.8.4.rc1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
---
 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

Applied, thanks

Sascha

Quoted 97 lines
common/hush.c +6 -0
index a3235ba..bf1d9e6 100644
@@ -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];
common/parser.c +9 -0
index 4d993df..d390fb6 100644
@@ -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[])
 {
include/shell.h new file +12 -0
new file mode 100644
index 0000000..b98cac3
@@ -0,0 +1,12 @@
+/*
+ * (C) Copyright 2013 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ */
+
+#ifndef __SHELL_H__
+#define __SHELL_H__
+
+int shell_get_last_return_code(void);
+
+#endif /* __SHELL_H__ */
lib/process_escape_sequence.c +7 -0
index be77792..47a7e5c 100644
@@ -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);
Signature · 7 lines
1.8.4.rc1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox