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 EG = RolesGlobal
13 module EI = RolesInput
14 module EO = RolesOutput
15 module EU = RolesUtils
16 module ET = RolesTypes
18 let st = EU.new_status
21 if st.ET.w = [] then begin
22 if EU.compare_versions st.ET.s v <> 0 then begin
23 st.ET.s <- v; st.ET.m <- true
25 end else EU.raise_error ET.EWaiting
27 let select_entry = function
28 | [0] -> st.ET.r <- EU.list_toggle_all st.ET.r
29 | [0;m] -> st.ET.r <- EU.list_toggle m st.ET.r
31 let r = EU.list_nth m st.ET.r in
32 r.ET.o <- EU.list_toggle_all r.ET.o
34 let r = EU.list_nth m st.ET.r in
35 r.ET.o <- EU.list_toggle n r.ET.o
37 let r = EU.list_nth m st.ET.r in
38 r.ET.n <- EU.list_toggle_all r.ET.n
40 let r = EU.list_nth m st.ET.r in
41 r.ET.n <- EU.list_toggle n r.ET.n
42 | [1] -> st.ET.t <- EU.list_toggle_all st.ET.t
43 | [1;m] -> st.ET.t <- EU.list_toggle m st.ET.t
44 | [2] -> st.ET.w <- EU.list_toggle_all st.ET.w
45 | [2;m] -> st.ET.w <- EU.list_toggle m st.ET.w
46 | _ -> EU.raise_error ET.ENoEntry
49 let ts,os = EU.list_split st.ET.t in
50 let ws,ns = EU.list_split st.ET.w in
51 if os = [] && ns = [] then () else
52 begin match EU.list_select None st.ET.r with
54 let r = {ET.x = false; ET.v = st.ET.s; ET.o = os; ET.n = ns} in
55 st.ET.r <- EU.roles_union [false, r] st.ET.r
57 if r.ET.v <> st.ET.s then EU.raise_error ET.EWrongVersion else
58 r.ET.o <- EU.objs_union os r.ET.o;
59 r.ET.n <- EU.names_union ns r.ET.n;
61 st.ET.t <- ts; st.ET.w <- ws; st.ET.m <- true
64 if EU.exists_role_deleted st.ET.s st.ET.r || st.ET.t <> []
65 then EU.raise_error ET.ETops else
66 let ds, ts = EU.get_tops v st.ET.r in
67 if ds <> [] then begin
68 let r = {ET.x = false; ET.v = st.ET.s; ET.o = ds; ET.n = []} in
69 st.ET.r <- EU.roles_union [false, r] st.ET.r
71 if ts <> [] then st.ET.t <- ts;
72 if ds <> [] || ts <> [] then st.ET.m <- true
74 let rec add_matching () =
75 match EU.match_names 0 0 st.ET.t st.ET.w with
83 let read_waiting fname =
84 if st.ET.s = [] then EU.raise_error ET.ENoStage else
85 let ich = Scanf.Scanning.open_in fname in
86 let ws = EI.read_rev_names ich [] in
87 Scanf.Scanning.close_in ich;
88 let map ws w = EU.names_union ws [w] in
89 st.ET.w <- List.fold_left map st.ET.w ws;
90 if ws <> [] then st.ET.m <- true
93 if st.ET.s <> [] then EU.raise_error (ET.EStage st.ET.s) else
94 let fname = Filename.concat !EG.cwd "roles.osn" in
95 let ich = open_in fname in
96 let tmp = EI.read_status ich in
104 let write_status () =
105 let fname = Filename.concat !EG.cwd "roles.osn" in
106 let och = open_out fname in
107 EO.out_status och st;
111 let print_status () =
112 EO.out_status stdout st
115 before_r each_r before after after_r stage
116 before_t each_t after_t before_w each_w after_w =
117 let visit_tw _ _ = () in
121 EU.list_visit before_t each_t visit_tw after_t EU.string_of_obj (1::p) r.ET.o;
122 EU.list_visit before_w each_w visit_tw after_w EU.string_of_name (2::p) r.ET.n;
126 EU.list_visit before_r each_r visit_r after_r EU.string_of_role [0] st.ET.r;
127 stage (EU.string_of_version st.ET.s) st.ET.m;
128 EU.list_visit before_t each_t visit_tw after_t EU.string_of_obj [1] st.ET.t;
129 EU.list_visit before_w each_w visit_tw after_w EU.string_of_name [2] st.ET.w