LCOV - code coverage report
Current view: top level - idl/source/prj - svidl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 69 112 61.6 %
Date: 2014-11-03 Functions: 3 3 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             : 
      21             : #include <stdlib.h>
      22             : #include <stdio.h>
      23             : #include <database.hxx>
      24             : #include <globals.hxx>
      25             : #include <command.hxx>
      26             : #include <rtl/ustring.hxx>
      27             : #include <osl/file.hxx>
      28             : 
      29             : #define BR 0x8000
      30          16 : bool FileMove_Impl( const OUString & rFile1, const OUString & rFile2, bool bImmerVerschieben )
      31             : {
      32             :     //printf( "Move from %s to %s\n", rFile2.GetStr(), rFile1.GetStr() );
      33          16 :     sal_uLong nC1 = 0;
      34          16 :     sal_uLong nC2 = 1;
      35          16 :     if( !bImmerVerschieben )
      36             :     {
      37          16 :         SvFileStream aOutStm1( rFile1, STREAM_STD_READ );
      38          32 :         SvFileStream aOutStm2( rFile2, STREAM_STD_READ );
      39          16 :         if( aOutStm1.GetError() == SVSTREAM_OK )
      40             :         {
      41           0 :             sal_uInt8 * pBuf1 = new sal_uInt8[ BR ];
      42           0 :             sal_uInt8 * pBuf2 = new sal_uInt8[ BR ];
      43           0 :             nC1 = aOutStm1.Read( pBuf1, BR );
      44           0 :             nC2 = aOutStm2.Read( pBuf2, BR );
      45           0 :             while( nC1 == nC2 )
      46             :             {
      47           0 :                 if( memcmp( pBuf1, pBuf2, nC1 ) )
      48             :                 {
      49           0 :                     nC1++;
      50           0 :                     break;
      51             :                 }
      52             :                 else
      53             :                 {
      54           0 :                     if( 0x8000 != nC1 )
      55           0 :                         break;
      56           0 :                     nC1 = aOutStm1.Read( pBuf1, BR );
      57           0 :                     nC2 = aOutStm2.Read( pBuf2, BR );
      58             :                 }
      59             :             }
      60           0 :             delete[] pBuf1;
      61           0 :             delete[] pBuf2;
      62          16 :         }
      63             :     }
      64          16 :     OUString fileURL2;
      65          16 :     osl::FileBase::getFileURLFromSystemPath( rFile2, fileURL2 );
      66          16 :     if( nC1 != nC2 )
      67             :     {// something has changed
      68          16 :         OUString fileURL1;
      69          16 :         osl::FileBase::getFileURLFromSystemPath( rFile1, fileURL1 );
      70             :         // move file
      71          16 :         if( osl::FileBase::E_None != osl::File::move( fileURL2, fileURL1 ) )
      72             :         {
      73             :             // delete both files
      74           0 :             osl::File::remove( fileURL1 );
      75           0 :             osl::File::remove( fileURL2 );
      76           0 :             return false;
      77             :         }
      78          16 :         return true;
      79             :     }
      80           0 :     return osl::FileBase::E_None == osl::File::remove( fileURL2 );
      81             : }
      82             : 
      83             : //This function gets a system path to a file [fname], creates a temp file in
      84             : //the same folder as [fname] and returns the system path of the temp file.
      85          16 : inline OUString tempFileHelper(OUString const & fname)
      86             : {
      87          16 :     OUString aTmpFile;
      88             : 
      89          16 :     sal_Int32 delimIndex = fname.lastIndexOf( '/' );
      90          16 :     if( delimIndex > 0 )
      91             :     {
      92          16 :         OUString aTmpDir( fname.copy( 0,  delimIndex ) );
      93          16 :         osl::FileBase::getFileURLFromSystemPath( aTmpDir, aTmpDir );
      94          16 :         osl::FileBase::createTempFile( &aTmpDir, 0, &aTmpFile );
      95          16 :         osl::FileBase::getSystemPathFromFileURL( aTmpFile, aTmpFile );
      96             :     }
      97             :     else
      98             :     {
      99           0 :         OStringBuffer aStr("invalid filename: ");
     100           0 :         aStr.append(OUStringToOString(fname, RTL_TEXTENCODING_UTF8));
     101           0 :         fprintf(stderr, "%s\n", aStr.getStr());
     102             :     }
     103          16 :     return aTmpFile;
     104             : }
     105             : 
     106           8 : int main ( int argc, char ** argv)
     107             : {
     108           8 :     OUString aTmpSlotMapFile;
     109          16 :     OUString aTmpDepFile;
     110             : 
     111          16 :     SvCommand aCommand( argc, argv );
     112             : 
     113           8 :     if( aCommand.nVerbosity != 0 )
     114           0 :         printf( "StarView Interface Definition Language (IDL) Compiler 3.0\n" );
     115             : 
     116           8 :     Init();
     117           8 :     SvIdlWorkingBase * pDataBase = new SvIdlWorkingBase(aCommand);
     118             : 
     119           8 :     int nExit = 0;
     120           8 :     if( !aCommand.aExportFile.isEmpty() )
     121             :     {
     122           8 :         osl::DirectoryItem aDI;
     123          16 :         osl::FileStatus fileStatus( osl_FileStatus_Mask_FileName );
     124           8 :         osl::DirectoryItem::get( aCommand.aExportFile, aDI );
     125           8 :         aDI.getFileStatus(fileStatus);
     126          16 :         pDataBase->SetExportFile( fileStatus.getFileName() );
     127             :     }
     128             : 
     129           8 :     if( ReadIdl( pDataBase, aCommand ) )
     130             :     {
     131           8 :         if( nExit == 0 && !aCommand.aSlotMapFile.isEmpty() )
     132             :         {
     133           8 :             aTmpSlotMapFile = tempFileHelper(aCommand.aSlotMapFile);
     134           8 :             SvFileStream aOutStm( aTmpSlotMapFile, STREAM_READWRITE | STREAM_TRUNC );
     135           8 :             if( !pDataBase->WriteSfx( aOutStm ) )
     136             :             {
     137           0 :                 nExit = -1;
     138           0 :                 OStringBuffer aStr("cannot write slotmap file: ");
     139           0 :                 aStr.append(OUStringToOString(aCommand.aSlotMapFile, RTL_TEXTENCODING_UTF8));
     140           0 :                 fprintf(stderr, "%s\n", aStr.getStr());
     141           8 :             }
     142             :         }
     143           8 :         if (nExit == 0 && !aCommand.m_DepFile.isEmpty())
     144             :         {
     145           8 :             aTmpDepFile = tempFileHelper(aCommand.m_DepFile);
     146           8 :             SvFileStream aOutStm( aTmpDepFile, STREAM_READWRITE | STREAM_TRUNC );
     147           8 :             pDataBase->WriteDepFile(aOutStm, aCommand.aTargetFile);
     148           8 :             if( aOutStm.GetError() != SVSTREAM_OK )
     149             :             {
     150           0 :                 nExit = -1;
     151             :                 fprintf( stderr, "cannot write dependency file: %s\n",
     152             :                         OUStringToOString( aCommand.m_DepFile,
     153           0 :                             RTL_TEXTENCODING_UTF8 ).getStr() );
     154           8 :             }
     155             :         }
     156             :     }
     157             :     else
     158           0 :         nExit = -1;
     159             : 
     160           8 :     if( nExit == 0 )
     161             :     {
     162           8 :         bool bErr = false;
     163           8 :         bool bDoMove = aCommand.aTargetFile.isEmpty();
     164          16 :         OUString aErrFile, aErrFile2;
     165           8 :         if( !bErr && !aCommand.aSlotMapFile.isEmpty() )
     166             :         {
     167           8 :             bErr |= !FileMove_Impl( aCommand.aSlotMapFile, aTmpSlotMapFile, bDoMove );
     168           8 :             if( bErr ) {
     169           0 :                 aErrFile = aCommand.aSlotMapFile;
     170           0 :                 aErrFile2 = aTmpSlotMapFile;
     171             :             }
     172             :         }
     173           8 :         if (!bErr && !aCommand.m_DepFile.isEmpty())
     174             :         {
     175           8 :             bErr |= !FileMove_Impl( aCommand.m_DepFile, aTmpDepFile, bDoMove );
     176           8 :             if (bErr) {
     177           0 :                 aErrFile = aCommand.m_DepFile;
     178           0 :                 aErrFile2 = aTmpDepFile;
     179             :             }
     180             :         }
     181             : 
     182           8 :         if( bErr )
     183             :         {
     184           0 :             nExit = -1;
     185           0 :             OStringBuffer aStr("cannot move file from: ");
     186             :             aStr.append(OUStringToOString(aErrFile2,
     187           0 :                 RTL_TEXTENCODING_UTF8));
     188           0 :             aStr.append("\n              to file: ");
     189             :             aStr.append(OUStringToOString(aErrFile,
     190           0 :                 RTL_TEXTENCODING_UTF8));
     191           0 :             fprintf( stderr, "%s\n", aStr.getStr() );
     192             :         }
     193             :         else
     194             :         {
     195           8 :             if( !aCommand.aTargetFile.isEmpty() )
     196             :             {
     197             :                 // stamp file, because idl passed through correctly
     198             :                 SvFileStream aOutStm( aCommand.aTargetFile,
     199           8 :                                 STREAM_READWRITE | STREAM_TRUNC );
     200             :             }
     201           8 :         }
     202             :     }
     203             : 
     204           8 :     if( nExit != 0 )
     205             :     {
     206           0 :         if( !aCommand.aSlotMapFile.isEmpty() )
     207             :         {
     208           0 :             osl::FileBase::getSystemPathFromFileURL( aTmpSlotMapFile, aTmpSlotMapFile );
     209           0 :             osl::File::remove( aTmpSlotMapFile );
     210             :         }
     211             :     }
     212             : 
     213           8 :     delete pDataBase;
     214           8 :     DeInit();
     215           8 :     if( nExit != 0 )
     216           0 :         fprintf( stderr, "svidl terminated with errors\n" );
     217          16 :     return nExit;
     218             : }
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10