+// get or set <choicepoint>'s (in case of disamb error)
+function get_cps() {
+ return matita.choicepoints
+}
+
+function set_cps(cps) {
+ matita.choicepoints = cps;
+}
+
+// get radio buttons for <choice>'s in a given cp
+function get_choice_opts(i) {
+ var res = [];
+ var choices = get_cps()[i].childNodes;
+ for (var j = 0;j < choices.length;j++) {
+ var href = choices[j].getAttribute("href");
+ var title = choices[j].getAttribute("title");
+ var desc;
+ if (is_defined(title) && title != null) {
+ desc = title;
+ } else if (is_defined(href) && href != null) {
+ desc = href;
+ } else {
+ desc = null;
+ }
+
+ res[j] = document.createElement("input");
+ res[j].setAttribute("type","radio");
+ res[j].setAttribute("name","choice");
+ res[j].setAttribute("choicepointno",i);
+ res[j].setAttribute("choiceno",j);
+ res[j].setAttribute("href",href);
+ res[j].setAttribute("title",title);
+ if (desc != null) res[j].setAttribute("desc",desc);
+
+ if (j == 0) res[j].setAttribute("checked","");
+ }
+ return res;
+}
+
+// get radio buttons for <failure>'s in a given choice
+function get_failure_opts(i,j) {
+ var res = [];
+ var failures = get_cps()[i].childNodes[j].childNodes;
+ for (var k = 0;k < failures.length;k++) {
+ var start = failures[k].getAttribute("start");
+ var stop = failures[k].getAttribute("stop");
+ var title = failures[k].getAttribute("title");
+
+ res[k] = document.createElement("input");
+ res[k].setAttribute("type","radio");
+ res[k].setAttribute("name","failure");
+ res[k].setAttribute("choicepointno",i);
+ res[k].setAttribute("choiceno",j);
+ res[k].setAttribute("failureno",k);
+ res[k].setAttribute("start",start);
+ res[k].setAttribute("stop",stop);
+ res[k].setAttribute("title",title);
+
+ if (k == 0) res[k].setAttribute("checked","");
+ }
+ return res;
+}
+
+function next_cp(curcp) {
+ var cp = get_cps()[curcp];
+ var start = parseInt(cp.getAttribute("start"));
+ var stop = parseInt(cp.getAttribute("stop"));
+
+ matita.errorStart = start;
+ matita.errorStop = stop;
+ // matita.unlockedbackup = unlocked.innerHTML.html_to_matita();
+
+ var unlockedtxt = matita.unlockedbackup;
+ var pre = unlockedtxt.substring(0,start).matita_to_html();
+ var mid = unlockedtxt.substring(start,stop).matita_to_html();
+ var post = unlockedtxt.substring(stop).matita_to_html();
+ unlocked.innerHTML = pre +
+ "<span class=\"error\" title=\"error location\">" +
+ mid + "</span>" + post;
+
+ var title = "<H3>Error diagnostics</H3>";
+ disambcell.innerHTML = title;
+ var choices = get_choice_opts(curcp);
+ for (var i = 0;i < choices.length;i++) {
+ disambcell.appendChild(choices[i]);
+ var desc = choices[i].getAttribute("desc");
+ if (!is_defined(desc) || desc == null) {
+ desc = "Interpretation " + i;
+ }
+ disambcell.appendChild(document.createTextNode(desc));
+ disambcell.appendChild(document.createElement("br"));
+ }
+
+ // update index of the next choicepoint
+ new_curcp = (curcp + 1) % get_cps().length;
+
+ var okbutton = document.createElement("input");
+ okbutton.setAttribute("type","button");
+ okbutton.setAttribute("value","OK");
+ okbutton.setAttribute("onclick","show_failures()");
+ var cancelbutton = document.createElement("input");
+ cancelbutton.setAttribute("type","button");
+ cancelbutton.setAttribute("value","Close");
+ cancelbutton.setAttribute("onclick","cancel_disambiguate()");
+ var tryagainbutton = document.createElement("input");
+ tryagainbutton.setAttribute("type","button");
+ if (new_curcp > 0) {
+ tryagainbutton.setAttribute("value","None of the above");
+ } else {
+ tryagainbutton.setAttribute("value","Restart");
+ }
+ tryagainbutton.setAttribute("onclick","next_cp(" + new_curcp + ")");
+
+ disambcell.appendChild(okbutton);
+ disambcell.appendChild(tryagainbutton);
+ disambcell.appendChild(cancelbutton);
+
+ //disable_toparea();
+
+ //matita.disambMode = true;
+ updateSide();
+
+}
+
+function show_failures() {
+
+ var choice = document.getElementsByName("choice")[get_checked_index("choice")];
+ var cpno = parseInt(choice.getAttribute("choicepointno"));
+ var choiceno = parseInt(choice.getAttribute("choiceno"));
+ var choicedesc = choice.getAttribute("desc");
+
+ var title = "<H3>Error diagnostics</H3>";
+ var subtitle;
+ if (is_defined(choicedesc) && choicedesc != null) {
+ subtitle = "<p>Errors at node " + cpno + " = " + choicedesc + "</p>";
+ } else {
+ subtitle = "<p>Global errors:</p>";
+ }
+
+ disambcell.innerHTML = title + subtitle;
+ var failures = get_failure_opts(cpno,choiceno);
+ for (var i = 0;i < failures.length;i++) {
+ disambcell.appendChild(failures[i]);
+ disambcell.appendChild(document.createTextNode(failures[i].getAttribute("title")));
+ disambcell.appendChild(document.createElement("br"));
+ }
+
+ var okbutton = document.createElement("input");
+ okbutton.setAttribute("type","button");
+ okbutton.setAttribute("value","Show error loc");
+ okbutton.setAttribute("onclick","show_err()");
+ var cancelbutton = document.createElement("input");
+ cancelbutton.setAttribute("type","button");
+ cancelbutton.setAttribute("value","Close");
+ cancelbutton.setAttribute("onclick","cancel_disambiguate()");
+ var backbutton = document.createElement("input");
+ backbutton.setAttribute("type","button");
+ backbutton.setAttribute("value","<< Go back");
+ backbutton.setAttribute("onclick","next_cp(" + cpno + ")");
+
+ disambcell.appendChild(backbutton);
+ disambcell.appendChild(okbutton);
+ disambcell.appendChild(cancelbutton);
+
+}
+
+function show_err() {
+ var radios = document.getElementsByName("failure");
+ for (i = 0; i < radios.length; i++) {
+ if (radios[i].checked) {
+ var start = radios[i].getAttribute("start");
+ var stop = radios[i].getAttribute("stop");
+ var title = radios[i].getAttribute("title");
+ var unlockedtxt = matita.unlockedbackup;
+ var pre = unlockedtxt.substring(0,start).matita_to_html();
+ var mid = unlockedtxt.substring(start,stop).matita_to_html();
+ var post = unlockedtxt.substring(stop).matita_to_html();
+ unlocked.innerHTML = pre +
+ "<span class=\"error\" title=\"Disambiguation failure\">" +
+ mid + "</span>" + post;
+ break;
+ }
+ }
+}
+