X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FgTopLevel%2FxmlDiff.ml;h=2b9806c44b2de0f3c39ca40c88af25b0f9d3e71d;hb=faf362d25c28585add8c951300da0a54993d0d67;hp=e162100285afeee0fc8e5f014785c2121d0ecbd7;hpb=bb83d8839dddd6e6071f82cdbb5629c5125049de;p=helm.git diff --git a/helm/gTopLevel/xmlDiff.ml b/helm/gTopLevel/xmlDiff.ml index e16210028..2b9806c44 100644 --- a/helm/gTopLevel/xmlDiff.ml +++ b/helm/gTopLevel/xmlDiff.ml @@ -53,7 +53,7 @@ let highlight_node ?(color="yellow") (doc: Gdome.document) (n: Gdome.node) = ~namespaceURI:(Some (Gdome.domString mathmlns)) ~qualifiedName:(Gdome.domString "m:mstyle") in - highlighter#setAttribute ~name:(Gdome.domString "background") + highlighter#setAttribute ~name:(Gdome.domString "mathbackground") ~value:(Gdome.domString color) ; highlighter#setAttributeNS ~namespaceURI:(Some (Gdome.domString xmldiffns)) @@ -64,8 +64,9 @@ let highlight_node ?(color="yellow") (doc: Gdome.document) (n: Gdome.node) = None -> assert false | Some p -> p in + ignore + (parent#replaceChild ~oldChild:n ~newChild:(highlighter :> Gdome.node)) ; ignore (highlighter#appendChild n) ; - ignore (parent#appendChild (highlighter :> Gdome.node)) ; (highlighter :> Gdome.node) in let rec find_mstylable_node n = @@ -96,6 +97,18 @@ prerr_endline ("@@@ find_mstylable_node salgo da " ^ match n#get_localName with highlighter ;; +let iter_children ~f (n:Gdome.node) = + let rec aux = + function + None -> () + | Some n -> + let sibling = n#get_nextSibling in + (f n) ; + aux sibling + in + aux n#get_firstChild +;; + let highlight_nodes ~xrefs (doc:Gdome.document) = let highlighted = ref [] in let rec aux (n:Gdome.element) = @@ -108,14 +121,10 @@ let highlight_nodes ~xrefs (doc:Gdome.document) = highlighted := (highlight_node ~color:"#00ff00"(* light green *) doc (n :> Gdome.node)):: !highlighted ; - let children = n#get_childNodes in - for i = 0 to children#get_length - 1 do - match children#item i with - None -> assert false - | Some n -> - if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then - aux (new Gdome.element_of_node n) - done + iter_children (n :> Gdome.node) + ~f:(function n -> + if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then + aux (new Gdome.element_of_node n)) in aux doc#get_documentElement ; !highlighted @@ -284,8 +293,10 @@ prerr_endline !debugs ; done | _,_ -> assert false end ; +(* debugging only let fchildren = f#get_childNodes in let tchildren = t#get_childNodes in +*) let rec dumb_diff = function [],[] -> () @@ -305,31 +316,33 @@ prerr_endline ("XML_DIFF: appendo i nodi residui " ^ String.concat ", " (List.ma prerr_endline ("XML_DIFF: cancello i nodi residui " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") tl1)) ; List.iter (function n -> ignore (f#removeChild n)) tl1 in - let node_list_of_nodeList nl = - let rec aux i = - match nl#item ~index:i with + let node_list_of_nodeList n = + let rec aux = + function None -> [] | Some n when n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE or n#get_nodeType = GdomeNodeTypeT.TEXT_NODE -> - n::(aux (i+1)) + n::(aux n#get_nextSibling) | Some n -> prerr_endline ("XML_DIFF: mi sto perdendo i nodi di tipo " ^ string_of_int (Obj.magic n#get_nodeType)) ; - aux (i+1) + aux n#get_nextSibling in - aux 0 + aux n#get_firstChild in +(* debugging stuff only for i = 0 to fchildren#get_length - 1 do match fchildren#item i with None -> prerr_endline "EUREKA: ma siamo matti?" |Some n -> match n#get_nodeType with GdomeNodeTypeT.ATTRIBUTE_NODE -> prerr_endline "EUREKA attr" | GdomeNodeTypeT.CDATA_SECTION_NODE -> prerr_endline "EUREKA text" | GdomeNodeTypeT.DOCUMENT_FRAGMENT_NODE -> prerr_endline "EUREKA document fragment" | _ -> prerr_endline ("EUREKA " ^ string_of_int (Obj.magic n#get_nodeType)) done ; -prerr_endline("XML_DIFF: from ha " ^ string_of_int fchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList fchildren)) ^ " figli"); -prerr_endline("XML_DIFF: to ha " ^ string_of_int tchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList tchildren)) ^ " figli"); +prerr_endline("XML_DIFF: from ha " ^ string_of_int fchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList f)) ^ " figli"); +prerr_endline("XML_DIFF: to ha " ^ string_of_int tchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList t)) ^ " figli"); prerr_endline ("XML_DIFF: chiamo dumb_diff su " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList fchildren)) ^ " e " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList tchildren))) ; +*) dumb_diff - (node_list_of_nodeList fchildren, node_list_of_nodeList tchildren) + (node_list_of_nodeList f, node_list_of_nodeList t) | t1,t2,_,_,_,_ when (t1 = GdomeNodeTypeT.ELEMENT_NODE || t1 = GdomeNodeTypeT.TEXT_NODE) && (t2 = GdomeNodeTypeT.ELEMENT_NODE || t2 = GdomeNodeTypeT.TEXT_NODE) -> @@ -365,32 +378,28 @@ prerr_endline ("Rimpiazzo" ^ (match f#get_namespaceURI with Some s -> s#to_strin (d#get_documentElement :> Gdome.node) with (GdomeInit.DOMException (e,msg) as ex) -> -(* +(* CSC: Non si puo' per problemi di linking ;-( let module E = GdomeDOMExceptionT in *) prerr_endline ("DOM EXCEPTION: " ^ msg ^ " --- " ^ -string_of_int (Obj.magic e)) ; - raise ex - (* - match e with - E.NO_ERR -> "NO_ERR" - | E.INDEX_SIZE_ERR -> "INDEX_SIZE_ERR" - | E.DOMSTRING_SIZE_ERR -> "DOMSTRING_SIZE_ERR" - | E.HIERARCHY_REQUEST_ERR -> "HIERARCHY_REQUEST_ERR" - | E.WRONG_DOCUMENT_ERR -> "WRONG_DOCUMENT_ERR" - | E.INVALID_CHARACTER_ERR -> "INVALID_CHARACTER_ERR" - | E.NO_DATA_ALLOWED_ERR -> "NO_DATA_ALLOWER_ERR" - | E.NO_MODIFICATION_ALLOWED_ERR -> "NO_MODIFICATION_ALLOWED_ERR" - | E.NOT_FOUND_ERR -> "NOT_FOUND_ERR" - | E.NOT_SUPPORTED_ERR -> "NOT_SUPPORTED_ERR" - | E.INUSE_ATTRIBUTE_ERR -> "INUSE_ATTRIBUTE_ERR" - | E.INVALID_STATE_ERR -> "INVALID_STATE_ERR" - | E.SYNTAX_ERR -> "SYNTAX_ERR" - | E.INVALID_MODIFICATION_ERR -> "INVALID_MODIFICATION_ERR" - | E.NAMESPACE_ERR -> "NAMESPACE_ERR" - | E.INVALID_ACCESS_ERR -> "INVALID_ACCESS_ERR" -*) + match e with + GdomeDOMExceptionT.NO_ERR -> "NO_ERR" + | GdomeDOMExceptionT.INDEX_SIZE_ERR -> "INDEX_SIZE_ERR" + | GdomeDOMExceptionT.DOMSTRING_SIZE_ERR -> "DOMSTRING_SIZE_ERR" + | GdomeDOMExceptionT.HIERARCHY_REQUEST_ERR -> "HIERARCHY_REQUEST_ERR" + | GdomeDOMExceptionT.WRONG_DOCUMENT_ERR -> "WRONG_DOCUMENT_ERR" + | GdomeDOMExceptionT.INVALID_CHARACTER_ERR -> "INVALID_CHARACTER_ERR" + | GdomeDOMExceptionT.NO_DATA_ALLOWED_ERR -> "NO_DATA_ALLOWER_ERR" + | GdomeDOMExceptionT.NO_MODIFICATION_ALLOWED_ERR -> "NO_MODIFICATION_ALLOWED_ERR" + | GdomeDOMExceptionT.NOT_FOUND_ERR -> "NOT_FOUND_ERR" + | GdomeDOMExceptionT.NOT_SUPPORTED_ERR -> "NOT_SUPPORTED_ERR" + | GdomeDOMExceptionT.INUSE_ATTRIBUTE_ERR -> "INUSE_ATTRIBUTE_ERR" + | GdomeDOMExceptionT.INVALID_STATE_ERR -> "INVALID_STATE_ERR" + | GdomeDOMExceptionT.SYNTAX_ERR -> "SYNTAX_ERR" + | GdomeDOMExceptionT.INVALID_MODIFICATION_ERR -> "INVALID_MODIFICATION_ERR" + | GdomeDOMExceptionT.NAMESPACE_ERR -> "NAMESPACE_ERR" + | GdomeDOMExceptionT.INVALID_ACCESS_ERR -> "INVALID_ACCESS_ERR") | e -> prerr_endline "PROBLEMA" ; raise e