fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / rsc / source / parser / rsckey.cxx
blobcddfc01012324ec3459df689df4308869a67540f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <string.h>
24 #include <rscall.h>
25 #include <rsctools.hxx>
26 #include <rschash.hxx>
27 #include <rsckey.hxx>
29 #ifdef _MSC_VER
30 #define _cdecl __cdecl
31 #endif
33 extern "C" {
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 )
40 return 1;
41 else if( static_cast<KEY_STRUCT const *>(pFirst)->nName < static_cast<KEY_STRUCT const *>(pSecond)->nName )
42 return -1;
43 else
44 return 0;
47 RscNameTable::RscNameTable()
49 bSort = true;
50 nEntries = 0;
51 pTable = NULL;
54 RscNameTable::~RscNameTable()
56 if( pTable )
57 rtl_freeMemory( pTable );
61 void RscNameTable::SetSort( bool bSorted )
63 bSort = bSorted;
64 if( bSort && pTable)
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 )
74 if( pTable )
75 pTable = static_cast<KEY_STRUCT *>(
76 rtl_reallocateMemory( (void *)pTable,
77 ((nEntries +1) * sizeof( KEY_STRUCT )) ));
78 else
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;
86 nEntries++;
87 if( bSort )
88 SetSort();
90 return nName;
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 )
100 Atom nId;
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;
115 sal_uInt32 i;
117 if( bSort )
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 ));
125 else
127 i = 0;
128 while( i < nEntries && !pKey )
130 if( pTable[ i ].nName == nName )
131 pKey = &pTable[ i ];
132 i++;
136 if( pKey )
138 // Schluesselwort gefunden
139 *pEle = *pKey;
140 return true;
142 return false;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */