Branch data 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 : : /****************** I N C L U D E S **************************************/
21 : : #include <stdlib.h>
22 : : #include <stdio.h>
23 : : #include <ctype.h>
24 : : #include <string.h>
25 : : #include <rscall.h>
26 : : #include <rsctools.hxx>
27 : : #include <rschash.hxx>
28 : : #include <rsckey.hxx>
29 : :
30 : : #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
31 : : #define _cdecl __cdecl
32 : : #endif
33 : :
34 : : /****************** C o d e **********************************************/
35 : : /****************** keyword sort function ********************************/
36 : : extern "C" {
37 : : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond );
38 : : }
39 : :
40 : 17701864 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond )
41 : : {
42 [ + + ]: 17701864 : if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
43 : 4023508 : return( 1 );
44 [ + + ]: 13678356 : else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
45 : 12145894 : return( -1 );
46 : : else
47 : 17701864 : return( 0 );
48 : : }
49 : :
50 : : /*************************************************************************
51 : : |*
52 : : |* RscNameTable::RscNameTable()
53 : : |*
54 : : *************************************************************************/
55 : 1440 : RscNameTable::RscNameTable() {
56 : 1440 : bSort = sal_True;
57 : 1440 : nEntries = 0;
58 : 1440 : pTable = NULL;
59 : 1440 : };
60 : :
61 : : /*************************************************************************
62 : : |*
63 : : |* RscNameTable::~RscNameTable()
64 : : |*
65 : : *************************************************************************/
66 : 1440 : RscNameTable::~RscNameTable() {
67 [ + - ]: 1440 : if( pTable )
68 : 1440 : rtl_freeMemory( pTable );
69 : 1440 : };
70 : :
71 : :
72 : : /*************************************************************************
73 : : |*
74 : : |* RscNameTable::SetSort()
75 : : |*
76 : : *************************************************************************/
77 : 2880 : void RscNameTable::SetSort( sal_Bool bSorted ){
78 : 2880 : bSort = bSorted;
79 [ + + ][ + - ]: 2880 : if( bSort && pTable){
80 : : // Schluesselwort Feld sortieren
81 : : qsort( (void *)pTable, nEntries,
82 : 1440 : sizeof( KEY_STRUCT ), KeyCompare );
83 : : };
84 : 2880 : };
85 : :
86 : : /*************************************************************************
87 : : |*
88 : : |* RscNameTable::Put()
89 : : |*
90 : : *************************************************************************/
91 : 2027520 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, long nValue ){
92 [ + + ]: 2027520 : if( pTable )
93 : : pTable = (KEY_STRUCT *)
94 : : rtl_reallocateMemory( (void *)pTable,
95 : 2026080 : ((nEntries +1) * sizeof( KEY_STRUCT )) );
96 : : else
97 : : pTable = (KEY_STRUCT *)
98 : : rtl_allocateMemory( ((nEntries +1)
99 : 1440 : * sizeof( KEY_STRUCT )) );
100 : 2027520 : pTable[ nEntries ].nName = nName;
101 : 2027520 : pTable[ nEntries ].nTyp = nTyp;
102 : 2027520 : pTable[ nEntries ].yylval = nValue;
103 : 2027520 : nEntries++;
104 [ - + ]: 2027520 : if( bSort )
105 : 0 : SetSort();
106 : 2027520 : return( nName );
107 : : };
108 : :
109 : 1393920 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, long nValue )
110 : : {
111 [ + - ][ + - ]: 1393920 : return( Put( pHS->getID( pName ), nTyp, nValue ) );
112 : : };
113 : :
114 : 491040 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
115 : : {
116 : : Atom nId;
117 : :
118 [ + - ]: 491040 : nId = pHS->getID( pName );
119 : 491040 : return( Put( nId, nTyp, (long)nId ) );
120 : : };
121 : :
122 : 113760 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
123 : : {
124 : 113760 : return( Put( nName, nTyp, (long)pClass ) );
125 : : };
126 : :
127 : : /*************************************************************************
128 : : |*
129 : : |* RscNameTable::Get()
130 : : |*
131 : : *************************************************************************/
132 : 701582 : sal_Bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle ){
133 : 701582 : KEY_STRUCT * pKey = NULL;
134 : : KEY_STRUCT aSearchName;
135 : : sal_uInt32 i;
136 : :
137 [ + - ]: 701582 : if( bSort ){
138 : : // Suche nach dem Schluesselwort
139 : 701582 : aSearchName.nName = nName;
140 : : pKey = (KEY_STRUCT *)bsearch(
141 : : #ifdef UNX
142 : : (const char *) &aSearchName, (char *)pTable,
143 : : #else
144 : : (const void *) &aSearchName, (const void *)pTable,
145 : : #endif
146 [ + - ]: 701582 : nEntries, sizeof( KEY_STRUCT ), KeyCompare );
147 : : }
148 : : else{
149 : 0 : i = 0;
150 [ # # ][ # # ]: 0 : while( i < nEntries && !pKey ){
[ # # ]
151 [ # # ]: 0 : if( pTable[ i ].nName == nName )
152 : 0 : pKey = &pTable[ i ];
153 : 0 : i++;
154 : : };
155 : : };
156 : :
157 [ + - ]: 701582 : if( pKey ){ // Schluesselwort gefunden
158 : 701582 : *pEle = *pKey;
159 : 701582 : return( sal_True );
160 : : };
161 : 701582 : return( sal_False );
162 : : };
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|