3
# dumpdef.pl: Extract function declarations from C headers.
5
# Copyright (C) 2005 Ivan, Wong Yat Cheung <email@ivanwong.info>
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.
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.
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
23
my ($lines, $file, @symbols);
26
open HEADER, $file or die "Cannot open $file: $!\n";
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
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
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";
51
die "Usage: dumpdef.pl files...\n" if ($#ARGV == -1);
55
push @symbols, parse_header $ARGV[0];
57
} while ($#ARGV != -1);
59
print join "\n", sort @symbols;