Change fatal() and error() to use varargs.

This commit is contained in:
David Given 2013-05-10 12:04:21 +01:00
parent d91a1dc1a6
commit d89f172841
8 changed files with 37 additions and 11 deletions

View file

@ -10,6 +10,7 @@ static char rcsid[]= "$Id$";
#include <string.h> #include <string.h>
#include "param.h" #include "param.h"
#include "expr.h" #include "expr.h"
#include "extern.h"
#include <em_spec.h> #include <em_spec.h>
#include <em_flag.h> #include <em_flag.h>

View file

@ -8,6 +8,8 @@ static char rcsid[]= "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
#include "extern.h"
int nerrors=0; int nerrors=0;
@ -24,24 +26,38 @@ goodbye() {
#endif #endif
} }
/*VARARGS1*/ void errorv(const char* s, va_list ap)
fatal(s,a,b,c,d) char *s; { {
extern int lineno;
extern char *filename;
fprintf(stderr, "\"%s\", line %d:", filename, lineno);
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
nerrors++;
}
void fatal(const char* s, ...)
{
va_list ap;
va_start(ap, s);
errorv(s, ap);
va_end(ap);
error(s,a,b,c,d);
errorexit(); errorexit();
goodbye(); goodbye();
exit(-1); exit(-1);
} }
/*VARARGS1*/ void error(const char* s, ...)
error(s,a,b,c,d) char *s; { {
extern int lineno; va_list ap;
extern char *filename;
fprintf(stderr,"\"%s\", line %d:",filename,lineno); va_start(ap, s);
fprintf(stderr,s,a,b,c,d); errorv(s, ap);
fprintf(stderr,"\n"); va_end(ap);
nerrors++;
} }
#ifndef NDEBUG #ifndef NDEBUG

View file

@ -40,3 +40,7 @@ extern int use_tes;
extern char *mystrcpy(); extern char *mystrcpy();
extern char *myalloc(); extern char *myalloc();
extern void error(const char* s, ...);
extern void fatal(const char* s, ...);

View file

@ -9,6 +9,7 @@ static char rcsid[]= "$Id$";
#include "assert.h" #include "assert.h"
#include "param.h" #include "param.h"
#include "set.h" #include "set.h"
#include "extern.h"
#include <stdio.h> #include <stdio.h>
/* /*

View file

@ -9,6 +9,7 @@ static char rcsid[]= "$Id$";
#include "assert.h" #include "assert.h"
#include "param.h" #include "param.h"
#include "lookup.h" #include "lookup.h"
#include "extern.h"
char *myalloc(); char *myalloc();
char *mystrcpy(); char *mystrcpy();

View file

@ -8,6 +8,7 @@ static char rcsid[]= "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "extern.h"
char *filename; char *filename;
char *beg_sbrk; char *beg_sbrk;

View file

@ -7,6 +7,7 @@ static char rcsid[]= "$Id$";
#endif #endif
#include "param.h" #include "param.h"
#include "extern.h"
int nstrings=0; int nstrings=0;
char *l_strings[MAXSTRINGS]; char *l_strings[MAXSTRINGS];

View file

@ -13,6 +13,7 @@ static char rcsid[]= "$Id$";
#include "set.h" #include "set.h"
#include "instruct.h" #include "instruct.h"
#include "lookup.h" #include "lookup.h"
#include "extern.h"
#include <cgg_cg.h> #include <cgg_cg.h>
int wordsize; int wordsize;