Skip to contentSkip to conversation

main: unify command parsing functions

PATCH Superseded Michael Walle 2 participants 3 messages Jan 20, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 main: unify command parsing functions

Introduce source_commands() which incorporates run_command2() and parts of source().

All command script are now treated the same, that is newlines are accepted within a command script and variable.

Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>

---
changes v2:
- unconditionally include malloc.h, fixes compiler warning

 common/cmd_pxe.c    |    2 +-
 common/cmd_source.c |   32 +-----------------------------
 common/main.c       |   54 +++++++++++++++++++++++++++++++++-----------------
 include/common.h    |    4 +--
 4 files changed, 38 insertions(+), 54 deletions(-)
common/cmd_pxe.c +1 -1
index 7c0cb66..347fde1 100644
@@ -537,7 +537,7 @@ static int label_localboot(struct pxe_label *label)
 
 	printf("running: %s\n", dupcmd);
 
-	ret = run_command2(dupcmd, 0);
+	ret = source_commands(dupcmd, 0);
 
 	free(dupcmd);
 
common/cmd_source.c +1 -31
index 16a627a..33242df 100644
@@ -160,38 +160,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 = source_commands(cmd, 0);
 
-		/*
-		 * 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;
 }
common/main.c +35 -19

98 lines not on this page · raw message

include/common.h +1 -3
index 3df1def..c2e7813 100644
@@ -261,9 +261,7 @@ int	print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
 /* common/main.c */
 void	main_loop	(void);
 int	run_command	(const char *cmd, int flag);
-#ifdef CONFIG_CMD_PXE
-int run_command2(const char *cmd, int flag);
-#endif
+int source_commands(const char *cmd, int flag);
 int	readline	(const char *const prompt);
 int	readline_into_buffer	(const char *const prompt, char * buffer);
 int	parse_line (char *, char *[]);
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH v2 1/1 main: unify command parsing functions

Am Freitag 20 Januar 2012, 23:46:51 schrieb Michael Walle:

Quoted 6 lines

Introduce source_commands() which incorporates run_command2() and parts of source().

All command script are now treated the same, that is newlines are accepted within a command script and variable.

Quoted 6 lines
Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>

---
changes v2:
- unconditionally include malloc.h, fixes compiler warning

Actually, this patch is v3. Sorry.

Signature · 1 line
Michael
#2 lore raw

PATCH v2 1/1 main: unify command parsing functions

Hi Michael,

Quoted 7 lines · Michael Walle

Am Freitag 20 Januar 2012, 23:46:51 schrieb Michael Walle:

Quoted 6 lines

Introduce source_commands() which incorporates run_command2() and parts of source().

All command script are now treated the same, that is newlines are accepted within a command script and variable.

Quoted 8 lines
Quoted 6 lines
Cc Wolfgang Denk <[email protected]>
Cc Mike Frysinger <[email protected]>

---
changes v2:
?- unconditionally include malloc.h, fixes compiler warning

Actually, this patch is v3. Sorry.

This series seems to touch similar things my command execution refactor starting here:

http://patchwork.ozlabs.org/patch/136069/

If nothing else, that series looks like it would simplify your patch a lot. You may have comments also since you have been in the same code.

Regards,
Simon

Quoted 7 lines

--
Michael
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot