X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Fgragrep.ml;fp=helm%2Fsoftware%2Fmatita%2Fgragrep.ml;h=d44c08d27232495237483cc91c7019132639ce83;hb=908c9a60083706cffe3ca1c9d235a05d38a19516;hp=0000000000000000000000000000000000000000;hpb=a7c127e864bb78e17bdfc2ba6e113a032b4df618;p=helm.git diff --git a/helm/software/matita/gragrep.ml b/helm/software/matita/gragrep.ml new file mode 100644 index 000000000..d44c08d27 --- /dev/null +++ b/helm/software/matita/gragrep.ml @@ -0,0 +1,67 @@ +(* Copyright (C) 2006, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://helm.cs.unibo.it/ + *) + +open Printf + +let is_notation = function GrafiteParser.LNone _ -> true | _ -> false + +let grep () = + let recursive = ref false in + let spec = [ + "-r", Arg.Set recursive, "enable directory recursion"; + ] in + MatitaInit.add_cmdline_spec spec; + MatitaInit.initialize_all (); + let include_paths = + Helm_registry.get_list Helm_registry.string "matita.includes" in + let status = + CicNotation2.load_notation ~include_paths + BuildTimeConf.core_notation_script in + let path = + match Helm_registry.get_list Helm_registry.string "matita.args" with + | [ path ] -> path + | _ -> MatitaInit.die_usage () in + let grep_fun = + if !recursive then + (fun dirname -> + ignore (GrafiteWalker.rgrep_statement ~status + ~callback:(fun (fname, s) -> printf "%s: %s\n%!" fname s) + ~dirname is_notation)) + else + (fun fname -> + ignore (GrafiteWalker.grep_statement ~status + ~callback:(fun s -> printf "%s\n%!" s) + ~fname is_notation)) in + grep_fun path + +let handle_localized_exns f arg = + try + f arg + with HExtlib.Localized (loc, exn) -> + let loc_begin, loc_end = HExtlib.loc_of_floc loc in + eprintf "Error at %d-%d: %s\n%!" loc_begin loc_end (Printexc.to_string exn) + +let main () = handle_localized_exns grep () +