1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <rsctools.hxx>
26 #include <rschash.hxx>
30 #define _cdecl __cdecl
34 int SAL_CALL
KeyCompare( const void * pFirst
, const void * pSecond
);
37 int SAL_CALL
KeyCompare( const void * pFirst
, const void * pSecond
)
39 if( static_cast<KEY_STRUCT
const *>(pFirst
)->nName
> static_cast<KEY_STRUCT
const *>(pSecond
)->nName
)
41 else if( static_cast<KEY_STRUCT
const *>(pFirst
)->nName
< static_cast<KEY_STRUCT
const *>(pSecond
)->nName
)
47 RscNameTable::RscNameTable()
54 RscNameTable::~RscNameTable()
57 rtl_freeMemory( pTable
);
61 void RscNameTable::SetSort( bool bSorted
)
66 // Schluesselwort Feld sortieren
67 qsort( (void *)pTable
, nEntries
,
68 sizeof( KEY_STRUCT
), KeyCompare
);
72 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, sal_IntPtr nValue
)
75 pTable
= static_cast<KEY_STRUCT
*>(
76 rtl_reallocateMemory( (void *)pTable
,
77 ((nEntries
+1) * sizeof( KEY_STRUCT
)) ));
79 pTable
= static_cast<KEY_STRUCT
*>(
80 rtl_allocateMemory( ((nEntries
+1)
81 * sizeof( KEY_STRUCT
)) ));
83 pTable
[ nEntries
].nName
= nName
;
84 pTable
[ nEntries
].nTyp
= nTyp
;
85 pTable
[ nEntries
].yylval
= nValue
;
93 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
, sal_IntPtr nValue
)
95 return Put( pHS
->getID( pName
), nTyp
, nValue
);
98 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
)
102 nId
= pHS
->getID( pName
);
103 return Put( nId
, nTyp
, (sal_IntPtr
)nId
);
106 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, RscTop
* pClass
)
108 return Put( nName
, nTyp
, reinterpret_cast<sal_IntPtr
>(pClass
) );
111 bool RscNameTable::Get( Atom nName
, KEY_STRUCT
* pEle
)
113 KEY_STRUCT
* pKey
= NULL
;
114 KEY_STRUCT aSearchName
;
119 // Suche nach dem Schluesselwort
120 aSearchName
.nName
= nName
;
121 pKey
= static_cast<KEY_STRUCT
*>(bsearch(
122 &aSearchName
, pTable
,
123 nEntries
, sizeof( KEY_STRUCT
), KeyCompare
));
128 while( i
< nEntries
&& !pKey
)
130 if( pTable
[ i
].nName
== nName
)
138 // Schluesselwort gefunden
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */