/usr/lib/gapi-3.0/gapi_pp.pl is in gtk-sharp3-gapi 2.99.3-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #!/usr/bin/perl
#
# gapi_pp.pl : A source preprocessor for the extraction of API info from a
# C library source directory.
#
# Authors: Mike Kestner <mkestner@speakeasy.net>
# Martin Willemoes Hansen <mwh@sysrq.dk>
#
# Copyright (c) 2001 Mike Kestner
# Copyright (c) 2003 Martin Willemoes Hansen
# Copyright (c) 2003-2004 Novell, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
$private_regex = '^#if.*(ENABLE_BACKEND|ENABLE_ENGINE)';
$eatit_regex = '^#if(.*(__cplusplus|DEBUG|DISABLE_COMPAT|ENABLE_BROKEN)|\s+0\s*$)';
$ignoreit_regex = '^\s+\*|#ident|#error|#\s*include|#\s*else|#\s*undef|G_(BEGIN|END)_DECLS|GDKVAR|GTKVAR|GTKMAIN_C_VAR|GTKTYPEUTILS_VAR|VARIABLE|GTKTYPEBUILTIN|G_GNUC_INTERNAL';
foreach $arg (@ARGV) {
if (-d $arg && -e $arg) {
@hdrs = (@hdrs, `ls $arg/*.h`);
@srcs = (@srcs, `ls $arg/*.c`);
} elsif (-f $arg && -e $arg) {
@hdrs = (@hdrs, $arg) if ($arg =~ /\.h$/);
@srcs = (@srcs, $arg) if ($arg =~ /\.c$/);
} else {
die "unable to process arg: $arg";
}
}
foreach $fname (@hdrs) {
if ($fname =~ /test|private|internals|gtktextlayout|gtkmarshalers/) {
@privhdrs = (@privhdrs, $fname);
next;
}
open(INFILE, $fname) || die "Could open $fname\n";
$braces = 0;
$deprecated = -1;
$ifdeflevel = 0;
$prepend = "";
while ($line = <INFILE>) {
$braces++ if ($line =~ /{/ and $line !~ /}/);
$braces-- if ($line =~ /}/ and $line !~ /{/);
next if ($line =~ /$ignoreit_regex/);
$line =~ s/\/\*[^<].*?\*\///g;
next if ($line !~ /\S/);
$line = $prepend . $line;
$prepend = "";
while ($line =~ /(.*)\\$/) { $line = $1 . <INFILE>; }
if ($line =~ /#\s*define\s+\w+\s+\"/) {
$def = $line;
while ($def !~ /\".*\"/) {$def .= ($line = <INFILE>);}
print $def;
} elsif ($line =~ /#\s*define\s+\w+\s*\(\s*\w+_get_type\s*\(\)\)/) {
print $line;
} elsif ($line =~ /#\s*define\s+\w+\s*\D+/) {
$def = $line;
while ($line =~ /\\\n/) {$def .= ($line = <INFILE>);}
if ($def =~ /_CHECK_\w*CAST|INSTANCE_GET_INTERFACE/) {
$def =~ s/\\\n//g;
print $def;
}
} elsif ($line =~ /^\s*\/\*[^<]/) {
while ($line !~ /\*\//) {$line = <INFILE>;}
} elsif ($line =~ /^extern/) {
while ($line !~ /;/) {$line = <INFILE>;}
} elsif ($line =~ /^#ifndef\s+\w+_H_*\b/) {
while ($line !~ /#define|#endif/) {$line = <INFILE>;}
} elsif ($line =~ /$private_regex/) {
$nested = 0;
while ($line = <INFILE>) {
last if (!$nested && ($line =~ /#else|#endif/));
if ($line =~ /#if/) {
$nested++;
} elsif ($line =~ /#endif/) {
$nested--
}
next if ($line !~ /^struct/);
print "private$line";
do {
$line = <INFILE>;
print $line;
} until ($line =~ /^\}/);
}
} elsif ($line =~ /$eatit_regex/) {
$nested = 0;
while ($line = <INFILE>) {
last if (!$nested && ($line =~ /#else|#endif/));
if ($line =~ /#if/) {
$nested++;
} elsif ($line =~ /#endif/) {
$nested--
}
}
} elsif ($line =~ /^#\s*ifn?\s*\!?def/) {
$ifdeflevel++;
#print "#ifn?def ($ifdeflevel): $line\n";
if ($line =~ /#ifndef.*DISABLE_DEPRECATED/) {
$deprecated = $ifdeflevel;
} elsif ($line =~ /#if !defined.*DISABLE_DEPRECATED/) {
$deprecated = $ifdeflevel;
}
} elsif ($line =~ /^#\s*endif/) {
#print "#endif ($ifdeflevel): $line\n";
if ($deprecated == $ifdeflevel) {
$deprecated = -1;
}
$ifdeflevel--;
} elsif ($line =~ /typedef struct\s*\{?\s*$/) {
while ($line !~ /{/) {
chomp ($line);
$line .= <INFILE>;
}
my $first_line = $line;
my @lines = ();
$line = <INFILE>;
while ($line !~ /^}\s*(\w+);/) {
if ($line =~ /\(.*\).*\(/) {
while ($line !~ /;/) {
chomp ($line);
$nxt = <INFILE>;
$nxt =~ s/^\s+/ /;
$line .= $nxt;
}
}
push @lines, $line;
$line = <INFILE>;
}
$line =~ /^}\s*(\w+);/;
my $name = $1;
print "typedef struct _$name $name;\n";
print "struct _$name {\n";
foreach $line (@lines) {
if ($line =~ /(\s*.+\;)/) {
$field = $1;
$field =~ s/(\w+) const/const $1/;
print "$field\n";
}
}
print "};\n";
} elsif ($line =~ /^enum\s+\{/) {
while ($line !~ /^};/) {$line = <INFILE>;}
} elsif ($line =~ /^(typedef\s+)?union/) {
next if ($line =~ /^typedef\s+union\s+\w+\s+\w+;/);
while ($line !~ /^};/) {$line = <INFILE>;}
} elsif ($line =~ /(\s+)union\s*{/) {
# this is a hack for now, but I need it for the fields to work
$indent = $1;
$do_print = 1;
while ($line !~ /^$indent}\s*\w+;/) {
$line = <INFILE>;
next if ($line !~ /;/);
print $line if $do_print;
$do_print = 0;
}
} else {
if ($braces or $line =~ /;|\/\*/) {
if ($deprecated == -1) {
print $line;
} else {
print "deprecated$line";
}
} else {
$prepend = $line;
$prepend =~ s/\n/ /g;
}
}
}
}
foreach $fname (@srcs, @privhdrs) {
open(INFILE, $fname) || die "Could open $fname\n";
if ($fname =~ /builtins_ids/) {
while ($line = <INFILE>) {
next if ($line !~ /\{/);
chomp($line);
$builtin = "BUILTIN" . $line;
$builtin .= <INFILE>;
print $builtin;
}
next;
}
while ($line = <INFILE>) {
next if ($line !~ /^(struct|typedef struct.*;|\w+_class_init|\w+_base_init|\w+_default_init|\w+_get_type\b|G_DEFINE_TYPE_EXTENDED|G_DEFINE_TYPE_WITH_CODE|G_DEFINE_BOXED_TYPE|G_DEFINE_INTERFACE)/);
if ($line =~ /^G_DEFINE_(TYPE_EXTENDED|TYPE_WITH_CODE|BOXED_TYPE|INTERFACE)/) {
my $macro;
my $parens = 0;
do {
chomp ($line);
$line =~ s/(.*)\\$/\1/;
$line =~ s/^\s+(.*)/ \1/;
$macro .= $line;
foreach $chr (split (//, $line)) {
if ($chr eq "(") {
$parens++;
} elsif ($chr eq ")") {
$parens--;
}
}
$line = <INFILE>;
} while ($parens > 0);
print "$macro\n";
next if ($line !~ /^(struct|\w+_class_init|\w+_base_init)/);
}
if ($line =~ /^struct/) {
# need some of these to parse out parent types
print "private";
if ($line =~ /;/) {
print $line;
next;
}
} elsif ($line =~ /^typedef.*;/) {
print $line;
next;
}
$comment = 0;
$begin = 0;
$end = 0;
do {
# Following ifs strips out // and /* */ C comments
if ($line =~ /\/\*/) {
$comment = 1;
$begin = 1;
}
if ($comment != 1) {
$line =~ s/\/\/.*//;
print $line;
}
if ($line =~ /\*\//) {
$comment = 0;
$end = 1;
}
if ($begin == 1 && $end == 1) {
$line =~ s/\/\*.*\*\///;
print $line;
}
$begin = 0;
$end = 0;
} until (($line = <INFILE>) =~ /^}/);
print $line;
}
}
|