# find initial file $file = shift(@ARGV); # set output to binary mode binmode(STDOUT); # parse the initial file parse_file($file); exit 0; # read and parse a sprite table file sub parse_file { local($file) = @_; print STDERR "reading $file:\n"; local(@lines) = (); # open the file open(FILE, $file); while () { # read file line chop; push(@lines, $_); } # close the file close(FILE); for (@lines) { if (/^\s*$/ || /^\s*#/) { # blank line or comment } elsif (/^\s*\@include "(.+)"/) { # include file parse_file($1); } elsif (/^\s*\"(.*)\"\s+(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+0x(\w+)/) { # write sprite table line print pack("a32a8SSSSL", $1, $2, $3, $4, $5, $6, hex($7)); } } }