LCOV - code coverage report
Current view: top level - rsc/source/prj - start.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 114 152 75.0 %
Date: 2014-04-11 Functions: 4 5 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 <fcntl.h>
      24             : #include <string.h>
      25             : 
      26             : #ifdef UNX
      27             : #include <unistd.h>
      28             : #include <sys/wait.h>
      29             : #else // UNX
      30             : 
      31             : #include <io.h>
      32             : #include <process.h>
      33             : #include <dos.h>
      34             : 
      35             : #endif // UNX
      36             : 
      37             : #include <gui.hxx>
      38             : #include <rsctools.hxx>
      39             : #include <rscerror.h>
      40             : #include <sal/main.h>
      41             : #include <rtl/strbuf.hxx>
      42             : 
      43             : 
      44             : // Entry point declaration for modules rscpp and rsc2
      45             : extern "C"
      46             : {
      47             :     int rscpp_main(int, char**);
      48             : }
      49             : 
      50         395 : static bool CallPrePro( const OString& rInput,
      51             :                         const OString& rOutput, RscPtrPtr * pCmdLine,
      52             :                         bool bResponse )
      53             : {
      54         395 :     RscPtrPtr       aNewCmdL;   // Kommandozeile
      55         790 :     RscPtrPtr       aRespCmdL;   // Kommandozeile
      56         395 :     RscPtrPtr *     pCmdL = &aNewCmdL;
      57             :     int             i, nRet;
      58         395 :     FILE*           fRspFile = NULL;
      59         790 :     OString    aRspFileName;
      60             : 
      61         395 :     if( bResponse )
      62             :     {
      63         395 :         aRspFileName = ::GetTmpFileName();
      64         395 :         fRspFile = fopen( aRspFileName.getStr(), "w" );
      65             :     }
      66             : 
      67         395 :     if( !fRspFile )
      68           0 :         aNewCmdL.Append( rsc_strdup( "rscpp" ) );
      69             : 
      70         395 :     bool bVerbose = false;
      71       11900 :     for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
      72             :     {
      73       11505 :         if ( 0 == rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
      74             :         {
      75           0 :             bVerbose = true;
      76           0 :             continue;
      77             :         }
      78       34515 :         if ( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-u", 2 ) ||
      79       18220 :              !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-i", 2 ) ||
      80        6715 :              !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-d", 2 ))
      81             :         {
      82        9925 :             aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
      83             :         }
      84             :     }
      85             : 
      86         395 :     aNewCmdL.Append( rsc_strdup( rInput.getStr() ) );
      87         395 :     aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) );
      88         395 :     aNewCmdL.Append( (void *)0 );
      89             : 
      90         395 :     if ( bVerbose )
      91             :     {
      92           0 :         printf( "Preprocessor commandline: " );
      93           0 :         for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
      94             :         {
      95           0 :             printf( " " );
      96           0 :             printf( "%s", (const char *)pCmdL->GetEntry( i ) );
      97             :         }
      98           0 :         printf( "\n" );
      99             :     }
     100             : 
     101         395 :     if( fRspFile )
     102             :     {
     103         395 :         aRespCmdL.Append( rsc_strdup( "rscpp" ) );
     104         395 :         OStringBuffer aTmpStr;
     105         395 :         aTmpStr.append('@').append(aRspFileName);
     106         395 :         aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) );
     107         395 :         aRespCmdL.Append( (void *)0 );
     108             : 
     109         395 :         pCmdL = &aRespCmdL;
     110       11110 :         for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
     111             :         {
     112       10715 :             fprintf( fRspFile, "%s ", (const char *)aNewCmdL.GetEntry( i ) );
     113             :         }
     114         395 :         fclose( fRspFile );
     115             : 
     116         395 :         if ( bVerbose )
     117             :         {
     118           0 :             printf( "Preprocessor startline: " );
     119           0 :             for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
     120             :             {
     121           0 :                 printf( " " );
     122           0 :                 printf( "%s", (const char *)pCmdL->GetEntry( i ) );
     123             :             }
     124           0 :             printf( "\n" );
     125         395 :         }
     126             :     }
     127             : 
     128         395 :     nRet = rscpp_main( pCmdL->GetCount()-1, (char**)pCmdL->GetBlock() );
     129             : 
     130         395 :     if ( fRspFile )
     131             :     {
     132             :         #if OSL_DEBUG_LEVEL > 5
     133             :         fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() );
     134             :         #else
     135         395 :         unlink( aRspFileName.getStr() );
     136             :         #endif
     137             :     }
     138         395 :     if ( nRet )
     139           0 :         return false;
     140             : 
     141         790 :     return true;
     142             : }
     143             : 
     144             : 
     145         451 : static bool CallRsc2( RscStrList * pInputList,
     146             :                       const OString &rSrsName, RscPtrPtr * pCmdLine )
     147             : {
     148             :     int nRet;
     149             :     OString*  pString;
     150         451 :     RscVerbosity eVerbosity = RscVerbosityNormal;
     151             : 
     152         451 :     RscPtrPtr aNewCmdL;
     153         451 :     aNewCmdL.Append( rsc_strdup( "rsc2" ) );
     154             : 
     155       12853 :     for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i)
     156             :     {
     157       12402 :         if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-verbose" ) )
     158             :         {
     159           0 :             eVerbosity = RscVerbosityVerbose;
     160           0 :             continue;
     161             :         }
     162       12402 :         if ( !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-quiet" ) )
     163             :         {
     164           0 :             eVerbosity = RscVerbositySilent;
     165           0 :             continue;
     166             :         }
     167       36811 :         if( !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ),  "-fp=", 4 ) ||
     168       24014 :             !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-fo=", 4 ) ||
     169       23619 :             !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-presponse", 9 ) ||
     170       23224 :             !rsc_strnicmp( (char *)pCmdLine->GetEntry( i ), "-rc", 3 ) ||
     171       23224 :             !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-+" ) ||
     172       23224 :             !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-br" ) ||
     173       23224 :             !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-bz" ) ||
     174       35570 :             !rsc_stricmp( (char *)pCmdLine->GetEntry( i ), "-r" ) ||
     175       11556 :             ( '-' != *(char *)pCmdLine->GetEntry( i ) ) )
     176             :         {
     177             :         }
     178             :         else
     179             :         {
     180       11104 :             aNewCmdL.Append( rsc_strdup( (char *)pCmdLine->GetEntry( i ) ) );
     181             :         }
     182             :     };
     183             : 
     184         451 :     aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) );
     185             : 
     186         903 :     for ( size_t i = 0, n = pInputList->size(); i < n; ++i )
     187             :     {
     188         452 :         pString = (*pInputList)[ i ];
     189         452 :         aNewCmdL.Append( rsc_strdup( pString->getStr() ) );
     190             :     };
     191             : 
     192         451 :     if ( eVerbosity >= RscVerbosityVerbose )
     193             :     {
     194           0 :         printf( "Rsc2 commandline: " );
     195           0 :         for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ )
     196             :         {
     197           0 :             printf( " %s", (const char *)aNewCmdL.GetEntry( i ) );
     198             :         }
     199           0 :         printf( "\n" );
     200             :     }
     201             : 
     202         451 :     nRet = rsc2_main( aNewCmdL.GetCount(), (char**)aNewCmdL.GetBlock() );
     203             : 
     204         451 :     if( nRet )
     205           0 :         return false;
     206         451 :     return true;
     207             : }
     208             : 
     209         902 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
     210             : {
     211         451 :     bool        bPrePro  = true;
     212         451 :     bool        bHelp    = false;
     213         451 :     bool        bError   = false;
     214         451 :     bool        bResponse = false;
     215         451 :     OString     aSrsName;
     216         902 :     OString     aResName;
     217         902 :     RscStrList  aInputList;
     218         902 :     RscStrList  aTmpList;
     219             :     char *      pStr;
     220             :     char **     ppStr;
     221         902 :     RscPtrPtr   aCmdLine;       // Kommandozeile
     222             :     sal_uInt32  i;
     223             :     OString*    pString;
     224             : 
     225         451 :     pStr = ::ResponseFile( &aCmdLine, argv, argc );
     226         451 :     if( pStr )
     227             :     {
     228           0 :         printf( "Cannot open response file <%s>\n", pStr );
     229           0 :         return( 1 );
     230             :     };
     231             : 
     232         451 :     ppStr  = (char **)aCmdLine.GetBlock();
     233         451 :     ppStr++;
     234         451 :     i = 1;
     235         451 :     bool bSetSrs = false;
     236       13304 :     while( ppStr && i < (aCmdLine.GetCount() -1) )
     237             :     {
     238       12402 :         if( '-' == **ppStr )
     239             :         {
     240       23900 :             if( !rsc_stricmp( (*ppStr) + 1, "p" )
     241       11950 :               || !rsc_stricmp( (*ppStr) + 1, "l" ) )
     242             :             { // kein Preprozessor
     243          56 :                 bPrePro = false;
     244             :             }
     245       11894 :             else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
     246             :             { // Hilfe anzeigen
     247           0 :                 bHelp = true;
     248             :             }
     249       11894 :             else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
     250             :             { // whether to use response file when parameterising preprocessor
     251         395 :                 bResponse = true;
     252             :             }
     253       11499 :             else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
     254             :             { // anderer Name fuer .res-file
     255           0 :                 aResName = (*ppStr) + 4;
     256             :             }
     257       11499 :             else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
     258             :             { // anderer Name fuer .srs-file
     259         395 :                 bSetSrs  = true;
     260         395 :                 aSrsName = (*ppStr);
     261             :             }
     262             :         }
     263             :         else
     264             :         {
     265             :             // Eingabedatei
     266         452 :             aInputList.push_back( new OString(*ppStr) );
     267             :         }
     268       12402 :         ppStr++;
     269       12402 :         i++;
     270             :     }
     271             : 
     272         451 :     if( !aInputList.empty() )
     273             :     {
     274             :         /* build the output file names          */
     275         451 :         if (!aResName.getLength())
     276         451 :             aResName = OutputFile( *aInputList[ 0 ], "res" );
     277         451 :         if( ! bSetSrs )
     278             :         {
     279         112 :             aSrsName = OStringBuffer("-fp=").append(OutputFile(*aInputList[0], "srs")).
     280          56 :                 makeStringAndClear();
     281             :         }
     282             :     };
     283             : 
     284         451 :     if( bHelp )
     285           0 :         bPrePro = false;
     286             : 
     287         451 :     if( bPrePro && !aInputList.empty() )
     288             :     {
     289         395 :         OString aTmpName;
     290             : 
     291         790 :         for ( size_t k = 0, n = aInputList.size(); k < n; ++k )
     292             :         {
     293         395 :             pString = aInputList[ k ];
     294         395 :             aTmpName = ::GetTmpFileName();
     295         395 :             if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) )
     296             :             {
     297           0 :                 printf( "Error starting preprocessor\n" );
     298           0 :                 bError = true;
     299           0 :                 break;
     300             :             }
     301         395 :             aTmpList.push_back( new OString(aTmpName) );
     302         395 :         };
     303             :     };
     304             : 
     305         451 :     if( !bError )
     306             :     {
     307         451 :         if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) )
     308             :         {
     309           0 :             if( !bHelp )
     310             :             {
     311           0 :                 printf( "Error starting rsc2 compiler\n" );
     312           0 :                 bError = true;
     313             :             }
     314             :         };
     315             :     };
     316             : 
     317         846 :     for ( size_t k = 0, n = aTmpList.size(); k < n; ++k )
     318         395 :         unlink( aTmpList[ k ]->getStr() );
     319             : 
     320         902 :     return bError ? EXIT_FAILURE : EXIT_SUCCESS;
     321             : }
     322             : 
     323           0 : void RscExit( sal_uInt32 nExit )
     324             : {
     325           0 :     if( nExit )
     326           0 :         printf( "Program exit is %d\n", (int)nExit );
     327           0 :     exit( nExit );
     328             : }
     329             : 
     330             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10