]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/xoa/lib.ml
573e0ebfb14a8bb9d5125d199071e82d02897e47
[helm.git] / matita / components / binaries / xoa / lib.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 F   = Filename
13
14 module R   = Helm_registry
15
16 let template = "matita.ma.templ"
17
18 let myself = F.basename Sys.argv.(0)
19
20 let get_preamble conf =
21    R.load_from conf;
22    let rt_base_dir = R.get_string "matita.rt_base_dir" in
23    F.concat rt_base_dir template
24
25 let copy_preamble preamble och =
26    let ich = open_in preamble in
27    let rec read () =
28       Printf.fprintf och "%s\n" (input_line ich); read ()
29    in
30    try read () with End_of_file -> close_in ich
31
32 let print_comment och =
33    let stars = String.make (30 - String.length myself) '*' in
34    Printf.fprintf och "(* This file was generated by %s: do not edit %s*)\n\n" myself stars
35
36 let open_out preamble name =
37    let path = [
38       R.get_string "xoa.output_dir"; 
39       name
40    ] in
41    let name = List.fold_left F.concat "" path in 
42    let och = open_out (name ^ ".ma") in
43    copy_preamble preamble och; print_comment och;
44    och
45
46 let out_include och s =
47    Printf.fprintf och "include \"%s\".\n\n" s