From 3969a288b2c18b1b4da9a9941a8a3a77480dd4d1 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Wed, 6 Jul 2005 17:15:02 +0000 Subject: [PATCH] added index.theory handling --- helm/ocaml/getter/http_getter.ml | 52 +++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/helm/ocaml/getter/http_getter.ml b/helm/ocaml/getter/http_getter.ml index dd4e483fa..43c4be473 100644 --- a/helm/ocaml/getter/http_getter.ml +++ b/helm/ocaml/getter/http_getter.ml @@ -67,7 +67,7 @@ let showable_file_RE = Pcre.regexp "(\\.con|\\.ind|\\.var|\\.body|\\.types|\\.proof_tree)$" let xml_suffix = ".xml" -let theory_suffix = ".theory" ^ xml_suffix +let theory_suffix = ".theory" (* global maps, shared by all threads *) @@ -134,6 +134,7 @@ let resolve_remote uri = let help () = Http_getter_const.usage_string (Http_getter_env.env_to_string ()) let exists uri = + prerr_endline ("Http_getter.exists " ^ uri); if remote () then exists_remote uri else @@ -147,10 +148,17 @@ let resolve uri = Http_getter_storage.resolve (uri ^ xml_suffix) with Http_getter_storage.Resource_not_found _ -> raise (Key_not_found uri) +let deref_index_theory uri = + if is_theory_uri uri && Filename.basename uri = "index.theory" then + strip_trailing_slash (Filename.dirname uri) ^ theory_suffix + else + uri + let getxml uri = if remote () then getxml_remote uri else begin try + let uri = deref_index_theory uri in Http_getter_storage.filename (uri ^ xml_suffix) with Http_getter_storage.Resource_not_found _ -> raise (Key_not_found uri) end @@ -221,9 +229,19 @@ let collect_ls_items dirs_set objs_tbl = objs_tbl; List.rev !items +let contains_object = (<>) [] +(* List.iter + (function + | Ls_section name -> prerr_endline (name ^ "/"); + | Ls_object obj -> prerr_endline obj.uri) + l; + prerr_endline (string_of_bool b); + b *) +(* List.exists (function Ls_object _ -> true | _ -> false) *) + (** non regexp-aware version of ls *) -let dumb_ls uri_prefix = -(* prerr_endline ("Http_getter.dumb_ls " ^ uri_prefix); *) +let rec dumb_ls uri_prefix = + prerr_endline ("Http_getter.dumb_ls " ^ uri_prefix); if is_cic_obj_uri uri_prefix then begin let dirs = ref StringSet.empty in let objs = Hashtbl.create 17 in @@ -239,23 +257,41 @@ let dumb_ls uri_prefix = collect_ls_items !dirs objs end else if is_theory_uri uri_prefix then begin let items = ref [] in + let add_theory fname = + items := + Ls_object { + uri = fname; ann = false; types = No; body = No; proof_tree = No } + :: !items + in + let cic_uri_prefix = + Pcre.replace_first ~rex:heading_theory_RE ~templ:"cic:" uri_prefix + in List.iter (fun fname -> if ends_with_slash fname then items := Ls_section (strip_trailing_slash fname) :: !items else try - let obj = - { uri = strip_suffix ~suffix:xml_suffix fname; - ann = false; types = No; body = No; proof_tree = No } - in - items := Ls_object obj :: !items + let fname = strip_suffix ~suffix:xml_suffix fname in + let theory_name = strip_suffix ~suffix:theory_suffix fname in + let sub_theory = normalize_dir cic_uri_prefix ^ theory_name ^ "/" in + if is_empty_theory sub_theory then add_theory fname with Invalid_argument _ -> ()) (Http_getter_storage.ls uri_prefix); + (try + if contains_object (dumb_ls cic_uri_prefix) + && exists (strip_trailing_slash uri_prefix ^ theory_suffix) + then + add_theory "index.theory"; + with Unresolvable_URI _ -> ()); !items end else raise (Invalid_URI uri_prefix) +and is_empty_theory uri_prefix = + prerr_endline ("is_empty_theory " ^ uri_prefix); + not (contains_object (dumb_ls uri_prefix)) + (* handle simple regular expressions of the form "...(..|..|..)..." on cic * uris, not meant to be a real implementation of regexp. The only we use is * "(cic|theory):/..." *) -- 2.39.2