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 (* FEATURE MOVED TO HTTP_GETTER, Zack
38 module OrderedStrings =
41 let compare (s1 : t) (s2 : t) = compare s1 s2
47 (* FEATURE MOVED TO HTTP_GETTER, Zack
48 module MapOfStrings = Map.Make(OrderedStrings);;
51 (* FEATURE MOVED TO HTTP_GETTER, Zack
53 let module C = Configuration in
54 if Sys.command ("helm_wget " ^ C.tmp_dir ^ " " ^ url ^ "/\"" ^
55 C.indexname ^ "\"") <> 0
57 raise (ErrorGetting url) ;
58 let tmpfilename = C.tmp_dir ^ "/" ^ C.indexname in
59 let fd = open_in tmpfilename in
64 match (Str.split (Str.regexp "[ \t]+") (input_line fd)) with
66 | [uri;comp] -> (uri,".gz")
68 uris := (uri,comp) :: !uris
70 [] (* only to make the compiler happy *)
73 Sys.remove tmpfilename ;
78 (* FEATURE MOVED TO HTTP_GETTER, Zack
79 (* mk_urls_of_uris list_of_servers_base_urls *)
80 let rec mk_urls_of_uris =
82 [] -> MapOfStrings.empty
84 let map = mk_urls_of_uris tl in
85 let uris = read_index he in
86 let url_of_uri (uri,comp) =
87 let url = uri ^ ".xml" ^ comp in
88 let url' = Str.replace_first (Str.regexp "cic:") he url in
89 let url'' = Str.replace_first (Str.regexp "theory:") he url' in
93 (fun (uri,comp) m -> MapOfStrings.add uri (url_of_uri (uri,comp)) m)
98 exception PerlGetterNotResponding;;
100 (* FEATURE MOVED TO HTTP_GETTER, Zack
102 let module C = Configuration in
103 let fd = open_in C.servers_file in
104 let servers = ref [] in
107 servers := (input_line fd) :: !servers
111 let urls_of_uris = mk_urls_of_uris (List.rev !servers) in
112 (try Sys.remove (C.uris_dbm ^ ".db") with _ -> ()) ;
114 Dbm.opendbm C.uris_dbm [Dbm.Dbm_wronly ; Dbm.Dbm_create] 0o660
116 MapOfStrings.iter (fun uri url -> Dbm.add dbm uri url) urls_of_uris ;
118 (* Inform also the Perl-getter *)
119 if Sys.command ("wget -O /dev/null http://localhost:8081/update") <> 0
121 raise PerlGetterNotResponding ;
126 (* deliver update request to http_getter *)
127 ClientHTTP.send (Configuration.getter_url ^ "update")
130 (* url_of_uri : uri -> url *)
132 let dbm = Dbm.opendbm Configuration.uris_dbm [Dbm.Dbm_rdonly] 0o660 in
133 let url = Dbm.find dbm (UriManager.string_of_uri uri) in
138 let filedir_of_uri uri =
139 let fn = UriManager.buri_of_uri uri in
140 let fn' = Str.replace_first (Str.regexp ".*:") Configuration.dest fn in
144 let name_and_ext_of_uri uri =
145 let str = UriManager.string_of_uri uri in
146 Str.replace_first (Str.regexp ".*/") "" str
149 (* get_file : uri -> filename *)
151 let dir = filedir_of_uri uri in
152 let fn = dir ^ "/" ^ name_and_ext_of_uri uri ^ ".xml" in
153 if not (Sys.file_exists fn) then
155 let url = url_of_uri uri in
156 (*CSC: use -q for quiet mode *)
157 if Sys.command ("helm_wget " ^ dir ^ " \"" ^ url ^"\"") <> 0
159 raise (ErrorGetting url) ;
164 let raw_get = ClientHTTP.get_and_save
166 (* get : uri -> filename *)
167 (* If uri is the URI of an annotation, the annotated object is processed *)
169 let module U = UriManager in
172 (Str.replace_first (Str.regexp "\.types$") ""
173 (Str.replace_first (Str.regexp "\.ann$") "" (U.string_of_uri uri))))
176 (* get_ann : uri -> filename *)
177 (* If uri is the URI of an annotation, the annotation file is processed *)
178 let get_ann = get_file;;
180 (* get_ann_file_name_and_uri : uri -> filename * annuri *)
181 (* If given an URI, it returns the name of the corresponding *)
182 (* annotation file and the annotation uri *)
183 let get_ann_file_name_and_uri uri =
184 let module U = UriManager in
185 let uri = U.string_of_uri uri in
188 if Str.string_match (Str.regexp ".*\.ann$") uri 0 then
194 let dir = filedir_of_uri annuri in
195 let fn = dir ^ "/" ^ name_and_ext_of_uri annuri ^ ".xml" in