xref: /trunk/main/rsc/inc/rscdef.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*f7c60c9cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f7c60c9cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f7c60c9cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f7c60c9cSAndrew Rist  * distributed with this work for additional information
6*f7c60c9cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f7c60c9cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f7c60c9cSAndrew Rist  * "License"); you may not use this file except in compliance
9*f7c60c9cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f7c60c9cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f7c60c9cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f7c60c9cSAndrew Rist  * software distributed under the License is distributed on an
15*f7c60c9cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f7c60c9cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f7c60c9cSAndrew Rist  * specific language governing permissions and limitations
18*f7c60c9cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f7c60c9cSAndrew Rist  *************************************************************/
21*f7c60c9cSAndrew Rist 
22*f7c60c9cSAndrew Rist 
23cdf0e10cSrcweir #ifndef _RSCDEF_HXX
24cdf0e10cSrcweir #define _RSCDEF_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifndef _TOOLS_UNQIDX_HXX
27cdf0e10cSrcweir #include <tools/unqidx.hxx>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <rsctree.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /****************** C L A S S E S ****************************************/
32cdf0e10cSrcweir class RscExpression;
33cdf0e10cSrcweir class RscFileTab;
34cdf0e10cSrcweir class RscDefine;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /*********** R s c E x p r e s s i o n ***********************************/
37cdf0e10cSrcweir #define RSCEXP_LONG     0
38cdf0e10cSrcweir #define RSCEXP_EXP      1
39cdf0e10cSrcweir #define RSCEXP_DEF      2
40cdf0e10cSrcweir #define RSCEXP_NOTHING  3
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class RscExpType
43cdf0e10cSrcweir {
44cdf0e10cSrcweir public:
45cdf0e10cSrcweir     union {
46cdf0e10cSrcweir         RscExpression * pExp;
47cdf0e10cSrcweir         RscDefine     * pDef;
48cdf0e10cSrcweir         struct {
49cdf0e10cSrcweir              short           nHi;
50cdf0e10cSrcweir              unsigned short  nLo;
51cdf0e10cSrcweir         } aLong;
52cdf0e10cSrcweir     } aExp;
53cdf0e10cSrcweir     char cType;
54cdf0e10cSrcweir     char cUnused;
IsNumber() const55cdf0e10cSrcweir     sal_Bool IsNumber()    const { return( RSCEXP_LONG     == cType ); }
IsExpression() const56cdf0e10cSrcweir     sal_Bool IsExpression()const { return( RSCEXP_EXP      == cType ); }
IsDefinition() const57cdf0e10cSrcweir     sal_Bool IsDefinition()const { return( RSCEXP_DEF      == cType ); }
IsNothing() const58cdf0e10cSrcweir     sal_Bool IsNothing()   const { return( RSCEXP_NOTHING  == cType ); }
SetLong(sal_Int32 lValue)59cdf0e10cSrcweir     void SetLong( sal_Int32 lValue ){
60cdf0e10cSrcweir             aExp.aLong.nHi = (short)(lValue >> 16);
61cdf0e10cSrcweir             aExp.aLong.nLo = (unsigned short)lValue;
62cdf0e10cSrcweir             cType = RSCEXP_LONG;
63cdf0e10cSrcweir          }
GetLong() const64cdf0e10cSrcweir     sal_Int32 GetLong() const{
65cdf0e10cSrcweir              return aExp.aLong.nLo |
66cdf0e10cSrcweir                     ((sal_Int32)aExp.aLong.nHi << 16);
67cdf0e10cSrcweir          }
68cdf0e10cSrcweir     sal_Bool Evaluate( sal_Int32 * pValue ) const;
69cdf0e10cSrcweir     void GetMacro( ByteString & ) const;
70cdf0e10cSrcweir };
71cdf0e10cSrcweir 
72cdf0e10cSrcweir /*********** R s c I d ***************************************************/
73cdf0e10cSrcweir class RscId
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     static      sal_Bool bNames;// sal_False, bei den Namenoperation nur Zahlen
76cdf0e10cSrcweir public:
77cdf0e10cSrcweir     RscExpType  aExp;       // Zahl, Define oder Ausdruck
78cdf0e10cSrcweir     sal_Int32   GetNumber() const;
79cdf0e10cSrcweir     void    Create( const RscExpType & rExpType );
Create()80cdf0e10cSrcweir     void    Create(){ aExp.cType = RSCEXP_NOTHING; }
81cdf0e10cSrcweir 
RscId()82cdf0e10cSrcweir             RscId() { Create();                         }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             RscId( RscDefine * pEle );
RscId(sal_Int32 lNumber)85cdf0e10cSrcweir             RscId( sal_Int32 lNumber )
86cdf0e10cSrcweir                     { aExp.SetLong( lNumber );          }
87cdf0e10cSrcweir 
RscId(const RscExpType & rExpType)88cdf0e10cSrcweir             RscId( const RscExpType & rExpType )
89cdf0e10cSrcweir                     { Create( rExpType );               }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             void Destroy();
92cdf0e10cSrcweir 
~RscId()93cdf0e10cSrcweir             ~RscId(){
94cdf0e10cSrcweir                 Destroy();
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             RscId( const RscId& rRscId );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             RscId& operator = ( const RscId& rRscId );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     static sal_Bool    IsSetNames();
102cdf0e10cSrcweir     static void    SetNames( sal_Bool bSet = sal_True );
103cdf0e10cSrcweir     operator         sal_Int32() const;   // Gibt Nummer zurueck
104cdf0e10cSrcweir     ByteString     GetName()  const;   // Gibt den Namen des Defines zurueck
105cdf0e10cSrcweir     ByteString     GetMacro()  const;  // Gibt das Macro zurueck
106cdf0e10cSrcweir     sal_Bool    operator <  ( const RscId& rRscId ) const;
107cdf0e10cSrcweir     sal_Bool    operator >  ( const RscId& rRscId ) const;
108cdf0e10cSrcweir     sal_Bool    operator == ( const RscId& rRscId ) const;
operator <=(const RscId & rRscId) const109cdf0e10cSrcweir     sal_Bool    operator <=  ( const RscId& rRscId ) const
110cdf0e10cSrcweir             { return !(operator > ( rRscId )); }
operator >=(const RscId & rRscId) const111cdf0e10cSrcweir     sal_Bool    operator >= ( const RscId& rRscId ) const
112cdf0e10cSrcweir             { return !(operator < ( rRscId )); }
IsId() const113cdf0e10cSrcweir     sal_Bool    IsId() const { return !aExp.IsNothing(); }
114cdf0e10cSrcweir };
115cdf0e10cSrcweir 
116cdf0e10cSrcweir /*********** R s c D e f i n e *******************************************/
117cdf0e10cSrcweir class RscDefine : public StringNode
118cdf0e10cSrcweir {
119cdf0e10cSrcweir friend class RscFileTab;
120cdf0e10cSrcweir friend class RscDefineList;
121cdf0e10cSrcweir friend class RscDefTree;
122cdf0e10cSrcweir friend class RscExpression;
123cdf0e10cSrcweir friend class RscId;
124cdf0e10cSrcweir     sal_uLong           lFileKey;   // zu welcher Datei gehoert das Define
125cdf0e10cSrcweir     sal_uInt32          nRefCount;  // Wieviele Referenzen auf dieses Objekt
126cdf0e10cSrcweir     sal_Int32           lId;        // Identifier
127cdf0e10cSrcweir     RscExpression * pExp;       // Ausdruck
128cdf0e10cSrcweir protected:
129cdf0e10cSrcweir 
130cdf0e10cSrcweir             RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
131cdf0e10cSrcweir                        sal_Int32 lDefId );
132cdf0e10cSrcweir             RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
133cdf0e10cSrcweir                        RscExpression * pExpression );
134cdf0e10cSrcweir             ~RscDefine();
IncRef()135cdf0e10cSrcweir     void    IncRef(){ nRefCount++; }
GetRefCount() const136cdf0e10cSrcweir     sal_uInt32  GetRefCount() const    { return nRefCount; }
137cdf0e10cSrcweir     void    DecRef();
138cdf0e10cSrcweir     void    DefineToNumber();
SetName(const ByteString & rNewName)139cdf0e10cSrcweir     void    SetName( const ByteString & rNewName ){ aName = rNewName; }
140cdf0e10cSrcweir     void    ChangeMacro( RscExpression * pExpression );
141cdf0e10cSrcweir     void    ChangeMacro( sal_Int32 lIdentifier );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     using StringNode::Search;
144cdf0e10cSrcweir public:
145cdf0e10cSrcweir     RscDefine * Search( const char * );
GetFileKey() const146cdf0e10cSrcweir     sal_uLong       GetFileKey() const { return lFileKey; }
147cdf0e10cSrcweir     sal_Bool        Evaluate();
GetNumber() const148cdf0e10cSrcweir     sal_Int32       GetNumber() const  { return lId;      }
149cdf0e10cSrcweir     ByteString  GetMacro();
150cdf0e10cSrcweir };
151cdf0e10cSrcweir 
152cdf0e10cSrcweir DECLARE_LIST( RscSubDefList, RscDefine * )
153cdf0e10cSrcweir 
154cdf0e10cSrcweir class RscDefineList : public RscSubDefList {
155cdf0e10cSrcweir friend class RscFile;
156cdf0e10cSrcweir friend class RscFileTab;
157cdf0e10cSrcweir private:
158cdf0e10cSrcweir                 // pExpression wird auf jedenfall Eigentum der Liste
159cdf0e10cSrcweir     RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
160cdf0e10cSrcweir                      sal_Int32 lDefId, sal_uLong lPos );
161cdf0e10cSrcweir     RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
162cdf0e10cSrcweir                      RscExpression * pExpression, sal_uLong lPos );
163cdf0e10cSrcweir     sal_Bool        Befor( const RscDefine * pFree, const RscDefine * pDepend );
164cdf0e10cSrcweir     sal_Bool        Remove( RscDefine * pDef );
165cdf0e10cSrcweir     sal_Bool        Remove( sal_uLong nIndex );
166cdf0e10cSrcweir     sal_Bool        Remove();
167cdf0e10cSrcweir public:
168cdf0e10cSrcweir     void        WriteAll( FILE * fOutput );
169cdf0e10cSrcweir };
170cdf0e10cSrcweir 
171cdf0e10cSrcweir /*********** R s c E x p r e s s i o n ***********************************/
172cdf0e10cSrcweir class RscExpression {
173cdf0e10cSrcweir friend class RscFileTab;
174cdf0e10cSrcweir     char        cOperation;
175cdf0e10cSrcweir     RscExpType  aLeftExp;
176cdf0e10cSrcweir     RscExpType  aRightExp;
177cdf0e10cSrcweir public:
178cdf0e10cSrcweir                 RscExpression( RscExpType aLE, char cOp,
179cdf0e10cSrcweir                                RscExpType aRE );
180cdf0e10cSrcweir                 ~RscExpression();
181cdf0e10cSrcweir     sal_Bool        Evaluate( sal_Int32 * pValue );
182cdf0e10cSrcweir     ByteString  GetMacro();
183cdf0e10cSrcweir };
184cdf0e10cSrcweir 
185cdf0e10cSrcweir /********************** R S C F I L E ************************************/
186cdf0e10cSrcweir class RscDepend {
187cdf0e10cSrcweir     sal_uLong            lKey;
188cdf0e10cSrcweir public:
RscDepend(sal_uLong lIncKey)189cdf0e10cSrcweir             RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
GetFileKey()190cdf0e10cSrcweir     sal_uLong   GetFileKey(){ return lKey; }
191cdf0e10cSrcweir };
192cdf0e10cSrcweir DECLARE_LIST( RscDependList, RscDepend * )
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // Tabelle die alle Dateinamen enthaelt
195cdf0e10cSrcweir class RscFile : public RscDependList
196cdf0e10cSrcweir {
197cdf0e10cSrcweir friend class RscFileTab;
198cdf0e10cSrcweir     sal_Bool            bIncFile;   // Ist es eine Include-Datei
199cdf0e10cSrcweir public:
200cdf0e10cSrcweir     sal_Bool            bLoaded;    // Ist die Datei geladen
201cdf0e10cSrcweir     sal_Bool            bScanned;   // Wurde Datei nach Inclide abgesucht
202cdf0e10cSrcweir     sal_Bool            bDirty;     // Dirty-Flag
203cdf0e10cSrcweir     ByteString      aFileName;  // Name der Datei
204cdf0e10cSrcweir     ByteString      aPathName;  // Pfad und Name der Datei
205cdf0e10cSrcweir     RscDefineList   aDefLst;    // Liste der Defines
206cdf0e10cSrcweir 
207cdf0e10cSrcweir                     RscFile();
208cdf0e10cSrcweir                     ~RscFile();
209cdf0e10cSrcweir     sal_Bool            InsertDependFile( sal_uLong lDepFile, sal_uLong lPos );
210cdf0e10cSrcweir     void            RemoveDependFile( sal_uLong lDepFile );
211cdf0e10cSrcweir     sal_Bool            Depend( sal_uLong lDepend, sal_uLong lFree );
SetIncFlag()212cdf0e10cSrcweir     void            SetIncFlag(){ bIncFile = sal_True; };
IsIncFile()213cdf0e10cSrcweir     sal_Bool            IsIncFile(){  return bIncFile; };
214cdf0e10cSrcweir };
215cdf0e10cSrcweir 
216cdf0e10cSrcweir DECLARE_UNIQUEINDEX( RscSubFileTab, RscFile * )
217cdf0e10cSrcweir #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
218cdf0e10cSrcweir 
219cdf0e10cSrcweir class RscDefTree {
220cdf0e10cSrcweir     RscDefine * pDefRoot;
221cdf0e10cSrcweir public:
222cdf0e10cSrcweir     static sal_Bool Evaluate( RscDefine * pDef );
RscDefTree()223cdf0e10cSrcweir                 RscDefTree(){ pDefRoot = NULL; }
224cdf0e10cSrcweir                 ~RscDefTree();
225cdf0e10cSrcweir     void        Remove();
226cdf0e10cSrcweir     sal_Bool        Evaluate();
227cdf0e10cSrcweir     RscDefine * Search( const char * pName );
228cdf0e10cSrcweir     void        Insert( RscDefine * pDef );
229cdf0e10cSrcweir     void        Remove( RscDefine * pDef );
230cdf0e10cSrcweir };
231cdf0e10cSrcweir 
232cdf0e10cSrcweir class RscFileTab : public RscSubFileTab {
233cdf0e10cSrcweir     RscDefTree aDefTree;
234cdf0e10cSrcweir     sal_uLong       Find( const ByteString & rName );
235cdf0e10cSrcweir public:
236cdf0e10cSrcweir                 RscFileTab();
237cdf0e10cSrcweir                 ~RscFileTab();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     RscDefine * FindDef( const char * );
FindDef(const ByteString & rStr)240cdf0e10cSrcweir     RscDefine * FindDef( const ByteString& rStr ) { return FindDef( rStr.GetBuffer() ); }
241cdf0e10cSrcweir     RscDefine * FindDef( sal_uLong lKey, const ByteString & );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     sal_Bool        Depend( sal_uLong lDepend, sal_uLong lFree );
244cdf0e10cSrcweir     sal_Bool        TestDef( sal_uLong lFileKey, sal_uLong lPos,
245cdf0e10cSrcweir                          const RscDefine * pDefDec );
246cdf0e10cSrcweir     sal_Bool        TestDef( sal_uLong lFileKey, sal_uLong lPos,
247cdf0e10cSrcweir                          const RscExpression * pExpDec );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
250cdf0e10cSrcweir                         sal_Int32 lId, sal_uLong lPos );
251cdf0e10cSrcweir     RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
252cdf0e10cSrcweir                         RscExpression *, sal_uLong lPos );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     sal_Bool        ChangeDef( const ByteString & rDefName, sal_Int32 lId );
255cdf0e10cSrcweir     sal_Bool        ChangeDef( const ByteString & rDefName, RscExpression * );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     sal_Bool IsDefUsed( const ByteString & );
258cdf0e10cSrcweir     void DeleteDef( const ByteString & );
259cdf0e10cSrcweir     sal_Bool ChangeDefName( const ByteString & rDefName,
260cdf0e10cSrcweir                         const ByteString & rNewName );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir            // Alle Defines die in dieser Datei Definiert sind loeschen
263cdf0e10cSrcweir     void   DeleteFileContext( sal_uLong lKey );
264cdf0e10cSrcweir     void   DeleteFile( sal_uLong lKey );
265cdf0e10cSrcweir     sal_uLong  NewCodeFile( const ByteString & rName );
266cdf0e10cSrcweir     sal_uLong  NewIncFile( const ByteString & rName, const ByteString & rPath );
GetFile(sal_uLong lFileKey)267cdf0e10cSrcweir     RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
268cdf0e10cSrcweir };
269cdf0e10cSrcweir 
270cdf0e10cSrcweir #endif // _RSCDEF_HXX
271