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/
30 type thingsToInitilaize =
31 ConfigurationFile | Db | Environment | Getter | Makelib | CmdLine | Registry
33 exception FailedToInitialize of thingsToInitilaize
38 if not (List.exists (fun x -> x = item) l) then
39 raise (FailedToInitialize item))
42 let already_configured s l =
43 List.for_all (fun item -> List.exists (fun x -> x = item) l) s
45 let conffile = ref BuildTimeConf.matita_conf
47 let registry_defaults =
50 "matita.system", "false";
51 "matita.debug", "false";
52 "matita.external_editor", "gvim -f -c 'go %p' %f";
53 "matita.preserve", "false";
54 "matita.quiet", "false";
55 "matita.profile", "true";
58 let set_registry_values =
59 List.iter (fun key, value -> Helm_registry.set ~key ~value)
61 let fill_registry init_status =
62 if not (already_configured [ Registry ] init_status) then begin
63 set_registry_values registry_defaults;
64 Registry :: init_status
68 let load_configuration init_status =
69 wants [ Registry ] init_status;
70 if not (already_configured [ConfigurationFile] init_status) then
72 Helm_registry.load_from !conffile;
73 if not (Helm_registry.has "user.name") then begin
74 let login = (Unix.getpwuid (Unix.getuid ())).Unix.pw_name in
75 Helm_registry.set "user.name" login
77 if Helm_registry.get_bool "matita.system" then
78 Helm_registry.set "user.home" BuildTimeConf.runtime_base_dir;
79 ConfigurationFile::init_status
84 let initialize_db init_status =
85 wants [ ConfigurationFile; CmdLine ] init_status;
86 if not (already_configured [ Db ] init_status) then
88 if not (Helm_registry.get_bool "matita.system") then
89 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
90 LibraryDb.create_owner_environment ();
96 let initialize_makelib init_status =
97 wants [ConfigurationFile] init_status;
98 if not (already_configured [Makelib] init_status) then
100 MatitamakeLib.initialize ();
106 let initialize_environment init_status =
107 wants [ConfigurationFile] init_status;
108 if not (already_configured [Getter;Environment] init_status) then
111 CicEnvironment.set_trust (* environment trust *)
113 Helm_registry.get_opt_default Helm_registry.get_bool
114 ~default:true "matita.environment_trust" in
116 Getter::Environment::init_status
123 let usages = Hashtbl.create 11
126 (fun (name, s) -> Hashtbl.replace usages name s)
129 Usage: matitac [ OPTION ... ] FILE
131 BuildTimeConf.version;
134 Usage: matita [ OPTION ... ] [ FILE ... ]
136 BuildTimeConf.version;
140 Usage: cicbrowser [ URL | WHELP QUERY ]
142 BuildTimeConf.version;
144 sprintf "MatitaDep v%s
145 Usage: matitadep [ OPTION ... ] FILE ...
147 BuildTimeConf.version;
149 sprintf "MatitaClean v%s
150 Usage: matitaclean all
151 matitaclean [ (FILE | URI) ... ]
153 BuildTimeConf.version;
156 sprintf "Matita v%s\nUsage: matita [ ARG ]\nOptions:" BuildTimeConf.version
159 let basename = Filename.basename Sys.argv.(0) in
161 try Filename.chop_extension basename with Invalid_argument _ -> basename
163 try Hashtbl.find usages usage_key with Not_found -> default_usage
165 let parse_cmdline init_status =
166 if not (already_configured [CmdLine] init_status) then begin
167 let includes = ref [ BuildTimeConf.stdlib_dir ] in
169 let add_l l = fun s -> l := s :: !l in
172 "-I", Arg.String (add_l includes),
173 ("<path> Adds path to the list of searched paths for the "
174 ^ "include command");
175 "-conffile", Arg.Set_string conffile,
176 (Printf.sprintf "<filename> Read configuration from filename (default: %s)"
177 BuildTimeConf.matita_conf);
178 "-q", Arg.Unit (fun () -> Helm_registry.set_bool "matita.quiet" true),
179 "Turn off verbose compilation";
181 Arg.Unit (fun () -> Helm_registry.set_bool "matita.preserve" true),
182 "Turns off automatic baseuri cleaning";
183 "-nodb", Arg.Unit (fun () -> Helm_registry.set_bool "db.nodb" true),
184 ("Avoid using external database connection "
185 ^ "(WARNING: disable many features)");
186 "-system", Arg.Unit (fun () ->
187 Helm_registry.set_bool "matita.system" true),
188 ("Act on the system library instead of the user one"
189 ^ "(WARNING: not for the casual user)");
191 Arg.Unit (fun () -> Helm_registry.set_bool "matita.profile" false),
192 "Turns off profiling printings";
195 if BuildTimeConf.debug then
197 Arg.Unit (fun () -> Helm_registry.set_bool "matita.debug" true),
198 ("Do not catch top-level exception "
199 ^ "(useful for backtrace inspection)");
203 std_arg_spec @ debug_arg_spec
205 let set_list ~key l =
206 Helm_registry.set_list Helm_registry.of_string ~key ~value:(List.rev !l)
208 Arg.parse arg_spec (add_l args) (usage ());
209 set_list ~key:"matita.includes" includes;
210 set_list ~key:"matita.args" args;
211 HExtlib.set_profiling_printings
212 (fun () -> Helm_registry.get_bool "matita.profile");
213 CmdLine :: init_status
218 print_endline (usage ());
221 let initialize_all () =
223 List.fold_left (fun s f -> f s) !status
225 parse_cmdline; load_configuration; initialize_makelib;
226 initialize_db; initialize_environment ]
227 (* initialize_notation
228 (initialize_environment
232 (parse_cmdline !status))))) *)
234 let load_configuration_file () =
235 status := load_configuration !status
237 let parse_cmdline () =
238 status := parse_cmdline !status
240 let fill_registry () =
241 status := fill_registry !status