1cdf0e10cSrcweir#!/usr/solar/bin/perl 2cdf0e10cSrcweir 3*7e90fac2SAndrew Rist#************************************************************** 4*7e90fac2SAndrew Rist# 5*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 6*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 7*7e90fac2SAndrew Rist# distributed with this work for additional information 8*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 9*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 10*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 11*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 12*7e90fac2SAndrew Rist# 13*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 14*7e90fac2SAndrew Rist# 15*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 16*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 17*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 19*7e90fac2SAndrew Rist# specific language governing permissions and limitations 20*7e90fac2SAndrew Rist# under the License. 21*7e90fac2SAndrew Rist# 22*7e90fac2SAndrew Rist#************************************************************** 23cdf0e10cSrcweir 24cdf0e10cSrcweirif ( $#ARGV != 3 ) { 25cdf0e10cSrcweir print STDERR "usage: cl2c.pl <file.cl> <file.c> <file.src> <resname>\n"; 26cdf0e10cSrcweir exit -1; 27cdf0e10cSrcweir} 28cdf0e10cSrcweir 29cdf0e10cSrcweir$CL=$ARGV[0]; 30cdf0e10cSrcweir$C=$ARGV[1]; 31cdf0e10cSrcweir$SRC=$ARGV[2]; 32cdf0e10cSrcweir$RNAME=$ARGV[3]; 33cdf0e10cSrcweir 34cdf0e10cSrcweirsub sconv 35cdf0e10cSrcweir{ 36cdf0e10cSrcweir local($s)=@_[0]; 37cdf0e10cSrcweir local($o,$c); 38cdf0e10cSrcweir $_=""; 39cdf0e10cSrcweir foreach $o ( unpack("C*",$s) ) { 40cdf0e10cSrcweir $c=chr($o); 41cdf0e10cSrcweir if ( $o >= 32 && $o < 127 ) { 42cdf0e10cSrcweir $_ .= $c; 43cdf0e10cSrcweir } else { 44cdf0e10cSrcweir $_ .= sprintf("\\%o", $o); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir } 47cdf0e10cSrcweir return $_; 48cdf0e10cSrcweir} 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweirsub makeneutral { 52cdf0e10cSrcweir 53cdf0e10cSrcweir print COUT "\n\n/**\n"; 54cdf0e10cSrcweir print COUT " * Get neutral language for specific language.\n"; 55cdf0e10cSrcweir print COUT " * This simplifies the getText switch cases and allows to handle\n"; 56cdf0e10cSrcweir print COUT " * previously unknown language derivates due to foreign installations.\n"; 57cdf0e10cSrcweir print COUT " * If you want to distinguish between some dialects change this function\n"; 58cdf0e10cSrcweir print COUT " * to return the desired nLang before doing the bit masking stuff.\n"; 59cdf0e10cSrcweir print COUT " * See xlang.h for defined LANGUAGE_*\n"; 60cdf0e10cSrcweir print COUT " */\n"; 61cdf0e10cSrcweir 62cdf0e10cSrcweir # taken from tools/source/intntl/intn.cxx International::GetNeutralLanguage 63cdf0e10cSrcweir print COUT "static USHORT GetNeutralLanguage( USHORT nLang )\n"; 64cdf0e10cSrcweir print COUT "{\n"; 65cdf0e10cSrcweir print COUT "\tUSHORT nPrimLang;\n"; 66cdf0e10cSrcweir print COUT "\n"; 67cdf0e10cSrcweir print COUT "\t/* ignore LANGUAGE_USER* */\n"; 68cdf0e10cSrcweir print COUT "\tif ( (nLang & 0x03FF) >= 0x0200 )\n"; 69cdf0e10cSrcweir print COUT "\t return nLang;\n"; 70cdf0e10cSrcweir print COUT "\n"; 71cdf0e10cSrcweir print COUT "\tnLang &= 0x03FF;\n"; 72cdf0e10cSrcweir print COUT "\n"; 73cdf0e10cSrcweir print COUT "\tnPrimLang = nLang | 0x0400;\n"; 74cdf0e10cSrcweir print COUT "\n"; 75cdf0e10cSrcweir print COUT "\tswitch ( nPrimLang )\n"; 76cdf0e10cSrcweir print COUT "\t{\n"; 77cdf0e10cSrcweir print COUT "\t\tcase LANGUAGE_CHINESE_TRADITIONAL:\n"; 78cdf0e10cSrcweir print COUT "\t\t\tnLang = LANGUAGE_CHINESE;\n"; 79cdf0e10cSrcweir print COUT "\t\t\tbreak;\n"; 80cdf0e10cSrcweir print COUT "\t\tcase LANGUAGE_ENGLISH_US:\n"; 81cdf0e10cSrcweir print COUT "\t\t\tnLang = LANGUAGE_ENGLISH;\n"; 82cdf0e10cSrcweir print COUT "\t\t\tbreak;\n"; 83cdf0e10cSrcweir print COUT "\t\tcase LANGUAGE_NORWEGIAN_BOKMAL:\n"; 84cdf0e10cSrcweir print COUT "\t\t\tnLang = LANGUAGE_NORWEGIAN;\n"; 85cdf0e10cSrcweir print COUT "\t\t\tbreak;\n"; 86cdf0e10cSrcweir print COUT "\t\tcase LANGUAGE_PORTUGUESE_BRAZILIAN:\n"; 87cdf0e10cSrcweir print COUT "\t\t\tnLang = LANGUAGE_PORTUGUESE;\n"; 88cdf0e10cSrcweir print COUT "\t\t\tbreak;\n"; 89cdf0e10cSrcweir print COUT "\n"; 90cdf0e10cSrcweir print COUT "\t\tdefault:\n"; 91cdf0e10cSrcweir print COUT "\t\t\tnLang = nPrimLang;\n"; 92cdf0e10cSrcweir print COUT "\t\t\tbreak;\n"; 93cdf0e10cSrcweir print COUT "\t}\n"; 94cdf0e10cSrcweir print COUT "\n"; 95cdf0e10cSrcweir print COUT "\treturn nLang;\n"; 96cdf0e10cSrcweir print COUT "}\n"; 97cdf0e10cSrcweir print COUT "\n"; 98cdf0e10cSrcweir 99cdf0e10cSrcweir} 100cdf0e10cSrcweir 101cdf0e10cSrcweir 102cdf0e10cSrcweirsub maketext { 103cdf0e10cSrcweir 104cdf0e10cSrcweir print COUT "\n\n/**\n"; 105cdf0e10cSrcweir print COUT " * Get text resource for current language.\n"; 106cdf0e10cSrcweir print COUT " * Remember that 8-bit characters are shown in\n"; 107cdf0e10cSrcweir print COUT " * system dependend code pages!\n"; 108cdf0e10cSrcweir print COUT " * To get correct results you will have to distuinguish\n"; 109cdf0e10cSrcweir print COUT " * for example between UNIX and WIN and OS2 target systems.\n"; 110cdf0e10cSrcweir print COUT " */\n"; 111cdf0e10cSrcweir 112cdf0e10cSrcweir print COUT "static char* getText( int nResource )\n{\n"; 113cdf0e10cSrcweir print COUT "\tswitch( nResource ) {\n"; 114cdf0e10cSrcweir 115cdf0e10cSrcweir $resflag=0; 116cdf0e10cSrcweir $strname=""; 117cdf0e10cSrcweir $cnt=0; 118cdf0e10cSrcweir $text_english=""; 119cdf0e10cSrcweir 120cdf0e10cSrcweir while (<SRCIN>) { 121cdf0e10cSrcweir $resflag=1 if ( /Resource\s$RNAME/ ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir if ( /\{/ ) { 124cdf0e10cSrcweir if ( ++$cnt == 2 ) { 125cdf0e10cSrcweir # start language 126cdf0e10cSrcweir $text_english=""; 127cdf0e10cSrcweir print COUT "\t\t\tswitch( _nLanguage ) {\n"; 128cdf0e10cSrcweir next; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir if ( /\}/ ) { 133cdf0e10cSrcweir if ( --$cnt == 1 ) { 134cdf0e10cSrcweir # end language 135cdf0e10cSrcweir 136cdf0e10cSrcweir if ( $text_english ne "" ) { 137cdf0e10cSrcweir print COUT "\t\t\t\tcase LANGUAGE_ENGLISH:\n\t\t\t\tdefault:\n"; 138cdf0e10cSrcweir print COUT "\t\t\t\treturn(" . $text_english . ")\;\n"; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir print COUT "\t\t\t}\n\t\t\tbreak;\n"; 142cdf0e10cSrcweir next; 143cdf0e10cSrcweir } elsif ( $cnt == 0 ) { 144cdf0e10cSrcweir # end of resource 145cdf0e10cSrcweir $resflag=0; 146cdf0e10cSrcweir print COUT "\t\tdefault:\n\t\t\tbreak;\n"; 147cdf0e10cSrcweir print COUT "\t}\n\treturn(\"\");\n}\n"; 148cdf0e10cSrcweir next; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir if ( $resflag && $cnt == 1) { 154cdf0e10cSrcweir if ( /\sString\s(([A-Z]|\_|[0-9]|[a-z])*)/ ) { 155cdf0e10cSrcweir $strname=$1; 156cdf0e10cSrcweir print COUT "\t\tcase " . $strname . ":\n"; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir if ( $cnt == 2 && /^\s*Text/ ) { 161cdf0e10cSrcweir $langname="german"; 162cdf0e10cSrcweir ($textdef,@textx)=split(/=/); 163cdf0e10cSrcweir $text=join("=",@textx); 164cdf0e10cSrcweir if ( $textdef =~ /\[\s+(.*)\s+\]/ ) { 165cdf0e10cSrcweir $langname=$1; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir else { 168cdf0e10cSrcweir $langname="ENGLISH_US"; # no [...] => not to be translated 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir $langname="LANGUAGE_" . uc($langname); 172cdf0e10cSrcweir 173cdf0e10cSrcweir chop($text) while ( $text=~/(\r|\n|\;)$/ ); 174cdf0e10cSrcweir $text=sconv($text); 175cdf0e10cSrcweir # english_us, not english because it's developer's pigeon 176cdf0e10cSrcweir if ( $langname eq "LANGUAGE_ENGLISH_US" ) { 177cdf0e10cSrcweir $text_english=$text; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir # ISO coded, obtain at least the default 180cdf0e10cSrcweir elsif ( $langname =~ /^LANGUAGE_EN-US$/ ) { 181cdf0e10cSrcweir $text_english=$text; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir # we don't know about USER languages, ENGLISH will be appended later 184cdf0e10cSrcweir elsif ( ! ( $langname =~ /LANGUAGE_USER/ || $langname =~ /^LANGUAGE_ENGLISH$/ ) ) { 185cdf0e10cSrcweir # ER 28.04.99: for the moment only German and English are 186cdf0e10cSrcweir # exported, because we have a problem with non-existing 187cdf0e10cSrcweir # character code tables for systems other than Windoze. 188cdf0e10cSrcweir # => Chinese would be definitely mixed up and we don't 189cdf0e10cSrcweir # want to insult anybody.. others like Spanish would look 190cdf0e10cSrcweir # very ugly, but we'll have to live with bad German Umlauts. 191cdf0e10cSrcweir if ( $langname =~ /LANGUAGE_(GERMAN|ENGLISH)/ ) { 192cdf0e10cSrcweir print COUT "\t\t\t\tcase " . $langname . ":\n"; 193cdf0e10cSrcweir print COUT "\t\t\t\treturn(" . $text . ")\;\n"; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir makeneutral(); 201cdf0e10cSrcweir 202cdf0e10cSrcweir} 203cdf0e10cSrcweir 204cdf0e10cSrcweiropen(CLIN,"<$CL") || die "can not open $CL\n"; 205cdf0e10cSrcweiropen(SRCIN,"<$SRC") || die "can not open $CL\n"; 206cdf0e10cSrcweiropen(COUT,">$C") || die "can not open $CL\n"; 207cdf0e10cSrcweir 208cdf0e10cSrcweir$ccnt=0; 209cdf0e10cSrcweir$incomment=0; 210cdf0e10cSrcweirwhile(<CLIN>) { 211cdf0e10cSrcweir if ( /^\/\*--(-*)/ ) { 212cdf0e10cSrcweir $incomment=1; 213cdf0e10cSrcweir $ccnt++; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir print COUT $_ if ( $incomment==0 || $ccnt==1 ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir &maketext() if ( /^static USHORT _nLanguage=/ ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir if ( /(-*)--\*\/$/ ) { 221cdf0e10cSrcweir $incomment=0; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir} 225cdf0e10cSrcweir 226cdf0e10cSrcweirclose(CLIN); 227cdf0e10cSrcweirclose(SRCIN); 228cdf0e10cSrcweirclose(COUT); 229cdf0e10cSrcweir 230cdf0e10cSrcweirexit 0; 231cdf0e10cSrcweir 232cdf0e10cSrcweir 233