First start for "Manage Settings" and "Browse Themes" (FS#4997 by Mark Bright)
[Rockbox.git] / tools / genlang
blobcde23f85fa744b07447b006a54a04c58f97eeab6
1 #!/usr/bin/perl -s
3 if(!$ARGV[0]) {
4 print <<MOO
5 Usage: genlang [-p=<prefix>] <language file>
7 When running this program. <prefix>.h and <prefix>.c will be created in the
8 "current directory". <prefix> is "lang" by default.
9 MOO
11 exit;
14 my $prefix = $p;
15 if(!$prefix) {
16 $prefix="lang";
19 my $input = $ARGV[0];
21 open(HFILE, ">$prefix.h");
22 open(CFILE, ">$prefix.c");
24 print HFILE <<MOO
25 /* This file was automatically generated using genlang */
27 * The str() macro/functions is how to access strings that might be
28 * translated. Use it like str(MACRO) and expect a string to be
29 * returned!
31 #define str(x) language_strings[x]
33 /* this is the array for holding the string pointers.
34 It will be initialized at runtime. */
35 extern unsigned char *language_strings[];
36 /* this contains the concatenation of all strings, separated by \\0 chars */
37 extern const unsigned char language_builtin[];
39 /* The enum below contains all available strings */
40 enum {
41 MOO
44 print CFILE <<MOO
45 /* This file was automaticly generated using genlang, the strings come
46 from "$input" */
48 #include "$prefix.h"
50 unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY];
51 const unsigned char language_builtin[] =
52 MOO
55 open(LANG, "<$input");
56 while(<LANG>) {
57 $line++;
58 if($_ =~ / *\#/) {
59 # comment
60 next;
62 # get rid of DOS newlines
63 $_ =~ s/\r//g;
64 if($_ =~ / *([a-z]+): *(.*)/) {
65 ($var, $value) = ($1, $2);
66 # print "$var => $value\n";
68 $set{$var} = $value;
70 if( (($var eq "new") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
71 (($var eq "voice") && $value && ($value !~ /^\"(.*)\"\W*$/)) ||
72 (($var eq "eng") && ($value !~ /^\"(.*)\"\W*$/)) ) {
73 print "$input:$line:missing quotes for ".$set{'id'}."\n";
74 $errors++;
75 next;
78 if($var eq "new") {
79 # the last one for a single phrase
81 if(!$value || ($value eq "\"\"") ) {
82 # if not set, get the english version
83 $value = $set{'eng'};
85 # print "VOICE: ".$set{'voice'}." VALUE: $value\n";
86 # Note: if both entries are "", the string is deprecated,
87 # but must be included to maintain compatibility
88 if($set{'id'} =~ /^VOICE_/) {
89 # voice-only
90 push @vfile, $set{'id'};
92 else {
93 push @hfile, $set{'id'};
94 $value =~ s/^\"(.*)\"\W*$/\"$1\\0\"/;
95 print CFILE " $value\n";
98 undef %set;
104 close(LANG);
106 for(@hfile) {
107 print HFILE " $_,\n";
110 print HFILE <<MOO
111 LANG_LAST_INDEX_IN_ARRAY, /* this is not a string, this is a marker */
112 /* --- below this follows voice-only strings --- */
113 VOICEONLY_DELIMITER = 0x8000,
117 for(@vfile) {
118 print HFILE " $_,\n";
121 print HFILE <<MOO
123 /* end of generated enum list */
127 print CFILE <<MOO
129 /* end of generated string list */
133 close(CFILE);
134 close(HFILE);
136 exit $errors;