8b06a013e0
put in an array git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2310 a1c6a512-1295-4272-9138-f99709370657
93 lines
1.6 KiB
Perl
Executable file
93 lines
1.6 KiB
Perl
Executable file
#!/usr/bin/perl -s
|
|
|
|
if(!$ARGV[0]) {
|
|
print <<MOO
|
|
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.
|
|
MOO
|
|
;
|
|
exit;
|
|
}
|
|
|
|
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 */
|
|
/*
|
|
* The str() macro/functions is how to access strings that might be
|
|
* translated. Use it like str(MACRO) and except a string to be
|
|
* returned!
|
|
*/
|
|
#define str(x) language_strings[x]
|
|
|
|
/* this is the array with all the strings */
|
|
extern unsigned char *language_strings[];
|
|
|
|
enum {
|
|
MOO
|
|
;
|
|
|
|
print CFILE <<MOO
|
|
/* This file was automaticly generated using genlang, the strings come
|
|
from "$input" */
|
|
|
|
unsigned char *language_strings[]={
|
|
MOO
|
|
;
|
|
|
|
open(LANG, "<$input");
|
|
while(<LANG>) {
|
|
if($_ =~ / *\#/) {
|
|
# comment
|
|
next;
|
|
}
|
|
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'};
|
|
}
|
|
|
|
print HFILE " ".$set{'id'}.",\n";
|
|
print CFILE " $value,\n";
|
|
|
|
undef %set;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
close(LANG);
|
|
|
|
|
|
print HFILE <<MOO
|
|
};
|
|
/* end of generated enum list */
|
|
MOO
|
|
;
|
|
|
|
print CFILE <<MOO
|
|
};
|
|
/* end of generated string list */
|
|
MOO
|
|
;
|
|
|
|
close(CFILE);
|
|
close(HFILE);
|