]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/xoa/lib.ml
auxiliary executables (xoa, matitadep, probe, matex) ported to dune
[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/matita.ma.templ"
18
19 let myself = F.basename Sys.argv.(0)
20
21 let rt_base_dir = F.dirname Sys.argv.(0)
22
23 let get_preamble () =
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_header def och =
34   let msg = if def then "LOGIC" else "GROUND NOTATION" in
35   let stars = String.make (72 - String.length msg) '*' in
36   Printf.fprintf och "(* %s %s*)\n\n" msg stars
37
38 let print_comment och =
39   let msg = Printf.sprintf "NOTE: This file was generated by %s, do not edit" myself in
40   let stars = String.make (72 - String.length msg) '*' in
41   Printf.fprintf och "(* %s %s*)\n\n" msg stars
42
43 let exists_out name =
44   let path = [
45     R.get_string "xoa.output_dir";
46     name
47   ] in
48   let name = List.fold_left F.concat "" path in
49   K.file_exists (name ^ ".ma")
50
51 let open_out def preamble name =
52   let path = [
53     R.get_string "xoa.output_dir";
54     name
55   ] in
56   let name = List.fold_left F.concat "" path in
57   let och = open_out (name ^ ".ma") in
58   copy_preamble preamble och;
59   print_header def och;
60   print_comment och;
61   och
62
63 let out_include och s =
64   Printf.fprintf och "include \"%s\".\n\n" s