LCOV - code coverage report
Current view: top level - idl/source/prj - command.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 71 109 65.1 %
Date: 2015-06-13 12:38:46 Functions: 6 6 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             : #include <sal/config.h>
      21             : 
      22             : #include <stdlib.h>
      23             : #include <stdio.h>
      24             : #include <string.h>
      25             : #include <ctype.h>
      26             : 
      27             : #include <osl/diagnose.h>
      28             : 
      29             : #include <command.hxx>
      30             : #include <globals.hxx>
      31             : #include <database.hxx>
      32             : 
      33             : char const * SyntaxStrings[] = {
      34             : "basic-type:",
      35             : "\tvoid|        char|       int|        float|      double|",
      36             : "\tUINT16|      INT16|      UINT32|     INT32|      BOOL|",
      37             : "\tBYTE|        String|     SbxObject",
      38             : "",
      39             : "{ import \"filename\" }\n",
      40             : "module definition:",
      41             : "module",
      42             : "\tunique id range (ask MM)",
      43             : "modul-name",
      44             : "'['",
      45             : "\tSlotIdFile( \"filename\" )",
      46             : "']'",
      47             : "'{'",
      48             : "\t{ include \"filename\" }\n",
      49             : 
      50             : "\titem definition:",
      51             : "\titem type item-name;\n",
      52             : 
      53             : "\ttype definition:",
      54             : "\tstruct | union identifier",
      55             : "\t'{'",
      56             : "\t\t{ type idetifier }",
      57             : "\t'}'",
      58             : "\t|",
      59             : "\tenum identifier",
      60             : "\t'{'",
      61             : "\t\t{ identifier, }",
      62             : "\t'}'",
      63             : "\t|",
      64             : "\ttypedef type identifier\n",
      65             : 
      66             : "\titem-method:",
      67             : "\titem identifier item-method-args\n",
      68             : 
      69             : "\titem-method-args:",
      70             : "\t( { item parameter-name SLOT_ID } )\n",
      71             : 
      72             : "\tslot definition:",
      73             : "\titem identifier SLOT_ID [ item-method-args ]",
      74             : "\t'['\n",
      75             : 
      76             : "\t\titem-method-args",
      77             : "\t\tAccelConfig, MenuConfig, StatusBarConfig, ToolbarConfig",
      78             : "\t\tAutomation*",
      79             : "\t\tAutoUpdate",
      80             : "\t\tContainer",
      81             : "\t\tDefault        = Identifier",
      82             : "\t\tExecMethod     = Identifier",
      83             : "\t\tExport*",
      84             : "\t\tFastCall",
      85             : "\t\tGet, Set",
      86             : "\t\tGroupId        = Identifier",
      87             : "\t\tHasCoreId",
      88             : "\t\tHasDialog",
      89             : "\t\tIsCollection",
      90             : "\t\tImageRotation",
      91             : "\t\tImageReflection",
      92             : "\t\tPseudoPrefix   = Identifier",
      93             : "\t\tPseudoSlots",
      94             : "\t\tReadOnly",
      95             : "\t\tReadOnlyDoc*",
      96             : "\t\tRecordPerSet*, RecordPerItem, RecordManual, NoRecord",
      97             : "\t\tRecordAbsolute",
      98             : "\t\tStateMethod    = Identifier",
      99             : "\t\tSynchron*, Asynchron",
     100             : "\t\tToggle",
     101             : "\t']'\n",
     102             : 
     103             : "\tinterface definition:",
     104             : "\tshell | interface identifier ':' interface",
     105             : "\t'{'",
     106             : "\t\t{ slot }",
     107             : "\t'}'\n",
     108             : "---syntax example is sfx.idl---\n",
     109             : NULL };
     110             : 
     111             : char CommandLineSyntax[] =
     112             : "-fs<slotmap file>\n"
     113             : "-fm<makefile target file>\n"
     114             : "-help, ?                   @<file> response file\n"
     115             : " <filenames>\n";
     116             : 
     117           8 : void Init()
     118             : {
     119           8 :     if( !IDLAPP->pHashTable )
     120           8 :         IDLAPP->pHashTable      = new SvStringHashTable( 2801 );
     121           8 :     if( !IDLAPP->pGlobalNames )
     122           8 :         IDLAPP->pGlobalNames    = new SvGlobalHashNames();
     123           8 : }
     124             : 
     125           8 : void DeInit()
     126             : {
     127           8 :     delete IDLAPP;
     128           8 : }
     129             : 
     130           8 : bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
     131             : {
     132          16 :     for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
     133             :     {
     134           8 :         OUString aFileName ( rCommand.aInFileList[ n ] );
     135           8 :         pDataBase->AddDepFile(aFileName);
     136          16 :         SvFileStream aStm( aFileName, STREAM_STD_READ | StreamMode::NOCREATE );
     137           8 :         if( aStm.GetError() == SVSTREAM_OK )
     138             :         {
     139           8 :             SvTokenStream aTokStm( aStm, aFileName );
     140           8 :             if( !pDataBase->ReadSvIdl( aTokStm, false, rCommand.aPath ) )
     141           0 :                 return false;
     142             :         }
     143             :         else
     144             :         {
     145             :             const OString aStr(OUStringToOString(aFileName,
     146           0 :                 RTL_TEXTENCODING_UTF8));
     147           0 :             fprintf( stderr, "unable to read input file: %s\n", aStr.getStr() );
     148           0 :             return false;
     149             :         }
     150           8 :     }
     151           8 :     return true;
     152             : }
     153             : 
     154           8 : static bool ResponseFile( StringList * pList, int argc, char ** argv )
     155             : {
     156             :     // program name
     157           8 :     pList->push_back( OUString::createFromAscii(*argv) );
     158         115 :     for( int i = 1; i < argc; i++ )
     159             :     {
     160         107 :         if( '@' == **(argv +i) )
     161             :         { // when @, then response file
     162           0 :             SvFileStream aStm( OUString::createFromAscii((*(argv +i)) +1), STREAM_STD_READ | StreamMode::NOCREATE );
     163           0 :             if( aStm.GetError() != SVSTREAM_OK )
     164           0 :                 return false;
     165             : 
     166           0 :             OString aStr;
     167           0 :             while( aStm.ReadLine( aStr ) )
     168             :             {
     169           0 :                 sal_uInt16 n = 0;
     170           0 :                 sal_uInt16 nPos = 1;
     171           0 :                 while( n != nPos )
     172             :                 {
     173           0 :                     while( aStr[n] && isspace( aStr[n] ) )
     174           0 :                         n++;
     175           0 :                     nPos = n;
     176           0 :                     while( aStr[n] && !isspace( aStr[n] ) )
     177           0 :                         n++;
     178           0 :                     if( n != nPos )
     179           0 :                         pList->push_back( OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
     180             :                 }
     181           0 :             }
     182             :         }
     183         107 :         else if( argv[ i ] )
     184         107 :             pList->push_back( OUString::createFromAscii( argv[ i ] ) );
     185             :     }
     186           8 :     return true;
     187             : }
     188             : 
     189           8 : SvCommand::SvCommand( int argc, char ** argv )
     190           8 :     : nVerbosity(1)
     191             : {
     192           8 :     StringList aList;
     193             : 
     194           8 :     if( ResponseFile( &aList, argc, argv ) )
     195             :     {
     196         115 :         for( size_t i = 1; i < aList.size(); i++ )
     197             :         {
     198         107 :             OUString aParam( aList[ i ] );
     199         107 :             sal_Unicode aFirstChar( aParam[0] );
     200         107 :             if( '-' == aFirstChar )
     201             :             {
     202          99 :                 aParam = aParam.copy( 1 );
     203          99 :                 aFirstChar = aParam[0];
     204          99 :                 if( aFirstChar == 'F' || aFirstChar == 'f' )
     205             :                 {
     206          32 :                     aParam = aParam.copy( 1 );
     207          32 :                     aFirstChar = aParam[0];
     208          32 :                     OUString aName( aParam.copy( 1 ) );
     209          32 :                     if( 's' == aFirstChar )
     210             :                     { // name of slot output
     211           8 :                         aSlotMapFile = aName;
     212             :                     }
     213          24 :                     else if( 'm' == aFirstChar )
     214             :                     { // name of info file
     215           8 :                         aTargetFile = aName;
     216             :                     }
     217          16 :                     else if( 'x' == aFirstChar )
     218             :                     { // name of IDL file for the CSV file
     219           8 :                         aExportFile = aName;
     220             :                     }
     221           8 :                     else if( 'M' == aFirstChar )
     222             :                     {
     223           8 :                         m_DepFile = aName;
     224             :                     }
     225             :                     else
     226             :                     {
     227             :                         printf(
     228             :                             "unknown switch: %s\n",
     229             :                             OUStringToOString(
     230           0 :                                 aParam, RTL_TEXTENCODING_UTF8).getStr());
     231           0 :                         exit( -1 );
     232          32 :                     }
     233             :                 }
     234          67 :                 else if( aParam.equalsIgnoreAsciiCase( "help" ) || aParam.equalsIgnoreAsciiCase( "?" ) )
     235             :                 { // help
     236           0 :                     printf( "%s", CommandLineSyntax );
     237             :                 }
     238          67 :                 else if( aParam.equalsIgnoreAsciiCase( "quiet" ) )
     239             :                 {
     240           8 :                     nVerbosity = 0;
     241             :                 }
     242          59 :                 else if( aParam.equalsIgnoreAsciiCase( "verbose" ) )
     243             :                 {
     244           0 :                     nVerbosity = 2;
     245             :                 }
     246          59 :                 else if( aParam.equalsIgnoreAsciiCase( "syntax" ) )
     247             :                 { // help
     248           0 :                     int j = 0;
     249           0 :                     while(SyntaxStrings[j])
     250           0 :                         printf("%s\n",SyntaxStrings[j++]);
     251             :                 }
     252          59 :                 else if (aParam == "isystem")
     253             :                 {
     254             :                     // ignore "-isystem" and following arg
     255           0 :                     if (i < aList.size())
     256             :                     {
     257           0 :                         ++i;
     258             :                     }
     259             :                 }
     260          59 :                 else if (aParam.startsWith("isystem"))
     261             :                 {
     262             :                     // ignore args starting with "-isystem"
     263             :                 }
     264          59 :                 else if( aParam.startsWithIgnoreAsciiCase( "i" ) )
     265             :                 { // define include paths
     266          59 :                     OUString aName( aParam.copy( 1 ) );
     267          59 :                     if( !aPath.isEmpty() )
     268          51 :                         aPath += OUString( SAL_PATHSEPARATOR );
     269          59 :                     aPath += aName;
     270             :                 }
     271           0 :                 else if( aParam.startsWithIgnoreAsciiCase( "rsc" ) )
     272             :                 { // first line in *.srs file
     273             :                     OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
     274           0 :                     if( !aList[ i + 1 ].isEmpty() )
     275             :                     {
     276           0 :                         i++;
     277             :                     }
     278             :                 }
     279             :                 else
     280             :                 {
     281             :                     // temporary compatibility hack
     282             :                     printf(
     283             :                         "unknown switch: %s\n",
     284             :                         OUStringToOString(
     285           0 :                             aParam, RTL_TEXTENCODING_UTF8).getStr());
     286           0 :                     exit( -1 );
     287             :                 }
     288             :             }
     289             :             else
     290             :             {
     291           8 :                 aInFileList.push_back( aParam );
     292             :             }
     293         107 :         }
     294             :     }
     295             :     else
     296             :     {
     297           0 :         printf( "%s", CommandLineSyntax );
     298             :     }
     299             : 
     300           8 :     aList.clear();
     301             : 
     302          16 :     OString aInc(getenv("INCLUDE"));
     303             :     // append include environment variable
     304           8 :     if( aInc.getLength() )
     305             :     {
     306           0 :         if( !aPath.isEmpty() )
     307           0 :             aPath += OUString( SAL_PATHSEPARATOR );
     308           0 :         aPath += OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
     309           8 :     }
     310           8 : }
     311             : 
     312          16 : SvCommand::~SvCommand()
     313             : {
     314             :     // release String list
     315           8 :     aInFileList.clear();
     316           8 : }
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11