]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/xoa/xoa.ml
made executable again
[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 incremental = ref true
19 let separate = ref false
20
21 let preamble =
22   L.get_preamble ()
23
24 let clear () =
25   incremental := true;
26   separate := false;
27   R.clear ()
28
29 let unm_ex s =
30   Scanf.sscanf s "%u %u" A.mk_exists
31
32 let unm_or s =
33   Scanf.sscanf s "%u" A.mk_or
34
35 let unm_and s =
36   Scanf.sscanf s "%u" A.mk_and
37
38 let process_centralized conf =
39   R.load_from conf;
40   if R.has "xoa.objects" && R.has "xoa.notations" then begin
41     let ooch = L.open_out true preamble (R.get_string "xoa.objects") in
42     let noch = L.open_out false preamble (R.get_string "xoa.notations") in
43     List.iter (L.out_include ooch) (R.get_list R.string "xoa.include");
44     L.out_include ooch (R.get_string "xoa.notations" ^ ".ma");
45     List.iter (E.generate ooch noch) (R.get_list unm_ex "xoa.ex");
46     List.iter (E.generate ooch noch) (R.get_list unm_or "xoa.or");
47     List.iter (E.generate ooch noch) (R.get_list unm_and "xoa.and");
48     close_out noch; close_out ooch
49   end
50
51 let generate (p, o, n) d =
52   let oname, nname = match d with
53     | A.Exists (c, v) ->
54       let oname = Printf.sprintf "%s/ex_%u_%u" o c v in
55       let nname = Printf.sprintf "%s/ex_%u_%u" n c v in
56       oname, nname
57     | A.Or c          ->
58       let oname = Printf.sprintf "%s/or_%u" o c in
59       let nname = Printf.sprintf "%s/or_%u" n c in
60       oname, nname
61     | A.And c         ->
62       let oname = Printf.sprintf "%s/and_%u" o c in
63       let nname = Printf.sprintf "%s/and_%u" n c in
64       oname, nname
65   in
66   if !incremental && L.exists_out oname && L.exists_out nname then () else
67   begin
68     let ooch = L.open_out true p oname in
69     let noch = L.open_out false p nname in
70     List.iter (L.out_include ooch) (R.get_list R.string "xoa.include");
71     L.out_include ooch (nname ^ ".ma");
72     E.generate ooch noch d;
73     close_out noch; close_out ooch
74   end
75
76 let process_distributed conf =
77   R.load_from conf;
78   if R.has "xoa.objects" && R.has "xoa.notations" then begin
79     let st = preamble, R.get_string "xoa.objects", R.get_string "xoa.notations" in
80     List.iter (generate st) (R.get_list unm_ex "xoa.ex");
81     List.iter (generate st) (R.get_list unm_or "xoa.or");
82     List.iter (generate st) (R.get_list unm_and "xoa.and");
83   end
84
85 let process conf =
86   if !separate then process_distributed conf else process_centralized conf
87
88 let _ =
89   let help = "Usage: xoa [ -Xs | <configuration file> ]*\n" in
90   let help_X  = " Clear configuration" in
91   let help_s  = " Generate separate objects" in
92   let help_u  = " Update existing separate files" in
93   Arg.parse [
94     "-X", Arg.Unit clear, help_X;
95     "-s", Arg.Set separate, help_s;
96     "-u", Arg.Clear incremental, help_u;
97   ] process help