shithub: rgbds

Download patch

ref: a7cb0a166ad9c6844b7b0cf216278ff137846081
parent: f3635416112b6444c0f1dd53744a72b3e05c9c19
author: ISSOtm <eldredhabert0@gmail.com>
date: Mon Feb 3 16:01:38 EST 2020

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.

--- a/src/link/object.c
+++ b/src/link/object.c
@@ -334,12 +334,31 @@
 }
 
 /**
- * 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 @@
 			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);
 }