1 (* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
33 (******************************************************************************)
35 exception ErrorGetting of string;;
37 module OrderedStrings =
40 let compare (s1 : t) (s2 : t) = compare s1 s2
44 module MapOfStrings = Map.Make(OrderedStrings);;
47 let module C = Configuration in
48 if Sys.command ("helm_wget " ^ C.tmpdir ^ " " ^ url ^ "/\"" ^
49 C.indexname ^ "\"") <> 0
51 raise (ErrorGetting url) ;
52 let tmpfilename = C.tmpdir ^ "/" ^ C.indexname in
53 let fd = open_in tmpfilename in
57 uris := (input_line fd) :: !uris
59 [] (* only to make the compiler happy *)
62 Sys.remove tmpfilename ;
66 (* mk_urls_of_uris list_of_servers_base_urls *)
67 let rec mk_urls_of_uris =
69 [] -> MapOfStrings.empty
71 let map = mk_urls_of_uris tl in
72 let uris = read_index he in
74 let url = uri ^ ".xml" in
75 let url' = Str.replace_first (Str.regexp "cic:") he url in
76 let url'' = Str.replace_first (Str.regexp "theory:") he url' in
80 (fun uri m -> MapOfStrings.add uri (url_of_uri uri) m)
84 exception PerlGetterNotResponding;;
87 let module C = Configuration in
88 let fd = open_in C.servers_file in
89 let servers = ref [] in
92 servers := (input_line fd) :: !servers
96 let urls_of_uris = mk_urls_of_uris (List.rev !servers) in
97 (try Sys.remove (C.uris_dbm ^ ".db") with _ -> ()) ;
99 Dbm.opendbm C.uris_dbm [Dbm.Dbm_wronly ; Dbm.Dbm_create] 0o660
101 MapOfStrings.iter (fun uri url -> Dbm.add dbm uri url) urls_of_uris ;
103 (* Inform also the Perl-getter *)
104 if Sys.command ("wget -O /dev/null http://localhost:8081/update") <> 0
106 raise PerlGetterNotResponding ;
109 (* url_of_uri : uri -> url *)
111 let dbm = Dbm.opendbm Configuration.uris_dbm [Dbm.Dbm_rdonly] 0o660 in
112 let url = Dbm.find dbm (UriManager.string_of_uri uri) in
117 let filedir_of_uri uri =
118 let fn = UriManager.buri_of_uri uri in
119 let fn' = Str.replace_first (Str.regexp ".*:") Configuration.dest fn in
123 let name_and_ext_of_uri uri =
124 let str = UriManager.string_of_uri uri in
125 Str.replace_first (Str.regexp ".*/") "" str
128 (* get_file : uri -> filename *)
130 let dir = filedir_of_uri uri in
131 let fn = dir ^ "/" ^ name_and_ext_of_uri uri ^ ".xml" in
132 if not (Sys.file_exists fn) then
134 let url = url_of_uri uri in
135 (*CSC: use -q for quiet mode *)
136 if Sys.command ("helm_wget " ^ dir ^ " \"" ^ url ^"\"") <> 0
138 raise (ErrorGetting url) ;
143 (* get : uri -> filename *)
144 (* If uri is the URI of an annotation, the annotated object is processed *)
146 let module U = UriManager in
149 (Str.replace_first (Str.regexp "\.types$") ""
150 (Str.replace_first (Str.regexp "\.ann$") "" (U.string_of_uri uri))))
153 (* get_ann : uri -> filename *)
154 (* If uri is the URI of an annotation, the annotation file is processed *)
155 let get_ann = get_file;;
157 (* get_ann_file_name_and_uri : uri -> filename * annuri *)
158 (* If given an URI, it returns the name of the corresponding *)
159 (* annotation file and the annotation uri *)
160 let get_ann_file_name_and_uri uri =
161 let module U = UriManager in
162 let uri = U.string_of_uri uri in
165 if Str.string_match (Str.regexp ".*\.ann$") uri 0 then
171 let dir = filedir_of_uri annuri in
172 let fn = dir ^ "/" ^ name_and_ext_of_uri annuri ^ ".xml" in