1 (* Copyright (C) 2004-2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
30 (** {2 Initialization} *)
33 (* "-opt", Arg...., "set bla bla bla"; *)
36 sprintf "MatitaC v%s\nUsage: matitac [option ...] file\nOptions:"
40 Helm_registry.load_from "matita.conf.xml";
42 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
43 MatitaDb.clean_owner_environment ();
44 MatitaDb.create_owner_environment ()
46 let status = ref (Lazy.force MatitaEngine.initial_status) ;;
48 let run_script is eval_function =
49 let slash_n_RE = Pcre.regexp "\\n" in
51 (* dump_status status; *)
52 let stm = TacticAstPp.pp_statement stm in
53 let stm = Pcre.replace ~rex:slash_n_RE stm in
55 if String.length stm > 50 then
56 String.sub stm 0 50 ^ " ..."
60 MatitaLog.debug ("Executing: ``" ^ stm ^ "''")
63 eval_function status is cb
66 | CicTextualParser2.Parse_error _ as exn -> raise exn
68 MatitaLog.error (Printexc.to_string exn);
73 let add_script fname = acc := fname :: !acc in
74 Arg.parse arg_spec add_script usage;
77 | _ -> prerr_endline usage; exit 1
79 let pp_ocaml_mode () =
81 MatitaLog.message " ** Entering Ocaml mode ** ";
83 MatitaLog.message "Type 'MatitacLib.go ();;' to enter an interactive matitac";
87 let str = Stream.of_channel stdin in
89 run_script str MatitaEngine.eval_from_stream_greedy
91 | MatitaEngine.Drop -> pp_ocaml_mode ()
92 | Sys.Break -> MatitaLog.error "user break!"; go ()
93 | MatitaTypes.Command_error _ -> go ()
94 | CicTextualParser2.Parse_error (floc,err) ->
96 if Stream.peek str = None then
99 let (x, y) = CicAst.loc_of_floc floc in
100 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
101 | exn -> MatitaLog.error (Printexc.to_string exn); go ()
106 Http_getter_logger.log "Sync map tree to disk...";
107 Http_getter.sync_dump_file ();
108 print_endline "\nThanks for using Matita!\n");
109 Sys.catch_break true;
110 let fname = fname () in
112 let time = Unix.time () in
113 MatitaLog.message (sprintf "execution of %s started:" fname);
118 | fname -> open_in fname)
120 run_script is MatitaEngine.eval_from_stream;
121 let elapsed = Unix.time () -. time in
122 let tm = Unix.gmtime elapsed in
124 if tm.Unix.tm_sec > 0 then (string_of_int tm.Unix.tm_sec ^ "''") else ""
127 if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min ^ "' ") else ""
130 if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else ""
132 let proof_status = !status.proof_status in
133 if proof_status <> MatitaTypes.No_proof then
136 "there are still incomplete proofs at the end of the script";
142 (sprintf "execution of %s completed in %s." fname (hou^min^sec));
146 | Sys.Break -> MatitaLog.error "user break!"; exit ~-1
147 | MatitaEngine.Drop ->
148 if mode = `COMPILER then
152 | CicTextualParser2.Parse_error (floc,err) ->
153 let (x, y) = CicAst.loc_of_floc floc in
154 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
155 Http_getter.sync_dump_file ();