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

Generated by: LCOV version 1.10