/
errmsg.c
237 lines (206 loc) · 6.83 KB
/
errmsg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Diagnostics routines (errors/warnings/notes)
*
****************************************************************************/
#include <stdarg.h>
#include <ctype.h>
#include "globals.h"
#include "symbols.h"
#include "directiv.h"
#include "input.h"
#include "tokenize.h"
#include "symbols.h"
#include "queues.h"
#include "macro.h"
#include "fatal.h"
#include "msgtext.h"
#include "listing.h"
#include "segment.h"
extern char *MsgGet( int resourceid, char *buffer );
extern void print_source_nesting_structure( void );
extern char banner_printed;
// WngLvls[level] // warning levels associated with warning messages
// CompFlags.errout_redirected
/* globals to this module */
#define ErrLimit Options.error_limit
#define WngLevel Options.warning_level
//static bool Errfile_Written;
//static void PrtMsg( int severity, int msgnum, va_list args1, va_list args2 );
//void PutMsg( FILE *fp, int severity, int msgnum, va_list args );
void AsmError( int msgnum )
/*************************/
{
AsmErr( msgnum );
}
#ifdef DEBUG_OUT
void DoDebugMsg( const char *format, ... )
/****************************************/
{
va_list args;
if( !Options.debug ) return;
if( ModuleInfo.cref == FALSE ) return;
va_start( args, format );
vprintf( format, args );
va_end( args );
}
#endif
static void OpenErrFile( void )
/**********************/
{
// if( !isatty( fileno( errout ) ) ) return;
if( FileInfo.fname[ERR] != NULL ) {
FileInfo.file[ERR] = fopen( FileInfo.fname[ERR], "w" );
}
}
void PutMsg( FILE *fp, int severity, int msgnum, va_list args )
/********************************************************************/
{
int i,j;
char *type;
char msgbuf[MAXMSGSIZE];
char buffer[MAX_LINE_LEN];
if( fp != NULL ) {
MsgGet( msgnum, msgbuf );
switch (severity ) {
case 1: type = MsgGetEx( MSG_FATAL_PREFIX ); break;
case 2: type = MsgGetEx( MSG_ERROR_PREFIX ); break;
case 4: type = MsgGetEx( MSG_WARNING_PREFIX ); break;
default: type = NULL; i = 0; break;
}
if ( type )
i = sprintf( buffer, "%s A%4u: ", type, severity * 1000 + msgnum );
i += vsprintf( buffer+i, msgbuf, args );
//buffer[i] = NULLC;
if ( severity && (j = GetCurrSrcPos( msgbuf ))) {
fwrite( msgbuf, 1, j, fp );
} else
j = 0;
fwrite( buffer, 1, i, fp );
fwrite( "\n", 1, 1, fp );
/* if in Pass 1, add the error msg to the listing */
if ( FileInfo.file[LST] &&
severity &&
Parse_Pass == PASS_1 &&
fp == FileInfo.file[ERR] ) {
LstWrite( LSTTYPE_DIRECTIVE, GetCurrOffset(), 0 );
LstPrintf( " %s", buffer );
LstNL();
}
}
}
static void PrtMsg( int severity, int msgnum, va_list args1, va_list args2 )
/***************************************************************************/
{
if( !banner_printed )
trademark();
if( FileInfo.file[ERR] == NULL )
OpenErrFile();
PutMsg( errout, severity, msgnum, args1 );
fflush( errout ); /* 27-feb-90 */
if( FileInfo.file[ERR] ) {
//Errfile_Written = TRUE;
PutMsg( FileInfo.file[ERR], severity, msgnum, args2 );
}
}
/* notes: "included by", "macro called from", ... */
void PrintNote( int msgnum, ... )
/*****************************/
{
va_list args1, args2;
va_start( args1, msgnum );
va_start( args2, msgnum );
PrtMsg( 0, msgnum, args1, args2 );
va_end( args1 );
va_end( args2 );
}
void AsmErr( int msgnum, ... )
/****************************/
{
va_list args1, args2;
#ifdef DEBUG_OUT
DebugCurrLine();
#endif
va_start( args1, msgnum );
va_start( args2, msgnum );
PrtMsg( 2, msgnum, args1, args2 );
va_end( args1 );
va_end( args2 );
ModuleInfo.error_count++;
write_to_file = FALSE;
print_source_nesting_structure();
if( ErrLimit != -1 && ModuleInfo.error_count == ErrLimit+1 ) {
PrtMsg( 2, TOO_MANY_ERRORS, args1, args2 );
/* Just simulate the END directive, don't do a fatal exit!
This allows to continue to assemble further modules.
*/
ModuleInfo.EndDirectiveFound = TRUE;
}
}
void AsmWarn( int level, int msgnum, ... )
/****************************************/
{
va_list args1, args2;
if( level <= WngLevel ) {
#ifdef DEBUG_OUT
DebugCurrLine();
#endif
va_start( args1, msgnum );
va_start( args2, msgnum );
if( !Options.warning_error ) {
PrtMsg( 4, msgnum, args1, args2 );
ModuleInfo.warning_count++;
} else {
PrtMsg( 2, msgnum, args1, args2 );
ModuleInfo.error_count++;
}
va_end( args1 );
va_end( args2 );
print_source_nesting_structure();
}
}
void InitErrFile( void )
/*********************/
{
remove( FileInfo.fname[ERR] );
}
#ifndef NDEBUG
int InternalError( const char *file, unsigned line )
/**************************************************/
// it's used by myassert() function in debug version
{
char buffer[MAX_LINE_LEN];
DebugMsg(("InternalError enter\n"));
ModuleInfo.error_count++;
GetCurrSrcPos( buffer );
fprintf( errout, "%s", buffer );
fprintf( errout, MsgGetEx( INTERNAL_ERROR ), file, line );
close_files();
exit( EXIT_FAILURE );
return(0);
}
#endif