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.
This commit is contained in:
ISSOtm
2020-02-03 21:01:38 +01:00
parent f363541611
commit a7cb0a166a

View File

@@ -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);
}