LCOV - code coverage report
Current view: top level - idl/source/prj - command.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 93 138 67.4 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 149 378 39.4 %

           Branch data     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                 :         16 : void Init()
     121                 :            : {
     122         [ +  - ]:         16 :     if( !IDLAPP->pHashTable )
     123         [ +  - ]:         16 :         IDLAPP->pHashTable      = new SvStringHashTable( 2801 );
     124         [ +  - ]:         16 :     if( !IDLAPP->pGlobalNames )
     125         [ +  - ]:         16 :         IDLAPP->pGlobalNames    = new SvGlobalHashNames();
     126                 :         16 : }
     127                 :            : 
     128                 :         16 : void DeInit()
     129                 :            : {
     130         [ +  - ]:         16 :     delete IDLAPP;
     131                 :         16 : }
     132                 :            : 
     133                 :         16 : sal_Bool ReadIdl( SvIdlWorkingBase * pDataBase, const SvCommand & rCommand )
     134                 :            : {
     135         [ +  + ]:         32 :     for( size_t n = 0; n < rCommand.aInFileList.size(); ++n )
     136                 :            :     {
     137 [ +  - ][ +  - ]:         16 :         String aFileName ( *rCommand.aInFileList[ n ] );
     138         [ +  - ]:         16 :         pDataBase->AddDepFile(aFileName);
     139         [ +  - ]:         16 :         SvFileStream aStm( aFileName, STREAM_STD_READ | STREAM_NOCREATE );
     140         [ +  - ]:         16 :         if( aStm.GetError() == SVSTREAM_OK )
     141                 :            :         {
     142 [ +  - ][ -  + ]:         16 :             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         [ +  - ]:         16 :                 SvTokenStream aTokStm( aStm, aFileName );
     163 [ +  - ][ -  + ]:         16 :                 if( !pDataBase->ReadSvIdl( aTokStm, sal_False, rCommand.aPath ) )
     164 [ +  - ][ +  - ]:         16 :                     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                 :         16 :             return sal_False;
     173                 :            :         }
     174 [ +  - ][ -  + ]:         16 :     }
         [ +  - ][ +  - ]
     175                 :         16 :     return sal_True;
     176                 :            : }
     177                 :            : 
     178                 :         16 : static sal_Bool ResponseFile( StringList * pList, int argc, char ** argv )
     179                 :            : {
     180                 :            :     // program name
     181 [ +  - ][ +  - ]:         16 :     pList->push_back( new String(rtl::OUString::createFromAscii(*argv) ) );
                 [ +  - ]
     182         [ +  + ]:        302 :     for( int i = 1; i < argc; i++ )
     183                 :            :     {
     184         [ -  + ]:        286 :         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         [ +  - ]:        286 :         else if( argv[ i ] )
     208 [ +  - ][ +  - ]:        286 :             pList->push_back( new String( rtl::OUString::createFromAscii( argv[ i ] ) ) );
                 [ +  - ]
     209                 :            :     }
     210                 :         16 :     return sal_True;
     211                 :            : }
     212                 :            : 
     213                 :         16 : SvCommand::SvCommand( int argc, char ** argv )
     214 [ +  - ][ +  - ]:         16 :     : nVerbosity(1), nFlags( 0 )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     215                 :            : {
     216         [ +  - ]:         16 :     StringList aList;
     217                 :            : 
     218 [ +  - ][ +  - ]:         16 :     if( ResponseFile( &aList, argc, argv ) )
     219         [ +  + ]:        302 :     for( size_t i = 1; i < aList.size(); i++ )
     220                 :            :     {
     221 [ +  - ][ +  - ]:        286 :         String aParam( *aList[ i ] );
     222                 :        286 :         sal_Unicode aFirstChar( aParam.GetChar(0) );
     223         [ +  + ]:        286 :         if( '-' == aFirstChar )
     224                 :            :         {
     225         [ +  - ]:        270 :             aParam.Erase( 0, 1 );
     226                 :        270 :             aFirstChar = aParam.GetChar(0);
     227 [ +  + ][ +  - ]:        270 :             if( aFirstChar == 'F' || aFirstChar == 'f' )
     228                 :            :             {
     229         [ +  - ]:        112 :                 aParam.Erase( 0, 1 );
     230                 :        112 :                 aFirstChar = aParam.GetChar(0);
     231         [ +  - ]:        112 :                 String aName( aParam.Copy( 1 ) );
     232         [ +  + ]:        112 :                 if( 's' == aFirstChar )
     233                 :            :                 { // name of slot output
     234         [ +  - ]:         16 :                     aSlotMapFile = aName;
     235                 :            :                 }
     236         [ +  + ]:         96 :                 else if( 'l' == aFirstChar )
     237                 :            :                 { // name of listing
     238         [ +  - ]:         16 :                     aListFile = aName;
     239                 :            :                 }
     240         [ +  - ]:         80 :                 else if( 'i' == aFirstChar )
     241                 :            :                 {
     242                 :            :                 }
     243         [ +  - ]:         80 :                 else if( 'o' == aFirstChar )
     244                 :            :                 {
     245                 :            :                 }
     246         [ +  + ]:         80 :                 else if( 'd' == aFirstChar )
     247                 :            :                 { // name of data set file
     248         [ +  - ]:         16 :                     aDataBaseFile = aName;
     249                 :            :                 }
     250         [ +  - ]:         64 :                 else if( 'D' == aFirstChar )
     251                 :            :                 {
     252                 :            :                 }
     253         [ +  - ]:         64 :                 else if( 'C' == aFirstChar )
     254                 :            :                 {
     255                 :            :                 }
     256         [ +  - ]:         64 :                 else if( 'H' == aFirstChar )
     257                 :            :                 {
     258                 :            :                 }
     259         [ +  - ]:         64 :                 else if( 'c' == aFirstChar )
     260                 :            :                 {
     261                 :            :                 }
     262         [ +  - ]:         64 :                 else if( 'h' == aFirstChar )
     263                 :            :                 {
     264                 :            :                 }
     265         [ +  - ]:         64 :                 else if( 't' == aFirstChar )
     266                 :            :                 {
     267                 :            :                 }
     268         [ +  + ]:         64 :                 else if( 'm' == aFirstChar )
     269                 :            :                 { // name of info file
     270         [ +  - ]:         16 :                     aTargetFile = aName;
     271                 :            :                 }
     272         [ +  - ]:         48 :                 else if( 'r' == aFirstChar )
     273                 :            :                 {
     274                 :            :                 }
     275         [ +  + ]:         48 :                 else if( 'z' == aFirstChar )
     276                 :            :                 { // name of HelpId file
     277         [ +  - ]:         16 :                     aHelpIdFile = aName;
     278                 :            :                 }
     279         [ -  + ]:         32 :                 else if( 'y' == aFirstChar )
     280                 :            :                 { // name of CSV file
     281         [ #  # ]:          0 :                     aCSVFile = aName;
     282                 :            :                 }
     283         [ +  + ]:         32 :                 else if( 'x' == aFirstChar )
     284                 :            :                 { // name of IDL file for the CSV file
     285         [ +  - ]:         16 :                     aExportFile = aName;
     286                 :            :                 }
     287         [ +  - ]:         16 :                 else if( 'M' == aFirstChar )
     288                 :            :                 {
     289         [ +  - ]:         16 :                     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         [ +  - ]:        112 :                 }
     299                 :            :             }
     300 [ +  - ][ +  - ]:        158 :             else if( aParam.EqualsIgnoreCaseAscii( "help" ) || aParam.EqualsIgnoreCaseAscii( "?" ) )
         [ +  - ][ -  + ]
                 [ -  + ]
     301                 :            :             { // help
     302         [ #  # ]:          0 :                 printf( "%s", CommandLineSyntax );
     303                 :            :             }
     304 [ +  - ][ +  + ]:        158 :             else if( aParam.EqualsIgnoreCaseAscii( "quiet" ) )
     305                 :            :             {
     306                 :         16 :                 nVerbosity = 0;
     307                 :            :             }
     308 [ +  - ][ -  + ]:        142 :             else if( aParam.EqualsIgnoreCaseAscii( "verbose" ) )
     309                 :            :             {
     310                 :          0 :                 nVerbosity = 2;
     311                 :            :             }
     312 [ +  - ][ -  + ]:        142 :             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 [ +  - ][ +  - ]:        142 :             else if( aParam.EqualsIgnoreCaseAscii( "i", 0, 1 ) )
     319                 :            :             { // define include paths
     320         [ +  - ]:        142 :                 String aName( aParam.Copy( 1 ) );
     321         [ +  + ]:        142 :                 if( aPath.Len() )
     322 [ +  - ][ +  - ]:        126 :                     aPath += DirEntry::GetSearchDelimiter();
                 [ +  - ]
     323 [ +  - ][ +  - ]:        142 :                 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                 :        270 :                 exit( -1 );
     341                 :            :             }
     342                 :            :         }
     343                 :            :         else
     344                 :            :         {
     345 [ +  - ][ +  - ]:         16 :             aInFileList.push_back( new String( aParam ) );
                 [ +  - ]
     346                 :            :         }
     347         [ +  - ]:        286 :     }
     348                 :            :     else
     349                 :            :     {
     350         [ #  # ]:          0 :         printf( "%s", CommandLineSyntax );
     351                 :            :     }
     352                 :            : 
     353         [ +  + ]:        318 :     for ( size_t i = 0, n = aList.size(); i < n; ++i )
     354 [ +  - ][ +  - ]:        302 :         delete aList[ i ];
                 [ +  - ]
     355                 :         16 :     aList.clear();
     356                 :            : 
     357                 :         16 :     rtl::OString aInc(getenv("INCLUDE"));
     358                 :            :     // append include environment variable
     359         [ -  + ]:         16 :     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                 :         16 :     }
     365                 :         16 : }
     366                 :            : 
     367 [ +  - ][ +  - ]:         16 : SvCommand::~SvCommand()
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     368                 :            : {
     369                 :            :     // release String list
     370         [ +  + ]:         32 :     for ( size_t i = 0, n = aInFileList.size(); i < n; ++i )
     371 [ +  - ][ +  - ]:         16 :         delete aInFileList[ i ];
                 [ +  - ]
     372                 :         16 :     aInFileList.clear();
     373                 :         16 : }
     374                 :            : 
     375                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10