You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ja...@apache.org on 2013/01/24 13:21:39 UTC
svn commit: r1437973 [8/11] - in
/openoffice/branches/l10n/main/l10ntools/source: ./ filter/ filter/merge/
filter/utils/ help/
Added: openoffice/branches/l10n/main/l10ntools/source/helpmerge.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/helpmerge.cxx?rev=1437973&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/helpmerge.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/helpmerge.cxx Thu Jan 24 12:21:38 2013
@@ -0,0 +1,712 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_l10ntools.hxx"
+#include <tools/fsys.hxx>
+#include <osl/file.hxx>
+// local includes
+#include <stdio.h>
+#include <stdlib.h>
+#include "helpmerge.hxx"
+#include "utf8conv.hxx"
+#include <algorithm>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include "rtl/strbuf.hxx"
+#ifdef WNT
+#include <direct.h>
+//#include <WinBase.h>
+#include "tools/prewin.h"
+#include <windows.h>
+#include "tools/postwin.h"
+#endif
+
+/*****************************************************************************/
+void HelpParser::FillInFallbacks( LangHashMap& rElem_out, ByteString sLangIdx_in ){
+/*****************************************************************************/
+ static const ByteString ENGLISH_LANGUAGECODE( "en-US" );
+ static const ByteString GERMAN_LANGUAGECODE ( "de" );
+ ByteString sCur;
+ XMLElement* pTmp = NULL;
+ XMLElement* pTmp2 = NULL;
+
+ sCur = sLangIdx_in;
+ ByteString sFallback( sCur );
+ GetIsoFallback( sFallback );
+ if( (rElem_out.find( sFallback ) != rElem_out.end()) && rElem_out[ sFallback ] != NULL ){
+ pTmp2 = rElem_out[ sFallback ];
+ pTmp = new XMLElement( *pTmp2 ) ; // Copy
+ pTmp->SetPos( pTmp2->GetPos()+1 );
+ pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US) );
+ rElem_out[ sLangIdx_in ] = pTmp;
+ pTmp2 = NULL;
+ }
+ else if( (rElem_out.find( ENGLISH_LANGUAGECODE ) != rElem_out.end()) && rElem_out[ ENGLISH_LANGUAGECODE ] != NULL ){// No English
+ pTmp2 = rElem_out[ ENGLISH_LANGUAGECODE ];
+ pTmp = new XMLElement( *pTmp2 ) ; // Copy
+ pTmp->SetPos( pTmp2->GetPos()+1 );
+ pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US) );
+ rElem_out[ sCur ] = pTmp;
+ pTmp2 = NULL;
+ }
+ else if( (rElem_out.find( GERMAN_LANGUAGECODE ) != rElem_out.end() ) && rElem_out[ GERMAN_LANGUAGECODE ] != NULL ){// No English
+ pTmp2 = rElem_out[ GERMAN_LANGUAGECODE ];
+ pTmp = new XMLElement( *pTmp2 ); // Copy
+ pTmp->SetPos( pTmp2->GetPos()+1 );
+ pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US ) );
+ rElem_out[ sCur ] = pTmp;
+ pTmp2 = NULL;
+ }else{
+ fprintf(stdout,"ERROR: No Fallback found for language %s:\n",sCur.GetBuffer());
+ rElem_out[ sCur ]=new XMLElement(); // Use dummy element
+ }
+}
+
+/*****************************************************************************/
+void HelpParser::Dump(XMLHashMap* rElem_in) {
+/*****************************************************************************/
+ for(XMLHashMap::iterator pos = rElem_in->begin();pos != rElem_in->end(); ++pos){
+ Dump(pos->second,pos->first);
+ }
+}
+/*****************************************************************************/
+void HelpParser::Dump(LangHashMap* rElem_in,const ByteString sKey_in) {
+/*****************************************************************************/
+ ByteString x;
+ OString y;
+ fprintf(stdout,"+------------%s-----------+\n",sKey_in.GetBuffer() );
+ for(LangHashMap::iterator posn=rElem_in->begin();posn!=rElem_in->end();++posn){
+ x=posn->first;
+ y=posn->second->ToOString();
+ fprintf(stdout,"key=%s value=%s\n",x.GetBuffer(),y.getStr());
+ }
+ fprintf(stdout,"+--------------------------+\n");
+}
+
+HelpParser::HelpParser( const ByteString &rHelpFile, bool rUTF8 , bool rHasInputList )
+ : sHelpFile( rHelpFile ),
+ bUTF8 ( rUTF8 ),
+ bHasInputList( rHasInputList )
+ {};
+
+/*****************************************************************************/
+bool HelpParser::CreateSDF(
+/*****************************************************************************/
+ const ByteString &rSDFFile_in, const ByteString &rPrj_in,const ByteString &rRoot_in,
+ const ByteString &sHelpFile, XMLFile *pXmlFile, const ByteString &rGsi1){
+ // GSI File constants
+ static const String GSI_SEQUENCE1( String::CreateFromAscii("\t0\t") );
+ static const String GSI_SEQUENCE2( String::CreateFromAscii("\t\t\t0\t") );
+ static const String GSI_TAB ( String::CreateFromAscii("\t") );
+ static const String GSI_SEQUENCE4( String::CreateFromAscii("\t\t\t\t") );
+ static const String ret ( String::CreateFromAscii("\n") );
+ static const String ret_char ( String::CreateFromAscii("") );
+ static const String tab ( String::CreateFromAscii("\t") );
+ static const String tab_char ( String::CreateFromAscii("") );
+
+ SimpleXMLParser aParser;
+ String sUsedTempFile;
+ String sXmlFile;
+
+ if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ){
+ DirEntry aTempFile = Export::GetTempFile();
+ DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) );
+ aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
+ String sTempFile = aTempFile.GetFull();
+ Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) );
+ sUsedTempFile = sTempFile;
+ sXmlFile = sTempFile;
+ }else{
+ sUsedTempFile = String::CreateFromAscii("");
+ sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US );
+ }
+
+// ByteString fullFilePath;
+ //DirEntry aFile( sXmlFile );
+ //makeAbsolutePath( sHelpFile , rRoot_in);
+ ByteString fullFilePath = rPrj_in;
+ fullFilePath.Append( "\\" );
+ fullFilePath.Append( makeAbsolutePath( sHelpFile , rRoot_in ) );
+ fullFilePath.SearchAndReplaceAll( "\\", "/" );
+
+ String strFullPath( fullFilePath.GetBuffer() , RTL_TEXTENCODING_ASCII_US );
+
+ //printf( "%s\n", fullFilePath.GetBuffer() );
+ std::auto_ptr <XMLFile> file ( aParser.Execute( strFullPath , sXmlFile, pXmlFile ) );
+
+ if(file.get() == NULL){
+ printf("%s\n",ByteString(aParser.GetError().sMessage,RTL_TEXTENCODING_ASCII_US).GetBuffer());
+ exit(-1);
+ //return false;
+ }
+ file->Extract();
+ if( !file->CheckExportStatus() ){
+ return true;
+ }
+ SvFileStream aSDFStream( String( rSDFFile_in, RTL_TEXTENCODING_ASCII_US ),
+ STREAM_STD_WRITE | STREAM_TRUNC );
+
+ if ( !aSDFStream.IsOpen()) {
+ fprintf(stdout,"Can't open file %s\n",rSDFFile_in.GetBuffer());
+ return false;
+ }
+
+ ByteString sActFileName = makeAbsolutePath( sHelpFile , rRoot_in );
+
+ XMLHashMap* aXMLStrHM = file->GetStrings();
+ LangHashMap* pElem;
+ XMLElement* pXMLElement = NULL;
+
+ //Dump(aXMLStrHM);
+
+ ByteString sTimeStamp( Export::GetTimeStamp() );
+ OUString sOUTimeStamp( sTimeStamp.GetBuffer() , sTimeStamp.Len() , RTL_TEXTENCODING_ASCII_US );
+
+ OUStringBuffer sBuffer;
+ const OUString sOUPrj( rPrj_in.GetBuffer() , rPrj_in.Len() , RTL_TEXTENCODING_ASCII_US );
+ const OUString sOUActFileName(sActFileName.GetBuffer() , sActFileName.Len() , RTL_TEXTENCODING_ASCII_US );
+ const OUString sOUGsi1( rGsi1.GetBuffer() , rGsi1.Len() , RTL_TEXTENCODING_ASCII_US );
+
+ Export::InitLanguages( false );
+ std::vector<ByteString> aLanguages = Export::GetLanguages();
+
+ std::vector<ByteString> order = file->getOrder();
+ std::vector<ByteString>::iterator pos;
+ XMLHashMap::iterator posm;
+
+ for( pos = order.begin(); pos != order.end() ; ++pos )
+ {
+ posm = aXMLStrHM->find( *pos );
+ pElem = posm->second;
+ ByteString sCur;
+
+ for( unsigned int n = 0; n < aLanguages.size(); n++ )
+ {
+ sCur = aLanguages[ n ];
+ if(pElem->find( sCur )==pElem->end())
+ {
+ FillInFallbacks( *pElem , sCur );
+ }
+ pXMLElement = (*pElem)[ sCur ];
+
+ if( pXMLElement != NULL )
+ {
+ OUString data = pXMLElement->ToOUString();
+ String sTmp = String(data.getStr());
+ sTmp.SearchAndReplaceAll(ret,ret_char); // Remove \n
+ sTmp.SearchAndReplaceAll(tab,tab_char); // Remove \t
+
+ data = OUString( sTmp );
+ sBuffer.append( sOUPrj );
+ sBuffer.append( GSI_TAB ); //"\t";
+ if ( rRoot_in.Len())
+ sBuffer.append( sOUActFileName );
+ sBuffer.append( GSI_SEQUENCE1 ); //"\t0\t";
+ sBuffer.append( sOUGsi1 ); //"help";
+ sBuffer.append( GSI_TAB ); //"\t";
+ ByteString sID = posm->first; // ID
+ sBuffer.append( OUString( sID.GetBuffer() , sID.Len() , RTL_TEXTENCODING_UTF8 ) );
+ sBuffer.append( GSI_TAB ); //"\t";
+ ByteString sOldRef = pXMLElement->GetOldref(); // oldref
+ sBuffer.append( OUString(sOldRef.GetBuffer() , sOldRef.Len() , RTL_TEXTENCODING_UTF8 ) );
+ sBuffer.append( GSI_SEQUENCE2 ); //"\t\t\t0\t";
+ sBuffer.append( OUString( sCur.GetBuffer() , sCur.Len() , RTL_TEXTENCODING_UTF8 ) );
+ sBuffer.append( GSI_TAB ); //"\t";
+ sBuffer.append( data );
+ sBuffer.append( GSI_SEQUENCE4 ); //"\t\t\t\t";
+ sBuffer.append( sOUTimeStamp );
+ ByteString sOut( sBuffer.makeStringAndClear().getStr() , RTL_TEXTENCODING_UTF8 );
+ //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( rPrj_in ) ) )
+ //{
+ if( data.getLength() > 0 ) aSDFStream.WriteLine( sOut );
+ //}
+ pXMLElement=NULL;
+ }else fprintf(stdout,"\nDBG: NullPointer in HelpParser::CreateSDF , Language %s\n",sCur.GetBuffer() );
+ }
+
+ }
+ //Dump(aXMLStrHM);
+ aSDFStream.Close();
+
+ if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){
+ DirEntry aTempFile( sUsedTempFile );
+ aTempFile.Kill();
+ }
+ return sal_True;
+}
+
+ByteString HelpParser::makeAbsolutePath( const ByteString& sHelpFile , const ByteString& rRoot_in )
+{
+ DirEntry aEntry( String( sHelpFile, RTL_TEXTENCODING_ASCII_US ));
+ aEntry.ToAbs();
+ String sFullEntry = aEntry.GetFull();
+ aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
+ aEntry += DirEntry( rRoot_in );
+ ByteString sPrjEntry( aEntry.GetFull(), gsl_getSystemTextEncoding());
+ ByteString sActFileName(
+ sFullEntry.Copy( sPrjEntry.Len() + 1 ), gsl_getSystemTextEncoding());
+
+ sActFileName.SearchAndReplaceAll( "/", "\\" );
+ return sActFileName;
+}
+bool HelpParser::Merge( const ByteString &rSDFFile, const ByteString &rDestinationFile ,
+ ByteString& sLanguage , MergeDataFile& aMergeDataFile )
+{
+
+ (void) rSDFFile;
+ bool hasNoError = true;
+
+ SimpleXMLParser aParser;
+
+ String sUsedTempFile;
+ String sXmlFile;
+
+ if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ){
+ DirEntry aTempFile = Export::GetTempFile();
+ DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) );
+ aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
+ String sTempFile = aTempFile.GetFull();
+ Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) );
+ sUsedTempFile = sTempFile;
+ sXmlFile = sTempFile;
+ }else{
+ sUsedTempFile = String::CreateFromAscii("");
+ sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US );
+ }
+
+ OUString sOUHelpFile( sXmlFile );
+ String fullFilePath;
+ DirEntry aFile( sXmlFile );
+
+ XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( '0' ) ) );
+ printf("Dest file %s\n",rDestinationFile.GetBuffer());
+ hasNoError = MergeSingleFile( xmlfile , aMergeDataFile , sLanguage , rDestinationFile );
+ delete xmlfile;
+ if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){
+ DirEntry aTempFile( sUsedTempFile );
+ aTempFile.Kill();
+ }
+ return hasNoError;
+}
+
+bool ByteStringEqual( const ByteString& rKey1, const ByteString& rKey2 ) {
+ return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL;
+};
+bool ByteStringLess( const ByteString& rKey1, const ByteString& rKey2 ) {
+ return rKey1.CompareTo( rKey2 )==COMPARE_LESS;
+}
+
+void HelpParser::parse_languages( std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile ){
+ std::vector<ByteString> aTmp;
+
+ const ByteString DE ("de");
+ const ByteString ENUS ("en-US");
+ static const ByteString ALL( "ALL" );
+
+ Export::InitLanguages( false );
+
+ if( Export::sLanguages.EqualsIgnoreCaseAscii( ALL ) )
+ {
+ aLanguages = aMergeDataFile.GetLanguages();
+ aLanguages.push_back( DE );
+ aLanguages.push_back( ENUS );
+
+ if( !Export::sForcedLanguages.Equals("") )
+ {
+ std::vector<ByteString> aFL = Export::GetForcedLanguages();
+ std::copy( aFL.begin() ,
+ aFL.end() ,
+ back_inserter( aLanguages )
+ );
+ std::sort( aLanguages.begin() , aLanguages.end() , ByteStringLess );
+ std::vector<ByteString>::iterator unique_iter = std::unique( aLanguages.begin() , aLanguages.end() , ByteStringEqual );
+ std::copy( aLanguages.begin() , unique_iter , back_inserter( aTmp ) );
+ aLanguages = aTmp;
+ }
+ }
+ else{
+ aLanguages = Export::GetLanguages();
+ }
+
+}
+
+bool HelpParser::Merge(
+ const ByteString &rSDFFile, const ByteString &rPathX , const ByteString &rPathY , bool bISO ,
+ const std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir )
+{
+
+
+ (void) rSDFFile ;
+ bool hasNoError = true;
+ SimpleXMLParser aParser;
+ String sUsedTempFile;
+ String sXmlFile;
+
+ if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) )
+ {
+ DirEntry aTempFile = Export::GetTempFile();
+ DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) );
+ aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
+ String sTempFile = aTempFile.GetFull();
+ Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) );
+ sUsedTempFile = sTempFile;
+ sXmlFile = sTempFile;
+ }
+ else
+ {
+ sUsedTempFile = String::CreateFromAscii("");
+ sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US );
+ }
+
+
+ OUString sOUHelpFile( sXmlFile );
+ String fullFilePath;
+ DirEntry aFile( sXmlFile );
+
+ XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( '0' ) ) );
+ xmlfile->Extract();
+
+ if( xmlfile == NULL)
+ {
+ printf("%s\n",ByteString(aParser.GetError().sMessage,RTL_TEXTENCODING_UTF8).GetBuffer());
+ exit(-1);
+ //return false;
+ }
+
+
+ ByteString sCur;
+ for( unsigned int n = 0; n < aLanguages.size(); n++ ){
+ sCur = aLanguages[ n ];
+
+ ByteString sFilepath;
+ if( bISO ) sFilepath = GetOutpath( rPathX , sCur , rPathY );
+ else sFilepath = rPathX;
+ if( bCreateDir ) MakeDir( sFilepath );
+
+ XMLFile* file = new XMLFile( *xmlfile );
+ sFilepath.Append( sHelpFile );
+ hasNoError = MergeSingleFile( file , aMergeDataFile , sCur , sFilepath );
+ delete file;
+
+ if( !hasNoError ) return false; // Stop on error
+ }
+
+ if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) )
+ {
+ DirEntry aTempFile( sUsedTempFile );
+ aTempFile.Kill();
+ }
+ delete xmlfile;
+ return hasNoError;
+}
+
+bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const ByteString& sLanguage ,
+ ByteString sPath )
+{
+ file->Extract();
+
+ XMLHashMap* aXMLStrHM = file->GetStrings();
+ LangHashMap* aLangHM;
+ static ResData pResData( "","","");
+ pResData.sResTyp = "help";
+
+ ByteString sTmp = Export::sLanguages;
+
+ sTmp.EraseLeadingAndTrailingChars();
+
+ for(XMLHashMap::iterator pos=aXMLStrHM->begin();pos!=aXMLStrHM->end();++pos) // Merge every l10n related string
+ {
+
+ aLangHM = pos->second;
+ //printf("*********************DUMPING HASHMAP***************************************");
+ //Dump( aXMLStrHM );
+ //printf("DBG: sHelpFile = %s\n",sHelpFile.GetBuffer() );
+
+ pResData.sGId = pos->first;
+ pResData.sFilename = sHelpFile;
+
+ ProcessHelp( aLangHM , sLanguage, &pResData , aMergeDataFile );
+ }
+
+
+ // Init temp and target file
+ ByteString sTempFile;
+ ByteString sTargetFile( sPath );
+ ByteString sTempFileCopy;
+
+ static const ByteString INPATH = Export::GetEnv( "INPATH" );
+ Export::getRandomName( sPath , sTempFile , INPATH );
+ Export::getRandomName( sPath , sTempFileCopy , INPATH );
+ // Write in the temp file
+ bool hasNoError = file->Write ( sTempFile );
+ if( !hasNoError )
+ {
+ cerr << "ERROR: file->Write failed\n";
+ return false;
+ }
+
+ DirEntry aTmp( sTempFile );
+ DirEntry aTmp2( sTempFileCopy );
+ DirEntry aTar( sTargetFile );
+
+ if( !Export::CopyFile( sTempFile , sTempFileCopy ) )
+ {
+#if defined(UNX) || defined(OS2)
+ sleep( 3 );
+#else
+ Sleep( 3 );
+#endif
+ if( !Export::CopyFile( sTempFile , sTempFileCopy ) )
+ {
+ cerr << "ERROR: Can not copy file from " << sTempFile.GetBuffer() << " to " << sTempFileCopy.GetBuffer() << "\n";
+ return false;
+ }
+ }
+ //remove( sTargetFile.GetBuffer() );
+
+ FileStat aFSTest( aTar );
+ if( aFSTest.GetSize() < 1 )
+ {
+ remove( sTargetFile.GetBuffer() );
+ }
+ int rc;
+#if defined(UNX) || defined(OS2)
+ rc = rename( sTempFile.GetBuffer() , sTargetFile.GetBuffer() );
+#else
+ rc = MoveFileEx( sTempFile.GetBuffer() , sTargetFile.GetBuffer(), MOVEFILE_REPLACE_EXISTING );
+#endif
+ FileStat aFS( aTar );
+
+ //cout << "mv " << sTempFile.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
+ //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
+// Windows rename returns -1 if the file already exits
+//#ifdef UNX
+ if( rc < 0 || aFS.GetSize() < 1 )
+//#else
+// if( aFS.GetSize() < 1 )
+//#endif
+ {
+#if defined(UNX) || defined(OS2)
+ sleep( 3 );
+#else
+ Sleep( 3 );
+#endif
+ aFSTest.Update( aTar );
+ if( aFSTest.GetSize() < 1 )
+ {
+ remove( sTargetFile.GetBuffer() );
+ }
+#if defined(UNX) || defined(OS2)
+ rc = rename( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() );
+#else
+ rc = MoveFileEx( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() , MOVEFILE_REPLACE_EXISTING );
+#endif
+ aFS.Update( aTar );
+
+ //cout << "mv2 " << sTempFileCopy.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
+ //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
+
+// Windows rename returns -1 if the file already exits
+//#ifdef WNT
+// if( aFS.GetSize() < 1 )
+//#else
+ if( rc < 0 || aFS.GetSize() < 1 )
+//#endif
+ {
+ cerr << "ERROR: helpex Can't rename file " << sTempFileCopy.GetBuffer() << " to " << sTargetFile.GetBuffer() << " rename rc=" << rc << " filesize=" << aFS.GetSize() << "\n";
+ aTmp.Kill();
+ aTmp2.Kill();
+ if( aFS.GetSize() < 1 )
+ aTar.Kill();
+ return false;
+ }
+ }
+ aTmp.Kill();
+ aTmp2.Kill();
+
+ return true;
+}
+
+ByteString HelpParser::GetOutpath( const ByteString& rPathX , const ByteString& sCur , const ByteString& rPathY ){
+ ByteString testpath = rPathX;
+ static const ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+ testpath.EraseTrailingChars( '/' );
+ testpath.EraseTrailingChars( '\\' );
+ testpath += sDelimiter;
+ testpath += sCur;
+ testpath += sDelimiter;
+ ByteString sRelativePath( rPathY );
+ sRelativePath.EraseLeadingChars( '/' );
+ sRelativePath.EraseLeadingChars( '\\' );
+ testpath += sRelativePath;
+ testpath += sDelimiter;
+ return testpath;
+}
+void HelpParser::MakeDir( const ByteString& sPath ){
+ ByteString sTPath( sPath );
+ ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+ sTPath.SearchAndReplaceAll( sDelimiter , '/' );
+ sal_uInt16 cnt = sTPath.GetTokenCount( '/' );
+ ByteString sCreateDir;
+ for( sal_uInt16 i = 0 ; i < cnt ; i++ )
+ {
+ sCreateDir += sTPath.GetToken( i , '/' );
+ sCreateDir += sDelimiter;
+#ifdef WNT
+ _mkdir( sCreateDir.GetBuffer() );
+#else
+ mkdir( sCreateDir.GetBuffer() , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
+#endif
+ }
+}
+
+
+/* ProcessHelp Methode: search for en-US entry and replace it with the current language*/
+void HelpParser::ProcessHelp( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){
+
+ XMLElement* pXMLElement = NULL;
+ PFormEntrys *pEntrys = NULL;
+ XMLData *data = NULL;
+ XMLParentNode *parent = NULL;
+
+ String sNewdata;
+ ByteString sLId;
+ ByteString sGId;
+
+ pEntrys = NULL;
+
+#ifdef MERGE_SOURCE_LANGUAGES
+ if( true ){ // Merge en-US!
+#else
+ if( !sCur.EqualsIgnoreCaseAscii("en-US") ){
+#endif
+ pXMLElement = (*aLangHM)[ "en-US" ];
+ if( pXMLElement == NULL )
+ {
+ printf("Error: Can't find en-US entry\n");
+ }
+ if( pXMLElement != NULL )
+ {
+ parent = pXMLElement->GetParent();
+ sLId = pXMLElement->GetOldref();
+ pResData->sId = sLId;
+
+ pEntrys = aMergeDataFile.GetPFormEntrys( pResData );
+ if( pEntrys != NULL)
+ {
+ ByteString sNewText;
+ pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
+ sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 );
+ if ( sNewdata.Len())
+ {
+ if( pXMLElement != NULL )
+ {
+ data = new XMLData( sNewdata , NULL , true ); // Add new one
+ pXMLElement->RemoveAndDeleteAllChilds();
+ pXMLElement->AddChild( data );
+ aLangHM->erase( sCur );
+ }
+ }
+ }else if( pResData == NULL ){fprintf(stdout,"Can't find GID=%s LID=%s TYP=%s\n",pResData->sGId.GetBuffer(),pResData->sId.GetBuffer(),pResData->sResTyp.GetBuffer());}
+ pXMLElement->ChangeLanguageTag( String( sCur , RTL_TEXTENCODING_ASCII_US) );
+ }
+
+ }
+}
+/* Process() Method merges */
+void HelpParser::Process( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){
+
+ XMLElement* pXMLElement = NULL;
+ PFormEntrys *pEntrys = NULL;
+ XMLData *data = NULL;
+ XMLParentNode *parent = NULL;
+ XMLDefault *xmldefault = NULL;
+
+ short curLang = 0;
+ String sNewdata;
+ bool isFallback = false;
+ ByteString sLId;
+ ByteString sGId;
+
+ pEntrys = NULL;
+
+#ifdef MERGE_SOURCE_LANGUAGES
+ if( true ){ // Merge en-US!
+#else
+ if( !sCur.EqualsIgnoreCaseAscii("en-US") ){
+#endif
+ pXMLElement = (*aLangHM)[ sCur ];
+ if( pXMLElement == NULL )
+ {
+ FillInFallbacks( *aLangHM , sCur );
+ pXMLElement = ( *aLangHM )[ sCur ];
+ isFallback = true;
+ }
+ if( pXMLElement != NULL )
+ {
+ parent = pXMLElement->GetParent();
+ sLId = pXMLElement->GetOldref();
+ pResData->sId = sLId;
+
+ pEntrys = aMergeDataFile.GetPFormEntrys( pResData );
+ if( pEntrys != NULL)
+ {
+ ByteString sNewText;
+ pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
+ sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 );
+ if ( sNewdata.Len())
+ {
+ printf("Entries found\n");
+ if( pXMLElement != NULL )
+ {
+ data = new XMLData( sNewdata , NULL , true ); // Add new one
+ if( pXMLElement->ToOUString().compareTo( OUString(data->GetData()) ) != 0 )
+ {
+ pXMLElement->RemoveAndDeleteAllChilds();
+ pXMLElement->AddChild( data );
+ }
+ if( isFallback )
+ {
+ xmldefault = new XMLDefault( String::CreateFromAscii("\n") , NULL );
+ int pos = parent->GetPosition( pXMLElement->GetId() );
+ if( pos != -1 ){
+ parent->AddChild(xmldefault , pos+1 );
+ parent->AddChild(pXMLElement , pos+2 );
+ }
+ else fprintf(stdout,"ERROR: Can't find reference Element of id %s language %d\n",pXMLElement->GetId().GetBuffer(),curLang);
+ }
+
+ aLangHM->erase( sCur );
+ }
+ }
+ delete pResData;
+ }else if( pResData == NULL ){fprintf(stdout,"Can't find GID=%s LID=%s TYP=%s\n",pResData->sGId.GetBuffer(),pResData->sId.GetBuffer(),pResData->sResTyp.GetBuffer());}
+ }
+
+ }
+}
+
Propchange: openoffice/branches/l10n/main/l10ntools/source/helpmerge.cxx
------------------------------------------------------------------------------
svn:executable = *
Added: openoffice/branches/l10n/main/l10ntools/source/inireader.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/inireader.cxx?rev=1437973&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/inireader.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/inireader.cxx Thu Jan 24 12:21:38 2013
@@ -0,0 +1,153 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include <unicode/regex.h>
+#include <unicode/unistr.h>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include "inireader.hxx"
+
+using namespace std;
+namespace transex3
+{
+
+bool INIreader::read( INImap& myMap , string& filename )
+{
+ ifstream aFStream( filename.c_str() );
+ if( aFStream && aFStream.is_open())
+ {
+ string line;
+ string section;
+ string param_key;
+ string param_value;
+ stringmap* myvalues = 0;
+
+ while( std::getline( aFStream , line ) )
+ {
+ trim( line );
+ if( line.empty() ){
+ }
+ else if( is_section( line , section ) )
+ {
+ //cerr << "[" << section << "]\n";
+ myvalues = new stringmap();
+ myMap[ section ] = myvalues ;
+ }
+ else if ( is_parameter( line , param_key , param_value ) )
+ {
+ //cerr << "" << param_key << " = " << param_value << "\n";
+ if( myvalues )
+ {
+ (*myvalues)[ param_key ] = param_value ;
+ }
+ else
+ {
+ cerr << "ERROR: The INI file " << filename << " appears to be broken ... parameters without a section?!?\n";
+ if( aFStream.is_open() ) aFStream.close();
+ return false;
+ }
+ }
+ }
+
+ if( aFStream.is_open() )
+ aFStream.close();
+
+ return true;
+ }
+ else
+ {
+ cerr << "ERROR: Can't open file '" << filename << "'\n";
+ }
+ return false;
+}
+
+bool INIreader::is_section( string& line , string& section_str )
+{
+ // Error in regex ?
+ check_status( section_status );
+ UnicodeString target( line.c_str() , line.length() );
+
+ section_match->reset( target );
+ check_status( section_status );
+
+ if( section_match->find() )
+ {
+ check_status( section_status );
+ UnicodeString result( section_match->group( 1 , section_status) );
+ check_status( section_status );
+ toStlString( result , section_str );
+
+ return true;
+ }
+ return false;
+}
+
+bool INIreader::is_parameter( string& line , string& parameter_key , string& parameter_value )
+{
+ // Error in regex ?
+ check_status( parameter_status );
+ UnicodeString target( line.c_str() , line.length() );
+
+ parameter_match->reset( target );
+ check_status( parameter_status );
+
+ if( parameter_match->find() )
+ {
+ check_status( parameter_status );
+
+ UnicodeString result1( parameter_match->group( 1 , parameter_status) );
+ check_status( parameter_status );
+ toStlString( result1 , parameter_key );
+ UnicodeString result2( parameter_match->group( 2 , parameter_status) );
+ check_status( parameter_status );
+ toStlString( result2 , parameter_value );
+
+ return true;
+ }
+ return false;
+}
+
+void INIreader::check_status( UErrorCode status )
+{
+ if( U_FAILURE( status) )
+ {
+ cerr << "Error in or while using regex: " << u_errorName( status ) << "\n";
+ exit(-1);
+ }
+}
+
+void INIreader::toStlString( const UnicodeString& str , string& stl_str)
+{
+ // convert to string
+ char* buffer = new char[ str.length()*3 ];
+ str.extract( 0 , str.length() , buffer );
+ stl_str = string( buffer );
+ delete [] buffer;
+}
+
+void INIreader::trim( string& str )
+{
+ string str1 = str.substr( 0 , str.find_last_not_of(' ') + 1 );
+ str = str1.empty() ? str1 : str1.substr( str1.find_first_not_of(' ') );
+}
+
+}
Propchange: openoffice/branches/l10n/main/l10ntools/source/inireader.cxx
------------------------------------------------------------------------------
svn:executable = *
Added: openoffice/branches/l10n/main/l10ntools/source/lngex.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/lngex.cxx?rev=1437973&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/lngex.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/lngex.cxx Thu Jan 24 12:21:38 2013
@@ -0,0 +1,201 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_l10ntools.hxx"
+#include <stdio.h>
+
+// local includes
+#include "lngmerge.hxx"
+
+// defines to parse command line
+#define STATE_NON 0x0001
+#define STATE_INPUT 0x0002
+#define STATE_OUTPUT 0x0003
+#define STATE_PRJ 0x0004
+#define STATE_ROOT 0x0005
+#define STATE_MERGESRC 0x0006
+#define STATE_ERRORLOG 0x0007
+#define STATE_BREAKHELP 0x0008
+#define STATE_UNMERGE 0x0009
+#define STATE_UTF8 0x000A
+#define STATE_ULF 0x000B
+#define STATE_LANGUAGES 0x000C
+
+// set of global variables
+ByteString sInputFile;
+sal_Bool bEnableExport;
+sal_Bool bMergeMode;
+sal_Bool bErrorLog;
+sal_Bool bUTF8;
+sal_Bool bULF; // ULF = Unicode Language File
+ByteString sPrj;
+ByteString sPrjRoot;
+ByteString sOutputFile;
+ByteString sMergeSrc;
+
+/*****************************************************************************/
+sal_Bool ParseCommandLine( int argc, char* argv[])
+/*****************************************************************************/
+{
+ bEnableExport = sal_False;
+ bMergeMode = sal_False;
+ bErrorLog = sal_True;
+ bUTF8 = sal_True;
+ bULF = sal_False;
+ sPrj = "";
+ sPrjRoot = "";
+ Export::sLanguages = "";
+
+ sal_uInt16 nState = STATE_NON;
+ sal_Bool bInput = sal_False;
+
+ // parse command line
+ for( int i = 1; i < argc; i++ ) {
+ ByteString sSwitch( argv[ i ] );
+ sSwitch.ToUpperAscii();
+ if ( sSwitch == "-I" ) {
+ nState = STATE_INPUT; // next tokens specifies source files
+ }
+ else if ( sSwitch == "-O" ) {
+ nState = STATE_OUTPUT; // next token specifies the dest file
+ }
+ else if ( sSwitch == "-P" ) {
+ nState = STATE_PRJ; // next token specifies the cur. project
+ }
+ else if ( sSwitch == "-R" ) {
+ nState = STATE_ROOT; // next token specifies path to project root
+ }
+ else if ( sSwitch == "-M" ) {
+ nState = STATE_MERGESRC; // next token specifies the merge database
+ }
+ else if ( sSwitch == "-E" ) {
+ nState = STATE_ERRORLOG;
+ bErrorLog = sal_False;
+ }
+ else if ( sSwitch == "-UTF8" ) {
+ nState = STATE_UTF8;
+ bUTF8 = sal_True;
+ }
+/* else if ( sSwitch == "-NOUTF8" ) {
+ nState = STATE_UTF8;
+ bUTF8 = sal_False;
+ }*/
+/* else if ( sSwitch == "-ULF" ) {
+ nState = STATE_ULF;
+ bULF = sal_True;
+ }*/
+ else if ( sSwitch == "-L" ) {
+ nState = STATE_LANGUAGES;
+ }
+ else {
+ switch ( nState ) {
+ case STATE_NON: {
+ return sal_False; // no valid command line
+ }
+ //break;
+ case STATE_INPUT: {
+ sInputFile = argv[ i ];
+ bInput = sal_True; // source file found
+ }
+ break;
+ case STATE_OUTPUT: {
+ sOutputFile = argv[ i ]; // the dest. file
+ }
+ break;
+ case STATE_PRJ: {
+ sPrj = argv[ i ];
+// sPrj.ToLowerAscii(); // the project
+ }
+ break;
+ case STATE_ROOT: {
+ sPrjRoot = argv[ i ]; // path to project root
+ }
+ break;
+ case STATE_MERGESRC: {
+ sMergeSrc = argv[ i ];
+ bMergeMode = sal_True; // activate merge mode, cause merge database found
+ }
+ break;
+ case STATE_LANGUAGES: {
+ Export::sLanguages = argv[ i ];
+ }
+ break;
+ }
+ }
+ }
+
+ if ( bInput ) {
+ // command line is valid
+ bULF = sal_True;
+ bEnableExport = sal_True;
+ return sal_True;
+ }
+
+ // command line is not valid
+ return sal_False;
+}
+
+
+/*****************************************************************************/
+void Help()
+/*****************************************************************************/
+{
+ fprintf( stdout, "Syntax:ULFEX[-p Prj][-r PrjRoot]-i FileIn -o FileOut[-m DataBase][-L l1,l2,...]\n" );
+ fprintf( stdout, " Prj: Project\n" );
+ fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
+ fprintf( stdout, " FileIn: Source file (*.lng)\n" );
+ fprintf( stdout, " FileOut: Destination file (*.*)\n" );
+ fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
+ fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
+ fprintf( stdout, " A fallback language can be defined like this: l1=f1.\n" );
+ fprintf( stdout, " f1, f2,... are also elements of (de,en-US...)\n" );
+ fprintf( stdout, " Example: -L de,es=en-US\n" );
+ fprintf( stdout, " Restriction to de and es, en-US will be fallback for es\n" );
+}
+
+/*****************************************************************************/
+#if defined(UNX) || defined(OS2)
+int main( int argc, char *argv[] )
+#else
+int _cdecl main( int argc, char *argv[] )
+#endif
+/*****************************************************************************/
+{
+ if ( !ParseCommandLine( argc, argv )) {
+ Help();
+ return 1;
+ }
+ fprintf(stdout, ".");
+ fflush( stdout );
+
+ if ( sOutputFile.Len()) {
+ LngParser aParser( sInputFile, bUTF8, bULF );
+ if ( bMergeMode )
+ aParser.Merge( sMergeSrc, sOutputFile , sPrj );
+ else
+ aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot );
+ }
+
+ return 0;
+}
Propchange: openoffice/branches/l10n/main/l10ntools/source/lngex.cxx
------------------------------------------------------------------------------
svn:executable = *
Added: openoffice/branches/l10n/main/l10ntools/source/lngmerge.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/lngmerge.cxx?rev=1437973&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/lngmerge.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/lngmerge.cxx Thu Jan 24 12:21:38 2013
@@ -0,0 +1,352 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_l10ntools.hxx"
+#include <tools/fsys.hxx>
+
+// local includes
+#include "lngmerge.hxx"
+#include "utf8conv.hxx"
+#include <iostream>
+using namespace std;
+//
+// class LngParser
+//
+/*****************************************************************************/
+LngParser::LngParser( const ByteString &rLngFile, sal_Bool bUTF8, sal_Bool bULFFormat )
+/*****************************************************************************/
+ :
+ nError( LNG_OK ),
+ pLines( NULL ),
+ sSource( rLngFile ),
+ bDBIsUTF8( bUTF8 ),
+ bULF( bULFFormat )
+{
+ pLines = new LngLineList( 100, 100 );
+ DirEntry aEntry( String( sSource, RTL_TEXTENCODING_ASCII_US ));
+ if ( aEntry.Exists()) {
+ SvFileStream aStream( String( sSource, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
+ if ( aStream.IsOpen()) {
+ ByteString sLine;
+ bool bFirstLine = true;
+ while ( !aStream.IsEof()) {
+ aStream.ReadLine( sLine );
+
+ if( bFirstLine ){ // Always remove UTF8 BOM from the first line
+ Export::RemoveUTF8ByteOrderMarker( sLine );
+ bFirstLine = false;
+ }
+
+ pLines->Insert( new ByteString( sLine ), LIST_APPEND );
+ }
+ }
+ else
+ nError = LNG_COULD_NOT_OPEN;
+ }
+ else
+ nError = LNG_FILE_NOTFOUND;
+}
+
+/*****************************************************************************/
+LngParser::~LngParser()
+/*****************************************************************************/
+{
+ for ( sal_uLong i = 0; i < pLines->Count(); i++ )
+ delete pLines->GetObject( i );
+ delete pLines;
+}
+
+/*****************************************************************************/
+void LngParser::FillInFallbacks( ByteStringHashMap Text )
+/*****************************************************************************/
+{
+ ByteString sCur;
+ for( unsigned int n = 0; n < aLanguages.size(); n++ ){
+ sCur = aLanguages[ n ];
+
+ if( Export::isAllowed( sCur ) ){
+ ByteString sFallbackLang = Export::GetFallbackLanguage( sCur );
+ if( sFallbackLang.Len() ){
+ Text[ sCur ] = Text[ sFallbackLang ];
+ }
+ }
+ }
+}
+
+/*****************************************************************************/
+sal_Bool LngParser::CreateSDF(
+ const ByteString &rSDFFile, const ByteString &rPrj,
+ const ByteString &rRoot )
+/*****************************************************************************/
+{
+
+ Export::InitLanguages( false );
+ aLanguages = Export::GetLanguages();
+ SvFileStream aSDFStream( String( rSDFFile, RTL_TEXTENCODING_ASCII_US ),
+ STREAM_STD_WRITE | STREAM_TRUNC );
+ if ( !aSDFStream.IsOpen()) {
+ nError = SDF_COULD_NOT_OPEN;
+ }
+ aSDFStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
+ nError = SDF_OK;
+ DirEntry aEntry( String( sSource, RTL_TEXTENCODING_ASCII_US ));
+ aEntry.ToAbs();
+ String sFullEntry = aEntry.GetFull();
+ aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
+ aEntry += DirEntry( rRoot );
+ ByteString sPrjEntry( aEntry.GetFull(), gsl_getSystemTextEncoding());
+ ByteString sActFileName(
+ sFullEntry.Copy( sPrjEntry.Len() + 1 ), gsl_getSystemTextEncoding());
+ sActFileName.SearchAndReplaceAll( "/", "\\" );
+
+ sal_uLong nPos = 0;
+ sal_Bool bStart = true;
+ ByteString sGroup;
+ ByteStringHashMap Text;
+ ByteString sID;
+ ByteString sLine;
+
+ while( nPos < pLines->Count() ){
+ sLine = *pLines->GetObject( nPos++ );
+ while( nPos < pLines->Count() && !isNextGroup( sGroup , sLine ) ){
+ ReadLine( sLine , Text );
+ sID = sGroup;
+ sLine = *pLines->GetObject( nPos++ );
+ };
+ if( bStart ){
+ bStart = false;
+ sID = sGroup;
+ }
+ else {
+
+ WriteSDF( aSDFStream , Text , rPrj , rRoot , sActFileName , sID );
+ }
+ }
+ aSDFStream.Close();
+ return true;
+}
+
+ void LngParser::WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout ,
+ const ByteString &rPrj , const ByteString &rRoot ,
+ const ByteString &sActFileName , const ByteString &sID )
+ {
+
+ sal_Bool bExport = true;
+ if ( bExport ) {
+ ByteString sTimeStamp( Export::GetTimeStamp());
+ ByteString sCur;
+ FillInFallbacks( rText_inout );
+ for( unsigned int n = 0; n < aLanguages.size(); n++ ){
+ sCur = aLanguages[ n ];
+ ByteString sAct = rText_inout[ sCur ];
+ if ( !sAct.Len() && sCur.Len() )
+ sAct = rText_inout[ ByteString("en-US") ];
+
+ ByteString sOutput( rPrj ); sOutput += "\t";
+ if ( rRoot.Len())
+ sOutput += sActFileName;
+ sOutput += "\t0\t";
+ sOutput += "LngText\t";
+ sOutput += sID; sOutput += "\t\t\t\t0\t";
+ sOutput += sCur; sOutput += "\t";
+ sOutput += sAct; sOutput += "\t\t\t\t";
+ sOutput += sTimeStamp;
+ //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( rPrj ) ) )
+ aSDFStream.WriteLine( sOutput );
+ }
+ }
+ }
+ bool LngParser::isNextGroup( ByteString &sGroup_out , ByteString &sLine_in ){
+ sLine_in.EraseLeadingChars( ' ' );
+ sLine_in.EraseTrailingChars( ' ' );
+ if (( sLine_in.GetChar( 0 ) == '[' ) &&
+ ( sLine_in.GetChar( sLine_in.Len() - 1 ) == ']' )){
+ sGroup_out = sLine_in.GetToken( 1, '[' ).GetToken( 0, ']' );
+ sGroup_out.EraseLeadingChars( ' ' );
+ sGroup_out.EraseTrailingChars( ' ' );
+ return true;
+ }
+ return false;
+ }
+ void LngParser::ReadLine( const ByteString &sLine_in , ByteStringHashMap &rText_inout){
+ //printf("sLine -> '%s'\n",sLine_in.GetBuffer());
+ ByteString sLang = sLine_in.GetToken( 0, '=' );
+ sLang.EraseLeadingChars( ' ' );
+ sLang.EraseTrailingChars( ' ' );
+ ByteString sText = sLine_in.GetToken( 1, '\"' ).GetToken( 0, '\"' );
+ if( sLang.Len() )
+ rText_inout[ sLang ] = sText;
+ }
+
+/*****************************************************************************/
+sal_Bool LngParser::Merge(
+ const ByteString &rSDFFile, const ByteString &rDestinationFile , const ByteString& rPrj )
+/*****************************************************************************/
+{
+ (void) rPrj;
+ Export::InitLanguages( true );
+ SvFileStream aDestination(
+ String( rDestinationFile, RTL_TEXTENCODING_ASCII_US ),
+ STREAM_STD_WRITE | STREAM_TRUNC );
+ if ( !aDestination.IsOpen()) {
+ nError = LNG_COULD_NOT_OPEN;
+ }
+ nError = LNG_OK;
+// MergeDataFile( const ByteString &rFileName, const ByteString& rFile , sal_Bool bErrLog, CharSet aCharSet, sal_Bool bUTF8 );
+
+ MergeDataFile aMergeDataFile( rSDFFile, sSource , sal_False, RTL_TEXTENCODING_MS_1252);//, bDBIsUTF8 );
+ ByteString sTmp( Export::sLanguages );
+ if( sTmp.ToUpperAscii().Equals("ALL") )
+ Export::SetLanguages( aMergeDataFile.GetLanguages() );
+ aLanguages = Export::GetLanguages();
+
+ sal_uLong nPos = 0;
+ sal_Bool bGroup = sal_False;
+ ByteString sGroup;
+
+ // seek to next group
+ while ( nPos < pLines->Count() && !bGroup ) {
+ ByteString sLine( *pLines->GetObject( nPos ));
+ sLine.EraseLeadingChars( ' ' );
+ sLine.EraseTrailingChars( ' ' );
+ if (( sLine.GetChar( 0 ) == '[' ) &&
+ ( sLine.GetChar( sLine.Len() - 1 ) == ']' ))
+ {
+ sGroup = sLine.GetToken( 1, '[' ).GetToken( 0, ']' );
+ sGroup.EraseLeadingChars( ' ' );
+ sGroup.EraseTrailingChars( ' ' );
+ bGroup = sal_True;
+ }
+ nPos ++;
+ }
+
+ while ( nPos < pLines->Count()) {
+ ByteStringHashMap Text;
+ ByteString sID( sGroup );
+ sal_uLong nLastLangPos = 0;
+
+ ResData *pResData = new ResData( "", sID , sSource );
+ pResData->sResTyp = "LngText";
+ PFormEntrys *pEntrys = aMergeDataFile.GetPFormEntrys( pResData );
+ // read languages
+ bGroup = sal_False;
+
+ ByteString sLanguagesDone;
+
+ while ( nPos < pLines->Count() && !bGroup ) {
+ ByteString sLine( *pLines->GetObject( nPos ));
+ sLine.EraseLeadingChars( ' ' );
+ sLine.EraseTrailingChars( ' ' );
+ if (( sLine.GetChar( 0 ) == '[' ) &&
+ ( sLine.GetChar( sLine.Len() - 1 ) == ']' ))
+ {
+ sGroup = sLine.GetToken( 1, '[' ).GetToken( 0, ']' );
+ sGroup.EraseLeadingChars( ' ' );
+ sGroup.EraseTrailingChars( ' ' );
+ bGroup = sal_True;
+ nPos ++;
+ sLanguagesDone = "";
+ }
+ else if ( sLine.GetTokenCount( '=' ) > 1 ) {
+ ByteString sLang = sLine.GetToken( 0, '=' );
+ sLang.EraseLeadingChars( ' ' );
+ sLang.EraseTrailingChars( ' ' );
+
+ ByteString sSearch( ";" );
+ sSearch += sLang;
+ sSearch += ";";
+
+ if (( sLanguagesDone.Search( sSearch ) != STRING_NOTFOUND )) {
+ pLines->Remove( nPos );
+ }
+ if( bULF && pEntrys )
+ {
+ // this is a valid text line
+ ByteString sText = sLine.GetToken( 1, '\"' ).GetToken( 0, '\"' );
+ if( sLang.Len() ){
+ ByteString sNewText;
+ pEntrys->GetText( sNewText, STRING_TYP_TEXT, sLang, sal_True );
+
+ if ( sNewText.Len()) {
+ ByteString *pLine = pLines->GetObject( nPos );
+
+ ByteString sText1( sLang );
+ sText1 += " = \"";
+ sText1 += sNewText;
+ sText1 += "\"";
+ *pLine = sText1;
+ //}
+ Text[ sLang ] = sNewText;
+ }
+ }
+ nLastLangPos = nPos;
+ nPos ++;
+ sLanguagesDone += sSearch;
+ }
+ else {
+ nLastLangPos = nPos;
+ nPos ++;
+ sLanguagesDone += sSearch;
+ }
+ }
+ else
+ nPos++;
+ }
+ ByteString sCur;
+ if ( nLastLangPos ) {
+ for( unsigned int n = 0; n < aLanguages.size(); n++ ){
+ sCur = aLanguages[ n ];
+ if( //( !sCur.EqualsIgnoreCaseAscii("de") ||
+ //( sCur.EqualsIgnoreCaseAscii("de") && Export::isMergingGermanAllowed( rPrj ) ) )
+ !sCur.EqualsIgnoreCaseAscii("en-US") && !Text[ sCur ].Len() && pEntrys ){
+
+ ByteString sNewText;
+ pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur, sal_True );
+ if (( sNewText.Len()) &&
+ !(( sCur.Equals("x-comment") ) && ( sNewText == "-" )))
+ {
+ ByteString sLine;
+ sLine += sCur;
+ sLine += " = \"";
+ sLine += sNewText;
+ sLine += "\"";
+
+ nLastLangPos++;
+ nPos++;
+
+ pLines->Insert( new ByteString( sLine ), nLastLangPos );
+ }
+ }
+ }
+ }
+
+ delete pResData;
+ }
+
+ for ( sal_uLong i = 0; i < pLines->Count(); i++ )
+ aDestination.WriteLine( *pLines->GetObject( i ));
+
+ aDestination.Close();
+ return sal_True;
+}
Propchange: openoffice/branches/l10n/main/l10ntools/source/lngmerge.cxx
------------------------------------------------------------------------------
svn:executable = *
Added: openoffice/branches/l10n/main/l10ntools/source/localize.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/localize.cxx?rev=1437973&view=auto
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/localize.cxx (added)
+++ openoffice/branches/l10n/main/l10ntools/source/localize.cxx Thu Jan 24 12:21:38 2013
@@ -0,0 +1,966 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_l10ntools.hxx"
+
+#include "srciter.hxx"
+#include "export.hxx"
+#include "treeconfig.hxx"
+#include <string>
+#include <vector>
+#include <stdio.h>
+#include <iostream>
+#include "tools/errcode.hxx"
+#include "tools/fsys.hxx"
+
+#ifndef L10NTOOLS_FILE_HXX
+#define L10NTOOLS_FILE_HXX
+#include <l10ntools/file.hxx>
+#endif
+
+namespace transex3
+{
+
+//
+// SourceTreeLocalizer
+//
+
+const char *ExeTable[][5] = {
+ { "src", "transex3", " -UTF8 -e", "negative", "noiso" },
+ { "hrc", "transex3", " -UTF8 -e", "positive", "noiso" },
+ { "tree", "xhtex", "", "negative", "noiso" },
+ { "xtx", "xtxex", "", "negative", "noiso" },
+ { "ulf", "ulfex", " -e", "negative", "noiso" },
+ { "xrb", "xmlex", "-UTF8 -e", "negative", "iso" },
+ { "xxl", "xmlex", "-UTF8 -e", "negative", "iso" },
+ { "xgf", "xmlex", "-UTF8 -e -t:xgf", "negative", "iso" },
+ { "xcd", "cfgex", "-UTF8 -e", "negative", "iso" },
+ { "xcu", "cfgex", "-UTF8 -e", "negative", "iso" },
+ { "xcs", "cfgex", "-UTF8 -e -f", "negative", "iso" },
+ { "xrm", "xrmex", "-UTF8 -e", "negative", "iso" },
+ { "xhp", "helpex", " -e", "negative", "noiso" },
+ { "properties", "jpropex", " -e", "negative", "noiso" },
+ { "NULL", "NULL", "NULL", "NULL", "NULL" }
+};
+
+const char *NegativeList[] = {
+ "officecfg/data/org.openoffice.Office.Labels.xcd",
+ "officecfg/data/org/openoffice/Office/Labels.xcd",
+ "officecfg/data/org/openoffice/Office/SFX.xcd",
+ "officecfg/data/org/openoffice/Office/Accelerators.xcu",
+ "hidother.src",
+ "NULL"
+};
+
+const char *PositiveList[] = {
+ "svx/inc/globlmn_tmpl.hrc",
+ "sw/source/ui/inc/swmn_tmpl.hrc",
+ "sw/source/ui/inc/swacc_tmpl.hrc",
+ "sw/source/ui/inc/toolbox_tmpl.hrc",
+ "offmgr/inc/offmenu_tmpl.hrc",
+ "offmgr/source/offapp/intro/intro_tmpl.hrc",
+ "dbaccess/source/ui/inc/toolbox_tmpl.hrc",
+ "svx/source/intro/intro_tmpl.hrc",
+ "dbaccess/source/ui/dlg/AutoControls_tmpl.hrc",
+ "svx/source/unodialogs/textconversiondlgs/chinese_direction_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_DataLabel_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_LegendPosition_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_Statistic_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_Titlesx_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_SecondaryAxisCheckBoxes_tmpl.hrc",
+ "chart2/source/controller/menu/MenuItems_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_ErrorBar_tmpl.hrc",
+ "chart2/source/controller/dialogs/res_Trendline_tmpl.hrc",
+ "svx.link/inc/globlmn_tmpl.hrc",
+ "sw.link/source/ui/inc/swmn_tmpl.hrc",
+ "sw.link/source/ui/inc/swacc_tmpl.hrc",
+ "sw.link/source/ui/inc/toolbox_tmpl.hrc",
+ "offmgr.link/inc/offmenu_tmpl.hrc",
+ "offmgr.link/source/offapp/intro/intro_tmpl.hrc",
+ "dbaccess.link/source/ui/inc/toolbox_tmpl.hrc",
+ "svx.link/source/intro/intro_tmpl.hrc",
+ "dbaccess.link/source/ui/dlg/AutoControls_tmpl.hrc",
+ "svx.link/source/unodialogs/textconversiondlgs/chinese_direction_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_DataLabel_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_LegendPosition_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_Statistic_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_Titlesx_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_SecondaryAxisCheckBoxes_tmpl.hrc",
+ "chart2.link/source/controller/menu/MenuItems_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_ErrorBar_tmpl.hrc",
+ "chart2.link/source/controller/dialogs/res_Trendline_tmpl.hrc",
+ "NULL"
+};
+
+
+const char PRJ_DIR_NAME[] = "prj";
+const char DLIST_NAME[] = "d.lst";
+
+#define LOCALIZE_NONE 0x0000
+#define LOCALIZE_EXTRACT 0x0001
+#define LOCALIZE_MERGE 0x0002
+
+class SourceTreeLocalizer : public SourceTreeIterator
+{
+private:
+ SvFileStream aSDF;
+ sal_uInt16 nMode;
+
+ ByteString sLanguageRestriction;
+
+ ByteString sOutputFile;
+
+ int nFileCnt;
+
+ const ByteString GetProjectName( sal_Bool bAbs = sal_False );
+ const ByteString GetProjectRootRel();
+
+
+ sal_Bool CheckNegativeList( const ByteString &rFileName );
+ sal_Bool CheckPositiveList( const ByteString &rFileName );
+
+ void WorkOnFile(
+ const ByteString &rFileName,
+ const ByteString &rExecutable,
+ const ByteString &rParameter
+ );
+
+ void WorkOnFileType(
+ const ByteString &rDirectory,
+ const ByteString &rExtension,
+ const ByteString &rExecutable,
+ const ByteString &rParameter,
+ const ByteString &rCollectMode
+ );
+ void WorkOnDirectory( const ByteString &rDirectory );
+ sal_Bool ExecuteMerge();
+ sal_Bool MergeSingleFile(
+ const ByteString &rPrj,
+ const ByteString &rFile,
+ const ByteString &rSDFFile
+ );
+
+public:
+ SourceTreeLocalizer( const ByteString &rRoot, const ByteString &rVersion , bool bLocal , bool skip_links );
+ ~SourceTreeLocalizer();
+
+ ByteString getSourceLanguages( ByteString sLanguageRestriction , ByteString sCommand );
+
+ void SetLanguageRestriction( const ByteString& rRestrictions )
+ { sLanguageRestriction = rRestrictions; }
+ int getFileCnt();
+ sal_Bool Extract( const ByteString &rDestinationFile );
+ sal_Bool Merge( const ByteString &rSourceFile , const ByteString &rOutput );
+ int GetFileCnt();
+ virtual void OnExecuteDirectory( const rtl::OUString &rDirectory );
+};
+
+/*****************************************************************************/
+SourceTreeLocalizer::SourceTreeLocalizer(
+ const ByteString &rRoot, const ByteString &rVersion, bool bLocal_in , bool skip_links )
+/*****************************************************************************/
+ : SourceTreeIterator( rRoot, rVersion , bLocal_in ),
+ nMode( LOCALIZE_NONE ),
+ nFileCnt( 0 )
+{
+ bSkipLinks = skip_links ;
+}
+
+/*****************************************************************************/
+SourceTreeLocalizer::~SourceTreeLocalizer()
+/*****************************************************************************/
+{
+}
+
+/*****************************************************************************/
+const ByteString SourceTreeLocalizer::GetProjectName( sal_Bool bAbs )
+/*****************************************************************************/
+{
+ sal_Bool bFound = sal_False;
+ DirEntry aCur;
+ aCur.ToAbs();
+
+ for ( ; ! bFound && aCur.Level() > 1; aCur.CutName() )
+ {
+ DirEntry aTest = aCur + DirEntry(PRJ_DIR_NAME) + DirEntry(DLIST_NAME);
+ if ( aTest.Exists() )
+ {
+ if ( bAbs )
+ return ByteString( aCur.GetFull(), RTL_TEXTENCODING_ASCII_US );
+ else
+ return ByteString( aCur.GetName(), RTL_TEXTENCODING_ASCII_US );
+ }
+ }
+
+ return "";
+}
+/*****************************************************************************/
+int SourceTreeLocalizer::GetFileCnt(){
+/*****************************************************************************/
+ return nFileCnt;
+}
+
+/*****************************************************************************/
+const ByteString SourceTreeLocalizer::GetProjectRootRel()
+/*****************************************************************************/
+{
+ ByteString sProjectRoot( GetProjectName( sal_True ));
+ DirEntry aCur;
+ aCur.ToAbs();
+ ByteString sCur( aCur.GetFull(), RTL_TEXTENCODING_ASCII_US );
+
+ if( sCur.SearchAndReplace( sProjectRoot, "" ) == STRING_NOTFOUND )
+ return "";
+
+ ByteString sDelimiter(
+ DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+
+ sCur.SearchAndReplaceAll( sDelimiter, "/" );
+ sCur.EraseLeadingChars( '/' );
+ sal_uLong nCount = sCur.GetTokenCount( '/' );
+
+ ByteString sProjectRootRel;
+ for ( sal_uLong i = 0; i < nCount; i++ ) {
+ if ( sProjectRootRel.Len())
+ sProjectRootRel += sDelimiter;
+ sProjectRootRel += "..";
+ }
+ if ( sProjectRootRel.Len())
+ return sProjectRootRel;
+
+ return ".";
+}
+
+bool skipProject( ByteString sPrj )
+{
+ static const ByteString READLICENSE( "readlicense" );
+ return sPrj.EqualsIgnoreCaseAscii( READLICENSE );
+}
+
+/*****************************************************************************/
+void SourceTreeLocalizer::WorkOnFile(
+ const ByteString &rFileName, const ByteString &rExecutable,
+ const ByteString &rParameter )
+/*****************************************************************************/
+{
+ String sFull( rFileName, RTL_TEXTENCODING_ASCII_US );
+ DirEntry aEntry( sFull );
+ ByteString sFileName( aEntry.GetName(), RTL_TEXTENCODING_ASCII_US );
+
+ // set current working directory
+ DirEntry aPath( aEntry.GetPath());
+ DirEntry aOldCWD;
+ aPath.SetCWD();
+
+ ByteString sPrj( GetProjectName());
+ if ( sPrj.Len() && !skipProject( sPrj ) )
+ {
+ ByteString sRoot( GetProjectRootRel());
+
+ DirEntry aTemp( Export::GetTempFile());
+ ByteString sTempFile( aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US );
+
+ ByteString sDel;
+#if defined(WNT) || defined(OS2)
+ sDel=ByteString("\\");
+#else
+ sDel=ByteString("/");
+#endif
+ ByteString sPath1( Export::GetEnv("SOLARVER") );
+ ByteString sPath2( Export::GetEnv("INPATH") );
+ ByteString sPath3( "bin" );
+ ByteString sPath4( Export::GetEnv("UPDMINOREXT") );
+ ByteString sExecutable( sPath1 );
+ sExecutable += sDel ;
+ sExecutable += sPath2 ;
+ sExecutable += sDel;
+ sExecutable += sPath3 ;
+ sExecutable += sPath4 ;
+ sExecutable += sDel ;
+ sExecutable += rExecutable ;
+
+
+ ByteString sCommand( sExecutable );
+ sCommand += " ";
+ sCommand += rParameter;
+ sCommand += " -p ";
+ sCommand += sPrj;
+ sCommand += " -r ";
+ sCommand += sRoot;
+ sCommand += " -i ";
+ sCommand += sFileName;
+ sCommand += " -o ";
+ sCommand += sTempFile;
+ if ( sLanguageRestriction.Len()) {
+ sCommand += " -l ";
+ sCommand += getSourceLanguages( sLanguageRestriction , sCommand );
+ }
+
+ //printf("DBG: %s\n",sCommand.GetBuffer());
+ if (system(sCommand.GetBuffer()) == -1)
+ fprintf(stderr, "%s failed\n", sCommand.GetBuffer());
+ nFileCnt++;
+ printf(".");
+ fflush( stdout );
+
+ SvFileStream aSDFIn( aTemp.GetFull(), STREAM_READ );
+ ByteString sLine;
+ while ( aSDFIn.IsOpen() && !aSDFIn.IsEof()) {
+ aSDFIn.ReadLine( sLine );
+ if ( sLine.Len()) {
+ aSDF.WriteLine( sLine );
+ }
+ }
+ aSDFIn.Close();
+
+ aTemp.Kill();
+
+ }
+ // reset current working directory
+ aOldCWD.SetCWD();
+}
+
+ByteString SourceTreeLocalizer::getSourceLanguages( ByteString sLanguageRestriction_inout , ByteString sCommand )
+{
+ // Source languages in helpcontent2 and macromigration en-US only!
+ if( sCommand.Search("helpex") != STRING_NOTFOUND ) {
+ sLanguageRestriction_inout.Assign( ByteString("en-US") );
+ }
+ else if( sCommand.Search("xmlex") != STRING_NOTFOUND ){
+ sLanguageRestriction_inout.Assign( ByteString("en-US") );
+ }
+ return sLanguageRestriction_inout;
+}
+
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::CheckNegativeList( const ByteString &rFileName )
+/*****************************************************************************/
+{
+ sal_uLong nIndex = 0;
+ sal_Bool bReturn = sal_True;
+
+ ByteString sDelimiter(
+ DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+
+ ByteString sFileName( rFileName );
+ sFileName.ToLowerAscii();
+
+ ByteString sNegative( NegativeList[ nIndex ] );
+ while( !sNegative.Equals( "NULL" ) && bReturn ) {
+ sNegative.SearchAndReplaceAll( "\\", sDelimiter );
+ sNegative.SearchAndReplaceAll( "/", sDelimiter );
+ sNegative.ToLowerAscii();
+
+ if( sFileName.Search( sNegative ) == sFileName.Len() - sNegative.Len())
+ bReturn = sal_False;
+
+ nIndex++;
+ sNegative = NegativeList[ nIndex ];
+ }
+
+ return bReturn;
+}
+
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::CheckPositiveList( const ByteString &rFileName )
+/*****************************************************************************/
+{
+ sal_uLong nIndex = 0;
+ sal_Bool bReturn = sal_False;
+
+ ByteString sDelimiter(
+ DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+
+ ByteString sFileName( rFileName );
+ sFileName.ToLowerAscii();
+
+ ByteString sNegative( PositiveList[ nIndex ] );
+ while( !sNegative.Equals( "NULL" ) && !bReturn ) {
+ sNegative.SearchAndReplaceAll( "\\", sDelimiter );
+ sNegative.SearchAndReplaceAll( "/", sDelimiter );
+ sNegative.ToLowerAscii();
+
+ if( sFileName.Search( sNegative ) == sFileName.Len() - sNegative.Len())
+ bReturn = sal_True;
+
+ nIndex++;
+ sNegative = PositiveList[ nIndex ];
+ }
+
+ return bReturn;
+}
+
+/*****************************************************************************/
+void SourceTreeLocalizer::WorkOnFileType(
+ const ByteString &rDirectory, const ByteString &rExtension,
+ const ByteString &rExecutable, const ByteString &rParameter,
+ const ByteString &rCollectMode
+)
+/*****************************************************************************/
+{
+ String sWild( rDirectory, RTL_TEXTENCODING_ASCII_US );
+ sWild += DirEntry::GetAccessDelimiter();
+ sWild += String::CreateFromAscii( "*." );
+ sWild += String( rExtension, RTL_TEXTENCODING_ASCII_US );
+
+ DirEntry aEntry( sWild );
+ Dir aDir( sWild, FSYS_KIND_FILE );
+
+ for ( sal_uInt16 i = 0; i < aDir.Count(); i++ ) {
+ DirEntry aFile( aDir[ i ] );
+ ByteString sFile( aFile.GetFull(), RTL_TEXTENCODING_ASCII_US );
+
+ sal_Bool bAllowed = sal_True;
+
+ if ( rCollectMode.Equals( "negative" ))
+ bAllowed = CheckNegativeList( sFile );
+ else if ( rCollectMode.Equals( "positive" ))
+ bAllowed = CheckPositiveList( sFile );
+
+ if ( bAllowed )
+ WorkOnFile( sFile, rExecutable, rParameter );
+ }
+}
+
+/*****************************************************************************/
+void SourceTreeLocalizer::WorkOnDirectory( const ByteString &rDirectory )
+/*****************************************************************************/
+{
+ //printf("Working on Directory %s\n",rDirectory.GetBuffer());
+ sal_uLong nIndex = 0;
+ ByteString sExtension( ExeTable[ nIndex ][ 0 ] );
+ ByteString sExecutable( ExeTable[ nIndex ][ 1 ] );
+ ByteString sParameter( ExeTable[ nIndex ][ 2 ] );
+ ByteString sCollectMode( ExeTable[ nIndex ][ 3 ] );
+
+ while( !sExtension.Equals( "NULL" )) {
+ WorkOnFileType(
+ rDirectory,
+ sExtension,
+ sExecutable,
+ sParameter,
+ sCollectMode
+ );
+
+ nIndex++;
+
+ sExtension = ExeTable[ nIndex ][ 0 ];
+ sExecutable = ExeTable[ nIndex ][ 1 ];
+ sParameter = ExeTable[ nIndex ][ 2 ];
+ sCollectMode = ExeTable[ nIndex ][ 3 ];
+ }
+}
+
+void SourceTreeLocalizer::OnExecuteDirectory( const rtl::OUString &aDirectory )
+{
+ ByteString rDirectory( rtl::OUStringToOString( aDirectory , RTL_TEXTENCODING_UTF8 , aDirectory.getLength() ) ) ;
+ if ( nMode == LOCALIZE_NONE ){
+ }
+ else
+ WorkOnDirectory( rDirectory );
+}
+
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::Extract( const ByteString &rDestinationFile )
+/*****************************************************************************/
+{
+ nMode = LOCALIZE_EXTRACT;
+
+ aSDF.Open( String( rDestinationFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_STD_WRITE );
+ aSDF.SetLineDelimiter( LINEEND_CRLF );
+
+ sal_Bool bReturn = aSDF.IsOpen();
+ if ( bReturn ) {
+ aSDF.Seek( STREAM_SEEK_TO_END );
+ bReturn = StartExecute();
+ aSDF.Close();
+ }
+ else{
+ printf("ERROR: Can't create file %s\n", rDestinationFile.GetBuffer() );
+ }
+ nMode = LOCALIZE_NONE;
+ aSDF.Close();
+ return bReturn;
+}
+
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::MergeSingleFile(
+ const ByteString &rPrj,
+ const ByteString &rFile,
+ const ByteString &rSDFFile
+)
+/*****************************************************************************/
+{
+ //printf("MergeSingleFile(%s,%s,%s)",rPrj.GetBuffer(),rFile.GetBuffer(),rSDFFile.GetBuffer());
+ if ( !rFile.Len())
+ return sal_True;
+
+ ByteString sRoot( Export::GetEnv( "SRC_ROOT" ));
+ DirEntry aEntry( String( sRoot, RTL_TEXTENCODING_ASCII_US ));
+ aEntry += DirEntry( String( rPrj, RTL_TEXTENCODING_ASCII_US ));
+
+ ByteString sDelimiter(
+ DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
+
+ ByteString sCur( rFile );
+ sCur.SearchAndReplaceAll( "\\", sDelimiter );
+ sCur.SearchAndReplaceAll( "/", sDelimiter );
+
+ aEntry += DirEntry( String( sCur, RTL_TEXTENCODING_ASCII_US ));
+ ByteString sFile( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
+
+ ByteString sBCur( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
+
+ sal_uLong nIndex = 0;
+ ByteString sExtension( aEntry.GetExtension(), RTL_TEXTENCODING_ASCII_US );
+ ByteString sCandidate( ExeTable[ nIndex ][ 0 ] );
+
+ while( !sCandidate.Equals ("NULL") && !sCandidate.Equals(sExtension) )
+ sCandidate = ExeTable[ ++nIndex ][ 0 ];
+
+ if ( !sCandidate.Equals( "NULL" ) ) {
+ if( !aEntry.Exists()) {
+ DirEntryKind theDir=FSYS_KIND_FILE;
+ Dir myDir( aEntry.GetPath(), theDir);
+ DirEntry current;
+ sal_Bool found=sal_False;
+ for( sal_uInt16 x=0; x < myDir.Count() && !found;){
+ current=myDir[x++];
+ StringCompare result=current.GetName().CompareIgnoreCaseToAscii( aEntry.GetName() );
+ if( result==COMPARE_EQUAL ){
+ fprintf(stderr,"WARNING: %s not found\n", ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US).GetBuffer() );
+ fprintf(stderr,"but use %s instead \n" , ByteString(current.GetFull(), RTL_TEXTENCODING_ASCII_US).GetBuffer() );
+ aEntry=current;
+ found=sal_True;
+ }
+ }
+ if(!found) return sal_True;
+
+ }
+
+ DirEntry aOut( Export::GetTempFile() );
+ ByteString sOutput;
+ if( sOutputFile.Len() == 0 )
+ sOutput = ByteString ( aOut.GetFull(), RTL_TEXTENCODING_ASCII_US );
+ else
+ sOutput = sOutputFile;
+ ByteString sCommand( ExeTable[ nIndex ][ 1 ] );
+ sCommand += " -i ";
+ sCommand += ByteString( aEntry.GetName(), RTL_TEXTENCODING_ASCII_US );
+ sCommand += " -m ";
+ sCommand += rSDFFile;
+ sCommand += " -o ";
+ sCommand += sOutput;
+ sCommand += " ";
+ sCommand += ByteString( ExeTable[ nIndex ][ 2 ] );
+ if ( sLanguageRestriction.Len()) {
+ sCommand += " -l ";
+ sCommand += sLanguageRestriction;
+ }
+
+ DirEntry aPath( aEntry.GetPath());
+ DirEntry aOldCWD;
+ aPath.SetCWD();
+
+ if (system(sCommand.GetBuffer()) == -1)
+ fprintf(stderr, "%s failed\n", sCommand.GetBuffer());
+ nFileCnt++;
+ printf(".");
+ SvFileStream aInStream( aOut.GetFull(), STREAM_READ );
+ if ( !aInStream.IsOpen()) {
+ fprintf( stderr,
+ "ERROR: Unable to open file %s for reading!\n",
+ sOutput.GetBuffer());
+ }
+ else {
+ FileStat::SetReadOnlyFlag( aEntry, sal_False );
+ String myStr2(aEntry.GetFull());
+ String aTemp22 = String::CreateFromAscii("_tmp");
+ myStr2.Append(aTemp22);
+
+ ByteString test(myStr2,RTL_TEXTENCODING_ASCII_US);
+ SvFileStream aOutStream( myStr2, STREAM_STD_WRITE | STREAM_TRUNC );
+ if ( !aOutStream.IsOpen()) {
+ ByteString test2(myStr2,RTL_TEXTENCODING_ASCII_US);
+ fprintf( stderr,"ERROR: Unable to open file %s for modification!\n", test2.GetBuffer());
+ aInStream.Close();
+ }
+
+ else {
+ ByteString sLine;
+ aOutStream.SetLineDelimiter( LINEEND_LF );
+
+ aInStream.ReadLine( sLine );
+ while ( !aInStream.IsEof()) {
+ aOutStream.WriteLine( sLine );
+ aInStream.ReadLine( sLine );
+ }
+ aInStream.Close();
+ aOutStream.Close();
+
+
+ DirEntry myTempFile(ByteString(myStr2,RTL_TEXTENCODING_ASCII_US)); // xxx_tmp ->
+ DirEntry myFile(ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US));// xxx
+
+ DirEntry oldFile(ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US));
+
+ if(oldFile.Kill()==ERRCODE_NONE){
+ if(myTempFile.MoveTo(myFile)!=ERRCODE_NONE){
+ fprintf( stderr, "ERROR: Can't rename file %s\n",ByteString(myStr2,RTL_TEXTENCODING_ASCII_US).GetBuffer());
+ }
+ }
+ else{
+ fprintf( stderr, "ERROR: Can't remove file %s\n",ByteString(aEntry.GetFull(),RTL_TEXTENCODING_ASCII_US).GetBuffer());
+ }
+ } // else
+
+ aOldCWD.SetCWD();
+ aOut.Kill();
+ } // else
+ }
+ return sal_True;
+}
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::ExecuteMerge( )
+/*****************************************************************************/
+{
+ DirEntry aEntry( Export::GetTempFile());
+ sal_Bool bReturn = sal_True;
+ bool bMerged = false;
+
+ ByteString sFileName;
+ ByteString sCurFile;
+ ByteString sLine;
+ ByteString sFileKey;
+
+ SvFileStream aFile;
+
+ ByteString sOutputFileName = sOutputFile;
+ ByteString sInpath(".");
+ sInpath += Export::GetEnv("INPATH");
+ ByteString sBlank("");
+
+ sOutputFileName.SearchAndReplaceAll( sInpath , sBlank );
+
+ String sDel = DirEntry::GetAccessDelimiter();
+ ByteString sBDel( sDel.GetBuffer() , sDel.Len() , RTL_TEXTENCODING_UTF8 );
+ if( bLocal ){
+ xub_StrLen nPos = sOutputFileName.SearchBackward( sBDel.GetChar(0) );
+ sOutputFileName = sOutputFileName.Copy( nPos+1 , sOutputFileName.Len()-nPos-1 );
+ }
+ ByteStringBoolHashMap aFileHM;
+ // Read all possible files
+ while ( !aSDF.IsEof()) {
+ aSDF.ReadLine( sLine );
+ sFileName = sLine.GetToken( 0, '\t' );
+ sFileName += "#";
+ sFileName += sLine.GetToken( 1, '\t' );
+ aFileHM[sFileName]=true;
+ }
+
+ for( ByteStringBoolHashMap::iterator iter = aFileHM.begin(); iter != aFileHM.end(); ++iter ){
+ sFileKey = iter->first;
+ aSDF.Seek( 0 );
+ aFile.Open( aEntry.GetFull(), STREAM_STD_WRITE |STREAM_TRUNC );
+
+ while ( !aSDF.IsEof()) {
+ aSDF.ReadLine( sLine );
+ sFileName = sLine.GetToken( 0, '\t' );
+ sFileName += "#";
+ sFileName += sLine.GetToken( 1, '\t' );
+ if( sFileName.Len() && ( sFileName.CompareTo(sFileKey) == COMPARE_EQUAL ) ){
+ if ( aFile.IsOpen() && sLine.Len())
+ aFile.WriteLine( sLine );
+ }
+ }
+ if ( aFile.IsOpen())
+ aFile.Close();
+
+ ByteString sPrj( sFileKey.GetToken( 0, '#' ));
+ ByteString sFile( sFileKey.GetToken( 1, '#' ));
+ ByteString sSDFFile( aFile.GetFileName(), RTL_TEXTENCODING_ASCII_US );
+
+ //printf("localize test sPrj = %s , sFile = %s , sSDFFile = %s sOutputFileName = %s\n",sPrj.GetBuffer(), sFile.GetBuffer() , sSDFFile.GetBuffer() , sOutputFileName.GetBuffer() );
+
+ // Test
+ bLocal = true;
+ // Test
+
+ if( bLocal ){
+ sal_uInt16 nPos = sFile.SearchBackward( '\\' );
+ ByteString sTmp = sFile.Copy( nPos+1 , sFile.Len()-nPos-1 );
+ //printf("'%s'='%s'\n",sTmp.GetBuffer(), sOutputFileName.GetBuffer());
+ if( sTmp.CompareTo(sOutputFileName) == COMPARE_EQUAL ){
+ bMerged = true;
+ if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
+ bReturn = sal_False;
+ }else{
+ bMerged = true;
+ //printf("MergeSingleFile('%s','%s','%s')\n",sPrj.GetBuffer(),sFile.GetBuffer(),sSDFFile.GetBuffer());
+ if ( !MergeSingleFile( sPrj, sFile, sSDFFile ))
+ bReturn = sal_False;
+ }
+ }
+ }
+ aEntry.Kill();
+ // If Outputfile not included in the SDF file copy it without merge
+
+ if( bLocal && !bMerged ){
+ DirEntry aSourceFile( sOutputFileName.GetBuffer() );
+ FSysError aErr = aSourceFile.CopyTo( DirEntry ( sOutputFile.GetBuffer() ) , FSYS_ACTION_COPYFILE );
+ if( aErr != FSYS_ERR_OK ){
+ printf("ERROR: Can't copy file '%s' to '%s' %d\n",sOutputFileName.GetBuffer(),sOutputFile.GetBuffer(),sal::static_int_cast<int>(aErr));
+ }
+ }
+ return bReturn;
+
+}
+
+/*****************************************************************************/
+sal_Bool SourceTreeLocalizer::Merge( const ByteString &rSourceFile , const ByteString &rOutput )
+/*****************************************************************************/
+{
+ sOutputFile = rOutput;
+ nMode = LOCALIZE_MERGE;
+ aSDF.Open( String( rSourceFile, RTL_TEXTENCODING_ASCII_US ),
+ STREAM_STD_READ );
+
+ sal_Bool bReturn = aSDF.IsOpen();
+ if ( bReturn ) {
+ bReturn = ExecuteMerge();
+// aSDF.Close();
+ }
+ aSDF.Close();
+ nMode = LOCALIZE_NONE;
+ return bReturn;
+}
+
+}
+using namespace transex3;
+
+#define STATE_NONE 0x0000
+#define STATE_EXPORT 0x0001
+#define STATE_MERGE 0x0002
+#define STATE_ISOCODE 0x0003
+#define STATE_LANGUAGES 0x0004
+#define STATE_FILENAME 0x0005
+#define STATE_OUTPUT 0x0006
+
+/*****************************************************************************/
+void Help()
+/*****************************************************************************/
+{
+ fprintf( stdout,
+ "localize (c)2001 by Sun Microsystems\n"
+ "====================================\n" );
+ fprintf( stdout,
+ "As part of the L10N framework, localize extracts and merges translations\n"
+ "out of and into the whole source tree.\n\n"
+ "Syntax: localize -e -l en-US -f FileName \n"
+ "Parameter:\n"
+ "\t-e: Extract mode\n"
+ "\tFileName: Output file when extract mode, input file when merge mode\n"
+ "\tl1...ln: supported languages (\"all\" for all languages).\n"
+ );
+
+ fprintf( stdout,
+ "Valid language codes for l1...ln and f1...fn are:\n" );
+ fprintf( stdout,
+ "\nExample 1:\n"
+ "==========\n"
+ "localize -e -l en-US -f MyFile\n\n"
+ "All strings will be extracted for language de and language en-US.\n"
+ );
+}
+
+/*****************************************************************************/
+int Error()
+/*****************************************************************************/
+{
+ Help();
+ return 1;
+}
+
+/*****************************************************************************/
+sal_Bool CheckLanguages( ByteString &rLanguages )
+/*****************************************************************************/
+{
+ ByteString sTmp( rLanguages );
+ return true;
+}
+
+/*****************************************************************************/
+#if defined(UNX) || defined(OS2)
+int main( int argc, char *argv[] )
+#else
+int _cdecl main( int argc, char *argv[] )
+#endif
+/*****************************************************************************/
+{
+ String sTempBase( String::CreateFromAscii( "loc" ));
+ DirEntry::SetTempNameBase( sTempBase );
+ sal_uInt16 nState = STATE_NONE;
+
+ sal_Bool bExport = sal_False;
+ sal_Bool bMerge = sal_False;
+ bool bSkipLinks = false;
+
+ ByteString sLanguages;
+ ByteString sFileName;
+ ByteString sOutput;
+
+ bExport = sal_True;
+
+ for( int i = 1; i < argc; i++ ) {
+ ByteString sSwitch( argv[ i ] );
+ sSwitch.ToUpperAscii();
+
+ if ( sSwitch.Equals( "-E" )) {
+ nState = STATE_EXPORT;
+ if ( bMerge )
+ return Error();
+ bExport = sal_True;
+ }
+ else if ( sSwitch.Equals( "-I" ) )
+ nState = STATE_ISOCODE;
+ else if ( sSwitch.Equals( "-L" ) )
+ nState = STATE_LANGUAGES;
+ else if ( sSwitch.Equals( "-F" ) )
+ nState = STATE_FILENAME;
+ else if ( ByteString( argv[ i ]).ToUpperAscii().Equals( "-O" ) )
+ nState = STATE_OUTPUT;
+ else {
+ switch ( nState ) {
+ case STATE_NONE:
+ return Error();
+ case STATE_OUTPUT:
+ if ( sOutput.Len())
+ return Error();
+ sOutput = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+ case STATE_LANGUAGES:
+ if ( sLanguages.Len())
+ return Error();
+ sLanguages = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+ case STATE_FILENAME:
+ if ( sFileName.Len())
+ return Error();
+ sFileName = ByteString( argv[ i ] );
+ nState = STATE_NONE;
+ break;
+ default:
+ return Error();
+ }
+ }
+ }
+ if ( !bMerge && !bExport ) {
+ Help();
+ return 1;
+ }
+
+ ByteString sSolarVer( Export::GetEnv( "WORK_STAMP" ));
+ ByteString sVersion( Export::GetEnv( "WORK_STAMP" ));
+
+ if ( !sSolarVer.Len() || !sVersion.Len()) {
+ fprintf( stderr, "ERROR: No environment set!\n" );
+ return 1;
+ }
+
+ if ( !CheckLanguages( sLanguages ))
+ return 2;
+
+ if ( !sFileName.Len()) {
+ fprintf( stderr, "ERROR: No filename given\n" );
+ return 3;
+ }
+
+ DirEntry aEntry( String( sFileName , RTL_TEXTENCODING_ASCII_US ));
+ aEntry.ToAbs();
+ String sFullEntry = aEntry.GetFull();
+ ByteString sFileABS( aEntry.GetFull(), gsl_getSystemTextEncoding());
+ //printf("B %s\nA %s\n",rDestinationFile.GetBuffer(), sFile.GetBuffer());
+ sFileName = sFileABS;
+
+ Treeconfig treeconfig;
+ vector<string> repos;
+ bool hasPwd = treeconfig.getActiveRepositories( repos );
+ if( hasPwd ) cout << "Found special path!\n";
+
+ string minor_ext;
+ bool has_minor_ext;
+
+ if( Export::GetEnv("UPDMINOREXT") != NULL )
+ {
+ minor_ext = string( Export::GetEnv("UPDMINOREXT") );
+ has_minor_ext = minor_ext.size();
+ }
+ else
+ has_minor_ext = false;
+
+ // localize through all repositories
+ for( vector<string>::iterator iter = repos.begin(); iter != repos.end() ; ++iter )
+ {
+ string curRepository;
+ if( has_minor_ext )
+ curRepository = string( Export::GetEnv("SOURCE_ROOT_DIR") ) + "/" + *iter + minor_ext;
+ else
+ curRepository = string( Export::GetEnv("SOURCE_ROOT_DIR") ) + "/" + *iter;
+ cout << "Localizing repository " << curRepository << "\n";
+ SourceTreeLocalizer aIter( ByteString( curRepository.c_str() ) , sVersion , (sOutput.Len() > 0) , bSkipLinks );
+ aIter.SetLanguageRestriction( sLanguages );
+ if ( bExport ){
+ fflush( stdout );
+ if( *iter == "ooo" )
+ aIter.Extract( sFileName );
+ else
+ {
+ ByteString sFileNameWithExt( sFileName );
+ sFileNameWithExt += ByteString( "." );
+ sFileNameWithExt += ByteString( (*iter).c_str() );
+ aIter.Extract( sFileNameWithExt );
+ }
+ printf("\n%d files found!\n",aIter.GetFileCnt());
+ }
+ }
+ if( hasPwd )
+ {
+ string pwd;
+ Export::getCurrentDir( pwd );
+ cout << "Localizing repository " << pwd << "\n";
+ SourceTreeLocalizer aIter( ByteString( pwd.c_str() ) , sVersion , (sOutput.Len() > 0) , bSkipLinks );
+ aIter.SetLanguageRestriction( sLanguages );
+ if ( bExport ){
+ fflush( stdout );
+ aIter.Extract( sFileName );
+ printf("\n%d files found!\n",aIter.GetFileCnt());
+ }
+
+ }
+
+ return 0;
+}
+
Propchange: openoffice/branches/l10n/main/l10ntools/source/localize.cxx
------------------------------------------------------------------------------
svn:executable = *
Modified: openoffice/branches/l10n/main/l10ntools/source/makefile.mk
URL: http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/makefile.mk?rev=1437973&r1=1437972&r2=1437973&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/makefile.mk (original)
+++ openoffice/branches/l10n/main/l10ntools/source/makefile.mk Thu Jan 24 12:21:38 2013
@@ -26,7 +26,7 @@ PRJ=..
INCPRE=$(MISC)
PRJNAME=l10ntools
-TARGET=genLang
+TARGET=transex
TARGETTYPE=CUI
LIBTARGET=no
# --- Settings -----------------------------------------------------
@@ -43,10 +43,164 @@ CFLAGS+=-DSYSTEM_EXPAT
# --- Files --------------------------------------------------------
+OBJFILES= \
+ $(OBJ)$/export.obj \
+ $(OBJ)$/export2.obj \
+ $(OBJ)$/merge.obj \
+ $(OBJ)$/srciter.obj \
+ $(OBJ)$/utf8conv.obj \
+ $(OBJ)$/xmlparse.obj \
+ $(OBJ)$/helpmerge.obj \
+ $(OBJ)$/helpex.obj \
+ $(OBJ)$/file.obj \
+ $(OBJ)$/directory.obj
+
+
+LIB1TARGET= $(LB)$/$(TARGET).lib
+LIB1ARCHIV= $(LB)$/libtransex.a
+#LIB1FILES= $(LB)$/transex3.lib
+LIB1OBJFILES= $(OBJ)$/export.obj \
+ $(OBJ)$/export2.obj \
+ $(OBJ)$/merge.obj \
+ $(OBJ)$/srciter.obj \
+ $(OBJ)$/file.obj \
+ $(OBJ)$/directory.obj \
+ $(OBJ)$/utf8conv.obj
+
+
+APP1VERSIONMAP=exports.map
+
+# extractor and merger for *.src and *.hrc
+APP1TARGET= transex3
+#APP1OBJS= $(OBJ)$/src_yy.obj
+APP1OBJS= $(OBJ)$/src_yy_wrapper.obj
+
+APP1STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+
+.IF "$(OS)"=="MACOSX"
+# static libs at end for OS X
+.ENDIF
+
+APP1LIBS+= $(LB)$/$(TARGET).lib
+APP1DEPN= $(OBJ)$/src_yy_wrapper.obj $(LB)$/$(TARGET).lib
+
+APP2TARGET= helpex
+APP2OBJS= $(OBJ)$/helpmerge.obj $(OBJ)$/xmlparse.obj $(OBJ)$/export2.obj $(OBJ)$/utf8conv.obj $(OBJ)$/merge.obj $(OBJ)$/helpex.obj
+APP2RPATH= NONE
+
+.IF "$(OS)"!="MACOSX"
+.ENDIF
+
+APP2STDLIBS+=$(SALLIB) $(EXPATASCII3RDLIB) $(TOOLSLIB) $(VOSLIB)
+
+.IF "$(OS)"=="MACOSX"
+# static libs at end for OS X
+.ENDIF
+
+# extractor and merger for *.lng and *.lng
+APP3TARGET= ulfex
+APP3OBJS= $(OBJ)$/lngmerge.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/lngex.obj $(OBJ)$/utf8conv.obj
+APP3RPATH= NONE
+
+.IF "$(OS)"!="MACOSX"
+#APP3STDLIBS+= $(BTSTRPLIB)
+.ENDIF
+APP3STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+.IF "$(OS)"=="MACOSX"
+# static libs at end for OS X
+.ENDIF
+
+# encoding converter for *.gsi
+APP4TARGET= gsiconv
+APP4OBJS= $(OBJ)$/utf8conv.obj $(OBJ)$/gsiconv.obj
+APP4STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+
+# tag checker for *.gsi
+APP5TARGET= gsicheck
+APP5OBJS= $(OBJ)$/gsicheck.obj $(OBJ)$/tagtest.obj
+APP5STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+
+# extractor and merger for *.cfg
+APP6TARGET= cfgex
+APP6OBJS= $(OBJ)$/cfgmerge.obj $(OBJ)$/cfg_yy_wrapper.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/utf8conv.obj
+
+.IF "$(OS)"!="MACOSX"
+#APP6STDLIBS+= $(BTSTRPLIB)
+.ENDIF
+
+APP6STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+
+.IF "$(OS)"=="MACOSX"
+# static libs at end for OS X
+.ENDIF
+
+# extractor and merger for *.xrm
+APP7TARGET= xrmex
+APP7OBJS= $(OBJ)$/xrmmerge.obj $(OBJ)$/xrm_yy_wrapper.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/utf8conv.obj
+APP7RPATH= NONE
+
+.IF "$(OS)"!="MACOSX"
+.ENDIF
+
+APP7STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(SALLIB)
+
+.IF "$(OS)"=="MACOSX"
+# static libs at end for OS X
+.ENDIF
+
+#
+#APP8TARGET= treeconfig
+#APP8OBJS= $(OBJ)$/treeconfig.obj $(OBJ)$/inireader.obj $(OBJ)$/export2.obj
+#APP8STDLIBS=$(TOOLSLIB) $(SALLIB) $(VOSLIB) $(ICUINLIB) $(STLPORT)
+
+# localizer for l10n framework
+APP9TARGET= localize_sl
+EXCEPTIONSFILES= \
+ $(OBJ)$/localize.obj
+APP9OBJS= $(OBJ)$/localize.obj $(OBJ)$/utf8conv.obj $(OBJ)$/srciter.obj $(OBJ)$/export2.obj $(OBJ)$/file.obj $(OBJ)$/directory.obj $(OBJ)$/treeconfig.obj $(OBJ)$/inireader.obj
+
+APP9STDLIBS+= \
+ $(TOOLSLIB) \
+ $(VOSLIB) \
+ $(ICUINLIB) \
+ $(ICUUCLIB) \
+ $(STLPORTLIB) \
+ $(SALLIB)
+
+DEPOBJFILES=$(APP1OBJS) $(APP2OBJS) $(APP3OBJS) $(APP4OBJS) $(APP5OBJS) $(APP6OBJS) $(APP7OBJS) $(APP8OBJS) $(APP9OBJS)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+$(MISC)$/%_yy.c : %lex.l
+ flex -l -w -8 -o$@ $<
+
+
+# --- Files --------------------------------------------------------
+
# localizer for new l10n framework
#
-APP1TARGET= genLang
-APP1OBJS= $(OBJ)$/gLang.obj \
+APP8TARGET= genLang
+APP8OBJS= $(OBJ)$/gLang.obj \
$(OBJ)$/gL10nMem.obj \
$(OBJ)$/gHandler.obj \
$(OBJ)$/gConProp.obj \
@@ -66,19 +220,12 @@ APP1OBJS= $(OBJ)$/gLang.obj \
$(OBJ)$/gConXcuWrap.obj \
$(OBJ)$/gConXrmWrap.obj \
$(OBJ)$/gConXhpWrap.obj
-APP1RPATH= NONE
-APP1STDLIBS+= $(TOOLSLIB) \
+APP8RPATH= NONE
+APP8STDLIBS+= $(TOOLSLIB) \
$(VOSLIB) \
$(SALLIB)
-DEPOBJFILES=$(APP1OBJS)
-
-# --- Targets ------------------------------------------------------
-
-.INCLUDE : target.mk
-
-$(MISC)$/%_yy.c : %lex.l
- flex -l -w -8 -o$@ $<
+DEPOBJFILES=$(APP8OBJS)
# Helper to suppress warnings in lex generated c code, see #i57362#
@@ -89,3 +236,6 @@ $(OBJ)$/gConXcsWrap.obj: $(MISC)$/gConXc
$(OBJ)$/gConXrmWrap.obj: $(MISC)$/gConXrm_yy.c
$(OBJ)$/gConXhpWrap.obj: $(MISC)$/gConXhp_yy.c
+$(OBJ)$/src_yy_wrapper.obj: $(MISC)$/src_yy.c
+$(OBJ)$/cfg_yy_wrapper.obj: $(MISC)$/cfg_yy.c
+$(OBJ)$/xrm_yy_wrapper.obj: $(MISC)$/xrm_yy.c