The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
ENT file checker
Posted by: Faxmachinen | July 27, 2009 @ 5:39pm
Perl Code
[
Download
]
#!/usr/bin/perl # check_ents.pl # For finding entities in ENT files who have more than 64 key/value pairs # By Faxmachinen use strict; use constant MAX_PROPS => 64; local $/; # Slurp entire files unless (@ARGV) { $0 =~ m/([^\\\/]+)$/; print "Usage: $1 <level1.ent> [level2.ent] [...]\n"; exit 0; } foreach my $file (@ARGV) { my $num_ents = 0; my @bad_ents = (); unless (open FILE, $file) { print "Could not open \"$file\".\n"; next; } print "Scanning file \"$file\"... "; my $file_content = <FILE>; foreach ($file_content =~ m/\{([^\}]*)\}/sg) { $num_ents++; # We use an array to count number of key/value pairs, since outputs often have duplicate key names. my @props = m/"([^"]*)"/sg; my $num_props = scalar @props / 2; if ($num_props > &MAX_PROPS) { # Then we use a map to get information about bad entities. my %props = @props; my $name = 'UNKNOWN'; my $hid = -1; if (exists $props{'targetname'}) { $name = $props{'targetname'}; } if (exists $props{'classname'}) { $name = $props{'classname'}; } if (exists $props{'origin'}) { $name .= " @ <$props{'origin'}>"; } if (exists $props{'hammerid'}) { $hid = $props{'hammerid'}; } push @bad_ents, [$name, $num_props, $hid]; } } print "$num_ents entities scanned: "; if (@bad_ents) { print "\n"; print "\t$_->[0] (hammerid $_->[2]) has $_->[1] key/value pairs, max is " . &MAX_PROPS . ".\n" foreach (@bad_ents); } else { print "No bad entities.\n" } }
Syntax Highlighting
[
Open in new window
]
Author Comments
Only checks whether entities have more than 64 key/value pairs for now.
Rating
4.17 / 8
137 Votes
http://codebin.yi.org/337
page generated in 0.00 seconds