[Swift-commit] r7052 - in SwiftApps/tryswift: . scripts

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Tue Sep 10 14:41:45 CDT 2013


Author: davidk
Date: 2013-09-10 14:41:45 -0500 (Tue, 10 Sep 2013)
New Revision: 7052

Added:
   SwiftApps/tryswift/clean.sh
   SwiftApps/tryswift/index.html
   SwiftApps/tryswift/scripts/
   SwiftApps/tryswift/scripts/arrays.swift
   SwiftApps/tryswift/scripts/capitalise.swift
   SwiftApps/tryswift/scripts/capitalise_anonymous.swift
   SwiftApps/tryswift/scripts/default.swift
   SwiftApps/tryswift/scripts/fixed_array_mapper.swift
   SwiftApps/tryswift/scripts/foreach.swift
   SwiftApps/tryswift/scripts/hello.swift
   SwiftApps/tryswift/scripts/if.swift
   SwiftApps/tryswift/scripts/manyparam.swift
   SwiftApps/tryswift/scripts/my_first_mapper.swift
   SwiftApps/tryswift/scripts/parameter.swift
   SwiftApps/tryswift/scripts/regexp_mapper.swift
   SwiftApps/tryswift/scripts/restart.swift
   SwiftApps/tryswift/scripts/sequential_iteration.swift
   SwiftApps/tryswift/scripts/sleep.swift
   SwiftApps/tryswift/scripts/types.swift
   SwiftApps/tryswift/sites.xml
   SwiftApps/tryswift/tc.data
   SwiftApps/tryswift/test.php
   SwiftApps/tryswift/tryswift-php.css
   SwiftApps/tryswift/tryswift.css
   SwiftApps/tryswift/tryswift.php
Log:
Tryswift scripts


Added: SwiftApps/tryswift/clean.sh
===================================================================
--- SwiftApps/tryswift/clean.sh	                        (rev 0)
+++ SwiftApps/tryswift/clean.sh	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,3 @@
+#!/bin/bash -x
+
+rm -rf tmp.*


Property changes on: SwiftApps/tryswift/clean.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/tryswift/index.html
===================================================================
--- SwiftApps/tryswift/index.html	                        (rev 0)
+++ SwiftApps/tryswift/index.html	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,86 @@
+<html>
+   <link rel="stylesheet" type="text/css" href="tryswift.css">
+   <head>
+      <title>Try Swift</title>
+   </head>
+
+   <body>
+      <div id="header">
+      <hr>
+      Try Swift
+      <hr>
+      </div>
+
+      <div id="wrap">
+      <div id="wrapHeader">
+         <br>
+         Enter your Swift code below
+      </div>
+      <form name="sourceForm" action="http://54.212.60.65:8080/tryswift.php" method="POST">
+         <div id="textAreaDiv">
+            <textarea id="source" name="source" spellcheck="false" wrap="physical"></textarea><br>
+         </div>
+         <div id="progsDiv">
+         <div id="progsDivText">
+            Example Programs<br><br>
+            <ul>
+            <li><input type="radio" name="existingApplications" value="scripts/hello.swift" onclick="addtext()">hello.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/manyparam.swift" onclick="addtext()">manyparam.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/capitalise.swift" onclick="addtext()">capitalise.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/default.swift" onclick="addtext()">default.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/if.swift" onclick="addtext()">if.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/manyparam.swift" onclick="addtext()">manyparam.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/parameter.swift" onclick="addtext()">parameter.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/sleep.swift" onclick="addtext()">sleep.swift</li>
+            <li><input type="radio" name="existingApplications" value="scripts/types.swift" onclick="addtext()">types.swift</li>
+            </ul>
+         </div>
+         </div>
+         <div id="submitButton">
+            <input type="submit" name="submit" value="Submit" />
+         </div>
+         <div id="appsDiv">
+         <div id="appsDivText">
+            Available Applications<br><br>
+            <ul>
+            <li>echo</li>
+            <li>cat</li>
+            <li>ls</li>
+            <li>grep</li>
+            <li>sort</li>
+            <li>paste</li>
+            <li>cp</li>
+            <li>touch</li>
+            <li>wc</li>
+            <li>sleep</li>
+            </ul>
+         </div>
+         </div>
+      </form>
+      </div>
+
+      <script type="text/javascript">
+         
+         function addtext() {
+            var filePath = "http://swiftlang.org/tryswift/" + getRadioValue();
+            var xmlhttp = new XMLHttpRequest();
+            xmlhttp.open("GET", filePath, false);
+            xmlhttp.send(null);
+            var fileContent = xmlhttp.responseText;
+            document.getElementById('source').value = fileContent;
+         }
+         
+         function getRadioValue() {
+            var l = sourceForm.existingApplications.length;
+            var radio_value;
+            for(var i=0; i<l; i++) {
+               if(sourceForm.existingApplications[i].checked) 
+                  radio_value = sourceForm.existingApplications[i].value;
+            }
+            return radio_value;
+         }
+
+      </script>
+      </div>
+   </body>
+</html>

Added: SwiftApps/tryswift/scripts/arrays.swift
===================================================================
--- SwiftApps/tryswift/scripts/arrays.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/arrays.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,12 @@
+type messagefile; 
+
+app (messagefile t) greeting (string s[]) {   
+     echo s[0] s[1] s[2] stdout=@filename(t);
+}
+
+messagefile outfile <"arrays.txt">;
+
+string words[] = ["how","are","you"];
+
+outfile = greeting(words);
+

Added: SwiftApps/tryswift/scripts/capitalise.swift
===================================================================
--- SwiftApps/tryswift/scripts/capitalise.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/capitalise.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,14 @@
+type messagefile;
+
+app (messagefile t) greeting (string s) {   
+    echo s stdout=@filename(t);
+}
+
+app (messagefile o) capitalise(messagefile i) {   
+    tr "[a-z]" "[A-Z]" stdin=@filename(i) stdout=@filename(o);
+}
+
+messagefile hellofile <"capitalise.1.txt">;
+messagefile final <"capitalise.2.txt">;
+hellofile = greeting("hello from Swift");
+final = capitalise(hellofile);

Added: SwiftApps/tryswift/scripts/capitalise_anonymous.swift
===================================================================
--- SwiftApps/tryswift/scripts/capitalise_anonymous.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/capitalise_anonymous.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,14 @@
+type messagefile;
+
+app (messagefile t) greeting (string s) {   
+    echo s stdout=@filename(t);
+}
+
+app (messagefile o) capitalise(messagefile i) {   
+    tr "[a-z]" "[A-Z]" stdin=@filename(i) stdout=@filename(o);
+}
+
+messagefile hellofile;
+messagefile final <"capitalise_anonymous.txt">;
+hellofile = greeting("hello from Swift");
+final = capitalise(hellofile);

Added: SwiftApps/tryswift/scripts/default.swift
===================================================================
--- SwiftApps/tryswift/scripts/default.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/default.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,15 @@
+type file;
+
+// s has a default value
+app (file t) echo (string s="hello world") { 
+        echo s stdout=@filename(t);		
+}
+
+file hw1<"default.1.txt">;
+file hw2<"default.2.txt">;
+
+// procedure call using the default value
+hw1 = echo();		
+
+// using a different value
+hw2 = echo(s="hello again"); 

Added: SwiftApps/tryswift/scripts/fixed_array_mapper.swift
===================================================================
--- SwiftApps/tryswift/scripts/fixed_array_mapper.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/fixed_array_mapper.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,16 @@
+type messagefile; 
+type countfile; 
+
+app (countfile t) countwords (messagefile f) {   
+   wc "-w" @filename(f) stdout=@filename(t);
+}
+
+string inputNames = "fixed_array_mapper.1.txt fixed_array_mapper.2.txt fixed_array_mapper.3.txt";
+string outputNames = "fixed_array_mapper.1.count fixed_array_mapper.2.count fixed_array_mapper.3.count";
+
+messagefile inputfiles[] <fixed_array_mapper;files=inputNames>;
+countfile outputfiles[] <fixed_array_mapper;files=outputNames>;
+
+outputfiles[0] = countwords(inputfiles[0]);
+outputfiles[1] = countwords(inputfiles[1]);
+outputfiles[2] = countwords(inputfiles[2]);

Added: SwiftApps/tryswift/scripts/foreach.swift
===================================================================
--- SwiftApps/tryswift/scripts/foreach.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/foreach.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,18 @@
+type messagefile; 
+type countfile; 
+
+app (countfile t) countwords (messagefile f) {   
+     wc "-w" @filename(f) stdout=@filename(t);
+}
+
+string inputNames = "foreach.1.txt foreach.2.txt foreach.3.txt";
+
+messagefile inputfiles[] <fixed_array_mapper;files=inputNames>;
+
+foreach f in inputfiles {
+  countfile c<regexp_mapper;
+	    source=@f,
+            match="(.*)txt",
+            transform="\\1count">;
+  c = countwords(f);
+}

Added: SwiftApps/tryswift/scripts/hello.swift
===================================================================
--- SwiftApps/tryswift/scripts/hello.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/hello.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,10 @@
+type messagefile;
+
+app (messagefile t) greeting() { 
+    echo "Hello, world!" stdout=@filename(t);
+}
+
+messagefile outfile <"hello.txt">;
+
+outfile = greeting();
+

Added: SwiftApps/tryswift/scripts/if.swift
===================================================================
--- SwiftApps/tryswift/scripts/if.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/if.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,16 @@
+type messagefile;
+
+app (messagefile t) greeting (string s) {
+   echo s stdout=@filename(t);
+}
+
+messagefile outfile <"if.txt">;
+
+boolean morning = true;
+
+if(morning) {
+  outfile = greeting("good morning");
+} else {
+  outfile = greeting("good afternoon");
+}
+

Added: SwiftApps/tryswift/scripts/manyparam.swift
===================================================================
--- SwiftApps/tryswift/scripts/manyparam.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/manyparam.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,13 @@
+type messagefile;
+
+app (messagefile t) greeting (string s) {   
+    echo s stdout=@filename(t);
+}
+
+messagefile english <"manyparam.english.txt">;
+messagefile french <"manyparam.french.txt">;
+messagefile japanese <"manyparam.japanese.txt">;
+
+english = greeting("hello");
+french = greeting("bonjour");
+japanese = greeting("konnichiwa");

Added: SwiftApps/tryswift/scripts/my_first_mapper.swift
===================================================================
--- SwiftApps/tryswift/scripts/my_first_mapper.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/my_first_mapper.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,9 @@
+type messagefile;
+
+app (messagefile t) greeting() {
+        echo "hello" stdout=@filename(t);
+}
+
+messagefile outfile <my_first_mapper>;
+
+outfile = greeting();

Added: SwiftApps/tryswift/scripts/parameter.swift
===================================================================
--- SwiftApps/tryswift/scripts/parameter.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/parameter.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,8 @@
+type messagefile;
+
+app (messagefile t) greeting (string s) {   
+    echo s stdout=@filename(t);
+}
+
+messagefile outfile <"parameter.hello.txt">;
+outfile = greeting("hello world");

Added: SwiftApps/tryswift/scripts/regexp_mapper.swift
===================================================================
--- SwiftApps/tryswift/scripts/regexp_mapper.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/regexp_mapper.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,16 @@
+type messagefile; 
+type countfile; 
+
+app (countfile t) countwords (messagefile f) {   
+	wc "-w" @filename(f) stdout=@filename(t);
+}
+
+messagefile inputfile <"regexp_mapper.words.txt">;
+
+countfile c <regexp_mapper;
+	    source=@inputfile,
+            match="(.*)txt",
+            transform="\\1count">;
+
+c = countwords(inputfile);
+

Added: SwiftApps/tryswift/scripts/restart.swift
===================================================================
--- SwiftApps/tryswift/scripts/restart.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/restart.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,24 @@
+type file;  
+  
+app (file f) touch() {  
+    touch @f;  
+}  
+  
+app (file f) processL(file inp) {  
+    echo "processL" stdout=@f;  
+}  
+  
+app (file f) processR(file inp) {  
+    broken "process" stdout=@f;  
+}  
+  
+app (file f) join(file left, file right) {  
+    echo "join" @left @right stdout=@f;  
+}  
+  
+file f = touch();  
+  
+file g = processL(f);  
+file h = processR(f);  
+  
+file i = join(g,h);  

Added: SwiftApps/tryswift/scripts/sequential_iteration.swift
===================================================================
--- SwiftApps/tryswift/scripts/sequential_iteration.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/sequential_iteration.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,18 @@
+type counterfile;  
+  
+app (counterfile t) echo(string m) {   
+    echo m stdout=@filename(t);  
+}  
+  
+app (counterfile t) countstep(counterfile i) {  
+    wcl @filename(i) @filename(t);  
+}  
+  
+counterfile a[]  <simple_mapper;prefix="sequential_iteration.foldout">;  
+  
+a[0] = echo("793578934574893");  
+  
+iterate v {  
+  a[v+1] = countstep(a[v]);  
+ trace("extract int value ", at extractint(a[v+1]));  
+} until (@extractint(a[v+1]) <= 1);  

Added: SwiftApps/tryswift/scripts/sleep.swift
===================================================================
--- SwiftApps/tryswift/scripts/sleep.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/sleep.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,9 @@
+type file;
+
+app sleep (int s) {   
+     sleep s;
+}
+
+foreach f in [1:5] {
+   sleep(30);
+}

Added: SwiftApps/tryswift/scripts/types.swift
===================================================================
--- SwiftApps/tryswift/scripts/types.swift	                        (rev 0)
+++ SwiftApps/tryswift/scripts/types.swift	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,20 @@
+type messagefile;
+
+type details {
+    string name;
+    int pies;
+}
+
+app (messagefile t) greeting (details d) {   
+    echo "Hello. Your name is" d.name "and you have eaten" d.pies "pies." stdout=@filename(t);
+}
+
+details person;
+
+person.name = "John";
+person.pies = 3;
+
+messagefile outfile <"types.pies.txt">;
+
+outfile = greeting(person);
+

Added: SwiftApps/tryswift/sites.xml
===================================================================
--- SwiftApps/tryswift/sites.xml	                        (rev 0)
+++ SwiftApps/tryswift/sites.xml	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,11 @@
+<config>
+  <pool handle="local">
+    <filesystem provider="local" />
+    <execution provider="coaster" jobmanager="local:local"/>
+    <profile namespace="globus"  key="jobthrottle">0.079</profile>
+    <profile namespace="karajan"  key="initialScore">10000</profile>
+    <profile namespace="globus"   key="maxTime">1000</profile>
+    <profile namespace="globus"   key="nodeGranularity">1</profile>
+    <workdirectory>/home/tryswift/work</workdirectory>
+  </pool>
+</config>

Added: SwiftApps/tryswift/tc.data
===================================================================
--- SwiftApps/tryswift/tc.data	                        (rev 0)
+++ SwiftApps/tryswift/tc.data	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,7 @@
+local echo /bin/echo
+local cat /bin/cat
+local grep /bin/grep
+local sort /bin/sort
+local paste /usr/bin/paste
+local wc /usr/bin/wc
+local sleep /bin/sleep

Added: SwiftApps/tryswift/test.php
===================================================================
--- SwiftApps/tryswift/test.php	                        (rev 0)
+++ SwiftApps/tryswift/test.php	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,23 @@
+<?php 
+
+$cmd = "ping -c 100 127.0.0.1";
+
+$descriptorspec = array(
+   0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
+   1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
+   2 => array("pipe", "w")    // stderr is a pipe that the child will write to
+);
+
+flush();
+
+$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
+echo "<pre>";
+if (is_resource($process)) {
+    while ($s = fgets($pipes[1])) {
+        print $s;
+        flush();
+    }
+}
+echo "</pre>";
+?>
+

Added: SwiftApps/tryswift/tryswift-php.css
===================================================================
--- SwiftApps/tryswift/tryswift-php.css	                        (rev 0)
+++ SwiftApps/tryswift/tryswift-php.css	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,64 @@
+html,body 
+{
+   margin:0;
+   padding:0;
+   width: 900px;
+   height: 600px;
+   margin-left: auto;
+   margin-right: auto;
+}
+
+a {
+text-decoration: none;
+}
+
+table { 
+border: 0; 
+border-bottom: 1px solid black;
+border-left: 1px solid black;
+border-right: 1px solid black;
+background-color:#f6f6f6
+font-family: monospace;
+width: 900px;
+}
+
+#style1 td {
+border-left: 1px solid black;
+border-right: 1px solid black;
+border-top: 0;
+border-bottom: 0;
+background-color:#f6f6f6
+padding-left: 0px;
+padding-right: 0px;
+padding-top: 2px;
+padding-bottom: 2px;
+}
+
+#style2 td {
+border-top: 0;
+border-bottom: 0;
+border-left: 1px solid black;
+background-color:#f6f6f6
+padding-left: 10px;
+padding-right: 0;
+padding-top: 0px;
+padding-bottom: 0px;
+}
+
+#header {
+font-family:courier-new,monospace;
+font-size:150%;
+color:#2c1f8e;
+vertical-align:sub;
+}
+
+caption {
+background:#e3e3e3;
+border-right: 1px solid black;
+border-left: 1px solid black;
+border-top: 1px solid black;
+border-bottom: 1px solid black;
+margin-top: 10px;
+padding: 2px;
+}
+

Added: SwiftApps/tryswift/tryswift.css
===================================================================
--- SwiftApps/tryswift/tryswift.css	                        (rev 0)
+++ SwiftApps/tryswift/tryswift.css	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,110 @@
+html,body 
+{
+   margin:0;
+   padding:0;
+   width: 900px;
+   height: 600px;
+   margin-left: auto;
+   margin-right: auto;
+}
+
+#header {
+font-family:courier-new,monospace;
+font-size:150%;
+color:#2c1f8e;
+vertical-align:sub;
+}
+
+#wrap {
+position: relative;
+width: 900px;
+height: 600px;
+border: 1px;
+border-style: solid;
+}
+
+#textAreaDiv {
+position: absolute;
+left: 200px;
+right: 200px;
+top: 50px;
+bottom: 50px;
+height: 500px;
+width: 500px;
+}
+
+#wrapHeader {
+position:absolute;
+top: 0px;
+left: 0px;
+width: 900px;
+height: 50px;
+background:#f6f6f6;
+text-align: center;
+}
+
+#progsDiv {
+position: absolute;
+left: 0px;
+top: 50px;
+background:#f6f6f6;
+height: 550px;
+width: 200px;
+}
+
+#progsDivText {
+margin-left:10px;
+margin-right:10px;
+background:#f6f6f6;
+}
+
+#appsDiv {
+position: absolute;
+right: 0px;
+top: 50px;
+background:#f6f6f6;
+height: 550px;
+width: 200px;
+}
+
+#appsDivText {
+margin-left:10px;
+margin-right:10px;
+background:#f6f6f6;
+}
+
+#submitButton {
+position: absolute;
+right: 200px;
+left: 200px;
+bottom: 0px;
+background:#f6f6f6;
+height: 50px;
+width: 500px;
+}
+
+textarea {
+border-bottom:1px solid black;
+border-top:1px solid black;
+border-left:1px solid black;
+border-right:1px solid black;
+border-style: solid;
+border-width: thin;
+padding: 0;
+height: 500px;
+width: 500px;
+}
+
+ul {
+list-style-type:none;
+margin-top: 0;
+margin-left: 0;
+padding-left: 5px;
+}
+
+li {
+margin-left: 0;
+padding-left: 5px; 
+padding-bottom: 10px;
+text-align: left;
+}

Added: SwiftApps/tryswift/tryswift.php
===================================================================
--- SwiftApps/tryswift/tryswift.php	                        (rev 0)
+++ SwiftApps/tryswift/tryswift.php	2013-09-10 19:41:45 UTC (rev 7052)
@@ -0,0 +1,104 @@
+<link rel="stylesheet" type="text/css" href="tryswift-php.css">
+<html><head><title>Try Swift Results</title></head>
+<body>
+<div id=\"header\"><hr>Try Swift</hr></div>
+<table cellspacing="0" title="Swift Source Code">
+
+<?PHP
+
+function copy_file($src, $dst) {
+   if(!copy($src, $dst)) {
+      die("Failed to copy $src to $dst\n");
+   }
+}
+
+$source = $_POST['source'];
+$web_directory = "/home/tryswift/tryswift";
+$url = "http://54.212.60.65:8080";
+$cmd = "PATH=/usr/bin:/bin:$PATH /home/tryswift/swift-0.94.1-RC2/bin/swift -sites.file sites.xml -tc.file tc.data script.swift";
+
+# Create directory structure
+$unique = uniqid();
+$dirname = $web_directory . "/" . $unique;
+umask(0);
+if (!mkdir($dirname, 0755)) { die("Failed to create folder $dirname"); }
+if (!chdir($dirname))       { die("Unable to chdir to $dirname"); }
+
+# Copy and create Swift files
+copy_file("$web_directory/sites.xml", "$dirname/sites.xml");
+copy_file("$web_directory/tc.data", "$dirname/tc.data");
+$script = $dirname . "/script.swift";
+
+if(!file_put_contents($script, $source)) {
+   die("Unable to write swift script");
+}
+
+ob_implicit_flush(true);
+
+$descriptorspec = array(
+   0 => array("pipe", "r"),   // stdin is a pipe that the child will read from
+   1 => array("pipe", "w"),   // stdout is a pipe that the child will write to
+   2 => array("file", "$dirname/err.txt", "a")    // stderr is a pipe that the child will write to
+);
+
+echo "<pre>";
+print "<table cellspacing=\"0\" title=\"Swift Results\">\n";
+print "<caption>Swift Source Code [<a href=\"$url/$unique/script.swift\" style='text-decoration: none;'>Download</a>]</caption>\n";
+
+$count=0;
+foreach(explode("\n", $_POST['source']) as $line) {
+        print "<tr style=\"background-color:#f6f6f6;\">" .
+              "<td style=\"text-align: center; width: 25px\">" . ++$count . "</td>" .
+              "<td style=\"text-align: left; border-left: 1px solid black; padding-left: 10px;\">$line&nbsp</td></tr>\n";
+}
+print "</table>\n";
+print "<table cellspacing=\"0\" title=\"Swift Results\">\n";
+print "<caption>Swift Execution</caption>\n";
+
+# Run Swift
+$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
+if (is_resource($process)) {
+    while ($s = fgets($pipes[1])) {
+        print "<tr style=\"background-color:#f6f6f6;\">" .
+              "<td style=\"text-align: left; border-left: 0px solid black; padding-left: 10px;\">$s&nbsp</td></tr>\n";
+        flush(); 
+    }   
+}
+
+echo "</table></pre>";
+proc_close($process);
+
+# List output files
+$filehtml = "";
+$print_files=0;
+
+if ($handle = opendir("$web_directory/$unique")) {
+    while (false !== ($entry = readdir($handle))) {
+        if ( $entry != "." && 
+             $entry != ".." &&
+             $entry != "err.txt" &&
+             $entry != "tc.data" &&
+             $entry != "sites.xml" &&
+             $entry != "script.swift" &&
+             substr($entry, -2) != ".d" &&
+             substr($entry, -4) != ".kml" &&
+             substr($entry, -7) != ".swiftx" &&
+             substr($entry, -4) != ".log"
+        ) {
+           if($print_files == 0) { $print_files=1; }
+           $filehtml .= "<tr style=\"background-color:#f6f6f6;\">" .
+                 "<td style=\"text-align: left; border-left: 0px solid black; padding-left: 10px;\">" .
+                 "<a href=\"$url/$unique/$entry\">$entry</a>&nbsp</td></tr>\n";
+        }
+    }
+    closedir($handle);
+}
+
+if($print_files) {
+   print "<table cellspacing=\"0\" title=\"List of Files\">\n" .
+         "<caption>List of Files</caption>\n" . 
+         $filehtml .
+         "</table>\n";
+}
+
+?>


Property changes on: SwiftApps/tryswift/tryswift.php
___________________________________________________________________
Added: svn:executable
   + *




More information about the Swift-commit mailing list