Update ooo320-m1
[ooovba.git] / rsc / source / parser / erscerr.cxx
blob0dc33e980bfcd64e3ea042abf5da78e2cc3a467a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: erscerr.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 #include <stdlib.h>
34 #include <stdio.h>
36 #include <tools/rcid.h>
37 #include <rschash.hxx>
38 #include <rscerror.h>
39 #include <rscall.h>
40 #include <rscdb.hxx>
41 #include <rscpar.hxx>
43 #include "rsclex.hxx"
45 /*************************************************************************
47 |* ERRTYPE::operator = ;
49 |* Beschreibung
50 |* Ersterstellung MM 25.09.91
51 |* Letzte Aenderung MM 25.09.91
53 *************************************************************************/
54 ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError )
56 if( !IsError() ){
57 if( rError.IsError() || !IsWarning() )
58 nError = rError.nError;
60 return *this;
63 /*************************************************************************
65 |* RscError::StdOut();
67 |* Beschreibung
68 |* Ersterstellung MM 06.05.91
69 |* Letzte Aenderung MM 06.05.91
71 *************************************************************************/
72 void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel )
74 if ( m_verbosity >= _verbosityLevel )
76 if( pStr ){
77 printf( "%s", pStr );
78 fflush( stdout );
83 /*************************************************************************
85 |* RscError::StdErr();
87 |* Beschreibung
88 |* Ersterstellung PL 11/07/2001
89 |* Letzte Aenderung PL 11/07/2001
91 *************************************************************************/
92 void RscError::StdErr( const char * pStr )
94 #ifndef WIN
95 if( pStr )
96 fprintf( stderr, "%s", pStr );
97 #endif
100 /*************************************************************************
102 |* RscError::LstOut();
104 |* Beschreibung
105 |* Ersterstellung MM 06.05.91
106 |* Letzte Aenderung MM 06.05.91
108 *************************************************************************/
109 void RscError::LstOut( const char * pStr ){
110 if( fListing && pStr )
111 fprintf( fListing, "%s", pStr );
114 /*************************************************************************
116 |* RscError::StdLstOut();
118 |* Beschreibung
119 |* Ersterstellung MM 06.05.91
120 |* Letzte Aenderung MM 06.05.91
122 *************************************************************************/
123 void RscError::StdLstOut( const char * pStr ){
124 StdOut( pStr );
125 LstOut( pStr );
128 /*************************************************************************
130 |* RscError::StdLstErr();
132 |* Beschreibung
133 |* Ersterstellung PL 11/07/2001
134 |* Letzte Aenderung PL 11/07/2001
136 *************************************************************************/
137 void RscError::StdLstErr( const char * pStr ){
138 StdErr( pStr );
139 LstOut( pStr );
142 /*************************************************************************
144 |* RscError::WriteError();
146 |* Beschreibung
147 |* Ersterstellung MM 06.05.91
148 |* Letzte Aenderung MM 06.05.91
150 *************************************************************************/
151 void RscError::WriteError( const ERRTYPE& rError, const char * pMessage )
153 switch( rError )
155 case ERR_ERROR: {
156 StdLstErr( "!! " );
157 if( 1 == nErrors )
158 StdLstErr( ByteString::CreateFromInt32( nErrors ).GetBuffer() );
159 else
160 StdLstErr( ByteString::CreateFromInt32( (nErrors -1) ).GetBuffer() );
161 StdLstErr( " Error" );
162 StdLstErr( " found!!" );
164 break;
166 case ERR_UNKNOWN_METHOD:
167 StdLstErr( "The used type is not allowed." );
168 break;
170 case ERR_OPENFILE:
171 StdLstErr( "This file <" );
172 StdLstErr( pMessage );
173 StdLstErr( "> cannot be opened." );
174 break;
176 case ERR_RENAMEFILE:
177 StdLstErr( "rename <" );
178 StdLstErr( pMessage );
179 StdLstErr( "> s not possible." );
180 break;
182 case ERR_FILESIZE:
183 StdLstErr( "Wrong file <" );
184 StdLstErr( pMessage );
185 StdLstErr( "> length." );
186 break;
188 case ERR_FILEFORMAT:
189 StdLstErr( "Wrong file type <" );
190 StdLstErr( pMessage );
191 StdLstErr( ">." );
192 break;
194 case ERR_NOCHAR:
195 StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255.");
196 break;
198 case ERR_NORSCINST:
199 StdLstErr( "Internal error, instance invalid.");
200 break;
203 case ERR_NOINPUT:
204 StdLstErr( "Input file was not specified.\n");
205 case ERR_USAGE:
206 StdLstOut( "Copyright (C) 1990-92 STAR DIVISION GmbH\n" );
208 char buf[40];
210 StdLstOut( "DataVersion: " );
211 sprintf( buf, "%d.%d\n\n",
212 RSCVERSION_ID / 100, RSCVERSION_ID % 100 );
213 StdLstOut( buf );
216 StdLstOut( "Command line: rsc [Switches] <Source File(s)>\n" );
217 StdLstOut( "Command line: rsc @<Command File>\n" );
218 StdLstOut( "-h shows this help.\n" );
219 StdLstOut( "-p No Preprocessor.\n" );
220 StdLstOut( "-s Syntax analysis, creates .srs file\n");
221 StdLstOut( "-l Linker, links files created with rsc -s,\n" );
222 StdLstOut( " creates .rc file and .res file.\n" );
223 StdLstOut( "-r Prevents .res file.\n" );
224 StdLstOut( "-d Symbol definitions for the Preprocessor.\n" );
225 StdLstOut( "-i Include directives for the Preprocessor.\n" );
226 StdLstOut( "-presponse Use response file for Preprocessor.\n" );
227 StdLstOut( "-lg<language> Use a different language.\n" );
228 StdLstOut( "-pp=<filename> Use a different Preprocessor.\n" );
229 StdLstOut( "-rsc2=<filename> Specify the location for rsc2.\n" );
230 StdLstOut( "No longer existent: -rc<filename> Use a different system resource compiler.\n" );
231 StdLstOut( "-fs=<filename> Name of the .res file.\n" );
232 StdLstOut( "-lip=<path> additional search path for system dependant files\n" );
233 StdLstOut( "-fp=<filename> Renaming of the .srs file.\n" );
234 StdLstOut( "-fl=<filename> Listing file.\n" );
235 StdLstOut( "-fh=<filename> Header file.\n" );
236 StdLstOut( "-fc=<filename> Code file.\n" );
237 StdLstOut( "-ft=<filename> Touch a file when done in rsc2 (for dependencies)\n" );
238 StdLstOut( "-fr=<filename> Ressource constructor .cxx-file.\n" );
239 StdLstOut( "-fx=<filename> Name of .src-file.\n" );
240 StdLstOut( "-oil=<dir> Output directory for image list files\n" );
241 StdLstOut( "-r<ENV>=<path> replace <path> by <ENV> in image list files\n" );
242 StdLstOut( "-CHARSET_... Convert to this character set.\n" );
243 StdLstOut( "-BIGENDIAN Format of number values.\n" );
244 StdLstOut( "-LITTLEENDIAN Format of number values.\n" );
245 StdLstOut( "-SMART Generate smart names (cxx, hxx).\n" );
246 StdLstOut( "-SrsDefault Only write one language to srs file.\n" );
247 StdLstOut( "\nwhen creating multiple .res files in one pass, please give these\n" );
248 StdLstOut( "options in consecutive blocks:\n" );
249 StdLstOut( "-lg<language> -fs<filename> [-lip<path> [-lip<path>] ]\n" );
250 StdLstOut( "a new block begins when either -lg or -fs is used again.\n" );
251 break;
253 case ERR_UNKNOWNSW:
254 StdLstErr( "Unknown switch <" );
255 StdLstErr( pMessage );
256 StdLstErr( ">." );
257 break;
259 case ERR_REFTODEEP:
260 StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." );
261 break;
263 case ERR_CONT_INVALIDPOS:
264 StdLstErr( "Internal error, Container class: invalid position." );
265 break;
267 case ERR_CONT_INVALIDTYPE:
268 StdLstErr( "Invalid type <" );
269 StdLstErr( pMessage );
270 StdLstErr( ">." );
271 break;
273 case ERR_ARRAY_INVALIDINDEX:
274 StdLstErr( "Internal error, Array class: invalid index." );
275 break;
277 case ERR_RSCINST_NOVARNAME:
278 StdLstErr( "Internal error, invalid name of variable." );
279 break;
281 case ERR_YACC:
282 StdLstErr( pMessage );
283 break;
285 case ERR_DOUBLEID:
286 StdLstErr( "Two global resources have the same identifier." );
287 break;
289 case ERR_FALSETYPE:
290 StdLstErr( "Wrong type <" );
291 StdLstErr( pMessage );
292 StdLstErr( ">." );
293 break;
295 case ERR_NOVARIABLENAME:
296 StdLstErr( "The variable <" );
297 StdLstErr( pMessage );
298 StdLstErr( "> must not be used here." );
299 break;
301 case ERR_RSCRANGE_OUTDEFSET:
302 StdLstErr( "The used value is not in the expected domain." );
303 break;
305 case ERR_USHORTRANGE:
306 StdLstErr( "Value is <" );
307 StdLstErr( pMessage );
308 StdLstErr( "> the allowed domain is from 0 up to 65535." );
309 break;
311 case ERR_IDRANGE:
312 StdLstErr( "Value is <" );
313 StdLstErr( pMessage );
314 StdLstErr( "> the allowed domain is from 1 up to 32767." );
315 break;
317 case ERR_NOCOPYOBJ:
318 StdLstErr( "Default resource <" );
319 StdLstErr( pMessage );
320 StdLstErr( "> not found." );
321 break;
323 case ERR_REFNOTALLOWED:
324 StdLstErr( "The use of a reference is not allowed." );
325 break;
327 case ERR_COPYNOTALLOWED:
328 StdLstErr( "The use of a default resource is not allowed." );
329 break;
331 case ERR_IDEXPECTED:
332 StdLstErr( "An identifier needs to be specified." );
333 break;
335 case ERR_DOUBLEDEFINE:
336 StdLstErr( "The symbol <" );
337 StdLstErr( pMessage );
338 StdLstErr( "> is defined twice." );
339 break;
341 case ERR_RSCINST_RESERVEDNAME:
342 StdLstErr( "The symbol <" );
343 StdLstErr( pMessage );
344 StdLstErr( "> is a reserved name." );
345 break;
347 case ERR_ZERODIVISION:
348 StdLstErr( "Attempt to divide by zero." );
349 break;
351 case ERR_PRAGMA:
352 StdLstErr( "Error in a #pragma statement." );
353 break;
355 case ERR_DECLAREDEFINE:
356 StdLstErr( "Error in the declaration part of the macro." );
357 break;
359 case ERR_NOTYPE:
360 StdLstErr( "type expected." );
361 break;
363 case ERR_NOIMAGE:
364 StdLstErr( "The image(s) <" );
365 StdLstErr( pMessage );
366 StdLstErr( "> could not be found." );
367 break;
369 /****************** W A R N I N G S **************************************/
370 case WRN_LOCALID:
371 StdLstErr( "Sub resources should have an identifier < 256." );
372 break;
374 case WRN_GLOBALID:
375 StdLstErr( "Global resources should have an identifier >= 256." );
376 break;
378 case WRN_SUBINMEMBER:
379 StdLstErr( "Sub resources are ignored." );
380 break;
382 case WRN_CONT_NOID:
383 StdLstErr( "Resources without name are ignored." );
384 break;
386 case WRN_CONT_DOUBLEID:
387 StdLstErr( "Two local resources have the same identifier." );
388 break;
390 case WRN_STR_REFNOTFOUND:
391 StdLstErr( "String reference <" );
392 StdLstErr( pMessage );
393 StdLstErr( " > could not be resolved." );
394 break;
396 case WRN_MGR_REFNOTFOUND:
397 StdLstErr( "Reference <" );
398 StdLstErr( pMessage );
399 StdLstErr( " > could not be resolved." );
400 break;
402 default:
403 if( pMessage ){
404 StdLstErr( "\nMessage: " );
405 StdLstErr( pMessage );
407 break;
411 /*************************************************************************
413 |* RscErrorFormat()
415 |* Beschreibung
416 |* Ersterstellung MM 06.05.91
417 |* Letzte Aenderung MM 06.05.91
419 *************************************************************************/
420 void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass,
421 const RscId & aId ){
422 char buf[ 10 ];
423 sal_uInt32 i;
425 if( pFI )
427 pFI->SetError( rError );
428 StdErr( "\n" );
429 StdErr( pFI->GetLine() );
430 StdErr( "\n" );
431 // Fehlerposition anzeigen
432 for( i = 0; (i +1) < pFI->GetScanPos(); i++ )
433 StdLstErr( " " );
434 LstOut( " ^" ); //Zeilennummern beachten
435 StdErr( "^" );
436 StdLstErr( "\n" );
438 StdLstErr( "f" );
439 sprintf( buf, "%u", (unsigned int)rError );
440 StdLstErr( buf );
442 if( pFI && pTC ){
443 StdLstErr( ": \"" );
444 StdLstErr( pTC->aFileTab.Get( pFI->GetFileIndex() )->aFileName.GetBuffer() );
445 StdLstErr( "\", line " );
446 sprintf( buf, "%u", (unsigned int)pFI->GetLineNo() );
447 StdLstErr( buf );
450 if( rError.IsError() )
451 StdLstErr( ": Error" );
452 else
453 StdLstErr( ": Warning" );
455 if( pClass || aId.IsId() )
457 StdLstErr( " in the object (" );
458 if( pClass )
460 StdLstErr( "Type: " );
461 StdLstErr( pHS->getString( pClass->GetId() ).getStr() );
462 if( aId.IsId() )
463 StdLstErr( ", " );
465 if( aId.IsId() )
466 StdLstErr( aId.GetName().GetBuffer() );
467 StdLstErr( "):\n" );
469 else
470 StdLstErr( ": " );
473 /*************************************************************************
475 |* RscError::Error()
477 |* Beschreibung
478 |* Ersterstellung MM 06.05.91
479 |* Letzte Aenderung MM 06.05.91
481 *************************************************************************/
482 void RscError::Error( const ERRTYPE& rError, RscTop * pClass,
483 const RscId & aId, const char * pMessage )
485 if( WRN_LOCALID == rError ) // Keine Warning erzeugen
486 return;
487 if( rError.IsError() )
488 nErrors++;
489 if( rError.IsError() || rError.IsWarning() ){
490 ErrorFormat( rError, pClass, aId );
491 WriteError( rError, pMessage );
492 StdLstErr( "\n" );
496 /*************************************************************************
498 |* RscError::FatalError();
500 |* Beschreibung
501 |* Ersterstellung MM 06.05.91
502 |* Letzte Aenderung MM 06.05.91
504 *************************************************************************/
505 void RscError::FatalError( const ERRTYPE& rError, const RscId &aId,
506 const char * pMessage )
508 if( ERR_USAGE != rError ){
509 nErrors++;
510 ErrorFormat( rError, NULL, aId );
511 WriteError( rError, pMessage );
512 StdLstErr( "\nTerminating compiler\n" );
514 else
515 WriteError( rError, pMessage );
517 exit( 1 );