xref: /trunk/main/l10ntools/source/export.cxx (revision 98f76e59)
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, beginning 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 parsing 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 		// these tokens are not mandatory for parsing, so ignore them...
556 		if ( bMergeMode )
557 			WriteToMerged( sOrig , false ); // ...or write 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 assignment
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 APPFONTMAPPING: {
1084 			bDontWriteOutput = sal_False;
1085 			// this is a AppfontMapping, so look if it's a definition
1086 			// of field size
1087 			ByteString sKey = sToken.GetToken( 0, '=' );
1088 			sKey.EraseAllChars( ' ' );
1089 			sKey.EraseAllChars( '\t' );
1090 			ByteString sMapping = sToken.GetToken( 1, '=' );
1091 			sMapping = sMapping.GetToken( 1, '(' );
1092 			sMapping = sMapping.GetToken( 0, ')' );
1093 			sMapping.EraseAllChars( ' ' );
1094 			sMapping.EraseAllChars( '\t' );
1095 			if ( sKey.ToUpperAscii() == "SIZE" ) {
1096 				pResData->nWidth = ( sal_uInt16 ) sMapping.GetToken( 0, ',' ).ToInt64();
1097 			}
1098 			else if ( sKey == "POSSIZE" ) {
1099 				pResData->nWidth = ( sal_uInt16 ) sMapping.GetToken( 2, ',' ).ToInt64();
1100 			}
1101 		}
1102 		break;
1103 		case RSCDEFINELEND:
1104 			bDontWriteOutput = sal_False;
1105 		break;
1106 		case CONDITION: {
1107 			bDontWriteOutput = sal_False;
1108 			while( sToken.SearchAndReplace( "\r", " " ) != STRING_NOTFOUND ) {};
1109 			while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1110 			while( sToken.SearchAndReplace( "  ", " " ) != STRING_NOTFOUND ) {};
1111 			ByteString sCondition = sToken.GetToken( 0, ' ' );
1112 			if ( sCondition == "#ifndef" ) {
1113 				sActPForm = "!defined ";
1114 				sActPForm += sToken.GetToken( 1, ' ' );
1115 			}
1116 			else if ( sCondition == "#ifdef" ) {
1117 				sActPForm = "defined ";
1118 				sActPForm += sToken.GetToken( 1, ' ' );
1119 			}
1120 			else if ( sCondition == "#if" ) {
1121 				sActPForm = sToken.Copy( 4 );
1122 				while ( sActPForm.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND ) {};
1123 			}
1124 			else if ( sCondition == "#elif" ) {
1125 				sActPForm = sToken.Copy( 6 );
1126 				while ( sActPForm.SearchAndReplace( "||", "\\or" ) != STRING_NOTFOUND ) {};
1127 			}
1128 			else if ( sCondition == "#else" ) {
1129 				sActPForm = sCondition;
1130 			}
1131 			else if ( sCondition == "#endif" ) {
1132 				sActPForm = "";
1133 			}
1134 			else break;
1135 			if ( nLevel ) {
1136 				WriteData( pResData, sal_True );
1137 				pResData->sPForm = sActPForm;
1138 			}
1139 		}
1140 		break;
1141 		case EMPTYLINE : {
1142 			bDontWriteOutput = sal_False;
1143 			if ( bDefine ) {
1144 				bNextMustBeDefineEOL = sal_False;
1145                 bDefine = sal_False;
1146 				while ( nLevel )
1147 					Parse( LEVELDOWN, "" );
1148                     //WorkOnTokenSet( LEVELDOWN, pTkn );
1149 			}
1150 		}
1151 		break;
1152 		case PRAGMA : {
1153 			bDontWriteOutput = sal_False;
1154 			while( sToken.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1155 			while( sToken.SearchAndReplace( "  ", " " ) != STRING_NOTFOUND ) {};
1156 			sToken.EraseLeadingChars( ' ' );
1157 			sToken.EraseTrailingChars( ' ' );
1158 
1159 			ByteString sCharset = sToken.GetToken( 1, ' ' );
1160 			ByteString sSet = sToken.GetToken( 2, ' ' );
1161 			if (( sCharset.ToUpperAscii() == "CHARSET_IBMPC" ) ||
1162 				( sCharset == "RTL_TEXTENCODING_IBM_850" ) ||
1163 				(( sCharset == "CHARSET" ) && ( sSet.ToUpperAscii() == "IBMPC" )))
1164 			{
1165 				aCharSet = RTL_TEXTENCODING_IBM_850;
1166 			}
1167 			else if (( sCharset == "CHARSET_ANSI" ) ||
1168 				( sCharset == "RTL_TEXTENCODING_MS_1252" ) ||
1169 				(( sCharset == "CHARSET" ) && ( sSet.ToUpperAscii() == "ANSI" )))
1170 			{
1171 				aCharSet = RTL_TEXTENCODING_MS_1252;
1172 			}
1173 		}
1174 		break;
1175 		case TEXTREFID : {
1176 			bDontWriteOutput = sal_True;
1177  			/*ByteString sK = sToken.GetToken( 0, '=' );
1178             ByteString sKey = sK.EraseAllChars( '\t' ).EraseAllChars( ' ' );
1179 			ByteString sT = sToken.GetToken( 1, '=' ).GetToken( 0, ';' );
1180             sal_uInt16 nRefId = ( sal_uInt16 ) sT.EraseAllChars( '\t' ).EraseAllChars( ' ' ).ToInt32();
1181 			if (( sKey.ToUpperAscii() == "TEXT" ) ||
1182 				( sKey == "MESSAGE" ) ||
1183 				( sKey == "CUSTOMUNITTEXT" ) ||
1184 				( sKey == "SLOTNAME" ) ||
1185 				( sKey == "UINAME" ))
1186 					pResData->nTextRefId = nRefId;
1187 			else if ( sKey == "HELPTEXT" )
1188 				pResData->nHelpTextRefId = nRefId;
1189 			else if ( sKey == "QUICKHELPTEXT" )
1190 				pResData->nQuickHelpTextRefId = nRefId;
1191 			else if ( sKey == "TITLE" )
1192 				pResData->nTitleRefId = nRefId;*/
1193 		}
1194 		}
1195 	if ( bWriteToMerged ) {
1196 		// the current token must be written to dest. without merging
1197 
1198         if( bDefine && sOrig.Len() > 2 ){
1199             for( sal_uInt16 n = 0 ; n < sOrig.Len() ; n++ ){
1200                 if( sOrig.GetChar( n ) == '\n' && sOrig.GetChar( n-1 ) != '\\'){
1201                     sOrig.Insert('\\' , n++ );
1202                 }
1203             }
1204         }
1205         WriteToMerged( sOrig , false);
1206 	}
1207 
1208 	if ( bExecuteDown ) {
1209 		Parse( LEVELDOWN, "" );
1210         //WorkOnTokenSet( LEVELDOWN, pTkn );
1211 	}
1212 
1213 	return 1;
1214 }
1215 
1216 /*****************************************************************************/
CutComment(ByteString & rText)1217 void Export::CutComment( ByteString &rText )
1218 /*****************************************************************************/
1219 {
1220 	if ( rText.Search( "//" ) != STRING_NOTFOUND ) {
1221 		ByteString sWork( rText );
1222 		sWork.SearchAndReplaceAll( "\\\"", "XX" );
1223 		sal_uInt16 i = 0;
1224 		sal_Bool bInner = sal_False;
1225 
1226 		while ( i < sWork.Len() - 1 ) {
1227 			if ( sWork.GetChar( i ) == '\"' )
1228 				bInner = !bInner;
1229 			else if
1230 				(( sWork.GetChar( i ) == '/' ) &&
1231 				( !bInner ) &&
1232 				( sWork.GetChar( i + 1 ) == '/' ))
1233 			{
1234 				rText.Erase( i );
1235 				return;
1236 			}
1237 			i++;
1238 		}
1239 	}
1240 }
1241 
UnmergeUTF8(ByteString & sOrig)1242 void Export::UnmergeUTF8( ByteString& sOrig ){
1243 	sal_uInt16 nPos1 = sOrig.Search('\"');
1244 	sal_uInt16 nPos2 = sOrig.SearchBackward('\"');
1245 	if( nPos1 > 0 && nPos2 > 0 && nPos1 < nPos2){
1246 		ByteString sPart = sOrig.Copy(nPos1+1 , nPos2-1);
1247 		ByteString sPartUTF8 = sPart;
1248 		sPartUTF8.Convert( RTL_TEXTENCODING_MS_1252 , RTL_TEXTENCODING_UTF8 );
1249 		sOrig.SearchAndReplace( sPart , sPartUTF8 );
1250 	}
1251 }
1252 
1253 /*****************************************************************************/
ListExists(ResData * pResData,sal_uInt16 nLst)1254 sal_Bool Export::ListExists( ResData *pResData, sal_uInt16 nLst )
1255 /*****************************************************************************/
1256 {
1257 	switch ( nLst ) {
1258 		case LIST_STRING: return pResData->pStringList != NULL;
1259 		case LIST_FILTER: return pResData->pFilterList != NULL;
1260 		case LIST_ITEM: return pResData->pItemList != NULL;
1261 		case LIST_PAIRED: return pResData->pPairedList != NULL;
1262 		case LIST_UIENTRIES: return pResData->pUIEntries != NULL;
1263 	}
1264 	return sal_False;
1265 }
1266 
1267 /*****************************************************************************/
WriteData(ResData * pResData,sal_Bool bCreateNew)1268 sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
1269 /*****************************************************************************/
1270 {
1271 	if ( bMergeMode ) {
1272 		MergeRest( pResData );
1273 		return sal_True;
1274 	}
1275 
1276 	if ( bUnmerge )
1277 		return sal_True;
1278 
1279 /*    ByteStringHashMap::iterator pos3 = pResData->sText.begin();
1280     ByteStringHashMap::iterator end3 = pResData->sText.end();
1281     for(;pos3!=end3;++pos3){
1282 
1283         printf("[%s]=%s\n", pos3->first.GetBuffer(), pos3->second.GetBuffer() );
1284     }*/
1285    	// mandatory to export: en-US
1286 
1287      if (( //pResData->sText[ ByteString("de") ].Len() &&
1288         ( pResData->sText[ SOURCE_LANGUAGE ].Len()))
1289         ||
1290         ( //pResData->sHelpText[ ByteString("de") ].Len() &&
1291         (  pResData->sHelpText[ SOURCE_LANGUAGE ].Len()))
1292         ||
1293         ( //pResData->sQuickHelpText[ ByteString("de") ].Len() &&
1294         (  pResData->sQuickHelpText[ SOURCE_LANGUAGE ].Len()))
1295          ||
1296         ( //pResData->sTitle[ ByteString("de") ].Len() &&
1297         (  pResData->sTitle[ SOURCE_LANGUAGE ].Len())))
1298 
1299 	{
1300 		FillInFallbacks( pResData );
1301 
1302 		ByteString sGID = pResData->sGId;
1303 		ByteString sLID;
1304 		if ( !sGID.Len())
1305 			sGID = pResData->sId;
1306 		else
1307 			sLID = pResData->sId;
1308 
1309 		ByteString sXText;
1310 		ByteString sXHText;
1311 		ByteString sXQHText;
1312 		ByteString sXTitle;
1313 
1314 		ByteString sTimeStamp( Export::GetTimeStamp());
1315         ByteString sCur;
1316 
1317         for( unsigned int n = 0; n < aLanguages.size(); n++ ){
1318             sCur = aLanguages[ n ];
1319                 if ( !sCur.EqualsIgnoreCaseAscii("x-comment") ){
1320                     if ( pResData->sText[ sCur ].Len())
1321                         sXText = pResData->sText[ sCur ];
1322 					else {
1323 						sXText = pResData->sText[ SOURCE_LANGUAGE ];
1324 						/*if ( !sXText.Len())
1325 							sXText = pResData->sText[ ByteString("en") ];
1326 						if ( !sXText.Len())
1327 							sXText = pResData->sText[ ByteString("de") ];*/
1328 					}
1329 
1330                     if ( pResData->sHelpText[ sCur ].Len())
1331                         sXHText = pResData->sHelpText[ sCur ];
1332 					else {
1333 						sXHText = pResData->sHelpText[ SOURCE_LANGUAGE ];
1334 						/*if ( !sXHText.Len())
1335 							sXHText = pResData->sHelpText[ ByteString("en") ];
1336 						if ( !sXText.Len())
1337 							sXHText = pResData->sHelpText[ ByteString("de") ];*/
1338 					}
1339 
1340                     if ( pResData->sQuickHelpText[ sCur ].Len())
1341                         sXQHText = pResData->sQuickHelpText[ sCur ];
1342 					else {
1343 						sXQHText = pResData->sQuickHelpText[ SOURCE_LANGUAGE ];
1344 						/*if ( !sXQHText.Len())
1345 							sXQHText = pResData->sQuickHelpText[ ByteString("en") ];
1346 						if ( !sXQHText.Len())
1347 							sXQHText = pResData->sQuickHelpText[ ByteString("de") ];*/
1348 					}
1349 
1350                     if ( pResData->sTitle[ sCur ].Len())
1351                         sXTitle = pResData->sTitle[ sCur ];
1352 					else {
1353 						sXTitle = pResData->sTitle[ SOURCE_LANGUAGE ];
1354 						/*if ( !sXTitle.Len())
1355 							sXTitle = pResData->sTitle[ ByteString("en") ];
1356 						if ( !sXTitle.Len())
1357 							sXTitle = pResData->sTitle[ ByteString("de") ];*/
1358 					}
1359 
1360 					if ( !sXText.Len())
1361 						sXText = "-";
1362 
1363 					if ( !sXHText.Len()) {
1364 						/*if ( pResData->sHelpText[ ByteString("de") ].Len())
1365 							sXHText = pResData->sHelpText[ ByteString("de") ];*/
1366 						if ( pResData->sHelpText[ SOURCE_LANGUAGE ].Len())
1367 							sXHText = pResData->sHelpText[ SOURCE_LANGUAGE ];
1368 						/*else if ( pResData->sHelpText[ ByteString("en") ].Len())
1369 							sXHText = pResData->sHelpText[ ByteString("en") ];*/
1370 					}
1371 				}
1372 				else
1373                     sXText = pResData->sText[ sCur ];
1374 
1375 				if ( bEnableExport ) {
1376 					ByteString sOutput( sProject ); sOutput += "\t";
1377 					if ( sRoot.Len())
1378 						sOutput += sActFileName;
1379 					sOutput += "\t0\t";
1380 					sOutput += pResData->sResTyp; sOutput += "\t";
1381 					sOutput += sGID; sOutput += "\t";
1382 					sOutput += sLID; sOutput += "\t";
1383 					sOutput += pResData->sHelpId; sOutput	+= "\t";
1384 					sOutput += pResData->sPForm; sOutput	+= "\t";
1385 					sOutput += ByteString::CreateFromInt64( pResData->nWidth ); sOutput += "\t";
1386                     sOutput += sCur; sOutput += "\t";
1387 
1388 
1389 					sOutput += sXText; sOutput	+= "\t";
1390 					sOutput += sXHText; sOutput += "\t";
1391 					sOutput += sXQHText; sOutput+= "\t";
1392 					sOutput += sXTitle; sOutput += "\t";
1393 					sOutput += sTimeStamp;
1394 
1395                  // if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1396 				    aOutput.WriteLine( sOutput );
1397 				}
1398 
1399 				if ( bCreateNew ) {
1400                     pResData->sText[ sCur ]			= "";
1401 					pResData->sHelpText[ sCur ]		= "";
1402 					pResData->sQuickHelpText[ sCur ]= "";
1403 					pResData->sTitle[ sCur ]		= "";
1404 				}
1405 			}
1406 	}
1407 	FillInFallbacks( pResData );
1408 	if ( pResData->pStringList ) {
1409 		ByteString sList( "stringlist" );
1410 		WriteExportList( pResData, pResData->pStringList, sList, bCreateNew );
1411 		if ( bCreateNew )
1412 			pResData->pStringList = 0;
1413 	}
1414 	if ( pResData->pFilterList ) {
1415 		ByteString sList( "filterlist" );
1416 		WriteExportList( pResData, pResData->pFilterList, sList, bCreateNew );
1417 		if ( bCreateNew )
1418 			pResData->pFilterList = 0;
1419 	}
1420 	if ( pResData->pItemList ) {
1421 		ByteString sList( "itemlist" );
1422 		WriteExportList( pResData, pResData->pItemList, sList, bCreateNew );
1423 		if ( bCreateNew )
1424 			pResData->pItemList = 0;
1425 	}
1426 	if ( pResData->pPairedList ) {
1427 		ByteString sList( "pairedlist" );
1428 		WriteExportList( pResData, pResData->pPairedList, sList, bCreateNew );
1429 		if ( bCreateNew )
1430 			pResData->pItemList = 0;
1431 	}
1432 	if ( pResData->pUIEntries ) {
1433 		ByteString sList( "uientries" );
1434 		WriteExportList( pResData, pResData->pUIEntries, sList, bCreateNew );
1435 		if ( bCreateNew )
1436 			pResData->pUIEntries = 0;
1437 	}
1438 	return sal_True;
1439 }
GetPairedListID(const ByteString & sText)1440 ByteString Export::GetPairedListID( const ByteString& sText ){
1441 // < "STRING" ; IDENTIFIER ; > ;
1442 	ByteString sIdent = sText.GetToken( 1, ';' );
1443 	sIdent.ToUpperAscii();
1444 	while( sIdent.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1445 	sIdent.EraseTrailingChars( ' ' );
1446 	sIdent.EraseLeadingChars( ' ' );
1447 	return sIdent;
1448 }
GetPairedListString(const ByteString & sText)1449 ByteString Export::GetPairedListString( const ByteString& sText ){
1450 // < "STRING" ; IDENTIFIER ; > ;
1451 	ByteString sString = sText.GetToken( 0, ';' );
1452 	while( sString.SearchAndReplace( "\t", " " ) != STRING_NOTFOUND ) {};
1453 	sString.EraseTrailingChars( ' ' );
1454 	ByteString s1 = sString.Copy( sString.Search( '\"' )+1 );
1455 	sString = s1.Copy( 0 , s1.SearchBackward( '\"' ) );
1456 	sString.EraseTrailingChars( ' ' );
1457 	sString.EraseLeadingChars( ' ' );
1458 	return sString;
1459 }
StripList(const ByteString & sText)1460 ByteString Export::StripList( const ByteString& sText ){
1461 	ByteString s1 = sText.Copy( sText.Search( '\"' ) + 1 );
1462 	return s1.Copy( 0 , s1.SearchBackward( '\"' ) );
1463 }
1464 
1465 /*****************************************************************************/
WriteExportList(ResData * pResData,ExportList * pExportList,const ByteString & rTyp,sal_Bool bCreateNew)1466 sal_Bool Export::WriteExportList( ResData *pResData, ExportList *pExportList,
1467 						const ByteString &rTyp, sal_Bool bCreateNew )
1468 /*****************************************************************************/
1469 {
1470 	ByteString sGID = pResData->sGId;
1471 	if ( !sGID.Len())
1472 		sGID = pResData->sId;
1473 	else {
1474 		sGID += ".";
1475 		sGID += pResData->sId;
1476 		sGID.EraseTrailingChars( '.' );
1477 	}
1478 
1479 	ByteString sTimeStamp( Export::GetTimeStamp());
1480 	ByteString sCur;
1481 	for ( sal_uLong i = 0; pExportList != NULL && i < pExportList->Count(); i++ ) {
1482 		ExportListEntry *pEntry = pExportList->GetObject( i );
1483 				// mandatory for export: german and eng. and/or enus
1484 		//ByteString a("Export::WriteExportList::pEntry");
1485 		//Export::DumpMap( a, *pEntry );
1486 
1487 		ByteString sLID( ByteString::CreateFromInt64( i + 1 ));
1488         for( unsigned int n = 0; n < aLanguages.size(); n++ ){
1489             sCur = aLanguages[ n ];
1490             if ( //1 )
1491 				  //(*pEntry)[ ByteString("de") ].Len() &&
1492 				 	(*pEntry)[ SOURCE_LANGUAGE ].Len() )
1493 					//||
1494 				 	// 	(*pEntry)[ ByteString("en") ].Len()))
1495 				{
1496 					if ( bEnableExport )
1497 					{
1498 						ByteString sText((*pEntry)[ SOURCE_LANGUAGE ] );
1499 
1500                         // Strip PairList Line String
1501 						if( rTyp.EqualsIgnoreCaseAscii("pairedlist") ){
1502                             sLID = GetPairedListID( sText );
1503 							if ((*pEntry)[ sCur ].Len())
1504 								sText = (*pEntry)[ sCur ];
1505 							sText = GetPairedListString( sText );
1506                         }
1507 						else{
1508 							//if ((*pEntry)[ sCur ].Len()){
1509 							//	if( sCur.EqualsIgnoreCaseAscii("de") ){
1510 							//		sText = StripList( (*pEntry)[ sCur ] );
1511 							//	}
1512 							//	else
1513 									sText = StripList( (*pEntry)[ sCur ] );
1514                                     if( sText == "\\\"" )
1515                                         sText = "\"";
1516 							//}
1517 						}
1518 
1519 						ByteString sOutput( sProject ); sOutput += "\t";
1520 						if ( sRoot.Len())
1521 							sOutput += sActFileName;
1522 						sOutput += "\t0\t";
1523 						sOutput += rTyp; sOutput += "\t";
1524 						sOutput += sGID; sOutput += "\t";
1525 						sOutput += sLID; sOutput += "\t\t";
1526 						sOutput += pResData->sPForm; sOutput += "\t0\t";
1527                         sOutput += sCur; sOutput += "\t";
1528 
1529 						sOutput += sText; sOutput += "\t\t\t\t";
1530 						sOutput += sTimeStamp;
1531 
1532                         //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sProject ) ) )
1533                         aOutput.WriteLine( sOutput );
1534 
1535 					}
1536 				}
1537 		}
1538 		if ( bCreateNew )
1539 			delete [] pEntry;
1540 	}
1541 	if ( bCreateNew )
1542 		delete pExportList;
1543 
1544 	return sal_True;
1545 }
1546 
1547 /*****************************************************************************/
FullId()1548 ByteString Export::FullId()
1549 /*****************************************************************************/
1550 {
1551 	ByteString sFull;
1552 	if ( nLevel > 1 ) {
1553 		sFull = aResStack.GetObject( 0 )->sId;
1554 		for ( sal_uInt16 i = 1; i < nLevel - 1; i++ ) {
1555 			ByteString sToAdd = aResStack.GetObject( i )->sId;
1556 			if ( sToAdd.Len()) {
1557 				sFull += ".";
1558 				sFull += sToAdd;
1559 			}
1560 		}
1561 	}
1562     if ( sFull.Len() > 255 ) {
1563 		ByteString sError( "GroupId > 255 chars" );
1564 	    printf("GroupID = %s\n",sFull.GetBuffer());
1565         yyerror( sError.GetBufferAccess());
1566 		sError.ReleaseBufferAccess();
1567 	}
1568 
1569 	return sFull;
1570 }
1571 
1572 /*****************************************************************************/
InsertListEntry(const ByteString & rText,const ByteString & rLine)1573 void Export::InsertListEntry( const ByteString &rText, const ByteString &rLine )
1574 /*****************************************************************************/
1575 {
1576 	ResData *pResData = aResStack.GetObject( nLevel-1 );
1577 
1578 	ExportList *pList = NULL;
1579 	if ( nList == LIST_STRING ) {
1580 		pList = pResData->pStringList;
1581 		if ( !pList ) {
1582 			pResData->pStringList = new ExportList();
1583 			pList = pResData->pStringList;
1584 			nListIndex = 0;
1585 		}
1586 	}
1587 	else if ( nList == LIST_FILTER ) {
1588 		pList = pResData->pFilterList;
1589 		if ( !pList ) {
1590 			pResData->pFilterList = new ExportList();
1591 			pList = pResData->pFilterList;
1592 			nListIndex = 0;
1593 		}
1594 	}
1595 	else if ( nList == LIST_ITEM ) {
1596 		pList = pResData->pItemList;
1597 		if ( !pList ) {
1598 			pResData->pItemList = new ExportList();
1599 			pList = pResData->pItemList;
1600 			nListIndex = 0;
1601 		}
1602 	}
1603 	else if ( nList == LIST_PAIRED ) {
1604 		pList = pResData->pPairedList;
1605 		if ( !pList ) {
1606 			pResData->pPairedList = new ExportList();
1607 			pList = pResData->pPairedList;
1608 			nListIndex = 0;
1609 		}
1610 	}
1611 	else if ( nList == LIST_UIENTRIES ) {
1612 		pList = pResData->pUIEntries;
1613 		if ( !pList ) {
1614 			pResData->pUIEntries = new ExportList();
1615 			pList = pResData->pUIEntries;
1616 			nListIndex = 0;
1617 		}
1618 	}
1619 	else
1620 		return;
1621 
1622 	if ( nListIndex + 1 > pList->Count()) {
1623 		ExportListEntry *pNew = new ExportListEntry();
1624 		(*pNew)[ LIST_REFID ] = ByteString::CreateFromInt32( REFID_NONE );
1625 		pList->Insert( pNew, LIST_APPEND );
1626 	}
1627 	ExportListEntry *pCurEntry = pList->GetObject( nListIndex );
1628 
1629 	// For paired list use the line to set proper lid
1630 	if( nList == LIST_PAIRED ){
1631 		(*pCurEntry)[ nListLang ] = rLine;
1632 	}else
1633 		(*pCurEntry)[ nListLang ] = rText;
1634 
1635 	// Remember en-US fallback string, so each list has the same amount of elements
1636 	//if ( nListLang.EqualsIgnoreCaseAscii("en-US") ) {
1637 	if ( Export::isSourceLanguage( nListLang ) ) {
1638 		if( nList == LIST_PAIRED ){
1639 			const ByteString sPlist("pairedlist");
1640 			ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sId , GetPairedListID( rLine ) , sFilename );
1641 			pResData->addFallbackData( sKey , rText );
1642 		}
1643 		// new fallback
1644 		else{
1645 			const ByteString sPlist("list");
1646 			ByteString a( pResData->sGId );
1647 			a.Append( "." );
1648 			a.Append( pResData->sId );
1649 			sal_Int64 x = nListIndex+1;
1650 			ByteString b( ByteString::CreateFromInt64( x ) );
1651 			ByteString sKey = MergeDataFile::CreateKey( sPlist , a , b , sFilename );
1652 			pResData->addFallbackData( sKey , rText );
1653 		}
1654 		// new fallback
1655 	}
1656 
1657 	//if ( nListLang.EqualsIgnoreCaseAscii("en-US") ) {
1658 	if ( Export::isSourceLanguage( nListLang ) ) {
1659 		if( nList == LIST_PAIRED ){
1660 			(*pCurEntry)[ SOURCE_LANGUAGE ] = rLine;
1661 		}
1662 		else
1663 			(*pCurEntry)[ SOURCE_LANGUAGE ] = rLine;
1664 
1665 		pList->NewSourceLanguageListEntry();
1666 	}
1667 
1668 	//printf("Export::InsertListEntry ResData.id = %s ResData.ListData = %s\n",pResData->sId.GetBuffer() ,(*pCurEntry)[ nListLang ].GetBuffer());
1669 	nListIndex++;
1670 }
1671 
1672 /*****************************************************************************/
CleanValue(ByteString & rValue)1673 void Export::CleanValue( ByteString &rValue )
1674 /*****************************************************************************/
1675 {
1676 	while ( rValue.Len()) {
1677 		if (( rValue.GetChar( 0 ) == ' ' ) || ( rValue.GetChar( 0 ) == '\t' ))
1678 			rValue = rValue.Copy( 1 );
1679 		else
1680 			break;
1681 	}
1682 
1683 	if ( rValue.Len()) {
1684 		for ( sal_uInt16 i = rValue.Len() - 1; i > 0; i-- ) {
1685 			if (( rValue.GetChar( i ) == ' ' ) || ( rValue.GetChar( i ) == '\t' ) ||
1686 				( rValue.GetChar( i ) == '\n' ) || ( rValue.GetChar( i ) == ';' ) ||
1687 				( rValue.GetChar( i ) == '{' ) || ( rValue.GetChar( i ) == '\\' ) ||
1688 				( rValue.GetChar( i ) == '\r' ))
1689 				rValue.Erase( i );
1690 			else
1691 				break;
1692 		}
1693 	}
1694 }
1695 
1696 
1697 /*****************************************************************************/
GetText(const ByteString & rSource,int nToken)1698 ByteString Export::GetText( const ByteString &rSource, int nToken )
1699 /*****************************************************************************/
1700 #define TXT_STATE_NON  	0x000
1701 #define TXT_STATE_TEXT	0x001
1702 #define TXT_STATE_MACRO	0x002
1703 {
1704 	ByteString sReturn;
1705 	switch ( nToken ) {
1706 		case TEXTLINE:
1707 		case LONGTEXTLINE: {
1708 			ByteString sTmp( rSource.Copy( rSource.Search( "=" )));
1709 			CleanValue( sTmp );
1710 			sTmp.EraseAllChars( '\n' );
1711 			sTmp.EraseAllChars( '\r' );
1712 
1713 			while ( sTmp.SearchAndReplace( "\\\\\"", "-=<[BSlashBSlashHKom]>=-\"" )
1714 				!= STRING_NOTFOUND ) {};
1715 			while ( sTmp.SearchAndReplace( "\\\"", "-=<[Hochkomma]>=-" )
1716 				!= STRING_NOTFOUND ) {};
1717 			while ( sTmp.SearchAndReplace( "\\", "-=<[0x7F]>=-" )
1718 				!= STRING_NOTFOUND ) {};
1719 			while ( sTmp.SearchAndReplace( "\\0x7F", "-=<[0x7F]>=-" )
1720 				!= STRING_NOTFOUND ) {};
1721 
1722 			sal_uInt16 nStart = 0;
1723 			sal_uInt16 nState = TXT_STATE_MACRO;
1724 
1725 		    nState = TXT_STATE_TEXT;
1726 			nStart = 1;
1727 
1728 
1729 			for ( sal_uInt16 i = nStart; i < sTmp.GetTokenCount( '\"' ); i++ ) {
1730 				ByteString sToken = sTmp.GetToken( i, '\"' );
1731 				if ( sToken.Len()) {
1732 					if ( nState == TXT_STATE_TEXT ) {
1733 						sReturn += sToken;
1734 						nState = TXT_STATE_MACRO;
1735 					}
1736 					else {
1737 						while( sToken.SearchAndReplace( "\t", " " ) !=
1738 							STRING_NOTFOUND ) {};
1739 						while( sToken.SearchAndReplace( "  ", " " ) !=
1740 							STRING_NOTFOUND ) {};
1741 						sToken.EraseLeadingChars( ' ' );
1742 						sToken.EraseTrailingChars( ' ' );
1743 						if ( sToken.Len()) {
1744 							sReturn += "\\\" ";
1745 							sReturn += sToken;
1746 							sReturn += " \\\"";
1747 						}
1748 						nState = TXT_STATE_TEXT;
1749 					}
1750 				}
1751 			}
1752 
1753 			while ( sReturn.SearchAndReplace( "-=<[0x7F]>=-", "" )
1754 				!= STRING_NOTFOUND ) {};
1755 			while ( sReturn.SearchAndReplace( "-=<[Hochkomma]>=-", "\"" )
1756 				!= STRING_NOTFOUND ) {};
1757 			while ( sReturn.SearchAndReplace( "-=<[BSlashBSlashHKom]>=-", "\\\\" )
1758 				!= STRING_NOTFOUND ) {};
1759 
1760 
1761 			while ( sReturn.SearchAndReplace( "\\\\", "-=<[BSlashBSlash]>=-" )
1762 				!= STRING_NOTFOUND ) {};
1763 			while ( sReturn.SearchAndReplace( "-=<[BSlashBSlash]>=-", "\\" )
1764 				!= STRING_NOTFOUND ) {};
1765 
1766 		}
1767 		break;
1768 	}
1769 	return sReturn;
1770 }
1771 
1772 /*****************************************************************************/
WriteToMerged(const ByteString & rText,bool bSDFContent)1773 void Export::WriteToMerged( const ByteString &rText , bool bSDFContent )
1774 /*****************************************************************************/
1775 {
1776 	static ByteString SLASH  ('\\');
1777     static ByteString RETURN ('\n');
1778 	//printf("%s\n",rText.GetBuffer() );
1779 
1780     #if 0
1781     // statement has no effect
1782     if( pParseQueue->bMflag && !bSDFContent ) pParseQueue->bMflag;
1783     #endif
1784 
1785     if ( !bDontWriteOutput || !bUnmerge ) {
1786 		ByteString sText( rText );
1787 		while ( sText.SearchAndReplace( " \n", "\n" ) != STRING_NOTFOUND ) {};
1788         if( pParseQueue->bNextIsM && bSDFContent && sText.Len() > 2 ){
1789             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1790                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1791                     sText.Insert('\\' , n++ );
1792 
1793                 }
1794             }
1795         }
1796         else if( pParseQueue->bLastWasM && sText.Len() > 2 ){
1797             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1798                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1799                     sText.Insert('\\' , n++ );
1800                 }
1801                 if( sText.GetChar( n ) == '\n' )pParseQueue->bMflag=true;
1802             }
1803         }
1804         else if( pParseQueue->bCurrentIsM && bSDFContent && sText.Len() > 2 ){
1805             for( sal_uInt16 n = 0 ; n < sText.Len() ; n++ ){
1806                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1807                     sText.Insert('\\' , n++ );
1808                     pParseQueue->bMflag=true;
1809                 }
1810             }
1811         }
1812         else if( pParseQueue->bMflag ){
1813             for( sal_uInt16 n = 1 ; n < sText.Len() ; n++ ){
1814                 if( sText.GetChar( n ) == '\n' && sText.GetChar( n-1 ) != '\\'){
1815                     sText.Insert('\\' , n++ );
1816                 }
1817             }
1818         }
1819         for ( sal_uInt16 i = 0; i < sText.Len(); i++ ) {
1820 			if ( sText.GetChar( i ) != '\n' ){
1821 				aOutput.Write( ByteString( sText.GetChar( i )).GetBuffer(), 1 );
1822 
1823 			}
1824             else{
1825                 aOutput.WriteLine( ByteString());
1826             }
1827 
1828 		}
1829 	}
1830 }
1831 
1832 /*****************************************************************************/
ConvertMergeContent(ByteString & rText)1833 void Export::ConvertMergeContent( ByteString &rText )
1834 /*****************************************************************************/
1835 {
1836 	sal_Bool bNoOpen = ( rText.Search( "\\\"" ) != 0 );
1837 	ByteString sClose( rText.Copy( rText.Len() - 2 ));
1838 	sal_Bool bNoClose = ( sClose != "\\\"" );
1839 	ByteString sNew;
1840 	for ( sal_uInt16 i = 0; i < rText.Len(); i++ ) {
1841 		ByteString sChar( rText.GetChar( i ));
1842 		if ( sChar == "\\" ) {
1843 			if (( i + 1 ) < rText.Len()) {
1844 				ByteString sNext( rText.GetChar( i + 1 ));
1845 				if ( sNext == "\"" ) {
1846 					sChar = "\"";
1847 					i++;
1848 				}
1849 				else if ( sNext == "n" ) {
1850 					sChar = "\\n";
1851 					i++;
1852 				}
1853 				else if ( sNext == "t" ) {
1854 					sChar = "\\t";
1855 					i++;
1856 				}
1857 				else if ( sNext == "\'" ) {
1858 					sChar = "\\\'";
1859 					i++;
1860 				}
1861 				else
1862 					sChar = "\\\\";
1863 			}
1864 			else {
1865 				sChar = "\\\\";
1866 			}
1867 		}
1868 		else if ( sChar == "\"" ) {
1869 			sChar = "\\\"";
1870 		}
1871 		else if ( sChar == "" ) {
1872 			sChar = "\\0x7F";
1873 		}
1874 		sNew += sChar;
1875 	}
1876 
1877 	rText = sNew;
1878 
1879 	if ( bNoOpen ) {
1880 		ByteString sTmp( rText );
1881 		rText = "\"";
1882 		rText += sTmp;
1883 	}
1884 	if ( bNoClose )
1885 		rText += "\"";
1886 }
1887 
1888 /*****************************************************************************/
PrepareTextToMerge(ByteString & rText,sal_uInt16 nTyp,ByteString & nLangIndex,ResData * pResData)1889 sal_Bool Export::PrepareTextToMerge( ByteString &rText, sal_uInt16 nTyp,
1890                                 ByteString &nLangIndex, ResData *pResData )
1891 /*****************************************************************************/
1892 {
1893 	// position to merge in:
1894 	sal_uInt16 nStart = 0;
1895 	sal_uInt16 nEnd = 0;
1896 	ByteString sOldId = pResData->sId;
1897 	ByteString sOldGId = pResData->sGId;
1898 	ByteString sOldTyp = pResData->sResTyp;
1899 
1900 	ByteString sOrigText( rText );
1901 
1902 	switch ( nTyp ) {
1903 		case LIST_STRING :
1904 		case LIST_UIENTRIES :
1905 		case LIST_FILTER :
1906 		case LIST_PAIRED:
1907 		case LIST_ITEM :
1908 		{
1909 			if ( bUnmerge )
1910 				return sal_True;
1911 
1912 			ExportList *pList = NULL;
1913 			switch ( nTyp ) {
1914 				case LIST_STRING : {
1915 					pResData->sResTyp = "stringlist";
1916 					pList = pResData->pStringList;
1917 				}
1918 				break;
1919 				case LIST_UIENTRIES : {
1920 					pResData->sResTyp = "uientries";
1921 					pList = pResData->pUIEntries;
1922 				}
1923 				break;
1924 				case LIST_FILTER : {
1925 					pResData->sResTyp = "filterlist";
1926 					pList = pResData->pFilterList;
1927 				}
1928 				break;
1929 				case LIST_ITEM : {
1930 					pResData->sResTyp = "itemlist";
1931 					pList = pResData->pItemList;
1932 				}
1933 				break;
1934 				case LIST_PAIRED : {
1935 					pResData->sResTyp = "pairedlist";
1936 					pList = pResData->pPairedList;
1937 				}
1938 				break;
1939 
1940 			}
1941 			if ( pList ) {
1942 				ExportListEntry *pCurEntry = pList->GetObject( nListIndex - 1 );
1943 				if ( pCurEntry ) {
1944 					//printf("%s\n",Export::DumpMap( "pCurEntry", *pCurEntry ).GetBuffer() );
1945 					//ByteString a("pCurEntry");
1946 					//Export::DumpMap( a , *pCurEntry );
1947 					rText = (*pCurEntry)[ SOURCE_LANGUAGE ];
1948 					if( nTyp == LIST_PAIRED ){
1949 						pResData->addMergedLanguage( nLangIndex );
1950 					}
1951                 }
1952 			}
1953 
1954 			nStart = rText.Search( "\"" );
1955 			if ( nStart == STRING_NOTFOUND ) {
1956 				rText = sOrigText;
1957 				return sal_False;
1958 			}
1959 
1960 			sal_Bool bFound = sal_False;
1961 			for ( nEnd = nStart + 1; nEnd < rText.Len() && !bFound; nEnd++ ) {
1962 				if ( rText.GetChar( nEnd ) == '\"' )
1963 					bFound = sal_True;
1964 			}
1965 			if ( !bFound ) {
1966 				rText = sOrigText;
1967 				return sal_False;
1968 			}
1969 
1970 			nEnd --;
1971 			sLastListLine = rText;
1972 			if (( sLastListLine.Search( ">" ) != STRING_NOTFOUND ) &&
1973 				( sLastListLine.Search( "<" ) == STRING_NOTFOUND ))
1974 			{
1975 				ByteString sTmp = sLastListLine;
1976 				sLastListLine = "<";
1977 				sLastListLine += sTmp;
1978 			}
1979 			if ( pResData->sResTyp.EqualsIgnoreCaseAscii( "pairedlist" ) ){
1980                pResData->sId = GetPairedListID( sLastListLine );
1981             }
1982             else pResData->sId = ByteString::CreateFromInt32( nListIndex );
1983 
1984 			if ( pResData->sGId.Len())
1985 				pResData->sGId += ".";
1986 			pResData->sGId += sOldId;
1987 			nTyp = STRING_TYP_TEXT;
1988 		}
1989 		break;
1990 		case STRING_TYP_TEXT :
1991 		case STRING_TYP_HELPTEXT :
1992 		case STRING_TYP_QUICKHELPTEXT :
1993 		case STRING_TYP_TITLE :
1994 		{
1995 			/*if ( bUnmerge ) {
1996 				if (( nLangIndex != ByteString("de") ) &&
1997                     ( nLangIndex != ByteString("en-US") ))
1998 				{
1999 					bDontWriteOutput = sal_True;
2000 				}
2001 				return sal_True;
2002 			}*/
2003 
2004 			nStart = rText.Search( "=" );
2005 			if ( nStart == STRING_NOTFOUND ) {
2006 				rText = sOrigText;
2007 				return sal_False;
2008 			}
2009 
2010 			nStart++;
2011 			sal_Bool bFound = sal_False;
2012 			while(( nStart < rText.Len()) && !bFound ) {
2013 				if (( rText.GetChar( nStart ) != ' ' ) && ( rText.GetChar( nStart ) != '\t' ))
2014 					bFound = sal_True;
2015 				else
2016 					nStart ++;
2017 			}
2018 
2019 			// no start position found
2020 			if ( !bFound ) {
2021 				rText = sOrigText;
2022 				return sal_False;
2023 			}
2024 
2025 			// position to end merging in
2026 			nEnd = rText.Len() - 1;
2027 			bFound = sal_False;
2028 
2029 			while (( nEnd > nStart ) && !bFound ) {
2030 				if (( rText.GetChar( nEnd ) != ' ' ) && ( rText.GetChar( nEnd ) != '\t' ) &&
2031 					( rText.GetChar( nEnd ) != '\n' ) && ( rText.GetChar( nEnd ) != ';' ) &&
2032 					( rText.GetChar( nEnd ) != '{' ) && ( rText.GetChar( nEnd ) != '\\' ))
2033 				{
2034 					bFound = sal_True;
2035 				}
2036 				else
2037 					nEnd --;
2038 			}
2039 		}
2040 		break;
2041 	}
2042 
2043 	// search for merge data
2044     if ( !pMergeDataFile ){
2045         pMergeDataFile = new MergeDataFile( sMergeSrc, sFile , bErrorLog, aCharSet);//, bUTF8 );
2046 
2047         // Init Languages
2048         ByteString sTmp = Export::sLanguages;
2049         if( sTmp.ToUpperAscii().Equals("ALL") )
2050             SetLanguages( pMergeDataFile->GetLanguages() );
2051         else if( !isInitialized )InitLanguages();
2052 
2053     }
2054 //	printf("*************DUMPING****************\n");
2055 //	printf("%s\n",pMergeDataFile->Dump().GetBuffer());
2056 //	printf("*************DUMPING****************\n");
2057 
2058 //	printf("Dumping ResData\n");
2059 //	pResData->Dump();
2060 	PFormEntrys *pEntrys = pMergeDataFile->GetPFormEntrys( pResData );
2061 	//printf("Dumping pEntrys\n");
2062 	//if( pEntrys ) pEntrys->Dump();
2063 	pResData->sId = sOldId;
2064 	pResData->sGId = sOldGId;
2065 	pResData->sResTyp = sOldTyp;
2066 
2067 	if ( !pEntrys ) {
2068 		rText = sOrigText;
2069 		return sal_False; // no data found
2070 	}
2071 
2072 	ByteString sContent;
2073 	pEntrys->GetTransex3Text( sContent, nTyp, nLangIndex );
2074 	//if ( !sContent.Len() && ( ! nLangIndex.EqualsIgnoreCaseAscii("en-US") )) {
2075 	if ( !sContent.Len() && ( ! Export::isSourceLanguage( nLangIndex ) )) {
2076 		rText = sOrigText;
2077 		return sal_False; // no data found
2078 	}
2079 
2080 	//if ( nLangIndex.EqualsIgnoreCaseAscii("en-US") ) {
2081 	if ( Export::isSourceLanguage( nLangIndex ) ) {
2082 		return sal_False;
2083 	}
2084 
2085 	ByteString sPostFix( rText.Copy( ++nEnd ));
2086 	rText.Erase( nStart );
2087 
2088 	//ConvertMergeContent( sContent, nTyp );
2089 	ConvertMergeContent( sContent );
2090 
2091 
2092 
2093 	//printf("Merged %s\n",nLangIndex.GetBuffer());
2094 	// merge new res. in text line
2095 	rText += sContent;
2096 	rText += sPostFix;
2097 
2098 	return sal_True;
2099 }
2100 
2101 /*****************************************************************************/
MergeRest(ResData * pResData,sal_uInt16 nMode)2102 void Export::MergeRest( ResData *pResData, sal_uInt16 nMode )
2103 /*****************************************************************************/
2104 {
2105 	//if ( bUnmerge ) { return;}
2106 
2107 	//pResData->Dump();
2108 
2109 	if ( !pMergeDataFile ){
2110 		pMergeDataFile = new MergeDataFile( sMergeSrc, sFile ,bErrorLog, aCharSet);//, bUTF8 );
2111 
2112         // Init Languages
2113         ByteString sTmp = Export::sLanguages;
2114         if( sTmp.ToUpperAscii().Equals("ALL") )
2115             SetLanguages( pMergeDataFile->GetLanguages() );
2116         else if( !isInitialized )InitLanguages();
2117 
2118 	}
2119 	switch ( nMode ) {
2120 		case MERGE_MODE_NORMAL : {
2121 			PFormEntrys *pEntry = pMergeDataFile->GetPFormEntrys( pResData );
2122 
2123             bool bWriteNoSlash = false;
2124 			if ( pEntry && pResData->bText ) {
2125 
2126 				sal_Bool bAddSemikolon = sal_False;
2127 				sal_Bool bFirst = sal_True;
2128                 ByteString sCur;
2129                 ByteString sTmp = Export::sLanguages;
2130 
2131                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2132                     sCur = aLanguages[ n ];
2133 
2134                     ByteString sText;
2135                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_TEXT, sCur , sal_True );
2136 					if ( bText && sText.Len() && sText != "-" ) {
2137 						ByteString sOutput;
2138 						if ( bNextMustBeDefineEOL) {
2139 							if ( bFirst )
2140 								sOutput += "\t\\\n";
2141 							else
2142 								sOutput += ";\t\\\n";
2143 						}
2144 						bFirst=sal_False;
2145 						sOutput += "\t";
2146 						sOutput += pResData->sTextTyp;
2147                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US")) {
2148 						if ( ! Export::isSourceLanguage( sCur ) ) {
2149 							sOutput += "[ ";
2150 							sOutput += sCur;
2151 							sOutput += " ] ";
2152 						}
2153 						sOutput += "= ";
2154                         ConvertMergeContent( sText );
2155 						sOutput += sText;
2156 
2157                         if ( bDefine && bWriteNoSlash )
2158 						    sOutput += ";\n";
2159 
2160                         if ( bDefine )
2161 							sOutput += ";\\\n";
2162 						else if ( !bNextMustBeDefineEOL )
2163 							sOutput += ";\n";
2164 						else
2165 							bAddSemikolon = sal_True;
2166 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2167 							sOutput += "\t";
2168 						WriteToMerged( sOutput , true );
2169 					}
2170                 }
2171 
2172 
2173 				if ( bAddSemikolon ) {
2174 					ByteString sOutput( ";" );
2175 					WriteToMerged( sOutput , false );
2176 				}
2177 			}
2178 
2179 			if ( pEntry && pResData->bQuickHelpText ) {
2180 				sal_Bool bAddSemikolon = sal_False;
2181 				sal_Bool bFirst = sal_True;
2182                 ByteString sCur;
2183 
2184                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2185                     sCur = aLanguages[ n ];
2186 
2187 					ByteString sText;
2188                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_QUICKHELPTEXT, sCur, sal_True );
2189 					if ( bText && sText.Len() && sText != "-" ) {
2190 						ByteString sOutput;
2191 						if ( bNextMustBeDefineEOL) {
2192 							if ( bFirst )
2193 								sOutput += "\t\\\n";
2194 							else
2195 								sOutput += ";\t\\\n";
2196 						}
2197 						bFirst=sal_False;
2198 						sOutput += "\t";
2199 						sOutput += "QuickHelpText";
2200                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2201 						if ( ! Export::isSourceLanguage( sCur ) ) {
2202 							sOutput += "[ ";
2203 							sOutput += sCur;
2204 							sOutput += " ] ";
2205 						}
2206 						sOutput += "= ";
2207                         ConvertMergeContent( sText );
2208 						sOutput += sText;
2209 						if ( bDefine )
2210 							sOutput += ";\\\n";
2211 						else if ( !bNextMustBeDefineEOL )
2212 							sOutput += ";\n";
2213 						else
2214 							bAddSemikolon = sal_True;
2215 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2216 							sOutput += "\t";
2217 						WriteToMerged( sOutput ,true );
2218 					}
2219 				}
2220 				if ( bAddSemikolon ) {
2221 					ByteString sOutput( ";" );
2222 					WriteToMerged( sOutput , false );
2223 				}
2224 			}
2225 
2226 			if ( pEntry && pResData->bTitle ) {
2227 				sal_Bool bAddSemikolon = sal_False;
2228 				sal_Bool bFirst = sal_True;
2229                 ByteString sCur;
2230 
2231                 for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2232                     sCur = aLanguages[ n ];
2233 
2234                 ByteString sText;
2235                     sal_Bool bText = pEntry->GetTransex3Text( sText, STRING_TYP_TITLE, sCur, sal_True );
2236 					if ( bText && sText.Len() && sText != "-" ) {
2237 						ByteString sOutput;
2238 						if ( bNextMustBeDefineEOL) {
2239 							if ( bFirst )
2240 								sOutput += "\t\\\n";
2241 							else
2242 								sOutput += ";\t\\\n";
2243 						}
2244 						bFirst=sal_False;
2245 						sOutput += "\t";
2246 						sOutput += "Title";
2247                         //if ( !sCur.EqualsIgnoreCaseAscii("en-US") ) {
2248 						if ( ! Export::isSourceLanguage( sCur ) ) {
2249 							sOutput += "[ ";
2250 							sOutput += sCur;
2251 							sOutput += " ] ";
2252 						}
2253 						sOutput += "= ";
2254                         ConvertMergeContent( sText );
2255 						sOutput += sText;
2256 						if ( bDefine )
2257 							sOutput += ";\\\n";
2258 						else if ( !bNextMustBeDefineEOL )
2259 							sOutput += ";\n";
2260 						else
2261 							bAddSemikolon = sal_True;
2262 						for ( sal_uInt16 j = 1; j < nLevel; j++ )
2263 							sOutput += "\t";
2264 						WriteToMerged( sOutput ,true );
2265 					}
2266 				}
2267 				if ( bAddSemikolon ) {
2268 					ByteString sOutput( ";" );
2269 					WriteToMerged( sOutput ,false);
2270 				}
2271 			}
2272 			// Merge Lists
2273 
2274 			if ( pResData->bList ) {
2275 				//printf("Dumping ResData\n");
2276 				//pResData->Dump();
2277 
2278 				bool bPairedList = false;
2279 				ByteString sOldId = pResData->sId;
2280 				ByteString sOldGId = pResData->sGId;
2281 				ByteString sOldTyp = pResData->sResTyp;
2282 				if ( pResData->sGId.Len())
2283 					pResData->sGId += ".";
2284 				pResData->sGId += sOldId;
2285 				ByteString sSpace;
2286 				for ( sal_uInt16 i = 1; i < nLevel-1; i++ )
2287 					sSpace += "\t";
2288 				for ( sal_uInt16 nT = LIST_STRING; nT <= LIST_UIENTRIES; nT++ ) {
2289 					ExportList *pList = NULL;
2290 					switch ( nT ) {
2291                         case LIST_STRING : pResData->sResTyp = "stringlist"; pList = pResData->pStringList; bPairedList = false; break;
2292 						case LIST_FILTER : pResData->sResTyp = "filterlist"; pList = pResData->pFilterList; bPairedList = false; break;
2293 						case LIST_UIENTRIES : pResData->sResTyp = "uientries"; pList = pResData->pUIEntries;bPairedList = false; break;
2294 						case LIST_ITEM : pResData->sResTyp = "itemlist"; pList = pResData->pItemList;       bPairedList = false; break;
2295                         case LIST_PAIRED : pResData->sResTyp = "pairedlist"; pList = pResData->pPairedList; bPairedList = true;  break;
2296 					}
2297                     ByteString sCur;
2298                     for( unsigned int n = 0; n < aLanguages.size(); n++ ){
2299                         sCur = aLanguages[ n ];
2300 						sal_uInt16 nIdx = 1;
2301 
2302 						// Set matching pairedlist identifier
2303 						if( bPairedList && pResData->pPairedList && ( nIdx == 1 ) ){
2304 							ExportListEntry* pListE = ( ExportListEntry* ) pResData->pPairedList->GetObject( nIdx-1 );
2305 							pResData->sId = GetPairedListID ( (*pListE)[ SOURCE_LANGUAGE ] );
2306 						}
2307 						else
2308 							pResData->sId = ByteString("1");
2309 
2310 						PFormEntrys *pEntrys;
2311 						sal_uLong nLIndex = 0;
2312 						sal_uLong nMaxIndex = 0;
2313 						if ( pList )
2314 							nMaxIndex = pList->GetSourceLanguageListEntryCount();
2315 						pEntrys = pMergeDataFile->GetPFormEntrys( pResData );
2316                         while( pEntrys && ( nLIndex < nMaxIndex )) {
2317 						    //printf("Lang %s, List Index %d\n",sCur.GetBuffer(),(int)nLIndex);
2318 							ByteString sText;
2319                             sal_Bool bText;
2320 							bText = pEntrys->GetTransex3Text( sText, STRING_TYP_TEXT, sCur, sal_True );
2321 							if( !bText )
2322 								bText = pEntrys->GetTransex3Text( sText , STRING_TYP_TEXT, SOURCE_LANGUAGE , sal_False );
2323 
2324 							// Use fallback, if data is missing in sdf file
2325 							//if( !bText && pResData->sResTyp.Equals( "pairedlist" ) ){
2326 							if( !bText && bPairedList ){
2327 								if( pResData->isMerged( sCur ) ) break;
2328 								const ByteString sPlist("pairedlist");
2329 								ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sGId , pResData->sId , sFilename );
2330 								bText = pResData->getFallbackData( sKey , sText );
2331 							}else if ( !bText ){// new fallback
2332 								if( pResData->isMerged( sCur ) ) break;
2333 								const ByteString sPlist("list");
2334 								ByteString sKey = MergeDataFile::CreateKey( sPlist , pResData->sGId , pResData->sId , sFilename );
2335 								bText = pResData->getFallbackData( sKey , sText );
2336 							} // new fallback
2337 
2338 							if ( bText && sText.Len()) {
2339 								//if( pEntrys ) pEntrys->Dump();
2340 								if ( nIdx == 1 ) {
2341 									ByteString sHead;
2342 									if ( bNextMustBeDefineEOL )
2343 										sHead = "\\\n\t";
2344 									sHead += sSpace;
2345 									switch ( nT ) {
2346 										case LIST_STRING : sHead += "StringList "; break;
2347 										case LIST_FILTER : sHead += "FilterList "; break;
2348 										case LIST_ITEM : sHead += "ItemList "; break;
2349 										case LIST_PAIRED : sHead += "PairedList "; break;
2350 										case LIST_UIENTRIES : sHead += "UIEntries "; break;
2351 									}
2352   									sHead += "[ ";
2353                                     sHead += sCur;
2354 									sHead += " ] ";
2355 									//}
2356 									if ( bDefine || bNextMustBeDefineEOL ) {
2357 										sHead += "= \\\n";
2358 										sHead += sSpace;
2359 										sHead += "\t{\\\n\t";
2360 									}
2361 									else {
2362 										sHead += "= \n";
2363 										sHead += sSpace;
2364 										sHead += "\t{\n\t";
2365 									}
2366 									WriteToMerged( sHead , true);
2367 								}
2368 								ByteString sLine;
2369 								if ( pList && pList->GetObject( nLIndex ))
2370 									sLine = ( *pList->GetObject( nLIndex ))[ SOURCE_LANGUAGE ];
2371 								if ( !sLine.Len())
2372 									sLine = sLastListLine;
2373 
2374 								if ( sLastListLine.Search( "<" ) != STRING_NOTFOUND ) {
2375 									if (( nT != LIST_UIENTRIES ) &&
2376 										(( sLine.Search( "{" ) == STRING_NOTFOUND ) ||
2377 										( sLine.Search( "{" ) >= sLine.Search( "\"" ))) &&
2378 										(( sLine.Search( "<" ) == STRING_NOTFOUND ) ||
2379 										( sLine.Search( "<" ) >= sLine.Search( "\"" ))))
2380 									{
2381 										sLine.SearchAndReplace( "\"", "< \"" );
2382 									}
2383 								}
2384 
2385 								sal_uInt16 nStart, nEnd;
2386 								nStart = sLine.Search( "\"" );
2387 
2388 								ByteString sPostFix;
2389 								if( !bPairedList ){
2390 									nEnd = sLine.SearchBackward( '\"' );
2391 									sPostFix = ByteString( sLine.Copy( ++nEnd ));
2392 									sLine.Erase( nStart );
2393 								}
2394 
2395 
2396                             	ConvertMergeContent( sText );
2397 
2398 								// merge new res. in text line
2399 								if( bPairedList ){
2400 									sLine = MergePairedList( sLine , sText );
2401 								}
2402 								else{
2403 									sLine += sText;
2404 									sLine += sPostFix;
2405 								}
2406 
2407 								ByteString sText1( "\t" );
2408 								sText1 += sLine;
2409 								if ( bDefine || bNextMustBeDefineEOL )
2410 									sText1 += " ;\\\n";
2411 								else
2412 									sText1 += " ;\n";
2413 								sText1 += sSpace;
2414 								sText1 += "\t";
2415 								//printf("Writing '%s'\n",sText1.GetBuffer());
2416 								WriteToMerged( sText1 ,true );
2417 
2418 								// Set matching pairedlist identifier
2419 								if ( bPairedList ){
2420 									nIdx++;
2421 									ExportListEntry* pListE = ( ExportListEntry* ) pResData->pPairedList->GetObject( ( nIdx ) -1 );
2422 									if( pListE ){
2423 										pResData->sId = GetPairedListID ( (*pListE)[ SOURCE_LANGUAGE ] );
2424 									}
2425                                 }
2426                                 else
2427                                     pResData->sId = ByteString::CreateFromInt32( ++nIdx );
2428                             }
2429 							else
2430 								break;
2431 							nLIndex ++;
2432 							PFormEntrys *oldEntry = pEntrys;
2433 							pEntrys = pMergeDataFile->GetPFormEntrys( pResData ); // <--- game over
2434 							if( !pEntrys )
2435 								pEntrys = oldEntry;
2436 						}
2437 						if ( nIdx > 1 ) {
2438 							ByteString sFooter( sSpace.Copy( 1 ));
2439 							if ( bNextMustBeDefineEOL )
2440 								sFooter += "};";
2441 							else if ( !bDefine )
2442 								sFooter += "};\n\t";
2443 							else
2444 								sFooter += "\n\n";
2445 							WriteToMerged( sFooter ,true );
2446 						}
2447 					}
2448 				}
2449 
2450 				pResData->sId = sOldId;
2451 				pResData->sGId = sOldGId;
2452 				pResData->sResTyp = sOldTyp;
2453 			}
2454 		}
2455 		break;
2456 		case MERGE_MODE_LIST : {
2457 			ExportList *pList = NULL;
2458 			switch ( nList ) {
2459 			    // PairedList
2460                 case LIST_STRING : pList = pResData->pStringList; break;
2461 				case LIST_FILTER : pList = pResData->pFilterList; break;
2462 				case LIST_UIENTRIES : pList = pResData->pUIEntries; break;
2463 				case LIST_ITEM : pList = pResData->pItemList; break;
2464 				case LIST_PAIRED : pList = pResData->pPairedList; break;
2465 
2466 			}
2467 
2468 			nListIndex++;
2469 			sal_uLong nMaxIndex = 0;
2470 			if ( pList )
2471 				nMaxIndex = pList->GetSourceLanguageListEntryCount();
2472 			ByteString sLine;
2473 			if ( pList && pList->GetObject( nListIndex ))
2474 				sLine = ( *pList->GetObject( nListIndex ))[ SOURCE_LANGUAGE ];
2475 			if ( !sLine.Len())
2476 				sLine = sLastListLine;
2477 
2478 			if ( sLastListLine.Search( "<" ) != STRING_NOTFOUND ) {
2479 				if (( nList != LIST_UIENTRIES ) &&
2480 					(( sLine.Search( "{" ) == STRING_NOTFOUND ) ||
2481 					( sLine.Search( "{" ) >= sLine.Search( "\"" ))) &&
2482 					(( sLine.Search( "<" ) == STRING_NOTFOUND ) ||
2483 					( sLine.Search( "<" ) >= sLine.Search( "\"" ))))
2484 				{
2485 					sLine.SearchAndReplace( "\"", "< \"" );
2486 				}
2487 			}
2488 
2489 			while( PrepareTextToMerge( sLine, nList, nListLang, pResData ) && ( nListIndex <= nMaxIndex )) {
2490 				ByteString sText( "\t" );
2491 				sText += sLine;
2492 				sText += " ;";
2493 				sText += "\n";
2494 				for ( sal_uInt16 i = 0; i < nLevel; i++ )
2495 					sText += "\t";
2496 				WriteToMerged( sText ,false );
2497 				nListIndex++;
2498 				if ( pList && pList->GetObject( nListIndex ))
2499 					sLine = ( *pList->GetObject( nListIndex ))[ SOURCE_LANGUAGE ];
2500 				if ( !sLine.Len())
2501 					sLine = sLastListLine;
2502 				sLine += " ;";
2503 			}
2504 		}
2505 		break;
2506 	}
2507     pParseQueue->bMflag = false;
2508 }
2509 
MergePairedList(ByteString & sLine,ByteString & sText)2510 ByteString Export::MergePairedList( ByteString& sLine , ByteString& sText ){
2511 // < "xy" ; IDENTIFIER ; >
2512 	ByteString sPre  = sLine.Copy( 0 , sLine.Search('\"') );
2513 	ByteString sPost = sLine.Copy( sLine.SearchBackward('\"') + 1 , sLine.Len() );
2514 	sPre.Append( sText );
2515 	sPre.Append( sPost );
2516 	return sPre;
2517 }
2518 
2519 /*****************************************************************************/
SetChildWithText()2520 void Export::SetChildWithText()
2521 /*****************************************************************************/
2522 {
2523 	if ( aResStack.Count() > 1 ) {
2524 		for ( sal_uLong i = 0; i < aResStack.Count() - 1; i++ ) {
2525 			aResStack.GetObject( i )->bChildWithText = sal_True;
2526 		}
2527 	}
2528 }
2529 
Push(const QueueEntry & aEntry)2530 void ParserQueue::Push( const QueueEntry& aEntry ){
2531 //    printf("nTyp = %d ",aEntry.nTyp);
2532     sal_uInt16 nLen = aEntry.sLine.Len();
2533 
2534     if( !bStart ){
2535         aQueueCur->push( aEntry );
2536         if( nLen > 1 && aEntry.sLine.GetChar( nLen-1 ) == '\n' )
2537             bStart = true;
2538         else if ( aEntry.nTyp != IGNOREDTOKENS ){
2539             if( nLen > 1 && ( aEntry.sLine.GetChar( nLen-1 ) == '\\') ){
2540                 // Next is Macro
2541                 bCurrentIsM = true;
2542              }else{
2543                 // Next is no Macro
2544                 bCurrentIsM = false;
2545              }
2546         }
2547     }
2548     else{
2549         aQueueNext->push( aEntry );
2550         if( nLen > 1 && aEntry.sLine.GetChar( nLen-1 ) != '\n' ){
2551             if( nLen > 1 && ( aEntry.sLine.GetChar( nLen-1 ) == '\\') ){
2552                 // Next is Macro
2553                 bNextIsM = true;
2554             }
2555             else{
2556                 // Next is no Macro
2557                 bNextIsM = false;
2558             }
2559         }else if( nLen > 2 && aEntry.sLine.GetChar( nLen-1 ) == '\n' ){
2560             if( aEntry.nTyp != IGNOREDTOKENS ){
2561                 if( nLen > 2 && ( aEntry.sLine.GetChar( nLen-2 ) == '\\') ){
2562                     // Next is Macro
2563                     bNextIsM = true;
2564                 }
2565                 else{
2566                     // Next is no Macro
2567                     bNextIsM = false;
2568                 }
2569             }
2570             // Pop current
2571             Pop( *aQueueCur );
2572             bLastWasM = bCurrentIsM;
2573             // next -> current
2574             bCurrentIsM = bNextIsM;
2575             aQref = aQueueCur;
2576             aQueueCur = aQueueNext;
2577             aQueueNext = aQref;
2578 
2579         }
2580 
2581         else{
2582             // Pop current
2583             Pop( *aQueueCur );
2584             bLastWasM = bCurrentIsM;
2585             // next -> current
2586             bCurrentIsM = bNextIsM;
2587             aQref = aQueueCur;
2588             aQueueCur = aQueueNext;
2589             aQueueNext = aQref;
2590         }
2591     }
2592 }
2593 
Close()2594 void ParserQueue::Close(){
2595     // Pop current
2596     Pop( *aQueueCur );
2597     // next -> current
2598     bLastWasM = bCurrentIsM;
2599     bCurrentIsM = bNextIsM;
2600     aQref = aQueueCur;
2601     aQueueCur = aQueueNext;
2602     aQueueNext = aQref;
2603     bNextIsM = false;
2604     Pop( *aQueueNext );
2605 };
Pop(std::queue<QueueEntry> & aQueue)2606 void ParserQueue::Pop( std::queue<QueueEntry>& aQueue ){
2607     while( !aQueue.empty() ){
2608         QueueEntry aEntry = aQueue.front();
2609         aQueue.pop();
2610         aExport.Execute( aEntry.nTyp , (char*) aEntry.sLine.GetBuffer() );
2611     }
2612 }
ParserQueue(Export & aExportObj)2613 ParserQueue::ParserQueue( Export& aExportObj )
2614         :
2615           bCurrentIsM( false ),
2616           bNextIsM( false ) ,
2617           bLastWasM( false ),
2618           bMflag( false ) ,
2619           aExport( aExportObj ) ,
2620           bStart( false ) ,
2621           bStartNext( false )
2622 {
2623           aQueueNext = new std::queue<QueueEntry>;
2624           aQueueCur  = new std::queue<QueueEntry>;
2625 }
2626 
2627 
~ParserQueue()2628 ParserQueue::~ParserQueue(){
2629     if( aQueueNext )    delete aQueueNext;
2630     if( aQueueCur )     delete aQueueCur;
2631 }
2632 
2633