mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 03:02:06 +00:00
Refactor error reporting to simplify BSD-style err (#949)
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
#include "asm/warning.h"
|
||||
#include "parser.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "extern/getopt.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "error.h"
|
||||
#include "version.h"
|
||||
|
||||
#ifdef __clang__
|
||||
@@ -74,7 +74,7 @@ static char *make_escape(char const *str)
|
||||
char *dest = escaped_str;
|
||||
|
||||
if (escaped_str == NULL)
|
||||
err(1, "%s: Failed to allocate memory", __func__);
|
||||
err("%s: Failed to allocate memory", __func__);
|
||||
|
||||
while (*str) {
|
||||
/* All dollars needs to be doubled */
|
||||
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
|
||||
if (strlen(musl_optarg) == 2)
|
||||
opt_B(&musl_optarg[1]);
|
||||
else
|
||||
errx(1, "Must specify exactly 2 characters for option 'b'");
|
||||
errx("Must specify exactly 2 characters for option 'b'");
|
||||
break;
|
||||
|
||||
char *equals;
|
||||
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
|
||||
if (strlen(musl_optarg) == 4)
|
||||
opt_G(&musl_optarg[1]);
|
||||
else
|
||||
errx(1, "Must specify exactly 4 characters for option 'g'");
|
||||
errx("Must specify exactly 4 characters for option 'g'");
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
@@ -235,7 +235,7 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
dependfile = fopen(musl_optarg, "w");
|
||||
if (dependfile == NULL)
|
||||
err(1, "Could not open dependfile %s", musl_optarg);
|
||||
err("Could not open dependfile %s", musl_optarg);
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
@@ -247,10 +247,10 @@ int main(int argc, char *argv[])
|
||||
fill = strtoul(musl_optarg, &ep, 0);
|
||||
|
||||
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'p'");
|
||||
errx("Invalid argument for option 'p'");
|
||||
|
||||
if (fill < 0 || fill > 0xFF)
|
||||
errx(1, "Argument for option 'p' must be between 0 and 0xFF");
|
||||
errx("Argument for option 'p' must be between 0 and 0xFF");
|
||||
|
||||
opt_P(fill);
|
||||
break;
|
||||
@@ -259,7 +259,7 @@ int main(int argc, char *argv[])
|
||||
maxDepth = strtoul(musl_optarg, &ep, 0);
|
||||
|
||||
if (musl_optarg[0] == '\0' || *ep != '\0')
|
||||
errx(1, "Invalid argument for option 'r'");
|
||||
errx("Invalid argument for option 'r'");
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
|
||||
targetFileName = realloc(targetFileName,
|
||||
targetFileNameLen + newTargetLen + 1);
|
||||
if (targetFileName == NULL)
|
||||
err(1, "Cannot append new file to target file list");
|
||||
err("Cannot append new file to target file list");
|
||||
memcpy(&targetFileName[targetFileNameLen], newTarget, newTargetLen);
|
||||
if (depType == 'Q')
|
||||
free(newTarget);
|
||||
@@ -336,7 +336,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (dependfile) {
|
||||
if (!targetFileName)
|
||||
errx(1, "Dependency files can only be created if a target file is specified with either -o, -MQ or -MT");
|
||||
errx("Dependency files can only be created if a target file is specified with either -o, -MQ or -MT");
|
||||
|
||||
fprintf(dependfile, "%s: %s\n", targetFileName, mainFileName);
|
||||
}
|
||||
@@ -357,7 +357,7 @@ int main(int argc, char *argv[])
|
||||
sect_CheckUnionClosed();
|
||||
|
||||
if (nbErrors != 0)
|
||||
errx(1, "Assembly aborted (%u error%s)!", nbErrors,
|
||||
errx("Assembly aborted (%u error%s)!", nbErrors,
|
||||
nbErrors == 1 ? "" : "s");
|
||||
|
||||
// If parse aborted due to missing an include, and `-MG` was given, exit normally
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "linkdefs.h"
|
||||
#include "platform.h" // strdup
|
||||
|
||||
@@ -528,7 +527,7 @@ void out_WriteObject(void)
|
||||
f = fdopen(1, "wb");
|
||||
|
||||
if (!f)
|
||||
err(1, "Couldn't write file '%s'", objectName);
|
||||
err("Couldn't write file '%s'", objectName);
|
||||
|
||||
/* Also write symbols that weren't written above */
|
||||
sym_ForEach(registerUnregisteredSymbol, NULL);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "asm/symbol.h"
|
||||
#include "asm/warning.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
#include "platform.h" // strdup
|
||||
|
||||
uint8_t fillByte;
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
#include "asm/util.h"
|
||||
#include "asm/warning.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "hashmap.h"
|
||||
#include "helpers.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "asm/main.h"
|
||||
#include "asm/warning.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
|
||||
unsigned int nbErrors = 0;
|
||||
|
||||
@@ -215,7 +215,7 @@ void processWarningFlag(char *flag)
|
||||
if (!strcmp(flag, warningFlags[id])) {
|
||||
/* We got a match! */
|
||||
if (setError)
|
||||
errx(1, "Cannot make meta warning \"%s\" into an error",
|
||||
errx("Cannot make meta warning \"%s\" into an error",
|
||||
flag);
|
||||
|
||||
for (uint8_t const *ptr = metaWarningCommands[id - META_WARNINGS_START];
|
||||
|
||||
Reference in New Issue
Block a user