File: gapi-cdecl-insert

package info (click to toggle)
gnome-sharp2 2.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 3,524 kB
  • ctags: 1,144
  • sloc: sh: 9,068; cs: 5,409; makefile: 526; ansic: 239; xml: 112; perl: 32
file content (58 lines) | stat: -rwxr-xr-x 1,920 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/perl
#
# gapi-cdecl-insert : Inserts il into an assembly for CDecl callback delegates.
#
# Authors: Mike Kestner <mkestner@novell.com>
#
# Copyright (c) 2005 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.

die "Usage: gapi-cdecl-insert [--keyfile=<file>] <assembly_path>\n" if ($ARGV > 2);
foreach $arg (@ARGV) {
	if ($arg =~ /--keyfile=(.*)/) {
		$key = $1;
	} elsif (-e $arg) {
		$assembly = $arg;
	} else {
		die "Usage: gapi-cdecl-insert [--keyfile=<file>] <assembly_path>\n";
	}
}

if ($assembly =~ /(.*)\.dll/) {
	$basename = $1;
	`ildasm $assembly /out:$basename.raw`;
	open(INFILE, $basename . ".raw") || die "Couldn't open $basename.raw\n";
	open(OUTFILE, "> $basename.il") || die "Couldn't open $basename.il\n";
	while ($line = <INFILE>) {
		$insert = 1 if ($line =~ /\.custom instance void .*GLib\.CDeclCallbackAttribute/);

		if ($insert && $line =~ /(.*)\s+(Invoke\(.*)/) {
			print OUTFILE "$1 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) $2";
			$insert = 0;
			next;
		}
		print OUTFILE $line;
	}
	`ilasm /DLL /QUIET $basename.il`;
	`sn -R $assembly gtk-sharp.snk` if ($key);
	unlink "$basename.raw";
	unlink "$basename.il";
	unlink "$basename.res";
} else {
	print "This script only works for dlls.\nUsage: gapi-cdecl-insert [--keyfile=<file>] <dll_path>\n";
}