xref: /aoo41x/main/rsc/source/parser/rsckey.cxx (revision 477794c1)
1*477794c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*477794c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*477794c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*477794c1SAndrew Rist  * distributed with this work for additional information
6*477794c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*477794c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*477794c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*477794c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*477794c1SAndrew Rist  *
11*477794c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*477794c1SAndrew Rist  *
13*477794c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*477794c1SAndrew Rist  * software distributed under the License is distributed on an
15*477794c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*477794c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*477794c1SAndrew Rist  * specific language governing permissions and limitations
18*477794c1SAndrew Rist  * under the License.
19*477794c1SAndrew Rist  *
20*477794c1SAndrew Rist  *************************************************************/
21*477794c1SAndrew Rist 
22*477794c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_rsc.hxx"
26cdf0e10cSrcweir /****************** I N C L U D E S **************************************/
27cdf0e10cSrcweir #include <stdlib.h>
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir #include <ctype.h>
30cdf0e10cSrcweir #include <string.h>
31cdf0e10cSrcweir #include <rscall.h>
32cdf0e10cSrcweir #include <rsctools.hxx>
33cdf0e10cSrcweir #include <rschash.hxx>
34cdf0e10cSrcweir #include <rsckey.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
37cdf0e10cSrcweir #define _cdecl __cdecl
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /****************** C o d e **********************************************/
41cdf0e10cSrcweir /****************** keyword sort function ********************************/
42cdf0e10cSrcweir extern "C" {
43cdf0e10cSrcweir #if defined( ZTC ) && defined( PM2 )
44cdf0e10cSrcweir     int __CLIB KeyCompare( const void * pFirst, const void * pSecond );
45cdf0e10cSrcweir #else
46cdf0e10cSrcweir #if defined( WNT ) && !defined( WTC ) && !defined (ICC)
47cdf0e10cSrcweir     int _cdecl KeyCompare( const void * pFirst, const void * pSecond );
48cdf0e10cSrcweir #else
49cdf0e10cSrcweir     int KeyCompare( const void * pFirst, const void * pSecond );
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #if defined( WNT ) && !defined( WTC ) && !defined(ICC)
KeyCompare(const void * pFirst,const void * pSecond)55cdf0e10cSrcweir int _cdecl KeyCompare( const void * pFirst, const void * pSecond ){
56cdf0e10cSrcweir #else
57cdf0e10cSrcweir int KeyCompare( const void * pFirst, const void * pSecond ){
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir     if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
60cdf0e10cSrcweir         return( 1 );
61cdf0e10cSrcweir     else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
62cdf0e10cSrcweir         return( -1 );
63cdf0e10cSrcweir     else
64cdf0e10cSrcweir         return( 0 );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*************************************************************************
68cdf0e10cSrcweir |*
69cdf0e10cSrcweir |*    RscNameTable::RscNameTable()
70cdf0e10cSrcweir |*
71cdf0e10cSrcweir |*    Beschreibung      RES.DOC
72cdf0e10cSrcweir |*    Ersterstellung    MM 28.02.91
73cdf0e10cSrcweir |*    Letzte Aenderung  MM 28.02.91
74cdf0e10cSrcweir |*
75cdf0e10cSrcweir *************************************************************************/
76cdf0e10cSrcweir RscNameTable::RscNameTable() {
77cdf0e10cSrcweir     bSort    = sal_True;
78cdf0e10cSrcweir     nEntries = 0;
79cdf0e10cSrcweir     pTable   = NULL;
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir /*************************************************************************
83cdf0e10cSrcweir |*
84cdf0e10cSrcweir |*    RscNameTable::~RscNameTable()
85cdf0e10cSrcweir |*
86cdf0e10cSrcweir |*    Beschreibung
87cdf0e10cSrcweir |*    Ersterstellung    MM 15.05.91
88cdf0e10cSrcweir |*    Letzte Aenderung  MM 15.05.91
89cdf0e10cSrcweir |*
90cdf0e10cSrcweir *************************************************************************/
91cdf0e10cSrcweir RscNameTable::~RscNameTable() {
92cdf0e10cSrcweir     if( pTable )
93cdf0e10cSrcweir         rtl_freeMemory( pTable );
94cdf0e10cSrcweir };
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir /*************************************************************************
98cdf0e10cSrcweir |*
99cdf0e10cSrcweir |*    RscNameTable::SetSort()
100cdf0e10cSrcweir |*
101cdf0e10cSrcweir |*    Beschreibung      RES.DOC
102cdf0e10cSrcweir |*    Ersterstellung    MM 28.02.91
103cdf0e10cSrcweir |*    Letzte Aenderung  MM 28.02.91
104cdf0e10cSrcweir |*
105cdf0e10cSrcweir *************************************************************************/
106cdf0e10cSrcweir void RscNameTable::SetSort( sal_Bool bSorted ){
107cdf0e10cSrcweir     bSort = bSorted;
108cdf0e10cSrcweir     if( bSort && pTable){
109cdf0e10cSrcweir         // Schluesselwort Feld sortieren
110cdf0e10cSrcweir         qsort( (void *)pTable, nEntries,
111cdf0e10cSrcweir                sizeof( KEY_STRUCT ), KeyCompare );
112cdf0e10cSrcweir     };
113cdf0e10cSrcweir };
114cdf0e10cSrcweir 
115cdf0e10cSrcweir /*************************************************************************
116cdf0e10cSrcweir |*
117cdf0e10cSrcweir |*    RscNameTable::Put()
118cdf0e10cSrcweir |*
119cdf0e10cSrcweir |*    Beschreibung      RES.DOC
120cdf0e10cSrcweir |*    Ersterstellung    MM 28.02.91
121cdf0e10cSrcweir |*    Letzte Aenderung  MM 28.02.91
122cdf0e10cSrcweir |*
123cdf0e10cSrcweir *************************************************************************/
124cdf0e10cSrcweir Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, long nValue ){
125cdf0e10cSrcweir     if( pTable )
126cdf0e10cSrcweir         pTable = (KEY_STRUCT *)
127cdf0e10cSrcweir                  rtl_reallocateMemory( (void *)pTable,
128cdf0e10cSrcweir                  ((nEntries +1) * sizeof( KEY_STRUCT )) );
129cdf0e10cSrcweir     else
130cdf0e10cSrcweir         pTable = (KEY_STRUCT *)
131cdf0e10cSrcweir                  rtl_allocateMemory( ((nEntries +1)
132cdf0e10cSrcweir                                  * sizeof( KEY_STRUCT )) );
133cdf0e10cSrcweir     pTable[ nEntries ].nName  = nName;
134cdf0e10cSrcweir     pTable[ nEntries ].nTyp   = nTyp;
135cdf0e10cSrcweir     pTable[ nEntries ].yylval = nValue;
136cdf0e10cSrcweir     nEntries++;
137cdf0e10cSrcweir     if( bSort )
138cdf0e10cSrcweir         SetSort();
139cdf0e10cSrcweir     return( nName );
140cdf0e10cSrcweir };
141cdf0e10cSrcweir 
142cdf0e10cSrcweir Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, long nValue )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     return( Put( pHS->getID( pName ), nTyp, nValue ) );
145cdf0e10cSrcweir };
146cdf0e10cSrcweir 
147cdf0e10cSrcweir Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     return( Put( nName, nTyp, (long)nName ) );
150cdf0e10cSrcweir };
151cdf0e10cSrcweir 
152cdf0e10cSrcweir Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     Atom  nId;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     nId = pHS->getID( pName );
157cdf0e10cSrcweir     return( Put( nId, nTyp, (long)nId ) );
158cdf0e10cSrcweir };
159cdf0e10cSrcweir 
160cdf0e10cSrcweir Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     return( Put( nName, nTyp, (long)pClass ) );
163cdf0e10cSrcweir };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, RscTop * pClass )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     return( Put( pHS->getID( pName ), nTyp, (long)pClass ) );
168cdf0e10cSrcweir };
169cdf0e10cSrcweir 
170cdf0e10cSrcweir /*************************************************************************
171cdf0e10cSrcweir |*
172cdf0e10cSrcweir |*    RscNameTable::Get()
173cdf0e10cSrcweir |*
174cdf0e10cSrcweir |*    Beschreibung      RES.DOC
175cdf0e10cSrcweir |*    Ersterstellung    MM 28.02.91
176cdf0e10cSrcweir |*    Letzte Aenderung  MM 28.02.91
177cdf0e10cSrcweir |*
178cdf0e10cSrcweir *************************************************************************/
179cdf0e10cSrcweir sal_Bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle ){
180cdf0e10cSrcweir     KEY_STRUCT * pKey = NULL;
181cdf0e10cSrcweir     KEY_STRUCT  aSearchName;
182cdf0e10cSrcweir     sal_uInt32  i;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     if( bSort ){
185cdf0e10cSrcweir         // Suche nach dem Schluesselwort
186cdf0e10cSrcweir         aSearchName.nName = nName;
187cdf0e10cSrcweir         pKey = (KEY_STRUCT *)bsearch(
188cdf0e10cSrcweir #ifdef UNX
189cdf0e10cSrcweir                    (const char *) &aSearchName, (char *)pTable,
190cdf0e10cSrcweir #else
191cdf0e10cSrcweir                    (const void *) &aSearchName, (const void *)pTable,
192cdf0e10cSrcweir #endif
193cdf0e10cSrcweir                    nEntries, sizeof( KEY_STRUCT ), KeyCompare );
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     else{
196cdf0e10cSrcweir         i = 0;
197cdf0e10cSrcweir         while( i < nEntries && !pKey ){
198cdf0e10cSrcweir             if( pTable[ i ].nName == nName )
199cdf0e10cSrcweir                 pKey = &pTable[ i ];
200cdf0e10cSrcweir             i++;
201cdf0e10cSrcweir         };
202cdf0e10cSrcweir     };
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     if( pKey ){ // Schluesselwort gefunden
205cdf0e10cSrcweir         *pEle = *pKey;
206cdf0e10cSrcweir         return( sal_True );
207cdf0e10cSrcweir     };
208cdf0e10cSrcweir     return( sal_False );
209cdf0e10cSrcweir };
210cdf0e10cSrcweir 
211