Add the results of reference implementations back.
[tatoo.git] / src / html.ml
index f049195..b35f17d 100644 (file)
@@ -34,10 +34,10 @@ let trace ?(msg="") nid r t d  =
 
 let finalize_node n r b =
   Hashtbl.replace final n (b,r)
-module K = 
+module K =
 struct
   type t = int * StateSet.t * StateSet.t
-  let hash (a,b,c) = HASHINT3(a, (b.StateSet.id :> int), (c.StateSet.id :> int) )
+  let hash (a,b,c) = HASHINT3(a, (b.StateSet.id :> int), (c.StateSet.id :> int))
   let equal ((a1,b1,c1) as x) ((a2,b2,c2) as y) =
     x == y || (a1 == a2 && b1 == b2 && c1 == c2)
 end
@@ -85,17 +85,35 @@ let gen_trace (type s) = fun auto t tree ->
       let marked, last_round = try Hashtbl.find final node_id with Not_found ->
         Printf.eprintf ">>> %i\n%!" node_id; false, !max_round;
       in
-      let pc = if !max_round == 0 then 1. else float_of_int last_round /. float_of_int !max_round in
       let scolor, tcolor =
-        let { sat ; todo; _ } = List.hd(M.find last_round m) in
-        let c = (last_round, sat, todo) in color c, text_color c
+        let { sat ; todo; _ } =
+          match M.find last_round m with
+            [] -> { sat = StateSet.empty; todo= StateSet.empty; msg = "ERROR" }
+          | [ e ] -> e
+          | l -> List.hd (List.tl (List.rev l))
+        in
+        let c = (last_round, StateSet.union sat todo, StateSet.empty) in
+        color c, text_color c
       in
       let tag = QName.to_string (T.tag tree node) in
       let lbox = (String.length tag + 2) * 10 in
       let s_node = "node" ^ (string_of_int node_id) in
-      fprintf osvg "<rect id=\"%s\" onclick=\"activate(\'%s\');\" x=\"%i\" y=\"%i\" width=\"%i\" height=\"20\" style=\"fill:%s;stroke:rgb(0,0,0)%s\"/>\n%!"
-        s_node s_node x y lbox scolor (if marked then ";stroke-width:4" else ";stroke-width:2;stroke-dasharray:2,2");
-      fprintf osvg "<text x=\"%i\" y=\"%i\" style=\"fill:%s;font-size:17;font-family:typewriter;\" onclick=\"activate(\'%s\');\" >%s</text>\n" (x+10) (y+15) tcolor s_node tag;
+      fprintf osvg
+        "<rect id=\"%s\" onclick=\"activate(\'%s\');\" x=\"%i\" y=\"%i\"\
+ width=\"%i\" height=\"20\" style=\"fill:%s;stroke:rgb(0,0,0)%s\"/>\n%!"
+        s_node
+        s_node
+        x y
+        lbox
+        scolor
+        (if marked
+         then ";stroke-width:4"
+         else ";stroke-width:2;stroke-dasharray:2,2");
+      fprintf osvg "<text x=\"%i\" y=\"%i\" style=\"fill:%s;font-size:17;\
+font-family:typewriter;\" onclick=\"activate(\'%s\');\" >%s</text>\n"
+        (x+10)
+        (y+15)
+        tcolor s_node tag;
       fprintf ohtml "data['%s'] = new Array();\n" s_node;
       M.iter
         (fun i l ->
@@ -108,10 +126,12 @@ let gen_trace (type s) = fun auto t tree ->
       let x_next = max (x+lbox) (maxw1+10) in
       if node != root then begin
         if node == T.first_child tree parent then
-          fprintf osvg  "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\" style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
+          fprintf osvg  "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\"\
+style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
             (x + lbox / 2) (y-20) (x + lbox / 2) (y);
         if next != T.nil then
-          fprintf osvg "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\" style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
+          fprintf osvg "<line x1=\"%i\" y1=\"%i\" x2=\"%i\" y2=\"%i\"\
+style=\"stroke:rgb(0,0,0);stroke-width:2\"/>\n"
             (x + lbox) (y+10) x_next (y+10);
       end;
       let maxw2, maxy2 = loop osvg ohtml next node x_next y in
@@ -146,7 +166,8 @@ Ata.print auto;
   d.innerHTML = msg;
   return;
   };\n";
-  fprintf ohtml "</script>\n<div id='svg'><svg width=\"%i\" height=\"%i\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"
+  fprintf ohtml "</script>\n<div id='svg'><svg width=\"%i\"\
+height=\"%i\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"
     maxw maxh;
   let fi = open_in "tests/trace/trace.svg" in
   try
@@ -160,5 +181,3 @@ Ata.print auto;
       pp_print_flush ohtml ();
       close_out ohtml_;
       close_in fi
-
-