From ac632d92230f9739df8f024370ab3509be0e5c4e Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Sat, 26 Jul 2025 12:29:57 -0400 Subject: [PATCH] RGBFIX returns 1 if there was a `-Werror` before processing any files --- include/fix/mbc.hpp | 2 -- include/fix/warning.hpp | 1 + src/fix/main.cpp | 2 +- src/fix/mbc.cpp | 30 +++++++++++++++--------------- src/fix/warning.cpp | 6 +++++- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/fix/mbc.hpp b/include/fix/mbc.hpp index d43b32a0..fac13ed2 100644 --- a/include/fix/mbc.hpp +++ b/include/fix/mbc.hpp @@ -76,8 +76,6 @@ enum MbcType { MBC_NONE = UNSPECIFIED, // No MBC specified, do not act on it }; -void mbc_PrintAcceptedNames(FILE *file); - bool mbc_HasRAM(MbcType type); char const *mbc_Name(MbcType type); MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor); diff --git a/include/fix/warning.hpp b/include/fix/warning.hpp index 6b9ed96d..728177c3 100644 --- a/include/fix/warning.hpp +++ b/include/fix/warning.hpp @@ -37,6 +37,7 @@ void error(char const *fmt, ...); void fatal(char const *fmt, ...); void resetErrors(); +bool anyErrors(); uint32_t checkErrors(char const *filename); #endif // RGBDS_FIX_WARNING_HPP diff --git a/src/fix/main.cpp b/src/fix/main.cpp index 2a010f28..75d86192 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -901,7 +901,7 @@ int main(int argc, char *argv[]) { fatalWithUsage("If `-o` is set then only a single input file may be specified"); } - bool failed = false; + bool failed = anyErrors(); do { failed |= processFilename(*argv, outputFilename); } while (*++argv); diff --git a/src/fix/mbc.cpp b/src/fix/mbc.cpp index bf70510d..b0abc5d4 100644 --- a/src/fix/mbc.cpp +++ b/src/fix/mbc.cpp @@ -7,20 +7,7 @@ #include "fix/warning.hpp" -[[gnu::format(printf, 1, 2), noreturn]] -static void fatalWithMBCNames(char const *fmt, ...) { - va_list ap; - fputs("FATAL: ", stderr); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - putc('\n', stderr); - - mbc_PrintAcceptedNames(stderr); - exit(1); -} - -void mbc_PrintAcceptedNames(FILE *file) { +static void printAcceptedMbcNames(FILE *file) { fputs("Accepted MBC names:\n", file); fputs("\tROM ($00) [aka ROM_ONLY]\n", file); fputs("\tMBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)\n", file); @@ -45,6 +32,19 @@ void mbc_PrintAcceptedNames(FILE *file) { fputs("\tTPP1_1.0+BATTERY+TIMER+MULTIRUMBLE\n", file); } +[[gnu::format(printf, 1, 2), noreturn]] +static void fatalWithMBCNames(char const *fmt, ...) { + va_list ap; + fputs("FATAL: ", stderr); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + putc('\n', stderr); + + printAcceptedMbcNames(stderr); + exit(1); +} + bool mbc_HasRAM(MbcType type) { switch (type) { case ROM_RAM: @@ -241,7 +241,7 @@ MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor) char const *fullName = name; if (!strcasecmp(name, "help") || !strcasecmp(name, "list")) { - mbc_PrintAcceptedNames(stdout); + printAcceptedMbcNames(stdout); exit(0); } diff --git a/src/fix/warning.cpp b/src/fix/warning.cpp index f60e63e2..8fa7558f 100644 --- a/src/fix/warning.cpp +++ b/src/fix/warning.cpp @@ -23,8 +23,12 @@ void resetErrors() { nbErrors = 0; } +bool anyErrors() { + return nbErrors > 0; +} + uint32_t checkErrors(char const *filename) { - if (nbErrors > 0) { + if (anyErrors()) { fprintf( stderr, "Fixing \"%s\" failed with %u error%s\n",