From c0f455993a8a82b2e85b07d6b9fa8c885c029b0f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 22 Sep 2005 11:22:43 +0000 Subject: Initial parser for the langv2 language file format git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7537 a1c6a512-1295-4272-9138-f99709370657 --- tools/genlang2 | 252 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100755 tools/genlang2 (limited to 'tools/genlang2') diff --git a/tools/genlang2 b/tools/genlang2 new file mode 100755 index 0000000000..6db7d39a45 --- /dev/null +++ b/tools/genlang2 @@ -0,0 +1,252 @@ +#!/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 <