.gnumeric: For clipboards, send also result values.
[gnumeric.git] / tools / dumpdef.pl
blob99323d87991946850e0dc1c752d1cb7bd308f7d0
1 #!/usr/bin/perl -w
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/>
20 sub parse_header {
21 my ($lines, $file, @symbols);
23 $file = shift;
24 open HEADER, $file or die "Cannot open $file: $!\n";
25 $/ = undef;
26 $lines = <HEADER>;
27 close HEADER;
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
33 \s*\)\s* #close
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
37 |G_GNUC_DEPRECATED)?
38 \s*;/gxm) {
39 push @symbols, $1;
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";
46 @symbols;
49 die "Usage: dumpdef.pl files...\n" if ($#ARGV == -1);
51 my @symbols;
52 do {
53 push @symbols, parse_header $ARGV[0];
54 shift @ARGV;
55 } while ($#ARGV != -1);
57 print join "\n", sort @symbols;
58 print "\n";