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")
76 let owner = (Helm_registry.get "matita.owner") ;;
77 let _ = MetadataTypes.ownerize_tables owner ;;
78 let _ = MatitaDb.clean_owner_environment dbd owner ;;
79 let _ = MatitaDb.create_owner_environment dbd owner ;;
82 new MatitaDisambiguator.disambiguator ~parserr ~dbd
83 ~chooseUris:mono_uris_callback ~chooseInterp:mono_interp_callback
85 let console = new tty_console
86 let interpreter = MatitaInterpreter.interpreter ~disambiguator ~console ()
88 let run_script fname =
89 message (sprintf "execution of %s started:" fname);
91 let ic = open_in fname in
94 snd (CicTextualParser2.parse_script (Stream.of_channel ic))
98 assert false (* should be something like (Unix.exit 1) *)
103 let rec aux = function
104 | [] -> () (* script is over *)
105 | DisambiguateTypes.Comment _ :: tl -> aux tl
106 | DisambiguateTypes.Command ast :: tl ->
109 | TacticAst.LocatedTactical (loc, _) -> loc
112 let (success, _) = interpreter#evalAst ast in
114 error (sprintf "%s: error at %s, aborting." fname
115 (CicAst.pp_location loc))
120 message (sprintf "execution of %s completed." fname)
122 let _ = List.iter run_script scripts