]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/matex/matex.ml
MaTeX
[helm.git] / matita / components / binaries / matex / matex.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 module A = Arg
13 module F = Filename
14
15 module U = NUri
16 module R = Helm_registry
17 module L = Librarian
18
19 module X = Ground
20 module G = Options
21 module E = Engine
22 module O = TeXOutput
23 module K = Kernel
24
25 let help_O = "<dir> Set this output directory"
26 let help_X = " Clear configuration and options"
27 let help_l = "<file> Output the list of generated files in this file"
28 let help_p = " omit types (default: no)"
29 let help_t = " Test anticipation (default: no)"
30
31 let help   = ""
32
33 (* internal functions *******************************************************)
34
35 let init registry =
36    R.load_from registry; 
37    if !G.no_init then begin
38       K.init ();
39       G.no_init := false;
40    end
41
42 let is_registry s =
43    F.check_suffix s ".conf.xml"
44
45 let no_init () =
46    failwith "MaTeX: main: registry not initialized" 
47
48 let malformed s =
49    failwith ("MaTeX: main: malformed argument: " ^ s)
50
51 let set_list fname =
52    let file = F.concat !G.out_dir fname in
53    G.close_list (); G.list_och := Some (open_out file)
54
55 let process s =
56    if is_registry s then init s
57    else if !G.no_init then no_init ()
58    else if L.is_uri s then E.process (U.uri_of_string s)
59    else malformed s
60
61 let main =
62 begin try
63    A.parse [
64       "-O", A.String ((:=) G.out_dir), help_O;
65       "-X", A.Unit G.clear, help_X;
66       "-l", A.String set_list, help_l;
67       "-p", A.Set G.no_types, help_p;
68       "-t", A.Set G.test, help_t;
69    ] process help
70 with
71    | X.Error s -> X.log s
72 end;
73 G.close_list ()