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

Generated by: LCOV version 1.10