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(menv)
154 debug("metasenv.length = " + menv.length);
155 if (menv.length == 0) {
161 goalarray = new Array();
162 metalist = listnil();
163 var tmp_goallist = "";
164 for (i = 0; i < menv.length; i++) {
165 metano = menv[i].getAttribute("number");
166 metaname = menv[i].childNodes[0].childNodes[0].data;
167 goal = menv[i].childNodes[1].childNodes[0].data;
168 debug ("found meta n. " + metano);
169 debug ("found goal\nBEGIN" + goal + "\nEND");
170 goalarray[metano] = goal;
171 tmp_goallist = " <A href=\"javascript:switch_goal(" + metano + ")\">" + metaname + "</A>" + tmp_goallist;
172 metalist = listcons(metano,metalist);
173 debug ("goalarray[\"" + metano + "\"] = " + goalarray[metano]);
175 goals.innerHTML = tmp_goallist;
176 debug("new metalist is '" + metalist + "'");
177 if (is_nil(metalist)) {
181 switch_goal(listhd(metalist));
186 function switch_goal(meta)
188 if (typeof meta == "undefined") {
189 goalview.innerHTML = "";
192 debug("switch_goal " + meta + "\n" + goalarray[meta]);
193 goalview.innerHTML = "<B>Goal ?" + meta + ":</B>\n\n" + goalarray[meta];
197 String.prototype.unescapeHTML = function()
199 var patt1 = /<br(\/|)>/gi;
200 var patt2 = /</gi;
201 var patt3 = />/gi;
203 result = result.replace(patt1,"\n");
204 result = result.replace(patt2,"<");
205 result = result.replace(patt3,">");
206 return (unescape(result));
211 advanceButton.disabled = true;
212 retractButton.disabled = true;
213 cursorButton.disabled = true;
214 bottomButton.disabled = true;
219 advanceButton.disabled = false;
220 retractButton.disabled = false;
221 cursorButton.disabled = false;
222 bottomButton.disabled = false;
225 function is_defined(x)
227 return (typeof x != "undefined");
230 /* servicename: name of the service being called
231 * reqbody: text of the request
232 * processResponse: processes the server response
233 * (takes the response text in input, undefined in case of error)
235 function callServer(servicename,processResponse,reqbody)
239 if (window.XMLHttpRequest)
241 req = new XMLHttpRequest();
243 else if (window.ActiveXObject)
246 req = new ActiveXObject("Msxml2.XMLHTTP");
250 req = new ActiveXObject("Microsoft.XMLHTTP");
254 req.onreadystatechange = function()
262 stxt = req.statusText;
265 debug(req.responseText);
266 if (window.DOMParser) {
267 parser=new DOMParser();
268 xmlDoc=parser.parseFromString(req.responseText,"text/xml");
270 else // Internet Explorer
272 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
273 xmlDoc.async="false";
274 xmlDoc.loadXML(req.responseText);
276 processResponse(xmlDoc);
282 req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
291 function advanceForm1()
293 processor = function(xml) {
294 if (is_defined(xml)) {
295 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
296 len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
297 len0 = unlocked.innerHTML.length;
298 unescaped = unlocked.innerHTML.unescapeHTML();
299 parsedtxt = unescaped.substr(0,len);
300 unparsedtxt = unescaped.substr(len);
301 locked.innerHTML = locked.innerHTML + parsedtxt;
302 unlocked.innerHTML = unparsedtxt;
303 len1 = unlocked.innerHTML.length;
305 metasenv = xml.getElementsByTagName("meta");
306 populate_goalarray(metasenv);
307 statements = listcons(len2,statements);
308 unlocked.scrollIntoView(true);
310 debug("advance failed");
315 callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
319 function gotoBottom()
321 processor = function(xml) {
322 if (is_defined(xml)) {
323 // debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
324 len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
325 len0 = unlocked.innerHTML.length;
326 unescaped = unlocked.innerHTML.unescapeHTML();
327 parsedtxt = unescaped.substr(0,len);
328 unparsedtxt = unescaped.substr(len);
329 locked.innerHTML = locked.innerHTML + parsedtxt;
330 unlocked.innerHTML = unparsedtxt;
331 len1 = unlocked.innerHTML.length;
333 metasenv = xml.getElementsByTagName("meta");
334 populate_goalarray(metasenv);
335 statements = listcons(len2,statements);
336 unlocked.scrollIntoView(true);
338 debug("goto bottom failed");
343 callServer("bottom",processor,unlocked.innerHTML.unescapeHTML());
348 function gotoPos(offset)
350 if (!is_defined(offset)) {
351 offset = getCursorPos();
353 processor = function(xml) {
354 if (is_defined(xml)) {
355 // debug("goto pos: received response\nBEGIN\n" + req.responseText + "\nEND");
356 len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
357 len0 = unlocked.innerHTML.length;
358 unescaped = unlocked.innerHTML.unescapeHTML();
359 parsedtxt = unescaped.substr(0,len);
360 unparsedtxt = unescaped.substr(len);
361 locked.innerHTML = locked.innerHTML + parsedtxt;
362 unlocked.innerHTML = unparsedtxt;
363 len1 = unlocked.innerHTML.length;
365 metasenv = xml.getElementsByTagName("meta");
366 // populate_goalarray(metasenv);
367 statements = listcons(len2,statements);
368 unlocked.scrollIntoView(true);
369 // la populate non andrebbe fatta a ogni passo
371 populate_goalarray(metasenv);
374 gotoPos(offset - len);
377 unlocked.scrollIntoView(true);
378 populate_goalarray(metasenv);
383 callServer("advance",processor,unlocked.innerHTML.unescapeHTML());
388 processor = function(xml) {
389 if (typeof xml != "undefined") {
390 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
391 statementlen = parseInt(listhd(statements));
392 statements = listtl(statements);
393 lockedlen = locked.innerHTML.length - statementlen;
394 statement = locked.innerHTML.substr(lockedlen, statementlen);
395 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
396 unlocked.innerHTML = statement + unlocked.innerHTML;
397 metasenv = xml.getElementsByTagName("meta");
398 populate_goalarray(metasenv);
399 unlocked.scrollIntoView(true);
401 debug("retract failed");
407 callServer("retract",processor);
413 processor = function(xml)
415 if (is_defined(xml)) {
416 locked.innerHTML = "";
417 unlocked.innerHTML = xml.documentElement.firstChild.data;
419 debug("file open failed");
422 callServer("open?file=" + escape(filename.value),processor);
427 function hideSequent() {
428 goalcell.parentNode.removeChild(goalcell);
429 scriptcell.setAttribute("colspan","2");
432 function showSequent() {
433 scriptcell.setAttribute("colspan","1");
434 workarea.appendChild(goalcell);
437 function removeElement(id) {
438 var element = document.getElementById(id);
439 element.parentNode.removeChild(element);
442 function getCursorPos() {
444 if (window.getSelection) {
445 var selObj = window.getSelection();
446 var selRange = selObj.getRangeAt(0);
447 //cursorPos = findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
448 cursorPos = findNode(unlocked.childNodes, selObj.anchorNode,0) + selObj.anchorOffset;
449 /* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
452 else if (document.selection) {
453 var range = document.selection.createRange();
454 var bookmark = range.getBookmark();
455 /* FIXME the following works wrong when the document is longer than 65535 chars */
456 cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
461 function findNode(list, node, acc) {
462 for (var i = 0; i < list.length; i++) {
463 if (list[i] == node) {
464 // debug("success " + i);
467 if (list[i].hasChildNodes()) {
469 // debug("recursion on node " + i);
470 return (findNode(list[i].childNodes,node,acc))
472 catch (e) { /* debug("recursion failed"); */ }
474 sandbox = document.getElementById("sandbox");
475 dup = list[i].cloneNode(true);
476 sandbox.appendChild(dup);
477 // debug("fail " + i + ": " + sandbox.innerHTML);
478 acc += sandbox.innerHTML.length;
479 sandbox.removeChild(dup);
485 debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));