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, see <https://www.gnu.org/licenses/>
21 my ($lines, $file, @symbols);
24 open HEADER
, $file or die "Cannot open $file: $!\n";
28 while ($lines =~ /^\s
*[A
-Za
-z_
]\w
*(?
:\s
+[A
-Za
-z_
]\w
*)*[\s\
*]+ #function type
29 ([A
-Za
-z_
]\w
*)\s
*\
( #function name
30 (?
:\s
*[A
-Za
-z_
]\w
*(?
:[\s\
*]+[A
-Za
-z_
]\w
*)*[\s\
*]*(?
:[A
-Za
-z_
]\w
*)?
(?
:\s
*\
[\s
*\
]\s
*)?
#[first arg
31 (?
:\s
*,\s
*[A
-Za
-z_
]\w
*(?
:[\s\
*]+[A
-Za
-z_
]\w
*)*[\s\
*]+(?
:[A
-Za
-z_
]\w
*)?
(?
:\s
*\
[\s
*\
]\s
*)?
)* #[more args]]
32 (?
:\s
*,\s
*\
.{3})?
|void
) #vargs or void
34 (?
:(?
:G_GNUC_PRINTF
|G_GNUC_SCANF
)\s
*\
(\s
*\d
+\s
*,\s
*\d
+\
) # predefined macro modifiers]
35 |G_GNUC_FORMAT\s
*\
(\s
*\d
+\s
*\
)
36 |G_GNUC_NORETURN
|G_GNUC_CONST
|G_GNUC_UNUSED
|G_GNUC_NO_INSTRUMENT
41 while ($lines =~ /^\s
*(?
:extern
|__attribute__\
(\
(dllexport\
)\
))\s
+ #function type
42 [A
-Za
-z_
]\w
*(?
:[\s\
*]+[A
-Za
-z_
]\w
*)*[\s\
*]+([A
-Za
-z_
]\w
*) #[first arg
43 \s
*(?
:\
[\s
*\
]\s
*)?
;/gxm
) {
44 push @symbols, "$1 DATA";
49 die "Usage: dumpdef.pl files...\n" if ($#ARGV == -1);
53 push @symbols, parse_header
$ARGV[0];
55 } while ($#ARGV != -1);
57 print join "\n", sort @symbols;