LCOV - code coverage report
Current view: top level - libreoffice/idl/source/prj - command.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 138 65.2 %
Date: 2012-12-27 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 <tools/fsys.hxx>
      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 :         String aFileName ( *rCommand.aInFileList[ n ] );
     138           8 :         pDataBase->AddDepFile(aFileName);
     139           8 :         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 :                     rtl::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(rtl::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 rtl::OString aStr(rtl::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( new String(rtl::OUString::createFromAscii(*argv) ) );
     182         151 :     for( int i = 1; i < argc; i++ )
     183             :     {
     184         143 :         if( '@' == **(argv +i) )
     185             :         { // when @, then response file
     186           0 :             SvFileStream aStm( rtl::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 :             rtl::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( new String( rtl::OStringToOUString(aStr.copy(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) ) );
     204             :                 }
     205           0 :             }
     206             :         }
     207         143 :         else if( argv[ i ] )
     208         143 :             pList->push_back( new String( rtl::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         151 :     for( size_t i = 1; i < aList.size(); i++ )
     220             :     {
     221         143 :         String aParam( *aList[ i ] );
     222         143 :         sal_Unicode aFirstChar( aParam.GetChar(0) );
     223         143 :         if( '-' == aFirstChar )
     224             :         {
     225         135 :             aParam.Erase( 0, 1 );
     226         135 :             aFirstChar = aParam.GetChar(0);
     227         135 :             if( aFirstChar == 'F' || aFirstChar == 'f' )
     228             :             {
     229          56 :                 aParam.Erase( 0, 1 );
     230          56 :                 aFirstChar = aParam.GetChar(0);
     231          56 :                 String aName( aParam.Copy( 1 ) );
     232          56 :                 if( 's' == aFirstChar )
     233             :                 { // name of slot output
     234           8 :                     aSlotMapFile = aName;
     235             :                 }
     236          48 :                 else if( 'l' == aFirstChar )
     237             :                 { // name of listing
     238           8 :                     aListFile = aName;
     239             :                 }
     240          40 :                 else if( 'i' == aFirstChar )
     241             :                 {
     242             :                 }
     243          40 :                 else if( 'o' == aFirstChar )
     244             :                 {
     245             :                 }
     246          40 :                 else if( 'd' == aFirstChar )
     247             :                 { // name of data set file
     248           8 :                     aDataBaseFile = aName;
     249             :                 }
     250          32 :                 else if( 'D' == aFirstChar )
     251             :                 {
     252             :                 }
     253          32 :                 else if( 'C' == aFirstChar )
     254             :                 {
     255             :                 }
     256          32 :                 else if( 'H' == aFirstChar )
     257             :                 {
     258             :                 }
     259          32 :                 else if( 'c' == aFirstChar )
     260             :                 {
     261             :                 }
     262          32 :                 else if( 'h' == aFirstChar )
     263             :                 {
     264             :                 }
     265          32 :                 else if( 't' == aFirstChar )
     266             :                 {
     267             :                 }
     268          32 :                 else if( 'm' == aFirstChar )
     269             :                 { // name of info file
     270           8 :                     aTargetFile = aName;
     271             :                 }
     272          24 :                 else if( 'r' == aFirstChar )
     273             :                 {
     274             :                 }
     275          24 :                 else if( 'z' == aFirstChar )
     276             :                 { // name of HelpId file
     277           8 :                     aHelpIdFile = aName;
     278             :                 }
     279          16 :                 else if( 'y' == aFirstChar )
     280             :                 { // name of CSV file
     281           0 :                     aCSVFile = aName;
     282             :                 }
     283          16 :                 else if( 'x' == aFirstChar )
     284             :                 { // name of IDL file for the CSV file
     285           8 :                     aExportFile = aName;
     286             :                 }
     287           8 :                 else if( 'M' == aFirstChar )
     288             :                 {
     289           8 :                     m_DepFile = aName;
     290             :                 }
     291             :                 else
     292             :                 {
     293             :                     printf(
     294             :                         "unknown switch: %s\n",
     295             :                         rtl::OUStringToOString(
     296           0 :                             aParam, RTL_TEXTENCODING_UTF8).getStr());
     297           0 :                     exit( -1 );
     298          56 :                 }
     299             :             }
     300          79 :             else if( aParam.EqualsIgnoreCaseAscii( "help" ) || aParam.EqualsIgnoreCaseAscii( "?" ) )
     301             :             { // help
     302           0 :                 printf( "%s", CommandLineSyntax );
     303             :             }
     304          79 :             else if( aParam.EqualsIgnoreCaseAscii( "quiet" ) )
     305             :             {
     306           8 :                 nVerbosity = 0;
     307             :             }
     308          71 :             else if( aParam.EqualsIgnoreCaseAscii( "verbose" ) )
     309             :             {
     310           0 :                 nVerbosity = 2;
     311             :             }
     312          71 :             else if( aParam.EqualsIgnoreCaseAscii( "syntax" ) )
     313             :             { // help
     314           0 :                 int j = 0;
     315           0 :                 while(SyntaxStrings[j])
     316           0 :                     printf("%s\n",SyntaxStrings[j++]);
     317             :             }
     318          71 :             else if( aParam.EqualsIgnoreCaseAscii( "i", 0, 1 ) )
     319             :             { // define include paths
     320          71 :                 String aName( aParam.Copy( 1 ) );
     321          71 :                 if( aPath.Len() )
     322          63 :                     aPath += DirEntry::GetSearchDelimiter();
     323          71 :                 aPath += aName;
     324             :             }
     325           0 :             else if( aParam.EqualsIgnoreCaseAscii( "rsc", 0, 3 ) )
     326             :             { // first line in *.srs file
     327             :                 OSL_ENSURE(false, "does anything use this option, doesn't look like it belong here");
     328           0 :                 if( aList[ i + 1 ] )
     329             :                 {
     330           0 :                     i++;
     331             :                 }
     332             :             }
     333             :             else
     334             :             {
     335             :                 // temporary compatibility hack
     336             :                 printf(
     337             :                     "unknown switch: %s\n",
     338             :                     rtl::OUStringToOString(
     339           0 :                         aParam, RTL_TEXTENCODING_UTF8).getStr());
     340           0 :                 exit( -1 );
     341             :             }
     342             :         }
     343             :         else
     344             :         {
     345           8 :             aInFileList.push_back( new String( aParam ) );
     346             :         }
     347         143 :     }
     348             :     else
     349             :     {
     350           0 :         printf( "%s", CommandLineSyntax );
     351             :     }
     352             : 
     353         159 :     for ( size_t i = 0, n = aList.size(); i < n; ++i )
     354         151 :         delete aList[ i ];
     355           8 :     aList.clear();
     356             : 
     357           8 :     rtl::OString aInc(getenv("INCLUDE"));
     358             :     // append include environment variable
     359           8 :     if( aInc.getLength() )
     360             :     {
     361           0 :         if( aPath.Len() )
     362           0 :             aPath += DirEntry::GetSearchDelimiter();
     363           0 :         aPath += rtl::OStringToOUString(aInc, RTL_TEXTENCODING_ASCII_US);
     364           8 :     }
     365           8 : }
     366             : 
     367          16 : SvCommand::~SvCommand()
     368             : {
     369             :     // release String list
     370          16 :     for ( size_t i = 0, n = aInFileList.size(); i < n; ++i )
     371           8 :         delete aInFileList[ i ];
     372           8 :     aInFileList.clear();
     373           8 : }
     374             : 
     375             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10