@@ -37,222 +37,10 @@ void main(string[] args) {
3737[end here]
3838------
3939
40- Go to http://dpaste.dzfl.pl/md5sum, paste your example to Source box and click "Compute".
41- Copy generated md5sum. Open run-main-website.js file and add following
42-
43- mainPage["yourMd5Sum"] = ["standard input is has 0 position", "standard args has 1 position"];
44-
45- Save, reload website and see if standard input and/or standard arguments are displayed in your example form.
46-
4740TL;DR
4841All examples are replaced with custom form by default. You need to do additional work only if you wan't
4942your example to have deafault standard input or default standard arguments.
50-
51- */
52-
53- /**
54- Taken from http://www.webtoolkit.info/javascript-md5.html
5543*/
56- var MD5 = function ( string ) {
57-
58- function RotateLeft ( lValue , iShiftBits ) {
59- return ( lValue << iShiftBits ) | ( lValue >>> ( 32 - iShiftBits ) ) ;
60- }
61-
62- function AddUnsigned ( lX , lY ) {
63- var lX4 , lY4 , lX8 , lY8 , lResult ;
64- lX8 = ( lX & 0x80000000 ) ;
65- lY8 = ( lY & 0x80000000 ) ;
66- lX4 = ( lX & 0x40000000 ) ;
67- lY4 = ( lY & 0x40000000 ) ;
68- lResult = ( lX & 0x3FFFFFFF ) + ( lY & 0x3FFFFFFF ) ;
69- if ( lX4 & lY4 ) {
70- return ( lResult ^ 0x80000000 ^ lX8 ^ lY8 ) ;
71- }
72- if ( lX4 | lY4 ) {
73- if ( lResult & 0x40000000 ) {
74- return ( lResult ^ 0xC0000000 ^ lX8 ^ lY8 ) ;
75- } else {
76- return ( lResult ^ 0x40000000 ^ lX8 ^ lY8 ) ;
77- }
78- } else {
79- return ( lResult ^ lX8 ^ lY8 ) ;
80- }
81- }
82-
83- function F ( x , y , z ) { return ( x & y ) | ( ( ~ x ) & z ) ; }
84- function G ( x , y , z ) { return ( x & z ) | ( y & ( ~ z ) ) ; }
85- function H ( x , y , z ) { return ( x ^ y ^ z ) ; }
86- function I ( x , y , z ) { return ( y ^ ( x | ( ~ z ) ) ) ; }
87-
88- function FF ( a , b , c , d , x , s , ac ) {
89- a = AddUnsigned ( a , AddUnsigned ( AddUnsigned ( F ( b , c , d ) , x ) , ac ) ) ;
90- return AddUnsigned ( RotateLeft ( a , s ) , b ) ;
91- } ;
92-
93- function GG ( a , b , c , d , x , s , ac ) {
94- a = AddUnsigned ( a , AddUnsigned ( AddUnsigned ( G ( b , c , d ) , x ) , ac ) ) ;
95- return AddUnsigned ( RotateLeft ( a , s ) , b ) ;
96- } ;
97-
98- function HH ( a , b , c , d , x , s , ac ) {
99- a = AddUnsigned ( a , AddUnsigned ( AddUnsigned ( H ( b , c , d ) , x ) , ac ) ) ;
100- return AddUnsigned ( RotateLeft ( a , s ) , b ) ;
101- } ;
102-
103- function II ( a , b , c , d , x , s , ac ) {
104- a = AddUnsigned ( a , AddUnsigned ( AddUnsigned ( I ( b , c , d ) , x ) , ac ) ) ;
105- return AddUnsigned ( RotateLeft ( a , s ) , b ) ;
106- } ;
107-
108- function ConvertToWordArray ( string ) {
109- var lWordCount ;
110- var lMessageLength = string . length ;
111- var lNumberOfWords_temp1 = lMessageLength + 8 ;
112- var lNumberOfWords_temp2 = ( lNumberOfWords_temp1 - ( lNumberOfWords_temp1 % 64 ) ) / 64 ;
113- var lNumberOfWords = ( lNumberOfWords_temp2 + 1 ) * 16 ;
114- var lWordArray = Array ( lNumberOfWords - 1 ) ;
115- var lBytePosition = 0 ;
116- var lByteCount = 0 ;
117- while ( lByteCount < lMessageLength ) {
118- lWordCount = ( lByteCount - ( lByteCount % 4 ) ) / 4 ;
119- lBytePosition = ( lByteCount % 4 ) * 8 ;
120- lWordArray [ lWordCount ] = ( lWordArray [ lWordCount ] | ( string . charCodeAt ( lByteCount ) << lBytePosition ) ) ;
121- lByteCount ++ ;
122- }
123- lWordCount = ( lByteCount - ( lByteCount % 4 ) ) / 4 ;
124- lBytePosition = ( lByteCount % 4 ) * 8 ;
125- lWordArray [ lWordCount ] = lWordArray [ lWordCount ] | ( 0x80 << lBytePosition ) ;
126- lWordArray [ lNumberOfWords - 2 ] = lMessageLength << 3 ;
127- lWordArray [ lNumberOfWords - 1 ] = lMessageLength >>> 29 ;
128- return lWordArray ;
129- } ;
130-
131- function WordToHex ( lValue ) {
132- var WordToHexValue = "" , WordToHexValue_temp = "" , lByte , lCount ;
133- for ( lCount = 0 ; lCount <= 3 ; lCount ++ ) {
134- lByte = ( lValue >>> ( lCount * 8 ) ) & 255 ;
135- WordToHexValue_temp = "0" + lByte . toString ( 16 ) ;
136- WordToHexValue = WordToHexValue + WordToHexValue_temp . substr ( WordToHexValue_temp . length - 2 , 2 ) ;
137- }
138- return WordToHexValue ;
139- } ;
140-
141- function Utf8Encode ( string ) {
142- string = string . replace ( / \r \n / g, "\n" ) ;
143- var utftext = "" ;
144-
145- for ( var n = 0 ; n < string . length ; n ++ ) {
146-
147- var c = string . charCodeAt ( n ) ;
148-
149- if ( c < 128 ) {
150- utftext += String . fromCharCode ( c ) ;
151- }
152- else if ( ( c > 127 ) && ( c < 2048 ) ) {
153- utftext += String . fromCharCode ( ( c >> 6 ) | 192 ) ;
154- utftext += String . fromCharCode ( ( c & 63 ) | 128 ) ;
155- }
156- else {
157- utftext += String . fromCharCode ( ( c >> 12 ) | 224 ) ;
158- utftext += String . fromCharCode ( ( ( c >> 6 ) & 63 ) | 128 ) ;
159- utftext += String . fromCharCode ( ( c & 63 ) | 128 ) ;
160- }
161-
162- }
163-
164- return utftext ;
165- } ;
166-
167- var x = Array ( ) ;
168- var k , AA , BB , CC , DD , a , b , c , d ;
169- var S11 = 7 , S12 = 12 , S13 = 17 , S14 = 22 ;
170- var S21 = 5 , S22 = 9 , S23 = 14 , S24 = 20 ;
171- var S31 = 4 , S32 = 11 , S33 = 16 , S34 = 23 ;
172- var S41 = 6 , S42 = 10 , S43 = 15 , S44 = 21 ;
173-
174- string = Utf8Encode ( string ) ;
175-
176- x = ConvertToWordArray ( string ) ;
177-
178- a = 0x67452301 ; b = 0xEFCDAB89 ; c = 0x98BADCFE ; d = 0x10325476 ;
179-
180- for ( k = 0 ; k < x . length ; k += 16 ) {
181- AA = a ; BB = b ; CC = c ; DD = d ;
182- a = FF ( a , b , c , d , x [ k + 0 ] , S11 , 0xD76AA478 ) ;
183- d = FF ( d , a , b , c , x [ k + 1 ] , S12 , 0xE8C7B756 ) ;
184- c = FF ( c , d , a , b , x [ k + 2 ] , S13 , 0x242070DB ) ;
185- b = FF ( b , c , d , a , x [ k + 3 ] , S14 , 0xC1BDCEEE ) ;
186- a = FF ( a , b , c , d , x [ k + 4 ] , S11 , 0xF57C0FAF ) ;
187- d = FF ( d , a , b , c , x [ k + 5 ] , S12 , 0x4787C62A ) ;
188- c = FF ( c , d , a , b , x [ k + 6 ] , S13 , 0xA8304613 ) ;
189- b = FF ( b , c , d , a , x [ k + 7 ] , S14 , 0xFD469501 ) ;
190- a = FF ( a , b , c , d , x [ k + 8 ] , S11 , 0x698098D8 ) ;
191- d = FF ( d , a , b , c , x [ k + 9 ] , S12 , 0x8B44F7AF ) ;
192- c = FF ( c , d , a , b , x [ k + 10 ] , S13 , 0xFFFF5BB1 ) ;
193- b = FF ( b , c , d , a , x [ k + 11 ] , S14 , 0x895CD7BE ) ;
194- a = FF ( a , b , c , d , x [ k + 12 ] , S11 , 0x6B901122 ) ;
195- d = FF ( d , a , b , c , x [ k + 13 ] , S12 , 0xFD987193 ) ;
196- c = FF ( c , d , a , b , x [ k + 14 ] , S13 , 0xA679438E ) ;
197- b = FF ( b , c , d , a , x [ k + 15 ] , S14 , 0x49B40821 ) ;
198- a = GG ( a , b , c , d , x [ k + 1 ] , S21 , 0xF61E2562 ) ;
199- d = GG ( d , a , b , c , x [ k + 6 ] , S22 , 0xC040B340 ) ;
200- c = GG ( c , d , a , b , x [ k + 11 ] , S23 , 0x265E5A51 ) ;
201- b = GG ( b , c , d , a , x [ k + 0 ] , S24 , 0xE9B6C7AA ) ;
202- a = GG ( a , b , c , d , x [ k + 5 ] , S21 , 0xD62F105D ) ;
203- d = GG ( d , a , b , c , x [ k + 10 ] , S22 , 0x2441453 ) ;
204- c = GG ( c , d , a , b , x [ k + 15 ] , S23 , 0xD8A1E681 ) ;
205- b = GG ( b , c , d , a , x [ k + 4 ] , S24 , 0xE7D3FBC8 ) ;
206- a = GG ( a , b , c , d , x [ k + 9 ] , S21 , 0x21E1CDE6 ) ;
207- d = GG ( d , a , b , c , x [ k + 14 ] , S22 , 0xC33707D6 ) ;
208- c = GG ( c , d , a , b , x [ k + 3 ] , S23 , 0xF4D50D87 ) ;
209- b = GG ( b , c , d , a , x [ k + 8 ] , S24 , 0x455A14ED ) ;
210- a = GG ( a , b , c , d , x [ k + 13 ] , S21 , 0xA9E3E905 ) ;
211- d = GG ( d , a , b , c , x [ k + 2 ] , S22 , 0xFCEFA3F8 ) ;
212- c = GG ( c , d , a , b , x [ k + 7 ] , S23 , 0x676F02D9 ) ;
213- b = GG ( b , c , d , a , x [ k + 12 ] , S24 , 0x8D2A4C8A ) ;
214- a = HH ( a , b , c , d , x [ k + 5 ] , S31 , 0xFFFA3942 ) ;
215- d = HH ( d , a , b , c , x [ k + 8 ] , S32 , 0x8771F681 ) ;
216- c = HH ( c , d , a , b , x [ k + 11 ] , S33 , 0x6D9D6122 ) ;
217- b = HH ( b , c , d , a , x [ k + 14 ] , S34 , 0xFDE5380C ) ;
218- a = HH ( a , b , c , d , x [ k + 1 ] , S31 , 0xA4BEEA44 ) ;
219- d = HH ( d , a , b , c , x [ k + 4 ] , S32 , 0x4BDECFA9 ) ;
220- c = HH ( c , d , a , b , x [ k + 7 ] , S33 , 0xF6BB4B60 ) ;
221- b = HH ( b , c , d , a , x [ k + 10 ] , S34 , 0xBEBFBC70 ) ;
222- a = HH ( a , b , c , d , x [ k + 13 ] , S31 , 0x289B7EC6 ) ;
223- d = HH ( d , a , b , c , x [ k + 0 ] , S32 , 0xEAA127FA ) ;
224- c = HH ( c , d , a , b , x [ k + 3 ] , S33 , 0xD4EF3085 ) ;
225- b = HH ( b , c , d , a , x [ k + 6 ] , S34 , 0x4881D05 ) ;
226- a = HH ( a , b , c , d , x [ k + 9 ] , S31 , 0xD9D4D039 ) ;
227- d = HH ( d , a , b , c , x [ k + 12 ] , S32 , 0xE6DB99E5 ) ;
228- c = HH ( c , d , a , b , x [ k + 15 ] , S33 , 0x1FA27CF8 ) ;
229- b = HH ( b , c , d , a , x [ k + 2 ] , S34 , 0xC4AC5665 ) ;
230- a = II ( a , b , c , d , x [ k + 0 ] , S41 , 0xF4292244 ) ;
231- d = II ( d , a , b , c , x [ k + 7 ] , S42 , 0x432AFF97 ) ;
232- c = II ( c , d , a , b , x [ k + 14 ] , S43 , 0xAB9423A7 ) ;
233- b = II ( b , c , d , a , x [ k + 5 ] , S44 , 0xFC93A039 ) ;
234- a = II ( a , b , c , d , x [ k + 12 ] , S41 , 0x655B59C3 ) ;
235- d = II ( d , a , b , c , x [ k + 3 ] , S42 , 0x8F0CCC92 ) ;
236- c = II ( c , d , a , b , x [ k + 10 ] , S43 , 0xFFEFF47D ) ;
237- b = II ( b , c , d , a , x [ k + 1 ] , S44 , 0x85845DD1 ) ;
238- a = II ( a , b , c , d , x [ k + 8 ] , S41 , 0x6FA87E4F ) ;
239- d = II ( d , a , b , c , x [ k + 15 ] , S42 , 0xFE2CE6E0 ) ;
240- c = II ( c , d , a , b , x [ k + 6 ] , S43 , 0xA3014314 ) ;
241- b = II ( b , c , d , a , x [ k + 13 ] , S44 , 0x4E0811A1 ) ;
242- a = II ( a , b , c , d , x [ k + 4 ] , S41 , 0xF7537E82 ) ;
243- d = II ( d , a , b , c , x [ k + 11 ] , S42 , 0xBD3AF235 ) ;
244- c = II ( c , d , a , b , x [ k + 2 ] , S43 , 0x2AD7D2BB ) ;
245- b = II ( b , c , d , a , x [ k + 9 ] , S44 , 0xEB86D391 ) ;
246- a = AddUnsigned ( a , AA ) ;
247- b = AddUnsigned ( b , BB ) ;
248- c = AddUnsigned ( c , CC ) ;
249- d = AddUnsigned ( d , DD ) ;
250- }
251-
252- var temp = WordToHex ( a ) + WordToHex ( b ) + WordToHex ( c ) + WordToHex ( d ) ;
253-
254- return temp . toLowerCase ( ) ;
255- }
25644
25745var nl2br = function ( )
25846{
@@ -335,45 +123,39 @@ $(document).ready(function()
335123
336124 var currentPage = $ ( location ) . attr ( 'pathname' ) ;
337125
338- if ( $ ( 'body' ) [ 0 ] . id != "Home" )
339- return ;
340-
341- $ ( 'pre[class~=d_code]' ) . each ( function ( index )
126+ $ ( '.runnable-examples' ) . each ( function ( index )
342127 {
343- var stripedText = $ ( this ) . text ( ) . replace ( / \s / gm, '' ) ;
344- var md5sum = MD5 ( stripedText ) ;
128+ var root = $ ( this ) ;
129+ var el = root . children ( "pre" ) ;
130+ var stripedText = el . text ( ) . replace ( / \s / gm, '' ) ;
345131
346- var stdin = "" ;
347- var args = "" ;
348- var currentExample = $ ( this ) ;
349- var orig = currentExample . html ( ) ;
132+ var stdin = root . children ( ".runnable-examples-stdin" ) . text ( ) ;
133+ var args = root . children ( ".runnable-examples-args" ) . text ( ) ;
350134
351- if ( typeof mainPage !== 'undefined' && md5sum in mainPage )
135+ // only show stdin or args if they are set
136+ if ( stdin . length > 0 )
352137 {
353- var elements = mainPage [ md5sum ] ;
354-
355- if ( elements == null )
356- return ; // this example is not runnable online
357-
358- if ( elements [ 0 ] != null )
359- stdin = elements [ 0 ] ;
360-
361- if ( elements [ 1 ] != null )
362- args = elements [ 1 ] ;
138+ stdin = '<div class="d_code_stdin"><span class="d_code_title">Standard input</span><br>'
139+ + '<textarea class="d_code_stdin">' + stdin + '</textarea></div>' ;
363140 }
141+ if ( args . length > 0 )
142+ {
143+ args = '<div class="d_code_args"><span class="d_code_title">Command line arguments</span><br>'
144+ + '<textarea class="d_code_args">' + args + '</textarea></div>' ;
145+ }
146+
147+ var currentExample = el ;
148+ var orig = currentExample . html ( ) ;
364149
365150 currentExample . replaceWith (
366151 '<div class="d_code"><pre class="d_code">' + orig + '</pre></div>'
367152 + '<div class="d_run_code">'
368153 + '<textarea class="d_code" style="display: none;"></textarea>'
369- + '<div class="d_code_stdin"><span class="d_code_title">Standard input</span><br>'
370- + '<textarea class="d_code_stdin">' + stdin + '</textarea></div>'
371- + '<div class="d_code_args"><span class="d_code_title">Command line arguments</span><br>'
372- + '<textarea class="d_code_args">' + args + '</textarea></div>'
154+ + stdin + args
373155 + '<div class="d_code_output"><span class="d_code_title">Application output</span><br><pre class="d_code_output" readonly>Running...</pre></div>'
374156 + '<input type="button" class="editButton" value="Edit">'
375- + '<input type="button" class="argsButton" value="Args">'
376- + '<input type="button" class="inputButton" value="Input">'
157+ + ( args . length > 0 ? '<input type="button" class="argsButton" value="Args">' : '' )
158+ + ( stdin . length > 0 ? '<input type="button" class="inputButton" value="Input">' : '' )
377159 + '<input type="button" class="runButton" value="Run">'
378160 + '<input type="button" class="resetButton" value="Reset"></div>'
379161 ) ;
0 commit comments