-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofound.ml
107 lines (98 loc) · 2.96 KB
/
profound.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(*
* Author: Kaustuv Chaudhuri <[email protected]>
* Copyright (C) 2013 Inria (Institut National de Recherche
* en Informatique et en Automatique)
* See LICENSE for licensing details.
*)
module Force = struct
(* open Form *)
end
open Batteries
open Syntax
let set_verbosity v =
let open Log in
begin match v with
| 0 -> loglevel := FATAL
| 1 -> loglevel := ERROR
| 2 -> loglevel := WARN
| 3 -> loglevel := INFO
| 4 -> loglevel := DEBUG
| _ -> loglevel := TRACE
end
let infile = ref None
let set_infile fn =
begin match !infile with
| Some ofn ->
Log.eprintf "Cannot specify more than one input file" ;
exit 1
| None ->
if Sys.file_exists fn then
infile := Some fn
else begin
Log.(log FATAL "Could not find input file %S" fn) ;
exit 2
end
end
let set_max_hist n =
let m = max 0 (min n 20) in
if m <> n then
Log.(log WARN "Cannot display %d history lines; displaying %d instead" n m) ;
Syntax_tex.max_hist := m
let parse_opts () =
let open Arg in
let opts = [
"-i", String set_infile, "<file> Read theorem from <file>" ;
"-v", Int set_verbosity, "<num> Set vebosity to <num>" ;
"-s", Set Syntax_fmt.display_sink_as_source, " Use the same colors for source and sink" ;
"-log", String Log.to_file, "<file> Log output to file (default: stdout)" ;
"-hist-lines", Int set_max_hist, "<num> Set the number of history lines to display to <num>" ;
"-version", Unit (fun () ->
Printf.printf "Profound %s\n" Version.str ;
exit 0
), " Display a version string" ;
"-vnum", Unit (fun () ->
Printf.printf "%s%!" Version.str ;
exit 0
), " Display a version number (no newline at end)" ;
] in
let opts = align opts in
let umsg = "Usage: profound [options] (theorem | -i file)" in
let imm_txt = ref None in
let add_txt txt = match !imm_txt with
| Some _ ->
Log.eprintf "Only a single theorem at a time!" ;
raise (Bad txt)
| None ->
imm_txt := Some txt
in
parse opts add_txt umsg ;
try begin match !infile, !imm_txt with
| _, Some txt ->
if Option.is_some !infile then
Log.(log ERROR "Ignoring input file %S" (Option.get !infile)) ;
Gui.Imm (Syntax_io.form_of_string [] txt)
| Some fin, None ->
Gui.File (fin, Syntax_io.load_file fin)
| None, None ->
Log.eprintf "Need an input file or theorem" ;
Arg.usage opts umsg ;
exit 1
end with
| Syntax_io.Parsing msg ->
if msg = "" then Log.eprintf "Parsing error"
else Log.eprintf "Parsing error: %s" msg ;
exit 1
let main () =
Log.to_stdout () ;
Log.(log INFO "Profound %s START" Version.str) ;
let mode = parse_opts () in
ignore (GMain.init ()) ;
Log.(log INFO "GTK+ Initialized") ;
Gui.run mode ;
Log.(log INFO "Done") ;
Log.reset ()
let () =
if !Sys.interactive then
Printf.printf "Profound %s\n" Version.str
else
main ()