xref: /aoo41x/main/idl/source/prj/database.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
30 
31 #include <ctype.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <tools/fsys.hxx>
35 #include <tools/debug.hxx>
36 #include <database.hxx>
37 #include <globals.hxx>
38 
39 /****************** SvIdlDataBase ****************************************/
40 /*************************************************************************
41 |*    SvIdlDataBase::SvIdlDataBase()
42 |*
43 |*    Beschreibung
44 *************************************************************************/
45 /*
46 void PrimeNumber(){
47     sal_uInt16 i, n;
48     for( i = 5001; i < 5500; i += 2 ){
49         for( n = 2; n < i && ((i % n) != 0); n++ );
50         if( n == i ){
51             printf( "\nPrimzahl: %d\n", i );
52             return;
53         }
54     }
55 }
56 */
57 
58 SvIdlDataBase::SvIdlDataBase( const SvCommand& rCmd )
59 	: bExport( sal_False )
60 	, nUniqueId( 0 )
61     , nVerbosity( rCmd.nVerbosity )
62     , bIsModified( sal_False )
63     , aPersStream( *IDLAPP->pClassMgr, NULL )
64     , pIdTable( NULL )
65 {
66 	//PrimeNumber();
67 }
68 
69 /*************************************************************************
70 |*    SvIdlDataBase::~SvIdlDataBase()
71 |*
72 |*    Beschreibung
73 *************************************************************************/
74 SvIdlDataBase::~SvIdlDataBase()
75 {
76     String * pStr = aIdFileList.First();
77     while( pStr )
78     {
79         delete pStr;
80         pStr = aIdFileList.Next();
81     }
82     delete pIdTable;
83 }
84 
85 /*************************************************************************
86 |*    SvIdlDataBase::GetTypeList()
87 |*
88 |*    Beschreibung
89 *************************************************************************/
90 #define ADD_TYPE( Name, OdlName, ParserChar, CName, BasName, BasPost )            \
91     aTypeList.Append( new SvMetaType( SvHash_##Name()->GetName(),	\
92                      BasName, OdlName, ParserChar, CName, BasName, BasPost ) );
93 
94 SvMetaTypeMemberList & SvIdlDataBase::GetTypeList()
95 {
96     if( aTypeList.Count() == 0 )
97     { // Initial fuellen
98         aTypeList.Append( new SvMetaTypeString() );
99         aTypeList.Append( new SvMetaTypevoid() );
100 
101 		// MI: IDispatch::Invoke kann keine unsigned
102         ADD_TYPE( UINT16,    "long", 'h', "unsigned short", "Long", "&" );
103         ADD_TYPE( INT16,     "short", 'h', "short", "Integer", "%" );
104         ADD_TYPE( UINT32,    "long", 'l', "unsigned long", "Long", "&" );
105         ADD_TYPE( INT32,     "long", 'l', "long", "Long", "&" );
106         ADD_TYPE( int,       "int", 'i', "int", "Integer", "%" );
107         ADD_TYPE( BOOL,      "boolean", 'b', "unsigned char", "Boolean", "" );
108         ADD_TYPE( char,      "char", 'c', "char", "Integer", "%" );
109         ADD_TYPE( BYTE,      "char", 'c', "unsigned char", "Integer", "%" );
110         ADD_TYPE( float,     "float", 'f', "float", "Single", "!" );
111         ADD_TYPE( double,    "double", 'F', "double", "Double", "#" );
112         ADD_TYPE( SbxObject, "VARIANT", 'o', "C_Object", "Object", "" );
113 
114 
115         // A c h t u n g !!!, bei hinzufuegen von Typen werden alle
116         // bin�ren Datenbasen inkompatibel
117 
118     /*
119         // So tun als ob die Init-Daten auf einem Stream gelesen wurden
120         SvMemoryStream aStm;
121         aPersStream.SetStream( &aStm );
122         // Alle Init-Daten Streamen
123         aPersStream << aTypeList;
124         // Nur die Id-Zuordnung merken
125         aPersStream.SetStream( NULL );
126     */
127     }
128     return aTypeList;
129 }
130 
131 /*************************************************************************
132 |*
133 |*    SvIdlDataBase::GetModuleInfo()
134 |*
135 |*    Beschreibung
136 |*    Ersterstellung    MM 13.12.94
137 |*    Letzte Aenderung  MM 13.12.94
138 |*
139 *************************************************************************/
140 SvMetaModule * SvIdlDataBase::GetModule( const ByteString & rName )
141 {
142     for( sal_uLong n = 0; n < aModuleList.Count(); n++ )
143         if( aModuleList.GetObject( n )->GetName() == rName )
144             return aModuleList.GetObject( n );
145     return NULL;
146 }
147 
148 /*************************************************************************
149 |*
150 |*    SvIdlDataBase::IsBinaryFormat()
151 |*
152 |*    Beschreibung
153 |*
154 *************************************************************************/
155 #define DATABASE_SIGNATURE  (sal_uInt32)0x13B799F2
156 #define DATABASE_VER 0x0006
157 sal_Bool SvIdlDataBase::IsBinaryFormat( SvStream & rStm )
158 {
159     sal_uInt32  nSig = 0;
160     sal_uLong   nPos = rStm.Tell();
161     rStm >> nSig;
162     rStm.Seek( nPos );
163 
164     return nSig == DATABASE_SIGNATURE;
165 }
166 
167 /*************************************************************************
168 |*
169 |*    SvIdlDataBase::Load()
170 |*
171 |*    Beschreibung
172 |*
173 *************************************************************************/
174 void SvIdlDataBase::Load( SvStream & rStm )
175 {
176     DBG_ASSERT( aTypeList.Count() == 0, "type list already initialized" );
177     SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
178 
179     sal_uInt16  nVersion = 0;
180     sal_uInt32  nSig = 0;
181 
182     aPStm >> nSig;
183     aPStm >> nVersion;
184     if( nSig != DATABASE_SIGNATURE )
185     {
186         aPStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
187         return;
188     }
189     if( nVersion != DATABASE_VER )
190     {
191         aPStm.SetError( SVSTREAM_WRONGVERSION );
192         return;
193     }
194     aPStm >> aClassList;
195     aPStm >> aTypeList;
196     aPStm >> aAttrList;
197     aPStm >> aModuleList;
198     aPStm >> nUniqueId;
199 
200     if( aPStm.IsEof() )
201         aPStm.SetError( SVSTREAM_GENERALERROR );
202 }
203 
204 /*************************************************************************
205 |*    SvIdlDataBase::Save()
206 |*
207 |*    Beschreibung
208 *************************************************************************/
209 void SvIdlDataBase::Save( SvStream & rStm, sal_uInt32 nFlags )
210 {
211     SvPersistStream aPStm( *IDLAPP->pClassMgr, &rStm );
212     aPStm.SetContextFlags( nFlags );
213 
214     aPStm << (sal_uInt32)DATABASE_SIGNATURE;
215     aPStm << (sal_uInt16)DATABASE_VER;
216 
217     sal_Bool bOnlyStreamedObjs = sal_False;
218     if( nFlags & IDL_WRITE_CALLING )
219         bOnlyStreamedObjs = sal_True;
220 
221     if( bOnlyStreamedObjs )
222     {
223         SvMetaClassMemberList aList;
224         for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
225         {
226             SvMetaModule * pModule = GetModuleList().GetObject( n );
227             if( !pModule->IsImported() )
228                 aList.Append( pModule->GetClassList() );
229         }
230         aPStm << aList;
231     }
232     else
233         aPStm << aClassList;
234 
235     //aClassList.WriteObjects( aPStm, bOnlyStreamedObjs );
236     aTypeList.WriteObjects( aPStm, bOnlyStreamedObjs );
237     aAttrList.WriteObjects( aPStm, bOnlyStreamedObjs );
238     aModuleList.WriteObjects( aPStm, bOnlyStreamedObjs );
239 	aPStm << nUniqueId;
240 }
241 
242 /*************************************************************************
243 |*    SvIdlDataBase::SetError()
244 |*
245 |*    Beschreibung
246 *************************************************************************/
247 void SvIdlDataBase::SetError( const ByteString & rError, SvToken * pTok )
248 {
249 	if( pTok->GetLine() > 10000 )
250 		aError.SetText( "hgchcg" );
251 
252     if( aError.nLine < pTok->GetLine()
253       || (aError.nLine == pTok->GetLine() && aError.nColumn < pTok->GetColumn()) )
254     {
255         aError = SvIdlError( pTok->GetLine(), pTok->GetColumn() );
256         aError.SetText( rError );
257     }
258 }
259 
260 /*************************************************************************
261 |*    SvIdlDataBase::Push()
262 |*
263 |*    Beschreibung
264 *************************************************************************/
265 void SvIdlDataBase::Push( SvMetaObject * pObj )
266 {
267 	GetStack().Push( pObj );
268 }
269 
270 #ifdef IDL_COMPILER
271 /*************************************************************************
272 |*
273 |*    SvIdlDataBase::FindId()
274 |*
275 |*    Beschreibung
276 |*
277 *************************************************************************/
278 sal_Bool SvIdlDataBase::FindId( const ByteString & rIdName, sal_uLong * pVal )
279 {
280     if( pIdTable )
281     {
282         sal_uInt32 nHash;
283         if( pIdTable->Test( rIdName, &nHash ) )
284         {
285             *pVal = pIdTable->Get( nHash )->GetValue();
286             return sal_True;
287         }
288     }
289     return sal_False;
290 }
291 
292 /*************************************************************************
293 |*
294 |*    SvIdlDataBase::InsertId()
295 |*
296 |*    Beschreibung
297 |*
298 *************************************************************************/
299 sal_Bool SvIdlDataBase::InsertId( const ByteString & rIdName, sal_uLong nVal )
300 {
301     if( !pIdTable )
302         pIdTable = new SvStringHashTable( 20003 );
303 
304     sal_uInt32 nHash;
305     if( pIdTable->Insert( rIdName, &nHash ) )
306     {
307         pIdTable->Get( nHash )->SetValue( nVal );
308         return sal_True;
309     }
310     return sal_False;
311 }
312 
313 /*************************************************************************
314 |*    SvIdlDataBase::ReadIdFile()
315 |*
316 |*    Beschreibung
317 *************************************************************************/
318 sal_Bool SvIdlDataBase::ReadIdFile( const String & rFileName )
319 {
320     DirEntry aFullName( rFileName );
321     aFullName.Find( GetPath() );
322 
323     String * pIdFile = aIdFileList.First();
324     while( pIdFile )
325     {
326         if( *pIdFile == rFileName )
327             return sal_True; // schon eingelesen
328         pIdFile = aIdFileList.Next();
329     }
330 
331     aIdFileList.Insert( new String( rFileName ), LIST_APPEND );
332 
333     SvTokenStream aTokStm( aFullName.GetFull() );
334     if( aTokStm.GetStream().GetError() == SVSTREAM_OK )
335     {
336         SvToken * pTok = aTokStm.GetToken_Next();
337 
338         while( !pTok->IsEof() )
339         {
340             if( pTok->IsChar() && pTok->GetChar() == '#' )
341             {
342                 pTok = aTokStm.GetToken_Next();
343                 if( pTok->Is( SvHash_define() ) )
344                 {
345                     pTok = aTokStm.GetToken_Next();
346                     ByteString aDefName;
347                     if( pTok->IsIdentifier() )
348                         aDefName = pTok->GetString();
349                     else
350                     {
351                         ByteString aStr( "unexpected token after define" );
352                         // Fehler setzen
353                         SetError( aStr, pTok );
354                         WriteError( aTokStm );
355                         return sal_False;
356                     }
357 
358                     sal_uLong nVal = 0;
359                     sal_Bool bOk = sal_True;
360                     while( bOk )
361                     {
362                         pTok = aTokStm.GetToken_Next();
363                         if( pTok->IsIdentifier() )
364                         {
365                             sal_uLong n;
366                             if( FindId( pTok->GetString(), &n ) )
367                                 nVal += n;
368                             else
369                                 bOk = sal_False;
370                         }
371                         else if( pTok->IsChar() )
372                         {
373                             if( pTok->GetChar() == '-'
374                               || pTok->GetChar() == '/'
375                               || pTok->GetChar() == '*'
376                               || pTok->GetChar() == '&'
377                               || pTok->GetChar() == '|'
378                               || pTok->GetChar() == '^'
379                               || pTok->GetChar() == '~' )
380                             {
381                                 ByteString aStr( "unknown operator '" );
382                                 aStr += pTok->GetChar();
383                                 aStr += "'in define";
384                                 // Fehler setzen
385                                 SetError( aStr, pTok );
386                                 WriteError( aTokStm );
387                                 return sal_False;
388                             }
389                             if( pTok->GetChar() != '+'
390                               && pTok->GetChar() != '('
391                               && pTok->GetChar() != ')' )
392                                 // nur + erlaubt, Klammern spielen kein Rolle,
393                                 // da + komutativ ist
394                                 break;
395                         }
396                         else if( pTok->IsInteger() )
397                         {
398                             nVal += pTok->GetNumber();
399                         }
400                         else
401                             break;
402                     }
403                     if( bOk )
404                     {
405                         if( !InsertId( aDefName, nVal ) )
406                         {
407 	                        ByteString aStr = "hash table overflow: ";
408 			                SetError( aStr, pTok );
409                             WriteError( aTokStm );
410                             return sal_False;
411                         }
412                     }
413                 }
414                 else if( pTok->Is( SvHash_include() ) )
415                 {
416                     pTok = aTokStm.GetToken_Next();
417                     ByteString aName;
418                     if( pTok->IsString() )
419                         aName = pTok->GetString();
420                     else if( pTok->IsChar() && pTok->GetChar() == '<' )
421                     {
422                         pTok = aTokStm.GetToken_Next();
423                         while( !pTok->IsEof()
424                           && !(pTok->IsChar() && pTok->GetChar() == '>') )
425                         {
426                             aName += pTok->GetTokenAsString();
427                             pTok = aTokStm.GetToken_Next();
428                         }
429                         if( pTok->IsEof() )
430                         {
431                             ByteString aStr( "unexpected eof in #include" );
432                             // Fehler setzen
433                             SetError( aStr, pTok );
434                             WriteError( aTokStm );
435                             return sal_False;
436                         }
437                     }
438                     if( !ReadIdFile( String::CreateFromAscii(aName.GetBuffer()) ) )
439                     {
440                         ByteString aStr = "cannot read file: ";
441                         aStr += aName;
442                         SetError( aStr, pTok );
443                         WriteError( aTokStm );
444                         return sal_False;
445                     }
446                 }
447             }
448             else
449                 pTok = aTokStm.GetToken_Next();
450         }
451     }
452     else
453         return sal_False;
454     return sal_True;
455 }
456 
457 /*************************************************************************
458 |*    SvIdlDataBase::FindType()
459 |*
460 |*    Beschreibung
461 *************************************************************************/
462 SvMetaType * SvIdlDataBase::FindType( const SvMetaType * pPType,
463 									SvMetaTypeMemberList & rList )
464 {
465 	SvMetaType * pType = rList.First();
466 	while( pType && pPType != pType )
467 		pType = rList.Next();
468 	return pType;
469 }
470 
471 SvMetaType * SvIdlDataBase::FindType( const ByteString & rName )
472 {
473 	SvMetaType * pType = aTypeList.First();
474 	while( pType && rName != pType->GetName() )
475 		pType = aTypeList.Next();
476 	return pType;
477 }
478 
479 /*************************************************************************
480 |*    SvIdlDataBase::ReadKnownType()
481 |*
482 |*    Beschreibung
483 *************************************************************************/
484 SvMetaType * SvIdlDataBase::ReadKnownType( SvTokenStream & rInStm )
485 {
486     sal_Bool bIn	= sal_False;
487     sal_Bool bOut	= sal_False;
488     int nCall0	= CALL_VALUE;
489     int nCall1	= CALL_VALUE;
490 	sal_Bool bSet   = sal_False; //irgent ein Attribut gesetzt
491 
492     sal_uInt32  nTokPos = rInStm.Tell();
493     SvToken * pTok = rInStm.GetToken_Next();
494 
495 	if( pTok->HasHash() )
496 	{
497 	    sal_uInt32 nBeginPos = 0; // kann mit Tell nicht vorkommen
498 	    while( nBeginPos != rInStm.Tell() )
499 	    {
500 	        nBeginPos = rInStm.Tell();
501 	        if( pTok->Is( SvHash_in() ) )
502 	        {
503 	            bIn  = sal_True;
504 	            pTok = rInStm.GetToken_Next();
505 				bSet = sal_True;
506 	        }
507 	        if( pTok->Is( SvHash_out() ) )
508 	        {
509 	            bOut = sal_True;
510 	            pTok = rInStm.GetToken_Next();
511 				bSet = sal_True;
512 	        }
513 	        if( pTok->Is( SvHash_inout() ) )
514 	        {
515 	            bIn  = sal_True;
516 	            bOut = sal_True;
517 	            pTok = rInStm.GetToken_Next();
518 				bSet = sal_True;
519 	        }
520 	    }
521 	}
522 /*
523     SvMetaTypeList aTmpTypeList;
524     if( FillTypeList( aTmpTypeList, pTok ) )
525 */
526     if( pTok->IsIdentifier() )
527     {
528         ByteString aName = pTok->GetString();
529         SvMetaTypeMemberList & rList = GetTypeList();
530         SvMetaType * pType = rList.First();
531         while( pType )
532         {
533             if( pType->GetName() == aName )
534 				break;
535             pType = rList.Next();
536         }
537 		if( pType )
538 		{
539 			pTok = rInStm.GetToken();
540 			if( pTok->IsChar() )
541 			{
542 				if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
543 				{
544 					nCall0 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
545 														CALL_POINTER;
546 					rInStm.GetToken_Next();
547 					pTok = rInStm.GetToken();
548 					if( pTok->GetChar() == '&' || pTok->GetChar() == '*' )
549 					{
550 						nCall1 = (pTok->GetChar() == '&') ? CALL_REFERENCE :
551 															CALL_POINTER;
552 						rInStm.GetToken_Next();
553 					}
554 					bSet = sal_True;
555 				}
556 			}
557 			/*
558 			SvMetaType * pMetaType = aTmpTypeList.First();
559 			while( pMetaType )
560 			{
561 				if( pMetaType->GetIn() == bIn
562 				  && pMetaType->GetOut() == bOut
563 				  && pMetaType->GetCall0() == nCall0
564 				  && pMetaType->GetCall1() == nCall1 )
565 				{
566 					return pMetaType;
567 				}
568 				pMetaType = aTmpTypeList.Next();
569 			}
570 			*/
571 			//SvMetaType * pType = aTmpTypeList.First();
572 			if( !bSet )
573 				// Ist genau dieser Typ
574 				return pType;
575 
576 			DBG_ASSERT( aTmpTypeList.First(), "mindestens ein Element" );
577 			SvMetaTypeRef xType = new SvMetaType( pType->GetName(), 'h', "dummy" );
578 			xType->SetRef( pType );
579 			xType->SetIn( bIn );
580 			xType->SetOut( bOut );
581 			xType->SetCall0( nCall0 );
582 			xType->SetCall1( nCall1 );
583 
584 			aTmpTypeList.Append( xType );
585 			return xType;
586 		}
587     }
588     rInStm.Seek( nTokPos );
589     return NULL;
590 }
591 
592 /*************************************************************************
593 |*
594 |*    SvIdlDataBase::ReadKnownAttr()
595 |*
596 |*    Beschreibung
597 |*
598 *************************************************************************/
599 SvMetaAttribute * SvIdlDataBase::ReadKnownAttr
600 (
601 	SvTokenStream & rInStm,
602 	SvMetaType *	pType	/* Wenn der pType == NULL, dann muss der Typ
603 							   noch gelesen werden. */
604 )
605 {
606     sal_uInt32  nTokPos = rInStm.Tell();
607 
608 	if( !pType )
609     	pType = ReadKnownType( rInStm );
610 
611     if( pType )
612     {
613 		// Wenn wir Slots auf die Wiese stellen, d"urfen wir nicht voraussetzen,
614 		// da\s jeder Slot einen anderen Namen hat!
615 /*
616         SvToken * pTok = rInStm.GetToken_Next();
617         if( pTok->IsIdentifier() )
618             for( sal_uLong n = 0; n < aAttrList.Count(); n++ )
619             {
620                 SvMetaAttribute * pAttr = aAttrList.GetObject( n );
621                 if( pAttr->GetName() == pTok->GetString() )
622                     return pAttr;
623             }
624 */
625     }
626     else
627     {
628         // sonst SlotId?
629         SvToken * pTok = rInStm.GetToken_Next();
630 	    if( pTok->IsIdentifier() )
631 	    {
632 			sal_uLong n;
633 	        if( FindId( pTok->GetString(), &n ) )
634 	        {
635 	            for( sal_uLong i = 0; i < aAttrList.Count(); i++ )
636 	            {
637 	                SvMetaAttribute * pAttr = aAttrList.GetObject( i );
638 	                if( pAttr->GetSlotId() == pTok->GetString() )
639 	                    return pAttr;
640 	            }
641 	        }
642 
643 			ByteString aStr( "Nicht gefunden : " );
644 			aStr += pTok->GetString();
645             DBG_ERROR( aStr.GetBuffer() );
646 		}
647     }
648 
649     rInStm.Seek( nTokPos );
650     return NULL;
651 }
652 
653 SvMetaAttribute* SvIdlDataBase::SearchKnownAttr
654 (
655 	const SvNumberIdentifier& rId
656 )
657 {
658 	sal_uLong n;
659 	if( FindId( rId, &n ) )
660 	{
661 	    for( sal_uLong i = 0; i < aAttrList.Count(); i++ )
662 	    {
663 	        SvMetaAttribute * pAttr = aAttrList.GetObject( i );
664 	        if( pAttr->GetSlotId() == rId )
665 	            return pAttr;
666 	    }
667 	}
668 
669 	return NULL;
670 }
671 
672 /*************************************************************************
673 |*    SvIdlDataBase::ReadKnownClass()
674 |*
675 |*    Beschreibung
676 *************************************************************************/
677 SvMetaClass * SvIdlDataBase::ReadKnownClass( SvTokenStream & rInStm )
678 {
679     sal_uInt32  nTokPos = rInStm.Tell();
680     SvToken * pTok = rInStm.GetToken_Next();
681 
682     if( pTok->IsIdentifier() )
683         for( sal_uLong n = 0; n < aClassList.Count(); n++ )
684         {
685             SvMetaClass * pClass = aClassList.GetObject( n );
686             if( pClass->GetName() == pTok->GetString() )
687                 return pClass;
688         }
689 
690     rInStm.Seek( nTokPos );
691     return NULL;
692 }
693 
694 /*************************************************************************
695 |*    SvIdlDataBase::Write()
696 |*
697 |*    Beschreibung
698 *************************************************************************/
699 void SvIdlDataBase::Write( const ByteString & rText )
700 {
701     if( nVerbosity != 0 )
702         fprintf( stdout, "%s", rText.GetBuffer() );
703 }
704 
705 /*************************************************************************
706 |*    SvIdlDataBase::WriteError()
707 |*
708 |*    Beschreibung
709 *************************************************************************/
710 void SvIdlDataBase::WriteError( const ByteString & rErrWrn,
711 								const ByteString & rFileName,
712 								const ByteString & rErrorText,
713 								sal_uLong nRow, sal_uLong nColumn ) const
714 {
715     //Fehlerbehandlung
716     fprintf( stderr, "\n%s --- %s: ( %ld, %ld )\n",
717              rFileName.GetBuffer(), rErrWrn.GetBuffer(), nRow, nColumn );
718 
719     if( rErrorText.Len() )
720     { // Fehler gesetzt
721         fprintf( stderr, "\t%s\n", rErrorText.GetBuffer() );
722 	}
723 }
724 
725 /*************************************************************************
726 |*    SvIdlDataBase::WriteError()
727 |*
728 |*    Beschreibung
729 *************************************************************************/
730 void SvIdlDataBase::WriteError( SvTokenStream & rInStm )
731 {
732     //Fehlerbehandlung
733     String aFileName( rInStm.GetFileName() );
734 	ByteString aErrorText;
735 	sal_uLong	nRow = 0, nColumn = 0;
736 
737     rInStm.SeekEnd();
738     SvToken *pTok = rInStm.GetToken();
739 
740     // Fehlerposition
741 	nRow 	= pTok->GetLine();
742 	nColumn = pTok->GetColumn();
743 
744     if( aError.IsError() )
745     { // Fehler gesetzt
746         // Fehler Token suchen
747 	    // Fehlertext
748 		if( aError.GetText().Len() )
749 		{
750 			aErrorText = "may be <";
751         	aErrorText += aError.GetText();
752 		}
753 		SvToken * pPrevTok = NULL;
754         while( pTok != pPrevTok )
755         {
756 			pPrevTok = pTok;
757             if( pTok->GetLine() == aError.nLine
758               && pTok->GetColumn() == aError.nColumn )
759                 break;
760             pTok = rInStm.GetToken_PrevAll();
761         }
762 
763         // Fehlerposition
764 		aErrorText += "> at ( ";
765 		aErrorText += ByteString::CreateFromInt64(aError.nLine);
766 		aErrorText += ", ";
767 		aErrorText += ByteString::CreateFromInt64(aError.nColumn);
768 		aErrorText += " )";
769 
770 		// Fehler zuruecksetzen
771 		aError = SvIdlError();
772     }
773 
774     WriteError( "error", ByteString( aFileName, RTL_TEXTENCODING_UTF8 ), aErrorText, nRow, nColumn );
775 
776     DBG_ASSERT( pTok, "token must be found" );
777     if( !pTok )
778         return;
779 
780     // Identifier in der Naehe suchen
781     if( !pTok->IsIdentifier() )
782     {
783         rInStm.GetToken_PrevAll();
784         pTok = rInStm.GetToken();
785     }
786     if( pTok && pTok->IsIdentifier() )
787     {
788         ByteString aN = IDLAPP->pHashTable->GetNearString( pTok->GetString() );
789         if( aN.Len() )
790             fprintf( stderr, "%s versus %s\n", pTok->GetString().GetBuffer(), aN.GetBuffer() );
791     }
792 }
793 
794 /****************** SvIdlWorkingBase ****************************************/
795 /*************************************************************************
796 |*    SvIdlWorkingBase::SvIdlWorkingBase()
797 |*
798 |*    Beschreibung
799 *************************************************************************/
800 SvIdlWorkingBase::SvIdlWorkingBase(const SvCommand& rCmd) : SvIdlDataBase(rCmd)
801 {
802 }
803 
804 /*************************************************************************
805 |*    SvIdlWorkingBase::ReadSvIdl()
806 |*
807 |*    Beschreibung
808 *************************************************************************/
809 sal_Bool SvIdlWorkingBase::ReadSvIdl( SvTokenStream & rInStm, sal_Bool bImported, const String & rPath )
810 {
811     aPath = rPath; // nur fuer den durchlauf gueltig
812     SvToken * pTok;
813     sal_Bool bOk = sal_True;
814         pTok = rInStm.GetToken();
815         // nur ein import ganz am Anfang
816         if( pTok->Is( SvHash_import() ) )
817         {
818             rInStm.GetToken_Next();
819             rInStm.Read( '(' ); // optional
820             pTok = rInStm.GetToken_Next();
821             if( pTok->IsString() )
822             {
823                 DirEntry aFullName( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
824                 if( aFullName.Find( rPath ) )
825                 {
826                     SvFileStream aStm( aFullName.GetFull(),
827                                         STREAM_STD_READ | STREAM_NOCREATE );
828                     Load( aStm );
829                     if( aStm.GetError() != SVSTREAM_OK )
830                     {
831                         if( aStm.GetError() == SVSTREAM_WRONGVERSION )
832                         {
833                             ByteString aStr( "wrong version, file " );
834                             aStr += ByteString( aFullName.GetFull(), RTL_TEXTENCODING_UTF8 );
835                             SetError( aStr, pTok );
836                             WriteError( rInStm );
837                             bOk = sal_False;
838                         }
839                         else
840                         {
841                             aStm.Seek( 0 );
842                             aStm.ResetError();
843                             SvTokenStream aTokStm( aStm, aFullName.GetFull() );
844                             bOk = ReadSvIdl( aTokStm, sal_True, rPath );
845                         }
846                     }
847                 }
848                 else
849                     bOk = sal_False;
850             }
851             else
852                 bOk = sal_False;
853         }
854 
855     sal_uInt32 nBeginPos = 0xFFFFFFFF; // kann mit Tell nicht vorkommen
856 
857     while( bOk && nBeginPos != rInStm.Tell() )
858     {
859         nBeginPos = rInStm.Tell();
860         pTok = rInStm.GetToken();
861         if( pTok->IsEof() )
862             return sal_True;
863         if( pTok->IsEmpty() )
864             bOk = sal_False;
865 
866         // nur ein import ganz am Anfang
867         /*else */if( pTok->Is( SvHash_module() ) )
868         {
869             SvMetaModuleRef aModule = new SvMetaModule( rInStm.GetFileName(), bImported );
870             if( aModule->ReadSvIdl( *this, rInStm ) )
871                 GetModuleList().Append( aModule );
872             else
873                 bOk = sal_False;
874         }
875         else
876             bOk = sal_False;
877     }
878     if( !bOk || !pTok->IsEof() )
879     {
880          //Fehlerbehandlung
881          WriteError( rInStm );
882          return sal_False;
883     }
884     return sal_True;
885 }
886 
887 /*************************************************************************
888 |*    SvIdlWorkingBase::WriteSvIdl()
889 |*
890 |*    Beschreibung
891 *************************************************************************/
892 sal_Bool SvIdlWorkingBase::WriteSvIdl( SvStream & rOutStm )
893 {
894     if( rOutStm.GetError() != SVSTREAM_OK )
895         return sal_False;
896 
897     SvStringHashList aList;
898     if( GetIdTable() )
899     {
900         GetIdTable()->FillHashList( &aList );
901         SvStringHashEntry * pEntry = aList.First();
902         while( pEntry )
903         {
904             rOutStm << "#define " << pEntry->GetName().GetBuffer()
905                     << '\t'
906                     << ByteString::CreateFromInt64(
907                         pEntry->GetValue() ).GetBuffer()
908                     << endl;
909             pEntry = aList.Next();
910         }
911     }
912 
913     for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
914     {
915         SvMetaModule * pModule = GetModuleList().GetObject( n );
916         //if( !pModule->IsImported() )
917             pModule->WriteSvIdl( *this, rOutStm, 0 );
918     }
919     return sal_True;
920 }
921 
922 /*************************************************************************
923 |*    SvIdlWorkingBase::WriteSfx()
924 |*
925 |*    Beschreibung
926 *************************************************************************/
927 sal_Bool SvIdlWorkingBase::WriteSfx( SvStream & rOutStm )
928 {
929     if( rOutStm.GetError() != SVSTREAM_OK )
930         return sal_False;
931 
932 	// alle Tmp-Variablen fuer das Schreiben zuruecksetzen
933 	WriteReset();
934 	SvMemoryStream aTmpStm( 256000, 256000 );
935 	sal_uLong n;
936     for( n = 0; n < GetModuleList().Count(); n++ )
937     {
938         SvMetaModule * pModule = GetModuleList().GetObject( n );
939         if( !pModule->IsImported() )
940             pModule->WriteSfx( *this, aTmpStm );
941 		aTmpStm.Seek( 0 );
942     }
943     for( n = 0; n < aUsedTypes.Count(); n++ )
944     {
945         SvMetaType * pType = aUsedTypes.GetObject( n );
946         pType->WriteSfx( *this, rOutStm );
947     }
948 	aUsedTypes.Clear();
949 	rOutStm << aTmpStm;
950     return sal_True;
951 }
952 
953 sal_Bool SvIdlWorkingBase::WriteHelpIds( SvStream& rOutStm )
954 {
955     if( rOutStm.GetError() != SVSTREAM_OK )
956         return sal_False;
957 
958     Table aIdTable;
959 	sal_uLong n;
960     for( n = 0; n < GetModuleList().Count(); n++ )
961     {
962         SvMetaModule * pModule = GetModuleList().GetObject( n );
963         //if( !pModule->IsImported() )
964             pModule->WriteHelpIds( *this, rOutStm, &aIdTable );
965     }
966 
967     const SvMetaAttributeMemberList & rAttrList = GetAttrList();
968     for( n = 0; n < rAttrList.Count(); n++ )
969     {
970         SvMetaAttribute * pAttr = rAttrList.GetObject( n );
971         pAttr->WriteHelpId( *this, rOutStm, &aIdTable );
972     }
973 
974 	return sal_True;
975 }
976 
977 /*************************************************************************
978 |*    SvIdlWorkingBase::WriteSfxItem()
979 |*
980 |*    Beschreibung
981 *************************************************************************/
982 sal_Bool SvIdlWorkingBase::WriteSfxItem( SvStream & )
983 {
984 	return sal_False;
985 }
986 
987 void SvIdlDataBase::StartNewFile( const String& rName )
988 {
989     bExport = ( aExportFile.EqualsIgnoreCaseAscii( rName ) );
990 }
991 
992 void SvIdlDataBase::AppendAttr( SvMetaAttribute *pAttr )
993 {
994 	aAttrList.Append( pAttr );
995 	if ( bExport )
996 		pAttr->SetNewAttribute( sal_True );
997 }
998 
999 sal_Bool SvIdlWorkingBase::WriteCSV( SvStream& rStrm )
1000 {
1001 	SvMetaAttributeMemberList &rList = GetAttrList();
1002 	sal_uLong nCount = rList.Count();
1003 	for ( sal_uLong n=0; n<nCount; n++ )
1004 	{
1005 		if ( rList.GetObject(n)->IsNewAttribute() )
1006 		{
1007 			rList.GetObject(n)->WriteCSV( *this, rStrm );
1008 		}
1009 	}
1010 
1011 	if ( rStrm.GetError() != SVSTREAM_OK )
1012 		return sal_False;
1013 	else
1014 		return sal_True;
1015 }
1016 
1017 /*************************************************************************
1018 |*    SvIdlWorkingBase::WriteDocumentation()
1019 |*
1020 |*    Beschreibung
1021 *************************************************************************/
1022 sal_Bool SvIdlWorkingBase::WriteDocumentation( SvStream & rOutStm )
1023 {
1024     if( rOutStm.GetError() != SVSTREAM_OK )
1025         return sal_False;
1026 
1027     for( sal_uLong n = 0; n < GetModuleList().Count(); n++ )
1028     {
1029         SvMetaModule * pModule = GetModuleList().GetObject( n );
1030         if( !pModule->IsImported() )
1031             pModule->Write( *this, rOutStm, 0, WRITE_DOCU );
1032     }
1033     return sal_True;
1034 }
1035 
1036 
1037 
1038 #endif // IDL_COMPILER
1039 
1040