LCOV - code coverage report
Current view: top level - rsc/source/res - rscmgr.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 148 0.0 %
Date: 2014-04-14 Functions: 0 15 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             : 
      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           0 : RscMgr::RscMgr( Atom nId, sal_uInt32 nTypeId, RscTop * pSuperCl )
      30           0 :     : RscClass( nId, nTypeId, pSuperCl )
      31             : {
      32           0 : }
      33             : 
      34           0 : sal_uInt32 RscMgr::Size()
      35             : {
      36           0 :     return RscClass::Size() + ALIGNED_SIZE( sizeof( RscMgrInst ) );
      37             : }
      38             : 
      39           0 : RSCINST RscMgr::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
      40             : {
      41           0 :     RSCINST aInst;
      42             :     RscMgrInst * pClassData;
      43             : 
      44           0 :     if( !pInst )
      45             :     {
      46           0 :         aInst.pClass = this;
      47           0 :         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
      48             :     }
      49             :     else
      50           0 :         aInst = *pInst;
      51             : 
      52           0 :     if( !bOwnClass && rDflt.IsInst() )
      53           0 :         bOwnClass = rDflt.pClass->InHierarchy( this );
      54             : 
      55           0 :     RscClass::Create( &aInst, rDflt, bOwnClass );
      56             : 
      57           0 :     pClassData = (RscMgrInst *)(aInst.pData + RscClass::Size() );
      58           0 :     pClassData->Create();
      59             : 
      60           0 :     if( bOwnClass )
      61             :     {
      62           0 :         RscMgrInst * pDfltData = (RscMgrInst *)(rDflt.pData + RscClass::Size());
      63           0 :         *pClassData = *pDfltData;
      64             :     };
      65             : 
      66           0 :     return aInst;
      67             : }
      68             : 
      69           0 : void RscMgr::Destroy( const RSCINST & rInst )
      70             : {
      71             :     RscMgrInst * pClassData;
      72             : 
      73           0 :     RscClass::Destroy( rInst );
      74             : 
      75           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
      76           0 :     pClassData->Destroy();
      77           0 : }
      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           0 : bool RscMgr::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     101             : {
     102           0 :     if( !RscClass::IsValueDefault( rInst, pDef ) )
     103           0 :         return false;
     104             : 
     105           0 :     if( pDef )
     106             :     {
     107           0 :         RscMgrInst * pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     108           0 :         RscMgrInst * pDfltData  = (RscMgrInst *)(pDef + RscClass::Size());
     109             : 
     110           0 :         if( !pClassData->aRefId.IsId() && !pDfltData->aRefId.IsId() )
     111             :         {
     112           0 :             return true;
     113             :         }
     114             :     }
     115             : 
     116           0 :     return false;
     117             : }
     118             : 
     119             : 
     120           0 : 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           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     128             : 
     129             :     fprintf( fOutput, "%s %s",
     130           0 :              pHS->getString( rInst.pClass->GetId() ).getStr(),
     131           0 :              (rId.GetName()).getStr() );
     132             : 
     133           0 :     if( pClassData->aRefId.IsId() )
     134           0 :         fprintf( fOutput, ",%s", pClassData->aRefId.GetName().getStr() );
     135             :     else
     136             :     {
     137           0 :         fprintf( fOutput, "\n" );
     138           0 :         for( i = 0; i < nTab; i++ )
     139           0 :             fputc( '\t', fOutput );
     140             : 
     141           0 :         fprintf( fOutput, "{\n" );
     142             : 
     143           0 :         rInst.pClass->WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName );
     144             : 
     145           0 :         RscClass::WriteSrc( rInst, fOutput, pTC, nTab +1, pVarName);
     146             : 
     147           0 :         for( i = 0; i < nTab; i++ )
     148           0 :             fputc( '\t', fOutput );
     149             : 
     150           0 :         fprintf( fOutput, "}" );
     151             :     }
     152           0 : }
     153             : 
     154           0 : void RscMgr::WriteSrc( const RSCINST &, FILE *, RscTypCont *, sal_uInt32,
     155             :                        const char * )
     156             : {
     157           0 : }
     158             : 
     159           0 : 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           0 :     ERRTYPE         aError;
     165           0 :     ObjNode *       pObjNode = NULL;
     166             : 
     167           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     168             : 
     169           0 :     if( pClassData->aRefId.IsId() )
     170             :     {
     171             :         //Erhoehen und abfragen um Endlosrekusion zu vermeiden
     172           0 :         nDeep++;
     173           0 :         if( nDeep > nRefDeep )
     174           0 :             aError = ERR_REFTODEEP;
     175             :         else
     176           0 :             pObjNode = rInst.pClass->GetRefClass()->
     177           0 :                                         GetObjNode( pClassData->aRefId );
     178             : 
     179           0 :         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           0 :     if( aError.IsOk() )
     189             :     {
     190           0 :         if( pObjNode )
     191             :         {
     192           0 :             RSCINST     aRefI;
     193           0 :             RscTop *    pTmpRefClass = rInst.pClass->GetRefClass();
     194             : 
     195           0 :             aRefI = RSCINST( rInst.pClass, pObjNode->GetRscObj() );
     196           0 :             if( pTmpRefClass == rInst.pClass )
     197             :             {
     198           0 :                 aError = aRefI.pClass->WriteRcHeader( aRefI, rMem, pTC,
     199           0 :                                                        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           0 :             nOldSize = rMem.IncSize( 16 /*sizeof( RSHEADER_TYPE )*/ );
     215             : 
     216           0 :             aError = rInst.pClass->WriteRc( rInst, rMem, pTC, nDeep, bExtra );
     217           0 :             if( aError.IsOk() )
     218           0 :                 aError = WriteInstRc( rInst, rMem, pTC, nDeep, bExtra );
     219           0 :             nLocalSize = rMem.Size();
     220             : 
     221           0 :             if( aError.IsOk() )
     222             :             {
     223             :                 // RscClass wird uebersprungen
     224           0 :                 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           0 :             sal_uInt32 nID = rId;
     237           0 :             rMem.PutAt( nOldSize, nID );
     238           0 :             rMem.PutAt( nOldSize +4, (sal_uInt32)rInst.pClass->GetTypId() );
     239           0 :             rMem.PutAt( nOldSize +8, (sal_uInt32)(rMem.Size() - nOldSize) );
     240           0 :             rMem.PutAt( nOldSize +12, (sal_uInt32)(nLocalSize - nOldSize) );
     241             :         };
     242             :     };
     243             : 
     244           0 :     return aError;
     245             : }
     246             : 
     247           0 : ERRTYPE RscMgr::WriteRc( const RSCINST &, RscWriteRc &,
     248             :                          RscTypCont *, sal_uInt32, bool )
     249             : 
     250             : {
     251           0 :     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           0 : ERRTYPE RscMgr::GetRef( const RSCINST & rInst, RscId * pRscId )
     274             : {
     275             :     RscMgrInst * pClassData;
     276             : 
     277           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     278           0 :     *pRscId = pClassData->aRefId;
     279           0 :     return ERR_OK;
     280             : }
     281             : 
     282           0 : ERRTYPE RscMgr::IsToDeep( const RSCINST & rInst, sal_uInt32 nDeep )
     283             : {
     284             :     RscMgrInst *    pClassData;
     285           0 :     RscId           aOldId, aId;
     286           0 :     ERRTYPE         aError;
     287           0 :     RSCINST         aTmpI = rInst;
     288             :     ObjNode *       pObjNode;
     289             : 
     290           0 :     pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     291             : 
     292           0 :     while( aTmpI.IsInst() && (nDeep < nRefDeep) && aError.IsOk() )
     293             :     {
     294             :         // Referenz holen
     295           0 :         aTmpI.pClass->GetRef( aTmpI, &aId );
     296             :         // Referenziertes Objekt holen
     297           0 :         pObjNode = aTmpI.pClass->GetObjNode( aId );
     298             :         // Referenzierte Objekt gefunden ?
     299           0 :         if( pObjNode )
     300             :         {
     301           0 :             aTmpI.pData = pObjNode->GetRscObj();
     302           0 :             nDeep++;
     303             :         }
     304             :         else //aTmpI.IsInst() wird false, Schleife beenden
     305           0 :             aTmpI.pData = NULL;
     306             :     }
     307             : 
     308           0 :     if( nDeep >= nRefDeep )
     309             :     {
     310           0 :         pClassData->aRefId = aOldId;
     311           0 :         aError             = ERR_REFTODEEP;
     312             :     }
     313             : 
     314           0 :     return aError;
     315             : }
     316             : 
     317           0 : ERRTYPE RscMgr::SetRef( const RSCINST & rInst, const RscId & rRefId )
     318             : {
     319             :     RscMgrInst *    pClassData;
     320           0 :     RscId           aOldId, aId;
     321           0 :     ERRTYPE         aError;
     322             : 
     323           0 :     if( rRefId.IsId() &&
     324           0 :         ((rRefId.GetNumber() < 1) ||
     325           0 :          (rRefId.GetNumber() > 0x7FFF)) )
     326             :     {
     327           0 :         aError = ERR_IDRANGE;
     328             :     }
     329             :     else
     330             :     {
     331           0 :         pClassData = (RscMgrInst *)(rInst.pData + RscClass::Size());
     332           0 :         aOldId = pClassData->aRefId;// Alten Wert merken
     333           0 :         pClassData->aRefId = rRefId;// vorher eintragen,
     334             :                                     // sonst Fehler bei rekursion
     335             : 
     336             : 
     337           0 :         aError = IsToDeep( rInst );
     338           0 :         if( aError.IsOk() )
     339           0 :             pClassData->bDflt  = false;
     340             :         else
     341           0 :             pClassData->aRefId = aOldId;
     342             :     }
     343             : 
     344           0 :     return aError;
     345             : }
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10