LCOV - code coverage report
Current view: top level - libreoffice/rsc/source/parser - rsckey.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 52 86.5 %
Date: 2012-12-27 Functions: 9 9 100.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             : /****************** 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             : #ifdef _MSC_VER
      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     8605098 : int SAL_CALL KeyCompare( const void * pFirst, const void * pSecond )
      41             : {
      42     8605098 :     if( ((KEY_STRUCT *)pFirst)->nName > ((KEY_STRUCT *)pSecond)->nName )
      43     1812579 :         return( 1 );
      44     6792519 :     else if( ((KEY_STRUCT *)pFirst)->nName < ((KEY_STRUCT *)pSecond)->nName )
      45     6053550 :         return( -1 );
      46             :     else
      47      738969 :         return( 0 );
      48             : }
      49             : 
      50             : /*************************************************************************
      51             : |*
      52             : |*    RscNameTable::RscNameTable()
      53             : |*
      54             : *************************************************************************/
      55         691 : RscNameTable::RscNameTable() {
      56         691 :     bSort    = sal_True;
      57         691 :     nEntries = 0;
      58         691 :     pTable   = NULL;
      59         691 : };
      60             : 
      61             : /*************************************************************************
      62             : |*
      63             : |*    RscNameTable::~RscNameTable()
      64             : |*
      65             : *************************************************************************/
      66         691 : RscNameTable::~RscNameTable() {
      67         691 :     if( pTable )
      68         691 :         rtl_freeMemory( pTable );
      69         691 : };
      70             : 
      71             : 
      72             : /*************************************************************************
      73             : |*
      74             : |*    RscNameTable::SetSort()
      75             : |*
      76             : *************************************************************************/
      77        1382 : void RscNameTable::SetSort( sal_Bool bSorted ){
      78        1382 :     bSort = bSorted;
      79        1382 :     if( bSort && pTable){
      80             :         // Schluesselwort Feld sortieren
      81             :         qsort( (void *)pTable, nEntries,
      82         691 :                sizeof( KEY_STRUCT ), KeyCompare );
      83             :     };
      84        1382 : };
      85             : 
      86             : /*************************************************************************
      87             : |*
      88             : |*    RscNameTable::Put()
      89             : |*
      90             : *************************************************************************/
      91     1014388 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, long nValue ){
      92     1014388 :     if( pTable )
      93             :         pTable = (KEY_STRUCT *)
      94             :                  rtl_reallocateMemory( (void *)pTable,
      95     1013697 :                  ((nEntries +1) * sizeof( KEY_STRUCT )) );
      96             :     else
      97             :         pTable = (KEY_STRUCT *)
      98             :                  rtl_allocateMemory( ((nEntries +1)
      99         691 :                                  * sizeof( KEY_STRUCT )) );
     100     1014388 :     pTable[ nEntries ].nName  = nName;
     101     1014388 :     pTable[ nEntries ].nTyp   = nTyp;
     102     1014388 :     pTable[ nEntries ].yylval = nValue;
     103     1014388 :     nEntries++;
     104     1014388 :     if( bSort )
     105           0 :         SetSort();
     106     1014388 :     return( nName );
     107             : };
     108             : 
     109      710348 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp, long nValue )
     110             : {
     111      710348 :     return( Put( pHS->getID( pName ), nTyp, nValue ) );
     112             : };
     113             : 
     114      235631 : Atom RscNameTable::Put( const char * pName, sal_uInt32 nTyp )
     115             : {
     116             :     Atom  nId;
     117             : 
     118      235631 :     nId = pHS->getID( pName );
     119      235631 :     return( Put( nId, nTyp, (long)nId ) );
     120             : };
     121             : 
     122       54589 : Atom RscNameTable::Put( Atom nName, sal_uInt32 nTyp, RscTop * pClass )
     123             : {
     124       54589 :     return( Put( nName, nTyp, (long)pClass ) );
     125             : };
     126             : 
     127             : /*************************************************************************
     128             : |*
     129             : |*    RscNameTable::Get()
     130             : |*
     131             : *************************************************************************/
     132      327133 : sal_Bool RscNameTable::Get( Atom nName, KEY_STRUCT * pEle ){
     133      327133 :     KEY_STRUCT * pKey = NULL;
     134             :     KEY_STRUCT  aSearchName;
     135             :     sal_uInt32  i;
     136             : 
     137      327133 :     if( bSort ){
     138             :         // Suche nach dem Schluesselwort
     139      327133 :         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      327133 :                    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      327133 :     if( pKey ){ // Schluesselwort gefunden
     158      327133 :         *pEle = *pKey;
     159      327133 :         return( sal_True );
     160             :     };
     161           0 :     return( sal_False );
     162             : };
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10