2 ################################################################################
4 # apicheck.pl -- generate C source for automated API check
6 ################################################################################
10 # $Date: 2006/05/25 17:21:23 +0200 $
12 ################################################################################
14 # Version 3.x, Copyright (C) 2004-2006, Marcus Holland-Moritz.
15 # Version 2.x, Copyright (C) 2001, Paul Marquess.
16 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
18 # This program is free software; you can redistribute it and/or
19 # modify it under the same terms as Perl itself.
21 ################################################################################
24 require 'parts/ppptools.pl';
28 open OUT, ">$file" or die "$file: $!\n";
34 my @f = parse_embed(qw( parts/embed.fnc parts/apidoc.fnc ));
36 my %todo = %{&parse_todo};
89 ORIGMARK => ['dORIGMARK;'],
90 POPpx => ['STRLEN n_a;'],
91 POPpbytex => ['STRLEN n_a;'],
100 UNDERBAR => ['dUNDERBAR;'],
101 XCPT_TRY_START => ['dXCPT;'],
102 XCPT_TRY_END => ['dXCPT;'],
103 XCPT_CATCH => ['dXCPT;'],
104 XCPT_RETHROW => ['dXCPT;'],
108 dSP => "some_global_var = !sp;",
109 dMARK => "some_global_var = !mark;",
110 dORIGMARK => "some_global_var = !origmark;",
111 dAX => "some_global_var = !ax;",
112 dITEMS => "some_global_var = !items;",
113 dXSARGS => "some_global_var = ax && items;",
114 NEWSV => "some_global_var = !arg1;",
115 New => "some_global_var = !arg1;",
116 Newc => "some_global_var = !arg1;",
117 Newz => "some_global_var = !arg1;",
118 dUNDERBAR => "(void) UNDERBAR;",
122 map { ($_ => 1) } qw(
137 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
138 * This file is built by $0.
139 * Any changes made here will be lost!
148 #ifndef DPPP_APICHECK_NO_PPPORT_H
151 #define NEED_grok_bin
152 #define NEED_grok_hex
153 #define NEED_grok_number
154 #define NEED_grok_numeric_radix
155 #define NEED_grok_oct
156 #define NEED_my_snprintf
157 #define NEED_newCONSTSUB
158 #define NEED_newRV_noinc
159 #define NEED_sv_2pv_nolen
160 #define NEED_sv_2pvbyte
161 #define NEED_sv_catpvf_mg
162 #define NEED_sv_catpvf_mg_nocontext
163 #define NEED_sv_setpvf_mg
164 #define NEED_sv_setpvf_mg_nocontext
165 #define NEED_vnewSVpvf
173 static int some_global_var;
176 static char *VARarg2;
177 static double VARarg3;
182 my %want = map { ($_ => 0) } @ARGV;
183 @f = grep { exists $want{$_->{name}} } @f;
184 for (@f) { $want{$_->{name}}++ }
186 die "nothing found for '$_'\n" unless $want{$_};
192 $ignore{$f->{name}} and next;
193 $f->{flags}{A} or next; # only public API members
195 $ignore{$f->{name}} = 1; # ignore duplicates
197 my $Perl_ = $f->{flags}{p} ? 'Perl_' : '';
206 for $ca (@{$f->{args}}) {
210 push @arg, qw(VARarg1 VARarg2 VARarg3);
213 my($n, $p, $d) = $a =~ /^ (\w+(?:\s+\w+)*)\s* # type name => $n
214 (\**) # pointer => $p
215 (?:\s*const\s*)? # const
216 ((?:\[[^\]]*\])*) # dimension => $d
218 or die "$0 - cannot parse argument: [$a]\n";
219 if (exists $amap{$n}) {
220 push @arg, $amap{$n};
223 $n = $tmap{$n} || $n;
224 if ($n eq 'const char' and $p eq '*' and !$f->{flags}{f}) {
228 my $v = 'arg' . $i++;
230 $stack .= " static $n $p$v$d;\n";
234 unless ($f->{flags}{n} || $f->{flags}{'m'}) {
235 $stack = " dTHX;\n$stack";
236 $aTHX = @arg ? 'aTHX_ ' : 'aTHX';
239 if ($stack{$f->{name}}) {
241 for (@{$stack{$f->{name}}}) {
247 my $args = join ', ', @arg;
248 my $rvt = $f->{ret} || 'void';
251 $ret = $castvoid{$f->{name}} ? '(void) ' : '';
254 $ret = $ignorerv{$f->{name}} ? '(void) ' : "return ";
256 my $aTHX_args = "$aTHX$args";
259 if ($postcode{$f->{name}}) {
260 $post = $postcode{$f->{name}};
265 unless ($f->{flags}{'m'} and @arg == 0) {
267 $aTHX_args = "($aTHX_args)";
271 /******************************************************************************
275 ******************************************************************************/
279 if ($todo{$f->{name}}) {
280 my($ver,$sub) = $todo{$f->{name}} =~ /^5\.(\d{3})(\d{3})$/ or die;
284 if ($ver < 6 && $sub > 0) {
285 $sub =~ s/0$// or die;
287 print OUT "#if PERL_VERSION > $ver || (PERL_VERSION == $ver && PERL_SUBVERSION >= $sub) /* TODO */\n";
291 ? "$Perl_$f->{name}$aTHX_args"
294 $f->{cond} and print OUT "#if $f->{cond}\n";
297 $rvt _DPPP_test_$f->{name} (void)
304 $ret$f->{name}$args;$post
308 some_global_var = items && ax;
314 $ret$Perl_$f->{name}$aTHX_args;$post
320 $f->{cond} and print OUT "#endif\n";
321 $todo{$f->{name}} and print OUT "#endif\n";