]> matita.cs.unibo.it Git - helm.git/blobdiff - components/library/librarian.ml
modifications to make matita behave reasonably, removed some useless windows
[helm.git] / components / library / librarian.ml
index 4c25bc309e1b9c7491832de4711a34ccfb0612f8..e8d0e7da12120e7672282c7e1c9fa68314e2498d 100644 (file)
@@ -1,4 +1,4 @@
-exception UnableToQualify
+exception NoRootFor of string
 
 let find_root path =
   let paths = List.rev (Str.split (Str.regexp "/") path) in
@@ -7,19 +7,10 @@ let find_root path =
     | [] -> ["/"]
   in
   let paths = List.map HExtlib.normalize_path (build paths) in
-  HExtlib.find_in paths "root"
+  try HExtlib.find_in paths "root"
+  with Failure "find_in" -> raise (NoRootFor path)
 ;;
   
-let is_prefix_of d1 d2 =
-    let len1 = String.length d1 in
-    let len2 = String.length d2 in
-    if len2 < len1 then 
-      false
-    else
-      let pref = String.sub d2 0 len1 in
-      pref = d1 && (len1 = len2 || d2.[len1] = '/')
-;;
-
 let ensure_trailing_slash s = 
   if s = "" then "/" else
   if s.[String.length s-1] <> '/' then s^"/" else s
@@ -39,7 +30,8 @@ let find_root_for ~include_paths file =
    try
      let mburi = Helm_registry.get "matita.baseuri" in
      match Str.split (Str.regexp " ") mburi with
-     | [root; buri] when is_prefix_of root path -> ":registry:", root, buri
+     | [root; buri] when HExtlib.is_prefix_of root path -> 
+         ":registry:", root, buri
      | _ -> raise (Helm_registry.Key_not_found "matita.baseuri")
    with Helm_registry.Key_not_found "matita.baseuri" -> 
      let rootpath = find_root path in
@@ -63,21 +55,6 @@ let find_root_for ~include_paths file =
    HLog.error (rootpath ^ " sets an incorrect baseuri: " ^ buri);
  ensure_trailing_slash root, remove_trailing_slash uri, path
 ;;
-
-let filename () =
-  try
-    Helm_registry.get "matita.filename"
-  with Helm_registry.Key_not_found "matita.filename" ->
-    try
-      match Helm_registry.get_list Helm_registry.string "matita.args" with
-      | [x] -> 
-         HLog.warn ("Using matita.args as filename: "^x);
-         Helm_registry.set "matita.filename" x;
-         x
-      | _ -> raise (Failure "no (or more than one) filename to compile")
-    with Helm_registry.Key_not_found "matita.filename" -> 
-      raise (Failure "Unable to get current file name")
-;;  
   
 let baseuri_of_script ?(include_paths=[]) file = 
   let root, buri, path = find_root_for ~include_paths file in
@@ -89,7 +66,7 @@ let baseuri_of_script ?(include_paths=[]) file =
     match l1, l2 with
     | h1::tl1,h2::tl2 when h1 = h2 -> substract tl1 tl2
     | l,[] -> l
-    | _ -> raise UnableToQualify
+    | _ -> raise (NoRootFor file)
   in
   let extra_buri = substract lpath lroot in
   let chop name =