let include_paths = ["/home/barolo/matitaB/matita/lib"];;
-(* lista [meta n., goal; meta n., goal; ... ] *)
-(* "item1#item2#...#" *)
-
+(* <metasenv>
+ * <meta number="...">
+ * <metaname>...</metaname>
+ * <goal>...</goal>
+ * </meta>
+ *
+ * ...
+ * </metasenv> *)
let output_status s =
let _,_,metasenv,subst,_ = s#obj in
let render_switch = function
let markup =
if is_loc then
(match depth, pos with
- | 0, 0 -> "<B>" ^ (render_switch sw) ^ "</B> "
+ | 0, 0 -> "<B>" ^ (render_switch sw) ^ "</B>"
| 0, _ ->
Printf.sprintf "<B>|<SUB>%d</SUB>: %s</B>" pos (render_switch sw)
| 1, pos when Stack.head_tag s#stack = `BranchTag ->
| _ -> render_switch sw)
else render_switch sw
in
- let markup = Netencoding.Url.encode ~plus:false markup in
- let txt0 = Netencoding.Url.encode ~plus:false (sequent sw) in
- (string_of_int metano ^ "|" ^ markup ^ "|" ^ txt0 ^ "#" ^ acc)
+ let markup =
+ Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () markup in
+ let markup = "<metaname>" ^ markup ^ "</metaname>" in
+ let sequent =
+ Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () (sequent sw)
+ in
+ let txt0 = "<goal>" ^ sequent ^ "</goal>" in
+ "<meta number=\"" ^ (string_of_int metano) ^ "\">" ^ markup ^
+ txt0 ^ "</meta>" ^ acc
in
- Stack.fold
- ~env:(render_sequent true) ~cont:(render_sequent false)
- ~todo:(render_sequent false) "" s#stack
+ let res = "<metasenv>" ^
+ (Stack.fold
+ ~env:(render_sequent true) ~cont:(render_sequent false)
+ ~todo:(render_sequent false) "" s#stack) ^
+ "</metasenv>"
+ in
+ prerr_endline ("sending metasenv:\n" ^ res); res
;;
(* let html_of_status s =
prerr_endline "getting 'file' argument";
let filename = List.assoc "file" req#params_GET in
prerr_endline ("reading file " ^ filename);
- let body = read_file filename in
+ let body =
+ Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false ()
+ (read_file filename) in
+ prerr_endline ("sending:\nBEGIN\n" ^ body ^ "\nEND");
+ let body = "<file>" ^ body ^ "</file>" in
let _,baseuri,_,_ =
Librarian.baseuri_of_script ~include_paths:[] filename
in
(0,"",txt), Printexc.to_string e, `Code 500)
in
(* prerr_endline ("server response:\n" ^ txt); *)
- let body = (string_of_int parsed_len) ^ "@" ^ txt in
- Http_daemon.respond ~code ~body outchan
+ let body =
+ "<response><parsed length=\"" ^ (string_of_int parsed_len) ^ "\" />" ^ txt
+ ^ "</response>"
+ in (prerr_endline ("sending advance response:\n" ^ body);
+ Http_daemon.respond ~code ~body outchan)
| "/bottom" ->
let script = req#body in
prerr_endline ("body length = " ^ (string_of_int (String.length script)));
(0,txt), Printexc.to_string e, `Code 500)
in
(* prerr_endline ("server response:\n" ^ txt); *)
- let body = (string_of_int parsed_len) ^ "@" ^ txt in
- Http_daemon.respond ~code ~body outchan
+ let body =
+ "<parsed length=\"" ^ (string_of_int parsed_len) ^ "\" />" ^ txt
+ in Http_daemon.respond ~code ~body outchan
| "/retract" ->
(try
let body = retract () in
{ Http_daemon.default_spec with
callback = callback;
port = 9999;
- mode = `Thread;
+ mode = `Single (*`Thread *) ;
}
;;
return (tripletmap (function (a,b,c) { return (c); }, p));
}
-function populate_goalarray(txt)
+function populate_goalarray(menv)
{
- if (txt == "") {
+ debug("metasenv.length = " + menv.length);
+ if (menv.length == 0) {
try {
hideSequent();
} catch (err) { };
} else {
showSequent();
- debug("populate with '" + txt + "'");
goalarray = new Array();
metalist = listnil();
var tmp_goallist = "";
- listiter (function(item)
- {
- debug ("item is '" + item + "'");
- tripletmap (function(a,ahtml,b) {
- debug ("found meta n. " + a);
- debug ("found goal\nBEGIN" + unescape(b) + "\nEND");
- goalarray[a] = unescape(b);
- tmp_goallist = " <A href=\"javascript:switch_goal(" + a + ")\">" + unescape(ahtml) + "</A>" + tmp_goallist;
- metalist = listcons(a,metalist);
- debug ("goalarray[\"" + a + "\"] = " + goalarray[a]);
- },item);
- }, txt);
- // metalist = listmap (p13,txt);
+ for (i = 0; i < menv.length; i++) {
+ metano = menv[i].getAttribute("number");
+ metaname = menv[i].childNodes[0].childNodes[0].data;
+ goal = menv[i].childNodes[1].childNodes[0].data;
+ debug ("found meta n. " + metano);
+ debug ("found goal\nBEGIN" + goal + "\nEND");
+ goalarray[metano] = goal;
+ tmp_goallist = " <A href=\"javascript:switch_goal(" + metano + ")\">" + metaname + "</A>" + tmp_goallist;
+ metalist = listcons(metano,metalist);
+ debug ("goalarray[\"" + metano + "\"] = " + goalarray[metano]);
+ }
goals.innerHTML = tmp_goallist;
debug("new metalist is '" + metalist + "'");
if (is_nil(metalist)) {
stat = req.status;
stxt = req.statusText;
if(stat == 200)
- {
- processResponse(req.responseText);
+ {
+ debug(req.responseText);
+ if (window.DOMParser) {
+ parser=new DOMParser();
+ xmlDoc=parser.parseFromString(req.responseText,"text/xml");
+ }
+ else // Internet Explorer
+ {
+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async="false";
+ xmlDoc.loadXML(req.responseText);
+ }
+ processResponse(xmlDoc);
} else {
- processResponse();
+ processResponse();
}
- // resume();
}
};
req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
function advanceForm1()
{
- processor = function(responseText) {
- if (is_defined(responseText)) {
+ processor = function(xml) {
+ if (is_defined(xml)) {
// debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
len2 = len0 - len1;
- metasenv = response[1];
- populate_goalarray(response[1]);
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
statements = listcons(len2,statements);
unlocked.scrollIntoView(true);
} else {
function gotoBottom()
{
- processor = function(responseText) {
- if (is_defined(responseText)) {
+ processor = function(xml) {
+ if (is_defined(xml)) {
// debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
- len0 = unlocked.innerHTML.length;
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
+ len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
unparsedtxt = unescaped.substr(len);
locked.innerHTML = locked.innerHTML + parsedtxt;
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
- len = len0 - len1;
- populate_goalarray(response[1]);
- statements = listcons(len,statements);
- unlocked.scrollIntoView(true);
+ len2 = len0 - len1;
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
+ statements = listcons(len2,statements);
+ unlocked.scrollIntoView(true);
} else {
debug("goto bottom failed");
}
if (!is_defined(offset)) {
offset = getCursorPos();
}
- processor = function(responseText) {
- if (is_defined(responseText)) {
- // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
- response = responseText.split("@");
- len = parseInt(response[0]);
+ processor = function(xml) {
+ if (is_defined(xml)) {
+ // debug("goto pos: received response\nBEGIN\n" + req.responseText + "\nEND");
+ len = parseInt(xml.getElementsByTagName("parsed")[0].getAttribute("length"));
len0 = unlocked.innerHTML.length;
unescaped = unlocked.innerHTML.unescapeHTML();
parsedtxt = unescaped.substr(0,len);
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
len2 = len0 - len1;
+ metasenv = xml.getElementsByTagName("meta");
+ // populate_goalarray(metasenv);
statements = listcons(len2,statements);
- metasenv = response[1];
+ unlocked.scrollIntoView(true);
// la populate non andrebbe fatta a ogni passo
if (offset <= len) {
- populate_goalarray(response[1]);
+ populate_goalarray(metasenv);
resume();
} else {
gotoPos(offset - len);
function retract()
{
- processor = function(responseText) {
- if (typeof responseText != "undefined") {
- debug("retract: received response\nBEGIN\n" + responseText + "\nEND");
+ processor = function(xml) {
+ if (typeof xml != "undefined") {
+ // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
statementlen = parseInt(listhd(statements));
statements = listtl(statements);
lockedlen = locked.innerHTML.length - statementlen;
statement = locked.innerHTML.substr(lockedlen, statementlen);
locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
unlocked.innerHTML = statement + unlocked.innerHTML;
- populate_goalarray(responseText);
+ metasenv = xml.getElementsByTagName("meta");
+ populate_goalarray(metasenv);
unlocked.scrollIntoView(true);
} else {
debug("retract failed");
function openFile()
{
- processor = function(responseText)
+ processor = function(xml)
{
- if (responseText) {
+ if (is_defined(xml)) {
locked.innerHTML = "";
- unlocked.innerHTML = responseText;
+ unlocked.innerHTML = xml.documentElement.firstChild.data;
} else {
debug("file open failed");
}