xref: /netbsd-src/external/bsd/openldap/dist/doc/devel/variadic_debug/04-variadic.cocci (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1@initialize:ocaml@
2@@
3// count the number of % characters in the format string
4let fmtn(fmt,n) =
5    List.length (Str.split_delim (Str.regexp_string "%") fmt) = n + 1
6
7@@
8identifier Logs =~ "Log[0-9]";
9@@
10-Logs
11+Log
12
13@@
14@@
15-StatslogTest
16+LogTest
17
18// Process two-argument Debug() macros with an extra zero
19@@
20char[] fmt : script:ocaml() { fmtn(fmt,2) };
21expression list[2] args;
22expression E;
23@@
24
25Debug( E, fmt, args
26-, 0
27 );
28
29@@
30char[] fmt : script:ocaml() { fmtn(fmt,2) };
31expression list[2] args;
32expression E;
33@@
34
35Debug( E, fmt, args
36-, NULL
37 );
38
39// Single argument Debug() macros with two extra zeroes
40@@
41char[] fmt : script:ocaml() { fmtn(fmt,1) };
42expression list[1] args;
43expression E;
44@@
45
46Debug( E, fmt, args
47-, 0, 0
48 );
49
50@@
51char[] fmt : script:ocaml() { fmtn(fmt,1) };
52expression list[1] args;
53expression E;
54@@
55
56Debug( E, fmt, args
57-, NULL, NULL
58 );
59
60// Debug() macros with no arguments just padded with zeroes
61@@
62expression E, S;
63@@
64
65Debug( E, S
66-, 0, 0, 0
67 );
68
69@@
70expression E, S;
71@@
72
73Debug( E, S
74-, NULL, NULL, NULL
75 );
76
77// Similar to above, just for Statslog
78@@
79char[] fmt : script:ocaml() { fmtn(fmt,5) };
80expression list[5] args;
81expression E;
82@@
83
84-Statslog
85+Debug
86 ( E, fmt, args );
87
88@@
89char[] fmt : script:ocaml() { fmtn(fmt,4) };
90expression list[4] args;
91expression E;
92@@
93
94-Statslog
95+Debug
96 ( E, fmt, args
97-, 0
98 );
99
100@@
101char[] fmt : script:ocaml() { fmtn(fmt,3) };
102expression list[3] args;
103expression E;
104@@
105
106-Statslog
107+Debug
108 ( E, fmt, args
109-, 0, 0
110 );
111
112@@
113char[] fmt : script:ocaml() { fmtn(fmt,2) };
114expression list[2] args;
115expression E;
116@@
117
118-Statslog
119+Debug
120 ( E, fmt, args
121-, 0, 0, 0
122 );
123
124@@
125char[] fmt : script:ocaml() { fmtn(fmt,1) };
126expression list[1] args;
127expression E;
128@@
129
130-Statslog
131+Debug
132 ( E, fmt, args
133-, 0, 0, 0, 0
134 );
135
136@@
137expression E, S;
138@@
139
140-Statslog
141+Debug
142 ( E, S
143-, 0, 0, 0, 0, 0
144 );
145
146// And StatslogEtime
147@@
148char[] fmt : script:ocaml() { fmtn(fmt,4) };
149expression list[4] args;
150expression E;
151@@
152
153StatslogEtime( E, fmt, args
154-, 0
155 );
156
157@@
158identifier Stats =~ "^Statslog";
159@@
160(
161 StatslogEtime
162|
163-Stats
164+Debug
165)
166