Add a test program for experimenting with lexicographic indices.
[SXSI/xpathcomp.git] / src / lextest.ml
1 (* Abstract type for the index, generated from C++ code *)
2
3 type index
4
5 external build_lex_index : Tree.t -> Tag.t -> index = "caml_build_lex_index"
6 external print_lex_index : index -> unit = "caml_print_lex_index"
7
8
9 let main () =
10   if Array.length Sys.argv != 3 then
11   let () = Printf.eprintf "Error: invalid argument" in exit 1
12   else
13   let file = Sys.argv.(1) in
14   (* Load the index or the xml file *)
15   Printf.printf "Loading document\n%!";
16   let document =
17     if Filename.check_suffix file ".srx"
18     then Tree.load file
19     else if Filename.check_suffix file ".xml" then Tree.parse_xml_uri file
20     else
21     let () = Printf.eprintf "Error: unrecognized extension" in exit 2
22   in
23   Printf.printf "Building lex index\n%!";
24   let index = build_lex_index document (Tag.tag Sys.argv.(2)) in
25   Printf.printf "Printing lex index\n%!";
26   print_lex_index index;
27   exit 0
28
29
30 let () =
31   try
32     main ()
33   with
34     e -> Printf.eprintf "Fatal error: %s" (Printexc.to_string e); exit 3
35