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

Generated by: LCOV version 1.10