]> mj.ucw.cz Git - libucw.git/blob - tools/map-symbols
Opt: Documented opt and its interaction with conf
[libucw.git] / tools / 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 parse {
8         my ($file) = @_;
9         print "# $file\n";
10         open my $f, '<', $file or die;
11         while (<$f>) {
12                 chomp;
13                 # Find things which look like top-level declarations
14                 s{//.*}{};
15                 s{/\*.*}{};
16                 /^\s/ and next;
17                 /^$/ and next;
18                 /^#/ and next;
19                 /^{/ and next;
20                 /}/ and next;
21                 /^"/ and next;
22                 /^-/ and next;          # Magic for ucw/getopt.h
23                 /^\w+:/ and next;       # Labels in inline functions
24                 /^typedef\s/ and next;
25                 /^static\s/ and next;
26                 /^(struct|union|enum)(\s+\w+)?(;|\s*{)/ and next;
27
28                 # print "$_\n";
29
30                 # Try to parse the declaration
31                 s{\[[^\]]*\]}{}g;       # Delete array sizes
32                 if (m{^extern [^,]*(\s+\**\w+(,\s+\**\w+)*);}) {
33                         my $x = $1;
34                         $x =~ s{[,*]}{}g;
35                         print join("\n", grep { !/^$/ } split /\s+/, $x), "\n";
36                 } elsif (m{( |\*)(\w+)\(}) {
37                         print "$2\n";
38                 } else {
39                         print "??? $_\n";
40                 }
41
42         }
43         close $f;
44 }
45
46 my %blacklist = map { $_ => 1 } qw(
47         ucw/binheap.h
48         ucw/char-map.h
49         ucw/ff-binary.h
50         ucw/gbuf.h
51         ucw/hashtable.h
52         ucw/kmp.h
53         ucw/kmp-search.h
54         ucw/redblack.h
55         ucw/str-match.h
56         ucw/strtonum.h
57         ucw/strtonum-gen.h
58         ucw/trie.h
59         charset/charconv-gen.h
60         charset/chartable.h
61         charset/U-cat.h
62         charset/U-ligatures.h
63         charset/U-lower.h
64         charset/U-unacc.h
65         charset/U-upper.h
66         images/image-walk.h
67         images/scale-gen.h
68 );
69
70 for my $f (<ucw/*.h>, <ucw/sorter/common.h>, <charset/*.h>, <images/*.h>) {
71         next if $blacklist{$f};
72         parse($f);
73 }