diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-20 13:25:33 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-20 13:25:33 +0000 |
commit | ec33ee08988cb5173be3b0ed102eddaae068a769 (patch) | |
tree | af92282e581311ee99809e332d86614d3140a86c /crawl-ref/source/misc/featname.pl | |
parent | e4ced2ef037b4a4d659d8afec85804267322dc0f (diff) | |
download | crawl-ref-ec33ee08988cb5173be3b0ed102eddaae068a769.tar.gz crawl-ref-ec33ee08988cb5173be3b0ed102eddaae068a769.zip |
Script to verify luadgn.cc and enum.h are in sync for dungeon features.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3105 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/misc/featname.pl')
-rw-r--r-- | crawl-ref/source/misc/featname.pl | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/crawl-ref/source/misc/featname.pl b/crawl-ref/source/misc/featname.pl new file mode 100644 index 0000000000..7b08c5806e --- /dev/null +++ b/crawl-ref/source/misc/featname.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# +# featname.pl +# +# Checks that the DNGN feature names in luadgn.cc match up with the enum +# constants in enum.h. +# + +use strict; +use warnings; + +my $FEATFILE = "enum.h"; +my $FNAMEFILE = "luadgn.cc"; +my ($features, $fnummap) = read_features($FEATFILE); +my @fnames = read_feature_names($FNAMEFILE); + +verify_names($features, $fnummap, \@fnames); + +sub read_feature_names { + my $file = shift; + my $text = do { local(@ARGV, $/) = $file; <> }; + my ($array) = $text =~ + /dngn_feature_names.*?=.*?{([^}]+)}/xs; + my @names = $array =~ /"([^"]*)"/gs; + return @names; +} + +sub verify_names { + my ($farr, $fmap, $fnames) = @_; + for (my $i = 0; $i < @$fnames; ++$i) { + my $name = $$fnames[$i]; + next unless $name; + my $feat = "DNGN_\U$name"; + $$fmap{$feat} = -1 unless exists $$fmap{$feat}; + if ($$fmap{$feat} != $i) { + die "$name is at $i, was expecting $$fmap{$feat} as in enum.\n"; + } + } + print "Feature names in $FNAMEFILE and $FEATFILE match ok.\n"; +} + +sub read_features { + my $file = shift; + my @lines = do { local (@ARGV) = $file; <> }; + + my @features = ([]) x 500; + my $in_enum; + my %fnummap; + my $currval = 0; + for my $line (@lines) { + if (!$in_enum) { + $in_enum = 1 if $line =~ /enum\s+dungeon_feature_type/; + } + else { + last if $line =~ /^\s*};/; + + s/^\s+//, s{//.*}{}, s/\s+$// for $line; + next unless $line =~ /\S/; + + my ($key, $val) = $line =~ /(DNGN\w+)(?:\s*=\s*(\w+))?/; + next unless $key; + + if (defined $val) { + if ($val =~ /^DNGN/) { + $val = $fnummap{$val}; + } + } + else { + $val = $currval; + } + $currval = $val + 1; + + $fnummap{$key} = $val; + push @{$features[$val]}, $key; + } + } + return (\@features, \%fnummap); +} |