]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/interface/getter.ml
Initial revision
[helm.git] / helm / interface / getter.ml
index 39af104ccb3e38de26d64ec5e500d1e84cea7627..5b973f2efc302f2863569e6d1a03a7274393b175 100644 (file)
@@ -1,3 +1,28 @@
+(* Copyright (C) 2000, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
 (******************************************************************************)
 (*                                                                            *)
 (*                               PROJECT HELM                                 *)
 (*                                                                            *)
 (******************************************************************************)
 
-exception ErrorGetting of string;;
-
-module OrderedStrings =
- struct
-  type t = string
-  let compare (s1 : t) (s2 : t) = compare s1 s2
- end
-;;
-
-module MapOfStrings = Map.Make(OrderedStrings);;
 
-let read_index url =
- let module C = Configuration in
-  if Sys.command ("wget -c -P " ^ C.tmpdir ^ " " ^ url ^ "/\"" ^
-   C.indexname ^ "\"") <> 0
-  then
-   raise (ErrorGetting url) ;
-  let tmpfilename = C.tmpdir ^ "/" ^ C.indexname in
-   let fd = open_in tmpfilename in
-   let uris = ref [] in
-    try
-     while true do
-      uris := (input_line fd) :: !uris
-     done ;
-     [] (* only to make the compiler happy *)
-    with
-     End_of_file ->
-      Sys.remove tmpfilename ;
-      !uris
-;;
-
-(* mk_urls_of_uris list_of_servers_base_urls *)
-let rec mk_urls_of_uris =
- function
-    [] -> MapOfStrings.empty
-  | he::tl ->
-     let map = mk_urls_of_uris tl in
-      let uris = read_index he in
-       let url_of_uri uri =
-        let url = uri  ^ ".xml" in
-         let url' = Str.replace_first (Str.regexp "cic:") he url in
-         let url'' = Str.replace_first (Str.regexp "theory:") he url' in
-          url''
-       in
-        List.fold_right
-         (fun uri m -> MapOfStrings.add uri (url_of_uri uri) m)
-         uris map
-;;
+(*CSC: il getter _DEVE_ diventare un semplice "binding" a quello in Perl *)
 
 let update () =
- let module C = Configuration in
-  let fd = open_in C.servers_file in
-  let servers = ref [] in
-   try
-    while true do
-     servers := (input_line fd) :: !servers
-    done
-   with
-    End_of_file ->
-     let urls_of_uris = mk_urls_of_uris (List.rev !servers) in
-      (try Sys.remove (C.uris_dbm ^ ".db") with _ -> ()) ;
-      let dbm =
-       Dbm.opendbm C.uris_dbm [Dbm.Dbm_wronly ; Dbm.Dbm_create] 0o660
-      in
-       MapOfStrings.iter (fun uri url -> Dbm.add dbm uri url) urls_of_uris ;
-       Dbm.close dbm
+(* deliver update request to http_getter *)
+ ClientHTTP.send (Configuration.getter_url ^ "update")
 ;;
 
 (* url_of_uri : uri -> url *)
@@ -94,6 +59,8 @@ let name_and_ext_of_uri uri =
   Str.replace_first (Str.regexp ".*/") "" str
 ;;
 
+let raw_get = ClientHTTP.get_and_save
+
 (* get_file : uri -> filename *)
 let get_file uri =
  let dir = filedir_of_uri uri in
@@ -101,10 +68,10 @@ let get_file uri =
    if not (Sys.file_exists fn) then
     begin
      let url = url_of_uri uri in
-      (*CSC: use -q for quiet mode *)
-      if Sys.command ("wget -c -P " ^ dir ^ " \"" ^ url ^"\"") <> 0
-      then
-       raise (ErrorGetting url) ;
+      raw_get
+       (Configuration.getter_url ^ "getxml?uri=" ^
+        UriManager.string_of_uri uri ^ "&format=normal&patch_dtd=no"
+       ) fn
     end ;
    fn
 ;;