summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémie Dimino <jeremie@dimino.org>2011-12-22 21:11:29 +0000
committerJérémie Dimino <jeremie@dimino.org>2011-12-22 21:11:29 +0000
commit7396974e1add4ac14a063da5461de50f2758d5ad (patch)
tree4e50648653a8246d0f1a6f7be2f2c9954a6c0ec5
parentddc66298a3c48dccaf1879e4262b6e870522aec7 (diff)
PR#5120: fix the output function of Camlp4.Debug.formatter
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11945 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--camlp4/Camlp4/Debug.ml23
1 files changed, 7 insertions, 16 deletions
diff --git a/camlp4/Camlp4/Debug.ml b/camlp4/Camlp4/Debug.ml
index 2d901f3e9..73a38db89 100644
--- a/camlp4/Camlp4/Debug.ml
+++ b/camlp4/Camlp4/Debug.ml
@@ -50,24 +50,15 @@ value mode =
value formatter =
let header = "camlp4-debug: " in
- let normal s =
- let rec self from accu =
- try
- let i = String.index_from s from '\n'
- in self (i + 1) [String.sub s from (i - from + 1) :: accu]
- with
- [ Not_found -> [ String.sub s from (String.length s - from) :: accu ] ]
- in String.concat header (List.rev (self 0 [])) in
- let after_new_line str = header ^ normal str in
- let f = ref after_new_line in
- let output str chr = do {
- output_string out_channel (f.val str);
- output_char out_channel chr;
- f.val := if chr = '\n' then after_new_line else normal;
- } in
+ let at_bol = ref True in
(make_formatter
(fun buf pos len ->
- let p = pred len in output (String.sub buf pos p) buf.[pos + p])
+ for i = pos to pos + len - 1 do
+ if at_bol.val then output_string out_channel header else ();
+ let ch = buf.[i];
+ output_char out_channel ch;
+ at_bol.val := ch = '\n';
+ done)
(fun () -> flush out_channel));
value printf section fmt = fprintf formatter ("%s: " ^^ fmt) section;