Update ooo320-m1
[ooovba.git] / idl / source / prj / database.cxx
blob7270423829fdcf848424ceba689fde9544119bc2
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( const SvCommand& rCmd )
62 : bExport( FALSE )
63 , nUniqueId( 0 )
64 , nVerbosity( rCmd.nVerbosity )
65 , bIsModified( FALSE )
66 , aPersStream( *IDLAPP->pClassMgr, NULL )
67 , pIdTable( NULL )
69 //PrimeNumber();
72 /*************************************************************************
73 |* SvIdlDataBase::~SvIdlDataBase()
75 |* Beschreibung
76 *************************************************************************/
77 SvIdlDataBase::~SvIdlDataBase()
79 String * pStr = aIdFileList.First();
80 while( pStr )
82 delete pStr;
83 pStr = aIdFileList.Next();
85 delete pIdTable;
88 /*************************************************************************
89 |* SvIdlDataBase::GetTypeList()
91 |* Beschreibung
92 *************************************************************************/
93 #define ADD_TYPE( Name, OdlName, ParserChar, CName, BasName, BasPost ) \
94 aTypeList.Append( new SvMetaType( SvHash_##Name()->GetName(), \
95 BasName, OdlName, ParserChar, CName, BasName, BasPost ) );
97 SvMetaTypeMemberList & SvIdlDataBase::GetTypeList()
99 if( aTypeList.Count() == 0 )
100 { // Initial fuellen
101 aTypeList.Append( new SvMetaTypeString() );
102 aTypeList.Append( new SvMetaTypevoid() );
104 // MI: IDispatch::Invoke kann keine unsigned
105 ADD_TYPE( UINT16, "long", 'h', "unsigned short", "Long", "&" );
106 ADD_TYPE( INT16, "short", 'h', "short", "Integer", "%" );
107 ADD_TYPE( UINT32, "long", 'l', "unsigned long", "Long", "&" );
108 ADD_TYPE( INT32, "long", 'l', "long", "Long", "&" );
109 ADD_TYPE( int, "int", 'i', "int", "Integer", "%" );
110 ADD_TYPE( BOOL, "boolean", 'b', "unsigned char", "Boolean", "" );
111 ADD_TYPE( char, "char", 'c', "char", "Integer", "%" );
112 ADD_TYPE( BYTE, "char", 'c', "unsigned char", "Integer", "%" );
113 ADD_TYPE( float, "float", 'f', "float", "Single", "!" );
114 ADD_TYPE( double, "double", 'F', "double", "Double", "#" );
115 ADD_TYPE( SbxObject, "VARIANT", 'o', "C_Object", "Object", "" );
117 // A c h t u n g !!!, bei hinzufuegen von Typen werden alle
118 // bin„ren Datenbasen inkompatibel
121 // So tun als ob die Init-Daten auf einem Stream gelesen wurden
122 SvMemoryStream aStm;
123 aPersStream.SetStream( &aStm );
124 // Alle Init-Daten Streamen
125 aPersStream << aTypeList;
126 // Nur die Id-Zuordnung merken
127 aPersStream.SetStream( NULL );
130 return aTypeList;
133 /*************************************************************************
135 |* SvIdlDataBase::GetModuleInfo()
137 |* Beschreibung
138 |* Ersterstellung MM 13.12.94
139 |* Letzte Aenderung MM 13.12.94
141 *************************************************************************/
142 SvMetaModule * SvIdlDataBase::GetModule( const ByteString & rName )
144 for( ULONG n = 0; n < aModuleList.Count(); n++ )
145 if( aModuleList.GetObject( n )->GetName() == rName )
146 return aModuleList.GetObject( n );
147 return NULL;
150 /*************************************************************************
152 |* SvIdlDataBase::IsBinaryFormat()
154 |* Beschreibung
156 *************************************************************************/
157 #define DATABASE_SIGNATURE (UINT32)0x13B799F2
158 #define DATABASE_VER 0x0006
159 BOOL SvIdlDataBase::IsBinaryFormat( SvStream & rStm )
161 UINT32 nSig = 0;
162 ULONG nPos = rStm.Tell();
163 rStm >> nSig;
164 rStm.Seek( nPos );
166 return nSig == DATABASE_SIGNATURE;
169 /*************************************************************************
171 |* SvIdlDataBase::Load()
173 |* Beschreibung
175 *************************************************************************/
176 void SvIdlDataBase::Load( SvStream & rStm )
178 DBG_ASSERT( aTypeList.Count() == 0, "type list already initialized" );
179 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
181 USHORT nVersion = 0;
182 UINT32 nSig = 0;
184 aPStm >> nSig;
185 aPStm >> nVersion;
186 if( nSig != DATABASE_SIGNATURE )
188 aPStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
189 return;
191 if( nVersion != DATABASE_VER )
193 aPStm.SetError( SVSTREAM_WRONGVERSION );
194 return;
196 aPStm >> aClassList;
197 aPStm >> aTypeList;
198 aPStm >> aAttrList;
199 aPStm >> aModuleList;
200 aPStm >> nUniqueId;
202 if( aPStm.IsEof() )
203 aPStm.SetError( SVSTREAM_GENERALERROR );
206 /*************************************************************************
207 |* SvIdlDataBase::Save()
209 |* Beschreibung
210 *************************************************************************/
211 void SvIdlDataBase::Save( SvStream & rStm, UINT32 nFlags )
213 SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
214 aPStm.SetContextFlags( nFlags );
216 aPStm << (UINT32)DATABASE_SIGNATURE;
217 aPStm << (USHORT)DATABASE_VER;
219 BOOL bOnlyStreamedObjs = FALSE;
220 if( nFlags & IDL_WRITE_CALLING )
221 bOnlyStreamedObjs = TRUE;
223 if( bOnlyStreamedObjs )
225 SvMetaClassMemberList aList;
226 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
228 SvMetaModule * pModule = GetModuleList().GetObject( n );
229 if( !pModule->IsImported() )
230 aList.Append( pModule->GetClassList() );
232 aPStm << aList;
234 else
235 aPStm << aClassList;
237 //aClassList.WriteObjects( aPStm, bOnlyStreamedObjs );
238 aTypeList.WriteObjects( aPStm, bOnlyStreamedObjs );
239 aAttrList.WriteObjects( aPStm, bOnlyStreamedObjs );
240 aModuleList.WriteObjects( aPStm, bOnlyStreamedObjs );
241 aPStm << nUniqueId;
244 /*************************************************************************
245 |* SvIdlDataBase::SetError()
247 |* Beschreibung
248 *************************************************************************/
249 void SvIdlDataBase::SetError( const ByteString & rError, SvToken * pTok )
251 if( pTok->GetLine() > 10000 )
252 aError.SetText( "hgchcg" );
254 if( aError.nLine < pTok->GetLine()
255 || (aError.nLine == pTok->GetLine() && aError.nColumn < pTok->GetColumn()) )
257 aError = SvIdlError( pTok->GetLine(), pTok->GetColumn() );
258 aError.SetText( rError );
262 /*************************************************************************
263 |* SvIdlDataBase::Push()
265 |* Beschreibung
266 *************************************************************************/
267 void SvIdlDataBase::Push( SvMetaObject * pObj )
269 GetStack().Push( pObj );
272 #ifdef IDL_COMPILER
273 /*************************************************************************
275 |* SvIdlDataBase::FindId()
277 |* Beschreibung
279 *************************************************************************/
280 BOOL SvIdlDataBase::FindId( const ByteString & rIdName, ULONG * pVal )
282 if( pIdTable )
284 UINT32 nHash;
285 if( pIdTable->Test( rIdName, &nHash ) )
287 *pVal = pIdTable->Get( nHash )->GetValue();
288 return TRUE;
291 return FALSE;
294 /*************************************************************************
296 |* SvIdlDataBase::InsertId()
298 |* Beschreibung
300 *************************************************************************/
301 BOOL SvIdlDataBase::InsertId( const ByteString & rIdName, ULONG nVal )
303 if( !pIdTable )
304 pIdTable = new SvStringHashTable( 20003 );
306 UINT32 nHash;
307 if( pIdTable->Insert( rIdName, &nHash ) )
309 pIdTable->Get( nHash )->SetValue( nVal );
310 return TRUE;
312 return FALSE;
315 /*************************************************************************
316 |* SvIdlDataBase::ReadIdFile()
318 |* Beschreibung
319 *************************************************************************/
320 BOOL SvIdlDataBase::ReadIdFile( const String & rFileName )
322 DirEntry aFullName( rFileName );
323 aFullName.Find( GetPath() );
325 String * pIdFile = aIdFileList.First();
326 while( pIdFile )
328 if( *pIdFile == rFileName )
329 return TRUE; // schon eingelesen
330 pIdFile = aIdFileList.Next();
333 aIdFileList.Insert( new String( rFileName ), LIST_APPEND );
335 SvTokenStream aTokStm( aFullName.GetFull() );
336 if( aTokStm.GetStream().GetError() == SVSTREAM_OK )
338 SvToken * pTok = aTokStm.GetToken_Next();
340 while( !pTok->IsEof() )
342 if( pTok->IsChar() && pTok->GetChar() == '#' )
344 pTok = aTokStm.GetToken_Next();
345 if( pTok->Is( SvHash_define() ) )
347 pTok = aTokStm.GetToken_Next();
348 ByteString aDefName;
349 if( pTok->IsIdentifier() )
350 aDefName = pTok->GetString();
351 else
353 ByteString aStr( "unexpected token after define" );
354 // Fehler setzen
355 SetError( aStr, pTok );
356 WriteError( aTokStm );
357 return FALSE;
360 ULONG nVal = 0;
361 BOOL bOk = TRUE;
362 while( bOk )
364 pTok = aTokStm.GetToken_Next();
365 if( pTok->IsIdentifier() )
367 ULONG n;
368 if( FindId( pTok->GetString(), &n ) )
369 nVal += n;
370 else
371 bOk = FALSE;
373 else if( pTok->IsChar() )
375 if( pTok->GetChar() == '-'
376 || pTok->GetChar() == '/'
377 || pTok->GetChar() == '*'
378 || pTok->GetChar() == '&'
379 || pTok->GetChar() == '|'
380 || pTok->GetChar() == '^'
381 || pTok->GetChar() == '~' )
383 ByteString aStr( "unknown operator '" );
384 aStr += pTok->GetChar();
385 aStr += "'in define";
386 // Fehler setzen
387 SetError( aStr, pTok );
388 WriteError( aTokStm );
389 return FALSE;
391 if( pTok->GetChar() != '+'
392 && pTok->GetChar() != '('
393 && pTok->GetChar() != ')' )
394 // nur + erlaubt, Klammern spielen kein Rolle,
395 // da + komutativ ist
396 break;
398 else if( pTok->IsInteger() )
400 nVal += pTok->GetNumber();
402 else
403 break;
405 if( bOk )
407 if( !InsertId( aDefName, nVal ) )
409 ByteString aStr = "hash table overflow: ";
410 SetError( aStr, pTok );
411 WriteError( aTokStm );
412 return FALSE;
416 else if( pTok->Is( SvHash_include() ) )
418 pTok = aTokStm.GetToken_Next();
419 ByteString aName;
420 if( pTok->IsString() )
421 aName = pTok->GetString();
422 else if( pTok->IsChar() && pTok->GetChar() == '<' )
424 pTok = aTokStm.GetToken_Next();
425 while( !pTok->IsEof()
426 && !(pTok->IsChar() && pTok->GetChar() == '>') )
428 aName += pTok->GetTokenAsString();
429 pTok = aTokStm.GetToken_Next();
431 if( pTok->IsEof() )
433 ByteString aStr( "unexpected eof in #include" );
434 // Fehler setzen
435 SetError( aStr, pTok );
436 WriteError( aTokStm );
437 return FALSE;
440 if( !ReadIdFile( String::CreateFromAscii(aName.GetBuffer()) ) )
442 ByteString aStr = "cannot read file: ";
443 aStr += aName;
444 SetError( aStr, pTok );
445 WriteError( aTokStm );
446 return FALSE;
450 else
451 pTok = aTokStm.GetToken_Next();
454 else
455 return FALSE;
456 return TRUE;
459 /*************************************************************************
460 |* SvIdlDataBase::FindType()
462 |* Beschreibung
463 *************************************************************************/
464 SvMetaType * SvIdlDataBase::FindType( const SvMetaType * pPType,
465 SvMetaTypeMemberList & rList )
467 SvMetaType * pType = rList.First();
468 while( pType && pPType != pType )
469 pType = rList.Next();
470 return pType;
473 SvMetaType * SvIdlDataBase::FindType( const ByteString & rName )
475 SvMetaType * pType = aTypeList.First();
476 while( pType && rName != pType->GetName() )
477 pType = aTypeList.Next();
478 return pType;
481 /*************************************************************************
482 |* SvIdlDataBase::ReadKnownType()
484 |* Beschreibung
485 *************************************************************************/
486 SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
488 BOOL bIn = FALSE;
489 BOOL bOut = FALSE;
490 int nCall0 = CALL_VALUE;
491 int nCall1 = CALL_VALUE;
492 BOOL bSet = FALSE; //irgent ein Attribut gesetzt
494 UINT32 nTokPos = rInStm.Tell();
495 SvToken * pTok = rInStm.GetToken_Next();
497 if( pTok->HasHash() )
499 UINT32 nBeginPos = 0; // kann mit Tell nicht vorkommen
500 while( nBeginPos != rInStm.Tell() )
502 nBeginPos = rInStm.Tell();
503 if( pTok->Is( SvHash_in() ) )
505 bIn = TRUE;
506 pTok = rInStm.GetToken_Next();
507 bSet = TRUE;
509 if( pTok->Is( SvHash_out() ) )
511 bOut = TRUE;
512 pTok = rInStm.GetToken_Next();
513 bSet = TRUE;
515 if( pTok->Is( SvHash_inout() ) )
517 bIn = TRUE;
518 bOut = TRUE;
519 pTok = rInStm.GetToken_Next();
520 bSet = TRUE;
525 SvMetaTypeList aTmpTypeList;
526 if( FillTypeList( aTmpTypeList, pTok ) )
528 if( pTok->IsIdentifier() )
530 ByteString aName = pTok->GetString();
531 SvMetaTypeMemberList & rList = GetTypeList();
532 SvMetaType * pType = rList.First();
533 while( pType )
535 if( pType->GetName() == aName )
536 break;
537 pType = rList.Next();
539 if( pType )
541 pTok = rInStm.GetToken();
542 if( pTok->IsChar() )
544 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
546 nCall0 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
547 CALL_POINTER;
548 rInStm.GetToken_Next();
549 pTok = rInStm.GetToken();
550 if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
552 nCall1 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
553 CALL_POINTER;
554 rInStm.GetToken_Next();
556 bSet = TRUE;
560 SvMetaType * pMetaType = aTmpTypeList.First();
561 while( pMetaType )
563 if( pMetaType->GetIn() == bIn
564 && pMetaType->GetOut() == bOut
565 && pMetaType->GetCall0() == nCall0
566 && pMetaType->GetCall1() == nCall1 )
568 return pMetaType;
570 pMetaType = aTmpTypeList.Next();
573 //SvMetaType * pType = aTmpTypeList.First();
574 if( !bSet )
575 // Ist genau dieser Typ
576 return pType;
578 DBG_ASSERT( aTmpTypeList.First(), "mindestens ein Element" );
579 SvMetaTypeRef xType = new SvMetaType( pType->GetName(), 'h', "dummy" );
580 xType->SetRef( pType );
581 xType->SetIn( bIn );
582 xType->SetOut( bOut );
583 xType->SetCall0( nCall0 );
584 xType->SetCall1( nCall1 );
586 aTmpTypeList.Append( xType );
587 return xType;
590 rInStm.Seek( nTokPos );
591 return NULL;
594 /*************************************************************************
596 |* SvIdlDataBase::ReadKnownAttr()
598 |* Beschreibung
600 *************************************************************************/
601 SvMetaAttribute * SvIdlDataBase::ReadKnownAttr
603 SvTokenStream & rInStm,
604 SvMetaType * pType /* Wenn der pType == NULL, dann muss der Typ
605 noch gelesen werden. */
608 UINT32 nTokPos = rInStm.Tell();
610 if( !pType )
611 pType = ReadKnownType( rInStm );
613 if( pType )
615 // Wenn wir Slots auf die Wiese stellen, d"urfen wir nicht voraussetzen,
616 // da\s jeder Slot einen anderen Namen hat!
618 SvToken * pTok = rInStm.GetToken_Next();
619 if( pTok->IsIdentifier() )
620 for( ULONG n = 0; n < aAttrList.Count(); n++ )
622 SvMetaAttribute * pAttr = aAttrList.GetObject( n );
623 if( pAttr->GetName() == pTok->GetString() )
624 return pAttr;
628 else
630 // sonst SlotId?
631 SvToken * pTok = rInStm.GetToken_Next();
632 if( pTok->IsIdentifier() )
634 ULONG n;
635 if( FindId( pTok->GetString(), &n ) )
637 for( ULONG i = 0; i < aAttrList.Count(); i++ )
639 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
640 if( pAttr->GetSlotId() == pTok->GetString() )
641 return pAttr;
645 ByteString aStr( "Nicht gefunden : " );
646 aStr += pTok->GetString();
647 DBG_ERROR( aStr.GetBuffer() );
651 rInStm.Seek( nTokPos );
652 return NULL;
655 SvMetaAttribute* SvIdlDataBase::SearchKnownAttr
657 const SvNumberIdentifier& rId
660 ULONG n;
661 if( FindId( rId, &n ) )
663 for( ULONG i = 0; i < aAttrList.Count(); i++ )
665 SvMetaAttribute * pAttr = aAttrList.GetObject( i );
666 if( pAttr->GetSlotId() == rId )
667 return pAttr;
671 return NULL;
674 /*************************************************************************
675 |* SvIdlDataBase::ReadKnownClass()
677 |* Beschreibung
678 *************************************************************************/
679 SvMetaClass * SvIdlDataBase::ReadKnownClass( SvTokenStream & rInStm )
681 UINT32 nTokPos = rInStm.Tell();
682 SvToken * pTok = rInStm.GetToken_Next();
684 if( pTok->IsIdentifier() )
685 for( ULONG n = 0; n < aClassList.Count(); n++ )
687 SvMetaClass * pClass = aClassList.GetObject( n );
688 if( pClass->GetName() == pTok->GetString() )
689 return pClass;
692 rInStm.Seek( nTokPos );
693 return NULL;
696 /*************************************************************************
697 |* SvIdlDataBase::Write()
699 |* Beschreibung
700 *************************************************************************/
701 void SvIdlDataBase::Write( const ByteString & rText )
703 #ifndef W31
704 if( nVerbosity != 0 )
705 fprintf( stdout, "%s", rText.GetBuffer() );
706 #endif
709 /*************************************************************************
710 |* SvIdlDataBase::WriteError()
712 |* Beschreibung
713 *************************************************************************/
714 void SvIdlDataBase::WriteError( const ByteString & rErrWrn,
715 const ByteString & rFileName,
716 const ByteString & rErrorText,
717 ULONG nRow, ULONG nColumn ) const
719 //Fehlerbehandlung
720 #ifndef W31
721 fprintf( stderr, "\n%s --- %s: ( %ld, %ld )\n",
722 rFileName.GetBuffer(), rErrWrn.GetBuffer(), nRow, nColumn );
724 if( rErrorText.Len() )
725 { // Fehler gesetzt
726 fprintf( stderr, "\t%s\n", rErrorText.GetBuffer() );
728 #endif
731 /*************************************************************************
732 |* SvIdlDataBase::WriteError()
734 |* Beschreibung
735 *************************************************************************/
736 void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
738 //Fehlerbehandlung
739 #ifndef W31
740 String aFileName( rInStm.GetFileName() );
741 ByteString aErrorText;
742 ULONG nRow = 0, nColumn = 0;
744 rInStm.SeekEnd();
745 SvToken *pTok = rInStm.GetToken();
747 // Fehlerposition
748 nRow = pTok->GetLine();
749 nColumn = pTok->GetColumn();
751 if( aError.IsError() )
752 { // Fehler gesetzt
753 // Fehler Token suchen
754 // Fehlertext
755 if( aError.GetText().Len() )
757 aErrorText = "may be <";
758 aErrorText += aError.GetText();
760 SvToken * pPrevTok = NULL;
761 while( pTok != pPrevTok )
763 pPrevTok = pTok;
764 if( pTok->GetLine() == aError.nLine
765 && pTok->GetColumn() == aError.nColumn )
766 break;
767 pTok = rInStm.GetToken_PrevAll();
770 // Fehlerposition
771 aErrorText += "> at ( ";
772 aErrorText += ByteString::CreateFromInt64(aError.nLine);
773 aErrorText += ", ";
774 aErrorText += ByteString::CreateFromInt64(aError.nColumn);
775 aErrorText += " )";
777 // Fehler zuruecksetzen
778 aError = SvIdlError();
781 WriteError( "error", ByteString( aFileName, RTL_TEXTENCODING_UTF8 ), aErrorText, nRow, nColumn );
783 DBG_ASSERT( pTok, "token must be found" );
784 if( !pTok )
785 return;
787 // Identifier in der Naehe suchen
788 if( !pTok->IsIdentifier() )
790 rInStm.GetToken_PrevAll();
791 pTok = rInStm.GetToken();
793 if( pTok && pTok->IsIdentifier() )
795 ByteString aN = IDLAPP->pHashTable->GetNearString( pTok->GetString() );
796 if( aN.Len() )
797 fprintf( stderr, "%s versus %s\n", pTok->GetString().GetBuffer(), aN.GetBuffer() );
799 #endif
802 /****************** SvIdlWorkingBase ****************************************/
803 /*************************************************************************
804 |* SvIdlWorkingBase::SvIdlWorkingBase()
806 |* Beschreibung
807 *************************************************************************/
808 SvIdlWorkingBase::SvIdlWorkingBase(const SvCommand& rCmd) : SvIdlDataBase(rCmd)
812 /*************************************************************************
813 |* SvIdlWorkingBase::ReadSvIdl()
815 |* Beschreibung
816 *************************************************************************/
817 BOOL SvIdlWorkingBase::ReadSvIdl( SvTokenStream & rInStm, BOOL bImported, const String & rPath )
819 aPath = rPath; // nur fuer den durchlauf gueltig
820 SvToken * pTok;
821 BOOL bOk = TRUE;
822 pTok = rInStm.GetToken();
823 // nur ein import ganz am Anfang
824 if( pTok->Is( SvHash_import() ) )
826 rInStm.GetToken_Next();
827 rInStm.Read( '(' ); // optional
828 pTok = rInStm.GetToken_Next();
829 if( pTok->IsString() )
831 DirEntry aFullName( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
832 if( aFullName.Find( rPath ) )
834 SvFileStream aStm( aFullName.GetFull(),
835 STREAM_STD_READ | STREAM_NOCREATE );
836 Load( aStm );
837 if( aStm.GetError() != SVSTREAM_OK )
839 if( aStm.GetError() == SVSTREAM_WRONGVERSION )
841 ByteString aStr( "wrong version, file " );
842 aStr += ByteString( aFullName.GetFull(), RTL_TEXTENCODING_UTF8 );
843 SetError( aStr, pTok );
844 WriteError( rInStm );
845 bOk = FALSE;
847 else
849 aStm.Seek( 0 );
850 aStm.ResetError();
851 SvTokenStream aTokStm( aStm, aFullName.GetFull() );
852 bOk = ReadSvIdl( aTokStm, TRUE, rPath );
856 else
857 bOk = FALSE;
859 else
860 bOk = FALSE;
863 UINT32 nBeginPos = 0xFFFFFFFF; // kann mit Tell nicht vorkommen
865 while( bOk && nBeginPos != rInStm.Tell() )
867 nBeginPos = rInStm.Tell();
868 pTok = rInStm.GetToken();
869 if( pTok->IsEof() )
870 return TRUE;
871 if( pTok->IsEmpty() )
872 bOk = FALSE;
874 // nur ein import ganz am Anfang
875 /*else */if( pTok->Is( SvHash_module() ) )
877 SvMetaModuleRef aModule = new SvMetaModule( rInStm.GetFileName(), bImported );
878 if( aModule->ReadSvIdl( *this, rInStm ) )
879 GetModuleList().Append( aModule );
880 else
881 bOk = FALSE;
883 else
884 bOk = FALSE;
886 if( !bOk || !pTok->IsEof() )
888 //Fehlerbehandlung
889 WriteError( rInStm );
890 return FALSE;
892 return TRUE;
895 /*************************************************************************
896 |* SvIdlWorkingBase::WriteSvIdl()
898 |* Beschreibung
899 *************************************************************************/
900 BOOL SvIdlWorkingBase::WriteSvIdl( SvStream & rOutStm )
902 if( rOutStm.GetError() != SVSTREAM_OK )
903 return FALSE;
905 SvStringHashList aList;
906 if( GetIdTable() )
908 GetIdTable()->FillHashList( &aList );
909 SvStringHashEntry * pEntry = aList.First();
910 while( pEntry )
912 rOutStm << "#define " << pEntry->GetName().GetBuffer()
913 << '\t'
914 << ByteString::CreateFromInt64(
915 pEntry->GetValue() ).GetBuffer()
916 << endl;
917 pEntry = aList.Next();
921 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
923 SvMetaModule * pModule = GetModuleList().GetObject( n );
924 //if( !pModule->IsImported() )
925 pModule->WriteSvIdl( *this, rOutStm, 0 );
927 return TRUE;
930 /*************************************************************************
931 |* SvIdlWorkingBase::WriteSfx()
933 |* Beschreibung
934 *************************************************************************/
935 BOOL SvIdlWorkingBase::WriteSfx( SvStream & rOutStm )
937 if( rOutStm.GetError() != SVSTREAM_OK )
938 return FALSE;
940 // alle Tmp-Variablen fuer das Schreiben zuruecksetzen
941 WriteReset();
942 SvMemoryStream aTmpStm( 256000, 256000 );
943 ULONG n;
944 for( n = 0; n < GetModuleList().Count(); n++ )
946 SvMetaModule * pModule = GetModuleList().GetObject( n );
947 if( !pModule->IsImported() )
948 pModule->WriteSfx( *this, aTmpStm );
949 aTmpStm.Seek( 0 );
951 for( n = 0; n < aUsedTypes.Count(); n++ )
953 SvMetaType * pType = aUsedTypes.GetObject( n );
954 pType->WriteSfx( *this, rOutStm );
956 aUsedTypes.Clear();
957 rOutStm << aTmpStm;
958 return TRUE;
961 BOOL SvIdlWorkingBase::WriteHelpIds( SvStream& rOutStm )
963 if( rOutStm.GetError() != SVSTREAM_OK )
964 return FALSE;
966 Table aIdTable;
967 ULONG n;
968 for( n = 0; n < GetModuleList().Count(); n++ )
970 SvMetaModule * pModule = GetModuleList().GetObject( n );
971 //if( !pModule->IsImported() )
972 pModule->WriteHelpIds( *this, rOutStm, &aIdTable );
975 const SvMetaAttributeMemberList & rAttrList = GetAttrList();
976 for( n = 0; n < rAttrList.Count(); n++ )
978 SvMetaAttribute * pAttr = rAttrList.GetObject( n );
979 pAttr->WriteHelpId( *this, rOutStm, &aIdTable );
982 return TRUE;
985 /*************************************************************************
986 |* SvIdlWorkingBase::WriteSfxItem()
988 |* Beschreibung
989 *************************************************************************/
990 BOOL SvIdlWorkingBase::WriteSfxItem( SvStream & )
992 return FALSE;
995 void SvIdlDataBase::StartNewFile( const String& rName )
997 bExport = ( aExportFile.EqualsIgnoreCaseAscii( rName ) );
1000 void SvIdlDataBase::AppendAttr( SvMetaAttribute *pAttr )
1002 aAttrList.Append( pAttr );
1003 if ( bExport )
1004 pAttr->SetNewAttribute( TRUE );
1007 BOOL SvIdlWorkingBase::WriteCSV( SvStream& rStrm )
1009 SvMetaAttributeMemberList &rList = GetAttrList();
1010 ULONG nCount = rList.Count();
1011 for ( ULONG n=0; n<nCount; n++ )
1013 if ( rList.GetObject(n)->IsNewAttribute() )
1015 rList.GetObject(n)->WriteCSV( *this, rStrm );
1019 if ( rStrm.GetError() != SVSTREAM_OK )
1020 return FALSE;
1021 else
1022 return TRUE;
1025 /*************************************************************************
1026 |* SvIdlWorkingBase::WriteDocumentation()
1028 |* Beschreibung
1029 *************************************************************************/
1030 BOOL SvIdlWorkingBase::WriteDocumentation( SvStream & rOutStm )
1032 if( rOutStm.GetError() != SVSTREAM_OK )
1033 return FALSE;
1035 for( ULONG n = 0; n < GetModuleList().Count(); n++ )
1037 SvMetaModule * pModule = GetModuleList().GetObject( n );
1038 if( !pModule->IsImported() )
1039 pModule->Write( *this, rOutStm, 0, WRITE_DOCU );
1041 return TRUE;
1046 #endif // IDL_COMPILER