]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/bin/recomm/recomm.ml
propagating the arithmetics library, partial commit
[helm.git] / matita / matita / contribs / lambdadelta / bin / recomm / recomm.ml
1 module EC = RecommCheck
2 module EL = RecommLexer
3 module EI = RecommInput
4 module EO = RecommOutput
5
6 module P1 = RecommPccFor
7 module P2 = RecommPcsAnd
8 module P3 = RecommPcsPar
9
10 module G = RecommGc
11
12 let write = ref false
13
14 let force = ref false
15
16 let subst = ref None
17
18 let chdir path =
19   Sys.chdir path
20
21 let start_substs () =
22   subst := Some (open_out "subst.txt")
23
24 let write_substs lint = function
25   | None     -> ()
26   | Some och -> EO.write_substs och lint
27
28 let stop_substs = function
29   | None     -> ()
30   | Some och -> close_out och
31
32 let rec process path name =
33   let file = Filename.concat path name in 
34   if Sys.is_directory file then begin
35     let dir = Sys.readdir file in
36     Array.iter (process file) dir
37   end else
38   if Filename.extension file = ".ma" then begin
39     Printf.eprintf "processing: %S\n" file;
40     let orig = EI.read_srcs file in
41     let lint = EC.recomm_srcs orig in
42     write_substs lint !subst;
43     if !force || (!write && lint <> orig) then EO.write_srcs file lint
44   end else begin
45     Printf.eprintf "skipping: %S\n" file
46   end
47
48 let msg_C = "<dir>  Set this working directory (default: .)"
49 let msg_L = " Log lexer tokens (default: no)"
50 let msg_c = "<int>  Set these output columns (default: 78)"
51 let msg_d = " Log with dark colors (default: no)"
52 let msg_f = " Write all output files (default: no)"
53 let msg_k = " Log key comments (default: no)"
54 let msg_m = " Log mark comments (default: no)"
55 let msg_n = " Log with no colors (default: yes)"
56 let msg_o = " Log other comments (default: no)"
57 let msg_r = " Replace the input files (default: no)"
58 let msg_s = " Log section comments (default: no)"
59 let msg_t = " Log title comments (default: no)"
60 let msg_u = " Write substitution file (default: no)"
61 let msg_w = " Write the changed output files (default: no)"
62
63 let main =
64   Arg.parse [
65     "-C", Arg.String chdir, msg_C;
66     "-L", Arg.Set EL.debug, msg_m;
67     "-c", Arg.Int ((:=) EO.width), msg_c;
68     "-d", Arg.Clear EC.bw, msg_d;
69     "-f", Arg.Set force, msg_f;
70     "-k", Arg.Set EC.log_k, msg_k;
71     "-m", Arg.Set EC.log_m, msg_m;
72     "-n", Arg.Set EC.bw, msg_n;
73     "-o", Arg.Set EC.log_o, msg_o;
74     "-r", Arg.Set EO.replace, msg_r;
75     "-s", Arg.Set EC.log_s, msg_s;
76     "-t", Arg.Set EC.log_t, msg_t;
77     "-u", Arg.Unit start_substs, msg_u;
78     "-w", Arg.Set write, msg_w;
79   ] (process "") "";
80   stop_substs !subst