1 (***********************************************************************)
5 (* Kim Nguyen, LRI UMR8623 *)
6 (* Université Paris-Sud & CNRS *)
8 (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (* Recherche Scientifique. All rights reserved. This file is *)
10 (* distributed under the terms of the GNU Lesser General Public *)
11 (* License, with the special exception on linking described in file *)
14 (***********************************************************************)
17 Time-stamp: <Last modified on 2013-04-25 15:05:36 CEST by Kim Nguyen>
23 let t1 = Unix.gettimeofday () in
25 let t2 = Unix.gettimeofday () in
26 let time = (t2 -. t1) *. 1000. in
27 Logger.msg `STATS "%s: %fms" msg time;
32 let () = Options.parse () in
34 let fd = open_in !Options.input_file in
35 let d = time Naive_tree.load_xml_file fd "parsing xml document" in
41 (Ulexing.from_latin1_string !Options.query)
45 time Xpath.Compile.path query "compiling XPath query"
48 match !Options.output_file with
49 | None | Some "-" | Some "/dev/stdout" -> stdout
50 | Some f -> open_out f
52 if !Options.stats then begin
53 Logger.msg `STATS "Query: %a " Xpath.Ast.print_path query;
54 Logger.msg `STATS "@[Automaton: @\n%a@]" Ata.print auto;
57 let module Naive = Eval.Make(Naive_tree) in
59 time (Naive.eval auto doc) (Naive_tree.root doc) "evaluating query"
62 output_string output "<xml_result>\n";
63 if !Options.count then begin
64 output_string output (string_of_int (List.length results));
65 output_char output '\n';
68 Naive_tree.print_xml output doc n;
69 output_char output '\n'
71 output_string output "</xml_result>\n";
73 if output != stdout then close_out output
75 ) () "serializing results"
82 Arg.Bad msg -> eprintf "Error: %s\n%!" msg; Options.usage (); exit 1
83 | Sys_error msg -> eprintf "Error: %s\n%!" msg; exit 2
84 | Tree.Parse_error msg -> eprintf "Error: file %s, %s\n%!" !Options.input_file msg; exit 3
85 | Xpath.Ulexer.Error (s, e, msg) -> eprintf "Error: character %i-%i: %s\n%!" s e msg; exit 4
86 | e -> eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e); exit 128