+open Arg
+
+let count = ref false
+let input_file = ref ""
+let output_file : string option ref = ref None
+let query = ref ""
+let stats = ref false
+
+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";
+]
+
+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 () = 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")
+
+