1 (* Copyright (C) 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/
28 type thingsToInitilaize =
29 ConfigurationFile | Db | Environment | Getter | Notation |
30 Paramodulation | Makelib | CmdLine
32 exception FailedToInitialize of thingsToInitilaize
37 if not (List.exists (fun x -> x = item) l) then
38 raise (FailedToInitialize item))
41 let already_configured s l =
42 List.for_all (fun item -> List.exists (fun x -> x = item) l) s
44 let load_configuration init_status =
45 if not (already_configured [ConfigurationFile] init_status) then
47 Helm_registry.load_from BuildTimeConf.matita_conf;
48 ConfigurationFile::init_status
53 let initialize_db init_status =
54 wants [ ConfigurationFile; CmdLine ] init_status;
55 if not (already_configured [ Db ] init_status) then
57 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
58 MatitaDb.create_owner_environment ();
64 let initialize_paramodulation init_status =
66 if not (already_configured [Paramodulation] init_status) then
68 Paramodulation.Saturation.init ();
69 Paramodulation::init_status
74 let initialize_makelib init_status =
75 wants [ConfigurationFile] init_status;
76 if not (already_configured [Makelib] init_status) then
78 MatitamakeLib.initialize ();
84 let initialize_notation init_status =
85 wants [ConfigurationFile] init_status;
86 if not (already_configured [Notation] init_status) then
88 CicNotation.load_notation BuildTimeConf.core_notation_script;
94 let initialize_environment init_status =
95 wants [ConfigurationFile] init_status;
96 if not (already_configured [Getter;Environment] init_status) then
99 CicEnvironment.set_trust (* environment trust *)
100 (let trust = Helm_registry.get_bool "matita.environment_trust" in
102 Getter::Environment::init_status
109 let usages = Hashtbl.create 11
112 (fun (name, s) -> Hashtbl.replace usages name s)
115 Usage: matitac [ OPTION ... ] FILE
117 BuildTimeConf.version;
120 Usage: matita [ OPTION ... ] [ FILE ... ]
122 BuildTimeConf.version;
126 Usage: cicbrowser [ URL | WHELP QUERY ]
128 BuildTimeConf.version;
130 sprintf "MatitaDep v%s
131 Usage: matitadep [ OPTION ... ] FILE ...
133 BuildTimeConf.version;
135 sprintf "MatitaClean v%s
136 Usage: matitaclean all
137 matitaclean [ (FILE | URI) ... ]
139 BuildTimeConf.version;
142 sprintf "Matita v%s\nUsage: matita [ ARG ]\nOptions:" BuildTimeConf.version
145 let basename = Filename.basename Sys.argv.(0) in
147 try Filename.chop_extension basename with Invalid_argument _ -> basename
149 try Hashtbl.find usages usage_key with Not_found -> default_usage
151 let registry_defaults =
154 "matita.debug", "false";
155 "matita.external_editor", "gvim -f -c 'go %p' %f";
156 "matita.preserve", "false";
157 "matita.quiet", "false";
160 let set_registry_values =
161 List.iter (fun key, value -> Helm_registry.set ~key ~value)
163 let parse_cmdline init_status =
164 if not (already_configured [CmdLine] init_status) then begin
165 let includes = ref [] in
167 let add_l l = fun s -> l := s :: !l in
170 "-I", Arg.String (add_l includes),
171 ("<path> Adds path to the list of searched paths for the "
172 ^ "include command");
173 "-q", Arg.Unit (fun () -> Helm_registry.set_bool "matita.quiet" true),
174 "Turn off verbose compilation";
176 Arg.Unit (fun () -> Helm_registry.set_bool "matita.preserve" true),
177 "Turns off automatic baseuri cleaning";
178 "-nodb", Arg.Unit (fun () -> Helm_registry.set_bool "db.nodb" true),
179 ("Avoid using external database connection "
180 ^ "(WARNING: disable many features)");
183 if BuildTimeConf.debug then
185 Arg.Unit (fun () -> Helm_registry.set_bool "matita.debug" true),
186 ("Do not catch top-level exception "
187 ^ "(useful for backtrace inspection)");
191 std_arg_spec @ debug_arg_spec
193 let set_list ~key l =
194 Helm_registry.set_list Helm_registry.of_string ~key ~value:(List.rev !l)
196 set_registry_values registry_defaults;
197 Arg.parse arg_spec (add_l args) (usage ());
198 set_list ~key:"matita.includes" includes;
199 set_list ~key:"matita.args" args;
200 CmdLine :: init_status
205 print_endline (usage ());
208 let initialize_all () =
211 (initialize_environment
213 (initialize_paramodulation
216 (parse_cmdline !status))))))
218 let load_configuration_file () =
219 status := load_configuration !status
221 let initialize_notation () =
222 status := initialize_notation (load_configuration !status)
224 let parse_cmdline () =
225 status := parse_cmdline !status