merge the formfield patch from ooo-build
[ooovba.git] / scp2 / macros / macro.pl
blob8f59dafbf7e9e2d7cfdbe1508e65e885b2cd5c50
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: macro.pl,v $
11 # $Revision: 1.10 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 my $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
33 my $lastcompletelangiso_var;;
34 my $outfile = "";
36 if ( !defined $completelangiso_var) {
37 print STDERR "ERROR: No language defined!\n";
38 exit 1;
41 my $poorhelplocalizations_var = $ENV{WITH_POOR_HELP_LOCALIZATIONS};
42 my %poorhelplocalizations;
43 foreach $lang (split (/ /, $poorhelplocalizations_var)) {
44 $poorhelplocalizations{$lang}++;
47 startup_check();
48 if ( "$completelangiso_var" eq "$lastcompletelangiso_var" ) {
49 print STDERR "No new languages. Keeping old file\n";
50 exit 0;
53 my @completelangiso = split " +", $completelangiso_var;
55 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
57 print OUTFILE "// generated file, do not edit\n\n";
58 print OUTFILE "// languages used for last time generation\n";
59 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
60 write_ALL_LANG();
61 write_OTHER_LANGS();
62 write_DIR_ISOLANGUAGE_ALL_LANG_2();
63 write_DIR_ISOLANGUAGE_ALL_LANG();
64 write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ();
65 write_DIR_IDENT_ALL_LANG();
66 write_EXTRA_ALL_LANG();
67 write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG();
68 write_EXTRA_IDENT_ALL_LANG();
69 write_RESFILE_ALL_LANG();
70 write_SHORT_RESFILE_ALL_LANG();
71 write_README_ALL_LANG();
72 write_README_TXT_ALL_LANG();
73 write_VALUE_ALL_LANG_LETTER_DIR();
74 write_KEY_ALL_LANG_LETTER();
75 write_FILE_ALL_LANG_LETTER();
77 close OUTFILE;
80 sub write_ALL_LANG
82 print OUTFILE "#define ALL_LANG(ident, resid) ";
83 foreach $lang (@completelangiso) {
84 print OUTFILE "\\\n\tident ($lang) = resid";
85 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
87 print OUTFILE "\n\n";
90 sub write_OTHER_LANGS
92 print OUTFILE "#define OTHER_LANGS ";
93 foreach $lang (@completelangiso) {
94 next if ( $lang eq "en-US");
95 print OUTFILE "\\\n\tDosName ($lang) = \"$lang\"";
96 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
98 print OUTFILE "\n\n";
101 sub write_DIR_ISOLANGUAGE_ALL_LANG_2
103 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 ";
104 print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t";
105 print OUTFILE "OTHER_LANGS";
106 print OUTFILE "\n\n";
109 sub write_DIR_ISOLANGUAGE_ALL_LANG
111 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG ";
112 print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t";
113 print OUTFILE "OTHER_LANGS";
114 print OUTFILE "\n\n";
117 sub write_DIR_ISOLANGUAGE_ALL_LANG_LPROJ
119 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_LPROJ ";
120 foreach $lang (@completelangiso) {
121 my $speciallang = $lang;
122 if ( $speciallang eq "en-US" ) { $speciallang = "en"; }
123 print OUTFILE "\\\n\tDosName ($lang) = \"$speciallang.lproj\"";
124 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
126 print OUTFILE "\n\n";
129 sub write_DIR_IDENT_ALL_LANG
131 print OUTFILE "#define DIR_IDENT_ALL_LANG(name) ";
132 foreach $lang (@completelangiso) {
133 print OUTFILE "\\\n\tDosName ($lang) = STRING(name)";
134 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
136 print OUTFILE "\n\n";
139 sub write_EXTRA_ALL_LANG
141 print OUTFILE "#define EXTRA_ALL_LANG(name) ";
142 foreach $lang (@completelangiso) {
143 print OUTFILE "\\\n\tName ($lang) = EXTRAFILENAME(name,_$lang)";
144 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
146 print OUTFILE "\n\n";
149 sub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG
151 my $first = 1;
152 print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) ";
153 foreach $lang (@completelangiso) {
154 next if ( $poorhelplocalizations{$lang} );
155 print OUTFILE ";" unless $first;
156 $first = 0;
157 print OUTFILE "\\\n\tName ($lang) = EXTRAFILENAME(name,_$lang)";
159 print OUTFILE "\n\n";
162 sub write_EXTRA_IDENT_ALL_LANG
164 print OUTFILE "#define EXTRA_IDENT_ALL_LANG(name) ";
165 foreach $lang (@completelangiso) {
166 print OUTFILE "\\\n\tName ($lang) = STRING(name)";
167 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
169 print OUTFILE "\n\n";
172 sub write_RESFILE_ALL_LANG
174 print OUTFILE "#define RESFILE_ALL_LANG(name) ";
175 foreach $lang (@completelangiso) {
176 print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)";
177 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
179 print OUTFILE "\n\n";
182 sub write_SHORT_RESFILE_ALL_LANG
184 print OUTFILE "#define SHORT_RESFILE_ALL_LANG(name) ";
185 foreach $lang (@completelangiso) {
186 print OUTFILE "\\\n\tName ($lang) = SHORTRESFILENAME(name,$lang)";
187 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
189 print OUTFILE "\n\n";
192 sub write_README_ALL_LANG
194 print OUTFILE "#define README_ALL_LANG(key, name) ";
195 foreach $lang (@completelangiso) {
196 print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)";
197 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
199 print OUTFILE "\n\n";
202 sub write_README_TXT_ALL_LANG
204 print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) ";
205 foreach $lang (@completelangiso) {
206 print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)";
207 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
209 print OUTFILE "\n\n";
212 # FIXME: Not used at all in OOo?, #i38597#
213 sub write_VALUE_ALL_LANG_LETTER_DIR
215 print OUTFILE "#define VALUE_ALL_LANG_LETTER_DIR ";
216 print OUTFILE "\\\n\tValue (en-US) = STRING(en);";
217 foreach $lang (@completelangiso) {
218 next if ( $lang eq "en-US");
219 print OUTFILE "\\\n\tValue ($lang) = STRING($lang)";
220 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
222 print OUTFILE "\n\n";
225 sub write_KEY_ALL_LANG_LETTER
227 print OUTFILE "#define KEY_ALL_LANG_LETTER ";
228 foreach $lang (@completelangiso) {
229 print OUTFILE "\\\n\tKey ($lang) = STRING($lang)";
230 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
232 print OUTFILE "\n\n";
235 sub write_FILE_ALL_LANG_LETTER
237 print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) ";
238 foreach $lang (@completelangiso) {
239 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)";
240 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
242 print OUTFILE "\n\n";
245 sub startup_check
247 my $i;
248 for ( $i=0; $i <= $#ARGV; $i++) {
249 if ( "$ARGV[$i]" eq "-o" ) {
250 if ( defined $ARGV[ $i + 1] ) {
251 $outfile = $ARGV[ $i + 1];
252 } else {
253 usage();
257 usage() if $i<2;
258 usage() if "$outfile" eq "";
259 if ( -f "$outfile" ) {
260 # changed script - run allways
261 return if (stat($0))[9] > (stat("$outfile"))[9] ;
263 open OLDFILE, "$outfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
264 while ( $line = <OLDFILE> ) {
265 if ( $line =~ /^\/\/.*completelangiso:/ ) {
266 $lastcompletelangiso_var = $line;
267 chomp $lastcompletelangiso_var;
268 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
269 last;
273 close OLDFILE;
277 sub usage
279 print STDERR "Generate language dependend macros use in *.scp files\n";
280 print STDERR "perl $0 -o outputfile\n";
281 exit 1;