From a7cb0a166ad9c6844b7b0cf216278ff137846081 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 3 Feb 2020 21:01:38 +0100 Subject: [PATCH] Inline `readRGBxObject` This was made separate with the intention of supporting multiple versions, but after some discussion this was decided against, so better improve readability instead. --- src/link/object.c | 56 +++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/src/link/object.c b/src/link/object.c index 01f520c7..7dcb2518 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -334,12 +334,31 @@ static void linkSymToSect(struct Symbol const *symbol, struct Section *section) } /** - * Reads a RGB7 object file. - * @param file The file to read from - * @param fileName The filename to report in errors + * Reads an object file of any supported format + * @param fileName The filename to report for errors */ -static void readRGB7File(FILE *file, char const *fileName) +void obj_ReadFile(char const *fileName) { + FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin; + + if (!file) + err(1, "Could not open file %s", fileName); + + /* Begin by reading the magic bytes and version number */ + uint8_t versionNumber; + int matchedElems = fscanf(file, RGBDS_OBJECT_VERSION_STRING, + &versionNumber); + + if (matchedElems != 1) + errx(1, "\"%s\" is not a RGBDS object file", fileName); + + verbosePrint("Reading object file %s, version %hhu\n", + fileName, versionNumber); + + if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER) + errx(1, "\"%s\" is an incompatible version %hhu object file", + fileName, versionNumber); + uint32_t revNum; tryReadlong(revNum, file, "%s: Cannot read revision number: %s", @@ -432,35 +451,6 @@ static void readRGB7File(FILE *file, char const *fileName) linkSymToSect(fileSymbols[i], fileSections[sectionID]); } } -} - -/** - * Reads an object file of any supported format - * @param fileName The filename to report for errors - */ -void obj_ReadFile(char const *fileName) -{ - FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin; - - if (!file) - err(1, "Could not open file %s", fileName); - - /* Begin by reading the magic bytes and version number */ - uint8_t versionNumber; - int matchedElems = fscanf(file, RGBDS_OBJECT_VERSION_STRING, - &versionNumber); - - if (matchedElems != 1) - errx(1, "\"%s\" is not a RGBDS object file", fileName); - - verbosePrint("Reading object file %s, version %hhu\n", - fileName, versionNumber); - - if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER) - errx(1, "\"%s\" is an incompatible version %hhu object file", - fileName, versionNumber); - - readRGB7File(file, fileName); fclose(file); }