]> matita.cs.unibo.it Git - helm.git/blob - matita/matitac.ml
d603d1b85d9909381f003d5aa8e6e5e7d6458396
[helm.git] / matita / matitac.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 module G = GrafiteAst
29 module L = LexiconAst
30 module H = HExtlib
31
32 (* from transcript *)
33
34 let out_comment och s =
35    let s = if s <> "" && s.[0] = '*' then "#" ^ s else s in 
36    Printf.fprintf och "%s%s%s\n\n" "(*" s "*)"
37
38 let out_line_comment och s =
39    let l = 70 - String.length s in
40    let s = Printf.sprintf " %s %s" s (String.make l '*') in
41    out_comment och s
42
43 let out_preamble och (path, lines) =
44    let ich = open_in path in
45    let rec print i =
46       if i > 0 then 
47          let s = input_line ich in
48          begin Printf.fprintf och "%s\n" s; print (pred i) end
49    in 
50    print lines;
51    out_line_comment och "This file was automatically generated: do not edit"
52
53 (* from matitacLib *)
54
55 let pp_ast_statement st =
56   GrafiteAstPp.pp_statement ~term_pp:CicNotationPp.pp_term
57     ~map_unicode_to_tex:(Helm_registry.get_bool
58       "matita.paste_unicode_as_tex")
59     ~lazy_term_pp:CicNotationPp.pp_term ~obj_pp:(CicNotationPp.pp_obj CicNotationPp.pp_term) st
60
61 (**)
62
63 let dump f =
64    Helm_registry.set_bool "matita.moo" false;
65    let floc = H.dummy_floc in
66    let nl_ast = G.Comment (floc, G.Note (floc, "")) in
67    let och = open_out f in
68    let atexit () = close_out och in
69    let nl () =  output_string och (pp_ast_statement nl_ast) in
70    let rt_base_dir = Filename.dirname Sys.argv.(0) in
71    let path = Filename.concat rt_base_dir "matita.ma.templ" in
72    let lines = 14 in
73    out_preamble och (path, lines);
74    let grafite_parser_cb fname = 
75       let ast = G.Executable (floc, G.Command (floc, G.Include (floc, fname))) in
76       output_string och (pp_ast_statement ast); nl (); nl ()
77    in
78    let matita_engine_cb = function
79       | G.Executable (_, G.Macro (_, G.Inline _)) 
80       | G.Executable (_, G.Command (_, G.Include _)) -> ()
81       | ast                                          ->
82          output_string och (pp_ast_statement ast); nl (); nl ()
83    in
84    let matitac_lib_cb = output_string och in
85    GrafiteParser.set_callback grafite_parser_cb;
86    MatitaEngine.set_callback matita_engine_cb;
87    MatitacLib.set_callback matitac_lib_cb;
88    at_exit atexit
89    
90 let main () =
91  Helm_registry.set_bool "matita.moo" true;
92  match Filename.basename Sys.argv.(0) with
93  |"gragrep"    |"gragrep.opt"    |"gragrep.opt.static"    ->Gragrep.main()
94  |"matitadep"  |"matitadep.opt"  |"matitadep.opt.static"  ->Matitadep.main()
95  |"matitaclean"|"matitaclean.opt"|"matitaclean.opt.static"->Matitaclean.main()
96  |"matitamake" |"matitamake.opt" |"matitamake.opt.static" ->Matitamake.main()
97  |"matitaprover"|"matitaprover.opt"
98  |"matitaprover.opt.static" ->Matitaprover.main()
99  |"matitawiki"|"matitawiki.opt" ->MatitaWiki.main()
100  | _ ->
101       let dump_msg = "<filename> Dump source with expanded macros to <filename>" in
102       MatitaInit.add_cmdline_spec ["-dump", Arg.String dump, dump_msg];
103       MatitacLib.main ()
104
105 let _ = main ()
106