"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / dumpdef.pl
1 #!/usr/bin/perl -w
2 #
3 # dumpdef.pl: Extract function declarations from C headers.
4 #
5 # Copyright (C) 2005 Ivan, Wong Yat Cheung <email@ivanwong.info>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of version 2.1 of the GNU Lesser General Public
9 # License as published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # USA
20 #
21
22 sub parse_header {
23     my ($lines, $file, @symbols);
24
25     $file = shift;
26     open HEADER, $file or die "Cannot open $file: $!\n";
27     $/ = undef;
28     $lines = <HEADER>;
29     close HEADER;
30     while ($lines =~ /^\s*[A-Za-z_]\w*(?:\s+[A-Za-z_]\w*)*[\s\*]+ #function type
31                       ([A-Za-z_]\w*)\s*\( #function name
32                       (?:\s*[A-Za-z_]\w*(?:[\s\*]+[A-Za-z_]\w*)*[\s\*]+[A-Za-z_]\w*(?:\s*\[\s*\]\s*)? #[first arg
33                        (?:\s*,\s*[A-Za-z_]\w*(?:[\s\*]+[A-Za-z_]\w*)*[\s\*]+[A-Za-z_]\w*(?:\s*\[\s*\]\s*)?)* #[more args]]
34                        (?:\s*,\s*\.{3})?|void) #vargs or void
35                       \s*\)\s* #close
36                       (?:(?:G_GNUC_PRINTF|G_GNUC_SCANF)\s*\(\s*\d+\s*,\s*\d+\) # predefined macro modifiers]
37                         |G_GNUC_FORMAT\s*\(\s*\d+\s*\)
38                         |G_GNUC_NORETURN|G_GNUC_CONST|G_GNUC_UNUSED|G_GNUC_NO_INSTRUMENT
39                                 |G_GNUC_DEPRECATED)?
40                       \s*;/gxm) {
41         push @symbols, $1;
42     }
43     while ($lines =~ /^\s*extern\s+ #function type
44                       [A-Za-z_]\w*(?:[\s\*]+[A-Za-z_]\w*)*[\s\*]+([A-Za-z_]\w*) #[first arg
45                       \s*(?:\[\s*\]\s*)?;/gxm) {
46         push @symbols, "$1 DATA";
47     }
48     @symbols;
49 }
50
51 die "Usage: dumpdef.pl files...\n" if ($#ARGV == -1);
52
53 my @symbols;
54 do {
55     push @symbols, parse_header $ARGV[0];
56     shift @ARGV;
57 } while ($#ARGV != -1);
58
59 print join "\n", sort @symbols;
60 print "\n";
61