Clean up a little

git-svn-id: https://glew.svn.sourceforge.net/svnroot/glew/trunk/glew@371 783a27ee-832a-0410-bc00-9f386506c6dd
This commit is contained in:
mem 2005-01-11 23:03:01 +00:00
parent 463439fd12
commit 6128bd95e1

View File

@ -67,12 +67,13 @@ my $voidtype_re = __compile_wordlist_cap(keys %void_typemap);
sub new($) sub new($)
{ {
my $class = shift; my $class = shift;
my $self = {}; my $self = { section => {} };
$self->{filename} = shift; $self->{filename} = shift;
local $/; local $/;
open(my $fh, "<$self->{filename}") or die "Can't open $self->{filename}"; open(my $fh, "<$self->{filename}") or die "Can't open $self->{filename}";
my $content = <$fh>; my $content = <$fh>;
my $section; my $section;
my $s = $self->{section};
$content =~ s{[ \t]+$}{}mg; $content =~ s{[ \t]+$}{}mg;
# Join lines that end with a word-character and ones that *begin* # Join lines that end with a word-character and ones that *begin*
@ -86,17 +87,16 @@ sub new($)
chomp; chomp;
s/^Name String$/Name Strings/; # Fix common mistake s/^Name String$/Name Strings/; # Fix common mistake
$section = $_; $section = $_;
$self->{$section} = ""; $s->{$section} = "";
} }
elsif (defined $section and exists $self->{$section}) elsif (defined $section and exists $s->{$section})
{ {
s{^\s+}{}mg; # Remove leading whitespace s{^\s+}{}mg; # Remove leading whitespace
$self->{$section} .= $_; $s->{$section} .= $_ . "\n";
$self->{$section} .= "\n";
} }
} }
$self->{$_} =~ s{(?:^\n+|\n+$)}{}s foreach keys %{$self}; $s->{$_} =~ s{(?:^\n+|\n+$)}{}s foreach keys %$s;
bless $self, $class; bless $self, $class;
} }
@ -104,26 +104,26 @@ sub new($)
sub sections() sub sections()
{ {
my $self = shift; my $self = shift;
grep { $_ ne "filename" } keys %{$self}; keys %{$self->{section}};
} }
sub name() sub name()
{ {
my $self = shift; my $self = shift;
$self->{Name}; $self->{section}->{Name};
} }
sub name_strings() sub name_strings()
{ {
my $self = shift; my $self = shift;
split("\n", $self->{"Name Strings"}); split("\n", $self->{section}->{"Name Strings"});
} }
sub tokens() sub tokens()
{ {
my $self = shift; my $self = shift;
my %tokens = (); my %tokens = ();
foreach (split /\n/, $self->{"New Tokens"}) foreach (split /\n/, $self->{section}->{"New Tokens"})
{ {
next unless /$token_re/; next unless /$token_re/;
my ($name, $value) = ($1, $2); my ($name, $value) = ($1, $2);
@ -140,12 +140,12 @@ sub functions()
my %functions = (); my %functions = ();
my @fnc = (); my @fnc = ();
foreach (split /\n/, $self->{"New Procedures and Functions"}) foreach (split /\n/, $self->{section}->{"New Procedures and Functions"})
{ {
push @fnc, $_ unless ($_ eq "" or $_ eq "None"); push @fnc, $_ unless ($_ eq "" or $_ eq "None");
if (/$eofnc_re/) next unless /$eofnc_re/;
{
if (__normalize_proto(@fnc) =~ /$function_re/) if (__normalize_proto(@fnc) =~ /$function_re/)
{ {
my ($return, $name, $parms) = ($1, $2, $3); my ($return, $name, $parms) = ($1, $2, $3);
@ -167,7 +167,6 @@ sub functions()
} }
@fnc = (); @fnc = ();
} }
}
return %functions; return %functions;
} }