LCOV - code coverage report
Current view: top level - rsc/source/res - rscmgr.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 112 148 75.7 %
Date: 2014-11-03 Functions: 12 15 80.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             : 
      21             : #include <stdlib.h>
      22             : #include <stdio.h>
      23             : #include <string.h>
      24             : #include <ctype.h>
      25             : 
      26             : #include <rscmgr.hxx>
      27             : #include <rscdb.hxx>
      28             : 
      29         419 : RscMgr::RscMgr( Atom nId, sal_uInt32 nTypeId, RscTop * pSuperCl )
      30         419 :     : RscClass( nId, nTypeId, pSuperCl )
      31             : {
      32         419 : }
      33             : 
      34        9099 : sal_uInt32 RscMgr::Size()
      35             : {
      36        9099 :     return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst ) );
      37             : }
      38             : 
      39       44162 : RSCINST RscMgr::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
      40             : {
      41       44162 :     RSCINST aInst;
      42             :     RscMgrInst * pClassData;
      43             : 
      44       44162 :     if( !pInst )
      45             :     {
      46        1138 :         aInst.pClass = this;
      47        1138 :         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
      48             :     }
      49             :     else
      50       43024 :         aInst = *pInst;
      51             : 
      52       44162 :     if( !bOwnClass && rDflt.IsInst() )
      53           0 :         bOwnClass = rDflt.pClass->InHierarchy( this );
      54             : 
      55       44162 :     RscClass::Create( &aInst, rDflt, bOwnClass );
      56             : 
      57       44162 :     pClassData = (RscMgrInst *)(aInst.pData + RscClass::Size() );
      58       44162 :     pClassData->Create();
      59             : 
      60       44162 :     if( bOwnClass )
      61             :     {
      62           0 :         RscMgrInst * pDfltData = (RscMgrInst *)(rDflt.pData + RscClass::Size());
      63           0 :         *pClassData = *pDfltData;
      64             :     }
      65             : 
      66       44162 :     return aInst;
      67             : }
      68             : 
      69       44162 : void RscMgr::Destroy( const RSCINST & rInst )
      70             : {
      71             :     RscMgrInst * pClassData;
      72             : 
      73       44162 :     RscClass::Destroy( rInst );
      74             : 
      75       44162 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
      76       44162 :     pClassData->Destroy();
      77       44162 : }
      78             : 
      79           0 : void RscMgr::SetToDefault( const RSCINST & rInst )
      80             : {
      81             :     RscMgrInst * pClassData;
      82             : 
      83           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
      84           0 :     pClassData->bDflt = true;
      85             : 
      86           0 :     RscClass::SetToDefault( rInst );
      87           0 : }
      88             : 
      89           0 : bool RscMgr::IsDefault( const RSCINST & rInst )
      90             : {
      91             :     RscMgrInst * pClassData;
      92             : 
      93           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
      94           0 :     if( !pClassData->bDflt )
      95           0 :         return false;
      96             : 
      97           0 :     return RscClass::IsDefault( rInst );
      98             : }
      99             : 
     100         644 : bool RscMgr::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     101             : {
     102         644 :     if( !RscClass::IsValueDefault( rInst, pDef ) )
     103           0 :         return false;
     104             : 
     105         644 :     if( pDef )
     106             :     {
     107         644 :         RscMgrInst * pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     108         644 :         RscMgrInst * pDfltData  = (RscMgrInst *)(pDef + RscClass::Size());
     109             : 
     110         644 :         if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() )
     111             :         {
     112         643 :             return true;
     113             :         }
     114             :     }
     115             : 
     116           1 :     return false;
     117             : }
     118             : 
     119             : 
     120       21839 : void RscMgr::WriteSrcHeader( const RSCINST & rInst, FILE * fOutput,
     121             :                              RscTypCont * pTC, sal_uInt32 nTab,
     122             :                              const RscId & rId, const char * pVarName )
     123             : {
     124             :     RscMgrInst * pClassData;
     125             :     sal_uInt32       i;
     126             : 
     127       21839 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     128             : 
     129             :     fprintf( fOutput, "%s %s",
     130       21839 :              pHS->getString( rInst.pClass->GetId() ).getStr(),
     131       43678 :              (rId.GetName()).getStr() );
     132             : 
     133       21839 :     if( pClassData->aRefId.IsId() )
     134           1 :         fprintf( fOutput, ",%s", pClassData->aRefId.GetName().getStr() );
     135             :     else
     136             :     {
     137       21838 :         fprintf( fOutput, "\n" );
     138       47101 :         for( i = 0; i < nTab; i++ )
     139       25263 :             fputc( '\t', fOutput );
     140             : 
     141       21838 :         fprintf( fOutput, "{\n" );
     142             : 
     143       21838 :         rInst.pClass->WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName );
     144             : 
     145       21838 :         RscClass::WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName);
     146             : 
     147       47101 :         for( i = 0; i < nTab; i++ )
     148       25263 :             fputc( '\t', fOutput );
     149             : 
     150       21838 :         fprintf( fOutput, "}" );
     151             :     }
     152       21839 : }
     153             : 
     154       21838 : void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32,
     155             :                        const char * )
     156             : {
     157       21838 : }
     158             : 
     159       21897 : ERRTYPE RscMgr::WriteRcHeader( const RSCINST & rInst, RscWriteRc & rMem,
     160             :                                RscTypCont * pTC, const RscId &rId,
     161             :                                sal_uInt32 nDeep, bool bExtra )
     162             : {
     163             :     RscMgrInst *    pClassData;
     164       21897 :     ERRTYPE         aError;
     165       21897 :     ObjNode *       pObjNode = NULL;
     166             : 
     167       21897 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     168             : 
     169       21897 :     if( pClassData->aRefId.IsId() )
     170             :     {
     171             :         //Erhoehen und abfragen um Endlosrekusion zu vermeiden
     172           1 :         nDeep++;
     173           1 :         if( nDeep > nRefDeep )
     174           0 :             aError = ERR_REFTODEEP;
     175             :         else
     176           1 :             pObjNode = rInst.pClass->GetRefClass()->
     177           2 :                                         GetObjNode( pClassData->aRefId );
     178             : 
     179           1 :         if( !pObjNode && pTC )
     180             :         {
     181           0 :             OStringBuffer aMsg(pHS->getString(rInst.pClass->GetId()));
     182           0 :             aMsg.append(' ').append(pClassData->aRefId.GetName());
     183           0 :             aError = WRN_MGR_REFNOTFOUND;
     184           0 :             pTC->pEH->Error(aError, rInst.pClass, rId, aMsg.getStr());
     185             :         }
     186             :     }
     187             : 
     188       21897 :     if( aError.IsOk() )
     189             :     {
     190       21897 :         if( pObjNode )
     191             :         {
     192           1 :             RSCINST     aRefI;
     193           1 :             RscTop *    pTmpRefClass = rInst.pClass->GetRefClass();
     194             : 
     195           1 :             aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
     196           1 :             if( pTmpRefClass == rInst.pClass )
     197             :             {
     198           3 :                 aError = aRefI.pClass->WriteRcHeader( aRefI, rMem, pTC,
     199           2 :                                                        rId, nDeep, bExtra );
     200             :             }
     201             :             else
     202             :             {
     203           0 :                 RSCINST aRefInst = rInst.pClass->Create( NULL, aRefI );
     204           0 :                 aError = aRefI.pClass->WriteRcHeader( aRefInst, rMem, pTC,
     205           0 :                                                        rId, nDeep, bExtra );
     206           0 :                 pTmpRefClass->Destroy( aRefInst );
     207             :             }
     208             :         }
     209             :         else
     210             :         {
     211             :             sal_uInt32          nOldSize;
     212             :             sal_uInt32          nLocalSize;
     213             : 
     214       21896 :             nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
     215             : 
     216       21896 :             aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep, bExtra );
     217       21896 :             if( aError.IsOk() )
     218       21896 :                 aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
     219       21896 :             nLocalSize = rMem.Size();
     220             : 
     221       21896 :             if( aError.IsOk() )
     222             :             {
     223             :                 // RscClass wird uebersprungen
     224       21896 :                 aError = RscTop::WriteRc( rInst, rMem, pTC, nDeep, bExtra );
     225             :             }
     226             : 
     227             :             /*
     228             :             // Definition der Struktur, aus denen die Resource aufgebaut ist
     229             :             struct RSHEADER_TYPE{
     230             :                 RESOURCE_TYPE   nRT;        // Resource Typ
     231             :                 sal_uInt32          nRT;        // Resource Typ
     232             :                 sal_uInt32          nGlobOff;   // Globaler Offset
     233             :                 sal_uInt32          nLocalOff;  // Lokaler Offset
     234             :             };
     235             :             */
     236       21896 :             sal_uInt32 nID = rId;
     237       21896 :             rMem.PutAt( nOldSize, nID );
     238       21896 :             rMem.PutAt( nOldSize +4, (sal_uInt32)rInst.pClass->GetTypId() );
     239       21896 :             rMem.PutAt( nOldSize +8, (sal_uInt32)(rMem.Size() - nOldSize) );
     240       21896 :             rMem.PutAt( nOldSize +12, (sal_uInt32)(nLocalSize - nOldSize) );
     241             :         }
     242             :     }
     243             : 
     244       21897 :     return aError;
     245             : }
     246             : 
     247       21896 : ERRTYPE RscMgr::WriteRc( const RSCINST &, RscWriteRc &,
     248             :                          RscTypCont *, sal_uInt32, bool )
     249             : 
     250             : {
     251       21896 :     return ERR_OK;
     252             : }
     253             : 
     254           0 : bool RscMgr::IsConsistent( const RSCINST & rInst )
     255             : {
     256             :     bool    bRet;
     257             :     RscMgrInst * pClassData;
     258             : 
     259           0 :     bRet = RscClass::IsConsistent( rInst );
     260             : 
     261           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     262           0 :     if( pClassData->aRefId.IsId() &&
     263           0 :         ((pClassData->aRefId.GetNumber() < 1) ||
     264           0 :          (pClassData->aRefId.GetNumber() > 0x7FFF) ||
     265           0 :          IsToDeep( rInst ).IsError()) )
     266             :     {
     267           0 :         bRet = false;
     268             :     }
     269             : 
     270           0 :     return bRet;
     271             : }
     272             : 
     273           6 : ERRTYPE RscMgr::GetRef( const RSCINST & rInst, RscId * pRscId )
     274             : {
     275             :     RscMgrInst * pClassData;
     276             : 
     277           6 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     278           6 :     *pRscId = pClassData->aRefId;
     279           6 :     return ERR_OK;
     280             : }
     281             : 
     282           3 : ERRTYPE RscMgr::IsToDeep( const RSCINST & rInst, sal_uInt32 nDeep )
     283             : {
     284             :     RscMgrInst *    pClassData;
     285           6 :     RscId           aOldId, aId;
     286           3 :     ERRTYPE         aError;
     287           3 :     RSCINST         aTmpI = rInst;
     288             :     ObjNode *       pObjNode;
     289             : 
     290           3 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     291             : 
     292          12 :     while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() )
     293             :     {
     294             :         // Referenz holen
     295           6 :         aTmpI.pClass->GetRef( aTmpI, &aId );
     296             :         // Referenziertes Objekt holen
     297           6 :         pObjNode = aTmpI.pClass->GetObjNode( aId );
     298             :         // Referenzierte Objekt gefunden ?
     299           6 :         if( pObjNode )
     300             :         {
     301           3 :             aTmpI.pData = pObjNode->GetRscObj();
     302           3 :             nDeep++;
     303             :         }
     304             :         else //aTmpI.IsInst() wird false, Schleife beenden
     305           3 :             aTmpI.pData = NULL;
     306             :     }
     307             : 
     308           3 :     if( nDeep >= nRefDeep )
     309             :     {
     310           0 :         pClassData->aRefId = aOldId;
     311           0 :         aError             = ERR_REFTODEEP;
     312             :     }
     313             : 
     314           6 :     return aError;
     315             : }
     316             : 
     317           3 : ERRTYPE RscMgr::SetRef( const RSCINST & rInst, const RscId & rRefId )
     318             : {
     319             :     RscMgrInst *    pClassData;
     320           6 :     RscId           aOldId, aId;
     321           3 :     ERRTYPE         aError;
     322             : 
     323           6 :     if( rRefId.IsId() &&
     324           6 :         ((rRefId.GetNumber() < 1) ||
     325           3 :          (rRefId.GetNumber() > 0x7FFF)) )
     326             :     {
     327           0 :         aError = ERR_IDRANGE;
     328             :     }
     329             :     else
     330             :     {
     331           3 :         pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     332           3 :         aOldId = pClassData->aRefId;// Alten Wert merken
     333           3 :         pClassData->aRefId = rRefId;// vorher eintragen,
     334             :                                     // sonst Fehler bei rekursion
     335             : 
     336             : 
     337           3 :         aError = IsToDeep( rInst );
     338           3 :         if( aError.IsOk() )
     339           3 :             pClassData->bDflt  = false;
     340             :         else
     341           0 :             pClassData->aRefId = aOldId;
     342             :     }
     343             : 
     344           6 :     return aError;
     345             : }
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10