SBSPSS/tools/Perl/pl/text_extract.pl
2001-01-09 18:00:05 +00:00

81 lines
1.6 KiB
Perl

#=========================================================================
#
# text_extract.pl
#
# Author: pkg@Climax
# Created:
# Project: SBSP
# Purpose: Extracts text ids from the translation header file and exports
# them to an in clude file. This is grabbing the ingame texts and
# putting them somewhere that the script compiler can use
# Usage: text_extract infile outfile tagprefix
# eg: text_extract trans.h scripts\defs\trans.h STR__INGAME__
#
# Copyright (c) 2001 Climax Development Ltd
#
#===========================================================================
local ($inFile,$outFile,$tagPrefix)=@ARGV;
#print "inFile: $inFile\n";
#print "outFile: $outFile\n";
#print "tagPrefix: $tagPrefix\n";
# Open files
open INFILE, $inFile || die "Can't open input file '$inFile': $!\n";
open OUTFILE, ">$outFile" || die "Can't open output file '$outFile': $!\n";
# Output header
print OUTFILE <<EOT
// TextIds for ingame text - Auto-generated by text_extract.pl
//
// Source file: $inFile
// Tag prefix: $tagPrefix
EOT
;
# Find the start of the enum list
$done=0;
while(!$done)
{
$line=<INFILE> || die "End of file found while looking while looking for start of enum list!\n";
if($line =~ /^\{/)
{
$done=1;
}
}
# Grab the ids
$done=0;
$textId=0;
while(!$done)
{
$line=<INFILE> || die "End of file found before end of enum list!\n";
chomp($line);
if($line=~/^\}/)
{
$done=1;
}
elsif($line=~/^\s*$/)
{
}
else
{
$line=~s/^\s*([\w]*).*/$1/;
if($line=~/^$tagPrefix/)
{
print OUTFILE "#define ",$line,"\t\t$textId\n";
}
$textId++;
}
}
# Done! :)
close INFILE;
close OUTFILE;