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 (* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
31 type pg_map = (MathQL.path * (bool * string * string option)) list
33 type pg_tables = (bool * string) list
35 type pg_alias = (string * string) list
37 let empty_map () = "", [], []
40 let default_map = "mathql_db_map.txt" in
42 try Sys.getenv "MATHQL_DB_MAP"
43 with Not_found -> default_map
45 let ich = open_in map in
46 let pgs = input_line ich in
48 let d = input_line ich in
49 match Str.split (Str.regexp "[ \t]+") d with
52 | t :: "<-" :: p -> aux ((p, (false, t, None)) :: r) s
53 | t :: c :: "<-" :: p -> aux ((p, (false, t, Some c)) :: r) s
54 | t :: "<+" :: p -> aux ((p, (true, t, None)) :: r) s
55 | t :: c :: "<+" :: p -> aux ((p, (true, t, Some c)) :: r) s
56 | [a; "->"; t] -> aux r ((a, t) :: s)
58 | _ -> raise (Failure "MQIMap.read_map")
60 let pgm, pga = aux [] [] in
64 let comp c1 c2 = match c1, c2 with
65 | (_, t1), (_, t2) when t1 < t2 -> U.Lt
66 | (_, t1), (_, t2) when t1 > t2 -> U.Gt
67 | (b1, t), (b2, _) -> U.Eq (b1 || b2, t)
69 let get_tables pgm p =
71 | q, (b, t, _) when q = p -> U.list_join comp l [(b, t)]
74 List.fold_left aux [] pgm
76 let rec refine_tables l1 l2 =
77 U.list_meet comp l1 l2
79 let default_table = function
83 with Not_found -> raise (Failure "MQIMap.default_table")
85 let get_field pgm p t =
87 | q, (_, u, _) when q = p && u = t -> true
90 match List.filter aux pgm with
91 | [_, (_, _, None)] -> ""
92 | [_, (_, _, Some c)] -> c
93 | _ -> raise (Failure "MQIMap.get_field")
96 try List.assoc a pga with Not_found -> a