xref: /aoo4110/main/l10ntools/source/export.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_l10ntools.hxx"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <tools/fsys.hxx>
29 #include "export.hxx"
30 #include "tokens.h"
31 #include "utf8conv.hxx"
32 #include <iostream>
33 
34 extern "C" { int yyerror( char * ); }
35 extern "C" { int YYWarning( char * ); }
36 
37 Export *pExport = 0L;
38 
39 // defines to parse command line
40 #define STATE_NON  		0x0001
41 #define STATE_INPUT		0x0002
42 #define STATE_OUTPUT	0x0003
43 #define STATE_PRJ		0x0004
44 #define STATE_ROOT		0x0005
45 #define STATE_MERGESRC	0x0006
46 #define STATE_ERRORLOG	0x0007
47 #define STATE_BREAKHELP	0x0008
48 #define STATE_UNMERGE	0x0009
49 #define STATE_UTF8		0x000A
50 #define STATE_LANGUAGES	0X000B
51 
52 // set of global variables
53 DECLARE_LIST( FileList, ByteString * )
54 FileList aInputFileList;
55 sal_Bool bEnableExport;
56 sal_Bool bMergeMode;
57 sal_Bool bErrorLog;
58 sal_Bool bBreakWhenHelpText;
59 sal_Bool bUnmerge;
60 sal_Bool bUTF8;
61 ByteString sPrj;
62 ByteString sPrjRoot;
63 ByteString sActFileName;
64 ByteString sOutputFile;
65 ByteString sMergeSrc;
66 ByteString sTempFile;
67 ByteString sFile;
68 MergeDataFile *pMergeDataFile;
69 FILE *pTempFile;
70 
71 
72 ByteString sStrBuffer;
73 bool bMarcro = false;
74 
75 extern "C" {
76 // the whole interface to lexer is in this extern "C" section
77 
78 
79 /*****************************************************************************/
GetOutputFile(int argc,char * argv[])80 extern char *GetOutputFile( int argc, char* argv[])
81 /*****************************************************************************/
82 {
83 	bEnableExport = sal_False;
84 	bMergeMode = sal_False;
85 	bErrorLog = sal_True;
86 	bBreakWhenHelpText = sal_False;
87 	bUnmerge = sal_False;
88 	bUTF8 = sal_True;
89 	sPrj = "";
90 	sPrjRoot = "";
91 	sActFileName = "";
92 	Export::sLanguages = "";
93     Export::sForcedLanguages = "";
94 	sTempFile = "";
95 	pTempFile = NULL;
96 	sal_uInt16 nState = STATE_NON;
97 	sal_Bool bInput = sal_False;
98 
99 	// parse command line
100 	for( int i = 1; i < argc; i++ ) {
101 		ByteString sSwitch( argv[ i ] );
102 
103         if (sSwitch == "-i"  || sSwitch == "-I" ) {
104 			nState = STATE_INPUT; // next tokens specifies source files
105 		}
106 		else if (sSwitch == "-o"  || sSwitch == "-O" ) {
107 			nState = STATE_OUTPUT; // next token specifies the dest file
108 		}
109 		else if (sSwitch == "-p"  || sSwitch == "-P" ) {
110 			nState = STATE_PRJ; // next token specifies the cur. project
111 		}
112 
113 		else if (sSwitch == "-r"  || sSwitch == "-R" ) {
114 			nState = STATE_ROOT; // next token specifies path to project root
115 		}
116 		else if (sSwitch == "-m"  || sSwitch == "-M" ) {
117 			nState = STATE_MERGESRC; // next token specifies the merge database
118 		}
119 		else if (sSwitch == "-e"  || sSwitch == "-E" ) {
120 			nState = STATE_ERRORLOG;
121 			bErrorLog = sal_False;
122 		}
123 		else if (sSwitch == "-b"  || sSwitch == "-B" ) {
124 			nState = STATE_BREAKHELP;
125 			bBreakWhenHelpText = sal_True;
126 		}
127 		else if (sSwitch == "-u"  || sSwitch == "-U" ) {
128 			nState = STATE_UNMERGE;
129 			bUnmerge = sal_True;
130 			bMergeMode = sal_True;
131 		}
132 		else if ( sSwitch.ToUpperAscii() == "-UTF8" ) {
133 			nState = STATE_UTF8;
134 			bUTF8 = sal_True;
135 		}
136 		else if ( sSwitch.ToUpperAscii() == "-NOUTF8" ) {
137 			nState = STATE_UTF8;
138 			bUTF8 = sal_False;
139 		}
140 		else if ( sSwitch == "-l"  || sSwitch == "-L" ) {
141 			nState = STATE_LANGUAGES;
142 		}
143 		else {
144 			switch ( nState ) {
145 				case STATE_NON: {
146 					return NULL;	// no valid command line
147 				}
148 				case STATE_INPUT: {
149 					aInputFileList.Insert( new ByteString( argv[ i ]), LIST_APPEND );
150 					bInput = sal_True; // min. one source file found
151 				}
152 				break;
153 				case STATE_OUTPUT: {
154 					sOutputFile = ByteString( argv[ i ]); // the dest. file
155 				}
156 				break;
157 				case STATE_PRJ: {
158 					sPrj = ByteString( argv[ i ]);
159 				}
160 				break;
161 				case STATE_ROOT: {
162 					sPrjRoot = ByteString( argv[ i ]); // path to project root
163 				}
164 				break;
165 				case STATE_MERGESRC: {
166 					sMergeSrc = ByteString( argv[ i ]);
167 					bMergeMode = sal_True; // activate merge mode, cause merge database found
168 				}
169 				break;
170 				case STATE_LANGUAGES: {
171 					Export::sLanguages = ByteString( argv[ i ]);
172 				}
173 				break;
174 			}
175 		}
176 	}
177     if( bUnmerge ) sMergeSrc = ByteString();
178 	if ( bInput ) {
179 		// command line is valid
180 		bEnableExport = sal_True;
181 		char *pReturn = new char[ sOutputFile.Len() + 1 ];
182 		strcpy( pReturn, sOutputFile.GetBuffer());  // #100211# - checked
183 		return pReturn;
184 	}
185 
186 	// command line is not valid
187 	return NULL;
188 }
189 /*****************************************************************************/
InitExport(char * pOutput,char * pFilename)190 int InitExport( char *pOutput , char* pFilename )
191 /*****************************************************************************/
192 {
193 	// instanciate Export
194 	ByteString sOutput( pOutput );
195     ByteString sFilename( pFilename );
196 
197 	if ( bMergeMode && !bUnmerge ) {
198 		// merge mode enabled, so read database
199 		pExport = new Export(sOutput, bEnableExport, sPrj, sPrjRoot, sMergeSrc , sFilename );
200 	}
201 	else
202 		// no merge mode, only export
203 		pExport = new Export( sOutput, bEnableExport, sPrj, sPrjRoot , sFilename );
204 	return 1;
205 }
206 
207 /*****************************************************************************/
EndExport()208 int EndExport()
209 /*****************************************************************************/
210 {
211 	delete pExport;
212 	return 1;
213 }
214 
getFilename()215 extern const char* getFilename()
216 {
217 	return (*(aInputFileList.GetObject( 0 ))).GetBuffer();
218 }
219 /*****************************************************************************/
GetNextFile()220 extern FILE *GetNextFile()
221 /*****************************************************************************/
222 {
223 	// look for next valid filename in input file list
224 	if ( sTempFile.Len()) {
225 		fclose( pTempFile );
226 		String sTemp( sTempFile, RTL_TEXTENCODING_ASCII_US );
227 		DirEntry aTemp( sTemp );
228 		aTemp.Kill();
229 	}
230 
231 	while ( aInputFileList.Count()) {
232 		ByteString sFileName( *(aInputFileList.GetObject( 0 )));
233 
234 		ByteString sOrigFile( sFileName );
235 
236 		sFileName = Export::GetNativeFile( sFileName );
237 		delete aInputFileList.GetObject(( sal_uLong ) 0 );
238 		aInputFileList.Remove(( sal_uLong ) 0 );
239 
240 		if ( sFileName == "" ) {
241 			fprintf( stderr, "ERROR: Could not precompile File %s\n",
242 				sOrigFile.GetBuffer());
243 			return GetNextFile();
244 		}
245 
246 		sTempFile = sFileName;
247         Export::RemoveUTF8ByteOrderMarkerFromFile( sFileName );
248 
249 		// able to open file?
250 		FILE *pFile = fopen( sFileName.GetBuffer(), "r" );
251 		if ( !pFile )
252 			fprintf( stderr, "Error: Could not open File %s\n",
253 				sFileName.GetBuffer());
254 		else {
255 			pTempFile = pFile;
256 
257 			// this is a valid file which can be opened, so
258 			// create path to project root
259 			DirEntry aEntry( String( sOrigFile, RTL_TEXTENCODING_ASCII_US ));
260 			aEntry.ToAbs();
261 			ByteString sFullEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
262 			aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
263 			aEntry += DirEntry( sPrjRoot );
264 			ByteString sPrjEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
265 
266 			// create file name, beginnig with project root
267 			// (e.g.: source\ui\src\menue.src)
268 			sActFileName = sFullEntry.Copy( sPrjEntry.Len() + 1 );
269 
270 
271 			sActFileName.SearchAndReplaceAll( "/", "\\" );
272             sFile = sActFileName;
273 
274 			if ( pExport ) {
275 				// create instance of class export
276 				pExport->Init();
277 			}
278 			// return the valid file handle
279             return pFile;
280 		}
281 	}
282 	// this means the file could not be opened
283 	return NULL;
284 }
285 
Parse(int nTyp,const char * pTokenText)286 int Parse( int nTyp, const char *pTokenText ){
287     pExport->Execute( nTyp , pTokenText );
288     return 1;
289 }
Close()290 void Close(){
291     pExport->pParseQueue->Close();
292 }
293 /*****************************************************************************/
WorkOnTokenSet(int nTyp,char * pTokenText)294 int WorkOnTokenSet( int nTyp, char *pTokenText )
295 /*****************************************************************************/
296 {
297 
298     pExport->pParseQueue->Push( QueueEntry( nTyp , ByteString( pTokenText ) ) );
299     return 1;
300 }
301 
302 } // extern
303 
304 extern "C" {
305 /*****************************************************************************/
SetError()306 int SetError()
307 /*****************************************************************************/
308 {
309 	// set error at global instance of class Export
310 	pExport->SetError();
311 	return 1;
312 }
313 }
314 
315 extern "C" {
316 /*****************************************************************************/
GetError()317 int GetError()
318 /*****************************************************************************/
319 {
320 	// get error at global instance of class Export
321 	if ( pExport->GetError())
322 		return 1;
323 	return sal_False;
324 }
325 }
326 
327 //
328 // class ResData
329 //
330 
Dump()331 void ResData::Dump(){
332 	printf("**************\nResData\n");
333 	printf("sPForm = %s , sResTyp = %s , sId = %s , sGId = %s , sHelpId = %s\n",sPForm.GetBuffer()
334 		,sResTyp.GetBuffer(),sId.GetBuffer(),sGId.GetBuffer(),sHelpId.GetBuffer());
335 
336 	ByteString a("*pStringList");
337 	ByteString b("*pUIEntries");
338 	ByteString c("*pFilterList");
339 	ByteString d("*pItemList");
340 	ByteString e("*pPairedList");
341 	ByteString f("sText");
342 
343 	Export::DumpMap( f , sText );
344 
345 	if( pStringList )	Export::DumpExportList( a , *pStringList );
346 	if( pUIEntries )	Export::DumpExportList( b , *pUIEntries );
347 	if( pFilterList )	Export::DumpExportList( c , *pFilterList );
348 	if( pItemList )		Export::DumpExportList( d , *pItemList );
349 	if( pPairedList )	Export::DumpExportList( e , *pPairedList );
350 	printf("\n");
351 }
352 
addFallbackData(ByteString & sId_in,const ByteString & sText_in)353 void ResData::addFallbackData( ByteString& sId_in , const ByteString& sText_in ){
354 	//printf(" ResData::addFallbackData ( sId = %s , sText = %s )\n", sId_in.GetBuffer() , sText_in.GetBuffer() );
355     aFallbackData[ sId_in ] = sText_in;
356 }
getFallbackData(ByteString & sId_in,ByteString & sText_inout)357 bool ResData::getFallbackData( ByteString& sId_in , ByteString& sText_inout ){
358 	sText_inout = aFallbackData[ sId_in ];
359 	//printf("ResData::getFallbackData( sId = %s , return sText = %s \n" , sId_in.GetBuffer(), sText_inout.GetBuffer());
360     return sText_inout.Len() > 0;
361 }
362 
addMergedLanguage(ByteString & sLang)363 void ResData::addMergedLanguage( ByteString& sLang ){
364 	aMergedLanguages[ sLang ]=ByteString("1");
365 }
isMerged(ByteString & sLang)366 bool ResData::isMerged( ByteString& sLang ){
367 	return aMergedLanguages[ sLang ].Equals("1");
368 }
369 
370 /*****************************************************************************/
SetId(const ByteString & rId,sal_uInt16 nLevel)371 sal_Bool ResData::SetId( const ByteString &rId, sal_uInt16 nLevel )
372 /*****************************************************************************/
373 {
374 	if ( nLevel > nIdLevel )
375 	{
376 		nIdLevel = nLevel;
377 		sId = rId;
378 
379 		if ( bChild && bChildWithText ) {
380 			ByteString sError( "ResId after child definition" );
381 			yyerror( sError.GetBufferAccess());
382 			sError.ReleaseBufferAccess();
383 			SetError();
384 		}
385 
386 		if ( sId.Len() > 255 ) {
387 			ByteString sWarning( "LocalId > 255 chars, truncating..." );
388 			YYWarning( sWarning.GetBufferAccess());
389 			sWarning.ReleaseBufferAccess();
390 			sId.Erase( 255 );
391 			sId.EraseTrailingChars( ' ' );
392 			sId.EraseTrailingChars( '\t' );
393 		}
394 
395 		return sal_True;
396 	}
397 
398 	return sal_False;
399 }
400 
401 //
402 // class Export
403 //
404 
405 /*****************************************************************************/
Export(const ByteString & rOutput,sal_Bool bWrite,const ByteString & rPrj,const ByteString & rPrjRoot,const ByteString & rFile)406 Export::Export( const ByteString &rOutput, sal_Bool bWrite,
407 				const ByteString &rPrj, const ByteString &rPrjRoot , const ByteString& rFile )
408 /*****************************************************************************/
409 				:
410 				pWordTransformer( NULL ),
411 				aCharSet( RTL_TEXTENCODING_MS_1252 ),
412 				bDefine( sal_False ),
413 				bNextMustBeDefineEOL( sal_False ),
414                 nLevel( 0 ),
415 				nList( LIST_NON ),
416 				nListIndex( 0 ),
417 				nListLevel( 0 ),
418                 bSkipFile( false ),
419 				sProject( sPrj ),
420 				sRoot( sPrjRoot ),
421 				bEnableExport( bWrite ),
422 				bMergeMode( bUnmerge ),
423 				bError( sal_False ),
424 				bReadOver( sal_False ),
425 				bDontWriteOutput( sal_False ),
426 				sFilename( rFile )
427 {
428     pParseQueue = new ParserQueue( *this );
429     (void) rPrj;
430     (void) rPrjRoot;
431     (void) rFile;
432 
433     if( !isInitialized ) InitLanguages();
434     // used when export is enabled
435 
436 	// open output stream
437 	if ( bEnableExport ) {
438 		aOutput.Open( String( rOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
439 		if( !aOutput.IsOpen() ) {
440             printf("ERROR : Can't open file %s\n",rOutput.GetBuffer());
441             exit ( -1 );
442         }
443         aOutput.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
444 
445 		aOutput.SetLineDelimiter( LINEEND_CRLF );
446 	}
447 }
448 
449 /*****************************************************************************/
Export(const ByteString & rOutput,sal_Bool bWrite,const ByteString & rPrj,const ByteString & rPrjRoot,const ByteString & rMergeSource,const ByteString & rFile)450 Export::Export( const ByteString &rOutput, sal_Bool bWrite,
451 				const ByteString &rPrj, const ByteString &rPrjRoot,
452 				const ByteString &rMergeSource , const ByteString& rFile )
453 /*****************************************************************************/
454 				:
455 				pWordTransformer( NULL ),
456 				aCharSet( RTL_TEXTENCODING_MS_1252 ),
457 				bDefine( sal_False ),
458 				bNextMustBeDefineEOL( sal_False ),
459                 nLevel( 0 ),
460 				nList( LIST_NON ),
461 				nListIndex( 0 ),
462 				nListLevel( 0 ),
463                 bSkipFile( false ),
464 				sProject( sPrj ),
465 				sRoot( sPrjRoot ),
466 				bEnableExport( bWrite ),
467 				bMergeMode( sal_True ),
468 				sMergeSrc( rMergeSource ),
469 				bError( sal_False ),
470 				bReadOver( sal_False ),
471 				bDontWriteOutput( sal_False ),
472 				sFilename( rFile )
473 {
474     (void) rPrj;
475     (void) rPrjRoot;
476     (void) rFile;
477     pParseQueue = new ParserQueue( *this );
478     if( !isInitialized ) InitLanguages( bMergeMode );
479     // used when merge is enabled
480 
481 	// open output stream
482 	if ( bEnableExport ) {
483 		aOutput.Open( String( rOutput, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_WRITE | STREAM_TRUNC );
484         aOutput.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
485 		aOutput.SetLineDelimiter( LINEEND_CRLF );
486 	}
487 
488 }
489 
490 /*****************************************************************************/
Init()491 void Export::Init()
492 /*****************************************************************************/
493 {
494 	// resets the internal status, used before parseing another file
495 	sActPForm = "";
496 	bDefine = sal_False;
497 	bNextMustBeDefineEOL = sal_False;
498 	nLevel = 0;
499 	nList = LIST_NON;
500     nListLang = ByteString( String::CreateFromAscii(""),RTL_TEXTENCODING_ASCII_US );
501 	nListIndex = 0;
502 	while ( aResStack.Count()) {
503 		delete aResStack.GetObject(( sal_uLong ) 0 );
504 		aResStack.Remove(( sal_uLong ) 0 );
505 	}
506 }
507 
508 /*****************************************************************************/
~Export()509 Export::~Export()
510 /*****************************************************************************/
511 {
512 	if( pParseQueue )
513         delete pParseQueue;
514 	// close output stream
515 	if ( bEnableExport )
516 		aOutput.Close();
517 	while ( aResStack.Count()) {
518 		delete aResStack.GetObject(( sal_uLong ) 0 );
519 		aResStack.Remove(( sal_uLong ) 0 );
520 	}
521 
522 	if ( bMergeMode && !bUnmerge ) {
523 		if ( !pMergeDataFile )
524 			pMergeDataFile = new MergeDataFile( sMergeSrc,sFile , bErrorLog, aCharSet);//, bUTF8 );
525 
526 		//pMergeDataFile->WriteErrorLog( sActFileName );
527 		delete pMergeDataFile;
528 	}
529 }
530 
531 /*****************************************************************************/
Execute(int nToken,const char * pToken)532 int Export::Execute( int nToken, const char * pToken )
533 /*****************************************************************************/
534 {
535 
536     ByteString sToken( pToken );
537 	ByteString sOrig( sToken );
538 /*	printf("+---------------\n");
539 	printf("sToken = %s\n",sToken.GetBuffer());
540 	printf("nToken = %d\n",nToken);
541 	printf("+---------------\n"); */
542     sal_Bool bWriteToMerged = bMergeMode;
543 
544 	if ( nToken == CONDITION ) {
545 		ByteString sTestToken( pToken );
546 		sTestToken.EraseAllChars( '\t' );
547 		sTestToken.EraseAllChars( ' ' );
548 		if (( !bReadOver ) && ( sTestToken.Search( "#ifndef__RSC_PARSER" ) == 0 ))
549 			bReadOver = sal_True;
550 		else if (( bReadOver ) && ( sTestToken.Search( "#endif" ) == 0 ))
551 			bReadOver = sal_False;
552 	}
553 	if ((( nToken < FILTER_LEVEL ) || ( bReadOver )) &&
554 		(!(( bNextMustBeDefineEOL ) && ( sOrig == "\n" )))) {
555 		// this tokens are not mandatory for parsing, so ignore them ...
556 		if ( bMergeMode )
557 			WriteToMerged( sOrig , false ); // ... ore whrite them directly to dest.
558 		return 0;
559 	}
560 
561 	ResData *pResData = NULL;
562 	if ( nLevel ) {
563 		// res. exists at cur. level
564 		pResData = aResStack.GetObject( nLevel-1 );
565 	}
566 	else if (( nToken != RESSOURCE ) &&
567 			( nToken != RESSOURCEEXPR ) &&
568 			( nToken != SMALRESSOURCE ) &&
569 			( nToken != LEVELUP ) &&
570 			( nToken != NORMDEFINE ) &&
571             ( nToken != RSCDEFINE ) &&
572 			( nToken != CONDITION ) &&
573 			( nToken != PRAGMA ))
574 	{
575 		// no res. exists at cur. level so return
576 		if ( bMergeMode )
577 			WriteToMerged( sOrig , false );
578 		return 0;
579 	}
580     // #define NO_LOCALIZE_EXPORT
581     if( bSkipFile ){
582         if ( bMergeMode ) {
583             WriteToMerged( sOrig , false );
584         }
585         return 1;
586 	}
587 
588 
589 	if ( bDefine ) {
590 		if (( nToken != EMPTYLINE ) && ( nToken != LEVELDOWN ) && ( nToken != LEVELUP )) {
591 			// cur. res. defined in macro
592 			if ( bNextMustBeDefineEOL ) {
593                 if ( nToken != RSCDEFINELEND ) {
594 					// end of macro found, so destroy res.
595 					bDefine = sal_False;
596 					if ( bMergeMode ) {
597 						/*if ( bDontWriteOutput && bUnmerge ) {
598 							bDontWriteOutput = sal_False;
599 							bNextMustBeDefineEOL = sal_False;
600 							bDefine = sal_True;
601 						}*/
602 						MergeRest( pResData );
603 					}
604 					bNextMustBeDefineEOL = sal_False;
605 					Execute( LEVELDOWN, "" );
606 				}
607 				else {
608 					// next line also in macro definition
609 					bNextMustBeDefineEOL = sal_False;
610 					if ( bMergeMode )
611 						WriteToMerged( sOrig , false );
612 					return 1;
613 				}
614 			}
615 			else if (( nToken != LISTASSIGNMENT ) && ( nToken != UIENTRIES )){
616 				// cur. line has macro line end
617 				ByteString sTmpLine( sToken );
618 				sTmpLine.EraseAllChars( '\t' ); sTmpLine.EraseAllChars( ' ' );
619                 #if 0
620                 // impossible, unsigned is never negative
621 				if( sTmpLine.Len() < 0 ){
622 					if ( sTmpLine.GetChar(( sal_uInt16 )( sTmpLine.Len() - 1 )) != '\\' )
623 						bNextMustBeDefineEOL = sal_True;
624 				}
625                 #endif
626 			}
627 		}
628 	}
629 
630 	sal_Bool bExecuteDown = sal_False;
631 	if ( nToken != LEVELDOWN ) {
632 		sal_uInt16 nOpen = 0;
633 		sal_uInt16 nClose = 0;
634 		sal_Bool bReadOver1 = sal_False;
635         sal_uInt16 i = 0;
636 		for ( i = 0; i < sToken.Len(); i++ ) {
637 			if ( sToken.GetChar( i ) == '\"' )
638 				bReadOver1 = !bReadOver1;
639 			if ( !bReadOver1 && ( sToken.GetChar( i ) == '{' ))
640 				nOpen++;
641 		}
642 
643 		bReadOver1 = sal_False;
644 		for ( i = 0; i < sToken.Len(); i++ ) {
645 			if ( sToken.GetChar( i ) == '\"' )
646 				bReadOver1 = !bReadOver1;
647 			if ( !bReadOver1 && ( sToken.GetChar( i ) == '}' ))
648 				nClose++;
649 		}
650 
651 		if ( nOpen < nClose )
652 			bExecuteDown = sal_True;
653 	}
654 	switch ( nToken ) {
655 
656         case NORMDEFINE:
657                         //printf("sToken = '%s'",sToken.GetBuffer());
658                         while( sToken.SearchAndReplace( "\r", " " ) != STRING_NOTFOUND ) {};
659                         while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
660                         while( sToken.SearchAndReplace( "  ", " " ) != STRING_NOTFOUND ) {};
661                         if( sToken.EqualsIgnoreCaseAscii( "#define NO_LOCALIZE_EXPORT" ) ){
662                             bSkipFile = true;
663                             return 0;
664                         }
665                         if ( bMergeMode )
666                           WriteToMerged( sOrig , false );
667 
668                         return 0;
669 
670 
671         case RSCDEFINE:
672 			bDefine = sal_True; // res. defined in macro
673 
674 		case RESSOURCE:
675 		case RESSOURCEEXPR: {
676 			bDontWriteOutput = sal_False;
677 			if ( nToken != RSCDEFINE )
678 				bNextMustBeDefineEOL = sal_False;
679 			// this is the beginning of a new res.
680 			nLevel++;
681 			if ( nLevel > 1 ) {
682 				aResStack.GetObject( nLevel - 2 )->bChild = sal_True;
683 			}
684 
685 			// create new instance for this res. and fill mandatory fields
686 
687 			pResData = new ResData( sActPForm, FullId() , sFilename );
688 			aResStack.Insert( pResData, LIST_APPEND );
689 			ByteString sBackup( sToken );
690 			sToken.EraseAllChars( '\n' );
691 			sToken.EraseAllChars( '\r' );
692 			sToken.EraseAllChars( '{' );
693 			while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
694 			sToken.EraseTrailingChars( ' ' );
695 			ByteString sT =  sToken.GetToken( 0, ' ' );
696             pResData->sResTyp = sT.ToLowerAscii();
697 			ByteString sId( sToken.Copy( pResData->sResTyp.Len() + 1 ));
698 			ByteString sCondition;
699 			if ( sId.Search( "#" ) != STRING_NOTFOUND ) {
700 				// between ResTyp, Id and paranthes is a precomp. condition
701 				sCondition = "#";
702 				sCondition += sId.GetToken( 1, '#' );
703 				sId = sId.GetToken( 0, '#' );
704 			}
705 			sId = sId.GetToken( 0, '/' );
706 			CleanValue( sId );
707 			sId = sId.EraseAllChars( '\t' );
708 			pResData->SetId( sId, ID_LEVEL_IDENTIFIER );
709 			if ( sCondition.Len()) {
710 				ByteString sEmpty( "" );
711 				Execute( CONDITION, sEmpty.GetBufferAccess()); 	// execute the
712 														  		// precomp.
713 																// condition
714 				sEmpty.ReleaseBufferAccess();
715 			}
716 		}
717 		break;
718 		case SMALRESSOURCE: {
719 			bDontWriteOutput = sal_False;
720 			// this is the beginning of a new res.
721 			bNextMustBeDefineEOL = sal_False;
722 			nLevel++;
723 			if ( nLevel > 1 ) {
724 				aResStack.GetObject( nLevel - 2 )->bChild = sal_True;
725 			}
726 
727 			// create new instance for this res. and fill mandatory fields
728 
729 			pResData = new ResData( sActPForm, FullId() , sFilename );
730 			aResStack.Insert( pResData, LIST_APPEND );
731 			sToken.EraseAllChars( '\n' );
732 			sToken.EraseAllChars( '\r' );
733 			sToken.EraseAllChars( '{' );
734 			sToken.EraseAllChars( '\t' );
735 			sToken.EraseAllChars( ' ' );
736 			sToken.EraseAllChars( '\\' );
737 			pResData->sResTyp = sToken.ToLowerAscii();
738 		}
739 		break;
740 		case LEVELUP: {
741 			// push
742 			if ( nList )
743 				nListLevel++;
744 			if ( nList )
745 				break;
746 
747 			bDontWriteOutput = sal_False;
748 			ByteString sLowerTyp;
749 			if ( pResData )
750 				sLowerTyp = "unknown";
751 			nLevel++;
752 			if ( nLevel > 1 ) {
753 				aResStack.GetObject( nLevel - 2 )->bChild = sal_True;
754 			}
755 
756 			ResData *pNewData = new ResData( sActPForm, FullId() , sFilename );
757 			pNewData->sResTyp = sLowerTyp;
758 			aResStack.Insert( pNewData, LIST_APPEND );
759 		}
760 		break;
761 		case LEVELDOWN: {
762 			// pop
763 			if ( !nList  ) {
764 				bDontWriteOutput = sal_False;
765 				if ( nLevel ) {
766 					if ( bDefine && (nLevel == 1 )) {
767                         bDefine = sal_False;
768 						bNextMustBeDefineEOL = sal_False;
769 					}
770 					WriteData( pResData );
771 					delete aResStack.GetObject( nLevel - 1 );
772 					aResStack.Remove( nLevel - 1 );
773 					nLevel--;
774 				}
775 			}
776 			else {
777 				if ( bDefine )
778 					bNextMustBeDefineEOL = sal_True;
779 				if ( !nListLevel ) {
780 					if ( bMergeMode )
781 						MergeRest( pResData, MERGE_MODE_LIST );
782 					nList = LIST_NON;
783 				}
784 				else
785 					nListLevel--;
786 			}
787 		}
788 		break;
789         case ASSIGNMENT: {
790 			bDontWriteOutput = sal_False;
791 			// interpret different types of assignement
792  			ByteString sKey = sToken.GetToken( 0, '=' );
793 			sKey.EraseAllChars( ' ' );
794 			sKey.EraseAllChars( '\t' );
795 			ByteString sValue = sToken.GetToken( 1, '=' );
796 			CleanValue( sValue );
797 			if ( sKey.ToUpperAscii() == "IDENTIFIER" ) {
798 				ByteString sId( sValue.EraseAllChars( '\t' ));
799 				pResData->SetId( sId.EraseAllChars( ' ' ), ID_LEVEL_IDENTIFIER );
800 			}
801 			else if ( sKey == "HELPID" ) {
802 				pResData->sHelpId = sValue;
803 			}
804 			else if ( sKey == "STRINGLIST" ) {
805 				//if ( bUnmerge ){
806 				//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
807 				//}
808 
809 				pResData->bList = sal_True;
810 				nList = LIST_STRING;
811                 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
812                 nListLang = SOURCE_LANGUAGE;
813 				nListIndex = 0;
814 				nListLevel = 0;
815 			}
816 			else if ( sKey == "FILTERLIST" ) {
817 				//if ( bUnmerge ){
818 				//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
819 				//}
820 				pResData->bList = sal_True;
821 				nList = LIST_FILTER;
822                 //ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
823 				nListLang = SOURCE_LANGUAGE;
824 				nListIndex = 0;
825 				nListLevel = 0;
826 			}
827 			else if ( sKey == "UIENTRIES" ) {
828 				//if ( bUnmerge ){
829 				//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));}
830 				pResData->bList = sal_True;
831 				nList = LIST_UIENTRIES;
832 				//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
833 				nListLang = SOURCE_LANGUAGE;
834 				nListIndex = 0;
835 				nListLevel = 0;
836 			}
837 			if (( sToken.Search( "{" ) != STRING_NOTFOUND ) &&
838 				( sToken.GetTokenCount( '{' ) > sToken.GetTokenCount( '}' )))
839 			{
840 				//WorkOnTokenSet( LEVELUP, pTkn );
841                 Parse( LEVELUP, "" );
842 			}
843             //if ( bUnmerge && ( nListLang.EqualsIgnoreCaseAscii("de") || nListLang.EqualsIgnoreCaseAscii("en-US") ) && ListExists( pResData, nList ))
844 			//	bDontWriteOutput = sal_True;
845  		}
846 		break;
847 		case UIENTRIES:
848 		case LISTASSIGNMENT: {
849 			bDontWriteOutput = sal_False;
850             ByteString sTmpToken( sToken);
851             sTmpToken.EraseAllChars(' ');
852             sal_uInt16 nPos = 0;
853             //nPos = sTmpToken.ToLowerAscii().Search("[de]=");
854 			nPos = sTmpToken.ToLowerAscii().Search("[en-us]=");
855             if( nPos != STRING_NOTFOUND ) {
856 				//if ( bUnmerge ){
857 				//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
858 				//}
859                 ByteString sKey = sTmpToken.Copy( 0 , nPos );
860 				sKey.EraseAllChars( ' ' );
861 				sKey.EraseAllChars( '\t' );
862 				ByteString sValue = sToken.GetToken( 1, '=' );
863 				CleanValue( sValue );
864 				if ( sKey.ToUpperAscii() ==  "STRINGLIST" ) {
865 					pResData->bList = sal_True;
866 					nList = LIST_STRING;
867 					//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
868 					nListLang = SOURCE_LANGUAGE;
869 					nListIndex = 0;
870 					nListLevel = 0;
871 				}
872 				else if ( sKey == "FILTERLIST" ) {
873 					pResData->bList = sal_True;
874 					nList = LIST_FILTER;
875 					//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
876 					nListLang = SOURCE_LANGUAGE;
877 					nListIndex = 0;
878 					nListLevel = 0;
879 				}
880 				// PairedList
881                 else if ( sKey ==  "PAIREDLIST" ) {
882 					pResData->bList = sal_True;
883 					nList = LIST_PAIRED;
884 					//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
885 					nListLang = SOURCE_LANGUAGE;
886 					nListIndex = 0;
887 					nListLevel = 0;
888 				}
889 
890                 else if ( sKey ==  "ITEMLIST" ) {
891 					pResData->bList = sal_True;
892 					nList = LIST_ITEM;
893 					//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
894 					nListLang = SOURCE_LANGUAGE;
895 					nListIndex = 0;
896 					nListLevel = 0;
897 				}
898 				else if ( sKey ==  "UIENTRIES" ) {
899 					pResData->bList = sal_True;
900 					nList = LIST_UIENTRIES;
901 					//ByteString sLang("en-US" , RTL_TEXTENCODING_ASCII_US );
902 					nListLang = SOURCE_LANGUAGE;
903 					nListIndex = 0;
904 					nListLevel = 0;
905 				}
906                 /*if ( bUnmerge && ( nListLang.EqualsIgnoreCaseAscii( "de" )
907                     || nListLang.EqualsIgnoreCaseAscii("en-US" ) )
908                     && ListExists( pResData, nList ))
909 					bDontWriteOutput = sal_True;*/
910 			}
911 			else {
912 				// new res. is a String- or FilterList
913 				ByteString sKey = sToken.GetToken( 0, '[' );
914 				sKey.EraseAllChars( ' ' );
915 				sKey.EraseAllChars( '\t' );
916 				if ( sKey.ToUpperAscii() == "STRINGLIST" )
917 					nList = LIST_STRING;
918 				else if ( sKey == "FILTERLIST" )
919 					nList = LIST_FILTER;
920 				else if ( sKey == "PAIREDLIST" )
921 					nList = LIST_PAIRED;				// abcd
922 				else if ( sKey == "ITEMLIST" )
923 					nList = LIST_ITEM;
924 				else if ( sKey == "UIENTRIES" )
925 					nList = LIST_UIENTRIES;
926 				if ( nList ) {
927 					ByteString sLang=sToken.GetToken( 1, '[' ).GetToken( 0, ']' );
928 					CleanValue( sLang );
929                     nListLang = sLang;
930                     /*if (( bUnmerge ) && ( !nListLang.EqualsIgnoreCaseAscii("de")) && ( !nListLang.EqualsIgnoreCaseAscii("en-US")))
931                         bDontWriteOutput = sal_True;*/
932 					nListIndex = 0;
933 					nListLevel = 0;
934                     /*if ( bUnmerge && nListLang.EqualsIgnoreCaseAscii("de")  && ListExists( pResData, nList ) )
935 						bDontWriteOutput = sal_True;*/
936 				}
937 			}
938 		}
939 		break;
940 		case TEXT:
941 		case _LISTTEXT:
942 		case LISTTEXT: {
943 			// this is an entry for a String- or FilterList
944 			if ( nList ) {
945 				SetChildWithText();
946 				ByteString sEntry( sToken.GetToken( 1, '\"' ));
947 				if ( sToken.GetTokenCount( '\"' ) > 3 )
948 					sEntry += "\"";
949 				if ( sEntry == "\\\"" )
950 					sEntry = "\"";
951 				//sEntry = sEntry.Convert( aCharSet, RTL_TEXTENCODING_MS_1252 );
952 				//sEntry = sEntry.Convert( RTL_TEXTENCODING_MS_1252, RTL_TEXTENCODING_UTF8 );
953 				InsertListEntry( sEntry, sOrig );
954 				if ( bMergeMode && ( sEntry != "\"" )) {
955 					PrepareTextToMerge( sOrig, nList, nListLang, pResData );
956 				}
957 			}
958 		}
959 		break;
960 		case LONGTEXTLINE:
961 		case TEXTLINE:
962 			bDontWriteOutput = sal_False;
963 			if ( nLevel ) {
964 				CutComment( sToken );
965 
966 				// this is a text line!!!
967 				ByteString sKey = sToken.GetToken( 0, '=' ).GetToken( 0, '[' );
968 				sKey.EraseAllChars( ' ' );
969 				sKey.EraseAllChars( '\t' );
970 				ByteString sText( GetText( sToken, nToken ));
971 				if ( !bMergeMode )
972 					sText = sText.Convert( aCharSet, RTL_TEXTENCODING_MS_1252 );
973 				ByteString sLang;
974 				if ( sToken.GetToken( 0, '=' ).Search( "[" ) != STRING_NOTFOUND ) {
975  					sLang = sToken.GetToken( 0, '=' ).GetToken( 1, '[' ).GetToken( 0, ']' );
976 					CleanValue( sLang );
977 				}
978 				ByteString nLangIndex = sLang;
979                 ByteString sOrigKey = sKey;
980 				if ( sText.Len() && sLang.Len() ) {
981 					if (( sKey.ToUpperAscii() == "TEXT" ) ||
982 						( sKey == "MESSAGE" ) ||
983 						( sKey == "CUSTOMUNITTEXT" ) ||
984 						( sKey == "SLOTNAME" ) ||
985 						( sKey == "UINAME" ))
986 					{
987 						//if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND )
988 						//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
989 
990 						SetChildWithText();
991                         //if ( nLangIndex.EqualsIgnoreCaseAscii("en-US") )
992 						if ( Export::isSourceLanguage( nLangIndex ) )
993 							pResData->SetId( sText, ID_LEVEL_TEXT );
994 
995 						pResData->bText = sal_True;
996 						pResData->sTextTyp = sOrigKey;
997 						if ( bMergeMode ) {
998 							PrepareTextToMerge( sOrig, STRING_TYP_TEXT, nLangIndex, pResData );
999 							//if ( bUnmerge )
1000 							//	pResData->sText[ nLangIndex ] = sText;
1001 						}
1002 						else {
1003 							if ( pResData->sText[ nLangIndex ].Len()) {
1004 								ByteString sError( "Language " );
1005                                 sError += nLangIndex;
1006 								sError += " defined twice";
1007 							}
1008 							pResData->sText[ nLangIndex ] = sText;
1009 						}
1010 					}
1011 					else if ( sKey == "HELPTEXT" ) {
1012 						//if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1013 						//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1014 						//	}
1015 						SetChildWithText();
1016 						pResData->bHelpText = sal_True;
1017 						if ( bBreakWhenHelpText ) {
1018 							ByteString sError( "\"HelpText\" found in source\n" );
1019 							YYWarning( sError.GetBufferAccess());
1020 							sError.ReleaseBufferAccess();
1021 							SetError();
1022 						}
1023 						if ( bMergeMode )
1024 							PrepareTextToMerge( sOrig, STRING_TYP_HELPTEXT, nLangIndex, pResData );
1025 							//if ( bUnmerge )
1026 							//	pResData->sHelpText[ nLangIndex ] = sText;
1027 						else {
1028 							if ( pResData->sHelpText[ nLangIndex ].Len()) {
1029 								ByteString sError( "Language " );
1030                                 sError += nLangIndex;
1031 								sError += " defined twice";
1032 							}
1033 							pResData->sHelpText[ nLangIndex ] = sText;
1034 						}
1035 					}
1036 					else if ( sKey == "QUICKHELPTEXT" ) {
1037 						//if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1038 						//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1039 						//	}
1040 						SetChildWithText();
1041 						pResData->bQuickHelpText = sal_True;
1042 						if ( bMergeMode )
1043 							PrepareTextToMerge( sOrig, STRING_TYP_QUICKHELPTEXT, nLangIndex, pResData );
1044 							//if ( bUnmerge )
1045 							//	pResData->sQuickHelpText[ nLangIndex ] = sText;
1046 						else {
1047 							if ( pResData->sQuickHelpText[ nLangIndex ].Len()) {
1048 								ByteString sError( "Language " );
1049                                 sError += nLangIndex;
1050 								sError += " defined twice";
1051 							}
1052 							pResData->sQuickHelpText[ nLangIndex ] = sText;
1053 						}
1054 					}
1055 					else if ( sKey == "TITLE" ) {
1056 						//if ( bUnmerge && sToken.GetToken( 0, '=' ).Search( "[" ) == STRING_NOTFOUND ){
1057 						//	( sOrig.SearchAndReplace( "=", "[ de ] =" ));
1058 						//	}
1059 						SetChildWithText();
1060 						pResData->bTitle = sal_True;
1061 						if ( bMergeMode )
1062 							PrepareTextToMerge( sOrig, STRING_TYP_TITLE, nLangIndex, pResData );
1063 							//if ( bUnmerge )
1064 							//	pResData->sTitle[ nLangIndex ] = sText;
1065 						else {
1066 							if ( pResData->sTitle[ nLangIndex ].Len()) {
1067 								ByteString sError( "Language " );
1068                                 sError += nLangIndex;
1069 								sError += " defined twice";
1070 							}
1071 							pResData->sTitle[ nLangIndex ] = sText;
1072 						}
1073 					}
1074 					else if ( sKey == "ACCESSPATH" ) {
1075 						pResData->SetId( sText, ID_LEVEL_ACCESSPATH );
1076 					}
1077 					else if ( sKey == "FIELDNAME" ) {
1078 						pResData->SetId( sText, ID_LEVEL_FIELDNAME );
1079 					}
1080 				}
1081 			}
1082 		break;
1083 		case NEWTEXTINRES: {
1084 			bDontWriteOutput = sal_True;
1085 			// this means something like // ### Achtung : Neuer Text ...
1086 			/*ByteString sLang( "GERMAN" );
1087 			ByteString sText = sToken.GetToken( 2, ':' ).GetToken( 0, '*' );
1088 			CleanValue( sText );
1089 			if ( sText.Len())
1090             	pResData->sText[ sLang ] = sText;*/
1091 		}
1092 		break;
1093 		case APPFONTMAPPING: {
1094 			bDontWriteOutput = sal_False;
1095 			// this is a AppfontMapping, so look if its a definition
1096 			// of field size
1097 			ByteString sKey = sToken.GetToken( 0, '=' );
1098 			sKey.EraseAllChars( ' ' );
1099 			sKey.EraseAllChars( '\t' );
1100 			ByteString sMapping = sToken.GetToken( 1, '=' );
1101 			sMapping = sMapping.GetToken( 1, '(' );
1102 			sMapping = sMapping.GetToken( 0, ')' );
1103 			sMapping.EraseAllChars( ' ' );
1104 			sMapping.EraseAllChars( '\t' );
1105 			if ( sKey.ToUpperAscii() == "SIZE" ) {
1106 				pResData->nWidth = ( sal_uInt16 ) sMapping.GetToken( 0, ',' ).ToInt64();
1107 			}
1108 			else if ( sKey == "POSSIZE" ) {
1109 				pResData->nWidth = ( sal_uInt16 ) sMapping.GetToken( 2, ',' ).ToInt64();
1110 			}
1111 		}
1112 		break;
1113 		case RSCDEFINELEND:
1114 			bDontWriteOutput = sal_False;
1115 		break;
1116 		case CONDITION: {
1117 			bDontWriteOutput = sal_False;
1118 			while( sToken.SearchAndReplace( "\r", " " ) != STRING_NOTFOUND ) {};
1119 			while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1120 			while( sToken.SearchAndReplace( "  ", " " ) != STRING_NOTFOUND ) {};
1121 			ByteString sCondition = sToken.GetToken( 0, ' ' );
1122 			if ( sCondition == "#ifndef" ) {
1123 				sActPForm = "!defined ";
1124 				sActPForm += sToken.GetToken( 1, ' ' );
1125 			}
1126 			else if ( sCondition == "#ifdef" ) {
1127 				sActPForm = "defined ";
1128 				sActPForm += sToken.GetToken( 1, ' ' );
1129 			}
1130 			else if ( sCondition == "#if" ) {
1131 				sActPForm = sToken.Copy( 4 );
1132 				while ( sActPForm.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND ) {};
1133 			}
1134 			else if ( sCondition == "#elif" ) {
1135 				sActPForm = sToken.Copy( 6 );
1136 				while ( sActPForm.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND ) {};
1137 			}
1138 			else if ( sCondition == "#else" ) {
1139 				sActPForm = sCondition;
1140 			}
1141 			else if ( sCondition == "#endif" ) {
1142 				sActPForm = "";
1143 			}
1144 			else break;
1145 			if ( nLevel ) {
1146 				WriteData( pResData, sal_True );
1147 				pResData->sPForm = sActPForm;
1148 			}
1149 		}
1150 		break;
1151 		case EMPTYLINE : {
1152 			bDontWriteOutput = sal_False;
1153 			if ( bDefine ) {
1154 				bNextMustBeDefineEOL = sal_False;
1155                 bDefine = sal_False;
1156 				while ( nLevel )
1157 					Parse( LEVELDOWN, "" );
1158                     //WorkOnTokenSet( LEVELDOWN, pTkn );
1159 			}
1160 		}
1161 		break;
1162 		case PRAGMA : {
1163 			bDontWriteOutput = sal_False;
1164 			while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1165 			while( sToken.SearchAndReplace( "  ", " " ) != STRING_NOTFOUND ) {};
1166 			sToken.EraseLeadingChars( ' ' );
1167 			sToken.EraseTrailingChars( ' ' );
1168 
1169 			ByteString sCharset = sToken.GetToken( 1, ' ' );
1170 			ByteString sSet = sToken.GetToken( 2, ' ' );
1171 			if (( sCharset.ToUpperAscii() == "CHARSET_IBMPC" ) ||
1172 				( sCharset == "RTL_TEXTENCODING_IBM_850" ) ||
1173 				(( sCharset == "CHARSET" ) && ( sSet.ToUpperAscii() == "IBMPC" )))
1174 			{
1175 				aCharSet = RTL_TEXTENCODING_IBM_850;
1176 			}
1177 			else if (( sCharset == "CHARSET_ANSI" ) ||
1178 				( sCharset == "RTL_TEXTENCODING_MS_1252" ) ||
1179 				(( sCharset == "CHARSET" ) && ( sSet.ToUpperAscii() == "ANSI" )))
1180 			{
1181 				aCharSet = RTL_TEXTENCODING_MS_1252;
1182 			}
1183 		}
1184 		break;
1185 		case TEXTREFID : {
1186 			bDontWriteOutput = sal_True;
1187  			/*ByteString sK = sToken.GetToken( 0, '=' );
1188             ByteString sKey = sK.EraseAllChars( '\t' ).EraseAllChars( ' ' );
1189 			ByteString sT = sToken.GetToken( 1, '=' ).GetToken( 0, ';' );
1190             sal_uInt16 nRefId = ( sal_uInt16 ) sT.EraseAllChars( '\t' ).EraseAllChars( ' ' ).ToInt32();
1191 			if (( sKey.ToUpperAscii() == "TEXT" ) ||
1192 				( sKey == "MESSAGE" ) ||
1193 				( sKey == "CUSTOMUNITTEXT" ) ||
1194 				( sKey == "SLOTNAME" ) ||
1195 				( sKey == "UINAME" ))
1196 					pResData->nTextRefId = nRefId;
1197 			else if ( sKey == "HELPTEXT" )
1198 				pResData->nHelpTextRefId = nRefId;
1199 			else if ( sKey == "QUICKHELPTEXT" )
1200 				pResData->nQuickHelpTextRefId = nRefId;
1201 			else if ( sKey == "TITLE" )
1202 				pResData->nTitleRefId = nRefId;*/
1203 		}
1204 		}
1205 	if ( bWriteToMerged ) {
1206 		// the current token must be written to dest. without merging
1207 
1208         if( bDefine && sOrig.Len() > 2 ){
1209             for( sal_uInt16 n = 0 ; n < sOrig.Len() ; n++ ){
1210                 if( sOrig.GetChar( n ) == '\n' && sOrig.GetChar( n-1 ) != '\\'){
1211                     sOrig.Insert('\\' , n++ );
1212                 }
1213             }
1214         }
1215         WriteToMerged( sOrig , false);
1216 	}
1217 
1218 	if ( bExecuteDown ) {
1219 		Parse( LEVELDOWN, "" );
1220         //WorkOnTokenSet( LEVELDOWN, pTkn );
1221 	}
1222 
1223 	return 1;
1224 }
1225 
1226 /*****************************************************************************/
CutComment(ByteString & rText)1227 void Export::CutComment( ByteString &rText )
1228 /*****************************************************************************/
1229 {
1230 	if ( rText.Search( "//" ) != STRING_NOTFOUND ) {
1231 		ByteString sWork( rText );
1232 		sWork.SearchAndReplaceAll( "\\\"", "XX" );
1233 		sal_uInt16 i = 0;
1234 		sal_Bool bInner = sal_False;
1235 
1236 		while ( i < sWork.Len() - 1 ) {
1237 			if ( sWork.GetChar( i ) == '\"' )
1238 				bInner = !bInner;
1239 			else if
1240 				(( sWork.GetChar( i ) == '/' ) &&
1241 				( !bInner ) &&
1242 				( sWork.GetChar( i + 1 ) == '/' ))
1243 			{
1244 				rText.Erase( i );
1245 				return;
1246 			}
1247 			i++;
1248 		}
1249 	}
1250 }
1251 
UnmergeUTF8(ByteString & sOrig)1252 void Export::UnmergeUTF8( ByteString& sOrig ){
1253 	sal_uInt16 nPos1 = sOrig.Search('\"');
1254 	sal_uInt16 nPos2 = sOrig.SearchBackward('\"');
1255 	if( nPos1 > 0 && nPos2 > 0 && nPos1 < nPos2){
1256 		ByteString sPart = sOrig.Copy(nPos1+1 , nPos2-1);
1257 		ByteString sPartUTF8 = sPart;
1258 		sPartUTF8.Convert( RTL_TEXTENCODING_MS_1252 , RTL_TEXTENCODING_UTF8 );
1259 		sOrig.SearchAndReplace( sPart , sPartUTF8 );
1260 	}
1261 }
1262 
1263 /*****************************************************************************/
ListExists(ResData * pResData,sal_uInt16 nLst)1264 sal_Bool Export::ListExists( ResData *pResData, sal_uInt16 nLst )
1265 /*****************************************************************************/
1266 {
1267 	switch ( nLst ) {
1268 		case LIST_STRING: return pResData->pStringList != NULL;
1269 		case LIST_FILTER: return pResData->pFilterList != NULL;
1270 		case LIST_ITEM: return pResData->pItemList != NULL;
1271         case LIST_PAIRED: return pResData->pPairedList != NULL;
1272 		case LIST_UIENTRIES: return pResData->pUIEntries != NULL;
1273 	}
1274 	return sal_False;
1275 }
1276 
1277 /*****************************************************************************/
WriteData(ResData * pResData,sal_Bool bCreateNew)1278 sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
1279 /*****************************************************************************/
1280 {
1281 	if ( bMergeMode ) {
1282 		MergeRest( pResData );
1283 		return sal_True;
1284 	}
1285 
1286 	if ( bUnmerge )
1287 		return sal_True;
1288 
1289 /*    ByteStringHashMap::iterator pos3 = pResData->sText.begin();
1290     ByteStringHashMap::iterator end3 = pResData->sText.end();
1291     for(;pos3!=end3;++pos3){
1292 
1293         printf("[%s]=%s\n", pos3->first.GetBuffer(), pos3->second.GetBuffer() );
1294     }*/
1295    	// mandatory to export: en-US
1296 
1297      if (( //pResData->sText[ ByteString("de") ].Len() &&
1298         ( pResData->sText[ SOURCE_LANGUAGE ].Len()))
1299         ||
1300         ( //pResData->sHelpText[ ByteString("de") ].Len() &&
1301         (  pResData->sHelpText[ SOURCE_LANGUAGE ].Len()))
1302         ||
1303         ( //pResData->sQuickHelpText[ ByteString("de") ].Len() &&
1304         (  pResData->sQuickHelpText[ SOURCE_LANGUAGE ].Len()))
1305          ||
1306         ( //pResData->sTitle[ ByteString("de") ].Len() &&
1307         (  pResData->sTitle[ SOURCE_LANGUAGE ].Len())))
1308 
1309    	{
1310 		FillInFallbacks( pResData );
1311 
1312 		ByteString sGID = pResData->sGId;
1313 		ByteString sLID;
1314 		if ( !sGID.Len())
1315 			sGID = pResData->sId;
1316 		else
1317 			sLID = pResData->sId;
1318 
1319 		ByteString sXText;
1320 		ByteString sXHText;
1321 		ByteString sXQHText;
1322 		ByteString sXTitle;
1323 
1324 		ByteString sTimeStamp( Export::GetTimeStamp());
1325         ByteString sCur;
1326 
1327         for( unsigned int n = 0; n < aLanguages.size(); n++ ){
1328             sCur = aLanguages[ n ];
1329                 if ( !sCur.EqualsIgnoreCaseAscii("x-comment") ){
1330                     if ( pResData->sText[ sCur ].Len())
1331                         sXText = pResData->sText[ sCur ];
1332 					else {
1333 						sXText = pResData->sText[ SOURCE_LANGUAGE ];
1334 						/*if ( !sXText.Len())
1335 							sXText = pResData->sText[ ByteString("en") ];
1336 						if ( !sXText.Len())
1337 							sXText = pResData->sText[ ByteString("de") ];*/
1338 					}
1339 
1340                     if ( pResData->sHelpText[ sCur ].Len())
1341                         sXHText = pResData->sHelpText[ sCur ];
1342 					else {
1343 						sXHText = pResData->sHelpText[ SOURCE_LANGUAGE ];
1344 						/*if ( !sXHText.Len())
1345 							sXHText = pResData->sHelpText[ ByteString("en") ];
1346 						if ( !sXText.Len())
1347 							sXHText = pResData->sHelpText[ ByteString("de") ];*/
1348 					}
1349 
1350                     if ( pResData->sQuickHelpText[ sCur ].Len())
1351                         sXQHText = pResData->sQuickHelpText[ sCur ];
1352 					else {
1353 						sXQHText = pResData->sQuickHelpText[ SOURCE_LANGUAGE ];
1354 						/*if ( !sXQHText.Len())
1355 							sXQHText = pResData->sQuickHelpText[ ByteString("en") ];
1356 						if ( !sXQHText.Len())
1357 							sXQHText = pResData->sQuickHelpText[ ByteString("de") ];*/
1358 					}
1359 
1360                     if ( pResData->sTitle[ sCur ].Len())
1361                         sXTitle = pResData->sTitle[ sCur ];
1362 					else {
1363 						sXTitle = pResData->sTitle[ SOURCE_LANGUAGE ];
1364 						/*if ( !sXTitle.Len())
1365 							sXTitle = pResData->sTitle[ ByteString("en") ];
1366 						if ( !sXTitle.Len())
1367 							sXTitle = pResData->sTitle[ ByteString("de") ];*/
1368 					}
1369 
1370 					if ( !sXText.Len())
1371 						sXText = "-";
1372 
1373 					if ( !sXHText.Len()) {
1374 						/*if ( pResData->sHelpText[ ByteString("de") ].Len())
1375 							sXHText = pResData->sHelpText[ ByteString("de") ];*/
1376 						if ( pResData->sHelpText[ SOURCE_LANGUAGE ].Len())
1377 							sXHText = pResData->sHelpText[ SOURCE_LANGUAGE ];
1378 						/*else if ( pResData->sHelpText[ ByteString("en") ].Len())
1379 							sXHText = pResData->sHelpText[ ByteString("en") ];*/
1380 					}
1381 				}
1382 				else
1383                     sXText = pResData->sText[ sCur ];
1384 
1385 				if ( bEnableExport ) {
1386 					ByteString sOutput( sProject ); sOutput += "\t";
1387 					if ( sRoot.Len())
1388 						sOutput += sActFileName;
1389 					sOutput += "\t0\t";
1390 					sOutput += pResData->sResTyp; sOutput += "\t";
1391 					sOutput += sGID; sOutput += "\t";
1392 					sOutput += sLID; sOutput += "\t";
1393 					sOutput += pResData->sHelpId; sOutput	+= "\t";
1394 					sOutput += pResData->sPForm; sOutput	+= "\t";
1395 					sOutput += ByteString::CreateFromInt64( pResData->nWidth ); sOutput += "\t";
1396                     sOutput += sCur; sOutput += "\t";
1397 
1398 
1399 					sOutput += sXText; sOutput	+= "\t";
1400 					sOutput += sXHText; sOutput += "\t";
1401 					sOutput += sXQHText; sOutput+= "\t";
1402 					sOutput += sXTitle; sOutput += "\t";
1403 					sOutput += sTimeStamp;
1404 
1405                  // if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1406 				    aOutput.WriteLine( sOutput );
1407 				}
1408 
1409 				if ( bCreateNew ) {
1410                     pResData->sText[ sCur ]			= "";
1411 					pResData->sHelpText[ sCur ]		= "";
1412 					pResData->sQuickHelpText[ sCur ]= "";
1413 					pResData->sTitle[ sCur ]		= "";
1414 				}
1415 			}
1416 	}
1417 	FillInFallbacks( pResData );
1418 	if ( pResData->pStringList ) {
1419 		ByteString sList( "stringlist" );
1420 		WriteExportList( pResData, pResData->pStringList, sList, bCreateNew );
1421 		if ( bCreateNew )
1422 			pResData->pStringList = 0;
1423 	}
1424 	if ( pResData->pFilterList ) {
1425 		ByteString sList( "filterlist" );
1426 		WriteExportList( pResData, pResData->pFilterList, sList, bCreateNew );
1427 		if ( bCreateNew )
1428 			pResData->pFilterList = 0;
1429 	}
1430 	if ( pResData->pItemList ) {
1431 		ByteString sList( "itemlist" );
1432 		WriteExportList( pResData, pResData->pItemList, sList, bCreateNew );
1433 		if ( bCreateNew )
1434 			pResData->pItemList = 0;
1435 	}
1436 	if ( pResData->pPairedList ) {
1437 		ByteString sList( "pairedlist" );
1438 		WriteExportList( pResData, pResData->pPairedList, sList, bCreateNew );
1439 		if ( bCreateNew )
1440 			pResData->pItemList = 0;
1441 	}
1442 	if ( pResData->pUIEntries ) {
1443 		ByteString sList( "uientries" );
1444 		WriteExportList( pResData, pResData->pUIEntries, sList, bCreateNew );
1445 		if ( bCreateNew )
1446 			pResData->pUIEntries = 0;
1447 	}
1448 	return sal_True;
1449 }
GetPairedListID(const ByteString & sText)1450 ByteString Export::GetPairedListID( const ByteString& sText ){
1451 // < "STRING" ; IDENTIFIER ; > ;
1452     ByteString sIdent = sText.GetToken( 1, ';' );
1453     sIdent.ToUpperAscii();
1454     while( sIdent.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1455     sIdent.EraseTrailingChars( ' ' );
1456 	sIdent.EraseLeadingChars( ' ' );
1457     return sIdent;
1458 }
GetPairedListString(const ByteString & sText)1459 ByteString Export::GetPairedListString( const ByteString& sText ){
1460 // < "STRING" ; IDENTIFIER ; > ;
1461 	ByteString sString = sText.GetToken( 0, ';' );
1462     while( sString.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1463     sString.EraseTrailingChars( ' ' );
1464 	ByteString s1 = sString.Copy( sString.Search( '\"' )+1 );
1465 	sString = s1.Copy( 0 , s1.SearchBackward( '\"' ) );
1466 	sString.EraseTrailingChars( ' ' );
1467 	sString.EraseLeadingChars( ' ' );
1468     return sString;
1469 }
StripList(const ByteString & sText)1470 ByteString Export::StripList( const ByteString& sText ){
1471 	ByteString s1 = sText.Copy( sText.Search( '\"' ) + 1 );
1472 	return s1.Copy( 0 , s1.SearchBackward( '\"' ) );
1473 }
1474 
1475 /*****************************************************************************/
WriteExportList(ResData * pResData,ExportList * pExportList,const ByteString & rTyp,sal_Bool bCreateNew)1476 sal_Bool Export::WriteExportList( ResData *pResData, ExportList *pExportList,
1477 						const ByteString &rTyp, sal_Bool bCreateNew )
1478 /*****************************************************************************/
1479 {
1480 	ByteString sGID = pResData->sGId;
1481 	if ( !sGID.Len())
1482 		sGID = pResData->sId;
1483 	else {
1484 		sGID += ".";
1485 		sGID += pResData->sId;
1486 		sGID.EraseTrailingChars( '.' );
1487 	}
1488 
1489 	ByteString sTimeStamp( Export::GetTimeStamp());
1490     ByteString sCur;
1491 	for ( sal_uLong i = 0; pExportList != NULL && i < pExportList->Count(); i++ ) {
1492 		ExportListEntry *pEntry = pExportList->GetObject( i );
1493 				// mandatory for export: german and eng. and/or enus
1494 		//ByteString a("Export::WriteExportList::pEntry");
1495 		//Export::DumpMap( a,  *pEntry );
1496 
1497 		ByteString sLID( ByteString::CreateFromInt64( i + 1 ));
1498         for( unsigned int n = 0; n < aLanguages.size(); n++ ){
1499             sCur = aLanguages[ n ];
1500             if ( //1 )
1501 				  //(*pEntry)[ ByteString("de") ].Len() &&
1502 				 	(*pEntry)[ SOURCE_LANGUAGE ].Len() )
1503 					//||
1504 				 	// 	(*pEntry)[ ByteString("en") ].Len()))
1505 				{
1506 					if ( bEnableExport )
1507 					{
1508 						ByteString sText((*pEntry)[ SOURCE_LANGUAGE ] );
1509 
1510                         // Strip PairList Line String
1511 						if( rTyp.EqualsIgnoreCaseAscii("pairedlist") ){
1512                             sLID = GetPairedListID( sText );
1513 							if ((*pEntry)[ sCur ].Len())
1514 								sText = (*pEntry)[ sCur ];
1515 							sText = GetPairedListString( sText );
1516                         }
1517 						else{
1518 							//if ((*pEntry)[ sCur ].Len()){
1519 							//	if( sCur.EqualsIgnoreCaseAscii("de") ){
1520 							//		sText = StripList( (*pEntry)[ sCur ] );
1521 							//	}
1522 							//	else
1523 									sText = StripList( (*pEntry)[ sCur ] );
1524                                     if( sText == "\\\"" )
1525                                         sText = "\"";
1526 							//}
1527 						}
1528 
1529 						ByteString sOutput( sProject ); sOutput += "\t";
1530 						if ( sRoot.Len())
1531 							sOutput += sActFileName;
1532 						sOutput += "\t0\t";
1533 						sOutput += rTyp; sOutput += "\t";
1534 						sOutput += sGID; sOutput += "\t";
1535 						sOutput += sLID; sOutput += "\t\t";
1536 						sOutput += pResData->sPForm; sOutput += "\t0\t";
1537                         sOutput += sCur; sOutput += "\t";
1538 
1539 						sOutput += sText; sOutput += "\t\t\t\t";
1540 						sOutput += sTimeStamp;
1541 
1542                         //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1543                         aOutput.WriteLine( sOutput );
1544 
1545 					}
1546 				}
1547 		}
1548 		if ( bCreateNew )
1549 			delete [] pEntry;
1550 	}
1551 	if ( bCreateNew )
1552 		delete pExportList;
1553 
1554 	return sal_True;
1555 }
1556 
1557 /*****************************************************************************/
FullId()1558 ByteString Export::FullId()
1559 /*****************************************************************************/
1560 {
1561 	ByteString sFull;
1562 	if ( nLevel > 1 ) {
1563 		sFull = aResStack.GetObject( 0 )->sId;
1564 		for ( sal_uInt16 i = 1; i < nLevel - 1; i++ ) {
1565 			ByteString sToAdd = aResStack.GetObject( i )->sId;
1566 			if ( sToAdd.Len()) {
1567 				sFull += ".";
1568 				sFull += sToAdd;
1569 			}
1570 		}
1571 	}
1572     if ( sFull.Len() > 255 ) {
1573 		ByteString sError( "GroupId > 255 chars" );
1574 	    printf("GroupID = %s\n",sFull.GetBuffer());
1575         yyerror( sError.GetBufferAccess());
1576 		sError.ReleaseBufferAccess();
1577 	}
1578 
1579 	return sFull;
1580 }
1581 
1582 /*****************************************************************************/
InsertListEntry(const ByteString & rText,const ByteString & rLine)1583 void Export::InsertListEntry( const ByteString &rText, const ByteString &rLine )
1584 /*****************************************************************************/
1585 {
1586 	ResData *pResData = aResStack.GetObject( nLevel-1 );
1587 
1588 	ExportList *pList = NULL;
1589 	if ( nList == LIST_STRING ) {
1590 		pList = pResData->pStringList;
1591 		if ( !pList ) {
1592 			pResData->pStringList = new ExportList();
1593 			pList = pResData->pStringList;
1594 			nListIndex = 0;
1595 		}
1596 	}
1597 	else if ( nList == LIST_FILTER ) {
1598 		pList = pResData->pFilterList;
1599 		if ( !pList ) {
1600 			pResData->pFilterList = new ExportList();
1601 			pList = pResData->pFilterList;
1602 			nListIndex = 0;
1603 		}
1604 	}
1605 	else if ( nList == LIST_ITEM ) {
1606 		pList = pResData->pItemList;
1607 		if ( !pList ) {
1608 			pResData->pItemList = new ExportList();
1609 			pList = pResData->pItemList;
1610 			nListIndex = 0;
1611 		}
1612 	}
1613 	else if ( nList == LIST_PAIRED ) {
1614 		pList = pResData->pPairedList;
1615 		if ( !pList ) {
1616 			pResData->pPairedList = new ExportList();
1617 			pList = pResData->pPairedList;
1618 			nListIndex = 0;
1619 		}
1620 	}
1621     else if ( nList == LIST_UIENTRIES ) {
1622 		pList = pResData->pUIEntries;
1623 		if ( !pList ) {
1624 			pResData->pUIEntries = new ExportList();
1625 			pList = pResData->pUIEntries;
1626 			nListIndex = 0;
1627 		}
1628 	}
1629 	else
1630 		return;
1631 
1632 	if ( nListIndex + 1 > pList->Count()) {
1633         ExportListEntry *pNew = new ExportListEntry();
1634 		(*pNew)[ LIST_REFID ] = ByteString::CreateFromInt32( REFID_NONE );
1635 		pList->Insert( pNew, LIST_APPEND );
1636 	}
1637 	ExportListEntry *pCurEntry = pList->GetObject( nListIndex );
1638 
1639 	// For paired list use the line to set proper lid
1640 	if( nList == LIST_PAIRED ){
1641 		(*pCurEntry)[ nListLang ] = rLine;
1642 	}else
1643 		(*pCurEntry)[ nListLang ] = rText;
1644 
1645 	// Remember en-US fallback string, so each list has the same amount of elements
1646 	//if ( nListLang.EqualsIgnoreCaseAscii("en-US")  ) {
1647 	if ( Export::isSourceLanguage( nListLang ) ) {
1648 		if( nList == LIST_PAIRED ){
1649 			const ByteString sPlist("pairedlist");
1650 			ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sId , GetPairedListID( rLine ) , sFilename );
1651 			pResData->addFallbackData( sKey , rText );
1652 		}
1653 		// new fallback
1654 		else{
1655 			const ByteString sPlist("list");
1656 			ByteString a( pResData->sGId );
1657 			a.Append( "." );
1658 			a.Append( pResData->sId );
1659 			sal_Int64 x = nListIndex+1;
1660 			ByteString b( ByteString::CreateFromInt64( x ) );
1661 			ByteString sKey = MergeDataFile::CreateKey( sPlist , a , b  , sFilename );
1662 			pResData->addFallbackData( sKey , rText );
1663 		}
1664 		// new fallback
1665 	}
1666 
1667 	//if ( nListLang.EqualsIgnoreCaseAscii("en-US")  ) {
1668 	if ( Export::isSourceLanguage( nListLang ) ) {
1669 		if( nList == LIST_PAIRED ){
1670 			(*pCurEntry)[ SOURCE_LANGUAGE ] = rLine;
1671 		}
1672 		else
1673 			(*pCurEntry)[ SOURCE_LANGUAGE ] = rLine;
1674 
1675         pList->NewSourceLanguageListEntry();
1676 	}
1677 
1678 	//printf("Export::InsertListEntry ResData.id = %s ResData.ListData = %s\n",pResData->sId.GetBuffer() ,(*pCurEntry)[ nListLang ].GetBuffer());
1679 	nListIndex++;
1680 }
1681 
1682 /*****************************************************************************/
CleanValue(ByteString & rValue)1683 void Export::CleanValue( ByteString &rValue )
1684 /*****************************************************************************/
1685 {
1686 	while ( rValue.Len()) {
1687 		if (( rValue.GetChar( 0 ) == ' ' ) || ( rValue.GetChar( 0 ) == '\t' ))
1688 			rValue = rValue.Copy( 1 );
1689 		else
1690 			break;
1691 	}
1692 
1693 	if ( rValue.Len()) {
1694 		for ( sal_uInt16 i = rValue.Len() - 1; i > 0; i-- ) {
1695 			if (( rValue.GetChar( i ) == ' ' ) || ( rValue.GetChar( i ) == '\t' ) ||
1696 				( rValue.GetChar( i ) == '\n' ) || ( rValue.GetChar( i ) == ';' ) ||
1697 				( rValue.GetChar( i ) == '{' ) || ( rValue.GetChar( i ) == '\\' ) ||
1698 				( rValue.GetChar( i ) == '\r' ))
1699 				rValue.Erase( i );
1700 			else
1701 				break;
1702 		}
1703 	}
1704 }
1705 
1706 
1707 /*****************************************************************************/
GetText(const ByteString & rSource,int nToken)1708 ByteString Export::GetText( const ByteString &rSource, int nToken )
1709 /*****************************************************************************/
1710 #define TXT_STATE_NON  	0x000
1711 #define TXT_STATE_TEXT	0x001
1712 #define TXT_STATE_MACRO	0x002
1713 {
1714 	ByteString sReturn;
1715 	switch ( nToken ) {
1716 		case TEXTLINE:
1717 		case LONGTEXTLINE: {
1718 			ByteString sTmp( rSource.Copy( rSource.Search( "=" )));
1719 			CleanValue( sTmp );
1720 			sTmp.EraseAllChars( '\n' );
1721 			sTmp.EraseAllChars( '\r' );
1722 
1723 			while ( sTmp.SearchAndReplace( "\\\\\"", "-=<[BSlashBSlashHKom]>=-\"" )
1724 				!= STRING_NOTFOUND ) {};
1725 			while ( sTmp.SearchAndReplace( "\\\"", "-=<[Hochkomma]>=-" )
1726 				!= STRING_NOTFOUND ) {};
1727 			while ( sTmp.SearchAndReplace( "\\", "-=<[0x7F]>=-" )
1728 				!= STRING_NOTFOUND ) {};
1729 			while ( sTmp.SearchAndReplace( "\\0x7F", "-=<[0x7F]>=-" )
1730 				!= STRING_NOTFOUND ) {};
1731 
1732 			sal_uInt16 nStart = 0;
1733 			sal_uInt16 nState = TXT_STATE_MACRO;
1734 
1735 		    nState = TXT_STATE_TEXT;
1736 			nStart = 1;
1737 
1738 
1739 			for ( sal_uInt16 i = nStart; i < sTmp.GetTokenCount( '\"' ); i++ ) {
1740 				ByteString sToken = sTmp.GetToken( i, '\"' );
1741 				if ( sToken.Len()) {
1742 					if ( nState == TXT_STATE_TEXT ) {
1743 						sReturn += sToken;
1744 						nState = TXT_STATE_MACRO;
1745 					}
1746 					else {
1747 						while( sToken.SearchAndReplace( "\t", " " ) !=
1748 							STRING_NOTFOUND ) {};
1749 						while( sToken.SearchAndReplace( "  ", " " ) !=
1750 							STRING_NOTFOUND ) {};
1751 						sToken.EraseLeadingChars( ' ' );
1752 						sToken.EraseTrailingChars( ' ' );
1753 						if ( sToken.Len()) {
1754 							sReturn += "\\\" ";
1755 							sReturn += sToken;
1756 							sReturn += " \\\"";
1757 						}
1758 						nState = TXT_STATE_TEXT;
1759 					}
1760 				}
1761 			}
1762 
1763 			while ( sReturn.SearchAndReplace( "-=<[0x7F]>=-", "" )
1764 				!= STRING_NOTFOUND ) {};
1765 			while ( sReturn.SearchAndReplace( "-=<[Hochkomma]>=-", "\"" )
1766 				!= STRING_NOTFOUND ) {};
1767 			while ( sReturn.SearchAndReplace( "-=<[BSlashBSlashHKom]>=-", "\\\\" )
1768 				!= STRING_NOTFOUND ) {};
1769 
1770 
1771 			while ( sReturn.SearchAndReplace( "\\\\", "-=<[BSlashBSlash]>=-" )
1772 				!= STRING_NOTFOUND ) {};
1773 			while ( sReturn.SearchAndReplace( "-=<[BSlashBSlash]>=-", "\\" )
1774 				!= STRING_NOTFOUND ) {};
1775 
1776 		}
1777 		break;
1778 	}
1779 	return sReturn;
1780 }
1781 
1782 /*****************************************************************************/
WriteToMerged(const ByteString & rText,bool bSDFContent)1783 void Export::WriteToMerged( const ByteString &rText , bool bSDFContent )
1784 /*****************************************************************************/
1785 {
1786 	static ByteString SLASH  ('\\');
1787     static ByteString RETURN ('\n');
1788 	//printf("%s\n",rText.GetBuffer() );
1789 
1790     #if 0
1791     // statement has no effect
1792     if( pParseQueue->bMflag && !bSDFContent ) pParseQueue->bMflag;
1793     #endif
1794 
1795     if ( !bDontWriteOutput || !bUnmerge ) {
1796 		ByteString sText( rText );
1797 		while ( sText.SearchAndReplace( " \n", "\n" ) != STRING_NOTFOUND ) {};
1798         if( pParseQueue->bNextIsM && bSDFContent && sText.Len() > 2 ){
1799             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1800                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1801                     sText.Insert('\\' , n++ );
1802 
1803                 }
1804             }
1805         }
1806         else if( pParseQueue->bLastWasM && sText.Len() > 2 ){
1807             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1808                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1809                     sText.Insert('\\' , n++ );
1810                 }
1811                 if( sText.GetChar( n ) == '\n' )pParseQueue->bMflag=true;
1812             }
1813         }
1814         else if( pParseQueue->bCurrentIsM && bSDFContent && sText.Len() > 2 ){
1815             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1816                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1817                     sText.Insert('\\' , n++ );
1818                     pParseQueue->bMflag=true;
1819                 }
1820             }
1821         }
1822         else if( pParseQueue->bMflag ){
1823             for( sal_uInt16 n = 1 ; n < sText.Len() ; n++ ){
1824                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1825                     sText.Insert('\\' , n++ );
1826                 }
1827             }
1828         }
1829         for ( sal_uInt16 i = 0; i < sText.Len(); i++ ) {
1830 			if ( sText.GetChar( i ) != '\n' ){
1831 				aOutput.Write( ByteString( sText.GetChar( i )).GetBuffer(), 1 );
1832 
1833 			}
1834             else{
1835                 aOutput.WriteLine( ByteString());
1836             }
1837 
1838 		}
1839     }
1840 }
1841 
1842 /*****************************************************************************/
ConvertMergeContent(ByteString & rText)1843 void Export::ConvertMergeContent( ByteString &rText )
1844 /*****************************************************************************/
1845 {
1846 	sal_Bool bNoOpen = ( rText.Search( "\\\"" ) != 0 );
1847 	ByteString sClose( rText.Copy( rText.Len() - 2 ));
1848 	sal_Bool bNoClose = ( sClose != "\\\"" );
1849 	ByteString sNew;
1850 	for ( sal_uInt16 i = 0; i < rText.Len(); i++ ) {
1851 		ByteString sChar( rText.GetChar( i ));
1852 		if ( sChar == "\\" ) {
1853 			if (( i + 1 ) < rText.Len()) {
1854 				ByteString sNext( rText.GetChar( i + 1 ));
1855 				if ( sNext == "\"" ) {
1856 					sChar = "\"";
1857 					i++;
1858 				}
1859 				else if ( sNext == "n" ) {
1860 					sChar = "\\n";
1861 					i++;
1862 				}
1863 				else if ( sNext == "t" ) {
1864 					sChar = "\\t";
1865 					i++;
1866 				}
1867 				else if ( sNext == "\'" ) {
1868 					sChar = "\\\'";
1869 					i++;
1870 				}
1871 				else
1872 					sChar = "\\\\";
1873 			}
1874 			else {
1875 				sChar = "\\\\";
1876 			}
1877 		}
1878 		else if ( sChar == "\"" ) {
1879 			sChar = "\\\"";
1880 		}
1881 		else if ( sChar == "" ) {
1882 			sChar = "\\0x7F";
1883 		}
1884 		sNew += sChar;
1885 	}
1886 
1887 	rText = sNew;
1888 
1889 	if ( bNoOpen ) {
1890 		ByteString sTmp( rText );
1891 		rText = "\"";
1892 		rText += sTmp;
1893 	}
1894 	if ( bNoClose )
1895 		rText += "\"";
1896 }
1897 
1898 /*****************************************************************************/
PrepareTextToMerge(ByteString & rText,sal_uInt16 nTyp,ByteString & nLangIndex,ResData * pResData)1899 sal_Bool Export::PrepareTextToMerge( ByteString &rText, sal_uInt16 nTyp,
1900                                 ByteString &nLangIndex, ResData *pResData )
1901 /*****************************************************************************/
1902 {
1903 	// position to merge in:
1904 	sal_uInt16 nStart = 0;
1905 	sal_uInt16 nEnd = 0;
1906 	ByteString sOldId = pResData->sId;
1907 	ByteString sOldGId = pResData->sGId;
1908 	ByteString sOldTyp = pResData->sResTyp;
1909 
1910 	ByteString sOrigText( rText );
1911 
1912 	switch ( nTyp ) {
1913 		case LIST_STRING :
1914 		case LIST_UIENTRIES :
1915 		case LIST_FILTER :
1916 		case LIST_PAIRED:
1917 		case LIST_ITEM :
1918 		{
1919 			if ( bUnmerge )
1920 				return sal_True;
1921 
1922 			ExportList *pList = NULL;
1923 			switch ( nTyp ) {
1924 				case LIST_STRING : {
1925 					pResData->sResTyp = "stringlist";
1926 					pList = pResData->pStringList;
1927 				}
1928 				break;
1929 				case LIST_UIENTRIES : {
1930 					pResData->sResTyp = "uientries";
1931 					pList = pResData->pUIEntries;
1932 				}
1933 				break;
1934 				case LIST_FILTER : {
1935 					pResData->sResTyp = "filterlist";
1936 					pList = pResData->pFilterList;
1937 				}
1938 				break;
1939 				case LIST_ITEM : {
1940 					pResData->sResTyp = "itemlist";
1941 					pList = pResData->pItemList;
1942 				}
1943 				break;
1944 				case LIST_PAIRED : {
1945 					pResData->sResTyp = "pairedlist";
1946 					pList = pResData->pPairedList;
1947 				}
1948 				break;
1949 
1950 			}
1951 			if ( pList ) {
1952 				ExportListEntry *pCurEntry = pList->GetObject( nListIndex - 1 );
1953 				if ( pCurEntry ) {
1954 					//printf("%s\n",Export::DumpMap( "pCurEntry", *pCurEntry ).GetBuffer() );
1955 					//ByteString a("pCurEntry");
1956 					//Export::DumpMap( a , *pCurEntry );
1957 					rText = (*pCurEntry)[ SOURCE_LANGUAGE ];
1958 					if( nTyp == LIST_PAIRED ){
1959 						pResData->addMergedLanguage( nLangIndex );
1960 					}
1961                 }
1962 			}
1963 
1964 			nStart = rText.Search( "\"" );
1965 			if ( nStart == STRING_NOTFOUND ) {
1966 				rText = sOrigText;
1967 				return sal_False;
1968 			}
1969 
1970 			sal_Bool bFound = sal_False;
1971 			for ( nEnd = nStart + 1; nEnd < rText.Len() && !bFound; nEnd++ ) {
1972 				if ( rText.GetChar( nEnd ) == '\"' )
1973 					bFound = sal_True;
1974 			}
1975 			if ( !bFound ) {
1976 				rText = sOrigText;
1977 				return sal_False;
1978 			}
1979 
1980 			nEnd --;
1981 			sLastListLine = rText;
1982 			if (( sLastListLine.Search( ">" ) != STRING_NOTFOUND ) &&
1983 				( sLastListLine.Search( "<" ) == STRING_NOTFOUND ))
1984 			{
1985 				ByteString sTmp = sLastListLine;
1986 				sLastListLine = "<";
1987 				sLastListLine += sTmp;
1988 			}
1989 			if ( pResData->sResTyp.EqualsIgnoreCaseAscii( "pairedlist" ) ){
1990                pResData->sId = GetPairedListID( sLastListLine );
1991             }
1992             else pResData->sId = ByteString::CreateFromInt32( nListIndex );
1993 
1994 			if ( pResData->sGId.Len())
1995 				pResData->sGId += ".";
1996 			pResData->sGId += sOldId;
1997 			nTyp = STRING_TYP_TEXT;
1998 		}
1999 		break;
2000 		case STRING_TYP_TEXT :
2001 		case STRING_TYP_HELPTEXT :
2002 		case STRING_TYP_QUICKHELPTEXT :
2003 		case STRING_TYP_TITLE :
2004 		{
2005 			/*if ( bUnmerge ) {
2006 				if (( nLangIndex != ByteString("de") ) &&
2007                     ( nLangIndex != ByteString("en-US") ))
2008 				{
2009 					bDontWriteOutput = sal_True;
2010 				}
2011 				return sal_True;
2012 			}*/
2013 
2014 			nStart = rText.Search( "=" );
2015 			if ( nStart == STRING_NOTFOUND ) {
2016 				rText = sOrigText;
2017 				return sal_False;
2018 			}
2019 
2020 			nStart++;
2021 			sal_Bool bFound = sal_False;
2022 			while(( nStart < rText.Len()) && !bFound ) {
2023 				if (( rText.GetChar( nStart ) != ' ' ) && ( rText.GetChar( nStart ) != '\t' ))
2024 					bFound = sal_True;
2025 				else
2026 					nStart ++;
2027 			}
2028 
2029 			// no start position found
2030 			if ( !bFound ) {
2031 				rText = sOrigText;
2032 				return sal_False;
2033 			}
2034 
2035 			// position to end mergeing in
2036 			nEnd = rText.Len() - 1;
2037 			bFound = sal_False;
2038 
2039 			while (( nEnd > nStart ) && !bFound ) {
2040 				if (( rText.GetChar( nEnd ) != ' ' ) && ( rText.GetChar( nEnd ) != '\t' ) &&
2041 					( rText.GetChar( nEnd ) != '\n' ) && ( rText.GetChar( nEnd ) != ';' ) &&
2042 					( rText.GetChar( nEnd ) != '{' ) && ( rText.GetChar( nEnd ) != '\\' ))
2043 				{
2044 					bFound = sal_True;
2045 				}
2046 				else
2047 					nEnd --;
2048 			}
2049 		}
2050 		break;
2051 	}
2052 
2053 	// search for merge data
2054     if ( !pMergeDataFile ){
2055         pMergeDataFile = new MergeDataFile( sMergeSrc, sFile , bErrorLog, aCharSet);//, bUTF8 );
2056 
2057         // Init Languages
2058         ByteString sTmp = Export::sLanguages;
2059         if( sTmp.ToUpperAscii().Equals("ALL") )
2060             SetLanguages( pMergeDataFile->GetLanguages() );
2061         else if( !isInitialized )InitLanguages();
2062 
2063     }
2064 //	printf("*************DUMPING****************\n");
2065 //	printf("%s\n",pMergeDataFile->Dump().GetBuffer());
2066 //	printf("*************DUMPING****************\n");
2067 
2068 //	printf("Dumping ResData\n");
2069 //	pResData->Dump();
2070 	PFormEntrys *pEntrys = pMergeDataFile->GetPFormEntrys( pResData );
2071 	//printf("Dumping pEntrys\n");
2072 	//if( pEntrys ) pEntrys->Dump();
2073 	pResData->sId = sOldId;
2074 	pResData->sGId = sOldGId;
2075 	pResData->sResTyp = sOldTyp;
2076 
2077 	if ( !pEntrys ) {
2078 		rText = sOrigText;
2079 		return sal_False; // no data found
2080 	}
2081 
2082 	ByteString sContent;
2083 	pEntrys->GetTransex3Text( sContent, nTyp, nLangIndex );
2084 	//if ( !sContent.Len() && ( ! nLangIndex.EqualsIgnoreCaseAscii("en-US") )) {
2085 	if ( !sContent.Len() && ( ! Export::isSourceLanguage( nLangIndex ) )) {
2086 		rText = sOrigText;
2087 		return sal_False; // no data found
2088 	}
2089 
2090 	//if ( nLangIndex.EqualsIgnoreCaseAscii("en-US") ) {
2091 	if ( Export::isSourceLanguage( nLangIndex ) ) {
2092 		return sal_False;
2093 	}
2094 
2095 	ByteString sPostFix( rText.Copy( ++nEnd ));
2096 	rText.Erase( nStart );
2097 
2098 	//ConvertMergeContent( sContent, nTyp );
2099     ConvertMergeContent( sContent );
2100 
2101 
2102 
2103 	//printf("Merged %s\n",nLangIndex.GetBuffer());
2104 	// merge new res. in text line
2105 	rText += sContent;
2106 	rText += sPostFix;
2107 
2108 	return sal_True;
2109 }
2110 
2111 /*****************************************************************************/
MergeRest(ResData * pResData,sal_uInt16 nMode)2112 void Export::MergeRest( ResData *pResData, sal_uInt16 nMode )
2113 /*****************************************************************************/
2114 {
2115 	//if ( bUnmerge ) { return;}
2116 
2117 	//pResData->Dump();
2118 
2119     if ( !pMergeDataFile ){
2120 		pMergeDataFile = new MergeDataFile( sMergeSrc, sFile ,bErrorLog, aCharSet);//, bUTF8 );
2121 
2122         // Init Languages
2123         ByteString sTmp = Export::sLanguages;
2124         if( sTmp.ToUpperAscii().Equals("ALL") )
2125             SetLanguages( pMergeDataFile->GetLanguages() );
2126         else if( !isInitialized )InitLanguages();
2127 
2128     }
2129 	switch ( nMode ) {
2130 		case MERGE_MODE_NORMAL : {
2131 			PFormEntrys *pEntry = pMergeDataFile->GetPFormEntrys( pResData );
2132 
2133             bool bWriteNoSlash = false;
2134 			if ( pEntry && pResData->bText ) {
2135 
2136 				sal_Bool bAddSemikolon = sal_False;
2137 				sal_Bool bFirst = sal_True;
2138                 ByteString sCur;
2139                 ByteString sTmp = Export::sLanguages;
2140 
2141                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2142                     sCur = aLanguages[ n ];
2143 
2144                     ByteString sText;
2145                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_TEXT, sCur , sal_True );
2146 					if ( bText && sText.Len() && sText != "-" ) {
2147 						ByteString sOutput;
2148 						if ( bNextMustBeDefineEOL)  {
2149 							if ( bFirst )
2150 								sOutput += "\t\\\n";
2151 							else
2152 								sOutput += ";\t\\\n";
2153 						}
2154 						bFirst=sal_False;
2155 						sOutput += "\t";
2156 						sOutput += pResData->sTextTyp;
2157                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US")) {
2158 						if ( ! Export::isSourceLanguage( sCur ) ) {
2159 							sOutput += "[ ";
2160 							sOutput += sCur;
2161 							sOutput += " ] ";
2162 						}
2163 						sOutput += "= ";
2164                         ConvertMergeContent( sText );
2165 						sOutput += sText;
2166 
2167                         if ( bDefine && bWriteNoSlash )
2168 						    sOutput += ";\n";
2169 
2170                         if ( bDefine )
2171 							sOutput += ";\\\n";
2172 						else if ( !bNextMustBeDefineEOL )
2173 							sOutput += ";\n";
2174 						else
2175 							bAddSemikolon = sal_True;
2176 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2177 							sOutput += "\t";
2178 						WriteToMerged( sOutput , true );
2179 					}
2180                 }
2181 
2182 
2183 				if ( bAddSemikolon ) {
2184 					ByteString sOutput( ";" );
2185 					WriteToMerged( sOutput , false );
2186 				}
2187 			}
2188 
2189 			if ( pEntry && pResData->bQuickHelpText ) {
2190 				sal_Bool bAddSemikolon = sal_False;
2191 				sal_Bool bFirst = sal_True;
2192                 ByteString sCur;
2193 
2194                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2195                     sCur = aLanguages[ n ];
2196 
2197 					ByteString sText;
2198                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_QUICKHELPTEXT, sCur, sal_True );
2199 					if ( bText && sText.Len() && sText != "-" ) {
2200 						ByteString sOutput;
2201 						if ( bNextMustBeDefineEOL)  {
2202 							if ( bFirst )
2203 								sOutput += "\t\\\n";
2204 							else
2205 								sOutput += ";\t\\\n";
2206 						}
2207 						bFirst=sal_False;
2208 						sOutput += "\t";
2209 						sOutput += "QuickHelpText";
2210                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2211 						if ( ! Export::isSourceLanguage( sCur ) ) {
2212 							sOutput += "[ ";
2213 							sOutput += sCur;
2214 							sOutput += " ] ";
2215 						}
2216 						sOutput += "= ";
2217                         ConvertMergeContent( sText );
2218 						sOutput += sText;
2219 						if ( bDefine )
2220 							sOutput += ";\\\n";
2221 						else if ( !bNextMustBeDefineEOL )
2222 							sOutput += ";\n";
2223 						else
2224 							bAddSemikolon = sal_True;
2225 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2226 							sOutput += "\t";
2227 						WriteToMerged( sOutput ,true );
2228 					}
2229 				}
2230 				if ( bAddSemikolon ) {
2231 					ByteString sOutput( ";" );
2232 					WriteToMerged( sOutput , false );
2233 				}
2234 			}
2235 
2236 			if ( pEntry && pResData->bTitle ) {
2237 				sal_Bool bAddSemikolon = sal_False;
2238 				sal_Bool bFirst = sal_True;
2239                 ByteString sCur;
2240 
2241                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2242                     sCur = aLanguages[ n ];
2243 
2244                 ByteString sText;
2245                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_TITLE, sCur, sal_True );
2246 					if ( bText && sText.Len() && sText != "-" ) {
2247 						ByteString sOutput;
2248 						if ( bNextMustBeDefineEOL)  {
2249 							if ( bFirst )
2250 								sOutput += "\t\\\n";
2251 							else
2252 								sOutput += ";\t\\\n";
2253 						}
2254 						bFirst=sal_False;
2255 						sOutput += "\t";
2256 						sOutput += "Title";
2257                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2258 						if ( ! Export::isSourceLanguage( sCur ) ) {
2259 							sOutput += "[ ";
2260 							sOutput += sCur;
2261 							sOutput += " ] ";
2262 						}
2263 						sOutput += "= ";
2264                         ConvertMergeContent( sText );
2265 						sOutput += sText;
2266 						if ( bDefine )
2267 							sOutput += ";\\\n";
2268 						else if ( !bNextMustBeDefineEOL )
2269 							sOutput += ";\n";
2270 						else
2271 							bAddSemikolon = sal_True;
2272 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2273 							sOutput += "\t";
2274 						WriteToMerged( sOutput ,true );
2275 					}
2276 				}
2277 				if ( bAddSemikolon ) {
2278 					ByteString sOutput( ";" );
2279 					WriteToMerged( sOutput ,false);
2280 				}
2281 			}
2282 			// Merge Lists
2283 
2284 			if ( pResData->bList ) {
2285 				//printf("Dumping ResData\n");
2286 				//pResData->Dump();
2287 
2288 				bool bPairedList = false;
2289 				ByteString sOldId = pResData->sId;
2290 				ByteString sOldGId = pResData->sGId;
2291 				ByteString sOldTyp = pResData->sResTyp;
2292 				if ( pResData->sGId.Len())
2293 					pResData->sGId += ".";
2294 				pResData->sGId += sOldId;
2295 				ByteString sSpace;
2296 				for ( sal_uInt16 i = 1; i < nLevel-1; i++ )
2297 					sSpace += "\t";
2298 				for ( sal_uInt16 nT = LIST_STRING; nT <= LIST_UIENTRIES; nT++ ) {
2299 					ExportList *pList = NULL;
2300 					switch ( nT ) {
2301                         case LIST_STRING : pResData->sResTyp = "stringlist"; pList = pResData->pStringList; bPairedList = false; break;
2302 						case LIST_FILTER : pResData->sResTyp = "filterlist"; pList = pResData->pFilterList; bPairedList = false; break;
2303 						case LIST_UIENTRIES : pResData->sResTyp = "uientries"; pList = pResData->pUIEntries;bPairedList = false; break;
2304 						case LIST_ITEM : pResData->sResTyp = "itemlist"; pList = pResData->pItemList;       bPairedList = false; break;
2305                         case LIST_PAIRED : pResData->sResTyp = "pairedlist"; pList = pResData->pPairedList; bPairedList = true;  break;
2306 					}
2307                     ByteString sCur;
2308                     for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2309                         sCur = aLanguages[ n ];
2310 						sal_uInt16 nIdx = 1;
2311 
2312 						// Set matching pairedlist identifier
2313 						if( bPairedList && pResData->pPairedList && ( nIdx == 1 ) ){
2314 							ExportListEntry* pListE = ( ExportListEntry* ) pResData->pPairedList->GetObject( nIdx-1 );
2315 							pResData->sId = GetPairedListID ( (*pListE)[ SOURCE_LANGUAGE ] );
2316 						}
2317 						else
2318 							pResData->sId = ByteString("1");
2319 
2320 						PFormEntrys *pEntrys;
2321 						sal_uLong nLIndex = 0;
2322 						sal_uLong nMaxIndex = 0;
2323 						if ( pList )
2324 							nMaxIndex = pList->GetSourceLanguageListEntryCount();
2325 						pEntrys = pMergeDataFile->GetPFormEntrys( pResData );
2326                         while( pEntrys  && ( nLIndex < nMaxIndex )) {
2327 						    //printf("Lang %s, List Index %d\n",sCur.GetBuffer(),(int)nLIndex);
2328 							ByteString sText;
2329                             sal_Bool bText;
2330 							bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True );
2331 							if( !bText )
2332 								bText = pEntrys->GetTransex3Text( sText , STRING_TYP_TEXT, SOURCE_LANGUAGE , sal_False );
2333 
2334 							// Use fallback, if data is missing in sdf file
2335 							//if( !bText && pResData->sResTyp.Equals( "pairedlist" ) ){
2336 							if( !bText && bPairedList ){
2337 								if( pResData->isMerged( sCur ) ) break;
2338 								const ByteString sPlist("pairedlist");
2339 								ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sGId , pResData->sId , sFilename );
2340 								bText = pResData->getFallbackData( sKey , sText );
2341 							}else if ( !bText ){// new fallback
2342 								if( pResData->isMerged( sCur ) ) break;
2343 								const ByteString sPlist("list");
2344 								ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sGId , pResData->sId , sFilename );
2345 								bText = pResData->getFallbackData( sKey , sText );
2346 							} // new fallback
2347 
2348 							if ( bText && sText.Len()) {
2349 								//if( pEntrys ) pEntrys->Dump();
2350 								if ( nIdx == 1 ) {
2351 									ByteString sHead;
2352 									if ( bNextMustBeDefineEOL )
2353 										sHead = "\\\n\t";
2354 									sHead += sSpace;
2355 									switch ( nT ) {
2356 										case LIST_STRING : sHead += "StringList "; break;
2357 										case LIST_FILTER : sHead += "FilterList "; break;
2358 										case LIST_ITEM : sHead += "ItemList "; break;
2359 										case LIST_PAIRED : sHead += "PairedList "; break;
2360 										case LIST_UIENTRIES : sHead += "UIEntries "; break;
2361 									}
2362   									sHead += "[ ";
2363                                     sHead += sCur;
2364 									sHead += " ] ";
2365 									//}
2366 									if ( bDefine || bNextMustBeDefineEOL ) {
2367 										sHead += "= \\\n";
2368 										sHead += sSpace;
2369 										sHead += "\t{\\\n\t";
2370 									}
2371 									else {
2372 										sHead += "= \n";
2373 										sHead += sSpace;
2374 										sHead += "\t{\n\t";
2375 									}
2376 									WriteToMerged( sHead , true);
2377 								}
2378 								ByteString sLine;
2379 								if ( pList && pList->GetObject( nLIndex ))
2380 									sLine = ( *pList->GetObject( nLIndex ))[ SOURCE_LANGUAGE ];
2381 								if ( !sLine.Len())
2382 									sLine = sLastListLine;
2383 
2384 								if ( sLastListLine.Search( "<" ) != STRING_NOTFOUND ) {
2385 									if (( nT != LIST_UIENTRIES ) &&
2386 										(( sLine.Search( "{" ) == STRING_NOTFOUND ) ||
2387 										( sLine.Search( "{" ) >= sLine.Search( "\"" ))) &&
2388 										(( sLine.Search( "<" ) == STRING_NOTFOUND ) ||
2389 										( sLine.Search( "<" ) >= sLine.Search( "\"" ))))
2390 									{
2391 										sLine.SearchAndReplace( "\"", "< \"" );
2392 									}
2393 								}
2394 
2395 								sal_uInt16 nStart, nEnd;
2396 								nStart = sLine.Search( "\"" );
2397 
2398 								ByteString sPostFix;
2399 								if( !bPairedList ){
2400 									nEnd = sLine.SearchBackward( '\"' );
2401 									sPostFix = ByteString( sLine.Copy( ++nEnd ));
2402 									sLine.Erase( nStart );
2403 								}
2404 
2405 
2406                             	ConvertMergeContent( sText );
2407 
2408 								// merge new res. in text line
2409 								if( bPairedList ){
2410 									sLine = MergePairedList( sLine , sText );
2411 								}
2412 								else{
2413 									sLine += sText;
2414 									sLine += sPostFix;
2415 								}
2416 
2417 								ByteString sText1( "\t" );
2418 								sText1 += sLine;
2419 								if ( bDefine || bNextMustBeDefineEOL )
2420 									sText1 += " ;\\\n";
2421 								else
2422 									sText1 += " ;\n";
2423 								sText1 += sSpace;
2424 								sText1 += "\t";
2425 								//printf("Writing '%s'\n",sText1.GetBuffer());
2426 								WriteToMerged( sText1 ,true );
2427 
2428 								// Set matching pairedlist identifier
2429 								if ( bPairedList ){
2430 									nIdx++;
2431 									ExportListEntry* pListE = ( ExportListEntry* ) pResData->pPairedList->GetObject( ( nIdx ) -1 );
2432 									if( pListE ){
2433 										pResData->sId = GetPairedListID ( (*pListE)[ SOURCE_LANGUAGE ] );
2434 									}
2435                                 }
2436                                 else
2437                                     pResData->sId = ByteString::CreateFromInt32( ++nIdx );
2438                             }
2439 							else
2440 								break;
2441 							nLIndex ++;
2442 							PFormEntrys *oldEntry = pEntrys;
2443 							pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); // <--- game over
2444 							if( !pEntrys )
2445 								pEntrys = oldEntry;
2446 						}
2447 						if ( nIdx > 1 ) {
2448 							ByteString sFooter( sSpace.Copy( 1 ));
2449 							if ( bNextMustBeDefineEOL )
2450 								sFooter += "};";
2451 							else if ( !bDefine )
2452 								sFooter += "};\n\t";
2453 							else
2454 								sFooter += "\n\n";
2455 							WriteToMerged( sFooter ,true );
2456 						}
2457 					}
2458 				}
2459 
2460 				pResData->sId = sOldId;
2461 				pResData->sGId = sOldGId;
2462 				pResData->sResTyp = sOldTyp;
2463 			}
2464 		}
2465 		break;
2466 		case MERGE_MODE_LIST : {
2467 			ExportList *pList = NULL;
2468 			switch ( nList ) {
2469 			    // PairedList
2470                 case LIST_STRING : pList = pResData->pStringList; break;
2471 				case LIST_FILTER : pList = pResData->pFilterList; break;
2472 				case LIST_UIENTRIES : pList = pResData->pUIEntries; break;
2473 				case LIST_ITEM : pList = pResData->pItemList; break;
2474 				case LIST_PAIRED : pList = pResData->pPairedList; break;
2475 
2476 			}
2477 
2478 			nListIndex++;
2479 			sal_uLong nMaxIndex = 0;
2480 			if ( pList )
2481 				nMaxIndex = pList->GetSourceLanguageListEntryCount();
2482 			ByteString sLine;
2483 			if ( pList && pList->GetObject( nListIndex ))
2484 				sLine = ( *pList->GetObject( nListIndex ))[ SOURCE_LANGUAGE ];
2485 			if ( !sLine.Len())
2486 				sLine = sLastListLine;
2487 
2488 			if ( sLastListLine.Search( "<" ) != STRING_NOTFOUND ) {
2489 				if (( nList != LIST_UIENTRIES ) &&
2490 					(( sLine.Search( "{" ) == STRING_NOTFOUND ) ||
2491 					( sLine.Search( "{" ) >= sLine.Search( "\"" ))) &&
2492 					(( sLine.Search( "<" ) == STRING_NOTFOUND ) ||
2493 					( sLine.Search( "<" ) >= sLine.Search( "\"" ))))
2494 				{
2495 					sLine.SearchAndReplace( "\"", "< \"" );
2496 				}
2497 			}
2498 
2499 			while( PrepareTextToMerge( sLine, nList, nListLang, pResData ) && ( nListIndex <= nMaxIndex )) {
2500 				ByteString sText( "\t" );
2501 				sText += sLine;
2502 				sText += " ;";
2503 				sText += "\n";
2504 				for ( sal_uInt16 i = 0; i < nLevel; i++ )
2505 					sText += "\t";
2506 				WriteToMerged( sText ,false );
2507 				nListIndex++;
2508 				if ( pList && pList->GetObject( nListIndex ))
2509 					sLine = ( *pList->GetObject( nListIndex ))[ SOURCE_LANGUAGE ];
2510 				if ( !sLine.Len())
2511 					sLine = sLastListLine;
2512 				sLine += " ;";
2513 			}
2514 		}
2515 		break;
2516 	}
2517     pParseQueue->bMflag = false;
2518 }
2519 
MergePairedList(ByteString & sLine,ByteString & sText)2520 ByteString Export::MergePairedList( ByteString& sLine , ByteString& sText ){
2521 // < "xy" ; IDENTIFIER ; >
2522 	ByteString sPre  = sLine.Copy( 0 , sLine.Search('\"') );
2523 	ByteString sPost = sLine.Copy( sLine.SearchBackward('\"') + 1 , sLine.Len() );
2524 	sPre.Append( sText );
2525 	sPre.Append( sPost );
2526 	return sPre;
2527 }
2528 
2529 /*****************************************************************************/
SetChildWithText()2530 void Export::SetChildWithText()
2531 /*****************************************************************************/
2532 {
2533 	if ( aResStack.Count() > 1 ) {
2534 		for ( sal_uLong i = 0; i < aResStack.Count() - 1; i++ ) {
2535 			aResStack.GetObject( i )->bChildWithText = sal_True;
2536 		}
2537 	}
2538 }
2539 
Push(const QueueEntry & aEntry)2540 void ParserQueue::Push( const QueueEntry& aEntry ){
2541 //    printf("nTyp = %d ",aEntry.nTyp);
2542     sal_uInt16 nLen = aEntry.sLine.Len();
2543 
2544     if( !bStart ){
2545         aQueueCur->push( aEntry );
2546         if( nLen > 1 && aEntry.sLine.GetChar( nLen-1 ) == '\n' )
2547             bStart = true;
2548         else if ( aEntry.nTyp != IGNOREDTOKENS ){
2549             if( nLen > 1 && ( aEntry.sLine.GetChar( nLen-1 ) == '\\') ){
2550                 // Next is Macro
2551                 bCurrentIsM = true;
2552              }else{
2553                 // Next is no Macro
2554                 bCurrentIsM = false;
2555              }
2556         }
2557     }
2558     else{
2559         aQueueNext->push( aEntry );
2560         if( nLen > 1 && aEntry.sLine.GetChar( nLen-1 ) != '\n' ){
2561             if( nLen > 1 && ( aEntry.sLine.GetChar( nLen-1  ) == '\\') ){
2562                 // Next is Macro
2563                 bNextIsM = true;
2564             }
2565             else{
2566                 // Next is no Macro
2567                 bNextIsM = false;
2568             }
2569         }else if( nLen > 2 && aEntry.sLine.GetChar( nLen-1 ) == '\n' ){
2570             if( aEntry.nTyp != IGNOREDTOKENS ){
2571                 if( nLen > 2 && ( aEntry.sLine.GetChar( nLen-2  ) == '\\') ){
2572                     // Next is Macro
2573                     bNextIsM = true;
2574                 }
2575                 else{
2576                     // Next is no Macro
2577                     bNextIsM = false;
2578                 }
2579             }
2580             // Pop current
2581             Pop( *aQueueCur );
2582             bLastWasM = bCurrentIsM;
2583             // next -> current
2584             bCurrentIsM = bNextIsM;
2585             aQref = aQueueCur;
2586             aQueueCur = aQueueNext;
2587             aQueueNext = aQref;
2588 
2589         }
2590 
2591         else{
2592             // Pop current
2593             Pop( *aQueueCur );
2594             bLastWasM = bCurrentIsM;
2595             // next -> current
2596             bCurrentIsM = bNextIsM;
2597             aQref = aQueueCur;
2598             aQueueCur = aQueueNext;
2599             aQueueNext = aQref;
2600         }
2601     }
2602 }
2603 
Close()2604 void ParserQueue::Close(){
2605     // Pop current
2606     Pop( *aQueueCur );
2607     // next -> current
2608     bLastWasM = bCurrentIsM;
2609     bCurrentIsM = bNextIsM;
2610     aQref = aQueueCur;
2611     aQueueCur = aQueueNext;
2612     aQueueNext = aQref;
2613     bNextIsM = false;
2614     Pop( *aQueueNext );
2615 };
Pop(std::queue<QueueEntry> & aQueue)2616 void ParserQueue::Pop( std::queue<QueueEntry>& aQueue ){
2617     while( !aQueue.empty() ){
2618         QueueEntry aEntry = aQueue.front();
2619         aQueue.pop();
2620         aExport.Execute( aEntry.nTyp , (char*) aEntry.sLine.GetBuffer() );
2621     }
2622 }
ParserQueue(Export & aExportObj)2623 ParserQueue::ParserQueue( Export& aExportObj )
2624         :
2625           bCurrentIsM( false ),
2626           bNextIsM( false ) ,
2627           bLastWasM( false ),
2628           bMflag( false ) ,
2629           aExport( aExportObj ) ,
2630           bStart( false ) ,
2631           bStartNext( false )
2632 {
2633           aQueueNext = new std::queue<QueueEntry>;
2634           aQueueCur  = new std::queue<QueueEntry>;
2635 }
2636 
2637 
~ParserQueue()2638 ParserQueue::~ParserQueue(){
2639     if( aQueueNext )    delete aQueueNext;
2640     if( aQueueCur )     delete aQueueCur;
2641 }
2642