NameContainer need not be an UNO object itself
[LibreOffice.git] / scp2 / macros / macro.pl
blob38ea02eb31dc9e7c30bdcfcf4fcb8b41fac99499
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 my $outfile;
20 my $destfile;
21 my $config_stamp;
22 my $lastcompletelangiso_var;
23 my $completelangiso_var = $ENV{COMPLETELANGISO_VAR};
24 my $help_langs_var = $ENV{HELP_LANGS};
26 if ( !defined $completelangiso_var) {
27 print STDERR "ERROR: No language defined!\n";
28 exit 1;
31 if (!args_require_build()) {
32 print STDERR "No new languages, or config. Keeping old file\n";
33 exit 0;
36 my @completelangiso = split " +", $completelangiso_var;
37 my @helplangs = split " +", $help_langs_var;
39 open OUTFILE, ">$outfile" or die "$0 ERROR: cannot open $outfile for writing!\n";
41 print OUTFILE "// generated file, do not edit\n\n";
42 print OUTFILE "// languages used for last time generation\n";
43 print OUTFILE "// completelangiso: $completelangiso_var\n\n";
44 print OUTFILE "// help_langs: $help_langs_var\n\n";
45 write_ITERATE_ALL_LANG();
46 write_ALL_LANG();
47 write_OTHER_LANGS();
48 write_DIR_ISOLANGUAGE_ALL_LANG_2();
49 write_DIR_ISOLANGUAGE_ALL_LANG();
50 write_EXTRA_ALL_LANG();
51 write_EXTRA_ALL_LANG_BUT_EN_US();
52 write_MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ();
53 write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG();
54 write_RESFILE_ALL_LANG();
55 write_README_ALL_LANG();
56 write_README_TXT_ALL_LANG();
57 write_FILE_ALL_LANG_LETTER();
59 close OUTFILE;
61 rename $outfile, $destfile;
63 sub write_ITERATE_ALL_LANG
65 print OUTFILE "#define ITERATE_ALL_LANG_FILE(gid,dir,macro,name,ext) ";
66 foreach $lang (@helplangs) {
67 my $shortlang = $lang;
68 $shortlang = "en" if $shortlang eq "en-US";
69 my $speciallang = $lang;
70 $speciallang =~ s/-/_/;
71 print OUTFILE "\\\nFile CONCAT3(gid_File_,gid,_$speciallang)";
72 print OUTFILE "\\\n\tDir = CONCAT3(gid_Dir_,dir,_$speciallang);";
73 print OUTFILE "\\\n\tmacro;";
74 print OUTFILE "\\\n\tName = STRING(CONCAT3(name,_$lang,ext)); ";
75 print OUTFILE "\\\nEnd ";
76 print OUTFILE "\\\n";
78 print OUTFILE "\n\n";
81 sub write_ALL_LANG
83 print OUTFILE "#define ALL_LANG(ident, resid) ";
84 foreach $lang (@completelangiso) {
85 print OUTFILE "\\\n\tident ($lang) = resid";
86 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
88 print OUTFILE "\n\n";
91 sub write_OTHER_LANGS
93 print OUTFILE "#define OTHER_LANGS ";
94 foreach $lang (@completelangiso) {
95 next if ( $lang eq "en-US");
96 print OUTFILE "\\\n\tDosName ($lang) = \"$lang\"";
97 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
99 print OUTFILE "\n\n";
102 sub write_DIR_ISOLANGUAGE_ALL_LANG_2
104 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG_2 ";
105 print OUTFILE "\\\n\tDosName (en-US) = \"en-US\"; \\\n\t";
106 print OUTFILE "OTHER_LANGS";
107 print OUTFILE "\n\n";
110 sub write_DIR_ISOLANGUAGE_ALL_LANG
112 print OUTFILE "#define DIR_ISOLANGUAGE_ALL_LANG ";
113 print OUTFILE "\\\n\tDosName (en-US) = \"en\"; \\\n\t";
114 print OUTFILE "OTHER_LANGS";
115 print OUTFILE "\n\n";
118 sub write_EXTRA_ALL_LANG
120 print OUTFILE "#define EXTRA_ALL_LANG(name,ext) ";
121 foreach $lang (@completelangiso) {
122 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
123 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
125 print OUTFILE "\n\n";
128 sub write_EXTRA_ALL_LANG_BUT_EN_US
130 print OUTFILE "#define EXTRA_ALL_LANG_BUT_EN_US(name,ext) ";
131 my $first = 1;
132 foreach $lang (@completelangiso) {
133 if ($lang ne "en-US") {
134 print OUTFILE "; " unless $first;
135 $first = 0;
136 print OUTFILE
137 "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,_$lang,ext)";
140 print OUTFILE "\n\n";
143 sub write_MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ
145 print OUTFILE "#define MO_ALL_LANG_EXCEPT_EN_US_AND_QTZ(name) ";
146 my $first = 1;
147 foreach $lang (@completelangiso) {
148 if (($lang ne "en-US") and ($lang ne "qtz")) {
149 print OUTFILE "; " unless $first;
150 $first = 0;
151 my $SRC_ROOT = $ENV{"SRC_ROOT"};
152 my $langdir = `$SRC_ROOT/solenv/bin/localestr $lang`;
153 chomp $langdir;
154 print OUTFILE
155 "\\\n\tName ($lang) = STRING(CONCAT3($langdir/LC_MESSAGES/,name,.mo))";
158 print OUTFILE "\n\n";
161 sub write_EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG
163 my $first = 1;
164 my $source;
165 if ($ENV{'ENABLE_HTMLHELP'} eq 'TRUE') {
166 $source = 'html-help'; # found in instsetoo_native/util/openoffice.lst.in's {filelistpath}/CustomTarget/helpcontent2/help3xsl/filelists
167 } else {
168 $source = 'HelpTarget';
170 print OUTFILE "#define EXTRA_ALL_GOOD_HELP_LOCALIZATIONS_LANG(name) ";
171 foreach $lang (@helplangs) {
172 print OUTFILE ";" unless $first;
173 $first = 0;
174 print OUTFILE "\\\n\tName ($lang) = EXTRAFILELISTNAME($source/,name,/$lang)";
176 print OUTFILE "\n\n";
179 sub write_RESFILE_ALL_LANG
181 print OUTFILE "#define RESFILE_ALL_LANG(name) ";
182 foreach $lang (@completelangiso) {
183 print OUTFILE "\\\n\tName ($lang) = RESFILENAME(name,$lang)";
184 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
186 print OUTFILE "\n\n";
189 sub write_README_ALL_LANG
191 print OUTFILE "#define README_ALL_LANG(key, name) ";
192 foreach $lang (@completelangiso) {
193 print OUTFILE "\\\n\tkey ($lang) = READMEFILENAME(name,_$lang)";
194 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
196 print OUTFILE "\n\n";
199 sub write_README_TXT_ALL_LANG
201 print OUTFILE "#define README_TXT_ALL_LANG(key, name, ext) ";
202 foreach $lang (@completelangiso) {
203 print OUTFILE "\\\n\tkey ($lang) = READMETXTFILENAME(name,_$lang,ext)";
204 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
206 print OUTFILE "\n\n";
209 sub write_FILE_ALL_LANG_LETTER
211 print OUTFILE "#define FILE_ALL_LANG_LETTER(name, ext) ";
212 foreach $lang (@completelangiso) {
213 print OUTFILE "\\\n\tName ($lang) = CONFIGLANGFILENAME(name,$lang,ext)";
214 print OUTFILE "; " if ( $lang ne $completelangiso[$#completelangiso]);
216 print OUTFILE "\n\n";
219 sub args_require_build
221 while (@ARGV) {
222 $opt = shift @ARGV;
223 $destfile = shift @ARGV if ($opt eq '-o');
224 $config_stamp = shift @ARGV if ($opt eq '-c');
226 usage() if (!defined ($destfile) || !defined ($config_stamp));
227 $outfile = "$destfile.tmp";
229 if ( -f "$destfile" ) {
230 # changed script - run always
231 return 1 if (stat($0))[9] > (stat("$destfile"))[9] ;
233 # changed config timestamp - run always
234 if (-f "$config_stamp") {
235 return 1 if (stat($config_stamp))[9] > (stat($destfile))[9];
238 open OLDFILE, "$destfile" or die "$0 - ERROR: $outfile exists but isn't readable.\n";
239 while ( $line = <OLDFILE> ) {
240 if ( $line =~ /^\/\/.*completelangiso:/ ) {
241 $lastcompletelangiso_var = $line;
242 chomp $lastcompletelangiso_var;
243 $lastcompletelangiso_var =~ s/^\/\/.*completelangiso:\s*//;
244 last;
248 close OLDFILE;
250 return 0 if ( "$completelangiso_var" eq "$lastcompletelangiso_var" );
252 return 1;
255 sub usage
257 print STDERR "Generate language dependent macros use in *.scp files\n";
258 print STDERR "perl $0 -o <outputfile> -c <config_stamp_file>\n";
259 exit 1;