From eb8612047832e32122ea4b06954cace14cb345db Mon Sep 17 00:00:00 2001 From: Daniel Elstner Date: Tue, 28 Nov 2006 22:20:28 +0000 Subject: Ignore whitespace in front of an enum typedef. This fixes parsing of * tools/enum.pl (parse): Ignore whitespace in front of an enum typedef. This fixes parsing of HildonTelephoneEditorFormat in hildon-libs. * tools/pm/Enum.pm (parse_values): Check whether the enumeration constants actually have a common module prefix before attempting to remove it. This fixes the incorrect parsing of inconsistently named enums in hildon-libs. --- ChangeLog | 10 ++++++++++ tools/enum.pl | 2 +- tools/pm/Enum.pm | 30 ++++++++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a443c9be..12606a81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-11-27 Daniel Elstner + + * tools/enum.pl (parse): Ignore whitespace in front of an enum + typedef. This fixes parsing of HildonTelephoneEditorFormat in + hildon-libs. + * tools/pm/Enum.pm (parse_values): Check whether the enumeration + constants actually have a common module prefix before attempting + to remove it. This fixes the incorrect parsing of inconsistently + named enums in hildon-libs. + 2006-11-27 Daniel Elstner * tools/enum.pl (form_names): Break the loop if the length of the diff --git a/tools/enum.pl b/tools/enum.pl index dd35dc3c..8cc6ff90 100644 --- a/tools/enum.pl +++ b/tools/enum.pl @@ -69,7 +69,7 @@ sub parse s/','/\%\%COMMA\%\%/; s/'}'/\%\%RBRACE\%\%/; - if (/^typedef enum/ ) + if (/^\s*typedef enum/ ) { print ";; From $file\n\n" if (!$from); $from=1; diff --git a/tools/pm/Enum.pm b/tools/pm/Enum.pm index e928bead..47485e15 100644 --- a/tools/pm/Enum.pm +++ b/tools/pm/Enum.pm @@ -79,6 +79,10 @@ sub parse_values($$) { my ($self, $value) = @_; + my $elem_names = []; + my $elem_values = []; + my $common_prefix = undef; + # break up the value statements foreach(split(/\s*'*[()]\s*/, $value)) { @@ -88,17 +92,35 @@ sub parse_values($$) { my ($name, $value) = ($1, $2); - # cut off the module prefix, e.g. GTK_ - $name =~ s/^[^_]+_//; + # detect whether there is module prefix common to all names, e.g. GTK_ + my $prefix = $1 if ($name =~ /^([^_]+_)/); + + if (not defined($common_prefix)) + { + $common_prefix = $prefix; + } + elsif ($prefix ne $common_prefix) + { + $common_prefix = ""; + } - push(@{$$self{elem_names}}, $name); - push(@{$$self{elem_values}}, $value); + push(@$elem_names, $name); + push(@$elem_values, $value); } else { GtkDefs::error("Unknown value statement ($_) in $$self{c_type}\n"); } } + + if ($common_prefix) + { + # cut off the module prefix, e.g. GTK_ + s/^$common_prefix// foreach (@$elem_names); + } + + $$self{elem_names} = $elem_names; + $$self{elem_values} = $elem_values; } sub beautify_values($) -- cgit v1.2.1