]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic/test.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / cic / test.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 open Printf
27
28 let _ =
29   Helm_registry.set "getter.mode" "remote";
30   Helm_registry.set "getter.url" "http://mowgli.cs.unibo.it:58081/"
31
32 let body_RE = Str.regexp "^.*\\.body$"
33 let con_RE = Str.regexp "^.*\\.con$"
34
35 let unlink f =
36   if Sys.file_exists f then
37     Unix.unlink f
38
39 let rec parse uri tmpfile1 tmpfile2 =
40 (*prerr_endline (sprintf "%s %s" tmpfile1 (match tmpfile2 with None -> "None" | Some f -> "Some " ^ f));*)
41   (try
42     let uri' = UriManager.uri_of_string uri in
43     let time_new0 = Unix.gettimeofday () in
44 (*    let obj_new = CicPushParser.CicParser.annobj_of_xml tmpfile1 tmpfile2 in*)
45     let obj_new = CicParser.annobj_of_xml uri' tmpfile1 tmpfile2 in
46     let time_new1 = Unix.gettimeofday () in
47
48     let time_old0 = Unix.gettimeofday () in
49     ignore (Unix.system (sprintf "gunzip -c %s > test.tmp && mv test.tmp %s"
50       tmpfile1 tmpfile1));
51     (match tmpfile2 with
52     | Some tmpfile2 ->
53         ignore (Unix.system (sprintf "gunzip -c %s > test.tmp && mv test.tmp %s"
54           tmpfile2 tmpfile2));
55     | None -> ());
56     let obj_old = CicPxpParser.CicParser.annobj_of_xml uri' tmpfile1 tmpfile2 in
57     let time_old1 = Unix.gettimeofday () in
58
59     let time_old = time_old1 -. time_old0 in
60     let time_new = time_new1 -. time_new0 in
61     let are_equal = (obj_old = obj_new) in
62     printf "%s\t%b\t%f\t%f\t%f\n"
63       uri are_equal time_old time_new (time_new /. time_old *. 100.);
64     flush stdout;
65   with
66   | CicParser.Getter_failure ("key_not_found", uri)
67     when Str.string_match body_RE uri 0 ->
68       parse uri tmpfile1 None
69   | CicParser.Parser_failure msg ->
70       printf "%s FAILED (%s)\n" uri msg; flush stdout)
71
72 let _ =
73   try
74     while true do
75       let uri = input_line stdin in
76       let tmpfile1 = Http_getter.getxml uri in
77       let tmpfile2 =
78         if Str.string_match con_RE uri 0 then begin
79           Some (Http_getter.getxml (uri ^ ".body"))
80         end else
81           None
82       in
83       parse uri tmpfile1 tmpfile2
84     done
85   with End_of_file -> ()
86