LCOV - code coverage report
Current view: top level - libreoffice/rsc/source/parser - erscerr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 242 5.4 %
Date: 2012-12-27 Functions: 3 10 30.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 <stdlib.h>
      21             : #include <stdio.h>
      22             : 
      23             : #include <tools/rcid.h>
      24             : #include <rschash.hxx>
      25             : #include <rscerror.h>
      26             : #include <rscall.h>
      27             : #include <rscdb.hxx>
      28             : #include <rscpar.hxx>
      29             : 
      30             : #include "rsclex.hxx"
      31             : 
      32             : /*************************************************************************
      33             : |*
      34             : |*    ERRTYPE::operator = ;
      35             : |*
      36             : *************************************************************************/
      37     1150674 : ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError )
      38             : {
      39     1150674 :     if( !IsError() ){
      40     1150674 :         if( rError.IsError() || !IsWarning() )
      41     1150674 :             nError = rError.nError;
      42             :     }
      43     1150674 :     return *this;
      44             : }
      45             : 
      46             : /*************************************************************************
      47             : |*
      48             : |*    RscError::StdOut();
      49             : |*
      50             : *************************************************************************/
      51       23514 : void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel )
      52             : {
      53       23514 :     if ( m_verbosity >= _verbosityLevel )
      54             :     {
      55           0 :         if( pStr ){
      56           0 :             printf( "%s", pStr );
      57           0 :             fflush( stdout );
      58             :         }
      59             :     }
      60       23514 : }
      61             : 
      62             : /*************************************************************************
      63             : |*
      64             : |*    RscError::StdErr();
      65             : |*
      66             : *************************************************************************/
      67           0 : void RscError::StdErr( const char * pStr )
      68             : {
      69           0 :     if( pStr )
      70           0 :         fprintf( stderr, "%s", pStr );
      71           0 : }
      72             : 
      73             : /*************************************************************************
      74             : |*
      75             : |*    RscError::LstOut();
      76             : |*
      77             : *************************************************************************/
      78           0 : void RscError::LstOut( const char * pStr ){
      79           0 :     if( fListing && pStr )
      80           0 :         fprintf( fListing, "%s", pStr );
      81           0 : }
      82             : 
      83             : /*************************************************************************
      84             : |*
      85             : |*    RscError::StdLstOut();
      86             : |*
      87             : *************************************************************************/
      88           0 : void RscError::StdLstOut( const char * pStr ){
      89           0 :     StdOut( pStr );
      90           0 :     LstOut( pStr );
      91           0 : }
      92             : 
      93             : /*************************************************************************
      94             : |*
      95             : |*    RscError::StdLstErr();
      96             : |*
      97             : *************************************************************************/
      98           0 : void RscError::StdLstErr( const char * pStr ){
      99           0 :     StdErr( pStr );
     100           0 :     LstOut( pStr );
     101           0 : }
     102             : 
     103             : /*************************************************************************
     104             : |*
     105             : |*    RscError::WriteError();
     106             : |*
     107             : *************************************************************************/
     108           0 : void RscError::WriteError( const ERRTYPE& rError, const char * pMessage )
     109             : {
     110           0 :     switch( rError )
     111             :     {
     112             :         case ERR_ERROR: {
     113           0 :             StdLstErr( "!! " );
     114           0 :             if( 1 == nErrors )
     115           0 :                 StdLstErr(rtl::OString::valueOf(static_cast<sal_Int32>(nErrors )).getStr());
     116             :             else
     117           0 :                 StdLstErr(rtl::OString::valueOf(static_cast<sal_Int32>(nErrors -1)).getStr());
     118           0 :             StdLstErr( " Error" );
     119           0 :             StdLstErr( " found!!" );
     120             :         }
     121           0 :         break;
     122             : 
     123             :         case ERR_UNKNOWN_METHOD:
     124           0 :             StdLstErr( "The used type is not allowed." );
     125           0 :         break;
     126             : 
     127             :         case ERR_OPENFILE:
     128           0 :             StdLstErr( "This file <" );
     129           0 :             StdLstErr( pMessage );
     130           0 :             StdLstErr( "> cannot be opened." );
     131           0 :         break;
     132             : 
     133             :         case ERR_RENAMEFILE:
     134           0 :             StdLstErr( "rename <" );
     135           0 :             StdLstErr( pMessage );
     136           0 :             StdLstErr( "> s not possible." );
     137           0 :         break;
     138             : 
     139             :         case ERR_FILESIZE:
     140           0 :             StdLstErr( "Wrong file <" );
     141           0 :             StdLstErr( pMessage );
     142           0 :             StdLstErr( "> length." );
     143           0 :         break;
     144             : 
     145             :         case ERR_FILEFORMAT:
     146           0 :             StdLstErr( "Wrong file type <" );
     147           0 :             StdLstErr( pMessage );
     148           0 :             StdLstErr( ">." );
     149           0 :         break;
     150             : 
     151             :         case ERR_NOCHAR:
     152           0 :             StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255.");
     153           0 :             break;
     154             : 
     155             :         case ERR_NORSCINST:
     156           0 :             StdLstErr( "Internal error, instance invalid.");
     157           0 :             break;
     158             : 
     159             : 
     160             :         case ERR_NOINPUT:
     161           0 :             StdLstErr( "Input file was not specified.\n");
     162             :         case ERR_USAGE:
     163           0 :             StdLstOut( "Copyright (C) 2000 - 2012 LibreOffice contributors.\n" );
     164             :             {
     165             :                 char    buf[40];
     166             : 
     167           0 :                 StdLstOut( "DataVersion: " );
     168             :                 sprintf( buf, "%d.%d\n\n",
     169           0 :                          RSCVERSION_ID / 100, RSCVERSION_ID % 100 );
     170           0 :                 StdLstOut( buf );
     171             :             };
     172             : 
     173           0 :             StdLstOut( "Command line: rsc [Switches] <Source File(s)>\n" );
     174           0 :             StdLstOut( "Command line: rsc @<Command File>\n" );
     175           0 :             StdLstOut( "-h  shows this help.\n" );
     176           0 :             StdLstOut( "-p  No Preprocessor.\n" );
     177           0 :             StdLstOut( "-s  Syntax analysis, creates .srs file\n");
     178           0 :             StdLstOut( "-l  Linker, links files created with rsc -s,\n" );
     179           0 :             StdLstOut( "    creates .rc file and .res file.\n" );
     180           0 :             StdLstOut( "-r  Prevents .res file.\n" );
     181           0 :             StdLstOut( "-d  Symbol definitions for the Preprocessor.\n" );
     182           0 :             StdLstOut( "-i  Include directives for the Preprocessor.\n" );
     183           0 :             StdLstOut( "-presponse     Use response file for Preprocessor.\n" );
     184           0 :             StdLstOut( "-lg<language>  Use a different language.\n" );
     185           0 :             StdLstOut( "-pp=<filename> Use a different Preprocessor.\n" );
     186           0 :             StdLstOut( "-rsc2=<filename> Specify the location for rsc2.\n" );
     187           0 :             StdLstOut( "No longer existent: -rc<filename>  Use a different system resource compiler.\n" );
     188           0 :             StdLstOut( "-fs=<filename> Name of the .res file.\n" );
     189           0 :             StdLstOut( "-lip=<path>    additional search path for system dependant files\n" );
     190           0 :             StdLstOut( "-fp=<filename> Renaming of the .srs file.\n" );
     191           0 :             StdLstOut( "-fl=<filename> Listing file.\n" );
     192           0 :             StdLstOut( "-fh=<filename> Header file.\n" );
     193           0 :             StdLstOut( "-fc=<filename> Code file.\n" );
     194           0 :             StdLstOut( "-ft=<filename> Touch a file when done in rsc2 (for dependencies)\n" );
     195           0 :             StdLstOut( "-fr=<filename> Resource constructor .cxx-file.\n" );
     196           0 :             StdLstOut( "-fx=<filename> Name of .src-file.\n" );
     197           0 :             StdLstOut( "-oil=<dir>     Output directory for image list files\n" );
     198           0 :             StdLstOut( "-r<ENV>=<path> replace <path> by <ENV> in image list files\n" );
     199           0 :             StdLstOut( "-CHARSET_...  Convert to this character set.\n" );
     200           0 :             StdLstOut( "-BIGENDIAN    Format of number values.\n" );
     201           0 :             StdLstOut( "-LITTLEENDIAN Format of number values.\n" );
     202           0 :             StdLstOut( "-SMART        Generate smart names (cxx, hxx).\n" );
     203           0 :             StdLstOut( "-SrsDefault   Only write one language to srs file.\n" );
     204           0 :             StdLstOut( "\nwhen creating multiple .res files in one pass, please give these\n" );
     205           0 :             StdLstOut( "options in consecutive blocks:\n" );
     206           0 :             StdLstOut( "-lg<language> -fs<filename> [-lip<path> [-lip<path>] ]\n" );
     207           0 :             StdLstOut( "a new block begins when either -lg or -fs is used again.\n" );
     208           0 :             break;
     209             : 
     210             :         case ERR_UNKNOWNSW:
     211           0 :             StdLstErr( "Unknown switch <" );
     212           0 :             StdLstErr( pMessage );
     213           0 :             StdLstErr( ">." );
     214           0 :             break;
     215             : 
     216             :         case ERR_REFTODEEP:
     217           0 :             StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." );
     218           0 :             break;
     219             : 
     220             :         case ERR_CONT_INVALIDPOS:
     221           0 :             StdLstErr( "Internal error, Container class: invalid position." );
     222           0 :             break;
     223             : 
     224             :         case ERR_CONT_INVALIDTYPE:
     225           0 :             StdLstErr( "Invalid type <" );
     226           0 :             StdLstErr( pMessage );
     227           0 :             StdLstErr( ">." );
     228           0 :             break;
     229             : 
     230             :         case ERR_ARRAY_INVALIDINDEX:
     231           0 :             StdLstErr( "Internal error, Array class: invalid index." );
     232           0 :             break;
     233             : 
     234             :         case ERR_RSCINST_NOVARNAME:
     235           0 :             StdLstErr( "Internal error, invalid name of variable." );
     236           0 :             break;
     237             : 
     238             :         case ERR_YACC:
     239           0 :             StdLstErr( pMessage );
     240           0 :             break;
     241             : 
     242             :         case ERR_DOUBLEID:
     243           0 :             StdLstErr( "Two global resources have the same identifier." );
     244           0 :             break;
     245             : 
     246             :         case ERR_FALSETYPE:
     247           0 :             StdLstErr( "Wrong type <" );
     248           0 :             StdLstErr( pMessage );
     249           0 :             StdLstErr( ">." );
     250           0 :             break;
     251             : 
     252             :         case ERR_NOVARIABLENAME:
     253           0 :             StdLstErr( "The variable <" );
     254           0 :             StdLstErr( pMessage );
     255           0 :             StdLstErr( "> must not be used here." );
     256           0 :             break;
     257             : 
     258             :         case ERR_RSCRANGE_OUTDEFSET:
     259           0 :             StdLstErr( "The used value is not in the expected domain." );
     260           0 :             break;
     261             : 
     262             :         case ERR_USHORTRANGE:
     263           0 :             StdLstErr( "Value is <" );
     264           0 :             StdLstErr( pMessage );
     265           0 :             StdLstErr( "> the allowed domain is from 0 up to 65535." );
     266           0 :             break;
     267             : 
     268             :         case ERR_IDRANGE:
     269           0 :             StdLstErr( "Value is <" );
     270           0 :             StdLstErr( pMessage );
     271           0 :             StdLstErr( "> the allowed domain is from 1 up to 32767." );
     272           0 :             break;
     273             : 
     274             :         case ERR_NOCOPYOBJ:
     275           0 :             StdLstErr( "Default resource <" );
     276           0 :             StdLstErr( pMessage );
     277           0 :             StdLstErr( "> not found." );
     278           0 :             break;
     279             : 
     280             :         case ERR_REFNOTALLOWED:
     281           0 :             StdLstErr( "The use of a reference is not allowed." );
     282           0 :             break;
     283             : 
     284             :         case ERR_COPYNOTALLOWED:
     285           0 :             StdLstErr( "The use of a default resource is not allowed." );
     286           0 :             break;
     287             : 
     288             :         case ERR_IDEXPECTED:
     289           0 :             StdLstErr( "An identifier needs to be specified." );
     290           0 :             break;
     291             : 
     292             :         case ERR_DOUBLEDEFINE:
     293           0 :             StdLstErr( "The symbol <" );
     294           0 :             StdLstErr( pMessage );
     295           0 :             StdLstErr( "> is defined twice." );
     296           0 :             break;
     297             : 
     298             :         case ERR_RSCINST_RESERVEDNAME:
     299           0 :             StdLstErr( "The symbol <" );
     300           0 :             StdLstErr( pMessage );
     301           0 :             StdLstErr( "> is a reserved name." );
     302           0 :             break;
     303             : 
     304             :         case ERR_ZERODIVISION:
     305           0 :             StdLstErr( "Attempt to divide by zero." );
     306           0 :             break;
     307             : 
     308             :         case ERR_PRAGMA:
     309           0 :             StdLstErr( "Error in a #pragma statement." );
     310           0 :             break;
     311             : 
     312             :         case ERR_DECLAREDEFINE:
     313           0 :             StdLstErr( "Error in the declaration part of the macro." );
     314           0 :             break;
     315             : 
     316             :         case ERR_NOTYPE:
     317           0 :             StdLstErr( "type expected." );
     318           0 :             break;
     319             : 
     320             :         case ERR_NOIMAGE:
     321           0 :             StdLstErr( "The image(s) <" );
     322           0 :             StdLstErr( pMessage );
     323           0 :             StdLstErr( "> could not be found." );
     324           0 :             break;
     325             : 
     326             : /****************** W A R N I N G S **************************************/
     327             :         case WRN_LOCALID:
     328           0 :             StdLstErr( "Sub resources should have an identifier < 256." );
     329           0 :             break;
     330             : 
     331             :         case WRN_GLOBALID:
     332           0 :             StdLstErr( "Global resources should have an identifier >= 256." );
     333           0 :             break;
     334             : 
     335             :         case WRN_SUBINMEMBER:
     336           0 :             StdLstErr( "Sub resources are ignored." );
     337           0 :             break;
     338             : 
     339             :         case WRN_CONT_NOID:
     340           0 :             StdLstErr( "Resources without name are ignored." );
     341           0 :             break;
     342             : 
     343             :         case WRN_CONT_DOUBLEID:
     344           0 :             StdLstErr( "Two local resources have the same identifier." );
     345           0 :             break;
     346             : 
     347             :         case WRN_STR_REFNOTFOUND:
     348           0 :             StdLstErr( "String reference <" );
     349           0 :             StdLstErr( pMessage );
     350           0 :             StdLstErr( " > could not be resolved." );
     351           0 :             break;
     352             : 
     353             :         case WRN_MGR_REFNOTFOUND:
     354           0 :             StdLstErr( "Reference <" );
     355           0 :             StdLstErr( pMessage );
     356           0 :             StdLstErr( " > could not be resolved." );
     357           0 :             break;
     358             : 
     359             :         default:
     360           0 :             if( pMessage ){
     361           0 :                 StdLstErr( "\nMessage: " );
     362           0 :                 StdLstErr( pMessage );
     363             :             };
     364           0 :             break;
     365             :     }
     366           0 : }
     367             : 
     368             : /*************************************************************************
     369             : |*
     370             : |*    RscErrorFormat()
     371             : |*
     372             : *************************************************************************/
     373           0 : void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass,
     374             :                             const RscId & aId ){
     375             :     char buf[ 10 ];
     376             :     sal_uInt32 i;
     377             : 
     378           0 :     if( pFI )
     379             :     {
     380           0 :         pFI->SetError( rError );
     381           0 :         StdErr( "\n" );
     382           0 :         StdErr( pFI->GetLine() );
     383           0 :         StdErr( "\n" );
     384             :         // Fehlerposition anzeigen
     385           0 :         for( i = 0; (i +1) < pFI->GetScanPos(); i++ )
     386           0 :             StdLstErr( " " );
     387           0 :         LstOut( "     ^" ); //Zeilennummern beachten
     388           0 :         StdErr( "^" );
     389           0 :         StdLstErr( "\n" );
     390             :     }
     391           0 :     StdLstErr( "f" );
     392           0 :     sprintf( buf, "%u", (unsigned int)rError );
     393           0 :     StdLstErr( buf );
     394             : 
     395           0 :     if( pFI && pTC ){
     396           0 :         StdLstErr( ": \"" );
     397           0 :         StdLstErr( pTC->aFileTab.Get( pFI->GetFileIndex() )->aFileName.getStr() );
     398           0 :         StdLstErr( "\", line " );
     399           0 :         sprintf( buf, "%u", (unsigned int)pFI->GetLineNo() );
     400           0 :         StdLstErr( buf );
     401             :     }
     402             : 
     403           0 :     if( rError.IsError() )
     404           0 :         StdLstErr( ": Error" );
     405             :     else
     406           0 :         StdLstErr( ": Warning" );
     407             : 
     408           0 :     if( pClass || aId.IsId() )
     409             :     {
     410           0 :         StdLstErr( " in the object (" );
     411           0 :         if( pClass )
     412             :         {
     413           0 :             StdLstErr( "Type: " );
     414           0 :             StdLstErr( pHS->getString( pClass->GetId() ).getStr() );
     415           0 :             if( aId.IsId() )
     416           0 :                 StdLstErr( ", " );
     417             :         }
     418           0 :         if( aId.IsId() )
     419           0 :             StdLstErr( aId.GetName().getStr() );
     420           0 :         StdLstErr( "):\n" );
     421             :     }
     422             :     else
     423           0 :         StdLstErr( ": " );
     424           0 : }
     425             : 
     426             : /*************************************************************************
     427             : |*
     428             : |*    RscError::Error()
     429             : |*
     430             : *************************************************************************/
     431        3543 : void RscError::Error( const ERRTYPE& rError, RscTop * pClass,
     432             :                       const RscId & aId, const char * pMessage )
     433             : {
     434        3543 :     if( WRN_LOCALID == rError ) // Keine Warning erzeugen
     435        7077 :         return;
     436           9 :     if( rError.IsError() )
     437           0 :         nErrors++;
     438           9 :     if( rError.IsError() || rError.IsWarning() ){
     439           0 :         ErrorFormat( rError, pClass, aId );
     440           0 :         WriteError( rError, pMessage );
     441           0 :         StdLstErr( "\n" );
     442             :     };
     443             : }
     444             : 
     445             : /*************************************************************************
     446             : |*
     447             : |*    RscError::FatalError();
     448             : |*
     449             : *************************************************************************/
     450           0 : void RscError::FatalError( const ERRTYPE& rError, const RscId &aId,
     451             :                            const char * pMessage )
     452             : {
     453           0 :     if( ERR_USAGE != rError ){
     454           0 :         nErrors++;
     455           0 :         ErrorFormat( rError, NULL, aId );
     456           0 :         WriteError( rError, pMessage );
     457           0 :         StdLstErr( "\nTerminating compiler\n" );
     458             :     }
     459             :     else
     460           0 :         WriteError( rError, pMessage );
     461             : 
     462           0 :     exit( 1 );
     463             : }
     464             : 
     465             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10