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
|
2004-06-03 08:23:05 +00:00
|
|
|
Usage: genlang [-p=<prefix>] <language file>
|
2002-09-17 07:17:25 +00:00
|
|
|
|
|
|
|
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
|
2004-05-21 23:37:08 +00:00
|
|
|
/* This file was automatically 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]
|
|
|
|
|
2005-01-19 21:43:15 +00:00
|
|
|
/* this is the array for holding the string pointers.
|
|
|
|
It will be initialized at runtime. */
|
2002-09-17 07:17:25 +00:00
|
|
|
extern unsigned char *language_strings[];
|
2005-01-19 21:43:15 +00:00
|
|
|
/* this contains the concatenation of all strings, separated by \0 chars */
|
|
|
|
extern const unsigned char language_builtin[];
|
2002-09-17 07:17:25 +00:00
|
|
|
|
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" */
|
2005-01-19 21:43:15 +00:00
|
|
|
|
|
|
|
#include "$prefix.h"
|
2002-09-17 07:17:25 +00:00
|
|
|
|
2005-01-19 21:43:15 +00:00
|
|
|
unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY];
|
|
|
|
const unsigned char language_builtin[] =
|
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";
|
2004-06-03 08:23:05 +00:00
|
|
|
# Note: if both entries are "", the string is deprecated,
|
|
|
|
# but must be included to maintain compatibility
|
2005-01-31 00:34:32 +00:00
|
|
|
if($set{'id'} =~ /^VOICE_/) {
|
2004-04-03 20:52:24 +00:00
|
|
|
# voice-only
|
|
|
|
push @vfile, $set{'id'};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @hfile, $set{'id'};
|
2005-02-01 01:23:58 +00:00
|
|
|
$value =~ s/^\"(.*)\"\W*$/\"$1\\0\"/;
|
2005-01-19 21:43:15 +00:00
|
|
|
print CFILE " $value\n";
|
2004-04-03 20:52:24 +00:00
|
|
|
}
|
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";
|
|
|
|
}
|
|
|
|
|
2005-01-19 21:12:38 +00:00
|
|
|
print HFILE <<MOO
|
|
|
|
LANG_LAST_INDEX_IN_ARRAY, /* this is not a string, this is a marker */
|
|
|
|
/* --- below this follows voice-only strings --- */
|
|
|
|
VOICEONLY_DELIMITER = 0x8000,
|
|
|
|
MOO
|
|
|
|
;
|
2004-04-03 20:52:24 +00:00
|
|
|
|
|
|
|
for(@vfile) {
|
|
|
|
print HFILE " $_,\n";
|
|
|
|
}
|
2002-09-17 07:17:25 +00:00
|
|
|
|
|
|
|
print HFILE <<MOO
|
|
|
|
};
|
|
|
|
/* end of generated enum list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
print CFILE <<MOO
|
2005-01-19 21:43:15 +00:00
|
|
|
;
|
2002-09-17 07:17:25 +00:00
|
|
|
/* end of generated string list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
close(CFILE);
|
|
|
|
close(HFILE);
|
2002-10-14 08:49:25 +00:00
|
|
|
|
|
|
|
exit $errors;
|