1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include "sal/config.h"
37 #ifndef L10NTOOLS_DIRECTORY_HXX
38 #define L10NTOOLS_DIRECTORY_HXX
39 #include <l10ntools/directory.hxx>
42 #include <osl/file.hxx>
45 #include <boost/unordered_map.hpp>
46 #include <iterator> /* std::iterator*/
47 #include <set> /* std::set*/
48 #include <vector> /* std::vector*/
57 #define NO_TRANSLATE_ISO "x-no-translate"
62 typedef boost::unordered_map
<rtl::OString
, rtl::OString
, rtl::OStringHash
>
65 typedef boost::unordered_map
<rtl::OString
, bool, rtl::OStringHash
>
68 typedef boost::unordered_map
<rtl::OString
, PFormEntrys
*, rtl::OStringHash
>
71 typedef boost::unordered_map
<rtl::OString
, MergeData
*, rtl::OStringHash
>
74 #define SOURCE_LANGUAGE rtl::OString(RTL_CONSTASCII_STRINGPARAM("en-US"))
75 #define X_COMMENT rtl::OString(RTL_CONSTASCII_STRINGPARAM("x-comment"))
76 #define LIST_REFID "LIST_REFID"
78 typedef OStringHashMap ExportListEntry
;
79 typedef ::std::vector
< ExportListEntry
* > ExportListBase
;
88 ExportListBase maList
;
89 std::size_t nSourceLanguageListEntryCount
;
92 ExportList() { nSourceLanguageListEntryCount
= 0; }
93 std::size_t GetSourceLanguageListEntryCount() { return nSourceLanguageListEntryCount
; }
94 void NewSourceLanguageListEntry() { nSourceLanguageListEntryCount
++; }
95 size_t size() const { return maList
.size(); }
96 void push_back( ExportListEntry
* item
) { maList
.push_back( item
); }
98 ExportListEntry
* operator [] ( size_t i
)
100 return ( i
< maList
.size() ) ? maList
[ i
] : NULL
;
104 #define REFID_NONE 0xFFFF
110 /******************************************************************************
111 * Purpose: holds mandatory data to export a single res (used with ResStack)
112 ******************************************************************************/
114 #define ID_LEVEL_NULL 0x0000
115 #define ID_LEVEL_AUTOID 0x0001
116 #define ID_LEVEL_TEXT 0x0002
117 #define ID_LEVEL_FIELDNAME 0x0003
118 #define ID_LEVEL_ACCESSPATH 0x0004
119 #define ID_LEVEL_IDENTIFIER 0x0005
120 #define ID_LEVEL_LISTINDEX 0x0006
126 sal_Bool
SetId(const rtl::OString
&rId
, sal_uInt16 nLevel
);
129 sal_uInt16 nChildIndex
;
132 sal_Bool bChildWithText
;
136 sal_Bool bQuickHelpText
;
140 sal_Bool bRestMerged
;
142 rtl::OString sResTyp
;
145 rtl::OString sHelpId
;
146 rtl::OString sFilename
;
148 OStringHashMap sText
;
149 sal_uInt16 nTextRefId
;
151 OStringHashMap sHelpText
;
152 sal_uInt16 nHelpTextRefId
;
154 OStringHashMap sQuickHelpText
;
155 sal_uInt16 nQuickHelpTextRefId
;
157 OStringHashMap sTitle
;
158 sal_uInt16 nTitleRefId
;
160 rtl::OString sTextTyp
;
162 ExportList
*pStringList
;
163 ExportList
*pUIEntries
;
164 ExportList
*pItemList
;
165 ExportList
*pFilterList
;
166 ExportList
*pPairedList
;
170 ResData(const rtl::OString
&rPF
, const rtl::OString
&rGId
)
174 nIdLevel( ID_LEVEL_NULL
),
176 bChildWithText( sal_False
),
178 bHelpText( sal_False
),
179 bQuickHelpText( sal_False
),
182 bRestMerged( sal_False
),
184 nTextRefId( REFID_NONE
),
185 nHelpTextRefId( REFID_NONE
),
186 nQuickHelpTextRefId( REFID_NONE
),
187 nTitleRefId( REFID_NONE
),
196 sGId
= sGId
.replaceAll("\r", rtl::OString());
197 sPForm
= sPForm
.replaceAll("\r", rtl::OString());
200 ResData(const rtl::OString
&rPF
, const rtl::OString
&rGId
, const rtl::OString
&rFilename
)
204 nIdLevel( ID_LEVEL_NULL
),
206 bChildWithText( sal_False
),
208 bHelpText( sal_False
),
209 bQuickHelpText( sal_False
),
212 bRestMerged( sal_False
),
214 sFilename( rFilename
),
215 nTextRefId( REFID_NONE
),
216 nHelpTextRefId( REFID_NONE
),
217 nQuickHelpTextRefId( REFID_NONE
),
218 nTitleRefId( REFID_NONE
),
227 sGId
= sGId
.replaceAll("\r", rtl::OString());
228 sPForm
= sPForm
.replaceAll("\r", rtl::OString());
237 /******************************************************************************
238 * Purpose: syntax check and export of *.src, called from lexer
239 ******************************************************************************/
241 #define LIST_NON 0x0000
242 #define LIST_STRING 0x0001
243 #define LIST_FILTER 0x0002
244 #define LIST_ITEM 0x0004
245 #define LIST_PAIRED 0x0005
246 #define LIST_UIENTRIES 0x0008
247 #define STRING_TYP_TEXT 0x0010
248 #define STRING_TYP_HELPTEXT 0x0020
249 #define STRING_TYP_QUICKHELPTEXT 0x0040
250 #define STRING_TYP_TITLE 0x0080
252 #define MERGE_MODE_NORMAL 0x0000
253 #define MERGE_MODE_LIST 0x0001
255 typedef ::std::vector
< ResData
* > ResStack
;
257 class WordTransformer
;
263 WordTransformer
*pWordTransformer
;
265 std::ofstream aOutput
;
267 ResStack aResStack
; // stack for parsing recursive
269 rtl::OString sActPForm
; // hold cur. system
271 sal_Bool bDefine
; // cur. res. in a define?
272 sal_Bool bNextMustBeDefineEOL
; // define but no \ at lineend
273 std::size_t nLevel
; // res. recursiv? how deep?
274 sal_uInt16 nList
; // cur. res. is String- or FilterList
275 rtl::OString m_sListLang
;
276 std::size_t nListIndex
;
277 std::size_t nListLevel
;
279 rtl::OString sProject
;
282 rtl::OString sMergeSrc
;
283 rtl::OString sLastListLine
;
284 sal_Bool bError
; // any errors while export?
286 sal_Bool bDontWriteOutput
;
287 rtl::OString sLastTextTyp
;
288 static bool isInitialized
;
289 rtl::OString sFilename
;
293 ParserQueue
* pParseQueue
; // public ?
294 static rtl::OString sLanguages
; // public ?
295 static rtl::OString sForcedLanguages
; // public ?
297 static void InitLanguages( bool bMergeMode
= false );
298 static void InitForcedLanguages( bool bMergeMode
= false );
299 static std::vector
<rtl::OString
> GetLanguages();
300 static std::vector
<rtl::OString
> GetForcedLanguages();
302 static void SetLanguages( std::vector
<rtl::OString
> val
);
303 static void RemoveUTF8ByteOrderMarker( rtl::OString
&rString
);
304 static bool hasUTF8ByteOrderMarker( const rtl::OString
&rString
);
305 static rtl::OString
QuoteHTML( rtl::OString
const &rString
);
307 static rtl::OString
UnquoteHTML( rtl::OString
const &rString
);
309 static bool isSourceLanguage(const rtl::OString
&rLanguage
);
310 static bool isAllowed(const rtl::OString
&rLanguage
);
312 static void Languages( std::vector
<rtl::OString
>::const_iterator
& begin
, std::vector
<rtl::OString
>::const_iterator
& end
);
315 static std::vector
<rtl::OString
> aLanguages
;
316 static std::vector
<rtl::OString
> aForcedLanguages
;
318 sal_Bool
WriteData( ResData
*pResData
, sal_Bool bCreateNew
= sal_False
);// called befor dest. cur ResData
319 sal_Bool
WriteExportList( ResData
*pResData
, ExportList
*pExportList
,
320 const rtl::OString
&rTyp
, sal_Bool bCreateNew
= sal_False
);
322 rtl::OString
MergePairedList( rtl::OString
const & sLine
, rtl::OString
const & sText
);
324 rtl::OString
FullId(); // creates cur. GID
326 rtl::OString
GetPairedListID(const rtl::OString
& rText
);
327 rtl::OString
GetPairedListString(const rtl::OString
& rText
);
328 rtl::OString
StripList(const rtl::OString
& rText
);
330 void InsertListEntry(const rtl::OString
&rText
, const rtl::OString
&rLine
);
331 void CleanValue( rtl::OString
&rValue
);
332 rtl::OString
GetText(const rtl::OString
&rSource
, int nToken
);
334 sal_Bool
PrepareTextToMerge(rtl::OString
&rText
, sal_uInt16 nTyp
,
335 rtl::OString
&rLangIndex
, ResData
*pResData
);
336 void ResData2Output( PFormEntrys
*pEntry
, sal_uInt16 nType
, const rtl::OString
& rTextType
);
337 void MergeRest( ResData
*pResData
, sal_uInt16 nMode
= MERGE_MODE_NORMAL
);
338 void ConvertMergeContent( rtl::OString
&rText
);
340 void WriteToMerged(const rtl::OString
&rText
, bool bSDFContent
);
341 void SetChildWithText();
343 void CutComment( rtl::OString
&rText
);
346 Export(const rtl::OString
&rOutput
);
347 Export(const rtl::OString
&rMergeSource
, const rtl::OString
&rOutput
);
351 int Execute( int nToken
, const char * pToken
); // called from lexer
352 void SetError() { bError
= sal_True
; }
353 sal_Bool
GetError() { return bError
; }
361 /******************************************************************************
362 * Purpose: holds information of data to merge (one pform)
363 ******************************************************************************/
367 friend class MergeDataFile
;
369 rtl::OString data_
; //TODO
370 rtl::OString sHelpText
; // empty string
371 OStringHashMap sText
;
372 OStringBoolHashMap bTextFirst
;
373 OStringHashMap sQuickHelpText
;
374 OStringBoolHashMap bQuickHelpTextFirst
;
375 OStringHashMap sTitle
;
376 OStringBoolHashMap bTitleFirst
;
379 PFormEntrys( const rtl::OString
&rPForm
) : data_( rPForm
) {};
380 void InsertEntry(const rtl::OString
&rId
, const rtl::OString
&rText
,
381 const rtl::OString
&rQuickHelpText
, const rtl::OString
&rTitle
)
384 sText
[ rId
] = rText
;
385 bTextFirst
[ rId
] = true;
386 sQuickHelpText
[ rId
] = rQuickHelpText
;
387 bQuickHelpTextFirst
[ rId
] = true;
388 sTitle
[ rId
] = rTitle
;
389 bTitleFirst
[ rId
] = true;
391 sal_Bool
GetText( rtl::OString
&rReturn
, sal_uInt16 nTyp
, const rtl::OString
&nLangIndex
, sal_Bool bDel
= sal_False
);
392 sal_Bool
GetTransex3Text( rtl::OString
&rReturn
, sal_uInt16 nTyp
, const rtl::OString
&nLangIndex
, sal_Bool bDel
= sal_False
);
400 /******************************************************************************
401 * Purpose: holds information of data to merge (one ressource)
402 ******************************************************************************/
408 friend class MergeDataFile
;
413 rtl::OString sFilename
;
414 PFormEntrysHashMap aMap
;
416 MergeData( const rtl::OString
&rTyp
, const rtl::OString
&rGID
, const rtl::OString
&rLID
, const rtl::OString
&rFilename
)
417 : sTyp( rTyp
), sGID( rGID
), sLID( rLID
) , sFilename( rFilename
) {};
419 PFormEntrys
* GetPFormEntries();
421 void Insert( PFormEntrys
* pfEntrys
);
422 PFormEntrys
* GetPFObject( const rtl::OString
&rPFO
);
424 sal_Bool
operator==( ResData
*pData
);
428 // class MergeDataFile
431 /******************************************************************************
432 * Purpose: holds information of data to merge
433 ******************************************************************************/
439 rtl::OString sErrorLog
;
440 MergeDataHashMap aMap
;
441 std::set
<rtl::OString
> aLanguageSet
;
443 MergeData
*GetMergeData( ResData
*pResData
, bool bCaseSensitve
= false );
444 void InsertEntry(const rtl::OString
&rTYP
, const rtl::OString
&rGID
,
445 const rtl::OString
&rLID
, const rtl::OString
&rPFO
,
446 const rtl::OString
&nLang
, const rtl::OString
&rTEXT
,
447 const rtl::OString
&rQHTEXT
, const rtl::OString
&rTITLE
,
448 const rtl::OString
&sFilename
, bool bCaseSensitive
);
450 explicit MergeDataFile(const rtl::OString
&rFileName
,
451 const rtl::OString
& rFile
, bool bErrLog
, bool bCaseSensitive
= false);
455 std::vector
<rtl::OString
> GetLanguages();
457 PFormEntrys
*GetPFormEntrys( ResData
*pResData
);
458 PFormEntrys
*GetPFormEntrysCaseSensitive( ResData
*pResData
);
460 static rtl::OString
CreateKey(const rtl::OString
& rTYP
, const rtl::OString
& rGID
,
461 const rtl::OString
& rLID
, const rtl::OString
& rFilename
, bool bCaseSensitive
= false);
468 QueueEntry(int nTypVal
, const rtl::OString
&rLineVal
)
469 : nTyp(nTypVal
), sLine(rLineVal
)
480 ParserQueue( Export
& aExportObj
);
483 inline void Push( const QueueEntry
& aEntry
);
484 bool bCurrentIsM
; // public ?
485 bool bNextIsM
; // public ?
486 bool bLastWasM
; // public ?
487 bool bMflag
; // public ?
492 std::queue
<QueueEntry
>* aQueueNext
;
494 std::queue
<QueueEntry
>* aQueueCur
;
496 std::queue
<QueueEntry
>* aQref
;
502 inline void Pop( std::queue
<QueueEntry
>& aQueue
);
507 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */