ack/util/led/error.c
George Koehler 3f3bf1e164 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 18:27:34 -04:00

99 lines
1.7 KiB
C

/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef lint
static char rcsid[] = "$Id$";
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include <unistd.h>
#include <out.h>
#include "const.h"
static short nerrors = 0;
static void diag(char *, char *, va_list);
void stop(void)
{
extern char *outputname;
extern int exitstatus;
if (nerrors) {
remove(outputname);
exit(nerrors);
}
exit(exitstatus);
}
/* VARARGS1 */
void fatal(char *format, ...)
{
va_list ap;
va_start(ap, format);
nerrors++;
diag("fatal", format, ap);
stop();
}
/* VARARGS1 */
void warning(char *format, ...)
{
va_list ap;
va_start(ap, format);
diag("warning", format, ap);
va_end(ap);
}
/* VARARGS1 */
void error(char *format, ...)
{
va_list ap;
va_start(ap, format);
nerrors++;
diag("error", format, ap);
va_end(ap);
}
/* 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;
}
/* VARARGS1 */
int do_verbose(char *format, ...)
{
va_list ap;
va_start(ap, format);
diag((char *) 0, format, ap);
va_end(ap);
return 1;
}
static void diag(char *tail, char *format, va_list ap)
{
extern char *progname, *archname, *modulname;
fprintf(stderr, "%s: ", progname);
if (archname && modulname)
fprintf(stderr, "%s(%.14s): ", archname, modulname);
else if (archname)
fprintf(stderr, "%s: ", archname);
else if (modulname)
fprintf(stderr, "%s: ", modulname);
vfprintf(stderr, format, ap);
if (tail) fprintf(stderr, " (%s)\n", tail);
else putc('\n', stderr);
}