1 (* Copyright (C) 2004, 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 let message s = printf "** MatitaC: %s\n" s; flush stdout
31 let warn s = eprintf "** MatitaC WARNING: %s\n" s; flush stdout
32 let error s = eprintf "** MatitaC ERROR: %s\n" s; flush stderr
34 (** console which prints on stdout/stderr *)
38 method echo_message s = message s
39 method echo_error s = error s
40 (* TODO Zack: this method is similar to omonymous method in console,
41 * factorize it in a common super class *)
42 method wrap_exn: 'a. (unit -> 'a) -> 'a option =
47 self#echo_error (explain exn);
51 (** {2 Initialization} *)
54 (* "-opt", Arg...., "set bla bla bla"; *)
57 sprintf "MatitaC v%s\nUsage: matitac [option ...] file ...\nOptions:"
61 Helm_registry.load_from "matita.conf.xml";
63 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
64 MatitaDb.clean_owner_environment ();
65 MatitaDb.create_owner_environment ()
69 let add_script fname = acc := fname :: !acc in
70 Arg.parse arg_spec add_script usage;
73 let console = new tty_console
74 let interpreter = MatitaInterpreter.interpreter ~console ()
76 let run_script fname =
77 message (sprintf "execution of %s started:" fname);
79 let ic = open_in fname in
82 snd (CicTextualParser2.parse_script (Stream.of_channel ic))
86 assert false (* should be something like (Unix.exit 1) *)
91 let rec aux = function
92 | [] -> () (* script is over *)
93 | DisambiguateTypes.Comment _ :: tl -> aux tl
94 | DisambiguateTypes.Command ast :: tl ->
97 | TacticAst.LocatedTactical (loc, _) -> loc
100 let (success, _) = interpreter#evalAst ast in
102 error (sprintf "%s: error at %s, aborting." fname
103 (CicAst.pp_location loc))
108 message (sprintf "execution of %s completed." fname)
110 let _ = List.iter run_script scripts