1 | #!/usr/bin/perl -w |
---|
2 | # |
---|
3 | # by Elliot Lee <sopwith@redhat.com> |
---|
4 | |
---|
5 | %trans = ( "NONE"=>"void", "CHAR"=>"char", |
---|
6 | "BOOL"=>"gboolean", "INT"=>"gint", |
---|
7 | "UINT"=>"guint", "LONG"=>"glong", |
---|
8 | "ULONG"=>"gulong", "FLOAT"=>"gfloat", |
---|
9 | "DOUBLE"=>"gdouble", "STRING"=>"gpointer", |
---|
10 | "ENUM"=>"gint", "FLAGS"=>"gint", |
---|
11 | "BOXED"=>"gpointer", |
---|
12 | "POINTER"=>"gpointer", |
---|
13 | "OBJECT"=>"gpointer", |
---|
14 | |
---|
15 | # complex types. These need special handling. |
---|
16 | "FOREIGN"=>"FOREIGN", |
---|
17 | "C_CALLBACK"=>"C_CALLBACK", |
---|
18 | "SIGNAL"=>"SIGNAL", |
---|
19 | "ARGS"=>"ARGS", |
---|
20 | "CALLBACK"=>"CALLBACK" |
---|
21 | ); |
---|
22 | |
---|
23 | if ($#ARGV != 2) { |
---|
24 | die ("Wrong number of arguments given, need <source> <target.h> <target.c>"); |
---|
25 | } |
---|
26 | |
---|
27 | open(IL, "<" . $ARGV[0]) || die ("Open failed: $!"); |
---|
28 | open(OH, ">" . $ARGV[1]) || die ("Open failed: $!"); |
---|
29 | open(OS, ">" . $ARGV[2]) || die ("Open failed: $!"); |
---|
30 | |
---|
31 | print OH <<EOT; |
---|
32 | #ifndef __GTK_MARSHAL_H__ |
---|
33 | #define __GTK_MARSHAL_H__ |
---|
34 | |
---|
35 | #include <gtk/gtktypeutils.h> |
---|
36 | #include <gtk/gtkobject.h> |
---|
37 | |
---|
38 | #ifdef __cplusplus |
---|
39 | extern "C" { |
---|
40 | #endif /* __cplusplus */ |
---|
41 | |
---|
42 | #define gtk_signal_default_marshaller gtk_marshal_NONE__NONE |
---|
43 | |
---|
44 | EOT |
---|
45 | |
---|
46 | print OS qq(#include "gtkmarshal.h"\n\n); |
---|
47 | |
---|
48 | while (defined($aline = <IL>)) { |
---|
49 | chomp $aline; |
---|
50 | ($retval, $paramlist) = split(/:/, $aline, 2); |
---|
51 | @params = split(/\s*,\s*/, $paramlist); |
---|
52 | |
---|
53 | my $funcname = $retval."__".join("_",@params); |
---|
54 | my $defname; |
---|
55 | |
---|
56 | next if (exists $defs{$funcname}); |
---|
57 | |
---|
58 | $doequiv = 0; |
---|
59 | for (@params, $retval) { |
---|
60 | if ($trans{$_} eq "gpointer" && $_ ne "POINTER") { |
---|
61 | $doequiv = 1; |
---|
62 | last; |
---|
63 | } |
---|
64 | if($_ eq "ENUM" || $_ eq "UINT" || $_ eq "ULONG") { |
---|
65 | $doequiv = 1; |
---|
66 | last; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | # Translate all function pointers to gpointer |
---|
71 | $defname = $funcname; |
---|
72 | if($doequiv) { |
---|
73 | print OH "#define gtk_marshal_$funcname "; |
---|
74 | $defs{$defname} = 1; |
---|
75 | |
---|
76 | for (@params, $retval) { |
---|
77 | if ($trans{$_} eq "gpointer") { |
---|
78 | $_ = "POINTER"; |
---|
79 | } |
---|
80 | if($_ eq "ENUM") { |
---|
81 | $_ = "UINT"; |
---|
82 | } |
---|
83 | if($_ eq "UINT") { |
---|
84 | $_ = "INT"; # Unvalidated assumption - please check |
---|
85 | } |
---|
86 | if($_ eq "ULONG") { |
---|
87 | $_ = "LONG"; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | $funcname = $retval."__".join("_",@params); |
---|
92 | |
---|
93 | print OH "gtk_marshal_$funcname\n\n"; |
---|
94 | next if (exists $defs{$funcname}); |
---|
95 | } |
---|
96 | $defs{$funcname} = 1; |
---|
97 | |
---|
98 | print OH <<EOT; |
---|
99 | void gtk_marshal_$funcname (GtkObject *object, |
---|
100 | GtkSignalFunc func, |
---|
101 | gpointer func_data, |
---|
102 | GtkArg *args); |
---|
103 | |
---|
104 | EOT |
---|
105 | |
---|
106 | print OS "typedef $trans{$retval} (*GtkSignal_$funcname) (GtkObject *object, \n"; |
---|
107 | $argn = 1; |
---|
108 | for (@params) { |
---|
109 | if($_ eq "C_CALLBACK") { |
---|
110 | print OS "gpointer arg".$argn."a,\n"; |
---|
111 | print OS "gpointer arg".$argn."b,\n"; |
---|
112 | $argn++; |
---|
113 | } elsif($_ eq "SIGNAL") { |
---|
114 | print OS "gpointer arg".$argn."a,\n"; |
---|
115 | print OS "gpointer arg".$argn."b,\n"; |
---|
116 | $argn++; |
---|
117 | } elsif($_ eq "ARGS") { |
---|
118 | print OS "gpointer arg".$argn."a,\n"; |
---|
119 | print OS "gpointer arg".$argn."b,\n"; |
---|
120 | $argn++; |
---|
121 | } elsif($_ eq "CALLBACK") { |
---|
122 | print OS "gpointer arg".$argn."a,\n"; |
---|
123 | print OS "gpointer arg".$argn."b,\n"; |
---|
124 | print OS "gpointer arg".$argn."c,\n"; |
---|
125 | $argn++; |
---|
126 | } elsif($_ eq "FOREIGN") { |
---|
127 | print OS "gpointer arg".$argn."a,\n"; |
---|
128 | print OS "gpointer arg".$argn."b,\n"; |
---|
129 | $argn++; |
---|
130 | } else { |
---|
131 | print OS "$trans{$_} arg".$argn++.",\n" unless $_ eq "NONE"; |
---|
132 | } |
---|
133 | } |
---|
134 | print OS "gpointer user_data);\n"; |
---|
135 | |
---|
136 | print OS <<EOT; |
---|
137 | void gtk_marshal_$funcname (GtkObject *object, |
---|
138 | GtkSignalFunc func, |
---|
139 | gpointer func_data, |
---|
140 | GtkArg *args) |
---|
141 | { |
---|
142 | GtkSignal_$funcname rfunc; |
---|
143 | EOT |
---|
144 | |
---|
145 | if($retval ne "NONE") { |
---|
146 | print OS " $trans{$retval} *return_val;\n"; |
---|
147 | $retn = 0; |
---|
148 | $retn = scalar @params unless $params[0] eq "NONE"; |
---|
149 | print OS " return_val = GTK_RETLOC_$retval (args[$retn]);\n"; |
---|
150 | } |
---|
151 | print OS " rfunc = (GtkSignal_$funcname) func;\n"; |
---|
152 | print OS " *return_val = " unless $retval eq "NONE"; |
---|
153 | print OS " (* rfunc) (object,\n"; |
---|
154 | |
---|
155 | for($i = 0; $i < (scalar @params); $i++) { |
---|
156 | if($params[$i] eq "C_CALLBACK") { |
---|
157 | print OS <<EOT; |
---|
158 | GTK_VALUE_C_CALLBACK(args[$i]).func, |
---|
159 | GTK_VALUE_C_CALLBACK(args[$i]).func_data, |
---|
160 | EOT |
---|
161 | } elsif ($params[$i] eq "SIGNAL") { |
---|
162 | print OS <<EOT; |
---|
163 | GTK_VALUE_SIGNAL(args[$i]).f, |
---|
164 | GTK_VALUE_SIGNAL(args[$i]).d, |
---|
165 | EOT |
---|
166 | } elsif ($params[$i] eq "CALLBACK") { |
---|
167 | print OS <<EOT; |
---|
168 | GTK_VALUE_CALLBACK(args[$i]).marshal, |
---|
169 | GTK_VALUE_CALLBACK(args[$i]).data, |
---|
170 | GTK_VALUE_CALLBACK(args[$i]).notify, |
---|
171 | EOT |
---|
172 | } elsif ($params[$i] eq "FOREIGN") { |
---|
173 | print OS <<EOT; |
---|
174 | GTK_VALUE_FOREIGN(args[$i]).data, |
---|
175 | GTK_VALUE_FOREIGN(args[$i]).notify, |
---|
176 | EOT |
---|
177 | } elsif ($params[$i] eq "NONE") { |
---|
178 | } else { |
---|
179 | print OS " GTK_VALUE_$params[$i](args[$i]),\n"; |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | print OS " func_data);\n}\n\n"; |
---|
184 | } |
---|
185 | print OH <<EOT; |
---|
186 | |
---|
187 | #ifdef __cplusplus |
---|
188 | } |
---|
189 | #endif /* __cplusplus */ |
---|
190 | |
---|
191 | #endif /* __GTK_MARSHAL_H__ */ |
---|
192 | EOT |
---|
193 | |
---|
194 | close(IL); close(OH); close(OS); |
---|