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
$ */
void
doprnt(File *fp, char *fmt, va_list argp)
doprnt(File *fp, const char *fmt, va_list argp)
{
char buf[SSIZE];

View file

@ -35,7 +35,7 @@ integral(int c)
%d = 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 *pb = buf;

View file

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

View file

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

View file

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

View file

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

View file

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