[Swift-commit] r7549 - in SwiftApps/swift-galaxy/swift: . test_exec
ketan at ci.uchicago.edu
ketan at ci.uchicago.edu
Mon Feb 3 12:40:28 CST 2014
Author: ketan
Date: 2014-02-03 12:40:28 -0600 (Mon, 03 Feb 2014)
New Revision: 7549
Added:
SwiftApps/swift-galaxy/swift/test_exec/bashtoswiftarrays.sh
Modified:
SwiftApps/swift-galaxy/swift/swiftforeachrange.sh
Log:
variable number of arguments
Modified: SwiftApps/swift-galaxy/swift/swiftforeachrange.sh
===================================================================
--- SwiftApps/swift-galaxy/swift/swiftforeachrange.sh 2014-02-03 16:24:31 UTC (rev 7548)
+++ SwiftApps/swift-galaxy/swift/swiftforeachrange.sh 2014-02-03 18:40:28 UTC (rev 7549)
@@ -23,19 +23,29 @@
logfile=$1
shift
+a=()
while [ $# -gt 0 ] ; do
- a="$a"" $1"
- shift
+ a+=("\"$1\"")
+ shift
done
+#workout the array only if user adds args else make it blank
+if [ ${#a[@]} -gt 0 ] ; then
+ tmp=$(printf -- '%s,' "${a[@]}")
+ arrayexpr='string args[]=['$(echo $tmp | sed s/,$//)'];';
+else
+ arrayexpr='string args[];'
+fi
+
#Build Swift source code
cat << EOF > /tmp/script.swift
type file;
-app (file _out, file _err) anapp(file _exec, int _i, string _args){
+app (file _out, file _err) anapp(file _exec, int _i, string _args[]){
sh @_exec _i _args stdout=@_out stderr=@_err;
}
-string args="$a";
+$arrayexpr
+
file exec<"$executable">;
foreach i in [$rstart:$rend:$stepsize]{
file out <single_file_mapper; file=@strcat("$outloc", "/", i, ".out")>;
Added: SwiftApps/swift-galaxy/swift/test_exec/bashtoswiftarrays.sh
===================================================================
--- SwiftApps/swift-galaxy/swift/test_exec/bashtoswiftarrays.sh (rev 0)
+++ SwiftApps/swift-galaxy/swift/test_exec/bashtoswiftarrays.sh 2014-02-03 18:40:28 UTC (rev 7549)
@@ -0,0 +1,29 @@
+a=()
+while [ $# -gt 0 ] ; do
+ a+=("\"$1\"")
+ shift
+done
+
+tmp=$(printf -- '%s,' "${a[@]}")
+
+expr='['$(echo $tmp | sed s/,$//)']'
+
+echo $expr
+
+#Build Swift source code
+#cat << EOF > /tmp/script.swift
+#type file;
+#
+#app (file _out, file _err) anapp(file _exec, int _i, string _args){
+# sh @_exec _i _args stdout=@_out stderr=@_err;
+#}
+##string args="$a";
+#string args[] = [];
+#file exec<"/bin/cat">;
+#foreach i in [0:2:1]{
+# file out <single_file_mapper; file=@strcat("/tmp/swift-sandbox", "/", i, ".out")>;
+# file err <single_file_mapper; file=@strcat("/tmp/swift-sandbox", "/", i, ".err")>;
+# (out,err) = anapp(exec, i, args);
+#}
+#EOF
+
More information about the Swift-commit
mailing list