WIP on beautyfying the pretty-printing module.
[SXSI/xpathcomp.git] / src / options.ml
1 open Format
2
3 let index_empty_texts = ref true
4 let sample_factor = ref 64
5 let disable_text_collection = ref false
6 let tc_threshold = ref 60000
7
8 let query = ref ""
9 let input_file = ref ""
10 let output_file = ref None
11 let save_file = ref ""
12 let count_only = ref false
13 let time = ref false
14 let bottom_up = ref false
15 let no_jump = ref false
16 let no_cache = 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 let docstats = ref false
23 let no_wrap_results = ref false
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_logger s =
42   List.iter (fun t ->
43     if t = "" then ()
44     else
45       match Utils.String.explode t ':' with
46         [ tr; lvl ] ->
47           let l = try int_of_string lvl with _ -> raise (Arg.Bad (lvl)) in
48           if Logger.is_logger tr then Logger.activate tr l
49           else raise (Arg.Bad (t))
50       | _ -> raise (Arg.Bad (t))
51   ) (Utils.String.explode s ',')
52
53 let pretty_loggers () =
54   ignore(flush_str_formatter());
55   Pretty.print_list
56     ~sep:", "
57     (fun f s -> fprintf f "%s" s)
58     str_formatter
59     (Logger.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     "-two", Arg.Set(twopass),
67     " Use twopass algorithm";
68
69     "-f", Arg.Set_int(sample_factor),
70     "<n> sample factor [default=64]";
71
72     "-ne", Arg.Clear(index_empty_texts),
73     " don't index empty texts [default=index]";
74
75     "-d", Arg.Set(disable_text_collection),
76     " disable text collection[default=false]";
77
78     "-s", Arg.Set_string(save_file),
79     "<save_file> save the intermediate representation into file.srx";
80
81     "-b", Arg.Set(bottom_up), " real bottom up run";
82
83     "-nj", Arg.Set(no_jump), " disable jumping";
84
85     "-nc", Arg.Set(no_cache), " disable caching";
86
87     "-nw", Arg.Set(no_wrap_results), " do not wrap results in <xml_results/>";
88
89     "-p",  Arg.Set(do_perf), " dump perf counters (Linux only)";
90
91     "-index-type", Arg.Symbol ([ "default"; "swcsa"; "rlcsa" ],
92                                set_index_type),
93     " choose text index type";
94
95     "-r", Arg.Set_int(repeat),
96     " repeat query execution n time (benchmarking only, default 1)";
97
98     "-doc-stats", Arg.Set(docstats),
99     " Compute document statistics (performs full traversal)";
100
101
102     "-v", Arg.Set(verbose), " verbose mode"; ] @
103 IFNDEF NTRACE
104 THEN [
105     "-log", Arg.String (set_logger),
106     "<logger1:l1,...,loggern:ln> enable logging with the specified level. Valid loggers are: "
107       ^ (pretty_loggers ())
108      ]
109 ELSE []
110 END
111
112
113 let parse_cmdline() =
114   let _ = Arg.parse spec anon_fun usage_msg
115   in
116   if (!pos > 3 || !pos < 2)
117   then begin Arg.usage spec usage_msg; exit 1 end;
118   Logger.set_verbose !verbose
119
120
121
122
123