]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/bin/recomm/recommOutput.ml
fe8bebe945148fdd03ce6450c4b8b3f1bdbc56ec
[helm.git] / matita / matita / contribs / lambdadelta / bin / recomm / recommOutput.ml
1 module ET = RecommTypes
2
3 let width = ref 78
4
5 let replace = ref false
6
7 let complete s =
8   let l = !width - String.length s - 6 in
9   if l < 0 then begin
10     Printf.eprintf "overfull: %S\n" s;
11     ""
12   end else begin
13     String.make l '*'
14   end
15
16 let out_src och = function
17   | ET.Line s             ->
18     Printf.fprintf och "%s" s
19   | ET.Text s             ->
20     Printf.fprintf och "%s" s
21   | ET.Mark s             ->
22     Printf.fprintf och "(* %s**)" s
23   | ET.Key (s1, s2)       ->
24     Printf.fprintf och "(* %s%s*)" s1 s2
25   | ET.Title ss           ->
26     let s = String.concat " " ss in
27     Printf.fprintf och "(* %s %s*)" s (complete s)
28   | ET.Slice ss           ->
29     let s = String.capitalize_ascii (String.concat " " ss) in
30     Printf.fprintf och "(* %s %s*)" s (complete s)
31   | ET.Other (s1, s2, s3) ->
32     Printf.fprintf och "%s%s%s" s1 s2 s3
33
34 let write_srcs file srcs =
35   let target =  
36     if !replace then begin
37       Sys.rename file (file ^ ".old");
38       file
39     end else begin
40       file ^ ".new"
41     end
42   in
43   let och = open_out target in
44   List.iter (out_src och) srcs;
45   close_out och