2 ################################################################################
4 # scanprov -- scan Perl headers for provided macros
6 ################################################################################
8 # Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
9 # Version 2.x, Copyright (C) 2001, Paul Marquess.
10 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
15 ################################################################################
20 require './parts/ppptools.pl';
21 require './parts/inc/inctools';
22 require './devel/devtools.pl';
26 install => '/tmp/perl/install/default',
32 GetOptions(\%opt, qw( install=s mode=s blead=s debug debug-start=s)) or die;
34 my $write = $opt{mode} eq 'write';
36 my %embed = map { ( $_->{name} => 1 ) }
37 parse_embed(qw(parts/embed.fnc parts/apidoc.fnc parts/ppport.fnc ));
39 # @provided is set to the elements that are provided, but not functions in the
41 my @provided = grep { !exists $embed{$_} }
42 map { /^(\w+)/ ? $1 : () }
43 `$^X ppport.h --list-provided`;
45 my $perls_ref = get_and_sort_perls(\%opt);
50 die "Couldn't find any perls" unless @$perls_ref > 1;
54 # We look in descending order of perl versions. Each time through the loop
55 # @provided is narrowed.
56 for my $p (@$perls_ref) {
57 print "checking perl $p->{version}...\n";
59 # Get the hdr files associated with this version
60 my $archlib = `$p->{path} -MConfig -l -e 'print \$Config{archlib}'`;
62 local @ARGV = glob "$archlib/CORE/*.h";
65 # %sym's keys are every single \w+ that occurs in all the headers,
66 # regardless of if they are in a comment, or what.
67 while (<>) { $sym{$_}++ for /(\w+)/g; }
69 # @provided is narrowed to include only those \w+ things that are mentioned
70 # in some hdr in this release. (If it isn't even mentioned, it won't exist in
71 # the release.) For those not mentioned, a key is added of the \w+ in %v.
72 # It is a subkey of this release's "todo" release, which is the next higher
73 # one. If we are at version n, we have already done version n+1 and the
74 # provided element was mentioned there, and now it no longer is. We take
75 # that to mean that to mean that the element became provided for in n+1.
76 # (khw notes that it could have just been in a comment for a bunch of
77 # releases above this, like
78 # /* Oh how I wish we had FOO */
79 # and at some point FOO got added. The method here is, hence, just a
81 @provided = map { $sym{$_} or $v{$p->{todo}}{$_}++;
86 # Read in the parts/base files. The hash ref has keys being all symbols found
87 # in all the files in base/, and the values being the perl versions each symbol
89 my $out = 'parts/base';
90 my $base_ref = parse_todo($out);
92 # Now add the results from above. At this point, The keys of %v are the 7
93 # digit BCD version numbers, and their subkeys are the symbols provided by
94 # D:P that are first mentioned in this version, like this:
96 # 'MY_CXT_CLONE' => 1,
98 # 'UTF8_MAXBYTES' => 1
101 for my $v (keys %v) {
103 # @new becomes the symbols for version $v not already in the file for $v
104 my @new = sort dictionary_order grep { !exists $base_ref->{$_} }
106 @new or next; # Nothing new, skip writing
110 $file = "$out/$file";
111 -e $file or die "non-existent: $file\n";
112 print "-- $file --\n";
113 $write and (open F, ">>$file" or die "$file: $!\n");
116 $write and printf F "%-30s # added by $0\n", $_;