summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2014-12-06 04:38:55 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2014-12-06 04:38:55 (GMT)
commit855db0ca0f17670e9301c0789b05624b943ace67 (patch)
treee8f9b40c88d946e4c0e117ef1df2cb1b9200a699
parent7eb3cadaa8c865ab429d4cd7602962383d98dd3d (diff)
downloadagnostic-855db0ca0f17670e9301c0789b05624b943ace67.zip
agnostic-855db0ca0f17670e9301c0789b05624b943ace67.tar.gz
agnostic-855db0ca0f17670e9301c0789b05624b943ace67.tar.bz2
shell: implement 'for' loop processing
The following now works: $ ./sh_c 'for a in a b c ; do echo a=$a ; done ; echo $a' a=a a=b a=c c
-rw-r--r--src/node_modules/shell/shell_executor2.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/node_modules/shell/shell_executor2.js b/src/node_modules/shell/shell_executor2.js
index 54d93b2..f989f65 100644
--- a/src/node_modules/shell/shell_executor2.js
+++ b/src/node_modules/shell/shell_executor2.js
@@ -149,6 +149,8 @@ function Command(process_state, obj)
return CompoundSubshell(process_state,value);
case "compound_currentshell":
return CompoundCurrentshell(value);
+ case "for_clause":
+ return ForClause(process_state,value);
default:
throw "Invalid Command type '" + type + '"';
}
@@ -299,6 +301,30 @@ function AndOrList(process_state, obj)
return exit_code ;
}
+
+/* ForClause() - process a 'for' statement */
+function ForClause(process_state, obj)
+{
+ var exit_code = 0 ;
+ ob_utils.VerifyAllowedKeys(obj, ["varname","wordlist","action"]);
+
+ var varname = obj["varname"];
+ /* Process the word-list, split into separate words */
+ var wordlist = Token(process_state,true,obj["wordlist"]);
+ /* The commands to exeute each iteration */
+ var action = obj["action"];
+
+ var exit_code;
+
+ for (var w in wordlist) {
+ shell_state.variable_set(process_state,varname,wordlist[w]);
+ exit_code = Command(process_state,action);
+ }
+
+ return exit_code;
+}
+
+
/*
SimpleCommand() - Process a single execution command,
(e.g. equivalent to a single program to run, a single call to 'exec()')