use varargs where needed

This commit is contained in:
ceriel 1988-04-15 15:19:27 +00:00
parent 32e125b3f9
commit 2549099d3b
2 changed files with 119 additions and 66 deletions

View file

@ -17,6 +17,8 @@
#include "errout.h" #include "errout.h"
#include "debug.h" #include "debug.h"
#include <varargs.h>
#include <system.h> #include <system.h>
#include <em_arith.h> #include <em_arith.h>
#include <em_label.h> #include <em_label.h>
@ -60,77 +62,111 @@ extern char *symbol2str();
#ifdef DEBUG #ifdef DEBUG
/*VARARGS1*/ /*VARARGS1*/
debug(fmt, args) debug(va_alist)
char *fmt; va_dcl
{ {
_error(VDEBUG, NULLNODE, fmt, &args); va_list ap;
va_start(ap);
_error(VDEBUG, NULLNODE, ap);
va_end(ap);
} }
#endif DEBUG #endif DEBUG
/*VARARGS1*/ /*VARARGS1*/
error(fmt, args) error(va_alist)
char *fmt; va_dcl
{ {
_error(ERROR, NULLNODE, fmt, &args); va_list ap;
va_start(ap);
_error(ERROR, NULLNODE, ap);
va_end(ap);
} }
/*VARARGS2*/ /*VARARGS2*/
node_error(node, fmt, args) node_error(va_alist)
va_dcl
{
t_node *node; t_node *node;
char *fmt; va_list ap;
{
_error(ERROR, node, fmt, &args);
}
/*VARARGS1*/ va_start(ap);
warning(class, fmt, args) node = va_arg(ap, t_node *);
char *fmt; _error(ERROR, node, ap);
{ va_end(ap);
warn_class = class;
if (class & warning_classes) _error(WARNING, NULLNODE, fmt, &args);
} }
/*VARARGS2*/ /*VARARGS2*/
node_warning(node, class, fmt, args) warning(va_alist)
t_node *node; va_dcl
char *fmt;
{ {
warn_class = class; va_list ap;
if (class & warning_classes) _error(WARNING, node, fmt, &args);
va_start(ap);
warn_class = va_arg(ap, int);
_error(WARNING, NULLNODE, ap);
va_end(ap);
}
/*VARARGS3*/
node_warning(va_alist)
va_dcl
{
t_node *nd;
va_list ap;
va_start(ap);
nd = va_arg(ap, t_node *);
warn_class = va_arg(ap, int);
_error(WARNING, nd, ap);
va_end(ap);
} }
/*VARARGS1*/ /*VARARGS1*/
lexerror(fmt, args) lexerror(va_alist)
char *fmt; va_dcl
{ {
_error(LEXERROR, NULLNODE, fmt, &args); va_list ap;
va_start(ap);
_error(LEXERROR, NULLNODE, ap);
va_end(ap);
}
/*VARARGS2*/
lexwarning(va_alist)
va_dcl
{
va_list ap;
va_start(ap);
warn_class = va_arg(ap, int);
_error(LEXWARNING, NULLNODE, ap);
va_end(ap);
} }
/*VARARGS1*/ /*VARARGS1*/
lexwarning(class, fmt, args) fatal(va_alist)
char *fmt; va_dcl
{ {
warn_class = class; va_list ap;
if (class & warning_classes) _error(LEXWARNING, NULLNODE, fmt, &args);
}
/*VARARGS1*/ va_start(ap);
fatal(fmt, args) _error(FATAL, NULLNODE, ap);
char *fmt; va_end(ap);
int args;
{
_error(FATAL, NULLNODE, fmt, &args);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
/*VARARGS1*/ /*VARARGS1*/
crash(fmt, args) crash(va_alist)
char *fmt; va_dcl
int args;
{ {
va_list ap;
_error(CRASH, NULLNODE, fmt, &args); va_start(ap);
_error(CRASH, NULLNODE, ap);
va_end(ap);
#ifdef DEBUG #ifdef DEBUG
sys_stop(S_ABORT); sys_stop(S_ABORT);
#else #else
@ -138,11 +174,10 @@ crash(fmt, args)
#endif #endif
} }
_error(class, node, fmt, argv) _error(class, node, ap)
int class; int class;
t_node *node; t_node *node;
char *fmt; va_list ap;
int argv[];
{ {
/* _error attempts to limit the number of error messages /* _error attempts to limit the number of error messages
for a given line to MAXERR_LINE. for a given line to MAXERR_LINE.
@ -152,6 +187,7 @@ _error(class, node, fmt, argv)
static char * last_fn = 0; static char * last_fn = 0;
static int e_seen = 0; static int e_seen = 0;
register char *remark = 0; register char *remark = 0;
char *fmt = va_arg(ap, char *);
/* Since name and number are gathered from different places /* Since name and number are gathered from different places
depending on the class, we first collect the relevant depending on the class, we first collect the relevant
@ -172,6 +208,7 @@ _error(class, node, fmt, argv)
switch (class) { switch (class) {
case WARNING: case WARNING:
case LEXWARNING: case LEXWARNING:
if (! warn_class & warning_classes) return;
switch(warn_class) { switch(warn_class) {
#ifndef STRICT_3RD_ED #ifndef STRICT_3RD_ED
case W_OLDFASHIONED: case W_OLDFASHIONED:
@ -244,6 +281,6 @@ _error(class, node, fmt, argv)
if (remark) fprint(ERROUT, "%s ", remark); if (remark) fprint(ERROUT, "%s ", remark);
doprnt(ERROUT, fmt, argv); /* contents of error */ doprnt(ERROUT, fmt, ap); /* contents of error */
fprint(ERROUT, "\n"); fprint(ERROUT, "\n");
} }

View file

@ -10,11 +10,12 @@
/* stripped down version from the one in the Modula-2 compiler */ /* stripped down version from the one in the Modula-2 compiler */
/* $Header$ */ /* $Header$ */
/* This file contains the (non-portable) error-message and diagnostic /* This file contains the error-message and diagnostic
giving functions. Be aware that they are called with a variable giving functions. Be aware that they are called with a variable
number of arguments! number of arguments!
*/ */
#include <varargs.h>
#include <system.h> #include <system.h>
#include "input.h" #include "input.h"
#include "f_info.h" #include "f_info.h"
@ -42,47 +43,62 @@ extern char *symbol2str();
*/ */
/*VARARGS1*/ /*VARARGS1*/
error(fmt, args) error(va_alist)
char *fmt; va_dcl
{ {
_error(ERROR, fmt, &args); va_list ap;
va_start(ap);
_error(ERROR, ap);
va_end(ap);
} }
/*VARARGS1*/ /*VARARGS1*/
Gerror(fmt, args) Gerror(va_alist)
char *fmt; va_dcl
{ {
va_list ap;
char *fn = FileName; char *fn = FileName;
FileName = 0; FileName = 0;
_error(ERROR, fmt, &args); va_start(ap);
_error(ERROR, ap);
va_end(ap);
FileName = fn; FileName = fn;
} }
/*VARARGS1*/ /*VARARGS1*/
lexerror(fmt, args) lexerror(va_alist)
char *fmt; va_dcl
{ {
_error(LEXERROR, fmt, &args); va_list ap;
va_start(ap);
_error(LEXERROR, ap);
va_end(ap);
} }
/*VARARGS1*/ /*VARARGS1*/
fatal(fmt, args) fatal(va_alist)
char *fmt; va_dcl
int args;
{ {
va_list ap;
_error(FATAL, fmt, &args); va_start(ap);
_error(FATAL, ap);
va_end(ap);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
/*VARARGS1*/ /*VARARGS1*/
crash(fmt, args) crash(va_alist)
char *fmt; va_dcl
int args;
{ {
va_list ap;
_error(CRASH, fmt, &args); va_start(ap);
_error(CRASH, ap);
va_end(ap);
#ifdef DEBUG #ifdef DEBUG
sys_stop(S_ABORT); sys_stop(S_ABORT);
#else #else
@ -90,16 +106,16 @@ crash(fmt, args)
#endif #endif
} }
_error(class, fmt, argv) _error(class, argv)
int class; int class;
char *fmt; va_list argv;
int argv[];
{ {
/* _error attempts to limit the number of error messages /* _error attempts to limit the number of error messages
for a given line to MAXERR_LINE. for a given line to MAXERR_LINE.
*/ */
unsigned int ln = 0; unsigned int ln = 0;
register char *remark = 0; register char *remark = 0;
char *fmt = va_arg(argv, char *);
/* Since name and number are gathered from different places /* Since name and number are gathered from different places
depending on the class, we first collect the relevant depending on the class, we first collect the relevant