1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: export.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_transex3.hxx"
35 #include <tools/fsys.hxx>
38 #include "utf8conv.hxx"
41 extern "C" { int yyerror( char * ); }
42 extern "C" { int YYWarning( char * ); }
46 // defines to parse command line
47 #define STATE_NON 0x0001
48 #define STATE_INPUT 0x0002
49 #define STATE_OUTPUT 0x0003
50 #define STATE_PRJ 0x0004
51 #define STATE_ROOT 0x0005
52 #define STATE_MERGESRC 0x0006
53 #define STATE_ERRORLOG 0x0007
54 #define STATE_BREAKHELP 0x0008
55 #define STATE_UNMERGE 0x0009
56 #define STATE_UTF8 0x000A
57 #define STATE_LANGUAGES 0X000B
59 // set of global variables
60 DECLARE_LIST( FileList
, ByteString
* )
61 FileList aInputFileList
;
65 BOOL bBreakWhenHelpText
;
71 ByteString sActFileName
;
72 ByteString sOutputFile
;
76 MergeDataFile
*pMergeDataFile
;
80 ByteString sStrBuffer
;
84 // the whole interface to lexer is in this extern "C" section
87 /*****************************************************************************/
88 extern char *GetOutputFile( int argc
, char* argv
[])
89 /*****************************************************************************/
91 bEnableExport
= FALSE
;
94 bBreakWhenHelpText
= FALSE
;
100 Export::sLanguages
= "";
101 Export::sForcedLanguages
= "";
105 USHORT nState
= STATE_NON
;
108 // parse command line
109 for( int i
= 1; i
< argc
; i
++ ) {
110 ByteString
sSwitch( argv
[ i
] );
112 if (sSwitch
== "-i" || sSwitch
== "-I" ) {
113 nState
= STATE_INPUT
; // next tokens specifies source files
115 else if (sSwitch
== "-o" || sSwitch
== "-O" ) {
116 nState
= STATE_OUTPUT
; // next token specifies the dest file
118 else if (sSwitch
== "-p" || sSwitch
== "-P" ) {
119 nState
= STATE_PRJ
; // next token specifies the cur. project
121 else if (sSwitch
== "-qq" || sSwitch
== "-QQ" ) {
125 else if (sSwitch
== "-r" || sSwitch
== "-R" ) {
126 nState
= STATE_ROOT
; // next token specifies path to project root
128 else if (sSwitch
== "-m" || sSwitch
== "-M" ) {
129 nState
= STATE_MERGESRC
; // next token specifies the merge database
131 else if (sSwitch
== "-e" || sSwitch
== "-E" ) {
132 nState
= STATE_ERRORLOG
;
135 else if (sSwitch
== "-b" || sSwitch
== "-B" ) {
136 nState
= STATE_BREAKHELP
;
137 bBreakWhenHelpText
= TRUE
;
139 else if (sSwitch
== "-u" || sSwitch
== "-U" ) {
140 nState
= STATE_UNMERGE
;
144 else if ( sSwitch
.ToUpperAscii() == "-UTF8" ) {
148 else if ( sSwitch
.ToUpperAscii() == "-NOUTF8" ) {
152 else if ( sSwitch
== "-l" || sSwitch
== "-L" ) {
153 nState
= STATE_LANGUAGES
;
158 return NULL
; // no valid command line
161 aInputFileList
.Insert( new ByteString( argv
[ i
]), LIST_APPEND
);
162 bInput
= TRUE
; // min. one source file found
166 sOutputFile
= ByteString( argv
[ i
]); // the dest. file
170 sPrj
= ByteString( argv
[ i
]);
174 sPrjRoot
= ByteString( argv
[ i
]); // path to project root
177 case STATE_MERGESRC
: {
178 sMergeSrc
= ByteString( argv
[ i
]);
179 bMergeMode
= TRUE
; // activate merge mode, cause merge database found
182 case STATE_LANGUAGES
: {
183 Export::sLanguages
= ByteString( argv
[ i
]);
189 if( bUnmerge
) sMergeSrc
= ByteString();
191 // command line is valid
192 bEnableExport
= TRUE
;
193 char *pReturn
= new char[ sOutputFile
.Len() + 1 ];
194 strcpy( pReturn
, sOutputFile
.GetBuffer()); // #100211# - checked
198 // command line is not valid
201 /*****************************************************************************/
203 /*****************************************************************************/
204 if( bQuiet
) return 1;
207 /*****************************************************************************/
208 int InitExport( char *pOutput
, char* pFilename
)
209 /*****************************************************************************/
211 // instanciate Export
212 ByteString
sOutput( pOutput
);
213 ByteString
sFilename( pFilename
);
215 if ( bMergeMode
&& !bUnmerge
) {
216 // merge mode enabled, so read database
217 pExport
= new Export(sOutput
, bEnableExport
, sPrj
, sPrjRoot
, sMergeSrc
, sFilename
);
220 // no merge mode, only export
221 pExport
= new Export( sOutput
, bEnableExport
, sPrj
, sPrjRoot
, sFilename
);
225 /*****************************************************************************/
227 /*****************************************************************************/
233 extern const char* getFilename()
235 return (*(aInputFileList
.GetObject( 0 ))).GetBuffer();
237 /*****************************************************************************/
238 extern FILE *GetNextFile()
239 /*****************************************************************************/
241 // look for next valid filename in input file list
242 if ( sTempFile
.Len()) {
244 String
sTemp( sTempFile
, RTL_TEXTENCODING_ASCII_US
);
245 DirEntry
aTemp( sTemp
);
249 while ( aInputFileList
.Count()) {
250 ByteString
sFileName( *(aInputFileList
.GetObject( 0 )));
252 ByteString
sOrigFile( sFileName
);
254 sFileName
= Export::GetNativeFile( sFileName
);
255 delete aInputFileList
.GetObject(( ULONG
) 0 );
256 aInputFileList
.Remove(( ULONG
) 0 );
258 if ( sFileName
== "" ) {
259 fprintf( stderr
, "ERROR: Could not precompile File %s\n",
260 sOrigFile
.GetBuffer());
261 return GetNextFile();
264 sTempFile
= sFileName
;
265 Export::RemoveUTF8ByteOrderMarkerFromFile( sFileName
);
267 // able to open file?
268 FILE *pFile
= fopen( sFileName
.GetBuffer(), "r" );
270 fprintf( stderr
, "Error: Could not open File %s\n",
271 sFileName
.GetBuffer());
275 // this is a valid file which can be opened, so
276 // create path to project root
277 DirEntry
aEntry( String( sOrigFile
, RTL_TEXTENCODING_ASCII_US
));
279 ByteString
sFullEntry( aEntry
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
280 aEntry
+= DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US
));
281 aEntry
+= DirEntry( sPrjRoot
);
282 ByteString
sPrjEntry( aEntry
.GetFull(), RTL_TEXTENCODING_ASCII_US
);
284 // create file name, beginnig with project root
285 // (e.g.: source\ui\src\menue.src)
286 sActFileName
= sFullEntry
.Copy( sPrjEntry
.Len() + 1 );
288 if( !bQuiet
) fprintf( stdout
, "\nProcessing File %s ...\n", sOrigFile
.GetBuffer());
290 sActFileName
.SearchAndReplaceAll( "/", "\\" );
291 sFile
= sActFileName
;
294 // create instance of class export
297 // return the valid file handle
301 // this means the file could not be opened
305 int Parse( int nTyp
, const char *pTokenText
){
306 pExport
->Execute( nTyp
, pTokenText
);
310 pExport
->pParseQueue
->Close();
312 /*****************************************************************************/
313 int WorkOnTokenSet( int nTyp
, char *pTokenText
)
314 /*****************************************************************************/
317 pExport
->pParseQueue
->Push( QueueEntry( nTyp
, ByteString( pTokenText
) ) );
324 /*****************************************************************************/
326 /*****************************************************************************/
328 // set error at global instance of class Export
335 /*****************************************************************************/
337 /*****************************************************************************/
339 // get error at global instance of class Export
340 if ( pExport
->GetError())
350 void ResData::Dump(){
351 printf("**************\nResData\n");
352 printf("sPForm = %s , sResTyp = %s , sId = %s , sGId = %s , sHelpId = %s\n",sPForm
.GetBuffer()
353 ,sResTyp
.GetBuffer(),sId
.GetBuffer(),sGId
.GetBuffer(),sHelpId
.GetBuffer());
355 ByteString
a("*pStringList");
356 ByteString
b("*pUIEntries");
357 ByteString
c("*pFilterList");
358 ByteString
d("*pItemList");
359 ByteString
e("*pPairedList");
360 ByteString
f("sText");
362 Export::DumpMap( f
, sText
);
364 if( pStringList
) Export::DumpExportList( a
, *pStringList
);
365 if( pUIEntries
) Export::DumpExportList( b
, *pUIEntries
);
366 if( pFilterList
) Export::DumpExportList( c
, *pFilterList
);
367 if( pItemList
) Export::DumpExportList( d
, *pItemList
);
368 if( pPairedList
) Export::DumpExportList( e
, *pPairedList
);
372 void ResData::addFallbackData( ByteString
& sId_in
, const ByteString
& sText_in
){
373 //printf(" ResData::addFallbackData ( sId = %s , sText = %s )\n", sId_in.GetBuffer() , sText_in.GetBuffer() );
374 aFallbackData
[ sId_in
] = sText_in
;
376 bool ResData::getFallbackData( ByteString
& sId_in
, ByteString
& sText_inout
){
377 sText_inout
= aFallbackData
[ sId_in
];
378 //printf("ResData::getFallbackData( sId = %s , return sText = %s \n" , sId_in.GetBuffer(), sText_inout.GetBuffer());
379 return sText_inout
.Len() > 0;
382 void ResData::addMergedLanguage( ByteString
& sLang
){
383 aMergedLanguages
[ sLang
]=ByteString("1");
385 bool ResData::isMerged( ByteString
& sLang
){
386 return aMergedLanguages
[ sLang
].Equals("1");
389 /*****************************************************************************/
390 BOOL
ResData::SetId( const ByteString
&rId
, USHORT nLevel
)
391 /*****************************************************************************/
393 if ( nLevel
> nIdLevel
)
398 if ( bChild
&& bChildWithText
) {
399 ByteString
sError( "ResId after child definition" );
400 yyerror( sError
.GetBufferAccess());
401 sError
.ReleaseBufferAccess();
405 if ( sId
.Len() > 255 ) {
406 ByteString
sWarning( "LocalId > 255 chars, truncating..." );
407 YYWarning( sWarning
.GetBufferAccess());
408 sWarning
.ReleaseBufferAccess();
410 sId
.EraseTrailingChars( ' ' );
411 sId
.EraseTrailingChars( '\t' );
424 /*****************************************************************************/
425 Export::Export( const ByteString
&rOutput
, BOOL bWrite
,
426 const ByteString
&rPrj
, const ByteString
&rPrjRoot
, const ByteString
& rFile
)
427 /*****************************************************************************/
429 pWordTransformer( NULL
),
430 aCharSet( RTL_TEXTENCODING_MS_1252
),
432 bNextMustBeDefineEOL( FALSE
),
440 bEnableExport( bWrite
),
441 bMergeMode( bUnmerge
),
444 bDontWriteOutput( FALSE
),
447 pParseQueue
= new ParserQueue( *this );
452 if( !isInitialized
) InitLanguages();
453 // used when export is enabled
455 // open output stream
456 if ( bEnableExport
) {
457 aOutput
.Open( String( rOutput
, RTL_TEXTENCODING_ASCII_US
), STREAM_STD_WRITE
| STREAM_TRUNC
);
458 if( !aOutput
.IsOpen() ) {
459 printf("ERROR : Can't open file %s\n",rOutput
.GetBuffer());
462 aOutput
.SetStreamCharSet( RTL_TEXTENCODING_UTF8
);
464 aOutput
.SetLineDelimiter( LINEEND_CRLF
);
468 /*****************************************************************************/
469 Export::Export( const ByteString
&rOutput
, BOOL bWrite
,
470 const ByteString
&rPrj
, const ByteString
&rPrjRoot
,
471 const ByteString
&rMergeSource
, const ByteString
& rFile
)
472 /*****************************************************************************/
474 pWordTransformer( NULL
),
475 aCharSet( RTL_TEXTENCODING_MS_1252
),
477 bNextMustBeDefineEOL( FALSE
),
485 bEnableExport( bWrite
),
487 sMergeSrc( rMergeSource
),
490 bDontWriteOutput( FALSE
),
496 pParseQueue
= new ParserQueue( *this );
497 if( !isInitialized
) InitLanguages( bMergeMode
);
498 // used when merge is enabled
500 // open output stream
501 if ( bEnableExport
) {
502 aOutput
.Open( String( rOutput
, RTL_TEXTENCODING_ASCII_US
), STREAM_STD_WRITE
| STREAM_TRUNC
);
503 aOutput
.SetStreamCharSet( RTL_TEXTENCODING_UTF8
);
504 aOutput
.SetLineDelimiter( LINEEND_CRLF
);
509 /*****************************************************************************/
511 /*****************************************************************************/
513 // resets the internal status, used before parseing another file
516 bNextMustBeDefineEOL
= FALSE
;
519 nListLang
= ByteString( String::CreateFromAscii(""),RTL_TEXTENCODING_ASCII_US
);
521 while ( aResStack
.Count()) {
522 delete aResStack
.GetObject(( ULONG
) 0 );
523 aResStack
.Remove(( ULONG
) 0 );
527 /*****************************************************************************/
529 /*****************************************************************************/
533 // close output stream
536 while ( aResStack
.Count()) {
537 delete aResStack
.GetObject(( ULONG
) 0 );
538 aResStack
.Remove(( ULONG
) 0 );
541 if ( bMergeMode
&& !bUnmerge
) {
542 if ( !pMergeDataFile
)
543 pMergeDataFile
= new MergeDataFile( sMergeSrc
,sFile
, bErrorLog
, aCharSet
);//, bUTF8 );
545 //pMergeDataFile->WriteErrorLog( sActFileName );
546 delete pMergeDataFile
;
550 /*****************************************************************************/
551 int Export::Execute( int nToken
, const char * pToken
)
552 /*****************************************************************************/
555 ByteString
sToken( pToken
);
556 ByteString
sOrig( sToken
);
557 /* printf("+---------------\n");
558 printf("sToken = %s\n",sToken.GetBuffer());
559 printf("nToken = %d\n",nToken);
560 printf("+---------------\n"); */
561 BOOL bWriteToMerged
= bMergeMode
;
563 if ( nToken
== CONDITION
) {
564 ByteString
sTestToken( pToken
);
565 sTestToken
.EraseAllChars( '\t' );
566 sTestToken
.EraseAllChars( ' ' );
567 if (( !bReadOver
) && ( sTestToken
.Search( "#ifndef__RSC_PARSER" ) == 0 ))
569 else if (( bReadOver
) && ( sTestToken
.Search( "#endif" ) == 0 ))
572 if ((( nToken
< FILTER_LEVEL
) || ( bReadOver
)) &&
573 (!(( bNextMustBeDefineEOL
) && ( sOrig
== "\n" )))) {
574 // this tokens are not mandatory for parsing, so ignore them ...
576 WriteToMerged( sOrig
, false ); // ... ore whrite them directly to dest.
580 ResData
*pResData
= NULL
;
582 // res. exists at cur. level
583 pResData
= aResStack
.GetObject( nLevel
-1 );
585 else if (( nToken
!= RESSOURCE
) &&
586 ( nToken
!= RESSOURCEEXPR
) &&
587 ( nToken
!= SMALRESSOURCE
) &&
588 ( nToken
!= LEVELUP
) &&
589 ( nToken
!= NORMDEFINE
) &&
590 ( nToken
!= RSCDEFINE
) &&
591 ( nToken
!= CONDITION
) &&
592 ( nToken
!= PRAGMA
))
594 // no res. exists at cur. level so return
596 WriteToMerged( sOrig
, false );
599 // #define NO_LOCALIZE_EXPORT
602 WriteToMerged( sOrig
, false );
609 if (( nToken
!= EMPTYLINE
) && ( nToken
!= LEVELDOWN
) && ( nToken
!= LEVELUP
)) {
610 // cur. res. defined in macro
611 if ( bNextMustBeDefineEOL
) {
612 if ( nToken
!= RSCDEFINELEND
) {
613 // end of macro found, so destroy res.
616 /*if ( bDontWriteOutput && bUnmerge ) {
617 bDontWriteOutput = FALSE;
618 bNextMustBeDefineEOL = FALSE;
621 MergeRest( pResData
);
623 bNextMustBeDefineEOL
= FALSE
;
624 Execute( LEVELDOWN
, "" );
627 // next line also in macro definition
628 bNextMustBeDefineEOL
= FALSE
;
630 WriteToMerged( sOrig
, false );
634 else if (( nToken
!= LISTASSIGNMENT
) && ( nToken
!= UIENTRIES
)){
635 // cur. line has macro line end
636 ByteString
sTmpLine( sToken
);
637 sTmpLine
.EraseAllChars( '\t' ); sTmpLine
.EraseAllChars( ' ' );
639 // impossible, unsigned is never negative
640 if( sTmpLine
.Len() < 0 ){
641 if ( sTmpLine
.GetChar(( USHORT
)( sTmpLine
.Len() - 1 )) != '\\' )
642 bNextMustBeDefineEOL
= TRUE
;
649 BOOL bExecuteDown
= FALSE
;
650 if ( nToken
!= LEVELDOWN
) {
653 BOOL bReadOver1
= FALSE
;
655 for ( i
= 0; i
< sToken
.Len(); i
++ ) {
656 if ( sToken
.GetChar( i
) == '\"' )
657 bReadOver1
= !bReadOver1
;
658 if ( !bReadOver1
&& ( sToken
.GetChar( i
) == '{' ))
663 for ( i
= 0; i
< sToken
.Len(); i
++ ) {
664 if ( sToken
.GetChar( i
) == '\"' )
665 bReadOver1
= !bReadOver1
;
666 if ( !bReadOver1
&& ( sToken
.GetChar( i
) == '}' ))
670 if ( nOpen
< nClose
)
676 //printf("sToken = '%s'",sToken.GetBuffer());
677 while( sToken
.SearchAndReplace( "\r", " " ) != STRING_NOTFOUND
) {};
678 while( sToken
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
679 while( sToken
.SearchAndReplace( " ", " " ) != STRING_NOTFOUND
) {};
680 if( sToken
.EqualsIgnoreCaseAscii( "#define NO_LOCALIZE_EXPORT" ) ){
685 WriteToMerged( sOrig
, false );
691 bDefine
= TRUE
; // res. defined in macro
694 case RESSOURCEEXPR
: {
695 bDontWriteOutput
= FALSE
;
696 if ( nToken
!= RSCDEFINE
)
697 bNextMustBeDefineEOL
= FALSE
;
698 // this is the beginning of a new res.
701 aResStack
.GetObject( nLevel
- 2 )->bChild
= TRUE
;
704 // create new instance for this res. and fill mandatory fields
706 pResData
= new ResData( sActPForm
, FullId() , sFilename
);
707 aResStack
.Insert( pResData
, LIST_APPEND
);
708 ByteString
sBackup( sToken
);
709 sToken
.EraseAllChars( '\n' );
710 sToken
.EraseAllChars( '\r' );
711 sToken
.EraseAllChars( '{' );
712 while( sToken
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
713 sToken
.EraseTrailingChars( ' ' );
714 ByteString sT
= sToken
.GetToken( 0, ' ' );
715 pResData
->sResTyp
= sT
.ToLowerAscii();
716 ByteString
sId( sToken
.Copy( pResData
->sResTyp
.Len() + 1 ));
717 ByteString sCondition
;
718 if ( sId
.Search( "#" ) != STRING_NOTFOUND
) {
719 // between ResTyp, Id and paranthes is a precomp. condition
721 sCondition
+= sId
.GetToken( 1, '#' );
722 sId
= sId
.GetToken( 0, '#' );
724 sId
= sId
.GetToken( 0, '/' );
726 sId
= sId
.EraseAllChars( '\t' );
727 pResData
->SetId( sId
, ID_LEVEL_IDENTIFIER
);
728 if ( sCondition
.Len()) {
729 ByteString
sEmpty( "" );
730 Execute( CONDITION
, sEmpty
.GetBufferAccess()); // execute the
733 sEmpty
.ReleaseBufferAccess();
737 case SMALRESSOURCE
: {
738 bDontWriteOutput
= FALSE
;
739 // this is the beginning of a new res.
740 bNextMustBeDefineEOL
= FALSE
;
743 aResStack
.GetObject( nLevel
- 2 )->bChild
= TRUE
;
746 // create new instance for this res. and fill mandatory fields
748 pResData
= new ResData( sActPForm
, FullId() , sFilename
);
749 aResStack
.Insert( pResData
, LIST_APPEND
);
750 sToken
.EraseAllChars( '\n' );
751 sToken
.EraseAllChars( '\r' );
752 sToken
.EraseAllChars( '{' );
753 sToken
.EraseAllChars( '\t' );
754 sToken
.EraseAllChars( ' ' );
755 sToken
.EraseAllChars( '\\' );
756 pResData
->sResTyp
= sToken
.ToLowerAscii();
766 bDontWriteOutput
= FALSE
;
767 ByteString sLowerTyp
;
769 sLowerTyp
= "unknown";
772 aResStack
.GetObject( nLevel
- 2 )->bChild
= TRUE
;
775 ResData
*pNewData
= new ResData( sActPForm
, FullId() , sFilename
);
776 pNewData
->sResTyp
= sLowerTyp
;
777 aResStack
.Insert( pNewData
, LIST_APPEND
);
783 bDontWriteOutput
= FALSE
;
785 if ( bDefine
&& (nLevel
== 1 )) {
787 bNextMustBeDefineEOL
= FALSE
;
789 WriteData( pResData
);
790 delete aResStack
.GetObject( nLevel
- 1 );
791 aResStack
.Remove( nLevel
- 1 );
797 bNextMustBeDefineEOL
= TRUE
;
800 MergeRest( pResData
, MERGE_MODE_LIST
);
809 bDontWriteOutput
= FALSE
;
810 // interpret different types of assignement
811 ByteString sKey
= sToken
.GetToken( 0, '=' );
812 sKey
.EraseAllChars( ' ' );
813 sKey
.EraseAllChars( '\t' );
814 ByteString sValue
= sToken
.GetToken( 1, '=' );
815 CleanValue( sValue
);
816 if ( sKey
.ToUpperAscii() == "IDENTIFIER" ) {
817 ByteString
sId( sValue
.EraseAllChars( '\t' ));
818 pResData
->SetId( sId
.EraseAllChars( ' ' ), ID_LEVEL_IDENTIFIER
);
820 else if ( sKey
== "HELPID" ) {
821 pResData
->sHelpId
= sValue
;
823 else if ( sKey
== "STRINGLIST" ) {
825 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
828 pResData
->bList
= TRUE
;
830 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
831 nListLang
= SOURCE_LANGUAGE
;
835 else if ( sKey
== "FILTERLIST" ) {
837 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
839 pResData
->bList
= TRUE
;
841 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
842 nListLang
= SOURCE_LANGUAGE
;
846 else if ( sKey
== "UIENTRIES" ) {
848 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));}
849 pResData
->bList
= TRUE
;
850 nList
= LIST_UIENTRIES
;
851 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
852 nListLang
= SOURCE_LANGUAGE
;
856 if (( sToken
.Search( "{" ) != STRING_NOTFOUND
) &&
857 ( sToken
.GetTokenCount( '{' ) > sToken
.GetTokenCount( '}' )))
859 //WorkOnTokenSet( LEVELUP, pTkn );
860 Parse( LEVELUP
, "" );
862 //if ( bUnmerge && ( nListLang.EqualsIgnoreCaseAscii("de") || nListLang.EqualsIgnoreCaseAscii("en-US") ) && ListExists( pResData, nList ))
863 // bDontWriteOutput = TRUE;
867 case LISTASSIGNMENT
: {
868 bDontWriteOutput
= FALSE
;
869 ByteString
sTmpToken( sToken
);
870 sTmpToken
.EraseAllChars(' ');
872 //nPos = sTmpToken.ToLowerAscii().Search("[de]=");
873 nPos
= sTmpToken
.ToLowerAscii().Search("[en-us]=");
874 if( nPos
!= STRING_NOTFOUND
) {
876 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
878 ByteString sKey
= sTmpToken
.Copy( 0 , nPos
);
879 sKey
.EraseAllChars( ' ' );
880 sKey
.EraseAllChars( '\t' );
881 ByteString sValue
= sToken
.GetToken( 1, '=' );
882 CleanValue( sValue
);
883 if ( sKey
.ToUpperAscii() == "STRINGLIST" ) {
884 pResData
->bList
= TRUE
;
886 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
887 nListLang
= SOURCE_LANGUAGE
;
891 else if ( sKey
== "FILTERLIST" ) {
892 pResData
->bList
= TRUE
;
894 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
895 nListLang
= SOURCE_LANGUAGE
;
900 else if ( sKey
== "PAIREDLIST" ) {
901 pResData
->bList
= TRUE
;
903 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
904 nListLang
= SOURCE_LANGUAGE
;
909 else if ( sKey
== "ITEMLIST" ) {
910 pResData
->bList
= TRUE
;
912 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
913 nListLang
= SOURCE_LANGUAGE
;
917 else if ( sKey
== "UIENTRIES" ) {
918 pResData
->bList
= TRUE
;
919 nList
= LIST_UIENTRIES
;
920 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
921 nListLang
= SOURCE_LANGUAGE
;
925 /*if ( bUnmerge && ( nListLang.EqualsIgnoreCaseAscii( "de" )
926 || nListLang.EqualsIgnoreCaseAscii("en-US" ) )
927 && ListExists( pResData, nList ))
928 bDontWriteOutput = TRUE;*/
931 // new res. is a String- or FilterList
932 ByteString sKey
= sToken
.GetToken( 0, '[' );
933 sKey
.EraseAllChars( ' ' );
934 sKey
.EraseAllChars( '\t' );
935 if ( sKey
.ToUpperAscii() == "STRINGLIST" )
937 else if ( sKey
== "FILTERLIST" )
939 else if ( sKey
== "PAIREDLIST" )
940 nList
= LIST_PAIRED
; // abcd
941 else if ( sKey
== "ITEMLIST" )
943 else if ( sKey
== "UIENTRIES" )
944 nList
= LIST_UIENTRIES
;
946 ByteString sLang
=sToken
.GetToken( 1, '[' ).GetToken( 0, ']' );
949 /*if (( bUnmerge ) && ( !nListLang.EqualsIgnoreCaseAscii("de")) && ( !nListLang.EqualsIgnoreCaseAscii("en-US")))
950 bDontWriteOutput = TRUE;*/
953 /*if ( bUnmerge && nListLang.EqualsIgnoreCaseAscii("de") && ListExists( pResData, nList ) )
954 bDontWriteOutput = TRUE;*/
962 // this is an entry for a String- or FilterList
965 ByteString
sEntry( sToken
.GetToken( 1, '\"' ));
966 if ( sToken
.GetTokenCount( '\"' ) > 3 )
968 if ( sEntry
== "\\\"" )
970 //sEntry = sEntry.Convert( aCharSet, RTL_TEXTENCODING_MS_1252 );
971 //sEntry = sEntry.Convert( RTL_TEXTENCODING_MS_1252, RTL_TEXTENCODING_UTF8 );
972 InsertListEntry( sEntry
, sOrig
);
973 if ( bMergeMode
&& ( sEntry
!= "\"" )) {
974 PrepareTextToMerge( sOrig
, nList
, nListLang
, pResData
);
981 bDontWriteOutput
= FALSE
;
983 CutComment( sToken
);
985 // this is a text line!!!
986 ByteString sKey
= sToken
.GetToken( 0, '=' ).GetToken( 0, '[' );
987 sKey
.EraseAllChars( ' ' );
988 sKey
.EraseAllChars( '\t' );
989 ByteString
sText( GetText( sToken
, nToken
));
991 sText
= sText
.Convert( aCharSet
, RTL_TEXTENCODING_MS_1252
);
993 if ( sToken
.GetToken( 0, '=' ).Search( "[" ) != STRING_NOTFOUND
) {
994 sLang
= sToken
.GetToken( 0, '=' ).GetToken( 1, '[' ).GetToken( 0, ']' );
997 ByteString nLangIndex
= sLang
;
998 ByteString sOrigKey
= sKey
;
999 if ( sText
.Len() && sLang
.Len() ) {
1000 if (( sKey
.ToUpperAscii() == "TEXT" ) ||
1001 ( sKey
== "MESSAGE" ) ||
1002 ( sKey
== "CUSTOMUNITTEXT" ) ||
1003 ( sKey
== "SLOTNAME" ) ||
1004 ( sKey
== "UINAME" ))
1006 //if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND )
1007 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1010 //if ( nLangIndex.EqualsIgnoreCaseAscii("en-US") )
1011 if ( Export::isSourceLanguage( nLangIndex
) )
1012 pResData
->SetId( sText
, ID_LEVEL_TEXT
);
1014 pResData
->bText
= TRUE
;
1015 pResData
->sTextTyp
= sOrigKey
;
1017 PrepareTextToMerge( sOrig
, STRING_TYP_TEXT
, nLangIndex
, pResData
);
1019 // pResData->sText[ nLangIndex ] = sText;
1022 if ( pResData
->sText
[ nLangIndex
].Len()) {
1023 ByteString
sError( "Language " );
1024 sError
+= nLangIndex
;
1025 sError
+= " defined twice";
1027 pResData
->sText
[ nLangIndex
] = sText
;
1030 else if ( sKey
== "HELPTEXT" ) {
1031 //if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1032 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1035 pResData
->bHelpText
= TRUE
;
1036 if ( bBreakWhenHelpText
) {
1037 ByteString
sError( "\"HelpText\" found in source\n" );
1038 YYWarning( sError
.GetBufferAccess());
1039 sError
.ReleaseBufferAccess();
1043 PrepareTextToMerge( sOrig
, STRING_TYP_HELPTEXT
, nLangIndex
, pResData
);
1045 // pResData->sHelpText[ nLangIndex ] = sText;
1047 if ( pResData
->sHelpText
[ nLangIndex
].Len()) {
1048 ByteString
sError( "Language " );
1049 sError
+= nLangIndex
;
1050 sError
+= " defined twice";
1052 pResData
->sHelpText
[ nLangIndex
] = sText
;
1055 else if ( sKey
== "QUICKHELPTEXT" ) {
1056 //if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1057 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1060 pResData
->bQuickHelpText
= TRUE
;
1062 PrepareTextToMerge( sOrig
, STRING_TYP_QUICKHELPTEXT
, nLangIndex
, pResData
);
1064 // pResData->sQuickHelpText[ nLangIndex ] = sText;
1066 if ( pResData
->sQuickHelpText
[ nLangIndex
].Len()) {
1067 ByteString
sError( "Language " );
1068 sError
+= nLangIndex
;
1069 sError
+= " defined twice";
1071 pResData
->sQuickHelpText
[ nLangIndex
] = sText
;
1074 else if ( sKey
== "TITLE" ) {
1075 //if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1076 // ( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1079 pResData
->bTitle
= TRUE
;
1081 PrepareTextToMerge( sOrig
, STRING_TYP_TITLE
, nLangIndex
, pResData
);
1083 // pResData->sTitle[ nLangIndex ] = sText;
1085 if ( pResData
->sTitle
[ nLangIndex
].Len()) {
1086 ByteString
sError( "Language " );
1087 sError
+= nLangIndex
;
1088 sError
+= " defined twice";
1090 pResData
->sTitle
[ nLangIndex
] = sText
;
1093 else if ( sKey
== "ACCESSPATH" ) {
1094 pResData
->SetId( sText
, ID_LEVEL_ACCESSPATH
);
1096 else if ( sKey
== "FIELDNAME" ) {
1097 pResData
->SetId( sText
, ID_LEVEL_FIELDNAME
);
1102 case NEWTEXTINRES
: {
1103 bDontWriteOutput
= TRUE
;
1104 // this means something like // ### Achtung : Neuer Text ...
1105 /*ByteString sLang( "GERMAN" );
1106 ByteString sText = sToken.GetToken( 2, ':' ).GetToken( 0, '*' );
1107 CleanValue( sText );
1109 pResData->sText[ sLang ] = sText;*/
1112 case APPFONTMAPPING
: {
1113 bDontWriteOutput
= FALSE
;
1114 // this is a AppfontMapping, so look if its a definition
1116 ByteString sKey
= sToken
.GetToken( 0, '=' );
1117 sKey
.EraseAllChars( ' ' );
1118 sKey
.EraseAllChars( '\t' );
1119 ByteString sMapping
= sToken
.GetToken( 1, '=' );
1120 sMapping
= sMapping
.GetToken( 1, '(' );
1121 sMapping
= sMapping
.GetToken( 0, ')' );
1122 sMapping
.EraseAllChars( ' ' );
1123 sMapping
.EraseAllChars( '\t' );
1124 if ( sKey
.ToUpperAscii() == "SIZE" ) {
1125 pResData
->nWidth
= ( USHORT
) sMapping
.GetToken( 0, ',' ).ToInt64();
1127 else if ( sKey
== "POSSIZE" ) {
1128 pResData
->nWidth
= ( USHORT
) sMapping
.GetToken( 2, ',' ).ToInt64();
1133 bDontWriteOutput
= FALSE
;
1136 bDontWriteOutput
= FALSE
;
1137 while( sToken
.SearchAndReplace( "\r", " " ) != STRING_NOTFOUND
) {};
1138 while( sToken
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
1139 while( sToken
.SearchAndReplace( " ", " " ) != STRING_NOTFOUND
) {};
1140 ByteString sCondition
= sToken
.GetToken( 0, ' ' );
1141 if ( sCondition
== "#ifndef" ) {
1142 sActPForm
= "!defined ";
1143 sActPForm
+= sToken
.GetToken( 1, ' ' );
1145 else if ( sCondition
== "#ifdef" ) {
1146 sActPForm
= "defined ";
1147 sActPForm
+= sToken
.GetToken( 1, ' ' );
1149 else if ( sCondition
== "#if" ) {
1150 sActPForm
= sToken
.Copy( 4 );
1151 while ( sActPForm
.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND
) {};
1153 else if ( sCondition
== "#elif" ) {
1154 sActPForm
= sToken
.Copy( 6 );
1155 while ( sActPForm
.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND
) {};
1157 else if ( sCondition
== "#else" ) {
1158 sActPForm
= sCondition
;
1160 else if ( sCondition
== "#endif" ) {
1165 WriteData( pResData
, TRUE
);
1166 pResData
->sPForm
= sActPForm
;
1171 bDontWriteOutput
= FALSE
;
1173 bNextMustBeDefineEOL
= FALSE
;
1176 Parse( LEVELDOWN
, "" );
1177 //WorkOnTokenSet( LEVELDOWN, pTkn );
1182 bDontWriteOutput
= FALSE
;
1183 while( sToken
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
1184 while( sToken
.SearchAndReplace( " ", " " ) != STRING_NOTFOUND
) {};
1185 sToken
.EraseLeadingChars( ' ' );
1186 sToken
.EraseTrailingChars( ' ' );
1188 ByteString sCharset
= sToken
.GetToken( 1, ' ' );
1189 ByteString sSet
= sToken
.GetToken( 2, ' ' );
1190 if (( sCharset
.ToUpperAscii() == "CHARSET_IBMPC" ) ||
1191 ( sCharset
== "RTL_TEXTENCODING_IBM_850" ) ||
1192 (( sCharset
== "CHARSET" ) && ( sSet
.ToUpperAscii() == "IBMPC" )))
1194 aCharSet
= RTL_TEXTENCODING_IBM_850
;
1196 else if (( sCharset
== "CHARSET_ANSI" ) ||
1197 ( sCharset
== "RTL_TEXTENCODING_MS_1252" ) ||
1198 (( sCharset
== "CHARSET" ) && ( sSet
.ToUpperAscii() == "ANSI" )))
1200 aCharSet
= RTL_TEXTENCODING_MS_1252
;
1205 bDontWriteOutput
= TRUE
;
1206 /*ByteString sK = sToken.GetToken( 0, '=' );
1207 ByteString sKey = sK.EraseAllChars( '\t' ).EraseAllChars( ' ' );
1208 ByteString sT = sToken.GetToken( 1, '=' ).GetToken( 0, ';' );
1209 USHORT nRefId = ( USHORT ) sT.EraseAllChars( '\t' ).EraseAllChars( ' ' ).ToInt32();
1210 if (( sKey.ToUpperAscii() == "TEXT" ) ||
1211 ( sKey == "MESSAGE" ) ||
1212 ( sKey == "CUSTOMUNITTEXT" ) ||
1213 ( sKey == "SLOTNAME" ) ||
1214 ( sKey == "UINAME" ))
1215 pResData->nTextRefId = nRefId;
1216 else if ( sKey == "HELPTEXT" )
1217 pResData->nHelpTextRefId = nRefId;
1218 else if ( sKey == "QUICKHELPTEXT" )
1219 pResData->nQuickHelpTextRefId = nRefId;
1220 else if ( sKey == "TITLE" )
1221 pResData->nTitleRefId = nRefId;*/
1224 if ( bWriteToMerged
) {
1225 // the current token must be written to dest. without merging
1227 if( bDefine
&& sOrig
.Len() > 2 ){
1228 for( USHORT n
= 0 ; n
< sOrig
.Len() ; n
++ ){
1229 if( sOrig
.GetChar( n
) == '\n' && sOrig
.GetChar( n
-1 ) != '\\'){
1230 sOrig
.Insert('\\' , n
++ );
1234 WriteToMerged( sOrig
, false);
1237 if ( bExecuteDown
) {
1238 Parse( LEVELDOWN
, "" );
1239 //WorkOnTokenSet( LEVELDOWN, pTkn );
1245 /*****************************************************************************/
1246 void Export::CutComment( ByteString
&rText
)
1247 /*****************************************************************************/
1249 if ( rText
.Search( "//" ) != STRING_NOTFOUND
) {
1250 ByteString
sWork( rText
);
1251 sWork
.SearchAndReplaceAll( "\\\"", "XX" );
1253 BOOL bInner
= FALSE
;
1255 while ( i
< sWork
.Len() - 1 ) {
1256 if ( sWork
.GetChar( i
) == '\"' )
1259 (( sWork
.GetChar( i
) == '/' ) &&
1261 ( sWork
.GetChar( i
+ 1 ) == '/' ))
1271 void Export::UnmergeUTF8( ByteString
& sOrig
){
1272 USHORT nPos1
= sOrig
.Search('\"');
1273 USHORT nPos2
= sOrig
.SearchBackward('\"');
1274 if( nPos1
> 0 && nPos2
> 0 && nPos1
< nPos2
){
1275 ByteString sPart
= sOrig
.Copy(nPos1
+1 , nPos2
-1);
1276 ByteString sPartUTF8
= sPart
;
1277 sPartUTF8
.Convert( RTL_TEXTENCODING_MS_1252
, RTL_TEXTENCODING_UTF8
);
1278 sOrig
.SearchAndReplace( sPart
, sPartUTF8
);
1282 /*****************************************************************************/
1283 BOOL
Export::ListExists( ResData
*pResData
, USHORT nLst
)
1284 /*****************************************************************************/
1287 case LIST_STRING
: return pResData
->pStringList
!= NULL
;
1288 case LIST_FILTER
: return pResData
->pFilterList
!= NULL
;
1289 case LIST_ITEM
: return pResData
->pItemList
!= NULL
;
1290 case LIST_PAIRED
: return pResData
->pPairedList
!= NULL
;
1291 case LIST_UIENTRIES
: return pResData
->pUIEntries
!= NULL
;
1296 /*****************************************************************************/
1297 BOOL
Export::WriteData( ResData
*pResData
, BOOL bCreateNew
)
1298 /*****************************************************************************/
1301 MergeRest( pResData
);
1308 /* ByteStringHashMap::iterator pos3 = pResData->sText.begin();
1309 ByteStringHashMap::iterator end3 = pResData->sText.end();
1310 for(;pos3!=end3;++pos3){
1312 printf("[%s]=%s\n", pos3->first.GetBuffer(), pos3->second.GetBuffer() );
1314 // mandatory to export: en-US
1316 if (( //pResData->sText[ ByteString("de") ].Len() &&
1317 ( pResData
->sText
[ SOURCE_LANGUAGE
].Len()))
1319 ( //pResData->sHelpText[ ByteString("de") ].Len() &&
1320 ( pResData
->sHelpText
[ SOURCE_LANGUAGE
].Len()))
1322 ( //pResData->sQuickHelpText[ ByteString("de") ].Len() &&
1323 ( pResData
->sQuickHelpText
[ SOURCE_LANGUAGE
].Len()))
1325 ( //pResData->sTitle[ ByteString("de") ].Len() &&
1326 ( pResData
->sTitle
[ SOURCE_LANGUAGE
].Len())))
1329 FillInFallbacks( pResData
);
1331 ByteString sGID
= pResData
->sGId
;
1334 sGID
= pResData
->sId
;
1336 sLID
= pResData
->sId
;
1340 ByteString sXQHText
;
1343 ByteString
sTimeStamp( Export::GetTimeStamp());
1346 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
1347 sCur
= aLanguages
[ n
];
1348 if ( !sCur
.EqualsIgnoreCaseAscii("x-comment") ){
1349 if ( pResData
->sText
[ sCur
].Len())
1350 sXText
= pResData
->sText
[ sCur
];
1352 sXText
= pResData
->sText
[ SOURCE_LANGUAGE
];
1353 /*if ( !sXText.Len())
1354 sXText = pResData->sText[ ByteString("en") ];
1356 sXText = pResData->sText[ ByteString("de") ];*/
1359 if ( pResData
->sHelpText
[ sCur
].Len())
1360 sXHText
= pResData
->sHelpText
[ sCur
];
1362 sXHText
= pResData
->sHelpText
[ SOURCE_LANGUAGE
];
1363 /*if ( !sXHText.Len())
1364 sXHText = pResData->sHelpText[ ByteString("en") ];
1366 sXHText = pResData->sHelpText[ ByteString("de") ];*/
1369 if ( pResData
->sQuickHelpText
[ sCur
].Len())
1370 sXQHText
= pResData
->sQuickHelpText
[ sCur
];
1372 sXQHText
= pResData
->sQuickHelpText
[ SOURCE_LANGUAGE
];
1373 /*if ( !sXQHText.Len())
1374 sXQHText = pResData->sQuickHelpText[ ByteString("en") ];
1375 if ( !sXQHText.Len())
1376 sXQHText = pResData->sQuickHelpText[ ByteString("de") ];*/
1379 if ( pResData
->sTitle
[ sCur
].Len())
1380 sXTitle
= pResData
->sTitle
[ sCur
];
1382 sXTitle
= pResData
->sTitle
[ SOURCE_LANGUAGE
];
1383 /*if ( !sXTitle.Len())
1384 sXTitle = pResData->sTitle[ ByteString("en") ];
1385 if ( !sXTitle.Len())
1386 sXTitle = pResData->sTitle[ ByteString("de") ];*/
1392 if ( !sXHText
.Len()) {
1393 /*if ( pResData->sHelpText[ ByteString("de") ].Len())
1394 sXHText = pResData->sHelpText[ ByteString("de") ];*/
1395 if ( pResData
->sHelpText
[ SOURCE_LANGUAGE
].Len())
1396 sXHText
= pResData
->sHelpText
[ SOURCE_LANGUAGE
];
1397 /*else if ( pResData->sHelpText[ ByteString("en") ].Len())
1398 sXHText = pResData->sHelpText[ ByteString("en") ];*/
1402 sXText
= pResData
->sText
[ sCur
];
1404 if ( bEnableExport
) {
1405 ByteString
sOutput( sProject
); sOutput
+= "\t";
1407 sOutput
+= sActFileName
;
1409 sOutput
+= pResData
->sResTyp
; sOutput
+= "\t";
1410 sOutput
+= sGID
; sOutput
+= "\t";
1411 sOutput
+= sLID
; sOutput
+= "\t";
1412 sOutput
+= pResData
->sHelpId
; sOutput
+= "\t";
1413 sOutput
+= pResData
->sPForm
; sOutput
+= "\t";
1414 sOutput
+= ByteString::CreateFromInt64( pResData
->nWidth
); sOutput
+= "\t";
1415 sOutput
+= sCur
; sOutput
+= "\t";
1418 sOutput
+= sXText
; sOutput
+= "\t";
1419 sOutput
+= sXHText
; sOutput
+= "\t";
1420 sOutput
+= sXQHText
; sOutput
+= "\t";
1421 sOutput
+= sXTitle
; sOutput
+= "\t";
1422 sOutput
+= sTimeStamp
;
1424 // if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1425 aOutput
.WriteLine( sOutput
);
1429 pResData
->sText
[ sCur
] = "";
1430 pResData
->sHelpText
[ sCur
] = "";
1431 pResData
->sQuickHelpText
[ sCur
]= "";
1432 pResData
->sTitle
[ sCur
] = "";
1436 FillInFallbacks( pResData
);
1437 if ( pResData
->pStringList
) {
1438 ByteString
sList( "stringlist" );
1439 WriteExportList( pResData
, pResData
->pStringList
, sList
, bCreateNew
);
1441 pResData
->pStringList
= 0;
1443 if ( pResData
->pFilterList
) {
1444 ByteString
sList( "filterlist" );
1445 WriteExportList( pResData
, pResData
->pFilterList
, sList
, bCreateNew
);
1447 pResData
->pFilterList
= 0;
1449 if ( pResData
->pItemList
) {
1450 ByteString
sList( "itemlist" );
1451 WriteExportList( pResData
, pResData
->pItemList
, sList
, bCreateNew
);
1453 pResData
->pItemList
= 0;
1455 if ( pResData
->pPairedList
) {
1456 ByteString
sList( "pairedlist" );
1457 WriteExportList( pResData
, pResData
->pPairedList
, sList
, bCreateNew
);
1459 pResData
->pItemList
= 0;
1461 if ( pResData
->pUIEntries
) {
1462 ByteString
sList( "uientries" );
1463 WriteExportList( pResData
, pResData
->pUIEntries
, sList
, bCreateNew
);
1465 pResData
->pUIEntries
= 0;
1469 ByteString
Export::GetPairedListID( const ByteString
& sText
){
1470 // < "STRING" ; IDENTIFIER ; > ;
1471 ByteString sIdent
= sText
.GetToken( 1, ';' );
1472 sIdent
.ToUpperAscii();
1473 while( sIdent
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
1474 sIdent
.EraseTrailingChars( ' ' );
1475 sIdent
.EraseLeadingChars( ' ' );
1478 ByteString
Export::GetPairedListString( const ByteString
& sText
){
1479 // < "STRING" ; IDENTIFIER ; > ;
1480 ByteString sString
= sText
.GetToken( 0, ';' );
1481 while( sString
.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND
) {};
1482 sString
.EraseTrailingChars( ' ' );
1483 ByteString s1
= sString
.Copy( sString
.Search( '\"' )+1 );
1484 sString
= s1
.Copy( 0 , s1
.SearchBackward( '\"' ) );
1485 sString
.EraseTrailingChars( ' ' );
1486 sString
.EraseLeadingChars( ' ' );
1489 ByteString
Export::StripList( const ByteString
& sText
){
1490 ByteString s1
= sText
.Copy( sText
.Search( '\"' ) + 1 );
1491 return s1
.Copy( 0 , s1
.SearchBackward( '\"' ) );
1494 /*****************************************************************************/
1495 BOOL
Export::WriteExportList( ResData
*pResData
, ExportList
*pExportList
,
1496 const ByteString
&rTyp
, BOOL bCreateNew
)
1497 /*****************************************************************************/
1499 ByteString sGID
= pResData
->sGId
;
1501 sGID
= pResData
->sId
;
1504 sGID
+= pResData
->sId
;
1505 sGID
.EraseTrailingChars( '.' );
1508 ByteString
sTimeStamp( Export::GetTimeStamp());
1510 for ( ULONG i
= 0; pExportList
!= NULL
&& i
< pExportList
->Count(); i
++ ) {
1511 ExportListEntry
*pEntry
= pExportList
->GetObject( i
);
1512 // mandatory for export: german and eng. and/or enus
1513 //ByteString a("Export::WriteExportList::pEntry");
1514 //Export::DumpMap( a, *pEntry );
1516 ByteString
sLID( ByteString::CreateFromInt64( i
+ 1 ));
1517 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
1518 sCur
= aLanguages
[ n
];
1520 //(*pEntry)[ ByteString("de") ].Len() &&
1521 (*pEntry
)[ SOURCE_LANGUAGE
].Len() )
1523 // (*pEntry)[ ByteString("en") ].Len()))
1525 if ( bEnableExport
)
1527 ByteString
sText((*pEntry
)[ SOURCE_LANGUAGE
] );
1529 // Strip PairList Line String
1530 if( rTyp
.EqualsIgnoreCaseAscii("pairedlist") ){
1531 sLID
= GetPairedListID( sText
);
1532 if ((*pEntry
)[ sCur
].Len())
1533 sText
= (*pEntry
)[ sCur
];
1534 sText
= GetPairedListString( sText
);
1537 //if ((*pEntry)[ sCur ].Len()){
1538 // if( sCur.EqualsIgnoreCaseAscii("de") ){
1539 // sText = StripList( (*pEntry)[ sCur ] );
1542 sText
= StripList( (*pEntry
)[ sCur
] );
1543 if( sText
== "\\\"" )
1548 ByteString
sOutput( sProject
); sOutput
+= "\t";
1550 sOutput
+= sActFileName
;
1552 sOutput
+= rTyp
; sOutput
+= "\t";
1553 sOutput
+= sGID
; sOutput
+= "\t";
1554 sOutput
+= sLID
; sOutput
+= "\t\t";
1555 sOutput
+= pResData
->sPForm
; sOutput
+= "\t0\t";
1556 sOutput
+= sCur
; sOutput
+= "\t";
1558 sOutput
+= sText
; sOutput
+= "\t\t\t\t";
1559 sOutput
+= sTimeStamp
;
1561 //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1562 aOutput
.WriteLine( sOutput
);
1576 /*****************************************************************************/
1577 ByteString
Export::FullId()
1578 /*****************************************************************************/
1582 sFull
= aResStack
.GetObject( 0 )->sId
;
1583 for ( USHORT i
= 1; i
< nLevel
- 1; i
++ ) {
1584 ByteString sToAdd
= aResStack
.GetObject( i
)->sId
;
1585 if ( sToAdd
.Len()) {
1591 if ( sFull
.Len() > 255 ) {
1592 ByteString
sError( "GroupId > 255 chars" );
1593 printf("GroupID = %s\n",sFull
.GetBuffer());
1594 yyerror( sError
.GetBufferAccess());
1595 sError
.ReleaseBufferAccess();
1601 /*****************************************************************************/
1602 void Export::InsertListEntry( const ByteString
&rText
, const ByteString
&rLine
)
1603 /*****************************************************************************/
1605 ResData
*pResData
= aResStack
.GetObject( nLevel
-1 );
1607 ExportList
*pList
= NULL
;
1608 if ( nList
== LIST_STRING
) {
1609 pList
= pResData
->pStringList
;
1611 pResData
->pStringList
= new ExportList();
1612 pList
= pResData
->pStringList
;
1616 else if ( nList
== LIST_FILTER
) {
1617 pList
= pResData
->pFilterList
;
1619 pResData
->pFilterList
= new ExportList();
1620 pList
= pResData
->pFilterList
;
1624 else if ( nList
== LIST_ITEM
) {
1625 pList
= pResData
->pItemList
;
1627 pResData
->pItemList
= new ExportList();
1628 pList
= pResData
->pItemList
;
1632 else if ( nList
== LIST_PAIRED
) {
1633 pList
= pResData
->pPairedList
;
1635 pResData
->pPairedList
= new ExportList();
1636 pList
= pResData
->pPairedList
;
1640 else if ( nList
== LIST_UIENTRIES
) {
1641 pList
= pResData
->pUIEntries
;
1643 pResData
->pUIEntries
= new ExportList();
1644 pList
= pResData
->pUIEntries
;
1651 if ( nListIndex
+ 1 > pList
->Count()) {
1652 ExportListEntry
*pNew
= new ExportListEntry();
1653 (*pNew
)[ LIST_REFID
] = ByteString::CreateFromInt32( REFID_NONE
);
1654 pList
->Insert( pNew
, LIST_APPEND
);
1656 ExportListEntry
*pCurEntry
= pList
->GetObject( nListIndex
);
1658 // For paired list use the line to set proper lid
1659 if( nList
== LIST_PAIRED
){
1660 (*pCurEntry
)[ nListLang
] = rLine
;
1662 (*pCurEntry
)[ nListLang
] = rText
;
1664 // Remember en-US fallback string, so each list has the same amount of elements
1665 //if ( nListLang.EqualsIgnoreCaseAscii("en-US") ) {
1666 if ( Export::isSourceLanguage( nListLang
) ) {
1667 if( nList
== LIST_PAIRED
){
1668 const ByteString
sPlist("pairedlist");
1669 ByteString sKey
= MergeDataFile::CreateKey( sPlist
, pResData
->sId
, GetPairedListID( rLine
) , sFilename
);
1670 pResData
->addFallbackData( sKey
, rText
);
1674 const ByteString
sPlist("list");
1675 ByteString
a( pResData
->sGId
);
1677 a
.Append( pResData
->sId
);
1678 sal_Int64 x
= nListIndex
+1;
1679 ByteString
b( ByteString::CreateFromInt64( x
) );
1680 ByteString sKey
= MergeDataFile::CreateKey( sPlist
, a
, b
, sFilename
);
1681 pResData
->addFallbackData( sKey
, rText
);
1686 //if ( nListLang.EqualsIgnoreCaseAscii("en-US") ) {
1687 if ( Export::isSourceLanguage( nListLang
) ) {
1688 if( nList
== LIST_PAIRED
){
1689 (*pCurEntry
)[ SOURCE_LANGUAGE
] = rLine
;
1692 (*pCurEntry
)[ SOURCE_LANGUAGE
] = rLine
;
1694 pList
->NewSourceLanguageListEntry();
1697 //printf("Export::InsertListEntry ResData.id = %s ResData.ListData = %s\n",pResData->sId.GetBuffer() ,(*pCurEntry)[ nListLang ].GetBuffer());
1701 /*****************************************************************************/
1702 void Export::CleanValue( ByteString
&rValue
)
1703 /*****************************************************************************/
1705 while ( rValue
.Len()) {
1706 if (( rValue
.GetChar( 0 ) == ' ' ) || ( rValue
.GetChar( 0 ) == '\t' ))
1707 rValue
= rValue
.Copy( 1 );
1712 if ( rValue
.Len()) {
1713 for ( USHORT i
= rValue
.Len() - 1; i
> 0; i
-- ) {
1714 if (( rValue
.GetChar( i
) == ' ' ) || ( rValue
.GetChar( i
) == '\t' ) ||
1715 ( rValue
.GetChar( i
) == '\n' ) || ( rValue
.GetChar( i
) == ';' ) ||
1716 ( rValue
.GetChar( i
) == '{' ) || ( rValue
.GetChar( i
) == '\\' ) ||
1717 ( rValue
.GetChar( i
) == '\r' ))
1726 /*****************************************************************************/
1727 ByteString
Export::GetText( const ByteString
&rSource
, int nToken
)
1728 /*****************************************************************************/
1729 #define TXT_STATE_NON 0x000
1730 #define TXT_STATE_TEXT 0x001
1731 #define TXT_STATE_MACRO 0x002
1736 case LONGTEXTLINE
: {
1737 ByteString
sTmp( rSource
.Copy( rSource
.Search( "=" )));
1739 sTmp
.EraseAllChars( '\n' );
1740 sTmp
.EraseAllChars( '\r' );
1742 while ( sTmp
.SearchAndReplace( "\\\\\"", "-=<[BSlashBSlashHKom]>=-\"" )
1743 != STRING_NOTFOUND
) {};
1744 while ( sTmp
.SearchAndReplace( "\\\"", "-=<[Hochkomma]>=-" )
1745 != STRING_NOTFOUND
) {};
1746 while ( sTmp
.SearchAndReplace( "\\\x7f", "-=<[0x7F]>=-" )
1747 != STRING_NOTFOUND
) {};
1748 while ( sTmp
.SearchAndReplace( "\\0x7F", "-=<[0x7F]>=-" )
1749 != STRING_NOTFOUND
) {};
1752 USHORT nState
= TXT_STATE_MACRO
;
1754 nState
= TXT_STATE_TEXT
;
1758 for ( USHORT i
= nStart
; i
< sTmp
.GetTokenCount( '\"' ); i
++ ) {
1759 ByteString sToken
= sTmp
.GetToken( i
, '\"' );
1760 if ( sToken
.Len()) {
1761 if ( nState
== TXT_STATE_TEXT
) {
1763 nState
= TXT_STATE_MACRO
;
1766 while( sToken
.SearchAndReplace( "\t", " " ) !=
1767 STRING_NOTFOUND
) {};
1768 while( sToken
.SearchAndReplace( " ", " " ) !=
1769 STRING_NOTFOUND
) {};
1770 sToken
.EraseLeadingChars( ' ' );
1771 sToken
.EraseTrailingChars( ' ' );
1772 if ( sToken
.Len()) {
1777 nState
= TXT_STATE_TEXT
;
1782 while ( sReturn
.SearchAndReplace( "-=<[0x7F]>=-", "\x7f" )
1783 != STRING_NOTFOUND
) {};
1784 while ( sReturn
.SearchAndReplace( "-=<[Hochkomma]>=-", "\"" )
1785 != STRING_NOTFOUND
) {};
1786 while ( sReturn
.SearchAndReplace( "-=<[BSlashBSlashHKom]>=-", "\\\\" )
1787 != STRING_NOTFOUND
) {};
1790 while ( sReturn
.SearchAndReplace( "\\\\", "-=<[BSlashBSlash]>=-" )
1791 != STRING_NOTFOUND
) {};
1792 while ( sReturn
.SearchAndReplace( "-=<[BSlashBSlash]>=-", "\\" )
1793 != STRING_NOTFOUND
) {};
1801 /*****************************************************************************/
1802 void Export::WriteToMerged( const ByteString
&rText
, bool bSDFContent
)
1803 /*****************************************************************************/
1805 static ByteString
SLASH ('\\');
1806 static ByteString
RETURN ('\n');
1807 //printf("%s\n",rText.GetBuffer() );
1810 // statement has no effect
1811 if( pParseQueue
->bMflag
&& !bSDFContent
) pParseQueue
->bMflag
;
1814 if ( !bDontWriteOutput
|| !bUnmerge
) {
1815 ByteString
sText( rText
);
1816 while ( sText
.SearchAndReplace( " \n", "\n" ) != STRING_NOTFOUND
) {};
1817 if( pParseQueue
->bNextIsM
&& bSDFContent
&& sText
.Len() > 2 ){
1818 for( USHORT n
= 0 ; n
< sText
.Len() ; n
++ ){
1819 if( sText
.GetChar( n
) == '\n' && sText
.GetChar( n
-1 ) != '\\'){
1820 sText
.Insert('\\' , n
++ );
1825 else if( pParseQueue
->bLastWasM
&& sText
.Len() > 2 ){
1826 for( USHORT n
= 0 ; n
< sText
.Len() ; n
++ ){
1827 if( sText
.GetChar( n
) == '\n' && sText
.GetChar( n
-1 ) != '\\'){
1828 sText
.Insert('\\' , n
++ );
1830 if( sText
.GetChar( n
) == '\n' )pParseQueue
->bMflag
=true;
1833 else if( pParseQueue
->bCurrentIsM
&& bSDFContent
&& sText
.Len() > 2 ){
1834 for( USHORT n
= 0 ; n
< sText
.Len() ; n
++ ){
1835 if( sText
.GetChar( n
) == '\n' && sText
.GetChar( n
-1 ) != '\\'){
1836 sText
.Insert('\\' , n
++ );
1837 pParseQueue
->bMflag
=true;
1841 else if( pParseQueue
->bMflag
){
1842 for( USHORT n
= 1 ; n
< sText
.Len() ; n
++ ){
1843 if( sText
.GetChar( n
) == '\n' && sText
.GetChar( n
-1 ) != '\\'){
1844 sText
.Insert('\\' , n
++ );
1848 for ( USHORT i
= 0; i
< sText
.Len(); i
++ ) {
1849 if ( sText
.GetChar( i
) != '\n' ){
1850 aOutput
.Write( ByteString( sText
.GetChar( i
)).GetBuffer(), 1 );
1854 aOutput
.WriteLine( ByteString());
1861 /*****************************************************************************/
1862 void Export::ConvertMergeContent( ByteString
&rText
)
1863 /*****************************************************************************/
1865 BOOL bNoOpen
= ( rText
.Search( "\\\"" ) != 0 );
1866 ByteString
sClose( rText
.Copy( rText
.Len() - 2 ));
1867 BOOL bNoClose
= ( sClose
!= "\\\"" );
1869 for ( USHORT i
= 0; i
< rText
.Len(); i
++ ) {
1870 ByteString
sChar( rText
.GetChar( i
));
1871 if ( sChar
== "\\" ) {
1872 if (( i
+ 1 ) < rText
.Len()) {
1873 ByteString
sNext( rText
.GetChar( i
+ 1 ));
1874 if ( sNext
== "\"" ) {
1878 else if ( sNext
== "n" ) {
1882 else if ( sNext
== "t" ) {
1886 else if ( sNext
== "\'" ) {
1897 else if ( sChar
== "\"" ) {
1900 else if ( sChar
== "\x7f" ) {
1909 ByteString
sTmp( rText
);
1917 /*****************************************************************************/
1918 BOOL
Export::PrepareTextToMerge( ByteString
&rText
, USHORT nTyp
,
1919 ByteString
&nLangIndex
, ResData
*pResData
)
1920 /*****************************************************************************/
1922 // position to merge in:
1925 ByteString sOldId
= pResData
->sId
;
1926 ByteString sOldGId
= pResData
->sGId
;
1927 ByteString sOldTyp
= pResData
->sResTyp
;
1929 ByteString
sOrigText( rText
);
1933 case LIST_UIENTRIES
:
1941 ExportList
*pList
= NULL
;
1943 case LIST_STRING
: {
1944 pResData
->sResTyp
= "stringlist";
1945 pList
= pResData
->pStringList
;
1948 case LIST_UIENTRIES
: {
1949 pResData
->sResTyp
= "uientries";
1950 pList
= pResData
->pUIEntries
;
1953 case LIST_FILTER
: {
1954 pResData
->sResTyp
= "filterlist";
1955 pList
= pResData
->pFilterList
;
1959 pResData
->sResTyp
= "itemlist";
1960 pList
= pResData
->pItemList
;
1963 case LIST_PAIRED
: {
1964 pResData
->sResTyp
= "pairedlist";
1965 pList
= pResData
->pPairedList
;
1971 ExportListEntry
*pCurEntry
= pList
->GetObject( nListIndex
- 1 );
1973 //printf("%s\n",Export::DumpMap( "pCurEntry", *pCurEntry ).GetBuffer() );
1974 //ByteString a("pCurEntry");
1975 //Export::DumpMap( a , *pCurEntry );
1976 rText
= (*pCurEntry
)[ SOURCE_LANGUAGE
];
1977 if( nTyp
== LIST_PAIRED
){
1978 pResData
->addMergedLanguage( nLangIndex
);
1983 nStart
= rText
.Search( "\"" );
1984 if ( nStart
== STRING_NOTFOUND
) {
1989 BOOL bFound
= FALSE
;
1990 for ( nEnd
= nStart
+ 1; nEnd
< rText
.Len() && !bFound
; nEnd
++ ) {
1991 if ( rText
.GetChar( nEnd
) == '\"' )
2000 sLastListLine
= rText
;
2001 if (( sLastListLine
.Search( ">" ) != STRING_NOTFOUND
) &&
2002 ( sLastListLine
.Search( "<" ) == STRING_NOTFOUND
))
2004 ByteString sTmp
= sLastListLine
;
2005 sLastListLine
= "<";
2006 sLastListLine
+= sTmp
;
2008 if ( pResData
->sResTyp
.EqualsIgnoreCaseAscii( "pairedlist" ) ){
2009 pResData
->sId
= GetPairedListID( sLastListLine
);
2011 else pResData
->sId
= ByteString::CreateFromInt32( nListIndex
);
2013 if ( pResData
->sGId
.Len())
2014 pResData
->sGId
+= ".";
2015 pResData
->sGId
+= sOldId
;
2016 nTyp
= STRING_TYP_TEXT
;
2019 case STRING_TYP_TEXT
:
2020 case STRING_TYP_HELPTEXT
:
2021 case STRING_TYP_QUICKHELPTEXT
:
2022 case STRING_TYP_TITLE
:
2025 if (( nLangIndex != ByteString("de") ) &&
2026 ( nLangIndex != ByteString("en-US") ))
2028 bDontWriteOutput = TRUE;
2033 nStart
= rText
.Search( "=" );
2034 if ( nStart
== STRING_NOTFOUND
) {
2040 BOOL bFound
= FALSE
;
2041 while(( nStart
< rText
.Len()) && !bFound
) {
2042 if (( rText
.GetChar( nStart
) != ' ' ) && ( rText
.GetChar( nStart
) != '\t' ))
2048 // no start position found
2054 // position to end mergeing in
2055 nEnd
= rText
.Len() - 1;
2058 while (( nEnd
> nStart
) && !bFound
) {
2059 if (( rText
.GetChar( nEnd
) != ' ' ) && ( rText
.GetChar( nEnd
) != '\t' ) &&
2060 ( rText
.GetChar( nEnd
) != '\n' ) && ( rText
.GetChar( nEnd
) != ';' ) &&
2061 ( rText
.GetChar( nEnd
) != '{' ) && ( rText
.GetChar( nEnd
) != '\\' ))
2072 // search for merge data
2073 if ( !pMergeDataFile
){
2074 pMergeDataFile
= new MergeDataFile( sMergeSrc
, sFile
, bErrorLog
, aCharSet
);//, bUTF8 );
2077 ByteString sTmp
= Export::sLanguages
;
2078 if( sTmp
.ToUpperAscii().Equals("ALL") )
2079 SetLanguages( pMergeDataFile
->GetLanguages() );
2080 else if( !isInitialized
)InitLanguages();
2083 // printf("*************DUMPING****************\n");
2084 // printf("%s\n",pMergeDataFile->Dump().GetBuffer());
2085 // printf("*************DUMPING****************\n");
2087 // printf("Dumping ResData\n");
2088 // pResData->Dump();
2089 PFormEntrys
*pEntrys
= pMergeDataFile
->GetPFormEntrys( pResData
);
2090 //printf("Dumping pEntrys\n");
2091 //if( pEntrys ) pEntrys->Dump();
2092 pResData
->sId
= sOldId
;
2093 pResData
->sGId
= sOldGId
;
2094 pResData
->sResTyp
= sOldTyp
;
2098 return FALSE
; // no data found
2101 ByteString sContent
;
2102 pEntrys
->GetText( sContent
, nTyp
, nLangIndex
);
2103 //if ( !sContent.Len() && ( ! nLangIndex.EqualsIgnoreCaseAscii("en-US") )) {
2104 if ( !sContent
.Len() && ( ! Export::isSourceLanguage( nLangIndex
) )) {
2106 return FALSE
; // no data found
2109 //if ( nLangIndex.EqualsIgnoreCaseAscii("en-US") ) {
2110 if ( Export::isSourceLanguage( nLangIndex
) ) {
2114 ByteString
sPostFix( rText
.Copy( ++nEnd
));
2115 rText
.Erase( nStart
);
2117 //ConvertMergeContent( sContent, nTyp );
2118 ConvertMergeContent( sContent
);
2122 //printf("Merged %s\n",nLangIndex.GetBuffer());
2123 // merge new res. in text line
2130 /*****************************************************************************/
2131 void Export::MergeRest( ResData
*pResData
, USHORT nMode
)
2132 /*****************************************************************************/
2134 //if ( bUnmerge ) { return;}
2138 if ( !pMergeDataFile
){
2139 pMergeDataFile
= new MergeDataFile( sMergeSrc
, sFile
,bErrorLog
, aCharSet
);//, bUTF8 );
2142 ByteString sTmp
= Export::sLanguages
;
2143 if( sTmp
.ToUpperAscii().Equals("ALL") )
2144 SetLanguages( pMergeDataFile
->GetLanguages() );
2145 else if( !isInitialized
)InitLanguages();
2149 case MERGE_MODE_NORMAL
: {
2150 PFormEntrys
*pEntry
= pMergeDataFile
->GetPFormEntrys( pResData
);
2152 bool bWriteNoSlash
= false;
2153 if ( pEntry
&& pResData
->bText
) {
2155 BOOL bAddSemikolon
= FALSE
;
2158 ByteString sTmp
= Export::sLanguages
;
2160 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
2161 sCur
= aLanguages
[ n
];
2164 BOOL bText
= pEntry
->GetText( sText
, STRING_TYP_TEXT
, sCur
, TRUE
);
2165 if ( bText
&& sText
.Len() && sText
!= "-" ) {
2167 if ( bNextMustBeDefineEOL
) {
2169 sOutput
+= "\t\\\n";
2171 sOutput
+= ";\t\\\n";
2175 sOutput
+= pResData
->sTextTyp
;
2176 //if ( !sCur.EqualsIgnoreCaseAscii("en-US")) {
2177 if ( ! Export::isSourceLanguage( sCur
) ) {
2183 ConvertMergeContent( sText
);
2186 if ( bDefine
&& bWriteNoSlash
)
2191 else if ( !bNextMustBeDefineEOL
)
2194 bAddSemikolon
= TRUE
;
2195 for ( USHORT j
= 1; j
< nLevel
; j
++ )
2197 WriteToMerged( sOutput
, true );
2202 if ( bAddSemikolon
) {
2203 ByteString
sOutput( ";" );
2204 WriteToMerged( sOutput
, false );
2208 if ( pEntry
&& pResData
->bQuickHelpText
) {
2209 BOOL bAddSemikolon
= FALSE
;
2213 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
2214 sCur
= aLanguages
[ n
];
2217 BOOL bText
= pEntry
->GetText( sText
, STRING_TYP_QUICKHELPTEXT
, sCur
, TRUE
);
2218 if ( bText
&& sText
.Len() && sText
!= "-" ) {
2220 if ( bNextMustBeDefineEOL
) {
2222 sOutput
+= "\t\\\n";
2224 sOutput
+= ";\t\\\n";
2228 sOutput
+= "QuickHelpText";
2229 //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2230 if ( ! Export::isSourceLanguage( sCur
) ) {
2236 ConvertMergeContent( sText
);
2240 else if ( !bNextMustBeDefineEOL
)
2243 bAddSemikolon
= TRUE
;
2244 for ( USHORT j
= 1; j
< nLevel
; j
++ )
2246 WriteToMerged( sOutput
,true );
2249 if ( bAddSemikolon
) {
2250 ByteString
sOutput( ";" );
2251 WriteToMerged( sOutput
, false );
2255 if ( pEntry
&& pResData
->bTitle
) {
2256 BOOL bAddSemikolon
= FALSE
;
2260 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
2261 sCur
= aLanguages
[ n
];
2264 BOOL bText
= pEntry
->GetText( sText
, STRING_TYP_TITLE
, sCur
, TRUE
);
2265 if ( bText
&& sText
.Len() && sText
!= "-" ) {
2267 if ( bNextMustBeDefineEOL
) {
2269 sOutput
+= "\t\\\n";
2271 sOutput
+= ";\t\\\n";
2276 //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2277 if ( ! Export::isSourceLanguage( sCur
) ) {
2283 ConvertMergeContent( sText
);
2287 else if ( !bNextMustBeDefineEOL
)
2290 bAddSemikolon
= TRUE
;
2291 for ( USHORT j
= 1; j
< nLevel
; j
++ )
2293 WriteToMerged( sOutput
,true );
2296 if ( bAddSemikolon
) {
2297 ByteString
sOutput( ";" );
2298 WriteToMerged( sOutput
,false);
2303 if ( pResData
->bList
) {
2304 //printf("Dumping ResData\n");
2307 bool bPairedList
= false;
2308 ByteString sOldId
= pResData
->sId
;
2309 ByteString sOldGId
= pResData
->sGId
;
2310 ByteString sOldTyp
= pResData
->sResTyp
;
2311 if ( pResData
->sGId
.Len())
2312 pResData
->sGId
+= ".";
2313 pResData
->sGId
+= sOldId
;
2315 for ( USHORT i
= 1; i
< nLevel
-1; i
++ )
2317 for ( USHORT nT
= LIST_STRING
; nT
<= LIST_UIENTRIES
; nT
++ ) {
2318 ExportList
*pList
= NULL
;
2320 case LIST_STRING
: pResData
->sResTyp
= "stringlist"; pList
= pResData
->pStringList
; bPairedList
= false; break;
2321 case LIST_FILTER
: pResData
->sResTyp
= "filterlist"; pList
= pResData
->pFilterList
; bPairedList
= false; break;
2322 case LIST_UIENTRIES
: pResData
->sResTyp
= "uientries"; pList
= pResData
->pUIEntries
;bPairedList
= false; break;
2323 case LIST_ITEM
: pResData
->sResTyp
= "itemlist"; pList
= pResData
->pItemList
; bPairedList
= false; break;
2324 case LIST_PAIRED
: pResData
->sResTyp
= "pairedlist"; pList
= pResData
->pPairedList
; bPairedList
= true; break;
2327 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
2328 sCur
= aLanguages
[ n
];
2331 // Set matching pairedlist identifier
2332 if( bPairedList
&& pResData
->pPairedList
&& ( nIdx
== 1 ) ){
2333 ExportListEntry
* pListE
= ( ExportListEntry
* ) pResData
->pPairedList
->GetObject( nIdx
-1 );
2334 pResData
->sId
= GetPairedListID ( (*pListE
)[ SOURCE_LANGUAGE
] );
2337 pResData
->sId
= ByteString("1");
2339 PFormEntrys
*pEntrys
;
2341 ULONG nMaxIndex
= 0;
2343 nMaxIndex
= pList
->GetSourceLanguageListEntryCount();
2344 pEntrys
= pMergeDataFile
->GetPFormEntrys( pResData
);
2345 while( pEntrys
&& ( nLIndex
< nMaxIndex
)) {
2346 //printf("Lang %s, List Index %d\n",sCur.GetBuffer(),(int)nLIndex);
2349 bText
= pEntrys
->GetText( sText
, STRING_TYP_TEXT
, sCur
, TRUE
);
2351 bText
= pEntrys
->GetText( sText
, STRING_TYP_TEXT
, SOURCE_LANGUAGE
, FALSE
);
2353 // Use fallback, if data is missing in sdf file
2354 //if( !bText && pResData->sResTyp.Equals( "pairedlist" ) ){
2355 if( !bText
&& bPairedList
){
2356 if( pResData
->isMerged( sCur
) ) break;
2357 const ByteString
sPlist("pairedlist");
2358 ByteString sKey
= MergeDataFile::CreateKey( sPlist
, pResData
->sGId
, pResData
->sId
, sFilename
);
2359 bText
= pResData
->getFallbackData( sKey
, sText
);
2360 }else if ( !bText
){// new fallback
2361 if( pResData
->isMerged( sCur
) ) break;
2362 const ByteString
sPlist("list");
2363 ByteString sKey
= MergeDataFile::CreateKey( sPlist
, pResData
->sGId
, pResData
->sId
, sFilename
);
2364 bText
= pResData
->getFallbackData( sKey
, sText
);
2367 if ( bText
&& sText
.Len()) {
2368 //if( pEntrys ) pEntrys->Dump();
2371 if ( bNextMustBeDefineEOL
)
2375 case LIST_STRING
: sHead
+= "StringList "; break;
2376 case LIST_FILTER
: sHead
+= "FilterList "; break;
2377 case LIST_ITEM
: sHead
+= "ItemList "; break;
2378 case LIST_PAIRED
: sHead
+= "PairedList "; break;
2379 case LIST_UIENTRIES
: sHead
+= "UIEntries "; break;
2385 if ( bDefine
|| bNextMustBeDefineEOL
) {
2388 sHead
+= "\t{\\\n\t";
2395 WriteToMerged( sHead
, true);
2398 if ( pList
&& pList
->GetObject( nLIndex
))
2399 sLine
= ( *pList
->GetObject( nLIndex
))[ SOURCE_LANGUAGE
];
2401 sLine
= sLastListLine
;
2403 if ( sLastListLine
.Search( "<" ) != STRING_NOTFOUND
) {
2404 if (( nT
!= LIST_UIENTRIES
) &&
2405 (( sLine
.Search( "{" ) == STRING_NOTFOUND
) ||
2406 ( sLine
.Search( "{" ) >= sLine
.Search( "\"" ))) &&
2407 (( sLine
.Search( "<" ) == STRING_NOTFOUND
) ||
2408 ( sLine
.Search( "<" ) >= sLine
.Search( "\"" ))))
2410 sLine
.SearchAndReplace( "\"", "< \"" );
2414 USHORT nStart
, nEnd
;
2415 nStart
= sLine
.Search( "\"" );
2417 ByteString sPostFix
;
2419 nEnd
= sLine
.SearchBackward( '\"' );
2420 sPostFix
= ByteString( sLine
.Copy( ++nEnd
));
2421 sLine
.Erase( nStart
);
2425 ConvertMergeContent( sText
);
2427 // merge new res. in text line
2429 sLine
= MergePairedList( sLine
, sText
);
2436 ByteString
sText1( "\t" );
2438 if ( bDefine
|| bNextMustBeDefineEOL
)
2444 //printf("Writing '%s'\n",sText1.GetBuffer());
2445 WriteToMerged( sText1
,true );
2447 // Set matching pairedlist identifier
2450 ExportListEntry
* pListE
= ( ExportListEntry
* ) pResData
->pPairedList
->GetObject( ( nIdx
) -1 );
2452 pResData
->sId
= GetPairedListID ( (*pListE
)[ SOURCE_LANGUAGE
] );
2456 pResData
->sId
= ByteString::CreateFromInt32( ++nIdx
);
2461 PFormEntrys
*oldEntry
= pEntrys
;
2462 pEntrys
= pMergeDataFile
->GetPFormEntrys( pResData
); // <--- game over
2467 ByteString
sFooter( sSpace
.Copy( 1 ));
2468 if ( bNextMustBeDefineEOL
)
2470 else if ( !bDefine
)
2471 sFooter
+= "};\n\t";
2474 WriteToMerged( sFooter
,true );
2479 pResData
->sId
= sOldId
;
2480 pResData
->sGId
= sOldGId
;
2481 pResData
->sResTyp
= sOldTyp
;
2485 case MERGE_MODE_LIST
: {
2486 ExportList
*pList
= NULL
;
2489 case LIST_STRING
: pList
= pResData
->pStringList
; break;
2490 case LIST_FILTER
: pList
= pResData
->pFilterList
; break;
2491 case LIST_UIENTRIES
: pList
= pResData
->pUIEntries
; break;
2492 case LIST_ITEM
: pList
= pResData
->pItemList
; break;
2493 case LIST_PAIRED
: pList
= pResData
->pPairedList
; break;
2498 ULONG nMaxIndex
= 0;
2500 nMaxIndex
= pList
->GetSourceLanguageListEntryCount();
2502 if ( pList
&& pList
->GetObject( nListIndex
))
2503 sLine
= ( *pList
->GetObject( nListIndex
))[ SOURCE_LANGUAGE
];
2505 sLine
= sLastListLine
;
2507 if ( sLastListLine
.Search( "<" ) != STRING_NOTFOUND
) {
2508 if (( nList
!= LIST_UIENTRIES
) &&
2509 (( sLine
.Search( "{" ) == STRING_NOTFOUND
) ||
2510 ( sLine
.Search( "{" ) >= sLine
.Search( "\"" ))) &&
2511 (( sLine
.Search( "<" ) == STRING_NOTFOUND
) ||
2512 ( sLine
.Search( "<" ) >= sLine
.Search( "\"" ))))
2514 sLine
.SearchAndReplace( "\"", "< \"" );
2518 while( PrepareTextToMerge( sLine
, nList
, nListLang
, pResData
) && ( nListIndex
<= nMaxIndex
)) {
2519 ByteString
sText( "\t" );
2523 for ( USHORT i
= 0; i
< nLevel
; i
++ )
2525 WriteToMerged( sText
,false );
2527 if ( pList
&& pList
->GetObject( nListIndex
))
2528 sLine
= ( *pList
->GetObject( nListIndex
))[ SOURCE_LANGUAGE
];
2530 sLine
= sLastListLine
;
2536 pParseQueue
->bMflag
= false;
2539 ByteString
Export::MergePairedList( ByteString
& sLine
, ByteString
& sText
){
2540 // < "xy" ; IDENTIFIER ; >
2541 ByteString sPre
= sLine
.Copy( 0 , sLine
.Search('\"') );
2542 ByteString sPost
= sLine
.Copy( sLine
.SearchBackward('\"') + 1 , sLine
.Len() );
2543 sPre
.Append( sText
);
2544 sPre
.Append( sPost
);
2548 /*****************************************************************************/
2549 void Export::SetChildWithText()
2550 /*****************************************************************************/
2552 if ( aResStack
.Count() > 1 ) {
2553 for ( ULONG i
= 0; i
< aResStack
.Count() - 1; i
++ ) {
2554 aResStack
.GetObject( i
)->bChildWithText
= TRUE
;
2559 void ParserQueue::Push( const QueueEntry
& aEntry
){
2560 // printf("nTyp = %d ",aEntry.nTyp);
2561 USHORT nLen
= aEntry
.sLine
.Len();
2564 aQueueCur
->push( aEntry
);
2565 if( nLen
> 1 && aEntry
.sLine
.GetChar( nLen
-1 ) == '\n' )
2567 else if ( aEntry
.nTyp
!= IGNOREDTOKENS
){
2568 if( nLen
> 1 && ( aEntry
.sLine
.GetChar( nLen
-1 ) == '\\') ){
2573 bCurrentIsM
= false;
2578 aQueueNext
->push( aEntry
);
2579 if( nLen
> 1 && aEntry
.sLine
.GetChar( nLen
-1 ) != '\n' ){
2580 if( nLen
> 1 && ( aEntry
.sLine
.GetChar( nLen
-1 ) == '\\') ){
2588 }else if( nLen
> 2 && aEntry
.sLine
.GetChar( nLen
-1 ) == '\n' ){
2589 if( aEntry
.nTyp
!= IGNOREDTOKENS
){
2590 if( nLen
> 2 && ( aEntry
.sLine
.GetChar( nLen
-2 ) == '\\') ){
2601 bLastWasM
= bCurrentIsM
;
2603 bCurrentIsM
= bNextIsM
;
2605 aQueueCur
= aQueueNext
;
2613 bLastWasM
= bCurrentIsM
;
2615 bCurrentIsM
= bNextIsM
;
2617 aQueueCur
= aQueueNext
;
2623 void ParserQueue::Close(){
2627 bLastWasM
= bCurrentIsM
;
2628 bCurrentIsM
= bNextIsM
;
2630 aQueueCur
= aQueueNext
;
2635 void ParserQueue::Pop( std::queue
<QueueEntry
>& aQueue
){
2636 while( !aQueue
.empty() ){
2637 QueueEntry aEntry
= aQueue
.front();
2639 aExport
.Execute( aEntry
.nTyp
, (char*) aEntry
.sLine
.GetBuffer() );
2642 ParserQueue::ParserQueue( Export
& aExportObj
)
2644 bCurrentIsM( false ),
2648 aExport( aExportObj
) ,
2652 aQueueNext
= new std::queue
<QueueEntry
>;
2653 aQueueCur
= new std::queue
<QueueEntry
>;
2657 ParserQueue::~ParserQueue(){
2658 if( aQueueNext
) delete aQueueNext
;
2659 if( aQueueCur
) delete aQueueCur
;