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>) {
|
|
|
|
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);
|
|
|
|
# print "$var => $value\n";
|
|
|
|
|
|
|
|
$set{$var} = $value;
|
|
|
|
|
|
|
|
if($var eq "new") {
|
|
|
|
# the last one for a single phrase
|
|
|
|
|
|
|
|
if(!$value) {
|
|
|
|
# if not set, get the english version
|
|
|
|
$value = $set{'eng'};
|
|
|
|
}
|
|
|
|
|
2002-09-17 07:17:25 +00:00
|
|
|
print HFILE " ".$set{'id'}.",\n";
|
|
|
|
print CFILE " $value,\n";
|
|
|
|
|
2002-09-16 15:01:38 +00:00
|
|
|
undef %set;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
close(LANG);
|
2002-09-17 07:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
print HFILE <<MOO
|
|
|
|
};
|
|
|
|
/* end of generated enum list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
print CFILE <<MOO
|
|
|
|
};
|
|
|
|
/* end of generated string list */
|
|
|
|
MOO
|
|
|
|
;
|
|
|
|
|
|
|
|
close(CFILE);
|
|
|
|
close(HFILE);
|