2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 module ET = RolesTypes
17 let list_union error compare l1 l2 =
18 let rec aux l1 l2 = match l1 with
20 | hd1::tl1 -> match l2 with
23 let b = compare (snd hd1) (snd hd2) in
24 if b > 0 then hd2 :: aux l1 tl2
25 else if b < 0 then hd1 :: aux tl1 l2
26 else raise_error (error (snd hd1))
30 let list_compare compare l1 l2 =
31 let rec aux l1 l2 = match l1 with
33 if l2 = [] then 0 else -1
34 | hd1::tl1 -> match l2 with
37 let b = compare hd1 hd2 in
38 if b = 0 then aux tl1 tl2 else b
42 let rec list_nth n = function
43 | [] -> raise_error ET.ENoEntry
44 | (_,hd)::tl -> if n = 0 then hd else list_nth (pred n) tl
46 let rec list_toggle n = function
47 | [] -> raise_error ET.ENoEntry
48 | (b,hd)::tl -> if n = 0 then (not b,hd)::tl else (b,hd)::list_toggle (pred n) tl
50 let rec list_toggle_all = function
52 | (b,hd)::tl -> (not b,hd)::list_toggle_all tl
54 let string_of_version v =
55 String.concat "." (List.map string_of_int v)
57 let version_of_string s =
58 List.map int_of_string (String.split_on_char '.' s)
60 let string_of_name n =
63 let name_of_string s =
64 String.split_on_char '_' s
66 let compare_names n1 n2 =
67 list_compare compare n1 n2
69 let string_of_obj (v,n) =
70 Printf.sprintf "%s/%s" (string_of_version v) (string_of_name n)
73 match String.split_on_char '/' s with
74 | [sv;sn] -> version_of_string sv, name_of_string sn
75 | _ -> failwith "obj_of_string"
78 ET.r = []; ET.s = []; ET.t = []; ET.w = [];
81 let pointer_of_string = version_of_string
83 let string_of_error = function
85 Printf.sprintf "unknown input file type %S" x
87 Printf.sprintf "current stage %S" (string_of_version v)
89 Printf.sprintf "current stage not defined"
91 Printf.sprintf "current stage not finished"
93 Printf.sprintf "name clash %S" (string_of_name n)
95 Printf.sprintf "entry not found"