2 ################################################################################
4 # apicheck.pl -- generate C source for automated API check
6 ################################################################################
10 # $Date: 2006/05/19 16:15:51 +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';
27 open OUT, ">$ARGV[0]" or die "$ARGV[0]: $!\n";
33 my @f = parse_embed(qw( parts/embed.fnc parts/apidoc.fnc ));
35 my %todo = %{&parse_todo};
88 ORIGMARK => ['dORIGMARK;'],
89 POPpx => ['STRLEN n_a;'],
90 POPpbytex => ['STRLEN n_a;'],
99 UNDERBAR => ['dUNDERBAR;'],
100 XCPT_TRY_START => ['dXCPT;'],
101 XCPT_TRY_END => ['dXCPT;'],
102 XCPT_CATCH => ['dXCPT;'],
103 XCPT_RETHROW => ['dXCPT;'],
107 dSP => "some_global_var = !sp;",
108 dMARK => "some_global_var = !mark;",
109 dORIGMARK => "some_global_var = !origmark;",
110 dAX => "some_global_var = !ax;",
111 dITEMS => "some_global_var = !items;",
112 dXSARGS => "some_global_var = ax && items;",
113 NEWSV => "some_global_var = !arg1;",
114 New => "some_global_var = !arg1;",
115 Newc => "some_global_var = !arg1;",
116 Newz => "some_global_var = !arg1;",
117 dUNDERBAR => "(void) UNDERBAR;",
121 map { ($_ => 1) } qw(
136 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
137 * This file is built by $0.
138 * Any changes made here will be lost!
147 #ifndef DPPP_APICHECK_NO_PPPORT_H
150 #define NEED_grok_bin
151 #define NEED_grok_hex
152 #define NEED_grok_number
153 #define NEED_grok_numeric_radix
154 #define NEED_grok_oct
155 #define NEED_my_snprintf
156 #define NEED_newCONSTSUB
157 #define NEED_newRV_noinc
158 #define NEED_sv_2pv_nolen
159 #define NEED_sv_2pvbyte
160 #define NEED_sv_catpvf_mg
161 #define NEED_sv_catpvf_mg_nocontext
162 #define NEED_sv_setpvf_mg
163 #define NEED_sv_setpvf_mg_nocontext
164 #define NEED_vnewSVpvf
172 static int some_global_var;
175 static char *VARarg2;
176 static double VARarg3;
182 $ignore{$f->{name}} and next;
183 $f->{flags}{A} or next; # only public API members
185 $ignore{$f->{name}} = 1; # ignore duplicates
187 my $Perl_ = $f->{flags}{p} ? 'Perl_' : '';
196 for $ca (@{$f->{args}}) {
200 push @arg, qw(VARarg1 VARarg2 VARarg3);
203 my($n, $p, $d) = $a =~ /^ (\w+(?:\s+\w+)*)\s* # type name => $n
204 (\**) # pointer => $p
205 (?:\s*const\s*)? # const
206 ((?:\[[^\]]*\])*) # dimension => $d
208 or die "$0 - cannot parse argument: [$a]\n";
209 if (exists $amap{$n}) {
210 push @arg, $amap{$n};
213 $n = $tmap{$n} || $n;
214 my $v = 'arg' . $i++;
216 $stack .= " static $n $p$v$d;\n";
219 unless ($f->{flags}{n} || $f->{flags}{'m'}) {
220 $stack = " dTHX;\n$stack";
221 $aTHX = @arg ? 'aTHX_ ' : 'aTHX';
224 if ($stack{$f->{name}}) {
226 for (@{$stack{$f->{name}}}) {
232 my $args = join ', ', @arg;
233 my $rvt = $f->{ret} || 'void';
236 $ret = $castvoid{$f->{name}} ? '(void) ' : '';
239 $ret = $ignorerv{$f->{name}} ? '(void) ' : "return ";
241 my $aTHX_args = "$aTHX$args";
244 if ($postcode{$f->{name}}) {
245 $post = $postcode{$f->{name}};
250 unless ($f->{flags}{'m'} and @arg == 0) {
252 $aTHX_args = "($aTHX_args)";
256 /******************************************************************************
260 ******************************************************************************/
264 if ($todo{$f->{name}}) {
265 my($ver,$sub) = $todo{$f->{name}} =~ /^5\.(\d{3})(\d{3})$/ or die;
269 if ($ver < 6 && $sub > 0) {
270 $sub =~ s/0$// or die;
272 print OUT "#if PERL_VERSION > $ver || (PERL_VERSION == $ver && PERL_SUBVERSION >= $sub) /* TODO */\n";
276 ? "$Perl_$f->{name}$aTHX_args"
279 $f->{cond} and print OUT "#if $f->{cond}\n";
282 $rvt _DPPP_test_$f->{name} (void)
289 $ret$f->{name}$args;$post
293 some_global_var = items && ax;
299 $ret$Perl_$f->{name}$aTHX_args;$post
305 $f->{cond} and print OUT "#endif\n";
306 $todo{$f->{name}} and print OUT "#endif\n";