merge the formfield patch from ooo-build
[ooovba.git] / rsc / source / parser / rsckey.cxx
blob6d102135c48fec631bd0bea3d7e45019c94d8f6b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rsckey.cxx,v $
10 * $Revision: 1.7 $
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 **************************************/
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <string.h>
38 #include <rscall.h>
39 #include <rsctools.hxx>
40 #include <rschash.hxx>
41 #include <rsckey.hxx>
43 #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
44 #define _cdecl __cdecl
45 #endif
47 /****************** C o d e **********************************************/
48 /****************** keyword sort function ********************************/
49 extern "C" {
50 #if defined( ZTC ) && defined( PM2 )
51 int __CLIB KeyCompare( const void * pFirst, const void * pSecond );
52 #else
53 #if defined( WNT ) && !defined( WTC ) && !defined (ICC)
54 int _cdecl KeyCompare( const void * pFirst, const void * pSecond );
55 #else
56 int KeyCompare( const void * pFirst, const void * pSecond );
57 #endif
58 #endif
61 #if defined( WNT ) && !defined( WTC ) && !defined(ICC)
62 int _cdecl KeyCompare( const void * pFirst, const void * pSecond ){
63 #else
64 int KeyCompare( const void * pFirst, const void * pSecond ){
65 #endif
66 if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
67 return( 1 );
68 else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
69 return( -1 );
70 else
71 return( 0 );
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() {
84 bSort = TRUE;
85 nEntries = 0;
86 pTable = NULL;
89 /*************************************************************************
91 |* RscNameTable::~RscNameTable()
93 |* Beschreibung
94 |* Ersterstellung MM 15.05.91
95 |* Letzte Aenderung MM 15.05.91
97 *************************************************************************/
98 RscNameTable::~RscNameTable() {
99 if( pTable )
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 ){
114 bSort = 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 ){
132 if( pTable )
133 pTable = (KEY_STRUCT *)
134 rtl_reallocateMemory( (void *)pTable,
135 ((nEntries +1) * sizeof( KEY_STRUCT )) );
136 else
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;
143 nEntries++;
144 if( bSort )
145 SetSort();
146 return( nName );
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 )
161 Atom nId;
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;
189 sal_uInt32 i;
191 if( bSort ){
192 // Suche nach dem Schluesselwort
193 aSearchName.nName = nName;
194 pKey = (KEY_STRUCT *)bsearch(
195 #ifdef UNX
196 (const char *) &aSearchName, (char *)pTable,
197 #else
198 (const void *) &aSearchName, (const void *)pTable,
199 #endif
200 nEntries, sizeof( KEY_STRUCT ), KeyCompare );
202 else{
203 i = 0;
204 while( i < nEntries && !pKey ){
205 if( pTable[ i ].nName == nName )
206 pKey = &pTable[ i ];
207 i++;
211 if( pKey ){ // Schluesselwort gefunden
212 *pEle = *pKey;
213 return( TRUE );
215 return( FALSE );