]> mj.ucw.cz Git - libucw.git/blob - maint/abi-map-symbols
Created an OpenWRT package
[libucw.git] / maint / abi-map-symbols
1 #!/usr/bin/perl
2 # Search for symbols which might need renaming
3 # (c) 2014 Martin Mares <mj@ucw.cz>
4
5 use common::sense;
6
7 sub symbol {
8         my ($sym) = @_;
9         return if $sym =~ m{^(ucw|ucwlib)_};
10         print "$sym\n";
11 }
12
13 sub parse {
14         my ($file) = @_;
15         print "# $file\n";
16         open my $f, '<', $file or die;
17         while (<$f>) {
18                 chomp;
19                 # Interpret special comments
20                 m{// NOAPI} and next;
21                 if (m{// API: (\w+)}) {
22                         print "$1\n";
23                         next;
24                 }
25                 # Find things which look like top-level declarations
26                 s{//.*}{};
27                 s{/\*.*}{};
28                 /^\s/ and next;
29                 /^$/ and next;
30                 /^#/ and next;
31                 /^{/ and next;
32                 /}/ and next;
33                 /^"/ and next;
34                 /^-/ and next;          # Magic for ucw/getopt.h
35                 /^\w+:/ and next;       # Labels in inline functions
36                 /^typedef\s/ and next;
37                 /^static\s/ and next;
38                 /^(struct|union|enum)(\s+\w+)?(;|\s*{)/ and next;
39
40                 # print "$_\n";
41
42                 # Try to parse the declaration
43                 s{\[[^\]]*\]}{}g;       # Delete array sizes
44                 if (m{^extern [^,]*(\s+\**\w+(,\s+\**\w+)*);}) {
45                         my $x = $1;
46                         $x =~ s{[,*]}{}g;
47                         symbol $_ for grep { !/^$/ } split /\s+/, $x;
48                 } elsif (m{( |\*)(\w+)\(}) {
49                         symbol($2);
50                 } else {
51                         print "??? $_\n";
52                 }
53
54         }
55         close $f;
56 }
57
58 my %blacklist = map { $_ => 1 } qw(
59         ucw/binheap.h
60         ucw/char-map.h
61         ucw/ff-binary.h
62         ucw/gbuf.h
63         ucw/hashtable.h
64         ucw/kmp.h
65         ucw/kmp-search.h
66         ucw/redblack.h
67         ucw/str-match.h
68         ucw/strtonum.h
69         ucw/strtonum-gen.h
70         ucw/trie.h
71         charset/charconv-gen.h
72         charset/chartable.h
73         charset/U-cat.h
74         charset/U-ligatures.h
75         charset/U-lower.h
76         charset/U-unacc.h
77         charset/U-upper.h
78         images/image-walk.h
79         images/scale-gen.h
80 );
81
82 for my $f (<ucw/*.h>, <ucw/sorter/common.h>, <charset/*.h>, <images/*.h>, <ucw-xml/*.h>, <ucw-json/*.h>) {
83         next if $blacklist{$f};
84         parse($f);
85 }