1 /* E R R O R A N D D I A G N O S T I C R O U T I N E S */
3 /* This file contains the (non-portable) error-message and diagnostic
4 giving functions. Be aware that they are called with a variable
40 extern char *symbol2str();
42 /* There are three general error-message functions:
43 lexerror() lexical and pre-processor error messages
44 error() syntactic and pre-processor messagese
45 node_error() errors in nodes
46 The difference lies in the place where the file name and line
48 Lexical errors report from the global variables LineNumber and
49 FileName, node errors get their information from the
50 node, whereas other errors use the information in the token.
62 _error(VDEBUG, NULLNODE, fmt, ap);
75 _error(ERROR, NULLNODE, fmt, ap);
81 node_error(struct node *node, char *fmt, ...)
87 _error(ERROR, node, fmt, ap);
93 warning(char *fmt, ...)
99 _error(WARNING, NULLNODE, fmt, ap);
105 node_warning(struct node *node, char *fmt, ...)
111 _error(WARNING, node, fmt, ap);
117 lexerror(char *fmt, ...)
123 _error(LEXERROR, NULLNODE, fmt, ap);
129 lexwarning(char *fmt, ...)
135 _error(LEXWARNING, NULLNODE, fmt, ap);
141 fatal(char *fmt, ...)
147 _error(FATAL, NULLNODE, fmt, ap);
154 crash(char *fmt, ...)
160 _error(CRASH, NULLNODE, fmt, ap);
179 char *fmt = va_arg(ap, char *);
180 _error(VDEBUG, NULLNODE, fmt, ap);
194 char *fmt = va_arg(ap, char *);
195 _error(ERROR, NULLNODE, fmt, ap);
208 struct node *node = va_arg(ap, struct node *);
209 char *fmt = va_arg(ap, char *);
210 _error(ERROR, node, fmt, ap);
223 char *fmt = va_arg(ap, char *);
224 _error(WARNING, NULLNODE, fmt, ap);
230 node_warning(va_alist)
237 char *fmt = va_arg(ap, char *);
238 struct node *node = va_arg(ap, struct node *);
239 _error(WARNING, node, fmt, ap);
252 char *fmt = va_arg(ap, char *);
253 _error(LEXERROR, NULLNODE, fmt, ap);
266 char *fmt = va_arg(ap, char *);
267 _error(LEXWARNING, NULLNODE, fmt, ap);
280 char *fmt = va_arg(ap, char *);
281 _error(FATAL, NULLNODE, fmt, ap);
295 char *fmt = va_arg(ap, char *);
296 _error(CRASH, NULLNODE, fmt, ap);
307 _error(class, node, fmt, ap)
313 /* _error attempts to limit the number of error messages
314 for a given line to MAXERR_LINE.
316 static unsigned int last_ln = 0;
318 static char * last_fn = 0;
319 static int e_seen = 0, w_seen = 0;
320 register char *remark = 0;
322 /* Since name and number are gathered from different places
323 depending on the class, we first collect the relevant
324 values and then decide what to print.
332 if( C_busy() ) C_ms_err();
341 if (options['w']) return;
342 remark = "(warning)";
345 remark = "CRASH\007";
348 remark = "fatal error --";
361 ln = node ? node->nd_lineno : dot.tk_lineno;
375 if( class != VDEBUG ) {
377 if( FileName == last_fn && ln == last_ln ) {
378 /* we've seen this place before */
379 if( class != WARNING && class != LEXWARNING ) {
381 if( e_seen == MAXERR_LINE ) fmt = "etc ...";
382 else if( e_seen > MAXERR_LINE )
383 /* and too often, I'd say ! */
388 if( w_seen == MAXERR_LINE ) fmt = "etc ...";
389 else if( w_seen > MAXERR_LINE )
394 /* brand new place */
403 if( FileName ) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln);
405 if( remark ) fprint(ERROUT, "%s ", remark);
407 doprnt(ERROUT, fmt, ap); /* contents of error */
408 fprint(ERROUT, "\n");