1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (* "cic:/a/b/c.con" => [| "cic:/a" ; "cic:/a/b" ; "cic:/a/b/c.con" ; "c" |] *)
27 type uri = string array;;
33 let string_of_uri uri = uri.(Array.length uri - 2);;
34 let name_of_uri uri = uri.(Array.length uri - 1);;
35 let buri_of_uri uri = uri.(Array.length uri - 3);;
36 let depth_of_uri uri = Array.length uri - 2;;
38 (*CSC: ora e' diventato poco efficiente, migliorare *)
39 let relative_depth curi uri cookingsno =
40 let rec length_of_current_prefix l1 l2 =
42 (he1::tl1, he2::tl2) when he1 == he2 ->
43 1 + length_of_current_prefix tl1 tl2
47 length_of_current_prefix
48 (Array.to_list (Array.sub curi 0 (Array.length curi - (2 + cookingsno))))
49 (Array.to_list (Array.sub uri 0 (Array.length uri - 2)))
50 (*CSC: vecchio codice da eliminare
54 length_of_current_prefix (Array.to_list curi) (Array.to_list uri)
58 module OrderedStrings =
61 let compare (s1 : t) (s2 : t) = compare s1 s2
65 module SetOfStrings = Map.Make(OrderedStrings);;
67 (*CSC: commento obsoleto ed errato *)
68 (* Invariant: the map is the identity function, *)
69 (* i.e. (SetOfStrings.find str !set_of_uri) == str *)
70 let set_of_uri = ref SetOfStrings.empty;;
71 let set_of_prefixes = ref SetOfStrings.empty;;
73 (* similar to uri_of_string, but used for prefixes of uris *)
74 let normalize prefix =
76 SetOfStrings.find prefix !set_of_prefixes
79 set_of_prefixes := SetOfStrings.add prefix prefix !set_of_prefixes ;
83 exception IllFormedUri of string;;
89 let prefix_uri = curi ^ "/" ^ he
90 and name = List.hd (Str.split (Str.regexp "\.") he) in
91 [ normalize prefix_uri ; name ]
93 let prefix_uri = curi ^ "/" ^ he in
94 (normalize prefix_uri)::(aux prefix_uri tl)
95 | _ -> raise (IllFormedUri str)
97 let tokens = (Str.split (Str.regexp "/") str) in
100 (try (List.hd tokens, List.tl tokens)
101 with Failure "hd" | Failure "tl" ->
102 raise (IllFormedUri str))
107 let uri_of_string str =
109 SetOfStrings.find str !set_of_uri
112 let uri = Array.of_list (mk_prefixes str) in
113 set_of_uri := SetOfStrings.add str uri !set_of_uri ;
117 let cicuri_of_uri uri =
118 let completeuri = string_of_uri uri in
120 (Str.replace_first (Str.regexp "\.types$") ""
121 (Str.replace_first (Str.regexp "\.ann$") "" completeuri))
123 if completeuri = newcompleteuri then
126 let newuri = Array.copy uri in
127 newuri.(Array.length uri - 2) <- newcompleteuri ;
131 let annuri_of_uri uri =
132 let completeuri = string_of_uri uri in
133 if Str.string_match (Str.regexp ".*\.ann$") completeuri 0 then
136 let newuri = Array.copy uri in
137 newuri.(Array.length uri - 2) <- completeuri ^ ".ann" ;
141 let uri_is_annuri uri =
142 Str.string_match (Str.regexp ".*\.ann$") (string_of_uri uri) 0