244
let _chan_pr2 = ref (None: out_channel option)
246
let out_chan_pr2 ?(newline=true) s =
247
match !_chan_pr2 with
250
output_string chan (s ^ (if newline then "\n" else ""));
241
255
prerr_string !_prefix_pr;
242
256
do_n !_tab_level_print (fun () -> prerr_string " ");
244
258
prerr_string "\n";
247
263
let pr2_no_nl s =
248
264
prerr_string !_prefix_pr;
249
265
do_n !_tab_level_print (fun () -> prerr_string " ");
268
out_chan_pr2 ~newline:false s;
253
272
let pr_xxxxxxxxxxxxxxxxx () =
254
273
pr "-----------------------------------------------------------------------"
386
405
let _already_printed = Hashtbl.create 101
387
406
let disable_pr2_once = ref false
389
409
if !disable_pr2_once then pr2 s
391
411
if not (Hashtbl.mem _already_printed s)
393
413
Hashtbl.add _already_printed s true;
417
let pr2_once s = xxx_once pr2 s
419
(* ---------------------------------------------------------------------- *)
420
let mk_pr2_wrappers aref =
425
(* just to the log file *)
432
xxx_once out_chan_pr2 s
398
437
(* ---------------------------------------------------------------------- *)
399
438
(* could also be in File section *)
1051
1094
let pp s = Format.print_string s
1055
(* julia: convert something printed using format to print into a string *)
1056
let format_to_string f =
1057
let o = open_out "/tmp/out" in
1058
Format.set_formatter_out_channel o;
1060
Format.print_flush();
1061
Format.set_formatter_out_channel stdout;
1063
let i = open_in "/tmp/out" in
1064
let lines = ref [] in
1066
let cur = input_line i in
1067
lines := cur :: !lines;
1069
(try loop() with End_of_file -> ());
1071
String.concat "\n" (List.rev !lines)
1075
1096
let mk_str_func_of_assoc_conv xs =
1076
1097
let swap (x,y) = (y,x) in
1401
1443
Gc.set {(Gc.get ()) with Gc.stack_limit = 100 * 1024 * 1024}
1404
1448
(* if process a big set of files then dont want get overflow in the middle
1405
1449
* so for this we are ready to spend some extra time at the beginning that
1406
1450
* could save far more later.
5350
let (full_charpos_to_pos2: filename -> (int * int) array ) = fun filename ->
5352
let arr = Array.create (filesize filename + 2) (0,0) in
5394
let full_charpos_to_pos2 = fun filename ->
5396
let size = (filesize filename + 2) in
5398
let arr = Array.create size (0,0) in
5354
5400
let chan = open_in filename in
5394
5440
column = snd (table.(x.charpos));
5445
let full_charpos_to_pos_large2 = fun filename ->
5447
let size = (filesize filename + 2) in
5449
(* old: let arr = Array.create size (0,0) in *)
5450
let arr1 = Bigarray.Array1.create
5451
Bigarray.int Bigarray.c_layout size in
5452
let arr2 = Bigarray.Array1.create
5453
Bigarray.int Bigarray.c_layout size in
5454
Bigarray.Array1.fill arr1 0;
5455
Bigarray.Array1.fill arr2 0;
5457
let chan = open_in filename in
5459
let charpos = ref 0 in
5462
let rec full_charpos_to_pos_aux () =
5464
let s = (input_line chan) in
5467
(* '... +1 do' cos input_line dont return the trailing \n *)
5468
for i = 0 to (slength s - 1) + 1 do
5469
(* old: arr.(!charpos + i) <- (!line, i); *)
5470
arr1.{!charpos + i} <- (!line);
5471
arr2.{!charpos + i} <- i;
5473
charpos := !charpos + slength s + 1;
5474
full_charpos_to_pos_aux();
5477
for i = !charpos to (* old: Array.length arr *)
5478
Bigarray.Array1.dim arr1 - 1 do
5479
(* old: arr.(i) <- (!line, 0); *)
5486
full_charpos_to_pos_aux ();
5488
(fun i -> arr1.{i}, arr2.{i})
5490
let full_charpos_to_pos_large a =
5491
profile_code "Common.full_charpos_to_pos_large"
5492
(fun () -> full_charpos_to_pos_large2 a)
5495
let complete_parse_info_large filename table x =
5498
line = fst (table (x.charpos));
5499
column = snd (table (x.charpos));
5397
5502
(*---------------------------------------------------------------------------*)
5398
5503
(* Decalage is here to handle stuff such as cpp which include file and who
5399
5504
* can make shift.
5896
6001
| _ -> failwith "md5sum_of_string wrong output"
6005
let with_pr2_to_string f =
6006
let file = new_temp_file "pr2" "out" in
6007
redirect_stdout_stderr file f;
6010
(* julia: convert something printed using format to print into a string *)
6011
let format_to_string f =
6012
let (nm,o) = Filename.open_temp_file "format_to_s" ".out" in
6013
Format.set_formatter_out_channel o;
6015
Format.print_newline();
6016
Format.print_flush();
6017
Format.set_formatter_out_channel stdout;
6019
let i = open_in nm in
6020
let lines = ref [] in
6022
let cur = input_line i in
6023
lines := cur :: !lines;
6025
(try loop() with End_of_file -> ());
6027
command2 ("rm -f " ^ nm);
6028
String.concat "\n" (List.rev !lines)
5899
6032
(*****************************************************************************)
5900
6033
(* Misc/test *)
5901
6034
(*****************************************************************************)