LCOV - code coverage report
Current view: top level - rsc/source/prj - start.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 120 165 72.7 %
Date: 2015-06-13 12:38:46 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         361 : static bool CallPrePro( const OString& rInput,
      45             :                         const OString& rOutput, RscPtrPtr * pCmdLine,
      46             :                         bool bResponse )
      47             : {
      48         361 :     RscPtrPtr       aNewCmdL;   // Kommandozeile
      49         722 :     RscPtrPtr       aRespCmdL;   // Kommandozeile
      50         361 :     RscPtrPtr *     pCmdL = &aNewCmdL;
      51             :     int             i, nRet;
      52         361 :     FILE*           fRspFile = NULL;
      53         722 :     OString    aRspFileName;
      54             : 
      55         361 :     if( bResponse )
      56             :     {
      57         361 :         aRspFileName = ::GetTmpFileName();
      58         361 :         fRspFile = fopen( aRspFileName.getStr(), "w" );
      59             :     }
      60             : 
      61         361 :     if( !fRspFile )
      62           0 :         aNewCmdL.Append( rsc_strdup( "rscpp" ) );
      63             : 
      64         361 :     bool bVerbose = false;
      65        9755 :     for( i = 1; i < int(pCmdLine->GetCount() -1); i++ )
      66             :     {
      67        9394 :         if ( 0 == rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) )
      68             :         {
      69           0 :             bVerbose = true;
      70           0 :             continue;
      71             :         }
      72        9394 :         if (strcmp(static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem") == 0)
      73             :         {
      74             :             // ignore "-isystem" and following arg
      75           0 :             if (i < int(pCmdLine->GetCount()) - 1)
      76             :             {
      77           0 :                 ++i;
      78             :             }
      79           0 :             continue;
      80             :         }
      81        9394 :         if (strncmp(
      82        9394 :                 static_cast<char *>(pCmdLine->GetEntry(i)), "-isystem",
      83        9394 :                 strlen("-isystem"))
      84             :             == 0)
      85             :         {
      86             :             // ignore args starting with "-isystem"
      87           0 :             continue;
      88             :         }
      89       28182 :         if ( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-u", 2 ) ||
      90       14448 :              !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-i", 2 ) ||
      91        5054 :              !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-d", 2 ))
      92             :         {
      93        7950 :             aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) );
      94             :         }
      95             :     }
      96             : 
      97         361 :     aNewCmdL.Append( rsc_strdup( rInput.getStr() ) );
      98         361 :     aNewCmdL.Append( rsc_strdup( rOutput.getStr() ) );
      99         361 :     aNewCmdL.Append( static_cast<void *>(nullptr) );
     100             : 
     101         361 :     if ( bVerbose )
     102             :     {
     103           0 :         printf( "Preprocessor commandline: " );
     104           0 :         for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
     105             :         {
     106           0 :             printf( " " );
     107           0 :             printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) );
     108             :         }
     109           0 :         printf( "\n" );
     110             :     }
     111             : 
     112         361 :     if( fRspFile )
     113             :     {
     114         361 :         aRespCmdL.Append( rsc_strdup( "rscpp" ) );
     115         361 :         OStringBuffer aTmpStr;
     116         361 :         aTmpStr.append('@').append(aRspFileName);
     117         361 :         aRespCmdL.Append( rsc_strdup( aTmpStr.getStr() ) );
     118         361 :         aRespCmdL.Append( static_cast<void *>(nullptr) );
     119             : 
     120         361 :         pCmdL = &aRespCmdL;
     121        9033 :         for( i = 0; i < (int)(aNewCmdL.GetCount() -1); i++ )
     122             :         {
     123        8672 :             fprintf( fRspFile, "%s ", static_cast<const char *>(aNewCmdL.GetEntry( i )) );
     124             :         }
     125         361 :         fclose( fRspFile );
     126             : 
     127         361 :         if ( bVerbose )
     128             :         {
     129           0 :             printf( "Preprocessor startline: " );
     130           0 :             for( i = 0; i < (int)(pCmdL->GetCount() -1); i++ )
     131             :             {
     132           0 :                 printf( " " );
     133           0 :                 printf( "%s", static_cast<const char *>(pCmdL->GetEntry( i )) );
     134             :             }
     135           0 :             printf( "\n" );
     136         361 :         }
     137             :     }
     138             : 
     139         361 :     nRet = rscpp_main( pCmdL->GetCount()-1, reinterpret_cast<char**>(pCmdL->GetBlock()) );
     140             : 
     141         361 :     if ( fRspFile )
     142             :     {
     143             :         #if OSL_DEBUG_LEVEL > 5
     144             :         fprintf( stderr, "leaving response file %s\n", aRspFileName.getStr() );
     145             :         #else
     146         361 :         unlink( aRspFileName.getStr() );
     147             :         #endif
     148             :     }
     149         361 :     if ( nRet )
     150           0 :         return false;
     151             : 
     152         722 :     return true;
     153             : }
     154             : 
     155             : 
     156         417 : static bool CallRsc2( RscStrList * pInputList,
     157             :                       const OString &rSrsName, RscPtrPtr * pCmdLine )
     158             : {
     159             :     int nRet;
     160         417 :     RscVerbosity eVerbosity = RscVerbosityNormal;
     161             : 
     162         417 :     RscPtrPtr aNewCmdL;
     163         417 :     aNewCmdL.Append( rsc_strdup( "rsc2" ) );
     164             : 
     165       10707 :     for (int i = 1; i < (int)(pCmdLine->GetCount() -1); ++i)
     166             :     {
     167       10290 :         if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-verbose" ) )
     168             :         {
     169           0 :             eVerbosity = RscVerbosityVerbose;
     170           0 :             continue;
     171             :         }
     172       10290 :         if ( !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-quiet" ) )
     173             :         {
     174           0 :             eVerbosity = RscVerbositySilent;
     175           0 :             continue;
     176             :         }
     177       30509 :         if( !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )),  "-fp=", 4 ) ||
     178       19858 :             !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-fo=", 4 ) ||
     179       19497 :             !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-presponse", 10 ) ||
     180       19136 :             !rsc_strnicmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-rc", 3 ) ||
     181       19136 :             !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-+" ) ||
     182       19136 :             !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-br" ) ||
     183       19136 :             !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-bz" ) ||
     184       29370 :             !rsc_stricmp( static_cast<char *>(pCmdLine->GetEntry( i )), "-r" ) ||
     185        9512 :             ( '-' != *static_cast<char *>(pCmdLine->GetEntry( i )) ) )
     186             :         {
     187             :         }
     188             :         else
     189             :         {
     190        9095 :             aNewCmdL.Append( rsc_strdup( static_cast<char *>(pCmdLine->GetEntry( i )) ) );
     191             :         }
     192             :     }
     193             : 
     194         417 :     aNewCmdL.Append( rsc_strdup( rSrsName.getStr() ) );
     195             : 
     196         834 :     for ( size_t i = 0, n = pInputList->size(); i < n; ++i )
     197             :     {
     198         417 :         OString* pString = (*pInputList)[ i ];
     199         417 :         aNewCmdL.Append( rsc_strdup( pString->getStr() ) );
     200             :     }
     201             : 
     202         417 :     if ( eVerbosity >= RscVerbosityVerbose )
     203             :     {
     204           0 :         printf( "Rsc2 commandline: " );
     205           0 :         for( size_t i = 0; i < (unsigned int)(aNewCmdL.GetCount() -1); i++ )
     206             :         {
     207           0 :             printf( " %s", static_cast<const char *>(aNewCmdL.GetEntry( i )) );
     208             :         }
     209           0 :         printf( "\n" );
     210             :     }
     211             : 
     212         417 :     nRet = rsc2_main( aNewCmdL.GetCount(), reinterpret_cast<char**>(aNewCmdL.GetBlock()) );
     213             : 
     214         417 :     if( nRet )
     215           0 :         return false;
     216         417 :     return true;
     217             : }
     218             : 
     219         834 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
     220             : {
     221         417 :     bool        bPrePro  = true;
     222         417 :     bool        bHelp    = false;
     223         417 :     bool        bError   = false;
     224         417 :     bool        bResponse = false;
     225         417 :     OString     aSrsName;
     226         834 :     OString     aResName;
     227         834 :     RscStrList  aInputList;
     228         834 :     RscStrList  aTmpList;
     229             :     char *      pStr;
     230             :     char **     ppStr;
     231         834 :     RscPtrPtr   aCmdLine;       // Kommandozeile
     232             :     sal_uInt32  i;
     233             : 
     234         417 :     pStr = ::ResponseFile( &aCmdLine, argv, argc );
     235         417 :     if( pStr )
     236             :     {
     237           0 :         printf( "Cannot open response file <%s>\n", pStr );
     238           0 :         return 1;
     239             :     };
     240             : 
     241         417 :     ppStr  = reinterpret_cast<char **>(aCmdLine.GetBlock());
     242         417 :     ppStr++;
     243         417 :     i = 1;
     244         417 :     bool bSetSrs = false;
     245       11124 :     while( ppStr && i < (aCmdLine.GetCount() -1) )
     246             :     {
     247       10290 :         if (strcmp(*ppStr, "-isystem") == 0)
     248             :         {
     249             :             // ignore "-isystem" and following arg
     250           0 :             if (i < aCmdLine.GetCount() - 1)
     251             :             {
     252           0 :                 ++ppStr;
     253           0 :                 ++i;
     254             :             }
     255             :         }
     256       10290 :         else if (strncmp(*ppStr, "-isystem", strlen("-isystem")) == 0)
     257             :         {
     258             :             // ignore args starting with "-isystem"
     259             :         }
     260       10290 :         else if( '-' == **ppStr )
     261             :         {
     262       19746 :             if( !rsc_stricmp( (*ppStr) + 1, "p" )
     263        9873 :               || !rsc_stricmp( (*ppStr) + 1, "l" ) )
     264             :             { // kein Preprozessor
     265          56 :                 bPrePro = false;
     266             :             }
     267        9817 :             else if( !rsc_stricmp( (*ppStr) + 1, "h" ) )
     268             :             { // Hilfe anzeigen
     269           0 :                 bHelp = true;
     270             :             }
     271        9817 :             else if( !rsc_strnicmp( (*ppStr) + 1, "presponse", 9 ) )
     272             :             { // whether to use response file when parameterising preprocessor
     273         361 :                 bResponse = true;
     274             :             }
     275        9456 :             else if( !rsc_strnicmp( (*ppStr) + 1, "fo=", 3 ) )
     276             :             { // anderer Name fuer .res-file
     277           0 :                 aResName = (*ppStr) + 4;
     278             :             }
     279        9456 :             else if( !rsc_strnicmp( (*ppStr) + 1, "fp=", 3 ) )
     280             :             { // anderer Name fuer .srs-file
     281         361 :                 bSetSrs  = true;
     282         361 :                 aSrsName = (*ppStr);
     283             :             }
     284             :         }
     285             :         else
     286             :         {
     287             :             // Eingabedatei
     288         417 :             aInputList.push_back( new OString(*ppStr) );
     289             :         }
     290       10290 :         ppStr++;
     291       10290 :         i++;
     292             :     }
     293             : 
     294         417 :     if( !aInputList.empty() )
     295             :     {
     296             :         /* build the output file names          */
     297         417 :         if (!aResName.getLength())
     298         417 :             aResName = OutputFile( *aInputList[ 0 ], "res" );
     299         417 :         if( ! bSetSrs )
     300             :         {
     301         112 :             aSrsName = OStringBuffer("-fp=").append(OutputFile(*aInputList[0], "srs")).
     302          56 :                 makeStringAndClear();
     303             :         }
     304             :     };
     305             : 
     306         417 :     if( bHelp )
     307           0 :         bPrePro = false;
     308             : 
     309         417 :     if( bPrePro && !aInputList.empty() )
     310             :     {
     311         361 :         OString aTmpName;
     312             : 
     313         722 :         for ( size_t k = 0, n = aInputList.size(); k < n; ++k )
     314             :         {
     315         361 :             OString* pString = aInputList[ k ];
     316         361 :             aTmpName = ::GetTmpFileName();
     317         361 :             if( !CallPrePro( *pString, aTmpName, &aCmdLine, bResponse ) )
     318             :             {
     319           0 :                 printf( "Error starting preprocessor\n" );
     320           0 :                 bError = true;
     321           0 :                 break;
     322             :             }
     323         361 :             aTmpList.push_back( new OString(aTmpName) );
     324         361 :         };
     325             :     };
     326             : 
     327         417 :     if( !bError )
     328             :     {
     329         417 :         if( !CallRsc2( bPrePro ? &aTmpList : &aInputList, aSrsName, &aCmdLine ) )
     330             :         {
     331           0 :             if( !bHelp )
     332             :             {
     333           0 :                 printf( "Error starting rsc2 compiler\n" );
     334           0 :                 bError = true;
     335             :             }
     336             :         };
     337             :     };
     338             : 
     339         778 :     for ( size_t k = 0, n = aTmpList.size(); k < n; ++k )
     340         361 :         unlink( aTmpList[ k ]->getStr() );
     341             : 
     342         834 :     return bError ? EXIT_FAILURE : EXIT_SUCCESS;
     343             : }
     344             : 
     345           0 : void RscExit( sal_uInt32 nExit )
     346             : {
     347           0 :     if( nExit )
     348           0 :         printf( "Program exit is %d\n", (int)nExit );
     349           0 :     exit( nExit );
     350             : }
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11