2002-09-17 07:17:25 +00:00
|
|
|
#!/usr/bin/perl -s
|
2002-09-16 15:01:38 +00:00
|
|
|
|
|
|
|
if(!$ARGV[0]) {
|
|
|
|
print <<MOO
|
2002-09-17 07:17:25 +00:00
|
|
|
Usage: lang.pl [-p=<prefix>] <language file>
|
|
|
|
|
|
|
|
When running this program. <prefix>.h and <prefix>.c will be created in the
|
|
|
|
"current directory". <prefix> is "lang" by default.
|
2002-09-16 15:01:38 +00:00
|
|
|
MOO
|
|
|
|
;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2002-09-17 07:17:25 +00:00
|
|
|
my $prefix = $p;
|
|
|
|
if(!$prefix) {
|
|
|
|
$prefix="lang";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $input = $ARGV[0];
|
|
|
|
|
|
|
|
open(HFILE, ">$prefix.h");
|
|
|
|
open(CFILE, ">$prefix.c");
|
|
|
|
|
|
|
|
print HFILE <<MOO
|
|
|
|
/* This file was automaticly generated using genlang */
|
2002-09-16 15:01:38 +00:00
|
|
|
/*
|
|
|
|
* The str() macro/functions is how to access strings that might be
|
2002-09-20 06:37:25 +00:00
|
|
|
* translated. Use it like str(MACRO) and expect a string to be
|
2002-09-16 15:01:38 +00:00
|
|
|
* returned!
|
|
|
|
*/
|
2002-09-17 07:17:25 +00:00
|
|
|
#define str(x) language_strings[x]
|
|
|
|
|
|
|
|
/* this is the array with all the strings */
|
|
|
|
extern unsigned char *language_strings[];
|
|
|
|
|
2002-09-20 06:37:25 +00:00
|
|
|
/* The enum below contains all available strings */
|
2002-09-17 07:17:25 +00:00
|
|
|
enum {
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
print CFILE <<MOO
|
|
|
|
/* This file was automaticly generated using genlang, the strings come
|
|
|
|
from "$input" */
|
|
|
|
|
|
|
|
unsigned char *language_strings[]={
|
2002-09-16 15:01:38 +00:00
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
2002-09-17 07:17:25 +00:00
|
|
|
open(LANG, "<$input");
|
2002-09-16 15:01:38 +00:00
|
|
|
while(<LANG>) {
|
2002-10-11 22:01:24 +00:00
|
|
|
$line++;
|
2002-09-16 15:01:38 +00:00
|
|
|
if($_ =~ / *\#/) {
|
|
|
|
# comment
|
|
|
|
next;
|
|
|
|
}
|
2002-09-20 07:06:15 +00:00
|
|
|
# get rid of DOS newlines
|
|
|
|
$_ =~ s/\r//g;
|
2002-09-16 15:01:38 +00:00
|
|
|
if($_ =~ / *([a-z]+): *(.*)/) {
|
|
|
|
($var, $value) = ($1, $2);
|
2002-10-11 22:01:24 +00:00
|
|
|
# print "$var => $value\n";
|
2002-09-16 15:01:38 +00:00
|
|
|
|
|
|
|
$set{$var} = $value;
|
|
|
|
|
2003-01-31 09:04:34 +00:00
|
|
|
if( (($var eq "new") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
|
2004-04-03 20:52:24 +00:00
|
|
|
(($var eq "voice") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
|
2003-01-31 09:04:34 +00:00
|
|
|
(($var eq "eng") && ($value !~ /^\"(.*)\"\W*$/)) ) {
|
2002-10-14 08:49:25 +00:00
|
|
|
print "$input:$line:missing quotes for ".$set{'id'}."\n";
|
|
|
|
$errors++;
|
2002-10-11 22:01:24 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2002-09-16 15:01:38 +00:00
|
|
|
if($var eq "new") {
|
|
|
|
# the last one for a single phrase
|
|
|
|
|
2002-10-14 09:11:48 +00:00
|
|
|
if(!$value || ($value eq "\"\"") ) {
|
2002-09-16 15:01:38 +00:00
|
|
|
# if not set, get the english version
|
|
|
|
$value = $set{'eng'};
|
|
|
|
}
|
2004-04-03 20:52:24 +00:00
|
|
|
# print "VOICE: ".$set{'voice'}." VALUE: $value\n";
|
|
|
|
if(($value eq "\"\"") && $set{'voice'}) {
|
|
|
|
# voice-only
|
|
|
|
push @vfile, $set{'id'};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @hfile, $set{'id'};
|
|
|
|
print CFILE " $value,\n";
|
|
|
|
}
|
2002-09-17 07:17:25 +00:00
|
|
|
|
2002-09-16 15:01:38 +00:00
|
|
|
undef %set;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
close(LANG);
|
2002-09-17 07:17:25 +00:00
|
|
|
|
2004-04-03 20:52:24 +00:00
|
|
|
for(@hfile) {
|
|
|
|
print HFILE " $_,\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print HFILE " /* --- below this follows voice-only strings --- */\n",
|
|
|
|
" VOICEONLY_DELIMITER = 0x8000,\n";
|
|
|
|
|
|
|
|
for(@vfile) {
|
|
|
|
print HFILE " $_,\n";
|
|
|
|
}
|
2002-09-17 07:17:25 +00:00
|
|
|
|
|
|
|
print HFILE <<MOO
|
2002-10-14 12:19:47 +00:00
|
|
|
LANG_LAST_INDEX_IN_ARRAY /* this is not a string, this is a marker */
|
2002-09-17 07:17:25 +00:00
|
|
|
};
|
|
|
|
/* end of generated enum list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
print CFILE <<MOO
|
|
|
|
};
|
|
|
|
/* end of generated string list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
close(CFILE);
|
|
|
|
close(HFILE);
|
2002-10-14 08:49:25 +00:00
|
|
|
|
|
|
|
exit $errors;
|