Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl -s |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 2 | |
| 3 | if(!$ARGV[0]) { |
| 4 | print <<MOO |
Linus Nielsen Feltzing | f84e93e | 2004-06-03 08:23:05 +0000 | [diff] [blame] | 5 | Usage: genlang [-p=<prefix>] <language file> |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 6 | |
| 7 | When running this program. <prefix>.h and <prefix>.c will be created in the |
| 8 | "current directory". <prefix> is "lang" by default. |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 9 | MOO |
| 10 | ; |
| 11 | exit; |
| 12 | } |
| 13 | |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 14 | my $prefix = $p; |
| 15 | if(!$prefix) { |
| 16 | $prefix="lang"; |
| 17 | } |
| 18 | |
| 19 | my $input = $ARGV[0]; |
| 20 | |
| 21 | open(HFILE, ">$prefix.h"); |
| 22 | open(CFILE, ">$prefix.c"); |
| 23 | |
| 24 | print HFILE <<MOO |
Linus Nielsen Feltzing | dfb5c6e | 2004-05-21 23:37:08 +0000 | [diff] [blame] | 25 | /* This file was automatically generated using genlang */ |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 26 | /* |
| 27 | * The str() macro/functions is how to access strings that might be |
Daniel Stenberg | 20963dd | 2002-09-20 06:37:25 +0000 | [diff] [blame] | 28 | * translated. Use it like str(MACRO) and expect a string to be |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 29 | * returned! |
| 30 | */ |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 31 | #define str(x) language_strings[x] |
| 32 | |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 33 | /* this is the array for holding the string pointers. |
| 34 | It will be initialized at runtime. */ |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 35 | extern unsigned char *language_strings[]; |
Daniel Stenberg | e7bd73f | 2005-07-31 21:58:49 +0000 | [diff] [blame] | 36 | /* this contains the concatenation of all strings, separated by \\0 chars */ |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 37 | extern const unsigned char language_builtin[]; |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 38 | |
Daniel Stenberg | 20963dd | 2002-09-20 06:37:25 +0000 | [diff] [blame] | 39 | /* The enum below contains all available strings */ |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 40 | enum { |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 41 | MOO |
| 42 | ; |
| 43 | |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 44 | print CFILE <<MOO |
| 45 | /* This file was automaticly generated using genlang, the strings come |
| 46 | from "$input" */ |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 47 | |
| 48 | #include "$prefix.h" |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 49 | |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 50 | unsigned char *language_strings[LANG_LAST_INDEX_IN_ARRAY]; |
| 51 | const unsigned char language_builtin[] = |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 52 | MOO |
| 53 | ; |
| 54 | |
| 55 | open(LANG, "<$input"); |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 56 | while(<LANG>) { |
Daniel Stenberg | 1017e25 | 2002-10-11 22:01:24 +0000 | [diff] [blame] | 57 | $line++; |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 58 | if($_ =~ / *\#/) { |
| 59 | # comment |
| 60 | next; |
| 61 | } |
Daniel Stenberg | 1b2db9e | 2002-09-20 07:06:15 +0000 | [diff] [blame] | 62 | # get rid of DOS newlines |
| 63 | $_ =~ s/\r//g; |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 64 | if($_ =~ / *([a-z]+): *(.*)/) { |
| 65 | ($var, $value) = ($1, $2); |
Daniel Stenberg | 1017e25 | 2002-10-11 22:01:24 +0000 | [diff] [blame] | 66 | # print "$var => $value\n"; |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 67 | |
| 68 | $set{$var} = $value; |
| 69 | |
Daniel Stenberg | 8f72d9e | 2003-01-31 09:04:34 +0000 | [diff] [blame] | 70 | if( (($var eq "new") && $value && ($value !~ /^\"(.*)\"\W*$/)) || |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 71 | (($var eq "voice") && $value && ($value !~ /^\"(.*)\"\W*$/)) || |
Daniel Stenberg | 8f72d9e | 2003-01-31 09:04:34 +0000 | [diff] [blame] | 72 | (($var eq "eng") && ($value !~ /^\"(.*)\"\W*$/)) ) { |
Daniel Stenberg | 17cf448 | 2002-10-14 08:49:25 +0000 | [diff] [blame] | 73 | print "$input:$line:missing quotes for ".$set{'id'}."\n"; |
| 74 | $errors++; |
Daniel Stenberg | 1017e25 | 2002-10-11 22:01:24 +0000 | [diff] [blame] | 75 | next; |
| 76 | } |
| 77 | |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 78 | if($var eq "new") { |
| 79 | # the last one for a single phrase |
| 80 | |
Daniel Stenberg | 1d7c104 | 2002-10-14 09:11:48 +0000 | [diff] [blame] | 81 | if(!$value || ($value eq "\"\"") ) { |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 82 | # if not set, get the english version |
| 83 | $value = $set{'eng'}; |
| 84 | } |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 85 | # print "VOICE: ".$set{'voice'}." VALUE: $value\n"; |
Linus Nielsen Feltzing | f84e93e | 2004-06-03 08:23:05 +0000 | [diff] [blame] | 86 | # Note: if both entries are "", the string is deprecated, |
| 87 | # but must be included to maintain compatibility |
Jens Arnold | 19afad8 | 2005-01-31 00:34:32 +0000 | [diff] [blame] | 88 | if($set{'id'} =~ /^VOICE_/) { |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 89 | # voice-only |
| 90 | push @vfile, $set{'id'}; |
| 91 | } |
| 92 | else { |
| 93 | push @hfile, $set{'id'}; |
Jens Arnold | abfd29a | 2005-02-01 01:23:58 +0000 | [diff] [blame] | 94 | $value =~ s/^\"(.*)\"\W*$/\"$1\\0\"/; |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 95 | print CFILE " $value\n"; |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 96 | } |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 97 | |
Daniel Stenberg | e19f763 | 2002-09-16 15:01:38 +0000 | [diff] [blame] | 98 | undef %set; |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | } |
| 104 | close(LANG); |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 105 | |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 106 | for(@hfile) { |
| 107 | print HFILE " $_,\n"; |
| 108 | } |
| 109 | |
Jens Arnold | 3c2fefd | 2005-01-19 21:12:38 +0000 | [diff] [blame] | 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, |
| 114 | MOO |
| 115 | ; |
Jörg Hohensohn | f9495cb | 2004-04-03 20:52:24 +0000 | [diff] [blame] | 116 | |
| 117 | for(@vfile) { |
| 118 | print HFILE " $_,\n"; |
| 119 | } |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 120 | |
| 121 | print HFILE <<MOO |
| 122 | }; |
| 123 | /* end of generated enum list */ |
| 124 | MOO |
| 125 | ; |
| 126 | |
| 127 | print CFILE <<MOO |
Jens Arnold | 0f04029 | 2005-01-19 21:43:15 +0000 | [diff] [blame] | 128 | ; |
Daniel Stenberg | 8b06a01 | 2002-09-17 07:17:25 +0000 | [diff] [blame] | 129 | /* end of generated string list */ |
| 130 | MOO |
| 131 | ; |
| 132 | |
| 133 | close(CFILE); |
| 134 | close(HFILE); |
Daniel Stenberg | 17cf448 | 2002-10-14 08:49:25 +0000 | [diff] [blame] | 135 | |
| 136 | exit $errors; |