Bump version to 4.1-6
[LibreOffice.git] / l10ntools / inc / export.hxx
blob595c0273fb5f47e1d6df6aa8067aa5a417f1d82d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _EXPORT_HXX
21 #define _EXPORT_HXX
23 #include "sal/config.h"
24 #include "po.hxx"
26 #include <cstddef>
27 #include <fstream>
29 #include <osl/file.hxx>
30 #include <osl/file.h>
32 #include <boost/unordered_map.hpp>
33 #include <iterator>
34 #include <set>
35 #include <vector>
36 #include <queue>
37 #include <string>
39 #ifdef WNT
40 #include <direct.h>
41 #else
42 #include <unistd.h>
43 #endif
45 #define NO_TRANSLATE_ISO "x-no-translate"
47 class MergeEntrys;
49 typedef boost::unordered_map<OString, OString, OStringHash>
50 OStringHashMap;
52 typedef boost::unordered_map<OString, bool, OStringHash>
53 OStringBoolHashMap;
55 #define SOURCE_LANGUAGE "en-US"
56 #define X_COMMENT "x-comment"
57 #define LIST_REFID "LIST_REFID"
60 // class ExportList
63 typedef OStringHashMap ExportListEntry;
66 /// Container for parse different types of string lists
67 class ExportList
69 private:
70 std::vector< ExportListEntry* > maList;
71 std::size_t nSourceLanguageListEntryCount;
73 public:
74 ExportList() { nSourceLanguageListEntryCount = 0; }
75 std::size_t GetSourceLanguageListEntryCount() { return nSourceLanguageListEntryCount; }
76 void NewSourceLanguageListEntry() { nSourceLanguageListEntryCount++; }
77 size_t size() const { return maList.size(); }
78 void push_back( ExportListEntry* item ) { maList.push_back( item ); }
80 ExportListEntry* operator [] ( size_t i )
82 return ( i < maList.size() ) ? maList[ i ] : NULL;
86 #define REFID_NONE 0xFFFF
89 // class ResData
92 #define ID_LEVEL_NULL 0x0000
93 #define ID_LEVEL_AUTOID 0x0001
94 #define ID_LEVEL_TEXT 0x0002
95 #define ID_LEVEL_FIELDNAME 0x0003
96 #define ID_LEVEL_ACCESSPATH 0x0004
97 #define ID_LEVEL_IDENTIFIER 0x0005
98 #define ID_LEVEL_LISTINDEX 0x0006
101 /// Purpose: holds mandatory data to export a single res (used with ResStack)
102 class ResData
104 public:
105 ResData( const OString &rGId );
106 ResData( const OString &rGId , const OString &rFilename );
107 ~ResData();
108 sal_Bool SetId(const OString &rId, sal_uInt16 nLevel);
110 sal_uInt16 nIdLevel;
111 sal_Bool bChild;
112 sal_Bool bChildWithText;
114 sal_Bool bText;
115 sal_Bool bHelpText;
116 sal_Bool bQuickHelpText;
117 sal_Bool bTitle;
118 sal_Bool bList;
120 OString sResTyp;
121 OString sId;
122 OString sGId;
123 OString sHelpId;
124 OString sFilename;
126 OStringHashMap sText;
128 OStringHashMap sHelpText;
130 OStringHashMap sQuickHelpText;
132 OStringHashMap sTitle;
134 OString sTextTyp;
136 ExportList *pStringList;
137 ExportList *pUIEntries;
138 ExportList *pItemList;
139 ExportList *pFilterList;
140 ExportList *pPairedList;
145 // class Export
148 #define LIST_NON 0x0000
149 #define LIST_STRING 0x0001
150 #define LIST_FILTER 0x0002
151 #define LIST_ITEM 0x0004
152 #define LIST_PAIRED 0x0005
153 #define LIST_UIENTRIES 0x0008
154 #define STRING_TYP_TEXT 0x0010
155 #define STRING_TYP_HELPTEXT 0x0020
156 #define STRING_TYP_QUICKHELPTEXT 0x0040
157 #define STRING_TYP_TITLE 0x0080
159 #define MERGE_MODE_NORMAL 0x0000
160 #define MERGE_MODE_LIST 0x0001
162 typedef ::std::vector< ResData* > ResStack;
163 class ParserQueue;
165 /// Purpose: syntax check and export of *.src, called from lexer
166 class Export
168 private:
169 union
171 std::ofstream* mSimple;
172 PoOfstream* mPo;
174 } aOutput;
176 ResStack aResStack; ///< stack for parsing recursive
178 sal_Bool bDefine; // cur. res. in a define?
179 sal_Bool bNextMustBeDefineEOL; ///< define but no \ at lineend
180 std::size_t nLevel; // res. recursiv? how deep?
181 sal_uInt16 nList; ///< cur. res. is List
182 OString m_sListLang;
183 std::size_t nListIndex;
184 std::size_t nListLevel;
185 bool bSkipFile;
186 sal_Bool bMergeMode;
187 OString sMergeSrc;
188 sal_Bool bError; // any errors while export?
189 sal_Bool bReadOver;
190 sal_Bool bDontWriteOutput;
191 OString sLastTextTyp;
192 OString sFilename;
193 OString sLanguages;
195 std::vector<OString> aLanguages;
197 sal_Bool WriteData( ResData *pResData, sal_Bool bCreateNew = sal_False ); ///< called befor dest. cur ResData
198 sal_Bool WriteExportList( ResData *pResData, ExportList *pExportList,
199 const OString &rTyp, sal_Bool bCreateNew = sal_False );
201 OString MergePairedList( OString const & sLine , OString const & sText );
203 OString FullId(); ///< creates cur. GID
205 OString GetPairedListID(const OString & rText);
206 OString GetPairedListString(const OString& rText);
207 OString StripList(const OString& rText);
209 void InsertListEntry(const OString &rText, const OString &rLine);
210 void CleanValue( OString &rValue );
211 OString GetText(const OString &rSource, int nToken);
214 Get all MergeEntrys for the ExportList identified by pResData
215 Check whether list can merge and load all needed MergeEntry from DataBase.
217 bool GetAllMergeEntrysOfList(ResData *pResData, std::vector<MergeEntrys*>& o_vMergeEntrys, ExportList*& o_pList);
219 void ResData2Output( MergeEntrys *pEntry, sal_uInt16 nType, const OString& rTextType );
220 void MergeRest( ResData *pResData, sal_uInt16 nMode = MERGE_MODE_NORMAL );
221 void ConvertMergeContent( OString &rText );
222 void ConvertExportContent( OString &rText );
224 void WriteToMerged(const OString &rText , bool bSDFContent);
225 void SetChildWithText();
227 void CutComment( OString &rText );
229 public:
230 Export( const OString &rOutput );
231 Export(const OString &rMergeSource, const OString &rOutput, const OString &rLanguage);
232 ~Export();
234 void Init();
235 int Execute( int nToken, const char * pToken ); ///< called from lexer
236 void SetError() { bError = sal_True; }
237 sal_Bool GetError() { return bError; }
238 ParserQueue* pParseQueue; // public!!
243 // class MergeEntrys
246 /// Purpose: holds information of data to merge
247 class MergeEntrys
249 friend class MergeDataFile;
250 private:
251 OStringHashMap sText;
252 OStringBoolHashMap bTextFirst;
253 OStringHashMap sQuickHelpText;
254 OStringBoolHashMap bQuickHelpTextFirst;
255 OStringHashMap sTitle;
256 OStringBoolHashMap bTitleFirst;
258 public:
259 MergeEntrys(){};
260 void InsertEntry(const OString &rId, const OString &rText,
261 const OString &rQuickHelpText, const OString &rTitle)
264 sText[ rId ] = rText;
265 bTextFirst[ rId ] = true;
266 sQuickHelpText[ rId ] = rQuickHelpText;
267 bQuickHelpTextFirst[ rId ] = true;
268 sTitle[ rId ] = rTitle;
269 bTitleFirst[ rId ] = true;
271 sal_Bool GetText( OString &rReturn, sal_uInt16 nTyp, const OString &nLangIndex, sal_Bool bDel = sal_False );
274 Generate QTZ string with ResData
275 For executable which works one language and without PO files.
277 static OString GetQTZText(const ResData& rResData, const OString& rOrigText);
282 // class MergeDataHashMap
285 class MergeData;
287 /** Container for MergeData
289 This class is an HashMap with a hidden insertion
290 order. The class can used just like a simple
291 HashMap, but good to know that it's use is
292 more effective if the accessing(find) order
293 match with the insertion order.
295 In the most case, this match is good.
296 (e.g. reading PO files of different languages,
297 executables merging)
299 class MergeDataHashMap
301 private:
302 typedef boost::unordered_map<OString, MergeData*, OStringHash> HashMap_t;
304 public:
305 MergeDataHashMap():bFirstSearch(true){};
306 ~MergeDataHashMap(){};
308 typedef HashMap_t::iterator iterator;
309 typedef HashMap_t::const_iterator const_iterator;
311 std::pair<iterator,bool> insert(const OString& rKey, MergeData* pMergeData);
312 iterator find(const OString& rKey);
314 iterator begin() {return m_aHashMap.begin();}
315 iterator end() {return m_aHashMap.end();}
317 const_iterator begin() const {return m_aHashMap.begin();}
318 const_iterator end() const {return m_aHashMap.end();}
320 private:
321 bool bFirstSearch;
322 iterator aLastInsertion;
323 iterator aLastFound;
324 iterator aFirstInOrder;
325 HashMap_t m_aHashMap;
329 // class MergeData
332 /// Purpose: holds information of data to merge (one resource)
333 class MergeData
335 friend class MergeDataHashMap;
337 public:
338 OString sTyp;
339 OString sGID;
340 OString sLID;
341 OString sFilename;
342 MergeEntrys* pMergeEntrys;
343 private:
344 MergeDataHashMap::iterator m_aNextData;
345 public:
346 MergeData( const OString &rTyp, const OString &rGID, const OString &rLID , const OString &rFilename );
347 ~MergeData();
348 MergeEntrys* GetMergeEntries();
350 sal_Bool operator==( ResData *pData );
354 // class MergeDataFile
357 /// Purpose: holds information of data to merge, read from PO file
358 class MergeDataFile
360 private:
361 MergeDataHashMap aMap;
362 std::set<OString> aLanguageSet;
364 MergeData *GetMergeData( ResData *pResData , bool bCaseSensitve = false );
365 void InsertEntry(const OString &rTYP, const OString &rGID,
366 const OString &rLID, const OString &nLang,
367 const OString &rTEXT, const OString &rQHTEXT,
368 const OString &rTITLE, const OString &sFilename,
369 bool bFirstLang, bool bCaseSensitive);
370 public:
371 explicit MergeDataFile(
372 const OString &rFileName, const OString& rFile,
373 bool bCaseSensitive, bool bWithQtz = true );
374 ~MergeDataFile();
377 std::vector<OString> GetLanguages() const;
378 const MergeDataHashMap& getMap() const { return aMap; }
380 MergeEntrys *GetMergeEntrys( ResData *pResData );
381 MergeEntrys *GetMergeEntrysCaseSensitive( ResData *pResData );
383 static OString CreateKey(const OString& rTYP, const OString& rGID,
384 const OString& rLID, const OString& rFilename , bool bCaseSensitive = false);
388 class QueueEntry
390 public:
391 QueueEntry(int nTypVal, const OString &rLineVal)
392 : nTyp(nTypVal), sLine(rLineVal)
395 int nTyp;
396 OString sLine;
399 class ParserQueue
401 public:
403 ParserQueue( Export& aExportObj );
404 ~ParserQueue();
406 inline void Push( const QueueEntry& aEntry );
407 bool bCurrentIsM; // public ?
408 bool bNextIsM; // public ?
409 bool bLastWasM; // public ?
410 bool bMflag; // public ?
412 void Close();
413 private:
414 std::queue<QueueEntry>* aQueueNext;
415 std::queue<QueueEntry>* aQueueCur;
416 std::queue<QueueEntry>* aQref;
418 Export& aExport;
419 bool bStart;
421 inline void Pop( std::queue<QueueEntry>& aQueue );
424 #endif // _EXPORT_HXX
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */