diff options
author | Zolnai Tamás <zolnaitamas2000g@gmail.com> | 2012-11-18 15:24:44 +0100 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000g@gmail.com> | 2012-11-18 19:18:44 +0100 |
commit | 5d84ae59e70b8b1017959a68934ac1f455ce2b13 (patch) | |
tree | caee93552f4afc35ad473909b04e7e866b4b6450 /l10ntools/source | |
parent | fedd4a578e8e22f8a40990a3272056f5b7572110 (diff) |
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
Diffstat (limited to 'l10ntools/source')
-rw-r--r-- | l10ntools/source/helpex.cxx | 80 | ||||
-rw-r--r-- | l10ntools/source/helpmerge.cxx | 45 | ||||
-rw-r--r-- | l10ntools/source/merge.cxx | 13 |
3 files changed, 80 insertions, 58 deletions
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 <iostream> +#include <fstream> +#include <string> +#include <cstring> #include <stdio.h> #include <stdlib.h> @@ -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<rtl::OString>& aLanguages , MergeD } -bool HelpParser::Merge( - const rtl::OString &rSDFFile, const rtl::OString &rPathX , const rtl::OString &rPathY , bool bISO , - const std::vector<rtl::OString>& 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(); |