]> matita.cs.unibo.it Git - helm.git/blob - helm/interface/experiment.ml
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / interface / experiment.ml
1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 24/01/2000                                 *)
32 (*                                                                            *)
33 (* This is a textual interface to the Coq-like pretty printer cicPp for cic   *)
34 (* terms exported in xml. It uses directly the modules cicPp and cache and    *)
35 (* indirectly all the other modules (cicParser, cicParser2, cicParser3,       *)
36 (* getter). The syntax is  "experiment[.opt] filename1 ... filenamen" where   *)
37 (* filenamei is the path-name of an xml file describing a cic term. On stdout *)
38 (* are pretty-printed all the n terms                                         *)
39 (*                                                                            *)
40 (******************************************************************************)
41
42 let pretty_print    = ref true;;
43 let read_from_stdin = ref false;;
44 let uris_in_input   = ref false;;
45
46 let parse uri =
47  if !pretty_print then
48   begin
49    print_endline ("^^^" ^ uri ^ "^^^") ;
50    print_string (CicPp.ppobj (CicCache.get_obj (UriManager.uri_of_string uri)));
51    print_endline ("\n$$$" ^ uri ^ "$$$\n")
52   end
53  else
54   begin
55    print_string uri ;
56    let _ = CicCache.get_obj  (UriManager.uri_of_string uri) in
57     print_endline " OK!" ;
58     flush stdout
59   end
60 ;;
61
62 let uri_of_filename fn =
63  if !uris_in_input then fn
64  else
65   let uri =
66    Str.replace_first (Str.regexp (Str.quote Configuration.helm_dir)) "cic:" fn
67   in
68    let uri' = Str.replace_first (Str.regexp "\.xml$") "" uri in
69     uri'
70 ;;
71
72 let read_filenames_from_stdin () =
73  let files = ref [] in
74   try
75    while true do
76     let l = Str.split (Str.regexp " ") (read_line ()) in
77      List.iter (fun x -> files := (uri_of_filename x) :: !files) l
78    done
79   with
80    End_of_file ->
81     files := List.rev !files ;
82     List.iter parse !files
83 ;;
84
85 (* filenames are read from command line and converted to uris via *)
86 (* uri_of_filenames; then the cic terms are load in cache via     *)
87 (* CicCache.get_obj  and then pretty printed via CicPp.ppobj      *)
88
89 let main() =
90   let files = ref [] in
91   Arg.parse
92    ["-nopp", Arg.Clear pretty_print, "Do not pretty print, parse only" ;
93     "-stdin", Arg.Set read_from_stdin, "Read from stdin" ;
94     "-uris", Arg.Set uris_in_input, "Read uris, not filenames" ;
95     "-update", Arg.Unit Getter.update, "Update the getter view of the world"]
96    (fun x -> files := (uri_of_filename x) :: !files)
97    "
98 usage: experiment file ...
99
100 List of options:";
101   if !read_from_stdin then read_filenames_from_stdin ()
102   else
103    begin
104     files := List.rev !files;
105     List.iter parse !files
106    end
107 ;;
108
109 main();;