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( ((KEY_STRUCT
*)pFirst
)->nName
> ((KEY_STRUCT
*)pSecond
)->nName
)
41 else if( ((KEY_STRUCT
*)pFirst
)->nName
< ((KEY_STRUCT
*)pSecond
)->nName
)
47 RscNameTable::RscNameTable() {
53 RscNameTable::~RscNameTable() {
55 rtl_freeMemory( pTable
);
59 void RscNameTable::SetSort( sal_Bool bSorted
){
62 // Schluesselwort Feld sortieren
63 qsort( (void *)pTable
, nEntries
,
64 sizeof( KEY_STRUCT
), KeyCompare
);
68 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, long nValue
){
70 pTable
= (KEY_STRUCT
*)
71 rtl_reallocateMemory( (void *)pTable
,
72 ((nEntries
+1) * sizeof( KEY_STRUCT
)) );
74 pTable
= (KEY_STRUCT
*)
75 rtl_allocateMemory( ((nEntries
+1)
76 * sizeof( KEY_STRUCT
)) );
77 pTable
[ nEntries
].nName
= nName
;
78 pTable
[ nEntries
].nTyp
= nTyp
;
79 pTable
[ nEntries
].yylval
= nValue
;
86 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
, long nValue
)
88 return( Put( pHS
->getID( pName
), nTyp
, nValue
) );
91 Atom
RscNameTable::Put( const char * pName
, sal_uInt32 nTyp
)
95 nId
= pHS
->getID( pName
);
96 return( Put( nId
, nTyp
, (long)nId
) );
99 Atom
RscNameTable::Put( Atom nName
, sal_uInt32 nTyp
, RscTop
* pClass
)
101 return( Put( nName
, nTyp
, (long)pClass
) );
104 sal_Bool
RscNameTable::Get( Atom nName
, KEY_STRUCT
* pEle
){
105 KEY_STRUCT
* pKey
= NULL
;
106 KEY_STRUCT aSearchName
;
110 // Suche nach dem Schluesselwort
111 aSearchName
.nName
= nName
;
112 pKey
= (KEY_STRUCT
*)bsearch(
114 (const char *) &aSearchName
, (char *)pTable
,
116 (const void *) &aSearchName
, (const void *)pTable
,
118 nEntries
, sizeof( KEY_STRUCT
), KeyCompare
);
122 while( i
< nEntries
&& !pKey
){
123 if( pTable
[ i
].nName
== nName
)
129 if( pKey
){ // Schluesselwort gefunden
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */