1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rsckey.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
39 #include <rsctools.hxx>
40 #include <rschash.hxx>
43 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
44 #define _cdecl __cdecl
47 /****************** C o d e **********************************************/
48 /****************** keyword sort function ********************************/
50 #if defined( ZTC ) && defined( PM2 )
51 int __CLIB
KeyCompare( const void * pFirst
, const void * pSecond
);
53 #if defined( WNT ) && !defined( WTC ) && !defined (ICC)
54 int _cdecl
KeyCompare( const void * pFirst
, const void * pSecond
);
56 int KeyCompare( const void * pFirst
, const void * pSecond
);
61 #if defined( WNT ) && !defined( WTC ) && !defined(ICC)
62 int _cdecl
KeyCompare( const void * pFirst
, const void * pSecond
){
64 int KeyCompare( const void * pFirst
, const void * pSecond
){
66 if( ((KEY_STRUCT
*)pFirst
)->nName
> ((KEY_STRUCT
*)pSecond
)->nName
)
68 else if( ((KEY_STRUCT
*)pFirst
)->nName
< ((KEY_STRUCT
*)pSecond
)->nName
)
74 /*************************************************************************
76 |* RscNameTable::RscNameTable()
78 |* Beschreibung RES.DOC
79 |* Ersterstellung MM 28.02.91
80 |* Letzte Aenderung MM 28.02.91
82 *************************************************************************/
83 RscNameTable::RscNameTable() {
89 /*************************************************************************
91 |* RscNameTable::~RscNameTable()
94 |* Ersterstellung MM 15.05.91
95 |* Letzte Aenderung MM 15.05.91
97 *************************************************************************/
98 RscNameTable::~RscNameTable() {
100 rtl_freeMemory( pTable
);
104 /*************************************************************************
106 |* RscNameTable::SetSort()
108 |* Beschreibung RES.DOC
109 |* Ersterstellung MM 28.02.91
110 |* Letzte Aenderung MM 28.02.91
112 *************************************************************************/
113 void RscNameTable::SetSort( BOOL bSorted
){
115 if( bSort
&& pTable
){
116 // Schluesselwort Feld sortieren
117 qsort( (void *)pTable
, nEntries
,
118 sizeof( KEY_STRUCT
), KeyCompare
);
122 /*************************************************************************
124 |* RscNameTable::Put()
126 |* Beschreibung RES.DOC
127 |* Ersterstellung MM 28.02.91
128 |* Letzte Aenderung MM 28.02.91
130 *************************************************************************/
131 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, long nValue
){
133 pTable
= (KEY_STRUCT
*)
134 rtl_reallocateMemory( (void *)pTable
,
135 ((nEntries
+1) * sizeof( KEY_STRUCT
)) );
137 pTable
= (KEY_STRUCT
*)
138 rtl_allocateMemory( ((nEntries
+1)
139 * sizeof( KEY_STRUCT
)) );
140 pTable
[ nEntries
].nName
= nName
;
141 pTable
[ nEntries
].nTyp
= nTyp
;
142 pTable
[ nEntries
].yylval
= nValue
;
149 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
, long nValue
)
151 return( Put( pHS
->getID( pName
), nTyp
, nValue
) );
154 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
)
156 return( Put( nName
, nTyp
, (long)nName
) );
159 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
)
163 nId
= pHS
->getID( pName
);
164 return( Put( nId
, nTyp
, (long)nId
) );
167 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, RscTop
* pClass
)
169 return( Put( nName
, nTyp
, (long)pClass
) );
172 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
, RscTop
* pClass
)
174 return( Put( pHS
->getID( pName
), nTyp
, (long)pClass
) );
177 /*************************************************************************
179 |* RscNameTable::Get()
181 |* Beschreibung RES.DOC
182 |* Ersterstellung MM 28.02.91
183 |* Letzte Aenderung MM 28.02.91
185 *************************************************************************/
186 BOOL
RscNameTable::Get( Atom nName
, KEY_STRUCT
* pEle
){
187 KEY_STRUCT
* pKey
= NULL
;
188 KEY_STRUCT aSearchName
;
192 // Suche nach dem Schluesselwort
193 aSearchName
.nName
= nName
;
194 pKey
= (KEY_STRUCT
*)bsearch(
196 (const char *) &aSearchName
, (char *)pTable
,
198 (const void *) &aSearchName
, (const void *)pTable
,
200 nEntries
, sizeof( KEY_STRUCT
), KeyCompare
);
204 while( i
< nEntries
&& !pKey
){
205 if( pTable
[ i
].nName
== nName
)
211 if( pKey
){ // Schluesselwort gefunden