Coccinelle release 1.0.0-rc1
[bpt/coccinelle.git] / commons / common_extra.ml
CommitLineData
34e49164
C
1(* I put those functions here and not in common.ml to try to avoid
2 * as much as possible dependencies in common.ml so I can more easily
3 * make ocaml script that just do a load common.ml without the need
4 * to load many other files (like dumper.ml, or ANSITerminal.ml and
5 * other recursive dependencies).
ae4735db
C
6 *
7 * Note that you can still use the functions below from an open Common.
34e49164
C
8 * You don't need to do a 'open Common_extra'; loading the commons.cma is
9 * enough to make the connexions.
10 *)
11
12
91eba41f
C
13(* how to use it ? ex in LFS:
14 * Common.execute_and_show_progress (w.prop_iprop#length) (fun k ->
ae4735db 15 * w.prop_iprop#iter (fun (p, ip) ->
91eba41f
C
16 * k ();
17 * ...
18 * ));
ae4735db 19 *
91eba41f 20 *)
34e49164 21
ae4735db 22let execute_and_show_progress len f =
34e49164
C
23 let _count = ref 0 in
24 (* kind of continuation passed to f *)
ae4735db 25 let continue_pourcentage () =
34e49164
C
26 incr _count;
27 ANSITerminal.set_cursor 1 (-1);
28 ANSITerminal.printf [] "%d / %d" !_count len; flush stdout;
29 in
ae4735db 30 let nothing () = () in
91eba41f 31
34e49164 32 ANSITerminal.printf [] "0 / %d" len; flush stdout;
ae4735db 33 if !Common._batch_mode
91eba41f
C
34 then f nothing
35 else f continue_pourcentage
36 ;
34e49164
C
37 Common.pr2 ""
38
91eba41f 39
ae4735db 40let set_link () =
34e49164
C
41 Common._execute_and_show_progress_func := execute_and_show_progress
42
43
ae4735db 44let _init_execute =
34e49164 45 set_link ()