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