2002-01-04 02:02:28 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# gapi_pp.pl : A source preprocessor for the extraction of API info from a
|
|
|
|
# C library source directory.
|
|
|
|
#
|
2003-06-25 21:22:28 +00:00
|
|
|
# Authors: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
# Martin Willemoes Hansen <mwh@sysrq.dk>
|
2002-01-04 02:02:28 +00:00
|
|
|
#
|
2004-06-25 16:35:15 +00:00
|
|
|
# Copyright (c) 2001 Mike Kestner
|
|
|
|
# Copyright (c) 2003 Martin Willemoes Hansen
|
|
|
|
# Copyright (c) 2003 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.
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2004-02-10 16:04:50 +00:00
|
|
|
$private_regex = "^#if.*(ENABLE_BACKEND|ENABLE_ENGINE)";
|
2002-01-04 02:02:28 +00:00
|
|
|
$eatit_regex = "^#if.*(__cplusplus|DEBUG|DISABLE_(DEPRECATED|COMPAT)|ENABLE_BROKEN|COMPILATION)";
|
2004-01-28 21:44:25 +00:00
|
|
|
$ignoreit_regex = '^\s+\*|#ident|#\s*include|#\s*else|#\s*endif|#\s*undef|G_(BEGIN|END)_DECLS|extern|GDKVAR|GTKVAR|GTKMAIN_C_VAR|GTKTYPEUTILS_VAR|VARIABLE|GTKTYPEBUILTIN';
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2003-11-19 18:44:01 +00:00
|
|
|
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";
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach $fname (@hdrs) {
|
2002-01-07 23:30:01 +00:00
|
|
|
|
2002-01-17 00:26:46 +00:00
|
|
|
if ($fname =~ /test|private|internals|gtktextlayout|gtkmarshalers/) {
|
2002-01-07 23:30:01 +00:00
|
|
|
@privhdrs = (@privhdrs, $fname);
|
|
|
|
next;
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
open(INFILE, $fname) || die "Could open $fname\n";
|
|
|
|
|
2002-07-05 20:22:21 +00:00
|
|
|
$braces = 0;
|
|
|
|
$prepend = "";
|
2002-01-04 02:02:28 +00:00
|
|
|
while ($line = <INFILE>) {
|
2002-07-05 20:22:21 +00:00
|
|
|
$braces++ if ($line =~ /{/ and $line !~ /}/);
|
|
|
|
$braces-- if ($line =~ /}/ and $line !~ /{/);
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
next if ($line =~ /$ignoreit_regex/);
|
2003-10-09 05:54:55 +00:00
|
|
|
|
|
|
|
$line =~ s/\/\*.*?\*\///g;
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
next if ($line !~ /\S/);
|
|
|
|
|
2002-07-05 20:22:21 +00:00
|
|
|
$line = $prepend . $line;
|
|
|
|
$prepend = "";
|
|
|
|
|
|
|
|
if ($line =~ /#\s*define\s+\w+\s+\"/) {
|
|
|
|
$def = $line;
|
|
|
|
while ($def !~ /\".*\"/) {$def .= ($line = <INFILE>);}
|
|
|
|
print $def;
|
|
|
|
} elsif ($line =~ /#\s*define\s+\w+\s*\D+/) {
|
2002-01-04 02:02:28 +00:00
|
|
|
$def = $line;
|
|
|
|
while ($line =~ /\\\n/) {$def .= ($line = <INFILE>);}
|
2002-01-07 23:30:01 +00:00
|
|
|
if ($def =~ /_CHECK_\w*CAST|INSTANCE_GET_INTERFACE/) {
|
2002-01-04 02:02:28 +00:00
|
|
|
$def =~ s/\\\n//g;
|
|
|
|
print $def;
|
|
|
|
}
|
|
|
|
} elsif ($line =~ /^\s*\/\*/) {
|
|
|
|
while ($line !~ /\*\//) {$line = <INFILE>;}
|
|
|
|
} elsif ($line =~ /^#ifndef\s+\w+_H_*\b/) {
|
|
|
|
while ($line !~ /#define/) {$line = <INFILE>;}
|
2004-02-10 16:04:50 +00:00
|
|
|
} 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 =~ /^\}/);
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
} elsif ($line =~ /$eatit_regex/) {
|
2002-07-08 14:52:20 +00:00
|
|
|
$nested = 0;
|
|
|
|
while ($line = <INFILE>) {
|
|
|
|
last if (!$nested && ($line =~ /#else|#endif/));
|
|
|
|
if ($line =~ /#if/) {
|
|
|
|
$nested++;
|
|
|
|
} elsif ($line =~ /#endif/) {
|
|
|
|
$nested--
|
|
|
|
}
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
} elsif ($line =~ /^#\s*ifn?\s*\!?def/) {
|
|
|
|
#warn "Ignored #if:\n$line";
|
2002-08-12 19:14:44 +00:00
|
|
|
} elsif ($line =~ /typedef struct\s*\{/) {
|
|
|
|
my $first_line = $line;
|
|
|
|
my @lines = ();
|
|
|
|
$line = <INFILE>;
|
|
|
|
while ($line !~ /^}\s*(\w+);/) {
|
|
|
|
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";
|
2002-01-04 02:02:28 +00:00
|
|
|
} elsif ($line =~ /^enum\s+\{/) {
|
|
|
|
while ($line !~ /^};/) {$line = <INFILE>;}
|
2002-07-26 06:08:52 +00:00
|
|
|
} 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;
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
} else {
|
2002-07-05 20:22:21 +00:00
|
|
|
if ($braces or $line =~ /;/) {
|
|
|
|
print $line;
|
|
|
|
} else {
|
|
|
|
$prepend = $line;
|
|
|
|
$prepend =~ s/\n/ /g;
|
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-19 18:44:01 +00:00
|
|
|
foreach $fname (@srcs, @privhdrs) {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
open(INFILE, $fname) || die "Could open $fname\n";
|
|
|
|
|
2002-01-17 00:26:46 +00:00
|
|
|
if ($fname =~ /builtins_ids/) {
|
|
|
|
while ($line = <INFILE>) {
|
|
|
|
next if ($line !~ /\{/);
|
|
|
|
|
|
|
|
chomp($line);
|
|
|
|
$builtin = "BUILTIN" . $line;
|
|
|
|
$builtin .= <INFILE>;
|
|
|
|
print $builtin;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
while ($line = <INFILE>) {
|
2002-06-21 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: New base class for classes and interfaces.
* generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations.
* generator/ObjectGen.cs: Move half of this into ClassBase.
* generator/Method.cs: Turn all applicable Get/Set functions into .NET
accessors. Remove redundant == overload and move into Equals, as
it was confusing "!= null".
* generator/Parameters.cs: Alter signature creation to accept "is_set"
option, add support for variable arguments. Add properties "Count",
"IsVarArgs", "VAType".
* generator/Ctor.cs: Fixup for changes in Parameters (indenting,
signature creation).
* generator/Signal.cs: Support generating declarations.
* generator/SymbolTable: Change GetObjectGen to GetClassGen.
* glib/IWrapper.cs: Move "Handle" declaration to here, so
both classes and interfaces can benefit from it.
* glib/Object.cs: Inherit from IWrapper.cs
* parser/Metadata.pm: Support attribute changes on constructors,
methods, signals, and paramater lists.
* parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_"
functions here.
* parser/gapi_pp.pl: Remove boxed_type_register check, as it will
be caught in the init funcs.
* parser/Atk.metadata: Added.
* parser/Gtk.metadata: Add all needed signal/method collision
renames. Rename GtkEditable.Editable accessors to IsEditable,
as .NET does not like accessors with the same name as their
declaring type. Tag TreeStore constructor as varargs.
* samples/ButtonApp.cs: s/EmitAdd/Add.
* samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated.
svn path=/trunk/gtk-sharp/; revision=5394
2002-06-21 17:15:19 +00:00
|
|
|
#next if ($line !~ /^(struct|\w+_class_init)|g_boxed_type_register_static/);
|
|
|
|
next if ($line !~ /^(struct|\w+_class_init|\w+_base_init|\w+_get_type)/);
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
if ($line =~ /^struct/) {
|
|
|
|
# need some of these to parse out parent types
|
|
|
|
print "private";
|
|
|
|
}
|
|
|
|
|
2003-06-25 21:22:28 +00:00
|
|
|
$comment = 0;
|
|
|
|
$begin = 0;
|
|
|
|
$end = 0;
|
2002-01-04 02:02:28 +00:00
|
|
|
do {
|
2003-06-25 21:22:28 +00:00
|
|
|
# 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;
|
2002-01-04 02:02:28 +00:00
|
|
|
} until (($line = <INFILE>) =~ /^}/);
|
|
|
|
print $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|