Use <stdarg.h> in util/misc/convert.c

I made a syntax error in some .e file, and em_encode dumped core
because a 64-bit pointer didn't fit in a 32-bit int.  Now use stdarg
to pass pointers to error() and fatal().

Stop using the number of errors as the exit status.  Many systems use
only the low 8 bits of the exit status, so 256 errors would become 0.

Also change modules/src/print to accept const char *buf
This commit is contained in:
George Koehler 2017-12-06 17:09:12 -05:00
parent 6d91bdbbbd
commit 88207db638
7 changed files with 29 additions and 19 deletions

View file

@ -16,7 +16,7 @@
%d = int %d = int
$ */ $ */
void void
doprnt(File *fp, char *fmt, va_list argp) doprnt(File *fp, const char *fmt, va_list argp)
{ {
char buf[SSIZE]; char buf[SSIZE];

View file

@ -35,7 +35,7 @@ integral(int c)
%d = int %d = int
$ */ $ */
int int
_format(char *buf, char *fmt, va_list argp) _format(char *buf, const char *fmt, va_list argp)
{ {
register char *pf = fmt; register char *pf = fmt;
register char *pb = buf; register char *pb = buf;

View file

@ -17,7 +17,7 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
void void
fprint(File *fp, char *fmt, ...) fprint(File *fp, const char *fmt, ...)
{ {
va_list args; va_list args;
char buf[SSIZE]; char buf[SSIZE];

View file

@ -17,7 +17,7 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
void void
print(char *fmt, ...) print(const char *fmt, ...)
{ {
va_list args; va_list args;
char buf[SSIZE]; char buf[SSIZE];

View file

@ -9,10 +9,10 @@
#include <stdarg.h> #include <stdarg.h>
void print(char *fmt, ...); void print(const char *fmt, ...);
void fprint(File *f, char *fmt, ...); void fprint(File *f, const char *fmt, ...);
void doprnt(File *f, char *fmt, va_list ap); void doprnt(File *f, const char *fmt, va_list ap);
int _format(char *buf, char *fmt, va_list ap); int _format(char *buf, const char *fmt, va_list ap);
char *sprint(char *buf, char *fmt, ...); char *sprint(char *buf, const char *fmt, ...);
#endif /* __PRINT_INCLUDED__ */ #endif /* __PRINT_INCLUDED__ */

View file

@ -17,7 +17,7 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
char * char *
sprint(char *buf, char *fmt, ...) sprint(char *buf, const char *fmt, ...)
{ {
va_list args; va_list args;

View file

@ -16,8 +16,10 @@ static char rcsid[] = "$Id$";
linked. linked.
*/ */
#include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include "system.h" #include "system.h"
#include "print.h"
#include "em_pseu.h" #include "em_pseu.h"
#include "em_mnem.h" #include "em_mnem.h"
#include "em_spec.h" #include "em_spec.h"
@ -30,8 +32,11 @@ char *filename; /* Name of input file */
int errors; /* Number of errors */ int errors; /* Number of errors */
extern char *C_error; extern char *C_error;
main(argc,argv) void error(const char *, ...);
char **argv; void fatal(const char *, ...);
int
main(int argc, char **argv)
{ {
struct e_instr buf; struct e_instr buf;
register struct e_instr *p = &buf; register struct e_instr *p = &buf;
@ -66,27 +71,32 @@ main(argc,argv)
} }
C_close(); C_close();
EM_close(); EM_close();
exit(errors); exit(errors ? 1 : 0);
} }
/* VARARGS */ /* VARARGS */
error(s,a1,a2,a3,a4) void
char *s; error(const char *s, ...)
{ {
va_list ap;
va_start(ap, s);
fprint(STDERR, fprint(STDERR,
"%s, line %d: ", "%s, line %d: ",
filename ? filename : "standard input", filename ? filename : "standard input",
EM_lineno); EM_lineno);
fprint(STDERR,s,a1,a2,a3,a4); doprnt(STDERR, s, ap);
fprint(STDERR, "\n"); fprint(STDERR, "\n");
errors++; errors++;
va_end(ap);
} }
/* VARARGS */ /* VARARGS */
fatal(s,a1,a2,a3,a4) void
char *s; fatal(const char *s, ...)
{ {
va_list ap;
va_start(ap, s);
if (C_busy()) C_close(); if (C_busy()) C_close();
error(s,a1,a2,a3,a4); error(s, ap);
exit(1); exit(1);
} }