Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
29 : #ifdef _MSC_VER
30 : #define _cdecl __cdecl
31 : #endif
32 :
33 : extern "C" {
34 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond );
35 : }
36 :
37 6150092 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond )
38 : {
39 6150092 : if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
40 1534826 : return( 1 );
41 4615266 : else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
42 4035810 : return( -1 );
43 : else
44 579456 : return( 0 );
45 : }
46 :
47 419 : RscNameTable::RscNameTable()
48 : {
49 419 : bSort = true;
50 419 : nEntries = 0;
51 419 : pTable = NULL;
52 419 : };
53 :
54 419 : RscNameTable::~RscNameTable()
55 : {
56 419 : if( pTable )
57 419 : rtl_freeMemory( pTable );
58 419 : };
59 :
60 :
61 838 : void RscNameTable::SetSort( bool bSorted )
62 : {
63 838 : bSort = bSorted;
64 838 : if( bSort && pTable)
65 : {
66 : // Schluesselwort Feld sortieren
67 : qsort( (void *)pTable, nEntries,
68 419 : sizeof( KEY_STRUCT ), KeyCompare );
69 : }
70 838 : };
71 :
72 753781 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, long nValue )
73 : {
74 753781 : if( pTable )
75 : pTable = (KEY_STRUCT *)
76 : rtl_reallocateMemory( (void *)pTable,
77 753362 : ((nEntries +1) * sizeof( KEY_STRUCT )) );
78 : else
79 : pTable = (KEY_STRUCT *)
80 419 : rtl_allocateMemory( ((nEntries +1)
81 419 : * sizeof( KEY_STRUCT )) );
82 :
83 753781 : pTable[ nEntries ].nName = nName;
84 753781 : pTable[ nEntries ].nTyp = nTyp;
85 753781 : pTable[ nEntries ].yylval = nValue;
86 753781 : nEntries++;
87 753781 : if( bSort )
88 0 : SetSort();
89 :
90 753781 : return nName;
91 : };
92 :
93 624729 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, long nValue )
94 : {
95 624729 : return Put( pHS->getID( pName ), nTyp, nValue );
96 : };
97 :
98 102236 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
99 : {
100 : Atom nId;
101 :
102 102236 : nId = pHS->getID( pName );
103 102236 : return Put( nId, nTyp, (long)nId );
104 : };
105 :
106 18436 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
107 : {
108 18436 : return Put( nName, nTyp, reinterpret_cast<long>(pClass) );
109 : };
110 :
111 159618 : bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle )
112 : {
113 159618 : KEY_STRUCT * pKey = NULL;
114 : KEY_STRUCT aSearchName;
115 : sal_uInt32 i;
116 :
117 159618 : if( bSort )
118 : {
119 : // Suche nach dem Schluesselwort
120 159618 : aSearchName.nName = nName;
121 : pKey = (KEY_STRUCT *)bsearch(
122 : #ifdef UNX
123 : (const char *) &aSearchName, (char *)pTable,
124 : #else
125 : (const void *) &aSearchName, (const void *)pTable,
126 : #endif
127 159618 : nEntries, sizeof( KEY_STRUCT ), KeyCompare );
128 : }
129 : else
130 : {
131 0 : i = 0;
132 0 : while( i < nEntries && !pKey )
133 : {
134 0 : if( pTable[ i ].nName == nName )
135 0 : pKey = &pTable[ i ];
136 0 : i++;
137 : }
138 : }
139 :
140 159618 : if( pKey )
141 : {
142 : // Schluesselwort gefunden
143 159618 : *pEle = *pKey;
144 159618 : return true;
145 : }
146 0 : return false;
147 : };
148 :
149 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|