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:"
60 let _ = Helm_registry.load_from "matita.conf.xml"
64 let add_script fname = acc := fname :: !acc in
65 Arg.parse arg_spec add_script usage;
68 let parserr = new MatitaDisambiguator.parserr ()
71 ~host:(Helm_registry.get "db.host")
72 ~user:(Helm_registry.get "db.user")
73 ~database:(Helm_registry.get "db.database")
75 let _ = MetadataDb.clean ~dbd ~owner:(Helm_registry.get "matita.owner")
77 new MatitaDisambiguator.disambiguator ~parserr ~dbd
78 ~chooseUris:mono_uris_callback ~chooseInterp:mono_interp_callback
80 let console = new tty_console
81 let currentProof = (new MatitaProof.currentProof :> MatitaTypes.currentProof)
83 new MatitaInterpreter.interpreter
84 ~disambiguator ~currentProof ~console ~dbd ()
86 let run_script fname =
87 message (sprintf "execution of %s started." fname);
89 let ic = open_in fname in
90 let ast = snd (CicTextualParser2.parse_script (Stream.of_channel ic)) in
94 let rec aux = function
96 | DisambiguateTypes.Comment _ :: tl -> aux tl
97 | DisambiguateTypes.Command ast :: tl ->
100 | TacticAst.LocatedTactical (loc, _) -> loc
103 let (success, _) = interpreter#evalAst ast in
105 error (sprintf "%s: error at %s, aborting." fname
106 (CicAst.pp_location loc))
112 let _ = List.iter run_script scripts