d72763ec8ba29a2277cb223530acf3716a4db5a1
[SXSI/xpathcomp.git] / src / options.ml
1 let index_empty_texts = ref false
2 let sample_factor = ref 64
3 let disable_text_collection = ref false
4 let tc_threshold = ref 60000
5
6 let query = ref ""
7 let input_file = ref ""
8 let output_file = ref None
9 let save_file = ref ""
10 let count_only = ref false
11 let time = ref false
12 let bottom_up = ref false
13 let no_jump = ref false
14 let verbose = ref false
15 let text_index_type = ref 0
16 let do_perf = ref false
17
18 (* Only valid if compiled with -DTRACE *)
19 let trace_file = ref "trace.dot"
20
21
22 let set_index_type = function
23   | "default" -> text_index_type := 0
24   | "swcsa" -> text_index_type := 1
25   | "rlcsa" -> text_index_type := 2
26   | s -> raise (Arg.Bad(s))
27
28 let usage_msg = Printf.sprintf "%s [options] <input.{xml|srx}> 'query' [output]" Sys.argv.(0)
29
30
31 let pos = ref 0
32 let anon_fun =
33   fun s -> match !pos with
34     | 0 -> input_file:= s;incr pos
35     | 1 -> query := s; incr pos
36     | 2 -> output_file := Some s; incr pos
37     | _ -> raise (Arg.Bad(s))
38
39 let spec = Arg.align
40   [ "-c", Arg.Set(count_only),
41     " counting only (don't materialize the result set)";
42
43     "-f", Arg.Set_int(sample_factor),
44     "<n> sample factor [default=64]";
45
46     "-i", Arg.Set(index_empty_texts),
47     " index empty texts [default=false]";
48
49     "-d", Arg.Set(disable_text_collection),
50     " disable text collection[default=false]";
51
52     "-s", Arg.Set_string(save_file),
53     "<save_file> save the intermediate representation into file.srx";
54
55     "-b", Arg.Set(bottom_up), " real bottom up run";
56
57     "-nj", Arg.Set(no_jump), " disable jumping";
58
59     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
60
61     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
62                                set_index_type),
63     " choose text index type";
64
65     "-v", Arg.Set(verbose), " verbose mode"; ] @
66 IFDEF TRACE
67 THEN [
68     "-trace-file", Arg.Set_string(trace_file),
69     "<trace_file> save the full trace in dot format in <trace_file>"
70      ]
71 ELSE []
72 END
73
74
75 let parse_cmdline() =
76   let _ = Arg.parse spec anon_fun usage_msg
77   in
78   if (!pos > 3 || !pos < 2)
79   then begin Arg.usage spec usage_msg; exit 1 end
80
81
82
83
84