1using "equivalence.iso"
2
3@initialize:ocaml@
4@@
5// count the number of % characters in the format string
6let fmtn(fmt,n) =
7    List.length (Str.split_delim (Str.regexp_string "%") fmt) = n + 1
8
9# replace osip_debug/oslocal_debug with Debug() macros first
10@@
11expression E;
12expression list args;
13@@
14(
15-osip_debug
16|
17-oslocal_debug
18)
19+Debug
20 (
21-E,
22+LDAP_DEBUG_TRACE,
23 args );
24
25// replace Debug( ..., arg1, arg2, 0 ) with Debug2( ..., arg1, arg2 )
26@@
27char[] fmt : script:ocaml() { fmtn(fmt,2) };
28expression list[2] args;
29expression E;
30@@
31
32-Debug
33+Debug2
34 ( E, _(fmt), args
35-, 0
36 );
37
38// replace Debug( ..., arg1, 0, 0 ) with Debug1()
39@@
40char[] fmt : script:ocaml() { fmtn(fmt,1) };
41expression list[1] args;
42expression E;
43@@
44
45-Debug
46+Debug1
47 ( E, _(fmt), args
48-, 0, 0
49 );
50
51// Zero-argument Debug() -> Debug0()
52@@
53expression E, S;
54@@
55
56-Debug
57+Debug0
58 ( E, S
59-, 0, 0, 0
60 );
61
62// everything else is a regular 3-argument debug macro, replace with Debug3()
63@@
64expression E, S;
65expression list[3] args;
66@@
67
68-Debug
69+Debug3
70 ( E, S, args );
71