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