18 locked = document.getElementById("locked");
19 unlocked = document.getElementById("unlocked");
20 workarea = document.getElementById("workarea");
21 scriptcell = document.getElementById("scriptcell");
22 goalcell = document.getElementById("goalcell");
23 goals = document.getElementById("goals");
24 goalview = document.getElementById("goalview");
25 filename = document.getElementById("filename");
26 logarea = document.getElementById("logarea");
27 advanceButton = document.getElementById("advance");
28 retractButton = document.getElementById("retract");
29 cursorButton = document.getElementById("cursor");
30 bottomButton = document.getElementById("bottom");
32 // hide sequent view at start
38 logarea.innerHTML = txt + "\n" + logarea.innerHTML;
44 debug("hd of '" + l + "' = '" + ar[0] + "'");
52 debug("tl of '" + l + "' = '" + tl + "'");
56 function listcons(x,l)
58 debug("cons '" + x + "' on '" + l + "'");
72 function fold_left (f,acc,l)
75 { debug("'" + l + "' is fold end");
78 { debug("'" + l + "' is fold cons");
79 return(fold_left (f,f(acc,(listhd(l))),listtl(l))); }
82 function listiter (f,l)
85 { debug("'" + l + "' is nil");
90 debug("'" + l + "' is not nil");
92 listiter(f,listtl(l));
96 function listmap (f,l)
98 debug("listmap on " + l);
100 { debug("returning listnil");
104 { debug("cons f(hd) map(f,tl)");
105 return(f(listhd(l)) + "#" + listmap(f,listtl(l)));
109 var statements = listnil();
112 var metalist = listnil();
114 function pairmap (f,p)
116 debug("pairmap of '" + p + "'");
118 return (f(ar[0],ar[1]));
121 function tripletmap (f,p)
123 debug("tripletmap of '" + p + "'");
125 return (f(ar[0],ar[1],ar[2]));
131 return (pairmap (function (a,b) { return (a); }, p));
137 return (tripletmap (function (a,b,c) { return (a); }, p));
143 return (tripletmap (function (a,b,c) { return (b); }, p));
149 return (tripletmap (function (a,b,c) { return (c); }, p));
152 function populate_goalarray(txt)
160 debug("populate with '" + txt + "'");
161 goalarray = new Array();
162 metalist = listnil();
163 var tmp_goallist = "";
164 listiter (function(item)
166 debug ("item is '" + item + "'");
167 tripletmap (function(a,ahtml,b) {
168 debug ("found meta n. " + a);
169 debug ("found goal\nBEGIN" + unescape(b) + "\nEND");
170 goalarray[a] = unescape(b);
171 tmp_goallist = " <A href=\"javascript:switch_goal(" + a + ")\">" + unescape(ahtml) + "</A>" + tmp_goallist;
172 metalist = listcons(a,metalist);
173 debug ("goalarray[\"" + a + "\"] = " + goalarray[a]);
176 // metalist = listmap (p13,txt);
177 goals.innerHTML = tmp_goallist;
178 debug("new metalist is '" + metalist + "'");
179 if (is_nil(metalist)) {
183 switch_goal(listhd(metalist));
188 function switch_goal(meta)
190 if (typeof meta == "undefined") {
191 goalview.innerHTML = "";
194 debug("switch_goal " + meta + "\n" + goalarray[meta]);
195 goalview.innerHTML = "<B>Goal ?" + meta + ":</B>\n\n" + goalarray[meta];
199 String.prototype.unescapeHTML = function()
201 var patt1 = /<br(\/|)>/gi;
202 var patt2 = /</gi;
203 var patt3 = />/gi;
205 result = result.replace(patt1,"\n");
206 result = result.replace(patt2,"<");
207 result = result.replace(patt3,">");
208 return (unescape(result));
213 advanceButton.disabled = true;
214 retractButton.disabled = true;
215 cursorButton.disabled = true;
216 bottomButton.disabled = true;
221 advanceButton.disabled = false;
222 retractButton.disabled = false;
223 cursorButton.disabled = false;
224 bottomButton.disabled = false;
227 function is_defined(x)
229 return (typeof x != "undefined");
232 /* servicename: name of the service being called
233 * reqbody: text of the request
234 * processResponse: processes the server response
235 * (takes the response text in input, undefined in case of error)
237 function callServer(servicename,processResponse,reqbody)
241 if (window.XMLHttpRequest)
243 req = new XMLHttpRequest();
245 else if (window.ActiveXObject)
248 req = new ActiveXObject("Msxml2.XMLHTTP");
252 req = new ActiveXObject("Microsoft.XMLHTTP");
256 req.onreadystatechange = function()
264 stxt = req.statusText;
267 processResponse(req.responseText);
274 req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
283 function advanceForm1()
285 processor = function(responseText) {
286 if (is_defined(responseText)) {
287 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
288 response = responseText.split("@");
289 len = parseInt(response[0]);
290 len0 = unlocked.innerHTML.length;
291 unescaped = unlocked.innerHTML.unescapeHTML();
292 parsedtxt = unescaped.substr(0,len);
293 unparsedtxt = unescaped.substr(len);
294 locked.innerHTML = locked.innerHTML + parsedtxt;
295 unlocked.innerHTML = unparsedtxt;
296 len1 = unlocked.innerHTML.length;
298 metasenv = response[1];
299 populate_goalarray(response[1]);
300 statements = listcons(len2,statements);
301 unlocked.scrollIntoView(true);
303 debug("advance failed");
308 callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
312 function gotoBottom()
314 processor = function(responseText) {
315 if (is_defined(responseText)) {
316 // debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
317 response = responseText.split("@");
318 len = parseInt(response[0]);
319 len0 = unlocked.innerHTML.length;
320 unescaped = unlocked.innerHTML.unescapeHTML();
321 parsedtxt = unescaped.substr(0,len);
322 unparsedtxt = unescaped.substr(len);
323 locked.innerHTML = locked.innerHTML + parsedtxt;
324 unlocked.innerHTML = unparsedtxt;
325 len1 = unlocked.innerHTML.length;
327 populate_goalarray(response[1]);
328 statements = listcons(len,statements);
329 unlocked.scrollIntoView(true);
331 debug("goto bottom failed");
336 callServer("bottom",processor,unlocked.innerHTML.unescapeHTML());
341 function gotoPos(offset)
343 if (!is_defined(offset)) {
344 offset = getCursorPos();
346 processor = function(responseText) {
347 if (is_defined(responseText)) {
348 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
349 response = responseText.split("@");
350 len = parseInt(response[0]);
351 len0 = unlocked.innerHTML.length;
352 unescaped = unlocked.innerHTML.unescapeHTML();
353 parsedtxt = unescaped.substr(0,len);
354 unparsedtxt = unescaped.substr(len);
355 locked.innerHTML = locked.innerHTML + parsedtxt;
356 unlocked.innerHTML = unparsedtxt;
357 len1 = unlocked.innerHTML.length;
359 statements = listcons(len2,statements);
360 metasenv = response[1];
361 // la populate non andrebbe fatta a ogni passo
363 populate_goalarray(response[1]);
366 gotoPos(offset - len);
369 unlocked.scrollIntoView(true);
370 populate_goalarray(metasenv);
375 callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
380 processor = function(responseText) {
381 if (typeof responseText != "undefined") {
382 debug("retract: received response\nBEGIN\n" + responseText + "\nEND");
383 statementlen = parseInt(listhd(statements));
384 statements = listtl(statements);
385 lockedlen = locked.innerHTML.length - statementlen;
386 statement = locked.innerHTML.substr(lockedlen, statementlen);
387 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
388 unlocked.innerHTML = statement + unlocked.innerHTML;
389 populate_goalarray(responseText);
390 unlocked.scrollIntoView(true);
392 debug("retract failed");
398 callServer("retract",processor);
404 processor = function(responseText)
407 locked.innerHTML = "";
408 unlocked.innerHTML = responseText;
410 debug("file open failed");
413 callServer("open?file=" + escape(filename.value),processor);
418 function hideSequent() {
419 goalcell.parentNode.removeChild(goalcell);
420 scriptcell.setAttribute("colspan","2");
423 function showSequent() {
424 scriptcell.setAttribute("colspan","1");
425 workarea.appendChild(goalcell);
428 function removeElement(id) {
429 var element = document.getElementById(id);
430 element.parentNode.removeChild(element);
433 function getCursorPos() {
435 if (window.getSelection) {
436 var selObj = window.getSelection();
437 var selRange = selObj.getRangeAt(0);
438 //cursorPos = findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
439 cursorPos = findNode(unlocked.childNodes, selObj.anchorNode,0) + selObj.anchorOffset;
440 /* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
443 else if (document.selection) {
444 var range = document.selection.createRange();
445 var bookmark = range.getBookmark();
446 /* FIXME the following works wrong when the document is longer than 65535 chars */
447 cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
452 function findNode(list, node, acc) {
453 for (var i = 0; i < list.length; i++) {
454 if (list[i] == node) {
455 // debug("success " + i);
458 if (list[i].hasChildNodes()) {
460 // debug("recursion on node " + i);
461 return (findNode(list[i].childNodes,node,acc))
463 catch (e) { /* debug("recursion failed"); */ }
465 sandbox = document.getElementById("sandbox");
466 dup = list[i].cloneNode(true);
467 sandbox.appendChild(dup);
468 // debug("fail " + i + ": " + sandbox.innerHTML);
469 acc += sandbox.innerHTML.length;
470 sandbox.removeChild(dup);
476 debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));