From 437ae002185a81802cb31b00fa777a7b5d8f9847 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 29 Aug 2012 09:47:26 +0200 Subject: Renew localization and kill sdf 1.step Extract strings from source directly to pot files Implement PoHeader and PoEntry classes Renew fomrat of pot/po files Implement conversion from old po to new po Change-Id: I411b6041f7d525e76b189d7f31adc5b9ab60f6d6 Reviewed-on: https://gerrit.libreoffice.org/506 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/Executable_localize.mk | 9 ++ l10ntools/Executable_renewpo.mk | 36 +++++ l10ntools/Module_l10ntools.mk | 1 + l10ntools/StaticLibrary_transex.mk | 1 + l10ntools/inc/po.hxx | 97 ++++++++++++ l10ntools/source/localize.cxx | 135 +++++++++++----- l10ntools/source/po.cxx | 309 +++++++++++++++++++++++++++++++++++++ l10ntools/source/renewpo.cxx | 168 ++++++++++++++++++++ 8 files changed, 717 insertions(+), 39 deletions(-) create mode 100644 l10ntools/Executable_renewpo.mk create mode 100644 l10ntools/inc/po.hxx create mode 100644 l10ntools/source/po.cxx create mode 100644 l10ntools/source/renewpo.cxx (limited to 'l10ntools') diff --git a/l10ntools/Executable_localize.mk b/l10ntools/Executable_localize.mk index 511604ac74d2..6184a8982bd5 100644 --- a/l10ntools/Executable_localize.mk +++ b/l10ntools/Executable_localize.mk @@ -26,10 +26,19 @@ $(eval $(call gb_Executable_Executable,localize)) +$(eval $(call gb_Executable_set_include,localize,\ + -I$(SRCDIR)/l10ntools/inc \ + $$(INCLUDE) \ +)) + $(eval $(call gb_Executable_use_libraries,localize,\ sal \ )) +$(eval $(call gb_Executable_use_static_libraries,localize,\ + transex \ +)) + $(eval $(call gb_Executable_add_exception_objects,localize,\ l10ntools/source/localize \ )) diff --git a/l10ntools/Executable_renewpo.mk b/l10ntools/Executable_renewpo.mk new file mode 100644 index 000000000000..33e38b22751f --- /dev/null +++ b/l10ntools/Executable_renewpo.mk @@ -0,0 +1,36 @@ +# for the specific language governing rights and limitations under the +# License. +# +# Major Contributor(s): +# Copyright (C) 2012 David Ostrovsky (initial developer) +# +# All Rights Reserved. +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. + +$(eval $(call gb_Executable_Executable,renewpo)) + +$(eval $(call gb_Executable_set_include,renewpo,\ + -I$(SRCDIR)/l10ntools/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Executable_use_libraries,renewpo,\ + sal \ +)) + +$(eval $(call gb_Executable_use_static_libraries,renewpo,\ + transex \ +)) + +$(eval $(call gb_Executable_add_exception_objects,renewpo,\ + l10ntools/source/renewpo \ +)) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Module_l10ntools.mk b/l10ntools/Module_l10ntools.mk index e3c11344a0c9..fb2a3b3289e5 100644 --- a/l10ntools/Module_l10ntools.mk +++ b/l10ntools/Module_l10ntools.mk @@ -38,6 +38,7 @@ $(eval $(call gb_Module_add_targets,l10ntools,\ Executable_transex3 \ Executable_helpindexer \ Executable_helplinker \ + Executable_renewpo \ StaticLibrary_transex \ Library_helplinker \ Package_inc \ diff --git a/l10ntools/StaticLibrary_transex.mk b/l10ntools/StaticLibrary_transex.mk index e8c84b7d3662..21f50e572ef6 100644 --- a/l10ntools/StaticLibrary_transex.mk +++ b/l10ntools/StaticLibrary_transex.mk @@ -37,6 +37,7 @@ $(eval $(call gb_StaticLibrary_add_exception_objects,transex,\ l10ntools/source/merge \ l10ntools/source/file \ l10ntools/source/directory \ + l10ntools/source/po \ )) # vim: set noet sw=4 ts=4: diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx new file mode 100644 index 000000000000..de01053ba217 --- /dev/null +++ b/l10ntools/inc/po.hxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _PO_INCLUDED +#define _PO_INCLUDED + +#include +#include + +class PoEntry +{ + +private: + + OString m_sWhiteSpace; + OString m_sExtractCom; + OString m_sReference; + OString m_sContext; + OString m_sUnTransStr; + OString m_sTransStr; + + OString m_sKeyId; + +protected: + void setExtractCom(const OString& rExtCom) + { m_sExtractCom = rExtCom; } + +public: + PoEntry(); + PoEntry(const OString& i_rSDFLine, + const sal_uInt16 eType = TEXT); + virtual ~PoEntry(); + + virtual void writeToFile(std::ofstream& io_rOFStream); + + void setTransStr(const OString& rTransStr); + + enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, + LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID, + TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP }; +}; + + + + +class PoHeader: public PoEntry +{ + +private: + OString m_sExtractionSource; + OString m_sProjectIdVersion; + OString m_sReportMsgidBugsTo; + OString m_sPotCreationDate; + OString m_sPoRevisionDate; + OString m_sLastTranslator; + OString m_sLanguageTeam; + OString m_sMimeVersion; + OString m_sPluralForms; + OString m_sContentType; + OString m_sCharset; + OString m_sEncoding; + OString m_sXGenerator; + OString m_sXAcceleratorMarker; + +public: + PoHeader( const OString& rExtSrc ); + ~PoHeader(); +}; + +#endif // _PO_INCLUDED + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index a54d096503df..c10c3f515c0f 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -50,16 +50,12 @@ #include "sal/main.h" #include "sal/types.h" +#include "po.hxx" + using namespace std; namespace { -namespace global { - -std::ofstream output; - -} - rtl::OUString getEnvironment(rtl::OUString const & variable) { rtl::OUString value; if (osl_getEnvironment(variable.pData, &value.pData) != osl_Process_E_None) @@ -174,7 +170,8 @@ bool passesPositiveList(rtl::OUString const & url) { void handleCommand( rtl::OUString const & project, rtl::OUString const & projectRoot, - rtl::OUString const & url, rtl::OUString const & executable, bool positive) + rtl::OUString const & url, rtl::OUString const & actualDir, + std::ofstream & outPut, rtl::OUString const & executable, bool positive) { if (positive ? passesPositiveList(url) : passesNegativeList(url)) { rtl::OUString inPath; @@ -197,13 +194,13 @@ void handleCommand( throw false; //TODO } rtl::OUStringBuffer buf( - getEnvironment( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SOLARVER")))); - buf.append('/'); - buf.append( - getEnvironment( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("INPATH_FOR_BUILD")))); + //getEnvironment( + //rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SOLARVER")))); + //buf.append('/'); + //buf.append( + //getEnvironment( + rtl::OUString("/home/zolnai/git/libo/solver/unxlngi6.pro")); + // RTL_CONSTASCII_USTRINGPARAM("INPATH_FOR_BUILD")))); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/bin/")); buf.append(executable); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" -e -p ")); @@ -239,23 +236,70 @@ void handleCommand( } std::ifstream in(outPath8.getStr()); if (!in.is_open()) { - std::cerr << "Error: Cannot open " << outPath.getStr() << "\n"; + std::cerr << "Error: Cannot open " << outPath8.getStr() << "\n"; throw false; //TODO } + + std::string s; + std::getline(in, s); + if (!in.eof() && !outPut.is_open()) + { + rtl::OUString outDirUrl; + if (osl::FileBase::getFileURLFromSystemPath(actualDir. + copy(0,actualDir.lastIndexOf('/')), outDirUrl) + != osl::FileBase::E_None) + { + std::cerr << "Error: Cannot convert pathname to URL\n"; + throw false; //TODO + } + osl::Directory::createPath(outDirUrl); + + rtl::OString outFilePath; + if (!actualDir.concat(".pot"). + convertToString( + &outFilePath, osl_getThreadTextEncoding(), + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) + { + std::cerr << "Error: Cannot convert pathname from UTF-16\n"; + throw false; //TODO + } + outPut.open(outFilePath.getStr(), + std::ios_base::out | std::ios_base::trunc); + rtl::OString relativPath; + if (!inPath.copy(inPath.indexOf(project), + inPath.lastIndexOf('/')-inPath.indexOf(project)). + convertToString(&relativPath, osl_getThreadTextEncoding(), + (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR + | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) + { + std::cerr << "Error: Cannot convert pathname from UTF-16\n"; + throw false; //TODO + } + PoHeader(relativPath).writeToFile(outPut); + } while (!in.eof()) { - std::string s; + OString sLine = OString(s.data(),s.length()); + if (!sLine.isEmpty()) + { + if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) + PoEntry(sLine).writeToFile(outPut); + if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) + PoEntry(sLine,PoEntry::QUICKHELPTEXT).writeToFile(outPut); + if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) + PoEntry(sLine,PoEntry::TITLE).writeToFile(outPut); + } std::getline(in, s); - if (!s.empty()) - global::output << s << '\n'; - } + }; in.close(); } } void handleFile( rtl::OUString const & project, rtl::OUString const & projectRoot, - rtl::OUString const & url) + rtl::OUString const & url, rtl::OUString const & actualDir, + std::ofstream & outPut) { struct Command { char const * extension; @@ -277,7 +321,7 @@ void handleFile( commands[i].extension, commands[i].extensionLength)) { handleCommand( - project, projectRoot, url, + project, projectRoot, url, actualDir, outPut, rtl::OUString::createFromAscii(commands[i].executable), commands[i].positive); break; @@ -386,8 +430,9 @@ bool excludeDirectory(rtl::OUString const & directory) { /// level <= 0) void handleDirectory( rtl::OUString const & url, int level, rtl::OUString const & project, - rtl::OUString const & projectRoot) + rtl::OUString const & projectRoot, rtl::OUString const & actualDir) { + std::ofstream output; osl::Directory dir(url); if (dir.open() != osl::FileBase::E_None) { std::cerr @@ -417,7 +462,8 @@ void handleDirectory( case -1: // the clone or src directory if (stat.getFileType() == osl::FileStatus::Directory) { handleDirectory( - stat.getFileURL(), 0, rtl::OUString(), rtl::OUString()); + stat.getFileURL(), 0, rtl::OUString(), + rtl::OUString(), actualDir); } break; case 0: // a root directory @@ -425,12 +471,14 @@ void handleDirectory( if (includeProject(stat.getFileName())) { handleDirectory( stat.getFileURL(), 1, stat.getFileName(), - rtl::OUString()); - } else if ( stat.getFileName() == "clone" || stat.getFileName() == "src" ) + rtl::OUString(), actualDir.concat("/"). + concat(stat.getFileName())); + } else if ( stat.getFileName() == "clone" || + stat.getFileName() == "src" ) { handleDirectory( stat.getFileURL(), -1, rtl::OUString(), - rtl::OUString()); + rtl::OUString(), actualDir); } } break; @@ -442,24 +490,29 @@ void handleDirectory( pr += rtl::OUString('/'); } pr += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("..")); - handleDirectory(stat.getFileURL(), 2, project, pr); + handleDirectory(stat.getFileURL(), 2, project, pr, + actualDir.concat("/"). + concat(stat.getFileName())); } } else { - handleFile(project, projectRoot, stat.getFileURL()); + handleFile(project, projectRoot, + stat.getFileURL(), actualDir, output); } break; } } + if (output.is_open()) + output.close(); if (dir.close() != osl::FileBase::E_None) { std::cerr << "Error: Cannot close directory\n"; throw false; //TODO } } -void handleProjects(char const * root) { +void handleProjects(char const * sourceRoot, char const * destRoot) { rtl::OUString root16; if (!rtl_convertStringToUString( - &root16.pData, root, rtl_str_getLength(root), + &root16.pData, sourceRoot, rtl_str_getLength(sourceRoot), osl_getThreadTextEncoding(), (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR @@ -475,9 +528,19 @@ void handleProjects(char const * root) { std::cerr << "Error: Cannot convert pathname to URL\n"; throw false; //TODO } - handleDirectory(rootUrl, 0, rtl::OUString(), rtl::OUString()); + rtl::OUString outPutRoot; + if (!rtl_convertStringToUString( + &outPutRoot.pData, destRoot, rtl_str_getLength(destRoot), + osl_getThreadTextEncoding(), + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))) + { + std::cerr << "Error: Cannot convert pathname to UTF-16\n"; + throw false; //TODO + } + handleDirectory(rootUrl, 0, rtl::OUString(), rtl::OUString(), outPutRoot); } - } SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { @@ -490,17 +553,11 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { "Syntax: localize \n"); std::exit(EXIT_FAILURE); } - global::output.open(argv[2], std::ios_base::out | std::ios_base::trunc); - if (!global::output.is_open()) { - std::cerr << "Error: Cannot append to " << argv[2] << '\n'; - std::exit(EXIT_FAILURE); - } try { - handleProjects(argv[1]); + handleProjects(argv[1],argv[2]); } catch (bool) { //TODO return EXIT_FAILURE; } - global::output.close(); return EXIT_SUCCESS; } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx new file mode 100644 index 000000000000..ab926792f70d --- /dev/null +++ b/l10ntools/source/po.cxx @@ -0,0 +1,309 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "po.hxx" +#include +#include + +#define ESCAPED OString("\\n\\t\\r\\\\\\\"") +#define UNESCAPED OString("\n\t\r\\\"") + + +//Get actual time in "YEAR-MO-DA HO:MI+ZONE" form +OString ImplGetTime() +{ + time_t aNow(time(NULL)); + struct tm* pNow(localtime(&aNow)); + char pBuff[50]; + strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); + return pBuff; +} + +//Split string at the delimiter char +void ImplSplitAt(const OString& rSource, const sal_Int32 nDelimiter, + std::vector& o_vParts) +{ + o_vParts.resize( 0 ); + sal_Int32 nActIndex( 0 ); + sal_Int32 nLastSplit( 0 ); + while( nActIndex < rSource.getLength() ) + { + if ( rSource[nActIndex] == nDelimiter ) + { + o_vParts.push_back(rSource.copy(nLastSplit,nActIndex-nLastSplit)); + nLastSplit = nActIndex+1; + } + ++nActIndex; + } + o_vParts.push_back(rSource.copy(nLastSplit)); +} + +//Escape text +OString ImplEscapeText(const OString& rText, const OString& rUnEscaped, + const OString& rEscaped) +{ + if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; + OString sResult = rText; + sal_Int32 nCount = 0; + for(sal_Int32 nIndex=0; nIndex\\\"\\\\","<>\"\\"); +} + +//Unescape extracted text +OString ImplFromSDFText(const OString& rText) +{ + return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); +} + + +//Generate msgctxt, msgid and msgstr strings +OString ImplGenMsgString(const OString& rSource) +{ + if ( rSource.isEmpty() ) + return "\"\""; + + OString sResult = "\"" + rSource + "\""; + sal_Int32 nIndex = 0; + while((nIndex=sResult.indexOf("\\n",nIndex))!=-1) + { + if( sResult.copy(nIndex-1,3) != "\\\\n" ) + sResult = sResult.replaceAt(nIndex,2,"\\n\"\n\""); + ++nIndex; + } + + if ( sResult.indexOf('\n') != -1 ) + return "\"\"\n" + sResult; + + return sResult; +} + +//Generate crc24 +sal_Int32 ImplGenCRC24(const OString& rKey) +{ + const sal_Int32 CRC24_INIT = 0x00b704ce; + const sal_Int32 CRC24_POLY = 0x00864cfb; + sal_Int32 nCRC = CRC24_INIT; + sal_Int32 nPosition = 0; + + while ( nPosition < rKey.getLength() ) + { + nCRC ^= sal_Int32(rKey[nPosition]) << 16; + for (sal_uInt16 i = 0; i < 8; ++i) + { + nCRC <<= 1; + if (nCRC & 0x01000000) + nCRC ^= CRC24_POLY; + } + ++nPosition; + } + return nCRC & 0x00ffffff; +} + +//Generate KeyId +OString ImplGenKeyId(const OString& rSourcePath, const OString& rContext) +{ + std::vector vPathParts; + ImplSplitAt(rSourcePath,'\\',vPathParts); + if ( vPathParts.size()<3 ) throw; + + sal_Int32 nCRC = ImplGenCRC24( vPathParts[vPathParts.size()-3] + "_" + + vPathParts[vPathParts.size()-2] + "_" + + vPathParts[vPathParts.size()-1] + "_" + + rContext); + const OString sSymbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#_"; + OString sKeyId = ""; + while ( sKeyId.getLength() < 4 ) + { + sKeyId += sSymbols.copy(nCRC & 63, 1); + nCRC >>= 6; + } + return sKeyId; +} + +//Default constructor +PoEntry::PoEntry() + : m_sWhiteSpace( OString() ) + , m_sExtractCom( OString() ) + , m_sReference( OString() ) + , m_sContext( OString() ) + , m_sUnTransStr( OString() ) + , m_sTransStr( OString() ) + , m_sKeyId( OString() ) +{ +} + +//Construct PoEntry from sdfline +PoEntry::PoEntry(const OString& rSDFLine, const sal_uInt16 eType) + : m_sWhiteSpace( "\n" ) + , m_sExtractCom( OString() ) + , m_sTransStr( OString() ) + , m_sKeyId( OString() ) +{ + std::vector vParts; + ImplSplitAt(rSDFLine,'\t',vParts); + if(vParts.size()!=15) throw; + + m_sReference = vParts[SOURCEFILE]. + copy(vParts[SOURCEFILE].lastIndexOf("\\")+1); + m_sContext = vParts[GROUPID] + "\\n" + + (vParts[LOCALID].isEmpty()? "" : vParts[LOCALID] + "\\n") + + vParts[RESOURCETYPE]; + + switch(eType){ + case TEXT: + m_sContext += ".text"; break; + case QUICKHELPTEXT: + m_sContext += ".quickhelptext"; break; + case TITLE: + m_sContext += ".title"; break; + default: + throw; break; + } + if (m_sReference.endsWith(".xhp")) + m_sUnTransStr = ImplFromSDFHelpText(vParts[eType]); + else + m_sUnTransStr = ImplFromSDFText(vParts[eType]); + + m_sExtractCom = vParts[HELPTEXT]; + m_sKeyId = ImplGenKeyId(vParts[PROJECT] + + "\\" + vParts[SOURCEFILE],m_sContext); +} + +PoEntry::~PoEntry() +{ +} + +//Write out +void PoEntry::writeToFile(std::ofstream& io_rOFStream) +{ + if ( !m_sWhiteSpace.isEmpty() ) + io_rOFStream << m_sWhiteSpace.getStr(); + if ( !m_sExtractCom.isEmpty() ) + io_rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; + if ( !m_sKeyId.isEmpty() ) + io_rOFStream << "#. " << m_sKeyId.getStr() << std::endl; + if ( !m_sReference.isEmpty() ) + io_rOFStream << "#: " << m_sReference.getStr() << std::endl; + if ( !m_sContext.isEmpty() ) + io_rOFStream << "msgctxt " + << ImplGenMsgString(m_sContext).getStr() << std::endl; + io_rOFStream << "msgid " + << ImplGenMsgString( + ImplEscapeText(m_sUnTransStr)).getStr() + << std::endl; + io_rOFStream << "msgstr " + << ImplGenMsgString( + ImplEscapeText(m_sTransStr)).getStr() + << std::endl; +} + +void PoEntry::setTransStr(const OString& rTransStr) +{ + m_sTransStr = ImplUnEscapeText(rTransStr); +} + +//Constructor +PoHeader::PoHeader( const OString& rExtSrc ) + : m_sExtractionSource( rExtSrc ) + , m_sProjectIdVersion( "PACKAGE VERSION" ) + , m_sReportMsgidBugsTo( OString("https://bugs.freedesktop.org/") + + "enter_bug.cgi?product=LibreOffice&" + + "bug_status=UNCONFIRMED&component=UI" ) + , m_sPotCreationDate( ImplGetTime() ) + , m_sPoRevisionDate( "YEAR-MO-DA HO:MI+ZONE" ) + , m_sLastTranslator( "FULL NAME " ) + , m_sLanguageTeam( "LANGUAGE " ) + , m_sMimeVersion( "1.0" ) + , m_sContentType( "text/plain" ) + , m_sCharset( "UTF-8" ) + , m_sEncoding( "8bit" ) + , m_sXGenerator( "LibreOffice" ) + , m_sXAcceleratorMarker( "~" ) +{ + setExtractCom("extracted from " + rExtSrc); + setTransStr("Project-Id-Version: " + m_sProjectIdVersion + "\n" + + "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + + "POT-Creation-Date: " + m_sPotCreationDate + "\n" + + "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + + "Last-Translator: " + m_sLastTranslator + "\n" + + "Language-Team: " + m_sLanguageTeam + "\n" + + "MIME-Version: " + m_sMimeVersion + "\n" + + "Content-Type: " + m_sContentType + "; " + + "charset=" + m_sCharset + "\n" + + "Content-Transfer-Encoding: " + m_sEncoding + "\n" + + "X-Genarator: " + m_sXGenerator + "\n" + + "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); +} + +PoHeader::~PoHeader() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx new file mode 100644 index 000000000000..c9fad34a99f3 --- /dev/null +++ b/l10ntools/source/renewpo.cxx @@ -0,0 +1,168 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include +#include +#include +#include +#include +#include "po.hxx" + +using namespace std; + +//Check wheather the two entry are the same but in different languages +bool IsSameEntry(const OString& rFirstEntry,const OString& rSecEntry) +{ + for(int i = PoEntry::PROJECT; i<=PoEntry::LOCALID;++i) + { + if ( rFirstEntry.getToken(i,'\t') != rSecEntry.getToken(i,'\t')) + return false; + } + return true; +} + +//Get path of po file +OString GetPath(const OString& rPath, const OString& rLine) +{ + OString sSourceFile = rLine.getToken(PoEntry::SOURCEFILE,'\t'); + OString sSourcePath = rPath + "/" + + rLine.getToken(PoEntry::PROJECT,'\t') + "/" + + sSourceFile.copy(0,sSourceFile.lastIndexOf("\\")). + replaceAll("\\","/"); + return sSourcePath; +} + +//Renew po files of the actual language +void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, + const OString& rpo2ooPath, const OString& rSDFPath) +{ + const OString LangEntryName = pLangEntry->d_name; + const OString SDFFileName = LangEntryName + ".sdf"; + + //Generate and open sdf + cout << "Start process with language: " << LangEntryName.getStr() << endl; + system( (rpo2ooPath + " -t " + rSDFPath + + " -l " + LangEntryName + " " + + rPath.getStr() + LangEntryName + " " + + SDFFileName).getStr()); + + ofstream aOutPut; + ifstream aSDFInput(SDFFileName.getStr()); + string s; + getline(aSDFInput,s); + OString sLine = OString(s.data(),s.length()); + while(!aSDFInput.eof()) + { + OString sActUnTrans = sLine; + OString sPath = rPath + LangEntryName; + OString sActSourcePath = GetPath(sPath,sActUnTrans); + //Make new po file, copy header with some changes + if (!aOutPut.is_open()) + { + aOutPut.open((sActSourcePath + ".po_tmp").getStr(), + std::ios_base::out | std::ios_base::trunc); + ifstream aPOInput((sActSourcePath + ".po").getStr()); + getline(aPOInput,s); + while(s!="") + { + if (s.find("#. extracted from")!=string::npos) + s = string(s,0,s.length()-3); + if (s.find("Report-Msgid-Bugs-To")!=string::npos) + s = string("\"Report-Msgid-Bugs-To: ") + + "https://bugs.freedesktop.org/enter_bug.cgi?product=" + + "LibreOffice&bug_status=UNCONFIRMED&component=UI\\n\""; + if (s.find("X-Generator")!=string::npos) + s = "\"X-Generator: LibreOffice\\n\""; + aOutPut << s << endl; + getline(aPOInput,s); + }; + aPOInput.close(); + } + + //Set PoEntry and write out + getline(aSDFInput,s); + sLine = OString(s.data(),s.length()); + OString sActTrans; + if (IsSameEntry(sActUnTrans,sLine)) + { + sActTrans = sLine; + getline(aSDFInput,s); + sLine = OString(s.data(),s.length()); + } + else + { + sActTrans =""; + } + PoEntry aPE(sActUnTrans); + aPE.setTransStr(sActTrans.getToken(PoEntry::TEXT,'\t')); + aPE.writeToFile(aOutPut); + + //Check wheather next entry is in the same po file + OString sNextSourcePath = GetPath(sPath,sLine); + if (sNextSourcePath!=sActSourcePath) + { + aOutPut.close(); + system(("rm " + sActSourcePath +".po").getStr()); + system(("mv "+ sActSourcePath +".po_tmp " + + sActSourcePath +".po").getStr()); + } + } + + //Close and remove sdf file + aSDFInput.close(); + system(("rm " + SDFFileName).getStr()); + aOutPut.close(); +} + + +int main(int argc, char* argv[]) +{ + //Usage + if (argc < 4) + { + cout << "Use: renewpot translationsdir po2oo en-us.sdf" << endl; + cout << "translationsdir: in this dir there are language" << endl; + cout << "directories which contain the po files. These" << endl; + cout << "directories have named by the languageid" << endl; + cout << "po2oo: the path withwhich po2oo can be call" << endl; + cout << "en-us.sdf: the path to call po2oo with this sdf" << endl; + return 1; + } + + //Call processing function with all language directories + DIR* pTranslations = opendir(argv[1]); + while ( struct dirent* pActEntry = readdir(pTranslations) ) + { + if ( OString(pActEntry->d_name).indexOf('.')==-1 ) + HandleLanguage(pActEntry,OString(argv[1]), + OString(argv[2]),OString(argv[3])); + } + closedir(pTranslations); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit From 0319a1c8d1df4a86b847f5d6178966a29e7c24cb Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 29 Aug 2012 09:51:44 +0200 Subject: Some improvement in po classes Raise general po functionalities from PoEntry to the GenPoEntry class. Thus PoEntry contains only the specific things with which LibreOffice localization tool works. Improve escaping text. Change-Id: I98894e7c218d37c226f48b30a1f8b59a5ff1a0bf Reviewed-on: https://gerrit.libreoffice.org/507 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 58 +++++++--- l10ntools/source/localize.cxx | 4 +- l10ntools/source/po.cxx | 248 ++++++++++++++++++++++-------------------- 3 files changed, 173 insertions(+), 137 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index de01053ba217..ffdb0d2af36c 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -32,7 +32,7 @@ #include #include -class PoEntry +class GenPoEntry { private: @@ -44,31 +44,55 @@ private: OString m_sUnTransStr; OString m_sTransStr; - OString m_sKeyId; - -protected: - void setExtractCom(const OString& rExtCom) - { m_sExtractCom = rExtCom; } - public: - PoEntry(); - PoEntry(const OString& i_rSDFLine, - const sal_uInt16 eType = TEXT); - virtual ~PoEntry(); - - virtual void writeToFile(std::ofstream& io_rOFStream); - - void setTransStr(const OString& rTransStr); + GenPoEntry(); + virtual ~GenPoEntry(); + + virtual void setWhiteSpace(const OString& rWhiteSpace) + { m_sWhiteSpace = rWhiteSpace; } + virtual void setExtractCom(const OString& rExtractCom) + { m_sExtractCom = rExtractCom; } + virtual void setReference(const OString& rReference) + { m_sReference = rReference; } + virtual void setContext(const OString& rContext) + { m_sContext = rContext; } + virtual void setUnTransStr(const OString& rUnTransStr) + { m_sUnTransStr = rUnTransStr; } + virtual void setTransStr(const OString& rTransStr) + { m_sTransStr = rTransStr; } + + virtual void writeToFile(std::ofstream& io_rOFStream); +}; +class PoEntry: public GenPoEntry +{ +public: enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID, TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP }; -}; + enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE }; +private: + + OString m_sSourceFile; + OString m_sGroupId; + OString m_sLocalId; + OString m_sResourceType; + TYPE m_eType; + OString m_sHelpText; + OString m_sKeyId; +public: + + PoEntry(const OString& i_rSDFLine, + const TYPE eType = TTEXT); + virtual ~PoEntry(); + virtual void setUnTransStr(const OString& rUnTransStr); + virtual void setTransStr(const OString& rTransStr); +}; -class PoHeader: public PoEntry +class PoHeader: public GenPoEntry { private: diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index c10c3f515c0f..ac24ed6733e5 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -286,9 +286,9 @@ void handleCommand( if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) PoEntry(sLine).writeToFile(outPut); if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) - PoEntry(sLine,PoEntry::QUICKHELPTEXT).writeToFile(outPut); + PoEntry(sLine,PoEntry::TQUICKHELPTEXT).writeToFile(outPut); if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) - PoEntry(sLine,PoEntry::TITLE).writeToFile(outPut); + PoEntry(sLine,PoEntry::TTITLE).writeToFile(outPut); } std::getline(in, s); }; diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index ab926792f70d..98364f3d6036 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -30,42 +30,15 @@ #include #include -#define ESCAPED OString("\\n\\t\\r\\\\\\\"") -#define UNESCAPED OString("\n\t\r\\\"") +#define POESCAPED OString("\\n\\t\\r\\\\\\\"") +#define POUNESCAPED OString("\n\t\r\\\"") - -//Get actual time in "YEAR-MO-DA HO:MI+ZONE" form -OString ImplGetTime() -{ - time_t aNow(time(NULL)); - struct tm* pNow(localtime(&aNow)); - char pBuff[50]; - strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); - return pBuff; -} - -//Split string at the delimiter char -void ImplSplitAt(const OString& rSource, const sal_Int32 nDelimiter, - std::vector& o_vParts) -{ - o_vParts.resize( 0 ); - sal_Int32 nActIndex( 0 ); - sal_Int32 nLastSplit( 0 ); - while( nActIndex < rSource.getLength() ) - { - if ( rSource[nActIndex] == nDelimiter ) - { - o_vParts.push_back(rSource.copy(nLastSplit,nActIndex-nLastSplit)); - nLastSplit = nActIndex+1; - } - ++nActIndex; - } - o_vParts.push_back(rSource.copy(nLastSplit)); -} +//Class GenPoEntry //Escape text -OString ImplEscapeText(const OString& rText, const OString& rUnEscaped, - const OString& rEscaped) +OString ImplEscapeText(const OString& rText, + const OString& rUnEscaped= POUNESCAPED, + const OString& rEscaped = POESCAPED) { if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; OString sResult = rText; @@ -80,16 +53,10 @@ OString ImplEscapeText(const OString& rText, const OString& rUnEscaped, return sResult; } - -//Escape text to write to po files -OString ImplEscapeText(const OString& rText) -{ - return ImplEscapeText(rText,UNESCAPED,ESCAPED); -} - //Unescape text -OString ImplUnEscapeText(const OString& rText,const OString& rEscaped, - const OString& rUnEscaped) +OString ImplUnEscapeText(const OString& rText, + const OString& rEscaped = POESCAPED, + const OString& rUnEscaped = POUNESCAPED) { if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; OString sResult = rText; @@ -104,25 +71,6 @@ OString ImplUnEscapeText(const OString& rText,const OString& rEscaped, return sResult; } -//Unescape text from po files -OString ImplUnEscapeText(const OString& rText) -{ - return ImplUnEscapeText(rText,ESCAPED,UNESCAPED); -} - -//Unescape extracted helptext -OString ImplFromSDFHelpText(const OString& rText) -{ - return ImplUnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); -} - -//Unescape extracted text -OString ImplFromSDFText(const OString& rText) -{ - return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); -} - - //Generate msgctxt, msgid and msgstr strings OString ImplGenMsgString(const OString& rSource) { @@ -144,6 +92,67 @@ OString ImplGenMsgString(const OString& rSource) return sResult; } +//Default constructor +GenPoEntry::GenPoEntry() + : m_sWhiteSpace( OString() ) + , m_sExtractCom( OString() ) + , m_sReference( OString() ) + , m_sContext( OString() ) + , m_sUnTransStr( OString() ) + , m_sTransStr( OString() ) +{ +} + +//Destructor +GenPoEntry::~GenPoEntry() +{ +} + +//Write to file +void GenPoEntry::writeToFile(std::ofstream& io_rOFStream) +{ + if ( !m_sWhiteSpace.isEmpty() ) + io_rOFStream << m_sWhiteSpace.getStr(); + if ( !m_sExtractCom.isEmpty() ) + io_rOFStream << "#. " + << m_sExtractCom.replaceAll("\n","\n#. ").getStr() + << std::endl; + if ( !m_sReference.isEmpty() ) + io_rOFStream << "#: " << m_sReference.getStr() << std::endl; + if ( !m_sContext.isEmpty() ) + io_rOFStream << "msgctxt " + << ImplGenMsgString(m_sContext).getStr() << std::endl; + io_rOFStream << "msgid " + << ImplGenMsgString( + ImplEscapeText(m_sUnTransStr)).getStr() + << std::endl; + io_rOFStream << "msgstr " + << ImplGenMsgString( + ImplEscapeText(m_sTransStr)).getStr() + << std::endl; +} + +//Class PoEntry + +//Split string at the delimiter char +void ImplSplitAt(const OString& rSource, const sal_Int32 nDelimiter, + std::vector& o_vParts) +{ + o_vParts.resize( 0 ); + sal_Int32 nActIndex( 0 ); + sal_Int32 nLastSplit( 0 ); + while( nActIndex < rSource.getLength() ) + { + if ( rSource[nActIndex] == nDelimiter ) + { + o_vParts.push_back(rSource.copy(nLastSplit,nActIndex-nLastSplit)); + nLastSplit = nActIndex+1; + } + ++nActIndex; + } + o_vParts.push_back(rSource.copy(nLastSplit)); +} + //Generate crc24 sal_Int32 ImplGenCRC24(const OString& rKey) { @@ -187,86 +196,89 @@ OString ImplGenKeyId(const OString& rSourcePath, const OString& rContext) return sKeyId; } -//Default constructor -PoEntry::PoEntry() - : m_sWhiteSpace( OString() ) - , m_sExtractCom( OString() ) - , m_sReference( OString() ) - , m_sContext( OString() ) - , m_sUnTransStr( OString() ) - , m_sTransStr( OString() ) - , m_sKeyId( OString() ) -{ -} - //Construct PoEntry from sdfline -PoEntry::PoEntry(const OString& rSDFLine, const sal_uInt16 eType) - : m_sWhiteSpace( "\n" ) - , m_sExtractCom( OString() ) - , m_sTransStr( OString() ) +PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) + : m_sSourceFile( OString() ) + , m_sGroupId( OString() ) + , m_sLocalId( OString() ) + , m_sResourceType(OString() ) + , m_eType( TTEXT ) , m_sKeyId( OString() ) { + setWhiteSpace("\n"); std::vector vParts; ImplSplitAt(rSDFLine,'\t',vParts); if(vParts.size()!=15) throw; - m_sReference = vParts[SOURCEFILE]. - copy(vParts[SOURCEFILE].lastIndexOf("\\")+1); - m_sContext = vParts[GROUPID] + "\\n" + - (vParts[LOCALID].isEmpty()? "" : vParts[LOCALID] + "\\n") + - vParts[RESOURCETYPE]; - + m_sSourceFile = vParts[SOURCEFILE]. + copy(vParts[SOURCEFILE].lastIndexOf("\\")+1); + setReference(m_sSourceFile); + m_sGroupId = vParts[GROUPID]; + m_sLocalId = vParts[LOCALID]; + m_sResourceType = vParts[RESOURCETYPE]; + m_eType = eType; + m_sHelpText = vParts[HELPTEXT]; + + OString sContext = m_sGroupId + "\\n" + + (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\\n") + + m_sResourceType; switch(eType){ - case TEXT: - m_sContext += ".text"; break; - case QUICKHELPTEXT: - m_sContext += ".quickhelptext"; break; - case TITLE: - m_sContext += ".title"; break; + case TTEXT: + sContext += ".text"; break; + case TQUICKHELPTEXT: + sContext += ".quickhelptext"; break; + case TTITLE: + sContext += ".title"; break; default: throw; break; } - if (m_sReference.endsWith(".xhp")) - m_sUnTransStr = ImplFromSDFHelpText(vParts[eType]); - else - m_sUnTransStr = ImplFromSDFText(vParts[eType]); + setContext(sContext); + m_sKeyId = ImplGenKeyId(vParts[PROJECT] + "\\" + vParts[SOURCEFILE], + sContext); + setExtractCom((m_sHelpText.isEmpty() ? "" : m_sHelpText + "\n") + m_sKeyId); - m_sExtractCom = vParts[HELPTEXT]; - m_sKeyId = ImplGenKeyId(vParts[PROJECT] + - "\\" + vParts[SOURCEFILE],m_sContext); + setUnTransStr(vParts[eType]); } PoEntry::~PoEntry() { } -//Write out -void PoEntry::writeToFile(std::ofstream& io_rOFStream) +//Unescape sdf text +OString ImplUnEscapeSDFText(const OString& rText,const bool bHelpText = false) { - if ( !m_sWhiteSpace.isEmpty() ) - io_rOFStream << m_sWhiteSpace.getStr(); - if ( !m_sExtractCom.isEmpty() ) - io_rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; - if ( !m_sKeyId.isEmpty() ) - io_rOFStream << "#. " << m_sKeyId.getStr() << std::endl; - if ( !m_sReference.isEmpty() ) - io_rOFStream << "#: " << m_sReference.getStr() << std::endl; - if ( !m_sContext.isEmpty() ) - io_rOFStream << "msgctxt " - << ImplGenMsgString(m_sContext).getStr() << std::endl; - io_rOFStream << "msgid " - << ImplGenMsgString( - ImplEscapeText(m_sUnTransStr)).getStr() - << std::endl; - io_rOFStream << "msgstr " - << ImplGenMsgString( - ImplEscapeText(m_sTransStr)).getStr() - << std::endl; + if ( bHelpText ) + return ImplUnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); + else + return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); } +//Set translation text when input is in sdf format +void PoEntry::setUnTransStr(const OString& rUnTransStr) +{ + GenPoEntry::setUnTransStr( + ImplUnEscapeSDFText( + rUnTransStr,m_sSourceFile.endsWith(".xhp"))); +} + +//Set translated text when input is in sdf format void PoEntry::setTransStr(const OString& rTransStr) { - m_sTransStr = ImplUnEscapeText(rTransStr); + GenPoEntry::setTransStr( + ImplUnEscapeSDFText( + rTransStr,m_sSourceFile.endsWith(".xhp"))); +} + +//Class PoHeader + +//Get actual time in "YEAR-MO-DA HO:MI+ZONE" form +OString ImplGetTime() +{ + time_t aNow(time(NULL)); + struct tm* pNow(localtime(&aNow)); + char pBuff[50]; + strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); + return pBuff; } //Constructor -- cgit From 305ecb308a9b6f54263fd526cfdda9167fcaab56 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 29 Aug 2012 09:54:30 +0200 Subject: Make renew working well Change po2lo output: write out the untranslated sdf line too, write out translated sdf line only if there is translation to the komponent, write out fuzzy entries and indicate which entries are fuzzy. Change GenPoEntry to write out fuzzy flag Change renewpo to write out all type of entries not just text and to remove id duplicates which are made by xrmex Change-Id: Idc9b6062638d1d5fcbbae75e0396996b63e9a7a0 Reviewed-on: https://gerrit.libreoffice.org/508 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 3 ++ l10ntools/scripts/po2lo | 29 +++++++++++------- l10ntools/source/localize.cxx | 16 +++++----- l10ntools/source/po.cxx | 3 ++ l10ntools/source/renewpo.cxx | 69 +++++++++++++++++++++++++++++++++---------- 5 files changed, 85 insertions(+), 35 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index ffdb0d2af36c..fddd9074cf9d 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -43,6 +43,7 @@ private: OString m_sContext; OString m_sUnTransStr; OString m_sTransStr; + bool m_bFuzzy; public: GenPoEntry(); @@ -60,6 +61,8 @@ public: { m_sUnTransStr = rUnTransStr; } virtual void setTransStr(const OString& rTransStr) { m_sTransStr = rTransStr; } + virtual void setFuzzy(bool bFuzzy) + { m_bFuzzy = bFuzzy; } virtual void writeToFile(std::ofstream& io_rOFStream); }; diff --git a/l10ntools/scripts/po2lo b/l10ntools/scripts/po2lo index cdf8892fc950..579699102710 100755 --- a/l10ntools/scripts/po2lo +++ b/l10ntools/scripts/po2lo @@ -41,6 +41,7 @@ class Entry: """Represents a single line in an SDF file.""" def __init__(self, items): + self.has_translation = None; self.items = items # list of 15 fields path = self.items[1].split('\\') self.po = "%s/%s/%s.po" % (options.input.replace('\\', '/'), self.items[0], "/".join(path[:-1])) @@ -65,13 +66,20 @@ class Entry: """Translates text in the entry based on translations.""" self.items[9] = options.language + self.items[2] = "" + self.has_translation = False for idx, key in self.keys: try: - self.items[idx] = translations.data[(self.po, key)] + if translations.data[(self.po, key)][1]: + self.items[2] += "1" + else: + self.items[2] += "0" + self.items[idx] = translations.data[(self.po, key)][0] + self.has_translation = True self.items[14] = "2002-02-02 02:02:02" except KeyError: - pass + self.items[idx]="" self.items[14] = self.items[14].strip() def sdf2po(self, s): @@ -95,8 +103,10 @@ class Template: sock = xopen(options.output, "w", encoding='utf-8') for line in self.lines: + sock.write("\t".join(line.items)) line.translate(translations) - sock.write("\t".join(line.items)+"\r\n") + if line.has_translation: + sock.write("\t".join(line.items)+"\r\n") sock.close() class Translations: @@ -120,10 +130,10 @@ class Translations: elif line.startswith("msgstr "): trans = line.strip()[8:-1] if len(trans): + self.setdata(path, key, trans, fuzzy) if fuzzy: fuzzy = False else: - self.setdata(path, key, trans) multiline = False else: buf = [] @@ -132,16 +142,15 @@ class Translations: elif multiline and line.startswith('"'): buf.append(line.strip()[1:-1]) elif multiline and not len(line.strip()) and len("".join(buf)): + self.setdata(path, key, "".join(buf),fuzzy) if fuzzy: fuzzy = False - else: - self.setdata(path, key, "".join(buf)) buf = [] multiline = False - if multiline and len("".join(buf)) and not fuzzy: - self.setdata(path, key, "".join(buf)) + if multiline and len("".join(buf)): + self.setdata(path, key, "".join(buf),fuzzy) - def setdata(self, path, key, s): + def setdata(self, path, key, s, fuzzy = False): """Sets the translation for a given path and key, handling (un)escaping as well.""" if key: @@ -151,7 +160,7 @@ class Translations: s = self.escape_help_text(s) else: s = s.replace('\\\\', '\\') - self.data[(path.replace('\\', '/'), key)] = s + self.data[(path.replace('\\', '/'), key)] = ( s , fuzzy ) def escape_help_text(self, text): """Escapes the help text as it would be in an SDF file.""" diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index ac24ed6733e5..bef2444ae6a8 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -281,15 +281,13 @@ void handleCommand( while (!in.eof()) { OString sLine = OString(s.data(),s.length()); - if (!sLine.isEmpty()) - { - if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) - PoEntry(sLine).writeToFile(outPut); - if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) - PoEntry(sLine,PoEntry::TQUICKHELPTEXT).writeToFile(outPut); - if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) - PoEntry(sLine,PoEntry::TTITLE).writeToFile(outPut); - } + + if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) + PoEntry(sLine).writeToFile(outPut); + if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) + PoEntry(sLine,PoEntry::TQUICKHELPTEXT).writeToFile(outPut); + if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) + PoEntry(sLine,PoEntry::TTITLE).writeToFile(outPut); std::getline(in, s); }; in.close(); diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 98364f3d6036..9bedf4d2d409 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -100,6 +100,7 @@ GenPoEntry::GenPoEntry() , m_sContext( OString() ) , m_sUnTransStr( OString() ) , m_sTransStr( OString() ) + , m_bFuzzy( false ) { } @@ -119,6 +120,8 @@ void GenPoEntry::writeToFile(std::ofstream& io_rOFStream) << std::endl; if ( !m_sReference.isEmpty() ) io_rOFStream << "#: " << m_sReference.getStr() << std::endl; + if ( m_bFuzzy ) + io_rOFStream << "#, fuzzy" << std::endl; if ( !m_sContext.isEmpty() ) io_rOFStream << "msgctxt " << ImplGenMsgString(m_sContext).getStr() << std::endl; diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index c9fad34a99f3..f68250ee37c0 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "po.hxx" @@ -40,7 +41,8 @@ bool IsSameEntry(const OString& rFirstEntry,const OString& rSecEntry) { for(int i = PoEntry::PROJECT; i<=PoEntry::LOCALID;++i) { - if ( rFirstEntry.getToken(i,'\t') != rSecEntry.getToken(i,'\t')) + if ( rFirstEntry.getToken(i,'\t') != rSecEntry.getToken(i,'\t') && + i != PoEntry::DUMMY) return false; } return true; @@ -57,19 +59,34 @@ OString GetPath(const OString& rPath, const OString& rLine) return sSourcePath; } +OString DelLocalId(const OString& rLine) +{ + sal_uInt16 nTabIndex = 0; + for(sal_uInt16 nComponent=0; nComponentd_name; const OString SDFFileName = LangEntryName + ".sdf"; //Generate and open sdf - cout << "Start process with language: " << LangEntryName.getStr() << endl; - system( (rpo2ooPath + " -t " + rSDFPath + - " -l " + LangEntryName + " " + - rPath.getStr() + LangEntryName + " " + - SDFFileName).getStr()); + cout << "Process start with language: " << LangEntryName.getStr() << endl; + system( (rpo2loPath + + " -i " + rPath.getStr() + LangEntryName + + " -o " + SDFFileName + + " -l " + LangEntryName + + " -t " + rSDFPath).getStr()); + cout << "Language sdf is ready!" << endl; ofstream aOutPut; ifstream aSDFInput(SDFFileName.getStr()); @@ -118,9 +135,31 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, { sActTrans =""; } - PoEntry aPE(sActUnTrans); - aPE.setTransStr(sActTrans.getToken(PoEntry::TEXT,'\t')); - aPE.writeToFile(aOutPut); + const vector vTypes = { PoEntry::TTEXT, + PoEntry::TQUICKHELPTEXT, + PoEntry::TTITLE }; + sal_uInt16 nDummyBit = 0; + for( sal_uInt16 nIndex=0; nIndex Date: Wed, 29 Aug 2012 12:42:11 +0200 Subject: Improve KeyId generation Move KeyId from PoEntry to GenPoEntry to make these classes more separated. Replace crc24 with crc32 (boost/crc). Extend KeyId's charset to [33,126] intervallum of ASCII Change-Id: If761a572e2a2651af3eab253a1582569ea68e440 Reviewed-on: https://gerrit.libreoffice.org/509 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 4 +-- l10ntools/source/po.cxx | 92 +++++++++++++++++++------------------------------ 2 files changed, 38 insertions(+), 58 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index fddd9074cf9d..3330afb0e880 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -44,6 +44,7 @@ private: OString m_sUnTransStr; OString m_sTransStr; bool m_bFuzzy; + OString m_sKeyId; public: GenPoEntry(); @@ -63,7 +64,7 @@ public: { m_sTransStr = rTransStr; } virtual void setFuzzy(bool bFuzzy) { m_bFuzzy = bFuzzy; } - + virtual void genKeyId(); virtual void writeToFile(std::ofstream& io_rOFStream); }; @@ -82,7 +83,6 @@ private: OString m_sResourceType; TYPE m_eType; OString m_sHelpText; - OString m_sKeyId; public: diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 9bedf4d2d409..c488c8798d0e 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -29,12 +29,29 @@ #include "po.hxx" #include #include +#include #define POESCAPED OString("\\n\\t\\r\\\\\\\"") #define POUNESCAPED OString("\n\t\r\\\"") //Class GenPoEntry +//Generate KeyId +OString ImplGenKeyId(const OString& rGenerator) +{ + boost::crc_32_type aCRC32; + aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); + sal_uInt32 nCRC = aCRC32.checksum(); + OString sKeyId = ""; + while ( sKeyId.getLength() < 4 ) + { + //Concat a char from the [33,126] intervallum of ASCII + sKeyId += OString(char(int(double(nCRC & 255)/255*93)+33)); + nCRC >>= 8; + } + return sKeyId; +} + //Escape text OString ImplEscapeText(const OString& rText, const OString& rUnEscaped= POUNESCAPED, @@ -101,6 +118,7 @@ GenPoEntry::GenPoEntry() , m_sUnTransStr( OString() ) , m_sTransStr( OString() ) , m_bFuzzy( false ) + , m_sKeyId( OString() ) { } @@ -109,15 +127,21 @@ GenPoEntry::~GenPoEntry() { } +//Set keyid +void GenPoEntry::genKeyId() +{ + m_sKeyId = ImplGenKeyId(m_sReference + m_sContext + m_sUnTransStr); +} + //Write to file void GenPoEntry::writeToFile(std::ofstream& io_rOFStream) { if ( !m_sWhiteSpace.isEmpty() ) io_rOFStream << m_sWhiteSpace.getStr(); if ( !m_sExtractCom.isEmpty() ) - io_rOFStream << "#. " - << m_sExtractCom.replaceAll("\n","\n#. ").getStr() - << std::endl; + io_rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; + if ( !m_sKeyId.isEmpty() ) + io_rOFStream << "#. " << m_sKeyId.getStr() << std::endl; if ( !m_sReference.isEmpty() ) io_rOFStream << "#: " << m_sReference.getStr() << std::endl; if ( m_bFuzzy ) @@ -125,14 +149,12 @@ void GenPoEntry::writeToFile(std::ofstream& io_rOFStream) if ( !m_sContext.isEmpty() ) io_rOFStream << "msgctxt " << ImplGenMsgString(m_sContext).getStr() << std::endl; - io_rOFStream << "msgid " - << ImplGenMsgString( - ImplEscapeText(m_sUnTransStr)).getStr() - << std::endl; - io_rOFStream << "msgstr " - << ImplGenMsgString( - ImplEscapeText(m_sTransStr)).getStr() - << std::endl; + io_rOFStream << "msgid " + << ImplGenMsgString(ImplEscapeText(m_sUnTransStr)).getStr() + << std::endl; + io_rOFStream << "msgstr " + << ImplGenMsgString(ImplEscapeText(m_sTransStr)).getStr() + << std::endl; } //Class PoEntry @@ -156,48 +178,7 @@ void ImplSplitAt(const OString& rSource, const sal_Int32 nDelimiter, o_vParts.push_back(rSource.copy(nLastSplit)); } -//Generate crc24 -sal_Int32 ImplGenCRC24(const OString& rKey) -{ - const sal_Int32 CRC24_INIT = 0x00b704ce; - const sal_Int32 CRC24_POLY = 0x00864cfb; - sal_Int32 nCRC = CRC24_INIT; - sal_Int32 nPosition = 0; - while ( nPosition < rKey.getLength() ) - { - nCRC ^= sal_Int32(rKey[nPosition]) << 16; - for (sal_uInt16 i = 0; i < 8; ++i) - { - nCRC <<= 1; - if (nCRC & 0x01000000) - nCRC ^= CRC24_POLY; - } - ++nPosition; - } - return nCRC & 0x00ffffff; -} - -//Generate KeyId -OString ImplGenKeyId(const OString& rSourcePath, const OString& rContext) -{ - std::vector vPathParts; - ImplSplitAt(rSourcePath,'\\',vPathParts); - if ( vPathParts.size()<3 ) throw; - - sal_Int32 nCRC = ImplGenCRC24( vPathParts[vPathParts.size()-3] + "_" + - vPathParts[vPathParts.size()-2] + "_" + - vPathParts[vPathParts.size()-1] + "_" + - rContext); - const OString sSymbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#_"; - OString sKeyId = ""; - while ( sKeyId.getLength() < 4 ) - { - sKeyId += sSymbols.copy(nCRC & 63, 1); - nCRC >>= 6; - } - return sKeyId; -} //Construct PoEntry from sdfline PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) @@ -206,7 +187,6 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) , m_sLocalId( OString() ) , m_sResourceType(OString() ) , m_eType( TTEXT ) - , m_sKeyId( OString() ) { setWhiteSpace("\n"); std::vector vParts; @@ -236,13 +216,13 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) throw; break; } setContext(sContext); - m_sKeyId = ImplGenKeyId(vParts[PROJECT] + "\\" + vParts[SOURCEFILE], - sContext); - setExtractCom((m_sHelpText.isEmpty() ? "" : m_sHelpText + "\n") + m_sKeyId); + setExtractCom(m_sHelpText); setUnTransStr(vParts[eType]); + genKeyId(); } +//Destructor PoEntry::~PoEntry() { } -- cgit From ecfa813595cb577781668219d9e17a0494f92bea Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 29 Aug 2012 12:58:29 +0200 Subject: Some cleanup Use normal integer types when it's unecessary to use sal_int types. Delete some hack from code. Change-Id: I93f0b1f260578d3aa9609b7e9d8a79053693971b Reviewed-on: https://gerrit.libreoffice.org/510 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/localize.cxx | 14 +++++++------- l10ntools/source/po.cxx | 22 +++++++++++----------- l10ntools/source/renewpo.cxx | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index bef2444ae6a8..598eccf60601 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -194,13 +194,13 @@ void handleCommand( throw false; //TODO } rtl::OUStringBuffer buf( - //getEnvironment( - //rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SOLARVER")))); - //buf.append('/'); - //buf.append( - //getEnvironment( - rtl::OUString("/home/zolnai/git/libo/solver/unxlngi6.pro")); - // RTL_CONSTASCII_USTRINGPARAM("INPATH_FOR_BUILD")))); + getEnvironment( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SOLARVER")))); + buf.append('/'); + buf.append( + getEnvironment( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("INPATH_FOR_BUILD")))); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/bin/")); buf.append(executable); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" -e -p ")); diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index c488c8798d0e..472e8766a86e 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -45,7 +45,7 @@ OString ImplGenKeyId(const OString& rGenerator) OString sKeyId = ""; while ( sKeyId.getLength() < 4 ) { - //Concat a char from the [33,126] intervallum of ASCII + //Concat a char from the [33,126] interval of ASCII sKeyId += OString(char(int(double(nCRC & 255)/255*93)+33)); nCRC >>= 8; } @@ -59,10 +59,10 @@ OString ImplEscapeText(const OString& rText, { if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; OString sResult = rText; - sal_Int32 nCount = 0; - for(sal_Int32 nIndex=0; nIndex& o_vParts) { o_vParts.resize( 0 ); - sal_Int32 nActIndex( 0 ); - sal_Int32 nLastSplit( 0 ); + int nActIndex( 0 ); + int nLastSplit( 0 ); while( nActIndex < rSource.getLength() ) { if ( rSource[nActIndex] == nDelimiter ) diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index f68250ee37c0..20738b1ca03c 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -61,8 +61,8 @@ OString GetPath(const OString& rPath, const OString& rLine) OString DelLocalId(const OString& rLine) { - sal_uInt16 nTabIndex = 0; - for(sal_uInt16 nComponent=0; nComponent vTypes = { PoEntry::TTEXT, PoEntry::TQUICKHELPTEXT, PoEntry::TTITLE }; - sal_uInt16 nDummyBit = 0; - for( sal_uInt16 nIndex=0; nIndex Date: Thu, 30 Aug 2012 12:41:18 +0200 Subject: More cleanup aka clean up cleanup Use integers consistently Change headers Make variable initialization uniform Change-Id: I91937704a80c0d5997ad81591ce79076794a4e32 Reviewed-on: https://gerrit.libreoffice.org/517 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/Executable_renewpo.mk | 19 ++++++--------- l10ntools/inc/po.hxx | 31 +++++-------------------- l10ntools/source/po.cxx | 51 +++++++++++++---------------------------- l10ntools/source/renewpo.cxx | 31 +++++-------------------- 4 files changed, 35 insertions(+), 97 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_renewpo.mk b/l10ntools/Executable_renewpo.mk index 33e38b22751f..4872e8a2bb77 100644 --- a/l10ntools/Executable_renewpo.mk +++ b/l10ntools/Executable_renewpo.mk @@ -1,18 +1,13 @@ -# for the specific language governing rights and limitations under the -# License. +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- # -# Major Contributor(s): -# Copyright (C) 2012 David Ostrovsky (initial developer) +# This file is part of the LibreOffice project. # -# All Rights Reserved. +# 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/. # -# For minor contributions see the git repository. +# convert old po to new po # -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 3 or later (the "GPLv3+"), or -# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), -# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable -# instead of those above. $(eval $(call gb_Executable_Executable,renewpo)) @@ -33,4 +28,4 @@ $(eval $(call gb_Executable_add_exception_objects,renewpo,\ l10ntools/source/renewpo \ )) -# vim:set shiftwidth=4 softtabstop=4 expandtab: +# vim: set noet sw=4 ts=4: diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 3330afb0e880..c03baf8dc829 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -1,30 +1,11 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 _PO_INCLUDED #define _PO_INCLUDED diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 472e8766a86e..6848d7e3680f 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -1,30 +1,11 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 "po.hxx" #include @@ -60,9 +41,9 @@ OString ImplEscapeText(const OString& rText, if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; OString sResult = rText; int nCount = 0; - for(int nIndex=0; nIndex& o_vParts) { o_vParts.resize( 0 ); - int nActIndex( 0 ); - int nLastSplit( 0 ); + sal_Int32 nActIndex = 0; + sal_Int32 nLastSplit = 0; while( nActIndex < rSource.getLength() ) { if ( rSource[nActIndex] == nDelimiter ) @@ -257,8 +238,8 @@ void PoEntry::setTransStr(const OString& rTransStr) //Get actual time in "YEAR-MO-DA HO:MI+ZONE" form OString ImplGetTime() { - time_t aNow(time(NULL)); - struct tm* pNow(localtime(&aNow)); + time_t aNow = time(NULL); + struct tm* pNow = localtime(&aNow); char pBuff[50]; strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); return pBuff; diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 20738b1ca03c..a6e127356118 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -1,30 +1,11 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 #include -- cgit From 8a8a39c4c129daa3547dce5f0caf20429997e919 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Fri, 31 Aug 2012 15:09:06 +0200 Subject: Implement more Po method for merge Implement file oprerations(entire reading and rest part of writing) Convert text to merge/sdf form Plus cleanup Change-Id: I6bab9bb202fcdc6d0f2a13f6c44d28e22c688e1e Reviewed-on: https://gerrit.libreoffice.org/520 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/Executable_localize.mk | 1 + l10ntools/Executable_renewpo.mk | 1 + l10ntools/StaticLibrary_transex.mk | 2 + l10ntools/inc/po.hxx | 20 ++- l10ntools/source/po.cxx | 324 +++++++++++++++++++++++++++++++------ l10ntools/source/renewpo.cxx | 4 +- 6 files changed, 299 insertions(+), 53 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_localize.mk b/l10ntools/Executable_localize.mk index 6184a8982bd5..e6e7f1fc2c6e 100644 --- a/l10ntools/Executable_localize.mk +++ b/l10ntools/Executable_localize.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,localize,\ $(eval $(call gb_Executable_use_libraries,localize,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,localize,\ diff --git a/l10ntools/Executable_renewpo.mk b/l10ntools/Executable_renewpo.mk index 4872e8a2bb77..5aa036a40100 100644 --- a/l10ntools/Executable_renewpo.mk +++ b/l10ntools/Executable_renewpo.mk @@ -18,6 +18,7 @@ $(eval $(call gb_Executable_set_include,renewpo,\ $(eval $(call gb_Executable_use_libraries,renewpo,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,renewpo,\ diff --git a/l10ntools/StaticLibrary_transex.mk b/l10ntools/StaticLibrary_transex.mk index 21f50e572ef6..82e20a012c5f 100644 --- a/l10ntools/StaticLibrary_transex.mk +++ b/l10ntools/StaticLibrary_transex.mk @@ -32,6 +32,8 @@ $(eval $(call gb_StaticLibrary_set_include,transex,\ $$(INCLUDE) \ )) +$(eval $(call gb_StaticLibrary_use_sdk_api,transex)) + $(eval $(call gb_StaticLibrary_add_exception_objects,transex,\ l10ntools/source/export2 \ l10ntools/source/merge \ diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index c03baf8dc829..df3004c1fe5e 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -31,6 +31,14 @@ public: GenPoEntry(); virtual ~GenPoEntry(); + virtual OString getWhiteSpace() const { return m_sWhiteSpace; } + virtual OString getExtractCom() const { return m_sExtractCom; } + virtual OString getReference() const { return m_sReference; } + virtual OString getContext() const { return m_sContext; } + virtual OString getUnTransStr() const { return m_sUnTransStr; } + virtual OString getTransStr() const { return m_sTransStr; } + virtual bool getFuzzy() const { return m_bFuzzy; } + virtual void setWhiteSpace(const OString& rWhiteSpace) { m_sWhiteSpace = rWhiteSpace; } virtual void setExtractCom(const OString& rExtractCom) @@ -46,7 +54,9 @@ public: virtual void setFuzzy(bool bFuzzy) { m_bFuzzy = bFuzzy; } virtual void genKeyId(); - virtual void writeToFile(std::ofstream& io_rOFStream); + + virtual void writeToFile(std::ofstream& rOFStream); + virtual void readFromFile(std::ifstream& rIFStream); }; class PoEntry: public GenPoEntry @@ -67,13 +77,19 @@ private: public: + PoEntry(); PoEntry(const OString& i_rSDFLine, - const TYPE eType = TTEXT); + const TYPE eType = TTEXT); virtual ~PoEntry(); + virtual OString getUnTransStr() const; + virtual OString getTransStr() const; virtual void setUnTransStr(const OString& rUnTransStr); virtual void setTransStr(const OString& rTransStr); + virtual void writeToFile(std::ofstream& rOFStream); + virtual void readFromFile(std::ifstream& rIFStream); + }; class PoHeader: public GenPoEntry diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 6848d7e3680f..a82a88b186f4 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -7,11 +7,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "po.hxx" +#include +#include +#include +#include +#include + +#include +#include #include #include #include +#include "po.hxx" + #define POESCAPED OString("\\n\\t\\r\\\\\\\"") #define POUNESCAPED OString("\n\t\r\\\"") @@ -69,17 +78,17 @@ OString ImplUnEscapeText(const OString& rText, return sResult; } -//Generate msgctxt, msgid and msgstr strings -OString ImplGenMsgString(const OString& rSource) +//Convert a normal string to msg/po output string +OString ImplGenMsgString(const OString& rString) { - if ( rSource.isEmpty() ) + if ( rString.isEmpty() ) return "\"\""; - OString sResult = "\"" + rSource + "\""; + OString sResult = "\"" + ImplEscapeText(rString) + "\""; sal_Int32 nIndex = 0; while((nIndex=sResult.indexOf("\\n",nIndex))!=-1) { - if( sResult.copy(nIndex-1,3) != "\\\\n" ) + if(sResult.copy(nIndex-1,3)!="\\\\n" && nIndex!=sResult.getLength()-3) sResult = sResult.replaceAt(nIndex,2,"\\n\"\n\""); ++nIndex; } @@ -90,6 +99,18 @@ OString ImplGenMsgString(const OString& rSource) return sResult; } +//Convert msg string to normal form +OString ImplGenNormString(const OString& rString) +{ + return ImplUnEscapeText(rString.copy(1,rString.getLength()-2)); +} + +//Decide whether a string starts with an other string +bool ImplStartsWith(const OString& rString,const OString& rStart) +{ + return rString.copy(0,rStart.getLength())==rStart; +} + //Default constructor GenPoEntry::GenPoEntry() : m_sWhiteSpace( OString() ) @@ -115,29 +136,79 @@ void GenPoEntry::genKeyId() } //Write to file -void GenPoEntry::writeToFile(std::ofstream& io_rOFStream) +void GenPoEntry::writeToFile(std::ofstream& rOFStream) { if ( !m_sWhiteSpace.isEmpty() ) - io_rOFStream << m_sWhiteSpace.getStr(); + rOFStream << m_sWhiteSpace.getStr(); if ( !m_sExtractCom.isEmpty() ) - io_rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; + rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; if ( !m_sKeyId.isEmpty() ) - io_rOFStream << "#. " << m_sKeyId.getStr() << std::endl; + rOFStream << "#. " << m_sKeyId.getStr() << std::endl; if ( !m_sReference.isEmpty() ) - io_rOFStream << "#: " << m_sReference.getStr() << std::endl; + rOFStream << "#: " << m_sReference.getStr() << std::endl; if ( m_bFuzzy ) - io_rOFStream << "#, fuzzy" << std::endl; + rOFStream << "#, fuzzy" << std::endl; if ( !m_sContext.isEmpty() ) - io_rOFStream << "msgctxt " - << ImplGenMsgString(m_sContext).getStr() << std::endl; - io_rOFStream << "msgid " - << ImplGenMsgString(ImplEscapeText(m_sUnTransStr)).getStr() - << std::endl; - io_rOFStream << "msgstr " - << ImplGenMsgString(ImplEscapeText(m_sTransStr)).getStr() - << std::endl; + rOFStream << "msgctxt " + << ImplGenMsgString(m_sContext).getStr() << std::endl; + rOFStream << "msgid " + << ImplGenMsgString(m_sUnTransStr).getStr() << std::endl; + rOFStream << "msgstr " + << ImplGenMsgString(m_sTransStr).getStr() << std::endl; } +//Read from file +void GenPoEntry::readFromFile(std::ifstream& rIFStream) +{ + m_sWhiteSpace = "\n"; + OString* pLastMsg = 0; + std::string sTemp; + getline(rIFStream,sTemp); + while(!rIFStream.eof()) + { + OString sLine = OString(sTemp.data(),sTemp.length()); + if (ImplStartsWith(sLine,"#. ")) + { + if (sLine.getLength()==7) + m_sKeyId = sLine.copy(3); + else + m_sExtractCom = sLine.copy(3); + } + else if (ImplStartsWith(sLine,"#: ")) + { + m_sReference = sLine.copy(3); + } + else if (ImplStartsWith(sLine,"#, fuzzy")) + { + m_bFuzzy = true; + } + else if (ImplStartsWith(sLine,"msgctxt ")) + { + m_sContext = ImplGenNormString(sLine.copy(8)); + pLastMsg = &m_sContext; + } + else if (ImplStartsWith(sLine,"msgid ")) + { + m_sUnTransStr = ImplGenNormString(sLine.copy(6)); + pLastMsg = &m_sUnTransStr; + } + else if (ImplStartsWith(sLine,"msgstr ")) + { + m_sTransStr = ImplGenNormString(sLine.copy(7)); + pLastMsg = &m_sTransStr; + } + else if (ImplStartsWith(sLine,"\"") && pLastMsg) + { + *pLastMsg += ImplGenNormString(sLine); + } + else + break; + getline(rIFStream,sTemp); + } + if (m_sKeyId.isEmpty()) + genKeyId(); + } + //Class PoEntry //Split string at the delimiter char @@ -159,8 +230,122 @@ void ImplSplitAt(const OString& rSource, const sal_Char nDelimiter, o_vParts.push_back(rSource.copy(nLastSplit)); } +//Unescape sdf string +OString ImplUnEscapeSDFText(const OString& rText,const bool bHelpText = false) +{ + if ( bHelpText ) + return ImplUnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); + else + return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); +} + +//Miminize the length of the regular expression result +void ImplMinimize(const OUString& rText, Regexpr& io_rRegExp, re_registers& io_rRegs) +{ + re_registers aPrevRegs; + const sal_Int32 nStart = io_rRegs.start[0]; + do + { + const OUString sTemp = rText.copy(0,io_rRegs.end[0]-1); + memcpy(static_cast(&aPrevRegs), static_cast(&io_rRegs), + sizeof(re_registers)); + memset(static_cast(&io_rRegs), 0, sizeof(re_registers)); + io_rRegExp.set_line(sTemp.getStr(),sTemp.getLength()); + io_rRegExp.re_search(&io_rRegs,nStart); + } while(io_rRegs.num_of_match); + + memcpy(static_cast(&io_rRegs),static_cast(&aPrevRegs), + sizeof(re_registers)); + io_rRegExp.set_line(rText.getStr(),rText.getLength()); +} + +//Find all special tag in a string using a regular expression +void ImplFindAllTag(const OString& rText,std::vector& o_vFoundTags) +{ + ::com::sun::star::util::SearchOptions aOptions; + aOptions.algorithmType = ::com::sun::star::util::SearchAlgorithms_REGEXP; + aOptions.searchFlag = ::com::sun::star::util::SearchFlags::NORM_WORD_ONLY; + aOptions.searchString = "<[/]?[a-z_\\-]+(| +[a-z]+=\".*\") *[/]?>"; + ::com::sun::star::uno::Reference< + ::com::sun::star::i18n::XExtendedTransliteration > xTrans; + + Regexpr aRegExp(aOptions,xTrans); + const OUString sTemp(OStringToOUString(rText,RTL_TEXTENCODING_UTF8)); + aRegExp.set_line(sTemp.getStr(),sTemp.getLength()); + + re_registers aRegs; + memset(static_cast(&aRegs), 0, sizeof(re_registers)); + sal_Int32 nStart = 0; + o_vFoundTags.resize(0); + aRegExp.re_search(&aRegs,nStart); + while(aRegs.num_of_match) + { + ImplMinimize(sTemp,aRegExp,aRegs); + o_vFoundTags.push_back( + rText.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0])); + nStart = aRegs.end[0]; + memset(static_cast(&aRegs), 0, sizeof(re_registers)); + aRegExp.re_search(&aRegs,nStart); + } +} + +//Escape special tags +OString ImplEscapeTags(const OString& rText) +{ + typedef std::vector StrVec; + const StrVec vTagsForEscape = + { "ahelp", "link", "item", "emph", "defaultinline", + "switchinline", "caseinline", "variable", + "bookmark_value", "image", "embedvar", "alt" }; + StrVec vFoundTags; + ImplFindAllTag(rText,vFoundTags); + OString sResult = rText; + for(StrVec::const_iterator pFound = vFoundTags.begin(); + pFound != vFoundTags.end(); ++pFound) + { + bool bEscapeThis = false; + for(StrVec::const_iterator pEscape = vTagsForEscape.begin(); + pEscape != vTagsForEscape.end(); ++pEscape) + { + if (ImplStartsWith(*pFound,"<" + *pEscape) || + *pFound == "") + { + bEscapeThis = true; + break; + } + } + if (bEscapeThis || *pFound=="
" || *pFound =="") + { + OString sToReplace = "\\<" + pFound->copy(1,pFound->getLength()-2). + replaceAll("\"","\\\"") + "\\>"; + sResult = sResult.replaceAll(*pFound, sToReplace); + } + } + return sResult; +} + +//Escape to get sdf/merge string +OString ImplEscapeSDFText(const OString& rText,const bool bHelpText = false) +{ + if ( bHelpText ) + return ImplEscapeTags(rText.replaceAll("\\","\\\\")); + else + return ImplEscapeText(rText,"\n\t\r","\\n\\t\\r"); +} +//Default constructor +PoEntry::PoEntry() + : GenPoEntry() + , m_sSourceFile( OString() ) + , m_sGroupId( OString() ) + , m_sLocalId( OString() ) + , m_sResourceType( OString() ) + , m_eType( TTEXT ) + , m_sHelpText( OString() ) +{ +} + //Construct PoEntry from sdfline PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) : m_sSourceFile( OString() ) @@ -168,39 +353,20 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) , m_sLocalId( OString() ) , m_sResourceType(OString() ) , m_eType( TTEXT ) + , m_sHelpText( OString() ) { - setWhiteSpace("\n"); std::vector vParts; ImplSplitAt(rSDFLine,'\t',vParts); if(vParts.size()!=15) throw; m_sSourceFile = vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1); - setReference(m_sSourceFile); + m_sResourceType = vParts[RESOURCETYPE]; m_sGroupId = vParts[GROUPID]; m_sLocalId = vParts[LOCALID]; - m_sResourceType = vParts[RESOURCETYPE]; m_eType = eType; m_sHelpText = vParts[HELPTEXT]; - - OString sContext = m_sGroupId + "\\n" + - (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\\n") + - m_sResourceType; - switch(eType){ - case TTEXT: - sContext += ".text"; break; - case TQUICKHELPTEXT: - sContext += ".quickhelptext"; break; - case TTITLE: - sContext += ".title"; break; - default: - throw; break; - } - setContext(sContext); - setExtractCom(m_sHelpText); - setUnTransStr(vParts[eType]); - genKeyId(); } //Destructor @@ -208,16 +374,22 @@ PoEntry::~PoEntry() { } -//Unescape sdf text -OString ImplUnEscapeSDFText(const OString& rText,const bool bHelpText = false) +//Get translation string in sdf/merge format +OString PoEntry::getUnTransStr() const { - if ( bHelpText ) - return ImplUnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); - else - return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); + return ImplEscapeSDFText(GenPoEntry::getUnTransStr(), + m_sSourceFile.endsWith(".xhp")); +} + +//Get translated string in sdf/merge format +OString PoEntry::getTransStr() const +{ + return ImplEscapeSDFText(GenPoEntry::getTransStr(), + m_sSourceFile.endsWith(".xhp")); + } -//Set translation text when input is in sdf format +//Set translation string when input is in sdf format void PoEntry::setUnTransStr(const OString& rUnTransStr) { GenPoEntry::setUnTransStr( @@ -225,7 +397,7 @@ void PoEntry::setUnTransStr(const OString& rUnTransStr) rUnTransStr,m_sSourceFile.endsWith(".xhp"))); } -//Set translated text when input is in sdf format +//Set translated string when input is in sdf format void PoEntry::setTransStr(const OString& rTransStr) { GenPoEntry::setTransStr( @@ -233,6 +405,60 @@ void PoEntry::setTransStr(const OString& rTransStr) rTransStr,m_sSourceFile.endsWith(".xhp"))); } +//Write to file +void PoEntry::writeToFile(std::ofstream& rOFStream) +{ + setWhiteSpace("\n"); + setExtractCom(m_sHelpText); + setReference(m_sSourceFile); + + OString sContext = m_sGroupId + "\n" + + (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\n") + + m_sResourceType; + switch(m_eType){ + case TTEXT: + sContext += ".text"; break; + case TQUICKHELPTEXT: + sContext += ".quickhelptext"; break; + case TTITLE: + sContext += ".title"; break; + default: + throw; break; + } + setContext(sContext); + genKeyId(); + GenPoEntry::writeToFile(rOFStream); +} + + +//Read from file +void PoEntry::readFromFile(std::ifstream& rIFStream) +{ + GenPoEntry::readFromFile(rIFStream); + m_sSourceFile = getReference(); + + OString sContext = getContext(); + m_sGroupId = sContext.getToken(0,'\n'); + + if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) + m_sResourceType = sContext.getToken(1,'\n').getToken(0,'.'); + else + { + m_sLocalId = sContext.getToken(1,'\n'); + m_sResourceType = sContext.getToken(2,'\n').getToken(0,'.'); + } + if (sContext.endsWith(".text")) + m_eType = TTEXT; + else if (sContext.endsWith(".quickhelptext")) + m_eType = TQUICKHELPTEXT; + else if (sContext.endsWith(".title")) + m_eType = TTITLE; + else + throw; + + m_sHelpText = getExtractCom(); +} + //Class PoHeader //Get actual time in "YEAR-MO-DA HO:MI+ZONE" form diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index a6e127356118..7e567f07d52e 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -63,7 +63,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, //Generate and open sdf cout << "Process start with language: " << LangEntryName.getStr() << endl; system( (rpo2loPath + - " -i " + rPath.getStr() + LangEntryName + + " -i " + rPath + "/" + LangEntryName + " -o " + SDFFileName + " -l " + LangEntryName + " -t " + rSDFPath).getStr()); @@ -77,7 +77,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, while(!aSDFInput.eof()) { OString sActUnTrans = sLine; - OString sPath = rPath + LangEntryName; + OString sPath = rPath + "/"+ LangEntryName; OString sActSourcePath = GetPath(sPath,sActUnTrans); //Make new po file, copy header with some changes if (!aOutPut.is_open()) -- cgit From dd83185b004e08fe0b291ede225d0e93be27c819 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Fri, 31 Aug 2012 18:19:32 +0200 Subject: Correct KeyId generator Use integer aritmetic and less cast Change-Id: I6fc0667fcbcee5f1a2dc964e2653c042338afa0c Reviewed-on: https://gerrit.libreoffice.org/523 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index a82a88b186f4..59199c22c293 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -32,14 +32,15 @@ OString ImplGenKeyId(const OString& rGenerator) boost::crc_32_type aCRC32; aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); sal_uInt32 nCRC = aCRC32.checksum(); - OString sKeyId = ""; - while ( sKeyId.getLength() < 4 ) + char sKeyId[5]; + for(int nIndex = 0; nIndex < 4; ++nIndex) { - //Concat a char from the [33,126] interval of ASCII - sKeyId += OString(char(int(double(nCRC & 255)/255*93)+33)); + //Get a char from the [33,126] interval of ASCII + sKeyId[nIndex] = static_cast((nCRC & 255) % 93 + 33); nCRC >>= 8; } - return sKeyId; + sKeyId[4] = 0; + return OString(sKeyId); } //Escape text -- cgit From 42a2fb1c24750dde53b737d1fb45e2bb7286a3f2 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 2 Sep 2012 21:10:35 +0200 Subject: Make interface for PoEntry Use composition insted of inheritance Make all necessary method. Make header file clear Make header file clear Plus cleanup. Change-Id: Idfcc7a4a4f51b402ec86a9685e8ad9fdb23fea71 Reviewed-on: https://gerrit.libreoffice.org/530 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 61 ++++++++++++------------ l10ntools/source/po.cxx | 120 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 117 insertions(+), 64 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index df3004c1fe5e..b4b18c49d980 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -39,27 +39,20 @@ public: virtual OString getTransStr() const { return m_sTransStr; } virtual bool getFuzzy() const { return m_bFuzzy; } - virtual void setWhiteSpace(const OString& rWhiteSpace) - { m_sWhiteSpace = rWhiteSpace; } - virtual void setExtractCom(const OString& rExtractCom) - { m_sExtractCom = rExtractCom; } - virtual void setReference(const OString& rReference) - { m_sReference = rReference; } - virtual void setContext(const OString& rContext) - { m_sContext = rContext; } - virtual void setUnTransStr(const OString& rUnTransStr) - { m_sUnTransStr = rUnTransStr; } - virtual void setTransStr(const OString& rTransStr) - { m_sTransStr = rTransStr; } - virtual void setFuzzy(bool bFuzzy) - { m_bFuzzy = bFuzzy; } + virtual void setWhiteSpace(const OString& rWhiteSpace); + virtual void setExtractCom(const OString& rExtractCom); + virtual void setReference(const OString& rReference); + virtual void setContext(const OString& rContext); + virtual void setUnTransStr(const OString& rUnTransStr); + virtual void setTransStr(const OString& rTransStr); + virtual void setFuzzy(const bool bFuzzy); virtual void genKeyId(); virtual void writeToFile(std::ofstream& rOFStream); virtual void readFromFile(std::ifstream& rIFStream); }; -class PoEntry: public GenPoEntry +class PoEntry { public: enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, @@ -68,34 +61,43 @@ public: enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE }; private: + GenPoEntry m_aGenPo; OString m_sSourceFile; OString m_sGroupId; OString m_sLocalId; OString m_sResourceType; TYPE m_eType; OString m_sHelpText; - public: - PoEntry(); - PoEntry(const OString& i_rSDFLine, - const TYPE eType = TTEXT); - virtual ~PoEntry(); - - virtual OString getUnTransStr() const; - virtual OString getTransStr() const; - virtual void setUnTransStr(const OString& rUnTransStr); - virtual void setTransStr(const OString& rTransStr); - - virtual void writeToFile(std::ofstream& rOFStream); - virtual void readFromFile(std::ifstream& rIFStream); + PoEntry(); + PoEntry(const OString& i_rSDFLine, + const TYPE eType = TTEXT); + virtual ~PoEntry(); + + OString getSourceFile() const { return m_sSourceFile; } + OString getGroupId() const { return m_sGroupId; } + OString getLocalId() const { return m_sLocalId; } + OString getResourceType() const { return m_sResourceType; } + TYPE getType() const { return m_eType; } + OString getHelpText() const { return m_sHelpText; } + OString getUnTransStr() const; + OString getTransStr() const; + bool getFuzzy() const { return m_aGenPo.getFuzzy(); } + void setUnTransStr(const OString& rUnTransStr); + void setTransStr(const OString& rTransStr); + void setFuzzy(const bool bFuzzy); + + void writeToFile(std::ofstream& rOFStream); + void readFromFile(std::ifstream& rIFStream); }; -class PoHeader: public GenPoEntry +class PoHeader { private: + GenPoEntry m_aGenPo; OString m_sExtractionSource; OString m_sProjectIdVersion; OString m_sReportMsgidBugsTo; @@ -114,6 +116,7 @@ private: public: PoHeader( const OString& rExtSrc ); ~PoHeader(); + void writeToFile(std::ofstream& rOFStream); }; #endif // _PO_INCLUDED diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 59199c22c293..1a7c5aead7df 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -39,7 +39,7 @@ OString ImplGenKeyId(const OString& rGenerator) sKeyId[nIndex] = static_cast((nCRC & 255) % 93 + 33); nCRC >>= 8; } - sKeyId[4] = 0; + sKeyId[4] = '\0'; return OString(sKeyId); } @@ -130,6 +130,42 @@ GenPoEntry::~GenPoEntry() { } +//Set class members +void GenPoEntry::setWhiteSpace(const OString& rWhiteSpace) +{ + m_sWhiteSpace = rWhiteSpace; +} + +void GenPoEntry::setExtractCom(const OString& rExtractCom) +{ + m_sExtractCom = rExtractCom; +} + +void GenPoEntry::setReference(const OString& rReference) +{ + m_sReference = rReference; +} + +void GenPoEntry::setContext(const OString& rContext) +{ + m_sContext = rContext; +} + +void GenPoEntry::setUnTransStr(const OString& rUnTransStr) +{ + m_sUnTransStr = rUnTransStr; +} + +void GenPoEntry::setTransStr(const OString& rTransStr) +{ + m_sTransStr = rTransStr; +} + +void GenPoEntry::setFuzzy(const bool bFuzzy) +{ + m_bFuzzy = bFuzzy; +} + //Set keyid void GenPoEntry::genKeyId() { @@ -337,7 +373,7 @@ OString ImplEscapeSDFText(const OString& rText,const bool bHelpText = false) //Default constructor PoEntry::PoEntry() - : GenPoEntry() + : m_aGenPo( GenPoEntry() ) , m_sSourceFile( OString() ) , m_sGroupId( OString() ) , m_sLocalId( OString() ) @@ -349,7 +385,8 @@ PoEntry::PoEntry() //Construct PoEntry from sdfline PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) - : m_sSourceFile( OString() ) + : m_aGenPo( GenPoEntry() ) + , m_sSourceFile( OString() ) , m_sGroupId( OString() ) , m_sLocalId( OString() ) , m_sResourceType(OString() ) @@ -378,14 +415,14 @@ PoEntry::~PoEntry() //Get translation string in sdf/merge format OString PoEntry::getUnTransStr() const { - return ImplEscapeSDFText(GenPoEntry::getUnTransStr(), + return ImplEscapeSDFText(m_aGenPo.getUnTransStr(), m_sSourceFile.endsWith(".xhp")); } //Get translated string in sdf/merge format OString PoEntry::getTransStr() const { - return ImplEscapeSDFText(GenPoEntry::getTransStr(), + return ImplEscapeSDFText(m_aGenPo.getTransStr(), m_sSourceFile.endsWith(".xhp")); } @@ -393,25 +430,31 @@ OString PoEntry::getTransStr() const //Set translation string when input is in sdf format void PoEntry::setUnTransStr(const OString& rUnTransStr) { - GenPoEntry::setUnTransStr( - ImplUnEscapeSDFText( - rUnTransStr,m_sSourceFile.endsWith(".xhp"))); + m_aGenPo.setUnTransStr( + ImplUnEscapeSDFText( + rUnTransStr,m_sSourceFile.endsWith(".xhp"))); } //Set translated string when input is in sdf format void PoEntry::setTransStr(const OString& rTransStr) { - GenPoEntry::setTransStr( - ImplUnEscapeSDFText( - rTransStr,m_sSourceFile.endsWith(".xhp"))); + m_aGenPo.setTransStr( + ImplUnEscapeSDFText( + rTransStr,m_sSourceFile.endsWith(".xhp"))); +} + +//Set fuzzy flag +void PoEntry::setFuzzy(const bool bFuzzy) +{ + m_aGenPo.setFuzzy(bFuzzy); } //Write to file void PoEntry::writeToFile(std::ofstream& rOFStream) { - setWhiteSpace("\n"); - setExtractCom(m_sHelpText); - setReference(m_sSourceFile); + m_aGenPo.setWhiteSpace("\n"); + m_aGenPo.setExtractCom(m_sHelpText); + m_aGenPo.setReference(m_sSourceFile); OString sContext = m_sGroupId + "\n" + (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\n") + @@ -426,19 +469,19 @@ void PoEntry::writeToFile(std::ofstream& rOFStream) default: throw; break; } - setContext(sContext); - genKeyId(); - GenPoEntry::writeToFile(rOFStream); + m_aGenPo.setContext(sContext); + m_aGenPo.genKeyId(); + m_aGenPo.writeToFile(rOFStream); } //Read from file void PoEntry::readFromFile(std::ifstream& rIFStream) { - GenPoEntry::readFromFile(rIFStream); - m_sSourceFile = getReference(); + m_aGenPo.readFromFile(rIFStream); + m_sSourceFile = m_aGenPo.getReference(); - OString sContext = getContext(); + OString sContext = m_aGenPo.getContext(); m_sGroupId = sContext.getToken(0,'\n'); if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) @@ -457,7 +500,7 @@ void PoEntry::readFromFile(std::ifstream& rIFStream) else throw; - m_sHelpText = getExtractCom(); + m_sHelpText = m_aGenPo.getExtractCom(); } //Class PoHeader @@ -474,7 +517,8 @@ OString ImplGetTime() //Constructor PoHeader::PoHeader( const OString& rExtSrc ) - : m_sExtractionSource( rExtSrc ) + : m_aGenPo( GenPoEntry() ) + , m_sExtractionSource( rExtSrc ) , m_sProjectIdVersion( "PACKAGE VERSION" ) , m_sReportMsgidBugsTo( OString("https://bugs.freedesktop.org/") + "enter_bug.cgi?product=LibreOffice&" + @@ -490,23 +534,29 @@ PoHeader::PoHeader( const OString& rExtSrc ) , m_sXGenerator( "LibreOffice" ) , m_sXAcceleratorMarker( "~" ) { - setExtractCom("extracted from " + rExtSrc); - setTransStr("Project-Id-Version: " + m_sProjectIdVersion + "\n" + - "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + - "POT-Creation-Date: " + m_sPotCreationDate + "\n" + - "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + - "Last-Translator: " + m_sLastTranslator + "\n" + - "Language-Team: " + m_sLanguageTeam + "\n" + - "MIME-Version: " + m_sMimeVersion + "\n" + - "Content-Type: " + m_sContentType + "; " + - "charset=" + m_sCharset + "\n" + - "Content-Transfer-Encoding: " + m_sEncoding + "\n" + - "X-Genarator: " + m_sXGenerator + "\n" + - "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); + m_aGenPo.setExtractCom("extracted from " + rExtSrc); + m_aGenPo.setTransStr( + "Project-Id-Version: " + m_sProjectIdVersion + "\n" + + "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + + "POT-Creation-Date: " + m_sPotCreationDate + "\n" + + "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + + "Last-Translator: " + m_sLastTranslator + "\n" + + "Language-Team: " + m_sLanguageTeam + "\n" + + "MIME-Version: " + m_sMimeVersion + "\n" + + "Content-Type: " + m_sContentType + "; " + + "charset=" + m_sCharset + "\n" + + "Content-Transfer-Encoding: " + m_sEncoding + "\n" + + "X-Genarator: " + m_sXGenerator + "\n" + + "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); } PoHeader::~PoHeader() { } +void PoHeader::writeToFile(std::ofstream& rOFStream) +{ + m_aGenPo.writeToFile(rOFStream); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit From 161f4ac95ae3df1daaede762862ea1c3ac4bb399 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 10 Sep 2012 20:31:38 +0200 Subject: Use po file for merge 1. step Make executables to waiting for po as input Add some function to po files Rewrite makefiles to use po files for merge Change KeyId generator not to use xml special charachters One filetype remain: properties Change-Id: If2bd2ae7afc61518c2d838a3cae301ef62dd9761 Reviewed-on: https://gerrit.libreoffice.org/593 Reviewed-by: Michael Stahl Tested-by: Michael Stahl --- l10ntools/Executable_cfgex.mk | 1 + l10ntools/Executable_helpex.mk | 1 + l10ntools/Executable_transex3.mk | 1 + l10ntools/Executable_ulfex.mk | 1 + l10ntools/Executable_xrmex.mk | 1 + l10ntools/inc/po.hxx | 18 +++- l10ntools/source/merge.cxx | 108 ++++++++++++++++++------ l10ntools/source/po.cxx | 175 +++++++++++++++++++++++++++++---------- l10ntools/source/renewpo.cxx | 6 +- 9 files changed, 238 insertions(+), 74 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_cfgex.mk b/l10ntools/Executable_cfgex.mk index 7dc23275da14..9fea979482bc 100644 --- a/l10ntools/Executable_cfgex.mk +++ b/l10ntools/Executable_cfgex.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,cfgex,\ $(eval $(call gb_Executable_use_libraries,cfgex,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_add_scanners,cfgex,\ diff --git a/l10ntools/Executable_helpex.mk b/l10ntools/Executable_helpex.mk index 470bd4c89d2c..3569dffb5156 100644 --- a/l10ntools/Executable_helpex.mk +++ b/l10ntools/Executable_helpex.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,helpex,\ $(eval $(call gb_Executable_use_libraries,helpex,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_use_external,helpex,expat_utf8)) diff --git a/l10ntools/Executable_transex3.mk b/l10ntools/Executable_transex3.mk index bc9a85272d9f..2d9590641d83 100644 --- a/l10ntools/Executable_transex3.mk +++ b/l10ntools/Executable_transex3.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,transex3,\ $(eval $(call gb_Executable_use_libraries,transex3,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_add_scanners,transex3,\ diff --git a/l10ntools/Executable_ulfex.mk b/l10ntools/Executable_ulfex.mk index e82c9b8ee812..f3fd559ac4f7 100644 --- a/l10ntools/Executable_ulfex.mk +++ b/l10ntools/Executable_ulfex.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,ulfex,\ $(eval $(call gb_Executable_use_libraries,ulfex,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,ulfex,\ diff --git a/l10ntools/Executable_xrmex.mk b/l10ntools/Executable_xrmex.mk index 33255f4eb7e1..b86dbc4b80d2 100644 --- a/l10ntools/Executable_xrmex.mk +++ b/l10ntools/Executable_xrmex.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Executable_set_include,xrmex,\ $(eval $(call gb_Executable_use_libraries,xrmex,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_add_scanners,xrmex,\ diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index b4b18c49d980..81bafe7b7f10 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -25,6 +25,7 @@ private: OString m_sUnTransStr; OString m_sTransStr; bool m_bFuzzy; + bool m_bNull; OString m_sKeyId; public: @@ -38,6 +39,8 @@ public: virtual OString getUnTransStr() const { return m_sUnTransStr; } virtual OString getTransStr() const { return m_sTransStr; } virtual bool getFuzzy() const { return m_bFuzzy; } + virtual bool isNull() const { return m_bNull; } + virtual OString getKeyId() const { return m_sKeyId; } virtual void setWhiteSpace(const OString& rWhiteSpace); virtual void setExtractCom(const OString& rExtractCom); @@ -68,6 +71,8 @@ private: OString m_sResourceType; TYPE m_eType; OString m_sHelpText; + + void SetMembers(); public: PoEntry(); @@ -84,6 +89,8 @@ public: OString getUnTransStr() const; OString getTransStr() const; bool getFuzzy() const { return m_aGenPo.getFuzzy(); } + bool isNull() const { return m_aGenPo.isNull(); } + OString getKeyId() const { return m_aGenPo.getKeyId(); } void setUnTransStr(const OString& rUnTransStr); void setTransStr(const OString& rTransStr); void setFuzzy(const bool bFuzzy); @@ -91,6 +98,8 @@ public: void writeToFile(std::ofstream& rOFStream); void readFromFile(std::ifstream& rIFStream); + static bool IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2); + }; class PoHeader @@ -105,18 +114,23 @@ private: OString m_sPoRevisionDate; OString m_sLastTranslator; OString m_sLanguageTeam; + OString m_sLanguage; OString m_sMimeVersion; - OString m_sPluralForms; OString m_sContentType; - OString m_sCharset; OString m_sEncoding; + OString m_sPluralForms; OString m_sXGenerator; OString m_sXAcceleratorMarker; + void SetMembers(); public: + PoHeader(); PoHeader( const OString& rExtSrc ); ~PoHeader(); + + OString getLanguage() const { return m_sLanguage; } void writeToFile(std::ofstream& rOFStream); + void readFromFile(std::ifstream& rIFStream); }; #endif // _PO_INCLUDED diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 5da52c57d640..a1c4570056e6 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -34,6 +34,7 @@ #include #include "export.hxx" +#include "po.hxx" namespace { @@ -142,42 +143,95 @@ MergeDataFile::MergeDataFile( bool bCaseSensitive) { std::ifstream aInputStream(rFileName.getStr()); - const ::rtl::OString sHACK(RTL_CONSTASCII_STRINGPARAM("HACK")); - const ::rtl::OString sFileNormalized(lcl_NormalizeFilename(rFile)); - const bool isFileEmpty = !sFileNormalized.isEmpty(); - if (!aInputStream.is_open()) { - printf("Warning : Can't open %s\n", rFileName.getStr()); + printf("Warning : Can't open po path container file"); return; } - while (!aInputStream.eof()) + std::string sPoFileName; + aInputStream >> sPoFileName; + bool bFirstLang = true; + while(!aInputStream.eof()) { - std::string buf; - std::getline(aInputStream, buf); - rtl::OString sLine(buf.data(), buf.length()); - sal_Int32 n = 0; - // Skip all wrong filenames - const ::rtl::OString filename = lcl_NormalizeFilename(sLine.getToken(1, '\t', n)); // token 1 - if(isFileEmpty || sFileNormalized.equals("") || (!isFileEmpty && filename.equals(sFileNormalized)) ) + std::ifstream aPoFile(sPoFileName.c_str()); + const OString sHACK("HACK"); + const OString sFileName(lcl_NormalizeFilename(rFile)); + + if (!aPoFile.is_open()) { - const rtl::OString sTYP = sLine.getToken( 1, '\t', n ); // token 3 - const rtl::OString sGID = sLine.getToken( 0, '\t', n ); // token 4 - const rtl::OString sLID = sLine.getToken( 0, '\t', n ); // token 5 - rtl::OString sPFO = sLine.getToken( 1, '\t', n ); // token 7 - sPFO = sHACK; - rtl::OString nLANG = sLine.getToken( 1, '\t', n ); // token 9 - nLANG = nLANG.trim(); - const rtl::OString sTEXT = sLine.getToken( 0, '\t', n ); // token 10 - const rtl::OString sQHTEXT = sLine.getToken( 1, '\t', n ); // token 12 - const rtl::OString sTITLE = sLine.getToken( 0, '\t', n ); // token 13 - - if (!nLANG.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"))) + printf("Warning : Can't open %s\n", sPoFileName.c_str()); + return; + } + + PoHeader aPoHeader; + aPoHeader.readFromFile(aPoFile); + const OString nLANG = aPoHeader.getLanguage(); + aLanguageSet.insert(nLANG); + PoEntry aNextPo; + do + { + aNextPo.readFromFile(aPoFile); + } while( !aNextPo.isNull() && aNextPo.getSourceFile() != sFileName ); + while( !aNextPo.isNull() && aNextPo.getSourceFile() == sFileName ) + { + PoEntry aActPo(aNextPo); + + bool bInSameComp = false; + OString sText; + OString sQHText; + OString sTitle; + OString sExText; + OString sExQHText; + OString sExTitle; + OString sQTZText; + OString sQTZQHText; + OString sQTZTitle; + do + { + if( bInSameComp ) + aActPo = PoEntry(aNextPo); + OString sTemp = aActPo.getTransStr(); + if( aActPo.getFuzzy() || sTemp.isEmpty() ) + sTemp = aActPo.getUnTransStr(); + switch( aActPo.getType() ) + { + case PoEntry::TTEXT: + sText = sTemp; + sExText = aActPo.getUnTransStr(); + sQTZText = aActPo.getKeyId(); + break; + case PoEntry::TQUICKHELPTEXT: + sQHText = sTemp; + sExQHText = aActPo.getUnTransStr(); + sQTZQHText = aActPo.getKeyId(); + break; + case PoEntry::TTITLE: + sTitle = sTemp; + sExTitle = aActPo.getUnTransStr(); + sQTZTitle = aActPo.getKeyId(); + break; + } + aNextPo.readFromFile(aPoFile); + } while(!aNextPo.isNull() && + (bInSameComp = PoEntry::IsInSameComp(aActPo,aNextPo))); + + InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), + aActPo.getLocalId(), sHACK, nLANG, sText, + sQHText, sTitle, sFileName, bCaseSensitive ); + if( bFirstLang ) { - aLanguageSet.insert(nLANG); - InsertEntry( sTYP, sGID, sLID, sPFO, nLANG, sTEXT, sQHTEXT, sTITLE, filename, bCaseSensitive ); + aLanguageSet.insert("qtz"); + InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), + aActPo.getLocalId(), sHACK, "qtz", + sQTZText + "‖" + sExText, + sQTZQHText + "‖" + sExQHText, + sQTZTitle + "‖" + sExTitle, + sFileName, bCaseSensitive ); } } + aPoFile.close(); + aInputStream >> sPoFileName; + bFirstLang = false; } aInputStream.close(); } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 1a7c5aead7df..3be13fcc7361 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -32,11 +32,12 @@ OString ImplGenKeyId(const OString& rGenerator) boost::crc_32_type aCRC32; aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); sal_uInt32 nCRC = aCRC32.checksum(); + //Use all readable ASCII charachter exclude xml special tags: ",',&,<,> + const OString sSymbols = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; char sKeyId[5]; - for(int nIndex = 0; nIndex < 4; ++nIndex) + for( short nKeyInd = 0; nKeyInd < 4; ++nKeyInd ) { - //Get a char from the [33,126] interval of ASCII - sKeyId[nIndex] = static_cast((nCRC & 255) % 93 + 33); + sKeyId[nKeyInd] = sSymbols[(nCRC & 255) % 89]; nCRC >>= 8; } sKeyId[4] = '\0'; @@ -109,7 +110,7 @@ OString ImplGenNormString(const OString& rString) //Decide whether a string starts with an other string bool ImplStartsWith(const OString& rString,const OString& rStart) { - return rString.copy(0,rStart.getLength())==rStart; + return rString.match(rStart); } //Default constructor @@ -121,6 +122,7 @@ GenPoEntry::GenPoEntry() , m_sUnTransStr( OString() ) , m_sTransStr( OString() ) , m_bFuzzy( false ) + , m_bNull( false ) , m_sKeyId( OString() ) { } @@ -197,6 +199,12 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) //Read from file void GenPoEntry::readFromFile(std::ifstream& rIFStream) { + *this = GenPoEntry(); + if( rIFStream.eof() ) + { + m_bNull = true; + return; + } m_sWhiteSpace = "\n"; OString* pLastMsg = 0; std::string sTemp; @@ -412,6 +420,34 @@ PoEntry::~PoEntry() { } +//Set members on the basis of m_aGenPo +void PoEntry::SetMembers() +{ + if( !m_aGenPo.isNull() ) + { + m_sSourceFile = m_aGenPo.getReference(); + OString sContext = m_aGenPo.getContext(); + m_sGroupId = sContext.getToken(0,'\n'); + + if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) + m_sResourceType = sContext.getToken(1,'\n').getToken(0,'.'); + else + { + m_sLocalId = sContext.getToken(1,'\n'); + m_sResourceType = sContext.getToken(2,'\n').getToken(0,'.'); + } + if (sContext.endsWith(".text")) + m_eType = TTEXT; + else if (sContext.endsWith(".quickhelptext")) + m_eType = TQUICKHELPTEXT; + else if (sContext.endsWith(".title")) + m_eType = TTITLE; + else{ + throw;} + m_sHelpText = m_aGenPo.getExtractCom(); + } +} + //Get translation string in sdf/merge format OString PoEntry::getUnTransStr() const { @@ -478,29 +514,18 @@ void PoEntry::writeToFile(std::ofstream& rOFStream) //Read from file void PoEntry::readFromFile(std::ifstream& rIFStream) { + *this = PoEntry(); m_aGenPo.readFromFile(rIFStream); - m_sSourceFile = m_aGenPo.getReference(); - - OString sContext = m_aGenPo.getContext(); - m_sGroupId = sContext.getToken(0,'\n'); - - if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) - m_sResourceType = sContext.getToken(1,'\n').getToken(0,'.'); - else - { - m_sLocalId = sContext.getToken(1,'\n'); - m_sResourceType = sContext.getToken(2,'\n').getToken(0,'.'); - } - if (sContext.endsWith(".text")) - m_eType = TTEXT; - else if (sContext.endsWith(".quickhelptext")) - m_eType = TQUICKHELPTEXT; - else if (sContext.endsWith(".title")) - m_eType = TTITLE; - else - throw; + SetMembers(); +} - m_sHelpText = m_aGenPo.getExtractCom(); +//Check whether po-s belong to the same localization component +bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) +{ + return ( rPo1.m_sSourceFile == rPo2.m_sSourceFile && + rPo1.m_sGroupId == rPo2.m_sGroupId && + rPo1.m_sLocalId == rPo2.m_sLocalId && + rPo1.m_sResourceType == rPo2.m_sResourceType ); } //Class PoHeader @@ -515,7 +540,35 @@ OString ImplGetTime() return pBuff; } -//Constructor +//Get relevant part of actual token +OString ImplGetElement(const OString& rText, const sal_Int32 nToken) +{ + OString sToken = rText.getToken(nToken,'\n'); + sal_Int32 nFirstIndex = sToken.indexOf(':') + 2; + return sToken.copy( nFirstIndex,sToken.getLength()-nFirstIndex ); +} + +//Default Constructor +PoHeader::PoHeader() + : m_aGenPo( GenPoEntry() ) + , m_sExtractionSource( OString() ) + , m_sProjectIdVersion( OString() ) + , m_sReportMsgidBugsTo( OString() ) + , m_sPotCreationDate( OString() ) + , m_sPoRevisionDate( OString() ) + , m_sLastTranslator( OString() ) + , m_sLanguageTeam( OString() ) + , m_sLanguage( OString() ) + , m_sMimeVersion( OString() ) + , m_sContentType( OString() ) + , m_sEncoding( OString() ) + , m_sPluralForms( OString() ) + , m_sXGenerator( OString() ) + , m_sXAcceleratorMarker( OString() ) +{ +} + +//Template Constructor PoHeader::PoHeader( const OString& rExtSrc ) : m_aGenPo( GenPoEntry() ) , m_sExtractionSource( rExtSrc ) @@ -527,36 +580,74 @@ PoHeader::PoHeader( const OString& rExtSrc ) , m_sPoRevisionDate( "YEAR-MO-DA HO:MI+ZONE" ) , m_sLastTranslator( "FULL NAME " ) , m_sLanguageTeam( "LANGUAGE " ) + , m_sLanguage( OString() ) , m_sMimeVersion( "1.0" ) - , m_sContentType( "text/plain" ) - , m_sCharset( "UTF-8" ) + , m_sContentType( "text/plain; charset=UTF-8" ) , m_sEncoding( "8bit" ) + , m_sPluralForms( OString() ) , m_sXGenerator( "LibreOffice" ) , m_sXAcceleratorMarker( "~" ) { - m_aGenPo.setExtractCom("extracted from " + rExtSrc); - m_aGenPo.setTransStr( - "Project-Id-Version: " + m_sProjectIdVersion + "\n" + - "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + - "POT-Creation-Date: " + m_sPotCreationDate + "\n" + - "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + - "Last-Translator: " + m_sLastTranslator + "\n" + - "Language-Team: " + m_sLanguageTeam + "\n" + - "MIME-Version: " + m_sMimeVersion + "\n" + - "Content-Type: " + m_sContentType + "; " + - "charset=" + m_sCharset + "\n" + - "Content-Transfer-Encoding: " + m_sEncoding + "\n" + - "X-Genarator: " + m_sXGenerator + "\n" + - "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); } PoHeader::~PoHeader() { } +//Set members on the basis of m_aGenPo +void PoHeader::SetMembers() +{ + if( !m_aGenPo.isNull() ) + { + m_sExtractionSource = m_aGenPo.getExtractCom(); + OString sTemp = m_aGenPo.getTransStr(); + + sal_Int32 nToken = 0; + m_sProjectIdVersion = ImplGetElement(sTemp,nToken++); + m_sReportMsgidBugsTo = ImplGetElement(sTemp,nToken++); + m_sPotCreationDate = ImplGetElement(sTemp,nToken++); + m_sPoRevisionDate = ImplGetElement(sTemp,nToken++); + m_sLastTranslator = ImplGetElement(sTemp,nToken++); + m_sLanguageTeam = ImplGetElement(sTemp,nToken++); + if( sTemp.getToken(nToken,'\n').match("Language:") ) + m_sLanguage = ImplGetElement(sTemp,nToken++); + m_sMimeVersion = ImplGetElement(sTemp,nToken++); + m_sContentType = ImplGetElement(sTemp,nToken++); + m_sEncoding = ImplGetElement(sTemp,nToken++); + if( sTemp.getToken(nToken,'\n').match("Plural-Forms:") ) + m_sPluralForms = ImplGetElement(sTemp,nToken++); + m_sXGenerator = ImplGetElement(sTemp,nToken++); + m_sXAcceleratorMarker = ImplGetElement(sTemp,nToken); + } +} + void PoHeader::writeToFile(std::ofstream& rOFStream) { + m_aGenPo.setExtractCom("extracted from " + m_sExtractionSource); + m_aGenPo.setTransStr( + "Project-Id-Version: " + m_sProjectIdVersion + "\n" + + "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + + "POT-Creation-Date: " + m_sPotCreationDate + "\n" + + "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + + "Last-Translator: " + m_sLastTranslator + "\n" + + "Language-Team: " + m_sLanguageTeam + "\n" + + ( m_sLanguage.isEmpty() ? "" : "Language: " + m_sLanguage + "\n" ) + + "MIME-Version: " + m_sMimeVersion + "\n" + + "Content-Type: " + m_sContentType + "\n" + + "Content-Transfer-Encoding: " + m_sEncoding + "\n" + + ( m_sPluralForms.isEmpty() ? "" : + "Plural-Forms: " + m_sPluralForms + "\n" ) + + "X-Genarator: " + m_sXGenerator + "\n" + + "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); m_aGenPo.writeToFile(rOFStream); } +void PoHeader::readFromFile(std::ifstream& rIFStream) +{ + *this = PoHeader(); + m_aGenPo.readFromFile(rIFStream); + SetMembers(); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 7e567f07d52e..3e4e98f34c02 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -124,15 +124,15 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, { if (!sActUnTrans.getToken(vTypes[nIndex],'\t').isEmpty()) { - /**Because of xrmex lexer there are duplicated id's, - only use this if the lexer have already fixed*/ + /**Because of xrmex there are duplicated id's, + only use this if xrmex have already fixed if (sActUnTrans.getToken(PoEntry::GROUPID,'\t')== sActUnTrans.getToken(PoEntry::LOCALID,'\t') && sActUnTrans.getToken(PoEntry::SOURCEFILE,'\t'). endsWith(".xrm")) { sActUnTrans = DelLocalId(sActUnTrans); - } + }*/ PoEntry aPE(sActUnTrans, vTypes[nIndex]); aPE.setTransStr(sActTrans.getToken(vTypes[nIndex],'\t')); aPE.setFuzzy(sActTrans.isEmpty() ? 0 : -- cgit From ab063326af9eeab5fcb50a52ec6d67cfc76f4f32 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Fri, 21 Sep 2012 22:57:08 +0200 Subject: remove inclusion of deprecated header Change-Id: If30210587f0562d7e5f24fb3acbdd7ef8b13a00f --- l10ntools/source/localize.cxx | 1 - 1 file changed, 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 598eccf60601..7c1ad3f0590f 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -39,7 +39,6 @@ #include "osl/file.hxx" #include "osl/process.h" #include "osl/thread.h" -#include "rtl/oustringostreaminserter.hxx" #include "rtl/string.h" #include "rtl/string.hxx" #include "rtl/textcvt.h" -- cgit From 27335522a2bfccb7254e146e1b35aa406772508d Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 23 Sep 2012 11:10:45 +0200 Subject: Use PoEntry and PoHeader more like an interface Delete all members except member with type GenPoEntry and use getter methods to define them. Plus correct renewpo. Change-Id: I97665b406467053fce8b4864b47456762887e715 Reviewed-on: https://gerrit.libreoffice.org/681 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 60 +++------- l10ntools/source/po.cxx | 261 ++++++++++++++++++------------------------- l10ntools/source/renewpo.cxx | 17 +-- 3 files changed, 136 insertions(+), 202 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 81bafe7b7f10..686c9f393468 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -15,9 +15,7 @@ class GenPoEntry { - private: - OString m_sWhiteSpace; OString m_sExtractCom; OString m_sReference; @@ -57,40 +55,30 @@ public: class PoEntry { +private: + GenPoEntry m_aGenPo; + public: enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID, TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP }; enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE }; -private: - - GenPoEntry m_aGenPo; - OString m_sSourceFile; - OString m_sGroupId; - OString m_sLocalId; - OString m_sResourceType; - TYPE m_eType; - OString m_sHelpText; - - void SetMembers(); -public: PoEntry(); - PoEntry(const OString& i_rSDFLine, + PoEntry(const OString& rSDFLine, const TYPE eType = TTEXT); - virtual ~PoEntry(); - - OString getSourceFile() const { return m_sSourceFile; } - OString getGroupId() const { return m_sGroupId; } - OString getLocalId() const { return m_sLocalId; } - OString getResourceType() const { return m_sResourceType; } - TYPE getType() const { return m_eType; } - OString getHelpText() const { return m_sHelpText; } + ~PoEntry(); + + OString getSourceFile() const; + OString getGroupId() const; + OString getLocalId() const; + OString getResourceType() const; + TYPE getType() const; OString getUnTransStr() const; OString getTransStr() const; - bool getFuzzy() const { return m_aGenPo.getFuzzy(); } - bool isNull() const { return m_aGenPo.isNull(); } - OString getKeyId() const { return m_aGenPo.getKeyId(); } + bool getFuzzy() const; + bool isNull() const; + OString getKeyId() const; void setUnTransStr(const OString& rUnTransStr); void setTransStr(const OString& rTransStr); void setFuzzy(const bool bFuzzy); @@ -104,31 +92,15 @@ public: class PoHeader { - private: GenPoEntry m_aGenPo; - OString m_sExtractionSource; - OString m_sProjectIdVersion; - OString m_sReportMsgidBugsTo; - OString m_sPotCreationDate; - OString m_sPoRevisionDate; - OString m_sLastTranslator; - OString m_sLanguageTeam; - OString m_sLanguage; - OString m_sMimeVersion; - OString m_sContentType; - OString m_sEncoding; - OString m_sPluralForms; - OString m_sXGenerator; - OString m_sXAcceleratorMarker; - - void SetMembers(); + public: PoHeader(); PoHeader( const OString& rExtSrc ); ~PoHeader(); - OString getLanguage() const { return m_sLanguage; } + OString getLanguage() const; void writeToFile(std::ofstream& rOFStream); void readFromFile(std::ifstream& rIFStream); }; diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 3be13fcc7361..f433aaba236e 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -382,37 +382,38 @@ OString ImplEscapeSDFText(const OString& rText,const bool bHelpText = false) //Default constructor PoEntry::PoEntry() : m_aGenPo( GenPoEntry() ) - , m_sSourceFile( OString() ) - , m_sGroupId( OString() ) - , m_sLocalId( OString() ) - , m_sResourceType( OString() ) - , m_eType( TTEXT ) - , m_sHelpText( OString() ) { } //Construct PoEntry from sdfline PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) : m_aGenPo( GenPoEntry() ) - , m_sSourceFile( OString() ) - , m_sGroupId( OString() ) - , m_sLocalId( OString() ) - , m_sResourceType(OString() ) - , m_eType( TTEXT ) - , m_sHelpText( OString() ) { std::vector vParts; ImplSplitAt(rSDFLine,'\t',vParts); if(vParts.size()!=15) throw; + m_aGenPo.setWhiteSpace("\n"); + + m_aGenPo.setReference(vParts[SOURCEFILE]. + copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); - m_sSourceFile = vParts[SOURCEFILE]. - copy(vParts[SOURCEFILE].lastIndexOf("\\")+1); - m_sResourceType = vParts[RESOURCETYPE]; - m_sGroupId = vParts[GROUPID]; - m_sLocalId = vParts[LOCALID]; - m_eType = eType; - m_sHelpText = vParts[HELPTEXT]; + m_aGenPo.setExtractCom(vParts[HELPTEXT]); + OString sContext = vParts[GROUPID] + "\n" + + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + + vParts[RESOURCETYPE]; + switch(eType){ + case TTEXT: + sContext += ".text"; break; + case TQUICKHELPTEXT: + sContext += ".quickhelptext"; break; + case TTITLE: + sContext += ".title"; break; + default: + throw; break; + } + m_aGenPo.setContext(sContext); setUnTransStr(vParts[eType]); + m_aGenPo.genKeyId(); } //Destructor @@ -420,46 +421,82 @@ PoEntry::~PoEntry() { } -//Set members on the basis of m_aGenPo -void PoEntry::SetMembers() +//Get name of file from which entry is extracted +OString PoEntry::getSourceFile() const { - if( !m_aGenPo.isNull() ) - { - m_sSourceFile = m_aGenPo.getReference(); - OString sContext = m_aGenPo.getContext(); - m_sGroupId = sContext.getToken(0,'\n'); + return m_aGenPo.getReference(); +} - if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) - m_sResourceType = sContext.getToken(1,'\n').getToken(0,'.'); - else - { - m_sLocalId = sContext.getToken(1,'\n'); - m_sResourceType = sContext.getToken(2,'\n').getToken(0,'.'); - } - if (sContext.endsWith(".text")) - m_eType = TTEXT; - else if (sContext.endsWith(".quickhelptext")) - m_eType = TQUICKHELPTEXT; - else if (sContext.endsWith(".title")) - m_eType = TTITLE; - else{ - throw;} - m_sHelpText = m_aGenPo.getExtractCom(); - } +//Get groupid +OString PoEntry::getGroupId() const +{ + return m_aGenPo.getContext().getToken(0,'\n'); +} + +//Get localid +OString PoEntry::getLocalId() const +{ + const OString sContext = m_aGenPo.getContext(); + if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) + return OString(); + else + return sContext.getToken(1,'\n'); +} + +//Get the type of component from which entry is extracted +OString PoEntry::getResourceType() const +{ + const OString sContext = m_aGenPo.getContext(); + if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) + return sContext.getToken(1,'\n').getToken(0,'.'); + else + return sContext.getToken(2,'\n').getToken(0,'.'); +} + +//Get the type of entry +PoEntry::TYPE PoEntry::getType() const +{ + const OString sContext = m_aGenPo.getContext(); + if (sContext.endsWith(".text")) + return TTEXT; + else if (sContext.endsWith(".quickhelptext")) + return TQUICKHELPTEXT; + else if (sContext.endsWith(".title")) + return TTITLE; + else throw; } +//Check wheather entry is fuzzy +bool PoEntry::getFuzzy() const +{ + return m_aGenPo.getFuzzy(); +} + +//Check wheather entry is null +bool PoEntry::isNull() const +{ + return m_aGenPo.isNull(); +} + +//Get keyid +OString PoEntry::getKeyId() const +{ + return m_aGenPo.getKeyId(); +} + + //Get translation string in sdf/merge format OString PoEntry::getUnTransStr() const { return ImplEscapeSDFText(m_aGenPo.getUnTransStr(), - m_sSourceFile.endsWith(".xhp")); + getSourceFile().endsWith(".xhp")); } //Get translated string in sdf/merge format OString PoEntry::getTransStr() const { return ImplEscapeSDFText(m_aGenPo.getTransStr(), - m_sSourceFile.endsWith(".xhp")); + getSourceFile().endsWith(".xhp")); } @@ -468,7 +505,7 @@ void PoEntry::setUnTransStr(const OString& rUnTransStr) { m_aGenPo.setUnTransStr( ImplUnEscapeSDFText( - rUnTransStr,m_sSourceFile.endsWith(".xhp"))); + rUnTransStr,getSourceFile().endsWith(".xhp"))); } //Set translated string when input is in sdf format @@ -476,7 +513,7 @@ void PoEntry::setTransStr(const OString& rTransStr) { m_aGenPo.setTransStr( ImplUnEscapeSDFText( - rTransStr,m_sSourceFile.endsWith(".xhp"))); + rTransStr,getSourceFile().endsWith(".xhp"))); } //Set fuzzy flag @@ -488,25 +525,6 @@ void PoEntry::setFuzzy(const bool bFuzzy) //Write to file void PoEntry::writeToFile(std::ofstream& rOFStream) { - m_aGenPo.setWhiteSpace("\n"); - m_aGenPo.setExtractCom(m_sHelpText); - m_aGenPo.setReference(m_sSourceFile); - - OString sContext = m_sGroupId + "\n" + - (m_sLocalId.isEmpty() ? "" : m_sLocalId + "\n") + - m_sResourceType; - switch(m_eType){ - case TTEXT: - sContext += ".text"; break; - case TQUICKHELPTEXT: - sContext += ".quickhelptext"; break; - case TTITLE: - sContext += ".title"; break; - default: - throw; break; - } - m_aGenPo.setContext(sContext); - m_aGenPo.genKeyId(); m_aGenPo.writeToFile(rOFStream); } @@ -516,16 +534,15 @@ void PoEntry::readFromFile(std::ifstream& rIFStream) { *this = PoEntry(); m_aGenPo.readFromFile(rIFStream); - SetMembers(); } //Check whether po-s belong to the same localization component bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) { - return ( rPo1.m_sSourceFile == rPo2.m_sSourceFile && - rPo1.m_sGroupId == rPo2.m_sGroupId && - rPo1.m_sLocalId == rPo2.m_sLocalId && - rPo1.m_sResourceType == rPo2.m_sResourceType ); + return ( rPo1.getSourceFile() == rPo2.getSourceFile() && + rPo1.getGroupId() == rPo2.getGroupId() && + rPo1.getLocalId() == rPo2.getLocalId() && + rPo1.getResourceType() == rPo2.getResourceType() ); } //Class PoHeader @@ -540,113 +557,57 @@ OString ImplGetTime() return pBuff; } -//Get relevant part of actual token -OString ImplGetElement(const OString& rText, const sal_Int32 nToken) -{ - OString sToken = rText.getToken(nToken,'\n'); - sal_Int32 nFirstIndex = sToken.indexOf(':') + 2; - return sToken.copy( nFirstIndex,sToken.getLength()-nFirstIndex ); -} - //Default Constructor PoHeader::PoHeader() : m_aGenPo( GenPoEntry() ) - , m_sExtractionSource( OString() ) - , m_sProjectIdVersion( OString() ) - , m_sReportMsgidBugsTo( OString() ) - , m_sPotCreationDate( OString() ) - , m_sPoRevisionDate( OString() ) - , m_sLastTranslator( OString() ) - , m_sLanguageTeam( OString() ) - , m_sLanguage( OString() ) - , m_sMimeVersion( OString() ) - , m_sContentType( OString() ) - , m_sEncoding( OString() ) - , m_sPluralForms( OString() ) - , m_sXGenerator( OString() ) - , m_sXAcceleratorMarker( OString() ) { } //Template Constructor PoHeader::PoHeader( const OString& rExtSrc ) : m_aGenPo( GenPoEntry() ) - , m_sExtractionSource( rExtSrc ) - , m_sProjectIdVersion( "PACKAGE VERSION" ) - , m_sReportMsgidBugsTo( OString("https://bugs.freedesktop.org/") + - "enter_bug.cgi?product=LibreOffice&" + - "bug_status=UNCONFIRMED&component=UI" ) - , m_sPotCreationDate( ImplGetTime() ) - , m_sPoRevisionDate( "YEAR-MO-DA HO:MI+ZONE" ) - , m_sLastTranslator( "FULL NAME " ) - , m_sLanguageTeam( "LANGUAGE " ) - , m_sLanguage( OString() ) - , m_sMimeVersion( "1.0" ) - , m_sContentType( "text/plain; charset=UTF-8" ) - , m_sEncoding( "8bit" ) - , m_sPluralForms( OString() ) - , m_sXGenerator( "LibreOffice" ) - , m_sXAcceleratorMarker( "~" ) { + m_aGenPo.setExtractCom("extracted from " + rExtSrc); + m_aGenPo.setTransStr( + OString("Project-Id-Version: PACKAGE VERSION\n" + "Report-Msgid-Bugs-To: https://bugs.freedesktop.org/enter_bug.cgi?" + "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" + "POT-Creation-Date: ") + ImplGetTime() + + OString("\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" + "Last-Translator: FULL NAME \n" + "Language-Team: LANGUAGE \n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=UTF-8\n" + "Content-Transfer-Encoding: 8bit\n" + "X-Genarator: LibreOffice\n" + "X-Accelerator_Marker: ~\n")); } PoHeader::~PoHeader() { } -//Set members on the basis of m_aGenPo -void PoHeader::SetMembers() +//Get the language of header +OString PoHeader::getLanguage() const { - if( !m_aGenPo.isNull() ) - { - m_sExtractionSource = m_aGenPo.getExtractCom(); - OString sTemp = m_aGenPo.getTransStr(); - - sal_Int32 nToken = 0; - m_sProjectIdVersion = ImplGetElement(sTemp,nToken++); - m_sReportMsgidBugsTo = ImplGetElement(sTemp,nToken++); - m_sPotCreationDate = ImplGetElement(sTemp,nToken++); - m_sPoRevisionDate = ImplGetElement(sTemp,nToken++); - m_sLastTranslator = ImplGetElement(sTemp,nToken++); - m_sLanguageTeam = ImplGetElement(sTemp,nToken++); - if( sTemp.getToken(nToken,'\n').match("Language:") ) - m_sLanguage = ImplGetElement(sTemp,nToken++); - m_sMimeVersion = ImplGetElement(sTemp,nToken++); - m_sContentType = ImplGetElement(sTemp,nToken++); - m_sEncoding = ImplGetElement(sTemp,nToken++); - if( sTemp.getToken(nToken,'\n').match("Plural-Forms:") ) - m_sPluralForms = ImplGetElement(sTemp,nToken++); - m_sXGenerator = ImplGetElement(sTemp,nToken++); - m_sXAcceleratorMarker = ImplGetElement(sTemp,nToken); - } + const OString sLang = "Language: "; + const OString sTransStr = m_aGenPo.getTransStr(); + const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength(); + const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex; + return sTransStr.copy(nFirstIndex,nCount); } +//Write out to file void PoHeader::writeToFile(std::ofstream& rOFStream) { - m_aGenPo.setExtractCom("extracted from " + m_sExtractionSource); - m_aGenPo.setTransStr( - "Project-Id-Version: " + m_sProjectIdVersion + "\n" + - "Report-Msgid-Bugs-To: " + m_sReportMsgidBugsTo + "\n" + - "POT-Creation-Date: " + m_sPotCreationDate + "\n" + - "PO-Revision-Date: " + m_sPoRevisionDate + "\n" + - "Last-Translator: " + m_sLastTranslator + "\n" + - "Language-Team: " + m_sLanguageTeam + "\n" + - ( m_sLanguage.isEmpty() ? "" : "Language: " + m_sLanguage + "\n" ) + - "MIME-Version: " + m_sMimeVersion + "\n" + - "Content-Type: " + m_sContentType + "\n" + - "Content-Transfer-Encoding: " + m_sEncoding + "\n" + - ( m_sPluralForms.isEmpty() ? "" : - "Plural-Forms: " + m_sPluralForms + "\n" ) + - "X-Genarator: " + m_sXGenerator + "\n" + - "X-Accelerator_Marker: " + m_sXAcceleratorMarker + "\n"); m_aGenPo.writeToFile(rOFStream); } +//Read from file void PoHeader::readFromFile(std::ifstream& rIFStream) { *this = PoHeader(); m_aGenPo.readFromFile(rIFStream); - SetMembers(); } diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 3e4e98f34c02..398b23bf9a85 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -106,7 +106,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, getline(aSDFInput,s); sLine = OString(s.data(),s.length()); OString sActTrans; - if (IsSameEntry(sActUnTrans,sLine)) + if (!aSDFInput.eof() && IsSameEntry(sActUnTrans,sLine)) { sActTrans = sLine; getline(aSDFInput,s); @@ -134,16 +134,18 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, sActUnTrans = DelLocalId(sActUnTrans); }*/ PoEntry aPE(sActUnTrans, vTypes[nIndex]); - aPE.setTransStr(sActTrans.getToken(vTypes[nIndex],'\t')); - aPE.setFuzzy(sActTrans.isEmpty() ? 0 : - bool(sActTrans.getToken(PoEntry::DUMMY,'\t'). - copy(nDummyBit++,1).toInt32())); + const OString sActStr = + sActTrans.getToken(vTypes[nIndex],'\t'); + aPE.setTransStr(sActStr); + aPE.setFuzzy( sActStr.isEmpty() ? false : + static_cast(sActTrans.getToken(PoEntry::DUMMY,'\t'). + copy(nDummyBit++,1).toBoolean())); aPE.writeToFile(aOutPut); } } - //Check wheather next entry is in the same po file - OString sNextSourcePath = GetPath(sPath,sLine); + OString sNextSourcePath = + !aSDFInput.eof() ? GetPath(sPath,sLine) : ""; if (sNextSourcePath!=sActSourcePath) { aOutPut.close(); @@ -156,7 +158,6 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, //Close and remove sdf file aSDFInput.close(); system(("rm " + SDFFileName).getStr()); - aOutPut.close(); } -- cgit From a6e55d489b611e8dedf001c7897b6b60519fb89a Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sat, 29 Sep 2012 20:58:39 +0200 Subject: Make l10ntools works with i18nregexp Change-Id: I80d3dbc19856d518ed8a94dba227372f5f74ec47 Reviewed-on: https://gerrit.libreoffice.org/725 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/Executable_uiex.mk | 1 + l10ntools/prj/build.lst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_uiex.mk b/l10ntools/Executable_uiex.mk index ca4d7266423a..052f9d017284 100644 --- a/l10ntools/Executable_uiex.mk +++ b/l10ntools/Executable_uiex.mk @@ -16,6 +16,7 @@ $(eval $(call gb_Executable_set_include,uiex,\ $(eval $(call gb_Executable_use_libraries,uiex,\ sal \ + i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,uiex,\ diff --git a/l10ntools/prj/build.lst b/l10ntools/prj/build.lst index 5f7fca144415..888b2343a4b5 100644 --- a/l10ntools/prj/build.lst +++ b/l10ntools/prj/build.lst @@ -1,3 +1,3 @@ -tr l10ntools : EXPAT:expat LIBXSLT:libxslt sal NULL +tr l10ntools : EXPAT:expat LIBXSLT:libxslt sal regexp NULL tr l10ntools usr1 - all tr_mkout NULL tr l10ntools\prj nmake - all tr_prj NULL -- cgit From 9baaced8b636e23045495c9a018d0859a9df8e76 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sat, 29 Sep 2012 21:01:30 +0200 Subject: Not use initializer-list for vector Change-Id: I6ed72b28be3ad00224cbf7308b4f27a6fb25e24e Reviewed-on: https://gerrit.libreoffice.org/726 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 10 ++++++---- l10ntools/source/renewpo.cxx | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index f433aaba236e..b2082a7ee80b 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -338,10 +338,12 @@ void ImplFindAllTag(const OString& rText,std::vector& o_vFoundTags) OString ImplEscapeTags(const OString& rText) { typedef std::vector StrVec; - const StrVec vTagsForEscape = - { "ahelp", "link", "item", "emph", "defaultinline", - "switchinline", "caseinline", "variable", - "bookmark_value", "image", "embedvar", "alt" }; + const OString vInitializer[] = { + "ahelp", "link", "item", "emph", "defaultinline", + "switchinline", "caseinline", "variable", + "bookmark_value", "image", "embedvar", "alt" }; + const StrVec vTagsForEscape( vInitializer, + vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); StrVec vFoundTags; ImplFindAllTag(rText,vFoundTags); OString sResult = rText; diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 398b23bf9a85..39152a7945fa 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -116,9 +116,10 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, { sActTrans =""; } - const vector vTypes = { PoEntry::TTEXT, - PoEntry::TQUICKHELPTEXT, - PoEntry::TTITLE }; + const PoEntry::TYPE vInitializer[] = + { PoEntry::TTEXT, PoEntry::TQUICKHELPTEXT, PoEntry::TTITLE }; + const vector vTypes( vInitializer, + vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); unsigned short nDummyBit = 0; for( unsigned nIndex=0; nIndex Date: Fri, 28 Sep 2012 17:52:13 +0200 Subject: Make Po classes robuster -Make PoOfstream\PoIfstream classes for checked po input\output -Make copyability obvious -Handle runtime errors with exceptions -Use assertions to define exceptations for programmers Plus some correction -Use simplier indentation -In renewpo.cxx, define sdf file as a tempfile instead of make it in current location -Use constructor to renew poheader -Use const where needed Change-Id: Ic11ce3b9eee9a9fa9fbc4ccda154623160ad9d8a Reviewed-on: https://gerrit.libreoffice.org/728 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/inc/po.hxx | 74 +++++++++++-- l10ntools/source/localize.cxx | 52 +++++---- l10ntools/source/merge.cxx | 98 ++++++++++++----- l10ntools/source/po.cxx | 246 ++++++++++++++++++++++++++++++++++-------- l10ntools/source/renewpo.cxx | 88 +++++++++------ 5 files changed, 426 insertions(+), 132 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 686c9f393468..76312a4a59e5 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -12,10 +12,15 @@ #include #include +#include + +class PoOfstream; +class PoIfstream; class GenPoEntry { private: + OString m_sWhiteSpace; OString m_sExtractCom; OString m_sReference; @@ -27,8 +32,10 @@ private: OString m_sKeyId; public: + GenPoEntry(); virtual ~GenPoEntry(); + //Default copy constructor and copy operator work well virtual OString getWhiteSpace() const { return m_sWhiteSpace; } virtual OString getExtractCom() const { return m_sExtractCom; } @@ -49,25 +56,33 @@ public: virtual void setFuzzy(const bool bFuzzy); virtual void genKeyId(); - virtual void writeToFile(std::ofstream& rOFStream); + virtual void writeToFile(std::ofstream& rOFStream) const; virtual void readFromFile(std::ifstream& rIFStream); }; class PoEntry { private: + GenPoEntry m_aGenPo; + bool m_bIsInitialized; public: - enum SDFPARTS { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, + + friend class PoOfstream; + friend class PoIfstream; + + enum SDFPART { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID, LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID, TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP }; enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE }; + enum Exception { INVALIDSDFLINE }; PoEntry(); PoEntry(const OString& rSDFLine, const TYPE eType = TTEXT); ~PoEntry(); + //Default copy constructor and copy operator work well OString getSourceFile() const; OString getGroupId() const; @@ -77,15 +92,11 @@ public: OString getUnTransStr() const; OString getTransStr() const; bool getFuzzy() const; - bool isNull() const; OString getKeyId() const; void setUnTransStr(const OString& rUnTransStr); void setTransStr(const OString& rTransStr); void setFuzzy(const bool bFuzzy); - void writeToFile(std::ofstream& rOFStream); - void readFromFile(std::ifstream& rIFStream); - static bool IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2); }; @@ -93,16 +104,63 @@ public: class PoHeader { private: + GenPoEntry m_aGenPo; + bool m_bIsInitialized; public: + + friend class PoOfstream; + friend class PoIfstream; + PoHeader(); PoHeader( const OString& rExtSrc ); + PoHeader( std::ifstream& rOldPo ); ~PoHeader(); + //Default copy constructor and copy operator work well OString getLanguage() const; - void writeToFile(std::ofstream& rOFStream); - void readFromFile(std::ifstream& rIFStream); +}; + +class PoOfstream: private boost::noncopyable +{ +private: + + std::ofstream m_aOutPut; + bool m_bIsAfterHeader; + +public: + PoOfstream(); + ~PoOfstream(); + bool isOpen() const { return m_aOutPut.is_open(); } + + void open(const OString& rFileName); + void close(); + void writeHeader(const PoHeader& rHeader); + void writeEntry(const PoEntry& rPo); +}; + +class PoIfstream: private boost::noncopyable +{ +private: + + std::ifstream m_aInPut; + bool m_bIsAfterHeader; + bool m_bEof; + +public: + + enum Exception { INVALIDENTRY, INVALIDHEADER }; + + PoIfstream(); + ~PoIfstream(); + bool isOpen() const { return m_aInPut.is_open(); } + bool eof() const { return m_bEof; } + + void open(const OString& rFileName); + void close(); + void readHeader(PoHeader& rHeader); + void readEntry(PoEntry& rPo); }; #endif // _PO_INCLUDED diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index a9a20c8b13da..87ee83bc1c58 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -170,7 +170,7 @@ bool passesPositiveList(rtl::OUString const & url) { void handleCommand( rtl::OUString const & project, rtl::OUString const & projectRoot, rtl::OUString const & url, rtl::OUString const & actualDir, - std::ofstream & outPut, rtl::OUString const & executable, bool positive) + PoOfstream & rPoOutPut, rtl::OUString const & executable, bool positive) { if (positive ? passesPositiveList(url) : passesNegativeList(url)) { rtl::OUString inPath; @@ -241,7 +241,7 @@ void handleCommand( std::string s; std::getline(in, s); - if (!in.eof() && !outPut.is_open()) + if (!in.eof() && !rPoOutPut.isOpen()) { rtl::OUString outDirUrl; if (osl::FileBase::getFileURLFromSystemPath(actualDir. @@ -263,8 +263,14 @@ void handleCommand( std::cerr << "Error: Cannot convert pathname from UTF-16\n"; throw false; //TODO } - outPut.open(outFilePath.getStr(), - std::ios_base::out | std::ios_base::trunc); + rPoOutPut.open(outFilePath.getStr()); + if (!rPoOutPut.isOpen()) + { + std::cerr + << "Error: Cannot open po file " + << outFilePath.getStr() << "\n"; + throw false; //TODO + } rtl::OString relativPath; if (!inPath.copy(inPath.indexOf(project), inPath.lastIndexOf('/')-inPath.indexOf(project)). @@ -275,18 +281,28 @@ void handleCommand( std::cerr << "Error: Cannot convert pathname from UTF-16\n"; throw false; //TODO } - PoHeader(relativPath).writeToFile(outPut); + rPoOutPut.writeHeader(PoHeader(relativPath)); } while (!in.eof()) { OString sLine = OString(s.data(),s.length()); - - if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) - PoEntry(sLine).writeToFile(outPut); - if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) - PoEntry(sLine,PoEntry::TQUICKHELPTEXT).writeToFile(outPut); - if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) - PoEntry(sLine,PoEntry::TTITLE).writeToFile(outPut); + try + { + if (!sLine.getToken(PoEntry::TEXT,'\t').isEmpty()) + rPoOutPut.writeEntry(PoEntry(sLine)); + if (!sLine.getToken(PoEntry::QUICKHELPTEXT,'\t').isEmpty()) + rPoOutPut.writeEntry(PoEntry(sLine,PoEntry::TQUICKHELPTEXT)); + if (!sLine.getToken(PoEntry::TITLE,'\t').isEmpty()) + rPoOutPut.writeEntry(PoEntry(sLine,PoEntry::TTITLE)); + } + catch(PoEntry::Exception& aException) + { + if(aException == PoEntry::INVALIDSDFLINE) + { + std::cerr << executable << "'s input is invalid\n"; + throw false; //TODO + } + } std::getline(in, s); }; in.close(); @@ -296,7 +312,7 @@ void handleCommand( void handleFile( rtl::OUString const & project, rtl::OUString const & projectRoot, rtl::OUString const & url, rtl::OUString const & actualDir, - std::ofstream & outPut) + PoOfstream & rPoOutPut) { struct Command { char const * extension; @@ -319,7 +335,7 @@ void handleFile( commands[i].extension, commands[i].extensionLength)) { handleCommand( - project, projectRoot, url, actualDir, outPut, + project, projectRoot, url, actualDir, rPoOutPut, rtl::OUString::createFromAscii(commands[i].executable), commands[i].positive); break; @@ -430,7 +446,7 @@ void handleDirectory( rtl::OUString const & url, int level, rtl::OUString const & project, rtl::OUString const & projectRoot, rtl::OUString const & actualDir) { - std::ofstream output; + PoOfstream aPoOutPut; osl::Directory dir(url); if (dir.open() != osl::FileBase::E_None) { std::cerr @@ -494,13 +510,13 @@ void handleDirectory( } } else { handleFile(project, projectRoot, - stat.getFileURL(), actualDir, output); + stat.getFileURL(), actualDir, aPoOutPut); } break; } } - if (output.is_open()) - output.close(); + if (aPoOutPut.isOpen()) + aPoOutPut.close(); if (dir.close() != osl::FileBase::E_None) { std::cerr << "Error: Cannot close directory\n"; throw false; //TODO diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index b87024a22dec..7e6c59598c95 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -45,6 +45,27 @@ namespace rFilename.lastIndexOf( '\\' ), rFilename.lastIndexOf( '/' ))+1); }; + + static bool lcl_ReadPoChecked( + PoEntry& o_rPoEntry, PoIfstream& rPoFile, + const std::string& rFileName) + { + try + { + rPoFile.readEntry( o_rPoEntry ); + } + catch( PoIfstream::Exception& aException ) + { + if( aException == PoIfstream::INVALIDENTRY ) + { + printf( + "Warning : %s contains invalid entry\n", + rFileName.c_str() ); + return false; + } + } + return true; + } } // @@ -142,8 +163,8 @@ MergeDataFile::MergeDataFile( const rtl::OString &rFile, bool bCaseSensitive) { - std::ifstream aInputStream(rFileName.getStr()); - if (!aInputStream.is_open()) + std::ifstream aInputStream( rFileName.getStr() ); + if ( !aInputStream.is_open() ) { printf("Warning : Can't open po path container file"); return; @@ -151,30 +172,45 @@ MergeDataFile::MergeDataFile( std::string sPoFileName; aInputStream >> sPoFileName; bool bFirstLang = true; - while(!aInputStream.eof()) + while( !aInputStream.eof() ) { - std::ifstream aPoFile(sPoFileName.c_str()); const OString sHACK("HACK"); - const OString sFileName(lcl_NormalizeFilename(rFile)); - - if (!aPoFile.is_open()) + const OString sFileName( lcl_NormalizeFilename(rFile) ); + PoIfstream aPoInput; + aPoInput.open( OString(sPoFileName.data(), sPoFileName.length()) ); + if ( !aPoInput.isOpen() ) { - printf("Warning : Can't open %s\n", sPoFileName.c_str()); + printf( "Warning : Can't open %s\n", sPoFileName.c_str() ); return; } - PoHeader aPoHeader; - aPoHeader.readFromFile(aPoFile); + try + { + aPoInput.readHeader( aPoHeader ); + } + catch( PoIfstream::Exception& aException ) + { + if( aException == PoIfstream::INVALIDHEADER ) + { + printf( + "Warning : %s has invalid header\n", + sPoFileName.c_str() ); + return; + } + } const OString nLANG = aPoHeader.getLanguage(); - aLanguageSet.insert(nLANG); + aLanguageSet.insert( nLANG ); PoEntry aNextPo; do { - aNextPo.readFromFile(aPoFile); - } while( !aNextPo.isNull() && aNextPo.getSourceFile() != sFileName ); - while( !aNextPo.isNull() && aNextPo.getSourceFile() == sFileName ) + if( !lcl_ReadPoChecked(aNextPo, aPoInput, sPoFileName) ) + { + return; + } + } while( !aPoInput.eof() && aNextPo.getSourceFile() != sFileName ); + while( !aPoInput.eof() && aNextPo.getSourceFile() == sFileName ) { - PoEntry aActPo(aNextPo); + PoEntry aActPo( aNextPo ); bool bInSameComp = false; OString sText; @@ -189,7 +225,7 @@ MergeDataFile::MergeDataFile( do { if( bInSameComp ) - aActPo = PoEntry(aNextPo); + aActPo = aNextPo; OString sTemp = aActPo.getTransStr(); if( aActPo.getFuzzy() || sTemp.isEmpty() ) sTemp = aActPo.getUnTransStr(); @@ -211,25 +247,29 @@ MergeDataFile::MergeDataFile( sQTZTitle = aActPo.getKeyId(); break; } - aNextPo.readFromFile(aPoFile); - } while(!aNextPo.isNull() && - (bInSameComp = PoEntry::IsInSameComp(aActPo,aNextPo))); + if( !lcl_ReadPoChecked(aNextPo, aPoInput, sPoFileName) ) + { + return; + } + } while( !aPoInput.eof() && + ( bInSameComp = PoEntry::IsInSameComp(aActPo, aNextPo) ) ); + + InsertEntry( + aActPo.getResourceType(), aActPo.getGroupId(), + aActPo.getLocalId(), sHACK, nLANG, sText, + sQHText, sTitle, sFileName, bCaseSensitive ); - InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), - aActPo.getLocalId(), sHACK, nLANG, sText, - sQHText, sTitle, sFileName, bCaseSensitive ); if( bFirstLang ) { aLanguageSet.insert("qtz"); - InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), - aActPo.getLocalId(), sHACK, "qtz", - sQTZText + "‖" + sExText, - sQTZQHText + "‖" + sExQHText, - sQTZTitle + "‖" + sExTitle, - sFileName, bCaseSensitive ); + InsertEntry( + aActPo.getResourceType(), aActPo.getGroupId(), + aActPo.getLocalId(), sHACK, "qtz", + sQTZText + "‖" + sExText, sQTZQHText + "‖" + sExQHText, + sQTZTitle + "‖" + sExTitle, sFileName, bCaseSensitive ); } } - aPoFile.close(); + aPoInput.close(); aInputStream >> sPoFileName; bFirstLang = false; } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index b2082a7ee80b..cf0b9632d854 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -13,10 +13,13 @@ #include #include -#include #include #include +#include + #include +#include + #include #include "po.hxx" @@ -49,7 +52,7 @@ OString ImplEscapeText(const OString& rText, const OString& rUnEscaped= POUNESCAPED, const OString& rEscaped = POESCAPED) { - if(rEscaped.getLength()!=2*rUnEscaped.getLength()) throw; + assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); OString sResult = rText; int nCount = 0; for(sal_Int32 nIndex=0; nIndex vParts; ImplSplitAt(rSDFLine,'\t',vParts); - if(vParts.size()!=15) throw; + if( vParts.size()!=15 || + vParts[SOURCEFILE].isEmpty() || + vParts[GROUPID].isEmpty() || + vParts[RESOURCETYPE].isEmpty() || + vParts[eType].isEmpty() ) + { + throw INVALIDSDFLINE; + } m_aGenPo.setWhiteSpace("\n"); m_aGenPo.setReference(vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); m_aGenPo.setExtractCom(vParts[HELPTEXT]); - OString sContext = vParts[GROUPID] + "\n" + + OString sContext = + vParts[GROUPID] + "\n" + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + vParts[RESOURCETYPE]; switch(eType){ @@ -410,12 +423,13 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) sContext += ".quickhelptext"; break; case TTITLE: sContext += ".title"; break; - default: - throw; break; + /*Default case is unneeded because the type of eType has + only three element*/ } m_aGenPo.setContext(sContext); setUnTransStr(vParts[eType]); m_aGenPo.genKeyId(); + m_bIsInitialized = true; } //Destructor @@ -426,18 +440,21 @@ PoEntry::~PoEntry() //Get name of file from which entry is extracted OString PoEntry::getSourceFile() const { + assert( m_bIsInitialized ); return m_aGenPo.getReference(); } //Get groupid OString PoEntry::getGroupId() const { + assert( m_bIsInitialized ); return m_aGenPo.getContext().getToken(0,'\n'); } //Get localid OString PoEntry::getLocalId() const { + assert( m_bIsInitialized ); const OString sContext = m_aGenPo.getContext(); if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) return OString(); @@ -448,6 +465,7 @@ OString PoEntry::getLocalId() const //Get the type of component from which entry is extracted OString PoEntry::getResourceType() const { + assert( m_bIsInitialized ); const OString sContext = m_aGenPo.getContext(); if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) return sContext.getToken(1,'\n').getToken(0,'.'); @@ -459,30 +477,28 @@ OString PoEntry::getResourceType() const PoEntry::TYPE PoEntry::getType() const { const OString sContext = m_aGenPo.getContext(); - if (sContext.endsWith(".text")) + const OString sType = sContext.copy( sContext.indexOf('.') + 1 ); + assert( m_bIsInitialized && + (sType == "text" || sType == "quickhelptext" || sType == "title") ); + if ( sType == "text" ) return TTEXT; - else if (sContext.endsWith(".quickhelptext")) + else if ( sType == "quickhelptext" ) return TQUICKHELPTEXT; - else if (sContext.endsWith(".title")) + else return TTITLE; - else throw; } //Check wheather entry is fuzzy bool PoEntry::getFuzzy() const { + assert( m_bIsInitialized ); return m_aGenPo.getFuzzy(); } -//Check wheather entry is null -bool PoEntry::isNull() const -{ - return m_aGenPo.isNull(); -} - //Get keyid OString PoEntry::getKeyId() const { + assert( m_bIsInitialized ); return m_aGenPo.getKeyId(); } @@ -490,15 +506,19 @@ OString PoEntry::getKeyId() const //Get translation string in sdf/merge format OString PoEntry::getUnTransStr() const { - return ImplEscapeSDFText(m_aGenPo.getUnTransStr(), - getSourceFile().endsWith(".xhp")); + assert( m_bIsInitialized ); + return + ImplEscapeSDFText( + m_aGenPo.getUnTransStr(), getSourceFile().endsWith(".xhp") ); } //Get translated string in sdf/merge format OString PoEntry::getTransStr() const { - return ImplEscapeSDFText(m_aGenPo.getTransStr(), - getSourceFile().endsWith(".xhp")); + assert( m_bIsInitialized ); + return + ImplEscapeSDFText( + m_aGenPo.getTransStr(), getSourceFile().endsWith(".xhp") ); } @@ -524,20 +544,6 @@ void PoEntry::setFuzzy(const bool bFuzzy) m_aGenPo.setFuzzy(bFuzzy); } -//Write to file -void PoEntry::writeToFile(std::ofstream& rOFStream) -{ - m_aGenPo.writeToFile(rOFStream); -} - - -//Read from file -void PoEntry::readFromFile(std::ifstream& rIFStream) -{ - *this = PoEntry(); - m_aGenPo.readFromFile(rIFStream); -} - //Check whether po-s belong to the same localization component bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) { @@ -559,15 +565,26 @@ OString ImplGetTime() return pBuff; } +OString ImplReplaceAttribute( + const OString& rSource, const OString& rOld, const OString& rNew ) +{ + const sal_Int32 nFirstIndex = rSource.indexOf( rOld ) + rOld.getLength()+2; + const sal_Int32 nCount = + rSource.indexOf( "\n", nFirstIndex ) - nFirstIndex; + return rSource.replaceFirst( rSource.copy(nFirstIndex, nCount), rNew ); +} + //Default Constructor PoHeader::PoHeader() : m_aGenPo( GenPoEntry() ) + , m_bIsInitialized( false ) { } //Template Constructor PoHeader::PoHeader( const OString& rExtSrc ) : m_aGenPo( GenPoEntry() ) + , m_bIsInitialized( false ) { m_aGenPo.setExtractCom("extracted from " + rExtSrc); m_aGenPo.setTransStr( @@ -583,6 +600,34 @@ PoHeader::PoHeader( const OString& rExtSrc ) "Content-Transfer-Encoding: 8bit\n" "X-Genarator: LibreOffice\n" "X-Accelerator_Marker: ~\n")); + m_bIsInitialized = true; +} + + +//Constructor for old headers to renew po files +PoHeader::PoHeader( std::ifstream& rOldPo ) + : m_aGenPo( GenPoEntry() ) + , m_bIsInitialized( false ) +{ + assert( rOldPo.is_open() ); + m_aGenPo.readFromFile( rOldPo ); + + m_aGenPo.setWhiteSpace( OString() ); + const OString sExtractCom = m_aGenPo.getExtractCom(); + m_aGenPo.setExtractCom( + sExtractCom.copy( 0, sExtractCom.getLength() - 3 ) ); + + OString sTransStr = m_aGenPo.getTransStr(); + sTransStr = + ImplReplaceAttribute( sTransStr, "Report-Msgid-Bugs-To", + "https://bugs.freedesktop.org/enter_bug.cgi?product=" + "LibreOffice&bug_status=UNCONFIRMED&component=UI" ); + sTransStr = + ImplReplaceAttribute( sTransStr, "X-Generator", "LibreOffice" ); + sTransStr = + ImplReplaceAttribute( sTransStr, "X-Accelerator-Marker", "~" ); + m_aGenPo.setTransStr( sTransStr ); + m_bIsInitialized = true; } PoHeader::~PoHeader() @@ -592,6 +637,7 @@ PoHeader::~PoHeader() //Get the language of header OString PoHeader::getLanguage() const { + assert( m_bIsInitialized ); const OString sLang = "Language: "; const OString sTransStr = m_aGenPo.getTransStr(); const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength(); @@ -599,18 +645,128 @@ OString PoHeader::getLanguage() const return sTransStr.copy(nFirstIndex,nCount); } -//Write out to file -void PoHeader::writeToFile(std::ofstream& rOFStream) +//Class PoOfstream + +PoOfstream::PoOfstream() + : m_aOutPut() + , m_bIsAfterHeader( false ) +{ +} + +PoOfstream::~PoOfstream() +{ + if( isOpen() ) + { + close(); + } +} + +void PoOfstream::open(const OString& rFileName) { - m_aGenPo.writeToFile(rOFStream); + assert( !isOpen() ); + m_aOutPut.open( rFileName.getStr(), + std::ios_base::out | std::ios_base::trunc ); + m_bIsAfterHeader = false; } -//Read from file -void PoHeader::readFromFile(std::ifstream& rIFStream) +void PoOfstream::close() +{ + assert( isOpen() ); + m_aOutPut.close(); +} + +void PoOfstream::writeHeader(const PoHeader& rPoHeader) +{ + assert( isOpen() && !m_bIsAfterHeader && rPoHeader.m_bIsInitialized ); + rPoHeader.m_aGenPo.writeToFile( m_aOutPut ); + m_bIsAfterHeader = true; +} + +void PoOfstream::writeEntry( const PoEntry& rPoEntry ) +{ + assert( isOpen() && m_bIsAfterHeader && rPoEntry.m_bIsInitialized ); + rPoEntry.m_aGenPo.writeToFile( m_aOutPut ); +} + +//Class PoIfstream + +PoIfstream::PoIfstream() + : m_aInPut() + , m_bIsAfterHeader( false ) + , m_bEof( false ) +{ +} + +PoIfstream::~PoIfstream() +{ + if( isOpen() ) + { + close(); + } +} + +void PoIfstream::open( const OString& rFileName ) +{ + assert( !isOpen() ); + m_aInPut.open( rFileName.getStr(), std::ios_base::in ); + m_bIsAfterHeader = false; + m_bEof = false; +} + +void PoIfstream::close() { - *this = PoHeader(); - m_aGenPo.readFromFile(rIFStream); + assert( isOpen() ); + m_aInPut.close(); } +void PoIfstream::readHeader( PoHeader& rPoHeader ) +{ + assert( isOpen() && !eof() && !m_bIsAfterHeader ); + GenPoEntry aGenPo; + aGenPo.readFromFile( m_aInPut ); + if( !aGenPo.getExtractCom().isEmpty() && + aGenPo.getUnTransStr().isEmpty() && + !aGenPo.getTransStr().isEmpty() ) + { + rPoHeader.m_aGenPo = aGenPo; + rPoHeader.m_bIsInitialized = true; + m_bIsAfterHeader = true; + } + else + { + throw INVALIDHEADER; + } +} + +void PoIfstream::readEntry( PoEntry& rPoEntry ) +{ + assert( isOpen() && !eof() && m_bIsAfterHeader ); + GenPoEntry aGenPo; + aGenPo.readFromFile( m_aInPut ); + if( aGenPo.isNull() ) + { + m_bEof = true; + rPoEntry = PoEntry(); + } + else + { + const OString sContext = aGenPo.getContext(); + const sal_Int32 nLastDot = sContext.lastIndexOf('.'); + const OString sType = sContext.copy( nLastDot + 1 ); + if( !aGenPo.getReference().isEmpty() && + sContext.indexOf('\n') > 0 && + (sType == "text" || sType == "quickhelptext" || sType == "title") && + nLastDot - sContext.lastIndexOf('\n') > 0 && + !aGenPo.getUnTransStr().isEmpty() ) + { + rPoEntry.m_aGenPo = aGenPo; + rPoEntry.m_bIsInitialized = true; + } + else + { + throw INVALIDENTRY; + } + } +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 39152a7945fa..83b3051134a9 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -12,7 +12,10 @@ #include #include #include + +#include #include + #include "po.hxx" using namespace std; @@ -58,10 +61,27 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, const OString& rpo2loPath, const OString& rSDFPath) { const OString LangEntryName = pLangEntry->d_name; - const OString SDFFileName = LangEntryName + ".sdf"; //Generate and open sdf cout << "Process start with language: " << LangEntryName.getStr() << endl; + OUString aTempUrl; + if (osl::FileBase::createTempFile(0, 0, &aTempUrl) + != osl::FileBase::E_None) + { + cerr << "osl::FileBase::createTempFile() failed\n"; + return; + } + OUString aTempPath; + if (osl::FileBase::getSystemPathFromFileURL(aTempUrl, aTempPath) + != osl::FileBase::E_None) + { + cerr + << "osl::FileBase::getSystemPathFromFileURL(" << aTempUrl + << ") failed\n"; + return; + } + const OString SDFFileName = + OUStringToOString(aTempPath, RTL_TEXTENCODING_UTF8); system( (rpo2loPath + " -i " + rPath + "/" + LangEntryName + " -o " + SDFFileName + @@ -69,7 +89,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, " -t " + rSDFPath).getStr()); cout << "Language sdf is ready!" << endl; - ofstream aOutPut; + PoOfstream aNewPo; ifstream aSDFInput(SDFFileName.getStr()); string s; getline(aSDFInput,s); @@ -77,40 +97,41 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, while(!aSDFInput.eof()) { OString sActUnTrans = sLine; - OString sPath = rPath + "/"+ LangEntryName; - OString sActSourcePath = GetPath(sPath,sActUnTrans); - //Make new po file, copy header with some changes - if (!aOutPut.is_open()) + const OString sPath = rPath + "/"+ LangEntryName; + const OString sActSourcePath = GetPath(sPath,sActUnTrans); + //Make new po file and add header + if (!aNewPo.isOpen()) { - aOutPut.open((sActSourcePath + ".po_tmp").getStr(), - std::ios_base::out | std::ios_base::trunc); - ifstream aPOInput((sActSourcePath + ".po").getStr()); - getline(aPOInput,s); - while(s!="") + const OString sNewPoFileName = sActSourcePath + ".po_tmp"; + aNewPo.open(sNewPoFileName); + if (!aNewPo.isOpen()) { - if (s.find("#. extracted from")!=string::npos) - s = string(s,0,s.length()-3); - if (s.find("Report-Msgid-Bugs-To")!=string::npos) - s = string("\"Report-Msgid-Bugs-To: ") + - "https://bugs.freedesktop.org/enter_bug.cgi?product=" + - "LibreOffice&bug_status=UNCONFIRMED&component=UI\\n\""; - if (s.find("X-Generator")!=string::npos) - s = "\"X-Generator: LibreOffice\\n\""; - aOutPut << s << endl; - getline(aPOInput,s); - }; - aPOInput.close(); + cerr + << "Cannot open temp file for new po: " + << sNewPoFileName.getStr() << endl; + return; + } + const OString sOldPoFileName = sActSourcePath + ".po"; + ifstream aOldPo(sOldPoFileName.getStr()); + if (!aOldPo.is_open()) + { + cerr + << "Cannot open old po file: " + << sOldPoFileName.getStr() << endl; + return; + } + aNewPo.writeHeader(PoHeader(aOldPo)); + aOldPo.close(); } //Set PoEntry and write out getline(aSDFInput,s); - sLine = OString(s.data(),s.length()); OString sActTrans; - if (!aSDFInput.eof() && IsSameEntry(sActUnTrans,sLine)) + if (!aSDFInput.eof() && + IsSameEntry(sActUnTrans,sLine = OString(s.data(),s.length()))) { sActTrans = sLine; getline(aSDFInput,s); - sLine = OString(s.data(),s.length()); } else { @@ -121,7 +142,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, const vector vTypes( vInitializer, vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); unsigned short nDummyBit = 0; - for( unsigned nIndex=0; nIndex(sActTrans.getToken(PoEntry::DUMMY,'\t'). copy(nDummyBit++,1).toBoolean())); - aPE.writeToFile(aOutPut); + aNewPo.writeEntry(aPE); } } //Check wheather next entry is in the same po file - OString sNextSourcePath = - !aSDFInput.eof() ? GetPath(sPath,sLine) : ""; + OString sNextSourcePath = aSDFInput.eof() ? "" : + GetPath(sPath,sLine = OString(s.data(),s.length())); if (sNextSourcePath!=sActSourcePath) { - aOutPut.close(); + aNewPo.close(); system(("rm " + sActSourcePath +".po").getStr()); system(("mv "+ sActSourcePath +".po_tmp " + sActSourcePath +".po").getStr()); @@ -158,7 +179,10 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, //Close and remove sdf file aSDFInput.close(); - system(("rm " + SDFFileName).getStr()); + if (osl::File::remove(aTempUrl) != osl::FileBase::E_None) + { + cerr << "Warning: failure removing temporary " << aTempUrl << '\n'; + } } -- cgit From 0e138f246cc490df35046bba83e459164620ca77 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 12:08:04 +0200 Subject: Move setting of po msgid to constructor because this is part of initialization Change-Id: If6ebe46cea93e378c9060f2c3ced09ab44a3d82a Reviewed-on: https://gerrit.libreoffice.org/729 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index cf0b9632d854..0649efedac0a 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -427,7 +427,9 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) only three element*/ } m_aGenPo.setContext(sContext); - setUnTransStr(vParts[eType]); + m_aGenPo.setUnTransStr( + ImplUnEscapeSDFText( + vParts[eType],vParts[SOURCEFILE].endsWith(".xhp"))); m_aGenPo.genKeyId(); m_bIsInitialized = true; } @@ -522,14 +524,6 @@ OString PoEntry::getTransStr() const } -//Set translation string when input is in sdf format -void PoEntry::setUnTransStr(const OString& rUnTransStr) -{ - m_aGenPo.setUnTransStr( - ImplUnEscapeSDFText( - rUnTransStr,getSourceFile().endsWith(".xhp"))); -} - //Set translated string when input is in sdf format void PoEntry::setTransStr(const OString& rTransStr) { -- cgit From 4869d45d8e6ba43f422ee3aa05b7c0baca28d1e0 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 12:47:56 +0200 Subject: Make error message clearer in localize which is written out when one of executables writes out invalid sdf line Change-Id: I167b31bf0f550222accdda8ee5a03d8e4a742d63 Reviewed-on: https://gerrit.libreoffice.org/730 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/localize.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 87ee83bc1c58..6bc92a8f3ee6 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -299,7 +299,11 @@ void handleCommand( { if(aException == PoEntry::INVALIDSDFLINE) { - std::cerr << executable << "'s input is invalid\n"; + std::cerr + << executable + << "'s output is invalid:\n" + << sLine.replaceAll("\t","\\t").getStr() + << std::endl; throw false; //TODO } } -- cgit From f1cbd2dc05c6765754891a909ff53f1852a878a5 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 13:11:54 +0200 Subject: Use ascii charachters to seperate qtzi Because previous used charachters cause warnings Change-Id: I8715fc2a05df9d84b34945618184c99d54de6579 Reviewed-on: https://gerrit.libreoffice.org/731 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/merge.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 7e6c59598c95..b9fe90f8ae4c 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -265,8 +265,8 @@ MergeDataFile::MergeDataFile( InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), aActPo.getLocalId(), sHACK, "qtz", - sQTZText + "‖" + sExText, sQTZQHText + "‖" + sExQHText, - sQTZTitle + "‖" + sExTitle, sFileName, bCaseSensitive ); + sQTZText + "||" + sExText, sQTZQHText + "||" + sExQHText, + sQTZTitle + "||" + sExTitle, sFileName, bCaseSensitive ); } } aPoInput.close(); -- cgit From 004f4fae87fe4fe3c31948d55206291b6de64ba9 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 16:33:47 +0200 Subject: Correct escaping tags which worked wrong with some language like Asturian Change-Id: Icd5939316ac84a3e569a9cbc04e38edda59dead1 Reviewed-on: https://gerrit.libreoffice.org/735 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 0649efedac0a..f929ce70dc18 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -330,7 +330,9 @@ void ImplFindAllTag(const OString& rText,std::vector& o_vFoundTags) { ImplMinimize(sTemp,aRegExp,aRegs); o_vFoundTags.push_back( - rText.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0])); + OUStringToOString( + sTemp.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0]), + RTL_TEXTENCODING_UTF8)); nStart = aRegs.end[0]; memset(static_cast(&aRegs), 0, sizeof(re_registers)); aRegExp.re_search(&aRegs,nStart); -- cgit From 0359041aac89ef07325f6b8baa2d5ff304e833b5 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 17:54:37 +0200 Subject: Corrections for merge -Correct po type-checking -Use new "lang" variable instead of nonexistent one -Add input parameter to ulfex Change-Id: I1dc17363179d69d40144b6a998eb1bf223bd05e9 Reviewed-on: https://gerrit.libreoffice.org/736 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index f929ce70dc18..b9e1c17589ae 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -481,7 +481,7 @@ OString PoEntry::getResourceType() const PoEntry::TYPE PoEntry::getType() const { const OString sContext = m_aGenPo.getContext(); - const OString sType = sContext.copy( sContext.indexOf('.') + 1 ); + const OString sType = sContext.copy( sContext.lastIndexOf('.') + 1 ); assert( m_bIsInitialized && (sType == "text" || sType == "quickhelptext" || sType == "title") ); if ( sType == "text" ) -- cgit From 9d300551b3dacd3693607e1015bea1461c173e1a Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 30 Sep 2012 18:26:15 +0200 Subject: Use new startsWith() method of OString Change-Id: If8787b007767aa2701ff1b13883bcf33df12a8fc Reviewed-on: https://gerrit.libreoffice.org/737 Reviewed-by: Andras Timar Tested-by: Andras Timar --- l10ntools/source/po.cxx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index b9e1c17589ae..a922575e41fd 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -110,12 +110,6 @@ OString ImplGenNormString(const OString& rString) return ImplUnEscapeText(rString.copy(1,rString.getLength()-2)); } -//Decide whether a string starts with an other string -bool ImplStartsWith(const OString& rString,const OString& rStart) -{ - return rString.match(rStart); -} - //Default constructor GenPoEntry::GenPoEntry() : m_sWhiteSpace( OString() ) @@ -215,37 +209,37 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) while(!rIFStream.eof()) { OString sLine = OString(sTemp.data(),sTemp.length()); - if (ImplStartsWith(sLine,"#. ")) + if (sLine.startsWith("#. ")) { if (sLine.getLength()==7) m_sKeyId = sLine.copy(3); else m_sExtractCom = sLine.copy(3); } - else if (ImplStartsWith(sLine,"#: ")) + else if (sLine.startsWith("#: ")) { m_sReference = sLine.copy(3); } - else if (ImplStartsWith(sLine,"#, fuzzy")) + else if (sLine.startsWith("#, fuzzy")) { m_bFuzzy = true; } - else if (ImplStartsWith(sLine,"msgctxt ")) + else if (sLine.startsWith("msgctxt ")) { m_sContext = ImplGenNormString(sLine.copy(8)); pLastMsg = &m_sContext; } - else if (ImplStartsWith(sLine,"msgid ")) + else if (sLine.startsWith("msgid ")) { m_sUnTransStr = ImplGenNormString(sLine.copy(6)); pLastMsg = &m_sUnTransStr; } - else if (ImplStartsWith(sLine,"msgstr ")) + else if (sLine.startsWith("msgstr ")) { m_sTransStr = ImplGenNormString(sLine.copy(7)); pLastMsg = &m_sTransStr; } - else if (ImplStartsWith(sLine,"\"") && pLastMsg) + else if (sLine.startsWith("\"") && pLastMsg) { *pLastMsg += ImplGenNormString(sLine); } @@ -359,7 +353,7 @@ OString ImplEscapeTags(const OString& rText) for(StrVec::const_iterator pEscape = vTagsForEscape.begin(); pEscape != vTagsForEscape.end(); ++pEscape) { - if (ImplStartsWith(*pFound,"<" + *pEscape) || + if (pFound->startsWith("<" + *pEscape) || *pFound == "") { bEscapeThis = true; -- cgit From 6f6f7a17dc82248446dc4eddfd51af08362fc352 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 26 Sep 2012 23:45:28 +0200 Subject: gbuild: split uwinapi out of gb_STDLIBS Change-Id: I53316e0b9369d806197bccb42cf22d3497af43e7 --- l10ntools/Executable_ulfconv.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'l10ntools') diff --git a/l10ntools/Executable_ulfconv.mk b/l10ntools/Executable_ulfconv.mk index 8ed5bb0e5f2c..7a92c2edd596 100644 --- a/l10ntools/Executable_ulfconv.mk +++ b/l10ntools/Executable_ulfconv.mk @@ -11,6 +11,7 @@ $(eval $(call gb_Executable_Executable,ulfconv)) $(eval $(call gb_Executable_use_libraries,ulfconv,\ sal \ + $(gb_UWINAPI) \ $(gb_STDLIBS) \ )) -- cgit From 816ec4b0933e36ac468230365359c3b9d8d52986 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Thu, 27 Sep 2012 00:49:12 +0200 Subject: gbuild: replace direct gb_STDLIBS use with ... ... new gb_LinkTarget_add_standard_system_libs Change-Id: Ib2bc843098db3d8c6822b45a3d21724e67f57d69 --- l10ntools/Executable_ulfconv.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_ulfconv.mk b/l10ntools/Executable_ulfconv.mk index 7a92c2edd596..b981e56e2e59 100644 --- a/l10ntools/Executable_ulfconv.mk +++ b/l10ntools/Executable_ulfconv.mk @@ -12,9 +12,10 @@ $(eval $(call gb_Executable_Executable,ulfconv)) $(eval $(call gb_Executable_use_libraries,ulfconv,\ sal \ $(gb_UWINAPI) \ - $(gb_STDLIBS) \ )) +$(eval $(call gb_Executable_add_standard_system_libs,ulfconv)) + $(eval $(call gb_Executable_add_exception_objects,ulfconv,\ l10ntools/source/ulfconv/ulfconv \ )) -- cgit From f011af716e2978cbf9fcb7748dc868c503edddff Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 28 Sep 2012 16:29:24 +0200 Subject: gbuild: invert handling of standard system libraries: Always link in gb_STDLIBS, except when the library explicitly opts out with gb_LinkTarget_disable_standard_system_libs. Change-Id: I489a99114fbfa46d0421a27cf6c7b899dc268a4a --- l10ntools/Executable_ulfconv.mk | 2 -- 1 file changed, 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_ulfconv.mk b/l10ntools/Executable_ulfconv.mk index b981e56e2e59..b8a2001a2359 100644 --- a/l10ntools/Executable_ulfconv.mk +++ b/l10ntools/Executable_ulfconv.mk @@ -14,8 +14,6 @@ $(eval $(call gb_Executable_use_libraries,ulfconv,\ $(gb_UWINAPI) \ )) -$(eval $(call gb_Executable_add_standard_system_libs,ulfconv)) - $(eval $(call gb_Executable_add_exception_objects,ulfconv,\ l10ntools/source/ulfconv/ulfconv \ )) -- cgit From e09e9bfb89e9e65c17acb1f027a9003beddd6d66 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Thu, 27 Sep 2012 13:52:10 +0100 Subject: re-base on ALv2 code. --- l10ntools/Makefile | 7 +++++ l10ntools/inc/cfgmerge.hxx | 37 ++++++++++--------------- l10ntools/inc/export.hxx | 37 ++++++++++--------------- l10ntools/inc/gsicheck.hxx | 37 ++++++++++--------------- l10ntools/inc/helpmerge.hxx | 37 ++++++++++--------------- l10ntools/inc/l10ntools/directory.hxx | 18 ++++++++++++ l10ntools/inc/l10ntools/file.hxx | 18 ++++++++++++ l10ntools/inc/lngmerge.hxx | 37 ++++++++++--------------- l10ntools/inc/tagtest.hxx | 37 ++++++++++--------------- l10ntools/inc/xmlparse.hxx | 37 ++++++++++--------------- l10ntools/inc/xrmmerge.hxx | 37 ++++++++++--------------- l10ntools/scripts/fast_merge.pl | 33 ++++++++-------------- l10ntools/scripts/keyidGen.pl | 35 +++++++++-------------- l10ntools/source/cfg_yy_wrapper.c | 18 ++++++++++++ l10ntools/source/cfglex.l | 19 ++++++++++++- l10ntools/source/cfgmerge.cxx | 37 ++++++++++--------------- l10ntools/source/directory.cxx | 37 ++++++++++--------------- l10ntools/source/export.cxx | 37 ++++++++++--------------- l10ntools/source/export2.cxx | 37 ++++++++++--------------- l10ntools/source/file.cxx | 43 ++++++++++++----------------- l10ntools/source/filter/merge/FCFGMerge.cfg | 33 ++++++++-------------- l10ntools/source/helpex.cxx | 37 ++++++++++--------------- l10ntools/source/helpmerge.cxx | 37 ++++++++++--------------- l10ntools/source/lngex.cxx | 37 ++++++++++--------------- l10ntools/source/lngmerge.cxx | 37 ++++++++++--------------- l10ntools/source/localize.cxx | 37 ++++++++++--------------- l10ntools/source/merge.cxx | 37 ++++++++++--------------- l10ntools/source/src_yy_wrapper.c | 18 ++++++++++++ l10ntools/source/srclex.l | 19 ++++++++++++- l10ntools/source/tagtest.cxx | 37 ++++++++++--------------- l10ntools/source/xmlparse.cxx | 37 ++++++++++--------------- l10ntools/source/xrm_yy_wrapper.c | 18 ++++++++++++ l10ntools/source/xrmlex.l | 19 ++++++++++++- l10ntools/source/xrmmerge.cxx | 37 ++++++++++--------------- 34 files changed, 499 insertions(+), 576 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Makefile b/l10ntools/Makefile index ccb1c85a04da..0997e628485b 100644 --- a/l10ntools/Makefile +++ b/l10ntools/Makefile @@ -1,4 +1,11 @@ # -*- 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/. +# module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx index c554aaf9246f..316c9dee2181 100644 --- a/l10ntools/inc/cfgmerge.hxx +++ b/l10ntools/inc/cfgmerge.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #ifndef _CFG_MERGE_HXX #define _CFG_MERGE_HXX diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx index be243600d6a6..9a4ce788ec77 100644 --- a/l10ntools/inc/export.hxx +++ b/l10ntools/inc/export.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #ifndef _EXPORT_HXX #define _EXPORT_HXX diff --git a/l10ntools/inc/gsicheck.hxx b/l10ntools/inc/gsicheck.hxx index 467925e46767..8d8992d2f6de 100644 --- a/l10ntools/inc/gsicheck.hxx +++ b/l10ntools/inc/gsicheck.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #ifndef _GSICHECK_HXX_ #define _GSICHECK_HXX_ diff --git a/l10ntools/inc/helpmerge.hxx b/l10ntools/inc/helpmerge.hxx index bc2a6afa253f..34dfdc7eb472 100644 --- a/l10ntools/inc/helpmerge.hxx +++ b/l10ntools/inc/helpmerge.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "export.hxx" #include "xmlparse.hxx" diff --git a/l10ntools/inc/l10ntools/directory.hxx b/l10ntools/inc/l10ntools/directory.hxx index d70e5fe333fa..ad192ec7dc55 100644 --- a/l10ntools/inc/l10ntools/directory.hxx +++ b/l10ntools/inc/l10ntools/directory.hxx @@ -1,4 +1,22 @@ /* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + #include #include #include diff --git a/l10ntools/inc/l10ntools/file.hxx b/l10ntools/inc/l10ntools/file.hxx index fae252e5f926..8c900ddd333f 100644 --- a/l10ntools/inc/l10ntools/file.hxx +++ b/l10ntools/inc/l10ntools/file.hxx @@ -1,4 +1,22 @@ /* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + #include "rtl/ustring.hxx" namespace transex diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx index dd9cbf6359d0..6391d1c25b3f 100644 --- a/l10ntools/inc/lngmerge.hxx +++ b/l10ntools/inc/lngmerge.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/inc/tagtest.hxx b/l10ntools/inc/tagtest.hxx index b546be2bab1e..a6ccec4d73ea 100644 --- a/l10ntools/inc/tagtest.hxx +++ b/l10ntools/inc/tagtest.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #ifndef _TAGTEST_HXX_ #define _TAGTEST_HXX_ diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx index 36fdd608e45c..0fedb2b7a6d8 100644 --- a/l10ntools/inc/xmlparse.hxx +++ b/l10ntools/inc/xmlparse.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #ifndef BOOTSTRP_XMLPARSE_HXX #define BOOTSTRP_XMLPARSE_HXX diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx index b80d37aaa5fa..e9839cee2288 100644 --- a/l10ntools/inc/xrmmerge.hxx +++ b/l10ntools/inc/xrmmerge.hxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/scripts/fast_merge.pl b/l10ntools/scripts/fast_merge.pl index 7074beaa3ff5..bd204870169d 100644 --- a/l10ntools/scripts/fast_merge.pl +++ b/l10ntools/scripts/fast_merge.pl @@ -1,32 +1,23 @@ : eval 'exec perl -wS $0 ${1+"$@"}' if 0; -#************************************************************************* # -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# This file is part of the LibreOffice project. # -# Copyright 2000, 2010 Oracle and/or its affiliates. +# 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/. # -# OpenOffice.org - a multi-platform office productivity suite +# This file incorporates work covered by the following license notice: # -# This file is part of OpenOffice.org. +# 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 . # -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* use strict; use Class::Struct; diff --git a/l10ntools/scripts/keyidGen.pl b/l10ntools/scripts/keyidGen.pl index cf95b2937830..6747ef15b022 100644 --- a/l10ntools/scripts/keyidGen.pl +++ b/l10ntools/scripts/keyidGen.pl @@ -1,32 +1,23 @@ -: +: eval 'exec perl -S $0 ${1+"$@"}' if 0; -#************************************************************************* # -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# This file is part of the LibreOffice project. # -# Copyright 2000, 2010 Oracle and/or its affiliates. +# 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/. # -# OpenOffice.org - a multi-platform office productivity suite +# This file incorporates work covered by the following license notice: # -# This file is part of OpenOffice.org. +# 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 . # -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* # # add keyids to sdf file # diff --git a/l10ntools/source/cfg_yy_wrapper.c b/l10ntools/source/cfg_yy_wrapper.c index b22d2a77cd87..485ce0ab6b7e 100644 --- a/l10ntools/source/cfg_yy_wrapper.c +++ b/l10ntools/source/cfg_yy_wrapper.c @@ -1,4 +1,22 @@ /* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + // Helper to suppress warnings in lex generated c code, see #i57362# #include "cfg_yy.c" diff --git a/l10ntools/source/cfglex.l b/l10ntools/source/cfglex.l index 16ddf289fda3..3ace0a7c3563 100644 --- a/l10ntools/source/cfglex.l +++ b/l10ntools/source/cfglex.l @@ -1,7 +1,24 @@ %{ /* - * lexer for parsing cfg source files + * 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/. * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +/* + * lexer for parsing cfg source files */ /* enlarge token buffer to tokenize whole strings */ diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index cca19c9bc1b1..41db0973fb47 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "common.hxx" #include "sal/config.h" diff --git a/l10ntools/source/directory.cxx b/l10ntools/source/directory.cxx index c2c73ea6a863..468bfbd67837 100644 --- a/l10ntools/source/directory.cxx +++ b/l10ntools/source/directory.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index 9cc3a56c296a..8fe8057188c3 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 013ae90d164f..726f36a59541 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/file.cxx b/l10ntools/source/file.cxx index d9d50553a979..be4fdde8c687 100644 --- a/l10ntools/source/file.cxx +++ b/l10ntools/source/file.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ +/* + * 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ #include diff --git a/l10ntools/source/filter/merge/FCFGMerge.cfg b/l10ntools/source/filter/merge/FCFGMerge.cfg index cae30bdd0260..4516a777bc57 100644 --- a/l10ntools/source/filter/merge/FCFGMerge.cfg +++ b/l10ntools/source/filter/merge/FCFGMerge.cfg @@ -1,29 +1,20 @@ -#************************************************************************* # -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. +# This file is part of the LibreOffice project. # -# OpenOffice.org - a multi-platform office productivity suite +# 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/. # -# This file is part of OpenOffice.org. +# This file incorporates work covered by the following license notice: # -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. +# 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 . # -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* #************************************************ # Specify the verbose mode of this tool. diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index 7896fdd8598a..470b4f1383bc 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index 2d4435c5e74c..05b3800bbc81 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/lngex.cxx b/l10ntools/source/lngex.cxx index 0e910badfff7..ab2f0afe0eb5 100644 --- a/l10ntools/source/lngex.cxx +++ b/l10ntools/source/lngex.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index 09cac112adeb..264b50c74f56 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 6bc92a8f3ee6..941f8d92f941 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index b9fe90f8ae4c..a58807594681 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/src_yy_wrapper.c b/l10ntools/source/src_yy_wrapper.c index da9c17fdc464..3fdcc392bfc4 100644 --- a/l10ntools/source/src_yy_wrapper.c +++ b/l10ntools/source/src_yy_wrapper.c @@ -1,4 +1,22 @@ /* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + // Helper to suppress warnings in lex generated c code, see #i57362# #include "src_yy.c" diff --git a/l10ntools/source/srclex.l b/l10ntools/source/srclex.l index 01be0df7ea3b..9215702b3c98 100644 --- a/l10ntools/source/srclex.l +++ b/l10ntools/source/srclex.l @@ -1,8 +1,25 @@ %{ /* - * lexer for parsing resource source files (*.src) + * 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/. * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +/* + * lexer for parsing resource source files (*.src) */ /* enlarge token buffer to tokenize whole strings */ diff --git a/l10ntools/source/tagtest.cxx b/l10ntools/source/tagtest.cxx index 062c5c78a583..ada1a36582f1 100644 --- a/l10ntools/source/tagtest.cxx +++ b/l10ntools/source/tagtest.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. +/* + * This file is part of the LibreOffice project. * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). + * 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/. * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. + * This file incorporates work covered by the following license notice: * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx index 48e0d3f97512..dc2e3d639606 100644 --- a/l10ntools/source/xmlparse.cxx +++ b/l10ntools/source/xmlparse.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" diff --git a/l10ntools/source/xrm_yy_wrapper.c b/l10ntools/source/xrm_yy_wrapper.c index 191d16f30146..36f902e0fdf6 100644 --- a/l10ntools/source/xrm_yy_wrapper.c +++ b/l10ntools/source/xrm_yy_wrapper.c @@ -1,4 +1,22 @@ /* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + // Helper to suppress warnings in lex generated c code, see #i57362# #include "xrm_yy.c" diff --git a/l10ntools/source/xrmlex.l b/l10ntools/source/xrmlex.l index eadb19f3fbfb..dfe74d7c1a56 100644 --- a/l10ntools/source/xrmlex.l +++ b/l10ntools/source/xrmlex.l @@ -1,7 +1,24 @@ %{ /* - * lexer for parsing xml-property source files (*.xml) + * 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/. * + * This file incorporates work covered by the following license notice: + * + * 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 . + */ + +/* + * lexer for parsing xml-property source files (*.xml) */ /* enlarge token buffer to tokenize whole strings */ diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index 7d2a01f2215e..a22996d8db43 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -1,30 +1,21 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* +/* + * This file is part of the LibreOffice project. * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * 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/. * - * Copyright 2000, 2010 Oracle and/or its affiliates. + * This file incorporates work covered by the following license notice: * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ + * 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 . + */ #include "sal/config.h" -- cgit From 8b22407ef36d1a8934f3d917354d95f37d4aab65 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 1 Oct 2012 20:26:05 +0200 Subject: Add some new checking Plus use UpperCamelCase name for some variable. Change-Id: Iaba8b6f47f03b723aa31ef4b45f8b6fd78b7866f --- l10ntools/inc/po.hxx | 2 ++ l10ntools/source/merge.cxx | 24 +++++++++++++++++++----- l10ntools/source/po.cxx | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 76312a4a59e5..9163e6a10230 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -113,6 +113,8 @@ public: friend class PoOfstream; friend class PoIfstream; + enum Exception { NOLANG }; + PoHeader(); PoHeader( const OString& rExtSrc ); PoHeader( std::ifstream& rOldPo ); diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index a58807594681..5738565dde1e 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -165,7 +165,7 @@ MergeDataFile::MergeDataFile( bool bFirstLang = true; while( !aInputStream.eof() ) { - const OString sHACK("HACK"); + const OString sHack("HACK"); const OString sFileName( lcl_NormalizeFilename(rFile) ); PoIfstream aPoInput; aPoInput.open( OString(sPoFileName.data(), sPoFileName.length()) ); @@ -189,8 +189,22 @@ MergeDataFile::MergeDataFile( return; } } - const OString nLANG = aPoHeader.getLanguage(); - aLanguageSet.insert( nLANG ); + OString sLang; + try + { + sLang = aPoHeader.getLanguage(); + } + catch( PoHeader::Exception& aException ) + { + if( aException = PoHeader::NOLANG ) + { + printf( + "Warning : %s' header not has language specification\n", + sPoFileName.c_str() ); + return; + } + } + aLanguageSet.insert( sLang ); PoEntry aNextPo; do { @@ -247,7 +261,7 @@ MergeDataFile::MergeDataFile( InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), - aActPo.getLocalId(), sHACK, nLANG, sText, + aActPo.getLocalId(), sHack, sLang, sText, sQHText, sTitle, sFileName, bCaseSensitive ); if( bFirstLang ) @@ -255,7 +269,7 @@ MergeDataFile::MergeDataFile( aLanguageSet.insert("qtz"); InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), - aActPo.getLocalId(), sHACK, "qtz", + aActPo.getLocalId(), sHack, "qtz", sQTZText + "||" + sExText, sQTZQHText + "||" + sExQHText, sQTZTitle + "||" + sExTitle, sFileName, bCaseSensitive ); } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index a922575e41fd..465e18e3ab6d 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -537,6 +537,7 @@ void PoEntry::setFuzzy(const bool bFuzzy) //Check whether po-s belong to the same localization component bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) { + assert( rPo1.m_bIsInitialized && rPo2.m_bIsInitialized ); return ( rPo1.getSourceFile() == rPo2.getSourceFile() && rPo1.getGroupId() == rPo2.getGroupId() && rPo1.getLocalId() == rPo2.getLocalId() && @@ -632,7 +633,11 @@ OString PoHeader::getLanguage() const const OString sTransStr = m_aGenPo.getTransStr(); const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength(); const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex; - return sTransStr.copy(nFirstIndex,nCount); + if( nFirstIndex == sLang.getLength()-1 || nCount == -nFirstIndex-1 ) + { + throw NOLANG; + } + return sTransStr.copy( nFirstIndex, nCount ); } //Class PoOfstream @@ -741,12 +746,16 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) else { const OString sContext = aGenPo.getContext(); + const sal_Int32 nFirstEndLine = sContext.indexOf('\n'); + const sal_Int32 nLastEndLine = sContext.lastIndexOf('\n'); const sal_Int32 nLastDot = sContext.lastIndexOf('.'); const OString sType = sContext.copy( nLastDot + 1 ); if( !aGenPo.getReference().isEmpty() && - sContext.indexOf('\n') > 0 && + nFirstEndLine > 0 && + (nLastEndLine == nFirstEndLine || + nLastEndLine == sContext.indexOf('\n',nFirstEndLine+1)) && + nLastDot - nLastEndLine > 1 && (sType == "text" || sType == "quickhelptext" || sType == "title") && - nLastDot - sContext.lastIndexOf('\n') > 0 && !aGenPo.getUnTransStr().isEmpty() ) { rPoEntry.m_aGenPo = aGenPo; -- cgit From e3bf6418a86cb0d9771f3a7b715e894bc02ae313 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 3 Oct 2012 10:25:46 +0200 Subject: Correct ulfex to ignore comments Change-Id: I50e41a3946ff885783006018f7b6ff2945cc7dfc --- l10ntools/source/lngmerge.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index 264b50c74f56..fcab6966aef1 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -232,7 +232,7 @@ sal_Bool LngParser::Merge( { sal_Int32 n = 0; rtl::OString sLang(sLine.getToken(0, '=', n)); - if (n == -1) + if (n == -1 || static_cast(sLine.match("/*"))) { ++nPos; } -- cgit From afcfb2fb26282e6e490922cca27d089b0980d071 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 3 Oct 2012 10:31:34 +0200 Subject: One little correction Change-Id: I675bd8a966b2c1654cd6547fc380a51925578835 --- l10ntools/source/merge.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 5738565dde1e..23609e0d268e 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -196,7 +196,7 @@ MergeDataFile::MergeDataFile( } catch( PoHeader::Exception& aException ) { - if( aException = PoHeader::NOLANG ) + if( aException == PoHeader::NOLANG ) { printf( "Warning : %s' header not has language specification\n", -- cgit From 85c93d57c46d02c66b6e604feb867d3ae1abac4e Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 3 Oct 2012 12:37:19 +0200 Subject: Ulfex ignores comments during extraction too During string extraction this does not cause real problem but causes unnecessary operations. Plus make isNextGroup not to change sLine_in parameter. Change-Id: I3db6a94ef320c096a7519f7f83dd4080d0588459 --- l10ntools/source/lngmerge.cxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index fcab6966aef1..b0282f5fb4d7 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -146,12 +146,12 @@ void LngParser::WriteSDF(std::ofstream &aSDFStream, } } -bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in) +bool LngParser::isNextGroup(rtl::OString &sGroup_out, const rtl::OString &sLine_in) { - sLine_in = sLine_in.trim(); - if ((sLine_in[0] == '[') && (sLine_in[sLine_in.getLength() - 1] == ']')) + const OString sLineTrim = sLine_in.trim(); + if ((sLineTrim[0] == '[') && (sLineTrim[sLineTrim.getLength() - 1] == ']')) { - sGroup_out = getBracketedContent(sLine_in).trim(); + sGroup_out = getBracketedContent(sLineTrim).trim(); return true; } return false; @@ -160,10 +160,13 @@ bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in) void LngParser::ReadLine(const rtl::OString &rLine_in, OStringHashMap &rText_inout) { - rtl::OString sLang(rLine_in.getToken(0, '=').trim()); - if (!sLang.isEmpty()) { - rtl::OString sText(rLine_in.getToken(1, '"')); - rText_inout[sLang] = sText; + if (!rLine_in.match(" *") && !rLine_in.match("/*")) + { + rtl::OString sLang(rLine_in.getToken(0, '=').trim()); + if (!sLang.isEmpty()) { + rtl::OString sText(rLine_in.getToken(1, '"')); + rText_inout[sLang] = sText; + } } } -- cgit From 39bcbb571158af926a1db8d49f1d87156a9b62ae Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 3 Oct 2012 14:20:18 +0200 Subject: Add new signature of isNextGroup in header to be consistant with implementation Change-Id: I2b2e68c4805ab575a8ee2d1ca835d79f8fe9cc45 --- l10ntools/inc/lngmerge.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx index 6391d1c25b3f..3995bd73c8c0 100644 --- a/l10ntools/inc/lngmerge.hxx +++ b/l10ntools/inc/lngmerge.hxx @@ -44,7 +44,7 @@ private: sal_Bool bULF; std::vector aLanguages; - bool isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in); + bool isNextGroup(rtl::OString &sGroup_out, const rtl::OString &sLine_in); void ReadLine(const rtl::OString &rLine_in, OStringHashMap &rText_inout); void WriteSDF(std::ofstream &aSDFStream, OStringHashMap &rText_inout, -- cgit From a418748140f993e481e2ff1cb37464936f0b2243 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 4 Oct 2012 18:57:28 +0200 Subject: Extract argument-handling to one source file Plus cleanup -Delete unneeded global variables -Delete -e input flag in general -Delete helpex's -x, -y and -lf input flags These are all unused Change-Id: I83db62543a728ed75fa6893c45566f11d1237c69 --- l10ntools/inc/export.hxx | 24 +++++ l10ntools/source/cfgmerge.cxx | 89 +++--------------- l10ntools/source/export.cxx | 86 +++--------------- l10ntools/source/export2.cxx | 105 +++++++++++++++++++++ l10ntools/source/helpex.cxx | 207 +++--------------------------------------- l10ntools/source/lngex.cxx | 137 ++-------------------------- l10ntools/source/localize.cxx | 2 +- l10ntools/source/uimerge.cxx | 113 ++--------------------- l10ntools/source/xrmlex.l | 14 +-- l10ntools/source/xrmmerge.cxx | 101 ++++----------------- 10 files changed, 210 insertions(+), 668 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx index 9a4ce788ec77..28807f6c95a8 100644 --- a/l10ntools/inc/export.hxx +++ b/l10ntools/inc/export.hxx @@ -248,6 +248,27 @@ typedef ::std::vector< ResData* > ResStack; class WordTransformer; class ParserQueue; +//result type of handleArguments() +struct HandledArgs +{ + OString m_sPrj; + OString m_sPrjRoot; + OString m_sInputFile; + OString m_sOutputFile; + OString m_sMergeSrc; + OString m_sLanguages; + bool m_bMergeMode; + HandledArgs() + : m_sPrj( OString() ) + , m_sPrjRoot( OString() ) + , m_sInputFile( OString() ) + , m_sOutputFile( OString() ) + , m_sMergeSrc( OString() ) + , m_sLanguages( OString() ) + , m_bMergeMode( false ) + {} +}; + class Export { private: @@ -285,6 +306,9 @@ public: static rtl::OString sLanguages; // public ? static rtl::OString sForcedLanguages; // public ? + static bool handleArguments(int argc, char * argv[], HandledArgs& o_aHandledArgs); + static void writeUsage(const OString& rName, const OString& rFileType); + static void InitLanguages( bool bMergeMode = false ); static void InitForcedLanguages( bool bMergeMode = false ); static std::vector GetLanguages(); diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index 41db0973fb47..3eb442f3a2cd 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -38,86 +38,24 @@ namespace { namespace global { -bool mergeMode = false; -char const * prj = 0; -char const * prjRoot = 0; char const * inputPathname = 0; -char const * outputPathname = 0; -char const * mergeSrc; boost::scoped_ptr< CfgParser > parser; } - -void handleArguments(int argc, char ** argv) { - for (int i = 1; i != argc; ++i) { - if (std::strcmp(argv[i], "-e") == 0) { - // ignored, used to be "Disable writing errorlog" - } else if (std::strcmp(argv[i], "-i") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::inputPathname = argv[i]; - } else if (std::strcmp(argv[i], "-l") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - Export::sLanguages = argv[i]; - } else if (std::strcmp(argv[i], "-m") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::mergeSrc = argv[i]; - global::mergeMode = true; - } else if (std::strcmp(argv[i], "-o") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::outputPathname = argv[i]; - } else if (std::strcmp(argv[i], "-p") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::prj = argv[i]; - } else if (std::strcmp(argv[i], "-r") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::prjRoot = argv[i]; - } else { - global::inputPathname = 0; // no valid command line - break; - } - } - if (global::inputPathname == 0 || global::outputPathname == 0) { - std::fprintf( - stderr, - ("Syntax: cfgex [-p Prj] [-r PrjRoot] -i FileIn -o FileOut" - " [-m DataBase] [-e] [-l l1,l2,...]\n" - " Prj: Project\n" - " PrjRoot: Path to project root (../.. etc.)\n" - " FileIn: Source files (*.src)\n" - " FileOut: Destination file (*.*)\n" - " DataBase: Mergedata (*.sdf)\n" - " -e: ignored\n" - " -l: Restrict the handled languages; l1, l2, ... are elements of" - " (de, en-US, ...)\n")); - std::exit(EXIT_FAILURE); - } - Export::InitLanguages(); -} - } extern "C" { FILE * init(int argc, char ** argv) { - handleArguments(argc, argv); + + HandledArgs aArgs; + if ( !Export::handleArguments(argc, argv, aArgs) ) + { + Export::writeUsage("cfgex","xcu"); + std::exit(EXIT_FAILURE); + } + Export::InitLanguages(); + global::inputPathname = aArgs.m_sInputFile.getStr(); FILE * pFile = std::fopen(global::inputPathname, "r"); if (pFile == 0) { @@ -127,16 +65,17 @@ FILE * init(int argc, char ** argv) { std::exit(EXIT_FAILURE); } - if (global::mergeMode) { + if (aArgs.m_bMergeMode) { global::parser.reset( new CfgMerge( - global::mergeSrc, global::outputPathname, + aArgs.m_sMergeSrc.getStr(), aArgs.m_sOutputFile.getStr(), global::inputPathname)); } else { global::parser.reset( new CfgExport( - global::outputPathname, global::prj, - common::pathnameToken(global::inputPathname, global::prjRoot))); + aArgs.m_sOutputFile.getStr(), aArgs.m_sPrj.getStr(), + common::pathnameToken(global::inputPathname, + aArgs.m_sPrjRoot.getStr()))); } return pFile; diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index 8fe8057188c3..d9dd5ac9878f 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -42,86 +42,28 @@ MergeDataFile * pMergeDataFile = 0; //TODO namespace global { -bool mergeMode = false; char const * prj = 0; char const * prjRoot = 0; char const * inputPathname = 0; -char const * outputPathname = 0; -char const * mergeSrc; boost::scoped_ptr< Export > exporter; } - -void handleArguments(int argc, char ** argv) { - for (int i = 1; i != argc; ++i) { - if (std::strcmp(argv[i], "-e") == 0) { - // ingored, used to be "Disable writing errorlog" - } else if (std::strcmp(argv[i], "-i") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::inputPathname = argv[i]; - } else if (std::strcmp(argv[i], "-l") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - Export::sLanguages = argv[i]; - } else if (std::strcmp(argv[i], "-m") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::mergeSrc = argv[i]; - global::mergeMode = true; - } else if (std::strcmp(argv[i], "-o") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::outputPathname = argv[i]; - } else if (std::strcmp(argv[i], "-p") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::prj = argv[i]; - } else if (std::strcmp(argv[i], "-r") == 0) { - if (++i == argc) { - global::inputPathname = 0; // no valid command line - break; - } - global::prjRoot = argv[i]; - } else { - global::inputPathname = 0; // no valid command line - break; - } - } - if (global::inputPathname == 0 || global::outputPathname == 0) { - std::fprintf( - stderr, - ("Syntax: transex3 [-p Prj] [-r PrjRoot] -i FileIn -o FileOut" - " [-m DataBase] [-e] [-l l1,l2,...]\n" - " Prj: Project\n" - " PrjRoot: Path to project root (../.. etc.)\n" - " FileIn: Source files (*.src)\n" - " FileOut: Destination file (*.*)\n" - " DataBase: Mergedata (*.sdf)\n" - " -e: ignored\n" - " -l: Restrict the handled languages; l1, l2, ... are elements of" - " (de, en-US, ...)\n")); - std::exit(EXIT_FAILURE); - } - Export::InitLanguages(); -} - } extern "C" { FILE * init(int argc, char ** argv) { - handleArguments(argc, argv); + + HandledArgs aArgs; + if ( !Export::handleArguments(argc, argv, aArgs) ) + { + Export::writeUsage("transex3","src/hrc"); + std::exit(EXIT_FAILURE); + } + Export::InitLanguages(); + global::prj = aArgs.m_sPrj.getStr(); + global::prjRoot = aArgs.m_sPrjRoot.getStr(); + global::inputPathname = aArgs.m_sInputFile.getStr(); FILE * pFile = std::fopen(global::inputPathname, "r"); if (pFile == 0) { @@ -131,13 +73,13 @@ FILE * init(int argc, char ** argv) { std::exit(EXIT_FAILURE); } - if (global::mergeMode) { + if (aArgs.m_bMergeMode) { global::exporter.reset( - new Export(global::mergeSrc, global::outputPathname)); + new Export(aArgs.m_sMergeSrc.getStr(), aArgs.m_sOutputFile.getStr())); } else { sActFileName = common::pathnameToken(global::inputPathname, global::prjRoot); - global::exporter.reset(new Export(global::outputPathname)); + global::exporter.reset(new Export(aArgs.m_sOutputFile.getStr())); } global::exporter->Init(); diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 726f36a59541..e2be3f3e9bed 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -31,6 +31,15 @@ #include #include +//flags for handleArguments() +#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_LANGUAGES 0x0007 + // // class ResData(); // @@ -82,6 +91,102 @@ rtl::OString Export::sLanguages; rtl::OString Export::sForcedLanguages; /*****************************************************************************/ +bool Export::handleArguments( + int argc, char * argv[], HandledArgs& o_aHandledArgs) +{ + if ( argc <= 1 ) + { + return false; + } + sLanguages = ""; + sal_uInt16 nState = STATE_NON; + + for( int i = 1; i < argc; i++ ) + { + if ( OString( argv[ i ] ).toAsciiUpperCase() == "-I" ) + { + nState = STATE_INPUT; // next token specifies source file + } + else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-O" ) + { + nState = STATE_OUTPUT; // next token specifies the dest file + } + else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-P" ) + { + nState = STATE_PRJ; // next token specifies the cur. project + } + else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-R" ) + { + nState = STATE_ROOT; // next token specifies path to project root + } + else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-M" ) + { + nState = STATE_MERGESRC; // next token specifies the merge database + } + else if ( OString( argv[ i ] ).toAsciiUpperCase() == "-L" ) + { + nState = STATE_LANGUAGES; + } + else + { + switch ( nState ) + { + case STATE_NON: + { + return false; // no valid command line + } + case STATE_INPUT: + { + o_aHandledArgs.m_sInputFile = OString( argv[i] ); + } + break; + case STATE_OUTPUT: + { + o_aHandledArgs.m_sOutputFile = OString( argv[i] ); + } + break; + case STATE_PRJ: + { + o_aHandledArgs.m_sPrj = OString( argv[i] ); + } + break; + case STATE_ROOT: + { + o_aHandledArgs.m_sPrjRoot = OString( argv[i] ); + } + break; + case STATE_MERGESRC: + { + o_aHandledArgs.m_sMergeSrc = OString( argv[i] ); + o_aHandledArgs.m_bMergeMode = true; + } + break; + case STATE_LANGUAGES: + { + sLanguages = OString( argv[i] ); + } + break; + } + } + } + return true; +} + +void Export::writeUsage(const OString& rName, const OString& rFileType) +{ + std::cout + << "Syntax: " << rName.getStr() + << " [-p Prj] [-r PrjRoot] -i FileIn -o FileOut" + << " [-m DataBase] [-l l1,l2,...]\n" + << " Prj: Project\n" + << " PrjRoot: Path to project root (../.. etc.)\n" + << " FileIn: Source files (*." << rFileType.getStr() << ")\n" + << " FileOut: Destination file (*.*)\n" + << " DataBase: Mergedata (*.po)\n" + << " -l: Restrict the handled languages; l1, l2, ... are elements of" + << " (de, en-US, ...)\n"; +} + /*****************************************************************************/ void Export::SetLanguages( std::vector val ){ /*****************************************************************************/ diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index 470b4f1383bc..574987eb0d03 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -28,213 +28,34 @@ #include "helpmerge.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_SDFFILE 0x0006 -#define STATE_ERRORLOG 0x0007 -#define STATE_BREAKHELP 0x0008 -#define STATE_UNMERGE 0x0009 -#define STATE_LANGUAGES 0x000A -#define STATE_FORCE_LANGUAGES 0x000B -#define STATE_OUTPUTX 0xfe -#define STATE_OUTPUTY 0xff - -// set of global variables -rtl::OString sInputFile; -sal_Bool bEnableExport; -sal_Bool bMergeMode; -rtl::OString sPrj; -rtl::OString sPrjRoot; -rtl::OString sOutputFile; -rtl::OString sOutputFileX; -rtl::OString sOutputFileY; -rtl::OString sSDFFile; - -/*****************************************************************************/ -sal_Bool ParseCommandLine( int argc, char* argv[]) -/*****************************************************************************/ -{ - bEnableExport = sal_False; - bMergeMode = sal_False; - sPrj = ""; - sPrjRoot = ""; - Export::sLanguages = ""; - Export::sForcedLanguages = ""; - - sal_uInt16 nState = STATE_NON; - sal_Bool bInput = sal_False; - - // parse command line - for( int i = 1; i < argc; i++ ) - { - rtl::OString aArg = rtl::OString(argv[i]).toAsciiUpperCase(); - if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-I"))) - nState = STATE_INPUT; // next tokens specifies source files - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-O"))) - nState = STATE_OUTPUT; // next token specifies the dest file - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-X"))) - nState = STATE_OUTPUTX; // next token specifies the dest file - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-Y" ))) - nState = STATE_OUTPUTY; // next token specifies the dest file - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-P" ))) - nState = STATE_PRJ; // next token specifies the cur. project - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-LF"))) - nState = STATE_FORCE_LANGUAGES; - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-R" ))) - nState = STATE_ROOT; // next token specifies path to project root - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-M" ))) - nState = STATE_SDFFILE; // next token specifies the merge database - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-E" ))) - { - nState = STATE_ERRORLOG; - } - else if (aArg.equalsL(RTL_CONSTASCII_STRINGPARAM("-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_OUTPUTX: { - sOutputFileX = argv[ i ]; // the dest. file - } - break; - case STATE_OUTPUTY: { - sOutputFileY = argv[ i ]; // the dest. file - } - break; - case STATE_PRJ: { - sPrj = argv[ i ]; - } - break; - case STATE_ROOT: { - sPrjRoot = argv[ i ]; // path to project root - } - break; - case STATE_SDFFILE: { - sSDFFile = argv[ i ]; - bMergeMode = sal_True; // activate merge mode, cause merge database found - } - break; - case STATE_LANGUAGES: { - Export::sLanguages = argv[ i ]; - } - case STATE_FORCE_LANGUAGES:{ - Export::sForcedLanguages = argv[ i ]; - } - break; - } - } - } - - if ( bInput ) { - // command line is valid - bEnableExport = sal_True; - return sal_True; - } - - // command line is not valid - return sal_False; -} - - -/*****************************************************************************/ -void Help() -/*****************************************************************************/ -{ - fprintf( stdout, "Syntax: HELPEX[-p Prj][-r PrjRoot]-i FileIn ( -o FileOut | -x path -y relfile )[-m DataBase][-e][-b][-u][-L l1,l2,...] -LF 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 (en-US,fr,de...)\n" ); - fprintf( stdout, " -LF: Force the creation of that languages\n" ); - -} - -/*****************************************************************************/ #ifndef TESTDRIVER SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { - if ( !ParseCommandLine( argc, argv )) { - Help(); + HandledArgs aArgs; + if ( !Export::handleArguments( argc, argv, aArgs) ) { + Export::writeUsage("helpex","xhp"); return 1; } //sal_uInt32 startfull = Export::startMessure(); - - bool hasInputList = sInputFile[0]=='@'; bool hasNoError = true; - if ( sOutputFile.getLength() ){ // Merge single file ? - HelpParser aParser( sInputFile ); + if ( !aArgs.m_sOutputFile.isEmpty() ){ + HelpParser aParser( aArgs.m_sInputFile ); - if ( bMergeMode ) + if ( aArgs.m_bMergeMode ) { //sal_uInt64 startreadloc = Export::startMessure(); - MergeDataFile aMergeDataFile(sSDFFile, sInputFile, false); + MergeDataFile aMergeDataFile( aArgs.m_sMergeSrc, aArgs.m_sInputFile, false ); - hasNoError = aParser.Merge( sSDFFile, sOutputFile , Export::sLanguages , aMergeDataFile ); + hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile , Export::sLanguages , aMergeDataFile ); } else - hasNoError = aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot, sInputFile, new XMLFile( rtl::OUString('0') ), "help" ); - }else if ( sOutputFileX.getLength() && sOutputFileY.getLength() && hasInputList ) { // Merge multiple files ? - if ( bMergeMode ){ - - ifstream aFStream( sInputFile.copy( 1 ).getStr() , ios::in ); - - if( !aFStream ){ - std::cerr << "ERROR: - helpex - Can't open the file " << sInputFile.copy( 1 ).getStr() << "\n"; - std::exit(EXIT_FAILURE); - } - - vector filelist; - rtl::OStringBuffer filename; - sal_Char aChar; - while( aFStream.get( aChar ) ) - { - if( aChar == ' ' || aChar == '\n') - filelist.push_back(filename.makeStringAndClear()); - else - filename.append( aChar ); - } - if( filename.getLength() > 0 ) - filelist.push_back(filename.makeStringAndClear()); - - aFStream.close(); - rtl::OString sHelpFile; // dummy - MergeDataFile aMergeDataFile( sSDFFile, sHelpFile, false ); - - std::vector aLanguages; - HelpParser::parse_languages( aLanguages , aMergeDataFile ); - - bool bCreateDir = true; - for( vector::iterator pos = filelist.begin() ; pos != filelist.end() ; ++pos ) - { - sHelpFile = *pos; - - HelpParser aParser( sHelpFile ); - hasNoError = aParser.Merge( sSDFFile , sOutputFileX , sOutputFileY , true , aLanguages , aMergeDataFile , bCreateDir ); - bCreateDir = false; - } - } - } else + hasNoError = + aParser.CreateSDF( + aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot, + aArgs.m_sInputFile, new XMLFile( OUString('0') ), "help" ); + } + else std::cerr << "helpex ERROR: Wrong input parameters!\n"; if( hasNoError ) diff --git a/l10ntools/source/lngex.cxx b/l10ntools/source/lngex.cxx index ab2f0afe0eb5..706ab26309b8 100644 --- a/l10ntools/source/lngex.cxx +++ b/l10ntools/source/lngex.cxx @@ -25,140 +25,23 @@ #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_ULF 0x000A -#define STATE_LANGUAGES 0x000B - -// set of global variables -rtl::OString sInputFile; -sal_Bool bEnableExport; -sal_Bool bMergeMode; -sal_Bool bUTF8; -sal_Bool bULF; // ULF = Unicode Language File -rtl::OString sPrj; -rtl::OString sPrjRoot; -rtl::OString sOutputFile; -rtl::OString sMergeSrc; - -/*****************************************************************************/ -sal_Bool ParseCommandLine( int argc, char* argv[]) -/*****************************************************************************/ -{ - bEnableExport = sal_False; - bMergeMode = sal_False; - 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++ ) { - rtl::OString sSwitch = rtl::OString(argv[i]).toAsciiUpperCase(); - if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-I"))) - nState = STATE_INPUT; // next tokens specifies source files - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-O"))) - nState = STATE_OUTPUT; // next token specifies the dest file - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-P"))) - nState = STATE_PRJ; // next token specifies the cur. project - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-R"))) - nState = STATE_ROOT; // next token specifies path to project root - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-M"))) - nState = STATE_MERGESRC; // next token specifies the merge database - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-E"))) - { - nState = STATE_ERRORLOG; - } - else if (sSwitch.equalsL(RTL_CONSTASCII_STRINGPARAM("-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 ]; - } - 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" ); -} - SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { - if ( !ParseCommandLine( argc, argv )) + + HandledArgs aArgs; + if ( !Export::handleArguments(argc, argv, aArgs) ) { - Help(); + Export::writeUsage("ulfex","ulf"); return 1; } - if (!sOutputFile.isEmpty()) + if (!aArgs.m_sOutputFile.isEmpty()) { - LngParser aParser( sInputFile, bULF ); - if ( bMergeMode ) - aParser.Merge(sMergeSrc, sOutputFile); + LngParser aParser( aArgs.m_sInputFile, true ); + if ( aArgs.m_bMergeMode ) + aParser.Merge(aArgs.m_sMergeSrc, aArgs.m_sOutputFile); else - aParser.CreateSDF( sOutputFile, sPrj, sPrjRoot ); + aParser.CreateSDF( + aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot ); } return 0; diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 941f8d92f941..fd1d8ca4b4d0 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -193,7 +193,7 @@ void handleCommand( RTL_CONSTASCII_USTRINGPARAM("INPATH_FOR_BUILD")))); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/bin/")); buf.append(executable); - buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" -e -p ")); + buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" -p ")); buf.append(project); buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" -r ")); buf.append(projectRoot); diff --git a/l10ntools/source/uimerge.cxx b/l10ntools/source/uimerge.cxx index bdf536a238dc..4192ed73d6be 100644 --- a/l10ntools/source/uimerge.cxx +++ b/l10ntools/source/uimerge.cxx @@ -26,100 +26,10 @@ #include #include -#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_LANGUAGES 0x000C - -sal_Bool bMergeMode; -sal_Bool bErrorLog; -sal_Bool bUTF8; -sal_Bool bDisplayName; -sal_Bool bExtensionDescription; rtl::OString sPrj; rtl::OString sPrjRoot; rtl::OString sInputFileName; rtl::OString sOutputFile; -rtl::OString sMergeSrc; -rtl::OString sLangAttribute; -rtl::OString sResourceType; -XRMResParser *pParser = NULL; - -void GetOutputFile( int argc, char* argv[]) -{ - bMergeMode = sal_False; - bErrorLog = sal_True; - bUTF8 = sal_True; - bDisplayName = sal_False; - bExtensionDescription = sal_False; - sPrj = ""; - sPrjRoot = ""; - sInputFileName = ""; - Export::sLanguages = ""; - sal_uInt16 nState = STATE_NON; - - // parse command line - for( int i = 1; i < argc; i++ ) { - if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-I" ) { - nState = STATE_INPUT; // next token specifies source file - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-O" ) { - nState = STATE_OUTPUT; // next token specifies the dest file - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-P" ) { - nState = STATE_PRJ; // next token specifies the cur. project - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-R" ) { - nState = STATE_ROOT; // next token specifies path to project root - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-M" ) { - nState = STATE_MERGESRC; // next token specifies the merge database - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-E" ) { - nState = STATE_ERRORLOG; - bErrorLog = sal_False; - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-L" ) { - nState = STATE_LANGUAGES; - } - else { - switch ( nState ) { - case STATE_NON: { - return; // no valid command line - } - case STATE_INPUT: { - sInputFileName = argv[ i ]; - } - break; - case STATE_OUTPUT: { - sOutputFile = argv[ i ]; // the dest. file - } - break; - case STATE_PRJ: { - sPrj = rtl::OString( argv[ i ]); - } - break; - case STATE_ROOT: { - sPrjRoot = rtl::OString( argv[ i ]); // path to project root - } - break; - case STATE_MERGESRC: { - sMergeSrc = rtl::OString( argv[ i ]); - bMergeMode = sal_True; // activate merge mode, cause merge database found - } - break; - case STATE_LANGUAGES: { - Export::sLanguages = rtl::OString( argv[ i ]); - } - break; - } - } - } -} int extractTranslations() { @@ -275,22 +185,19 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { int nRetValue = 0; - GetOutputFile( argc, argv ); - - if (sOutputFile.isEmpty()) + HandledArgs aArgs; + if ( !Export::handleArguments(argc, argv, aArgs) ) { - fprintf( stdout, "Syntax: UIEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-L l1,l2,...]\n" ); - fprintf( stdout, " Prj: Project\n" ); - fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" ); - fprintf( stdout, " FileIn: Source files (*.src)\n" ); - fprintf( stdout, " FileOut: Destination file (*.*)\n" ); - fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" ); - fprintf( stdout, " -e: Disable writing errorlog\n" ); - fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US,es...)\n" ); + Export::writeUsage("uiex","ui"); return 1; } - if (!bMergeMode) + sPrj = aArgs.m_sPrj; + sPrjRoot = aArgs.m_sPrjRoot; + sInputFileName = aArgs.m_sInputFile; + sOutputFile = aArgs.m_sOutputFile; + + if (!aArgs.m_bMergeMode) { if (Export::sLanguages != "en-US") { @@ -302,7 +209,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) } else { - Merge(sMergeSrc, sInputFileName, sOutputFile); + Merge(aArgs.m_sMergeSrc, sInputFileName, sOutputFile); } return nRetValue; diff --git a/l10ntools/source/xrmlex.l b/l10ntools/source/xrmlex.l index dfe74d7c1a56..8d6094c18d06 100644 --- a/l10ntools/source/xrmlex.l +++ b/l10ntools/source/xrmlex.l @@ -221,18 +221,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { pOutput = GetOutputFile( argc, argv ); - if ( !pOutput ) { - fprintf( stdout, "Syntax: XRMEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-b][-u][-NOUTF8][-L l1,l2,...]\n" ); - fprintf( stdout, " Prj: Project\n" ); - fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" ); - fprintf( stdout, " FileIn: Source files (*.src)\n" ); - fprintf( stdout, " FileOut: Destination file (*.*)\n" ); - fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" ); - fprintf( stdout, " -e: Disable writing errorlog\n" ); - fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" ); - fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" ); - fprintf( stdout, " -NOUTF8: disable UTF8 as language independent encoding\n" ); - fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US,es...)\n" ); + if ( !pOutput ) + { return 1; } pFile = GetXrmFile(); diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index a22996d8db43..4cf4d9e94253 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -36,20 +36,8 @@ using namespace std; void yyerror( const char * ); void YYWarning( const char * ); -// 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_LANGUAGES 0x000C - // set of global variables -sal_Bool bEnableExport; -sal_Bool bMergeMode; -sal_Bool bUTF8; +bool bMergeMode; sal_Bool bDisplayName; sal_Bool bExtensionDescription; rtl::OString sPrj; @@ -69,87 +57,30 @@ extern "C" { extern char *GetOutputFile( int argc, char* argv[]) /*****************************************************************************/ { - bEnableExport = sal_False; - bMergeMode = sal_False; - bUTF8 = sal_True; bDisplayName = sal_False; bExtensionDescription = sal_False; - sPrj = ""; - sPrjRoot = ""; - sInputFileName = ""; sActFileName = ""; - Export::sLanguages = ""; - sal_uInt16 nState = STATE_NON; - sal_Bool bInput = sal_False; - - // parse command line - for( int i = 1; i < argc; i++ ) { - if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-I" ) { - nState = STATE_INPUT; // next token specifies source file - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-O" ) { - nState = STATE_OUTPUT; // next token specifies the dest file - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-P" ) { - nState = STATE_PRJ; // next token specifies the cur. project - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-R" ) { - nState = STATE_ROOT; // next token specifies path to project root - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-M" ) { - nState = STATE_MERGESRC; // next token specifies the merge database - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-E" ) { - nState = STATE_ERRORLOG; - } - else if ( rtl::OString( argv[ i ] ).toAsciiUpperCase() == "-L" ) { - nState = STATE_LANGUAGES; - } - else { - switch ( nState ) { - case STATE_NON: { - return NULL; // no valid command line - } - case STATE_INPUT: { - sInputFileName = argv[ i ]; - bInput = sal_True; // source file found - } - break; - case STATE_OUTPUT: { - sOutputFile = argv[ i ]; // the dest. file - } - break; - case STATE_PRJ: { - sPrj = rtl::OString( argv[ i ]); - } - break; - case STATE_ROOT: { - sPrjRoot = rtl::OString( argv[ i ]); // path to project root - } - break; - case STATE_MERGESRC: { - sMergeSrc = rtl::OString( argv[ i ]); - bMergeMode = sal_True; // activate merge mode, cause merge database found - } - break; - case STATE_LANGUAGES: { - Export::sLanguages = rtl::OString( argv[ i ]); - } - break; - } - } - } - if ( bInput ) { + HandledArgs aArgs; + if ( Export::handleArguments(argc, argv, aArgs) ) + { // command line is valid - bEnableExport = sal_True; + bMergeMode = aArgs.m_bMergeMode; + sPrj = aArgs.m_sPrj; + sPrjRoot = aArgs.m_sPrjRoot; + sInputFileName = aArgs.m_sInputFile; + sOutputFile = aArgs.m_sOutputFile; + sMergeSrc = aArgs.m_sMergeSrc; char *pReturn = new char[ sOutputFile.getLength() + 1 ]; std::strcpy( pReturn, sOutputFile.getStr()); // #100211# - checked return pReturn; } - - // command line is not valid - return NULL; + else + { + // command line is not valid + Export::writeUsage("xrmex","xrm/xml"); + return NULL; + } } /*****************************************************************************/ -- cgit From f9e4d3bfe8eedd49afc2d2161f47a8825a02eec8 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 7 Oct 2012 11:42:37 +0200 Subject: Make Export::handleArguments method safer -Check wheather input and output file are given -Return with "empty" HandledArgs when input is invalid -Delete plus conditions from helpex and lngex Change-Id: I418b1ecaab5f0c78197845448ab062aa5d3ba4de --- l10ntools/source/export2.cxx | 12 +++++++++++- l10ntools/source/helpex.cxx | 28 ++++++++++++---------------- l10ntools/source/lngex.cxx | 15 ++++++--------- 3 files changed, 29 insertions(+), 26 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index e2be3f3e9bed..64a5b1b07e5c 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -94,6 +94,7 @@ rtl::OString Export::sForcedLanguages; bool Export::handleArguments( int argc, char * argv[], HandledArgs& o_aHandledArgs) { + o_aHandledArgs = HandledArgs(); if ( argc <= 1 ) { return false; @@ -169,7 +170,16 @@ bool Export::handleArguments( } } } - return true; + if( !o_aHandledArgs.m_sInputFile.isEmpty() && + !o_aHandledArgs.m_sOutputFile.isEmpty() ) + { + return true; + } + else + { + o_aHandledArgs = HandledArgs(); + return false; + } } void Export::writeUsage(const OString& rName, const OString& rFileType) diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index 574987eb0d03..8dca205cf36e 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -39,24 +39,20 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { //sal_uInt32 startfull = Export::startMessure(); bool hasNoError = true; - if ( !aArgs.m_sOutputFile.isEmpty() ){ - HelpParser aParser( aArgs.m_sInputFile ); - - if ( aArgs.m_bMergeMode ) - { - //sal_uInt64 startreadloc = Export::startMessure(); - MergeDataFile aMergeDataFile( aArgs.m_sMergeSrc, aArgs.m_sInputFile, false ); - - hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile , Export::sLanguages , aMergeDataFile ); - } - else - hasNoError = - aParser.CreateSDF( - aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot, - aArgs.m_sInputFile, new XMLFile( OUString('0') ), "help" ); + HelpParser aParser( aArgs.m_sInputFile ); + if ( aArgs.m_bMergeMode ) + { + //sal_uInt64 startreadloc = Export::startMessure(); + MergeDataFile aMergeDataFile( aArgs.m_sMergeSrc, aArgs.m_sInputFile, false ); + hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile , Export::sLanguages , aMergeDataFile ); } else - std::cerr << "helpex ERROR: Wrong input parameters!\n"; + { + hasNoError = + aParser.CreateSDF( + aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot, + aArgs.m_sInputFile, new XMLFile( OUString('0') ), "help" ); + } if( hasNoError ) return 0; diff --git a/l10ntools/source/lngex.cxx b/l10ntools/source/lngex.cxx index 706ab26309b8..eb5cccc578fc 100644 --- a/l10ntools/source/lngex.cxx +++ b/l10ntools/source/lngex.cxx @@ -34,15 +34,12 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { return 1; } - if (!aArgs.m_sOutputFile.isEmpty()) - { - LngParser aParser( aArgs.m_sInputFile, true ); - if ( aArgs.m_bMergeMode ) - aParser.Merge(aArgs.m_sMergeSrc, aArgs.m_sOutputFile); - else - aParser.CreateSDF( - aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot ); - } + LngParser aParser( aArgs.m_sInputFile, true ); + if ( aArgs.m_bMergeMode ) + aParser.Merge(aArgs.m_sMergeSrc, aArgs.m_sOutputFile); + else + aParser.CreateSDF( + aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot ); return 0; } -- cgit From f73618e9dea03d27138cd4599e351249a79bf46b Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sat, 6 Oct 2012 22:10:41 +0200 Subject: 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 --- 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 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 337 insertions(+), 12 deletions(-) create mode 100644 l10ntools/Executable_propex.mk create mode 100644 l10ntools/inc/propmerge.hxx delete mode 100755 l10ntools/scripts/propex.bat create mode 100644 l10ntools/source/propex.cxx create mode 100644 l10ntools/source/propmerge.cxx (limited to 'l10ntools') diff --git a/l10ntools/Executable_propex.mk b/l10ntools/Executable_propex.mk new file mode 100644 index 000000000000..d8dc16d323c2 --- /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 4b1d64d80e12..e6c0cc3a8047 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 3739f123b434..e97ec6c7d7a9 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 000000000000..3465635c602f --- /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 +#include + +class PropParser +{ +private: + std::vector 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 1174286920da..000000000000 --- a/l10ntools/scripts/propex.bat +++ /dev/null @@ -1,8 +0,0 @@ -@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 000000000000..2977cb158874 --- /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 000000000000..237444ffcfcd --- /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 +#include +#include +#include +#include + +#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( 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( 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() ) + , 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: */ -- cgit From 73ed390a7ff6b701b89faf91385aaa63e865e441 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 8 Oct 2012 18:23:31 +0200 Subject: Correct wrong memory addressing Some global variables in export.cxx and cfgmerge.cxx pointed to OString databuffer and after these strings are destroyed the pointers refered to invalid address. Use OString instead of const char* Change-Id: I4ea43f4b3772ef3370d79336559d39a67400fe2b --- l10ntools/source/cfgmerge.cxx | 10 +++++----- l10ntools/source/export.cxx | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index 3eb442f3a2cd..1d0a819b3d4c 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -38,7 +38,7 @@ namespace { namespace global { -char const * inputPathname = 0; +OString inputPathname; boost::scoped_ptr< CfgParser > parser; } @@ -55,13 +55,13 @@ FILE * init(int argc, char ** argv) { std::exit(EXIT_FAILURE); } Export::InitLanguages(); - global::inputPathname = aArgs.m_sInputFile.getStr(); + global::inputPathname = aArgs.m_sInputFile; - FILE * pFile = std::fopen(global::inputPathname, "r"); + FILE * pFile = std::fopen(global::inputPathname.getStr(), "r"); if (pFile == 0) { std::fprintf( stderr, "Error: Cannot open file \"%s\"\n", - global::inputPathname); + global::inputPathname.getStr() ); std::exit(EXIT_FAILURE); } @@ -74,7 +74,7 @@ FILE * init(int argc, char ** argv) { global::parser.reset( new CfgExport( aArgs.m_sOutputFile.getStr(), aArgs.m_sPrj.getStr(), - common::pathnameToken(global::inputPathname, + common::pathnameToken(global::inputPathname.getStr(), aArgs.m_sPrjRoot.getStr()))); } diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index d9dd5ac9878f..13870da558a2 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -42,9 +42,9 @@ MergeDataFile * pMergeDataFile = 0; //TODO namespace global { -char const * prj = 0; -char const * prjRoot = 0; -char const * inputPathname = 0; +OString prj; +OString prjRoot; +OString inputPathname; boost::scoped_ptr< Export > exporter; } @@ -61,15 +61,15 @@ FILE * init(int argc, char ** argv) { std::exit(EXIT_FAILURE); } Export::InitLanguages(); - global::prj = aArgs.m_sPrj.getStr(); - global::prjRoot = aArgs.m_sPrjRoot.getStr(); - global::inputPathname = aArgs.m_sInputFile.getStr(); + global::prj = aArgs.m_sPrj; + global::prjRoot = aArgs.m_sPrjRoot; + global::inputPathname = aArgs.m_sInputFile; - FILE * pFile = std::fopen(global::inputPathname, "r"); + FILE * pFile = std::fopen(global::inputPathname.getStr(), "r"); if (pFile == 0) { std::fprintf( stderr, "Error: Cannot open file \"%s\"\n", - global::inputPathname); + global::inputPathname.getStr()); std::exit(EXIT_FAILURE); } @@ -78,7 +78,8 @@ FILE * init(int argc, char ** argv) { new Export(aArgs.m_sMergeSrc.getStr(), aArgs.m_sOutputFile.getStr())); } else { sActFileName = - common::pathnameToken(global::inputPathname, global::prjRoot); + common::pathnameToken( + global::inputPathname.getStr(), global::prjRoot.getStr()); global::exporter.reset(new Export(aArgs.m_sOutputFile.getStr())); } -- cgit From 6134c08251ab0da568fc644e030e5af2d6a26a87 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Mon, 8 Oct 2012 19:36:55 +0200 Subject: typos Change-Id: Idb23b390af270bdd694ecce9ab14f47d25af8f57 --- l10ntools/source/propmerge.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 237444ffcfcd..08261684671b 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -71,7 +71,7 @@ namespace return sResult; } - //Escape unicode charachters + //Escape unicode characters void lcl_PrintJavaStyle( const OString& rText, std::ofstream &rOfstream ) { const OUString sTemp = @@ -94,7 +94,7 @@ namespace } } -//Open sourcefile and store it's lines +//Open source file and store its lines PropParser::PropParser( const OString& rInputFile, const OString& rLang, const bool bMergeMode ) @@ -122,7 +122,7 @@ PropParser::PropParser( else { std::cerr - << "Propex error: Cannot open sourcefile: " + << "Propex error: Cannot open source file: " << m_sSource.getStr() << std::endl; return; } @@ -175,7 +175,7 @@ void PropParser::Merge( const OString &rSDFFile, const OString &rDestinationFile rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc ); if( !aDestination.is_open() ) { std::cerr - << "Propex error: Cannot open sourcefile for merge: " + << "Propex error: Cannot open source file for merge: " << rDestinationFile.getStr() << std::endl; return; } -- cgit From 297531a3b3aa531ebb6d32761680b308d8fa3f9e Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Mon, 8 Oct 2012 19:37:57 +0200 Subject: remove propex/propmerge Perl scrips Change-Id: Iab39da2643ba38c4745c29277c10bc39a024ffa3 --- l10ntools/Package_scripts.mk | 2 - l10ntools/scripts/propex | 68 ---------------------------------- l10ntools/scripts/propmerge | 88 -------------------------------------------- 3 files changed, 158 deletions(-) delete mode 100755 l10ntools/scripts/propex delete mode 100755 l10ntools/scripts/propmerge (limited to 'l10ntools') diff --git a/l10ntools/Package_scripts.mk b/l10ntools/Package_scripts.mk index e97ec6c7d7a9..d00d283a8cc6 100644 --- a/l10ntools/Package_scripts.mk +++ b/l10ntools/Package_scripts.mk @@ -30,7 +30,5 @@ $(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/propmerge,propmerge)) - # vim: set noet sw=4 ts=4: diff --git a/l10ntools/scripts/propex b/l10ntools/scripts/propex deleted file mode 100755 index 35dcb258e381..000000000000 --- a/l10ntools/scripts/propex +++ /dev/null @@ -1,68 +0,0 @@ -: -eval 'exec perl -S $0 ${1+"$@"}' - if 0; -# Version: MPL 1.1 / GPLv3+ / LGPLv3+ -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License or as specified alternatively below. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Initial Developer of the Original Code is -# Andras Timar -# Portions created by the Initial Developer are Copyright (C) 2011 the -# Initial Developer. All Rights Reserved. -# -# Major Contributor(s): -# -# For minor contributions see the git repository. -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 3 or later (the "GPLv3+"), or -# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), -# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable -# instead of those above. -# -# extracts strings from Java properties files -# - -use strict; -use File::Basename; -use Getopt::Std; -use Cwd; - -my %options=(); -getopts("ep:r:i:o:l:", \%options); - -unless ( $options{i} =~ m/en_US/ ) {exit 0;} - -$options{i} =~ s|\\|/|g; # fix path on Windows, Perl expects / separator -my ($unused1, $dir, $unused2) = File::Basename::fileparse($options{i}); -my $file = substr ( Cwd::abs_path($options{i}), length(Cwd::abs_path($dir . $options{r})) + 1 ); -$file =~ s|/|\\|g; - -open (INFILE, "<$options{i}") || die "propex: cannot open input file: $options{i}"; -open (OUTFILE, ">$options{o}") || die "propex: cannot open output file: $options{o}"; - -while () { - chomp; - if (/=/) { - my ($id, $value) = split /=/; - $id =~ s/^\s+//; #remove leading spaces - $id =~ s/\s+$//; #remove trailing spaces - $value =~ s/^\s+//; #remove leading spaces - $value =~ s/\s+$//; #remove trailing spaces - $value =~ s/(\\u([0-9a-fA-F]{4}))/pack("C0U1",hex($2))/ge; #convert ascii escaped unicode to utf-8 - print OUTFILE "$options{p}\t$file\t0\tproperty\t$id\t\t\t\t0\ten-US\t$value\t\t\t\t20020202 02:02:02\n"; - } -} - -close (INFILE); -close (OUTFILE); - -exit 0; diff --git a/l10ntools/scripts/propmerge b/l10ntools/scripts/propmerge deleted file mode 100755 index 5ba420d5c858..000000000000 --- a/l10ntools/scripts/propmerge +++ /dev/null @@ -1,88 +0,0 @@ -: -eval 'exec perl -S $0 ${1+"$@"}' - if 0; -# Version: MPL 1.1 / GPLv3+ / LGPLv3+ -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License or as specified alternatively below. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Initial Developer of the Original Code is -# Andras Timar -# Portions created by the Initial Developer are Copyright (C) 2011 the -# Initial Developer. All Rights Reserved. -# -# Major Contributor(s): -# -# For minor contributions see the git repository. -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 3 or later (the "GPLv3+"), or -# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), -# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable -# instead of those above. -# -# merges strings from SDF file to properties files -# - -use strict; -use Getopt::Std; - -my %options=(); -getopts("i:m:", \%options); - -my %translations = (); -my %languages = (); - # ( leftpart ) ( rightpart ) - # prj file dummy type gid lid helpid pform width lang text helptext qhelptext title -my $sdf_regex = "((([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t])*\t([^\t]*)\t([^\t]*))\t([^\t]*)\t(([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)))"; - -open (SDFFILE, "<$options{m}") || die "propmerge: cannot open sdf file: $options{m}"; - -while () { - chomp; - if( /$sdf_regex/ ) { - my $gid = defined $7 ? $7 : ''; - my $lang = defined $12 ? $12 : ''; - my $text = defined $14 ? $14 : ''; - my $key = $lang . $gid; - $languages{$lang} = 1; - utf8::decode($text); - $text =~ s/([^\x{20}-\x{7E}])/sprintf("\\u%04X",ord($1))/ge; - $translations{$key} = $text; - } -} - -close (SDFFILE); - -foreach my $lang (keys %languages) { - my $locfilename = $options{i}; - $lang =~ s/-/_/; - $locfilename =~ s/en_US\.properties/$lang.properties/; - $lang =~ s/_/-/; - open (INFILE, "<$options{i}") || die "propmerge: cannot open source file: $options{i}"; - open (OUTFILE, ">$locfilename") || die "propmerge: cannot open output file: $locfilename"; - while () { - if (/=/) { - chomp; - my ($id, $value) = split /=/; - $id =~ s/^\s+//; #remove leading spaces - $id =~ s/\s+$//; #remove trailing spaces - my $key = $lang . $id; - print OUTFILE "$id=$translations{$key}\n"; - } - else { - print OUTFILE "$_"; - } - } - close (INFILE); - close (OUTFILE); -} - -exit 0; -- cgit From 247bac3266ee933716ecf85e0204b0d6b8c6da74 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 8 Oct 2012 22:43:26 +0200 Subject: Make an end of xrmex id duplication Use GroupId instead of LocalId because that is the primary id. Thus usage of LocalId becomes unneeded. Change-Id: I2770141fab47c07294ab15322848e8aef0de2cec --- l10ntools/source/xrmmerge.cxx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index 4cf4d9e94253..a3eb0e5418ee 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -192,9 +192,9 @@ int XRMResParser::Execute( int nToken, char * pToken ) switch ( nToken ) { case XRM_TEXT_START:{ - rtl::OString sNewLID = GetAttribute( rToken, "id" ); - if ( sNewLID != sLID ) { - sLID = sNewLID; + rtl::OString sNewGID = GetAttribute( rToken, "id" ); + if ( sNewGID != sGID ) { + sGID = sNewGID; } bText = sal_True; sCurrentText = ""; @@ -228,7 +228,7 @@ int XRMResParser::Execute( int nToken, char * pToken ) case DESC_TEXT_START:{ if (bDisplayName) { - sLID = rtl::OString("dispname"); + sGID = rtl::OString("dispname"); bText = sal_True; sCurrentText = ""; sCurrentOpenTag = rToken; @@ -264,7 +264,7 @@ int XRMResParser::Execute( int nToken, char * pToken ) case DESC_EXTENSION_DESCRIPTION_SRC: { if (bExtensionDescription) { - sLID = rtl::OString("extdesc"); + sGID = rtl::OString("extdesc"); sResourceType = rtl::OString ( "description" ); sLangAttribute = rtl::OString ( "lang" ); sCurrentOpenTag = rToken; @@ -429,7 +429,6 @@ void XRMResExport::WorkOnText( { rtl::OString sPlatform( "" ); pResData = new ResData( sPlatform, GetGID() ); - pResData->sId = GetLID(); } rtl::OString sText(rText); @@ -459,12 +458,8 @@ void XRMResExport::EndOfText( sOutput += "\t0\t"; sOutput += sResourceType; sOutput += "\t"; - sOutput += pResData->sId; - // USE LID AS GID OR MERGE DON'T WORK - //sOutput += pResData->sGId; - sOutput += "\t"; - sOutput += pResData->sId; - sOutput += "\t\t\t0\t"; + sOutput += pResData->sGId; + sOutput += "\t\t\t\t0\t"; sOutput += sCur; sOutput += "\t"; @@ -601,8 +596,7 @@ void XRMResMerge::WorkOnText( if ( pMergeDataFile ) { if ( !pResData ) { rtl::OString sPlatform( "" ); - pResData = new ResData( sPlatform, GetLID() , sFilename ); - pResData->sId = GetLID(); + pResData = new ResData( sPlatform, GetGID() , sFilename ); pResData->sResTyp = sResourceType; } -- cgit From 961728d58cb80e7eff11baf8d44c0d37dd1074c9 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 8 Oct 2012 23:03:00 +0200 Subject: Make renewpo to ignore double id in xml/xrm Change-Id: I01329beded3e81040726f525cdb5886b5f3a8c63 --- l10ntools/source/renewpo.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 83b3051134a9..4a11c368a0e7 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -147,14 +147,17 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, if (!sActUnTrans.getToken(vTypes[nIndex],'\t').isEmpty()) { /**Because of xrmex there are duplicated id's, - only use this if xrmex have already fixed + only use this if xrmex have already fixed*/ + const OString sSource = + sActUnTrans.getToken(PoEntry::SOURCEFILE,'\t'); + const OString sEnding = + sSource.copy(sSource.getLength()-4, 4); if (sActUnTrans.getToken(PoEntry::GROUPID,'\t')== sActUnTrans.getToken(PoEntry::LOCALID,'\t') && - sActUnTrans.getToken(PoEntry::SOURCEFILE,'\t'). - endsWith(".xrm")) + ( sEnding == ".xrm" || sEnding == ".xml" )) { sActUnTrans = DelLocalId(sActUnTrans); - }*/ + } PoEntry aPE(sActUnTrans, vTypes[nIndex]); const OString sActStr = sActTrans.getToken(vTypes[nIndex],'\t'); -- cgit From 63af8783bcb418e72e59f5faf3a070701b828845 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 9 Oct 2012 22:05:24 +0200 Subject: Use static, lcl_ and anonymus namespace for local functions Change-Id: I0393c9552ca353e80ac61d258a280cbcd53e1cba --- l10ntools/source/po.cxx | 427 ++++++++++++++++++++++------------------- l10ntools/source/propmerge.cxx | 8 +- 2 files changed, 229 insertions(+), 206 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 465e18e3ab6d..eaf83a933769 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -29,85 +29,91 @@ //Class GenPoEntry -//Generate KeyId -OString ImplGenKeyId(const OString& rGenerator) -{ - boost::crc_32_type aCRC32; - aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); - sal_uInt32 nCRC = aCRC32.checksum(); - //Use all readable ASCII charachter exclude xml special tags: ",',&,<,> - const OString sSymbols = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - char sKeyId[5]; - for( short nKeyInd = 0; nKeyInd < 4; ++nKeyInd ) +namespace +{ + //Generate KeyId + static OString lcl_GenKeyId(const OString& rGenerator) { - sKeyId[nKeyInd] = sSymbols[(nCRC & 255) % 89]; - nCRC >>= 8; + boost::crc_32_type aCRC32; + aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); + sal_uInt32 nCRC = aCRC32.checksum(); + //Use all readable ASCII charachter exclude xml special tags: ",',&,<,> + const OString sSymbols = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + char sKeyId[5]; + for( short nKeyInd = 0; nKeyInd < 4; ++nKeyInd ) + { + sKeyId[nKeyInd] = sSymbols[(nCRC & 255) % 89]; + nCRC >>= 8; + } + sKeyId[4] = '\0'; + return OString(sKeyId); } - sKeyId[4] = '\0'; - return OString(sKeyId); -} -//Escape text -OString ImplEscapeText(const OString& rText, - const OString& rUnEscaped= POUNESCAPED, - const OString& rEscaped = POESCAPED) -{ - assert( rEscaped.getLength() == 2*rUnEscaped.getLength() ); - OString sResult = rText; - int nCount = 0; - for(sal_Int32 nIndex=0; nIndex& o_vParts) +namespace { - o_vParts.resize( 0 ); - sal_Int32 nActIndex = 0; - sal_Int32 nLastSplit = 0; - while( nActIndex < rSource.getLength() ) + //Split string at the delimiter char + static void lcl_SplitAt(const OString& rSource, const sal_Char nDelimiter, + std::vector& o_vParts) { - if ( rSource[nActIndex] == nDelimiter ) + o_vParts.resize( 0 ); + sal_Int32 nActIndex = 0; + sal_Int32 nLastSplit = 0; + while( nActIndex < rSource.getLength() ) { - o_vParts.push_back(rSource.copy(nLastSplit,nActIndex-nLastSplit)); - nLastSplit = nActIndex+1; + if ( rSource[nActIndex] == nDelimiter ) + { + o_vParts.push_back( + rSource.copy(nLastSplit,nActIndex-nLastSplit)); + nLastSplit = nActIndex+1; + } + ++nActIndex; } - ++nActIndex; + o_vParts.push_back(rSource.copy(nLastSplit)); } - o_vParts.push_back(rSource.copy(nLastSplit)); -} -//Unescape sdf string -OString ImplUnEscapeSDFText(const OString& rText,const bool bHelpText = false) -{ - if ( bHelpText ) - return ImplUnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); - else - return ImplUnEscapeText(rText,"\\n\\t\\r","\n\t\r"); -} + //Unescape sdf string + static OString lcl_UnEscapeSDFText( + const OString& rText,const bool bHelpText = false ) + { + if ( bHelpText ) + return lcl_UnEscapeText(rText,"\\<\\>\\\"\\\\","<>\"\\"); + else + return lcl_UnEscapeText(rText,"\\n\\t\\r","\n\t\r"); + } -//Miminize the length of the regular expression result -void ImplMinimize(const OUString& rText, Regexpr& io_rRegExp, re_registers& io_rRegs) -{ - re_registers aPrevRegs; - const sal_Int32 nStart = io_rRegs.start[0]; - do + //Miminize the length of the regular expression result + static void lcl_Minimize( + const OUString& rText, Regexpr& io_rRegExp, re_registers& io_rRegs ) { - const OUString sTemp = rText.copy(0,io_rRegs.end[0]-1); - memcpy(static_cast(&aPrevRegs), static_cast(&io_rRegs), + re_registers aPrevRegs; + const sal_Int32 nStart = io_rRegs.start[0]; + do + { + const OUString sTemp = rText.copy(0,io_rRegs.end[0]-1); + memcpy( + static_cast(&aPrevRegs), + static_cast(&io_rRegs), + sizeof(re_registers)); + memset(static_cast(&io_rRegs), 0, sizeof(re_registers)); + io_rRegExp.set_line(sTemp.getStr(),sTemp.getLength()); + io_rRegExp.re_search(&io_rRegs,nStart); + } while(io_rRegs.num_of_match); + + memcpy(static_cast(&io_rRegs),static_cast(&aPrevRegs), sizeof(re_registers)); - memset(static_cast(&io_rRegs), 0, sizeof(re_registers)); - io_rRegExp.set_line(sTemp.getStr(),sTemp.getLength()); - io_rRegExp.re_search(&io_rRegs,nStart); - } while(io_rRegs.num_of_match); - - memcpy(static_cast(&io_rRegs),static_cast(&aPrevRegs), - sizeof(re_registers)); - io_rRegExp.set_line(rText.getStr(),rText.getLength()); -} - -//Find all special tag in a string using a regular expression -void ImplFindAllTag(const OString& rText,std::vector& o_vFoundTags) -{ - ::com::sun::star::util::SearchOptions aOptions; - aOptions.algorithmType = ::com::sun::star::util::SearchAlgorithms_REGEXP; - aOptions.searchFlag = ::com::sun::star::util::SearchFlags::NORM_WORD_ONLY; - aOptions.searchString = "<[/]?[a-z_\\-]+(| +[a-z]+=\".*\") *[/]?>"; - ::com::sun::star::uno::Reference< - ::com::sun::star::i18n::XExtendedTransliteration > xTrans; - - Regexpr aRegExp(aOptions,xTrans); - const OUString sTemp(OStringToOUString(rText,RTL_TEXTENCODING_UTF8)); - aRegExp.set_line(sTemp.getStr(),sTemp.getLength()); - - re_registers aRegs; - memset(static_cast(&aRegs), 0, sizeof(re_registers)); - sal_Int32 nStart = 0; - o_vFoundTags.resize(0); - aRegExp.re_search(&aRegs,nStart); - while(aRegs.num_of_match) + io_rRegExp.set_line(rText.getStr(),rText.getLength()); + } + + //Find all special tag in a string using a regular expression + static void lcl_FindAllTag( + const OString& rText,std::vector& o_vFoundTags ) { - ImplMinimize(sTemp,aRegExp,aRegs); - o_vFoundTags.push_back( - OUStringToOString( - sTemp.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0]), - RTL_TEXTENCODING_UTF8)); - nStart = aRegs.end[0]; + ::com::sun::star::util::SearchOptions aOptions; + aOptions.algorithmType = + ::com::sun::star::util::SearchAlgorithms_REGEXP; + aOptions.searchFlag = + ::com::sun::star::util::SearchFlags::NORM_WORD_ONLY; + aOptions.searchString = "<[/]?[a-z_\\-]+(| +[a-z]+=\".*\") *[/]?>"; + ::com::sun::star::uno::Reference< + ::com::sun::star::i18n::XExtendedTransliteration > xTrans; + + Regexpr aRegExp(aOptions,xTrans); + const OUString sTemp(OStringToOUString(rText,RTL_TEXTENCODING_UTF8)); + aRegExp.set_line(sTemp.getStr(),sTemp.getLength()); + + re_registers aRegs; memset(static_cast(&aRegs), 0, sizeof(re_registers)); + sal_Int32 nStart = 0; + o_vFoundTags.resize(0); aRegExp.re_search(&aRegs,nStart); + while(aRegs.num_of_match) + { + lcl_Minimize(sTemp,aRegExp,aRegs); + o_vFoundTags.push_back( + OUStringToOString( + sTemp.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0]), + RTL_TEXTENCODING_UTF8)); + nStart = aRegs.end[0]; + memset(static_cast(&aRegs), 0, sizeof(re_registers)); + aRegExp.re_search(&aRegs,nStart); + } } -} -//Escape special tags -OString ImplEscapeTags(const OString& rText) -{ - typedef std::vector StrVec; - const OString vInitializer[] = { - "ahelp", "link", "item", "emph", "defaultinline", - "switchinline", "caseinline", "variable", - "bookmark_value", "image", "embedvar", "alt" }; - const StrVec vTagsForEscape( vInitializer, - vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); - StrVec vFoundTags; - ImplFindAllTag(rText,vFoundTags); - OString sResult = rText; - for(StrVec::const_iterator pFound = vFoundTags.begin(); - pFound != vFoundTags.end(); ++pFound) + //Escape special tags + static OString lcl_EscapeTags( const OString& rText ) { - bool bEscapeThis = false; - for(StrVec::const_iterator pEscape = vTagsForEscape.begin(); - pEscape != vTagsForEscape.end(); ++pEscape) + typedef std::vector StrVec; + const OString vInitializer[] = { + "ahelp", "link", "item", "emph", "defaultinline", + "switchinline", "caseinline", "variable", + "bookmark_value", "image", "embedvar", "alt" }; + const StrVec vTagsForEscape( vInitializer, + vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); + StrVec vFoundTags; + lcl_FindAllTag(rText,vFoundTags); + OString sResult = rText; + for(StrVec::const_iterator pFound = vFoundTags.begin(); + pFound != vFoundTags.end(); ++pFound) { - if (pFound->startsWith("<" + *pEscape) || - *pFound == "") + bool bEscapeThis = false; + for(StrVec::const_iterator pEscape = vTagsForEscape.begin(); + pEscape != vTagsForEscape.end(); ++pEscape) { - bEscapeThis = true; - break; + if (pFound->startsWith("<" + *pEscape) || + *pFound == "") + { + bEscapeThis = true; + break; + } + } + if( bEscapeThis || *pFound=="
" || + *pFound =="") + { + OString sToReplace = "\\<" + + pFound->copy(1,pFound->getLength()-2). + replaceAll("\"","\\\"") + "\\>"; + sResult = sResult.replaceAll(*pFound, sToReplace); } } - if (bEscapeThis || *pFound=="
" || *pFound =="") - { - OString sToReplace = "\\<" + pFound->copy(1,pFound->getLength()-2). - replaceAll("\"","\\\"") + "\\>"; - sResult = sResult.replaceAll(*pFound, sToReplace); - } + return sResult; } - return sResult; -} -//Escape to get sdf/merge string -OString ImplEscapeSDFText(const OString& rText,const bool bHelpText = false) -{ - if ( bHelpText ) - return ImplEscapeTags(rText.replaceAll("\\","\\\\")); - else - return ImplEscapeText(rText,"\n\t\r","\\n\\t\\r"); + //Escape to get sdf/merge string + static OString lcl_EscapeSDFText( + const OString& rText,const bool bHelpText = false ) + { + if ( bHelpText ) + return lcl_EscapeTags(rText.replaceAll("\\","\\\\")); + else + return lcl_EscapeText(rText,"\n\t\r","\\n\\t\\r"); + } } - //Default constructor PoEntry::PoEntry() : m_aGenPo( GenPoEntry() ) @@ -393,7 +412,7 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) , m_bIsInitialized( false ) { std::vector vParts; - ImplSplitAt(rSDFLine,'\t',vParts); + lcl_SplitAt(rSDFLine,'\t',vParts); if( vParts.size()!=15 || vParts[SOURCEFILE].isEmpty() || vParts[GROUPID].isEmpty() || @@ -424,7 +443,7 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) } m_aGenPo.setContext(sContext); m_aGenPo.setUnTransStr( - ImplUnEscapeSDFText( + lcl_UnEscapeSDFText( vParts[eType],vParts[SOURCEFILE].endsWith(".xhp"))); m_aGenPo.genKeyId(); m_bIsInitialized = true; @@ -506,7 +525,7 @@ OString PoEntry::getUnTransStr() const { assert( m_bIsInitialized ); return - ImplEscapeSDFText( + lcl_EscapeSDFText( m_aGenPo.getUnTransStr(), getSourceFile().endsWith(".xhp") ); } @@ -515,7 +534,7 @@ OString PoEntry::getTransStr() const { assert( m_bIsInitialized ); return - ImplEscapeSDFText( + lcl_EscapeSDFText( m_aGenPo.getTransStr(), getSourceFile().endsWith(".xhp") ); } @@ -524,7 +543,7 @@ OString PoEntry::getTransStr() const void PoEntry::setTransStr(const OString& rTransStr) { m_aGenPo.setTransStr( - ImplUnEscapeSDFText( + lcl_UnEscapeSDFText( rTransStr,getSourceFile().endsWith(".xhp"))); } @@ -546,23 +565,27 @@ bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2) //Class PoHeader -//Get actual time in "YEAR-MO-DA HO:MI+ZONE" form -OString ImplGetTime() +namespace { - time_t aNow = time(NULL); - struct tm* pNow = localtime(&aNow); - char pBuff[50]; - strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); - return pBuff; -} + //Get actual time in "YEAR-MO-DA HO:MI+ZONE" form + static OString lcl_GetTime() + { + time_t aNow = time(NULL); + struct tm* pNow = localtime(&aNow); + char pBuff[50]; + strftime( pBuff, sizeof pBuff, "%Y-%m-%d %H:%M%z", pNow ); + return pBuff; + } -OString ImplReplaceAttribute( - const OString& rSource, const OString& rOld, const OString& rNew ) -{ - const sal_Int32 nFirstIndex = rSource.indexOf( rOld ) + rOld.getLength()+2; - const sal_Int32 nCount = - rSource.indexOf( "\n", nFirstIndex ) - nFirstIndex; - return rSource.replaceFirst( rSource.copy(nFirstIndex, nCount), rNew ); + static OString lcl_ReplaceAttribute( + const OString& rSource, const OString& rOld, const OString& rNew ) + { + const sal_Int32 nFirstIndex = + rSource.indexOf( rOld ) + rOld.getLength()+2; + const sal_Int32 nCount = + rSource.indexOf( "\n", nFirstIndex ) - nFirstIndex; + return rSource.replaceFirst( rSource.copy(nFirstIndex, nCount), rNew ); + } } //Default Constructor @@ -582,7 +605,7 @@ PoHeader::PoHeader( const OString& rExtSrc ) OString("Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.freedesktop.org/enter_bug.cgi?" "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" - "POT-Creation-Date: ") + ImplGetTime() + + "POT-Creation-Date: ") + lcl_GetTime() + OString("\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -610,13 +633,13 @@ PoHeader::PoHeader( std::ifstream& rOldPo ) OString sTransStr = m_aGenPo.getTransStr(); sTransStr = - ImplReplaceAttribute( sTransStr, "Report-Msgid-Bugs-To", + lcl_ReplaceAttribute( sTransStr, "Report-Msgid-Bugs-To", "https://bugs.freedesktop.org/enter_bug.cgi?product=" "LibreOffice&bug_status=UNCONFIRMED&component=UI" ); sTransStr = - ImplReplaceAttribute( sTransStr, "X-Generator", "LibreOffice" ); + lcl_ReplaceAttribute( sTransStr, "X-Generator", "LibreOffice" ); sTransStr = - ImplReplaceAttribute( sTransStr, "X-Accelerator-Marker", "~" ); + lcl_ReplaceAttribute( sTransStr, "X-Accelerator-Marker", "~" ); m_aGenPo.setTransStr( sTransStr ); m_bIsInitialized = true; } diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 08261684671b..0f1b20b6f1fe 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -20,7 +20,7 @@ namespace { //Write out an sdf line - void lcl_WriteSDF( + static void lcl_WriteSDF( std::ofstream &aSDFStream, const OString& rText, const OString& rPrj, const OString& rActFileName, const OString& rID ) { @@ -33,7 +33,7 @@ namespace } //Find ascii escaped unicode - sal_Int32 lcl_IndexOfUnicode( + static sal_Int32 lcl_IndexOfUnicode( const OString& rSource, const sal_Int32 nFrom = 0 ) { const OString sHexDigits = "0123456789abcdefABCDEF"; @@ -54,7 +54,7 @@ namespace } //Convert ascii escaped unicode to utf-8 - OString lcl_ConvertToUTF8( const OString& rText ) + static OString lcl_ConvertToUTF8( const OString& rText ) { OString sResult = rText; sal_Int32 nIndex = lcl_IndexOfUnicode( sResult ); @@ -72,7 +72,7 @@ namespace } //Escape unicode characters - void lcl_PrintJavaStyle( const OString& rText, std::ofstream &rOfstream ) + static void lcl_PrintJavaStyle( const OString& rText, std::ofstream &rOfstream ) { const OUString sTemp = OStringToOUString( rText, RTL_TEXTENCODING_UTF8 ); -- cgit From 1ef83f535f638ddfa7f2ad0533f88c37e7bcbeef Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 9 Oct 2012 22:31:23 +0200 Subject: Use _t suffix for typedef Change-Id: I8501739e9fb1b184facebc406ed6e20de1f7ab0a --- l10ntools/source/po.cxx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index eaf83a933769..0a5ae28037ff 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -352,21 +352,21 @@ namespace //Escape special tags static OString lcl_EscapeTags( const OString& rText ) { - typedef std::vector StrVec; + typedef std::vector StrVec_t; const OString vInitializer[] = { "ahelp", "link", "item", "emph", "defaultinline", "switchinline", "caseinline", "variable", "bookmark_value", "image", "embedvar", "alt" }; - const StrVec vTagsForEscape( vInitializer, + const StrVec_t vTagsForEscape( vInitializer, vInitializer + sizeof(vInitializer) / sizeof(vInitializer[0]) ); - StrVec vFoundTags; + StrVec_t vFoundTags; lcl_FindAllTag(rText,vFoundTags); OString sResult = rText; - for(StrVec::const_iterator pFound = vFoundTags.begin(); + for(StrVec_t::const_iterator pFound = vFoundTags.begin(); pFound != vFoundTags.end(); ++pFound) { bool bEscapeThis = false; - for(StrVec::const_iterator pEscape = vTagsForEscape.begin(); + for(StrVec_t::const_iterator pEscape = vTagsForEscape.begin(); pEscape != vTagsForEscape.end(); ++pEscape) { if (pFound->startsWith("<" + *pEscape) || -- cgit From 9ebb37f39bb85b1b900916c54ffd4e82f79186a0 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 10 Oct 2012 14:21:58 +0200 Subject: Relocate KeyId to PoEntry KeyId is PoEntry specific attribute rather than part of GenPoEntry. In GenPoEntry it is just part of extracted comment. Four character long helptext/x-comment can lead to incorrect behaviour during file reading. With checking it in sdf-po constructor we can prevent this kind of po comming into existence. Change-Id: I48cc8f34d2c1ca8b86baea25384f5b697f16dd66 --- l10ntools/inc/po.hxx | 3 -- l10ntools/source/po.cxx | 92 ++++++++++++++++++++++++++++--------------------- 2 files changed, 53 insertions(+), 42 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 9163e6a10230..d1112e1730d8 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -29,7 +29,6 @@ private: OString m_sTransStr; bool m_bFuzzy; bool m_bNull; - OString m_sKeyId; public: @@ -45,7 +44,6 @@ public: virtual OString getTransStr() const { return m_sTransStr; } virtual bool getFuzzy() const { return m_bFuzzy; } virtual bool isNull() const { return m_bNull; } - virtual OString getKeyId() const { return m_sKeyId; } virtual void setWhiteSpace(const OString& rWhiteSpace); virtual void setExtractCom(const OString& rExtractCom); @@ -54,7 +52,6 @@ public: virtual void setUnTransStr(const OString& rUnTransStr); virtual void setTransStr(const OString& rTransStr); virtual void setFuzzy(const bool bFuzzy); - virtual void genKeyId(); virtual void writeToFile(std::ofstream& rOFStream) const; virtual void readFromFile(std::ifstream& rIFStream); diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 0a5ae28037ff..0416ad0aa185 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -31,24 +31,6 @@ namespace { - //Generate KeyId - static OString lcl_GenKeyId(const OString& rGenerator) - { - boost::crc_32_type aCRC32; - aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); - sal_uInt32 nCRC = aCRC32.checksum(); - //Use all readable ASCII charachter exclude xml special tags: ",',&,<,> - const OString sSymbols = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - char sKeyId[5]; - for( short nKeyInd = 0; nKeyInd < 4; ++nKeyInd ) - { - sKeyId[nKeyInd] = sSymbols[(nCRC & 255) % 89]; - nCRC >>= 8; - } - sKeyId[4] = '\0'; - return OString(sKeyId); - } - //Escape text static OString lcl_EscapeText(const OString& rText, const OString& rUnEscaped= POUNESCAPED, @@ -126,7 +108,6 @@ GenPoEntry::GenPoEntry() , m_sTransStr( OString() ) , m_bFuzzy( false ) , m_bNull( false ) - , m_sKeyId( OString() ) { } @@ -171,21 +152,15 @@ void GenPoEntry::setFuzzy(const bool bFuzzy) m_bFuzzy = bFuzzy; } -//Set keyid -void GenPoEntry::genKeyId() -{ - m_sKeyId = lcl_GenKeyId( m_sReference + m_sContext + m_sUnTransStr ); -} - //Write to file void GenPoEntry::writeToFile(std::ofstream& rOFStream) const { if ( !m_sWhiteSpace.isEmpty() ) rOFStream << m_sWhiteSpace.getStr(); if ( !m_sExtractCom.isEmpty() ) - rOFStream << "#. " << m_sExtractCom.getStr() << std::endl; - if ( !m_sKeyId.isEmpty() ) - rOFStream << "#. " << m_sKeyId.getStr() << std::endl; + rOFStream + << "#. " + << m_sExtractCom.replaceAll("\n","\n#. ").getStr() << std::endl; if ( !m_sReference.isEmpty() ) rOFStream << "#: " << m_sReference.getStr() << std::endl; if ( m_bFuzzy ) @@ -217,10 +192,11 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) OString sLine = OString(sTemp.data(),sTemp.length()); if (sLine.startsWith("#. ")) { - if (sLine.getLength()==7) - m_sKeyId = sLine.copy(3); - else - m_sExtractCom = sLine.copy(3); + if( !m_sExtractCom.isEmpty() ) + { + m_sExtractCom += "\n"; + } + m_sExtractCom += sLine.copy(3); } else if (sLine.startsWith("#: ")) { @@ -253,14 +229,30 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) break; getline(rIFStream,sTemp); } - if( m_sKeyId.isEmpty() && !m_sUnTransStr.isEmpty() ) - genKeyId(); } //Class PoEntry namespace { + //Generate KeyId + static OString lcl_GenKeyId(const OString& rGenerator) + { + boost::crc_32_type aCRC32; + aCRC32.process_bytes(rGenerator.getStr(), rGenerator.getLength()); + sal_uInt32 nCRC = aCRC32.checksum(); + //Use all readable ASCII charachter exclude xml special tags: ",',&,<,> + const OString sSymbols = "!#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + char sKeyId[5]; + for( short nKeyInd = 0; nKeyInd < 4; ++nKeyInd ) + { + sKeyId[nKeyInd] = sSymbols[(nCRC & 255) % 89]; + nCRC >>= 8; + } + sKeyId[4] = '\0'; + return OString(sKeyId); + } + //Split string at the delimiter char static void lcl_SplitAt(const OString& rSource, const sal_Char nDelimiter, std::vector& o_vParts) @@ -417,7 +409,8 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) vParts[SOURCEFILE].isEmpty() || vParts[GROUPID].isEmpty() || vParts[RESOURCETYPE].isEmpty() || - vParts[eType].isEmpty() ) + vParts[eType].isEmpty() || + vParts[HELPTEXT].getLength() == 4 ) { throw INVALIDSDFLINE; } @@ -426,7 +419,6 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) m_aGenPo.setReference(vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); - m_aGenPo.setExtractCom(vParts[HELPTEXT]); OString sContext = vParts[GROUPID] + "\n" + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + @@ -441,11 +433,14 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) /*Default case is unneeded because the type of eType has only three element*/ } + m_aGenPo.setExtractCom( + ( !vParts[HELPTEXT].isEmpty() ? vParts[HELPTEXT] + "\n" : "" ) + + lcl_GenKeyId( + vParts[SOURCEFILE] + sContext + vParts[eType] ) ); m_aGenPo.setContext(sContext); m_aGenPo.setUnTransStr( lcl_UnEscapeSDFText( vParts[eType],vParts[SOURCEFILE].endsWith(".xhp"))); - m_aGenPo.genKeyId(); m_bIsInitialized = true; } @@ -516,7 +511,15 @@ bool PoEntry::getFuzzy() const OString PoEntry::getKeyId() const { assert( m_bIsInitialized ); - return m_aGenPo.getKeyId(); + const OString sExtractCom = m_aGenPo.getExtractCom(); + if( sExtractCom.indexOf("\n") == -1 ) + { + return sExtractCom; + } + else + { + return sExtractCom.getToken(1,'\n'); + } } @@ -778,10 +781,21 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) (nLastEndLine == nFirstEndLine || nLastEndLine == sContext.indexOf('\n',nFirstEndLine+1)) && nLastDot - nLastEndLine > 1 && - (sType == "text" || sType == "quickhelptext" || sType == "title") && + (sType == "text" || sType == "quickhelptext" || sType == "title")&& !aGenPo.getUnTransStr().isEmpty() ) { rPoEntry.m_aGenPo = aGenPo; + const OString sExtractCom = aGenPo.getExtractCom(); + if( sExtractCom.isEmpty() || + ( sExtractCom.getLength() != 4 && + sExtractCom.indexOf("\n") == -1 ) ) + { + aGenPo.setExtractCom( + ( !sExtractCom.isEmpty() ? sExtractCom + "\n" : "" ) + + lcl_GenKeyId( + aGenPo.getReference() + sContext + + aGenPo.getUnTransStr() ) ); + } rPoEntry.m_bIsInitialized = true; } else -- cgit From a76c979c1771566e806db67e44f387bb68b862cc Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 10 Oct 2012 15:08:46 +0200 Subject: Delete WhiteSpace member of GenPoEntry This member allows us to use more kind of whitespace between po entries but we use one end line everywhere so this variable is unneeded. Change-Id: I4e3c9040ca73580fd01484bb91325a9df04cb4e4 --- l10ntools/inc/po.hxx | 3 --- l10ntools/source/po.cxx | 15 +++------------ 2 files changed, 3 insertions(+), 15 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index d1112e1730d8..fa43b517b437 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -21,7 +21,6 @@ class GenPoEntry { private: - OString m_sWhiteSpace; OString m_sExtractCom; OString m_sReference; OString m_sContext; @@ -36,7 +35,6 @@ public: virtual ~GenPoEntry(); //Default copy constructor and copy operator work well - virtual OString getWhiteSpace() const { return m_sWhiteSpace; } virtual OString getExtractCom() const { return m_sExtractCom; } virtual OString getReference() const { return m_sReference; } virtual OString getContext() const { return m_sContext; } @@ -45,7 +43,6 @@ public: virtual bool getFuzzy() const { return m_bFuzzy; } virtual bool isNull() const { return m_bNull; } - virtual void setWhiteSpace(const OString& rWhiteSpace); virtual void setExtractCom(const OString& rExtractCom); virtual void setReference(const OString& rReference); virtual void setContext(const OString& rContext); diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 0416ad0aa185..e1c978de6f6f 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -100,8 +100,7 @@ namespace //Default constructor GenPoEntry::GenPoEntry() - : m_sWhiteSpace( OString() ) - , m_sExtractCom( OString() ) + : m_sExtractCom( OString() ) , m_sReference( OString() ) , m_sContext( OString() ) , m_sUnTransStr( OString() ) @@ -117,11 +116,6 @@ GenPoEntry::~GenPoEntry() } //Set class members -void GenPoEntry::setWhiteSpace(const OString& rWhiteSpace) -{ - m_sWhiteSpace = rWhiteSpace; -} - void GenPoEntry::setExtractCom(const OString& rExtractCom) { m_sExtractCom = rExtractCom; @@ -155,8 +149,8 @@ void GenPoEntry::setFuzzy(const bool bFuzzy) //Write to file void GenPoEntry::writeToFile(std::ofstream& rOFStream) const { - if ( !m_sWhiteSpace.isEmpty() ) - rOFStream << m_sWhiteSpace.getStr(); + if ( rOFStream.tellp() != 0 ) + rOFStream << std::endl; if ( !m_sExtractCom.isEmpty() ) rOFStream << "#. " @@ -183,7 +177,6 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_bNull = true; return; } - m_sWhiteSpace = "\n"; OString* pLastMsg = 0; std::string sTemp; getline(rIFStream,sTemp); @@ -414,7 +407,6 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) { throw INVALIDSDFLINE; } - m_aGenPo.setWhiteSpace("\n"); m_aGenPo.setReference(vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); @@ -629,7 +621,6 @@ PoHeader::PoHeader( std::ifstream& rOldPo ) assert( rOldPo.is_open() ); m_aGenPo.readFromFile( rOldPo ); - m_aGenPo.setWhiteSpace( OString() ); const OString sExtractCom = m_aGenPo.getExtractCom(); m_aGenPo.setExtractCom( sExtractCom.copy( 0, sExtractCom.getLength() - 3 ) ); -- cgit From 06175e8b19625cb5a43b1ae5ae63e419cee7e053 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 10 Oct 2012 15:30:40 +0200 Subject: Correct lngmerge not to work with eof Change-Id: Ibf80a31ea2c03ff2882e71a45acb71d9c9a16482 --- l10ntools/source/lngmerge.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index b0282f5fb4d7..efc6c81f6994 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -50,10 +50,10 @@ LngParser::LngParser(const rtl::OString &rLngFile, if (aStream.is_open()) { bool bFirstLine = true; + std::string s; + std::getline(aStream, s); while (!aStream.eof()) { - std::string s; - std::getline(aStream, s); rtl::OString sLine(s.data(), s.length()); if( bFirstLine ) @@ -64,6 +64,7 @@ LngParser::LngParser(const rtl::OString &rLngFile, } pLines->push_back( new rtl::OString(sLine) ); + std::getline(aStream, s); } } else -- cgit From 8a3ee4e765d4cf849ba0dae811789d633823573e Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 10 Oct 2012 18:37:17 +0200 Subject: Move GenPoEntry out of header GenPoEntry is part of implementation rather than an autonom class thus its place is in cxx file. Because of pointer members we have to override copy constructor and copy operator. In PoHeader class these methods are unneeded so make it non-copyable. The m_bIsinitialized member's meaning widen with that m_aGenPo points an object. So check it not just in getter but in setter methods too. Change-Id: I26ebb885c81d14820076e0d46625c60cc1cf7984 --- l10ntools/inc/po.hxx | 49 +++------------ l10ntools/source/po.cxx | 157 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 131 insertions(+), 75 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index fa43b517b437..2e371b476a62 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -16,49 +16,13 @@ class PoOfstream; class PoIfstream; - -class GenPoEntry -{ -private: - - OString m_sExtractCom; - OString m_sReference; - OString m_sContext; - OString m_sUnTransStr; - OString m_sTransStr; - bool m_bFuzzy; - bool m_bNull; - -public: - - GenPoEntry(); - virtual ~GenPoEntry(); - //Default copy constructor and copy operator work well - - virtual OString getExtractCom() const { return m_sExtractCom; } - virtual OString getReference() const { return m_sReference; } - virtual OString getContext() const { return m_sContext; } - virtual OString getUnTransStr() const { return m_sUnTransStr; } - virtual OString getTransStr() const { return m_sTransStr; } - virtual bool getFuzzy() const { return m_bFuzzy; } - virtual bool isNull() const { return m_bNull; } - - virtual void setExtractCom(const OString& rExtractCom); - virtual void setReference(const OString& rReference); - virtual void setContext(const OString& rContext); - virtual void setUnTransStr(const OString& rUnTransStr); - virtual void setTransStr(const OString& rTransStr); - virtual void setFuzzy(const bool bFuzzy); - - virtual void writeToFile(std::ofstream& rOFStream) const; - virtual void readFromFile(std::ifstream& rIFStream); -}; +class GenPoEntry; class PoEntry { private: - GenPoEntry m_aGenPo; + GenPoEntry* m_pGenPo; bool m_bIsInitialized; public: @@ -76,7 +40,9 @@ public: PoEntry(const OString& rSDFLine, const TYPE eType = TTEXT); ~PoEntry(); - //Default copy constructor and copy operator work well + + PoEntry( const PoEntry& rPo ); + PoEntry& operator=( const PoEntry& rPo ); OString getSourceFile() const; OString getGroupId() const; @@ -95,11 +61,11 @@ public: }; -class PoHeader +class PoHeader: private boost::noncopyable { private: - GenPoEntry m_aGenPo; + GenPoEntry* m_pGenPo; bool m_bIsInitialized; public: @@ -113,7 +79,6 @@ public: PoHeader( const OString& rExtSrc ); PoHeader( std::ifstream& rOldPo ); ~PoHeader(); - //Default copy constructor and copy operator work well OString getLanguage() const; }; diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index e1c978de6f6f..59e206b33bda 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -29,6 +29,43 @@ //Class GenPoEntry +class GenPoEntry +{ +private: + + OString m_sExtractCom; + OString m_sReference; + OString m_sContext; + OString m_sUnTransStr; + OString m_sTransStr; + bool m_bFuzzy; + bool m_bNull; + +public: + + GenPoEntry(); + virtual ~GenPoEntry(); + //Default copy constructor and copy operator work well + + virtual OString getExtractCom() const { return m_sExtractCom; } + virtual OString getReference() const { return m_sReference; } + virtual OString getContext() const { return m_sContext; } + virtual OString getUnTransStr() const { return m_sUnTransStr; } + virtual OString getTransStr() const { return m_sTransStr; } + virtual bool getFuzzy() const { return m_bFuzzy; } + virtual bool isNull() const { return m_bNull; } + + virtual void setExtractCom(const OString& rExtractCom); + virtual void setReference(const OString& rReference); + virtual void setContext(const OString& rContext); + virtual void setUnTransStr(const OString& rUnTransStr); + virtual void setTransStr(const OString& rTransStr); + virtual void setFuzzy(const bool bFuzzy); + + virtual void writeToFile(std::ofstream& rOFStream) const; + virtual void readFromFile(std::ifstream& rIFStream); +}; + namespace { //Escape text @@ -386,14 +423,14 @@ namespace //Default constructor PoEntry::PoEntry() - : m_aGenPo( GenPoEntry() ) + : m_pGenPo( 0 ) , m_bIsInitialized( false ) { } //Construct PoEntry from sdfline PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) - : m_aGenPo( GenPoEntry() ) + : m_pGenPo( 0 ) , m_bIsInitialized( false ) { std::vector vParts; @@ -408,7 +445,8 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) throw INVALIDSDFLINE; } - m_aGenPo.setReference(vParts[SOURCEFILE]. + m_pGenPo = new GenPoEntry(); + m_pGenPo->setReference(vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); OString sContext = @@ -425,12 +463,12 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) /*Default case is unneeded because the type of eType has only three element*/ } - m_aGenPo.setExtractCom( + m_pGenPo->setExtractCom( ( !vParts[HELPTEXT].isEmpty() ? vParts[HELPTEXT] + "\n" : "" ) + lcl_GenKeyId( vParts[SOURCEFILE] + sContext + vParts[eType] ) ); - m_aGenPo.setContext(sContext); - m_aGenPo.setUnTransStr( + m_pGenPo->setContext(sContext); + m_pGenPo->setUnTransStr( lcl_UnEscapeSDFText( vParts[eType],vParts[SOURCEFILE].endsWith(".xhp"))); m_bIsInitialized = true; @@ -438,28 +476,63 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) //Destructor PoEntry::~PoEntry() +{ + delete m_pGenPo; +} + +//Copy constructor +PoEntry::PoEntry( const PoEntry& rPo ) + : m_pGenPo( rPo.m_pGenPo ? new GenPoEntry( *(rPo.m_pGenPo) ) : 0 ) + , m_bIsInitialized( rPo.m_bIsInitialized ) { } +//Copy operator +PoEntry& PoEntry::operator=(const PoEntry& rPo) +{ + if( this == &rPo ) + { + return *this; + } + if( rPo.m_pGenPo ) + { + if( m_pGenPo ) + { + *m_pGenPo = *(rPo.m_pGenPo); + } + else + { + m_pGenPo = new GenPoEntry( *(rPo.m_pGenPo) ); + } + } + else + { + delete m_pGenPo; + m_pGenPo = 0; + } + m_bIsInitialized = rPo.m_bIsInitialized; + return *this; +} + //Get name of file from which entry is extracted OString PoEntry::getSourceFile() const { assert( m_bIsInitialized ); - return m_aGenPo.getReference(); + return m_pGenPo->getReference(); } //Get groupid OString PoEntry::getGroupId() const { assert( m_bIsInitialized ); - return m_aGenPo.getContext().getToken(0,'\n'); + return m_pGenPo->getContext().getToken(0,'\n'); } //Get localid OString PoEntry::getLocalId() const { assert( m_bIsInitialized ); - const OString sContext = m_aGenPo.getContext(); + const OString sContext = m_pGenPo->getContext(); if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) return OString(); else @@ -470,7 +543,7 @@ OString PoEntry::getLocalId() const OString PoEntry::getResourceType() const { assert( m_bIsInitialized ); - const OString sContext = m_aGenPo.getContext(); + const OString sContext = m_pGenPo->getContext(); if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) return sContext.getToken(1,'\n').getToken(0,'.'); else @@ -480,9 +553,10 @@ OString PoEntry::getResourceType() const //Get the type of entry PoEntry::TYPE PoEntry::getType() const { - const OString sContext = m_aGenPo.getContext(); + assert( m_bIsInitialized ); + const OString sContext = m_pGenPo->getContext(); const OString sType = sContext.copy( sContext.lastIndexOf('.') + 1 ); - assert( m_bIsInitialized && + assert( (sType == "text" || sType == "quickhelptext" || sType == "title") ); if ( sType == "text" ) return TTEXT; @@ -496,14 +570,14 @@ PoEntry::TYPE PoEntry::getType() const bool PoEntry::getFuzzy() const { assert( m_bIsInitialized ); - return m_aGenPo.getFuzzy(); + return m_pGenPo->getFuzzy(); } //Get keyid OString PoEntry::getKeyId() const { assert( m_bIsInitialized ); - const OString sExtractCom = m_aGenPo.getExtractCom(); + const OString sExtractCom = m_pGenPo->getExtractCom(); if( sExtractCom.indexOf("\n") == -1 ) { return sExtractCom; @@ -521,7 +595,7 @@ OString PoEntry::getUnTransStr() const assert( m_bIsInitialized ); return lcl_EscapeSDFText( - m_aGenPo.getUnTransStr(), getSourceFile().endsWith(".xhp") ); + m_pGenPo->getUnTransStr(), getSourceFile().endsWith(".xhp") ); } //Get translated string in sdf/merge format @@ -530,14 +604,15 @@ OString PoEntry::getTransStr() const assert( m_bIsInitialized ); return lcl_EscapeSDFText( - m_aGenPo.getTransStr(), getSourceFile().endsWith(".xhp") ); + m_pGenPo->getTransStr(), getSourceFile().endsWith(".xhp") ); } //Set translated string when input is in sdf format void PoEntry::setTransStr(const OString& rTransStr) { - m_aGenPo.setTransStr( + assert( m_bIsInitialized ); + m_pGenPo->setTransStr( lcl_UnEscapeSDFText( rTransStr,getSourceFile().endsWith(".xhp"))); } @@ -545,7 +620,8 @@ void PoEntry::setTransStr(const OString& rTransStr) //Set fuzzy flag void PoEntry::setFuzzy(const bool bFuzzy) { - m_aGenPo.setFuzzy(bFuzzy); + assert( m_bIsInitialized ); + m_pGenPo->setFuzzy(bFuzzy); } //Check whether po-s belong to the same localization component @@ -585,18 +661,18 @@ namespace //Default Constructor PoHeader::PoHeader() - : m_aGenPo( GenPoEntry() ) + : m_pGenPo( 0 ) , m_bIsInitialized( false ) { } //Template Constructor PoHeader::PoHeader( const OString& rExtSrc ) - : m_aGenPo( GenPoEntry() ) + : m_pGenPo( new GenPoEntry() ) , m_bIsInitialized( false ) { - m_aGenPo.setExtractCom("extracted from " + rExtSrc); - m_aGenPo.setTransStr( + m_pGenPo->setExtractCom("extracted from " + rExtSrc); + m_pGenPo->setTransStr( OString("Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.freedesktop.org/enter_bug.cgi?" "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" @@ -615,17 +691,17 @@ PoHeader::PoHeader( const OString& rExtSrc ) //Constructor for old headers to renew po files PoHeader::PoHeader( std::ifstream& rOldPo ) - : m_aGenPo( GenPoEntry() ) + : m_pGenPo( new GenPoEntry() ) , m_bIsInitialized( false ) { assert( rOldPo.is_open() ); - m_aGenPo.readFromFile( rOldPo ); + m_pGenPo->readFromFile( rOldPo ); - const OString sExtractCom = m_aGenPo.getExtractCom(); - m_aGenPo.setExtractCom( + const OString sExtractCom = m_pGenPo->getExtractCom(); + m_pGenPo->setExtractCom( sExtractCom.copy( 0, sExtractCom.getLength() - 3 ) ); - OString sTransStr = m_aGenPo.getTransStr(); + OString sTransStr = m_pGenPo->getTransStr(); sTransStr = lcl_ReplaceAttribute( sTransStr, "Report-Msgid-Bugs-To", "https://bugs.freedesktop.org/enter_bug.cgi?product=" @@ -634,12 +710,13 @@ PoHeader::PoHeader( std::ifstream& rOldPo ) lcl_ReplaceAttribute( sTransStr, "X-Generator", "LibreOffice" ); sTransStr = lcl_ReplaceAttribute( sTransStr, "X-Accelerator-Marker", "~" ); - m_aGenPo.setTransStr( sTransStr ); + m_pGenPo->setTransStr( sTransStr ); m_bIsInitialized = true; } PoHeader::~PoHeader() { + delete m_pGenPo; } //Get the language of header @@ -647,7 +724,7 @@ OString PoHeader::getLanguage() const { assert( m_bIsInitialized ); const OString sLang = "Language: "; - const OString sTransStr = m_aGenPo.getTransStr(); + const OString sTransStr = m_pGenPo->getTransStr(); const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength(); const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex; if( nFirstIndex == sLang.getLength()-1 || nCount == -nFirstIndex-1 ) @@ -690,14 +767,14 @@ void PoOfstream::close() void PoOfstream::writeHeader(const PoHeader& rPoHeader) { assert( isOpen() && !m_bIsAfterHeader && rPoHeader.m_bIsInitialized ); - rPoHeader.m_aGenPo.writeToFile( m_aOutPut ); + rPoHeader.m_pGenPo->writeToFile( m_aOutPut ); m_bIsAfterHeader = true; } void PoOfstream::writeEntry( const PoEntry& rPoEntry ) { assert( isOpen() && m_bIsAfterHeader && rPoEntry.m_bIsInitialized ); - rPoEntry.m_aGenPo.writeToFile( m_aOutPut ); + rPoEntry.m_pGenPo->writeToFile( m_aOutPut ); } //Class PoIfstream @@ -740,7 +817,14 @@ void PoIfstream::readHeader( PoHeader& rPoHeader ) aGenPo.getUnTransStr().isEmpty() && !aGenPo.getTransStr().isEmpty() ) { - rPoHeader.m_aGenPo = aGenPo; + if( rPoHeader.m_pGenPo ) + { + *(rPoHeader.m_pGenPo) = aGenPo; + } + else + { + rPoHeader.m_pGenPo = new GenPoEntry( aGenPo ); + } rPoHeader.m_bIsInitialized = true; m_bIsAfterHeader = true; } @@ -775,7 +859,14 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) (sType == "text" || sType == "quickhelptext" || sType == "title")&& !aGenPo.getUnTransStr().isEmpty() ) { - rPoEntry.m_aGenPo = aGenPo; + if( rPoEntry.m_pGenPo ) + { + *(rPoEntry.m_pGenPo) = aGenPo; + } + else + { + rPoEntry.m_pGenPo = new GenPoEntry( aGenPo ); + } const OString sExtractCom = aGenPo.getExtractCom(); if( sExtractCom.isEmpty() || ( sExtractCom.getLength() != 4 && -- cgit From 471f2fc3196be0e52ac4ac1ea49f760accd9d4d7 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 11 Oct 2012 20:26:36 +0200 Subject: Use MsgCtxt, MsgId and MsgCtxt which are fit better to concept of po. Change-Id: I772e691465351b1492bdb756fc67e3a9de265c25 --- l10ntools/inc/po.hxx | 8 +-- l10ntools/source/merge.cxx | 10 +-- l10ntools/source/po.cxx | 152 +++++++++++++++++++++---------------------- l10ntools/source/renewpo.cxx | 2 +- 4 files changed, 86 insertions(+), 86 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 2e371b476a62..060bb1799a4f 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -49,12 +49,12 @@ public: OString getLocalId() const; OString getResourceType() const; TYPE getType() const; - OString getUnTransStr() const; - OString getTransStr() const; + OString getMsgId() const; + OString getMsgStr() const; bool getFuzzy() const; OString getKeyId() const; - void setUnTransStr(const OString& rUnTransStr); - void setTransStr(const OString& rTransStr); + void setMsgId(const OString& rUnTransStr); + void setMsgStr(const OString& rTransStr); void setFuzzy(const bool bFuzzy); static bool IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2); diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 23609e0d268e..b47d556ea9ef 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -231,24 +231,24 @@ MergeDataFile::MergeDataFile( { if( bInSameComp ) aActPo = aNextPo; - OString sTemp = aActPo.getTransStr(); + OString sTemp = aActPo.getMsgStr(); if( aActPo.getFuzzy() || sTemp.isEmpty() ) - sTemp = aActPo.getUnTransStr(); + sTemp = aActPo.getMsgId(); switch( aActPo.getType() ) { case PoEntry::TTEXT: sText = sTemp; - sExText = aActPo.getUnTransStr(); + sExText = aActPo.getMsgId(); sQTZText = aActPo.getKeyId(); break; case PoEntry::TQUICKHELPTEXT: sQHText = sTemp; - sExQHText = aActPo.getUnTransStr(); + sExQHText = aActPo.getMsgId(); sQTZQHText = aActPo.getKeyId(); break; case PoEntry::TTITLE: sTitle = sTemp; - sExTitle = aActPo.getUnTransStr(); + sExTitle = aActPo.getMsgId(); sQTZTitle = aActPo.getKeyId(); break; } diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 59e206b33bda..bddf19805e41 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -35,9 +35,9 @@ private: OString m_sExtractCom; OString m_sReference; - OString m_sContext; - OString m_sUnTransStr; - OString m_sTransStr; + OString m_sMsgCtxt; + OString m_sMsgId; + OString m_sMsgStr; bool m_bFuzzy; bool m_bNull; @@ -49,17 +49,17 @@ public: virtual OString getExtractCom() const { return m_sExtractCom; } virtual OString getReference() const { return m_sReference; } - virtual OString getContext() const { return m_sContext; } - virtual OString getUnTransStr() const { return m_sUnTransStr; } - virtual OString getTransStr() const { return m_sTransStr; } + virtual OString getMsgCtxt() const { return m_sMsgCtxt; } + virtual OString getMsgId() const { return m_sMsgId; } + virtual OString getMsgStr() const { return m_sMsgStr; } virtual bool getFuzzy() const { return m_bFuzzy; } virtual bool isNull() const { return m_bNull; } virtual void setExtractCom(const OString& rExtractCom); virtual void setReference(const OString& rReference); - virtual void setContext(const OString& rContext); - virtual void setUnTransStr(const OString& rUnTransStr); - virtual void setTransStr(const OString& rTransStr); + virtual void setMsgCtxt(const OString& rMsgCtxt); + virtual void setMsgId(const OString& rMsgId); + virtual void setMsgStr(const OString& rMsgStr); virtual void setFuzzy(const bool bFuzzy); virtual void writeToFile(std::ofstream& rOFStream) const; @@ -139,9 +139,9 @@ namespace GenPoEntry::GenPoEntry() : m_sExtractCom( OString() ) , m_sReference( OString() ) - , m_sContext( OString() ) - , m_sUnTransStr( OString() ) - , m_sTransStr( OString() ) + , m_sMsgCtxt( OString() ) + , m_sMsgId( OString() ) + , m_sMsgStr( OString() ) , m_bFuzzy( false ) , m_bNull( false ) { @@ -163,19 +163,19 @@ void GenPoEntry::setReference(const OString& rReference) m_sReference = rReference; } -void GenPoEntry::setContext(const OString& rContext) +void GenPoEntry::setMsgCtxt(const OString& rMsgCtxt) { - m_sContext = rContext; + m_sMsgCtxt = rMsgCtxt; } -void GenPoEntry::setUnTransStr(const OString& rUnTransStr) +void GenPoEntry::setMsgId(const OString& rMsgId) { - m_sUnTransStr = rUnTransStr; + m_sMsgId = rMsgId; } -void GenPoEntry::setTransStr(const OString& rTransStr) +void GenPoEntry::setMsgStr(const OString& rMsgStr) { - m_sTransStr = rTransStr; + m_sMsgStr = rMsgStr; } void GenPoEntry::setFuzzy(const bool bFuzzy) @@ -196,13 +196,13 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) const rOFStream << "#: " << m_sReference.getStr() << std::endl; if ( m_bFuzzy ) rOFStream << "#, fuzzy" << std::endl; - if ( !m_sContext.isEmpty() ) + if ( !m_sMsgCtxt.isEmpty() ) rOFStream << "msgctxt " - << lcl_GenMsgString(m_sContext).getStr() << std::endl; + << lcl_GenMsgString(m_sMsgCtxt).getStr() << std::endl; rOFStream << "msgid " - << lcl_GenMsgString(m_sUnTransStr).getStr() << std::endl; + << lcl_GenMsgString(m_sMsgId).getStr() << std::endl; rOFStream << "msgstr " - << lcl_GenMsgString(m_sTransStr).getStr() << std::endl; + << lcl_GenMsgString(m_sMsgStr).getStr() << std::endl; } //Read from file @@ -238,18 +238,18 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) } else if (sLine.startsWith("msgctxt ")) { - m_sContext = lcl_GenNormString(sLine.copy(8)); - pLastMsg = &m_sContext; + m_sMsgCtxt = lcl_GenNormString(sLine.copy(8)); + pLastMsg = &m_sMsgCtxt; } else if (sLine.startsWith("msgid ")) { - m_sUnTransStr = lcl_GenNormString(sLine.copy(6)); - pLastMsg = &m_sUnTransStr; + m_sMsgId = lcl_GenNormString(sLine.copy(6)); + pLastMsg = &m_sMsgId; } else if (sLine.startsWith("msgstr ")) { - m_sTransStr = lcl_GenNormString(sLine.copy(7)); - pLastMsg = &m_sTransStr; + m_sMsgStr = lcl_GenNormString(sLine.copy(7)); + pLastMsg = &m_sMsgStr; } else if (sLine.startsWith("\"") && pLastMsg) { @@ -449,26 +449,26 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) m_pGenPo->setReference(vParts[SOURCEFILE]. copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); - OString sContext = + OString sMsgCtxt = vParts[GROUPID] + "\n" + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + vParts[RESOURCETYPE]; switch(eType){ case TTEXT: - sContext += ".text"; break; + sMsgCtxt += ".text"; break; case TQUICKHELPTEXT: - sContext += ".quickhelptext"; break; + sMsgCtxt += ".quickhelptext"; break; case TTITLE: - sContext += ".title"; break; + sMsgCtxt += ".title"; break; /*Default case is unneeded because the type of eType has only three element*/ } m_pGenPo->setExtractCom( ( !vParts[HELPTEXT].isEmpty() ? vParts[HELPTEXT] + "\n" : "" ) + lcl_GenKeyId( - vParts[SOURCEFILE] + sContext + vParts[eType] ) ); - m_pGenPo->setContext(sContext); - m_pGenPo->setUnTransStr( + vParts[SOURCEFILE] + sMsgCtxt + vParts[eType] ) ); + m_pGenPo->setMsgCtxt(sMsgCtxt); + m_pGenPo->setMsgId( lcl_UnEscapeSDFText( vParts[eType],vParts[SOURCEFILE].endsWith(".xhp"))); m_bIsInitialized = true; @@ -525,37 +525,37 @@ OString PoEntry::getSourceFile() const OString PoEntry::getGroupId() const { assert( m_bIsInitialized ); - return m_pGenPo->getContext().getToken(0,'\n'); + return m_pGenPo->getMsgCtxt().getToken(0,'\n'); } //Get localid OString PoEntry::getLocalId() const { assert( m_bIsInitialized ); - const OString sContext = m_pGenPo->getContext(); - if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) + const OString sMsgCtxt = m_pGenPo->getMsgCtxt(); + if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) return OString(); else - return sContext.getToken(1,'\n'); + return sMsgCtxt.getToken(1,'\n'); } //Get the type of component from which entry is extracted OString PoEntry::getResourceType() const { assert( m_bIsInitialized ); - const OString sContext = m_pGenPo->getContext(); - if (sContext.indexOf('\n')==sContext.lastIndexOf('\n')) - return sContext.getToken(1,'\n').getToken(0,'.'); + const OString sMsgCtxt = m_pGenPo->getMsgCtxt(); + if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) + return sMsgCtxt.getToken(1,'\n').getToken(0,'.'); else - return sContext.getToken(2,'\n').getToken(0,'.'); + return sMsgCtxt.getToken(2,'\n').getToken(0,'.'); } //Get the type of entry PoEntry::TYPE PoEntry::getType() const { assert( m_bIsInitialized ); - const OString sContext = m_pGenPo->getContext(); - const OString sType = sContext.copy( sContext.lastIndexOf('.') + 1 ); + const OString sMsgCtxt = m_pGenPo->getMsgCtxt(); + const OString sType = sMsgCtxt.copy( sMsgCtxt.lastIndexOf('.') + 1 ); assert( (sType == "text" || sType == "quickhelptext" || sType == "title") ); if ( sType == "text" ) @@ -590,31 +590,31 @@ OString PoEntry::getKeyId() const //Get translation string in sdf/merge format -OString PoEntry::getUnTransStr() const +OString PoEntry::getMsgId() const { assert( m_bIsInitialized ); return lcl_EscapeSDFText( - m_pGenPo->getUnTransStr(), getSourceFile().endsWith(".xhp") ); + m_pGenPo->getMsgId(), getSourceFile().endsWith(".xhp") ); } //Get translated string in sdf/merge format -OString PoEntry::getTransStr() const +OString PoEntry::getMsgStr() const { assert( m_bIsInitialized ); return lcl_EscapeSDFText( - m_pGenPo->getTransStr(), getSourceFile().endsWith(".xhp") ); + m_pGenPo->getMsgStr(), getSourceFile().endsWith(".xhp") ); } //Set translated string when input is in sdf format -void PoEntry::setTransStr(const OString& rTransStr) +void PoEntry::setMsgStr(const OString& rMsgStr) { assert( m_bIsInitialized ); - m_pGenPo->setTransStr( + m_pGenPo->setMsgStr( lcl_UnEscapeSDFText( - rTransStr,getSourceFile().endsWith(".xhp"))); + rMsgStr,getSourceFile().endsWith(".xhp"))); } //Set fuzzy flag @@ -672,7 +672,7 @@ PoHeader::PoHeader( const OString& rExtSrc ) , m_bIsInitialized( false ) { m_pGenPo->setExtractCom("extracted from " + rExtSrc); - m_pGenPo->setTransStr( + m_pGenPo->setMsgStr( OString("Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugs.freedesktop.org/enter_bug.cgi?" "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n" @@ -701,16 +701,16 @@ PoHeader::PoHeader( std::ifstream& rOldPo ) m_pGenPo->setExtractCom( sExtractCom.copy( 0, sExtractCom.getLength() - 3 ) ); - OString sTransStr = m_pGenPo->getTransStr(); - sTransStr = - lcl_ReplaceAttribute( sTransStr, "Report-Msgid-Bugs-To", + OString sMsgStr = m_pGenPo->getMsgStr(); + sMsgStr = + lcl_ReplaceAttribute( sMsgStr, "Report-Msgid-Bugs-To", "https://bugs.freedesktop.org/enter_bug.cgi?product=" "LibreOffice&bug_status=UNCONFIRMED&component=UI" ); - sTransStr = - lcl_ReplaceAttribute( sTransStr, "X-Generator", "LibreOffice" ); - sTransStr = - lcl_ReplaceAttribute( sTransStr, "X-Accelerator-Marker", "~" ); - m_pGenPo->setTransStr( sTransStr ); + sMsgStr = + lcl_ReplaceAttribute( sMsgStr, "X-Generator", "LibreOffice" ); + sMsgStr = + lcl_ReplaceAttribute( sMsgStr, "X-Accelerator-Marker", "~" ); + m_pGenPo->setMsgStr( sMsgStr ); m_bIsInitialized = true; } @@ -724,14 +724,14 @@ OString PoHeader::getLanguage() const { assert( m_bIsInitialized ); const OString sLang = "Language: "; - const OString sTransStr = m_pGenPo->getTransStr(); - const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength(); - const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex; + const OString sMsgStr = m_pGenPo->getMsgStr(); + const sal_Int32 nFirstIndex = sMsgStr.indexOf(sLang)+sLang.getLength(); + const sal_Int32 nCount = sMsgStr.indexOf('\n',nFirstIndex)-nFirstIndex; if( nFirstIndex == sLang.getLength()-1 || nCount == -nFirstIndex-1 ) { throw NOLANG; } - return sTransStr.copy( nFirstIndex, nCount ); + return sMsgStr.copy( nFirstIndex, nCount ); } //Class PoOfstream @@ -814,8 +814,8 @@ void PoIfstream::readHeader( PoHeader& rPoHeader ) GenPoEntry aGenPo; aGenPo.readFromFile( m_aInPut ); if( !aGenPo.getExtractCom().isEmpty() && - aGenPo.getUnTransStr().isEmpty() && - !aGenPo.getTransStr().isEmpty() ) + aGenPo.getMsgId().isEmpty() && + !aGenPo.getMsgStr().isEmpty() ) { if( rPoHeader.m_pGenPo ) { @@ -846,18 +846,18 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) } else { - const OString sContext = aGenPo.getContext(); - const sal_Int32 nFirstEndLine = sContext.indexOf('\n'); - const sal_Int32 nLastEndLine = sContext.lastIndexOf('\n'); - const sal_Int32 nLastDot = sContext.lastIndexOf('.'); - const OString sType = sContext.copy( nLastDot + 1 ); + const OString sMsgCtxt = aGenPo.getMsgCtxt(); + const sal_Int32 nFirstEndLine = sMsgCtxt.indexOf('\n'); + const sal_Int32 nLastEndLine = sMsgCtxt.lastIndexOf('\n'); + const sal_Int32 nLastDot = sMsgCtxt.lastIndexOf('.'); + const OString sType = sMsgCtxt.copy( nLastDot + 1 ); if( !aGenPo.getReference().isEmpty() && nFirstEndLine > 0 && (nLastEndLine == nFirstEndLine || - nLastEndLine == sContext.indexOf('\n',nFirstEndLine+1)) && + nLastEndLine == sMsgCtxt.indexOf('\n',nFirstEndLine+1)) && nLastDot - nLastEndLine > 1 && (sType == "text" || sType == "quickhelptext" || sType == "title")&& - !aGenPo.getUnTransStr().isEmpty() ) + !aGenPo.getMsgId().isEmpty() ) { if( rPoEntry.m_pGenPo ) { @@ -875,8 +875,8 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) aGenPo.setExtractCom( ( !sExtractCom.isEmpty() ? sExtractCom + "\n" : "" ) + lcl_GenKeyId( - aGenPo.getReference() + sContext + - aGenPo.getUnTransStr() ) ); + aGenPo.getReference() + sMsgCtxt + + aGenPo.getMsgId() ) ); } rPoEntry.m_bIsInitialized = true; } diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 4a11c368a0e7..241db58b72cf 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -161,7 +161,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, PoEntry aPE(sActUnTrans, vTypes[nIndex]); const OString sActStr = sActTrans.getToken(vTypes[nIndex],'\t'); - aPE.setTransStr(sActStr); + aPE.setMsgStr(sActStr); aPE.setFuzzy( sActStr.isEmpty() ? false : static_cast(sActTrans.getToken(PoEntry::DUMMY,'\t'). copy(nDummyBit++,1).toBoolean())); -- cgit From c6b26144c93aa5222e4260c5b0ef45ce5bdc18d2 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 11 Oct 2012 20:50:19 +0200 Subject: Use isFuzzy() instead of getFuzzy() to make more obvious its aim Change-Id: Idc98ae8ce2218c9d387c4f2cb6e4d5603b56aab3 --- l10ntools/inc/po.hxx | 2 +- l10ntools/source/merge.cxx | 2 +- l10ntools/source/po.cxx | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx index 060bb1799a4f..856c7bb04ff1 100644 --- a/l10ntools/inc/po.hxx +++ b/l10ntools/inc/po.hxx @@ -51,7 +51,7 @@ public: TYPE getType() const; OString getMsgId() const; OString getMsgStr() const; - bool getFuzzy() const; + bool isFuzzy() const; OString getKeyId() const; void setMsgId(const OString& rUnTransStr); void setMsgStr(const OString& rTransStr); diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index b47d556ea9ef..80188f53fb87 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -232,7 +232,7 @@ MergeDataFile::MergeDataFile( if( bInSameComp ) aActPo = aNextPo; OString sTemp = aActPo.getMsgStr(); - if( aActPo.getFuzzy() || sTemp.isEmpty() ) + if( aActPo.isFuzzy() || sTemp.isEmpty() ) sTemp = aActPo.getMsgId(); switch( aActPo.getType() ) { diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index bddf19805e41..9dd6d6adab56 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -52,7 +52,7 @@ public: virtual OString getMsgCtxt() const { return m_sMsgCtxt; } virtual OString getMsgId() const { return m_sMsgId; } virtual OString getMsgStr() const { return m_sMsgStr; } - virtual bool getFuzzy() const { return m_bFuzzy; } + virtual bool isFuzzy() const { return m_bFuzzy; } virtual bool isNull() const { return m_bNull; } virtual void setExtractCom(const OString& rExtractCom); @@ -567,10 +567,10 @@ PoEntry::TYPE PoEntry::getType() const } //Check wheather entry is fuzzy -bool PoEntry::getFuzzy() const +bool PoEntry::isFuzzy() const { assert( m_bIsInitialized ); - return m_pGenPo->getFuzzy(); + return m_pGenPo->isFuzzy(); } //Get keyid -- cgit From 8f57a9d2a186a2cd5d71ed8bbed106ab927322d4 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 29 Oct 2012 11:52:54 +0100 Subject: Correct some naming in propex Change-Id: Id5b17be8155f13529439dd9a46b42f6ffeed79b1 --- l10ntools/inc/propmerge.hxx | 2 +- l10ntools/source/propmerge.cxx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/propmerge.hxx b/l10ntools/inc/propmerge.hxx index 3465635c602f..4f0e3275a434 100644 --- a/l10ntools/inc/propmerge.hxx +++ b/l10ntools/inc/propmerge.hxx @@ -30,7 +30,7 @@ public: 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 ); + void Merge( const OString &rMergeSrc, const OString &rDestinationFile ); }; #endif //_PROPMERGE_INCLUDED diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 0f1b20b6f1fe..61400147691f 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -168,7 +168,7 @@ void PropParser::Extract( } //Merge strings to source file -void PropParser::Merge( const OString &rSDFFile, const OString &rDestinationFile ) +void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFile ) { assert( m_bIsInitialized ); std::ofstream aDestination( @@ -180,14 +180,14 @@ void PropParser::Merge( const OString &rSDFFile, const OString &rDestinationFile return; } - MergeDataFile aMergeDataFile( rSDFFile, m_sSource, false ); + MergeDataFile aMergeDataFile( rMergeSrc, 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; + << m_sLang.getStr() << " - " << rMergeSrc.getStr() << std::endl; return; } -- cgit From 0c7f8e6d0c2a414150c5f77d3419479bb8eeddb0 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 29 Oct 2012 12:53:18 +0100 Subject: Delete some unneeded checking from export2.cxx Change-Id: Ib41c81629fbc5a8bd709391091c2777d49f9d9c4 --- l10ntools/source/export2.cxx | 4 ---- 1 file changed, 4 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 64a5b1b07e5c..5ef2231f6d6e 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -95,10 +95,6 @@ bool Export::handleArguments( int argc, char * argv[], HandledArgs& o_aHandledArgs) { o_aHandledArgs = HandledArgs(); - if ( argc <= 1 ) - { - return false; - } sLanguages = ""; sal_uInt16 nState = STATE_NON; -- cgit From 0fd7f81ec6765133bc2a964afd832631cd1bbf31 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 1 Nov 2012 13:39:43 +0100 Subject: Implement new treex executable Which localize and update help tree files instead of update_tree.pl. Use it to update extensions' help. Next step: use it with general help. Change-Id: Ife9696bdd8b973ef3cf30626533e38720408179b --- l10ntools/Executable_treex.mk | 36 +++++ l10ntools/Module_l10ntools.mk | 1 + l10ntools/inc/treemerge.hxx | 38 ++++++ l10ntools/source/localize.cxx | 3 +- l10ntools/source/treemerge.cxx | 304 +++++++++++++++++++++++++++++++++++++++++ l10ntools/source/treex.cxx | 60 ++++++++ 6 files changed, 441 insertions(+), 1 deletion(-) create mode 100644 l10ntools/Executable_treex.mk create mode 100644 l10ntools/inc/treemerge.hxx create mode 100644 l10ntools/source/treemerge.cxx create mode 100644 l10ntools/source/treex.cxx (limited to 'l10ntools') diff --git a/l10ntools/Executable_treex.mk b/l10ntools/Executable_treex.mk new file mode 100644 index 000000000000..41af0a8bfbc9 --- /dev/null +++ b/l10ntools/Executable_treex.mk @@ -0,0 +1,36 @@ +# -*- 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,treex)) + +$(eval $(call gb_Executable_set_include,treex,\ + -I$(SRCDIR)/l10ntools/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Executable_use_libraries,treex,\ + sal \ + i18nregexp \ +)) + +$(eval $(call gb_Executable_use_static_libraries,treex,\ + transex \ +)) + +$(eval $(call gb_Executable_add_exception_objects,treex,\ + l10ntools/source/treemerge \ + l10ntools/source/treex \ +)) + +$(eval $(call gb_Executable_use_externals,treex,\ + libxml2 \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/l10ntools/Module_l10ntools.mk b/l10ntools/Module_l10ntools.mk index e6c0cc3a8047..6efcd7f45596 100644 --- a/l10ntools/Module_l10ntools.mk +++ b/l10ntools/Module_l10ntools.mk @@ -39,6 +39,7 @@ $(eval $(call gb_Module_add_targets,l10ntools,\ Executable_transex3 \ Executable_renewpo \ Executable_propex \ + Executable_treex \ StaticLibrary_transex \ Package_inc \ Package_scripts \ diff --git a/l10ntools/inc/treemerge.hxx b/l10ntools/inc/treemerge.hxx new file mode 100644 index 000000000000..3b681126bfab --- /dev/null +++ b/l10ntools/inc/treemerge.hxx @@ -0,0 +1,38 @@ +/* -*- 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 _TREEMERGE_INCLUDED +#define _TREEMERGE_INCLUDED + +#include +#include +#include + +class TreeParser +{ +private: + xmlDocPtr m_pSource; + OString m_sLang; + bool m_bIsInitialized; + +public: + TreeParser( + const OString& rInputFile, const OString& rLang ); + ~TreeParser(); + + bool isInitialized() const { return m_bIsInitialized; } + void Extract( + const OString& rSDFFile, const OString& rPrj, const OString& rRoot ); + void Merge( + const OString &rMergeSrc, const OString &rDestinationFile, + const OString &rXhpRoot ); +}; + +#endif //_TREEMERGE_INCLUDED +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index fd1d8ca4b4d0..f808af59d6cd 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -324,7 +324,8 @@ void handleFile( { RTL_CONSTASCII_STRINGPARAM(".xml"), "xrmex", true }, { RTL_CONSTASCII_STRINGPARAM(".xhp"), "helpex", false }, { RTL_CONSTASCII_STRINGPARAM(".properties"), "propex", false }, - { RTL_CONSTASCII_STRINGPARAM(".ui"), "uiex", false } }; + { RTL_CONSTASCII_STRINGPARAM(".ui"), "uiex", false }, + { RTL_CONSTASCII_STRINGPARAM(".tree"), "treex", false } }; for (std::size_t i = 0; i != SAL_N_ELEMENTS(commands); ++i) { if (url.endsWithAsciiL( commands[i].extension, commands[i].extensionLength)) diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx new file mode 100644 index 000000000000..12e931c6d221 --- /dev/null +++ b/l10ntools/source/treemerge.cxx @@ -0,0 +1,304 @@ +/* -*- 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 +#include +#include +#include + +#include +#include +#include +#include + +#include "export.hxx" +#include "common.hxx" +#include "treemerge.hxx" + + +namespace +{ + //Write out an sdf line + static void lcl_WriteSDF( + std::ofstream &aSDFStream, const OString& rText, const OString& rPrj, + const OString& rActFileName, const OString& rID, const OString& rType ) + { + OString sOutput( rPrj ); sOutput += "\t"; + sOutput += rActFileName; + sOutput += "\t0\t"; + sOutput += rType; sOutput += "\t"; + sOutput += rID; sOutput += "\t\t\t\t0\ten-US\t"; + sOutput += rText; sOutput += "\t\t\t\t"; + aSDFStream << sOutput.getStr() << std::endl; + } + + //Convert xmlChar* to OString + static OString lcl_xmlStrToOString( const xmlChar* pString ) + { + xmlChar* pTemp = xmlStrdup( pString ); + OString sResult = + static_cast(reinterpret_cast( pTemp )); + xmlFree( pTemp ); + return sResult; + } + + //Extract strings from nodes on all level recursively + static void lcl_ExtractLevel( + const xmlDocPtr pSource, const xmlNodePtr pRoot, + const xmlChar* pNodeName, std::ofstream& rSDFStream, + const OString& rPrj, const OString& rRoot ) + { + if( !pRoot->children ) + { + return; + } + for( xmlNodePtr pCurrent = pRoot->children->next; + pCurrent; pCurrent = pCurrent->next) + { + if (!xmlStrcmp(pCurrent->name, pNodeName)) + { + xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("id")); + xmlChar* pText = + xmlGetProp(pCurrent, (const xmlChar*)("title")); + lcl_WriteSDF( + rSDFStream, + lcl_xmlStrToOString( pText ), + rPrj, + common::pathnameToken( + pSource->name, rRoot.getStr()), + lcl_xmlStrToOString( pID ), + lcl_xmlStrToOString( pNodeName )); + + xmlFree( pID ); + xmlFree( pText ); + + lcl_ExtractLevel( + pSource, pCurrent, (const xmlChar *)("node"), + rSDFStream, rPrj, rRoot ); + } + } + } + + //Update id and content of the topic + static xmlNodePtr lcl_UpdateTopic( + const xmlNodePtr pCurrent, const OString& rXhpRoot ) + { + xmlNodePtr pReturn = pCurrent; + xmlChar* pID = xmlGetProp(pReturn, (const xmlChar*)("id")); + const OString sID = + lcl_xmlStrToOString( pID ); + xmlFree( pID ); + + const sal_Int32 nFirstSlash = sID.indexOf("/"); + //Update id attribute of topic + { + OString sNewID = + sID.copy( 0, nFirstSlash + 1 ) + + rXhpRoot.copy( rXhpRoot.lastIndexOf("/") + 1 ) + + sID.copy( sID.indexOf( "/", nFirstSlash + 1 ) ); + xmlSetProp( + pReturn, (const xmlChar*)("id"), + reinterpret_cast(sNewID.getStr())); + } + + const OString sXhpPath = + rXhpRoot + + sID.copy(sID.indexOf("/", nFirstSlash + 1)); + xmlDocPtr pXhpFile = xmlParseFile( sXhpPath.getStr() ); + //if xhpfile is missing than we put this topic into comment + if ( !pXhpFile ) + { + xmlNodePtr pTemp = pReturn; + xmlChar* sNewID = + xmlGetProp(pReturn, (const xmlChar*)("id")); + xmlChar* sComment = + xmlStrcat( xmlCharStrdup("removed "), sNewID ); + pReturn = xmlNewComment( sComment ); + xmlReplaceNode( pTemp, pReturn ); + xmlFree( pTemp ); + xmlFree( sNewID ); + xmlFree( sComment ); + } + //update topic's content on the basis of xhpfile's title + else + { + xmlNodePtr pXhpNode = xmlDocGetRootElement( pXhpFile ); + for( pXhpNode = pXhpNode->children; + pXhpNode; pXhpNode = pXhpNode->children ) + { + while( pXhpNode->type != XML_ELEMENT_NODE ) + { + pXhpNode = pXhpNode->next; + } + if(!xmlStrcmp(pXhpNode->name, (const xmlChar *)("title"))) + { + xmlChar* sTitle = + xmlNodeListGetString(pXhpFile, pXhpNode->children, 1); + OString sNewTitle = + lcl_xmlStrToOString( sTitle ). + replaceAll("$[officename]","%PRODUCTNAME"). + replaceAll("$[officeversion]","%PRODUCTVERSION"); + xmlNodeSetContent( + pReturn, + reinterpret_cast( sNewTitle.getStr() )); + xmlFree( sTitle ); + break; + } + } + if( !pXhpNode ) + { + std::cerr + << "Treex error: Cannot find title in " + << sXhpPath.getStr() << std::endl; + return 0; + } + xmlFree( pXhpFile ); + xmlCleanupParser(); + } + return pReturn; + } + //Localize title attribute of help_section and node tags + static void lcl_MergeLevel( + xmlDocPtr io_pSource, const xmlNodePtr pRoot, + const xmlChar * pNodeName, MergeDataFile* pMergeDataFile, + const OString& rLang, const OString& rXhpRoot ) + { + if( !pRoot->children ) + { + return; + } + for( xmlNodePtr pCurrent = pRoot->children; + pCurrent; pCurrent = pCurrent->next) + { + if( !xmlStrcmp(pCurrent->name, pNodeName) ) + { + if( pMergeDataFile ) + { + xmlChar* pID = xmlGetProp(pCurrent, (const xmlChar*)("id")); + ResData aResData( + "", lcl_xmlStrToOString( pID ), + static_cast(io_pSource->name) ); + xmlFree( pID ); + aResData.sResTyp = lcl_xmlStrToOString( pNodeName ); + PFormEntrys* pEntrys = + pMergeDataFile->GetPFormEntrys( &aResData ); + if( pEntrys ) + { + OString sNewText; + pEntrys->GetText( sNewText, STRING_TYP_TEXT, rLang ); + xmlSetProp( + pCurrent, (const xmlChar*)("title"), + (const xmlChar*)(sNewText.getStr())); + } + } + lcl_MergeLevel( + io_pSource, pCurrent, (const xmlChar *)("node"), + pMergeDataFile, rLang, rXhpRoot ); + } + else if( !xmlStrcmp(pCurrent->name, (const xmlChar *)("topic")) ) + { + pCurrent = lcl_UpdateTopic( pCurrent, rXhpRoot ); + } + } + } +} + +//Parse tree file +TreeParser::TreeParser( + const OString& rInputFile, const OString& rLang ) + : m_pSource( 0 ) + , m_sLang( rLang ) + , m_bIsInitialized( false ) +{ + m_pSource = xmlParseFile( rInputFile.getStr() ); + if ( !m_pSource ) { + std::cerr + << "Treex error: Cannot open source file: " + << rInputFile.getStr() << std::endl; + return; + } + if( !m_pSource->name ) + { + m_pSource->name = new char[strlen(rInputFile.getStr())+1]; + strcpy( m_pSource->name, rInputFile.getStr() ); + } + m_bIsInitialized = true; +} + +TreeParser::~TreeParser() +{ +} + +//Extract strings form source file +void TreeParser::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 + << "Treex error: Cannot open sdffile for extract: " + << rSDFFile.getStr() << std::endl; + return; + } + + xmlNodePtr pRootNode = xmlDocGetRootElement( m_pSource ); + lcl_ExtractLevel( + m_pSource, pRootNode, (const xmlChar *)("help_section"), + aSDFStream, rPrj, rRoot ); + + xmlFreeDoc( m_pSource ); + xmlCleanupParser(); + aSDFStream.close(); + m_bIsInitialized = false; +} + +//Merge strings to tree file and update reference to help files(xhp) +void TreeParser::Merge( + const OString &rMergeSrc, const OString &rDestinationFile, + const OString &rXhpRoot ) +{ + assert( m_bIsInitialized ); + + const xmlNodePtr pRootNode = xmlDocGetRootElement( m_pSource ); + if( m_sLang == "en-US" ) + { + lcl_MergeLevel( + m_pSource, pRootNode, (const xmlChar *)("help_section"), + 0, m_sLang, rXhpRoot ); + } + else + { + MergeDataFile aMergeDataFile( + rMergeSrc, static_cast( m_pSource->name ), false ); + + if( aMergeDataFile.GetLanguages()[0] != m_sLang ) + { + std::cerr + << "Treex error: given language conflicts with " + << "language of Mergedata file: " + << m_sLang.getStr() << " - " << rMergeSrc.getStr() << std::endl; + return; + } + + lcl_MergeLevel( + m_pSource, pRootNode, (const xmlChar *)("help_section"), + &aMergeDataFile, m_sLang, rXhpRoot ); + } + + xmlSaveFile( rDestinationFile.getStr(), m_pSource ); + xmlFreeDoc( m_pSource ); + xmlCleanupParser(); + m_bIsInitialized = false; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/treex.cxx b/l10ntools/source/treex.cxx new file mode 100644 index 000000000000..65807b1a5c0b --- /dev/null +++ b/l10ntools/source/treex.cxx @@ -0,0 +1,60 @@ +/* -*- 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 +#include "sal/main.h" + +#include "export.hxx" +#include "treemerge.hxx" + +void WriteUsage() +{ + std::cout + << "Syntax: Treex [-p Prj] [-r Root] -i FileIn -o FileOut" + << " [-m DataBase] [-l l1,l2,...]\n" + << " Prj: Project\n" + << " Root: Path to project root (../.. etc.)\n" + << " or path to root of localized xhp files\n" + << " FileIn: Source files (*.tree)\n" + << " FileOut: Destination file (*.*)\n" + << " DataBase: Mergedata (*.po)\n" + << " -l: Restrict the handled languages; l1, l2, ... are elements of" + << " (de, en-US, ...)\n"; +} + + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + HandledArgs aArgs; + if( !Export::handleArguments(argc, argv, aArgs) ) + { + WriteUsage(); + return 1; + } + + TreeParser aParser(aArgs.m_sInputFile, Export::sLanguages); + if( !aParser.isInitialized() ) + { + return 1; + } + + if( aArgs.m_bMergeMode || aArgs.m_sPrj.isEmpty() ) + { + aParser.Merge( + aArgs.m_sMergeSrc, aArgs.m_sOutputFile, aArgs.m_sPrjRoot ); + } + else + { + aParser.Extract( + aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot ); + } + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit From 0853451b46f7227ea41a049e8de580ac9a4d5bf1 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 4 Nov 2012 23:20:51 +0100 Subject: Correct propmerge If there is no po entry for a string than use the original en-US string Change-Id: I4296ae9c189a3c65cf93a806edbf1317651d1486 --- l10ntools/source/propmerge.cxx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'l10ntools') diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index 61400147691f..a858f44d8210 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -210,6 +210,10 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil lcl_PrintJavaStyle( sNewText, aDestination ); aDestination << std::endl; } + else + { + aDestination << sLine.getStr() << std::endl; + } } else { -- cgit From 428d9e15f98630df9a652be2b2f5064ac1bc7a89 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Wed, 7 Nov 2012 22:50:56 +0100 Subject: Delete unused files Belong to extensions which become unneeded because of treex Change-Id: I86ca7494a9022c1e72d64b2ec5cbd41d6e292a00 --- l10ntools/scripts/update_tree.pl | 394 --------------------------------------- 1 file changed, 394 deletions(-) delete mode 100644 l10ntools/scripts/update_tree.pl (limited to 'l10ntools') diff --git a/l10ntools/scripts/update_tree.pl b/l10ntools/scripts/update_tree.pl deleted file mode 100644 index 02faf6a37c72..000000000000 --- a/l10ntools/scripts/update_tree.pl +++ /dev/null @@ -1,394 +0,0 @@ -: -eval 'exec perl -wS $0 ${1+"$@"}' - if 0; -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2000, 2010 Oracle and/or its affiliates. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -use Cwd 'abs_path'; -use File::Find; -use File::Copy qw/cp mv/; -use File::Basename; - -# update the tree files in /misc/* - -$| = 1; - -my $prj = $ENV{PWD}; - -my $inpath = $ENV{WORKDIR}; -terminate() if ( ! defined $inpath ); - -my $destpath = $inpath; -my $with_lang = $ARGV[1]; -my $xmllint = $ENV{XMLLINT} || "$ENV{OUTDIR_FOR_BUILD}/bin/xmllint"; - -$tree_target_prefix = $ARGV[4]; - -# Always use / directory separators -$prj =~ s/\\/\//g if defined($prj); -$inpath =~ s/\\/\//g; -$destpath =~ s/\\/\//g; - -if ( ! defined $prj ) { -# do someting that works for manual call - ($scriptname = `pwd`) =~ s/\n/\/$0/; - ($tree_src = $scriptname) =~ s/\/update_tree.pl/\/..\/source\/auxiliary/; - ($tree_dest = $scriptname) =~ s/\/update_tree.pl/\/..\/$destpath\/misc/; - ($source_dir = $scriptname) =~ s/\/update_tree.pl/\/..\/source/; - ($source_dir_xhp = $scriptname) =~ s/\/update_tree.pl/\/..\/source/; - - if ( defined $ENV{TRYSDF} || defined $ENV{LOCALIZESDF} ) - { - if( defined $ENV{LOCALIZATION_FOUND} && $ENV{LOCALIZATION_FOUND} eq "YES" ) - { - $source_dir = $ENV{TRYSDF}; - } - elsif( defined $ENV{LOCALIZESDF} && $ENV{LOCALIZESDF} ne "" ) - { - $source_dir = $ENV{LOCALIZESDF}; - } - $source_dir =~ s/\/auxiliary\/localize.sdf$// ; - } - $treestrings = "$ARGV[0]"; - $treestrings=~ s/\/*.tree//g; -} else { - $source_dir_xhp = "$prj/source/presenter/help"; - $tree_src = "$ARGV[0]"; - $tree_src =~ s/\/help.tree//g; - $tree_dest = "$ARGV[3]"; - $tree_dest =~ s/\/help.tree//g; - $source_dir = "$ARGV[2]"; - $source_dir =~ s/\/localize.sdf//g; - $treestrings = "$ARGV[0]"; - $treestrings=~ s/\/help.tree/\/tree_strings.xhp/g; - - if( defined $ENV{LOCALIZATION_FOUND} && $ENV{LOCALIZATION_FOUND} eq "YES" ) - { - $source_dir = $ENV{TRYSDF}; - } - elsif ( defined $ENV{LOCALIZESDF} && $ENV{LOCALIZESDF} ne "" ) - { - $source_dir = $ENV{LOCALIZESDF}; - } - $source_dir =~ s/\/auxiliary\/localize.sdf$// ; -} - -# Get the English tree files as master -#------------------------------- -# Update English from xhp -#------------------------------- -&do_english; -#------------------------------- -# Update localizations from sdf -#------------------------------- - -if( defined $with_lang && $with_lang ne "" ) -{ - @langs = split /\s+/, $with_lang; - &read_loc; - for $l(@langs) - { - #if ($l ne "en-US") { - &do_lang($l); - #} - } -} -else -{ - print "\nNo WITH_LANG set, skipping l10n\n"; -} -#------------------------------- -# - -#################### -# SUBS -#################### -sub terminate { - $err = shift; - print "$err\n\n"; - $msg = <<"MSG"; - -update_tree.pl - all languages in WITH_LANG are processed. WITH_LANG=ALL is - not supported in manual calls. - - Updates the *.tree files. - At first, the English file is updated based on the English - help topic titles as read from the help files. Then, the - localized tree files are written based on the English tree - file and the localized help topic titles. - - Requires a valid LibreOffice build environment. -MSG - print "$msg\n"; - exit( -1 ); - # die "$msg\n"; -} - -#--------------------------------------------------- - -sub do_english { - undef %helpsection; undef %node; - &readtreestrings; - &gettreefiles; -} - -#--------------------------------------------------- -sub do_lang { - $lng = shift; - print "Processing $lng\n"; - &processtreefiles($lng); -} - -#--------------------------------------------------- -sub readtreestrings { - if (open TREE, $treestrings) { - print "Processing readtreestrings\n"; - while () { - chomp; - s/<\/*help:productname>//gis; - if (/help_section/) { - s/^\s*<.*help_section//; - s/<\/.*$//; - ($id = $_) =~ s/^.*id="(\d+)".*$/$1/; - ($title = $_) =~ s/^.*title="(.*)".*$/$1/; - $helpsection{$id} = $title; - } - - if (/node id=/) { - s/^\s*<.*node //; - s/<\/.*$//; - ($id = $_) =~ s/^.*id="(\d+)".*$/$1/; - ($title = $_) =~ s/^.*title="(.*)".*$/$1/; - $node{$id} = $title; - } - } - close TREE; - } else { - &terminate("Error opening $treestrings"); - } -} - -#------------------------------------ -sub gettreefiles { - # Read the tree files from the directory - # this list is also used for all foreign languages - if (opendir ENUS, "$tree_src") { - @treeviews = grep /\.tree/, readdir ENUS; - closedir ENUS; - } else { - &terminate("Cannot open directory $tree_src"); - } -} - -#------------------------------------ -sub processtreefiles { - $lng = shift; - use File::Temp qw/ tempfile /; - use File::Spec; - - for $tv(@treeviews) { - @lines = &readtv("$tree_src/$tv"); - for $l(@lines) { - if ($l =~ /topic/) { - ($id = $l) =~ s/^.*id="([^"]*)".*$/$1/gis; - ($module = $id) =~ s/^([^\/]*).*$/$1/; - $id =~ s/^.*?\///; - $file = "$source_dir_xhp/$lng/$id"; - - if ($lng eq 'en-US') { # english comes from the file - $temp = $l; - $temp =~ s/^.*]+id=".*"[^>]*>([^<]*)<\/topic>.*$/$1/gis; - $temp =~ s/'/\'/gis; $temp=~ s/&/+/gis; - $temp =~ s/"/\'/gis; $temp =~ s/&/+/gis; - - $id =~s/^.*\/(.*.xhp)/$1/; - $l = "$temp\n"; - } else { # localized comes from the localize sdf - if (defined($loc_title{$lng}->{$id})) { - $xhpname = $id; - $xhpname =~s/^.*\/(.*.xhp)/$1/; - $l = "$loc_title{$lng}->{$id}\n"; - } else { - } - } - } - - if ($l =~/{$id})) { - $l =~ s/title="(.*)"/title="$node{$lng}->{$id}"/; - } - } - } - - if ($l =~/{$id})) { - $l =~ s/title="(.*)"/title="$helpsection{$lng}->{$id}"/; - } - } - } - } - - - my $treeoutdir = "$tree_dest"; - my $tmpname_template=$tv."_XXXXX"; - my ( $treetmpfilehandle, $treetmpfile ) = tempfile($tmpname_template , DIR => File::Spec->tmpdir() ); - close $treetmpfilehandle ; - - if (open TV, ">$treetmpfile") { - for $line(@lines) { - $line =~ s/\$\[officename\]/%PRODUCTNAME/g; - $line =~ s/\$\[officeversion\]/%PRODUCTVERSION/g; - print TV $line; - } - close TV; - chmod 0664, $treetmpfile or &terminate("Cannot change rights on $treetmpfile"); - if( $^O eq 'MSWin32' ) - { - $tree_dest =~ s/\//\\/g ; - unlink "$tree_dest\\$tv" ; - mv $treetmpfile , "$tree_dest\\$tv" or &terminate("Cannot mv $treetmpfile to $tree_dest\\$tv" ); - } - else - { - unlink "$tree_dest/$tv" ; - my $ret=mv $treetmpfile , "$tree_dest/$tv" or &terminate("Cannot write to $tree_dest/$tv - Error $!"); - my $ret=mv "$tree_dest/$tv" , "$tree_dest/$tv" or &terminate("Cannot write to $tree_dest/$tv - Error $!"); - #xmllint is crashing on windows, fixme - if( $^O ne 'cygwin' ) - { - system("$xmllint --noout --noent $tree_dest/$tv") == 0 or &terminate("$tree_dest/$tv is illformed xml ($xmllint on $^O)" ); - } - } - } else { - &terminate("Cannot write to $tvout"); - } - } -} - -#------------------------------------ -sub readtv { - my $f = shift; - if (open TV, $f) { - $/ = "\n"; - my @l = ; - close TV; - return @l; - } else { - &terminate("Error opening $f"); - } -} - -#------------------------------------- -# read entries from localize.sdf files -#------------------------------------- -sub read_loc { - $/ = "\n"; - my $path = "$source_dir"; - @files = `find $source_dir -name localize.sdf`; - for my $fname (@files) { - $FS = '\t'; - open(LOCALIZE_SDF, $fname) || die 'Cannot open "localize.sdf".'."$fname"; - while () { - my $sdf_line = $_; - my ($Fld1,$file,$Fld3,$Fld4,$id,$Fld6,$Fld7,$Fld8,$Fld9,$lang,$text) = split($FS, $sdf_line , 12); - next if ( $Fld1 =~ /^#/); - if ($id eq 'tit') { - #strip filename - $file =~ s/.*text\\/text\\/g; - #convert \ to / in filename - $file =~ s/\\/\//g; - $file =~ s/^.*\/(.*)\/(.*)$/$1\/$2/; - #fpe: i46823 - need to encode &s, added encoding - $text =~ s/&(?!amp;)/&/g; - #help xml tags are not allowed in .tree files - $text =~ s/\\<.*?\\>//g; - # add entry to the hash - - $loc_title{$lang}->{$file} = $text; - } - if ($file =~ /tree_strings.xhp/) { - #strip filename - $file =~ s/.*text/text/g; - #convert \ to / in filename - $file =~ s/\\/\//g; - if ($text =~ /^ - my ($fld1,$app,$fld3,$id,$fld5,$sec_title) = split('"', $text, 7); - #fpe: i46823 - need to encode &s, added encoding - if( defined $sec_title ) - { - $sec_title =~ s/&(?!amp;)/&/g; - #help xml tags are not allowed in .tree files - $sec_title =~ s/\\<.*?\\>//g; - #unquot \ - terminate( "\n\nERROR: Bad string in file '$fname' will cause invalid xml tree file \n---\n'$sdf_line'\n---\nPlease remove or replace < = '<' and > = '>' within the title attribute '$sec_title'\n") , if( $sec_title =~ /[\<\>]/ ); - $helpsection{$lang}->{$id} = $sec_title; - } - } elsif ($text =~/ - # BEWARE: title may contain escaped '"' so only match " not preceded by \ - # using a zero‐width negative look‐behind assertion. - my ($fld1,$id,$fld3,$node_title,$Fld5) = split(/(?//g; - terminate( "\n\nERROR: Bad string in '$fname' will cause invalid xml tree file \n---\n'$sdf_line'\n---\nPlease remove or replace < = '<' and > = '>' within the title attribute '$node_title'\n") , if( $node_title =~ /[\<\>]/ ); - } - $node{$lang}->{$id} = $node_title; - } - } - } - close LOCALIZE_SDF; - } - # statistics - $total_elements=0; - foreach $lang (keys %loc_title) { - $no_elements = scalar(keys(%{$loc_title{$lang}})); - push(@langstat, "$lang:\t ".$no_elements." matches\n"); - $total_elements += $no_elements; - } -} -- cgit From 9e682e30e7cd2d90ad37921934fbf0f5f1897eb3 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 8 Nov 2012 11:13:59 +0100 Subject: Localize.cxx add correct header to po Belong to dictionaries modul Change-Id: Ifd8303fd294de2369383cc2ce7ebdd1487c90463 --- l10ntools/source/localize.cxx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index f808af59d6cd..c4af640834af 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -262,17 +262,23 @@ void handleCommand( << outFilePath.getStr() << "\n"; throw false; //TODO } - rtl::OString relativPath; - if (!inPath.copy(inPath.indexOf(project), - inPath.lastIndexOf('/')-inPath.indexOf(project)). - convertToString(&relativPath, osl_getThreadTextEncoding(), - (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR - | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) + + //Add header to actual po file { - std::cerr << "Error: Cannot convert pathname from UTF-16\n"; - throw false; //TODO + const sal_Int32 nProjectInd = inPath.indexOf(project); + const OString relativPath = + project == OUString("dictionaries") ? + OUStringToOString( + inPath.copy( nProjectInd + 13, + inPath.lastIndexOf('/')- nProjectInd - 13), + RTL_TEXTENCODING_UTF8 ) : + OUStringToOString( + inPath.copy( nProjectInd, + inPath.lastIndexOf('/')- nProjectInd), + RTL_TEXTENCODING_UTF8 ); + + rPoOutPut.writeHeader(PoHeader(relativPath)); } - rPoOutPut.writeHeader(PoHeader(relativPath)); } while (!in.eof()) { -- cgit From ed879cdf2957fcfb013a894dd1ed8bf512f10301 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 8 Nov 2012 12:05:55 +0100 Subject: Correct typo in po header Change-Id: Ic98467f5c32a0a84af62f68fbe84c68c3e37f1c1 --- l10ntools/source/po.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 9dd6d6adab56..18c0ef1042d4 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -683,8 +683,8 @@ PoHeader::PoHeader( const OString& rExtSrc ) "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" - "X-Genarator: LibreOffice\n" - "X-Accelerator_Marker: ~\n")); + "X-Generator: LibreOffice\n" + "X-Accelerator-Marker: ~\n")); m_bIsInitialized = true; } -- cgit From 643ffdf621a056a266c1c6121388e4d0b06adb0d Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Thu, 8 Nov 2012 17:16:06 +0100 Subject: Add an extra empty line to lngmerge It worked with eof before so an extra line is needed. See also this commit: 06175e8b19625cb5a43b1ae5ae63e419cee7e053 Change-Id: Ic3f43a52801429258df620229269b8426f1e2995 --- l10ntools/source/lngmerge.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'l10ntools') diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index efc6c81f6994..42b6384394ea 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -66,6 +66,7 @@ LngParser::LngParser(const rtl::OString &rLngFile, pLines->push_back( new rtl::OString(sLine) ); std::getline(aStream, s); } + pLines->push_back( new rtl::OString() ); } else nError = LNG_COULD_NOT_OPEN; -- cgit From 8e0d67bed54633d555a4601a5d79e2d5ba7ab2bb Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sat, 10 Nov 2012 11:58:48 +0100 Subject: Add some check to renewpo Change-Id: I7b90785516f172f7b552a9e5ae30d02f7c52d7cf --- l10ntools/source/renewpo.cxx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 241db58b72cf..32d19d594c09 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -158,14 +158,23 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, { sActUnTrans = DelLocalId(sActUnTrans); } - PoEntry aPE(sActUnTrans, vTypes[nIndex]); - const OString sActStr = - sActTrans.getToken(vTypes[nIndex],'\t'); - aPE.setMsgStr(sActStr); - aPE.setFuzzy( sActStr.isEmpty() ? false : - static_cast(sActTrans.getToken(PoEntry::DUMMY,'\t'). - copy(nDummyBit++,1).toBoolean())); - aNewPo.writeEntry(aPE); + try + { + PoEntry aPE(sActUnTrans, vTypes[nIndex]); + const OString sActStr = + sActTrans.getToken(vTypes[nIndex],'\t'); + aPE.setMsgStr(sActStr); + aPE.setFuzzy( sActStr.isEmpty() ? false : + static_cast(sActTrans.getToken(PoEntry::DUMMY,'\t'). + copy(nDummyBit++,1).toBoolean())); + aNewPo.writeEntry(aPE); + } + catch( PoEntry::Exception& ) + { + cerr + << "Invalid sdf line " + << sActUnTrans.replaceAll("\t","\\t").getStr() << '\n'; + } } } //Check wheather next entry is in the same po file -- cgit From deaceba0c27040ad9982b16e2be8745f6bd1605a Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Tue, 13 Nov 2012 11:40:10 +0100 Subject: XML tag check in help and readme translations Change-Id: Iec88ae875e00777f499cd0044f256275d854dca8 --- l10ntools/Executable_helpex.mk | 4 ++++ l10ntools/Executable_xrmex.mk | 4 ++++ l10ntools/source/helper.hxx | 20 ++++++++++++++++++++ l10ntools/source/helpmerge.cxx | 15 +++++++++++---- l10ntools/source/xrmmerge.cxx | 4 +++- 5 files changed, 42 insertions(+), 5 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_helpex.mk b/l10ntools/Executable_helpex.mk index 22f2ae9288a4..b7e63100b351 100644 --- a/l10ntools/Executable_helpex.mk +++ b/l10ntools/Executable_helpex.mk @@ -49,4 +49,8 @@ $(eval $(call gb_Executable_add_exception_objects,helpex,\ l10ntools/source/helpmerge \ )) +$(eval $(call gb_Executable_use_externals,helpex,\ + libxml2 \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_xrmex.mk b/l10ntools/Executable_xrmex.mk index 02e776a2277b..73c56abe420a 100644 --- a/l10ntools/Executable_xrmex.mk +++ b/l10ntools/Executable_xrmex.mk @@ -50,4 +50,8 @@ $(eval $(call gb_Executable_add_exception_objects,xrmex,\ l10ntools/source/xrmmerge \ )) +$(eval $(call gb_Executable_use_externals,xrmex,\ + libxml2 \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx index cc33b71ff8ac..1e28aa6c4d50 100644 --- a/l10ntools/source/helper.hxx +++ b/l10ntools/source/helper.hxx @@ -35,6 +35,8 @@ #include #include +#include + #include "rtl/string.hxx" #include "rtl/ustring.hxx" #include "sal/types.h" @@ -100,6 +102,24 @@ inline sal_Int32 indexOfAnyAsciiL( return -1; } +inline bool isWellFormedXML( OString const & text ) +{ + xmlDocPtr doc; + OString content; + bool result = true; + + content = ""; + content += text; + content += ""; + doc = xmlParseMemory(content.getStr(),(int)content.getLength()); + if (doc == NULL) { + result = false; + } + xmlFreeDoc(doc); + xmlCleanupParser(); + return result; +} + template< typename T > inline T abbreviate( T const & text, sal_Int32 start, sal_Int32 length) { diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index 05b3800bbc81..aab255f75a05 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -341,7 +341,7 @@ void HelpParser::MakeDir(const rtl::OString& rPath) void HelpParser::ProcessHelp( LangHashMap* aLangHM , const rtl::OString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){ XMLElement* pXMLElement = NULL; - PFormEntrys *pEntrys = NULL; + PFormEntrys *pEntrys = NULL; XMLData *data = NULL; rtl::OString sLId; @@ -379,9 +379,16 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const rtl::OString& sCur , while ( (nPreSpaces < nLen) && (*(sSourceText.getStr()+nPreSpaces) == ' ') ) nPreSpaces++; pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); - rtl::OUString sNewdata( - sSourceText.copy(0,nPreSpaces) + - rtl::OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8)); + OUString sNewdata; + if (helper::isWellFormedXML(sNewText)) + { + sNewdata = sSourceText.copy(0,nPreSpaces) + + rtl::OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); + } + else + { + sNewdata = sSourceText; + } if (!sNewdata.isEmpty()) { if( pXMLElement != NULL ) diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index a3eb0e5418ee..b4868f5f8623 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -27,6 +27,7 @@ #include "export.hxx" #include "xrmmerge.hxx" #include "tokens.h" +#include "helper.hxx" #include #include #include @@ -606,7 +607,8 @@ void XRMResMerge::WorkOnText( if ( Export::isAllowed( sLang ) && ( pEntrys->GetText( sContent, STRING_TYP_TEXT, sLang )) && - ( sContent != "-" ) && !sContent.isEmpty()) + ( sContent != "-" ) && !sContent.isEmpty() && + helper::isWellFormedXML( sContent )) { rText = sContent; -- cgit From 0a7189a3b2d8fc78e9b3ce1b5fff2622557258a5 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Tue, 13 Nov 2012 11:44:29 +0100 Subject: remove obsoleted gsicheck tool Change-Id: Ib25a6feae34533fa3752fe57e857613ca113ee3a --- l10ntools/Executable_gsicheck.mk | 45 -- l10ntools/Module_l10ntools.mk | 1 - l10ntools/inc/tagtest.hxx | 346 --------- l10ntools/source/gsicheck.cxx | 1051 ------------------------- l10ntools/source/tagtest.cxx | 1570 -------------------------------------- 5 files changed, 3013 deletions(-) delete mode 100644 l10ntools/Executable_gsicheck.mk delete mode 100644 l10ntools/inc/tagtest.hxx delete mode 100644 l10ntools/source/gsicheck.cxx delete mode 100644 l10ntools/source/tagtest.cxx (limited to 'l10ntools') diff --git a/l10ntools/Executable_gsicheck.mk b/l10ntools/Executable_gsicheck.mk deleted file mode 100644 index 829a0296939f..000000000000 --- a/l10ntools/Executable_gsicheck.mk +++ /dev/null @@ -1,45 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -# Version: MPL 1.1 / GPLv3+ / LGPLv3+ -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License or as specified alternatively below. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# Major Contributor(s): -# Copyright (C) 2012 David Ostrovsky (initial developer) -# -# All Rights Reserved. -# -# For minor contributions see the git repository. -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 3 or later (the "GPLv3+"), or -# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), -# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable -# instead of those above. - -$(eval $(call gb_Executable_Executable,gsicheck)) - -$(eval $(call gb_Executable_set_include,gsicheck,\ - -I$(SRCDIR)/l10ntools/inc \ - $$(INCLUDE) \ -)) - -$(eval $(call gb_Executable_use_libraries,gsicheck,\ - sal \ -)) - -$(eval $(call gb_Executable_use_unpacked,gsicheck,boost)) - -$(eval $(call gb_Executable_add_exception_objects,gsicheck,\ - l10ntools/source/gsicheck \ - l10ntools/source/tagtest \ -)) - -# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Module_l10ntools.mk b/l10ntools/Module_l10ntools.mk index 6efcd7f45596..4b2b0f6d970d 100644 --- a/l10ntools/Module_l10ntools.mk +++ b/l10ntools/Module_l10ntools.mk @@ -31,7 +31,6 @@ $(eval $(call gb_Module_add_targets,l10ntools,\ Executable_idxdict \ Executable_ulfconv \ Executable_ulfex \ - Executable_gsicheck \ Executable_cfgex \ Executable_uiex \ Executable_xrmex \ diff --git a/l10ntools/inc/tagtest.hxx b/l10ntools/inc/tagtest.hxx deleted file mode 100644 index a6ccec4d73ea..000000000000 --- a/l10ntools/inc/tagtest.hxx +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * 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 . - */ - -#ifndef _TAGTEST_HXX_ -#define _TAGTEST_HXX_ - -#include -#include - -class GSILine; - -typedef sal_Int32 TokenId; - -#define TOK_INVALIDPOS (-1) - -class ParserMessage; -typedef ::std::vector< ParserMessage* > Impl_ParserMessageList; - -class ParserMessageList; - -typedef boost::unordered_map StringHashMap; - -class TokenInfo -{ -private: - void SplitTag( ParserMessageList &rErrorList ); - - rtl::OUString aTagName; - StringHashMap aProperties; - sal_Bool bClosed; // tag is closed - sal_Bool bCloseTag; // tag is close Tag - - - sal_Bool bIsBroken; - sal_Bool bHasBeenFixed; - sal_Bool bDone; - -public: - - rtl::OUString aTokenString; - TokenId nId; - sal_Int32 nPos; // Position in String - - TokenInfo():bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),nId( 0 ){;} -explicit TokenInfo( TokenId pnId, sal_Int32 nP ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),nId( pnId ),nPos(nP){;} - explicit TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr ):bClosed(sal_False),bCloseTag(sal_False),bIsBroken(sal_False),bHasBeenFixed(sal_False),bDone(sal_False),aTokenString( paStr ),nId( pnId ),nPos(nP) {;} - explicit TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList ); - - rtl::OUString GetTagName() const; - - rtl::OUString MakeTag() const; - - /** - Is the property to be ignored or does it have the default value anyways - **/ - sal_Bool IsPropertyRelevant( const rtl::OString &rName, const rtl::OUString &rValue ) const; - sal_Bool IsPropertyValueValid( const rtl::OString &rName, const rtl::OUString &rValue ) const; - /** - Does the property contain the same value for all languages - e.g.: the href in a link tag - **/ - sal_Bool IsPropertyInvariant( const rtl::OString &rName, const rtl::OUString &rValue ) const; - /** - a subset of IsPropertyInvariant but containing only those that are fixable - we dont wat to fix e.g.: ahelp :: visibility - **/ - sal_Bool IsPropertyFixable( const rtl::OString &rName ) const; - sal_Bool MatchesTranslation( TokenInfo& rInfo, sal_Bool bGenErrors, ParserMessageList &rErrorList, sal_Bool bFixTags = sal_False ) const; - - sal_Bool IsDone() const { return bDone; } - void SetDone( sal_Bool bNew = sal_True ) { bDone = bNew; } - - sal_Bool HasBeenFixed() const { return bHasBeenFixed; } - void SetHasBeenFixed( sal_Bool bNew = sal_True ) { bHasBeenFixed = bNew; } -}; - - -class ParserMessageList -{ -private: - Impl_ParserMessageList maList; - -public: - ~ParserMessageList() { clear(); } - void AddError( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag ); - void AddWarning( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag ); - - sal_Bool HasErrors(); - bool empty() const { return maList.empty(); } - size_t size() const { return maList.size(); } - ParserMessage* operator [] ( size_t i ) { return ( i < maList.size() ) ? maList[ i ] : NULL; } - void clear(); -}; - - -#define TAG_GROUPMASK 0xF000 -#define TAG_GROUPSHIFT 12 - -#define TAG_GROUP( nTag ) (( nTag & TAG_GROUPMASK ) >> TAG_GROUPSHIFT ) -#define TAG_NOGROUP( nTag ) ( nTag & ~TAG_GROUPMASK ) // ~ = Bitweises NOT - -#define TAG_NOMORETAGS 0x0 - -#define TAG_GROUP_FORMAT 0x1 -#define TAG_ON 0x100 -#define TAG_BOLDON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x001 ) -#define TAG_BOLDOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x001 ) -#define TAG_ITALICON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x002 ) -#define TAG_ITALICOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x002 ) -#define TAG_UNDERLINEON ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | TAG_ON | 0x004 ) -#define TAG_UNDERLINEOFF ( TAG_GROUP_FORMAT << TAG_GROUPSHIFT | 0x004 ) - -#define TAG_GROUP_NOTALLOWED 0x2 -#define TAG_HELPID ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x001 ) -#define TAG_MODIFY ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x002 ) -#define TAG_REFNR ( TAG_GROUP_NOTALLOWED << TAG_GROUPSHIFT | 0x004 ) - -#define TAG_GROUP_STRUCTURE 0x3 -#define TAG_NAME ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x001 ) -#define TAG_HREF ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x002 ) -#define TAG_AVIS ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x004 ) -#define TAG_AHID ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x008 ) - -#define TAG_TITEL ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x020 ) -#define TAG_KEY ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x040 ) -#define TAG_INDEX ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x080 ) - -#define TAG_REFSTART ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x100 ) - -#define TAG_GRAPHIC ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x200 ) -#define TAG_NEXTVERSION ( TAG_GROUP_STRUCTURE << TAG_GROUPSHIFT | 0x400 ) - -#define TAG_GROUP_SYSSWITCH 0x4 -#define TAG_WIN ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x001 ) -#define TAG_UNIX ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x002 ) -#define TAG_MAC ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x004 ) -#define TAG_OS2 ( TAG_GROUP_SYSSWITCH << TAG_GROUPSHIFT | 0x008 ) - -#define TAG_GROUP_PROGSWITCH 0x5 -#define TAG_WRITER ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x001 ) -#define TAG_CALC ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x002 ) -#define TAG_DRAW ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x004 ) -#define TAG_IMPRESS ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x008 ) -#define TAG_SCHEDULE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x010 ) -#define TAG_IMAGE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x020 ) -#define TAG_MATH ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x040 ) -#define TAG_CHART ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x080 ) -#define TAG_OFFICE ( TAG_GROUP_PROGSWITCH << TAG_GROUPSHIFT | 0x100 ) - - -#define TAG_GROUP_META 0x6 -#define TAG_OFFICEFULLNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x001 ) -#define TAG_OFFICENAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x002 ) -#define TAG_OFFICEPATH ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x004 ) -#define TAG_OFFICEVERSION ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x008 ) -#define TAG_PORTALNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x010 ) -#define TAG_PORTALFULLNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x020 ) -#define TAG_PORTALPATH ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x040 ) -#define TAG_PORTALVERSION ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x080 ) -#define TAG_PORTALSHORTNAME ( TAG_GROUP_META << TAG_GROUPSHIFT | 0x100 ) - - -#define TAG_GROUP_SINGLE 0x7 -#define TAG_REFINSERT ( TAG_GROUP_SINGLE << TAG_GROUPSHIFT | 0x001 ) - - -#define TAG_GROUP_MULTI 0x8 -#define TAG_END ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x010 ) -#define TAG_ELSE ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x020 ) -#define TAG_AEND ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x040 ) -#define TAG_VERSIONEND ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x080 ) -#define TAG_ENDGRAPHIC ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x100 ) - -#define TAG_GROUP_MISC 0x9 -#define TAG_COMMONSTART ( TAG_GROUP_MISC << TAG_GROUPSHIFT | 0x001 ) -#define TAG_COMMONEND ( TAG_GROUP_MISC << TAG_GROUPSHIFT | 0x002 ) - -#define TAG_UNKNOWN_TAG ( TAG_GROUP_MULTI << TAG_GROUPSHIFT | 0x800 ) - -typedef ::std::vector< TokenInfo* > TokenListImpl; - -class TokenList -{ -private: - TokenListImpl maList; - TokenList& operator =( const TokenList& rList ); - -public: - TokenList() {} - ~TokenList(){ clear(); } - - size_t size() const { return maList.size(); } - void clear() - { - for ( size_t i = 0 ; i < maList.size() ; i++ ) - delete maList[ i ]; - maList.clear(); - } - - void insert( TokenInfo p, size_t nIndex = size_t(-1) ) - { - if ( nIndex < maList.size() ) { - TokenListImpl::iterator it = maList.begin(); - ::std::advance( it, nIndex ); - maList.insert( it, new TokenInfo(p) ); - } else { - maList.push_back( new TokenInfo(p) ); - } - } - TokenInfo& operator [] ( size_t nIndex ) const - { - return *maList[ nIndex ]; - } - - TokenList( const TokenList& rList ); -}; - -class ParserMessage -{ - sal_Int32 nErrorNr; - rtl::OString aErrorText; - sal_Int32 nTagBegin,nTagLength; - -protected: - ParserMessage( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag ); -public: - - sal_Int32 GetErrorNr() { return nErrorNr; } - rtl::OString GetErrorText() { return aErrorText; } - - sal_Int32 GetTagBegin() { return nTagBegin; } - sal_Int32 GetTagLength() { return nTagLength; } - - virtual ~ParserMessage() {} - virtual sal_Bool IsError() =0; - virtual rtl::OString Prefix() =0; -}; - -class ParserError : public ParserMessage -{ -public: - ParserError( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag ); - - virtual sal_Bool IsError() {return sal_True;} - virtual rtl::OString Prefix() {return rtl::OString(RTL_CONSTASCII_STRINGPARAM("Error:")); } -}; - -class ParserWarning : public ParserMessage -{ -public: - ParserWarning( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag ); - - virtual sal_Bool IsError() {return sal_False;} - virtual rtl::OString Prefix() {return rtl::OString(RTL_CONSTASCII_STRINGPARAM("Warning:")); } -}; - -class SimpleParser -{ -private: - sal_Int32 nPos; - rtl::OUString aSource; - rtl::OUString aLastToken; - TokenList aTokenList; - - TokenInfo aNextTag; // to store closetag in case of combined tags like
- - rtl::OUString GetNextTokenString( ParserMessageList &rErrorList, sal_Int32 &rTokeStartPos ); - -public: - SimpleParser(); - void Parse( rtl::OUString const & PaSource ); - TokenInfo GetNextToken( ParserMessageList &rErrorList ); - static rtl::OUString GetLexem( TokenInfo const &aToken ); - TokenList& GetTokenList(){ return aTokenList; } -}; - -class TokenParser -{ - sal_Bool match( const TokenInfo &aCurrentToken, const TokenId &aExpectedToken ); - sal_Bool match( const TokenInfo &aCurrentToken, const TokenInfo &aExpectedToken ); - void ParseError( sal_Int32 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag ); - void Paragraph(); - void PfCase(); - void PfCaseBegin(); - void AppCase(); - void AppCaseBegin(); - void CaseEnd(); - void SimpleTag(); - void TagPair(); - void TagRef(); - - SimpleParser aParser; - TokenInfo aTag; - - TokenId nPfCaseOptions; - TokenId nAppCaseOptions; - sal_Bool bPfCaseActive ,bAppCaseActive; - - TokenId nActiveRefTypes; - - ParserMessageList *pErrorList; - -public: - TokenParser(); - void Parse( const rtl::OUString &aCode, ParserMessageList* pList ); - TokenList& GetTokenList(){ return aParser.GetTokenList(); } -}; - -class LingTest -{ -private: - TokenParser aReferenceParser; - TokenParser aTesteeParser; - ParserMessageList aCompareWarningList; - void CheckTags( TokenList &aReference, TokenList &aTestee, sal_Bool bFixTags ); - sal_Bool IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens ); - rtl::OUString aFixedTestee; -public: - void CheckReference( GSILine *aReference ); - void CheckTestee( GSILine *aTestee, sal_Bool bHasSourceLine, sal_Bool bFixTags ); - - ParserMessageList& GetCompareWarnings(){ return aCompareWarningList; } - sal_Bool HasCompareWarnings(){ return ( !aCompareWarningList.empty() ); } - - rtl::OUString GetFixedTestee(){ return aFixedTestee; } -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx deleted file mode 100644 index 1abc00d17ac9..000000000000 --- a/l10ntools/source/gsicheck.cxx +++ /dev/null @@ -1,1051 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "sal/config.h" - -#include -#include -#include -#include -#include - -#include - -#include -#include "sal/main.h" -#include "helper.hxx" -#include "tagtest.hxx" -#include "gsicheck.hxx" - -sal_Int32 const MAX_GID_LID_LEN = 250; - -namespace { - -rtl::OString copyUpTo( - rtl::OString const & text, sal_Int32 start, sal_Int32 maximumLength) -{ - assert(start >= 0 && start <= text.getLength()); - return text.copy(start, std::min(text.getLength() - start, maximumLength)); -} - -rtl::OString addSuffix( - rtl::OString const & pathname, rtl::OString const & suffix) -{ - sal_Int32 n = pathname.lastIndexOf('.'); - if (n == -1) { - fprintf( - stderr, - ("Error: pathname \"%s\" does not contain dot to add suffix in" - " front of\n"), - pathname.getStr()); - exit(EXIT_FAILURE); - } - return pathname.replaceAt(n, 0, suffix); -} - -} - -/*****************************************************************************/ -void PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::OString const & aPrefix, - rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString aUniqueId = rtl::OString() ) -/*****************************************************************************/ -{ - fprintf( stdout, "%s %s, Line %u", aType.getStr(), aPrefix.getStr(), static_cast( nLine ) ); - if ( !aUniqueId.isEmpty() ) - fprintf( stdout, ", UniqueID %s", aUniqueId.getStr() ); - fprintf( stdout, ": %s", aMsg.getStr() ); - - if ( bPrintContext ) - fprintf( stdout, " \"%s\"", aContext.getStr() ); - fprintf( stdout, "\n" ); -} - -/*****************************************************************************/ -void PrintError( rtl::OString const & aMsg, rtl::OString const & aPrefix, - rtl::OString const & aContext, sal_Bool bPrintContext, std::size_t nLine, rtl::OString const & aUniqueId = rtl::OString() ) -/*****************************************************************************/ -{ - PrintMessage( "Error:", aMsg, aPrefix, aContext, bPrintContext, nLine, aUniqueId ); -} - -bool LanguageOK( rtl::OString const & aLang ) -{ - sal_Int32 n = 0; - rtl::OString t0(aLang.getToken(0, '-', n)); - if (n == -1) { - return !t0.isEmpty() - && (helper::isAllAsciiDigits(t0) - || helper::isAllAsciiLowerCase(t0)); - } - rtl::OString t1(aLang.getToken(0, '-', n)); - return n == -1 - && !t0.isEmpty() && helper::isAllAsciiLowerCase(t0) - && !t1.isEmpty() && helper::isAllAsciiUpperCase(t1) - && !t0.equalsIgnoreAsciiCase(t1); -} - -class LazyStream: public std::ofstream -{ - -private: - rtl::OString aFileName; - bool bOpened; - -public: - LazyStream() - : aFileName() - , bOpened(false) - {}; - - void SetFileName( const rtl::OString& rFileName ) - { - aFileName = rFileName; - }; - - void LazyOpen(); -}; - -void LazyStream::LazyOpen() -{ - if ( !bOpened ) - { - open(aFileName.getStr(), std::ios_base::out | std::ios_base::trunc); - if (!is_open()) - { - fprintf( stderr, "\nERROR: Could not open Output-File %s!\n\n", - aFileName.getStr() ); - exit ( 4 ); - } - bOpened = true; - } -} - - -// -// class GSILine -// - -/*****************************************************************************/ -GSILine::GSILine( const rtl::OString &rLine, std::size_t nLine ) -/*****************************************************************************/ - : nLineNumber( nLine ) - , bOK( sal_True ) - , bFixed ( sal_False ) - , data_( rLine ) -{ - if (rLine.isEmpty()) { - NotOK(); - return; - } - - aFormat = FORMAT_SDF; - sal_Int32 n = 0; - aUniqId = rLine.getToken(0, '\t', n); // token 0 - aUniqId += "/"; - aUniqId += rLine.getToken(0, '\t', n); // token 1 - aUniqId += "/"; - aUniqId += rLine.getToken(1, '\t', n); // token 3 - aUniqId += "/"; - rtl::OString gid(rLine.getToken(0, '\t', n)); // token 4 - aUniqId += gid; - aUniqId += "/"; - rtl::OString lid(rLine.getToken(0, '\t', n)); // token 5 - aUniqId += lid; - aUniqId += "/"; - aUniqId += rLine.getToken(0, '\t', n); // token 6 - aUniqId += "/"; - aUniqId += rLine.getToken(0, '\t', n); // token 7 - rtl::OString length(rLine.getToken(0, '\t', n)); // token 8 - aLineType = rtl::OString(); - aLangId = rLine.getToken(0, '\t', n); // token 9 - aText = rLine.getToken(0, '\t', n); // token 10 - aQuickHelpText = rLine.getToken(1, '\t', n); // token 12 - aTitle = rLine.getToken(0, '\t', n); // token 13 - if (n == -1) { - NotOK(); - return; - } - rLine.getToken(0, '\t', n); // token 14 - if (n != -1) { - NotOK(); - return; - } - - // do some more format checks here - if (!helper::isAllAsciiDigits(length)) { - PrintError( - "The length field does not contain a number!", "Line format", - length, true, GetLineNumber(), GetUniqId()); - NotOK(); - } - if (!LanguageOK(aLangId)) { - PrintError( - "The Language is invalid!", "Line format", aLangId, true, - GetLineNumber(), GetUniqId()); - NotOK(); - } - // Limit GID and LID to MAX_GID_LID_LEN chars each for database conformity, - // see #137575#: - if (gid.getLength() > MAX_GID_LID_LEN || lid.getLength() > MAX_GID_LID_LEN) - { - PrintError( - (rtl::OString( - RTL_CONSTASCII_STRINGPARAM("GID and LID may only be ")) - + rtl::OString::valueOf(MAX_GID_LID_LEN) - + rtl::OString(RTL_CONSTASCII_STRINGPARAM(" chars long each"))), - "Line format", aLangId, true, GetLineNumber(), GetUniqId()); - NotOK(); - } -} - -/*****************************************************************************/ -void GSILine::NotOK() -/*****************************************************************************/ -{ - bOK = sal_False; -} - -/*****************************************************************************/ -void GSILine::ReassembleLine() -/*****************************************************************************/ -{ - if (GetLineFormat() != FORMAT_SDF) { - PrintError( - "Cannot reassemble line of unknown type (internal Error).", - "Line format", rtl::OString(), false, GetLineNumber(), - GetUniqId()); - return; - } - rtl::OStringBuffer b; - sal_Int32 n = 0; - for (sal_Int32 i = 0; i != 10; ++i) { - b.append(data_.getToken(0, '\t', n)); // token 0--9 - b.append('\t'); - } - b.append(aText); - b.append('\t'); - b.append(data_.getToken(1, '\t', n)); - // token 11; should be empty but there are some places in sc not - // reflected to sources - b.append('\t'); - b.append(aQuickHelpText); - b.append('\t'); - b.append(aTitle); - b.append('\t'); - b.append(data_.getToken(2, '\t', n)); // token 14 - data_ = b.makeStringAndClear(); -} - -// -// class GSIBlock -// -/*****************************************************************************/ -GSIBlock::GSIBlock( sal_Bool PbPrintContext, sal_Bool bSource, sal_Bool bTrans, sal_Bool bRef, sal_Bool bAllowSusp ) -/*****************************************************************************/ - : pSourceLine( NULL ) - , pReferenceLine( NULL ) - , bPrintContext( PbPrintContext ) - , bCheckSourceLang( bSource ) - , bCheckTranslationLang( bTrans ) - , bReference( bRef ) - , bAllowSuspicious( bAllowSusp ) - , bHasBlockError( sal_False ) -{ -} - -/*****************************************************************************/ -GSIBlock::~GSIBlock() -/*****************************************************************************/ -{ - delete pSourceLine; - delete pReferenceLine; - - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - delete maList[ i ]; - maList.clear(); -} - -void GSIBlock::InsertLine( GSILine* pLine, const rtl::OString &rSourceLang) -{ - if ( pLine->GetLanguageId() == rSourceLang ) - { - if ( pSourceLine ) - { - PrintError( "Source Language entry double. Treating as Translation.", "File format", "", pLine->GetLineNumber(), pLine->GetUniqId() ); - bHasBlockError = sal_True; - pSourceLine->NotOK(); - pLine->NotOK(); - } - else - { - pSourceLine = pLine; - return; - } - } - - if (!rSourceLang.isEmpty()) // only check blockstructure if source lang is given - { - for ( size_t nPos = 0, n = maList.size(); nPos < n; ++nPos ) - { - if ( maList[ nPos ]->GetLanguageId() == pLine->GetLanguageId() ) - { - PrintError( "Translation Language entry double. Checking both.", "File format", "", pLine->GetLineNumber(), pLine->GetUniqId() ); - bHasBlockError = sal_True; - maList[ nPos ]->NotOK(); - pLine->NotOK(); - } - nPos++; - } - } - maList.push_back( pLine ); -} - -/*****************************************************************************/ -void GSIBlock::SetReferenceLine( GSILine* pLine ) -/*****************************************************************************/ -{ - pReferenceLine = pLine; -} - -/*****************************************************************************/ -void GSIBlock::PrintMessage( rtl::OString const & aType, rtl::OString const & aMsg, rtl::OString const & aPrefix, - rtl::OString const & aContext, std::size_t nLine, rtl::OString const & aUniqueId ) -/*****************************************************************************/ -{ - ::PrintMessage( aType, aMsg, aPrefix, aContext, bPrintContext, nLine, aUniqueId ); -} - -/*****************************************************************************/ -void GSIBlock::PrintError( rtl::OString const & aMsg, rtl::OString const & aPrefix, - rtl::OString const & aContext, std::size_t nLine, rtl::OString const & aUniqueId ) -/*****************************************************************************/ -{ - PrintMessage( "Error:", aMsg, aPrefix, aContext, nLine, aUniqueId ); -} - -/*****************************************************************************/ -void GSIBlock::PrintList( ParserMessageList *pList, rtl::OString const & aPrefix, - GSILine *pLine ) -/*****************************************************************************/ -{ - for ( size_t i = 0 ; i < pList->size() ; i++ ) - { - ParserMessage *pMsg = (*pList)[ i ]; - rtl::OString aContext; - if ( bPrintContext ) - { - if ( pMsg->GetTagBegin() == -1 ) - aContext = pLine->GetText().copy( 0, 300 ); - else - aContext = helper::abbreviate( pLine->data_, pMsg->GetTagBegin()-150, 300 ); - aContext = aContext.trim(); - } - - PrintMessage( pMsg->Prefix(), pMsg->GetErrorText(), aPrefix, aContext, pLine->GetLineNumber(), pLine->GetUniqId() ); - } -} - -/*****************************************************************************/ -sal_Bool GSIBlock::IsUTF8( const rtl::OString &aTestee, sal_Bool bFixTags, sal_Int32 &nErrorPos, rtl::OString &aErrorMsg, sal_Bool &bHasBeenFixed, rtl::OString &aFixed ) const -/*****************************************************************************/ -{ - rtl::OUString aUTF8Tester( - rtl::OStringToOUString(aTestee, RTL_TEXTENCODING_UTF8)); - rtl::OString aTestee2( - rtl::OUStringToOString(aUTF8Tester, RTL_TEXTENCODING_UTF8)); - sal_Int32 i = 0; - while (i != std::min(aTestee.getLength(), aTestee2.getLength()) - && aTestee[i] == aTestee2[i]) - { - ++i; - } - if (i != aTestee.getLength() || i != aTestee2.getLength()) - { - aUTF8Tester = rtl::OUString(aTestee.getStr(), i, RTL_TEXTENCODING_UTF8); - nErrorPos = aUTF8Tester.getLength(); - aErrorMsg = "UTF8 Encoding seems to be broken"; - return sal_False; - } - - nErrorPos = helper::indexOfAnyAsciiL( - aUTF8Tester, - RTL_CONSTASCII_STRINGPARAM( - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0b\x0c\x0e\x0f\x10\x11\x12" - "\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f")); - if (nErrorPos != -1) - { - aErrorMsg = "String contains illegal character"; - return sal_False; - } - - if ( bFixTags ) - { - bHasBeenFixed = sal_False; - aFixed = rtl::OString(); - } - - return sal_True; -} - -/*****************************************************************************/ -sal_Bool GSIBlock::TestUTF8( GSILine* pTestee, sal_Bool bFixTags ) -/*****************************************************************************/ -{ - sal_Int32 nErrorPos = 0; - rtl::OString aErrorMsg; - sal_Bool bError = sal_False; - rtl::OString aFixed; - sal_Bool bHasBeenFixed = sal_False; - if ( !IsUTF8( pTestee->GetText(), bFixTags, nErrorPos, aErrorMsg, bHasBeenFixed, aFixed ) ) - { - rtl::OString aContext(copyUpTo(pTestee->GetText(), nErrorPos, 20)); - PrintError(rtl::OStringBuffer(aErrorMsg).append(RTL_CONSTASCII_STRINGPARAM(" in Text at Position ")) - .append(nErrorPos).getStr(), - "Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId()); - bError = sal_True; - if ( bHasBeenFixed ) - { - pTestee->SetText( aFixed ); - pTestee->SetFixed(); - } - } - if ( !IsUTF8( pTestee->GetQuickHelpText(), bFixTags, nErrorPos, aErrorMsg, bHasBeenFixed, aFixed ) ) - { - rtl::OString aContext( - copyUpTo(pTestee->GetQuickHelpText(), nErrorPos, 20)); - PrintError(rtl::OStringBuffer(aErrorMsg).append(RTL_CONSTASCII_STRINGPARAM(" in QuickHelpText at Position ")) - .append(nErrorPos).getStr(), - "Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId()); - bError = sal_True; - if ( bHasBeenFixed ) - { - pTestee->SetQuickHelpText( aFixed ); - pTestee->SetFixed(); - } - } - if ( !IsUTF8( pTestee->GetTitle(), bFixTags, nErrorPos, aErrorMsg, bHasBeenFixed, aFixed ) ) - { - rtl::OString aContext( pTestee->GetTitle().copy( nErrorPos, 20 ) ); - PrintError(rtl::OStringBuffer(aErrorMsg).append(RTL_CONSTASCII_STRINGPARAM(" in Title at Position ")) - .append(nErrorPos).getStr(), - "Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId()); - bError = sal_True; - if ( bHasBeenFixed ) - { - pTestee->SetTitle( aFixed ); - pTestee->SetFixed(); - } - } - if ( bError ) - pTestee->NotOK(); - return !bError; -} - - -/*****************************************************************************/ -sal_Bool GSIBlock::HasSuspiciousChars( GSILine* pTestee, GSILine* pSource ) -/*****************************************************************************/ -{ - sal_Int32 nPos = 0; - if ( !bAllowSuspicious && ( nPos = pTestee->GetText().indexOf("??")) != -1 ) - if ( pSource->GetText().indexOf("??") == -1 ) - { - rtl::OUString aUTF8Tester( - rtl::OStringToOUString( - pTestee->GetText().copy(0, nPos), RTL_TEXTENCODING_UTF8)); - sal_Int32 nErrorPos = aUTF8Tester.getLength(); - rtl::OString aContext( helper::abbreviate( pTestee->GetText(), nPos, 20 ) ); - PrintError(rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Found double questionmark in translation only. Looks like an encoding problem at Position ")) - .append(nErrorPos).getStr(), - "Text format", aContext, pTestee->GetLineNumber(), pTestee->GetUniqId()); - pTestee->NotOK(); - return sal_True; - } - - return sal_False; -} - - -/*****************************************************************************/ -sal_Bool GSIBlock::CheckSyntax( std::size_t nLine, sal_Bool bRequireSourceLine, sal_Bool bFixTags ) -/*****************************************************************************/ -{ - static LingTest aTester; - sal_Bool bHasError = sal_False; - - if ( !pSourceLine ) - { - if ( bRequireSourceLine ) - { - PrintError( "No source language entry defined!", "File format", "", nLine ); - bHasBlockError = sal_True; - } - } - else - { - aTester.CheckReference( pSourceLine ); - if ( pSourceLine->HasMessages() ) - { - PrintList( pSourceLine->GetMessageList(), "ReferenceString", pSourceLine ); - pSourceLine->NotOK(); - bHasError = sal_True; - } - } - if ( bReference ) - { - if ( !pReferenceLine ) - { - GSILine *pSource; - if ( pSourceLine ) - pSource = pSourceLine; - else - pSource = maList.empty() ? NULL : maList[ 0 ]; // get some other line - if ( pSource ) - PrintError( "No reference line found. Entry is new in source file", "File format", "", pSource->GetLineNumber(), pSource->GetUniqId() ); - else - PrintError( "No reference line found. Entry is new in source file", "File format", "", nLine ); - bHasBlockError = sal_True; - } - else - { - if ( pSourceLine && pSourceLine->data_ != pReferenceLine->data_ ) - { - sal_Int32 nPos = pSourceLine->data_.indexOf( pReferenceLine->data_ ); - rtl::OStringBuffer aContext( pReferenceLine->data_.copy( nPos - 5, 15) ); - aContext.append( "\" --> \"" ).append( pSourceLine->data_.copy( nPos - 5, 15) ); - PrintError( "Source Language Entry has changed.", "File format", aContext.makeStringAndClear(), pSourceLine->GetLineNumber(), pSourceLine->GetUniqId() ); - pSourceLine->NotOK(); - bHasError = sal_True; - } - } - } - - if ( pSourceLine ) - bHasError |= !TestUTF8( pSourceLine, bFixTags ); - - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - { - GSILine* pItem = maList[ i ]; - aTester.CheckTestee( pItem, pSourceLine != NULL, bFixTags ); - if ( pItem->HasMessages() || aTester.HasCompareWarnings() ) - { - if ( pItem->HasMessages() || aTester.GetCompareWarnings().HasErrors() ) - pItem->NotOK(); - bHasError = sal_True; - PrintList( pItem->GetMessageList(), "Translation", pItem ); - PrintList( &(aTester.GetCompareWarnings()), "Translation Tag Mismatch", pItem ); - } - bHasError |= !TestUTF8( pItem, bFixTags ); - if ( pSourceLine ) - bHasError |= HasSuspiciousChars( pItem, pSourceLine ); - } - - return bHasError || bHasBlockError; -} - -void GSIBlock::WriteError( LazyStream &aErrOut, sal_Bool bRequireSourceLine ) -{ - if ( pSourceLine && pSourceLine->IsOK() && bCheckSourceLang && !bHasBlockError ) - return; - - sal_Bool bHasError = sal_False; - sal_Bool bCopyAll = ( !pSourceLine && bRequireSourceLine ) || ( pSourceLine && !pSourceLine->IsOK() && !bCheckTranslationLang ) || bHasBlockError; - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - { - GSILine* pItem = maList[ i ]; - if ( !pItem->IsOK() || bCopyAll ) - { - bHasError = sal_True; - aErrOut.LazyOpen(); - aErrOut << pItem->data_.getStr() << '\n'; - } - } - - if ( pSourceLine && ( bHasError || !pSourceLine->IsOK() ) && !( !bHasError && bCheckTranslationLang ) ) - { - aErrOut.LazyOpen(); - aErrOut << pSourceLine->data_.getStr() << '\n'; - } -} - -void GSIBlock::WriteCorrect( LazyStream &aOkOut, sal_Bool bRequireSourceLine ) -{ - if ( ( !pSourceLine && bRequireSourceLine ) || ( pSourceLine && !pSourceLine->IsOK() && !bCheckTranslationLang ) ) - return; - - sal_Bool bHasOK = sal_False; - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - { - GSILine* pItem = maList[ i ]; - if ( ( pItem->IsOK() || bCheckSourceLang ) && !bHasBlockError ) - { - bHasOK = sal_True; - aOkOut.LazyOpen(); - aOkOut << pItem->data_.getStr() << '\n'; - } - } - - if ( ( pSourceLine && pSourceLine->IsOK() && ( !maList.empty() || !bCheckTranslationLang ) ) || ( bHasOK && bCheckTranslationLang ) ) - { - aOkOut.LazyOpen(); - aOkOut << pSourceLine->data_.getStr() << '\n'; - } -} - -void GSIBlock::WriteFixed( LazyStream &aFixOut ) -{ - if ( pSourceLine && !pSourceLine->IsFixed() && bCheckSourceLang ) - return; - - sal_Bool bHasFixes = sal_False; - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - { - GSILine* pItem = maList[ i ]; - if ( pItem->IsFixed() ) - { - bHasFixes = sal_True; - aFixOut.LazyOpen(); - aFixOut << pItem->data_.getStr() << '\n'; - } - } - - if ( pSourceLine && ( bHasFixes || pSourceLine->IsFixed() ) ) - { - aFixOut.LazyOpen(); - aFixOut << pSourceLine->data_.getStr() << '\n'; - } -} - - -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ -/*****************************************************************************/ - -/*****************************************************************************/ -void Help() -/*****************************************************************************/ -{ - fprintf( stdout, "\n" ); - fprintf( stdout, "gsicheck checks the syntax of tags in SDF-Files\n" ); - fprintf( stdout, " checks for inconsistencies and malicious UTF8 encoding\n" ); - fprintf( stdout, " checks tags in Online Help\n" ); - fprintf( stdout, " relax GID/LID length to %s\n", - rtl::OString::valueOf(static_cast(MAX_GID_LID_LEN)).getStr() ); - fprintf( stdout, "\n" ); - fprintf( stdout, "Syntax: gsicheck [ -c ] [-f] [ -we ] [ -wef ErrorFilename ] [ -wc ]\n" ); - fprintf( stdout, " [ -wcf CorrectFilename ] [ -s | -t ] [ -l LanguageID ]\n" ); - fprintf( stdout, " [ -r ReferenceFile ] filename\n" ); - fprintf( stdout, "\n" ); - fprintf( stdout, "-c Add context to error message (Print the line containing the error)\n" ); - fprintf( stdout, "-f try to fix errors. See also -wf -wff \n" ); - fprintf( stdout, "-wf Write File containing all fixed parts\n" ); - fprintf( stdout, "-wff Same as above but give own filename\n" ); - fprintf( stdout, "-we Write File containing all errors\n" ); - fprintf( stdout, "-wef Same as above but give own filename\n" ); - fprintf( stdout, "-wc Write File containing all correct parts\n" ); - fprintf( stdout, "-wcf Same as above but give own filename\n" ); - fprintf( stdout, "-s Check only source language. Should be used before handing out to vendor.\n" ); - fprintf( stdout, "-t Check only Translation language(s). Should be used before merging.\n" ); - fprintf( stdout, "-e disable encoding checks. E.g.: double questionmark \'??\' which may be the\n" ); - fprintf( stdout, " result of false conversions\n" ); - fprintf( stdout, "-l ISO language code of the source language.\n" ); - fprintf( stdout, " Default is en-US. Use \"\" (empty string) or 'none'\n" ); - fprintf( stdout, " to disable source language dependent checks\n" ); - fprintf( stdout, "-r Reference filename to check that source language entries\n" ); - fprintf( stdout, " have not been changed\n" ); - fprintf( stdout, "\n" ); -} - -SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { - sal_Bool bError = sal_False; - sal_Bool bPrintContext = sal_False; - sal_Bool bCheckSourceLang = sal_False; - sal_Bool bCheckTranslationLang = sal_False; - sal_Bool bWriteError = sal_False; - sal_Bool bWriteCorrect = sal_False; - sal_Bool bWriteFixed = sal_False; - sal_Bool bFixTags = sal_False; - sal_Bool bAllowSuspicious = sal_False; - rtl::OString aErrorFilename; - rtl::OString aCorrectFilename; - rtl::OString aFixedFilename; - sal_Bool bFileHasError = sal_False; - rtl::OString aSourceLang( "en-US" ); // English is default - rtl::OString aFilename; - rtl::OString aReferenceFilename; - sal_Bool bReferenceFile = sal_False; - for ( int i = 1 ; i < argc ; i++ ) - { - if ( *argv[ i ] == '-' ) - { - switch (*(argv[ i ]+1)) - { - case 'c':bPrintContext = sal_True; - break; - case 'w': - { - if ( (*(argv[ i ]+2)) == 'e' ) - { - if ( (*(argv[ i ]+3)) == 'f' ) - if ( (i+1) < argc ) - { - aErrorFilename = argv[i + 1]; - bWriteError = sal_True; - i++; - } - else - { - fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] ); - bError = sal_True; - } - else - bWriteError = sal_True; - } - else if ( (*(argv[ i ]+2)) == 'c' ) - if ( (*(argv[ i ]+3)) == 'f' ) - if ( (i+1) < argc ) - { - aCorrectFilename = argv[i + 1]; - bWriteCorrect = sal_True; - i++; - } - else - { - fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] ); - bError = sal_True; - } - else - bWriteCorrect = sal_True; - else if ( (*(argv[ i ]+2)) == 'f' ) - if ( (*(argv[ i ]+3)) == 'f' ) - if ( (i+1) < argc ) - { - aFixedFilename = argv[i + 1]; - bWriteFixed = sal_True; - bFixTags = sal_True; - i++; - } - else - { - fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] ); - bError = sal_True; - } - else - { - bWriteFixed = sal_True; - bFixTags = sal_True; - } - else - { - fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] ); - bError = sal_True; - } - } - break; - case 's':bCheckSourceLang = sal_True; - break; - case 't':bCheckTranslationLang = sal_True; - break; - case 'l': - { - if ( (i+1) < argc ) - { - aSourceLang = argv[ i+1 ]; - if ( aSourceLang.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("none")) ) - aSourceLang = rtl::OString(); - i++; - } - else - { - fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] ); - bError = sal_True; - } - } - break; - case 'r': - { - if ( (i+1) < argc ) - { - aReferenceFilename = argv[ i+1 ]; - bReferenceFile = sal_True; - i++; - } - else - { - fprintf( stderr, "\nERROR: Switch %s requires parameter!\n\n", argv[ i ] ); - bError = sal_True; - } - } - break; - case 'f': - { - bFixTags = sal_True; - } - break; - case 'e': - { - bAllowSuspicious = sal_True; - } - break; - default: - fprintf( stderr, "\nERROR: Unknown Switch %s!\n\n", argv[ i ] ); - bError = sal_True; - } - } - else - { - if (aFilename.isEmpty()) - aFilename = argv[i]; - else - { - fprintf( stderr, "\nERROR: Only one filename may be specified!\n\n"); - bError = sal_True; - } - } - } - - - if (aFilename.isEmpty() || bError) - { - Help(); - exit ( 0 ); - } - - if ( !aSourceLang.isEmpty() && !LanguageOK( aSourceLang ) ) - { - fprintf( stderr, "\nERROR: The Language '%s' is invalid!\n\n", aSourceLang.getStr() ); - Help(); - exit ( 1 ); - } - - if ( bCheckSourceLang && bCheckTranslationLang ) - { - fprintf( stderr, "\nERROR: The Options -s and -t are mutually exclusive.\nUse only one of them.\n\n" ); - Help(); - exit ( 1 ); - } - - - - std::ifstream aGSI(aFilename.getStr()); - if (!aGSI.is_open()) { - fprintf( stderr, "\nERROR: Could not open GSI-File %s!\n\n", aFilename.getStr() ); - exit ( 3 ); - } - - std::ifstream aReferenceGSI; - if ( bReferenceFile ) - { - aReferenceGSI.open(aReferenceFilename.getStr()); - if (!aReferenceGSI.is_open()) { - fprintf( stderr, "\nERROR: Could not open Input-File %s!\n\n", aFilename.getStr() ); - exit ( 3 ); - } - } - - LazyStream aOkOut; - if ( bWriteCorrect ) - { - if (aCorrectFilename.isEmpty()) - { - aCorrectFilename = addSuffix( - aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_ok"))); - } - aOkOut.SetFileName(aCorrectFilename); - } - - LazyStream aErrOut; - if ( bWriteError ) - { - if (aErrorFilename.isEmpty()) - { - aErrorFilename = addSuffix( - aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_err"))); - } - aErrOut.SetFileName(aErrorFilename); - } - - LazyStream aFixOut; - if ( bWriteFixed ) - { - if (aFixedFilename.isEmpty()) - { - aFixedFilename = addSuffix( - aFilename, rtl::OString(RTL_CONSTASCII_STRINGPARAM("_fix"))); - } - aFixOut.SetFileName(aFixedFilename); - } - - - GSILine* pReferenceLine = NULL; - std::size_t nReferenceLine = 0; - - GSILine* pGSILine = NULL; - rtl::OString aOldId("No Valid ID"); // just set to something which can never be an ID - GSIBlock *pBlock = NULL; - std::size_t nLine = 0; - - while (!aGSI.eof()) - { - std::string s; - std::getline(aGSI, s); - nLine++; - pGSILine = new GSILine(rtl::OString(s.data(), s.length()), nLine ); - sal_Bool bDelete = sal_True; - - - if ( !pGSILine->data_.isEmpty() ) - { - if ( FORMAT_UNKNOWN == pGSILine->GetLineFormat() ) - { - PrintError( "Format of line is unknown. Ignoring!", "Line format", pGSILine->data_.copy( 0,40 ), bPrintContext, pGSILine->GetLineNumber() ); - pGSILine->NotOK(); - if ( bWriteError ) - { - bFileHasError = sal_True; - aErrOut.LazyOpen(); - aErrOut << pGSILine->data_.getStr(); - } - } - else if ( pGSILine->GetLineType().equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("res-comment")) ) - { // ignore comment lines, but write them to Correct Items File - if ( bWriteCorrect ) - { - aOkOut.LazyOpen(); - aOkOut << pGSILine->data_.getStr() << '\n'; - } - } - else - { - rtl::OString aId = pGSILine->GetUniqId(); - if ( aId != aOldId ) - { - if ( pBlock ) - { - bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags ); - - if ( bWriteError ) - pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() ); - if ( bWriteCorrect ) - pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() ); - if ( bWriteFixed ) - pBlock->WriteFixed( aFixOut ); - - delete pBlock; - } - pBlock = new GSIBlock( bPrintContext, bCheckSourceLang, bCheckTranslationLang, bReferenceFile, bAllowSuspicious ); - - aOldId = aId; - - - // find corresponding line in reference file - if ( bReferenceFile ) - { - sal_Bool bContinueSearching = sal_True; - while ( ( !aReferenceGSI.eof() || pReferenceLine ) && bContinueSearching ) - { - if ( !pReferenceLine ) - { - std::string s2; - std::getline(aReferenceGSI, s2); - nReferenceLine++; - pReferenceLine = new GSILine( - rtl::OString(s2.data(), s2.length()), - nReferenceLine); - } - if ( pReferenceLine->GetLineFormat() != FORMAT_UNKNOWN ) - { - if ( pReferenceLine->GetUniqId() == aId && pReferenceLine->GetLanguageId() == aSourceLang ) - { - pBlock->SetReferenceLine( pReferenceLine ); - pReferenceLine = NULL; - } - else if ( pReferenceLine->GetUniqId() > aId ) - { - bContinueSearching = sal_False; - } - else - { - if ( pReferenceLine->GetUniqId() < aId && pReferenceLine->GetLanguageId() == aSourceLang ) - PrintError( "No Entry in source file found. Entry has been removed from source file", "File format", "", bPrintContext, pGSILine->GetLineNumber(), pReferenceLine->GetUniqId() ); - delete pReferenceLine; - pReferenceLine = NULL; - } - } - else - { - delete pReferenceLine; - pReferenceLine = NULL; - } - - } - } - - } - - pBlock->InsertLine( pGSILine, aSourceLang ); - bDelete = sal_False; - } - } - if ( bDelete ) - delete pGSILine; - - } - if ( pBlock ) - { - bFileHasError |= pBlock->CheckSyntax( nLine, !aSourceLang.isEmpty(), bFixTags ); - - if ( bWriteError ) - pBlock->WriteError( aErrOut, !aSourceLang.isEmpty() ); - if ( bWriteCorrect ) - pBlock->WriteCorrect( aOkOut, !aSourceLang.isEmpty() ); - if ( bWriteFixed ) - pBlock->WriteFixed( aFixOut ); - - delete pBlock; - } - aGSI.close(); - - if ( bWriteError ) - aErrOut.close(); - if ( bWriteCorrect ) - aOkOut.close(); - if ( bWriteFixed ) - aFixOut.close(); - - if ( bFileHasError ) - return 55; - else - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/l10ntools/source/tagtest.cxx b/l10ntools/source/tagtest.cxx deleted file mode 100644 index ada1a36582f1..000000000000 --- a/l10ntools/source/tagtest.cxx +++ /dev/null @@ -1,1570 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * 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 . - */ - -#include "sal/config.h" - -#include "rtl/strbuf.hxx" -#include "rtl/string.hxx" -#include "rtl/ustrbuf.hxx" -#include "rtl/ustring.hxx" - -#include "tagtest.hxx" - -#if OSL_DEBUG_LEVEL > 1 -#include -#endif - -#include "gsicheck.hxx" -#include "helper.hxx" - -#define HAS_FLAG( nFlags, nFlag ) ( ( nFlags & nFlag ) != 0 ) -#define SET_FLAG( nFlags, nFlag ) ( nFlags |= nFlag ) -#define RESET_FLAG( nFlags, nFlag ) ( nFlags &= ~nFlag ) // ~ = Bitweises NOT - - - -TokenInfo::TokenInfo( TokenId pnId, sal_Int32 nP, rtl::OUString const & paStr, ParserMessageList &rErrorList ) -: bClosed(sal_False) -, bCloseTag(sal_False) -, bIsBroken(sal_False) -, bHasBeenFixed(sal_False) -, bDone(sal_False) -, aTokenString( paStr ) -, nId( pnId ) -, nPos(nP) -{ - if ( nId == TAG_COMMONSTART || nId == TAG_COMMONEND ) - SplitTag( rErrorList ); -} - -enum tagcheck { TC_START, TC_HAS_TAG_NAME, TC_HAS_PROP_NAME_EQ, TC_HAS_PROP_NAME_EQ_SP, TC_HAS_PROP_NAME_SP, TC_INSIDE_STRING, TC_PROP_FINISHED, TC_CLOSED, TC_CLOSED_SPACE, TC_CLOSETAG, TC_CLOSETAG_HAS_TAG_NAME, TC_FINISHED, TC_ERROR }; - -/* - \< link href = \"text\" name = \"C\" \> -START ' ' -> HAS_TAG_NAME -START '/' -> CLOSED -START '/' -> CLOSETAG - no Portion (starting with /) -START '>' -> FINISHED -HAS_TAG_NAME '=' -> HAS_PROP_NAME_EQ -HAS_TAG_NAME ' ' -> HAS_PROP_NAME_SP -HAS_TAG_NAME '/' -> CLOSED -HAS_TAG_NAME '>' -> FINISHED -HAS_PROP_NAME_SP '=' -> HAS_PROP_NAME_EQ -HAS_PROP_NAME_EQ ' ' -> HAS_PROP_NAME_EQ_SP -HAS_PROP_NAME_EQ '"' -> INSIDE_STRING -HAS_PROP_NAME_EQ_SP '"' -> INSIDE_STRING -INSIDE_STRING ' ' -> INSIDE_STRING -INSIDE_STRING '=' -> INSIDE_STRING -INSIDE_STRING '>' -> INSIDE_STRING -INSIDE_STRING '"' -> PROP_FINISHED -PROP_FINISHED ' ' -> HAS_TAG_NAME -PROP_FINISHED '/' -> CLOSED -PROP_FINISHED '>' -> FINISHED -CLOSED ' ' -> CLOSED_SPACE -CLOSED '>' -> FINISHED -CLOSED_SPACE '>' -> FINISHED - -CLOSETAG ' ' -> CLOSETAG_HAS_TAG_NAME -CLOSETAG '>' -> FINISHED -CLOSETAG_HAS_TAG_NAME '>' -> FINISHED - -*/ -void TokenInfo::SplitTag( ParserMessageList &rErrorList ) -{ - sal_Int32 nLastPos = 2; // skip initial \< - sal_Int32 nCheckPos = nLastPos; - static char const aDelims[] = " \\=>/"; - rtl::OUString aPortion; - rtl::OUString aValue; // store the value of a property - rtl::OString aName; // store the name of a property/tag - sal_Bool bCheckName = sal_False; - sal_Bool bCheckEmpty = sal_False; - sal_Unicode cDelim; - tagcheck aState = TC_START; - - // skip blanks - while ( nLastPos < aTokenString.getLength() && aTokenString[nLastPos] == ' ') - nLastPos++; - - nCheckPos = helper::indexOfAnyAsciiL( - aTokenString, RTL_CONSTASCII_STRINGPARAM(aDelims), nLastPos); - while ( nCheckPos != -1 && !( aState == TC_FINISHED || aState == TC_ERROR ) ) - { - aPortion = aTokenString.copy( nLastPos, nCheckPos-nLastPos ); - - if ( aTokenString[nCheckPos] == '\\' ) - nCheckPos++; - - cDelim = aTokenString[nCheckPos]; - nCheckPos++; - - switch ( aState ) - { -// START ' ' -> HAS_TAG_NAME -// START '/' -> CLOSED -// START '>' -> FINISHED - case TC_START: - aTagName = aPortion; - switch ( cDelim ) - { - case ' ': aState = TC_HAS_TAG_NAME; - bCheckName = sal_True; - break; - case '/': - { - if (aPortion.isEmpty()) - { - aState = TC_CLOSETAG; - } - else - { - aState = TC_CLOSED; - bCheckName = sal_True; - } - } - break; - case '>': aState = TC_FINISHED; - bCheckName = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// HAS_TAG_NAME '=' -> HAS_PROP_NAME_EQ -// HAS_TAG_NAME ' ' -> HAS_PROP_NAME_SP -// HAS_TAG_NAME '/' -> CLOSED -// HAS_TAG_NAME '>' -> FINISHED - case TC_HAS_TAG_NAME: - switch ( cDelim ) - { - case '=': aState = TC_HAS_PROP_NAME_EQ; - bCheckName = sal_True; - break; - case ' ': aState = TC_HAS_PROP_NAME_SP; - bCheckName = sal_True; - break; - case '/': aState = TC_CLOSED; - bCheckEmpty = sal_True; - break; - case '>': aState = TC_FINISHED; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// HAS_PROP_NAME_SP '=' -> HAS_PROP_NAME_EQ - case TC_HAS_PROP_NAME_SP: - switch ( cDelim ) - { - case '=': aState = TC_HAS_PROP_NAME_EQ; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// HAS_PROP_NAME_EQ ' ' -> HAS_PROP_NAME_EQ_SP -// HAS_PROP_NAME_EQ '"' -> INSIDE_STRING - case TC_HAS_PROP_NAME_EQ: - switch ( cDelim ) - { - case ' ': aState = TC_HAS_PROP_NAME_EQ_SP; - bCheckEmpty = sal_True; - break; - case '\"': aState = TC_INSIDE_STRING; - bCheckEmpty = sal_True; - aValue = rtl::OUString(); - break; - default: aState = TC_ERROR; - } - break; - -// HAS_PROP_NAME_EQ_SP '"' -> INSIDE_STRING - case TC_HAS_PROP_NAME_EQ_SP: - switch ( cDelim ) - { - case '\"': aState = TC_INSIDE_STRING; - bCheckEmpty = sal_True; - aValue = rtl::OUString(); - break; - default: aState = TC_ERROR; - } - break; - -// INSIDE_STRING * -> INSIDE_STRING -// INSIDE_STRING '"' -> PROP_FINISHED - case TC_INSIDE_STRING: - switch ( cDelim ) - { - case '\"': - { - aState = TC_PROP_FINISHED; - aValue += aPortion; - if ( aProperties.find( aName ) == aProperties.end() ) - { - if ( !IsPropertyValueValid( aName, aValue ) ) - { - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Property '")).append(aName).append(RTL_CONSTASCII_STRINGPARAM("' has invalid value '")).append(rtl::OUStringToOString(aValue, RTL_TEXTENCODING_UTF8)).append("' ").makeStringAndClear(), *this ); - bIsBroken = sal_True; - } - aProperties[ aName ] = aValue; - } - else - { - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Property '")).append(aName).append(RTL_CONSTASCII_STRINGPARAM("' defined twice ")).makeStringAndClear(), *this ); - bIsBroken = sal_True; - } - } - break; - default: - { - aState = TC_INSIDE_STRING; - aValue += aPortion; - aValue += rtl::OUString(cDelim); - } - } - break; - -// PROP_FINISHED ' ' -> HAS_TAG_NAME -// PROP_FINISHED '/' -> CLOSED -// PROP_FINISHED '>' -> FINISHED - case TC_PROP_FINISHED: - switch ( cDelim ) - { - case ' ': aState = TC_HAS_TAG_NAME; - bCheckEmpty = sal_True; - break; - case '/': aState = TC_CLOSED; - bCheckEmpty = sal_True; - break; - case '>': aState = TC_FINISHED; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// CLOSED ' ' -> CLOSED_SPACE -// CLOSED '>' -> FINISHED - case TC_CLOSED: - switch ( cDelim ) - { - case ' ': aState = TC_CLOSED_SPACE; - bCheckEmpty = sal_True; - bClosed = sal_True; - break; - case '>': aState = TC_FINISHED; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// CLOSED_SPACE '>' -> FINISHED - case TC_CLOSED_SPACE: - switch ( cDelim ) - { - case '>': aState = TC_FINISHED; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// CLOSETAG ' ' -> CLOSETAG_HAS_TAG_NAME -// CLOSETAG '>' -> FINISHED - case TC_CLOSETAG: - bCloseTag = sal_True; - switch ( cDelim ) - { - case ' ': aState = TC_CLOSETAG_HAS_TAG_NAME; - aTagName = aPortion; - bCheckName = sal_True; - break; - case '>': aState = TC_FINISHED; - aTagName = aPortion; - bCheckName = sal_True; - break; - default: aState = TC_ERROR; - } - break; - -// CLOSETAG_HAS_TAG_NAME '>' -> FINISHED - case TC_CLOSETAG_HAS_TAG_NAME: - switch ( cDelim ) - { - case '>': aState = TC_FINISHED; - bCheckEmpty = sal_True; - break; - default: aState = TC_ERROR; - } - break; - - - default: rErrorList.AddError( 99, "Internal error Parsing Tag ", *this ); - bIsBroken = sal_True; - - } - - if ( bCheckName ) - { - if (aPortion.isEmpty()) - { - rErrorList.AddError( 25, "Tag/Property name missing ", *this ); - bIsBroken = sal_True; - } - else - { - aName = rtl::OUStringToOString(aPortion, RTL_TEXTENCODING_UTF8); - // "a-zA-Z_-.0-9" - sal_Bool bBroken = sal_False; - const sal_Char* aBuf = aName.getStr(); - for (sal_Int32 nCount = 0 ; !bBroken && nCount < aName.getLength() ; ++nCount) - { - bBroken = ! ( ( aBuf[nCount] >= 'a' && aBuf[nCount] <= 'z' ) - ||( aBuf[nCount] >= 'A' && aBuf[nCount] <= 'Z' ) - ||( aBuf[nCount] >= '0' && aBuf[nCount] <= '9' ) - ||( aBuf[nCount] == '_' ) - ||( aBuf[nCount] == '-' ) - ||( aBuf[nCount] == '.' ) - ); - } - - if ( bBroken ) - { - rErrorList.AddError( 25, "Found illegal character in Tag/Property name ", *this ); - bIsBroken = sal_True; - } - } - - bCheckName = sal_False; - } - - if ( bCheckEmpty ) - { - if (!aPortion.isEmpty()) - { - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Found displaced characters '")).append(rtl::OUStringToOString(aPortion, RTL_TEXTENCODING_UTF8)).append(RTL_CONSTASCII_STRINGPARAM("' in Tag ")).makeStringAndClear(), *this ); - bIsBroken = sal_True; - } - bCheckEmpty = sal_False; - } - - - nLastPos = nCheckPos; - - // skip further blanks - if ( cDelim == ' ' && aState != TC_INSIDE_STRING ) - while ( nLastPos < aTokenString.getLength() && aTokenString[nLastPos] == ' ') - nLastPos++; - - nCheckPos = helper::indexOfAnyAsciiL( - aTokenString, RTL_CONSTASCII_STRINGPARAM(aDelims), nLastPos); - } - if ( aState != TC_FINISHED ) - { - rErrorList.AddError( 25, "Parsing error in Tag ", *this ); - bIsBroken = sal_True; - } -} - -sal_Bool TokenInfo::IsPropertyRelevant( const rtl::OString &rName, const rtl::OUString &rValue ) const -{ - if ( aTagName == "alt" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("xml-lang")) ) - return sal_False; - if ( aTagName == "ahelp" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("visibility")) && rValue == "visible" ) - return sal_False; - if ( aTagName == "image" && (rName.equalsL(RTL_CONSTASCII_STRINGPARAM("width")) || rName.equalsL(RTL_CONSTASCII_STRINGPARAM("height"))) ) - return sal_False; - - return sal_True; -} - -sal_Bool TokenInfo::IsPropertyValueValid( const rtl::OString &rName, const rtl::OUString &rValue ) const -{ -/* removed due to i56740 - if ( aTagName.EqualsAscii( "switchinline" ) && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("select")) ) - { - return rValue.EqualsAscii("sys") || - rValue.EqualsAscii("appl") || - rValue.EqualsAscii("distrib"); - } */ - if ( aTagName == "caseinline" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("select")) ) - { - return !rValue.isEmpty(); - } - - // we don't know any better so we assume it to be OK - return sal_True; -} - -sal_Bool TokenInfo::IsPropertyInvariant( const rtl::OString &rName, const rtl::OUString &rValue ) const -{ - if ( aTagName == "link" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("name")) ) - return sal_False; - if ( aTagName == "link" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("href")) ) - { // check for external reference - return - !(rValue.matchIgnoreAsciiCaseAsciiL( - RTL_CONSTASCII_STRINGPARAM("http:")) - || rValue.matchIgnoreAsciiCaseAsciiL( - RTL_CONSTASCII_STRINGPARAM("https:")) - || rValue.matchIgnoreAsciiCaseAsciiL( - RTL_CONSTASCII_STRINGPARAM("ftp:"))); - } - return sal_True; -} - -sal_Bool TokenInfo::IsPropertyFixable( const rtl::OString &rName ) const -{ - // name everything that is allowed to be fixed automatically here - if ( (aTagName == "ahelp" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("hid"))) - || (aTagName == "link" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("href"))) - || (aTagName == "alt" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("id"))) - || (aTagName == "variable" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("id"))) - || (aTagName == "image" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("src"))) - || (aTagName == "image" && rName.equalsL(RTL_CONSTASCII_STRINGPARAM("id")) )) - return sal_True; - return sal_False; -} - -sal_Bool TokenInfo::MatchesTranslation( TokenInfo& rInfo, sal_Bool bGenErrors, ParserMessageList &rErrorList, sal_Bool bFixTags ) const -{ - // check if tags are equal - // check if all existing properties are in the translation as well and - // whether they have a matching content (the same in most cases) - - if ( nId != rInfo.nId ) - return sal_False; - - if ( aTagName != rInfo.aTagName ) - return sal_False; - - // If one of the tags has formating errors already it does make no sense to check here, so return right away - if ( bGenErrors && ( bIsBroken || rInfo.bIsBroken ) ) - return sal_True; - - StringHashMap::const_iterator iProp; - for( iProp = aProperties.begin() ; iProp != aProperties.end(); ++iProp ) - { - if ( rInfo.aProperties.find( iProp->first ) != rInfo.aProperties.end() ) - { - if ( IsPropertyRelevant( iProp->first, iProp->second ) || IsPropertyRelevant( iProp->first, rInfo.aProperties.find( iProp->first )->second ) ) - { - if ( IsPropertyInvariant( iProp->first, iProp->second ) ) - { - if ( rInfo.aProperties.find( iProp->first )->second != iProp->second ) - { - if ( bGenErrors ) - { - if ( bFixTags && IsPropertyFixable( iProp->first ) ) - { - rInfo.aProperties.find( iProp->first )->second = iProp->second; - rInfo.SetHasBeenFixed(); - rErrorList.AddWarning( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Property '")).append(iProp->first).append(RTL_CONSTASCII_STRINGPARAM("': FIXED different value in Translation ")).makeStringAndClear(), *this ); - } - else - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Property '")).append(iProp->first).append(RTL_CONSTASCII_STRINGPARAM("': value different in Translation ")).makeStringAndClear(), *this ); - } - else return sal_False; - } - } - } - } - else - { - if ( IsPropertyRelevant( iProp->first, iProp->second ) ) - { - if ( bGenErrors ) - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Property '")).append(iProp->first).append(RTL_CONSTASCII_STRINGPARAM("' missing in Translation ")).makeStringAndClear(), *this ); - else return sal_False; - } - } - } - for( iProp = rInfo.aProperties.begin() ; iProp != rInfo.aProperties.end(); ++iProp ) - { - if ( aProperties.find( iProp->first ) == aProperties.end() ) - { - if ( IsPropertyRelevant( iProp->first, iProp->second ) ) - { - if ( bGenErrors ) - rErrorList.AddError( 25, rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM("Extra Property '")).append(iProp->first).append(RTL_CONSTASCII_STRINGPARAM("' in Translation ")).makeStringAndClear(), rInfo ); - else return sal_False; - } - } - } - - // if we reach here eather - // the tags match completely or - // the tags match but not the properties and we generated errors for that - return sal_True; -} - -rtl::OUString TokenInfo::GetTagName() const -{ - return aTagName; -} - -rtl::OUString TokenInfo::MakeTag() const -{ - rtl::OUStringBuffer aRet; - aRet.appendAscii("\\<"); - if ( bCloseTag ) - aRet.appendAscii("/"); - aRet.append( GetTagName() ); - StringHashMap::const_iterator iProp; - - for( iProp = aProperties.begin() ; iProp != aProperties.end(); ++iProp ) - { - aRet.appendAscii(" "); - aRet.append( rtl::OStringToOUString( iProp->first, RTL_TEXTENCODING_UTF8 ) ); - aRet.appendAscii("=\\\""); - aRet.append( iProp->second ); - aRet.appendAscii("\\\""); - } - if ( bClosed ) - aRet.appendAscii("/"); - aRet.appendAscii("\\>"); - return aRet.makeStringAndClear(); -} - - -void ParserMessageList::AddError( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag ) -{ - maList.push_back( new ParserError( nErrorNr, rErrorText, rTag ) ); -} - -void ParserMessageList::AddWarning( sal_Int32 nErrorNr, const rtl::OString& rErrorText, const TokenInfo &rTag ) -{ - maList.push_back( new ParserWarning( nErrorNr, rErrorText, rTag ) ); -} - -sal_Bool ParserMessageList::HasErrors() -{ - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - if ( maList[ i ]->IsError() ) - return sal_True; - return sal_False; -} - -void ParserMessageList::clear() -{ - for ( size_t i = 0, n = maList.size(); i < n; ++i ) - delete maList[ i ]; - maList.clear(); -} - -struct Tag -{ - rtl::OUString GetName() const { return rtl::OUString::createFromAscii( pName ); }; - const char* pName; - TokenId nTag; -}; - - -static const Tag aKnownTags[] = -{ -/* commenting oldstyle tags -// { "<#GROUP_FORMAT>", TAG_GROUP_FORMAT }, - { "<#BOLD>", TAG_BOLDON }, - { "<#/BOLD>", TAG_BOLDOFF }, - { "<#ITALIC>", TAG_ITALICON }, - { "<#/ITALIC>", TAG_ITALICOFF }, - { "<#UNDER>", TAG_UNDERLINEON }, - { "<#/UNDER>", TAG_UNDERLINEOFF }, - -// { "<#GROUP_NOTALLOWED>", TAG_GROUP_NOTALLOWED }, - { "<#HELPID>", TAG_HELPID }, - { "<#MODIFY>", TAG_MODIFY }, - { "<#REFNR>", TAG_REFNR }, - -// { "<#GROUP_STRUCTURE>", TAG_GROUP_STRUCTURE }, - { "<#NAME>", TAG_NAME }, - { "<#HREF>", TAG_HREF }, - { "<#AVIS>", TAG_AVIS }, - { "<#AHID>", TAG_AHID }, - { "<#AEND>", TAG_AEND }, - - { "<#TITEL>", TAG_TITEL }, - { "<#KEY>", TAG_KEY }, - { "<#INDEX>", TAG_INDEX }, - - { "<#REFSTART>", TAG_REFSTART }, - - { "<#GRAPHIC>", TAG_GRAPHIC }, - { "<#NEXTVERSION>", TAG_NEXTVERSION }, - - // { "<#GROUP_SYSSWITCH>", TAG_GROUP_SYSSWITCH }, - { "<#WIN>", TAG_WIN }, - { "<#UNIX>", TAG_UNIX }, - { "<#MAC>", TAG_MAC }, - { "<#OS2>", TAG_OS2 }, - -// { "<#GROUP_PROGSWITCH>", TAG_GROUP_PROGSWITCH }, - { "<#WRITER>", TAG_WRITER }, - { "<#CALC>", TAG_CALC }, - { "<#DRAW>", TAG_DRAW }, - { "<#IMPRESS>", TAG_IMPRESS }, - { "<#SCHEDULE>", TAG_SCHEDULE }, - { "<#IMAGE>", TAG_IMAGE }, - { "<#MATH>", TAG_MATH }, - { "<#CHART>", TAG_CHART }, - { "<#OFFICE>", TAG_OFFICE }, - */ -// { "<#TAG_GROUP_META>", TAG_GROUP_META }, - { "$[officefullname]", TAG_OFFICEFULLNAME }, - { "$[officename]", TAG_OFFICENAME }, - { "$[officepath]", TAG_OFFICEPATH }, - { "$[officeversion]", TAG_OFFICEVERSION }, - { "$[portalname]", TAG_PORTALNAME }, - { "$[portalfullname]", TAG_PORTALFULLNAME }, - { "$[portalpath]", TAG_PORTALPATH }, - { "$[portalversion]", TAG_PORTALVERSION }, - { "$[portalshortname]", TAG_PORTALSHORTNAME }, -/* commenting oldstyle tags -// { "<#TAG_GROUP_SINGLE>", TAG_GROUP_SINGLE }, - { "<#REFINSERT>", TAG_REFINSERT }, - -// { "<#GROUP_MULTI>", TAG_GROUP_MULTI }, - { "<#END>", TAG_END }, - { "<#ELSE>", TAG_ELSE }, - { "<#VERSIONEND>", TAG_VERSIONEND }, - { "<#ENDGRAPHIC>", TAG_ENDGRAPHIC },*/ - { "", TAG_COMMONSTART }, - { "", TAG_COMMONEND }, - - { "", TAG_NOMORETAGS }, - { "", TAG_UNKNOWN_TAG }, -}; - - -SimpleParser::SimpleParser() -: nPos( 0 ) -, aNextTag( TAG_NOMORETAGS, TOK_INVALIDPOS ) -{ -} - -void SimpleParser::Parse( rtl::OUString const & PaSource ) -{ - aSource = PaSource; - nPos = 0; - aLastToken = rtl::OUString(); - aNextTag = TokenInfo( TAG_NOMORETAGS, TOK_INVALIDPOS ); - aTokenList.clear(); -}; - -TokenInfo SimpleParser::GetNextToken( ParserMessageList &rErrorList ) -{ - TokenInfo aResult; - sal_Int32 nTokenStartPos = 0; - if ( aNextTag.nId != TAG_NOMORETAGS ) - { - aResult = aNextTag; - aNextTag = TokenInfo( TAG_NOMORETAGS, TOK_INVALIDPOS ); - } - else - { - aLastToken = GetNextTokenString( rErrorList, nTokenStartPos ); - if ( aLastToken.isEmpty() ) - return TokenInfo( TAG_NOMORETAGS, TOK_INVALIDPOS ); - - // do we have a \< ... \> style tag? - if (aLastToken.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("\\<"))) - { - // check for paired \" \" - bool bEven = true; - sal_Int32 nQuotePos = 0; - sal_Int32 nQuotedQuotesPos = - aLastToken.indexOfAsciiL(RTL_CONSTASCII_STRINGPARAM("\\\"")); - sal_Int32 nQuotedBackPos = aLastToken.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\\")); - // this is only to kick out quoted backslashes - while (nQuotedQuotesPos != -1) - { - if ( nQuotedBackPos != -1 && nQuotedBackPos <= nQuotedQuotesPos ) - nQuotePos = nQuotedBackPos+2; - else - { - nQuotePos = nQuotedQuotesPos+2; - bEven = !bEven; - } - nQuotedQuotesPos = aLastToken.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\""), nQuotePos); - nQuotedBackPos = aLastToken.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\\"), nQuotePos); - // this is only to kick out quoted backslashes - } - if ( !bEven ) - { - rErrorList.AddError( 24, "Missing quotes ( \\\" ) in Tag", TokenInfo( TAG_UNKNOWN_TAG, nTokenStartPos, aLastToken ) ); - } - - // check if we have an end-tag or a start-tag - sal_Int32 nNonBlankStartPos = 2; - while (aLastToken[nNonBlankStartPos] == ' ') - nNonBlankStartPos++; - if (aLastToken[nNonBlankStartPos] == '/') - aResult = TokenInfo( TAG_COMMONEND, nTokenStartPos, aLastToken, rErrorList ); - else - { - aResult = TokenInfo( TAG_COMMONSTART, nTokenStartPos, aLastToken, rErrorList ); - sal_Int32 nNonBlankEndPos = aLastToken.getLength() - 3; - while (aLastToken[nNonBlankEndPos] == ' ') - nNonBlankEndPos--; - if (aLastToken[nNonBlankEndPos] == '/') - aNextTag = TokenInfo( TAG_COMMONEND, nTokenStartPos, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\")), rErrorList ); - } - } - else - { - sal_Int32 i = 0; - while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG && - aLastToken != aKnownTags[i].GetName() ) - i++; - aResult = TokenInfo( aKnownTags[i].nTag, nTokenStartPos ); - } - } - - if ( aResult.nId == TAG_UNKNOWN_TAG ) - aResult = TokenInfo( TAG_UNKNOWN_TAG, nTokenStartPos, aLastToken ); - aTokenList.insert( aResult ); - return aResult; -} - -rtl::OUString SimpleParser::GetNextTokenString( ParserMessageList &rErrorList, sal_Int32 &rTagStartPos ) -{ - sal_Int32 nStyle2StartPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("$["), nPos ); - sal_Int32 nStyle3StartPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\<"), nPos); - sal_Int32 nStyle4StartPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\\"), nPos); - // this is only to kick out quoted backslashes - - rTagStartPos = 0; - - if (nStyle2StartPos == -1 && nStyle3StartPos == -1) - return rtl::OUString(); // no more tokens - - if ( nStyle4StartPos != -1 - && (nStyle2StartPos == -1 || nStyle4StartPos < nStyle2StartPos) - && (nStyle3StartPos == -1 || nStyle4StartPos < nStyle3StartPos ) ) - // to make sure \\ is always handled first - { // Skip quoted Backslash - nPos = nStyle4StartPos +2; - return GetNextTokenString( rErrorList, rTagStartPos ); - } - - if ( nStyle2StartPos != -1 && ( nStyle3StartPos == -1 || nStyle2StartPos < nStyle3StartPos ) ) - { // test for $[ ... ] style tokens - sal_Int32 nEndPos = aSource.indexOf(']', nStyle2StartPos); - if (nEndPos == -1) - { // Token is incomplete. Skip start and search for better ones - nPos = nStyle2StartPos +2; - return GetNextTokenString( rErrorList, rTagStartPos ); - } - nPos = nEndPos; - rTagStartPos = nStyle2StartPos; - return aSource.copy(nStyle2StartPos, nEndPos - nStyle2StartPos + 1); - } - else - { // test for \< ... \> style tokens - sal_Int32 nEndPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\>"), nStyle3StartPos); - sal_Int32 nQuotedBackPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\\"), nStyle3StartPos); - // this is only to kick out quoted backslashes - while (nQuotedBackPos <= nEndPos && nQuotedBackPos != -1) - { - nEndPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\>"), nQuotedBackPos + 2); - nQuotedBackPos = aSource.indexOfAsciiL( - RTL_CONSTASCII_STRINGPARAM("\\\\"), nQuotedBackPos + 2); - // this is only to kick out quoted backslashes - } - if (nEndPos == -1) - { // Token is incomplete. Skip start and search for better ones - nPos = nStyle3StartPos +2; - rErrorList.AddError( 24, "Tag Start '\\<' without Tag End '\\>'", TokenInfo( TAG_UNKNOWN_TAG, nStyle3StartPos, helper::abbreviate(aSource, nStyle3StartPos - 10, 20) ) ); - return GetNextTokenString( rErrorList, rTagStartPos ); - } - // check for paired quoted " --> \"sometext\" - - nPos = nEndPos; - rTagStartPos = nStyle3StartPos; - return aSource.copy(nStyle3StartPos, nEndPos-nStyle3StartPos + 2); - } -} - -rtl::OUString SimpleParser::GetLexem( TokenInfo const &aToken ) -{ - if ( !aToken.aTokenString.isEmpty() ) - return aToken.aTokenString; - else - { - sal_Int32 i = 0; - while ( aKnownTags[i].nTag != TAG_UNKNOWN_TAG && - aKnownTags[i].nTag != aToken.nId ) - i++; - - return aKnownTags[i].GetName(); - } -} - -TokenParser::TokenParser() -: pErrorList( NULL ) -{} - -void TokenParser::Parse( const rtl::OUString &aCode, ParserMessageList* pList ) -{ - pErrorList = pList; - - //Scanner initialisieren - aParser.Parse( aCode ); - - //erstes Symbol holen - aTag = aParser.GetNextToken( *pErrorList ); - - nPfCaseOptions = 0; - nAppCaseOptions = 0; - bPfCaseActive = sal_False; - bAppCaseActive = sal_False; - - nActiveRefTypes = 0; - - //Ausfuehren der Start-Produktion - Paragraph(); - - //Es wurde nicht die ganze Kette abgearbeitet, bisher ist aber - //kein Fehler aufgetreten - //=> es wurde ein einleitendes Tag vergessen - if ( aTag.nId != TAG_NOMORETAGS ) - { - switch ( aTag.nId ) - { - case TAG_END: - { - ParseError( 3, "Extra Tag <#END>. Switch or <#HREF> expected.", aTag ); - } - break; - case TAG_BOLDOFF: - { - ParseError( 4, "<#BOLD> expected before <#/BOLD>.", aTag ); - } - break; - case TAG_ITALICOFF: - { - ParseError( 5, "<#ITALIC> expected before <#/ITALIC>.", aTag ); - } - break; - case TAG_UNDERLINEOFF: - { - ParseError( 17, "<#UNDER> expected before <#/UNDER>.", aTag ); - } - break; - case TAG_AEND: - { - ParseError( 5, "Extra Tag <#AEND>. <#AVIS> or <#AHID> expected.", aTag ); - } - break; - case TAG_ELSE: - { - ParseError( 16, "Application-tag or platform-tag expected before <#ELSE>.", aTag ); - } - break; - case TAG_UNKNOWN_TAG: - { - ParseError( 6, "unknown Tag", aTag ); - } - break; - default: - { - ParseError( 6, "unexpected Tag", aTag ); - } - } - } - pErrorList = NULL; -} - -void TokenParser::Paragraph() -{ - switch ( aTag.nId ) - { - case TAG_GRAPHIC: - case TAG_NEXTVERSION: - { - TagRef(); - Paragraph(); - } - break; - case TAG_AVIS: - case TAG_AHID: - { - TagRef(); - Paragraph(); - } - break; - case TAG_HELPID: - { - SimpleTag(); - Paragraph(); - } - break; - case TAG_OFFICEFULLNAME: - case TAG_OFFICENAME: - case TAG_OFFICEPATH: - case TAG_OFFICEVERSION: - case TAG_PORTALNAME: - case TAG_PORTALFULLNAME: - case TAG_PORTALPATH: - case TAG_PORTALVERSION: - case TAG_PORTALSHORTNAME: - { - SimpleTag(); - Paragraph(); - } - break; - case TAG_REFINSERT: - { - SimpleTag(); - Paragraph(); - } - break; - case TAG_BOLDON: - case TAG_ITALICON: - case TAG_UNDERLINEON: - case TAG_COMMONSTART: - { - TagPair(); - Paragraph(); - } - break; - case TAG_HREF: - case TAG_NAME: - case TAG_KEY: - case TAG_INDEX: - case TAG_TITEL: - case TAG_REFSTART: - { - TagRef(); - Paragraph(); - } - break; - case TAG_WIN: - case TAG_UNIX: - case TAG_MAC: //... - { - if ( ! bPfCaseActive ) - { - //PfCases duerfen nicht verschachtelt sein: - bPfCaseActive = sal_True; - PfCase(); - - //So jetzt kann wieder ein PfCase kommen: - bPfCaseActive = sal_False; - Paragraph(); - } - } - break; - case TAG_WRITER: - case TAG_CALC: - case TAG_DRAW: - case TAG_IMPRESS: - case TAG_SCHEDULE: - case TAG_IMAGE: - case TAG_MATH: - case TAG_CHART: - case TAG_OFFICE: - { - if ( !bAppCaseActive ) - { - //AppCases duerfen nicht verschachtelt sein: - bAppCaseActive = sal_True; - AppCase(); - - //jetzt koennen wieder AppCases kommen: - bAppCaseActive = sal_False; - Paragraph(); - } - } - break; - - //Case TAG_BOLDOFF, TAG_ITALICOFF, TAG_BUNDERLINE, TAG_END - //nichts tun wg. epsilon-Prod. - } -} - -void TokenParser::PfCase() -{ - - //Produktion: - //PfCase -> PfCaseBegin Paragraph (PfCase | PfCaseEnd) - - PfCaseBegin(); - - //Jetzt ist eine PfCase-Produktion aktiv: - Paragraph(); - switch ( aTag.nId ) - { - case TAG_ELSE: - case TAG_END: - { - CaseEnd(); - } - break; - case TAG_WIN: - case TAG_UNIX: - case TAG_MAC: //First (PfBegin) - { - PfCase(); - } - break; - default: - ParseError( 8, "<#ELSE> or <#END> or platform-tag expected.", aTag ); - } - //Die gemerkten Tags wieder loeschen fuer naechstes PfCase: - nPfCaseOptions = 0; -} - -void TokenParser::PfCaseBegin() -{ - switch ( aTag.nId ) - { - case TAG_WIN: - case TAG_UNIX: - case TAG_MAC: - { - //Token darf noch nicht vorgekommen sein im - //aktuellen Plattform-Case: - if ( !HAS_FLAG( nPfCaseOptions, TAG_NOGROUP( aTag.nId ) ) ) - { - SET_FLAG( nPfCaseOptions, TAG_NOGROUP( aTag.nId ) ); - match( aTag, aTag ); - } - else { - ParseError( 9, "Tag defined twice in the same platform-case", aTag ); - } - } - } -} - -void TokenParser::AppCase() -{ - - //Produktion: - //AppCase -> AppCaseBegin Paragraph (AppCase | AppCaseEnd) - - - AppCaseBegin(); - - Paragraph(); - - switch ( aTag.nId ) - { - case TAG_ELSE: - case TAG_END: - { - CaseEnd(); - } - break; - case TAG_WRITER: - case TAG_DRAW: - case TAG_CALC: - case TAG_IMAGE: - case TAG_MATH: - case TAG_CHART: - case TAG_OFFICE: - case TAG_IMPRESS: - case TAG_SCHEDULE: //First (AppBegin) - { - AppCase(); - } - break; - default: - ParseError( 1, "<#ELSE> or <#END> or application-case-tag expected.", aTag ); - } - - //Die gemerkten Tags wieder loeschen fuer naechstes AppCase: - nAppCaseOptions = 0; -} - -void TokenParser::AppCaseBegin() -{ - switch ( aTag.nId ) - { - case TAG_WRITER: - case TAG_DRAW: - case TAG_CALC: - case TAG_IMAGE: - case TAG_MATH: - case TAG_CHART: - case TAG_OFFICE: - case TAG_IMPRESS: - case TAG_SCHEDULE: - { - //Token darf noch nicht vorgekommen sein im - //aktuellen Plattform-Case: - if ( !HAS_FLAG( nAppCaseOptions, TAG_NOGROUP( aTag.nId ) ) ) - { - SET_FLAG( nAppCaseOptions, TAG_NOGROUP( aTag.nId ) ); - match( aTag, aTag ); - } - else { - ParseError( 13, "Tag defined twice in the same application-case.", aTag ); - } - } - } -} - -void TokenParser::CaseEnd() -{ - //Produktion: - //CaseEnd -> <#ELSE> Paragraph <#END> | <#END> - - switch ( aTag.nId ) - { - case TAG_ELSE: - { - match( aTag, TAG_ELSE ); - Paragraph(); - match( aTag, TAG_END ); - } - break; - case TAG_END: - { - match( aTag, TAG_END ); - } - break; - default: - ParseError( 2, "<#ELSE> or <#END> expected.", aTag ); - } -} - -void TokenParser::SimpleTag() -{ - - switch ( aTag.nId ) - { - case TAG_HELPID: - { - match( aTag, TAG_HELPID ); - } - break; - case TAG_OFFICEFULLNAME: - case TAG_OFFICENAME: - case TAG_OFFICEPATH: - case TAG_OFFICEVERSION: - case TAG_PORTALNAME: - case TAG_PORTALFULLNAME: - case TAG_PORTALPATH: - case TAG_PORTALVERSION: - case TAG_PORTALSHORTNAME: - - case TAG_REFINSERT: - { - match( aTag, aTag ); - } - break; - default: - ParseError( 15, "[<#SimpleTag>] expected.", aTag ); - } -} - -void TokenParser::TagPair() -{ - switch ( aTag.nId ) - { - case TAG_BOLDON: - { - match( aTag, TAG_BOLDON ); - Paragraph(); - match( aTag, TAG_BOLDOFF ); - } - break; - case TAG_ITALICON: - { - match( aTag, TAG_ITALICON ); - Paragraph(); - match( aTag, TAG_ITALICOFF ); - } - break; - case TAG_UNDERLINEON: - { - match( aTag, TAG_UNDERLINEON ); - Paragraph(); - match( aTag, TAG_UNDERLINEOFF ); - } - break; - case TAG_COMMONSTART: - { - //remember tag so we can give the original tag in case of an error - TokenInfo aEndTag( aTag ); - aEndTag.nId = TAG_COMMONEND; - match( aTag, TAG_COMMONSTART ); - Paragraph(); - match( aTag, aEndTag ); - } - break; - default: - ParseError( 10, "<#BOLD>, <#ITALIC>, <#UNDER> expected.", aTag ); - } -} - - -void TokenParser::TagRef() -{ - switch ( aTag.nId ) - { - case TAG_GRAPHIC: - case TAG_NEXTVERSION: - { - if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) ) - { - TokenId aThisToken = aTag.nId; - SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - match( aTag, aTag ); - Paragraph(); - if ( aThisToken == TAG_GRAPHIC ) - match( aTag, TAG_ENDGRAPHIC ); - else - match( aTag, TAG_VERSIONEND ); - // don't reset since alowed only once per paragraph - // RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - } - else - { - ParseError( 11, "Tags <#GRAPHIC>,<#NEXTVERSION> allowed only once per paragraph at", aTag ); - } - } - break; - case TAG_AVIS: - case TAG_AHID: - { - if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) ) - { - TokenId aThisToken = aTag.nId; - SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - match( aTag, aTag ); - Paragraph(); - match( aTag, TAG_AEND ); - RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - } - else - { - ParseError( 11, "Nested <#AHID>,<#AVIS> not allowed.", aTag ); - } - } - break; - case TAG_HREF: - case TAG_NAME: - { - - } - // NOBREAK - case TAG_KEY: - case TAG_INDEX: - case TAG_TITEL: - case TAG_REFSTART: - { - if ( !HAS_FLAG( nActiveRefTypes, TAG_NOGROUP( aTag.nId ) ) ) - { - TokenId aThisToken = aTag.nId; - match( aTag, aTag ); - if ( aThisToken != TAG_NAME ) - { // TAG_NAME has no TAG_END - SET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - Paragraph(); - match( aTag, TAG_END ); - RESET_FLAG( nActiveRefTypes, TAG_NOGROUP( aThisToken ) ); - } - } - else - { - ParseError( 11, "Nested <#HREF>,<#NAME> or <#KEY> not allowed.", aTag ); - } - } - break; - default: - ParseError( 12, "<#HREF>,<#NAME> or <#KEY> expected.", aTag ); - } -} - -sal_Bool TokenParser::match( const TokenInfo &aCurrentToken, const TokenId &aExpectedToken ) -{ - return match( aCurrentToken, TokenInfo( aExpectedToken, TOK_INVALIDPOS ) ); -} - -sal_Bool TokenParser::match( const TokenInfo &aCurrentToken, const TokenInfo &rExpectedToken ) -{ - TokenInfo aExpectedToken( rExpectedToken ); - if ( aCurrentToken.nId == aExpectedToken.nId ) - { - if ( ( aCurrentToken.nId == TAG_COMMONEND - && aCurrentToken.GetTagName() == aExpectedToken.GetTagName() ) - || aCurrentToken.nId != TAG_COMMONEND ) - { - aTag = aParser.GetNextToken( *pErrorList ); - return sal_True; - } - } - - if ( aExpectedToken.nId == TAG_COMMONEND ) - { - aExpectedToken.aTokenString = - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Close tag for ")) - + aExpectedToken.aTokenString; - } - - rtl::OString sTmp(RTL_CONSTASCII_STRINGPARAM("Expected Symbol")); - if ( aCurrentToken.nId == TAG_NOMORETAGS ) - { - ParseError( 7, sTmp, aExpectedToken ); - } - else - { - rtl::OStringBuffer aBuf(sTmp); - aBuf.append(": "). - append(rtl::OUStringToOString(aParser.GetLexem( aExpectedToken ), RTL_TEXTENCODING_UTF8)). - append(RTL_CONSTASCII_STRINGPARAM(" near ")); - ParseError( 7, aBuf.makeStringAndClear(), aCurrentToken ); - } - return sal_False; -} - -void TokenParser::ParseError( sal_Int32 nErrNr, const rtl::OString &rErrMsg, const TokenInfo &rTag ) -{ - pErrorList->AddError( nErrNr, rErrMsg, rTag); - - // Das Fehlerhafte Tag ueberspringen - aTag = aParser.GetNextToken( *pErrorList ); -} - - -ParserMessage::ParserMessage( sal_Int32 PnErrorNr, const rtl::OString &rPaErrorText, const TokenInfo &rTag ) - : nErrorNr( PnErrorNr ) - , nTagBegin( 0 ) - , nTagLength( 0 ) -{ - rtl::OUString aLexem( SimpleParser::GetLexem( rTag ) ); - rtl::OStringBuffer aErrorBuffer(rPaErrorText); - aErrorBuffer.append(RTL_CONSTASCII_STRINGPARAM(": ")); - aErrorBuffer.append(rtl::OUStringToOString(aLexem, RTL_TEXTENCODING_UTF8)); - if ( rTag.nId == TAG_NOMORETAGS ) - aErrorBuffer.append(RTL_CONSTASCII_STRINGPARAM(" at end of line ")); - else if ( rTag.nPos != TOK_INVALIDPOS ) - { - aErrorBuffer.append(RTL_CONSTASCII_STRINGPARAM(" at Position ")); - aErrorBuffer.append(static_cast(rTag.nPos)); - } - aErrorText = aErrorBuffer.makeStringAndClear(); - nTagBegin = rTag.nPos; - nTagLength = aLexem.getLength(); -} - -ParserError::ParserError( sal_Int32 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag ) -: ParserMessage( ErrorNr, rErrorText, rTag ) -{} - -ParserWarning::ParserWarning( sal_Int32 ErrorNr, const rtl::OString &rErrorText, const TokenInfo &rTag ) -: ParserMessage( ErrorNr, rErrorText, rTag ) -{} - -sal_Bool LingTest::IsTagMandatory( TokenInfo const &aToken, TokenId &aMetaTokens ) -{ - TokenId aTokenId = aToken.nId; - TokenId aTokenGroup = TAG_GROUP( aTokenId ); - if ( TAG_GROUP_PROGSWITCH == aTokenGroup - || TAG_REFINSERT == aTokenId - || TAG_REFSTART == aTokenId - || TAG_NAME == aTokenId - || TAG_HREF == aTokenId - || TAG_AVIS == aTokenId - || TAG_AHID == aTokenId - || TAG_GRAPHIC == aTokenId - || TAG_NEXTVERSION == aTokenId - || ( TAG_GROUP_META == aTokenGroup && (aMetaTokens & aTokenId) == aTokenId ) ) - { - if ( TAG_GROUP_META == aTokenGroup ) - aMetaTokens |= aTokenId; - return sal_True; - } - else if ( TAG_COMMONSTART == aTokenId - || TAG_COMMONEND == aTokenId ) - { - rtl::OUString aTagName = aToken.GetTagName(); - return !(aTagName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("comment")) - || aTagName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("bookmark_value")) - || aTagName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("emph")) - || aTagName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("item")) - || aTagName.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("br")) ); - } - return sal_False; -} - -void LingTest::CheckTags( TokenList &aReference, TokenList &aTestee, sal_Bool bFixTags ) -{ - size_t i=0,j=0; - // Clean old Warnings - aCompareWarningList.clear(); - - /* in xml tags, do not require the following tags - comment - bookmark_value - emph - item - br - */ - - // filter uninteresting Tags - TokenId aMetaTokens = 0; - for ( i=0 ; i < aReference.size() ; i++ ) - { - if ( !IsTagMandatory( aReference[ i ], aMetaTokens ) ) - aReference[ i ].SetDone(); - } - - aMetaTokens = 0; - for ( i=0 ; i < aTestee.size() ; i++ ) - { - if ( !IsTagMandatory( aTestee[ i ], aMetaTokens ) ) - aTestee[ i ].SetDone(); - } - - // remove all matching tags - for ( i=0 ; i < aReference.size() ; i++ ) - { - if ( aReference[ i ].IsDone() ) - continue; - - sal_Bool bTagFound = sal_False; - for ( j=0 ; j < aTestee.size() && !bTagFound ; j++ ) - { - if ( aTestee[ j ].IsDone() ) - continue; - - if ( aReference[ i ].MatchesTranslation( aTestee[ j ], sal_False, aCompareWarningList ) ) - { - aReference[ i ].SetDone(); - aTestee[ j ].SetDone(); - bTagFound = sal_True; - } - } - } - - sal_Bool bCanFix = sal_True; - - if ( bFixTags ) - { - // we fix only if its a really simple case - sal_Int32 nTagCount = 0; - for ( i=0 ; i < aReference.size() ; i++ ) - if ( !aReference[ i ].IsDone() ) - nTagCount++; - if ( nTagCount > 1 ) - bCanFix = sal_False; - - nTagCount = 0; - for ( i=0 ; i < aTestee.size() ; i++ ) - if ( !aTestee[ i ].IsDone() ) - nTagCount++; - if ( nTagCount > 1 ) - bCanFix = sal_False; - } - - // generate errors for tags that have differing attributes - for ( i=0 ; i < aReference.size() ; i++ ) - { - if ( aReference[ i ].IsDone() ) - continue; - - sal_Bool bTagFound = sal_False; - for ( j=0 ; j < aTestee.size() && !bTagFound ; j++ ) - { - if ( aTestee[ j ].IsDone() ) - continue; - - if ( aReference[ i ].MatchesTranslation( aTestee[ j ], sal_True, aCompareWarningList, bCanFix && bFixTags ) ) - { - aReference[ i ].SetDone(); - aTestee[ j ].SetDone(); - bTagFound = sal_True; - } - } - } - - // list remaining tags as errors - for ( i=0 ; i < aReference.size() ; i++ ) - { - if ( aReference[ i ].IsDone() ) - continue; - - aCompareWarningList.AddError( 20, "Missing Tag in Translation", aReference[ i ] ); - } - for ( i=0 ; i < aTestee.size() ; i++ ) - { - if ( aTestee[ i ].IsDone() ) - continue; - - aCompareWarningList.AddError( 21, "Extra Tag in Translation", aTestee[ i ] ); - } - - for ( i=0 ; i < aReference.size() ; i++ ) - aReference[ i ].SetDone( sal_False ); - - for ( i=0 ; i < aTestee.size() ; i++ ) - aTestee[ i ].SetDone( sal_False ); -} - -void LingTest::CheckReference( GSILine *aReference ) -{ - aReferenceParser.Parse( aReference->GetUText(), aReference->GetMessageList() ); -} - -void LingTest::CheckTestee( GSILine *aTestee, sal_Bool bHasSourceLine, sal_Bool bFixTags ) -{ - aFixedTestee = aTestee->GetUText(); - aTesteeParser.Parse( aFixedTestee, aTestee->GetMessageList() ); - - if ( bHasSourceLine ) - CheckTags( aReferenceParser.GetTokenList(), aTesteeParser.GetTokenList(), bFixTags ); - - if ( bFixTags ) - { - TokenList& aTesteeTokens = aTesteeParser.GetTokenList(); - sal_Bool bFixesDone = sal_False; - // count backwards to allow replacing from right to left - int i; - for ( i = aTesteeTokens.size() ; i > 0 ; ) - { - if ( aTesteeTokens[ --i ].HasBeenFixed() ) - { - bFixesDone = sal_True; - aFixedTestee = aFixedTestee.replaceAt( aTesteeTokens[ i ].nPos, aTesteeTokens[ i ].aTokenString.getLength(), aTesteeTokens[ i ].MakeTag() ); - } - } - if ( bFixesDone ) - { - aTestee->SetUText( aFixedTestee ); - aTestee->SetFixed(); - } - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit From 6cfa7552eebf69daab1ed3acc2a9954d52f00aad Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Tue, 13 Nov 2012 21:55:18 +0100 Subject: fix XML tag check in help and readme translations Change-Id: I88a3ad382df41da96fcab38c3c06d5871228e082 --- l10ntools/source/helper.hxx | 46 ++++++++++++++++++++++++++++++++++++++++++ l10ntools/source/helpmerge.cxx | 2 +- l10ntools/source/xrmmerge.cxx | 4 ++-- 3 files changed, 49 insertions(+), 3 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx index 1e28aa6c4d50..1d268dd1c0f7 100644 --- a/l10ntools/source/helper.hxx +++ b/l10ntools/source/helper.hxx @@ -39,6 +39,7 @@ #include "rtl/string.hxx" #include "rtl/ustring.hxx" +#include "rtl/strbuf.hxx" #include "sal/types.h" namespace helper { @@ -102,6 +103,50 @@ inline sal_Int32 indexOfAnyAsciiL( return -1; } +rtl::OString QuotHTML(const rtl::OString &rString) +{ + rtl::OStringBuffer sReturn; + for (sal_Int32 i = 0; i < rString.getLength(); ++i) { + switch (rString[i]) { + case '\\': + if (i < rString.getLength()) { + switch (rString[i + 1]) { + case '"': + case '<': + case '>': + case '\\': + ++i; + break; + } + } + // fall through + default: + sReturn.append(rString[i]); + break; + + case '<': + sReturn.append("<"); + break; + + case '>': + sReturn.append(">"); + break; + + case '"': + sReturn.append("""); + break; + + case '&': + if (rString.matchL(RTL_CONSTASCII_STRINGPARAM("&"), i)) + sReturn.append('&'); + else + sReturn.append(RTL_CONSTASCII_STRINGPARAM("&")); + break; + } + } + return sReturn.makeStringAndClear(); +} + inline bool isWellFormedXML( OString const & text ) { xmlDocPtr doc; @@ -120,6 +165,7 @@ inline bool isWellFormedXML( OString const & text ) return result; } + template< typename T > inline T abbreviate( T const & text, sal_Int32 start, sal_Int32 length) { diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index aab255f75a05..8764935ced2c 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -380,7 +380,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const rtl::OString& sCur , nPreSpaces++; pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); OUString sNewdata; - if (helper::isWellFormedXML(sNewText)) + if (helper::isWellFormedXML(helper::QuotHTML(sNewText))) { sNewdata = sSourceText.copy(0,nPreSpaces) + rtl::OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index b4868f5f8623..5b562ea7f627 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -609,7 +609,6 @@ void XRMResMerge::WorkOnText( sContent, STRING_TYP_TEXT, sLang )) && ( sContent != "-" ) && !sContent.isEmpty() && helper::isWellFormedXML( sContent )) - { rText = sContent; ConvertStringToXMLFormat( rText ); @@ -645,7 +644,8 @@ void XRMResMerge::EndOfText( if (!sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")) && ( pEntrys->GetText( sContent, STRING_TYP_TEXT, sCur, sal_True )) && - ( sContent != "-" ) && !sContent.isEmpty()) + ( sContent != "-" ) && !sContent.isEmpty() && + helper::isWellFormedXML( sContent )) { rtl::OString sText( sContent ); rtl::OString sAdditionalLine( "\n " ); -- cgit From f6147cbe1c6097314a91299cb8a352bb40eeb4d6 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Fri, 16 Nov 2012 18:19:13 +0100 Subject: Handle dictionaries in the same way in localize By now, not needed to handle dictionaries in other way, because its root moves up directly to core. Change-Id: I90d6a67c90b00eea290f17e277fb13c0a6b0b5cd --- l10ntools/source/localize.cxx | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index 107d516cd354..8b3e94fbd0ef 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -267,15 +267,10 @@ void handleCommand( { const sal_Int32 nProjectInd = inPath.indexOf(project); const OString relativPath = - project == OUString("dictionaries") ? - OUStringToOString( - inPath.copy( nProjectInd + 13, - inPath.lastIndexOf('/')- nProjectInd - 13), - RTL_TEXTENCODING_UTF8 ) : - OUStringToOString( - inPath.copy( nProjectInd, - inPath.lastIndexOf('/')- nProjectInd), - RTL_TEXTENCODING_UTF8 ); + OUStringToOString( + inPath.copy( nProjectInd, + inPath.lastIndexOf('/')- nProjectInd), + RTL_TEXTENCODING_UTF8 ); rPoOutPut.writeHeader(PoHeader(relativPath)); } -- cgit From fea5e609ba800118cdb5d84c8bd78d00e86e003e Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Fri, 16 Nov 2012 16:33:19 +0100 Subject: Last changes in renewpo for migration Order PoEntries by their locations in original po files by adding serialnumber in po2lo and work up them in this order in renewpo. So the order will be the same in new po files. Change-Id: Idb0547a2e1262008b374fe450ec3e01af0cff839 --- l10ntools/scripts/po2lo | 33 ++++++---- l10ntools/source/renewpo.cxx | 139 +++++++++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 79 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/scripts/po2lo b/l10ntools/scripts/po2lo index 579699102710..6303c63a6fa7 100755 --- a/l10ntools/scripts/po2lo +++ b/l10ntools/scripts/po2lo @@ -41,7 +41,7 @@ class Entry: """Represents a single line in an SDF file.""" def __init__(self, items): - self.has_translation = None; + self.has_po = None self.items = items # list of 15 fields path = self.items[1].split('\\') self.po = "%s/%s/%s.po" % (options.input.replace('\\', '/'), self.items[0], "/".join(path[:-1])) @@ -67,15 +67,17 @@ class Entry: self.items[9] = options.language self.items[2] = "" - self.has_translation = False + self.has_po = False for idx, key in self.keys: try: - if translations.data[(self.po, key)][1]: + self.items[8] = str(translations.snumber[(self.po, key)]) + self.has_po = True + (text, fuzzy) = translations.data[(self.po, key)] + if fuzzy: self.items[2] += "1" else: self.items[2] += "0" - self.items[idx] = translations.data[(self.po, key)][0] - self.has_translation = True + self.items[idx] = text self.items[14] = "2002-02-02 02:02:02" except KeyError: @@ -103,9 +105,10 @@ class Template: sock = xopen(options.output, "w", encoding='utf-8') for line in self.lines: - sock.write("\t".join(line.items)) + temp = "\t".join(line.items) line.translate(translations) - if line.has_translation: + if line.has_po: + sock.write(temp) sock.write("\t".join(line.items)+"\r\n") sock.close() @@ -114,6 +117,8 @@ class Translations: def __init__(self): self.data = {} + self.snumber = {} + counter = 0 for root, dirs, files in os.walk(options.input): for file in files: path = "%s/%s" % (root, file) @@ -125,16 +130,17 @@ class Translations: for line in sock: if line.startswith("#: "): key = line.strip()[3:] + fuzzy = False elif line.startswith("#, fuzzy"): fuzzy = True + elif line.startswith("msgid "): + counter = counter + 1 + self.setserialnumber(path, key, counter) elif line.startswith("msgstr "): trans = line.strip()[8:-1] if len(trans): self.setdata(path, key, trans, fuzzy) - if fuzzy: - fuzzy = False - else: - multiline = False + multiline = False else: buf = [] buf.append(trans) @@ -143,8 +149,6 @@ class Translations: buf.append(line.strip()[1:-1]) elif multiline and not len(line.strip()) and len("".join(buf)): self.setdata(path, key, "".join(buf),fuzzy) - if fuzzy: - fuzzy = False buf = [] multiline = False if multiline and len("".join(buf)): @@ -162,6 +166,9 @@ class Translations: s = s.replace('\\\\', '\\') self.data[(path.replace('\\', '/'), key)] = ( s , fuzzy ) + def setserialnumber(self, path, key, number): + self.snumber[(path.replace('\\', '/'), key)] = ( number ) + def escape_help_text(self, text): """Escapes the help text as it would be in an SDF file.""" diff --git a/l10ntools/source/renewpo.cxx b/l10ntools/source/renewpo.cxx index 32d19d594c09..a9f3321d2c4b 100644 --- a/l10ntools/source/renewpo.cxx +++ b/l10ntools/source/renewpo.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -20,18 +21,18 @@ using namespace std; -//Check wheather the two entry are the same but in different languages -bool IsSameEntry(const OString& rFirstEntry,const OString& rSecEntry) +bool isInSameFile( const OString& rFirstLine, const OString& rSecondLine) { - for(int i = PoEntry::PROJECT; i<=PoEntry::LOCALID;++i) - { - if ( rFirstEntry.getToken(i,'\t') != rSecEntry.getToken(i,'\t') && - i != PoEntry::DUMMY) - return false; - } - return true; + const OString rFirstSource = + rFirstLine.getToken(PoEntry::SOURCEFILE,'\t'); + const OString rSecondSource = + rSecondLine.getToken(PoEntry::SOURCEFILE,'\t'); + return + rFirstSource.copy(0,rFirstSource.lastIndexOf("\\")) == + rSecondSource.copy(0,rSecondSource.lastIndexOf("\\")); } + //Get path of po file OString GetPath(const OString& rPath, const OString& rLine) { @@ -57,8 +58,9 @@ OString DelLocalId(const OString& rLine) } //Renew po files of the actual language -void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, - const OString& rpo2loPath, const OString& rSDFPath) +void HandleLanguage(struct dirent* pLangEntry, const OString& rOldPath, + const OString& rNewPath, const OString& rpo2loPath, + const OString& rSDFPath) { const OString LangEntryName = pLangEntry->d_name; @@ -83,35 +85,69 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, const OString SDFFileName = OUStringToOString(aTempPath, RTL_TEXTENCODING_UTF8); system( (rpo2loPath + - " -i " + rPath + "/" + LangEntryName + + " -i " + rOldPath + "/" + LangEntryName + " -o " + SDFFileName + " -l " + LangEntryName + " -t " + rSDFPath).getStr()); cout << "Language sdf is ready!" << endl; - PoOfstream aNewPo; + //Store info for po entries ifstream aSDFInput(SDFFileName.getStr()); + map > aPoInfos; string s; getline(aSDFInput,s); - OString sLine = OString(s.data(),s.length()); while(!aSDFInput.eof()) { - OString sActUnTrans = sLine; - const OString sPath = rPath + "/"+ LangEntryName; - const OString sActSourcePath = GetPath(sPath,sActUnTrans); + //Get strings belong to one po entry and store + const OString sActUnTrans = OString(s.data(),s.length()); + if( sActUnTrans.getToken(PoEntry::LANGUAGEID,'\t')=="ast" ) throw; + getline(aSDFInput,s); + const OString sActTrans = OString(s.data(),s.length()); + + if(!(aPoInfos.insert( pair >( + sActTrans.getToken(PoEntry::WIDTH,'\t').toInt32(), + pair(sActUnTrans,sActTrans))).second)) + { + cerr << "Error: faild to insert into map!" << '\n'; + throw; + } + getline(aSDFInput,s); + } + + //Close and remove sdf file + aSDFInput.close(); + if (osl::File::remove(aTempUrl) != osl::FileBase::E_None) + { + cerr << "Warning: failure removing temporary " << aTempUrl << '\n'; + } + + //Construct and write out po entries + PoOfstream aNewPo; + for( map >::iterator + pActInfo=aPoInfos.begin(); pActInfo!=aPoInfos.end(); ++pActInfo ) + { //Make new po file and add header - if (!aNewPo.isOpen()) + if ( pActInfo==aPoInfos.begin() || + !isInSameFile(((--pActInfo)++)->second.first,pActInfo->second.first) ) { - const OString sNewPoFileName = sActSourcePath + ".po_tmp"; + if( pActInfo!=aPoInfos.begin() ) + aNewPo.close(); + + const OString sNewPoFileName = + GetPath(rNewPath + "/" +LangEntryName,pActInfo->second.first) + + ".po"; + system(("mkdir -p " + sNewPoFileName.copy(0,sNewPoFileName.lastIndexOf("/"))).getStr()); aNewPo.open(sNewPoFileName); if (!aNewPo.isOpen()) { cerr - << "Cannot open temp file for new po: " + << "Cannot open new po file: " << sNewPoFileName.getStr() << endl; return; } - const OString sOldPoFileName = sActSourcePath + ".po"; + const OString sOldPoFileName = + GetPath(rOldPath + "/" +LangEntryName,pActInfo->second.first) + + ".po"; ifstream aOldPo(sOldPoFileName.getStr()); if (!aOldPo.is_open()) { @@ -124,19 +160,7 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, aOldPo.close(); } - //Set PoEntry and write out - getline(aSDFInput,s); - OString sActTrans; - if (!aSDFInput.eof() && - IsSameEntry(sActUnTrans,sLine = OString(s.data(),s.length()))) - { - sActTrans = sLine; - getline(aSDFInput,s); - } - else - { - sActTrans =""; - } + //Write out po entries const PoEntry::TYPE vInitializer[] = { PoEntry::TTEXT, PoEntry::TQUICKHELPTEXT, PoEntry::TTITLE }; const vector vTypes( vInitializer, @@ -144,28 +168,28 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, unsigned short nDummyBit = 0; for( unsigned short nIndex=0; nIndexsecond.first.getToken(vTypes[nIndex],'\t').isEmpty()) { /**Because of xrmex there are duplicated id's, - only use this if xrmex have already fixed*/ + only use this if xrmex have already fixed*/ const OString sSource = - sActUnTrans.getToken(PoEntry::SOURCEFILE,'\t'); + pActInfo->second.first.getToken(PoEntry::SOURCEFILE,'\t'); const OString sEnding = sSource.copy(sSource.getLength()-4, 4); - if (sActUnTrans.getToken(PoEntry::GROUPID,'\t')== - sActUnTrans.getToken(PoEntry::LOCALID,'\t') && + if (pActInfo->second.first.getToken(PoEntry::GROUPID,'\t')== + pActInfo->second.first.getToken(PoEntry::LOCALID,'\t') && ( sEnding == ".xrm" || sEnding == ".xml" )) { - sActUnTrans = DelLocalId(sActUnTrans); + pActInfo->second.first = DelLocalId(pActInfo->second.first); } try { - PoEntry aPE(sActUnTrans, vTypes[nIndex]); + PoEntry aPE(pActInfo->second.first, vTypes[nIndex]); const OString sActStr = - sActTrans.getToken(vTypes[nIndex],'\t'); + pActInfo->second.second.getToken(vTypes[nIndex],'\t'); aPE.setMsgStr(sActStr); aPE.setFuzzy( sActStr.isEmpty() ? false : - static_cast(sActTrans.getToken(PoEntry::DUMMY,'\t'). + static_cast(pActInfo->second.second.getToken(PoEntry::DUMMY,'\t'). copy(nDummyBit++,1).toBoolean())); aNewPo.writeEntry(aPE); } @@ -173,28 +197,13 @@ void HandleLanguage(struct dirent* pLangEntry, const OString& rPath, { cerr << "Invalid sdf line " - << sActUnTrans.replaceAll("\t","\\t").getStr() << '\n'; + << pActInfo->second.first.replaceAll("\t","\\t").getStr() << '\n'; } } } - //Check wheather next entry is in the same po file - OString sNextSourcePath = aSDFInput.eof() ? "" : - GetPath(sPath,sLine = OString(s.data(),s.length())); - if (sNextSourcePath!=sActSourcePath) - { - aNewPo.close(); - system(("rm " + sActSourcePath +".po").getStr()); - system(("mv "+ sActSourcePath +".po_tmp " + - sActSourcePath +".po").getStr()); - } - } - - //Close and remove sdf file - aSDFInput.close(); - if (osl::File::remove(aTempUrl) != osl::FileBase::E_None) - { - cerr << "Warning: failure removing temporary " << aTempUrl << '\n'; } + aNewPo.close(); + aPoInfos.clear(); } @@ -203,10 +212,7 @@ int main(int argc, char* argv[]) //Usage if (argc < 4) { - cout << "Use: renewpot translationsdir po2lo en-US.sdf" << endl; - cout << "translationsdir: this directory contains the po" << endl; - cout << "files of all languages. Every language has a" << endl; - cout << "directory named with language id." << endl; + cout << "Use: renewpot oldpots newpots po2lo en-US.sdf" << endl; return 1; } @@ -216,7 +222,8 @@ int main(int argc, char* argv[]) { if ( OString(pActEntry->d_name).indexOf('.')==-1 ) HandleLanguage(pActEntry,OString(argv[1]), - OString(argv[2]),OString(argv[3])); + OString(argv[2]),OString(argv[3]), + OString(argv[4])); } closedir(pTranslations); } -- cgit From 302a099e5264742204b625f1cce949892d8a84f9 Mon Sep 17 00:00:00 2001 From: Ztamas Date: Sun, 18 Nov 2012 12:07:58 +0100 Subject: Write source file into po entries' msgctxt So (msgctxt, msgid) pair is unique in one po file Change-Id: I64635dd7a6352300ed5fb6949a1b78c2a070c660 --- l10ntools/source/po.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 18c0ef1042d4..df9efe31bc64 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -198,7 +198,8 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) const rOFStream << "#, fuzzy" << std::endl; if ( !m_sMsgCtxt.isEmpty() ) rOFStream << "msgctxt " - << lcl_GenMsgString(m_sMsgCtxt).getStr() << std::endl; + << lcl_GenMsgString(m_sReference+"\n"+m_sMsgCtxt).getStr() + << std::endl; rOFStream << "msgid " << lcl_GenMsgString(m_sMsgId).getStr() << std::endl; rOFStream << "msgstr " @@ -251,7 +252,8 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_sMsgStr = lcl_GenNormString(sLine.copy(7)); pLastMsg = &m_sMsgStr; } - else if (sLine.startsWith("\"") && pLastMsg) + else if (sLine.startsWith("\"") && pLastMsg && + (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) { *pLastMsg += lcl_GenNormString(sLine); } -- cgit From 889574a50c8f5bdffed9f3eb70426cedae0a589c Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Sun, 18 Nov 2012 12:47:54 +0100 Subject: put filename into msgctxt, because po entries must be unique Change-Id: I700b668863c2b20cdf60fa672a994b8ae4dc613a --- l10ntools/source/po.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index df9efe31bc64..2ccaed61bb17 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -452,7 +452,8 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); OString sMsgCtxt = - vParts[GROUPID] + "\n" + + vParts[SOURCEFILE].copy(vParts[SOURCEFILE].lastIndexOf("\\")+1) + + "\n" + vParts[GROUPID] + "\n" + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + vParts[RESOURCETYPE]; switch(eType){ @@ -527,7 +528,7 @@ OString PoEntry::getSourceFile() const OString PoEntry::getGroupId() const { assert( m_bIsInitialized ); - return m_pGenPo->getMsgCtxt().getToken(0,'\n'); + return m_pGenPo->getMsgCtxt().getToken(1,'\n'); } //Get localid @@ -538,7 +539,7 @@ OString PoEntry::getLocalId() const if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) return OString(); else - return sMsgCtxt.getToken(1,'\n'); + return sMsgCtxt.getToken(2,'\n'); } //Get the type of component from which entry is extracted @@ -547,9 +548,9 @@ OString PoEntry::getResourceType() const assert( m_bIsInitialized ); const OString sMsgCtxt = m_pGenPo->getMsgCtxt(); if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) - return sMsgCtxt.getToken(1,'\n').getToken(0,'.'); - else return sMsgCtxt.getToken(2,'\n').getToken(0,'.'); + else + return sMsgCtxt.getToken(3,'\n').getToken(0,'.'); } //Get the type of entry -- cgit From 124dc60e5519ee4d1c2454050b6f54a7b020905d Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Sun, 18 Nov 2012 13:04:33 +0100 Subject: Revert "put filename into msgctxt, because po entries must be unique" This reverts commit 889574a50c8f5bdffed9f3eb70426cedae0a589c. --- l10ntools/source/po.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 2ccaed61bb17..df9efe31bc64 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -452,8 +452,7 @@ PoEntry::PoEntry(const OString& rSDFLine, const TYPE eType) copy(vParts[SOURCEFILE].lastIndexOf("\\")+1)); OString sMsgCtxt = - vParts[SOURCEFILE].copy(vParts[SOURCEFILE].lastIndexOf("\\")+1) + - "\n" + vParts[GROUPID] + "\n" + + vParts[GROUPID] + "\n" + (vParts[LOCALID].isEmpty() ? "" : vParts[LOCALID] + "\n") + vParts[RESOURCETYPE]; switch(eType){ @@ -528,7 +527,7 @@ OString PoEntry::getSourceFile() const OString PoEntry::getGroupId() const { assert( m_bIsInitialized ); - return m_pGenPo->getMsgCtxt().getToken(1,'\n'); + return m_pGenPo->getMsgCtxt().getToken(0,'\n'); } //Get localid @@ -539,7 +538,7 @@ OString PoEntry::getLocalId() const if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) return OString(); else - return sMsgCtxt.getToken(2,'\n'); + return sMsgCtxt.getToken(1,'\n'); } //Get the type of component from which entry is extracted @@ -548,9 +547,9 @@ OString PoEntry::getResourceType() const assert( m_bIsInitialized ); const OString sMsgCtxt = m_pGenPo->getMsgCtxt(); if (sMsgCtxt.indexOf('\n')==sMsgCtxt.lastIndexOf('\n')) - return sMsgCtxt.getToken(2,'\n').getToken(0,'.'); + return sMsgCtxt.getToken(1,'\n').getToken(0,'.'); else - return sMsgCtxt.getToken(3,'\n').getToken(0,'.'); + return sMsgCtxt.getToken(2,'\n').getToken(0,'.'); } //Get the type of entry -- cgit From b0f07bbbc4f179d442ff96471669f02e82686657 Mon Sep 17 00:00:00 2001 From: Ztamas Date: Sun, 18 Nov 2012 12:07:58 +0100 Subject: Write source file into po entries' msgctxt So (msgctxt, msgid) pair is unique in one po file Change-Id: I64635dd7a6352300ed5fb6949a1b78c2a070c660 --- l10ntools/source/po.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index df9efe31bc64..ce71207ec3e5 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -255,7 +255,10 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) else if (sLine.startsWith("\"") && pLastMsg && (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) { - *pLastMsg += lcl_GenNormString(sLine); + if ( pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\\n\"" ) + { + *pLastMsg += lcl_GenNormString(sLine); + } } else break; -- cgit From 7f81bbb1c7f090d9e962e5c2cb7b694298bfe1c8 Mon Sep 17 00:00:00 2001 From: Ztamas Date: Sun, 18 Nov 2012 12:07:58 +0100 Subject: Correct skiping source file line of msgctxt Change-Id: I64635dd7a6352300ed5fb6949a1b78c2a070c660 --- l10ntools/source/po.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index ce71207ec3e5..e59db110dcc7 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -252,8 +252,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_sMsgStr = lcl_GenNormString(sLine.copy(7)); pLastMsg = &m_sMsgStr; } - else if (sLine.startsWith("\"") && pLastMsg && - (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) + else if (sLine.startsWith("\"") && pLastMsg) { if ( pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\\n\"" ) { -- cgit From ce48aa1488652ba8b24ada4d62b75aacf3ef6717 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 14:38:47 +0100 Subject: Revert "Correct skiping source file line of msgctxt" This reverts commit 7f81bbb1c7f090d9e962e5c2cb7b694298bfe1c8. --- l10ntools/source/po.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index e59db110dcc7..ce71207ec3e5 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -252,7 +252,8 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_sMsgStr = lcl_GenNormString(sLine.copy(7)); pLastMsg = &m_sMsgStr; } - else if (sLine.startsWith("\"") && pLastMsg) + else if (sLine.startsWith("\"") && pLastMsg && + (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) { if ( pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\\n\"" ) { -- cgit From d15706ec0ac0e1eaec1b95fe0271d17393915e32 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 14:39:17 +0100 Subject: Revert "Write source file into po entries' msgctxt" This reverts commit b0f07bbbc4f179d442ff96471669f02e82686657. --- l10ntools/source/po.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index ce71207ec3e5..df9efe31bc64 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -255,10 +255,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) else if (sLine.startsWith("\"") && pLastMsg && (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) { - if ( pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\\n\"" ) - { - *pLastMsg += lcl_GenNormString(sLine); - } + *pLastMsg += lcl_GenNormString(sLine); } else break; -- cgit From c48c4ace3630451c771afa20080f9bfb7ba05c03 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 14:42:04 +0100 Subject: Correct skipping source file line of msgctxt Change-Id: I7aed7a75c6e9b36efca9837c0137075065bcd1e6 --- l10ntools/source/po.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index df9efe31bc64..648634c2f569 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -252,10 +252,12 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_sMsgStr = lcl_GenNormString(sLine.copy(7)); pLastMsg = &m_sMsgStr; } - else if (sLine.startsWith("\"") && pLastMsg && - (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\"") ) + else if (sLine.startsWith("\"") && pLastMsg) { - *pLastMsg += lcl_GenNormString(sLine); + if (pLastMsg != &m_sMsgCtxt || sLine != "\"" + m_sReference + "\\n\"") + { + *pLastMsg += lcl_GenNormString(sLine); + } } else break; -- cgit From 5d84ae59e70b8b1017959a68934ac1f455ce2b13 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 15:24:44 +0100 Subject: Localize xhp files in help Make helpex to be able to work with more xhp files at one time - Add new input flag "-mi" which means multiinput - Input is a file include pathes to xhp files (these are in the same directory so their strings are in the same po file) - Output is a file include pathes to dest xhp files - Merge reads all po entry from the specified po file if MergeDataFile ctor's second parameter is empty Rewrite makefiles to work with new syntax Plus Delete some unused code Change-Id: I5eb12d7a6f5e9cda378788410d3c50052eb752b8 --- l10ntools/inc/helpmerge.hxx | 2 -- l10ntools/source/helpex.cxx | 80 ++++++++++++++++++++++++++++++++++++++---- l10ntools/source/helpmerge.cxx | 45 ------------------------ l10ntools/source/merge.cxx | 13 +++---- 4 files changed, 80 insertions(+), 60 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/inc/helpmerge.hxx b/l10ntools/inc/helpmerge.hxx index 34dfdc7eb472..401f8392a424 100644 --- a/l10ntools/inc/helpmerge.hxx +++ b/l10ntools/inc/helpmerge.hxx @@ -55,8 +55,6 @@ public: /// point to existing files. bool Merge( const rtl::OString &rSDFFile_in, const rtl::OString &rDestinationFile_in , const rtl::OString& sLanguage , MergeDataFile& aMergeDataFile ); - bool Merge( const rtl::OString &rSDFFile, const rtl::OString &rPathX , const rtl::OString &rPathY , bool bISO - , const std::vector& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir ); private: rtl::OString GetOutpath( const rtl::OString& rPathX , const rtl::OString& sCur , const rtl::OString& rPathY ); diff --git a/l10ntools/source/helpex.cxx b/l10ntools/source/helpex.cxx index 8dca205cf36e..7ab581a2a1d6 100644 --- a/l10ntools/source/helpex.cxx +++ b/l10ntools/source/helpex.cxx @@ -20,6 +20,9 @@ #include "sal/config.h" #include +#include +#include +#include #include #include @@ -30,24 +33,87 @@ #ifndef TESTDRIVER +void WriteUsage() +{ + std::cout + << "Syntax: Helpex [-p Prj] [-r Root] -[m]i FileIn -o FileOut" + << " [-m DataBase] [-l l1,l2,...]\n" + << " Prj: Project\n" + << " Root: Path to project root (../.. etc.)\n" + << " FileIn + i: Source file (*.xhp)\n" + << " FileIn + -mi: File including pathes of source files" + << " (only for merge)" + << " FileOut: Destination file (*.*) or files (in case of -mi)\n" + << " DataBase: Mergedata (*.po)\n" + << " -l: Restrict the handled languages; l1, l2, ... are elements of" + << " (de, en-US, ...)\n"; +} + SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { + + bool bMultiMerge = false; + for (int nIndex = 1; nIndex != argc; ++nIndex) + { + if (std::strcmp(argv[nIndex], "-mi") == 0) + { + argv[nIndex][1] = 'i'; + argv[nIndex][2] = '\0'; + bMultiMerge = true; + break; + } + } + HandledArgs aArgs; - if ( !Export::handleArguments( argc, argv, aArgs) ) { - Export::writeUsage("helpex","xhp"); + if ( !Export::handleArguments( argc, argv, aArgs) ) + { + WriteUsage(); return 1; } - //sal_uInt32 startfull = Export::startMessure(); bool hasNoError = true; - HelpParser aParser( aArgs.m_sInputFile ); if ( aArgs.m_bMergeMode ) { - //sal_uInt64 startreadloc = Export::startMessure(); - MergeDataFile aMergeDataFile( aArgs.m_sMergeSrc, aArgs.m_sInputFile, false ); - hasNoError = aParser.Merge( aArgs.m_sMergeSrc, aArgs.m_sOutputFile , Export::sLanguages , aMergeDataFile ); + if( bMultiMerge ) + { + std::ifstream aInput( aArgs.m_sInputFile.getStr() ); + if( !aInput.is_open() ) + { + std::cerr << "Helpex error: cannot open input file\n"; + return 1; + } + MergeDataFile aMergeDataFile( aArgs.m_sMergeSrc, OString(), false); + std::string sTemp; + aInput >> sTemp; + while( !aInput.eof() ) + { + const OString sXhpFile( sTemp.data(), sTemp.length() ); + HelpParser aParser( sXhpFile ); + const OString sOutput( + aArgs.m_sOutputFile + + sXhpFile.copy( sXhpFile.lastIndexOf("/") )); + if( !aParser.Merge( aArgs.m_sMergeSrc, sOutput, + Export::sLanguages, aMergeDataFile )) + { + hasNoError = false; + } + aInput >> sTemp; + } + aInput.close(); + } + else + { + HelpParser aParser( aArgs.m_sInputFile ); + MergeDataFile aMergeDataFile( + aArgs.m_sMergeSrc, aArgs.m_sInputFile, false ); + hasNoError = + aParser.Merge( + aArgs.m_sMergeSrc, aArgs.m_sOutputFile, + Export::sLanguages , aMergeDataFile ); + } } else { + HelpParser aParser( aArgs.m_sInputFile ); hasNoError = aParser.CreateSDF( aArgs.m_sOutputFile, aArgs.m_sPrj, aArgs.m_sPrjRoot, diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index 8764935ced2c..68f745397378 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -227,51 +227,6 @@ void HelpParser::parse_languages( std::vector& aLanguages , MergeD } -bool HelpParser::Merge( - const rtl::OString &rSDFFile, const rtl::OString &rPathX , const rtl::OString &rPathY , bool bISO , - const std::vector& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir ) -{ - - - (void) rSDFFile ; - bool hasNoError = true; - SimpleXMLParser aParser; - rtl::OUString sXmlFile( - rtl::OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US)); - //TODO: explicit BOM handling? - - XMLFile* xmlfile = aParser.Execute( sXmlFile, new XMLFile( rtl::OUString('0') ) ); - - if( xmlfile == NULL) - { - printf("%s\n", rtl::OUStringToOString(aParser.GetError().sMessage, RTL_TEXTENCODING_UTF8).getStr()); - exit(-1); - } - - xmlfile->Extract(); - - rtl::OString sCur; - for( unsigned int n = 0; n < aLanguages.size(); n++ ){ - sCur = aLanguages[ n ]; - - rtl::OString sFilepath; - if( bISO ) sFilepath = GetOutpath( rPathX , sCur , rPathY ); - else sFilepath = rPathX; - if( bCreateDir ) - MakeDir(sFilepath); - - XMLFile* file = new XMLFile( *xmlfile ); - sFilepath += sHelpFile; - hasNoError = MergeSingleFile( file , aMergeDataFile , sCur , sFilepath ); - delete file; - - if( !hasNoError ) return false; // Stop on error - } - - delete xmlfile; - return hasNoError; -} - bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const rtl::OString& sLanguage , rtl::OString const & sPath ) { diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index 80188f53fb87..73bd8dd7d866 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -150,8 +150,7 @@ sal_Bool MergeData::operator==( ResData *pData ) // MergeDataFile::MergeDataFile( - const rtl::OString &rFileName, - const rtl::OString &rFile, + const rtl::OString &rFileName, const rtl::OString &rFile, bool bCaseSensitive) { std::ifstream aInputStream( rFileName.getStr() ); @@ -167,6 +166,7 @@ MergeDataFile::MergeDataFile( { const OString sHack("HACK"); const OString sFileName( lcl_NormalizeFilename(rFile) ); + const bool bReadAll = sFileName.isEmpty(); PoIfstream aPoInput; aPoInput.open( OString(sPoFileName.data(), sPoFileName.length()) ); if ( !aPoInput.isOpen() ) @@ -212,8 +212,8 @@ MergeDataFile::MergeDataFile( { return; } - } while( !aPoInput.eof() && aNextPo.getSourceFile() != sFileName ); - while( !aPoInput.eof() && aNextPo.getSourceFile() == sFileName ) + } while( !aPoInput.eof() && aNextPo.getSourceFile() != sFileName && !bReadAll ); + while( !aPoInput.eof() && (aNextPo.getSourceFile() == sFileName || bReadAll )) { PoEntry aActPo( aNextPo ); @@ -262,7 +262,7 @@ MergeDataFile::MergeDataFile( InsertEntry( aActPo.getResourceType(), aActPo.getGroupId(), aActPo.getLocalId(), sHack, sLang, sText, - sQHText, sTitle, sFileName, bCaseSensitive ); + sQHText, sTitle, aActPo.getSourceFile(), bCaseSensitive ); if( bFirstLang ) { @@ -271,7 +271,8 @@ MergeDataFile::MergeDataFile( aActPo.getResourceType(), aActPo.getGroupId(), aActPo.getLocalId(), sHack, "qtz", sQTZText + "||" + sExText, sQTZQHText + "||" + sExQHText, - sQTZTitle + "||" + sExTitle, sFileName, bCaseSensitive ); + sQTZTitle + "||" + sExTitle, aActPo.getSourceFile(), + bCaseSensitive ); } } aPoInput.close(); -- cgit From 06d5579c9291b6061ee89eed8f505f436375e15d Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 18:20:38 +0100 Subject: Localize tree files in help -Treex works well when po is not exist, send a warning but make en-US tree-s. Change-Id: Ib2b790742c022211a8d250b66891cef045941398 --- l10ntools/source/treemerge.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx index 12e931c6d221..8555c8f013a1 100644 --- a/l10ntools/source/treemerge.cxx +++ b/l10ntools/source/treemerge.cxx @@ -279,8 +279,8 @@ void TreeParser::Merge( { MergeDataFile aMergeDataFile( rMergeSrc, static_cast( m_pSource->name ), false ); - - if( aMergeDataFile.GetLanguages()[0] != m_sLang ) + const std::vector vLanguages = aMergeDataFile.GetLanguages(); + if( !vLanguages.empty() && vLanguages[0] != m_sLang ) { std::cerr << "Treex error: given language conflicts with " @@ -288,7 +288,6 @@ void TreeParser::Merge( << m_sLang.getStr() << " - " << rMergeSrc.getStr() << std::endl; return; } - lcl_MergeLevel( m_pSource, pRootNode, (const xmlChar *)("help_section"), &aMergeDataFile, m_sLang, rXhpRoot ); -- cgit From 3f469dd69c2eb9d8f193da7f88d05719762b600c Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Sun, 18 Nov 2012 22:49:36 +0100 Subject: Fix some encoding problem in treemerge Change-Id: I275ccba8f07ccaba1ead0ad83a382d3ad19c722a --- l10ntools/source/treemerge.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/treemerge.cxx b/l10ntools/source/treemerge.cxx index 8555c8f013a1..622564c5d58c 100644 --- a/l10ntools/source/treemerge.cxx +++ b/l10ntools/source/treemerge.cxx @@ -146,7 +146,9 @@ namespace replaceAll("$[officeversion]","%PRODUCTVERSION"); xmlNodeSetContent( pReturn, - reinterpret_cast( sNewTitle.getStr() )); + xmlEncodeSpecialChars( NULL, + reinterpret_cast( + sNewTitle.getStr() ))); xmlFree( sTitle ); break; } -- cgit From 7429ab2e2caa49466a455ad3e2e04057524225d0 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Mon, 19 Nov 2012 18:19:52 +0100 Subject: Use icu regex in l10ntools instead of i18nregexp Change-Id: I9062aafa2fefa26b7b1edf0440f4675b2f469e5d --- l10ntools/Executable_cfgex.mk | 6 +++- l10ntools/Executable_helpex.mk | 3 +- l10ntools/Executable_localize.mk | 6 +++- l10ntools/Executable_propex.mk | 6 +++- l10ntools/Executable_renewpo.mk | 6 +++- l10ntools/Executable_transex3.mk | 6 +++- l10ntools/Executable_treex.mk | 3 +- l10ntools/Executable_uiex.mk | 3 +- l10ntools/Executable_ulfex.mk | 6 +++- l10ntools/Executable_xrmex.mk | 3 +- l10ntools/prj/build.lst | 2 +- l10ntools/source/po.cxx | 77 ++++++++++++++-------------------------- 12 files changed, 65 insertions(+), 62 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/Executable_cfgex.mk b/l10ntools/Executable_cfgex.mk index 7804470c05a7..60b31669c25c 100644 --- a/l10ntools/Executable_cfgex.mk +++ b/l10ntools/Executable_cfgex.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,cfgex,\ $(eval $(call gb_Executable_use_libraries,cfgex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_unpacked,cfgex,boost)) @@ -50,4 +49,9 @@ $(eval $(call gb_Executable_add_exception_objects,cfgex,\ l10ntools/source/cfgmerge \ )) +$(eval $(call gb_Executable_use_externals,cfgex,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_helpex.mk b/l10ntools/Executable_helpex.mk index b7e63100b351..cd2469dc971b 100644 --- a/l10ntools/Executable_helpex.mk +++ b/l10ntools/Executable_helpex.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,helpex,\ $(eval $(call gb_Executable_use_libraries,helpex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_external,helpex,expat_utf8)) @@ -51,6 +50,8 @@ $(eval $(call gb_Executable_add_exception_objects,helpex,\ $(eval $(call gb_Executable_use_externals,helpex,\ libxml2 \ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ )) # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_localize.mk b/l10ntools/Executable_localize.mk index e6e7f1fc2c6e..a810b6cd8e22 100644 --- a/l10ntools/Executable_localize.mk +++ b/l10ntools/Executable_localize.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,localize,\ $(eval $(call gb_Executable_use_libraries,localize,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,localize,\ @@ -44,4 +43,9 @@ $(eval $(call gb_Executable_add_exception_objects,localize,\ l10ntools/source/localize \ )) +$(eval $(call gb_Executable_use_externals,localize,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_propex.mk b/l10ntools/Executable_propex.mk index d8dc16d323c2..06080c682840 100644 --- a/l10ntools/Executable_propex.mk +++ b/l10ntools/Executable_propex.mk @@ -17,7 +17,6 @@ $(eval $(call gb_Executable_set_include,propex,\ $(eval $(call gb_Executable_use_libraries,propex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,propex,\ @@ -29,4 +28,9 @@ $(eval $(call gb_Executable_add_exception_objects,propex,\ l10ntools/source/propex \ )) +$(eval $(call gb_Executable_use_externals,propex,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim: set noet sw=4 ts=4: diff --git a/l10ntools/Executable_renewpo.mk b/l10ntools/Executable_renewpo.mk index 5aa036a40100..db84a41ae5d7 100644 --- a/l10ntools/Executable_renewpo.mk +++ b/l10ntools/Executable_renewpo.mk @@ -18,7 +18,6 @@ $(eval $(call gb_Executable_set_include,renewpo,\ $(eval $(call gb_Executable_use_libraries,renewpo,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,renewpo,\ @@ -29,4 +28,9 @@ $(eval $(call gb_Executable_add_exception_objects,renewpo,\ l10ntools/source/renewpo \ )) +$(eval $(call gb_Executable_use_externals,renewpo,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim: set noet sw=4 ts=4: diff --git a/l10ntools/Executable_transex3.mk b/l10ntools/Executable_transex3.mk index 2d9590641d83..d2b7952f0372 100644 --- a/l10ntools/Executable_transex3.mk +++ b/l10ntools/Executable_transex3.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,transex3,\ $(eval $(call gb_Executable_use_libraries,transex3,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_add_scanners,transex3,\ @@ -50,4 +49,9 @@ $(eval $(call gb_Executable_add_exception_objects,transex3,\ l10ntools/source/export \ )) +$(eval $(call gb_Executable_use_externals,transex3,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_treex.mk b/l10ntools/Executable_treex.mk index 41af0a8bfbc9..af77c71a1546 100644 --- a/l10ntools/Executable_treex.mk +++ b/l10ntools/Executable_treex.mk @@ -17,7 +17,6 @@ $(eval $(call gb_Executable_set_include,treex,\ $(eval $(call gb_Executable_use_libraries,treex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_static_libraries,treex,\ @@ -31,6 +30,8 @@ $(eval $(call gb_Executable_add_exception_objects,treex,\ $(eval $(call gb_Executable_use_externals,treex,\ libxml2 \ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ )) # vim: set noet sw=4 ts=4: diff --git a/l10ntools/Executable_uiex.mk b/l10ntools/Executable_uiex.mk index 520b010265f0..de8d0c83a4d6 100644 --- a/l10ntools/Executable_uiex.mk +++ b/l10ntools/Executable_uiex.mk @@ -16,7 +16,6 @@ $(eval $(call gb_Executable_set_include,uiex,\ $(eval $(call gb_Executable_use_libraries,uiex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_unpacked,uiex,boost)) @@ -33,6 +32,8 @@ $(eval $(call gb_Executable_use_externals,uiex,\ libexslt \ libxml2 \ libxslt \ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ )) # vim: set noet sw=4 ts=4: diff --git a/l10ntools/Executable_ulfex.mk b/l10ntools/Executable_ulfex.mk index b975f5c47e11..9a7040a6ff9e 100644 --- a/l10ntools/Executable_ulfex.mk +++ b/l10ntools/Executable_ulfex.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,ulfex,\ $(eval $(call gb_Executable_use_libraries,ulfex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_unpacked,ulfex,boost)) @@ -47,4 +46,9 @@ $(eval $(call gb_Executable_add_exception_objects,ulfex,\ l10ntools/source/lngex \ )) +$(eval $(call gb_Executable_use_externals,ulfex,\ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ +)) + # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/Executable_xrmex.mk b/l10ntools/Executable_xrmex.mk index 73c56abe420a..ea0810fc3a53 100644 --- a/l10ntools/Executable_xrmex.mk +++ b/l10ntools/Executable_xrmex.mk @@ -33,7 +33,6 @@ $(eval $(call gb_Executable_set_include,xrmex,\ $(eval $(call gb_Executable_use_libraries,xrmex,\ sal \ - i18nregexp \ )) $(eval $(call gb_Executable_use_unpacked,xrmex,boost)) @@ -52,6 +51,8 @@ $(eval $(call gb_Executable_add_exception_objects,xrmex,\ $(eval $(call gb_Executable_use_externals,xrmex,\ libxml2 \ + icuuc \ + $(if $(filter MSC,$(COM)),icuin,icui18n) \ )) # vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/l10ntools/prj/build.lst b/l10ntools/prj/build.lst index 888b2343a4b5..af0fdfeff475 100644 --- a/l10ntools/prj/build.lst +++ b/l10ntools/prj/build.lst @@ -1,3 +1,3 @@ -tr l10ntools : EXPAT:expat LIBXSLT:libxslt sal regexp NULL +tr l10ntools : EXPAT:expat LIBXSLT:libxslt ICU:icu sal NULL tr l10ntools usr1 - all tr_mkout NULL tr l10ntools\prj nmake - all tr_prj NULL diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 648634c2f569..1be60ecaf312 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -7,10 +7,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include -#include -#include -#include #include #include @@ -21,12 +17,15 @@ #include #include +#include #include "po.hxx" #define POESCAPED OString("\\n\\t\\r\\\\\\\"") #define POUNESCAPED OString("\n\t\r\\\"") +using namespace U_ICU_NAMESPACE; + //Class GenPoEntry class GenPoEntry @@ -317,61 +316,37 @@ namespace return lcl_UnEscapeText(rText,"\\n\\t\\r","\n\t\r"); } - //Miminize the length of the regular expression result - static void lcl_Minimize( - const OUString& rText, Regexpr& io_rRegExp, re_registers& io_rRegs ) - { - re_registers aPrevRegs; - const sal_Int32 nStart = io_rRegs.start[0]; - do - { - const OUString sTemp = rText.copy(0,io_rRegs.end[0]-1); - memcpy( - static_cast(&aPrevRegs), - static_cast(&io_rRegs), - sizeof(re_registers)); - memset(static_cast(&io_rRegs), 0, sizeof(re_registers)); - io_rRegExp.set_line(sTemp.getStr(),sTemp.getLength()); - io_rRegExp.re_search(&io_rRegs,nStart); - } while(io_rRegs.num_of_match); - - memcpy(static_cast(&io_rRegs),static_cast(&aPrevRegs), - sizeof(re_registers)); - io_rRegExp.set_line(rText.getStr(),rText.getLength()); - } - //Find all special tag in a string using a regular expression static void lcl_FindAllTag( const OString& rText,std::vector& o_vFoundTags ) { - ::com::sun::star::util::SearchOptions aOptions; - aOptions.algorithmType = - ::com::sun::star::util::SearchAlgorithms_REGEXP; - aOptions.searchFlag = - ::com::sun::star::util::SearchFlags::NORM_WORD_ONLY; - aOptions.searchString = "<[/]?[a-z_\\-]+(| +[a-z]+=\".*\") *[/]?>"; - ::com::sun::star::uno::Reference< - ::com::sun::star::i18n::XExtendedTransliteration > xTrans; - - Regexpr aRegExp(aOptions,xTrans); - const OUString sTemp(OStringToOUString(rText,RTL_TEXTENCODING_UTF8)); - aRegExp.set_line(sTemp.getStr(),sTemp.getLength()); - - re_registers aRegs; - memset(static_cast(&aRegs), 0, sizeof(re_registers)); - sal_Int32 nStart = 0; - o_vFoundTags.resize(0); - aRegExp.re_search(&aRegs,nStart); - while(aRegs.num_of_match) + + UErrorCode nIcuErr = U_ZERO_ERROR; + sal_uInt32 nSearchFlags = UREGEX_DOTALL | UREGEX_CASE_INSENSITIVE; + OUString sLocaleText( OStringToOUString(rText,RTL_TEXTENCODING_UTF8) ); + OUString sPattern( "<[/]??[a-z_-]+?(?:| +[a-z]+?=\".*?\") *[/]??>" ); + UnicodeString sSearchPat( + reinterpret_cast( + sPattern.getStr()), sPattern.getLength() ); + UnicodeString sSource( + reinterpret_cast( + sLocaleText.getStr()), sLocaleText.getLength() ); + + RegexMatcher aRegexMatcher( sSearchPat, nSearchFlags, nIcuErr ); + aRegexMatcher.reset( sSource ); + int64_t nStartPos = 0; + while( aRegexMatcher.find(nStartPos, nIcuErr) && + nIcuErr == U_ZERO_ERROR ) { - lcl_Minimize(sTemp,aRegExp,aRegs); + UnicodeString sMatch = + aRegexMatcher.group(nIcuErr); o_vFoundTags.push_back( OUStringToOString( - sTemp.copy(aRegs.start[0],aRegs.end[0]-aRegs.start[0]), + OUString( + reinterpret_cast( + sMatch.getBuffer()),sMatch.length()), RTL_TEXTENCODING_UTF8)); - nStart = aRegs.end[0]; - memset(static_cast(&aRegs), 0, sizeof(re_registers)); - aRegExp.re_search(&aRegs,nStart); + nStartPos = aRegexMatcher.start(nIcuErr)+1; } } -- cgit From 073ff5518f2e341dde7d7ce732cfecb029c85ce6 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 20 Nov 2012 00:24:20 +0100 Subject: Generate qtz properties Qtz has no own po files so use one of configured langauge's po files (en-US excludex) Plus copy all properties files independently of localization Change-Id: Ica7ccb7d3111f2fc2b3bbde4b839cb564967130a --- l10ntools/source/propmerge.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'l10ntools') diff --git a/l10ntools/source/propmerge.cxx b/l10ntools/source/propmerge.cxx index a858f44d8210..689e931c4b72 100644 --- a/l10ntools/source/propmerge.cxx +++ b/l10ntools/source/propmerge.cxx @@ -182,7 +182,8 @@ void PropParser::Merge( const OString &rMergeSrc, const OString &rDestinationFil MergeDataFile aMergeDataFile( rMergeSrc, m_sSource, false ); - if( aMergeDataFile.GetLanguages()[0] != m_sLang ) + const std::vector aLanguages = aMergeDataFile.GetLanguages(); + if( m_sLang != "qtz" && !aLanguages.empty() && aLanguages[0] != m_sLang ) { std::cerr << "Propex error: given language conflicts with " -- cgit