Update caching infrastructure to automatically resize when needed.
[SXSI/xpathcomp.git] / src / options.ml
1 open Utils
2 open Format
3
4 let index_empty_texts = ref false
5 let sample_factor = ref 64
6 let disable_text_collection = ref false
7 let tc_threshold = ref 60000
8
9 let query = ref ""
10 let input_file = ref ""
11 let output_file = ref None
12 let save_file = ref ""
13 let count_only = ref false
14 let time = ref false
15 let bottom_up = ref false
16 let no_jump = ref false
17 let verbose = ref false
18 let text_index_type = ref 0
19 let do_perf = ref false
20
21 (* Only valid if compiled with -DTRACE *)
22 let trace_file = ref "trace.dot"
23
24
25 let set_index_type = function
26   | "default" -> text_index_type := 0
27   | "swcsa" -> text_index_type := 1
28   | "rlcsa" -> text_index_type := 2
29   | s -> raise (Arg.Bad(s))
30
31 let usage_msg = Printf.sprintf "%s [options] <input.{xml|srx}> 'query' [output]" Sys.argv.(0)
32
33 let pos = ref 0
34 let anon_fun =
35   fun s -> match !pos with
36     | 0 -> input_file:= s;incr pos
37     | 1 -> query := s; incr pos
38     | 2 -> output_file := Some s; incr pos
39     | _ -> raise (Arg.Bad(s))
40
41 let set_tracer s =
42   List.iter (fun t ->
43     if t = "" then ()
44     else
45       match String.explode t ':' with
46         [ tr; lvl ] ->
47           let l = try int_of_string lvl with _ -> raise (Arg.Bad (lvl)) in
48           if Tracer.is_tracer tr then Tracer.activate tr l
49           else raise (Arg.Bad (t))
50       | _ -> raise (Arg.Bad (t))
51   ) (String.explode s ',')
52
53 let pretty_tracers () =
54   ignore(flush_str_formatter());
55   Pretty.print_list
56     ~sep:", "
57     (fun f s -> fprintf f "%s" s)
58     str_formatter
59     (Tracer.available ());
60   flush_str_formatter ()
61
62 let spec = Arg.align
63   [ "-c", Arg.Set(count_only),
64     " counting only (don't materialize the result set)";
65
66     "-f", Arg.Set_int(sample_factor),
67     "<n> sample factor [default=64]";
68
69     "-i", Arg.Set(index_empty_texts),
70     " index empty texts [default=false]";
71
72     "-d", Arg.Set(disable_text_collection),
73     " disable text collection[default=false]";
74
75     "-s", Arg.Set_string(save_file),
76     "<save_file> save the intermediate representation into file.srx";
77
78     "-b", Arg.Set(bottom_up), " real bottom up run";
79
80     "-nj", Arg.Set(no_jump), " disable jumping";
81
82     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
83
84     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
85                                set_index_type),
86     " choose text index type";
87
88     "-v", Arg.Set(verbose), " verbose mode"; ] @
89 IFNDEF NTRACE
90 THEN [
91     "-trace-file", Arg.Set_string(trace_file),
92     "<trace_file> save the full trace in dot format in <trace_file>";
93     "-trace", Arg.String (set_tracer),
94     "<tracer1:l1,...,tracern:ln> enable tracing with the specified level. Valid tracers are: "
95       ^ (pretty_tracers ())
96      ]
97 ELSE []
98 END
99
100
101 let parse_cmdline() =
102   let _ = Arg.parse spec anon_fun usage_msg
103   in
104   if (!pos > 3 || !pos < 2)
105   then begin Arg.usage spec usage_msg; exit 1 end
106
107
108
109
110