Add a new option to choose tree model at runtime.
[tatoo.git] / src / options.ml
index 142b709..c303c80 100644 (file)
@@ -1,39 +1,53 @@
 open Arg
 
 let count = ref false
-let input_file = ref ""
+let input_file : string option ref = ref None
 let output_file : string option ref = ref None
-let query = ref ""
+let queries = ref []
 let stats = ref false
+let compose = ref false
+let parallel = ref false
+let supported_models = [ "naive", (module Naive_tree : Tree.S);
+                         "compact",(module Compact_tree : Tree.S);
+                       ]
+let tree_model = ref  (fst (List.hd supported_models))
+let set_model s = tree_model := s
+
+let set_string_option r s = r := Some s
 
 let specs = align [
-  "-c", Set count, "";
-  "--count", Set count, " write the number of results only";
-  "-s", Set stats, "";
-  "--stats", Set stats, " display timing and various statistics";
+  "-c", Set count,
+        "  write the number of results only";
+  "--count", Set count, " ";
+  "-s", Set stats,
+        "  display timing and various statistics";
+  "--stats", Set stats, " ";
+  "-d", String (set_string_option input_file),
+        "  specify the input document file [default stdin]";
+  "--doc", String (set_string_option input_file), " ";
+  "-o", String (set_string_option output_file),
+        "  specify the output file [default stdout]";
+  "--out", String (set_string_option output_file), " ";
+  "-C", Set compose,
+        "  compose queries: each query is applied to the results of the \
+previous one [default run all queries from the root node]";
+  "--compose", Set compose, " ";
+  "-p", Set parallel,
+        "  run all queries in parallel [default run all queries \
+sequentially]";
+  "--parallel", Set parallel, " ";
+  "-m", Symbol (List.map fst supported_models, set_model),
+  "  specify tree model (naive or compact, default to naive)";
+  "--model", Symbol (List.map fst supported_models, set_model), " ";
 ]
 
-let usage_msg = Printf.sprintf "usage: %s [options] input.xml query [output.xml]" Sys.argv.(0)
-
-let get_anon, anon_arg =
-  let args = ref []  in
-  (fun () -> !args),
-  (fun s -> args := s::!args)
+let usage_msg =
+  Printf.sprintf "usage: %s [options] query [query ... query]" Sys.argv.(0)
 
 let usage () = usage specs usage_msg
 
 let parse () =
-  parse specs anon_arg usage_msg;
-  match List.rev (get_anon ()) with
-     input :: q :: maybe_output ->
-       input_file := input;
-       query := q;
-       begin
-         match maybe_output with
-           [] -> ()
-         | [ output ] -> output_file := Some output
-         | _ -> raise (Arg.Bad "too many arguments")
-       end
-  | [] | [ _ ] -> raise (Arg.Bad "not enough arguments")
-
-
+  parse specs (fun q -> queries := q :: !queries ) usage_msg;
+  match !queries with
+    [] -> raise (Arg.Bad "missing query")
+  | l -> queries := List.rev l