1#!/usr/solar/bin/perl 2 3########################################################################## 4# 5# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6# 7# Copyright 2000, 2010 Oracle and/or its affiliates. 8# 9# OpenOffice.org - a multi-platform office productivity suite 10# 11# This file is part of OpenOffice.org. 12# 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. 16# 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). 22# 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. 27# 28########################################################################## 29 30if ( $#ARGV != 3 ) { 31 print STDERR "usage: cl2c.pl <file.cl> <file.c> <file.src> <resname>\n"; 32 exit -1; 33} 34 35$CL=$ARGV[0]; 36$C=$ARGV[1]; 37$SRC=$ARGV[2]; 38$RNAME=$ARGV[3]; 39 40sub sconv 41{ 42 local($s)=@_[0]; 43 local($o,$c); 44 $_=""; 45 foreach $o ( unpack("C*",$s) ) { 46 $c=chr($o); 47 if ( $o >= 32 && $o < 127 ) { 48 $_ .= $c; 49 } else { 50 $_ .= sprintf("\\%o", $o); 51 } 52 } 53 return $_; 54} 55 56 57sub makeneutral { 58 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"; 66 print COUT " */\n"; 67 68 # taken from tools/source/intntl/intn.cxx International::GetNeutralLanguage 69 print COUT "static USHORT GetNeutralLanguage( USHORT nLang )\n"; 70 print COUT "{\n"; 71 print COUT "\tUSHORT nPrimLang;\n"; 72 print COUT "\n"; 73 print COUT "\t/* ignore LANGUAGE_USER* */\n"; 74 print COUT "\tif ( (nLang & 0x03FF) >= 0x0200 )\n"; 75 print COUT "\t return nLang;\n"; 76 print COUT "\n"; 77 print COUT "\tnLang &= 0x03FF;\n"; 78 print COUT "\n"; 79 print COUT "\tnPrimLang = nLang | 0x0400;\n"; 80 print COUT "\n"; 81 print COUT "\tswitch ( nPrimLang )\n"; 82 print COUT "\t{\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"; 95 print COUT "\n"; 96 print COUT "\t\tdefault:\n"; 97 print COUT "\t\t\tnLang = nPrimLang;\n"; 98 print COUT "\t\t\tbreak;\n"; 99 print COUT "\t}\n"; 100 print COUT "\n"; 101 print COUT "\treturn nLang;\n"; 102 print COUT "}\n"; 103 print COUT "\n"; 104 105} 106 107 108sub maketext { 109 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"; 116 print COUT " */\n"; 117 118 print COUT "static char* getText( int nResource )\n{\n"; 119 print COUT "\tswitch( nResource ) {\n"; 120 121 $resflag=0; 122 $strname=""; 123 $cnt=0; 124 $text_english=""; 125 126 while (<SRCIN>) { 127 $resflag=1 if ( /Resource\s$RNAME/ ); 128 129 if ( /\{/ ) { 130 if ( ++$cnt == 2 ) { 131 # start language 132 $text_english=""; 133 print COUT "\t\t\tswitch( _nLanguage ) {\n"; 134 next; 135 } 136 } 137 138 if ( /\}/ ) { 139 if ( --$cnt == 1 ) { 140 # end language 141 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"; 145 } 146 147 print COUT "\t\t\t}\n\t\t\tbreak;\n"; 148 next; 149 } elsif ( $cnt == 0 ) { 150 # end of resource 151 $resflag=0; 152 print COUT "\t\tdefault:\n\t\t\tbreak;\n"; 153 print COUT "\t}\n\treturn(\"\");\n}\n"; 154 next; 155 } 156 157 } 158 159 if ( $resflag && $cnt == 1) { 160 if ( /\sString\s(([A-Z]|\_|[0-9]|[a-z])*)/ ) { 161 $strname=$1; 162 print COUT "\t\tcase " . $strname . ":\n"; 163 } 164 } 165 166 if ( $cnt == 2 && /^\s*Text/ ) { 167 $langname="german"; 168 ($textdef,@textx)=split(/=/); 169 $text=join("=",@textx); 170 if ( $textdef =~ /\[\s+(.*)\s+\]/ ) { 171 $langname=$1; 172 } 173 else { 174 $langname="ENGLISH_US"; # no [...] => not to be translated 175 } 176 177 $langname="LANGUAGE_" . uc($langname); 178 179 chop($text) while ( $text=~/(\r|\n|\;)$/ ); 180 $text=sconv($text); 181 # english_us, not english because it's developer's pigeon 182 if ( $langname eq "LANGUAGE_ENGLISH_US" ) { 183 $text_english=$text; 184 } 185 # ISO coded, obtain at least the default 186 elsif ( $langname =~ /^LANGUAGE_EN-US$/ ) { 187 $text_english=$text; 188 } 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"; 200 } 201 } 202 203 } 204 } 205 206 makeneutral(); 207 208} 209 210open(CLIN,"<$CL") || die "can not open $CL\n"; 211open(SRCIN,"<$SRC") || die "can not open $CL\n"; 212open(COUT,">$C") || die "can not open $CL\n"; 213 214$ccnt=0; 215$incomment=0; 216while(<CLIN>) { 217 if ( /^\/\*--(-*)/ ) { 218 $incomment=1; 219 $ccnt++; 220 } 221 222 print COUT $_ if ( $incomment==0 || $ccnt==1 ); 223 224 &maketext() if ( /^static USHORT _nLanguage=/ ); 225 226 if ( /(-*)--\*\/$/ ) { 227 $incomment=0; 228 } 229 230} 231 232close(CLIN); 233close(SRCIN); 234close(COUT); 235 236exit 0; 237 238 239