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