1 (******************************************************************************)
5 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
8 (******************************************************************************)
10 exception ErrorGetting of string;;
12 module OrderedStrings =
15 let compare (s1 : t) (s2 : t) = compare s1 s2
19 module MapOfStrings = Map.Make(OrderedStrings);;
22 let module C = Configuration in
23 if Sys.command ("./mywget " ^ C.tmpdir ^ " " ^ url ^ "/\"" ^
24 C.indexname ^ "\"") <> 0
26 raise (ErrorGetting url) ;
27 let tmpfilename = C.tmpdir ^ "/" ^ C.indexname in
28 let fd = open_in tmpfilename in
32 uris := (input_line fd) :: !uris
34 [] (* only to make the compiler happy *)
37 Sys.remove tmpfilename ;
41 (* mk_urls_of_uris list_of_servers_base_urls *)
42 let rec mk_urls_of_uris =
44 [] -> MapOfStrings.empty
46 let map = mk_urls_of_uris tl in
47 let uris = read_index he in
49 let url = uri ^ ".xml" in
50 let url' = Str.replace_first (Str.regexp "cic:") he url in
51 let url'' = Str.replace_first (Str.regexp "theory:") he url' in
55 (fun uri m -> MapOfStrings.add uri (url_of_uri uri) m)
59 exception PerlGetterNotResponding;;
62 let module C = Configuration in
63 let fd = open_in C.servers_file in
64 let servers = ref [] in
67 servers := (input_line fd) :: !servers
71 let urls_of_uris = mk_urls_of_uris (List.rev !servers) in
72 (try Sys.remove (C.uris_dbm ^ ".db") with _ -> ()) ;
74 Dbm.opendbm C.uris_dbm [Dbm.Dbm_wronly ; Dbm.Dbm_create] 0o660
76 MapOfStrings.iter (fun uri url -> Dbm.add dbm uri url) urls_of_uris ;
78 (* Inform also the Perl-getter *)
79 if Sys.command ("wget -O /dev/null http://localhost:8081/update") <> 0
81 raise PerlGetterNotResponding ;
84 (* url_of_uri : uri -> url *)
86 let dbm = Dbm.opendbm Configuration.uris_dbm [Dbm.Dbm_rdonly] 0o660 in
87 let url = Dbm.find dbm (UriManager.string_of_uri uri) in
92 let filedir_of_uri uri =
93 let fn = UriManager.buri_of_uri uri in
94 let fn' = Str.replace_first (Str.regexp ".*:") Configuration.dest fn in
98 let name_and_ext_of_uri uri =
99 let str = UriManager.string_of_uri uri in
100 Str.replace_first (Str.regexp ".*/") "" str
103 (* get_file : uri -> filename *)
105 let dir = filedir_of_uri uri in
106 let fn = dir ^ "/" ^ name_and_ext_of_uri uri ^ ".xml" in
107 if not (Sys.file_exists fn) then
109 let url = url_of_uri uri in
110 (*CSC: use -q for quiet mode *)
111 if Sys.command ("./mywget " ^ dir ^ " \"" ^ url ^"\"") <> 0
113 raise (ErrorGetting url) ;
118 (* get : uri -> filename *)
119 (* If uri is the URI of an annotation, the annotated object is processed *)
121 let module U = UriManager in
124 (Str.replace_first (Str.regexp "\.types$") ""
125 (Str.replace_first (Str.regexp "\.ann$") "" (U.string_of_uri uri))))
128 (* get_ann : uri -> filename *)
129 (* If uri is the URI of an annotation, the annotation file is processed *)
130 let get_ann = get_file;;
132 (* get_ann_file_name_and_uri : uri -> filename * annuri *)
133 (* If given an URI, it returns the name of the corresponding *)
134 (* annotation file and the annotation uri *)
135 let get_ann_file_name_and_uri uri =
136 let module U = UriManager in
137 let uri = U.string_of_uri uri in
140 if Str.string_match (Str.regexp ".*\.ann$") uri 0 then
146 let dir = filedir_of_uri annuri in
147 let fn = dir ^ "/" ^ name_and_ext_of_uri annuri ^ ".xml" in