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