diff options
author | Nils Wallménius <nils@rockbox.org> | 2010-06-04 20:40:49 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2010-06-04 20:40:49 +0000 |
commit | b91fa0425090536a254e25807e75ff624c07d503 (patch) | |
tree | ad012fc24cb1160cf610ff6357f224a9ff696af2 /tools | |
parent | 3704f1f71acc097eb181361631de19b127d61b63 (diff) | |
download | rockbox-b91fa0425090536a254e25807e75ff624c07d503.tar.gz rockbox-b91fa0425090536a254e25807e75ff624c07d503.zip |
Implement a --delete option for langtoo for easy deletion of lang phrases
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26556 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/langtool.pl | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/tools/langtool.pl b/tools/langtool.pl index 2e959317c1..a0e147c4ad 100755 --- a/tools/langtool.pl +++ b/tools/langtool.pl | |||
@@ -53,6 +53,12 @@ Usage langtool [--inplace] --options langfile1 [langfile2 ...] | |||
53 | Example: | 53 | Example: |
54 | langtool --changetarget --from e200 --to e200,c200 --id LANG_ON dansk.lang | 54 | langtool --changetarget --from e200 --to e200,c200 --id LANG_ON dansk.lang |
55 | 55 | ||
56 | --delete --id ID_1,ID_2 --id ID_3 langfile | ||
57 | |||
58 | Delete a number of ids. THIS WILL BREAK BACKWARDS COMPATIBILITY. Use with | ||
59 | extreme caution. | ||
60 | Example: langtool --delete --id LANG_LEFT,LANG_RIGHT english.lang | ||
61 | |||
56 | --inplace | 62 | --inplace |
57 | 63 | ||
58 | Perform file operations in-place, instead of outputting the result to | 64 | Perform file operations in-place, instead of outputting the result to |
@@ -77,6 +83,7 @@ my $changesource = ''; | |||
77 | my $changeid = ''; | 83 | my $changeid = ''; |
78 | my $changetarget = ''; | 84 | my $changetarget = ''; |
79 | my $changedesc = ''; | 85 | my $changedesc = ''; |
86 | my $delete = ''; | ||
80 | my $inplace = ''; | 87 | my $inplace = ''; |
81 | my $help = ''; | 88 | my $help = ''; |
82 | # Parameters | 89 | # Parameters |
@@ -91,6 +98,7 @@ GetOptions( | |||
91 | 'changeid' => \$changeid, | 98 | 'changeid' => \$changeid, |
92 | 'changetarget' => \$changetarget, | 99 | 'changetarget' => \$changetarget, |
93 | 'changedesc' => \$changedesc, | 100 | 'changedesc' => \$changedesc, |
101 | 'delete' => \$delete, | ||
94 | 'help' => \$help, | 102 | 'help' => \$help, |
95 | 'inplace' => \$inplace, | 103 | 'inplace' => \$inplace, |
96 | 104 | ||
@@ -110,8 +118,8 @@ if ($help) { | |||
110 | exit(); | 118 | exit(); |
111 | } | 119 | } |
112 | # More than one option set (or none) | 120 | # More than one option set (or none) |
113 | elsif (($deprecate + $changesource + $changeid + $changetarget + $changedesc) != 1) { | 121 | elsif (($deprecate + $changesource + $changeid + $changetarget + $changedesc +$delete) != 1) { |
114 | error("Exactly one of --deprecate, --changesource, --changeid, --changetarget,\n--changedesc must be used."); | 122 | error("Exactly one of --deprecate, --changesource, --changeid, --changetarget,\n--changedesc, --delete must be used."); |
115 | } | 123 | } |
116 | # Do changeid, but either from or to is empty | 124 | # Do changeid, but either from or to is empty |
117 | elsif ($changeid and ($from eq "" or $to eq "")) { | 125 | elsif ($changeid and ($from eq "" or $to eq "")) { |
@@ -129,6 +137,10 @@ elsif ($changetarget and ($from eq "" or $to eq "")) { | |||
129 | elsif ($deprecate and $numids < 1) { | 137 | elsif ($deprecate and $numids < 1) { |
130 | error("--deprecate used, but no IDs specified"); | 138 | error("--deprecate used, but no IDs specified"); |
131 | } | 139 | } |
140 | # Do delete, but no ids set | ||
141 | elsif ($delete and $numids < 1) { | ||
142 | error("--delete used, but no IDs specified"); | ||
143 | } | ||
132 | # Do changesource, but either target or to not set | 144 | # Do changesource, but either target or to not set |
133 | elsif ($changesource and ($s_target eq "" or $to eq "")) { | 145 | elsif ($changesource and ($s_target eq "" or $to eq "")) { |
134 | error("--changesource used, but --target or --to not set"); | 146 | error("--changesource used, but --target or --to not set"); |
@@ -159,7 +171,7 @@ foreach my $file (@ARGV) { | |||
159 | my $target = ""; | 171 | my $target = ""; |
160 | my $string = ""; | 172 | my $string = ""; |
161 | my $open = 0; | 173 | my $open = 0; |
162 | my $output = ""; | 174 | my @output; |
163 | 175 | ||
164 | for (<LANGFILE>) { | 176 | for (<LANGFILE>) { |
165 | my $line = $_; | 177 | my $line = $_; |
@@ -209,6 +221,16 @@ foreach my $file (@ARGV) { | |||
209 | } | 221 | } |
210 | } | 222 | } |
211 | } | 223 | } |
224 | elsif ($delete) { | ||
225 | if ($id ne "" and grep(/^$id$/, @ids)) { | ||
226 | if ($location eq "phrase" and $line =~ /id:/) { | ||
227 | # Kluge to nuke the <phrase> line | ||
228 | pop(@output); | ||
229 | } | ||
230 | # Set the whole phrase to empty string. | ||
231 | $line = ""; | ||
232 | } | ||
233 | } | ||
212 | elsif ($changetarget) { | 234 | elsif ($changetarget) { |
213 | # Change target if set and it's the same as $from | 235 | # Change target if set and it's the same as $from |
214 | if ($id ne "" and grep(/^$id$/, @ids) and $location =~ /source|dest|voice/ and $target eq $from) { | 236 | if ($id ne "" and grep(/^$id$/, @ids) and $location =~ /source|dest|voice/ and $target eq $from) { |
@@ -234,17 +256,16 @@ foreach my $file (@ARGV) { | |||
234 | print("This should never happen.\n"); | 256 | print("This should never happen.\n"); |
235 | exit(3); | 257 | exit(3); |
236 | } | 258 | } |
237 | if ($inplace) { | 259 | |
238 | $output .= $line; | 260 | push(@output, $line); |
239 | } | ||
240 | else { | ||
241 | print($line); | ||
242 | } | ||
243 | } | 261 | } |
244 | close(LANGFILE); | 262 | close(LANGFILE); |
245 | if ($inplace) { | 263 | if ($inplace) { |
246 | open(LANGFILE, ">", $file) or die(sprintf("Couldn't open file for writing: %s\n", $file)); | 264 | open(LANGFILE, ">", $file) or die(sprintf("Couldn't open file for writing: %s\n", $file)); |
247 | print(LANGFILE $output); | 265 | print(LANGFILE @output); |
248 | close(LANGFILE); | 266 | close(LANGFILE); |
249 | } | 267 | } |
268 | else { | ||
269 | print(@output); | ||
270 | } | ||
250 | } | 271 | } |