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