diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-09-08 14:37:50 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-09-08 14:37:50 +0000 |
commit | 82acdd3e1cad9256e1721cbb3da500453f19724d (patch) | |
tree | b68ce4d0c92fde08389bffdbf2dda6d7c45dac51 /tools | |
parent | 87daeae7c295d14583096f93ddcff0fd959fee6a (diff) | |
download | rockbox-82acdd3e1cad9256e1721cbb3da500453f19724d.tar.gz rockbox-82acdd3e1cad9256e1721cbb3da500453f19724d.zip |
Make genlang faster by doing better regexes.
With this change generating all languages takes only two-thirds the
time. It changes the acceptable syntax for target wildcards in language
files, however: instead of a comma-separated list of glob-style
wildcards it requires that it be a comma-separated list of prefix
matches, i.e. the * can only appear at the end of each wildcard, and ?
cannot be used. This does not require any changes to existing language
files as they are all already in this form.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30481 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/genlang | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/tools/genlang b/tools/genlang index 19b637d237..33adb2c7e3 100755 --- a/tools/genlang +++ b/tools/genlang | |||
@@ -121,7 +121,23 @@ if(!$target && !$update && !$sortfile) { | |||
121 | print STDERR "Please specify a target (with -t)!\n"; | 121 | print STDERR "Please specify a target (with -t)!\n"; |
122 | exit; | 122 | exit; |
123 | } | 123 | } |
124 | my @target_parts = split ':', $target; | 124 | |
125 | # Build up a regex which can be applied to target wildcard lists. We only need | ||
126 | # to support prefix matches, so a target parameter of foo:bar can be expanded | ||
127 | # to the regex "\*|f\*|fo\*|foo|b\*|ba\*|bar" and applied to the wildcard list | ||
128 | # (plus end-of-string or commas on either side). The regex engine should | ||
129 | # discard any duplicates generated for us in the process of constructing the | ||
130 | # state machine, so we don't bother to check. | ||
131 | my $target_regex = "(?:^|,) *(?:\\*"; | ||
132 | foreach my $target_part (split ':', $target) { | ||
133 | for (my $c=1; $c<length $target_part; $c++) { | ||
134 | my $partial = substr $target_part, 0, $c; | ||
135 | $target_regex .= "|$partial\\*"; | ||
136 | } | ||
137 | $target_regex .= "|$target_part"; | ||
138 | } | ||
139 | $target_regex .= ") *(?:,|\$)"; | ||
140 | $target_regex = qr/$target_regex/; | ||
125 | 141 | ||
126 | my $binpath = ""; | 142 | my $binpath = ""; |
127 | if ($binary =~ m|(.*)/[^/]+|) { | 143 | if ($binary =~ m|(.*)/[^/]+|) { |
@@ -178,21 +194,10 @@ sub options { | |||
178 | sub parsetarget { | 194 | sub parsetarget { |
179 | my ($debug, $strref, $full, $n, $v)=@_; | 195 | my ($debug, $strref, $full, $n, $v)=@_; |
180 | my $string; | 196 | my $string; |
181 | my @all= split(" *, *", $n); | 197 | if ($n =~ $target_regex) { |
182 | my $test; | 198 | $string = $v; |
183 | for $test (@all) { | 199 | $$strref = $string; |
184 | $test =~ s/\*/.*/g; | 200 | return $string; |
185 | $test =~ s/\?/./g; | ||
186 | |||
187 | # print "TEST ($debug) $target for $test\n"; | ||
188 | for my $part (@target_parts) { | ||
189 | if($part =~ /^$test\z/) { | ||
190 | $string = $v; | ||
191 | # print "MATCH: $test => $v\n"; | ||
192 | $$strref = $string; | ||
193 | return $string; | ||
194 | } | ||
195 | } | ||
196 | } | 201 | } |
197 | } | 202 | } |
198 | 203 | ||