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:"
41 let run_script is eval_function =
44 | None -> assert false
47 let slash_n_RE = Pcre.regexp "\\n" in
49 (* dump_status status; *)
50 let stm = TacticAstPp.pp_statement stm in
51 let stm = Pcre.replace ~rex:slash_n_RE stm in
53 if String.length stm > 50 then
54 String.sub stm 0 50 ^ " ..."
58 MatitaLog.debug ("Executing: ``" ^ stm ^ "''")
61 eval_function status is cb
64 | CicTextualParser2.Parse_error _ as exn -> raise exn
66 MatitaLog.error (MatitaExcPp.to_string exn);
71 let add_script fname = acc := fname :: !acc in
72 Arg.parse arg_spec add_script usage;
75 | _ -> prerr_endline usage; exit 1
77 let pp_ocaml_mode () =
79 MatitaLog.message " ** Entering Ocaml mode ** ";
81 MatitaLog.message "Type 'go ();;' to enter an interactive matitac";
94 let baseuri = MatitaTypes.get_string_option !status "baseuri" in
95 MatitacleanLib.clean_baseuris ~verbose:false [baseuri];
97 with MatitaTypes.Option_error("baseuri", "not found") ->
98 (* no baseuri ==> nothing to clean yet *)
101 let rec interactive_loop () =
102 let str = Stream.of_channel stdin in
104 run_script str MatitaEngine.eval_from_stream_greedy
106 | MatitaEngine.Drop -> pp_ocaml_mode ()
107 | Sys.Break -> MatitaLog.error "user break!"; interactive_loop ()
108 | MatitaTypes.Command_error _ -> interactive_loop ()
109 | CicTextualParser2.Parse_error (floc,err) ->
111 if Stream.peek str = None then
117 let (x, y) = CicAst.loc_of_floc floc in
118 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
120 | exn -> MatitaLog.error (Printexc.to_string exn); interactive_loop ()
123 Helm_registry.load_from "matita.conf.xml";
125 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
126 status := Some (ref (Lazy.force MatitaEngine.initial_status));
127 Sys.catch_break true;
130 let dump_moo_to_file file moo =
131 let os = open_out (MatitaMisc.obj_file_of_script file) in
132 let output s = output_string os s in
133 output "(* GENERATED FILE: DO NOT EDIT! *)\n\n";
134 List.iter output (List.rev moo);
138 Helm_registry.load_from "matita.conf.xml";
140 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
141 status := Some (ref (Lazy.force MatitaEngine.initial_status));
142 Sys.catch_break true;
143 let fname = fname () in
145 let time = Unix.time () in
146 MatitaLog.message (sprintf "execution of %s started:" fname);
151 | fname -> open_in fname)
153 run_script is MatitaEngine.eval_from_stream;
154 let elapsed = Unix.time () -. time in
155 let tm = Unix.gmtime elapsed in
157 if tm.Unix.tm_sec > 0 then (string_of_int tm.Unix.tm_sec ^ "''") else ""
160 if tm.Unix.tm_min > 0 then (string_of_int tm.Unix.tm_min ^ "' ") else ""
163 if tm.Unix.tm_hour > 0 then (string_of_int tm.Unix.tm_hour ^ "h ") else ""
165 let proof_status,moo_content_rev =
167 | Some s -> !s.proof_status, !s.moo_content_rev
168 | None -> assert false
170 if proof_status <> MatitaTypes.No_proof then
173 "there are still incomplete proofs at the end of the script";
178 dump_moo_to_file fname moo_content_rev;
180 (sprintf "execution of %s completed in %s." fname (hou^min^sec));
185 MatitaLog.error "user break!";
186 if mode = `COMPILER then
187 clean_exit (Some ~-1)
190 | MatitaEngine.Drop ->
191 if mode = `COMPILER then
195 | CicTextualParser2.Parse_error (floc,err) ->
196 let (x, y) = CicAst.loc_of_floc floc in
197 MatitaLog.error (sprintf "Parse error at %d-%d: %s" x y err);
198 if mode = `COMPILER then
203 if mode = `COMPILER then