mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
* Remove `err` and `warn`, keep `errx` and `warnx`, using them in RGBGFX too * Separate RGBGFX and RGBLINK warnings/errors from main options * Separate `report` function into `error` and `fatal` messages * Implicit newlines for most RGBASM errors
53 lines
906 B
C++
53 lines
906 B
C++
// SPDX-License-Identifier: MIT
|
|
|
|
#include "gfx/warning.hpp"
|
|
|
|
#include <limits>
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
static uintmax_t nbErrors;
|
|
|
|
[[noreturn]]
|
|
void giveUp() {
|
|
fprintf(stderr, "Conversion aborted after %ju error%s\n", nbErrors, nbErrors == 1 ? "" : "s");
|
|
exit(1);
|
|
}
|
|
|
|
void requireZeroErrors() {
|
|
if (nbErrors != 0) {
|
|
giveUp();
|
|
}
|
|
}
|
|
|
|
void error(char const *fmt, ...) {
|
|
va_list ap;
|
|
fputs("error: ", stderr);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
putc('\n', stderr);
|
|
|
|
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
|
nbErrors++;
|
|
}
|
|
}
|
|
|
|
[[noreturn]]
|
|
void fatal(char const *fmt, ...) {
|
|
va_list ap;
|
|
fputs("FATAL: ", stderr);
|
|
va_start(ap, fmt);
|
|
vfprintf(stderr, fmt, ap);
|
|
va_end(ap);
|
|
putc('\n', stderr);
|
|
|
|
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
|
nbErrors++;
|
|
}
|
|
|
|
giveUp();
|
|
}
|