1999-03-20 07:04:16 +08:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
2006-12-10 05:33:38 +08:00
|
|
|
# GIMP - The GNU Image Manipulation Program
|
2003-07-03 08:47:26 +08:00
|
|
|
# Copyright (C) 1999-2003 Manish Singh <yosh@gimp.org>
|
1999-03-20 07:04:16 +08:00
|
|
|
|
2009-01-18 06:28:01 +08:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
1999-03-20 07:04:16 +08:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1999-03-20 07:04:16 +08:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUTFILE 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
|
2018-07-12 05:27:07 +08:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
BEGIN {
|
2011-11-07 00:33:20 +08:00
|
|
|
$srcdir = $ENV{srcdir} || '.';
|
|
|
|
$destdir = $ENV{destdir} || '.';
|
|
|
|
$builddir = $ENV{builddir} || '.';
|
2023-08-30 21:52:47 +08:00
|
|
|
$topsrcdir = $ENV{topsrcdir} || '.';
|
1999-03-20 07:04:16 +08:00
|
|
|
}
|
|
|
|
|
1999-03-21 10:14:08 +08:00
|
|
|
use lib $srcdir;
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
use Text::Wrap qw(wrap $columns);
|
1999-04-04 13:59:08 +08:00
|
|
|
$columns = 77;
|
1999-03-20 07:04:16 +08:00
|
|
|
|
1999-07-08 13:26:18 +08:00
|
|
|
#BEGIN { require 'util.pl' }
|
|
|
|
require 'util.pl';
|
1999-03-21 10:14:08 +08:00
|
|
|
|
|
|
|
*write_file = \&Gimp::CodeGen::util::write_file;
|
|
|
|
*FILE_EXT = \$Gimp::CodeGen::util::FILE_EXT;
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
my $header = <<'HEADER';
|
2006-12-10 05:33:38 +08:00
|
|
|
:# GIMP - The GNU Image Manipulation Program
|
2003-07-03 08:47:26 +08:00
|
|
|
:# Copyright (C) 1999-2003 Manish Singh <yosh@gimp.org>
|
1999-03-20 07:04:16 +08:00
|
|
|
:
|
2009-01-18 06:28:01 +08:00
|
|
|
:# This program is free software: you can redistribute it and/or modify
|
1999-03-20 07:04:16 +08:00
|
|
|
:# it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
:# the Free Software Foundation; either version 3 of the License, or
|
1999-03-20 07:04:16 +08:00
|
|
|
:# (at your option) any later version.
|
|
|
|
:
|
|
|
|
:# This program is distributed in the hope that it will be useful,
|
|
|
|
:# but WITHOUTFILE 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
|
2018-07-12 05:27:07 +08:00
|
|
|
:# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1999-03-20 07:04:16 +08:00
|
|
|
:
|
|
|
|
:# autogenerated by enumgen.pl
|
|
|
|
:
|
|
|
|
:package Gimp::CodeGen::enums;
|
|
|
|
:
|
|
|
|
:%enums = (
|
|
|
|
HEADER
|
|
|
|
|
2018-03-18 03:19:58 +08:00
|
|
|
my $external;
|
|
|
|
open my $EXTERNAL, "enums-external.pl";
|
|
|
|
{
|
|
|
|
local $/;
|
|
|
|
$external = <$EXTERNAL>;
|
|
|
|
}
|
|
|
|
close $EXTERNAL;
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
my $footer = <<'FOOTER';
|
|
|
|
:);
|
|
|
|
:
|
|
|
|
:foreach $e (values %enums) {
|
|
|
|
: $e->{info} = "";
|
1999-04-04 13:59:08 +08:00
|
|
|
: foreach (@{$e->{symbols}}) {
|
2002-03-18 06:54:26 +08:00
|
|
|
: $e->{info} .= "$_ ($e->{mapping}->{$_}), "
|
1999-04-04 13:59:08 +08:00
|
|
|
: }
|
1999-03-20 07:04:16 +08:00
|
|
|
: $e->{info} =~ s/, $//;
|
|
|
|
:}
|
|
|
|
:
|
|
|
|
:1;
|
|
|
|
FOOTER
|
|
|
|
|
2002-03-18 06:54:26 +08:00
|
|
|
my ($enumname, $contig, $symbols, @mapping, $before);
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
# Most of this enum parsing stuff was swiped from makeenums.pl in GTK+
|
1999-04-04 13:59:08 +08:00
|
|
|
sub parse_options {
|
|
|
|
my $opts = shift;
|
|
|
|
my @opts;
|
|
|
|
|
|
|
|
for $opt (split /\s*,\s*/, $opts) {
|
2003-06-30 05:54:09 +08:00
|
|
|
$opt =~ s/^\s*//;
|
|
|
|
$opt =~ s/\s*$//;
|
|
|
|
my ($key,$val) = $opt =~ /([-\w]+)(?:=(.+))?/;
|
1999-04-04 13:59:08 +08:00
|
|
|
defined $val or $val = 1;
|
|
|
|
push @opts, $key, $val;
|
|
|
|
}
|
|
|
|
@opts;
|
|
|
|
}
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
sub parse_entries {
|
|
|
|
my $file = shift;
|
2003-06-30 05:54:09 +08:00
|
|
|
my $file_name = shift;
|
|
|
|
my $looking_for_name = 0;
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
while (<$file>) {
|
|
|
|
# Read lines until we have no open comments
|
2003-06-30 05:54:09 +08:00
|
|
|
while (m@/\*([^*]|\*(?!/))*$@) {
|
1999-03-20 07:04:16 +08:00
|
|
|
my $new;
|
2003-06-30 05:54:09 +08:00
|
|
|
defined ($new = <$file>) || die "Unmatched comment in $ARGV";
|
1999-03-20 07:04:16 +08:00
|
|
|
$_ .= $new;
|
|
|
|
}
|
2003-06-30 05:54:09 +08:00
|
|
|
# strip comments w/o options
|
1999-03-20 07:04:16 +08:00
|
|
|
s@/\*(?!<)
|
|
|
|
([^*]+|\*(?!/))*
|
|
|
|
\*/@@gx;
|
|
|
|
|
|
|
|
s@\n@ @;
|
|
|
|
|
|
|
|
next if m@^\s*$@;
|
|
|
|
|
2003-06-30 05:54:09 +08:00
|
|
|
if ($looking_for_name) {
|
|
|
|
if (/^\s*(\w+)/) {
|
|
|
|
$enumname = $1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
# Handle include files
|
|
|
|
if (/^\#include\s*<([^>]*)>/ ) {
|
|
|
|
my $file= "../$1";
|
|
|
|
open NEWFILE, $file or die "Cannot open include file $file: $!\n";
|
|
|
|
|
2003-06-30 05:54:09 +08:00
|
|
|
if (&parse_entries (\*NEWFILE, $NEWFILE)) {
|
1999-03-20 07:04:16 +08:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^\s*\}\s*(\w+)/) {
|
|
|
|
$enumname = $1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-06-30 05:54:09 +08:00
|
|
|
if (/^\s*\}/) {
|
|
|
|
$looking_for_name = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
1999-03-20 07:04:16 +08:00
|
|
|
if (m@^\s*
|
|
|
|
(\w+)\s* # name
|
|
|
|
(?:=( # value
|
|
|
|
(?:[^,/]|/(?!\*))*
|
|
|
|
))?,?\s*
|
|
|
|
(?:/\*< # options
|
|
|
|
(([^*]|\*(?!/))*)
|
2002-03-18 06:54:26 +08:00
|
|
|
>\s*\*/)?,?
|
1999-03-20 07:04:16 +08:00
|
|
|
\s*$
|
|
|
|
@x) {
|
1999-04-04 13:59:08 +08:00
|
|
|
my ($name, $value, $options) = ($1, $2, $3);
|
|
|
|
|
|
|
|
if (defined $options) {
|
|
|
|
my %options = parse_options($options);
|
2004-01-06 22:02:08 +08:00
|
|
|
next if defined $options{"pdb-skip"};
|
1999-09-24 07:42:38 +08:00
|
|
|
}
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
$symbols .= $name . ' ';
|
|
|
|
|
|
|
|
# Figure out a default value (not really foolproof)
|
|
|
|
$value = $before + 1 if !defined $value;
|
|
|
|
$value =~ s/\s*$//s;
|
|
|
|
$value =~ s/^\s*//s;
|
|
|
|
|
|
|
|
push @mapping, $name, $value;
|
|
|
|
|
|
|
|
my $test = $before + 1;
|
|
|
|
|
|
|
|
# Warnings in our eval should be fatal so they set $@
|
|
|
|
local $SIG{__WARN__} = sub { die $_[0] };
|
|
|
|
|
|
|
|
# Try to get a numeric value
|
|
|
|
eval "\$test = $value * 1;";
|
|
|
|
|
|
|
|
# Assume noncontiguous if it's not a number
|
|
|
|
$contig = 0 if $contig && ($@ || $test - 1 != $before);
|
|
|
|
|
|
|
|
$before = $test;
|
2003-06-30 05:54:09 +08:00
|
|
|
} elsif (m@^\s*\#@) {
|
|
|
|
# ignore preprocessor directives
|
1999-03-20 07:04:16 +08:00
|
|
|
} else {
|
2003-06-30 05:54:09 +08:00
|
|
|
print STDERR "$0: $file_name:$.: Failed to parse `$_'\n";
|
1999-03-20 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $code = "";
|
|
|
|
while (<>) {
|
|
|
|
if (eof) {
|
|
|
|
close (ARGV); # reset line numbering
|
|
|
|
}
|
|
|
|
|
2003-06-30 05:54:09 +08:00
|
|
|
# read lines until we have no open comments
|
|
|
|
while (m@/\*([^*]|\*(?!/))*$@) {
|
|
|
|
my $new;
|
|
|
|
defined ($new = <>) || die "Unmatched comment in $ARGV";
|
|
|
|
$_ .= $new;
|
|
|
|
}
|
|
|
|
# strip comments w/o options
|
|
|
|
s@/\*(?!<)
|
|
|
|
([^*]+|\*(?!/))*
|
|
|
|
\*/@@gx;
|
|
|
|
|
1999-04-04 13:59:08 +08:00
|
|
|
if (m@^\s*typedef\s+enum\s*
|
|
|
|
({)?\s*
|
|
|
|
(?:/\*<
|
|
|
|
(([^*]|\*(?!/))*)
|
2002-03-18 06:54:26 +08:00
|
|
|
>\s*\*/)?
|
1999-04-04 13:59:08 +08:00
|
|
|
@x) {
|
|
|
|
if (defined $2) {
|
|
|
|
my %options = parse_options($2);
|
2003-06-30 05:54:09 +08:00
|
|
|
next if defined $options{"pdb-skip"};
|
1999-04-04 13:59:08 +08:00
|
|
|
}
|
1999-03-20 07:04:16 +08:00
|
|
|
# Didn't have trailing '{' look on next lines
|
|
|
|
if (!defined $1) {
|
|
|
|
while (<>) {
|
|
|
|
if (s/^\s*\{//) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-18 06:54:26 +08:00
|
|
|
$symbols = ""; $contig = 1; $before = -1; @mapping = ();
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
# Now parse the entries
|
2003-06-30 05:54:09 +08:00
|
|
|
&parse_entries (\*ARGV, $ARGV);
|
1999-03-20 07:04:16 +08:00
|
|
|
|
|
|
|
$symbols =~ s/\s*$//s;
|
|
|
|
$symbols = wrap("\t\t\t ", "\t\t\t " , $symbols);
|
|
|
|
$symbols =~ s/^\s*//s;
|
|
|
|
|
|
|
|
my $mapping = ""; $pos = 1;
|
|
|
|
foreach (@mapping) {
|
|
|
|
$mapping .= $pos++ % 2 ? "$_ => " : "'$_',\n\t\t ";
|
|
|
|
}
|
|
|
|
$mapping =~ s/,\n\s*$//s;
|
|
|
|
|
2023-08-30 21:52:47 +08:00
|
|
|
$ARGV =~ s@($topsrcdir/)?(?:(?:..|app)/)*@@;
|
1999-04-23 14:55:37 +08:00
|
|
|
|
2003-06-30 05:54:09 +08:00
|
|
|
$code .= <<ENTRY;
|
1999-04-10 12:52:07 +08:00
|
|
|
: $enumname =>
|
|
|
|
: { contig => $contig,
|
2001-01-22 07:24:26 +08:00
|
|
|
: header => '$ARGV',
|
1999-04-10 12:52:07 +08:00
|
|
|
: symbols => [ qw($symbols) ],
|
2002-03-18 06:54:26 +08:00
|
|
|
: mapping => { $mapping }
|
1999-04-10 12:52:07 +08:00
|
|
|
: },
|
1999-03-20 07:04:16 +08:00
|
|
|
ENTRY
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$code =~ s/,\n$/\n/s;
|
|
|
|
|
1999-04-10 12:52:07 +08:00
|
|
|
foreach ($header, $code, $footer) { s/^://mg }
|
|
|
|
|
2018-03-15 02:36:31 +08:00
|
|
|
$outfile = "$builddir/pdb/enums.pl$FILE_EXT";
|
1999-03-21 10:14:08 +08:00
|
|
|
open OUTFILE, "> $outfile";
|
2018-03-18 03:19:58 +08:00
|
|
|
print OUTFILE $header, $external, $code, $footer;
|
1999-03-20 07:04:16 +08:00
|
|
|
close OUTFILE;
|
2018-03-15 02:36:31 +08:00
|
|
|
&write_file($outfile, "$destdir/pdb");
|