Split the Options module in two to remove a circular dependency in
[SXSI/xpathcomp.git] / src / options.ml
1 open Utils
2 open Format
3 open Config
4
5 let set_index_type = function
6   | "default" -> text_index_type := 0
7   | "swcsa" -> text_index_type := 1
8   | "rlcsa" -> text_index_type := 2
9   | s -> raise (Arg.Bad(s))
10
11 let usage_msg = Printf.sprintf "%s [options] <input.{xml|srx}> 'query' [output]" Sys.argv.(0)
12
13 let pos = ref 0
14 let anon_fun =
15   fun s -> match !pos with
16     | 0 -> input_file:= s;incr pos
17     | 1 -> query := s; incr pos
18     | 2 -> output_file := Some s; incr pos
19     | _ -> raise (Arg.Bad(s))
20
21 let set_logger s =
22   List.iter (fun t ->
23     if t = "" then ()
24     else
25       match String.explode t ':' with
26         [ tr; lvl ] ->
27           let l = try int_of_string lvl with _ -> raise (Arg.Bad (lvl)) in
28           if Logger.is_logger tr then Logger.activate tr l
29           else raise (Arg.Bad (t))
30       | _ -> raise (Arg.Bad (t))
31   ) (String.explode s ',')
32
33 let pretty_loggers () =
34   ignore(flush_str_formatter());
35   Pretty.print_list
36     ~sep:", "
37     (fun f s -> fprintf f "%s" s)
38     str_formatter
39     (Logger.available ());
40   flush_str_formatter ()
41
42 let spec = Arg.align
43   [ "-c", Arg.Set(count_only),
44     " counting only (don't materialize the result set)";
45
46     "-two", Arg.Set(twopass),
47     " Use twopass algorithm";
48
49     "-f", Arg.Set_int(sample_factor),
50     "<n> sample factor [default=64]";
51
52     "-ne", Arg.Clear(index_empty_texts),
53     " don't index empty texts [default=index]";
54
55     "-d", Arg.Set(disable_text_collection),
56     " disable text collection[default=false]";
57
58     "-s", Arg.Set_string(save_file),
59     "<save_file> save the intermediate representation into file.srx";
60
61     "-b", Arg.Set(bottom_up), " real bottom up run";
62
63     "-nj", Arg.Set(no_jump), " disable jumping";
64
65     "-nc", Arg.Set(no_cache), " disable caching";
66
67     "-nw", Arg.Set(no_wrap_results), " do not wrap results in <xml_results/>";
68
69     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
70
71     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
72                                set_index_type),
73     " choose text index type";
74
75     "-r", Arg.Set_int(repeat),
76     " repeat query execution n time (benchmarking only, default 1)";
77
78     "-doc-stats", Arg.Set(docstats),
79     " Compute document statistics (performs full traversal)";
80
81
82     "-v", Arg.Set(verbose), " verbose mode"; ] @
83 IFNDEF NTRACE
84 THEN [
85     "-log", Arg.String (set_logger),
86     "<logger1:l1,...,loggern:ln> enable logging with the specified level. Valid loggers are: "
87       ^ (pretty_loggers ())
88      ]
89 ELSE []
90 END
91
92
93 let parse_cmdline() =
94   let _ = Arg.parse spec anon_fun usage_msg
95   in
96   if (!pos > 3 || !pos < 2)
97   then begin Arg.usage spec usage_msg; exit 1 end;
98   Logger.set_verbose !verbose
99
100
101
102
103