1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include "sal/config.h"
29 #include <osl/file.hxx>
32 #include <boost/unordered_map.hpp>
45 #define NO_TRANSLATE_ISO "x-no-translate"
49 typedef boost::unordered_map
<OString
, OString
, OStringHash
>
52 typedef boost::unordered_map
<OString
, bool, OStringHash
>
55 #define SOURCE_LANGUAGE "en-US"
56 #define X_COMMENT "x-comment"
57 #define LIST_REFID "LIST_REFID"
63 typedef OStringHashMap ExportListEntry
;
66 /// Container for parse different types of string lists
70 std::vector
< ExportListEntry
* > maList
;
71 std::size_t nSourceLanguageListEntryCount
;
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
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)
105 ResData( const OString
&rGId
);
106 ResData( const OString
&rGId
, const OString
&rFilename
);
108 sal_Bool
SetId(const OString
&rId
, sal_uInt16 nLevel
);
112 sal_Bool bChildWithText
;
116 sal_Bool bQuickHelpText
;
126 OStringHashMap sText
;
128 OStringHashMap sHelpText
;
130 OStringHashMap sQuickHelpText
;
132 OStringHashMap sTitle
;
136 ExportList
*pStringList
;
137 ExportList
*pUIEntries
;
138 ExportList
*pItemList
;
139 ExportList
*pFilterList
;
140 ExportList
*pPairedList
;
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
;
165 /// Purpose: syntax check and export of *.src, called from lexer
171 std::ofstream
* mSimple
;
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
183 std::size_t nListIndex
;
184 std::size_t nListLevel
;
188 sal_Bool bError
; // any errors while export?
190 sal_Bool bDontWriteOutput
;
191 OString sLastTextTyp
;
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
);
230 Export( const OString
&rOutput
);
231 Export(const OString
&rMergeSource
, const OString
&rOutput
, const OString
&rLanguage
);
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!!
246 /// Purpose: holds information of data to merge
249 friend class MergeDataFile
;
251 OStringHashMap sText
;
252 OStringBoolHashMap bTextFirst
;
253 OStringHashMap sQuickHelpText
;
254 OStringBoolHashMap bQuickHelpTextFirst
;
255 OStringHashMap sTitle
;
256 OStringBoolHashMap bTitleFirst
;
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
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,
299 class MergeDataHashMap
302 typedef boost::unordered_map
<OString
, MergeData
*, OStringHash
> HashMap_t
;
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();}
322 iterator aLastInsertion
;
324 iterator aFirstInOrder
;
325 HashMap_t m_aHashMap
;
332 /// Purpose: holds information of data to merge (one resource)
335 friend class MergeDataHashMap
;
342 MergeEntrys
* pMergeEntrys
;
344 MergeDataHashMap::iterator m_aNextData
;
346 MergeData( const OString
&rTyp
, const OString
&rGID
, const OString
&rLID
, const OString
&rFilename
);
348 MergeEntrys
* GetMergeEntries();
350 sal_Bool
operator==( ResData
*pData
);
354 // class MergeDataFile
357 /// Purpose: holds information of data to merge, read from PO file
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
);
371 explicit MergeDataFile(
372 const OString
&rFileName
, const OString
& rFile
,
373 bool bCaseSensitive
, bool bWithQtz
= true );
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);
391 QueueEntry(int nTypVal
, const OString
&rLineVal
)
392 : nTyp(nTypVal
), sLine(rLineVal
)
403 ParserQueue( Export
& aExportObj
);
406 inline void Push( const QueueEntry
& aEntry
);
407 bool bCurrentIsM
; // public ?
408 bool bNextIsM
; // public ?
409 bool bLastWasM
; // public ?
410 bool bMflag
; // public ?
414 std::queue
<QueueEntry
>* aQueueNext
;
415 std::queue
<QueueEntry
>* aQueueCur
;
416 std::queue
<QueueEntry
>* aQref
;
421 inline void Pop( std::queue
<QueueEntry
>& aQueue
);
424 #endif // _EXPORT_HXX
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */