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