update dev300-m58
[ooovba.git] / idl / source / prj / database.cxx
blob36aeae40f68b927598a6f9888cf4417abeda0204
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: database.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idl.hxx"
34 #include <ctype.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <tools/fsys.hxx>
38 #include <tools/debug.hxx>
39 #include <database.hxx>
40 #include <globals.hxx>
42 /****************** SvIdlDataBase ****************************************/
43 /*************************************************************************
44 |* SvIdlDataBase::SvIdlDataBase()
46 |* Beschreibung
47 *************************************************************************/
49 void PrimeNumber(){
50 USHORT i, n;
51 for( i = 5001; i < 5500; i += 2 ){
52 for( n = 2; n < i && ((i % n) != 0); n++ );
53 if( n == i ){
54 printf( "\nPrimzahl: %d\n", i );
55 return;
61 SvIdlDataBase::SvIdlDataBase()
62 : bExport( FALSE )
63 , nUniqueId( 0 )
64 , bIsModified( FALSE )
65 , aPersStream( *IDLAPP->pClassMgr, NULL )
66 , pIdTable( NULL )
68 //PrimeNumber();
71 /*************************************************************************
72 |* SvIdlDataBase::~SvIdlDataBase()
74 |* Beschreibung
75 *************************************************************************/
76 SvIdlDataBase::~SvIdlDataBase()
78 String * pStr = aIdFileList.First();
79 while( pStr )
81 delete pStr;
82 pStr = aIdFileList.Next();
84 delete pIdTable;
87 /*************************************************************************
88 |* SvIdlDataBase::GetTypeList()
90 |* Beschreibung
91 *************************************************************************/
92 #define ADD_TYPE( Name, OdlName, ParserChar, CName, BasName, BasPost ) \
93 aTypeList.Append( new SvMetaType( SvHash_##Name()->GetName(), \
94 BasName, OdlName, ParserChar, CName, BasName, BasPost ) );
96 SvMetaTypeMemberList & SvIdlDataBase::GetTypeList()
98 if( aTypeList.Count() == 0 )
99 { // Initial fuellen
100 aTypeList.Append( new SvMetaTypeString() );
101 aTypeList.Append( new SvMetaTypevoid() );
103 // MI: IDispatch::Invoke kann keine unsigned
104 ADD_TYPE( UINT16, "long", 'h', "unsigned short", "Long", "&" );
105 ADD_TYPE( INT16, "short", 'h', "short", "Integer", "%" );
106 ADD_TYPE( UINT32, "long", 'l', "unsigned long", "Long", "&" );
107 ADD_TYPE( INT32, "long", 'l', "long", "Long", "&" );
108 ADD_TYPE( int, "int", 'i', "int", "Integer", "%" );
109 ADD_TYPE( BOOL, "boolean", 'b', "unsigned char", "Boolean", "" );
110 ADD_TYPE( char, "char", 'c', "char", "Integer", "%" );
111 ADD_TYPE( BYTE, "char", 'c', "unsigned char", "Integer", "%" );
112 ADD_TYPE( float, "float", 'f', "float", "Single", "!" );
113 ADD_TYPE( double, "double", 'F', "double", "Double", "#" );
114 ADD_TYPE( SbxObject, "VARIANT", 'o', "C_Object", "Object", "" );
116 // A c h t u n g !!!, bei hinzufuegen von Typen werden alle
117 // bin„ren Datenbasen inkompatibel
120 // So tun als ob die Init-Daten auf einem Stream gelesen wurden
121 SvMemoryStream aStm;
122 aPersStream.SetStream( &aStm );
123 // Alle Init-Daten Streamen
124 aPersStream << aTypeList;
125 // Nur die Id-Zuordnung merken
126 aPersStream.SetStream( NULL );
129 return aTypeList;
132 /*************************************************************************
134 |* SvIdlDataBase::GetModuleInfo()
136 |* Beschreibung
137 |* Ersterstellung MM 13.12.94
138 |* Letzte Aenderung MM 13.12.94
140 *************************************************************************/
141 SvMetaModule * SvIdlDataBase::GetModule( const ByteString & rName )
143 for( ULONG n = 0; n < aModuleList.Count(); n++ )
144 if( aModuleList.GetObject( n )->GetName() == rName )
145 return aModuleList.GetObject( n );
146 return NULL;
149 /*************************************************************************
151 |* SvIdlDataBase::IsBinaryFormat()
153 |* Beschreibung
155 *************************************************************************/
156 #define DATABASE_SIGNATURE (UINT32)0x13B799F2
157 #define DATABASE_VER 0x0006
158 BOOL SvIdlDataBase::IsBinaryFormat( SvStream & rStm )
160 UINT32 nSig = 0;
161 ULONG nPos = rStm.Tell();
162 rStm >> nSig;
163 rStm.Seek( nPos );
165 return nSig == DATABASE_SIGNATURE;
168 /*************************************************************************
170 |* SvIdlDataBase::Load()
172 |* Beschreibung
174 *************************************************************************/
175 void SvIdlDataBase::Load( SvStream & rStm )
177 DBG_ASSERT( aTypeList.Count() == 0, "type list already initialized" );
178 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
180 USHORT nVersion = 0;
181 UINT32 nSig = 0;
183 aPStm >> nSig;
184 aPStm >> nVersion;
185 if( nSig != DATABASE_SIGNATURE )
187 aPStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
188 return;
190 if( nVersion != DATABASE_VER )
192 aPStm.SetError( SVSTREAM_WRONGVERSION );
193 return;
195 aPStm >> aClassList;
196 aPStm >> aTypeList;
197 aPStm >> aAttrList;
198 aPStm >> aModuleList;
199 aPStm >> nUniqueId;
201 if( aPStm.IsEof() )
202 aPStm.SetError( SVSTREAM_GENERALERROR );
205 /*************************************************************************
206 |* SvIdlDataBase::Save()
208 |* Beschreibung
209 *************************************************************************/
210 void SvIdlDataBase::Save( SvStream & rStm, UINT32 nFlags )
212 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
213 aPStm.SetContextFlags( nFlags );
215 aPStm << (UINT32)DATABASE_SIGNATURE;
216 aPStm << (USHORT)DATABASE_VER;
218 BOOL bOnlyStreamedObjs = FALSE;
219 if( nFlags & IDL_WRITE_CALLING )
220 bOnlyStreamedObjs = TRUE;
222 if( bOnlyStreamedObjs )
224 SvMetaClassMemberList aList;
225 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
227 SvMetaModule * pModule = GetModuleList().GetObject( n );
228 if( !pModule->IsImported() )
229 aList.Append( pModule->GetClassList() );
231 aPStm << aList;
233 else
234 aPStm << aClassList;
236 //aClassList.WriteObjects( aPStm, bOnlyStreamedObjs );
237 aTypeList.WriteObjects( aPStm, bOnlyStreamedObjs );
238 aAttrList.WriteObjects( aPStm, bOnlyStreamedObjs );
239 aModuleList.WriteObjects( aPStm, bOnlyStreamedObjs );
240 aPStm << nUniqueId;
243 /*************************************************************************
244 |* SvIdlDataBase::SetError()
246 |* Beschreibung
247 *************************************************************************/
248 void SvIdlDataBase::SetError( const ByteString & rError, SvToken * pTok )
250 if( pTok->GetLine() > 10000 )
251 aError.SetText( "hgchcg" );
253 if( aError.nLine < pTok->GetLine()
254 || (aError.nLine == pTok->GetLine() && aError.nColumn < pTok->GetColumn()) )
256 aError = SvIdlError( pTok->GetLine(), pTok->GetColumn() );
257 aError.SetText( rError );
261 /*************************************************************************
262 |* SvIdlDataBase::Push()
264 |* Beschreibung
265 *************************************************************************/
266 void SvIdlDataBase::Push( SvMetaObject * pObj )
268 GetStack().Push( pObj );
271 #ifdef IDL_COMPILER
272 /*************************************************************************
274 |* SvIdlDataBase::FindId()
276 |* Beschreibung
278 *************************************************************************/
279 BOOL SvIdlDataBase::FindId( const ByteString & rIdName, ULONG * pVal )
281 if( pIdTable )
283 UINT32 nHash;
284 if( pIdTable->Test( rIdName, &nHash ) )
286 *pVal = pIdTable->Get( nHash )->GetValue();
287 return TRUE;
290 return FALSE;
293 /*************************************************************************
295 |* SvIdlDataBase::InsertId()
297 |* Beschreibung
299 *************************************************************************/
300 BOOL SvIdlDataBase::InsertId( const ByteString & rIdName, ULONG nVal )
302 if( !pIdTable )
303 pIdTable = new SvStringHashTable( 20003 );
305 UINT32 nHash;
306 if( pIdTable->Insert( rIdName, &nHash ) )
308 pIdTable->Get( nHash )->SetValue( nVal );
309 return TRUE;
311 return FALSE;
314 /*************************************************************************
315 |* SvIdlDataBase::ReadIdFile()
317 |* Beschreibung
318 *************************************************************************/
319 BOOL SvIdlDataBase::ReadIdFile( const String & rFileName )
321 DirEntry aFullName( rFileName );
322 aFullName.Find( GetPath() );
324 String * pIdFile = aIdFileList.First();
325 while( pIdFile )
327 if( *pIdFile == rFileName )
328 return TRUE; // schon eingelesen
329 pIdFile = aIdFileList.Next();
332 aIdFileList.Insert( new String( rFileName ), LIST_APPEND );
334 SvTokenStream aTokStm( aFullName.GetFull() );
335 if( aTokStm.GetStream().GetError() == SVSTREAM_OK )
337 SvToken * pTok = aTokStm.GetToken_Next();
339 while( !pTok->IsEof() )
341 if( pTok->IsChar() && pTok->GetChar() == '#' )
343 pTok = aTokStm.GetToken_Next();
344 if( pTok->Is( SvHash_define() ) )
346 pTok = aTokStm.GetToken_Next();
347 ByteString aDefName;
348 if( pTok->IsIdentifier() )
349 aDefName = pTok->GetString();
350 else
352 ByteString aStr( "unexpected token after define" );
353 // Fehler setzen
354 SetError( aStr, pTok );
355 WriteError( aTokStm );
356 return FALSE;
359 ULONG nVal = 0;
360 BOOL bOk = TRUE;
361 while( bOk )
363 pTok = aTokStm.GetToken_Next();
364 if( pTok->IsIdentifier() )
366 ULONG n;
367 if( FindId( pTok->GetString(), &n ) )
368 nVal += n;
369 else
370 bOk = FALSE;
372 else if( pTok->IsChar() )
374 if( pTok->GetChar() == '-'
375 || pTok->GetChar() == '/'
376 || pTok->GetChar() == '*'
377 || pTok->GetChar() == '&'
378 || pTok->GetChar() == '|'
379 || pTok->GetChar() == '^'
380 || pTok->GetChar() == '~' )
382 ByteString aStr( "unknown operator '" );
383 aStr += pTok->GetChar();
384 aStr += "'in define";
385 // Fehler setzen
386 SetError( aStr, pTok );
387 WriteError( aTokStm );
388 return FALSE;
390 if( pTok->GetChar() != '+'
391 && pTok->GetChar() != '('
392 && pTok->GetChar() != ')' )
393 // nur + erlaubt, Klammern spielen kein Rolle,
394 // da + komutativ ist
395 break;
397 else if( pTok->IsInteger() )
399 nVal += pTok->GetNumber();
401 else
402 break;
404 if( bOk )
406 if( !InsertId( aDefName, nVal ) )
408 ByteString aStr = "hash table overflow: ";
409 SetError( aStr, pTok );
410 WriteError( aTokStm );
411 return FALSE;
415 else if( pTok->Is( SvHash_include() ) )
417 pTok = aTokStm.GetToken_Next();
418 ByteString aName;
419 if( pTok->IsString() )
420 aName = pTok->GetString();
421 else if( pTok->IsChar() && pTok->GetChar() == '<' )
423 pTok = aTokStm.GetToken_Next();
424 while( !pTok->IsEof()
425 && !(pTok->IsChar() && pTok->GetChar() == '>') )
427 aName += pTok->GetTokenAsString();
428 pTok = aTokStm.GetToken_Next();
430 if( pTok->IsEof() )
432 ByteString aStr( "unexpected eof in #include" );
433 // Fehler setzen
434 SetError( aStr, pTok );
435 WriteError( aTokStm );
436 return FALSE;
439 if( !ReadIdFile( String::CreateFromAscii(aName.GetBuffer()) ) )
441 ByteString aStr = "cannot read file: ";
442 aStr += aName;
443 SetError( aStr, pTok );
444 WriteError( aTokStm );
445 return FALSE;
449 else
450 pTok = aTokStm.GetToken_Next();
453 else
454 return FALSE;
455 return TRUE;
458 /*************************************************************************
459 |* SvIdlDataBase::FindType()
461 |* Beschreibung
462 *************************************************************************/
463 SvMetaType * SvIdlDataBase::FindType( const SvMetaType * pPType,
464 SvMetaTypeMemberList & rList )
466 SvMetaType * pType = rList.First();
467 while( pType && pPType != pType )
468 pType = rList.Next();
469 return pType;
472 SvMetaType * SvIdlDataBase::FindType( const ByteString & rName )
474 SvMetaType * pType = aTypeList.First();
475 while( pType && rName != pType->GetName() )
476 pType = aTypeList.Next();
477 return pType;
480 /*************************************************************************
481 |* SvIdlDataBase::ReadKnownType()
483 |* Beschreibung
484 *************************************************************************/
485 SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
487 BOOL bIn = FALSE;
488 BOOL bOut = FALSE;
489 int nCall0 = CALL_VALUE;
490 int nCall1 = CALL_VALUE;
491 BOOL bSet = FALSE; //irgent ein Attribut gesetzt
493 UINT32 nTokPos = rInStm.Tell();
494 SvToken * pTok = rInStm.GetToken_Next();
496 if( pTok->HasHash() )
498 UINT32 nBeginPos = 0; // kann mit Tell nicht vorkommen
499 while( nBeginPos != rInStm.Tell() )
501 nBeginPos = rInStm.Tell();
502 if( pTok->Is( SvHash_in() ) )
504 bIn = TRUE;
505 pTok = rInStm.GetToken_Next();
506 bSet = TRUE;
508 if( pTok->Is( SvHash_out() ) )
510 bOut = TRUE;
511 pTok = rInStm.GetToken_Next();
512 bSet = TRUE;
514 if( pTok->Is( SvHash_inout() ) )
516 bIn = TRUE;
517 bOut = TRUE;
518 pTok = rInStm.GetToken_Next();
519 bSet = TRUE;
524 SvMetaTypeList aTmpTypeList;
525 if( FillTypeList( aTmpTypeList, pTok ) )
527 if( pTok->IsIdentifier() )
529 ByteString aName = pTok->GetString();
530 SvMetaTypeMemberList & rList = GetTypeList();
531 SvMetaType * pType = rList.First();
532 while( pType )
534 if( pType->GetName() == aName )
535 break;
536 pType = rList.Next();
538 if( pType )
540 pTok = rInStm.GetToken();
541 if( pTok->IsChar() )
543 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
545 nCall0 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
546 CALL_POINTER;
547 rInStm.GetToken_Next();
548 pTok = rInStm.GetToken();
549 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
551 nCall1 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
552 CALL_POINTER;
553 rInStm.GetToken_Next();
555 bSet = TRUE;
559 SvMetaType * pMetaType = aTmpTypeList.First();
560 while( pMetaType )
562 if( pMetaType->GetIn() == bIn
563 && pMetaType->GetOut() == bOut
564 && pMetaType->GetCall0() == nCall0
565 && pMetaType->GetCall1() == nCall1 )
567 return pMetaType;
569 pMetaType = aTmpTypeList.Next();
572 //SvMetaType * pType = aTmpTypeList.First();
573 if( !bSet )
574 // Ist genau dieser Typ
575 return pType;
577 DBG_ASSERT( aTmpTypeList.First(), "mindestens ein Element" );
578 SvMetaTypeRef xType = new SvMetaType( pType->GetName(), 'h', "dummy" );
579 xType->SetRef( pType );
580 xType->SetIn( bIn );
581 xType->SetOut( bOut );
582 xType->SetCall0( nCall0 );
583 xType->SetCall1( nCall1 );
585 aTmpTypeList.Append( xType );
586 return xType;
589 rInStm.Seek( nTokPos );
590 return NULL;
593 /*************************************************************************
595 |* SvIdlDataBase::ReadKnownAttr()
597 |* Beschreibung
599 *************************************************************************/
600 SvMetaAttribute * SvIdlDataBase::ReadKnownAttr
602 SvTokenStream & rInStm,
603 SvMetaType * pType /* Wenn der pType == NULL, dann muss der Typ
604 noch gelesen werden. */
607 UINT32 nTokPos = rInStm.Tell();
609 if( !pType )
610 pType = ReadKnownType( rInStm );
612 if( pType )
614 // Wenn wir Slots auf die Wiese stellen, d"urfen wir nicht voraussetzen,
615 // da\s jeder Slot einen anderen Namen hat!
617 SvToken * pTok = rInStm.GetToken_Next();
618 if( pTok->IsIdentifier() )
619 for( ULONG n = 0; n < aAttrList.Count(); n++ )
621 SvMetaAttribute * pAttr = aAttrList.GetObject( n );
622 if( pAttr->GetName() == pTok->GetString() )
623 return pAttr;
627 else
629 // sonst SlotId?
630 SvToken * pTok = rInStm.GetToken_Next();
631 if( pTok->IsIdentifier() )
633 ULONG n;
634 if( FindId( pTok->GetString(), &n ) )
636 for( ULONG i = 0; i < aAttrList.Count(); i++ )
638 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
639 if( pAttr->GetSlotId() == pTok->GetString() )
640 return pAttr;
644 ByteString aStr( "Nicht gefunden : " );
645 aStr += pTok->GetString();
646 DBG_ERROR( aStr.GetBuffer() );
650 rInStm.Seek( nTokPos );
651 return NULL;
654 SvMetaAttribute* SvIdlDataBase::SearchKnownAttr
656 const SvNumberIdentifier& rId
659 ULONG n;
660 if( FindId( rId, &n ) )
662 for( ULONG i = 0; i < aAttrList.Count(); i++ )
664 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
665 if( pAttr->GetSlotId() == rId )
666 return pAttr;
670 return NULL;
673 /*************************************************************************
674 |* SvIdlDataBase::ReadKnownClass()
676 |* Beschreibung
677 *************************************************************************/
678 SvMetaClass * SvIdlDataBase::ReadKnownClass( SvTokenStream & rInStm )
680 UINT32 nTokPos = rInStm.Tell();
681 SvToken * pTok = rInStm.GetToken_Next();
683 if( pTok->IsIdentifier() )
684 for( ULONG n = 0; n < aClassList.Count(); n++ )
686 SvMetaClass * pClass = aClassList.GetObject( n );
687 if( pClass->GetName() == pTok->GetString() )
688 return pClass;
691 rInStm.Seek( nTokPos );
692 return NULL;
695 /*************************************************************************
696 |* SvIdlDataBase::Write()
698 |* Beschreibung
699 *************************************************************************/
700 void SvIdlDataBase::Write( const ByteString & rText )
702 #ifndef W31
703 fprintf( stdout, "%s", rText.GetBuffer() );
704 #endif
707 /*************************************************************************
708 |* SvIdlDataBase::WriteError()
710 |* Beschreibung
711 *************************************************************************/
712 void SvIdlDataBase::WriteError( const ByteString & rErrWrn,
713 const ByteString & rFileName,
714 const ByteString & rErrorText,
715 ULONG nRow, ULONG nColumn ) const
717 //Fehlerbehandlung
718 #ifndef W31
719 fprintf( stderr, "\n%s --- %s: ( %ld, %ld )\n",
720 rFileName.GetBuffer(), rErrWrn.GetBuffer(), nRow, nColumn );
722 if( rErrorText.Len() )
723 { // Fehler gesetzt
724 fprintf( stderr, "\t%s\n", rErrorText.GetBuffer() );
726 #endif
729 /*************************************************************************
730 |* SvIdlDataBase::WriteError()
732 |* Beschreibung
733 *************************************************************************/
734 void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
736 //Fehlerbehandlung
737 #ifndef W31
738 String aFileName( rInStm.GetFileName() );
739 ByteString aErrorText;
740 ULONG nRow = 0, nColumn = 0;
742 rInStm.SeekEnd();
743 SvToken *pTok = rInStm.GetToken();
745 // Fehlerposition
746 nRow = pTok->GetLine();
747 nColumn = pTok->GetColumn();
749 if( aError.IsError() )
750 { // Fehler gesetzt
751 // Fehler Token suchen
752 // Fehlertext
753 if( aError.GetText().Len() )
755 aErrorText = "may be <";
756 aErrorText += aError.GetText();
758 SvToken * pPrevTok = NULL;
759 while( pTok != pPrevTok )
761 pPrevTok = pTok;
762 if( pTok->GetLine() == aError.nLine
763 && pTok->GetColumn() == aError.nColumn )
764 break;
765 pTok = rInStm.GetToken_PrevAll();
768 // Fehlerposition
769 aErrorText += "> at ( ";
770 aErrorText += ByteString::CreateFromInt64(aError.nLine);
771 aErrorText += ", ";
772 aErrorText += ByteString::CreateFromInt64(aError.nColumn);
773 aErrorText += " )";
775 // Fehler zuruecksetzen
776 aError = SvIdlError();
779 WriteError( "error", ByteString( aFileName, RTL_TEXTENCODING_UTF8 ), aErrorText, nRow, nColumn );
781 DBG_ASSERT( pTok, "token must be found" );
782 if( !pTok )
783 return;
785 // Identifier in der Naehe suchen
786 if( !pTok->IsIdentifier() )
788 rInStm.GetToken_PrevAll();
789 pTok = rInStm.GetToken();
791 if( pTok && pTok->IsIdentifier() )
793 ByteString aN = IDLAPP->pHashTable->GetNearString( pTok->GetString() );
794 if( aN.Len() )
795 fprintf( stderr, "%s versus %s\n", pTok->GetString().GetBuffer(), aN.GetBuffer() );
797 #endif
800 /****************** SvIdlWorkingBase ****************************************/
801 /*************************************************************************
802 |* SvIdlWorkingBase::SvIdlWorkingBase()
804 |* Beschreibung
805 *************************************************************************/
806 SvIdlWorkingBase::SvIdlWorkingBase()
810 /*************************************************************************
811 |* SvIdlWorkingBase::ReadSvIdl()
813 |* Beschreibung
814 *************************************************************************/
815 BOOL SvIdlWorkingBase::ReadSvIdl( SvTokenStream & rInStm, BOOL bImported, const String & rPath )
817 aPath = rPath; // nur fuer den durchlauf gueltig
818 SvToken * pTok;
819 BOOL bOk = TRUE;
820 pTok = rInStm.GetToken();
821 // nur ein import ganz am Anfang
822 if( pTok->Is( SvHash_import() ) )
824 rInStm.GetToken_Next();
825 rInStm.Read( '(' ); // optional
826 pTok = rInStm.GetToken_Next();
827 if( pTok->IsString() )
829 DirEntry aFullName( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
830 if( aFullName.Find( rPath ) )
832 SvFileStream aStm( aFullName.GetFull(),
833 STREAM_STD_READ | STREAM_NOCREATE );
834 Load( aStm );
835 if( aStm.GetError() != SVSTREAM_OK )
837 if( aStm.GetError() == SVSTREAM_WRONGVERSION )
839 ByteString aStr( "wrong version, file " );
840 aStr += ByteString( aFullName.GetFull(), RTL_TEXTENCODING_UTF8 );
841 SetError( aStr, pTok );
842 WriteError( rInStm );
843 bOk = FALSE;
845 else
847 aStm.Seek( 0 );
848 aStm.ResetError();
849 SvTokenStream aTokStm( aStm, aFullName.GetFull() );
850 bOk = ReadSvIdl( aTokStm, TRUE, rPath );
854 else
855 bOk = FALSE;
857 else
858 bOk = FALSE;
861 UINT32 nBeginPos = 0xFFFFFFFF; // kann mit Tell nicht vorkommen
863 while( bOk && nBeginPos != rInStm.Tell() )
865 nBeginPos = rInStm.Tell();
866 pTok = rInStm.GetToken();
867 if( pTok->IsEof() )
868 return TRUE;
869 if( pTok->IsEmpty() )
870 bOk = FALSE;
872 // nur ein import ganz am Anfang
873 /*else */if( pTok->Is( SvHash_module() ) )
875 SvMetaModuleRef aModule = new SvMetaModule( rInStm.GetFileName(), bImported );
876 if( aModule->ReadSvIdl( *this, rInStm ) )
877 GetModuleList().Append( aModule );
878 else
879 bOk = FALSE;
881 else
882 bOk = FALSE;
884 if( !bOk || !pTok->IsEof() )
886 //Fehlerbehandlung
887 WriteError( rInStm );
888 return FALSE;
890 return TRUE;
893 /*************************************************************************
894 |* SvIdlWorkingBase::WriteSvIdl()
896 |* Beschreibung
897 *************************************************************************/
898 BOOL SvIdlWorkingBase::WriteSvIdl( SvStream & rOutStm )
900 if( rOutStm.GetError() != SVSTREAM_OK )
901 return FALSE;
903 SvStringHashList aList;
904 if( GetIdTable() )
906 GetIdTable()->FillHashList( &aList );
907 SvStringHashEntry * pEntry = aList.First();
908 while( pEntry )
910 rOutStm << "#define " << pEntry->GetName().GetBuffer()
911 << '\t'
912 << ByteString::CreateFromInt64(
913 pEntry->GetValue() ).GetBuffer()
914 << endl;
915 pEntry = aList.Next();
919 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
921 SvMetaModule * pModule = GetModuleList().GetObject( n );
922 //if( !pModule->IsImported() )
923 pModule->WriteSvIdl( *this, rOutStm, 0 );
925 return TRUE;
928 /*************************************************************************
929 |* SvIdlWorkingBase::WriteSfx()
931 |* Beschreibung
932 *************************************************************************/
933 BOOL SvIdlWorkingBase::WriteSfx( SvStream & rOutStm )
935 if( rOutStm.GetError() != SVSTREAM_OK )
936 return FALSE;
938 // alle Tmp-Variablen fuer das Schreiben zuruecksetzen
939 WriteReset();
940 SvMemoryStream aTmpStm( 256000, 256000 );
941 ULONG n;
942 for( n = 0; n < GetModuleList().Count(); n++ )
944 SvMetaModule * pModule = GetModuleList().GetObject( n );
945 if( !pModule->IsImported() )
946 pModule->WriteSfx( *this, aTmpStm );
947 aTmpStm.Seek( 0 );
949 for( n = 0; n < aUsedTypes.Count(); n++ )
951 SvMetaType * pType = aUsedTypes.GetObject( n );
952 pType->WriteSfx( *this, rOutStm );
954 aUsedTypes.Clear();
955 rOutStm << aTmpStm;
956 return TRUE;
959 BOOL SvIdlWorkingBase::WriteHelpIds( SvStream& rOutStm )
961 if( rOutStm.GetError() != SVSTREAM_OK )
962 return FALSE;
964 Table aIdTable;
965 ULONG n;
966 for( n = 0; n < GetModuleList().Count(); n++ )
968 SvMetaModule * pModule = GetModuleList().GetObject( n );
969 //if( !pModule->IsImported() )
970 pModule->WriteHelpIds( *this, rOutStm, &aIdTable );
973 const SvMetaAttributeMemberList & rAttrList = GetAttrList();
974 for( n = 0; n < rAttrList.Count(); n++ )
976 SvMetaAttribute * pAttr = rAttrList.GetObject( n );
977 pAttr->WriteHelpId( *this, rOutStm, &aIdTable );
980 return TRUE;
983 /*************************************************************************
984 |* SvIdlWorkingBase::WriteSfxItem()
986 |* Beschreibung
987 *************************************************************************/
988 BOOL SvIdlWorkingBase::WriteSfxItem( SvStream & )
990 return FALSE;
993 void SvIdlDataBase::StartNewFile( const String& rName )
995 bExport = ( aExportFile.EqualsIgnoreCaseAscii( rName ) );
998 void SvIdlDataBase::AppendAttr( SvMetaAttribute *pAttr )
1000 aAttrList.Append( pAttr );
1001 if ( bExport )
1002 pAttr->SetNewAttribute( TRUE );
1005 BOOL SvIdlWorkingBase::WriteCSV( SvStream& rStrm )
1007 SvMetaAttributeMemberList &rList = GetAttrList();
1008 ULONG nCount = rList.Count();
1009 for ( ULONG n=0; n<nCount; n++ )
1011 if ( rList.GetObject(n)->IsNewAttribute() )
1013 rList.GetObject(n)->WriteCSV( *this, rStrm );
1017 if ( rStrm.GetError() != SVSTREAM_OK )
1018 return FALSE;
1019 else
1020 return TRUE;
1023 /*************************************************************************
1024 |* SvIdlWorkingBase::WriteDocumentation()
1026 |* Beschreibung
1027 *************************************************************************/
1028 BOOL SvIdlWorkingBase::WriteDocumentation( SvStream & rOutStm )
1030 if( rOutStm.GetError() != SVSTREAM_OK )
1031 return FALSE;
1033 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
1035 SvMetaModule * pModule = GetModuleList().GetObject( n );
1036 if( !pModule->IsImported() )
1037 pModule->Write( *this, rOutStm, 0, WRITE_DOCU );
1039 return TRUE;
1044 #endif // IDL_COMPILER