1 : # -*- perl -*- vim: ft=perl
2 eval 'exec perl -w -S $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
31 # See Usage() below or invoke without arguments for short instructions.
32 # For long instructions use the source, Luke ;-)
40 "langid - a hackish utility to lookup lang.h language defines and LangIDs,\n",
41 "isolang.cxx ISO639/ISO3166 mapping, locale data files, langtab.src language\n",
42 "listbox entries, langlist.mk, file_ooo.scp registry name, globals.pm and\n",
43 "msi-encodinglist.txt\n\n",
45 "Usage: $0 [--single] {language string} | {LangID} | {primarylanguage sublanguage} | {language-country}\n\n",
47 "A language string will be used as a generic string match in all searched files.\n",
48 "You may enclose the language string in word delimiters,\n",
49 "e.g. \\blanguage_german\\b for a specific match.\n",
50 "If the language string expression matches more than one define,\n",
51 "e.g. as in 'german', all matching defines will be processed.\n",
52 "If the language string does not match a define or an identifier in\n",
53 "langtab.src, a generic string match of the listbox entries will be tried.\n\n",
55 "Numeric values of LangID,primarylanguage,sublanguage can be given\n",
56 "decimal, hexadecimal (leading 0x), octal (leading 0) or binary (leading 0b).\n",
57 "The exact language_define of an exact match will be used in remaining lookups.\n\n",
59 "A language-country pair will lookup a xx-YY mapping from isolang.cxx,\n",
60 "for example: 'en-US' or 'de-' or '-CH',\n",
61 "xx and YY can be given case insensitive, will be lowered-uppered internally,\n",
62 "and xx and YY themselves may be regular expressions.\n",
63 "Also here a list of matches will be processed.\n\n",
65 "If option --single is given, only the first match will be processed.\n\n";
68 my $SOLARVERSION = $ENV{"SOLARVERSION"};
69 my $INPATH = $ENV{"INPATH"};
70 my $SRC_ROOT = $ENV{"SRC_ROOT"};
71 my $UPDMINOREXT = $ENV{"UPDMINOREXT"};
72 if (!defined($SOLARVERSION) || !defined($INPATH) || !defined($SRC_ROOT))
74 print "\nNeed \$SOLARVERSION, \$INPATH and \$SRC_ROOT, please set your OOo environment!\n";
78 if (!defined($UPDMINOREXT)) {
81 my $SOLENVINC = "$SOLARVERSION/$INPATH/inc$UPDMINOREXT";
83 my $LANGUAGE_MASK_PRIMARY = 0x03ff;
85 sub getPrimaryLanguage
($)
88 return $lcid & $LANGUAGE_MASK_PRIMARY;
100 return ($sub << 10) | $pri;
106 my( $regex, $path, $module, $name, @addregex) = @_;
112 # Try module under current working directory first to catch local
113 # modifications. A Not yet delivered lang.h is a special case.
114 if ("$path/$module/$name" eq "$SOLENVINC/i18npool/lang.h") {
115 $file = "./$module/inc/i18npool/lang.h"; }
117 $file = "./$module/$name"; }
118 if (!($found = open( IN
, $file)))
120 # Then with the given path.
121 $file = "$path/$module/$name";
122 if (!($found = open( IN
, $file)))
125 $file = "$path/$module.lnk/$name";
126 if (!($found = open( IN
, $file))) {
128 $file = "$path/$module.link/$name";
129 if (!($found = open( IN
, $file))) {
130 print "No $file either.\n"; }
137 while (my $line = <IN
>)
139 if ($line =~ /$regex/)
148 push( @result, $line);
152 # By convention first element is opener, second element is closer.
155 if ($line =~ /$addregex[0]/)
158 $arecloser = $addregex[1];
163 for (my $i = 2; $i < @addregex; ++$i)
165 if ($line =~ /$addregex[$i]/)
174 push( @result, $line);
177 if ($line =~ /$arecloser/)
187 print "Not found in $file\n";
188 #print "Not found in $file for $regex @addregex\n";
196 my( $lcid, @parts, $grepdef, $options, $single);
199 for ($options = 0; $options < @ARGV && $ARGV[$options] =~ /^--/; ++$options)
201 if ($ARGV[$options] eq '--single') { $single = 1; }
202 else { print "Unknown option: $ARGV[$options]\n"; }
204 if (@ARGV == 1 + $options)
206 # 0x hex, 0b bin, 0 oct
207 if ($ARGV[$options] =~ /^0/) {
208 $lcid = oct( $ARGV[0]); }
209 elsif ($ARGV[$options] =~ /^[0-9]/) {
210 $lcid = $ARGV[$options]; }
213 $grepdef = $ARGV[$options];
216 $parts[0] = getPrimaryLanguage
( $lcid);
217 $parts[1] = getSubLanguage
( $lcid);
219 elsif (@ARGV == 2 + $options)
221 for (my $i = $options; $i < 2 + $options; ++$i)
223 if ($ARGV[$i] =~ /^0/) {
224 $parts[$i] = oct( $ARGV[$i]); }
226 $parts[$i] = $ARGV[$i]; }
228 $lcid = makeLangID
( $parts[1], $parts[0]);
235 my $modifier = "(?i)";
236 my (@resultlist, @greplist, $result);
237 # If no string was given on the command line, but value(s) were, lookup the
238 # LangID value to obtain the define identifier.
241 # #define LANGUAGE_AFRIKAANS 0x0436
242 @resultlist = grepFile
(
243 $modifier . '^\s*#\s*define\s+[A-Z_]*' . $grepdef,
244 $SOLENVINC, "i18npool", "lang.h", ());
248 printf( "LangID: 0x%04X (dec %d), primary: 0x%03x, sub 0x%02x\n", $lcid,
249 $lcid, $parts[0], $parts[1]);
250 my $buf = sprintf( "0x%04X", $lcid);
251 @resultlist = grepFile
(
252 '^\s*#\s*define\s+\w+\s+' . $buf,
253 $SOLENVINC, "i18npool", "lang.h", ());
255 for $result (@resultlist)
257 # #define LANGUAGE_AFRIKAANS 0x0436
258 if ($result =~ /^\s*#\s*define\s+(\w+)\s+(0x[0-9a-fA-F]+)/)
260 push( @greplist, '\b' . $1 . '\b');
261 $modifier = ""; # complete identifier now case sensitive
266 # If the string given is of the form xx-yy lookup a language,country pair
267 # to obtain the define identifier. xx and yy themselfs may be regexps.
268 # xx- is a short form for 'xx-.*' and -yy a short form for '.*-yy'
269 if ($grepdef =~ /^(.*)-$/) {
270 $grepdef = $1 . "-.*"; }
271 if ($grepdef =~ /^-(.*)$/) {
272 $grepdef = ".*-" . $1; }
273 if ($grepdef =~ /^(.*)-(.*)$/)
279 # { LANGUAGE_AFRIKAANS, "af", "ZA" },
280 @resultlist = grepFile
(
281 '^\s*\{\s*\w+\s*,\s*\"' . $lang . '\"\s*,\s*\"' . $coun . '\"\s*\}\s*,',
282 "$SRC_ROOT", "i18npool", "source/isolang/isolang.cxx", ());
283 for $result (@resultlist)
285 if ($result =~ /^\s*\{\s*(\w+)\s*,\s*\"\w+\"\s*,\s*\"(\w+)?\"\s*\}\s*,/)
287 push( @greplist, '\b' . $1 . '\b');
288 $modifier = ""; # complete identifier now case sensitive
295 if (!@greplist && $grepdef) {
296 push( @greplist, $grepdef); }
297 for $grepdef (@greplist)
299 print "\nUsing: " . $grepdef . "\n";
301 # Decimal LCID, was needed for Langpack.ulf but isn't used anymore,
302 # keep just in case we'd need it again.
303 # #define LANGUAGE_AFRIKAANS 0x0436
304 @resultlist = grepFile
(
305 $modifier . '^\s*#\s*define\s+[A-Z_]*' . $grepdef,
306 $SOLENVINC, "i18npool", "lang.h", ());
308 for $result (@resultlist)
310 # #define LANGUAGE_AFRIKAANS 0x0436
311 if ($result =~ /^\s*#\s*define\s+(\w+)\s+(0x[0-9a-fA-F]+)/)
313 push( @lcidlist, oct( $2));
317 # { LANGUAGE_AFRIKAANS, "af", "ZA" },
318 @resultlist = grepFile
(
319 $modifier . '^\s*\{\s*.*' . $grepdef . '.*\s*,\s*\".*\"\s*,\s*\".*\"\s*\}\s*,',
320 "$SRC_ROOT", "i18npool", "source/isolang/isolang.cxx", ());
322 my @langcoungreplist;
323 for $result (@resultlist)
325 if ($result =~ /^\s*\{\s*\w+\s*,\s*\"(\w+)\"\s*,\s*\"(\w+)?\"\s*\}\s*,/)
332 $loca = $lang . "_" . $coun;
333 push( @langcoungreplist, '\b' . $lang . '\b(-' . $coun . ')?');
339 push( @langcoungreplist, '\b' . $lang . '\b');
341 my $file = "$SRC_ROOT/i18npool/source/localedata/data/$loca.xml";
343 if (!($found = open( LD
, $file)))
345 $file = "$SRC_ROOT/i18npool.lnk/source/localedata/data/$loca.xml";
346 if (!($found = open( LD
, $file)))
348 $file = "$SRC_ROOT/i18npool.link/source/localedata/data/$loca.xml";
349 $found = open( LD
, $file);
354 print "Found $file:\n";
356 while (my $line = <LD
>)
358 if ($line =~ /<(Language|Country)>/) {
362 if ($line =~ /<\/(Language
|Country
)>/) {
368 print "No $SRC_ROOT/i18npool/source/localedata/data/$loca.xml\n"; }
372 # case LANGUAGE_ARABIC:
374 $modifier . '^\s*case\s*.*' . $grepdef . '.*\s*:',
375 "$SRC_ROOT", "i18npool", "source/isolang/mslangid.cxx", ());
377 # With CWS 'langstatusbar' the language listbox resource file gets a new location.
379 my $name = "source/dialog/langtab.src";
380 if (!(-e
"$SRC_ROOT/$module/$name")) {
382 $name = "source/misc/langtab.src";
384 # < "Afrikaans" ; LANGUAGE_AFRIKAANS ; > ;
386 @resultlist = grepFile
(
387 $modifier . '^\s*<\s*\".*\"\s*;\s*.*' . $grepdef . '.*\s*;\s*>\s*;',
388 "$SRC_ROOT", $module, $name, ());
392 $modifier . '^\s*<\s*\".*' . $grepdef . '.*\"\s*;\s*.*\s*;\s*>\s*;',
393 "$SRC_ROOT", $module, $name, ()); }
395 for my $langcoun (@langcoungreplist)
397 # Name (xxx) = "/registry/spool/org/openoffice/Office/Common-ctl.xcu";
399 '^\s*Name\s*\(' . $langcoun . '\)\s*=',
400 "$SRC_ROOT", "scp2", "source/ooo/file_ooo.scp", ());
402 # completelangiso=af ar as-IN ... zu
404 '^\s*completelangiso\s*=\s*(\s*([a-z]{2,3})(-[A-Z][A-Z])?)*' . $langcoun . '',
405 "$SRC_ROOT", "solenv", "inc/langlist.mk",
406 # needs a duplicated pair of backslashes to produce a literal \\
407 ('^\s*completelangiso\s*=', '^\s*$', '^\s*' . $langcoun . '\s*\\\\*$'));
409 # @noMSLocaleLangs = ( "br", "bs", ... )
411 '^\s*@noMSLocaleLangs\s*=\s*\(\s*(\s*"([a-z]{2,3})(-[A-Z][A-Z])?"\s*,?)*' . $langcoun . '',
412 "$SRC_ROOT", "solenv", "bin/modules/installer/globals.pm",
413 ('^\s*@noMSLocaleLangs\s*=', '\)\s*$', '"' . $langcoun . '"'));
415 # af 1252 1078 # Afrikaans
417 '^\s*' . $langcoun . '',
418 "$SRC_ROOT", "setup_native", "source/win32/msi-encodinglist.txt", ());