#!/usr/bin/perl -s if(!$ARGV[0]) { print <][-t=][-v] .h and .c will be created in the current directory. is "lang" by default. Use -v for verbose (debug) output. MOO ; exit; } my $prefix = $p; if(!$prefix) { $prefix="lang"; } my $target = $t; if(!$target) { print "Please specify a target!\n"; exit; } my $verbose=$v; my %id; # string to num hash my @idnum; # num to string array my %source; # id string to source phrase hash my %dest; # id string to dest phrase hash my %voice; # id string to voice phrase hash my $input = $ARGV[0]; open(HFILE, ">$prefix.h"); open(CFILE, ">$prefix.c"); print HFILE < $v\n"; } } if($string) { $$strref = $string; } return $string; } my $src; sub source { parsetarget("src", \$src, @_); } my $dest; sub dest { parsetarget("dest", \$dest, @_); } my $voice; sub voice { parsetarget("voice", \$voice, @_); } my $idcount; # counter for ID numbers open(LANG, "<$input"); while() { $line++; if($_ =~ / *\#/) { # comment next; } # get rid of DOS newlines $_ =~ s/\r//g; # print "M: $m\n"; if(/ *<([^>]*)>/) { my $part = $1; #print "P: $part\n"; if($part =~ /^\//) { if($part eq "/phrase") { my $idstr = $phrase{'id'}; $id{$idstr} = $idcount; $idnum[$idcount]=$idstr; $source{$idstr}=$src; $dest{$idstr}=$dest; $voice{$idstr}=$voice; if($verbose) { print "id: $phrase{id}\n"; print "source: $src\n"; print "dest: $dest\n"; print "voice: $voice\n"; } $idcount++; undef $src; undef $dest; undef $voice; undef %phrase; } # starts with a slash, this _ends_ this section $m = pop @m; # get back old value next; } push @m, $m; # store old value $m = $1; next; } if(/^ *([^:]+): *(.*)/) { my ($name, $val)=($1, $2); &$m($_, $name, $val); } } close(LANG); # Output the ID names for the enum in the header file my $i; for $i (1 .. $idcount) { my $name=$idnum[$i - 1]; # get the ID name $name =~ s/\"//g; # cut off the quotes printf HFILE (" %s,\n", $name); } # Output separation marker for last string ID and the upcoming voice IDs print HFILE <