0c7c92d8abcdcbe9dbb2c0501f712f9a778afd62
[SXSI/xpathcomp.git] / src / options.ml
1 open Utils
2 open Format
3
4 let index_empty_texts = ref true
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 let twopass = ref false
21 let repeat = ref 1
22
23 let set_index_type = function
24   | "default" -> text_index_type := 0
25   | "swcsa" -> text_index_type := 1
26   | "rlcsa" -> text_index_type := 2
27   | s -> raise (Arg.Bad(s))
28
29 let usage_msg = Printf.sprintf "%s [options] <input.{xml|srx}> 'query' [output]" Sys.argv.(0)
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 set_logger s =
40   List.iter (fun t ->
41     if t = "" then ()
42     else
43       match String.explode t ':' with
44         [ tr; lvl ] ->
45           let l = try int_of_string lvl with _ -> raise (Arg.Bad (lvl)) in
46           if Logger.is_logger tr then Logger.activate tr l
47           else raise (Arg.Bad (t))
48       | _ -> raise (Arg.Bad (t))
49   ) (String.explode s ',')
50
51 let pretty_loggers () =
52   ignore(flush_str_formatter());
53   Pretty.print_list
54     ~sep:", "
55     (fun f s -> fprintf f "%s" s)
56     str_formatter
57     (Logger.available ());
58   flush_str_formatter ()
59
60 let spec = Arg.align
61   [ "-c", Arg.Set(count_only),
62     " counting only (don't materialize the result set)";
63
64     "-two", Arg.Set(twopass),
65     " Use twopass algorithm";
66
67     "-f", Arg.Set_int(sample_factor),
68     "<n> sample factor [default=64]";
69
70     "-ne", Arg.Clear(index_empty_texts),
71     " don't index empty texts [default=index]";
72
73     "-d", Arg.Set(disable_text_collection),
74     " disable text collection[default=false]";
75
76     "-s", Arg.Set_string(save_file),
77     "<save_file> save the intermediate representation into file.srx";
78
79     "-b", Arg.Set(bottom_up), " real bottom up run";
80
81     "-nj", Arg.Set(no_jump), " disable jumping";
82
83     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
84
85     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
86                                set_index_type),
87     " choose text index type";
88
89     "-r", Arg.Set_int(repeat),
90     " repeat query execution n time (benchmarking only, default 1)";
91
92
93
94     "-v", Arg.Set(verbose), " verbose mode"; ] @
95 IFNDEF NTRACE
96 THEN [
97     "-log", Arg.String (set_logger),
98     "<logger1:l1,...,loggern:ln> enable logging with the specified level. Valid loggers are: "
99       ^ (pretty_loggers ())
100      ]
101 ELSE []
102 END
103
104
105 let parse_cmdline() =
106   let _ = Arg.parse spec anon_fun usage_msg
107   in
108   if (!pos > 3 || !pos < 2)
109   then begin Arg.usage spec usage_msg; exit 1 end
110
111
112
113
114