]> matita.cs.unibo.it Git - helm.git/blob - matita/gragrep.ml
modifications to make matita behave reasonably, removed some useless windows
[helm.git] / matita / gragrep.ml
1 (* Copyright (C) 2006, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 let is_notation = function GrafiteParser.LNone _ -> true | _ -> false
29
30 let grep () =
31   let recursive = ref false in
32   let spec = [
33     "-r", Arg.Set recursive, "enable directory recursion";
34   ] in
35   MatitaInit.add_cmdline_spec spec;
36   MatitaInit.initialize_all ();
37   let include_paths =
38     Helm_registry.get_list Helm_registry.string "matita.includes" in
39   let status =
40     CicNotation2.load_notation ~include_paths
41       BuildTimeConf.core_notation_script in
42   let path =
43     match Helm_registry.get_list Helm_registry.string "matita.args" with
44     | [ path ] -> path
45     | _ -> MatitaInit.die_usage () in
46   let grep_fun =
47     if !recursive then
48       (fun dirname ->
49         ignore (GrafiteWalker.rgrep_statement ~status
50           ~callback:(fun (fname, s) -> printf "%s: %s\n%!" fname s)
51           ~dirname is_notation))
52     else
53       (fun fname ->
54         ignore (GrafiteWalker.grep_statement ~status
55           ~callback:(fun s -> printf "%s\n%!" s)
56           ~fname is_notation)) in
57   grep_fun path
58
59 let handle_localized_exns f arg =
60   try
61     f arg
62   with HExtlib.Localized (loc, exn) ->
63     let loc_begin, loc_end = HExtlib.loc_of_floc loc in
64     eprintf "Error at %d-%d: %s\n%!" loc_begin loc_end (Printexc.to_string exn)
65
66 let main () = handle_localized_exns grep ()
67