xref: /trunk/main/scp2/macros/macro.pl (revision cdf0e10c)
1*cdf0e10cSrcweir#*************************************************************************
2*cdf0e10cSrcweir#
3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir#
5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir#
7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir#
9*cdf0e10cSrcweir# This file is part of OpenOffice.org.
10*cdf0e10cSrcweir#
11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir# only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir#
15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir#
21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir# version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir# for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir#
26*cdf0e10cSrcweir#*************************************************************************
27*cdf0e10cSrcweir
28*cdf0e10cSrcweirmy $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
29*cdf0e10cSrcweirmy $lastcompletelangiso_var;;
30*cdf0e10cSrcweirmy $outfile = "";
31*cdf0e10cSrcweir
32*cdf0e10cSrcweirif ( !defined $completelangiso_var) {
33*cdf0e10cSrcweir	print STDERR "ERROR: No language defined!\n";
34*cdf0e10cSrcweir	exit 1;
35*cdf0e10cSrcweir}
36*cdf0e10cSrcweir
37*cdf0e10cSrcweirmy $poorhelplocalizations_var = $ENV{WITH_POOR_HELP_LOCALIZATIONS};
38*cdf0e10cSrcweirmy %poorhelplocalizations;
39*cdf0e10cSrcweirforeach $lang (split (/ /, $poorhelplocalizations_var)) {
40*cdf0e10cSrcweir  $poorhelplocalizations{$lang}++;
41*cdf0e10cSrcweir}
42*cdf0e10cSrcweir
43*cdf0e10cSrcweirstartup_check();
44*cdf0e10cSrcweirif ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
45*cdf0e10cSrcweir    print STDERR "No new languages. Keeping old file\n";
46*cdf0e10cSrcweir    exit 0;
47*cdf0e10cSrcweir}
48*cdf0e10cSrcweir
49*cdf0e10cSrcweirmy @completelangiso = split " +", $completelangiso_var;
50*cdf0e10cSrcweir
51*cdf0e10cSrcweiropen OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
52*cdf0e10cSrcweir
53*cdf0e10cSrcweirprint OUTFILE "// generated file, do not edit\n\n";
54*cdf0e10cSrcweirprint OUTFILE "// languages used for last time generation\n";
55*cdf0e10cSrcweirprint OUTFILE "// completelangiso: $completelangiso_var\n\n";
56*cdf0e10cSrcweirwrite_ALL_LANG();
57*cdf0e10cSrcweirwrite_OTHER_LANGS();
58*cdf0e10cSrcweirwrite_DIR_ISOLANGUAGE_ALL_LANG_2();
59*cdf0e10cSrcweirwrite_DIR_ISOLANGUAGE_ALL_LANG();
60*cdf0e10cSrcweirwrite_DIR_ISOLANGUAGE_ALL_LANG_LPROJ();
61*cdf0e10cSrcweirwrite_DIR_IDENT_ALL_LANG();
62*cdf0e10cSrcweirwrite_EXTRA_ALL_LANG();
63*cdf0e10cSrcweirwrite_EXTRA_ALL_LANG_BUT_EN_US();
64*cdf0e10cSrcweirwrite_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG();
65*cdf0e10cSrcweirwrite_EXTRA_IDENT_ALL_LANG();
66*cdf0e10cSrcweirwrite_RESFILE_ALL_LANG();
67*cdf0e10cSrcweirwrite_SHORT_RESFILE_ALL_LANG();
68*cdf0e10cSrcweirwrite_README_ALL_LANG();
69*cdf0e10cSrcweirwrite_README_TXT_ALL_LANG();
70*cdf0e10cSrcweirwrite_VALUE_ALL_LANG_LETTER_DIR();
71*cdf0e10cSrcweirwrite_KEY_ALL_LANG_LETTER();
72*cdf0e10cSrcweirwrite_FILE_ALL_LANG_LETTER();
73*cdf0e10cSrcweir
74*cdf0e10cSrcweirclose OUTFILE;
75*cdf0e10cSrcweir
76*cdf0e10cSrcweir
77*cdf0e10cSrcweirsub write_ALL_LANG
78*cdf0e10cSrcweir{
79*cdf0e10cSrcweir	print OUTFILE "#define ALL_LANG(ident, resid) ";
80*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
81*cdf0e10cSrcweir		print OUTFILE "\\\n\tident ($lang) = resid";
82*cdf0e10cSrcweir		print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
83*cdf0e10cSrcweir	}
84*cdf0e10cSrcweir	print OUTFILE "\n\n";
85*cdf0e10cSrcweir}
86*cdf0e10cSrcweir
87*cdf0e10cSrcweirsub write_OTHER_LANGS
88*cdf0e10cSrcweir{
89*cdf0e10cSrcweir	print OUTFILE "#define OTHER_LANGS ";
90*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
91*cdf0e10cSrcweir        next if ( $lang eq "en-US");
92*cdf0e10cSrcweir		print OUTFILE "\\\n\tDosName ($lang) = \"$lang\"";
93*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
94*cdf0e10cSrcweir	}
95*cdf0e10cSrcweir        print OUTFILE "\n\n";
96*cdf0e10cSrcweir}
97*cdf0e10cSrcweir
98*cdf0e10cSrcweirsub write_DIR_ISOLANGUAGE_ALL_LANG_2
99*cdf0e10cSrcweir{
100*cdf0e10cSrcweir	print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 ";
101*cdf0e10cSrcweir	print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t";
102*cdf0e10cSrcweir	print OUTFILE "OTHER_LANGS";
103*cdf0e10cSrcweir        print OUTFILE "\n\n";
104*cdf0e10cSrcweir}
105*cdf0e10cSrcweir
106*cdf0e10cSrcweirsub write_DIR_ISOLANGUAGE_ALL_LANG
107*cdf0e10cSrcweir{
108*cdf0e10cSrcweir	print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG ";
109*cdf0e10cSrcweir	print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t";
110*cdf0e10cSrcweir	print OUTFILE "OTHER_LANGS";
111*cdf0e10cSrcweir        print OUTFILE "\n\n";
112*cdf0e10cSrcweir}
113*cdf0e10cSrcweir
114*cdf0e10cSrcweirsub write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ
115*cdf0e10cSrcweir{
116*cdf0e10cSrcweir    print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_LPROJ ";
117*cdf0e10cSrcweir    foreach $lang (@completelangiso) {
118*cdf0e10cSrcweir    	my $speciallang = $lang;
119*cdf0e10cSrcweir    	if ( $speciallang eq "en-US" ) { $speciallang = "en"; }
120*cdf0e10cSrcweir        print OUTFILE "\\\n\tDosName ($lang) = \"$speciallang.lproj\"";
121*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
122*cdf0e10cSrcweir    }
123*cdf0e10cSrcweir    print OUTFILE "\n\n";
124*cdf0e10cSrcweir}
125*cdf0e10cSrcweir
126*cdf0e10cSrcweirsub write_DIR_IDENT_ALL_LANG
127*cdf0e10cSrcweir{
128*cdf0e10cSrcweir	print OUTFILE "#define DIR_IDENT_ALL_LANG(name) ";
129*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
130*cdf0e10cSrcweir		print OUTFILE "\\\n\tDosName ($lang) = STRING(name)";
131*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
132*cdf0e10cSrcweir	}
133*cdf0e10cSrcweir	print OUTFILE "\n\n";
134*cdf0e10cSrcweir}
135*cdf0e10cSrcweir
136*cdf0e10cSrcweirsub write_EXTRA_ALL_LANG
137*cdf0e10cSrcweir{
138*cdf0e10cSrcweir	print OUTFILE "#define EXTRA_ALL_LANG(name,ext) ";
139*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
140*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
141*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
142*cdf0e10cSrcweir	}
143*cdf0e10cSrcweir	print OUTFILE "\n\n";
144*cdf0e10cSrcweir}
145*cdf0e10cSrcweir
146*cdf0e10cSrcweirsub write_EXTRA_ALL_LANG_BUT_EN_US
147*cdf0e10cSrcweir{
148*cdf0e10cSrcweir    print OUTFILE "#define EXTRA_ALL_LANG_BUT_EN_US(name,ext) ";
149*cdf0e10cSrcweir    my $first = 1;
150*cdf0e10cSrcweir    foreach $lang (@completelangiso) {
151*cdf0e10cSrcweir        if ($lang ne "en-US") {
152*cdf0e10cSrcweir            print OUTFILE "; " unless $first;
153*cdf0e10cSrcweir            $first = 0;
154*cdf0e10cSrcweir            print OUTFILE
155*cdf0e10cSrcweir                "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
156*cdf0e10cSrcweir        }
157*cdf0e10cSrcweir    }
158*cdf0e10cSrcweir    print OUTFILE "\n\n";
159*cdf0e10cSrcweir}
160*cdf0e10cSrcweir
161*cdf0e10cSrcweirsub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG
162*cdf0e10cSrcweir{
163*cdf0e10cSrcweir    my $first = 1;
164*cdf0e10cSrcweir	print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) ";
165*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
166*cdf0e10cSrcweir		next if ( $poorhelplocalizations{$lang} );
167*cdf0e10cSrcweir		print OUTFILE ";" unless $first;
168*cdf0e10cSrcweir		$first = 0;
169*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = EXTRAFILENAME(name,_$lang)";
170*cdf0e10cSrcweir	}
171*cdf0e10cSrcweir	print OUTFILE "\n\n";
172*cdf0e10cSrcweir}
173*cdf0e10cSrcweir
174*cdf0e10cSrcweirsub write_EXTRA_IDENT_ALL_LANG
175*cdf0e10cSrcweir{
176*cdf0e10cSrcweir	print OUTFILE "#define EXTRA_IDENT_ALL_LANG(name) ";
177*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
178*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = STRING(name)";
179*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
180*cdf0e10cSrcweir	}
181*cdf0e10cSrcweir	print OUTFILE "\n\n";
182*cdf0e10cSrcweir}
183*cdf0e10cSrcweir
184*cdf0e10cSrcweirsub write_RESFILE_ALL_LANG
185*cdf0e10cSrcweir{
186*cdf0e10cSrcweir	print OUTFILE "#define RESFILE_ALL_LANG(name) ";
187*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
188*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)";
189*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
190*cdf0e10cSrcweir	}
191*cdf0e10cSrcweir	print OUTFILE "\n\n";
192*cdf0e10cSrcweir}
193*cdf0e10cSrcweir
194*cdf0e10cSrcweirsub write_SHORT_RESFILE_ALL_LANG
195*cdf0e10cSrcweir{
196*cdf0e10cSrcweir	print OUTFILE "#define SHORT_RESFILE_ALL_LANG(name) ";
197*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
198*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = SHORTRESFILENAME(name,$lang)";
199*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
200*cdf0e10cSrcweir	}
201*cdf0e10cSrcweir	print OUTFILE "\n\n";
202*cdf0e10cSrcweir}
203*cdf0e10cSrcweir
204*cdf0e10cSrcweirsub write_README_ALL_LANG
205*cdf0e10cSrcweir{
206*cdf0e10cSrcweir	print OUTFILE "#define README_ALL_LANG(key, name) ";
207*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
208*cdf0e10cSrcweir		print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)";
209*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
210*cdf0e10cSrcweir	}
211*cdf0e10cSrcweir	print OUTFILE "\n\n";
212*cdf0e10cSrcweir}
213*cdf0e10cSrcweir
214*cdf0e10cSrcweirsub write_README_TXT_ALL_LANG
215*cdf0e10cSrcweir{
216*cdf0e10cSrcweir	print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) ";
217*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
218*cdf0e10cSrcweir		print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)";
219*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
220*cdf0e10cSrcweir	}
221*cdf0e10cSrcweir	print OUTFILE "\n\n";
222*cdf0e10cSrcweir}
223*cdf0e10cSrcweir
224*cdf0e10cSrcweir# FIXME: Not used at all in OOo?, #i38597#
225*cdf0e10cSrcweirsub write_VALUE_ALL_LANG_LETTER_DIR
226*cdf0e10cSrcweir{
227*cdf0e10cSrcweir	print OUTFILE "#define VALUE_ALL_LANG_LETTER_DIR ";
228*cdf0e10cSrcweir	print OUTFILE "\\\n\tValue (en-US) = STRING(en);";
229*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
230*cdf0e10cSrcweir        next if ( $lang eq "en-US");
231*cdf0e10cSrcweir		print OUTFILE "\\\n\tValue ($lang) = STRING($lang)";
232*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
233*cdf0e10cSrcweir	}
234*cdf0e10cSrcweir	print OUTFILE "\n\n";
235*cdf0e10cSrcweir}
236*cdf0e10cSrcweir
237*cdf0e10cSrcweirsub write_KEY_ALL_LANG_LETTER
238*cdf0e10cSrcweir{
239*cdf0e10cSrcweir	print OUTFILE "#define KEY_ALL_LANG_LETTER ";
240*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
241*cdf0e10cSrcweir		print OUTFILE "\\\n\tKey ($lang) = STRING($lang)";
242*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
243*cdf0e10cSrcweir	}
244*cdf0e10cSrcweir	print OUTFILE "\n\n";
245*cdf0e10cSrcweir}
246*cdf0e10cSrcweir
247*cdf0e10cSrcweirsub write_FILE_ALL_LANG_LETTER
248*cdf0e10cSrcweir{
249*cdf0e10cSrcweir	print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) ";
250*cdf0e10cSrcweir	foreach $lang (@completelangiso) {
251*cdf0e10cSrcweir		print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)";
252*cdf0e10cSrcweir        print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
253*cdf0e10cSrcweir	}
254*cdf0e10cSrcweir	print OUTFILE "\n\n";
255*cdf0e10cSrcweir}
256*cdf0e10cSrcweir
257*cdf0e10cSrcweirsub startup_check
258*cdf0e10cSrcweir{
259*cdf0e10cSrcweir    my $i;
260*cdf0e10cSrcweir    for ( $i=0; $i <= $#ARGV; $i++) {
261*cdf0e10cSrcweir        if ( "$ARGV[$i]" eq "-o" ) {
262*cdf0e10cSrcweir            if ( defined $ARGV[ $i + 1] ) {
263*cdf0e10cSrcweir                $outfile = $ARGV[ $i + 1];
264*cdf0e10cSrcweir            } else {
265*cdf0e10cSrcweir                usage();
266*cdf0e10cSrcweir            }
267*cdf0e10cSrcweir        }
268*cdf0e10cSrcweir    }
269*cdf0e10cSrcweir    usage() if $i<2;
270*cdf0e10cSrcweir    usage() if "$outfile" eq "";
271*cdf0e10cSrcweir    if ( -f "$outfile" ) {
272*cdf0e10cSrcweir		# changed script - run allways
273*cdf0e10cSrcweir		return if (stat($0))[9] > (stat("$outfile"))[9] ;
274*cdf0e10cSrcweir
275*cdf0e10cSrcweir        open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
276*cdf0e10cSrcweir        while ( $line = <OLDFILE> ) {
277*cdf0e10cSrcweir            if ( $line =~ /^\/\/.*completelangiso:/ ) {
278*cdf0e10cSrcweir                $lastcompletelangiso_var = $line;
279*cdf0e10cSrcweir                chomp $lastcompletelangiso_var;
280*cdf0e10cSrcweir                $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
281*cdf0e10cSrcweir                last;
282*cdf0e10cSrcweir            }
283*cdf0e10cSrcweir
284*cdf0e10cSrcweir        }
285*cdf0e10cSrcweir        close OLDFILE;
286*cdf0e10cSrcweir    }
287*cdf0e10cSrcweir}
288*cdf0e10cSrcweir
289*cdf0e10cSrcweirsub usage
290*cdf0e10cSrcweir{
291*cdf0e10cSrcweir    print STDERR "Generate language dependend macros use in *.scp files\n";
292*cdf0e10cSrcweir    print STDERR "perl $0 -o outputfile\n";
293*cdf0e10cSrcweir    exit  1;
294*cdf0e10cSrcweir}
295