bump product version to 4.1.6.2
[LibreOffice.git] / rsc / source / parser / rsckey.cxx
blobc9ed1c44dc328fb325bc53abb029d50a85938e95
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( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
40 return( 1 );
41 else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
42 return( -1 );
43 else
44 return( 0 );
47 RscNameTable::RscNameTable() {
48 bSort = sal_True;
49 nEntries = 0;
50 pTable = NULL;
53 RscNameTable::~RscNameTable() {
54 if( pTable )
55 rtl_freeMemory( pTable );
59 void RscNameTable::SetSort( sal_Bool bSorted ){
60 bSort = bSorted;
61 if( bSort && pTable){
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 ){
69 if( pTable )
70 pTable = (KEY_STRUCT *)
71 rtl_reallocateMemory( (void *)pTable,
72 ((nEntries +1) * sizeof( KEY_STRUCT )) );
73 else
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;
80 nEntries++;
81 if( bSort )
82 SetSort();
83 return( nName );
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 )
93 Atom nId;
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;
107 sal_uInt32 i;
109 if( bSort ){
110 // Suche nach dem Schluesselwort
111 aSearchName.nName = nName;
112 pKey = (KEY_STRUCT *)bsearch(
113 #ifdef UNX
114 (const char *) &aSearchName, (char *)pTable,
115 #else
116 (const void *) &aSearchName, (const void *)pTable,
117 #endif
118 nEntries, sizeof( KEY_STRUCT ), KeyCompare );
120 else{
121 i = 0;
122 while( i < nEntries && !pKey ){
123 if( pTable[ i ].nName == nName )
124 pKey = &pTable[ i ];
125 i++;
129 if( pKey ){ // Schluesselwort gefunden
130 *pEle = *pKey;
131 return( sal_True );
133 return( sal_False );
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */