From 4694574a0dd67cab15d8408007a9665928e6a776 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Fri, 19 Oct 2012 21:13:06 +0200 Subject: [PATCH] Add option -nw control the wrapping of results in an node. --- src/main.ml | 2 +- src/nodeSet.ml | 15 ++++++++------- src/nodeSet.mli | 2 +- src/options.ml | 2 ++ src/options.mli | 1 + 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.ml b/src/main.ml index 96e835e..2030452 100644 --- a/src/main.ml +++ b/src/main.ml @@ -28,7 +28,7 @@ let mk_runtime run auto doc arg count print outfile = match outfile with None -> () | Some file -> - time ~count:1 ~msg:"Serialization time" (print file doc) r + time ~count:1 ~msg:"Serialization time" (print file !Options.no_wrap_results doc) r ;; let main v query_string output = diff --git a/src/nodeSet.ml b/src/nodeSet.ml index c2265b2..fc0bb0e 100644 --- a/src/nodeSet.ml +++ b/src/nodeSet.ml @@ -24,7 +24,7 @@ module type S = val iter : ( elt -> unit) -> t -> unit val fold : ( elt -> 'a -> 'a) -> t -> 'a -> 'a val length : t -> int - val serialize : string -> Tree.t -> t -> unit + val serialize : string -> bool -> Tree.t -> t -> unit end @@ -52,11 +52,12 @@ module Count : S with type t = int = let fold _ _ _ = failwith "fold not implemented" let map _ _ = failwith "map not implemented" let length x = x - let serialize f _ x = + let serialize f b _ x = let o = open_out f in - output_string o "\n"; + if not b then output_string o "\n"; output_string o (string_of_int x); - output_string o "\n\n"; + output_char o '\n'; + if not b then output_string o "\n"; close_out o end @@ -191,19 +192,19 @@ module Mat : S with type t = Tree.node mat = let length l = l.length - let serialize name v l = + let serialize name b v l = let fd, finish = if name = "-" then Unix.stdout, ignore else Unix.openfile name [ Unix.O_WRONLY; Unix.O_TRUNC; Unix.O_CREAT ] 0o666, Unix.close in - ignore (Unix.write fd "\n" 0 13); + if not b then ignore (Unix.write fd "\n" 0 13); if l.length > 0 then begin iter (fun node -> Tree.print_xml v node fd) l; Tree.flush v fd; end; - ignore (Unix.write fd "\n" 0 14); + if not b then ignore (Unix.write fd "\n" 0 14); finish fd end diff --git a/src/nodeSet.mli b/src/nodeSet.mli index 2417ede..d9215ac 100644 --- a/src/nodeSet.mli +++ b/src/nodeSet.mli @@ -21,7 +21,7 @@ module type S = val iter : ( elt -> unit) -> t -> unit val fold : ( elt -> 'a -> 'a) -> t -> 'a -> 'a val length : t -> int - val serialize : string -> Tree.t -> t -> unit + val serialize : string -> bool -> Tree.t -> t -> unit diff --git a/src/options.ml b/src/options.ml index 6dfaaef..4a7a0c7 100644 --- a/src/options.ml +++ b/src/options.ml @@ -21,6 +21,7 @@ let do_perf = ref false let twopass = ref false let repeat = ref 1 let docstats = ref false +let no_wrap_results = ref false let set_index_type = function | "default" -> text_index_type := 0 @@ -84,6 +85,7 @@ let spec = Arg.align "-nc", Arg.Set(no_cache), " disable caching"; + "-nw", Arg.Set(no_wrap_results), " do not wrap results in "; "-p", Arg.Set(do_perf), " dump perf counters (Linux only)"; diff --git a/src/options.mli b/src/options.mli index 6267853..4626e57 100644 --- a/src/options.mli +++ b/src/options.mli @@ -18,3 +18,4 @@ val do_perf : bool ref val twopass : bool ref val repeat : int ref val docstats : bool ref +val no_wrap_results : bool ref -- 2.17.1