]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/xoa/xoa.ml
d6f0bca0d49fa252af44a588ab51010c53176279
[helm.git] / matita / components / binaries / xoa / xoa.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 module R = Helm_registry
13
14 module L = Lib
15 module A = Ast
16 module E = Engine
17
18 let separate = ref false
19
20 let clear () =
21    separate := false;
22    R.clear ()
23
24 let unm_ex s =
25    Scanf.sscanf s "%u %u" A.mk_exists
26
27 let unm_or s =
28    Scanf.sscanf s "%u" A.mk_or
29
30 let unm_and s =
31    Scanf.sscanf s "%u" A.mk_and
32
33 let process_centralized conf =
34    let preamble = L.get_preamble conf in
35    if R.has "xoa.objects" && R.has "xoa.notations" then begin
36       let ooch = L.open_out preamble (R.get_string "xoa.objects") in
37       let noch = L.open_out preamble (R.get_string "xoa.notations") in
38       List.iter (L.out_include ooch) (R.get_list R.string "xoa.include");
39       L.out_include ooch (R.get_string "xoa.notations" ^ ".ma");
40       List.iter (E.generate ooch noch) (R.get_list unm_ex "xoa.ex");
41       List.iter (E.generate ooch noch) (R.get_list unm_or "xoa.or");
42       List.iter (E.generate ooch noch) (R.get_list unm_and "xoa.and");
43       close_out noch; close_out ooch
44    end
45
46 let generate (p, o, n) = function
47    | A.Exists (c, v) as d ->
48       let oname = Printf.sprintf "%s/ex_%u_%u" o c v in
49       let nname = Printf.sprintf "%s/ex_%u_%u" n c v in
50       let ooch = L.open_out p oname in
51       let noch = L.open_out p nname in
52       List.iter (L.out_include ooch) (R.get_list R.string "xoa.include");
53       L.out_include ooch (nname ^ ".ma");
54       E.generate ooch noch d;
55       close_out noch; close_out ooch
56    | A.Or c          -> ()
57    | A.And c         -> ()
58
59 let process_distributed conf =
60    let preamble = L.get_preamble conf in
61    if R.has "xoa.objects" && R.has "xoa.notations" then begin
62       let st = preamble, R.get_string "xoa.objects", R.get_string "xoa.notations" in
63       List.iter (generate st) (R.get_list unm_ex "xoa.ex");
64       List.iter (generate st) (R.get_list unm_or "xoa.or");
65       List.iter (generate st) (R.get_list unm_and "xoa.and");
66    end
67
68 let process conf =
69    if !separate then process_distributed conf else process_centralized conf
70
71 let _ =
72    let help = "Usage: xoa [ -Xs | <configuration file> ]*\n" in
73    let help_X  = " Clear configuration" in
74    let help_s  = " Generate separate objects" in
75    Arg.parse [
76       "-X", Arg.Unit clear, help_X;
77       "-s", Arg.Set separate, help_s;
78    ] process help