ack/util/led/error.c

99 lines
1.7 KiB
C
Raw Permalink Normal View History

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>
#include <unistd.h>
#include <out.h>
1985-01-10 13:17:22 +00:00
#include "const.h"
static short nerrors = 0;
static void diag(char *, char *, va_list);
1985-01-10 13:17:22 +00:00
void stop(void)
1985-01-10 13:17:22 +00:00
{
extern char *outputname;
extern int exitstatus;
1985-01-10 13:17:22 +00:00
if (nerrors) {
remove(outputname);
exit(nerrors);
}
1985-01-10 13:17:22 +00:00
exit(exitstatus);
1985-01-10 13:17:22 +00:00
}
/* VARARGS1 */
void fatal(char *format, ...)
1985-01-10 13:17:22 +00:00
{
va_list ap;
va_start(ap, format);
1985-01-10 13:17:22 +00:00
nerrors++;
diag("fatal", format, ap);
1985-01-10 13:17:22 +00:00
stop();
}
/* VARARGS1 */
void warning(char *format, ...)
1985-01-10 13:17:22 +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 */
void error(char *format, ...)
1985-01-10 13:17:22 +00:00
{
va_list ap;
va_start(ap, format);
1985-01-10 13:17:22 +00:00
nerrors++;
diag("error", format, ap);
va_end(ap);
1985-01-10 13:17:22 +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 */
int do_verbose(char *format, ...)
1990-03-15 10:44:14 +00:00
{
va_list ap;
va_start(ap, format);
diag((char *) 0, format, ap);
va_end(ap);
return 1;
1990-03-15 10:44:14 +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);
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
}