xref: /AOO41X/main/l10ntools/source/cfgmerge.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_l10ntools.hxx"
30*cdf0e10cSrcweir #include <stdio.h>
31*cdf0e10cSrcweir #include <tools/string.hxx>
32*cdf0e10cSrcweir #include <tools/fsys.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir // local includes
35*cdf0e10cSrcweir #include "export.hxx"
36*cdf0e10cSrcweir #include "cfgmerge.hxx"
37*cdf0e10cSrcweir #include "tokens.h"
38*cdf0e10cSrcweir #include "utf8conv.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir extern "C" { int yyerror( char * ); }
41*cdf0e10cSrcweir extern "C" { int YYWarning( char * ); }
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir // defines to parse command line
44*cdf0e10cSrcweir #define STATE_NON  		0x0001
45*cdf0e10cSrcweir #define STATE_INPUT		0x0002
46*cdf0e10cSrcweir #define STATE_OUTPUT	0x0003
47*cdf0e10cSrcweir #define STATE_PRJ		0x0004
48*cdf0e10cSrcweir #define STATE_ROOT		0x0005
49*cdf0e10cSrcweir #define STATE_MERGESRC	0x0006
50*cdf0e10cSrcweir #define STATE_ERRORLOG	0x0007
51*cdf0e10cSrcweir #define STATE_UTF8		0x0008
52*cdf0e10cSrcweir #define STATE_LANGUAGES	0X0009
53*cdf0e10cSrcweir #define STATE_ISOCODE99	0x000A
54*cdf0e10cSrcweir #define STATE_FORCE		0x000B
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // set of global variables
57*cdf0e10cSrcweir sal_Bool bEnableExport;
58*cdf0e10cSrcweir sal_Bool bMergeMode;
59*cdf0e10cSrcweir sal_Bool bErrorLog;
60*cdf0e10cSrcweir sal_Bool bForce;
61*cdf0e10cSrcweir sal_Bool bUTF8;
62*cdf0e10cSrcweir ByteString sPrj;
63*cdf0e10cSrcweir ByteString sPrjRoot;
64*cdf0e10cSrcweir ByteString sInputFileName;
65*cdf0e10cSrcweir ByteString sActFileName;
66*cdf0e10cSrcweir ByteString sFullEntry;
67*cdf0e10cSrcweir ByteString sOutputFile;
68*cdf0e10cSrcweir ByteString sMergeSrc;
69*cdf0e10cSrcweir String sUsedTempFile;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir CfgParser *pParser;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir extern "C" {
74*cdf0e10cSrcweir // the whole interface to lexer is in this extern "C" section
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir /*****************************************************************************/
77*cdf0e10cSrcweir extern char *GetOutputFile( int argc, char* argv[])
78*cdf0e10cSrcweir /*****************************************************************************/
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	bEnableExport   = sal_False;
81*cdf0e10cSrcweir 	bMergeMode      = sal_False;
82*cdf0e10cSrcweir 	bErrorLog       = sal_True;
83*cdf0e10cSrcweir 	bForce          = sal_False;
84*cdf0e10cSrcweir 	bUTF8           = sal_True;
85*cdf0e10cSrcweir     sPrj            = "";
86*cdf0e10cSrcweir 	sPrjRoot        = "";
87*cdf0e10cSrcweir 	sInputFileName  = "";
88*cdf0e10cSrcweir 	sActFileName    = "";
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	sal_uInt16 nState = STATE_NON;
91*cdf0e10cSrcweir 	sal_Bool bInput = sal_False;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	// parse command line
94*cdf0e10cSrcweir 	for( int i = 1; i < argc; i++ ) {
95*cdf0e10cSrcweir         ByteString sSwitch( argv[ i ] );
96*cdf0e10cSrcweir         sSwitch.ToUpperAscii();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         if ( sSwitch == "-I" ) {
99*cdf0e10cSrcweir 			nState = STATE_INPUT; // next token specifies source file
100*cdf0e10cSrcweir 		}
101*cdf0e10cSrcweir 		else if ( sSwitch == "-O" ) {
102*cdf0e10cSrcweir 			nState = STATE_OUTPUT; // next token specifies the dest file
103*cdf0e10cSrcweir 		}
104*cdf0e10cSrcweir 		else if ( sSwitch == "-P" ) {
105*cdf0e10cSrcweir 			nState = STATE_PRJ; // next token specifies the cur. project
106*cdf0e10cSrcweir 		}
107*cdf0e10cSrcweir 		else if ( sSwitch == "-R" ) {
108*cdf0e10cSrcweir 			nState = STATE_ROOT; // next token specifies path to project root
109*cdf0e10cSrcweir 		}
110*cdf0e10cSrcweir 		else if ( sSwitch == "-M" ) {
111*cdf0e10cSrcweir 			nState = STATE_MERGESRC; // next token specifies the merge database
112*cdf0e10cSrcweir 		}
113*cdf0e10cSrcweir 		else if ( sSwitch == "-E" ) {
114*cdf0e10cSrcweir 			nState = STATE_ERRORLOG;
115*cdf0e10cSrcweir 			bErrorLog = sal_False;
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 		else if ( sSwitch == "-UTF8" ) {
118*cdf0e10cSrcweir 			nState = STATE_UTF8;
119*cdf0e10cSrcweir 			bUTF8 = sal_True;
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir 		else if ( sSwitch == "-NOUTF8" ) {
122*cdf0e10cSrcweir 			nState = STATE_UTF8;
123*cdf0e10cSrcweir 			bUTF8 = sal_False;
124*cdf0e10cSrcweir 		}
125*cdf0e10cSrcweir 		else if ( sSwitch == "-F" ) {
126*cdf0e10cSrcweir 			nState = STATE_FORCE;
127*cdf0e10cSrcweir 			bForce = sal_True;
128*cdf0e10cSrcweir 		}
129*cdf0e10cSrcweir         else if ( sSwitch == "-L" ) {
130*cdf0e10cSrcweir 			nState = STATE_LANGUAGES;
131*cdf0e10cSrcweir 		}
132*cdf0e10cSrcweir 		else if ( sSwitch.ToUpperAscii() == "-ISO99" ) {
133*cdf0e10cSrcweir 			nState = STATE_ISOCODE99;
134*cdf0e10cSrcweir 		}
135*cdf0e10cSrcweir 		else {
136*cdf0e10cSrcweir 			switch ( nState ) {
137*cdf0e10cSrcweir 				case STATE_NON: {
138*cdf0e10cSrcweir 					return NULL;	// no valid command line
139*cdf0e10cSrcweir 				}
140*cdf0e10cSrcweir 				case STATE_INPUT: {
141*cdf0e10cSrcweir 					sInputFileName = argv[ i ];
142*cdf0e10cSrcweir 					bInput = sal_True; // source file found
143*cdf0e10cSrcweir 				}
144*cdf0e10cSrcweir 				break;
145*cdf0e10cSrcweir 				case STATE_OUTPUT: {
146*cdf0e10cSrcweir 					sOutputFile = argv[ i ]; // the dest. file
147*cdf0e10cSrcweir 				}
148*cdf0e10cSrcweir 				break;
149*cdf0e10cSrcweir 				case STATE_PRJ: {
150*cdf0e10cSrcweir 					sPrj = ByteString( argv[ i ]);
151*cdf0e10cSrcweir //					sPrj.ToLowerAscii(); // the project
152*cdf0e10cSrcweir 				}
153*cdf0e10cSrcweir 				break;
154*cdf0e10cSrcweir 				case STATE_ROOT: {
155*cdf0e10cSrcweir 					sPrjRoot = ByteString( argv[ i ]); // path to project root
156*cdf0e10cSrcweir 				}
157*cdf0e10cSrcweir 				break;
158*cdf0e10cSrcweir 				case STATE_MERGESRC: {
159*cdf0e10cSrcweir 					sMergeSrc = ByteString( argv[ i ]);
160*cdf0e10cSrcweir 					bMergeMode = sal_True; // activate merge mode, cause merge database found
161*cdf0e10cSrcweir 				}
162*cdf0e10cSrcweir 				break;
163*cdf0e10cSrcweir 				case STATE_LANGUAGES: {
164*cdf0e10cSrcweir 					Export::sLanguages = ByteString( argv[ i ]);
165*cdf0e10cSrcweir 				}
166*cdf0e10cSrcweir 				break;
167*cdf0e10cSrcweir 			}
168*cdf0e10cSrcweir 		}
169*cdf0e10cSrcweir 	}
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	if ( bInput ) {
172*cdf0e10cSrcweir 		// command line is valid
173*cdf0e10cSrcweir 		bEnableExport = sal_True;
174*cdf0e10cSrcweir 		char *pReturn = new char[ sOutputFile.Len() + 1 ];
175*cdf0e10cSrcweir 		strcpy( pReturn, sOutputFile.GetBuffer());  // #100211# - checked
176*cdf0e10cSrcweir 		return pReturn;
177*cdf0e10cSrcweir 	}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	// command line is not valid
180*cdf0e10cSrcweir 	return NULL;
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir /*****************************************************************************/
183*cdf0e10cSrcweir int InitCfgExport( char *pOutput , char* pFilename )
184*cdf0e10cSrcweir /*****************************************************************************/
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	// instanciate Export
187*cdf0e10cSrcweir 	ByteString sOutput( pOutput );
188*cdf0e10cSrcweir 	ByteString sFilename( pFilename );
189*cdf0e10cSrcweir     Export::InitLanguages();
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	if ( bMergeMode )
192*cdf0e10cSrcweir 		pParser = new CfgMerge( sMergeSrc, sOutputFile, sFilename );
193*cdf0e10cSrcweir   	else if ( sOutputFile.Len())
194*cdf0e10cSrcweir 		pParser = new CfgExport( sOutputFile, sPrj, sActFileName );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	return 1;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir /*****************************************************************************/
200*cdf0e10cSrcweir int EndCfgExport()
201*cdf0e10cSrcweir /*****************************************************************************/
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir 	delete pParser;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	return 1;
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir void removeTempFile(){
209*cdf0e10cSrcweir     if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){
210*cdf0e10cSrcweir         DirEntry aTempFile( sUsedTempFile );
211*cdf0e10cSrcweir         aTempFile.Kill();
212*cdf0e10cSrcweir     }
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir extern const char* getFilename()
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 	return sInputFileName.GetBuffer();
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir /*****************************************************************************/
219*cdf0e10cSrcweir extern FILE *GetCfgFile()
220*cdf0e10cSrcweir /*****************************************************************************/
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir 	FILE *pFile = 0;
223*cdf0e10cSrcweir     // look for valid filename
224*cdf0e10cSrcweir 	if ( sInputFileName.Len()) {
225*cdf0e10cSrcweir         if( Export::fileHasUTF8ByteOrderMarker( sInputFileName ) ){
226*cdf0e10cSrcweir             DirEntry aTempFile = Export::GetTempFile();
227*cdf0e10cSrcweir             DirEntry aSourceFile( String( sInputFileName , RTL_TEXTENCODING_ASCII_US ) );
228*cdf0e10cSrcweir             aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
229*cdf0e10cSrcweir             String sTempFile = aTempFile.GetFull();
230*cdf0e10cSrcweir             Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) );
231*cdf0e10cSrcweir             pFile = fopen( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ).GetBuffer(), "r" );
232*cdf0e10cSrcweir             sUsedTempFile = sTempFile;
233*cdf0e10cSrcweir         }else{
234*cdf0e10cSrcweir             // able to open file?
235*cdf0e10cSrcweir             pFile = fopen( sInputFileName.GetBuffer(), "r" );
236*cdf0e10cSrcweir             sUsedTempFile = String::CreateFromAscii("");
237*cdf0e10cSrcweir         }
238*cdf0e10cSrcweir 		if ( !pFile ){
239*cdf0e10cSrcweir 			fprintf( stderr, "Error: Could not open file %s\n",
240*cdf0e10cSrcweir 				sInputFileName.GetBuffer());
241*cdf0e10cSrcweir             exit( -13 );
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir 		else {
244*cdf0e10cSrcweir 			// this is a valid file which can be opened, so
245*cdf0e10cSrcweir 			// create path to project root
246*cdf0e10cSrcweir 			DirEntry aEntry( String( sInputFileName, RTL_TEXTENCODING_ASCII_US ));
247*cdf0e10cSrcweir 			aEntry.ToAbs();
248*cdf0e10cSrcweir 			sFullEntry= ByteString( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
249*cdf0e10cSrcweir 			aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
250*cdf0e10cSrcweir 			aEntry += DirEntry( sPrjRoot );
251*cdf0e10cSrcweir 			ByteString sPrjEntry( aEntry.GetFull(), RTL_TEXTENCODING_ASCII_US );
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 			// create file name, beginnig with project root
254*cdf0e10cSrcweir 			// (e.g.: source\ui\src\menue.src)
255*cdf0e10cSrcweir //			printf("sFullEntry = %s\n",sFullEntry.GetBuffer());
256*cdf0e10cSrcweir             sActFileName = sFullEntry.Copy( sPrjEntry.Len() + 1 );
257*cdf0e10cSrcweir //            printf("sActFileName = %s\n",sActFileName.GetBuffer());
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 			sActFileName.SearchAndReplaceAll( "/", "\\" );
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 			return pFile;
262*cdf0e10cSrcweir 		}
263*cdf0e10cSrcweir 	}
264*cdf0e10cSrcweir 	// this means the file could not be opened
265*cdf0e10cSrcweir 	return NULL;
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir /*****************************************************************************/
269*cdf0e10cSrcweir int WorkOnTokenSet( int nTyp, char *pTokenText )
270*cdf0e10cSrcweir /*****************************************************************************/
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir 	pParser->Execute( nTyp, pTokenText );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 	return 1;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir /*****************************************************************************/
279*cdf0e10cSrcweir int SetError()
280*cdf0e10cSrcweir /*****************************************************************************/
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	return 1;
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir /*****************************************************************************/
286*cdf0e10cSrcweir int GetError()
287*cdf0e10cSrcweir /*****************************************************************************/
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir 	return 0;
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir //
294*cdf0e10cSrcweir // class CfgStackData
295*cdf0e10cSrcweir //
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir CfgStackData* CfgStack::Push( const ByteString &rTag, const ByteString &rId )
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     CfgStackData *pD = new CfgStackData( rTag, rId );
300*cdf0e10cSrcweir     Insert( pD, LIST_APPEND );
301*cdf0e10cSrcweir     return pD;
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir //
305*cdf0e10cSrcweir // class CfgStack
306*cdf0e10cSrcweir //
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir /*****************************************************************************/
309*cdf0e10cSrcweir CfgStack::~CfgStack()
310*cdf0e10cSrcweir /*****************************************************************************/
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	for ( sal_uLong i = 0; i < Count(); i++ )
313*cdf0e10cSrcweir 		delete GetObject( i );
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir /*****************************************************************************/
317*cdf0e10cSrcweir ByteString CfgStack::GetAccessPath( sal_uLong nPos )
318*cdf0e10cSrcweir /*****************************************************************************/
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir 	if ( nPos == LIST_APPEND )
321*cdf0e10cSrcweir 		nPos = Count() - 1;
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 	ByteString sReturn;
324*cdf0e10cSrcweir 	for ( sal_uLong i = 0; i <= nPos; i++ ) {
325*cdf0e10cSrcweir 		if ( i )
326*cdf0e10cSrcweir 			sReturn += ".";
327*cdf0e10cSrcweir 		sReturn += GetStackData( i )->GetIdentifier();
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	return sReturn;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir /*****************************************************************************/
334*cdf0e10cSrcweir CfgStackData *CfgStack::GetStackData( sal_uLong nPos )
335*cdf0e10cSrcweir /*****************************************************************************/
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	if ( nPos == LIST_APPEND )
338*cdf0e10cSrcweir 		nPos = Count() - 1;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	return GetObject( nPos );
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir //
344*cdf0e10cSrcweir // class CfgParser
345*cdf0e10cSrcweir //
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir /*****************************************************************************/
348*cdf0e10cSrcweir CfgParser::CfgParser()
349*cdf0e10cSrcweir /*****************************************************************************/
350*cdf0e10cSrcweir 				: pStackData( NULL ),
351*cdf0e10cSrcweir 				bLocalize( sal_False )
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir /*****************************************************************************/
356*cdf0e10cSrcweir CfgParser::~CfgParser()
357*cdf0e10cSrcweir /*****************************************************************************/
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir /*****************************************************************************/
363*cdf0e10cSrcweir sal_Bool CfgParser::IsTokenClosed( const ByteString &rToken )
364*cdf0e10cSrcweir /*****************************************************************************/
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir 	return rToken.GetChar( rToken.Len() - 2 ) == '/';
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir /*****************************************************************************/
370*cdf0e10cSrcweir void CfgParser::AddText(
371*cdf0e10cSrcweir 	ByteString &rText,
372*cdf0e10cSrcweir 	const ByteString &rIsoLang,
373*cdf0e10cSrcweir 	const ByteString &rResTyp
374*cdf0e10cSrcweir )
375*cdf0e10cSrcweir /*****************************************************************************/
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir 		sal_uInt16 nTextLen = 0;
378*cdf0e10cSrcweir 		while ( rText.Len() != nTextLen ) {
379*cdf0e10cSrcweir 			nTextLen = rText.Len();
380*cdf0e10cSrcweir 			rText.SearchAndReplaceAll( "\n", " " );
381*cdf0e10cSrcweir 			rText.SearchAndReplaceAll( "\r", " " );
382*cdf0e10cSrcweir 			rText.SearchAndReplaceAll( "\t", " " );
383*cdf0e10cSrcweir 			rText.SearchAndReplaceAll( "  ", " " );
384*cdf0e10cSrcweir 		}
385*cdf0e10cSrcweir 		pStackData->sResTyp = rResTyp;
386*cdf0e10cSrcweir         WorkOnText( rText, rIsoLang );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         pStackData->sText[ rIsoLang ] = rText;
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir /*****************************************************************************/
393*cdf0e10cSrcweir void CfgParser::WorkOnRessourceEnd()
394*cdf0e10cSrcweir /*****************************************************************************/
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir /*****************************************************************************/
399*cdf0e10cSrcweir int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
400*cdf0e10cSrcweir /*****************************************************************************/
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir 	ByteString sToken( pToken );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	if ( sToken == " " || sToken == "\t" )
405*cdf0e10cSrcweir 		sLastWhitespace += sToken;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	ByteString sTokenName;
408*cdf0e10cSrcweir 	ByteString sTokenId;
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 	sal_Bool bOutput = sal_True;
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	switch ( nToken ) {
413*cdf0e10cSrcweir 		case CFG_TOKEN_PACKAGE:
414*cdf0e10cSrcweir 		case CFG_TOKEN_COMPONENT:
415*cdf0e10cSrcweir 		case CFG_TOKEN_TEMPLATE:
416*cdf0e10cSrcweir 		case CFG_TOKEN_CONFIGNAME:
417*cdf0e10cSrcweir 		case CFG_TOKEN_OORNAME:
418*cdf0e10cSrcweir 		case CFG_TOKEN_OORVALUE:
419*cdf0e10cSrcweir 		case CFG_TAG:
420*cdf0e10cSrcweir 		case ANYTOKEN:
421*cdf0e10cSrcweir 		case CFG_TEXT_START:
422*cdf0e10cSrcweir 		{
423*cdf0e10cSrcweir 			sTokenName = sToken.GetToken( 1, '<' ).GetToken( 0, '>' ).GetToken( 0, ' ' );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	  		if ( !IsTokenClosed( sToken )) {
426*cdf0e10cSrcweir 				ByteString sSearch;
427*cdf0e10cSrcweir 				switch ( nToken ) {
428*cdf0e10cSrcweir 					case CFG_TOKEN_PACKAGE:
429*cdf0e10cSrcweir 						sSearch = "package-id=";
430*cdf0e10cSrcweir 					break;
431*cdf0e10cSrcweir 					case CFG_TOKEN_COMPONENT:
432*cdf0e10cSrcweir 						sSearch = "component-id=";
433*cdf0e10cSrcweir 					break;
434*cdf0e10cSrcweir 					case CFG_TOKEN_TEMPLATE:
435*cdf0e10cSrcweir 						sSearch = "template-id=";
436*cdf0e10cSrcweir 					break;
437*cdf0e10cSrcweir 					case CFG_TOKEN_CONFIGNAME:
438*cdf0e10cSrcweir 						sSearch = "cfg:name=";
439*cdf0e10cSrcweir 					break;
440*cdf0e10cSrcweir 					case CFG_TOKEN_OORNAME:
441*cdf0e10cSrcweir 						sSearch = "oor:name=";
442*cdf0e10cSrcweir 						bLocalize = sal_True;
443*cdf0e10cSrcweir 					break;
444*cdf0e10cSrcweir 					case CFG_TOKEN_OORVALUE:
445*cdf0e10cSrcweir 						sSearch = "oor:value=";
446*cdf0e10cSrcweir 					break;
447*cdf0e10cSrcweir 					case CFG_TEXT_START: {
448*cdf0e10cSrcweir 						if ( sCurrentResTyp != sTokenName ) {
449*cdf0e10cSrcweir 							WorkOnRessourceEnd();
450*cdf0e10cSrcweir                             ByteString sCur;
451*cdf0e10cSrcweir                             for( unsigned int n = 0; n < aLanguages.size(); n++ ){
452*cdf0e10cSrcweir                                 sCur = aLanguages[ n ];
453*cdf0e10cSrcweir                                 pStackData->sText[ sCur ] = ByteString("");
454*cdf0e10cSrcweir                             }
455*cdf0e10cSrcweir                      	}
456*cdf0e10cSrcweir 						sCurrentResTyp = sTokenName;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 						ByteString sTemp = sToken.Copy( sToken.Search( "xml:lang=" ));
459*cdf0e10cSrcweir 						sCurrentIsoLang = sTemp.GetToken( 1, '\"' ).GetToken( 0, '\"' );
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 						if ( sCurrentIsoLang == NO_TRANSLATE_ISO )
462*cdf0e10cSrcweir 							bLocalize = sal_False;
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 						pStackData->sTextTag = sToken;
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 						sCurrentText = "";
467*cdf0e10cSrcweir 					}
468*cdf0e10cSrcweir 					break;
469*cdf0e10cSrcweir 				}
470*cdf0e10cSrcweir 				if ( sSearch.Len()) {
471*cdf0e10cSrcweir 					ByteString sTemp = sToken.Copy( sToken.Search( sSearch ));
472*cdf0e10cSrcweir 					sTokenId = sTemp.GetToken( 1, '\"' ).GetToken( 0, '\"' );
473*cdf0e10cSrcweir 				}
474*cdf0e10cSrcweir 				pStackData = aStack.Push( sTokenName, sTokenId );
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 				if ( sSearch == "cfg:name=" ) {
477*cdf0e10cSrcweir 					ByteString sTemp( sToken );
478*cdf0e10cSrcweir 					sTemp.ToUpperAscii();
479*cdf0e10cSrcweir 					bLocalize = (( sTemp.Search( "CFG:TYPE=\"STRING\"" ) != STRING_NOTFOUND ) &&
480*cdf0e10cSrcweir 						( sTemp.Search( "CFG:LOCALIZED=\"sal_True\"" ) != STRING_NOTFOUND ));
481*cdf0e10cSrcweir 				}
482*cdf0e10cSrcweir 			}
483*cdf0e10cSrcweir 			else if ( sTokenName == "label" ) {
484*cdf0e10cSrcweir 				if ( sCurrentResTyp != sTokenName ) {
485*cdf0e10cSrcweir 					WorkOnRessourceEnd();
486*cdf0e10cSrcweir                     ByteString sCur;
487*cdf0e10cSrcweir                     for( unsigned int n = 0; n < aLanguages.size(); n++ ){
488*cdf0e10cSrcweir                         sCur = aLanguages[ n ];
489*cdf0e10cSrcweir                         pStackData->sText[ sCur ] = ByteString("");
490*cdf0e10cSrcweir                     }
491*cdf0e10cSrcweir         		}
492*cdf0e10cSrcweir 				sCurrentResTyp = sTokenName;
493*cdf0e10cSrcweir 			}
494*cdf0e10cSrcweir 		}
495*cdf0e10cSrcweir 		break;
496*cdf0e10cSrcweir 		case CFG_CLOSETAG:
497*cdf0e10cSrcweir 			sTokenName = sToken.GetToken( 1, '/' ).GetToken( 0, '>' ).GetToken( 0, ' ' );
498*cdf0e10cSrcweir 		   	if ( aStack.GetStackData() && ( aStack.GetStackData()->GetTagType() == sTokenName )) {
499*cdf0e10cSrcweir 				if ( ! sCurrentText.Len())
500*cdf0e10cSrcweir 					WorkOnRessourceEnd();
501*cdf0e10cSrcweir 				aStack.Pop();
502*cdf0e10cSrcweir 				pStackData = aStack.GetStackData();
503*cdf0e10cSrcweir 			}
504*cdf0e10cSrcweir 			else {
505*cdf0e10cSrcweir 				ByteString sError( "Missplaced close tag: " );
506*cdf0e10cSrcweir                 ByteString sInFile(" in file ");
507*cdf0e10cSrcweir                 sError += sToken;
508*cdf0e10cSrcweir                 sError += sInFile;
509*cdf0e10cSrcweir                 sError += sFullEntry;
510*cdf0e10cSrcweir 				Error( sError );
511*cdf0e10cSrcweir                 exit ( 13 );
512*cdf0e10cSrcweir 			}
513*cdf0e10cSrcweir 		break;
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 		case CFG_TEXTCHAR:
516*cdf0e10cSrcweir 			sCurrentText += sToken;
517*cdf0e10cSrcweir 			bOutput = sal_False;
518*cdf0e10cSrcweir 		break;
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 		case CFG_TOKEN_NO_TRANSLATE:
521*cdf0e10cSrcweir 			bLocalize = sal_False;
522*cdf0e10cSrcweir 		break;
523*cdf0e10cSrcweir 	}
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir 	if ( sCurrentText.Len() && nToken != CFG_TEXTCHAR ) {
526*cdf0e10cSrcweir 		AddText( sCurrentText, sCurrentIsoLang, sCurrentResTyp );
527*cdf0e10cSrcweir 		Output( sCurrentText );
528*cdf0e10cSrcweir 		sCurrentText = "";
529*cdf0e10cSrcweir 		pStackData->sEndTextTag = sToken;
530*cdf0e10cSrcweir 	}
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 	if ( bOutput )
533*cdf0e10cSrcweir 		Output( sToken );
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	if ( sToken != " " && sToken != "\t" )
536*cdf0e10cSrcweir 		sLastWhitespace = "";
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 	return 1;
539*cdf0e10cSrcweir }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir /*****************************************************************************/
542*cdf0e10cSrcweir void CfgExport::Output( const ByteString& rOutput )
543*cdf0e10cSrcweir /*****************************************************************************/
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir     // Dummy operation to suppress warnings caused by poor class design
546*cdf0e10cSrcweir     ByteString a( rOutput );
547*cdf0e10cSrcweir }
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir /*****************************************************************************/
550*cdf0e10cSrcweir int CfgParser::Execute( int nToken, char * pToken )
551*cdf0e10cSrcweir /*****************************************************************************/
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	ByteString sToken( pToken );
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 	switch ( nToken ) {
556*cdf0e10cSrcweir 		case CFG_TAG:
557*cdf0e10cSrcweir 			if ( sToken.Search( "package-id=" ) != STRING_NOTFOUND )
558*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_PACKAGE, pToken );
559*cdf0e10cSrcweir 			else if ( sToken.Search( "component-id=" ) != STRING_NOTFOUND )
560*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_COMPONENT, pToken );
561*cdf0e10cSrcweir 			else if ( sToken.Search( "template-id=" ) != STRING_NOTFOUND )
562*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_TEMPLATE, pToken );
563*cdf0e10cSrcweir 			else if ( sToken.Search( "cfg:name=" ) != STRING_NOTFOUND )
564*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_OORNAME, pToken );
565*cdf0e10cSrcweir 			else if ( sToken.Search( "oor:name=" ) != STRING_NOTFOUND )
566*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_OORNAME, pToken );
567*cdf0e10cSrcweir 			else if ( sToken.Search( "oor:value=" ) != STRING_NOTFOUND )
568*cdf0e10cSrcweir 				return ExecuteAnalyzedToken( CFG_TOKEN_OORVALUE, pToken );
569*cdf0e10cSrcweir 		break;
570*cdf0e10cSrcweir 	}
571*cdf0e10cSrcweir 	return ExecuteAnalyzedToken( nToken, pToken );
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir /*****************************************************************************/
576*cdf0e10cSrcweir void CfgParser::Error( const ByteString &rError )
577*cdf0e10cSrcweir /*****************************************************************************/
578*cdf0e10cSrcweir {
579*cdf0e10cSrcweir //	ByteString sError( rError );
580*cdf0e10cSrcweir //    sError.Append("Error: In file ");
581*cdf0e10cSrcweir //    sError.Append( sActFileName );
582*cdf0e10cSrcweir     yyerror(( char * ) rError.GetBuffer());
583*cdf0e10cSrcweir }
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir //
587*cdf0e10cSrcweir // class CfgOutputParser
588*cdf0e10cSrcweir //
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir /*****************************************************************************/
591*cdf0e10cSrcweir CfgOutputParser::CfgOutputParser( const ByteString &rOutputFile )
592*cdf0e10cSrcweir /*****************************************************************************/
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir 	pOutputStream =
595*cdf0e10cSrcweir 		new SvFileStream(
596*cdf0e10cSrcweir 			String( rOutputFile, RTL_TEXTENCODING_ASCII_US ),
597*cdf0e10cSrcweir 			STREAM_STD_WRITE | STREAM_TRUNC
598*cdf0e10cSrcweir 		);
599*cdf0e10cSrcweir     pOutputStream->SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 	if ( !pOutputStream->IsOpen()) {
602*cdf0e10cSrcweir 		ByteString sError( "ERROR: Unable to open output file: " );
603*cdf0e10cSrcweir 		sError += rOutputFile;
604*cdf0e10cSrcweir 		Error( sError );
605*cdf0e10cSrcweir 		delete pOutputStream;
606*cdf0e10cSrcweir 		pOutputStream = NULL;
607*cdf0e10cSrcweir         exit( -13 );
608*cdf0e10cSrcweir 	}
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir /*****************************************************************************/
612*cdf0e10cSrcweir CfgOutputParser::~CfgOutputParser()
613*cdf0e10cSrcweir /*****************************************************************************/
614*cdf0e10cSrcweir {
615*cdf0e10cSrcweir 	if ( pOutputStream ) {
616*cdf0e10cSrcweir 		pOutputStream->Close();
617*cdf0e10cSrcweir 		delete pOutputStream;
618*cdf0e10cSrcweir 	}
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir //
622*cdf0e10cSrcweir // class CfgExport
623*cdf0e10cSrcweir //
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir /*****************************************************************************/
626*cdf0e10cSrcweir CfgExport::CfgExport(
627*cdf0e10cSrcweir 		const ByteString &rOutputFile,
628*cdf0e10cSrcweir 		const ByteString &rProject,
629*cdf0e10cSrcweir 		const ByteString &rFilePath
630*cdf0e10cSrcweir )
631*cdf0e10cSrcweir /*****************************************************************************/
632*cdf0e10cSrcweir 				: CfgOutputParser( rOutputFile ),
633*cdf0e10cSrcweir 				sPrj( rProject ),
634*cdf0e10cSrcweir 				sPath( rFilePath )
635*cdf0e10cSrcweir {
636*cdf0e10cSrcweir     Export::InitLanguages( false );
637*cdf0e10cSrcweir     aLanguages = Export::GetLanguages();
638*cdf0e10cSrcweir }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir /*****************************************************************************/
641*cdf0e10cSrcweir CfgExport::~CfgExport()
642*cdf0e10cSrcweir /*****************************************************************************/
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir }
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir /*****************************************************************************/
647*cdf0e10cSrcweir void CfgExport::WorkOnRessourceEnd()
648*cdf0e10cSrcweir /*****************************************************************************/
649*cdf0e10cSrcweir {
650*cdf0e10cSrcweir 	if ( pOutputStream && bLocalize ) {
651*cdf0e10cSrcweir 	if (( pStackData->sText[ ByteString("en-US") ].Len()
652*cdf0e10cSrcweir         ) ||
653*cdf0e10cSrcweir 			( bForce &&
654*cdf0e10cSrcweir 				( pStackData->sText[ ByteString("de") ].Len() ||
655*cdf0e10cSrcweir                     pStackData->sText[ ByteString("en-US") ].Len() )))
656*cdf0e10cSrcweir 		{
657*cdf0e10cSrcweir             ByteString sFallback = pStackData->sText[ ByteString("en-US") ];
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir             //if ( pStackData->sText[ ByteString("en-US") ].Len())
660*cdf0e10cSrcweir 			//	sFallback = pStackData->sText[ ByteString("en-US") ];
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir 			ByteString sLocalId = pStackData->sIdentifier;
663*cdf0e10cSrcweir 			ByteString sGroupId;
664*cdf0e10cSrcweir 			if ( aStack.Count() == 1 ) {
665*cdf0e10cSrcweir 				sGroupId = sLocalId;
666*cdf0e10cSrcweir 				sLocalId = "";
667*cdf0e10cSrcweir 			}
668*cdf0e10cSrcweir 			else {
669*cdf0e10cSrcweir 				sGroupId = aStack.GetAccessPath( aStack.Count() - 2 );
670*cdf0e10cSrcweir 			}
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 			ByteString sTimeStamp( Export::GetTimeStamp());
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir             ByteString sCur;
675*cdf0e10cSrcweir             for( unsigned int n = 0; n < aLanguages.size(); n++ ){
676*cdf0e10cSrcweir                 sCur = aLanguages[ n ];
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir 					ByteString sText = pStackData->sText[ sCur ];
679*cdf0e10cSrcweir 					if ( !sText.Len())
680*cdf0e10cSrcweir 						sText = sFallback;
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir                     Export::UnquotHTML( sText );
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 					ByteString sOutput( sPrj ); sOutput += "\t";
685*cdf0e10cSrcweir 					sOutput += sPath;
686*cdf0e10cSrcweir 					sOutput += "\t0\t";
687*cdf0e10cSrcweir 					sOutput += pStackData->sResTyp; sOutput += "\t";
688*cdf0e10cSrcweir 					sOutput += sGroupId; sOutput += "\t";
689*cdf0e10cSrcweir 					sOutput += sLocalId; sOutput += "\t\t\t0\t";
690*cdf0e10cSrcweir                     sOutput += sCur;
691*cdf0e10cSrcweir 					sOutput += "\t";
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir                     sOutput += sText; sOutput += "\t\t\t\t";
694*cdf0e10cSrcweir 					sOutput += sTimeStamp;
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir                     //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( sPrj ) ) )
697*cdf0e10cSrcweir 					pOutputStream->WriteLine( sOutput );
698*cdf0e10cSrcweir 			}
699*cdf0e10cSrcweir 		}
700*cdf0e10cSrcweir 	}
701*cdf0e10cSrcweir }
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir /*****************************************************************************/
704*cdf0e10cSrcweir void CfgExport::WorkOnText(
705*cdf0e10cSrcweir 	ByteString &rText,
706*cdf0e10cSrcweir     const ByteString &rIsoLang
707*cdf0e10cSrcweir )
708*cdf0e10cSrcweir /*****************************************************************************/
709*cdf0e10cSrcweir {
710*cdf0e10cSrcweir     if( rIsoLang.Len() ) Export::UnquotHTML( rText );
711*cdf0e10cSrcweir }
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir //
715*cdf0e10cSrcweir // class CfgMerge
716*cdf0e10cSrcweir //
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir /*****************************************************************************/
719*cdf0e10cSrcweir CfgMerge::CfgMerge(
720*cdf0e10cSrcweir 	const ByteString &rMergeSource, const ByteString &rOutputFile,
721*cdf0e10cSrcweir 	ByteString &rFilename )
722*cdf0e10cSrcweir /*****************************************************************************/
723*cdf0e10cSrcweir 				: CfgOutputParser( rOutputFile ),
724*cdf0e10cSrcweir 				pMergeDataFile( NULL ),
725*cdf0e10cSrcweir 				pResData( NULL ),
726*cdf0e10cSrcweir 				bGerman( sal_False ),
727*cdf0e10cSrcweir 				sFilename( rFilename ),
728*cdf0e10cSrcweir 				bEnglish( sal_False )
729*cdf0e10cSrcweir {
730*cdf0e10cSrcweir     if ( rMergeSource.Len()){
731*cdf0e10cSrcweir 		pMergeDataFile = new MergeDataFile(
732*cdf0e10cSrcweir 		rMergeSource, sInputFileName  , bErrorLog, RTL_TEXTENCODING_MS_1252, true );
733*cdf0e10cSrcweir         if( Export::sLanguages.EqualsIgnoreCaseAscii("ALL") ){
734*cdf0e10cSrcweir             Export::SetLanguages( pMergeDataFile->GetLanguages() );
735*cdf0e10cSrcweir             aLanguages = pMergeDataFile->GetLanguages();
736*cdf0e10cSrcweir         }
737*cdf0e10cSrcweir         else aLanguages = Export::GetLanguages();
738*cdf0e10cSrcweir     }else
739*cdf0e10cSrcweir         aLanguages = Export::GetLanguages();
740*cdf0e10cSrcweir }
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir /*****************************************************************************/
743*cdf0e10cSrcweir CfgMerge::~CfgMerge()
744*cdf0e10cSrcweir /*****************************************************************************/
745*cdf0e10cSrcweir {
746*cdf0e10cSrcweir 	delete pMergeDataFile;
747*cdf0e10cSrcweir 	delete pResData;
748*cdf0e10cSrcweir }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir /*****************************************************************************/
751*cdf0e10cSrcweir void CfgMerge::WorkOnText(
752*cdf0e10cSrcweir 	ByteString &rText,
753*cdf0e10cSrcweir     const ByteString& nLangIndex
754*cdf0e10cSrcweir )
755*cdf0e10cSrcweir /*****************************************************************************/
756*cdf0e10cSrcweir {
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir     if ( pMergeDataFile && bLocalize ) {
759*cdf0e10cSrcweir 		if ( !pResData ) {
760*cdf0e10cSrcweir 			ByteString sLocalId = pStackData->sIdentifier;
761*cdf0e10cSrcweir 			ByteString sGroupId;
762*cdf0e10cSrcweir 			if ( aStack.Count() == 1 ) {
763*cdf0e10cSrcweir 				sGroupId = sLocalId;
764*cdf0e10cSrcweir 				sLocalId = "";
765*cdf0e10cSrcweir 			}
766*cdf0e10cSrcweir 			else {
767*cdf0e10cSrcweir 				sGroupId = aStack.GetAccessPath( aStack.Count() - 2 );
768*cdf0e10cSrcweir 			}
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir 			ByteString sPlatform( "" );
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 			pResData = new ResData( sPlatform, sGroupId , sFilename );
773*cdf0e10cSrcweir 			pResData->sId = sLocalId;
774*cdf0e10cSrcweir 			pResData->sResTyp = pStackData->sResTyp;
775*cdf0e10cSrcweir 		}
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir         //if ( nLangIndex.EqualsIgnoreCaseAscii("de") )
778*cdf0e10cSrcweir 		//	bGerman = sal_True;
779*cdf0e10cSrcweir 		if (( nLangIndex.EqualsIgnoreCaseAscii("en-US") ))
780*cdf0e10cSrcweir 			bEnglish = sal_True;
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 		PFormEntrys *pEntrys = pMergeDataFile->GetPFormEntrysCaseSensitive( pResData );
783*cdf0e10cSrcweir 		if ( pEntrys ) {
784*cdf0e10cSrcweir 			ByteString sContent;
785*cdf0e10cSrcweir             pEntrys->GetText( sContent, STRING_TYP_TEXT, nLangIndex );
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir 			if ( Export::isAllowed( nLangIndex ) &&
788*cdf0e10cSrcweir 				( sContent != "-" ) && ( sContent.Len()))
789*cdf0e10cSrcweir 			{
790*cdf0e10cSrcweir #ifdef MERGE_SOURCE_LANGUAGES
791*cdf0e10cSrcweir                     if( nLangIndex.EqualsIgnoreCaseAscii("de") || nLangIndex.EqualsIgnoreCaseAscii("en-US") )
792*cdf0e10cSrcweir                         rText = sContent;
793*cdf0e10cSrcweir #endif
794*cdf0e10cSrcweir                 Export::QuotHTML( rText );
795*cdf0e10cSrcweir 			}
796*cdf0e10cSrcweir 		}
797*cdf0e10cSrcweir 	}
798*cdf0e10cSrcweir }
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir /*****************************************************************************/
801*cdf0e10cSrcweir void CfgMerge::Output( const ByteString& rOutput )
802*cdf0e10cSrcweir /*****************************************************************************/
803*cdf0e10cSrcweir {
804*cdf0e10cSrcweir 	if ( pOutputStream )
805*cdf0e10cSrcweir 		pOutputStream->Write( rOutput.GetBuffer(), rOutput.Len());
806*cdf0e10cSrcweir }
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir sal_uLong CfgStack::Push( CfgStackData *pStackData )
809*cdf0e10cSrcweir {
810*cdf0e10cSrcweir     Insert( pStackData, LIST_APPEND );
811*cdf0e10cSrcweir     return Count() - 1;
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir /*****************************************************************************/
815*cdf0e10cSrcweir void CfgMerge::WorkOnRessourceEnd()
816*cdf0e10cSrcweir /*****************************************************************************/
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir 	if ( pMergeDataFile && pResData && bLocalize && (( bEnglish ) || bForce )) {
820*cdf0e10cSrcweir 		PFormEntrys *pEntrys = pMergeDataFile->GetPFormEntrysCaseSensitive( pResData );
821*cdf0e10cSrcweir 		if ( pEntrys ) {
822*cdf0e10cSrcweir             ByteString sCur;
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir             for( unsigned int n = 0; n < aLanguages.size(); n++ ){
825*cdf0e10cSrcweir                 sCur = aLanguages[ n ];
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir 				ByteString sContent;
828*cdf0e10cSrcweir                 pEntrys->GetText( sContent, STRING_TYP_TEXT, sCur , sal_True );
829*cdf0e10cSrcweir                 if (
830*cdf0e10cSrcweir                     // (!sCur.EqualsIgnoreCaseAscii("de") )    &&
831*cdf0e10cSrcweir 					( !sCur.EqualsIgnoreCaseAscii("en-US") ) &&
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 					( sContent != "-" ) && ( sContent.Len()))
834*cdf0e10cSrcweir 				{
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir 					ByteString sText = sContent;
837*cdf0e10cSrcweir                     Export::QuotHTML( sText );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir 					ByteString sAdditionalLine( "\t" );
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir 					ByteString sTextTag = pStackData->sTextTag;
842*cdf0e10cSrcweir 					ByteString sTemp = sTextTag.Copy( sTextTag.Search( "xml:lang=" ));
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir 					ByteString sSearch = sTemp.GetToken( 0, '\"' );
845*cdf0e10cSrcweir 					sSearch += "\"";
846*cdf0e10cSrcweir 					sSearch += sTemp.GetToken( 1, '\"' );
847*cdf0e10cSrcweir 					sSearch += "\"";
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 					ByteString sReplace = sTemp.GetToken( 0, '\"' );
850*cdf0e10cSrcweir 					sReplace += "\"";
851*cdf0e10cSrcweir                     sReplace += sCur;
852*cdf0e10cSrcweir 					sReplace += "\"";
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 					sTextTag.SearchAndReplace( sSearch, sReplace );
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 					sAdditionalLine += sTextTag;
857*cdf0e10cSrcweir 					sAdditionalLine += sText;
858*cdf0e10cSrcweir 					sAdditionalLine += pStackData->sEndTextTag;
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 					sAdditionalLine += "\n";
861*cdf0e10cSrcweir 					sAdditionalLine += sLastWhitespace;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir 					Output( sAdditionalLine );
864*cdf0e10cSrcweir 				}
865*cdf0e10cSrcweir 			}
866*cdf0e10cSrcweir 		}
867*cdf0e10cSrcweir 	}
868*cdf0e10cSrcweir 	delete pResData;
869*cdf0e10cSrcweir 	pResData = NULL;
870*cdf0e10cSrcweir 	bGerman = sal_False;
871*cdf0e10cSrcweir 	bEnglish = sal_False;
872*cdf0e10cSrcweir }
873