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 6019393 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond )
38 : {
39 6019393 : if( static_cast<KEY_STRUCT const *>(pFirst)->nName > static_cast<KEY_STRUCT const *>(pSecond)->nName )
40 1414067 : return 1;
41 4605326 : else if( static_cast<KEY_STRUCT const *>(pFirst)->nName < static_cast<KEY_STRUCT const *>(pSecond)->nName )
42 4051724 : return -1;
43 : else
44 553602 : return 0;
45 : }
46 :
47 417 : RscNameTable::RscNameTable()
48 : {
49 417 : bSort = true;
50 417 : nEntries = 0;
51 417 : pTable = NULL;
52 417 : };
53 :
54 417 : RscNameTable::~RscNameTable()
55 : {
56 417 : if( pTable )
57 417 : rtl_freeMemory( pTable );
58 417 : };
59 :
60 :
61 834 : void RscNameTable::SetSort( bool bSorted )
62 : {
63 834 : bSort = bSorted;
64 834 : if( bSort && pTable)
65 : {
66 : // Schluesselwort Feld sortieren
67 : qsort( static_cast<void *>(pTable), nEntries,
68 417 : sizeof( KEY_STRUCT ), KeyCompare );
69 : }
70 834 : };
71 :
72 738090 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, sal_IntPtr nValue )
73 : {
74 738090 : if( pTable )
75 : pTable = static_cast<KEY_STRUCT *>(
76 : rtl_reallocateMemory( static_cast<void *>(pTable),
77 737673 : ((nEntries +1) * sizeof( KEY_STRUCT )) ));
78 : else
79 : pTable = static_cast<KEY_STRUCT *>(
80 417 : rtl_allocateMemory( ((nEntries +1)
81 417 : * sizeof( KEY_STRUCT )) ));
82 :
83 738090 : pTable[ nEntries ].nName = nName;
84 738090 : pTable[ nEntries ].nTyp = nTyp;
85 738090 : pTable[ nEntries ].yylval = nValue;
86 738090 : nEntries++;
87 738090 : if( bSort )
88 0 : SetSort();
89 :
90 738090 : return nName;
91 : };
92 :
93 622164 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, sal_IntPtr nValue )
94 : {
95 622164 : return Put( pHS->getID( pName ), nTyp, nValue );
96 : };
97 :
98 91740 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
99 : {
100 : Atom nId;
101 :
102 91740 : nId = pHS->getID( pName );
103 91740 : return Put( nId, nTyp, (sal_IntPtr)nId );
104 : };
105 :
106 15846 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
107 : {
108 15846 : return Put( nName, nTyp, reinterpret_cast<sal_IntPtr>(pClass) );
109 : };
110 :
111 150363 : bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle )
112 : {
113 150363 : KEY_STRUCT * pKey = NULL;
114 : KEY_STRUCT aSearchName;
115 : sal_uInt32 i;
116 :
117 150363 : if( bSort )
118 : {
119 : // Suche nach dem Schluesselwort
120 150363 : aSearchName.nName = nName;
121 : pKey = static_cast<KEY_STRUCT *>(bsearch(
122 : &aSearchName, pTable,
123 150363 : nEntries, sizeof( KEY_STRUCT ), KeyCompare ));
124 : }
125 : else
126 : {
127 0 : i = 0;
128 0 : while( i < nEntries && !pKey )
129 : {
130 0 : if( pTable[ i ].nName == nName )
131 0 : pKey = &pTable[ i ];
132 0 : i++;
133 : }
134 : }
135 :
136 150363 : if( pKey )
137 : {
138 : // Schluesselwort gefunden
139 150363 : *pEle = *pKey;
140 150363 : return true;
141 : }
142 0 : return false;
143 : };
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|