3 ##########################################################################
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
13 # OpenOffice.org is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License version 3
15 # only, as published by the Free Software Foundation.
17 # OpenOffice.org is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Lesser General Public License version 3 for more details
21 # (a copy is included in the LICENSE file that accompanied this code).
23 # You should have received a copy of the GNU Lesser General Public License
24 # version 3 along with OpenOffice.org. If not, see
25 # <http://www.openoffice.org/license.html>
26 # for a copy of the LGPLv3 License.
28 ##########################################################################
31 print STDERR
"usage: cl2c.pl <file.cl> <file.c> <file.src> <resname>\n";
45 foreach $o ( unpack("C*",$s) ) {
47 if ( $o >= 32 && $o < 127 ) {
50 $_ .= sprintf("\\%o", $o);
59 print COUT
"\n\n/**\n";
60 print COUT
" * Get neutral language for specific language.\n";
61 print COUT
" * This simplifies the getText switch cases and allows to handle\n";
62 print COUT
" * previously unknown language derivates due to foreign installations.\n";
63 print COUT
" * If you want to distinguish between some dialects change this function\n";
64 print COUT
" * to return the desired nLang before doing the bit masking stuff.\n";
65 print COUT
" * See xlang.h for defined LANGUAGE_*\n";
68 # taken from tools/source/intntl/intn.cxx International::GetNeutralLanguage
69 print COUT
"static USHORT GetNeutralLanguage( USHORT nLang )\n";
71 print COUT
"\tUSHORT nPrimLang;\n";
73 print COUT
"\t/* ignore LANGUAGE_USER* */\n";
74 print COUT
"\tif ( (nLang & 0x03FF) >= 0x0200 )\n";
75 print COUT
"\t return nLang;\n";
77 print COUT
"\tnLang &= 0x03FF;\n";
79 print COUT
"\tnPrimLang = nLang | 0x0400;\n";
81 print COUT
"\tswitch ( nPrimLang )\n";
83 print COUT
"\t\tcase LANGUAGE_CHINESE_TRADITIONAL:\n";
84 print COUT
"\t\t\tnLang = LANGUAGE_CHINESE;\n";
85 print COUT
"\t\t\tbreak;\n";
86 print COUT
"\t\tcase LANGUAGE_ENGLISH_US:\n";
87 print COUT
"\t\t\tnLang = LANGUAGE_ENGLISH;\n";
88 print COUT
"\t\t\tbreak;\n";
89 print COUT
"\t\tcase LANGUAGE_NORWEGIAN_BOKMAL:\n";
90 print COUT
"\t\t\tnLang = LANGUAGE_NORWEGIAN;\n";
91 print COUT
"\t\t\tbreak;\n";
92 print COUT
"\t\tcase LANGUAGE_PORTUGUESE_BRAZILIAN:\n";
93 print COUT
"\t\t\tnLang = LANGUAGE_PORTUGUESE;\n";
94 print COUT
"\t\t\tbreak;\n";
96 print COUT
"\t\tdefault:\n";
97 print COUT
"\t\t\tnLang = nPrimLang;\n";
98 print COUT
"\t\t\tbreak;\n";
101 print COUT
"\treturn nLang;\n";
110 print COUT
"\n\n/**\n";
111 print COUT
" * Get text resource for current language.\n";
112 print COUT
" * Remember that 8-bit characters are shown in\n";
113 print COUT
" * system dependend code pages!\n";
114 print COUT
" * To get correct results you will have to distuinguish\n";
115 print COUT
" * for example between UNIX and WIN and OS2 target systems.\n";
118 print COUT
"static char* getText( int nResource )\n{\n";
119 print COUT
"\tswitch( nResource ) {\n";
127 $resflag=1 if ( /Resource\s$RNAME/ );
133 print COUT
"\t\t\tswitch( _nLanguage ) {\n";
142 if ( $text_english ne "" ) {
143 print COUT
"\t\t\t\tcase LANGUAGE_ENGLISH:\n\t\t\t\tdefault:\n";
144 print COUT
"\t\t\t\treturn(" . $text_english . ")\;\n";
147 print COUT
"\t\t\t}\n\t\t\tbreak;\n";
149 } elsif ( $cnt == 0 ) {
152 print COUT
"\t\tdefault:\n\t\t\tbreak;\n";
153 print COUT
"\t}\n\treturn(\"\");\n}\n";
159 if ( $resflag && $cnt == 1) {
160 if ( /\sString\s(([A-Z]|\_|[0-9]|[a-z])*)/ ) {
162 print COUT
"\t\tcase " . $strname . ":\n";
166 if ( $cnt == 2 && /^\s*Text/ ) {
168 ($textdef,@textx)=split(/=/);
169 $text=join("=",@textx);
170 if ( $textdef =~ /\[\s+(.*)\s+\]/ ) {
174 $langname="ENGLISH_US"; # no [...] => not to be translated
177 $langname="LANGUAGE_" . uc($langname);
179 chop($text) while ( $text=~/(\r|\n|\;)$/ );
181 # english_us, not english because it's developer's pigeon
182 if ( $langname eq "LANGUAGE_ENGLISH_US" ) {
185 # ISO coded, obtain at least the default
186 elsif ( $langname =~ /^LANGUAGE_EN-US$/ ) {
189 # we don't know about USER languages, ENGLISH will be appended later
190 elsif ( ! ( $langname =~ /LANGUAGE_USER/ || $langname =~ /^LANGUAGE_ENGLISH$/ ) ) {
191 # ER 28.04.99: for the moment only German and English are
192 # exported, because we have a problem with non-existing
193 # character code tables for systems other than Windoze.
194 # => Chinese would be definitely mixed up and we don't
195 # want to insult anybody.. others like Spanish would look
196 # very ugly, but we'll have to live with bad German Umlauts.
197 if ( $langname =~ /LANGUAGE_(GERMAN|ENGLISH)/ ) {
198 print COUT
"\t\t\t\tcase " . $langname . ":\n";
199 print COUT
"\t\t\t\treturn(" . $text . ")\;\n";
210 open(CLIN
,"<$CL") || die "can not open $CL\n";
211 open(SRCIN
,"<$SRC") || die "can not open $CL\n";
212 open(COUT
,">$C") || die "can not open $CL\n";
217 if ( /^\/\
*--(-*)/ ) {
222 print COUT
$_ if ( $incomment==0 || $ccnt==1 );
224 &maketext
() if ( /^static USHORT _nLanguage=/ );
226 if ( /(-*)--\*\/$/ ) {