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 ("wget -c -P " ^ 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)
60 let module C = Configuration in
61 let fd = open_in C.servers_file in
62 let servers = ref [] in
65 servers := (input_line fd) :: !servers
69 let urls_of_uris = mk_urls_of_uris (List.rev !servers) in
70 (try Sys.remove (C.uris_dbm ^ ".db") with _ -> ()) ;
72 Dbm.opendbm C.uris_dbm [Dbm.Dbm_wronly ; Dbm.Dbm_create] 0o660
74 MapOfStrings.iter (fun uri url -> Dbm.add dbm uri url) urls_of_uris ;
78 (* url_of_uri : uri -> url *)
80 let dbm = Dbm.opendbm Configuration.uris_dbm [Dbm.Dbm_rdonly] 0o660 in
81 let url = Dbm.find dbm (UriManager.string_of_uri uri) in
86 let filedir_of_uri uri =
87 let fn = UriManager.buri_of_uri uri in
88 let fn' = Str.replace_first (Str.regexp ".*:") Configuration.dest fn in
92 let name_and_ext_of_uri uri =
93 let str = UriManager.string_of_uri uri in
94 Str.replace_first (Str.regexp ".*/") "" str
97 (* get_file : uri -> filename *)
99 let dir = filedir_of_uri uri in
100 let fn = dir ^ "/" ^ name_and_ext_of_uri uri ^ ".xml" in
101 if not (Sys.file_exists fn) then
103 let url = url_of_uri uri in
104 (*CSC: use -q for quiet mode *)
105 if Sys.command ("wget -c -P " ^ dir ^ " \"" ^ url ^"\"") <> 0
107 raise (ErrorGetting url) ;
112 (* get : uri -> filename *)
113 (* If uri is the URI of an annotation, the annotated object is processed *)
115 let module U = UriManager in
118 (Str.replace_first (Str.regexp "\.ann$") ""
119 (Str.replace_first (Str.regexp "\.types$") "" (U.string_of_uri uri))))
122 (* get_ann : uri -> filename *)
123 (* If uri is the URI of an annotation, the annotation file is processed *)
124 let get_ann = get_file;;
126 (* get_ann_file_name_and_uri : uri -> filename * annuri *)
127 (* If given an URI, it returns the name of the corresponding *)
128 (* annotation file and the annotation uri *)
129 let get_ann_file_name_and_uri uri =
130 let module U = UriManager in
131 let uri = U.string_of_uri uri in
134 if Str.string_match (Str.regexp ".*\.ann$") uri 0 then
140 let dir = filedir_of_uri annuri in
141 let fn = dir ^ "/" ^ name_and_ext_of_uri annuri ^ ".xml" in