]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitac.ml
added chronometer
[helm.git] / helm / matita / matitac.ml
1 (* Copyright (C) 2004-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 open Printf
27
28 open MatitaTypes
29
30 (** {2 Initialization} *)
31
32 let arg_spec = [
33 (*   "-opt", Arg...., "set bla bla bla"; *)
34 ]
35 let usage =
36   sprintf "MatitaC v%s\nUsage: matitac [option ...] file ...\nOptions:"
37     BuildTimeConf.version
38
39 let _ =
40   Helm_registry.load_from "matita.conf.xml";
41   Http_getter.init ();
42   MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
43   MatitaDb.clean_owner_environment ();
44   MatitaDb.create_owner_environment ()
45
46 let scripts =
47   let acc = ref [] in
48   let add_script fname = acc := fname :: !acc in
49   Arg.parse arg_spec add_script usage;
50   List.rev !acc
51
52 let run_script fname =
53   let is =
54     Stream.of_channel
55       (match fname with
56       | "stdin" -> stdin
57       | fname -> open_in fname)
58   in
59   let status = ref (Lazy.force MatitaEngine.initial_status) in
60   let slash_n_RE = Pcre.regexp "\\n" in
61   let cb status stm = 
62     (* dump_status status; *)
63     let stm = TacticAstPp.pp_statement stm in
64     let stm = Pcre.replace ~rex:slash_n_RE stm in
65     let stm = 
66       if String.length stm > 50 then
67         String.sub stm 0 50 ^ " ..."
68       else
69         stm
70     in
71     MatitaLog.debug ("Executing: ``" ^ stm ^ "''")
72   in
73   try
74     status := MatitaEngine.eval_from_stream !status is cb
75   with
76   | CicTextualParser2.Parse_error (floc,err) ->
77      let (x, y) = CicAst.loc_of_floc floc in
78      MatitaLog.message (sprintf "Parse error at %d-%d: %s" x y err);
79      Http_getter.sync_dump_file ();
80      exit 1
81   | exn -> 
82       MatitaLog.error (Printexc.to_string exn);
83       raise exn
84         
85 let _ = 
86   List.iter (fun fname -> 
87     let time = Unix.time () in
88     MatitaLog.message (sprintf "execution of %s started:" fname);
89     run_script fname;
90     let elapsed = Unix.time () -. time in
91     let tm = Unix.gmtime elapsed in
92     let sec = 
93       if tm.Unix.tm_sec > 0 then  (string_of_int tm.Unix.tm_sec ^ "''") else "" 
94     in
95     let min = 
96       if tm.Unix.tm_min > 0 then  (string_of_int tm.Unix.tm_min ^ "' ") else "" 
97     in
98     let hou = 
99       if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else "" 
100     in
101     MatitaLog.message 
102       (sprintf "execution of %s completed in %s." fname (hou^min^sec))) scripts;
103   Http_getter.sync_dump_file ();
104   exit(0)
105   
106