]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/matitaclean.ml
matitamake stuff:
[helm.git] / helm / matita / matitaclean.ml
1 module UM = UriManager;;
2 module TA = TacticAst;;
3
4 let _ =
5   Helm_registry.load_from BuildTimeConf.matita_conf;
6   Http_getter.init ();
7   MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
8   MatitaDb.create_owner_environment ()
9
10 let main uri_to_remove = MatitacleanLib.clean_baseuris uri_to_remove
11
12 let usage () =
13   prerr_endline "";
14   prerr_endline "usage:";
15   prerr_endline "\tmatitaclean all";
16   prerr_endline "\t\tcleans the whole environment";
17   prerr_endline "\tmatitaclean files...";
18   prerr_endline "\t\tcleans the output of the compilation of files...\n";
19   prerr_endline "";
20   exit 1
21     
22 let _ = 
23   if Array.length Sys.argv < 2 then usage ();
24   if Sys.argv.(1) = "all" then 
25     begin
26       MatitaDb.clean_owner_environment ();
27       exit 0
28     end
29   let uris_to_remove =ref [] in
30   let files_to_remove =ref [] in
31   (try 
32     for i = 1 to Array.length Sys.argv - 1 do
33       let suri = Sys.argv.(i) in
34       let uri = 
35         try
36           UM.buri_of_uri (UM.uri_of_string suri)
37         with
38           UM.IllFormedUri _ ->
39            files_to_remove := suri :: !files_to_remove;
40            let u = MatitacleanLib.baseuri_of_file suri in
41            if String.length u < 5 || String.sub u 0 5 <> "cic:/" then
42              begin
43                MatitaLog.error ("File " ^ suri ^ " defines a bad baseuri: "^u);
44                exit 1
45              end
46            else
47              u
48       in
49       uris_to_remove := uri :: !uris_to_remove
50     done
51   with
52     Invalid_argument _ -> usage ());
53   main !uris_to_remove;
54   let moos = List.map MatitaMisc.obj_file_of_script !files_to_remove in
55   List.iter
56     (fun s -> try Unix.unlink s with Unix.Unix_error _ -> ()) 
57     moos
58