xref: /trunk/main/rsc/source/tools/rscdef.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
31 
32 // Programmuebergreifende Includes.
33 #include <rscdef.hxx>
34 
35 /****************** C o d e **********************************************/
36 /****************** R s c I d ********************************************/
37 sal_Bool RscId::bNames = sal_True;
38 
39 /*************************************************************************
40 |*
41 |*    static RscId::SetNames
42 |*    static RscId::SetNoNames
43 |*
44 |*    Beschreibung
45 |*    Ersterstellung    MM 26.06.91
46 |*    Letzte Aenderung  MM 26.06.91
47 |*
48 *************************************************************************/
49 void RscId::SetNames( sal_Bool bSet )  { bNames = bSet;  }
50 sal_Bool RscId::IsSetNames()           { return bNames;  }
51 
52 /*************************************************************************
53 |*
54 |*    RscId::GetNumber
55 |*
56 |*    Beschreibung
57 |*    Ersterstellung    MM 17.05.91
58 |*    Letzte Aenderung  MM 17.05.91
59 |*
60 *************************************************************************/
61 sal_Int32 RscId::GetNumber() const{
62     sal_Int32 lVal;
63     aExp.Evaluate( &lVal );
64     return lVal;
65 }
66 
67 /*************************************************************************
68 |*
69 |*    RscId::Create()
70 |*
71 |*    Beschreibung
72 |*    Ersterstellung    MM 01.11.91
73 |*    Letzte Aenderung  MM 01.11.91
74 |*
75 *************************************************************************/
76 void RscId::Create( const RscExpType & rExpType )
77 {
78     aExp = rExpType;
79     if( aExp.IsDefinition() )
80         aExp.aExp.pDef->IncRef();
81     else if( aExp.IsExpression() ){
82         sal_Int32 lValue;
83 
84         aExp.Evaluate( &lValue );
85         aExp.SetLong( lValue );
86     }
87 }
88 
89 /*************************************************************************
90 |*
91 |*    RscId::Destroy()
92 |*
93 |*    Beschreibung
94 |*    Ersterstellung    MM 01.11.91
95 |*    Letzte Aenderung  MM 01.11.91
96 |*
97 *************************************************************************/
98 void RscId::Destroy(){
99     if( aExp.IsDefinition() )
100         aExp.aExp.pDef->DecRef();
101     aExp.cType = RSCEXP_NOTHING;
102 }
103 
104 /*************************************************************************
105 |*
106 |*    RscId::RscId()
107 |*
108 |*    Beschreibung
109 |*    Ersterstellung    MM 01.11.91
110 |*    Letzte Aenderung  MM 01.11.91
111 |*
112 *************************************************************************/
113 RscId::RscId( const RscId& rRscId ){
114     aExp = rRscId.aExp;
115     if( aExp.IsDefinition() )
116         aExp.aExp.pDef->IncRef();
117 }
118 
119 /*************************************************************************
120 |*
121 |*    RscId::RscId()
122 |*
123 |*    Beschreibung
124 |*    Ersterstellung    MM 01.11.91
125 |*    Letzte Aenderung  MM 25.11.91
126 |*
127 *************************************************************************/
128 RscId::RscId( RscDefine * pDef ){
129     RscExpType aExpType;
130 
131     aExpType.aExp.pDef = pDef;
132     aExpType.cType = RSCEXP_DEF;
133     Create( aExpType );
134 }
135 
136 /*************************************************************************
137 |*
138 |*    RscId:: =
139 |*
140 |*    Beschreibung
141 |*    Ersterstellung    MM 01.11.91
142 |*    Letzte Aenderung  MM 01.11.91
143 |*
144 *************************************************************************/
145 RscId& RscId::operator = ( const RscId& rRscId ){
146     if( rRscId.aExp.IsDefinition() )
147         rRscId.aExp.aExp.pDef->IncRef();
148     Destroy();
149     aExp = rRscId.aExp;
150     return *this;
151 }
152 
153 /*************************************************************************
154 |*
155 |*    RscId::operator ==
156 |*
157 |*    Beschreibung
158 |*    Ersterstellung    MM 16.05.91
159 |*    Letzte Aenderung  MM 16.05.91
160 |*
161 *************************************************************************/
162 sal_Bool RscId::operator == ( const RscId& rRscId ) const
163 {
164     return( GetNumber() == rRscId.GetNumber() );
165 }
166 
167 /*************************************************************************
168 |*
169 |*    RscId::operator <
170 |*
171 |*    Beschreibung
172 |*    Ersterstellung    MM 16.05.91
173 |*    Letzte Aenderung  MM 16.05.91
174 |*
175 *************************************************************************/
176 sal_Bool RscId::operator < ( const RscId& rRscId ) const
177 {
178     return( GetNumber() < rRscId.GetNumber() );
179 }
180 
181 /*************************************************************************
182 |*
183 |*    RscId::operator >
184 |*
185 |*    Beschreibung
186 |*    Ersterstellung    MM 16.05.91
187 |*    Letzte Aenderung  MM 16.05.91
188 |*
189 *************************************************************************/
190 sal_Bool RscId::operator > ( const RscId& rRscId ) const
191 {
192     return( GetNumber() > rRscId.GetNumber() );
193 }
194 
195 /*************************************************************************
196 |*
197 |*    RscId::sal_Int32()
198 |*
199 |*    Beschreibung
200 |*    Ersterstellung    MM 16.05.91
201 |*    Letzte Aenderung  MM 16.05.91
202 |*
203 *************************************************************************/
204 RscId::operator sal_Int32() const
205 {
206     return( GetNumber() );
207 }
208 
209 /*************************************************************************
210 |*
211 |*    RscId::GetNames()
212 |*
213 |*    Beschreibung
214 |*    Ersterstellung    MM 16.05.91
215 |*    Letzte Aenderung  MM 25.11.91
216 |*
217 *************************************************************************/
218 ByteString RscId::GetName() const
219 {
220     ByteString aStr;
221 
222     if ( !aExp.IsNothing() )
223     {
224         if( bNames )
225             aExp.GetMacro( aStr );
226         else
227             aStr = ByteString::CreateFromInt32( GetNumber() );
228     }
229 
230     return aStr;
231 }
232 
233 /*************************************************************************
234 |*
235 |*    RscId::GetMacro()
236 |*
237 |*    Beschreibung
238 |*    Ersterstellung    MM 01.11.91
239 |*    Letzte Aenderung  MM 25.11.91
240 |*
241 *************************************************************************/
242 ByteString RscId::GetMacro() const
243 {
244     ByteString aStr;
245 
246     if ( aExp.IsDefinition() )
247         aStr = aExp.aExp.pDef->GetMacro();
248     else
249         aExp.GetMacro( aStr );
250 
251     return aStr;
252 }
253 
254 /****************** R s c D e f i n e ************************************/
255 /*************************************************************************
256 |*
257 |*    RscDefine::RscDefine()
258 |*
259 |*    Beschreibung
260 |*    Ersterstellung    MM 01.11.91
261 |*    Letzte Aenderung  MM 01.11.91
262 |*
263 *************************************************************************/
264 RscDefine::RscDefine( sal_uLong lKey, const ByteString & rDefName, sal_Int32 lDefId )
265     : StringNode( rDefName )
266 {
267     nRefCount = 0;
268     lFileKey  = lKey;
269     lId       = lDefId;
270     pExp      = NULL;
271 }
272 
273 RscDefine::RscDefine( sal_uLong lKey, const ByteString & rDefName,
274                       RscExpression * pExpression  )
275     : StringNode( rDefName )
276 {
277     nRefCount = 0;
278     lFileKey  = lKey;
279     pExpression->Evaluate( &lId );
280     pExp      = pExpression;
281 }
282 
283 /*************************************************************************
284 |*
285 |*    RscDefine::~RscDefine()
286 |*
287 |*    Beschreibung
288 |*    Ersterstellung    MM 01.11.91
289 |*    Letzte Aenderung  MM 01.11.91
290 |*
291 *************************************************************************/
292 RscDefine::~RscDefine(){
293     if( pExp )
294         delete pExp;
295     if( nRefCount )
296         RscExit( 14 );
297 }
298 
299 /*************************************************************************
300 |*
301 |*    RscDefine::DecRef()
302 |*
303 |*    Beschreibung
304 |*    Ersterstellung    MM 01.11.91
305 |*    Letzte Aenderung  MM 01.11.91
306 |*
307 *************************************************************************/
308 void RscDefine::DecRef(){
309     nRefCount--;
310     if( 0 == nRefCount ){
311         delete this;
312     }
313 }
314 
315 /*************************************************************************
316 |*
317 |*    RscDefine::DefineToNumber()
318 |*
319 |*    Beschreibung
320 |*    Ersterstellung    MM 07.11.91
321 |*    Letzte Aenderung  MM 07.11.91
322 |*
323 *************************************************************************/
324 void RscDefine::DefineToNumber()
325 {
326     if( pExp )
327         delete pExp;
328     pExp = NULL;
329     SetName( ByteString::CreateFromInt32( lId ) );
330 }
331 
332 /*************************************************************************
333 |*
334 |*    RscDefine::ChangeMacro()
335 |*
336 |*    Beschreibung
337 |*    Ersterstellung    MM 04.11.91
338 |*    Letzte Aenderung  MM 04.11.91
339 |*
340 *************************************************************************/
341 void RscDefine::ChangeMacro( RscExpression * pExpression ){
342     if( pExp )
343         delete pExp;
344     pExp = pExpression;
345     pExp->Evaluate( &lId );
346 }
347 
348 void RscDefine::ChangeMacro( sal_Int32 lIdentifier ){
349     if( pExp ){
350         delete pExp;
351         pExp = NULL;
352     }
353     lId = lIdentifier;
354 }
355 
356 /*************************************************************************
357 |*
358 |*    RscDefine::Evaluate()
359 |*
360 |*    Beschreibung
361 |*    Ersterstellung    MM 01.11.91
362 |*    Letzte Aenderung  MM 01.11.91
363 |*
364 *************************************************************************/
365 sal_Bool RscDefine::Evaluate(){
366     sal_Bool    bRet = sal_True;
367 
368     if( pExp )
369         bRet = !pExp->Evaluate( &lId );
370 
371     return bRet;
372 }
373 
374 /*************************************************************************
375 |*
376 |*    RscDefine::Search()
377 |*
378 |*    Beschreibung
379 |*    Ersterstellung    MM 11.11.91
380 |*    Letzte Aenderung  MM 11.11.91
381 |*
382 *************************************************************************/
383 RscDefine * RscDefine::Search( const char * pStr ){
384     return (RscDefine *)StringNode::Search( pStr );
385 }
386 
387 /*************************************************************************
388 |*
389 |*    RscDefine::GetMacro()
390 |*
391 |*    Beschreibung
392 |*    Ersterstellung    MM 01.11.91
393 |*    Letzte Aenderung  MM 01.11.91
394 |*
395 *************************************************************************/
396 ByteString RscDefine::GetMacro()
397 {
398     if( pExp )
399         return pExp->GetMacro();
400     return ByteString::CreateFromInt32( lId );
401 }
402 
403 /****************** R s c D e f i n e L i s t ****************************/
404 /*************************************************************************
405 |*
406 |*    RscDefineList::New()
407 |*
408 |*    Beschreibung
409 |*    Ersterstellung    MM 04.11.91
410 |*    Letzte Aenderung  MM 04.11.91
411 |*
412 *************************************************************************/
413 RscDefine * RscDefineList::New( sal_uLong lFileKey, const ByteString & rDefName,
414                                 sal_Int32 lDefId, sal_uLong lPos )
415 {
416     RscDefine * pDef;
417 
418     pDef = new RscDefine( lFileKey, rDefName, lDefId );
419     pDef->IncRef();
420     Insert( pDef, lPos );
421     return pDef;
422 }
423 
424 RscDefine * RscDefineList::New( sal_uLong lFileKey, const ByteString & rDefName,
425                                 RscExpression * pExpression, sal_uLong lPos )
426 {
427     RscDefine * pDef;
428 
429     pDef = new RscDefine( lFileKey, rDefName, pExpression );
430     pDef->IncRef();
431     Insert( pDef, lPos );
432 
433     return pDef;
434 }
435 
436 /*************************************************************************
437 |*
438 |*    RscDefineList::Remove()
439 |*
440 |*    Beschreibung
441 |*    Ersterstellung    MM 04.11.91
442 |*    Letzte Aenderung  MM 04.11.91
443 |*
444 *************************************************************************/
445 sal_Bool RscDefineList::Remove( RscDefine * pDef ){
446     pDef = RscSubDefList::Remove( pDef );
447     if( pDef ){
448         pDef->DefineToNumber();
449         pDef->DecRef();
450     }
451 
452     return( NULL != pDef );
453 }
454 
455 sal_Bool RscDefineList::Remove( sal_uLong lIndex ){
456     RscDefine * pDef = RscSubDefList::Remove( lIndex );
457     if( pDef ){
458         pDef->DefineToNumber();
459         pDef->DecRef();
460     }
461 
462     return( NULL != pDef );
463 }
464 
465 sal_Bool RscDefineList::Remove(){
466     RscDefine * pDef;
467 
468     pDef = RscSubDefList::Remove( (sal_uLong)0 );
469 
470     if( pDef ){
471         pDef->DefineToNumber();
472         pDef->DecRef();
473     }
474     return( NULL != pDef );
475 }
476 
477 /*************************************************************************
478 |*
479 |*    RscDefineList::Befor()
480 |*
481 |*    Beschreibung
482 |*    Ersterstellung    MM 12.11.91
483 |*    Letzte Aenderung  MM 12.11.91
484 |*
485 *************************************************************************/
486 sal_Bool RscDefineList::Befor( const RscDefine * pFree,
487                            const RscDefine * pDepend )
488 {
489     RscDefine * pDef;
490 
491     pDef = First();
492     while( pDef ){
493         if( pDef == pFree ){
494             pDef = Next();
495             while( pDef ){
496                 if( pDef == pDepend )
497                     return sal_True;
498                 pDef = Next();
499             }
500         }
501         pDef = Next();
502     };
503     return sal_False;
504 }
505 
506 /*************************************************************************
507 |*
508 |*    RscDefineList::WriteAll()
509 |*
510 |*    Beschreibung
511 |*    Ersterstellung    MM 28.10.91
512 |*    Letzte Aenderung  MM 28.10.91
513 |*
514 *************************************************************************/
515 void RscDefineList::WriteAll( FILE * fOutput )
516 {
517     RscDefine * pDefEle = First();
518 
519     while( pDefEle )
520     {
521         fprintf( fOutput, "#define %s %s\n",
522                  pDefEle->GetName().GetBuffer(),
523                  pDefEle->GetMacro().GetBuffer() );
524         pDefEle = Next();
525     };
526 }
527 
528 /****************** R s c E x p T y p e **********************************/
529 /*************************************************************************
530 |*
531 |*    RscExpType::Evaluate()
532 |*
533 |*    Beschreibung
534 |*    Ersterstellung    MM 01.11.91
535 |*    Letzte Aenderung  MM 01.11.91
536 |*
537 *************************************************************************/
538 sal_Bool RscExpType::Evaluate( sal_Int32 * plValue ) const{
539     if( IsDefinition() ){
540         aExp.pDef->Evaluate();
541         // Eventuellen Fehler ignorieren
542         *plValue = aExp.pDef->GetNumber();
543     }
544     else if( IsExpression() )
545         return( aExp.pExp->Evaluate( plValue ) );
546     else if( IsNothing() )
547         *plValue = 0;
548     else
549         *plValue = GetLong();
550 
551     return sal_True;
552 }
553 
554 /*************************************************************************
555 |*
556 |*    RscExpType::GetMacro()
557 |*
558 |*    Beschreibung
559 |*    Ersterstellung    MM 01.11.91
560 |*    Letzte Aenderung  MM 01.11.91
561 |*
562 *************************************************************************/
563 void RscExpType::GetMacro( ByteString & rStr ) const
564 {
565     ByteString aStr;
566 
567     if( IsDefinition() )
568     {
569         rStr += aExp.pDef->GetName();
570     }
571     else if( IsExpression() )
572         rStr += aExp.pExp->GetMacro();
573     else if( IsNumber() )
574         rStr += ByteString::CreateFromInt32( GetLong() );
575 }
576 
577 
578 /****************** R s c E x p r e s s i o n ****************************/
579 /*************************************************************************
580 |*
581 |*    RscExpression::RscExpression()
582 |*
583 |*    Beschreibung
584 |*    Ersterstellung    MM 01.11.91
585 |*    Letzte Aenderung  MM 01.11.91
586 |*
587 *************************************************************************/
588 RscExpression::RscExpression( RscExpType aLE, char cOp, RscExpType aRE )
589 {
590     aLeftExp   = aLE;
591     cOperation = cOp;
592     aRightExp  = aRE;
593     if( aLeftExp.IsDefinition() )
594         aLeftExp.aExp.pDef->IncRef();
595     if( aRightExp.IsDefinition() )
596         aRightExp.aExp.pDef->IncRef();
597 }
598 
599 /*************************************************************************
600 |*
601 |*    RscExpression::~RscExpression()
602 |*
603 |*    Beschreibung
604 |*    Ersterstellung    MM 01.11.91
605 |*    Letzte Aenderung  MM 01.11.91
606 |*
607 *************************************************************************/
608 RscExpression::~RscExpression(){
609     if( aLeftExp.IsDefinition() )
610         aLeftExp.aExp.pDef->DecRef();
611     else if( aLeftExp.IsExpression() )
612         delete aLeftExp.aExp.pExp;
613 
614     if( aRightExp.IsDefinition() )
615         aRightExp.aExp.pDef->DecRef();
616     else if( aRightExp.IsExpression() )
617         delete aRightExp.aExp.pExp;
618 }
619 
620 /*************************************************************************
621 |*
622 |*    RscExpression::Evaluate()
623 |*
624 |*    Beschreibung
625 |*    Ersterstellung    MM 01.11.91
626 |*    Letzte Aenderung  MM 01.11.91
627 |*
628 *************************************************************************/
629 sal_Bool RscExpression::Evaluate( sal_Int32 * plValue ){
630     sal_Int32 lLeft;
631     sal_Int32 lRight;
632 
633     // linken und rechten Zweig auswerten
634     if( aLeftExp.Evaluate( &lLeft ) && aRightExp.Evaluate( &lRight ) ){
635         if( cOperation == '&' )
636             *plValue = lLeft & lRight;
637         else if( cOperation == '|' )
638             *plValue = lLeft | lRight;
639         else if( cOperation == '+' )
640             *plValue = lLeft + lRight;
641         else if( cOperation == '-' )
642             *plValue = lLeft - lRight;
643         else if( cOperation == '*' )
644             *plValue = lLeft * lRight;
645         else if( cOperation == 'r' )
646             *plValue = lLeft >> lRight;
647         else if( cOperation == 'l' )
648             *plValue = lLeft << lRight;
649         else{
650             if( 0L == lRight )
651                 return sal_False;
652             *plValue = lLeft / lRight;
653         };
654         return sal_True;
655     }
656     return sal_False;
657 }
658 
659 /*************************************************************************
660 |*
661 |*    RscExpression::GetMacro()
662 |*
663 |*    Beschreibung
664 |*    Ersterstellung    MM 01.11.91
665 |*    Letzte Aenderung  MM 01.11.91
666 |*
667 *************************************************************************/
668 ByteString RscExpression::GetMacro()
669 {
670     ByteString aLeft;
671 
672     // Ausgabeoptimierung
673     if( aLeftExp.IsNothing() )
674     {
675         if ( '-' == cOperation )
676         {
677             aLeft += '(';
678             aLeft += '-';
679         }
680         aRightExp.GetMacro( aLeft );
681         if( '-' == cOperation )
682             aLeft += ')';
683     }
684     else if( aRightExp.IsNothing() )
685         aLeftExp.GetMacro( aLeft );
686     else{
687         aLeft += '(';
688         // linken Zweig auswerten
689         aLeftExp.GetMacro( aLeft );
690 
691         aLeft += cOperation;
692 
693         aLeft += '(';
694         // rechten Zweig auswerten
695         aRightExp.GetMacro( aLeft );
696         aLeft += ')';
697 
698         aLeft += ')';
699     }
700 
701     return aLeft;
702 }
703 
704 /****************** R s c F i l e ****************************************/
705 /*************************************************************************
706 |*
707 |*    RscFile::RscFile()
708 |*
709 |*    Beschreibung
710 |*    Ersterstellung    MM 04.11.91
711 |*    Letzte Aenderung  MM 04.11.91
712 |*
713 *************************************************************************/
714 RscFile :: RscFile(){
715     bLoaded  = sal_False;
716     bIncFile = sal_False;
717     bDirty   = sal_False;
718     bScanned = sal_False;
719 }
720 
721 /*************************************************************************
722 |*
723 |*    RscFile::~RscFile()
724 |*
725 |*    Beschreibung
726 |*    Ersterstellung    MM 04.11.91
727 |*    Letzte Aenderung  MM 04.11.91
728 |*
729 *************************************************************************/
730 RscFile :: ~RscFile(){
731     RscDepend * pDep = Remove( (sal_uLong)0 );
732 
733     while( pDep ){
734         delete pDep;
735         pDep = Remove( (sal_uLong)0 );
736     }
737 
738     //von hinten nach vorne ist besser wegen der Abhaengigkeiten
739     //Objekte zerstoeren sich, wenn Referenzzaehler NULL
740     aDefLst.Last();
741     while( aDefLst.Remove() ) ;
742 }
743 
744 /*************************************************************************
745 |*
746 |*    RscFile::Depend()
747 |*
748 |*    Beschreibung      Diese Methode gibt sal_True zurueck, wenn lDepend
749 |*                      existiert und hinter lFree steht, oder wenn
750 |*                      lDepend nicht existiert.
751 |*    Ersterstellung    MM 12.11.91
752 |*    Letzte Aenderung  MM 12.11.91
753 |*
754 *************************************************************************/
755 sal_Bool RscFile::Depend( sal_uLong lDepend, sal_uLong lFree ){
756     RscDepend * pDep;
757 
758     pDep = Last();
759     while( pDep ){
760         if( pDep->GetFileKey() == lDepend ){
761             while( pDep ){
762                 if( pDep->GetFileKey() == lFree )
763                     return sal_True;
764                 pDep = Prev();
765             }
766             return sal_False;
767         }
768         pDep = Prev();
769     };
770 
771     return sal_True;
772 }
773 
774 /*************************************************************************
775 |*
776 |*    RscFile::InsertDependFile()
777 |*
778 |*    Beschreibung
779 |*    Ersterstellung    MM 06.01.92
780 |*    Letzte Aenderung  MM 06.01.92
781 |*
782 *************************************************************************/
783 sal_Bool RscFile :: InsertDependFile( sal_uLong lIncFile, sal_uLong lPos )
784 {
785     RscDepend * pDep;
786 
787     pDep = First();
788     while( pDep ){
789         if( pDep->GetFileKey() == lIncFile )
790             return sal_True;
791         pDep = Next();
792     }
793 
794     // Current-Zeiger steht auf letztem Element
795     if( lPos >= Count() ){ //letztes Element muss immer letztes bleiben
796         // Abhaengigkeit vor der letzten Position eintragen
797         Insert( new RscDepend( lIncFile ) );
798     }
799     else
800         Insert( new RscDepend( lIncFile ), lPos );
801 
802     return sal_True;
803 }
804 
805 /*************************************************************************
806 |*
807 |*    RscFile::RemoveDependFile()
808 |*
809 |*    Beschreibung
810 |*    Ersterstellung    MM 18.11.91
811 |*    Letzte Aenderung  MM 18.11.91
812 |*
813 *************************************************************************/
814 void RscFile :: RemoveDependFile( sal_uLong lDepFile )
815 {
816 
817     RscDepend * pDep = Last();
818 
819     while( pDep ){
820         if( pDep->GetFileKey() == lDepFile ){
821             Remove( pDep );
822             delete pDep;
823         }
824         pDep = Prev();
825     }
826 }
827 
828 /****************** R s c D e f T r e e **********************************/
829 /*************************************************************************
830 |*
831 |*    RscDefTree::~RscDefTree()
832 |*
833 |*    Beschreibung
834 |*    Ersterstellung    MM 12.11.91
835 |*    Letzte Aenderung  MM 12.11.91
836 |*
837 *************************************************************************/
838 RscDefTree::~RscDefTree(){
839     Remove();
840 }
841 
842 /*************************************************************************
843 |*
844 |*    RscDefTree::Remove()
845 |*
846 |*    Beschreibung
847 |*    Ersterstellung    MM 12.11.91
848 |*    Letzte Aenderung  MM 12.11.91
849 |*
850 *************************************************************************/
851 void RscDefTree::Remove(){
852     RscDefine * pDef;
853     while( pDefRoot ){
854         pDef = pDefRoot;
855         pDefRoot = (RscDefine *)pDefRoot->Remove( pDefRoot );
856         pDef->DecRef();
857     }
858 }
859 
860 /*************************************************************************
861 |*
862 |*    RscDefTree::~Search()
863 |*
864 |*    Beschreibung
865 |*    Ersterstellung    MM 12.11.91
866 |*    Letzte Aenderung  MM 12.11.91
867 |*
868 *************************************************************************/
869 RscDefine * RscDefTree::Search( const char * pName ){
870     if( pDefRoot )
871         return pDefRoot->Search( pName );
872     return NULL;
873 }
874 
875 /*************************************************************************
876 |*
877 |*    RscDefTree::Insert()
878 |*
879 |*    Beschreibung
880 |*    Ersterstellung    MM 12.11.91
881 |*    Letzte Aenderung  MM 12.11.91
882 |*
883 *************************************************************************/
884 void RscDefTree::Insert( RscDefine * pDef ){
885     if( pDefRoot )
886         pDefRoot->Insert( pDef );
887     else
888         pDefRoot = pDef;
889     pDef->IncRef();
890 }
891 
892 /*************************************************************************
893 |*
894 |*    RscDefTree::Remove()
895 |*
896 |*    Beschreibung
897 |*    Ersterstellung    MM 12.11.91
898 |*    Letzte Aenderung  MM 12.11.91
899 |*
900 *************************************************************************/
901 void RscDefTree::Remove( RscDefine * pDef ){
902     if( pDefRoot ){
903         //falls pDef == pDefRoot
904         pDefRoot = (RscDefine *)pDefRoot->Remove( pDef );
905     }
906     pDef->DecRef();
907 }
908 
909 /*************************************************************************
910 |*
911 |*    RscDefTree::Evaluate()
912 |*
913 |*    Beschreibung
914 |*    Ersterstellung    MM 12.11.91
915 |*    Letzte Aenderung  MM 12.11.91
916 |*
917 *************************************************************************/
918 sal_Bool RscDefTree::Evaluate( RscDefine * pDef ){
919     if( pDef ){
920         if( !Evaluate( (RscDefine *)pDef->Left() ) )
921             return sal_False;
922         if( !Evaluate( (RscDefine *)pDef->Right() ) )
923             return sal_False;
924     };
925     return sal_True;
926 }
927 
928 sal_Bool RscDefTree::Evaluate(){
929     return Evaluate( pDefRoot );
930 }
931 
932 /****************** R s c F i l e T a b **********************************/
933 /*************************************************************************
934 |*
935 |*    RscFileTab::RscFileTab()
936 |*
937 |*    Beschreibung
938 |*    Ersterstellung    MM 07.11.91
939 |*    Letzte Aenderung  MM 07.11.91
940 |*
941 *************************************************************************/
942 RscFileTab::RscFileTab(){
943 }
944 
945 /*************************************************************************
946 |*
947 |*    RscFileTab::~RscFileTab()
948 |*
949 |*    Beschreibung
950 |*    Ersterstellung    MM 04.11.91
951 |*    Letzte Aenderung  MM 04.11.91
952 |*
953 *************************************************************************/
954 RscFileTab :: ~RscFileTab(){
955     RscFile * pFile;
956 
957     aDefTree.Remove();
958 
959     pFile = Last();
960     while( pFile ){
961         Remove( GetIndex( pFile ) );
962         delete pFile;
963         pFile = Prev();
964     };
965 }
966 
967 /*************************************************************************
968 |*
969 |*    RscFileTab::Find()
970 |*
971 |*    Beschreibung
972 |*    Ersterstellung    MM 16.05.91
973 |*    Letzte Aenderung  MM 16.05.91
974 |*
975 *************************************************************************/
976 sal_uLong  RscFileTab :: Find( const ByteString & rName )
977 {
978     RscFile * pFName;
979 
980     pFName = First();
981     while( pFName && (pFName->aFileName != rName) )
982         pFName = Next();
983 
984     if( pFName )
985         return( GetIndex( pFName ) );
986     else
987         return( NOFILE_INDEX );
988 }
989 
990 /*************************************************************************
991 |*
992 |*    RscFileTab::FindDef()
993 |*
994 |*    Beschreibung
995 |*    Ersterstellung    MM 30.10.91
996 |*    Letzte Aenderung  MM 01.11.91
997 |*
998 *************************************************************************/
999 RscDefine * RscFileTab::FindDef( const char * pName ){
1000     return aDefTree.Search( pName );
1001 }
1002 
1003 /*************************************************************************
1004 |*
1005 |*    RscFileTab::FindDef()
1006 |*
1007 |*    Beschreibung
1008 |*    Ersterstellung    MM 30.10.91
1009 |*    Letzte Aenderung  MM 01.11.91
1010 |*
1011 *************************************************************************/
1012 RscDefine * RscFileTab::FindDef( sal_uLong lFileKey, const ByteString & rName )
1013 {
1014     RscDefine   * pDef = FindDef( rName );
1015 
1016     if( pDef )
1017         //befindet sich das DEFINE in einer Include-Datei in der
1018         //Datei lFileKey
1019         if( Depend( lFileKey, pDef->GetFileKey() ) )
1020             return pDef;
1021     return NULL;
1022 }
1023 
1024 /*************************************************************************
1025 |*
1026 |*    RscFileTab::Depend()
1027 |*
1028 |*    Beschreibung
1029 |*    Ersterstellung    MM 08.11.91
1030 |*    Letzte Aenderung  MM 08.11.91
1031 |*
1032 *************************************************************************/
1033 sal_Bool RscFileTab::Depend( sal_uLong lDepend, sal_uLong lFree ){
1034     if( lDepend == lFree )
1035         return sal_True;
1036 
1037     RscFile * pFile = First();
1038     while( pFile ){
1039         if( !pFile->IsIncFile() ){
1040             if( !pFile->Depend( lDepend, lFree ) )
1041                 return sal_False;
1042         };
1043         pFile = Next();
1044     };
1045 
1046     return sal_True;
1047 }
1048 
1049 /*************************************************************************
1050 |*
1051 |*    RscFileTab::TestDef()
1052 |*
1053 |*    Beschreibung
1054 |*    Ersterstellung    MM 14.01.92
1055 |*    Letzte Aenderung  MM 14.01.92
1056 |*
1057 *************************************************************************/
1058 sal_Bool RscFileTab::TestDef( sal_uLong lFileKey, sal_uLong lPos,
1059                           const RscDefine * pDefDec )
1060 {
1061     if( lFileKey == pDefDec->GetFileKey() ){
1062         RscFile * pFile = GetFile( pDefDec->GetFileKey() );
1063         if( pFile && (lPos <= pFile->aDefLst.GetPos( (RscDefine *)pDefDec ))
1064           && (lPos != LIST_APPEND) )
1065             return sal_False;
1066     }
1067     else if( !Depend( lFileKey, pDefDec->GetFileKey() ) )
1068         return sal_False;
1069 
1070     return TestDef( lFileKey, lPos, pDefDec->pExp );
1071 }
1072 
1073 /*************************************************************************
1074 |*
1075 |*    RscFileTab::TestDef()
1076 |*
1077 |*    Beschreibung
1078 |*    Ersterstellung    MM 14.01.92
1079 |*    Letzte Aenderung  MM 14.01.92
1080 |*
1081 *************************************************************************/
1082 sal_Bool RscFileTab::TestDef( sal_uLong lFileKey, sal_uLong lPos,
1083                           const RscExpression * pExpDec )
1084 {
1085     if( !pExpDec )
1086         return sal_True;
1087 
1088     if( pExpDec->aLeftExp.IsExpression() )
1089         if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pExp ) )
1090             return sal_False;
1091 
1092     if( pExpDec->aLeftExp.IsDefinition() )
1093         if( !TestDef( lFileKey, lPos, pExpDec->aLeftExp.aExp.pDef ) )
1094             return sal_False;
1095 
1096     if( pExpDec->aRightExp.IsExpression() )
1097         if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pExp ) )
1098             return sal_False;
1099 
1100     if( pExpDec->aRightExp.IsDefinition() )
1101         if( !TestDef( lFileKey, lPos, pExpDec->aRightExp.aExp.pDef ) )
1102             return sal_False;
1103 
1104     return sal_True;
1105 }
1106 
1107 /*************************************************************************
1108 |*
1109 |*    RscFileTab::NewDef()
1110 |*
1111 |*    Beschreibung
1112 |*    Ersterstellung    MM 04.11.91
1113 |*    Letzte Aenderung  MM 04.11.91
1114 |*
1115 *************************************************************************/
1116 RscDefine * RscFileTab::NewDef( sal_uLong lFileKey, const ByteString & rDefName,
1117                                 sal_Int32 lId, sal_uLong lPos )
1118 {
1119     RscDefine * pDef = FindDef( rDefName );
1120 
1121     if( !pDef ){
1122         RscFile * pFile = GetFile( lFileKey );
1123 
1124         if( pFile ){
1125             pDef = pFile->aDefLst.New( lFileKey, rDefName, lId, lPos );
1126             aDefTree.Insert( pDef );
1127         }
1128     }
1129     else
1130         pDef = NULL;
1131 
1132     return( pDef );
1133 }
1134 
1135 /*************************************************************************
1136 |*
1137 |*    RscFileTab::NewDef()
1138 |*
1139 |*    Beschreibung
1140 |*    Ersterstellung    MM 04.11.91
1141 |*    Letzte Aenderung  MM 04.11.91
1142 |*
1143 *************************************************************************/
1144 RscDefine * RscFileTab::NewDef( sal_uLong lFileKey, const ByteString & rDefName,
1145                                 RscExpression * pExp, sal_uLong lPos )
1146 {
1147     RscDefine * pDef = FindDef( rDefName );
1148 
1149     if( !pDef ){
1150         //Macros in den Expressions sind definiert ?
1151         if( TestDef( lFileKey, lPos, pExp ) ){
1152             RscFile * pFile = GetFile( lFileKey );
1153 
1154             if( pFile ){
1155                 pDef = pFile->aDefLst.New( lFileKey, rDefName, pExp, lPos );
1156                 aDefTree.Insert( pDef );
1157             }
1158         }
1159     }
1160     else
1161         pDef = NULL;
1162 
1163     if( !pDef ){
1164         // pExp wird immer Eigentum und muss, wenn es nicht benoetigt wird
1165         // geloescht werden
1166         delete pExp;
1167     }
1168     return( pDef );
1169 }
1170 
1171 /*************************************************************************
1172 |*
1173 |*    RscFileTab::IsDefUsed()
1174 |*
1175 |*    Beschreibung
1176 |*    Ersterstellung    MM 22.11.91
1177 |*    Letzte Aenderung  MM 22.11.91
1178 |*
1179 *************************************************************************/
1180 sal_Bool RscFileTab::IsDefUsed( const ByteString & rDefName )
1181 {
1182     RscDefine * pDef = FindDef( rDefName );
1183 
1184     if( pDef )
1185         return( pDef->GetRefCount() != 2 );
1186 
1187     return sal_False;
1188 }
1189 
1190 /*************************************************************************
1191 |*
1192 |*    RscFileTab::DeleteDef()
1193 |*
1194 |*    Beschreibung
1195 |*    Ersterstellung    MM 11.11.91
1196 |*    Letzte Aenderung  MM 11.11.91
1197 |*
1198 *************************************************************************/
1199 void RscFileTab::DeleteDef( const ByteString & rDefName )
1200 {
1201     RscDefine * pDef = FindDef( rDefName );
1202     RscFile   * pFile;
1203 
1204     if( pDef ){
1205         pFile = GetFile( pDef->GetFileKey() );
1206         if( pFile ){
1207             aDefTree.Remove( pDef );
1208             pFile->aDefLst.Remove( pDef );
1209         }
1210     };
1211 }
1212 
1213 /*************************************************************************
1214 |*
1215 |*    RscFileTab::ChangeDef()
1216 |*
1217 |*    Beschreibung
1218 |*    Ersterstellung    MM 04.11.91
1219 |*    Letzte Aenderung  MM 11.11.91
1220 |*
1221 *************************************************************************/
1222 sal_Bool RscFileTab::ChangeDef( const ByteString & rDefName, sal_Int32 lId )
1223 {
1224     RscDefine * pDef = FindDef( rDefName );
1225 
1226     if( pDef ){
1227         pDef->ChangeMacro( lId );
1228         //alle Macros neu bewerten
1229         return aDefTree.Evaluate();
1230     };
1231     return( sal_False );
1232 }
1233 
1234 /*************************************************************************
1235 |*
1236 |*    RscFileTab::ChangeDef()
1237 |*
1238 |*    Beschreibung
1239 |*    Ersterstellung    MM 04.11.91
1240 |*    Letzte Aenderung  MM 11.11.91
1241 |*
1242 *************************************************************************/
1243 sal_Bool RscFileTab::ChangeDef( const ByteString & rDefName,
1244                             RscExpression * pExp )
1245 {
1246     RscDefine * pDef = FindDef( rDefName );
1247     RscFile   * pFile;
1248     sal_uLong       lPos = 0;
1249 
1250     if( pDef ){
1251         pFile = GetFile( pDef->GetFileKey() );
1252         if( pFile )
1253             lPos = pFile->aDefLst.GetPos( pDef );
1254         //Macros in den Expressions sind definiert ?
1255         if( TestDef( pDef->GetFileKey(), lPos, pExp ) ){
1256             pDef->ChangeMacro( pExp );
1257             //alle Macros neu bewerten
1258             return aDefTree.Evaluate();
1259         }
1260     };
1261 
1262     // pExp wird immer Eigentum und muss, wenn es nicht benoetigt wird
1263     // geloescht werden
1264     delete pExp;
1265 
1266     return( sal_False );
1267 }
1268 
1269 /*************************************************************************
1270 |*
1271 |*    RscFileTab::ChangeDefName()
1272 |*
1273 |*    Beschreibung
1274 |*    Ersterstellung    MM 04.11.91
1275 |*    Letzte Aenderung  MM 04.11.91
1276 |*
1277 *************************************************************************/
1278 sal_Bool RscFileTab::ChangeDefName( const ByteString & rDefName,
1279                                 const ByteString & rNewName )
1280 {
1281     RscDefine * pDef = FindDef( rDefName );
1282 
1283     //Name gefunden ?
1284     if( pDef ){
1285         // und neuer Name noch nicht bekannt ?
1286         if( !FindDef( pDef->GetFileKey(), rNewName ) ){
1287             aDefTree.Remove( pDef );
1288             pDef->SetName( rNewName );
1289             aDefTree.Insert( pDef );
1290             return( sal_True );
1291         }
1292     };
1293 
1294     return( sal_False );
1295 }
1296 
1297 /*************************************************************************
1298 |*
1299 |*    RscFileTab::DeleteFileContext()
1300 |*
1301 |*    Beschreibung
1302 |*    Ersterstellung    MM 09.12.91
1303 |*    Letzte Aenderung  MM 09.12.91
1304 |*
1305 *************************************************************************/
1306 void RscFileTab :: DeleteFileContext( sal_uLong lFileKey ){
1307     RscFile     * pFName;
1308 
1309     pFName = GetFile( lFileKey );
1310     if( pFName ){
1311         RscDefine * pDef;
1312 
1313         pDef = pFName->aDefLst.First();
1314         while( pDef ){
1315             aDefTree.Remove( pDef );
1316             pDef = pFName->aDefLst.Next();
1317         };
1318         while( pFName->aDefLst.Remove( (sal_uLong)0 ) ) ;
1319     }
1320 }
1321 
1322 /*************************************************************************
1323 |*
1324 |*    RscFileTab::DeleteFile()
1325 |*
1326 |*    Beschreibung
1327 |*    Ersterstellung    MM 16.05.91
1328 |*    Letzte Aenderung  MM 16.05.91
1329 |*
1330 *************************************************************************/
1331 void RscFileTab :: DeleteFile( sal_uLong lFileKey ){
1332     RscFile     * pFName;
1333 
1334     //Defines freigeben
1335     DeleteFileContext( lFileKey );
1336 
1337     //Schleife ueber alle Abhaengigkeiten
1338     pFName = First();
1339     while( pFName ){
1340         pFName->RemoveDependFile( lFileKey );
1341         pFName = Next();
1342     };
1343 
1344     pFName = Remove( lFileKey );
1345     if( pFName )
1346         delete pFName;
1347 }
1348 
1349 /*************************************************************************
1350 |*
1351 |*    RscFileTab::NewCodeFile()
1352 |*
1353 |*    Beschreibung
1354 |*    Ersterstellung    MM 16.05.91
1355 |*    Letzte Aenderung  MM 16.05.91
1356 |*
1357 *************************************************************************/
1358 sal_uLong  RscFileTab :: NewCodeFile( const ByteString & rName )
1359 {
1360     sal_uLong       lKey;
1361     RscFile *   pFName;
1362 
1363     lKey = Find( rName );
1364     if( UNIQUEINDEX_ENTRY_NOTFOUND == lKey )
1365     {
1366         pFName = new RscFile();
1367         pFName->aFileName = rName;
1368         pFName->aPathName = rName;
1369         lKey = Insert( pFName );
1370         pFName->InsertDependFile( lKey, LIST_APPEND );
1371     }
1372     return lKey;
1373 }
1374 
1375 /*************************************************************************
1376 |*
1377 |*    RscFileTab::NewIncFile()
1378 |*
1379 |*    Beschreibung
1380 |*    Ersterstellung    MM 16.05.91
1381 |*    Letzte Aenderung  MM 16.05.91
1382 |*
1383 *************************************************************************/
1384 sal_uLong  RscFileTab :: NewIncFile( const ByteString & rName,
1385                                  const ByteString & rPath )
1386 {
1387     sal_uLong         lKey;
1388     RscFile * pFName;
1389 
1390     lKey = Find( rName );
1391     if( UNIQUEINDEX_ENTRY_NOTFOUND == lKey )
1392     {
1393         pFName = new RscFile();
1394         pFName->aFileName = rName;
1395         pFName->aPathName = rPath;
1396         pFName->SetIncFlag();
1397         lKey = Insert( pFName );
1398         pFName->InsertDependFile( lKey, LIST_APPEND );
1399     }
1400     return lKey;
1401 }
1402