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);
49 method show ?(msg = "") () = assert false; ()
50 method choose_uri (uris: string list): string = assert false
53 (** {2 Initialization} *)
56 (* "-opt", Arg...., "set bla bla bla"; *)
59 sprintf "MatitaC v%s\nUsage: matitac [option ...] file ...\nOptions:"
63 Helm_registry.load_from "matita.conf.xml";
65 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
66 MatitaDb.clean_owner_environment ();
67 MatitaDb.create_owner_environment ()
71 let add_script fname = acc := fname :: !acc in
72 Arg.parse arg_spec add_script usage;
75 let console = new tty_console
76 let interpreter = MatitaInterpreter.interpreter ~console ()
78 let run_script fname =
79 message (sprintf "execution of %s started:" fname);
81 let ic = open_in fname in
84 snd (CicTextualParser2.parse_script (Stream.of_channel ic))
88 assert false (* should be something like (Unix.exit 1) *)
93 let rec aux = function
94 | [] -> () (* script is over *)
95 | DisambiguateTypes.Comment _ :: tl -> aux tl
96 | DisambiguateTypes.Command ast :: tl ->
99 | TacticAst.LocatedTactical (loc, _) -> loc
102 let (success, _) = interpreter#evalAst ast in
104 error (sprintf "%s: error at %s, aborting." fname
105 (CicAst.pp_location loc))
110 message (sprintf "execution of %s completed." fname)
112 let _ = List.iter run_script scripts