LCOV - code coverage report
Current view: top level - l10ntools/inc - export.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 25 0.0 %
Date: 2014-04-14 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_L10NTOOLS_INC_EXPORT_HXX
      21             : #define INCLUDED_L10NTOOLS_INC_EXPORT_HXX
      22             : 
      23             : #include "sal/config.h"
      24             : #include "po.hxx"
      25             : 
      26             : #include <cstddef>
      27             : #include <fstream>
      28             : 
      29             : #include <osl/file.hxx>
      30             : #include <osl/file.h>
      31             : 
      32             : #include <boost/unordered_map.hpp>
      33             : #include <iterator>
      34             : #include <set>
      35             : #include <vector>
      36             : #include <queue>
      37             : #include <string>
      38             : 
      39             : #ifdef WNT
      40             : #include <direct.h>
      41             : #else
      42             : #include <unistd.h>
      43             : #endif
      44             : 
      45             : #define NO_TRANSLATE_ISO        "x-no-translate"
      46             : 
      47             : class MergeEntrys;
      48             : 
      49             : typedef boost::unordered_map<OString, OString, OStringHash>
      50             :     OStringHashMap;
      51             : 
      52             : typedef boost::unordered_map<OString, bool, OStringHash>
      53             :     OStringBoolHashMap;
      54             : 
      55             : #define SOURCE_LANGUAGE "en-US"
      56             : #define X_COMMENT "x-comment"
      57             : 
      58             : 
      59             : // class ResData
      60             : 
      61             : 
      62             : #define ID_LEVEL_NULL       0x0000
      63             : #define ID_LEVEL_TEXT       0x0002
      64             : #define ID_LEVEL_IDENTIFIER 0x0005
      65             : 
      66             : typedef std::vector< OString > ExportList;
      67             : 
      68             : /// Purpose: holds mandatory data to export a single res (used with ResStack)
      69           0 : class ResData
      70             : {
      71             : public:
      72             :     ResData( const OString &rGId );
      73             :     ResData( const OString &rGId , const OString &rFilename );
      74             :     bool SetId(const OString &rId, sal_uInt16 nLevel);
      75             : 
      76             :     sal_uInt16 nIdLevel;
      77             :     bool bChild;
      78             :     bool bChildWithText;
      79             : 
      80             :     bool bText;
      81             :     bool bQuickHelpText;
      82             :     bool bTitle;
      83             : 
      84             :     OString sResTyp;
      85             :     OString sId;
      86             :     OString sGId;
      87             :     OString sFilename;
      88             : 
      89             :     OStringHashMap sText;
      90             : 
      91             :     OStringHashMap sQuickHelpText;
      92             : 
      93             :     OStringHashMap sTitle;
      94             : 
      95             :     OString sTextTyp;
      96             : 
      97             :     ExportList  m_aList;
      98             : };
      99             : 
     100             : 
     101             : 
     102             : // class Export
     103             : 
     104             : 
     105             : #define LIST_NON                    0x0000
     106             : #define LIST_STRING                 0x0001
     107             : #define LIST_FILTER                 0x0002
     108             : #define LIST_ITEM                   0x0004
     109             : #define LIST_PAIRED                 0x0005
     110             : #define STRING_TYP_TEXT             0x0010
     111             : #define STRING_TYP_QUICKHELPTEXT    0x0040
     112             : #define STRING_TYP_TITLE            0x0080
     113             : 
     114             : #define MERGE_MODE_NORMAL           0x0000
     115             : #define MERGE_MODE_LIST             0x0001
     116             : 
     117             : typedef ::std::vector< ResData* > ResStack;
     118             : class ParserQueue;
     119             : 
     120             : /// Purpose: syntax check and export of *.src, called from lexer
     121             : class Export
     122             : {
     123             : private:
     124             :     union
     125             :     {
     126             :         std::ofstream* mSimple;
     127             :         PoOfstream* mPo;
     128             : 
     129             :     } aOutput;
     130             : 
     131             :     ResStack aResStack;                 ///< stack for parsing recursive
     132             : 
     133             :     bool bDefine;                       // cur. res. in a define?
     134             :     bool bNextMustBeDefineEOL;          ///< define but no \ at lineend
     135             :     std::size_t nLevel; // res. recursiv? how deep?
     136             :     sal_uInt16 nList;                       ///< cur. res. is List
     137             :     std::size_t nListIndex;
     138             :     std::size_t nListLevel;
     139             :     bool bMergeMode;
     140             :     OString sMergeSrc;
     141             :     bool bError;                        // any errors while export?
     142             :     bool bReadOver;
     143             :     OString sFilename;
     144             :     OString sLanguages;
     145             : 
     146             :     std::vector<OString> aLanguages;
     147             : 
     148             :     bool WriteData( ResData *pResData, bool bCreateNew = false ); ///< called befor dest. cur ResData
     149             :     bool WriteExportList( ResData *pResData, ExportList& rExportList, const sal_uInt16 nTyp );
     150             : 
     151             :     OString MergePairedList( OString const & sLine , OString const & sText );
     152             : 
     153             :     OString FullId();                    ///< creates cur. GID
     154             : 
     155             :     OString GetPairedListID(const OString & rText);
     156             :     OString GetPairedListString(const OString& rText);
     157             :     OString StripList(const OString& rText);
     158             : 
     159             :     void InsertListEntry(const OString &rLine);
     160             :     void CleanValue( OString &rValue );
     161             :     OString GetText(const OString &rSource, int nToken);
     162             : 
     163             :     void ResData2Output( MergeEntrys *pEntry, sal_uInt16 nType, const OString& rTextType );
     164             :     void MergeRest( ResData *pResData );
     165             :     void ConvertMergeContent( OString &rText );
     166             :     void ConvertExportContent( OString &rText );
     167             : 
     168             :     void WriteToMerged(const OString &rText , bool bSDFContent);
     169             :     void SetChildWithText();
     170             : 
     171             :     void CutComment( OString &rText );
     172             : 
     173           0 :     void WriteUTF8ByteOrderMarkToOutput() { *aOutput.mSimple << '\xEF' << '\xBB' << '\xBF'; }
     174             : 
     175             : public:
     176             :     Export( const OString &rOutput );
     177             :     Export(const OString &rMergeSource, const OString &rOutput, const OString &rLanguage, bool bUTF8BOM);
     178             :     ~Export();
     179             : 
     180             :     void Init();
     181             :     int Execute( int nToken, const char * pToken ); ///< called from lexer
     182           0 :     void SetError() { bError = true; }
     183           0 :     bool GetError() { return bError; }
     184             :     ParserQueue* pParseQueue; // public!!
     185             : };
     186             : 
     187             : 
     188             : 
     189             : // class MergeEntrys
     190             : 
     191             : 
     192             : /// Purpose: holds information of data to merge
     193           0 : class MergeEntrys
     194             : {
     195             : friend class MergeDataFile;
     196             : private:
     197             :     OStringHashMap sText;
     198             :     OStringBoolHashMap bTextFirst;
     199             :     OStringHashMap sQuickHelpText;
     200             :     OStringBoolHashMap bQuickHelpTextFirst;
     201             :     OStringHashMap sTitle;
     202             :     OStringBoolHashMap bTitleFirst;
     203             : 
     204             : public:
     205           0 :     MergeEntrys(){};
     206           0 :     void InsertEntry(const OString &rId, const OString &rText,
     207             :         const OString &rQuickHelpText, const OString &rTitle)
     208             :     {
     209             : 
     210           0 :         sText[ rId ] = rText;
     211           0 :         bTextFirst[ rId ] = true;
     212           0 :         sQuickHelpText[ rId ] = rQuickHelpText;
     213           0 :         bQuickHelpTextFirst[ rId ] = true;
     214           0 :         sTitle[ rId ] = rTitle;
     215           0 :         bTitleFirst[ rId ] = true;
     216           0 :     }
     217             :     bool GetText( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, bool bDel = false );
     218             : 
     219             :     /**
     220             :       Generate QTZ string with ResData
     221             :       For executable which works one language and without PO files.
     222             :     */
     223             :     static OString GetQTZText(const ResData& rResData, const OString& rOrigText);
     224             : 
     225             : };
     226             : 
     227             : 
     228             : // class MergeDataHashMap
     229             : 
     230             : 
     231             : class MergeData;
     232             : 
     233             : /** Container for MergeData
     234             : 
     235             :   This class is an HashMap with a hidden insertion
     236             :   order. The class can used just like a simple
     237             :   HashMap, but good to know that it's use is
     238             :   more effective if the accessing(find) order
     239             :   match with the insertion order.
     240             : 
     241             :   In the most case, this match is good.
     242             :   (e.g. reading PO files of different languages,
     243             :   executables merging)
     244             : */
     245             : class MergeDataHashMap
     246             : {
     247             :     private:
     248             :         typedef boost::unordered_map<OString, MergeData*, OStringHash> HashMap_t;
     249             : 
     250             :     public:
     251           0 :         MergeDataHashMap():bFirstSearch(true){};
     252           0 :         ~MergeDataHashMap(){};
     253             : 
     254             :         typedef HashMap_t::iterator iterator;
     255             :         typedef HashMap_t::const_iterator const_iterator;
     256             : 
     257             :         std::pair<iterator,bool> insert(const OString& rKey, MergeData* pMergeData);
     258             :         iterator find(const OString& rKey);
     259             : 
     260           0 :         iterator begin() {return m_aHashMap.begin();}
     261           0 :         iterator end() {return m_aHashMap.end();}
     262             : 
     263           0 :         const_iterator begin() const {return m_aHashMap.begin();}
     264           0 :         const_iterator end() const {return m_aHashMap.end();}
     265             : 
     266             :     private:
     267             :         bool bFirstSearch;
     268             :         iterator aLastInsertion;
     269             :         iterator aLastFound;
     270             :         iterator aFirstInOrder;
     271             :         HashMap_t m_aHashMap;
     272             : };
     273             : 
     274             : 
     275             : // class MergeData
     276             : 
     277             : 
     278             : /// Purpose: holds information of data to merge (one resource)
     279             : class MergeData
     280             : {
     281             :     friend class MergeDataHashMap;
     282             : 
     283             : public:
     284             :     OString sTyp;
     285             :     OString sGID;
     286             :     OString sLID;
     287             :     OString sFilename;
     288             :     MergeEntrys* pMergeEntrys;
     289             : private:
     290             :     MergeDataHashMap::iterator m_aNextData;
     291             : public:
     292             :     MergeData( const OString &rTyp, const OString &rGID, const OString &rLID , const OString &rFilename );
     293             :     ~MergeData();
     294             :     MergeEntrys* GetMergeEntries();
     295             : 
     296             :     bool operator==( ResData *pData );
     297             : };
     298             : 
     299             : 
     300             : // class MergeDataFile
     301             : 
     302             : 
     303             : /// Purpose: holds information of data to merge, read from PO file
     304             : class MergeDataFile
     305             : {
     306             :     private:
     307             :         MergeDataHashMap aMap;
     308             :         std::set<OString> aLanguageSet;
     309             : 
     310             :         MergeData *GetMergeData( ResData *pResData , bool bCaseSensitve = false );
     311             :         void InsertEntry(const OString &rTYP, const OString &rGID,
     312             :             const OString &rLID, const OString &nLang,
     313             :             const OString &rTEXT, const OString &rQHTEXT,
     314             :             const OString &rTITLE, const OString &sFilename,
     315             :             bool bFirstLang, bool bCaseSensitive);
     316             :     public:
     317             :         explicit MergeDataFile(
     318             :             const OString &rFileName, const OString& rFile,
     319             :             bool bCaseSensitive, bool bWithQtz = true );
     320             :         ~MergeDataFile();
     321             : 
     322             : 
     323             :         std::vector<OString> GetLanguages() const;
     324           0 :         const MergeDataHashMap& getMap() const { return aMap; }
     325             : 
     326             :         MergeEntrys *GetMergeEntrys( ResData *pResData );
     327             :         MergeEntrys *GetMergeEntrysCaseSensitive( ResData *pResData );
     328             : 
     329             :         static OString CreateKey(const OString& rTYP, const OString& rGID,
     330             :             const OString& rLID, const OString& rFilename , bool bCaseSensitive = false);
     331             : };
     332             : 
     333             : 
     334           0 : class QueueEntry
     335             : {
     336             : public:
     337           0 :     QueueEntry(int nTypVal, const OString &rLineVal)
     338           0 :         : nTyp(nTypVal), sLine(rLineVal)
     339             :     {
     340           0 :     }
     341             :     int nTyp;
     342             :     OString sLine;
     343             : };
     344             : 
     345             : class ParserQueue
     346             : {
     347             : public:
     348             : 
     349             :     ParserQueue( Export& aExportObj );
     350             :     ~ParserQueue();
     351             : 
     352             :     inline void Push( const QueueEntry& aEntry );
     353             :     bool bCurrentIsM;  // public ?
     354             :     bool bNextIsM;   // public ?
     355             :     bool bLastWasM;   // public ?
     356             :     bool bMflag;   // public ?
     357             : 
     358             :     void Close();
     359             : private:
     360             :     std::queue<QueueEntry>* aQueueNext;
     361             :     std::queue<QueueEntry>* aQueueCur;
     362             : 
     363             :     Export& aExport;
     364             :     bool bStart;
     365             : 
     366             :     inline void Pop( std::queue<QueueEntry>& aQueue );
     367             : 
     368             : };
     369             : #endif // INCLUDED_L10NTOOLS_INC_EXPORT_HXX
     370             : 
     371             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10