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