diff --git a/web/democode/perleditor.html b/web/democode/perleditor.html index 4bd48be..ae5b0bc 100644 --- a/web/democode/perleditor.html +++ b/web/democode/perleditor.html @@ -184,6 +184,36 @@ function setupOutputFile (fn, text) { cm.setValue( text ? text : '' ); } +function setupInputFile (inp) { + var fn; + if (inp["fn"]) fn = inp.fn; + else { // autogenerate a filename + for (var i=1; i<1000; i++) { + var testfn = "input"+i+".txt"; + var found = $('div.inputs>.filename') + .filter(function(){ return $(this).text() == testfn }); + if (!found.length) { + fn = testfn; + break } + } + if (!fn) { + $('#runnererrors>pre').text('Too many input files'); + $('#runnererrors').show(); + throw 'Too many input files'; + } + } + var div = $('
',{class:"codewithfn inputs"}); + div.append( $('',{class:"filename",text:fn}) ); + var ta = $('').appendTo(div); + $('#inputhere').before(div); + var cm = makeCM(ta,1,0); + div.data('CodeMirrorInstance', cm); + if (inp["text"]) + cm.setValue(inp.text); + else if (inp["url"]) + fetchUrl(inp.url,cm); +} + $(function () { var hashdata = window.location.hash.substr(1); @@ -210,18 +240,8 @@ $(function () { // input files $('.inputs').remove(); - if ( hash["inputs"] ) hash.inputs.forEach(function(inp,i) { - var fn = inp["fn"] || "input"+(i+1)+".txt"; - var div = $('',{class:"codewithfn inputs"}); - div.append( $('',{class:"filename",text:fn}) ); - var ta = $('').appendTo(div); - $('#inputhere').before(div); - var cm = makeCM(ta,1,0); - div.data('CodeMirrorInstance', cm); - if (inp["text"]) - cm.setValue(inp.text); - else if (inp["url"]) - fetchUrl(inp.url,cm); + if ( hash["inputs"] ) hash.inputs.forEach(function(inp) { + setupInputFile(inp); }); // stdout/stderr diff --git a/web/democode/perlrunner.html b/web/democode/perlrunner.html index baa7c8c..88f38df 100644 --- a/web/democode/perlrunner.html +++ b/web/democode/perlrunner.html @@ -142,6 +142,10 @@ window.addEventListener('message', function (event) { } // else // set up files and run perl var rp = event.data.runPerl; + //TODO: we don't check for overlaps in filenames between script+input files (maybe the editor should do that) + // one solution would be to just have the script be an input file (code mirror syntax highlighting based on filename?) + // note overlaps of output filenames with input files is ok + // we also don't check for duplicate filenames if (rp["script"]) { var script_fn = 'script.pl'; if (rp["script_fn"])