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

Generated by: LCOV version 1.11