8 my @namespace_whole = (); # list of strings.
9 my $function_prefix = "";
10 my $parent_dir = ""; # e.g. gtkmm
13 my @filenames_headers = ();
16 my %namespaces = (); # hashmap of lists of strings.
18 my %win32_nowrap = ();
21 # Loop through command line arguments, setting variables:
22 while ($ARGV[0] =~ /^-/)
24 if ($ARGV[0] =~ /--namespace=(\S+)/)
26 push(@namespace_whole, $1);
29 { $parent_dir = lc($1) . "mm"; }
31 elsif ($ARGV[0] =~ /--function_prefix=(\S+)/)
33 $function_prefix = "$1";
35 elsif ($ARGV[0] =~ /--parent_dir=(\S+)/)
41 $ARGV[0] =~ /--debug/) {$debug = 1;
43 elsif ($ARGV[0] =~ /--path=(\S+)/)
49 print "Error: unknown option $ARGV[0]\n";
60 if ($debug) {warn "Processing file : $ARGV[0]\n";}
62 my $filename = $ARGV[0];
63 open FILE, $filename or die "Couldn't open file $ARGV[0] : $!\n";
65 # my $file = $ARGV[0];
66 # $file =~ s/.*\/([^\/]+)$/$1/;
68 my @tmpnamespace = @namespace_whole;
74 if (/CLASS_START\((\w+)\)/) #We need a new way to get the namespace.
76 print "generate_wrap_init: namespace found: $1\n";
77 push(@tmpnamespace, $1);
79 elsif (/_CLASS_GOBJECT\s*\(/) #TODO: There is duplication of code here.
82 while ($line !~ /\)/ && ($_ = <FILE>))
87 $line =~ s/^.*_CLASS_GOBJECT\s*\(//;
89 ($cppname, $cname, $ccast) = split(/,/, $line);
91 $objects{$cppname} = $cname;
92 @{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
93 $basenames{$cppname} = lc($ccast);
95 elsif (/_CLASS_GTKOBJECT\s*\(/)
98 while ($line !~ /\)/ && ($_ = <FILE>))
103 $line =~ s/^.*_CLASS_GTKOBJECT\s*\(//;
105 ($cppname, $cname, $ccast) = split(/,/, $line);
107 #TODO: Remove this hack eventually.
108 if( ($cname ne "GtkTree") && ($cname ne "GtkTreeItem") && ($cname ne "GtkText") )
110 $objects{$cppname} = $cname;
111 @{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
112 $basenames{$cppname} = lc($ccast);
115 elsif (/_WRAP_GERROR\s*\(/) #TODO: There is duplication of code here.
118 while ($line !~ /\)/ && ($_ = <FILE>))
123 $line =~ s/^.*_WRAP_GERROR\s*\(//;
126 ($cppname, $cname, $ccast) = split(/,/, $line);
128 $exceptions{$cppname} = $cname;
129 @{$namespaces{$cppname}} = ( @tmpnamespace ); #both are lists of strings
130 $basenames{$cppname} = lc($ccast);
132 elsif (/_GTKMMPROC_WIN32_NO_WRAP/)
134 $win32_nowrap{$cppname} = 1;
136 elsif (/_IS_DEPRECATED/)
138 $deprecated{$cppname} = 1;
142 # Store header filename so that we can #include it later:
143 my $filename_header = $filename;
144 $filename_header =~ s/.*\/([^\/]+)\.hg/$1.h/;
145 push(@filenames_headers, $filename_header);
151 # my $namespace_whole_lower = lc($namespace_whole);
157 // Disable the 'const' function attribute of the get_type() functions.
158 // GCC would optimize them out because we don't use the return value.
160 #define G_GNUC_CONST /* empty */
162 #include <${parent_dir}/wrap_init.h>
163 #include <glibmm/error.h>
164 #include <glibmm/object.h>
166 // #include the widget headers so that we can call the get_type() static methods:
170 foreach( @filenames_headers )
172 print "#include \"" . $_ . "\"\n";
177 # Here we have to be subtle. The gtkmm objects are easy, they all go
178 # into the Gtk namespace. But in gnomemm, some go into the Gnome
179 # namespace (most of them), and some into the Gtk one (because the
180 # corresponding widget is Gtk-prefixed, e.g. GtkTed, GtkDial, etc...
182 # First, the Gtk namespace
184 print "extern \"C\"\n";
186 print "\n//Declarations of the *_get_type() functions:\n\n";
189 foreach $i (sort keys %objects)
191 if( $deprecated{$i} eq 1 )
193 # The uc(parent_dir) is a bit of a hack. One day it will get it wrong.
194 print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
197 #On Win32, these classes are not compiled:
198 if( $win32_nowrap{$i} eq 1 )
200 print "#ifndef G_OS_WIN32\n"
203 print "GType $basenames{$i}_get_type(void);\n";
205 if( $win32_nowrap{$i} eq 1 )
207 print "#endif //G_OS_WIN32\n"
210 if( $deprecated{$i} eq 1 )
212 print "#endif // *_DISABLE_DEPRECATED\n"
216 print "\n//Declarations of the *_error_quark() functions:\n\n";
219 foreach $i (sort keys %exceptions)
221 print "GQuark $basenames{$i}_quark(void);\n";
224 print "} // extern \"C\"\n";
227 print "\n//Declarations of the *_Class::wrap_new() methods, instead of including all the private headers:\n\n";
230 foreach $i (sort keys %objects)
232 if( $deprecated{$i} eq 1 )
234 # The uc(parent_dir) is a bit of a hack. One day it will get it wrong.
235 print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
238 #On Win32, these classes are not compiled:
239 if( $win32_nowrap{$i} eq 1 )
241 print "#ifndef G_OS_WIN32\n"
244 my $namespace_declarations = "";
245 my $namespace_close = "";
246 foreach ( @{$namespaces{$i}} )
248 $namespace_declarations .= "namespace $_ { ";
249 $namespace_close .= " }";
252 print "${namespace_declarations} class ${i}_Class { public: static Glib::ObjectBase* wrap_new(GObject*); }; ${namespace_close}\n";
254 if( $win32_nowrap{$i} eq 1 )
256 print "#endif //G_OS_WIN32\n"
259 if( $deprecated{$i} eq 1 )
261 print "#endif // *_DISABLE_DEPRECATED\n"
265 # print "\n//Declarations of the *Error::throw_func() methods:\n\n";
268 # foreach $i (sort keys %exceptions)
270 # my $namespace_declarations = "";
271 # my $namespace_close = "";
272 # foreach ( @{$namespaces{$i}} )
274 # $namespace_declarations .= "namespace $_ { ";
275 # $namespace_close .= " }";
278 # print "${namespace_declarations} class ${i} { public: static void throw_func(GError*); }; ${namespace_close}\n";
281 my $namespace_whole_declarations = "";
282 my $namespace_whole_close = "";
283 foreach( @namespace_whole )
285 $namespace_whole_declarations .= "namespace " . $_ ." { ";
286 $namespace_whole_close = "} //" . $_ . "\n" . $namespace_whole_close;
290 print "$namespace_whole_declarations\n";
292 print "void " .$function_prefix . "wrap_init()\n{\n";
295 # Generate namespace::wrap_init() body
298 print " // Register Error domains:\n";
300 foreach $i (sort keys %exceptions)
302 my $namespace_prefix = "";
303 foreach( @{$namespaces{$i}} )
305 $namespace_prefix .= $_ ."::";
308 print " Glib::Error::register_domain($basenames{$i}_quark(), &", "${namespace_prefix}${i}::throw_func);\n";
312 print "// Map gtypes to gtkmm wrapper-creation functions:\n";
314 foreach $i (sort keys %objects)
316 if( $deprecated{$i} eq 1 )
318 # The uc(parent_dir) is a bit of a hack. One day it will get it wrong.
319 print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
322 #On Win32, these classes are not compiled:
323 if( $win32_nowrap{$i} eq 1 )
325 print "#ifndef G_OS_WIN32\n"
328 my $namespace_prefix = "";
329 foreach( @{$namespaces{$i}} )
331 $namespace_prefix .= $_ ."::";
334 print " Glib::wrap_register($basenames{$i}_get_type(), &", "${namespace_prefix}${i}_Class::wrap_new);\n";
336 if( $win32_nowrap{$i} eq 1 )
338 print "#endif //G_OS_WIN32\n"
341 if( $deprecated{$i} eq 1 )
343 print "#endif // *_DISABLE_DEPRECATED\n"
348 print " // Register the gtkmm gtypes:\n";
350 foreach $i (sort keys %objects)
352 if( $deprecated{$i} eq 1 )
354 # The uc(parent_dir) is a bit of a hack. One day it will get it wrong.
355 print "#ifndef " . uc($parent_dir) ."_DISABLE_DEPRECATED\n"
358 #On Win32, these classes are not compiled:
359 if( $win32_nowrap{$i} eq 1 )
361 print "#ifndef G_OS_WIN32\n"
364 my $namespace_prefix = "";
365 foreach( @{$namespaces{$i}} )
367 $namespace_prefix .= $_ ."::";
370 print " ${namespace_prefix}${i}::get_type();\n";
372 if( $win32_nowrap{$i} eq 1 )
374 print "#endif //G_OS_WIN32\n"
377 if( $deprecated{$i} eq 1 )
379 print "#endif // *_DISABLE_DEPRECATED\n"
387 $namespace_whole_close