]> matita.cs.unibo.it Git - helm.git/blob - components/binaries/utilities/test_xml_parser.ml
matita 0.5.1 tagged
[helm.git] / components / binaries / utilities / test_xml_parser.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 let _ =
31   Helm_registry.set "getter.mode" "remote";
32   Helm_registry.set "getter.url" "http://mowgli.cs.unibo.it:58081/"
33
34 let body_RE = Str.regexp "^.*\\.body$"
35 let con_RE = Str.regexp "^.*\\.con$"
36
37 let unlink f =
38   if Sys.file_exists f then
39     Unix.unlink f
40
41 let rec parse uri tmpfile1 tmpfile2 =
42 (*prerr_endline (sprintf "%s %s" tmpfile1 (match tmpfile2 with None -> "None" | Some f -> "Some " ^ f));*)
43   (try
44     let uri' = UriManager.uri_of_string uri in
45     let time_new0 = Unix.gettimeofday () in
46 (*    let obj_new = CicPushParser.CicParser.annobj_of_xml tmpfile1 tmpfile2 in*)
47     let obj_new = CicParser.annobj_of_xml uri' tmpfile1 tmpfile2 in
48     let time_new1 = Unix.gettimeofday () in
49
50     let time_old0 = Unix.gettimeofday () in
51     ignore (Unix.system (sprintf "gunzip -c %s > test.tmp && mv test.tmp %s"
52       tmpfile1 tmpfile1));
53     (match tmpfile2 with
54     | Some tmpfile2 ->
55         ignore (Unix.system (sprintf "gunzip -c %s > test.tmp && mv test.tmp %s"
56           tmpfile2 tmpfile2));
57     | None -> ());
58     let obj_old = CicPxpParser.CicParser.annobj_of_xml uri' tmpfile1 tmpfile2 in
59     let time_old1 = Unix.gettimeofday () in
60
61     let time_old = time_old1 -. time_old0 in
62     let time_new = time_new1 -. time_new0 in
63     let are_equal = (obj_old = obj_new) in
64     printf "%s\t%b\t%f\t%f\t%f\n"
65       uri are_equal time_old time_new (time_new /. time_old *. 100.);
66     flush stdout;
67   with
68   | CicParser.Getter_failure ("key_not_found", uri)
69     when Str.string_match body_RE uri 0 ->
70       parse uri tmpfile1 None
71   | CicParser.Parser_failure msg ->
72       printf "%s FAILED (%s)\n" uri msg; flush stdout)
73
74 let _ =
75   try
76     while true do
77       let uri = input_line stdin in
78       let tmpfile1 = Http_getter.getxml uri in
79       let tmpfile2 =
80         if Str.string_match con_RE uri 0 then begin
81           Some (Http_getter.getxml (uri ^ ".body"))
82         end else
83           None
84       in
85       parse uri tmpfile1 tmpfile2
86     done
87   with End_of_file -> ()
88