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