3 # GIMP - The GNU Image Manipulation Program
4 # Copyright (C) 1999-2003 Manish Singh <yosh@gimp.org>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUTFILE ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 $srcdir = $ENV{srcdir
} || '.';
21 $destdir = $ENV{destdir
} || '.';
22 $builddir = $ENV{builddir
} || '.';
30 *enums
= \
%Gimp::CodeGen
::enums
::enums
;
32 *write_file
= \
&Gimp
::CodeGen
::util
::write_file
;
33 *FILE_EXT
= \
$Gimp::CodeGen
::util
::FILE_EXT
;
35 my $enumfile = "$builddir/libgimp/gimpenums.h$FILE_EXT";
36 open ENUMFILE
, "> $enumfile" or die "Can't open $enumfile: $!\n";
38 print ENUMFILE
<<'LGPL';
39 /* LIBGIMP - The GIMP Library
40 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
42 * This library is free software: you can redistribute it and/or
43 * modify it under the terms of the GNU Lesser General Public
44 * License as published by the Free Software Foundation; either
45 * version 3 of the License, or (at your option) any later version.
47 * This library is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 * Lesser General Public License for more details.
52 * You should have received a copy of the GNU Lesser General Public
53 * License along with this library. If not, see
54 * <https://www.gnu.org/licenses/>.
57 /* NOTE: This file is autogenerated by enumcode.pl */
61 my $guard = "__GIMP_ENUMS_H__";
62 print ENUMFILE
<<HEADER;
70 foreach (sort keys %enums) {
71 if (! ($enums{$_}->{header
} =~ /libgimp/) &&
72 ! $enums{$_}->{external
}) {
73 my $gtype = $func = $_;
75 for ($gtype) { s/Gimp//; s/([A-Z][^A-Z]+)/\U$1\E_/g; s/_$// }
76 for ($func) { s/Gimp//; s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// }
78 print ENUMFILE
"\n#define GIMP_TYPE_$gtype (gimp_$func\_get_type ())\n\n";
79 print ENUMFILE
"GType gimp_$func\_get_type (void) G_GNUC_CONST;\n\n";
80 print ENUMFILE
"typedef enum\n{\n";
82 my $enum = $enums{$_}; my $body = "";
84 foreach $symbol (@
{$enum->{symbols
}}) {
87 $body .= " = $enum->{mapping}->{$symbol}" if !$enum->{contig
};
98 print ENUMFILE
<<HEADER;
100 void gimp_enums_init (void);
102 const gchar ** gimp_enums_get_type_names (gint *n_type_names);
111 &write_file
($enumfile, "$destdir/libgimp");
113 $enumfile = "$builddir/libgimp/gimpenums.c.tail$FILE_EXT";
114 open ENUMFILE
, "> $enumfile" or die "Can't open $enumfile: $!\n";
116 print ENUMFILE
<<CODE;
118 typedef GType (* GimpGetTypeFunc) (void);
120 static const GimpGetTypeFunc get_type_funcs[] =
125 foreach (sort keys %enums) {
126 if (! ($_ =~ /GimpUnit/)) {
127 my $enum = $enums{$_};
129 my $gegl_enum = ($func =~ /Gegl/);
131 for ($func) { s/Gimp//; s/Gegl//; s/PDB/Pdb/;
132 s/([A-Z][^A-Z]+)/\L$1\E_/g; s/_$// }
134 print ENUMFILE
",\n" unless $first;
137 print ENUMFILE
" gegl_$func\_get_type";
139 print ENUMFILE
" gimp_$func\_get_type";
145 print ENUMFILE
"\n" unless $first;
147 print ENUMFILE
<<CODE;
150 static const gchar * const type_names[] =
155 foreach (sort keys %enums) {
156 if (! ($_ =~ /GimpUnit/)) {
157 my $enum = $enums{$_};
160 print ENUMFILE
",\n" unless $first;
161 print ENUMFILE
" \"$gtype\"";
166 print ENUMFILE
"\n" unless $first;
168 print ENUMFILE
<<CODE;
171 static gboolean enums_initialized = FALSE;
174 /* keep around as documentation how to do compat enums */
175 GType gimp_convert_dither_type_compat_get_type (void);
181 * This function makes sure all the enum types are registered
182 * with the #GType system. This is intended for use by language
183 * bindings that need the symbols early, before gimp_main is run.
184 * It's not necessary for plug-ins to call this directly, because
185 * the normal plug-in initialization code will handle it implicitly.
190 gimp_enums_init (void)
192 const GimpGetTypeFunc *funcs = get_type_funcs;
198 if (enums_initialized)
201 for (i = 0; i < G_N_ELEMENTS (get_type_funcs); i++, funcs++)
203 GType type = (*funcs) ();
205 g_type_class_ref (type);
209 /* keep around as documentation how to do compat enums */
211 /* keep compat enum code in sync with app/app.c (app_libs_init) */
212 quark = g_quark_from_static_string ("gimp-compat-enum");
214 g_type_set_qdata (GIMP_TYPE_CONVERT_DITHER_TYPE, quark,
215 (gpointer) gimp_convert_dither_type_compat_get_type ());
218 gimp_base_compat_enums_init ();
220 enums_initialized = TRUE;
224 * gimp_enums_get_type_names:
225 * \@n_type_names: return location for the number of names
227 * This function gives access to the list of enums registered by libgimp.
228 * The returned array is static and must not be modified.
230 * Return value: an array with type names
235 gimp_enums_get_type_names (gint *n_type_names)
237 g_return_val_if_fail (n_type_names != NULL, NULL);
239 *n_type_names = G_N_ELEMENTS (type_names);
241 return (const gchar **) type_names;
246 &write_file
($enumfile, "$destdir/libgimp");