]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/interface/getter.ml
This commit was manufactured by cvs2svn to create tag 'v0_0_2'.
[helm.git] / helm / interface / getter.ml
index 21c1901a183722c4b2ac040964827f7353c4e06f..85e64117b6be0fe66366d4eaea95c811364e8617 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                                 *)
@@ -20,7 +45,7 @@ module MapOfStrings = Map.Make(OrderedStrings);;
 
 let read_index url =
  let module C = Configuration in
-  if Sys.command ("wget -c -P " ^ C.tmpdir ^ " " ^ url ^ "/\"" ^
+  if Sys.command ("helm_wget " ^ C.tmpdir ^ " " ^ url ^ "/\"" ^
    C.indexname ^ "\"") <> 0
   then
    raise (ErrorGetting url) ;
@@ -29,7 +54,12 @@ let read_index url =
    let uris = ref [] in
     try
      while true do
-      uris := (input_line fd) :: !uris
+      let (uri,comp) =
+       match (Str.split (Str.regexp "[ \t]+") (input_line fd)) with
+         [uri] -> (uri,"")
+       | [uri;comp] -> (uri,".gz")
+      in
+       uris := (uri,comp) :: !uris
      done ;
      [] (* only to make the compiler happy *)
     with
@@ -45,17 +75,19 @@ let rec mk_urls_of_uris =
   | 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_of_uri (uri,comp) =
+        let url = uri  ^ ".xml" ^ comp 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)
+         (fun (uri,comp) m -> MapOfStrings.add uri (url_of_uri (uri,comp)) m)
          uris map
 ;;
 
+exception PerlGetterNotResponding;;
+
 let update () =
  let module C = Configuration in
   let fd = open_in C.servers_file in
@@ -72,7 +104,11 @@ let update () =
        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
+       Dbm.close dbm ;
+       (* Inform also the Perl-getter *)
+       if Sys.command ("wget -O /dev/null http://localhost:8081/update") <> 0
+       then
+        raise PerlGetterNotResponding ;
 ;;
 
 (* url_of_uri : uri -> url *)
@@ -102,7 +138,7 @@ let get_file uri =
     begin
      let url = url_of_uri uri in
       (*CSC: use -q for quiet mode *)
-      if Sys.command ("wget -c -P " ^ dir ^ " \"" ^ url ^"\"") <> 0
+      if Sys.command ("helm_wget " ^ dir ^ " \"" ^ url ^"\"") <> 0
       then
        raise (ErrorGetting url) ;
     end ;
@@ -115,8 +151,8 @@ let get uri =
  let module U = UriManager in
   get_file
    (U.uri_of_string
-    (Str.replace_first (Str.regexp "\.ann$") ""
-     (Str.replace_first (Str.regexp "\.types$") "" (U.string_of_uri uri))))
+    (Str.replace_first (Str.regexp "\.types$") ""
+     (Str.replace_first (Str.regexp "\.ann$") "" (U.string_of_uri uri))))
 ;;
 
 (* get_ann : uri -> filename *)