diff --git a/app.js b/app.js index 4e345df8413..c72d3844f2b 100755 --- a/app.js +++ b/app.js @@ -101,11 +101,12 @@ function clientOptionsHandler(compilers, fileSources) { google_analytics_enabled: gccProps('clientGoogleAnalyticsEnabled', false), sharing_enabled: gccProps('clientSharingEnabled', true), github_ribbon_enabled: gccProps('clientGitHubRibbonEnabled', true), - urlshortener: gccProps('clientURLShortener', 'google'), + urlshortener: gccProps('clientURLShortener', 'gist'), gapiKey: gccProps('google-api-key', 'AIzaSyAaz35KJv8DA0ABoime0fEIh32NmbyYbcQ'), defaultSource: gccProps('defaultSource', ''), language: language, compilers: compilers, + sourceExtension: compilerProps('compileFilename').split('.', 2)[1], defaultCompiler: compilerProps('defaultCompiler', ''), compileOptions: compilerProps("options"), supportsBinary: !!compilerProps("supportsBinary"), diff --git a/etc/config/gcc-explorer.lud-ldnmg01.properties b/etc/config/gcc-explorer.lud-ldnmg01.properties index 5c97f342199..6b2739e6284 100644 --- a/etc/config/gcc-explorer.lud-ldnmg01.properties +++ b/etc/config/gcc-explorer.lud-ldnmg01.properties @@ -1 +1,2 @@ -language=C++ \ No newline at end of file +language=C++ +clientURLShortener=gist diff --git a/etc/config/gcc-explorer.wud-mgodbolt01.properties b/etc/config/gcc-explorer.wud-mgodbolt01.properties index 324148db701..04dd42f6b52 100644 --- a/etc/config/gcc-explorer.wud-mgodbolt01.properties +++ b/etc/config/gcc-explorer.wud-mgodbolt01.properties @@ -1,7 +1,5 @@ -# Default settings for GCC Explorer. port=10240 compileTimeoutMs=5000 -compilers=/home/mgodbolt/.fighome/runtime/gcc/4.9.2-1/bin/g++ clientSharingEnabled=false tempDirCleanupSecs=10 diff --git a/static/compiler.js b/static/compiler.js index 9ae5c923c4c..3b1782322d1 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -327,12 +327,16 @@ function Compiler(domRoot, origFilters, windowLocalPrefix, onChangeCallback, lan return cppEditor.getValue(); } - function serialiseState() { + function serialiseState(compress) { var state = { - sourcez: LZString.compressToBase64(cppEditor.getValue()), compiler: domRoot.find('.compiler').val(), options: domRoot.find('.compiler_options').val() }; + if (compress) { + state.sourcez = LZString.compressToBase64(cppEditor.getValue()); + } else { + state.source = cppEditor.getValue(); + } return state; } diff --git a/static/gcc.css b/static/gcc.css index f4c20f97432..7e3ad24172c 100644 --- a/static/gcc.css +++ b/static/gcc.css @@ -8,6 +8,7 @@ body { */ #permalink { cursor: text; + width: 300px; } .sideBySide { diff --git a/static/gcc.js b/static/gcc.js index 9339ac41413..6b6873eb08f 100644 --- a/static/gcc.js +++ b/static/gcc.js @@ -156,34 +156,107 @@ function togglePermalink() { } function serialiseState() { - var state = { + return encodeURIComponent(JSON.stringify(getState(true))); +} + +function getState(compress) { + return { version: 3, filterAsm: getAsmFilters(), compilers: $.map(allCompilers, function (compiler) { - return compiler.serialiseState(); + return compiler.serialiseState(compress); }) }; - return encodeURIComponent(JSON.stringify(state)); +} + +function toGist(state) { + files = {}; + function nameFor(compiler) { + var addNum = 0; + var name, add; + for (; ;) { + add = addNum ? addNum.toString() : ""; + name = compiler + add + '.' + OPTIONS.sourceExtension; + if (files[name] === undefined) return name; + addNum++; + } + }; + state.compilers.forEach(function (s) { + var name = nameFor(s.compiler); + files[name] = { + content: s.source, + language: OPTIONS.language + }; + s.source = name; + }); + files['state.json'] = {content: JSON.stringify(state)}; + return JSON.stringify({ + description: "Compiler Explorer automatically generated files", + 'public': false, + files: files + }); +} + +function makeGist(onDone, onFail) { + var req = $.ajax('https://api.github.com/gists', { + type: 'POST', + //accepts: 'application/vnd.github.v3+json', + dataType: 'json', + contentType: 'application/json', + data: toGist(getState()) + }); + req.done(function (msg) { + onDone(msg); + }); + req.fail(function (jqXHR, textStatus) { + onFail(textStatus + " (" + jqXHR.statusText + ")"); + }); +} + +function fromGist(msg) { + var state = JSON.parse(msg.files['state.json'].content); + state.compilers.forEach(function (s) { + s.source = msg.files[s.source].content; + }); + return state; +} +function loadGist(gist) { + var req = $.ajax('https://api.github.com/gists/' + gist); + req.done(function (msg) { + loadState(fromGist(msg)); + }); + req.fail(function (jqXHR, textStatus) { + alert("Unable to load gist: " + textStatus + " (" + jqXHR.statusText + ")"); + }); } function deserialiseState(state) { + if (state.substr(0, 2) == "g=") { + loadGist(state.substr(2)); + return; + } try { state = $.parseJSON(decodeURIComponent(state)); - switch (state.version) { - case 1: - state.filterAsm = {}; - /* falls through */ - case 2: - state.compilers = [state]; - /* falls through */ - case 3: - break; - default: - return false; - } } catch (ignored) { return false; } + return loadState(state); +} + +function loadState(state) { + if (!state || state['version'] === undefined) return false; + switch (state.version) { + case 1: + state.filterAsm = {}; + /* falls through */ + case 2: + state.compilers = [state]; + /* falls through */ + case 3: + break; + default: + return false; + } setFilterUi(state.filterAsm); for (var i = 0; i < Math.min(allCompilers.length, state.compilers.length); i++) { allCompilers[i].setFilters(state.filterAsm); diff --git a/static/index.html b/static/index.html index 91ef1822c4b..89a1b8f127e 100644 --- a/static/index.html +++ b/static/index.html @@ -104,7 +104,7 @@ diff --git a/static/urlshorten-gist.js b/static/urlshorten-gist.js new file mode 100644 index 00000000000..a0cfad0f07f --- /dev/null +++ b/static/urlshorten-gist.js @@ -0,0 +1,9 @@ +function shortenURL(url, done) { + makeGist(function (msg) { + done(document.location.origin + "#g=" + msg.id); + }, + function (failure) { + done("Failed: " + failure); + } + ); +}