LCOV - code coverage report
Current view: top level - rsc/source/parser - rsckey.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 52 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          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           0 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond )
      38             : {
      39           0 :     if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
      40           0 :         return( 1 );
      41           0 :     else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
      42           0 :         return( -1 );
      43             :     else
      44           0 :         return( 0 );
      45             : }
      46             : 
      47           0 : RscNameTable::RscNameTable()
      48             : {
      49           0 :     bSort    = true;
      50           0 :     nEntries = 0;
      51           0 :     pTable   = NULL;
      52           0 : };
      53             : 
      54           0 : RscNameTable::~RscNameTable()
      55             : {
      56           0 :     if( pTable )
      57           0 :         rtl_freeMemory( pTable );
      58           0 : };
      59             : 
      60             : 
      61           0 : void RscNameTable::SetSort( bool bSorted )
      62             : {
      63           0 :     bSort = bSorted;
      64           0 :     if( bSort && pTable)
      65             :     {
      66             :         // Schluesselwort Feld sortieren
      67             :         qsort( (void *)pTable, nEntries,
      68           0 :                sizeof( KEY_STRUCT ), KeyCompare );
      69             :     };
      70           0 : };
      71             : 
      72           0 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, long nValue )
      73             : {
      74           0 :     if( pTable )
      75             :         pTable = (KEY_STRUCT *)
      76             :                  rtl_reallocateMemory( (void *)pTable,
      77           0 :                  ((nEntries +1) * sizeof( KEY_STRUCT )) );
      78             :     else
      79             :         pTable = (KEY_STRUCT *)
      80             :                  rtl_allocateMemory( ((nEntries +1)
      81           0 :                                  * sizeof( KEY_STRUCT )) );
      82             : 
      83           0 :     pTable[ nEntries ].nName  = nName;
      84           0 :     pTable[ nEntries ].nTyp   = nTyp;
      85           0 :     pTable[ nEntries ].yylval = nValue;
      86           0 :     nEntries++;
      87           0 :     if( bSort )
      88           0 :         SetSort();
      89             : 
      90           0 :     return nName;
      91             : };
      92             : 
      93           0 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, long nValue )
      94             : {
      95           0 :     return Put( pHS->getID( pName ), nTyp, nValue );
      96             : };
      97             : 
      98           0 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
      99             : {
     100             :     Atom  nId;
     101             : 
     102           0 :     nId = pHS->getID( pName );
     103           0 :     return Put( nId, nTyp, (long)nId );
     104             : };
     105             : 
     106           0 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
     107             : {
     108           0 :     return Put( nName, nTyp, (long)pClass );
     109             : };
     110             : 
     111           0 : bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle )
     112             : {
     113           0 :     KEY_STRUCT * pKey = NULL;
     114             :     KEY_STRUCT  aSearchName;
     115             :     sal_uInt32  i;
     116             : 
     117           0 :     if( bSort )
     118             :     {
     119             :         // Suche nach dem Schluesselwort
     120           0 :         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           0 :                 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           0 :     if( pKey )
     141             :     {
     142             :         // Schluesselwort gefunden
     143           0 :         *pEle = *pKey;
     144           0 :         return true;
     145             :     };
     146           0 :     return false;
     147             : };
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10