2011-02-08 05:46:02 +01:00
|
|
|
#! @PERL_PATH@
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2011-02-08 05:46:02 +01:00
|
|
|
use warnings;
|
2009-06-29 15:28:22 +02:00
|
|
|
use File::Basename;
|
2010-05-06 21:19:58 +02:00
|
|
|
use Safe;
|
2009-06-29 15:28:22 +02:00
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
# glib-mkenums.pl
|
|
|
|
# Information about the current enumeration
|
|
|
|
my $flags; # Is enumeration a bitmask?
|
2006-10-10 12:10:43 +02:00
|
|
|
my $option_underscore_name; # Overriden underscore variant of the enum name
|
|
|
|
# for example to fix the cases we don't get the
|
|
|
|
# mixed-case -> underscorized transform right.
|
|
|
|
my $option_lowercase_name; # DEPRECATED. A lower case name to use as part
|
|
|
|
# of the *_get_type() function, instead of the
|
|
|
|
# one that we guess. For instance, when an enum
|
|
|
|
# uses abnormal capitalization and we can not
|
|
|
|
# guess where to put the underscores.
|
2001-04-29 05:04:27 +02:00
|
|
|
my $seenbitshift; # Have we seen bitshift operators?
|
|
|
|
my $enum_prefix; # Prefix for this enumeration
|
|
|
|
my $enumname; # Name for this enumeration
|
|
|
|
my $enumshort; # $enumname without prefix
|
2008-06-23 14:06:39 +02:00
|
|
|
my $enumname_prefix; # prefix of $enumname
|
2001-04-29 05:04:27 +02:00
|
|
|
my $enumindex = 0; # Global enum counter
|
|
|
|
my $firstenum = 1; # Is this the first enumeration per file?
|
|
|
|
my @entries; # [ $name, $val ] for each entry
|
2010-05-06 21:19:58 +02:00
|
|
|
my $sandbox = Safe->new; # sandbox for safe evaluation of expressions
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
sub parse_trigraph {
|
|
|
|
my $opts = shift;
|
|
|
|
my @opts;
|
|
|
|
|
|
|
|
for $opt (split /\s*,\s*/, $opts) {
|
|
|
|
$opt =~ s/^\s*//;
|
|
|
|
$opt =~ s/\s*$//;
|
|
|
|
my ($key,$val) = $opt =~ /(\w+)(?:=(.+))?/;
|
|
|
|
defined $val or $val = 1;
|
|
|
|
push @opts, $key, $val;
|
|
|
|
}
|
|
|
|
@opts;
|
|
|
|
}
|
|
|
|
sub parse_entries {
|
|
|
|
my $file = shift;
|
|
|
|
my $file_name = shift;
|
2001-11-18 18:03:33 +01:00
|
|
|
my $looking_for_name = 0;
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
while (<$file>) {
|
2002-03-26 00:23:35 +01:00
|
|
|
# read lines until we have no open comments
|
|
|
|
while (m@/\*([^*]|\*(?!/))*$@) {
|
2001-04-29 05:04:27 +02:00
|
|
|
my $new;
|
2002-03-26 00:23:35 +01:00
|
|
|
defined ($new = <$file>) || die "Unmatched comment in $ARGV";
|
2001-04-29 05:04:27 +02:00
|
|
|
$_ .= $new;
|
|
|
|
}
|
|
|
|
# strip comments w/o options
|
2002-03-26 00:23:35 +01:00
|
|
|
s@/\*(?!<)
|
|
|
|
([^*]+|\*(?!/))*
|
|
|
|
\*/@@gx;
|
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
# strip newlines
|
2002-03-26 00:23:35 +01:00
|
|
|
s@\n@ @;
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
# skip empty lines
|
|
|
|
next if m@^\s*$@;
|
|
|
|
|
2001-11-18 18:03:33 +01:00
|
|
|
if ($looking_for_name) {
|
|
|
|
if (/^\s*(\w+)/) {
|
|
|
|
$enumname = $1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
# Handle include files
|
|
|
|
if (/^\#include\s*<([^>]*)>/ ) {
|
|
|
|
my $file= "../$1";
|
|
|
|
open NEWFILE, $file or die "Cannot open include file $file: $!\n";
|
|
|
|
|
|
|
|
if (parse_entries (\*NEWFILE, $NEWFILE)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^\s*\}\s*(\w+)/) {
|
|
|
|
$enumname = $1;
|
|
|
|
$enumindex++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-11-18 18:03:33 +01:00
|
|
|
if (/^\s*\}/) {
|
|
|
|
$enumindex++;
|
|
|
|
$looking_for_name = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
if (m@^\s*
|
|
|
|
(\w+)\s* # name
|
|
|
|
(?:=( # value
|
2004-02-27 01:49:56 +01:00
|
|
|
\s*\w+\s*\(.*\)\s* # macro with multiple args
|
|
|
|
| # OR
|
|
|
|
(?:[^,/]|/(?!\*))* # anything but a comma or comment
|
2001-04-29 05:04:27 +02:00
|
|
|
))?,?\s*
|
|
|
|
(?:/\*< # options
|
|
|
|
(([^*]|\*(?!/))*)
|
|
|
|
>\s*\*/)?,?
|
|
|
|
\s*$
|
|
|
|
@x) {
|
|
|
|
my ($name, $value, $options) = ($1,$2,$3);
|
|
|
|
|
|
|
|
if (!defined $flags && defined $value && $value =~ /<</) {
|
|
|
|
$seenbitshift = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined $options) {
|
|
|
|
my %options = parse_trigraph($options);
|
|
|
|
if (!defined $options{skip}) {
|
2010-05-06 21:19:58 +02:00
|
|
|
push @entries, [ $name, $value, $options{nick} ];
|
2001-04-29 05:04:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
2010-05-06 21:19:58 +02:00
|
|
|
push @entries, [ $name, $value ];
|
2001-04-29 05:04:27 +02:00
|
|
|
}
|
|
|
|
} elsif (m@^\s*\#@) {
|
|
|
|
# ignore preprocessor directives
|
|
|
|
} else {
|
|
|
|
print STDERR "$0: $file_name:$.: Failed to parse `$_'\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub version {
|
2006-08-29 13:29:24 +02:00
|
|
|
print "glib-mkenums version glib-@GLIB_VERSION@\n";
|
|
|
|
print "glib-mkenums comes with ABSOLUTELY NO WARRANTY.\n";
|
|
|
|
print "You may redistribute copies of glib-mkenums under the terms of\n";
|
|
|
|
print "the GNU General Public License which can be found in the\n";
|
|
|
|
print "GLib source package. Sources, examples and contact\n";
|
|
|
|
print "information are available at http://www.gtk.org\n";
|
2001-04-29 05:04:27 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
sub usage {
|
2009-03-01 16:40:07 +01:00
|
|
|
print "Usage:\n";
|
|
|
|
print " glib-mkenums [OPTION...] [FILES...]\n\n";
|
|
|
|
print "Help Options:\n";
|
|
|
|
print " -h, --help Show this help message\n\n";
|
|
|
|
print "Utility Options:\n";
|
2011-10-28 21:38:52 +02:00
|
|
|
print " --identifier-prefix <text> Identifier prefix\n";
|
|
|
|
print " --symbol-prefix <text> Symbol prefix\n";
|
|
|
|
print " --fhead <text> Output file header\n";
|
|
|
|
print " --fprod <text> Per input file production\n";
|
|
|
|
print " --ftail <text> Output file trailer\n";
|
|
|
|
print " --eprod <text> Per enum text (produced prior to value itarations)\n";
|
|
|
|
print " --vhead <text> Value header, produced before iterating over enum values\n";
|
|
|
|
print " --vprod <text> Value text, produced for each enum value\n";
|
|
|
|
print " --vtail <text> Value tail, produced after iterating over enum values\n";
|
|
|
|
print " --comments <text> Comment structure\n";
|
|
|
|
print " --template file Template file\n";
|
|
|
|
print " -v, --version Print version informations\n\n";
|
2006-08-29 13:29:24 +02:00
|
|
|
print "Production text substitutions:\n";
|
2009-03-01 16:40:07 +01:00
|
|
|
print " \@EnumName\@ PrefixTheXEnum\n";
|
|
|
|
print " \@enum_name\@ prefix_the_xenum\n";
|
|
|
|
print " \@ENUMNAME\@ PREFIX_THE_XENUM\n";
|
|
|
|
print " \@ENUMSHORT\@ THE_XENUM\n";
|
|
|
|
print " \@ENUMPREFIX\@ PREFIX\n";
|
|
|
|
print " \@VALUENAME\@ PREFIX_THE_XVALUE\n";
|
|
|
|
print " \@valuenick\@ the-xvalue\n";
|
2010-05-06 21:19:58 +02:00
|
|
|
print " \@valuenum\@ the integer value (limited support, Since: 2.26)\n";
|
2009-03-01 16:40:07 +01:00
|
|
|
print " \@type\@ either enum or flags\n";
|
|
|
|
print " \@Type\@ either Enum or Flags\n";
|
|
|
|
print " \@TYPE\@ either ENUM or FLAGS\n";
|
|
|
|
print " \@filename\@ name of current input file\n";
|
2009-06-29 15:28:22 +02:00
|
|
|
print " \@basename\@ base name of the current input file (Since: 2.22)\n";
|
2001-04-29 05:04:27 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# production variables:
|
2011-10-28 21:38:52 +02:00
|
|
|
my $idprefix = ""; # "G", "Gtk", etc
|
|
|
|
my $symprefix = ""; # "g", "gtk", etc, if not just lc($idprefix)
|
2001-04-29 05:04:27 +02:00
|
|
|
my $fhead = ""; # output file header
|
|
|
|
my $fprod = ""; # per input file production
|
|
|
|
my $ftail = ""; # output file trailer
|
|
|
|
my $eprod = ""; # per enum text (produced prior to value itarations)
|
|
|
|
my $vhead = ""; # value header, produced before iterating over enum values
|
|
|
|
my $vprod = ""; # value text, produced for each enum value
|
|
|
|
my $vtail = ""; # value tail, produced after iterating over enum values
|
2010-05-06 19:36:10 +02:00
|
|
|
my $comment_tmpl = ""; # comment template
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2002-10-16 00:26:39 +02:00
|
|
|
sub read_template_file {
|
|
|
|
my ($file) = @_;
|
|
|
|
my %tmpl = ('file-header', $fhead,
|
|
|
|
'file-production', $fprod,
|
|
|
|
'file-tail', $ftail,
|
|
|
|
'enumeration-production', $eprod,
|
|
|
|
'value-header', $vhead,
|
|
|
|
'value-production', $vprod,
|
|
|
|
'value-tail', $vtail,
|
|
|
|
'comment', $comment_tmpl);
|
|
|
|
my $in = 'junk';
|
|
|
|
open (FILE, $file) || die "Can't open $file: $!\n";
|
|
|
|
while (<FILE>) {
|
|
|
|
if (/^\/\*\*\*\s+(BEGIN|END)\s+([\w-]+)\s+\*\*\*\//) {
|
|
|
|
if (($in eq 'junk') && ($1 eq 'BEGIN') && (exists($tmpl{$2}))) {
|
|
|
|
$in = $2;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
elsif (($in eq $2) && ($1 eq 'END') && (exists($tmpl{$2}))) {
|
|
|
|
$in = 'junk';
|
|
|
|
next;
|
2006-10-10 12:10:43 +02:00
|
|
|
} else {
|
2002-10-16 00:26:39 +02:00
|
|
|
die "Malformed template file $file\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!($in eq 'junk')) {
|
|
|
|
$tmpl{$in} .= $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (FILE);
|
|
|
|
if (!($in eq 'junk')) {
|
|
|
|
die "Malformed template file $file\n";
|
|
|
|
}
|
|
|
|
$fhead = $tmpl{'file-header'};
|
|
|
|
$fprod = $tmpl{'file-production'};
|
|
|
|
$ftail = $tmpl{'file-tail'};
|
|
|
|
$eprod = $tmpl{'enumeration-production'};
|
|
|
|
$vhead = $tmpl{'value-header'};
|
|
|
|
$vprod = $tmpl{'value-production'};
|
|
|
|
$vtail = $tmpl{'value-tail'};
|
|
|
|
$comment_tmpl = $tmpl{'comment'};
|
2010-05-06 19:36:10 +02:00
|
|
|
|
|
|
|
# default to C-style comments
|
|
|
|
$comment_tmpl = "/* \@comment\@ */" if $comment_tmpl eq "";
|
2002-10-16 00:26:39 +02:00
|
|
|
}
|
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
if (!defined $ARGV[0]) {
|
|
|
|
usage;
|
|
|
|
}
|
2007-11-08 15:57:15 +01:00
|
|
|
while ($_=$ARGV[0],/^-/) {
|
2001-04-29 05:04:27 +02:00
|
|
|
shift;
|
|
|
|
last if /^--$/;
|
2009-03-01 16:40:07 +01:00
|
|
|
if (/^--template$/) { read_template_file (shift); }
|
2011-10-28 21:38:52 +02:00
|
|
|
elsif (/^--identifier-prefix$/) { $idprefix = shift }
|
|
|
|
elsif (/^--symbol-prefix$/) { $symprefix = shift }
|
2009-03-01 16:40:07 +01:00
|
|
|
elsif (/^--fhead$/) { $fhead = $fhead . shift }
|
|
|
|
elsif (/^--fprod$/) { $fprod = $fprod . shift }
|
|
|
|
elsif (/^--ftail$/) { $ftail = $ftail . shift }
|
|
|
|
elsif (/^--eprod$/) { $eprod = $eprod . shift }
|
|
|
|
elsif (/^--vhead$/) { $vhead = $vhead . shift }
|
|
|
|
elsif (/^--vprod$/) { $vprod = $vprod . shift }
|
|
|
|
elsif (/^--vtail$/) { $vtail = $vtail . shift }
|
|
|
|
elsif (/^--comments$/) { $comment_tmpl = shift }
|
2009-09-12 23:20:01 +02:00
|
|
|
elsif (/^--help$/ || /^-h$/ || /^-\?$/) { usage; }
|
2009-03-01 16:40:07 +01:00
|
|
|
elsif (/^--version$/ || /^-v$/) { version; }
|
2001-04-29 05:04:27 +02:00
|
|
|
else { usage; }
|
2007-11-08 15:57:15 +01:00
|
|
|
last if not defined($ARGV[0]);
|
2001-04-29 05:04:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# put auto-generation comment
|
|
|
|
{
|
|
|
|
my $comment = $comment_tmpl;
|
|
|
|
$comment =~ s/\@comment\@/Generated data (by glib-mkenums)/;
|
|
|
|
print "\n" . $comment . "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($fhead)) {
|
|
|
|
my $prod = $fhead;
|
2009-06-29 15:28:22 +02:00
|
|
|
my $base = basename ($ARGV[0]);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2002-10-16 00:26:39 +02:00
|
|
|
$prod =~ s/\@filename\@/$ARGV[0]/g;
|
2009-06-29 15:28:22 +02:00
|
|
|
$prod =~ s/\@basename\@/$base/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
while (<>) {
|
|
|
|
if (eof) {
|
|
|
|
close (ARGV); # reset line numbering
|
|
|
|
$firstenum = 1; # Flag to print filename at next enum
|
|
|
|
}
|
|
|
|
|
2002-03-26 00:23:35 +01:00
|
|
|
# read lines until we have no open comments
|
|
|
|
while (m@/\*([^*]|\*(?!/))*$@) {
|
2001-04-29 05:04:27 +02:00
|
|
|
my $new;
|
|
|
|
defined ($new = <>) || die "Unmatched comment in $ARGV";
|
|
|
|
$_ .= $new;
|
|
|
|
}
|
|
|
|
# strip comments w/o options
|
2002-03-26 00:23:35 +01:00
|
|
|
s@/\*(?!<)
|
|
|
|
([^*]+|\*(?!/))*
|
|
|
|
\*/@@gx;
|
|
|
|
|
2012-02-07 16:54:22 +01:00
|
|
|
# ignore forward declarations
|
|
|
|
next if /^\s*typedef\s+enum.*;/;
|
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
if (m@^\s*typedef\s+enum\s*
|
|
|
|
({)?\s*
|
|
|
|
(?:/\*<
|
|
|
|
(([^*]|\*(?!/))*)
|
|
|
|
>\s*\*/)?
|
2005-10-03 17:46:15 +02:00
|
|
|
\s*({)?
|
2001-04-29 05:04:27 +02:00
|
|
|
@x) {
|
|
|
|
if (defined $2) {
|
|
|
|
my %options = parse_trigraph ($2);
|
|
|
|
next if defined $options{skip};
|
|
|
|
$enum_prefix = $options{prefix};
|
|
|
|
$flags = $options{flags};
|
2006-10-10 12:10:43 +02:00
|
|
|
$option_lowercase_name = $options{lowercase_name};
|
|
|
|
$option_underscore_name = $options{underscore_name};
|
2001-04-29 05:04:27 +02:00
|
|
|
} else {
|
|
|
|
$enum_prefix = undef;
|
|
|
|
$flags = undef;
|
2006-10-10 12:10:43 +02:00
|
|
|
$option_lowercase_name = undef;
|
|
|
|
$option_underscore_name = undef;
|
|
|
|
}
|
|
|
|
if (defined $option_lowercase_name) {
|
|
|
|
if (defined $option_underscore_name) {
|
|
|
|
print STDERR "$0: $ARGV:$.: lowercase_name overriden with underscore_name\n";
|
|
|
|
$option_lowercase_name = undef;
|
|
|
|
} else {
|
|
|
|
print STDERR "$0: $ARGV:$.: lowercase_name is deprecated, use underscore_name\n";
|
|
|
|
}
|
2001-04-29 05:04:27 +02:00
|
|
|
}
|
|
|
|
# Didn't have trailing '{' look on next lines
|
2005-10-03 17:46:15 +02:00
|
|
|
if (!defined $1 && !defined $4) {
|
2001-04-29 05:04:27 +02:00
|
|
|
while (<>) {
|
2012-02-07 16:54:22 +01:00
|
|
|
if (eof) {
|
|
|
|
die "Hit end of file while parsing enum in $ARGV";
|
|
|
|
}
|
2001-04-29 05:04:27 +02:00
|
|
|
if (s/^\s*\{//) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$seenbitshift = 0;
|
|
|
|
@entries = ();
|
|
|
|
|
|
|
|
# Now parse the entries
|
|
|
|
parse_entries (\*ARGV, $ARGV);
|
|
|
|
|
|
|
|
# figure out if this was a flags or enums enumeration
|
|
|
|
if (!defined $flags) {
|
|
|
|
$flags = $seenbitshift;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Autogenerate a prefix
|
|
|
|
if (!defined $enum_prefix) {
|
|
|
|
for (@entries) {
|
2010-05-06 21:19:58 +02:00
|
|
|
my $nick = $_->[2];
|
2001-04-29 05:04:27 +02:00
|
|
|
if (!defined $nick) {
|
|
|
|
my $name = $_->[0];
|
|
|
|
if (defined $enum_prefix) {
|
|
|
|
my $tmp = ~ ($name ^ $enum_prefix);
|
|
|
|
($tmp) = $tmp =~ /(^\xff*)/;
|
|
|
|
$enum_prefix = $enum_prefix & $tmp;
|
|
|
|
} else {
|
|
|
|
$enum_prefix = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!defined $enum_prefix) {
|
|
|
|
$enum_prefix = "";
|
|
|
|
} else {
|
|
|
|
# Trim so that it ends in an underscore
|
|
|
|
$enum_prefix =~ s/_[^_]*$/_/;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# canonicalize user defined prefixes
|
|
|
|
$enum_prefix = uc($enum_prefix);
|
|
|
|
$enum_prefix =~ s/-/_/g;
|
|
|
|
$enum_prefix =~ s/(.*)([^_])$/$1$2_/;
|
|
|
|
}
|
|
|
|
|
|
|
|
for $entry (@entries) {
|
2010-05-06 21:19:58 +02:00
|
|
|
my ($name,$num,$nick) = @{$entry};
|
2001-04-29 05:04:27 +02:00
|
|
|
if (!defined $nick) {
|
|
|
|
($nick = $name) =~ s/^$enum_prefix//;
|
|
|
|
$nick =~ tr/_/-/;
|
|
|
|
$nick = lc($nick);
|
2010-05-06 21:19:58 +02:00
|
|
|
@{$entry} = ($name, $num, $nick);
|
2001-04-29 05:04:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Spit out the output
|
2006-10-10 12:10:43 +02:00
|
|
|
if (defined $option_underscore_name) {
|
|
|
|
$enumlong = uc $option_underscore_name;
|
|
|
|
$enumsym = lc $option_underscore_name;
|
|
|
|
$enumshort = $enumlong;
|
|
|
|
$enumshort =~ s/^[A-Z][A-Z0-9]*_//;
|
2008-06-23 14:06:39 +02:00
|
|
|
|
|
|
|
$enumname_prefix = $enumlong;
|
2011-10-14 20:32:11 +02:00
|
|
|
$enumname_prefix =~ s/_$enumshort$//;
|
2011-10-28 21:38:52 +02:00
|
|
|
} elsif (!$symprefix && !$idprefix) {
|
2006-10-10 12:10:43 +02:00
|
|
|
# enumname is e.g. GMatchType
|
|
|
|
$enspace = $enumname;
|
|
|
|
$enspace =~ s/^([A-Z][a-z]*).*$/$1/;
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2006-10-10 12:10:43 +02:00
|
|
|
$enumshort = $enumname;
|
|
|
|
$enumshort =~ s/^[A-Z][a-z]*//;
|
|
|
|
$enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g;
|
|
|
|
$enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
|
|
|
|
$enumshort = uc($enumshort);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2008-06-23 14:06:39 +02:00
|
|
|
$enumname_prefix = $enumname;
|
|
|
|
$enumname_prefix =~ s/^([A-Z][a-z]*).*$/$1/;
|
|
|
|
$enumname_prefix = uc($enumname_prefix);
|
|
|
|
|
2006-10-10 12:10:43 +02:00
|
|
|
$enumlong = uc($enspace) . "_" . $enumshort;
|
|
|
|
$enumsym = lc($enspace) . "_" . lc($enumshort);
|
|
|
|
|
|
|
|
if (defined($option_lowercase_name)) {
|
|
|
|
$enumsym = $option_lowercase_name;
|
|
|
|
}
|
2011-10-28 21:38:52 +02:00
|
|
|
} else {
|
|
|
|
$enumshort = $enumname;
|
|
|
|
if ($idprefix) {
|
|
|
|
$enumshort =~ s/^${idprefix}//;
|
|
|
|
} else {
|
|
|
|
$enumshort =~ s/^[A-Z][a-z]*//;
|
|
|
|
}
|
|
|
|
$enumshort =~ s/([^A-Z])([A-Z])/$1_$2/g;
|
|
|
|
$enumshort =~ s/([A-Z][A-Z])([A-Z][0-9a-z])/$1_$2/g;
|
|
|
|
$enumshort = uc($enumshort);
|
|
|
|
|
|
|
|
$enumname_prefix = $symprefix && uc($symprefix) || uc($idprefix);
|
|
|
|
|
|
|
|
$enumlong = $enumname_prefix . "_" . $enumshort;
|
|
|
|
$enumsym = lc($enumlong);
|
2006-10-10 12:10:43 +02:00
|
|
|
}
|
2003-12-30 11:42:57 +01:00
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
if ($firstenum) {
|
|
|
|
$firstenum = 0;
|
|
|
|
|
|
|
|
if (length($fprod)) {
|
|
|
|
my $prod = $fprod;
|
2009-06-29 15:28:22 +02:00
|
|
|
my $base = basename ($ARGV);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
$prod =~ s/\@filename\@/$ARGV/g;
|
2009-06-29 15:28:22 +02:00
|
|
|
$prod =~ s/\@basename\@/$base/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($eprod)) {
|
|
|
|
my $prod = $eprod;
|
|
|
|
|
|
|
|
$prod =~ s/\@enum_name\@/$enumsym/g;
|
|
|
|
$prod =~ s/\@EnumName\@/$enumname/g;
|
|
|
|
$prod =~ s/\@ENUMSHORT\@/$enumshort/g;
|
|
|
|
$prod =~ s/\@ENUMNAME\@/$enumlong/g;
|
2008-06-23 14:06:39 +02:00
|
|
|
$prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; }
|
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($vhead)) {
|
|
|
|
my $prod = $vhead;
|
|
|
|
|
|
|
|
$prod =~ s/\@enum_name\@/$enumsym/g;
|
|
|
|
$prod =~ s/\@EnumName\@/$enumname/g;
|
|
|
|
$prod =~ s/\@ENUMSHORT\@/$enumshort/g;
|
|
|
|
$prod =~ s/\@ENUMNAME\@/$enumlong/g;
|
2008-06-23 14:06:39 +02:00
|
|
|
$prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; }
|
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($vprod)) {
|
|
|
|
my $prod = $vprod;
|
2010-05-06 21:19:58 +02:00
|
|
|
my $next_num = 0;
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
for (@entries) {
|
2010-05-06 21:19:58 +02:00
|
|
|
my ($name,$num,$nick) = @{$_};
|
2004-04-22 23:02:34 +02:00
|
|
|
my $tmp_prod = $prod;
|
2001-04-29 05:04:27 +02:00
|
|
|
|
2010-05-06 21:19:58 +02:00
|
|
|
if ($prod =~ /\@valuenum\@/) {
|
|
|
|
# only attempt to eval the value if it is requested
|
|
|
|
# this prevents us from throwing errors otherwise
|
|
|
|
if (defined $num) {
|
|
|
|
# use sandboxed perl evaluation as a reasonable
|
|
|
|
# approximation to C constant folding
|
|
|
|
$num = $sandbox->reval ($num);
|
|
|
|
|
|
|
|
# make sure it parsed to an integer
|
|
|
|
if (!defined $num or $num !~ /^-?\d+$/) {
|
|
|
|
die "Unable to parse enum value '$num'";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$num = $next_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tmp_prod =~ s/\@valuenum\@/$num/g;
|
|
|
|
$next_num = $num + 1;
|
|
|
|
}
|
|
|
|
|
2001-04-29 05:04:27 +02:00
|
|
|
$tmp_prod =~ s/\@VALUENAME\@/$name/g;
|
|
|
|
$tmp_prod =~ s/\@valuenick\@/$nick/g;
|
|
|
|
if ($flags) { $tmp_prod =~ s/\@type\@/flags/g; } else { $tmp_prod =~ s/\@type\@/enum/g; }
|
|
|
|
if ($flags) { $tmp_prod =~ s/\@Type\@/Flags/g; } else { $tmp_prod =~ s/\@Type\@/Enum/g; }
|
|
|
|
if ($flags) { $tmp_prod =~ s/\@TYPE\@/FLAGS/g; } else { $tmp_prod =~ s/\@TYPE\@/ENUM/g; }
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($tmp_prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$tmp_prod\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($vtail)) {
|
|
|
|
my $prod = $vtail;
|
|
|
|
|
|
|
|
$prod =~ s/\@enum_name\@/$enumsym/g;
|
|
|
|
$prod =~ s/\@EnumName\@/$enumname/g;
|
|
|
|
$prod =~ s/\@ENUMSHORT\@/$enumshort/g;
|
|
|
|
$prod =~ s/\@ENUMNAME\@/$enumlong/g;
|
2008-06-23 14:06:39 +02:00
|
|
|
$prod =~ s/\@ENUMPREFIX\@/$enumname_prefix/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
if ($flags) { $prod =~ s/\@type\@/flags/g; } else { $prod =~ s/\@type\@/enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@Type\@/Flags/g; } else { $prod =~ s/\@Type\@/Enum/g; }
|
|
|
|
if ($flags) { $prod =~ s/\@TYPE\@/FLAGS/g; } else { $prod =~ s/\@TYPE\@/ENUM/g; }
|
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($ftail)) {
|
|
|
|
my $prod = $ftail;
|
2009-06-29 15:28:22 +02:00
|
|
|
my $base = basename ($ARGV);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
$prod =~ s/\@filename\@/$ARGV/g;
|
2009-06-29 15:28:22 +02:00
|
|
|
$prod =~ s/\@basename\@/$base/g;
|
2001-04-29 05:04:27 +02:00
|
|
|
$prod =~ s/\\a/\a/g; $prod =~ s/\\b/\b/g; $prod =~ s/\\t/\t/g; $prod =~ s/\\n/\n/g;
|
2001-04-30 19:59:47 +02:00
|
|
|
$prod =~ s/\\f/\f/g; $prod =~ s/\\r/\r/g;
|
2005-03-22 04:48:05 +01:00
|
|
|
chomp ($prod);
|
2001-04-29 05:04:27 +02:00
|
|
|
|
|
|
|
print "$prod\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# put auto-generation comment
|
|
|
|
{
|
|
|
|
my $comment = $comment_tmpl;
|
|
|
|
$comment =~ s/\@comment\@/Generated data ends here/;
|
|
|
|
print "\n" . $comment . "\n\n";
|
|
|
|
}
|