Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / idl / source / prj / database.cxx
blob3171197a1d07be2d717517aa6dd2c651fb1cc99c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <ctype.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <tools/fsys.hxx>
34 #include <tools/debug.hxx>
35 #include <database.hxx>
36 #include <globals.hxx>
37 #include <rtl/strbuf.hxx>
39 SvIdlDataBase::SvIdlDataBase( const SvCommand& rCmd )
40 : bExport( sal_False )
41 , nUniqueId( 0 )
42 , nVerbosity( rCmd.nVerbosity )
43 , bIsModified( sal_False )
44 , aPersStream( *IDLAPP->pClassMgr, NULL )
45 , pIdTable( NULL )
49 SvIdlDataBase::~SvIdlDataBase()
51 for ( size_t i = 0, n = aIdFileList.size(); i < n; ++i )
52 delete aIdFileList[ i ];
53 aIdFileList.clear();
55 delete pIdTable;
58 #define ADD_TYPE( Name, OdlName, ParserChar, CName, BasName, BasPost ) \
59 aTypeList.Append( new SvMetaType( SvHash_##Name()->GetName(), \
60 BasName, OdlName, ParserChar, CName, BasName, BasPost ) );
62 SvMetaTypeMemberList & SvIdlDataBase::GetTypeList()
64 if( aTypeList.Count() == 0 )
65 { // fill initially
66 aTypeList.Append( new SvMetaTypeString() );
67 aTypeList.Append( new SvMetaTypevoid() );
69 // MI: IDispatch::Invoke can not unsigned
70 ADD_TYPE( UINT16, "long", 'h', "unsigned short", "Long", "&" );
71 ADD_TYPE( INT16, "short", 'h', "short", "Integer", "%" );
72 ADD_TYPE( UINT32, "long", 'l', "unsigned long", "Long", "&" );
73 ADD_TYPE( INT32, "long", 'l', "long", "Long", "&" );
74 ADD_TYPE( int, "int", 'i', "int", "Integer", "%" );
75 ADD_TYPE( BOOL, "boolean", 'b', "unsigned char", "Boolean", "" );
76 ADD_TYPE( char, "char", 'c', "char", "Integer", "%" );
77 ADD_TYPE( BYTE, "char", 'c', "unsigned char", "Integer", "%" );
78 ADD_TYPE( float, "float", 'f', "float", "Single", "!" );
79 ADD_TYPE( double, "double", 'F', "double", "Double", "#" );
80 ADD_TYPE( SbxObject, "VARIANT", 'o', "C_Object", "Object", "" );
82 // Attention! When adding types all binary data bases get incompatible
85 return aTypeList;
88 SvMetaModule * SvIdlDataBase::GetModule( const rtl::OString& rName )
90 for( sal_uLong n = 0; n < aModuleList.Count(); n++ )
91 if( aModuleList.GetObject( n )->GetName().getString().equals(rName) )
92 return aModuleList.GetObject( n );
93 return NULL;
96 #define DATABASE_SIGNATURE (sal_uInt32)0x13B799F2
97 #define DATABASE_VER 0x0006
98 sal_Bool SvIdlDataBase::IsBinaryFormat( SvStream & rStm )
100 sal_uInt32 nSig = 0;
101 sal_uLong nPos = rStm.Tell();
102 rStm >> nSig;
103 rStm.Seek( nPos );
105 return nSig == DATABASE_SIGNATURE;
108 void SvIdlDataBase::Load( SvStream & rStm )
110 DBG_ASSERT( aTypeList.Count() == 0, "type list already initialized" );
111 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
113 sal_uInt16 nVersion = 0;
114 sal_uInt32 nSig = 0;
116 aPStm >> nSig;
117 aPStm >> nVersion;
118 if( nSig != DATABASE_SIGNATURE )
120 aPStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
121 return;
123 if( nVersion != DATABASE_VER )
125 aPStm.SetError( SVSTREAM_WRONGVERSION );
126 return;
128 aPStm >> aClassList;
129 aPStm >> aTypeList;
130 aPStm >> aAttrList;
131 aPStm >> aModuleList;
132 aPStm >> nUniqueId;
134 if( aPStm.IsEof() )
135 aPStm.SetError( SVSTREAM_GENERALERROR );
138 void SvIdlDataBase::Save( SvStream & rStm, sal_uInt32 nFlags )
140 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
141 aPStm.SetContextFlags( nFlags );
143 aPStm << (sal_uInt32)DATABASE_SIGNATURE;
144 aPStm << (sal_uInt16)DATABASE_VER;
146 sal_Bool bOnlyStreamedObjs = sal_False;
147 if( nFlags & IDL_WRITE_CALLING )
148 bOnlyStreamedObjs = sal_True;
150 if( bOnlyStreamedObjs )
152 SvMetaClassMemberList aList;
153 for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
155 SvMetaModule * pModule = GetModuleList().GetObject( n );
156 if( !pModule->IsImported() )
157 aList.Append( pModule->GetClassList() );
159 aPStm << aList;
161 else
162 aPStm << aClassList;
164 aTypeList.WriteObjects( aPStm, bOnlyStreamedObjs );
165 aAttrList.WriteObjects( aPStm, bOnlyStreamedObjs );
166 aModuleList.WriteObjects( aPStm, bOnlyStreamedObjs );
167 aPStm << nUniqueId;
170 void SvIdlDataBase::SetError( const rtl::OString& rError, SvToken * pTok )
172 if( pTok->GetLine() > 10000 )
173 aError.SetText( "hgchcg" );
175 if( aError.nLine < pTok->GetLine()
176 || (aError.nLine == pTok->GetLine() && aError.nColumn < pTok->GetColumn()) )
178 aError = SvIdlError( pTok->GetLine(), pTok->GetColumn() );
179 aError.SetText( rError );
183 void SvIdlDataBase::Push( SvMetaObject * pObj )
185 GetStack().Push( pObj );
188 sal_Bool SvIdlDataBase::FindId( const rtl::OString& rIdName, sal_uLong * pVal )
190 if( pIdTable )
192 sal_uInt32 nHash;
193 if( pIdTable->Test( rIdName, &nHash ) )
195 *pVal = pIdTable->Get( nHash )->GetValue();
196 return sal_True;
199 return sal_False;
202 sal_Bool SvIdlDataBase::InsertId( const rtl::OString& rIdName, sal_uLong nVal )
204 if( !pIdTable )
205 pIdTable = new SvStringHashTable( 20003 );
207 sal_uInt32 nHash;
208 if( pIdTable->Insert( rIdName, &nHash ) )
210 pIdTable->Get( nHash )->SetValue( nVal );
211 return sal_True;
213 return sal_False;
216 sal_Bool SvIdlDataBase::ReadIdFile( const String & rFileName )
218 DirEntry aFullName( rFileName );
219 aFullName.Find( GetPath() );
221 for ( size_t i = 0, n = aIdFileList.size(); i < n; ++i )
222 if ( *aIdFileList[ i ] == rFileName )
223 return sal_True;
225 aIdFileList.push_back( new String( rFileName ) );
227 this->AddDepFile(aFullName.GetFull());
228 SvTokenStream aTokStm( aFullName.GetFull() );
229 if( aTokStm.GetStream().GetError() == SVSTREAM_OK )
231 SvToken * pTok = aTokStm.GetToken_Next();
233 while( !pTok->IsEof() )
235 if( pTok->IsChar() && pTok->GetChar() == '#' )
237 pTok = aTokStm.GetToken_Next();
238 if( pTok->Is( SvHash_define() ) )
240 pTok = aTokStm.GetToken_Next();
241 rtl::OString aDefName;
242 if( pTok->IsIdentifier() )
243 aDefName = pTok->GetString();
244 else
246 rtl::OString aStr(RTL_CONSTASCII_STRINGPARAM(
247 "unexpected token after define"));
248 // set error
249 SetError( aStr, pTok );
250 WriteError( aTokStm );
251 return sal_False;
254 sal_uLong nVal = 0;
255 sal_Bool bOk = sal_True;
256 while( bOk )
258 pTok = aTokStm.GetToken_Next();
259 if( pTok->IsIdentifier() )
261 sal_uLong n;
262 if( FindId( pTok->GetString(), &n ) )
263 nVal += n;
264 else
265 bOk = sal_False;
267 else if( pTok->IsChar() )
269 if( pTok->GetChar() == '-'
270 || pTok->GetChar() == '/'
271 || pTok->GetChar() == '*'
272 || pTok->GetChar() == '&'
273 || pTok->GetChar() == '|'
274 || pTok->GetChar() == '^'
275 || pTok->GetChar() == '~' )
277 rtl::OStringBuffer aStr("unknown operator '");
278 aStr.append(pTok->GetChar());
279 aStr.append("'in define");
280 // set error
281 SetError( aStr.makeStringAndClear(), pTok );
282 WriteError( aTokStm );
283 return sal_False;
285 if( pTok->GetChar() != '+'
286 && pTok->GetChar() != '('
287 && pTok->GetChar() != ')' )
288 // only + is allowed, parentheses are immaterial
289 // because + is commutative
290 break;
292 else if( pTok->IsInteger() )
294 nVal += pTok->GetNumber();
296 else
297 break;
299 if( bOk )
301 if( !InsertId( aDefName, nVal ) )
303 rtl::OString aStr(RTL_CONSTASCII_STRINGPARAM("hash table overflow: "));
304 SetError( aStr, pTok );
305 WriteError( aTokStm );
306 return sal_False;
310 else if( pTok->Is( SvHash_include() ) )
312 pTok = aTokStm.GetToken_Next();
313 rtl::OStringBuffer aName;
314 if( pTok->IsString() )
315 aName.append(pTok->GetString());
316 else if( pTok->IsChar() && pTok->GetChar() == '<' )
318 pTok = aTokStm.GetToken_Next();
319 while( !pTok->IsEof()
320 && !(pTok->IsChar() && pTok->GetChar() == '>') )
322 aName.append(pTok->GetTokenAsString());
323 pTok = aTokStm.GetToken_Next();
325 if( pTok->IsEof() )
327 rtl::OString aStr(RTL_CONSTASCII_STRINGPARAM(
328 "unexpected eof in #include"));
329 // set error
330 SetError(aStr, pTok);
331 WriteError( aTokStm );
332 return sal_False;
335 if (!ReadIdFile(rtl::OStringToOUString(aName.toString(),
336 RTL_TEXTENCODING_ASCII_US)))
338 rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
339 "cannot read file: "));
340 aStr.append(aName.makeStringAndClear());
341 SetError(aStr.makeStringAndClear(), pTok);
342 WriteError( aTokStm );
343 return sal_False;
347 else
348 pTok = aTokStm.GetToken_Next();
351 else
352 return sal_False;
353 return sal_True;
356 SvMetaType * SvIdlDataBase::FindType( const SvMetaType * pPType,
357 SvMetaTypeMemberList & rList )
359 SvMetaType * pType = rList.First();
360 while( pType && pPType != pType )
361 pType = rList.Next();
362 return pType;
365 SvMetaType * SvIdlDataBase::FindType( const rtl::OString& rName )
367 SvMetaType * pType = aTypeList.First();
368 while( pType && !rName.equals(pType->GetName().getString()) )
369 pType = aTypeList.Next();
370 return pType;
373 SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
375 sal_Bool bIn = sal_False;
376 sal_Bool bOut = sal_False;
377 int nCall0 = CALL_VALUE;
378 int nCall1 = CALL_VALUE;
379 sal_Bool bSet = sal_False; // any attribute set
381 sal_uInt32 nTokPos = rInStm.Tell();
382 SvToken * pTok = rInStm.GetToken_Next();
384 if( pTok->HasHash() )
386 sal_uInt32 nBeginPos = 0; // can not happen with Tell
387 while( nBeginPos != rInStm.Tell() )
389 nBeginPos = rInStm.Tell();
390 if( pTok->Is( SvHash_in() ) )
392 bIn = sal_True;
393 pTok = rInStm.GetToken_Next();
394 bSet = sal_True;
396 if( pTok->Is( SvHash_out() ) )
398 bOut = sal_True;
399 pTok = rInStm.GetToken_Next();
400 bSet = sal_True;
402 if( pTok->Is( SvHash_inout() ) )
404 bIn = sal_True;
405 bOut = sal_True;
406 pTok = rInStm.GetToken_Next();
407 bSet = sal_True;
412 if( pTok->IsIdentifier() )
414 rtl::OString aName = pTok->GetString();
415 SvMetaTypeMemberList & rList = GetTypeList();
416 SvMetaType * pType = rList.First();
417 while( pType )
419 if( pType->GetName().getString().equals(aName) )
420 break;
421 pType = rList.Next();
423 if( pType )
425 pTok = rInStm.GetToken();
426 if( pTok->IsChar() )
428 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
430 nCall0 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
431 CALL_POINTER;
432 rInStm.GetToken_Next();
433 pTok = rInStm.GetToken();
434 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
436 nCall1 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
437 CALL_POINTER;
438 rInStm.GetToken_Next();
440 bSet = sal_True;
444 if( !bSet )
445 // is exactly this type
446 return pType;
448 DBG_ASSERT( aTmpTypeList.First(), "mindestens ein Element" );
449 SvMetaTypeRef xType = new SvMetaType( pType->GetName().getString(), 'h', "dummy" );
450 xType->SetRef( pType );
451 xType->SetIn( bIn );
452 xType->SetOut( bOut );
453 xType->SetCall0( nCall0 );
454 xType->SetCall1( nCall1 );
456 aTmpTypeList.Append( xType );
457 return xType;
460 rInStm.Seek( nTokPos );
461 return NULL;
464 SvMetaAttribute * SvIdlDataBase::ReadKnownAttr
466 SvTokenStream & rInStm,
467 SvMetaType * pType /* If pType == NULL, then the type has
468 still to be read. */
471 sal_uInt32 nTokPos = rInStm.Tell();
473 if( !pType )
474 pType = ReadKnownType( rInStm );
476 if( !pType )
478 // otherwise SlotId?
479 SvToken * pTok = rInStm.GetToken_Next();
480 if( pTok->IsIdentifier() )
482 sal_uLong n;
483 if( FindId( pTok->GetString(), &n ) )
485 for( sal_uLong i = 0; i < aAttrList.Count(); i++ )
487 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
488 if( pAttr->GetSlotId().getString().equals(pTok->GetString()) )
489 return pAttr;
493 rtl::OStringBuffer aStr("Nicht gefunden : ");
494 aStr.append(pTok->GetString());
495 OSL_FAIL(aStr.getStr());
499 rInStm.Seek( nTokPos );
500 return NULL;
503 SvMetaAttribute* SvIdlDataBase::SearchKnownAttr
505 const SvNumberIdentifier& rId
508 sal_uLong n;
509 if( FindId( rId.getString(), &n ) )
511 for( sal_uLong i = 0; i < aAttrList.Count(); i++ )
513 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
514 if( pAttr->GetSlotId().getString() == rId.getString() )
515 return pAttr;
519 return NULL;
522 SvMetaClass * SvIdlDataBase::ReadKnownClass( SvTokenStream & rInStm )
524 sal_uInt32 nTokPos = rInStm.Tell();
525 SvToken * pTok = rInStm.GetToken_Next();
527 if( pTok->IsIdentifier() )
528 for( sal_uLong n = 0; n < aClassList.Count(); n++ )
530 SvMetaClass * pClass = aClassList.GetObject( n );
531 if( pClass->GetName().getString().equals(pTok->GetString()) )
532 return pClass;
535 rInStm.Seek( nTokPos );
536 return NULL;
539 void SvIdlDataBase::Write(const rtl::OString& rText)
541 if( nVerbosity != 0 )
542 fprintf( stdout, "%s", rText.getStr() );
545 void SvIdlDataBase::WriteError( const rtl::OString& rErrWrn,
546 const rtl::OString& rFileName,
547 const rtl::OString& rErrorText,
548 sal_uLong nRow, sal_uLong nColumn ) const
550 // error treatment
551 fprintf( stderr, "\n%s --- %s: ( %ld, %ld )\n",
552 rFileName.getStr(), rErrWrn.getStr(), nRow, nColumn );
554 if( !rErrorText.isEmpty() )
555 { // error set
556 fprintf( stderr, "\t%s\n", rErrorText.getStr() );
560 void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
562 // error treatment
563 String aFileName( rInStm.GetFileName() );
564 rtl::OStringBuffer aErrorText;
565 sal_uLong nRow = 0, nColumn = 0;
567 rInStm.SeekEnd();
568 SvToken *pTok = rInStm.GetToken();
570 // error position
571 nRow = pTok->GetLine();
572 nColumn = pTok->GetColumn();
574 if( aError.IsError() )
575 { // error set
576 // search error token
577 // error text
578 if( !aError.GetText().isEmpty() )
580 aErrorText.append(RTL_CONSTASCII_STRINGPARAM("may be <"));
581 aErrorText.append(aError.GetText());
583 SvToken * pPrevTok = NULL;
584 while( pTok != pPrevTok )
586 pPrevTok = pTok;
587 if( pTok->GetLine() == aError.nLine
588 && pTok->GetColumn() == aError.nColumn )
589 break;
590 pTok = rInStm.GetToken_PrevAll();
593 // error position
594 aErrorText.append(RTL_CONSTASCII_STRINGPARAM("> at ( "));
595 aErrorText.append(static_cast<sal_Int64>(aError.nLine));
596 aErrorText.append(RTL_CONSTASCII_STRINGPARAM(", "));
597 aErrorText.append(static_cast<sal_Int64>(aError.nColumn));
598 aErrorText.append(RTL_CONSTASCII_STRINGPARAM(" )"));
600 // reset error
601 aError = SvIdlError();
604 WriteError("error", rtl::OUStringToOString(aFileName,
605 RTL_TEXTENCODING_UTF8), aErrorText.makeStringAndClear(), nRow, nColumn);
607 DBG_ASSERT( pTok, "token must be found" );
608 if( !pTok )
609 return;
611 // look for identifier close by
612 if( !pTok->IsIdentifier() )
614 rInStm.GetToken_PrevAll();
615 pTok = rInStm.GetToken();
617 if( pTok && pTok->IsIdentifier() )
619 rtl::OString aN = IDLAPP->pHashTable->GetNearString( pTok->GetString() );
620 if( !aN.isEmpty() )
621 fprintf( stderr, "%s versus %s\n", pTok->GetString().getStr(), aN.getStr() );
625 SvIdlWorkingBase::SvIdlWorkingBase(const SvCommand& rCmd) : SvIdlDataBase(rCmd)
629 sal_Bool SvIdlWorkingBase::ReadSvIdl( SvTokenStream & rInStm, sal_Bool bImported, const String & rPath )
631 aPath = rPath; // only valid for this iteration
632 SvToken * pTok;
633 sal_Bool bOk = sal_True;
634 pTok = rInStm.GetToken();
635 // only one import at the very beginning
636 if( pTok->Is( SvHash_import() ) )
638 rInStm.GetToken_Next();
639 rInStm.Read( '(' ); // optional
640 pTok = rInStm.GetToken_Next();
641 if( pTok->IsString() )
643 DirEntry aFullName( String::CreateFromAscii( pTok->GetString().getStr() ) );
644 if( aFullName.Find( rPath ) )
646 this->AddDepFile(aFullName.GetFull());
647 SvFileStream aStm( aFullName.GetFull(),
648 STREAM_STD_READ | STREAM_NOCREATE );
649 Load( aStm );
650 if( aStm.GetError() != SVSTREAM_OK )
652 if( aStm.GetError() == SVSTREAM_WRONGVERSION )
654 rtl::OStringBuffer aStr("wrong version, file ");
655 aStr.append(rtl::OUStringToOString(
656 aFullName.GetFull(), RTL_TEXTENCODING_UTF8));
657 SetError(aStr.makeStringAndClear(), pTok);
658 WriteError( rInStm );
659 bOk = sal_False;
661 else
663 aStm.Seek( 0 );
664 aStm.ResetError();
665 SvTokenStream aTokStm( aStm, aFullName.GetFull() );
666 bOk = ReadSvIdl( aTokStm, sal_True, rPath );
670 else
671 bOk = sal_False;
673 else
674 bOk = sal_False;
677 sal_uInt32 nBeginPos = 0xFFFFFFFF; // can not happen with Tell
679 while( bOk && nBeginPos != rInStm.Tell() )
681 nBeginPos = rInStm.Tell();
682 pTok = rInStm.GetToken();
683 if( pTok->IsEof() )
684 return sal_True;
685 if( pTok->IsEmpty() )
686 bOk = sal_False;
688 // only one import at the very beginning
689 if( pTok->Is( SvHash_module() ) )
691 SvMetaModuleRef aModule = new SvMetaModule( rInStm.GetFileName(), bImported );
692 if( aModule->ReadSvIdl( *this, rInStm ) )
693 GetModuleList().Append( aModule );
694 else
695 bOk = sal_False;
697 else
698 bOk = sal_False;
700 if( !bOk || !pTok->IsEof() )
702 // error treatment
703 WriteError( rInStm );
704 return sal_False;
706 return sal_True;
709 sal_Bool SvIdlWorkingBase::WriteSvIdl( SvStream & rOutStm )
711 if( rOutStm.GetError() != SVSTREAM_OK )
712 return sal_False;
714 SvStringHashList aList;
715 if( GetIdTable() )
717 GetIdTable()->FillHashList( &aList );
718 for ( size_t i = 0, n = aList.size(); i < n; ++i )
720 SvStringHashEntry* pEntry = aList[ i ];
721 rOutStm << "#define " << pEntry->GetName().getStr()
722 << '\t'
723 << rtl::OString::valueOf(static_cast<sal_Int64>(
724 pEntry->GetValue())).getStr()
725 << endl;
729 for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
731 SvMetaModule * pModule = GetModuleList().GetObject( n );
732 pModule->WriteSvIdl( *this, rOutStm, 0 );
734 return sal_True;
737 sal_Bool SvIdlWorkingBase::WriteSfx( SvStream & rOutStm )
739 if( rOutStm.GetError() != SVSTREAM_OK )
740 return sal_False;
742 // reset all tmp variables for writing
743 WriteReset();
744 SvMemoryStream aTmpStm( 256000, 256000 );
745 sal_uLong n;
746 for( n = 0; n < GetModuleList().Count(); n++ )
748 SvMetaModule * pModule = GetModuleList().GetObject( n );
749 if( !pModule->IsImported() )
750 pModule->WriteSfx( *this, aTmpStm );
751 aTmpStm.Seek( 0 );
753 for( n = 0; n < aUsedTypes.Count(); n++ )
755 SvMetaType * pType = aUsedTypes.GetObject( n );
756 pType->WriteSfx( *this, rOutStm );
758 aUsedTypes.Clear();
759 rOutStm << aTmpStm;
760 return sal_True;
763 sal_Bool SvIdlWorkingBase::WriteHelpIds( SvStream& rOutStm )
765 if( rOutStm.GetError() != SVSTREAM_OK )
766 return sal_False;
768 HelpIdTable aIdTable;
769 sal_uLong n;
770 for( n = 0; n < GetModuleList().Count(); n++ )
772 SvMetaModule * pModule = GetModuleList().GetObject( n );
773 pModule->WriteHelpIds( *this, rOutStm, aIdTable );
776 const SvMetaAttributeMemberList & rAttrList = GetAttrList();
777 for( n = 0; n < rAttrList.Count(); n++ )
779 SvMetaAttribute * pAttr = rAttrList.GetObject( n );
780 pAttr->WriteHelpId( *this, rOutStm, aIdTable );
783 return sal_True;
786 sal_Bool SvIdlWorkingBase::WriteSfxItem( SvStream & )
788 return sal_False;
791 void SvIdlDataBase::StartNewFile( const String& rName )
793 bExport = ( aExportFile.EqualsIgnoreCaseAscii( rName ) );
796 void SvIdlDataBase::AppendAttr( SvMetaAttribute *pAttr )
798 aAttrList.Append( pAttr );
799 if ( bExport )
800 pAttr->SetNewAttribute( sal_True );
803 sal_Bool SvIdlWorkingBase::WriteCSV( SvStream& rStrm )
805 SvMetaAttributeMemberList &rList = GetAttrList();
806 sal_uLong nCount = rList.Count();
807 for ( sal_uLong n=0; n<nCount; n++ )
809 if ( rList.GetObject(n)->IsNewAttribute() )
811 rList.GetObject(n)->WriteCSV( *this, rStrm );
815 if ( rStrm.GetError() != SVSTREAM_OK )
816 return sal_False;
817 else
818 return sal_True;
821 sal_Bool SvIdlWorkingBase::WriteDocumentation( SvStream & rOutStm )
823 if( rOutStm.GetError() != SVSTREAM_OK )
824 return sal_False;
826 for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
828 SvMetaModule * pModule = GetModuleList().GetObject( n );
829 if( !pModule->IsImported() )
830 pModule->Write( *this, rOutStm, 0, WRITE_DOCU );
832 return sal_True;
835 void SvIdlDataBase::AddDepFile(String const& rFileName)
837 m_DepFiles.insert(rFileName);
840 #ifdef WNT
841 static ::rtl::OString
842 lcl_ConvertToCygwin(::rtl::OString const& rString)
844 sal_Int32 i = 0;
845 sal_Int32 const len = rString.getLength();
846 ::rtl::OStringBuffer buf(len + 16);
847 if ((2 <= len) && (':' == rString[1]))
849 buf.append("/cygdrive/");
850 buf.append(static_cast<sal_Char>(tolower(rString[0])));
851 i = 2;
853 for (; i < len; ++i)
855 sal_Char const c(rString[i]);
856 switch (c)
858 case '\\':
859 buf.append('/');
860 break;
861 case ' ':
862 buf.append("\\ ");
863 break;
864 default:
865 buf.append(c);
866 break;
869 return buf.makeStringAndClear();
871 #endif
873 static ::rtl::OString
874 lcl_Convert(::rtl::OUString const& rString)
876 return
877 #ifdef WNT
878 lcl_ConvertToCygwin
879 #endif
880 (::rtl::OUStringToOString(rString, RTL_TEXTENCODING_UTF8));
883 struct WriteDep
885 SvFileStream & m_rStream;
886 explicit WriteDep(SvFileStream & rStream) : m_rStream(rStream) { }
887 void operator() (::rtl::OUString const& rItem)
889 m_rStream << " \\\n ";
890 m_rStream << lcl_Convert(rItem).getStr();
894 bool SvIdlDataBase::WriteDepFile(
895 SvFileStream & rStream, ::rtl::OUString const& rTarget)
897 rStream << lcl_Convert(rTarget).getStr();
898 rStream << " :";
899 ::std::for_each(m_DepFiles.begin(), m_DepFiles.end(), WriteDep(rStream));
900 return rStream.GetError() == SVSTREAM_OK;
903 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */