From: Stefano Zacchiroli Date: Thu, 15 Apr 2004 13:35:21 +0000 (+0000) Subject: - fixed dtd_base_urls implementation X-Git-Tag: dead_dir_walking~62 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=4cc248707314a05902ce8d70ceea1ac0541f9976;p=helm.git - fixed dtd_base_urls implementation - factorized a lot of code in document patching --- diff --git a/helm/ocaml/getter/http_getter_common.ml b/helm/ocaml/getter/http_getter_common.ml index b1f96d8bd..03f5c2a2a 100644 --- a/helm/ocaml/getter/http_getter_common.ml +++ b/helm/ocaml/getter/http_getter_common.ml @@ -72,56 +72,25 @@ let patch_xsl ?(via_http = true) () = in patch_include (patch_import line) -let patch_entity ?(via_http = true) () = - if via_http then - fun line -> - List.fold_left - (fun url s -> - Pcre.replace - ~pat:(sprintf "ENTITY (.*) SYSTEM\\s+\"(%s/)?" url) - ~templ:(sprintf "ENTITY $1 SYSTEM \"%s/getdtd?uri=" - (Lazy.force Http_getter_env.my_own_url)) - s) - line - (Lazy.force Http_getter_env.dtd_base_urls) - else - fun line -> - List.fold_left - (fun url s -> - Pcre.replace - ~pat:(sprintf "ENTITY (.*) SYSTEM\\s+\"(%s/)?" url) - ~templ:(sprintf "ENTITY $1 SYSTEM \"file://%s/" - (Lazy.force Http_getter_env.dtd_dir)) - s) - line - (Lazy.force Http_getter_env.dtd_base_urls) +let patch_system kind ?(via_http = true) () = + let rex = + Pcre.regexp (sprintf "%s (.*) SYSTEM\\s+\"((%s)/)?" kind + (String.concat "|" (Lazy.force Http_getter_env.dtd_base_urls))) + in + let templ = + if via_http then + sprintf "%s $1 SYSTEM \"%s/getdtd?uri=" kind + (Lazy.force Http_getter_env.my_own_url) + else + sprintf "%s $1 SYSTEM \"file://%s/" kind + (Lazy.force Http_getter_env.dtd_dir) + in + fun line -> Pcre.replace ~rex ~templ line -let patch_doctype ?(via_http = true) () = - if via_http then - fun line -> - List.fold_left - (fun url s -> - Pcre.replace - ~pat:(sprintf "DOCTYPE (.*) SYSTEM\\s+\"%s/" url) - ~templ:(sprintf "DOCTYPE $1 SYSTEM \"%s/getdtd?uri=" - (Lazy.force Http_getter_env.my_own_url)) - s) - line - (Lazy.force Http_getter_env.dtd_base_urls) - else - fun line -> - List.fold_left - (fun url s -> - Pcre.replace - ~pat:(sprintf "DOCTYPE (.*) SYSTEM\\s+\"%s/" url) - ~templ:(sprintf "DOCTYPE $1 SYSTEM \"file://%s/" - (Lazy.force Http_getter_env.my_own_url)) - s) - line - (Lazy.force Http_getter_env.dtd_base_urls) +let patch_entity = patch_system "ENTITY" +let patch_doctype = patch_system "DOCTYPE" let patch_dtd = patch_entity - let patch_xml ?via_http () line = patch_doctype ?via_http () (patch_entity ?via_http () line) diff --git a/helm/ocaml/getter/http_getter_misc.ml b/helm/ocaml/getter/http_getter_misc.ml index 6f612cc30..6db793369 100644 --- a/helm/ocaml/getter/http_getter_misc.ml +++ b/helm/ocaml/getter/http_getter_misc.ml @@ -198,7 +198,7 @@ let http_get url = try Some (Http_client.http_get url) with e -> - prerr_endline (sprintf + debug_print (sprintf "Warning: Http_client failed on url %s with exception: %s" url (Printexc.to_string e)); None