Skip to content

Commit f17d7f8

Browse files
authored
Merge pull request #2 from JuezUN/cpp-input
Cpp input
2 parents 0d846b0 + 9b8a5c6 commit f17d7f8

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

v3/iframe-embed.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<body>
2929

3030
<div id="vizDiv"></div>
31-
31+
<button id="show-hide-input-button" onclick="toggleUserInput()">Show input</button>
32+
<div style="display: none;" id="inputArea">
33+
<p>Input given by the user</p>
34+
<textarea style="width: 235px; height: 194px;" readonly id="userInput">No input given</textarea>
35+
</div>
3236
</body>
3337
</html>

v3/js/iframe-embed.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ function iframeHandleUncaughtException(trace) {
5252
$("#vizDiv").html(htmlspecialchars(excMsg));
5353
}
5454

55-
55+
function toggleUserInput(){
56+
var userInputDiv = document.getElementById('inputArea');
57+
var button = document.getElementById("show-hide-input-button");
58+
59+
var inputIsHidden = (userInputDiv.style.display === 'none');
60+
if( inputIsHidden ){
61+
userInputDiv.style.display = 'block';
62+
button.innerText = "Hide input";
63+
}else{
64+
userInputDiv.style.display = 'none';
65+
button.innerText = "Show input";
66+
}
67+
}
5668

5769
$(document).ready(function() {
5870
var queryStrOptions = getQueryStringOptions();
@@ -63,6 +75,7 @@ $(document).ready(function() {
6375
var heapPrimitivesBool = (queryStrOptions.heapPrimitives == 'true');
6476
var textRefsBool = (queryStrOptions.textReferences == 'true');
6577
var cumModeBool = (queryStrOptions.cumulative == 'true');
78+
rawInputLst = queryStrOptions.rawInputLst;
6679

6780
// these two are deprecated
6881
var drawParentPointerBool = (queryStrOptions.drawParentPointers == 'true');
@@ -91,7 +104,7 @@ $(document).ready(function() {
91104

92105
// David Pritchard's code for resizeContainer option ...
93106
var resizeContainer = ($.bbq.getState('resizeContainer') == 'true');
94-
107+
95108
if (resizeContainer) {
96109
function findContainer() {
97110
var ifs = window.top.document.getElementsByTagName("iframe");
@@ -103,9 +116,9 @@ $(document).ready(function() {
103116
}
104117
}
105118
}
106-
119+
107120
var container = findContainer();
108-
121+
109122
function resizeContainerNow() {
110123
$(container).height($("html").height());
111124
};
@@ -177,6 +190,10 @@ $(document).ready(function() {
177190
myVisualizer.redrawConnectors();
178191
});
179192

193+
// set user input into the text area
194+
if(rawInputLst){
195+
$("#userInput").val(rawInputLst.join("\n"));
196+
}
180197

181-
executeCodeFromScratch(); // finally, execute code and display visualization
198+
executeCode(); // finally, execute code and display visualization
182199
});

v3/js/opt-frontend-common.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if (window.location.protocol === 'https:') {
7777
var JAVA_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_java_jsonp'; // for deployment
7878
var RUBY_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_ruby_jsonp'; // for deployment
7979
var C_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_c_jsonp'; // for deployment
80-
var CPP_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_cpp_jsonp'; // for deployment
80+
var CPP_JSONP_ENDPOINT = "http://127.0.0.1:3000/exec_cpp_jsonp"; // for deployment
8181
}
8282

8383

@@ -1700,7 +1700,8 @@ function executeCodeAndCreateViz(codeToExec,
17001700
jsonp: "callback",
17011701
dataType: "jsonp",
17021702
data: {user_script : codeToExec,
1703-
options_json: JSON.stringify(backendOptionsObj)},
1703+
options_json: JSON.stringify(backendOptionsObj),
1704+
raw_input_json: JSON.stringify(rawInputLst)},
17041705
success: execCallback,
17051706
});
17061707
} else {

v4-cokapi/cokapi.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var util = require('util');
5252
// spawn a shell
5353
// http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback
5454

55-
var TIMEOUT_SECS = 15;
55+
var TIMEOUT_SECS = 30;
5656

5757
var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
5858

@@ -232,6 +232,8 @@ app.get('/exec_cpp_jsonp', exec_cpp_handler.bind(null, true, true));
232232

233233
function exec_cpp_handler(useCPP /* use bind first */, useJSONP /* use bind first */, req, res) {
234234
var usrCod = req.query.user_script;
235+
var userInput = JSON.parse(req.query.raw_input_json).join("\n");
236+
235237

236238
var exeFile;
237239
var args = [];
@@ -242,7 +244,8 @@ function exec_cpp_handler(useCPP /* use bind first */, useJSONP /* use bind firs
242244
'python',
243245
'/tmp/opt-cpp-backend/run_cpp_backend.py',
244246
usrCod,
245-
useCPP ? 'cpp' : 'c');
247+
useCPP ? 'cpp' : 'c',
248+
userInput);
246249

247250
child_process.execFile(exeFile, args,
248251
{timeout: TIMEOUT_SECS * 1000 /* milliseconds */,
@@ -260,13 +263,14 @@ function exec_cpp_handler(useCPP /* use bind first */, useJSONP /* use bind firs
260263
var https = require('https');
261264
var fs = require('fs');
262265

263-
var options = {
264-
key: fs.readFileSync('cokapi.com.key'),
265-
cert: fs.readFileSync('cokapi.com-BUNDLE.crt')
266-
};
267266

268267
var args = process.argv.slice(2);
269268
if (args.length > 0 && args[0] === 'https') {
269+
var options = {
270+
key: fs.readFileSync('cokapi.com.key'),
271+
cert: fs.readFileSync('cokapi.com-BUNDLE.crt')
272+
};
273+
270274
var server = https.createServer(options, app).listen(
271275
IS_DEBUG ? DEBUG_PORT : PRODUCTION_HTTPS_PORT,
272276
function() {

0 commit comments

Comments
 (0)