3
# The GIMP -- an 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 2 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, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
$srcdir = $ENV{srcdir} || '.';
22
$destdir = $ENV{srcdir} || '.';
27
use Text::Wrap qw(wrap $columns);
30
#BEGIN { require 'util.pl' }
33
*write_file = \&Gimp::CodeGen::util::write_file;
34
*FILE_EXT = \$Gimp::CodeGen::util::FILE_EXT;
36
my $header = <<'HEADER';
37
:# The GIMP -- an image manipulation program
38
:# Copyright (C) 1999-2003 Manish Singh <yosh@gimp.org>
40
:# This program is free software; you can redistribute it and/or modify
41
:# it under the terms of the GNU General Public License as published by
42
:# the Free Software Foundation; either version 2 of the License, or
43
:# (at your option) any later version.
45
:# This program is distributed in the hope that it will be useful,
46
:# but WITHOUTFILE ANY WARRANTY; without even the implied warranty of
47
:# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48
:# GNU General Public License for more details.
50
:# You should have received a copy of the GNU General Public License
51
:# along with this program; if not, write to the Free Software
52
:# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54
:# autogenerated by enumgen.pl
56
:package Gimp::CodeGen::enums;
61
my $footer = <<'FOOTER';
64
:foreach $e (values %enums) {
66
: foreach (@{$e->{symbols}}) {
67
: $e->{info} .= "$_ ($e->{mapping}->{$_}), "
69
: $e->{info} =~ s/, $//;
75
my ($enumname, $contig, $symbols, @mapping, $before);
77
# Most of this enum parsing stuff was swiped from makeenums.pl in GTK+
82
for $opt (split /\s*,\s*/, $opts) {
85
my ($key,$val) = $opt =~ /([-\w]+)(?:=(.+))?/;
86
defined $val or $val = 1;
87
push @opts, $key, $val;
94
my $file_name = shift;
95
my $looking_for_name = 0;
98
# Read lines until we have no open comments
99
while (m@/\*([^*]|\*(?!/))*$@) {
101
defined ($new = <$file>) || die "Unmatched comment in $ARGV";
104
# strip comments w/o options
113
if ($looking_for_name) {
120
# Handle include files
121
if (/^\#include\s*<([^>]*)>/ ) {
123
open NEWFILE, $file or die "Cannot open include file $file: $!\n";
125
if (&parse_entries (\*NEWFILE, $NEWFILE)) {
132
if (/^\s*\}\s*(\w+)/) {
138
$looking_for_name = 1;
152
my ($name, $value, $options) = ($1, $2, $3);
154
if (defined $options) {
155
my %options = parse_options($options);
156
next if defined $options{"pdb-skip"};
159
$symbols .= $name . ' ';
161
# Figure out a default value (not really foolproof)
162
$value = $before + 1 if !defined $value;
166
push @mapping, $name, $value;
168
my $test = $before + 1;
170
# Warnings in our eval should be fatal so they set $@
171
local $SIG{__WARN__} = sub { die $_[0] };
173
# Try to get a numeric value
174
eval "\$test = $value * 1;";
176
# Assume noncontiguous if it's not a number
177
$contig = 0 if $contig && ($@ || $test - 1 != $before);
180
} elsif (m@^\s*\#@) {
181
# ignore preprocessor directives
183
print STDERR "$0: $file_name:$.: Failed to parse `$_'\n";
192
close (ARGV); # reset line numbering
195
# read lines until we have no open comments
196
while (m@/\*([^*]|\*(?!/))*$@) {
198
defined ($new = <>) || die "Unmatched comment in $ARGV";
201
# strip comments w/o options
206
if (m@^\s*typedef\s+enum\s*
213
my %options = parse_options($2);
214
next if defined $options{"pdb-skip"};
216
# Didn't have trailing '{' look on next lines
225
$symbols = ""; $contig = 1; $before = -1; @mapping = ();
227
# Now parse the entries
228
&parse_entries (\*ARGV, $ARGV);
230
$symbols =~ s/\s*$//s;
231
$symbols = wrap("\t\t\t ", "\t\t\t " , $symbols);
232
$symbols =~ s/^\s*//s;
234
my $mapping = ""; $pos = 1;
236
$mapping .= $pos++ % 2 ? "$_ => " : "'$_',\n\t\t ";
238
$mapping =~ s/,\n\s*$//s;
240
$ARGV =~ s@(?:(?:..|app)/)*@@;
244
: { contig => $contig,
246
: symbols => [ qw($symbols) ],
247
: mapping => { $mapping }
253
$code =~ s/,\n$/\n/s;
255
foreach ($header, $code, $footer) { s/^://mg }
257
$outfile = "$destdir/enums.pl$FILE_EXT";
258
open OUTFILE, "> $outfile";
259
print OUTFILE $header, $code, $footer;
261
&write_file($outfile);