* [U-Boot] [PATCH] cmd_source: introduce run_script()
@ 2012-01-10 23:04 Michael Walle
2012-01-10 23:40 ` Mike Frysinger
0 siblings, 1 reply; 5+ messages in thread
From: Michael Walle @ 2012-01-10 23:04 UTC (permalink / raw)
To: u-boot
Move actual script execution into a new function run_script(), which then
can be called from other modules.
Signed-off-by: Michael Walle <michael@walle.cc>
Cc: Wolfgang Denk <wd@denx.de>
---
common/cmd_source.c | 71 ++++++++++++++++++++++++++++----------------------
include/common.h | 1 +
2 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/common/cmd_source.c b/common/cmd_source.c
index 16a627a..4b2740b 100644
--- a/common/cmd_source.c
+++ b/common/cmd_source.c
@@ -43,6 +43,45 @@
#include <hush.h>
#endif
+/*
+ * Run a series of commands, separated by '\n'.
+ * Beware, the contents of script may be modified while it is parsed.
+ */
+int run_script(char *script)
+{
+#ifndef CONFIG_SYS_HUSH_PARSER /*?? */
+ int rcode;
+ char *line = script;
+ char *next = script;
+
+ /*
+ * break into individual lines and execute each line;
+ * terminate on error.
+ */
+ while (*next) {
+ if (*next == '\n') {
+ *next = '\0';
+ /* run only non-empty commands */
+ if (*line) {
+ debug("** exec: \"%s\"\n", line);
+ if (run_command(line, 0) < 0) {
+ rcode = 1;
+ break;
+ }
+ }
+ line = next + 1;
+ }
+ ++next;
+ }
+
+ if (rcode == 0 && *line)
+ rcode = (run_command(line, 0) >= 0);
+ return rcode;
+#else
+ return parse_string_outer(script, FLAG_PARSE_SEMICOLON);
+#endif
+}
+
int
source (ulong addr, const char *fit_uname)
{
@@ -160,38 +199,8 @@ source (ulong addr, const char *fit_uname)
memmove (cmd, (char *)data, len);
*(cmd + len) = 0;
-#ifdef CONFIG_SYS_HUSH_PARSER /*?? */
- rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON);
-#else
- {
- char *line = cmd;
- char *next = cmd;
+ rcode = run_script(cmd);
- /*
- * break into individual lines,
- * and execute each line;
- * terminate on error.
- */
- while (*next) {
- if (*next == '\n') {
- *next = '\0';
- /* run only non-empty commands */
- if (*line) {
- debug ("** exec: \"%s\"\n",
- line);
- if (run_command (line, 0) < 0) {
- rcode = 1;
- break;
- }
- }
- line = next + 1;
- }
- ++next;
- }
- if (rcode == 0 && *line)
- rcode = (run_command(line, 0) >= 0);
- }
-#endif
free (cmd);
return rcode;
}
diff --git a/include/common.h b/include/common.h
index 3df1def..dcfbed6 100644
--- a/include/common.h
+++ b/include/common.h
@@ -296,6 +296,7 @@ void board_pre_console_putc(int ch);
void flash_perror (int);
/* common/cmd_source.c */
+int run_script(char *script);
int source (ulong addr, const char *fit_uname);
extern ulong load_addr; /* Default Load Address */
--
1.7.2.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] cmd_source: introduce run_script()
2012-01-10 23:04 [U-Boot] [PATCH] cmd_source: introduce run_script() Michael Walle
@ 2012-01-10 23:40 ` Mike Frysinger
2012-01-11 17:45 ` Michael Walle
2012-01-12 21:51 ` Michael Walle
0 siblings, 2 replies; 5+ messages in thread
From: Mike Frysinger @ 2012-01-10 23:40 UTC (permalink / raw)
To: u-boot
On Tuesday 10 January 2012 18:04:19 Michael Walle wrote:
> --- a/common/cmd_source.c
> +++ b/common/cmd_source.c
>
> +/*
> + * Run a series of commands, separated by '\n'.
> + * Beware, the contents of script may be modified while it is parsed.
> + */
> +int run_script(char *script)
const
also, we already have "run_command" and "run_command2", and they're both in
common/main.c. how about naming this "source_commands" and also putting it
into common/main.c ?
although i wonder if it'd be possible to merge this into existing
run_commands2() ... do we allow newlines now in variables that get run ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120110/e15c4c09/attachment.pgp>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] cmd_source: introduce run_script()
2012-01-10 23:40 ` Mike Frysinger
@ 2012-01-11 17:45 ` Michael Walle
2012-01-12 21:51 ` Michael Walle
1 sibling, 0 replies; 5+ messages in thread
From: Michael Walle @ 2012-01-11 17:45 UTC (permalink / raw)
To: u-boot
On Wed, January 11, 2012 00:40, Mike Frysinger wrote:
> On Tuesday 10 January 2012 18:04:19 Michael Walle wrote:
>> --- a/common/cmd_source.c
>> +++ b/common/cmd_source.c
>>
>> +/*
>> + * Run a series of commands, separated by '\n'.
>> + * Beware, the contents of script may be modified while it is parsed.
>> + */
>> +int run_script(char *script)
>
> const
const? const char *script? script is modified while parsing, see comment
above. I wanted to avoid copying.
> also, we already have "run_command" and "run_command2", and they're both
> in
> common/main.c. how about naming this "source_commands" and also putting
> it
> into common/main.c ?
i'm fine with that
--
michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] cmd_source: introduce run_script()
2012-01-10 23:40 ` Mike Frysinger
2012-01-11 17:45 ` Michael Walle
@ 2012-01-12 21:51 ` Michael Walle
2012-01-12 22:54 ` Michael Walle
1 sibling, 1 reply; 5+ messages in thread
From: Michael Walle @ 2012-01-12 21:51 UTC (permalink / raw)
To: u-boot
Am Mittwoch 11 Januar 2012, 00:40:04 schrieb Mike Frysinger:
> although i wonder if it'd be possible to merge this into existing
> run_commands2() ... do we allow newlines now in variables that get run ?
mh if the hush parser is enabled this seems to be true. eg. source() and
run_commands2() use the same parse_string_outer().
btw. shouldnt set source() FLAG_EXIT_FROM_LOOP, too? i'm trying to unify
things and just noticed this.
--
michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] cmd_source: introduce run_script()
2012-01-12 21:51 ` Michael Walle
@ 2012-01-12 22:54 ` Michael Walle
0 siblings, 0 replies; 5+ messages in thread
From: Michael Walle @ 2012-01-12 22:54 UTC (permalink / raw)
To: u-boot
Am Donnerstag 12 Januar 2012, 22:51:48 schrieb Michael
Walle:
> Am Mittwoch 11 Januar 2012, 00:40:04 schrieb Mike
Frysinger:
> > although i wonder if it'd be possible to merge this
into existing
> > run_commands2() ... do we allow newlines now in
variables that get run ?
>
> mh if the hush parser is enabled this seems to be true.
eg. source() and
> run_commands2() use the same parse_string_outer().
Actually parse_string_outer() terminates on '\n'. So i
think the current version of source() is broken.
--
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-12 22:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-10 23:04 [U-Boot] [PATCH] cmd_source: introduce run_script() Michael Walle
2012-01-10 23:40 ` Mike Frysinger
2012-01-11 17:45 ` Michael Walle
2012-01-12 21:51 ` Michael Walle
2012-01-12 22:54 ` Michael Walle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.