1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
: # -*- perl -*- vim: ft=perl
eval 'exec perl -w -S $0 ${1+"$@"}'
if 0;
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
# See Usage() below or invoke without arguments for short instructions.
# For long instructions use the source, Luke ;-)
use strict;
sub Usage()
{
print STDERR
"\n",
"langid - a hackish utility to lookup lang.h language defines and LangIDs,\n",
"isolang.cxx ISO639/ISO3166 mapping, locale data files, langtab.src language\n",
"listbox entries, langlist.mk, file_ooo.scp registry name, languages.pm and\n",
"msi-encodinglist.txt\n\n",
"Usage: $0 [--single] {language string} | {LangID} | {primarylanguage sublanguage} | {language-country}\n\n",
"A language string will be used as a generic string match in all searched files.\n",
"You may enclose the language string in word delimiters,\n",
"e.g. \\blanguage_german\\b for a specific match.\n",
"If the language string expression matches more than one define,\n",
"e.g. as in 'german', all matching defines will be processed.\n",
"If the language string does not match a define or an identifier in\n",
"langtab.src, a generic string match of the listbox entries will be tried.\n\n",
"Numeric values of LangID,primarylanguage,sublanguage can be given\n",
"decimal, hexadecimal (leading 0x), octal (leading 0) or binary (leading 0b).\n",
"The exact language_define of an exact match will be used in remaining lookups.\n\n",
"A language-country pair will lookup a xx-YY mapping from isolang.cxx,\n",
"for example: 'en-US' or 'de-' or '-CH',\n",
"xx and YY can be given case insensitive, will be lowered-uppered internally,\n",
"and xx and YY themselves may be regular expressions.\n",
"Also here a list of matches will be processed.\n\n",
"If option --single is given, only the first match will be processed.\n\n";
}
my $SOLARVERSION = $ENV{"SOLARVERSION"};
my $INPATH = $ENV{"INPATH"};
my $SRC_ROOT = $ENV{"SRC_ROOT"};
my $UPDMINOREXT = $ENV{"UPDMINOREXT"};
if (!defined($SOLARVERSION) || !defined($INPATH) || !defined($SRC_ROOT))
{
print "\nNeed \$SOLARVERSION, \$INPATH and \$SRC_ROOT, please set your OOo environment!\n";
Usage();
exit 1;
}
if (!defined($UPDMINOREXT)) {
$UPDMINOREXT = '';
}
my $SOLENVINC = "$SOLARVERSION/$INPATH/inc$UPDMINOREXT";
my $LANGUAGE_MASK_PRIMARY = 0x03ff;
sub getPrimaryLanguage($)
{
my($lcid) = @_;
return $lcid & $LANGUAGE_MASK_PRIMARY;
}
sub getSubLanguage($)
{
my($lcid) = @_;
return $lcid >> 10;
}
sub makeLangID($$)
{
my( $sub, $pri) = @_;
return ($sub << 10) | $pri;
}
sub grepFile($$$$@)
{
my( $regex, $path, $module, $name, @addregex) = @_;
my @result;
my $found = 0;
my $areopen = 0;
my $arecloser = '';
my $file;
# Try module under current working directory first to catch local
# modifications. A Not yet delivered lang.h is a special case.
if ("$path/$module/$name" eq "$SOLENVINC/i18npool/lang.h") {
$file = "./$module/inc/i18npool/lang.h"; }
else {
$file = "./$module/$name"; }
if (!($found = open( IN, $file)))
{
# Then with the given path.
$file = "$path/$module/$name";
if (!($found = open( IN, $file)))
{
print "No $file\n";
$file = "$path/$module.lnk/$name";
if (!($found = open( IN, $file))) {
print "No $file.\n";
$file = "$path/$module.link/$name";
if (!($found = open( IN, $file))) {
print "No $file either.\n"; }
}
}
}
if ($found)
{
$found = 0;
while (my $line = <IN>)
{
if ($line =~ /$regex/)
{
if (!$found)
{
$found = 1;
print "$file:\n";
}
chomp( $line);
print "$line\n";
push( @result, $line);
}
elsif (@addregex)
{
# By convention first element is opener, second element is closer.
if (!$areopen)
{
if ($line =~ /$addregex[0]/)
{
$areopen = 1;
$arecloser = $addregex[1];
}
}
if ($areopen)
{
for (my $i = 2; $i < @addregex; ++$i)
{
if ($line =~ /$addregex[$i]/)
{
if (!$found)
{
$found = 1;
print "$file:\n";
}
chomp( $line);
print "$line\n";
push( @result, $line);
}
}
if ($line =~ /$arecloser/)
{
$areopen = 0;
}
}
}
}
close( IN);
}
if (!$found) {
print "Not found in $file\n";
#print "Not found in $file for $regex @addregex\n";
}
return @result;
}
sub main()
{
my( $lcid, @parts, $grepdef, $options, $single);
$grepdef = 0;
$single = 0;
for ($options = 0; $options < @ARGV && $ARGV[$options] =~ /^--/; ++$options)
{
if ($ARGV[$options] eq '--single') { $single = 1; }
else { print "Unknown option: $ARGV[$options]\n"; }
}
if (@ARGV == 1 + $options)
{
# 0x hex, 0b bin, 0 oct
if ($ARGV[$options] =~ /^0/) {
$lcid = oct( $ARGV[0]); }
elsif ($ARGV[$options] =~ /^[0-9]/) {
$lcid = $ARGV[$options]; }
else
{
$grepdef = $ARGV[$options];
$lcid = 0;
}
$parts[0] = getPrimaryLanguage( $lcid);
$parts[1] = getSubLanguage( $lcid);
}
elsif (@ARGV == 2 + $options)
{
for (my $i = $options; $i < 2 + $options; ++$i)
{
if ($ARGV[$i] =~ /^0/) {
$parts[$i] = oct( $ARGV[$i]); }
else {
$parts[$i] = $ARGV[$i]; }
}
$lcid = makeLangID( $parts[1], $parts[0]);
}
else
{
Usage();
return 1;
}
my $modifier = "(?i)";
my (@resultlist, @greplist, $result);
# If no string was given on the command line, but value(s) were, lookup the
# LangID value to obtain the define identifier.
if ($grepdef)
{
# #define LANGUAGE_AFRIKAANS 0x0436
@resultlist = grepFile(
$modifier . '^\s*#\s*define\s+[A-Z_]*' . $grepdef,
$SOLENVINC, "i18npool", "lang.h", ());
}
else
{
printf( "LangID: 0x%04X (dec %d), primary: 0x%03x, sub 0x%02x\n", $lcid,
$lcid, $parts[0], $parts[1]);
my $buf = sprintf( "0x%04X", $lcid);
@resultlist = grepFile(
'^\s*#\s*define\s+\w+\s+' . $buf,
$SOLENVINC, "i18npool", "lang.h", ());
}
for $result (@resultlist)
{
# #define LANGUAGE_AFRIKAANS 0x0436
if ($result =~ /^\s*#\s*define\s+(\w+)\s+(0x[0-9a-fA-F]+)/)
{
push( @greplist, '\b' . $1 . '\b');
$modifier = ""; # complete identifier now case sensitive
if ($single) {
last; }
}
}
# If the string given is of the form xx-yy lookup a language,country pair
# to obtain the define identifier. xx and yy themselfs may be regexps.
# xx- is a short form for 'xx-.*' and -yy a short form for '.*-yy'
if ($grepdef =~ /^(.*)-$/) {
$grepdef = $1 . "-.*"; }
if ($grepdef =~ /^-(.*)$/) {
$grepdef = ".*-" . $1; }
if ($grepdef =~ /^(.*)-(.*)$/)
{
my $lang = $1;
my $coun = $2;
$lang = lc($lang);
$coun = uc($coun);
# { LANGUAGE_AFRIKAANS, "af", "ZA" },
@resultlist = grepFile(
'^\s*\{\s*\w+\s*,\s*\"' . $lang . '\"\s*,\s*\"' . $coun . '\"\s*\}\s*,',
"$SRC_ROOT", "i18npool", "source/isolang/isolang.cxx", ());
for $result (@resultlist)
{
if ($result =~ /^\s*\{\s*(\w+)\s*,\s*\"\w+\"\s*,\s*\"(\w+)?\"\s*\}\s*,/)
{
push( @greplist, '\b' . $1 . '\b');
$modifier = ""; # complete identifier now case sensitive
if ($single) {
last; }
}
}
$grepdef = 0;
}
if (!@greplist && $grepdef) {
push( @greplist, $grepdef); }
for $grepdef (@greplist)
{
print "\nUsing: " . $grepdef . "\n";
# Decimal LCID, was needed for Langpack.ulf but isn't used anymore,
# keep just in case we'd need it again.
# #define LANGUAGE_AFRIKAANS 0x0436
@resultlist = grepFile(
$modifier . '^\s*#\s*define\s+[A-Z_]*' . $grepdef,
$SOLENVINC, "i18npool", "lang.h", ());
my @lcidlist;
for $result (@resultlist)
{
# #define LANGUAGE_AFRIKAANS 0x0436
if ($result =~ /^\s*#\s*define\s+(\w+)\s+(0x[0-9a-fA-F]+)/)
{
push( @lcidlist, oct( $2));
}
}
# { LANGUAGE_AFRIKAANS, "af", "ZA" },
@resultlist = grepFile(
$modifier . '^\s*\{\s*.*' . $grepdef . '.*\s*,\s*\".*\"\s*,\s*\".*\"\s*\}\s*,',
"$SRC_ROOT", "i18npool", "source/isolang/isolang.cxx", ());
my @langcoungreplist;
for $result (@resultlist)
{
if ($result =~ /^\s*\{\s*\w+\s*,\s*\"(\w+)\"\s*,\s*\"(\w+)?\"\s*\}\s*,/)
{
my $lang = $1;
my $coun = $2;
my $loca;
if ($coun)
{
$loca = $lang . "_" . $coun;
push( @langcoungreplist, '\b' . $lang . '\b(-' . $coun . ')?');
}
else
{
$loca = $lang;
$coun = "";
push( @langcoungreplist, '\b' . $lang . '\b');
}
my $file = "$SRC_ROOT/i18npool/source/localedata/data/$loca.xml";
my $found;
if (!($found = open( LD, $file)))
{
$file = "$SRC_ROOT/i18npool.lnk/source/localedata/data/$loca.xml";
if (!($found = open( LD, $file)))
{
$file = "$SRC_ROOT/i18npool.link/source/localedata/data/$loca.xml";
$found = open( LD, $file);
}
}
if ($found)
{
print "Found $file:\n";
my $on = 0;
while (my $line = <LD>)
{
if ($line =~ /<(Language|Country)>/) {
$on = 1; }
if ($on) {
print $line; }
if ($line =~ /<\/(Language|Country)>/) {
$on = 0; }
}
close( LD);
}
else {
print "No $SRC_ROOT/i18npool/source/localedata/data/$loca.xml\n"; }
}
}
# case LANGUAGE_ARABIC:
grepFile(
$modifier . '^\s*case\s*.*' . $grepdef . '.*\s*:',
"$SRC_ROOT", "i18npool", "source/isolang/mslangid.cxx", ());
# With CWS 'langstatusbar' the language listbox resource file gets a new location.
my $module = "svx";
my $name = "source/dialog/langtab.src";
if (!(-e "$SRC_ROOT/$module/$name")) {
$module = "svtools";
$name = "source/misc/langtab.src";
}
# < "Afrikaans" ; LANGUAGE_AFRIKAANS ; > ;
# lookup define
@resultlist = grepFile(
$modifier . '^\s*<\s*\".*\"\s*;\s*.*' . $grepdef . '.*\s*;\s*>\s*;',
"$SRC_ROOT", $module, $name, ());
# lookup string
if (!@resultlist) {
grepFile(
$modifier . '^\s*<\s*\".*' . $grepdef . '.*\"\s*;\s*.*\s*;\s*>\s*;',
"$SRC_ROOT", $module, $name, ()); }
for my $langcoun (@langcoungreplist)
{
# Name (xxx) = "/registry/spool/org/openoffice/Office/Common-ctl.xcu";
grepFile(
'^\s*Name\s*\(' . $langcoun . '\)\s*=',
"$SRC_ROOT", "scp2", "source/ooo/file_ooo.scp", ());
# completelangiso=af ar as-IN ... zu
grepFile(
'^\s*completelangiso\s*=\s*(\s*([a-z]{2,3})(-[A-Z][A-Z])?)*' . $langcoun . '',
"$SRC_ROOT", "solenv", "inc/langlist.mk",
# needs a duplicated pair of backslashes to produce a literal \\
('^\s*completelangiso\s*=', '^\s*$', '^\s*' . $langcoun . '\s*\\\\*$'));
# @noMSLocaleLangs = ( "br", "bs", ... )
grepFile(
'^\s*@noMSLocaleLangs\s*=\s*\(\s*(\s*"([a-z]{2,3})(-[A-Z][A-Z])?"\s*,?)*' . $langcoun . '',
"$SRC_ROOT", "solenv", "bin/modules/installer/languages.pm",
('^\s*@noMSLocaleLangs\s*=', '\)\s*$', '"' . $langcoun . '"'));
# af 1252 1078 # Afrikaans
grepFile(
'^\s*' . $langcoun . '',
"$SRC_ROOT", "setup_native", "source/win32/msi-encodinglist.txt", ());
}
}
return 0;
}
main();
|