CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / rsc / source / parser / erscerr.cxx
blobed63510737aa3302099dcff01c7891ec2bd646c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 #include <stdlib.h>
31 #include <stdio.h>
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>
40 #include "rsclex.hxx"
42 /*************************************************************************
44 |* ERRTYPE::operator = ;
46 |* Beschreibung
47 |* Ersterstellung MM 25.09.91
48 |* Letzte Aenderung MM 25.09.91
50 *************************************************************************/
51 ERRTYPE& ERRTYPE::operator = ( const ERRTYPE & rError )
53 if( !IsError() ){
54 if( rError.IsError() || !IsWarning() )
55 nError = rError.nError;
57 return *this;
60 /*************************************************************************
62 |* RscError::StdOut();
64 |* Beschreibung
65 |* Ersterstellung MM 06.05.91
66 |* Letzte Aenderung MM 06.05.91
68 *************************************************************************/
69 void RscError::StdOut( const char * pStr, const RscVerbosity _verbosityLevel )
71 if ( m_verbosity >= _verbosityLevel )
73 if( pStr ){
74 printf( "%s", pStr );
75 fflush( stdout );
80 /*************************************************************************
82 |* RscError::StdErr();
84 |* Beschreibung
85 |* Ersterstellung PL 11/07/2001
86 |* Letzte Aenderung PL 11/07/2001
88 *************************************************************************/
89 void RscError::StdErr( const char * pStr )
91 if( pStr )
92 fprintf( stderr, "%s", pStr );
95 /*************************************************************************
97 |* RscError::LstOut();
99 |* Beschreibung
100 |* Ersterstellung MM 06.05.91
101 |* Letzte Aenderung MM 06.05.91
103 *************************************************************************/
104 void RscError::LstOut( const char * pStr ){
105 if( fListing && pStr )
106 fprintf( fListing, "%s", pStr );
109 /*************************************************************************
111 |* RscError::StdLstOut();
113 |* Beschreibung
114 |* Ersterstellung MM 06.05.91
115 |* Letzte Aenderung MM 06.05.91
117 *************************************************************************/
118 void RscError::StdLstOut( const char * pStr ){
119 StdOut( pStr );
120 LstOut( pStr );
123 /*************************************************************************
125 |* RscError::StdLstErr();
127 |* Beschreibung
128 |* Ersterstellung PL 11/07/2001
129 |* Letzte Aenderung PL 11/07/2001
131 *************************************************************************/
132 void RscError::StdLstErr( const char * pStr ){
133 StdErr( pStr );
134 LstOut( pStr );
137 /*************************************************************************
139 |* RscError::WriteError();
141 |* Beschreibung
142 |* Ersterstellung MM 06.05.91
143 |* Letzte Aenderung MM 06.05.91
145 *************************************************************************/
146 void RscError::WriteError( const ERRTYPE& rError, const char * pMessage )
148 switch( rError )
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!!" );
159 break;
161 case ERR_UNKNOWN_METHOD:
162 StdLstErr( "The used type is not allowed." );
163 break;
165 case ERR_OPENFILE:
166 StdLstErr( "This file <" );
167 StdLstErr( pMessage );
168 StdLstErr( "> cannot be opened." );
169 break;
171 case ERR_RENAMEFILE:
172 StdLstErr( "rename <" );
173 StdLstErr( pMessage );
174 StdLstErr( "> s not possible." );
175 break;
177 case ERR_FILESIZE:
178 StdLstErr( "Wrong file <" );
179 StdLstErr( pMessage );
180 StdLstErr( "> length." );
181 break;
183 case ERR_FILEFORMAT:
184 StdLstErr( "Wrong file type <" );
185 StdLstErr( pMessage );
186 StdLstErr( ">." );
187 break;
189 case ERR_NOCHAR:
190 StdLstErr( "Character: '\\xxx'; The value xxx is greater than 255.");
191 break;
193 case ERR_NORSCINST:
194 StdLstErr( "Internal error, instance invalid.");
195 break;
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" );
203 char buf[40];
205 StdLstOut( "DataVersion: " );
206 sprintf( buf, "%d.%d\n\n",
207 RSCVERSION_ID / 100, RSCVERSION_ID % 100 );
208 StdLstOut( buf );
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;
248 case ERR_UNKNOWNSW:
249 StdLstErr( "Unknown switch <" );
250 StdLstErr( pMessage );
251 StdLstErr( ">." );
252 break;
254 case ERR_REFTODEEP:
255 StdLstErr( "Too many reference levels have been used (see Switch -RefDeep)." );
256 break;
258 case ERR_CONT_INVALIDPOS:
259 StdLstErr( "Internal error, Container class: invalid position." );
260 break;
262 case ERR_CONT_INVALIDTYPE:
263 StdLstErr( "Invalid type <" );
264 StdLstErr( pMessage );
265 StdLstErr( ">." );
266 break;
268 case ERR_ARRAY_INVALIDINDEX:
269 StdLstErr( "Internal error, Array class: invalid index." );
270 break;
272 case ERR_RSCINST_NOVARNAME:
273 StdLstErr( "Internal error, invalid name of variable." );
274 break;
276 case ERR_YACC:
277 StdLstErr( pMessage );
278 break;
280 case ERR_DOUBLEID:
281 StdLstErr( "Two global resources have the same identifier." );
282 break;
284 case ERR_FALSETYPE:
285 StdLstErr( "Wrong type <" );
286 StdLstErr( pMessage );
287 StdLstErr( ">." );
288 break;
290 case ERR_NOVARIABLENAME:
291 StdLstErr( "The variable <" );
292 StdLstErr( pMessage );
293 StdLstErr( "> must not be used here." );
294 break;
296 case ERR_RSCRANGE_OUTDEFSET:
297 StdLstErr( "The used value is not in the expected domain." );
298 break;
300 case ERR_USHORTRANGE:
301 StdLstErr( "Value is <" );
302 StdLstErr( pMessage );
303 StdLstErr( "> the allowed domain is from 0 up to 65535." );
304 break;
306 case ERR_IDRANGE:
307 StdLstErr( "Value is <" );
308 StdLstErr( pMessage );
309 StdLstErr( "> the allowed domain is from 1 up to 32767." );
310 break;
312 case ERR_NOCOPYOBJ:
313 StdLstErr( "Default resource <" );
314 StdLstErr( pMessage );
315 StdLstErr( "> not found." );
316 break;
318 case ERR_REFNOTALLOWED:
319 StdLstErr( "The use of a reference is not allowed." );
320 break;
322 case ERR_COPYNOTALLOWED:
323 StdLstErr( "The use of a default resource is not allowed." );
324 break;
326 case ERR_IDEXPECTED:
327 StdLstErr( "An identifier needs to be specified." );
328 break;
330 case ERR_DOUBLEDEFINE:
331 StdLstErr( "The symbol <" );
332 StdLstErr( pMessage );
333 StdLstErr( "> is defined twice." );
334 break;
336 case ERR_RSCINST_RESERVEDNAME:
337 StdLstErr( "The symbol <" );
338 StdLstErr( pMessage );
339 StdLstErr( "> is a reserved name." );
340 break;
342 case ERR_ZERODIVISION:
343 StdLstErr( "Attempt to divide by zero." );
344 break;
346 case ERR_PRAGMA:
347 StdLstErr( "Error in a #pragma statement." );
348 break;
350 case ERR_DECLAREDEFINE:
351 StdLstErr( "Error in the declaration part of the macro." );
352 break;
354 case ERR_NOTYPE:
355 StdLstErr( "type expected." );
356 break;
358 case ERR_NOIMAGE:
359 StdLstErr( "The image(s) <" );
360 StdLstErr( pMessage );
361 StdLstErr( "> could not be found." );
362 break;
364 /****************** W A R N I N G S **************************************/
365 case WRN_LOCALID:
366 StdLstErr( "Sub resources should have an identifier < 256." );
367 break;
369 case WRN_GLOBALID:
370 StdLstErr( "Global resources should have an identifier >= 256." );
371 break;
373 case WRN_SUBINMEMBER:
374 StdLstErr( "Sub resources are ignored." );
375 break;
377 case WRN_CONT_NOID:
378 StdLstErr( "Resources without name are ignored." );
379 break;
381 case WRN_CONT_DOUBLEID:
382 StdLstErr( "Two local resources have the same identifier." );
383 break;
385 case WRN_STR_REFNOTFOUND:
386 StdLstErr( "String reference <" );
387 StdLstErr( pMessage );
388 StdLstErr( " > could not be resolved." );
389 break;
391 case WRN_MGR_REFNOTFOUND:
392 StdLstErr( "Reference <" );
393 StdLstErr( pMessage );
394 StdLstErr( " > could not be resolved." );
395 break;
397 default:
398 if( pMessage ){
399 StdLstErr( "\nMessage: " );
400 StdLstErr( pMessage );
402 break;
406 /*************************************************************************
408 |* RscErrorFormat()
410 |* Beschreibung
411 |* Ersterstellung MM 06.05.91
412 |* Letzte Aenderung MM 06.05.91
414 *************************************************************************/
415 void RscError::ErrorFormat( const ERRTYPE& rError, RscTop * pClass,
416 const RscId & aId ){
417 char buf[ 10 ];
418 sal_uInt32 i;
420 if( pFI )
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" );
433 StdLstErr( "f" );
434 sprintf( buf, "%u", (unsigned int)rError );
435 StdLstErr( buf );
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 );
445 if( rError.IsError() )
446 StdLstErr( ": Error" );
447 else
448 StdLstErr( ": Warning" );
450 if( pClass || aId.IsId() )
452 StdLstErr( " in the object (" );
453 if( pClass )
455 StdLstErr( "Type: " );
456 StdLstErr( pHS->getString( pClass->GetId() ).getStr() );
457 if( aId.IsId() )
458 StdLstErr( ", " );
460 if( aId.IsId() )
461 StdLstErr( aId.GetName().GetBuffer() );
462 StdLstErr( "):\n" );
464 else
465 StdLstErr( ": " );
468 /*************************************************************************
470 |* RscError::Error()
472 |* Beschreibung
473 |* Ersterstellung MM 06.05.91
474 |* Letzte Aenderung MM 06.05.91
476 *************************************************************************/
477 void RscError::Error( const ERRTYPE& rError, RscTop * pClass,
478 const RscId & aId, const char * pMessage )
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" );
491 /*************************************************************************
493 |* RscError::FatalError();
495 |* Beschreibung
496 |* Ersterstellung MM 06.05.91
497 |* Letzte Aenderung MM 06.05.91
499 *************************************************************************/
500 void RscError::FatalError( const ERRTYPE& rError, const RscId &aId,
501 const char * pMessage )
503 if( ERR_USAGE != rError ){
504 nErrors++;
505 ErrorFormat( rError, NULL, aId );
506 WriteError( rError, pMessage );
507 StdLstErr( "\nTerminating compiler\n" );
509 else
510 WriteError( rError, pMessage );
512 exit( 1 );