[Libreoffice-commits] .: Branch 'feature/killsdf' - l10ntools/Executable_propex.mk l10ntools/inc l10ntools/Module_l10ntools.mk l10ntools/Package_scripts.mk l10ntools/scripts l10ntools/source Repository.mk solenv/gbuild
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Oct 8 08:28:51 PDT 2012
Repository.mk | 1
l10ntools/Executable_propex.mk | 32 +++++
l10ntools/Module_l10ntools.mk | 1
l10ntools/Package_scripts.mk | 4
l10ntools/inc/propmerge.hxx | 37 ++++++
l10ntools/scripts/propex.bat | 8 -
l10ntools/source/propex.cxx | 45 +++++++
l10ntools/source/propmerge.cxx | 222 +++++++++++++++++++++++++++++++++++++++
solenv/gbuild/ExtensionTarget.mk | 32 +++--
9 files changed, 357 insertions(+), 25 deletions(-)
New commits:
commit f73618e9dea03d27138cd4599e351249a79bf46b
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date: Sat Oct 6 22:10:41 2012 +0200
Move propex/propmerge code to C++
Changes:
-Use same methods and commandline params
as other localizers
-Work with one lang during mergeing
-Work well with comments
-Correct makefiles according to one lang concept
Plus delete propex.bat to avoid conflicts
Change-Id: Ia9d2886db263c31f29692c3f6da2b8ec6542b564
diff --git a/Repository.mk b/Repository.mk
index c273b45..8aa8e6c 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -56,6 +56,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \
osl_process_child \
pdf2xml \
pdfunzip \
+ propex \
rdbmaker \
regsingleton \
regsvrex \
diff --git a/l10ntools/Executable_propex.mk b/l10ntools/Executable_propex.mk
new file mode 100644
index 0000000..d8dc16d
--- /dev/null
+++ b/l10ntools/Executable_propex.mk
@@ -0,0 +1,32 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+
+$(eval $(call gb_Executable_Executable,propex))
+
+$(eval $(call gb_Executable_set_include,propex,\
+ -I$(SRCDIR)/l10ntools/inc \
+ $$(INCLUDE) \
+))
+
+$(eval $(call gb_Executable_use_libraries,propex,\
+ sal \
+ i18nregexp \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,propex,\
+ transex \
+))
+
+$(eval $(call gb_Executable_add_exception_objects,propex,\
+ l10ntools/source/propmerge \
+ l10ntools/source/propex \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/l10ntools/Module_l10ntools.mk b/l10ntools/Module_l10ntools.mk
index 4b1d64d..e6c0cc3 100644
--- a/l10ntools/Module_l10ntools.mk
+++ b/l10ntools/Module_l10ntools.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_Module_add_targets,l10ntools,\
Executable_localize \
Executable_transex3 \
Executable_renewpo \
+ Executable_propex \
StaticLibrary_transex \
Package_inc \
Package_scripts \
diff --git a/l10ntools/Package_scripts.mk b/l10ntools/Package_scripts.mk
index 3739f12..e97ec6c 100644
--- a/l10ntools/Package_scripts.mk
+++ b/l10ntools/Package_scripts.mk
@@ -30,11 +30,7 @@ $(eval $(call gb_Package_add_file,l10ntools_scripts,bin/addkeyid2pot.pl,addkeyid
$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/fast_merge.pl,fast_merge.pl))
$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/keyidGen.pl,keyidGen.pl))
$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/po2lo,po2lo))
-$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/propex,propex))
$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/propmerge,propmerge))
-ifeq ($(OS_FOR_BUILD),WNT)
-$(eval $(call gb_Package_add_file,l10ntools_scripts,bin/propex.bat,propex.bat))
-endif
# vim: set noet sw=4 ts=4:
diff --git a/l10ntools/inc/propmerge.hxx b/l10ntools/inc/propmerge.hxx
new file mode 100644
index 0000000..3465635
--- /dev/null
+++ b/l10ntools/inc/propmerge.hxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef _PROPMERGE_INCLUDED
+#define _PROPMERGE_INCLUDED
+
+#include <rtl/string.hxx>
+#include <vector>
+
+class PropParser
+{
+private:
+ std::vector<OString> m_vLines;
+ OString m_sSource;
+ OString m_sLang;
+ bool m_bIsInitialized;
+
+public:
+ PropParser(
+ const OString& rInputFile, const OString& rLang,
+ const bool bMergeMode );
+ ~PropParser();
+
+ bool isInitialized() const { return m_bIsInitialized; }
+ void Extract(
+ const OString& rSDFFile, const OString& rPrj, const OString& rRoot );
+ void Merge( const OString &rSDFFile, const OString &rDestinationFile );
+};
+
+#endif //_PROPMERGE_INCLUDED
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/scripts/propex.bat b/l10ntools/scripts/propex.bat
deleted file mode 100755
index 1174286..0000000
--- a/l10ntools/scripts/propex.bat
+++ /dev/null
@@ -1,8 +0,0 @@
- at echo off
-
-if "x%PERL%x" EQU "xx" (
- echo ERROR: Perl not found. Environment is not set.
- exit /b 1
-)
-
-%PERL% %SOLARVER%\%INPATH%\bin\propex %*
\ No newline at end of file
diff --git a/l10ntools/source/propex.cxx b/l10ntools/source/propex.cxx
new file mode 100644
index 0000000..2977cb1
--- /dev/null
+++ b/l10ntools/source/propex.cxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "sal/main.h"
+
+#include "export.hxx"
+#include "propmerge.hxx"
+
+SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
+{
+ HandledArgs aArgs;
+ if( !Export::handleArguments(argc, argv, aArgs) )
+ {
+ Export::writeUsage("propex","properties");
+ return 1;
+ }
+
+ if( aArgs.m_sInputFile.indexOf("en_US") != -1 )
+ {
+ PropParser aParser(
+ aArgs.m_sInputFile, Export::sLanguages, aArgs.m_bMergeMode );
+ if( !aParser.isInitialized() )
+ {
+ return 1;
+ }
+ if( aArgs.m_bMergeMode )
+ {
+ aParser.Merge(aArgs.m_sMergeSrc, aArgs.m_sOutputFile);
+ }
+ else
+ {
+ aParser.Extract(
+ aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot );
+ }
+ }
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx
new file mode 100644
index 0000000..237444f
--- /dev/null
+++ b/l10ntools/source/propmerge.cxx
@@ -0,0 +1,222 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cstdlib>
+#include <cassert>
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+
+#include "export.hxx"
+#include "common.hxx"
+#include "propmerge.hxx"
+
+namespace
+{
+ //Write out an sdf line
+ void lcl_WriteSDF(
+ std::ofstream &aSDFStream, const OString& rText, const OString& rPrj,
+ const OString& rActFileName, const OString& rID )
+ {
+ OString sOutput( rPrj ); sOutput += "\t";
+ sOutput += rActFileName;
+ sOutput += "\t0\tproperty\t";
+ sOutput += rID; sOutput += "\t\t\t\t0\ten-US\t";
+ sOutput += rText; sOutput += "\t\t\t\t";
+ aSDFStream << sOutput.getStr() << std::endl;
+ }
+
+ //Find ascii escaped unicode
+ sal_Int32 lcl_IndexOfUnicode(
+ const OString& rSource, const sal_Int32 nFrom = 0 )
+ {
+ const OString sHexDigits = "0123456789abcdefABCDEF";
+ sal_Int32 nIndex = rSource.indexOf( "\\u", nFrom );
+ if( nIndex == -1 )
+ {
+ return -1;
+ }
+ bool bIsUnicode = true;
+ for( short nDist = 2; nDist <= 5; ++nDist )
+ {
+ if( sHexDigits.indexOf( rSource[nIndex + nDist] ) == -1 )
+ {
+ bIsUnicode = false;
+ }
+ }
+ return bIsUnicode ? nIndex : -1;
+ }
+
+ //Convert ascii escaped unicode to utf-8
+ OString lcl_ConvertToUTF8( const OString& rText )
+ {
+ OString sResult = rText;
+ sal_Int32 nIndex = lcl_IndexOfUnicode( sResult );
+ while( nIndex != -1 && nIndex < rText.getLength() )
+ {
+ const OString sHex = sResult.copy( nIndex + 2, 4 );
+ const sal_Unicode cDec =
+ static_cast<sal_Unicode>( strtol( sHex.getStr(), NULL, 16 ) );
+ const OString sNewChar =
+ OString( &cDec, 1, RTL_TEXTENCODING_UTF8 );
+ sResult = sResult.replaceAll( "\\u" + sHex, sNewChar );
+ nIndex = lcl_IndexOfUnicode( sResult, nIndex );
+ }
+ return sResult;
+ }
+
+ //Escape unicode charachters
+ void lcl_PrintJavaStyle( const OString& rText, std::ofstream &rOfstream )
+ {
+ const OUString sTemp =
+ OStringToOUString( rText, RTL_TEXTENCODING_UTF8 );
+ for ( sal_Int32 nIndex = 0; nIndex < sTemp.getLength(); ++nIndex )
+ {
+ sal_Unicode cUniCode = sTemp[nIndex];
+ if( cUniCode < 128 )
+ {
+ rOfstream << static_cast<char>( cUniCode );
+ }
+ else
+ {
+ rOfstream
+ << "\\u"
+ << std::setfill('0') << std::setw(2) << std::uppercase
+ << std::hex << (cUniCode >> 8) << (cUniCode & 0xFF);
+ }
+ }
+ }
+}
+
+//Open sourcefile and store it's lines
+PropParser::PropParser(
+ const OString& rInputFile, const OString& rLang,
+ const bool bMergeMode )
+ : m_vLines( std::vector<OString>() )
+ , m_sSource( rInputFile )
+ , m_sLang( rLang )
+ , m_bIsInitialized( false )
+{
+ std::ifstream aIfstream( m_sSource.getStr() );
+ if( aIfstream.is_open() )
+ {
+ std::string s;
+ std::getline( aIfstream, s );
+ while( !aIfstream.eof() )
+ {
+ OString sLine( s.data(), s.length() );
+ if( bMergeMode ||
+ ( !sLine.startsWith(" *") && !sLine.startsWith("/*") ) )
+ {
+ m_vLines.push_back( sLine );
+ }
+ std::getline( aIfstream, s );
+ }
+ }
+ else
+ {
+ std::cerr
+ << "Propex error: Cannot open sourcefile: "
+ << m_sSource.getStr() << std::endl;
+ return;
+ }
+ m_bIsInitialized = true;
+}
+
+PropParser::~PropParser()
+{
+}
+
+//Extract strings form source file
+void PropParser::Extract(
+ const OString& rSDFFile, const OString& rPrj, const OString& rRoot )
+{
+ assert( m_bIsInitialized );
+ std::ofstream aSDFStream(
+ rSDFFile.getStr(), std::ios_base::out | std::ios_base::trunc );
+ if( !aSDFStream.is_open() )
+ {
+ std::cerr
+ << "Propex error: Cannot open sdffile for extract: "
+ << rSDFFile.getStr() << std::endl;
+ return;
+ }
+
+ for( unsigned nIndex = 0; nIndex < m_vLines.size(); ++nIndex )
+ {
+ const OString sLine = m_vLines[nIndex];
+ const sal_Int32 nEqualSign = sLine.indexOf('=');
+ if( nEqualSign != -1 )
+ {
+ lcl_WriteSDF(
+ aSDFStream,
+ lcl_ConvertToUTF8( sLine.copy( nEqualSign + 1 ).trim() ),//Text
+ rPrj,
+ common::pathnameToken(
+ m_sSource.getStr(), rRoot.getStr()), //FileName
+ sLine.copy( 0, nEqualSign ).trim() ); //ID
+ }
+ }
+
+ aSDFStream.close();
+}
+
+//Merge strings to source file
+void PropParser::Merge( const OString &rSDFFile, const OString &rDestinationFile )
+{
+ assert( m_bIsInitialized );
+ std::ofstream aDestination(
+ rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc );
+ if( !aDestination.is_open() ) {
+ std::cerr
+ << "Propex error: Cannot open sourcefile for merge: "
+ << rDestinationFile.getStr() << std::endl;
+ return;
+ }
+
+ MergeDataFile aMergeDataFile( rSDFFile, m_sSource, false );
+
+ if( aMergeDataFile.GetLanguages()[0] != m_sLang )
+ {
+ std::cerr
+ << "Propex error: given language conflicts with "
+ << "language of Mergedata file: "
+ << m_sLang.getStr() << " - " << rSDFFile.getStr() << std::endl;
+ return;
+ }
+
+ for( unsigned nIndex = 0; nIndex < m_vLines.size(); ++nIndex )
+ {
+ const OString sLine = m_vLines[nIndex];
+ const sal_Int32 nEqualSign = sLine.indexOf('=');
+ if( !sLine.startsWith(" *") && !sLine.startsWith("/*") &&
+ nEqualSign != -1 )
+ {
+ const OString sID( sLine.copy( 0, sLine.indexOf("=") ).trim() );
+ ResData aResData( "", sID , m_sSource );
+ aResData.sResTyp = "property";
+ PFormEntrys* pEntrys = aMergeDataFile.GetPFormEntrys( &aResData );
+ if( pEntrys )
+ {
+ OString sNewText;
+ pEntrys->GetText( sNewText, STRING_TYP_TEXT, m_sLang );
+ aDestination << (sID + OString("=")).getStr();
+ lcl_PrintJavaStyle( sNewText, aDestination );
+ aDestination << std::endl;
+ }
+ }
+ else
+ {
+ aDestination << sLine.getStr() << std::endl;
+ }
+ }
+ aDestination.close();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/gbuild/ExtensionTarget.mk b/solenv/gbuild/ExtensionTarget.mk
index efa5a54..752eba1 100644
--- a/solenv/gbuild/ExtensionTarget.mk
+++ b/solenv/gbuild/ExtensionTarget.mk
@@ -34,10 +34,10 @@ gb_ExtensionTarget_ZIPCOMMAND := zip $(if $(findstring s,$(MAKEFLAGS)),-q)
gb_ExtensionTarget_XRMEXTARGET := $(call gb_Executable_get_target_for_build,xrmex)
gb_ExtensionTarget_XRMEXCOMMAND := \
$(gb_Helper_set_ld_path) $(gb_ExtensionTarget_XRMEXTARGET)
-# propmerge is a perl script
-gb_ExtensionTarget_PROPMERGETARGET := $(OUTDIR_FOR_BUILD)/bin/propmerge
+
+gb_ExtensionTarget_PROPMERGETARGET := $(call gb_Executable_get_target_for_build,propex)
gb_ExtensionTarget_PROPMERGECOMMAND := \
- $(PERL) $(gb_ExtensionTarget_PROPMERGETARGET)
+ $(gb_Helper_set_ld_path) $(gb_ExtensionTarget_PROPMERGETARGET)
gb_ExtensionTarget_UPDATETREETARGET := $(SRCDIR)/l10ntools/scripts/update_tree.pl
gb_ExtensionTarget_UPDATETREECOMMAND := \
@@ -213,24 +213,30 @@ endef
# localize .properties file
# source file is copied to $(WORKDIR)
define gb_ExtensionTarget_localize_properties
+$(foreach lang,$(gb_ExtensionTarget_ALL_LANGS),\
+ $(call gb_ExtensionTarget_localize_properties_onelang,$(1),$(subst en_US,$(subst -,_,$(lang)),$(2)),$(3),$(lang)))
+endef
+
+define gb_ExtensionTarget_localize_properties_onelang
$(call gb_ExtensionTarget_get_target,$(1)) : FILES += $(2)
-ifneq ($(strip $(gb_WITH_LANG)),)
-$(call gb_ExtensionTarget_get_target,$(1)) : FILES += $(foreach lang,$(subst -,_,$(gb_ExtensionTarget_TRANS_LANGS)),$(subst en_US,$(lang),$(2)))
+ifneq ($(filter-out en-US,$(4)),)
$(call gb_ExtensionTarget_get_rootdir,$(1))/$(2) : \
- POFILES := $(foreach lang,$(gb_ExtensionTarget_TRANS_LANGS),$(gb_POLOCATION)/$(lang)/$(patsubst /%/,%,$(subst $(SRCDIR),,$(dir $(3)))).po)
+ POFILE := $(gb_POLOCATION)/$(4)/$(patsubst /%/,%,$(subst $(SRCDIR),,$(dir $(3)))).po
$(call gb_ExtensionTarget_get_rootdir,$(1))/$(2) : \
- $(foreach lang,$(gb_ExtensionTarget_TRANS_LANGS),$(gb_POLOCATION)/$(lang)/$(patsubst /%/,%,$(subst $(SRCDIR),,$(dir $(3)))).po)
+ $(gb_POLOCATION)/$(4)/$(patsubst /%/,%,$(subst $(SRCDIR),,$(dir $(3)))).po
endif
$(call gb_ExtensionTarget_get_target,$(1)) : $(call gb_ExtensionTarget_get_rootdir,$(1))/$(2)
$(call gb_ExtensionTarget_get_rootdir,$(1))/$(2) : $(3) \
$(gb_ExtensionTarget_PROPMERGETARGET)
$$(call gb_Output_announce,$(2),$(true),PRP,3)
- MERGEINPUT=`$(gb_MKTEMP)` && \
- echo $$(POFILES) > $$$${MERGEINPUT} && \
- mkdir -p $$(dir $$@) && \
- cp -f $$< $$@ \
- $(if $(strip $(gb_WITH_LANG)),&& $(gb_ExtensionTarget_PROPMERGECOMMAND) -i $$@ -m $$$${MERGEINPUT}) && \
- rm -rf $$$${MERGEINPUT}
+ $$(call gb_Helper_abbreviate_dirs, \
+ $(if $(filter-out en-US,$(4)), \
+ MERGEINPUT=`$(gb_MKTEMP)` && \
+ echo $$(POFILE) > $$$${MERGEINPUT} && \
+ mkdir -p $$(dir $$@) && \
+ $(gb_ExtensionTarget_PROPMERGECOMMAND) -i $$< -o $$@ -m $$$${MERGEINPUT} -l $(4) && \
+ rm -rf $$$${MERGEINPUT}, \
+ cp $$< $$@))
endef
More information about the Libreoffice-commits
mailing list