1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-01-10 13:17:22 +00:00
|
|
|
#ifndef lint
|
1994-06-24 11:31:16 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-10 13:17:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-01-18 18:55:56 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdarg.h>
|
2019-03-22 19:15:40 +00:00
|
|
|
#include <unistd.h>
|
1986-10-20 10:17:57 +00:00
|
|
|
#include <out.h>
|
1985-01-10 13:17:22 +00:00
|
|
|
#include "const.h"
|
|
|
|
|
|
|
|
static short nerrors = 0;
|
2012-10-24 17:44:50 +00:00
|
|
|
static void diag(char *, char *, va_list);
|
1985-01-10 13:17:22 +00:00
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
void stop(void)
|
1985-01-10 13:17:22 +00:00
|
|
|
{
|
|
|
|
extern char *outputname;
|
1986-10-20 10:17:57 +00:00
|
|
|
extern int exitstatus;
|
1985-01-10 13:17:22 +00:00
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
if (nerrors) {
|
2019-03-24 09:08:45 +00:00
|
|
|
remove(outputname);
|
1986-10-20 10:17:57 +00:00
|
|
|
exit(nerrors);
|
|
|
|
}
|
1985-01-10 13:17:22 +00:00
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
exit(exitstatus);
|
1985-01-10 13:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
2019-03-24 09:08:45 +00:00
|
|
|
void fatal(char *format, ...)
|
1985-01-10 13:17:22 +00:00
|
|
|
{
|
2012-10-24 17:44:50 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
1985-01-10 13:17:22 +00:00
|
|
|
nerrors++;
|
2012-10-24 17:44:50 +00:00
|
|
|
diag("fatal", format, ap);
|
1985-01-10 13:17:22 +00:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
2019-03-24 09:08:45 +00:00
|
|
|
void warning(char *format, ...)
|
1985-01-10 13:17:22 +00:00
|
|
|
{
|
2012-10-24 17:44:50 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
diag("warning", format, ap);
|
|
|
|
va_end(ap);
|
1985-01-10 13:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* VARARGS1 */
|
2019-03-24 09:08:45 +00:00
|
|
|
void error(char *format, ...)
|
1985-01-10 13:17:22 +00:00
|
|
|
{
|
2012-10-24 17:44:50 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
1985-01-10 13:17:22 +00:00
|
|
|
nerrors++;
|
2012-10-24 17:44:50 +00:00
|
|
|
diag("error", format, ap);
|
|
|
|
va_end(ap);
|
1985-01-10 13:17:22 +00:00
|
|
|
}
|
|
|
|
|
Reduce warnings, adjust format strings in util/led
Calls like `debug("something\n", 0, 0, 0, 0)` cause clang warnings,
because debug() is a macro that passes its arguments to printf(), and
clang warns about extra 0s to printf(). Silence the warnings by
hiding the printf() in a new function do_debug(). The code still
passes extra 0s to printf(), but clang can't warn.
Macros debug() and verbose() should use C99 __VA_ARGS__, so they don't
require the extra 0s; but ACK doesn't use __VA_ARGS__ yet.
Adjust some format strings for debug() or fatal(), or cast their
arguments, to match their types. I don't know whether uint32_t is
unsigned int or unsigned long, so I cast it to unsigned long, and
print it with "%lx".
In util/led/sym.c, #include "save.h" to declare savechar(), and use
parentheses to silence a clang warning in hash().
2019-11-01 22:27:34 +00:00
|
|
|
/* VARARGS1 */
|
|
|
|
int do_debug(char *format, ...)
|
|
|
|
{
|
|
|
|
/* printf() and return 1 */
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
vprintf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1990-03-15 10:44:14 +00:00
|
|
|
/* VARARGS1 */
|
2019-03-24 09:08:45 +00:00
|
|
|
int do_verbose(char *format, ...)
|
1990-03-15 10:44:14 +00:00
|
|
|
{
|
2012-10-24 17:44:50 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
diag((char *) 0, format, ap);
|
|
|
|
va_end(ap);
|
2019-03-24 09:08:45 +00:00
|
|
|
return 1;
|
1990-03-15 10:44:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
static void diag(char *tail, char *format, va_list ap)
|
1985-01-10 13:17:22 +00:00
|
|
|
{
|
2017-01-18 18:55:56 +00:00
|
|
|
extern char *progname, *archname, *modulname;
|
1985-01-10 13:17:22 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
1990-03-15 10:44:14 +00:00
|
|
|
if (archname && modulname)
|
1990-07-30 11:56:28 +00:00
|
|
|
fprintf(stderr, "%s(%.14s): ", archname, modulname);
|
1990-03-15 10:44:14 +00:00
|
|
|
else if (archname)
|
1985-01-10 13:17:22 +00:00
|
|
|
fprintf(stderr, "%s: ", archname);
|
1990-03-15 10:44:14 +00:00
|
|
|
else if (modulname)
|
1990-11-27 09:39:52 +00:00
|
|
|
fprintf(stderr, "%s: ", modulname);
|
2012-10-24 17:44:50 +00:00
|
|
|
vfprintf(stderr, format, ap);
|
1990-03-15 10:44:14 +00:00
|
|
|
if (tail) fprintf(stderr, " (%s)\n", tail);
|
|
|
|
else putc('\n', stderr);
|
1985-01-10 13:17:22 +00:00
|
|
|
}
|