Fix errors

This commit is contained in:
Aetias
2023-10-14 12:47:35 +02:00
parent 44931d43a7
commit a480db7f3a
2 changed files with 20 additions and 19 deletions
+5 -6
View File
@@ -234,7 +234,7 @@ bool WriteFntSubtable(FileTree *tree, FntContext *pContext) {
size_t entrySize = sizeof(*entry) + entry->length + (entry->isSubdir ? 2 : 0);
if (!GrowFntSubtable(&ctx, entrySize)) return false;
FntSubEntry *dest = ctx.subtable + ctx.subtableSize;
FntSubEntry *dest = (FntSubEntry*) (ctx.subtable + ctx.subtableSize);
memcpy(dest, entry, entrySize);
ctx.subtableSize += entrySize;
}
@@ -306,7 +306,7 @@ bool WriteFnt(FILE *fpRom, size_t *pAddress, FileTree *pRoot, size_t firstFileId
rootEntry.parentId = 0; // will be set to number of directories later
size_t tableStart = address;
if (!WriteFntSubtable(fpRom, &address, pRoot, &ctx)) return false;
if (!WriteFntSubtable(pRoot, &ctx)) return false;
size_t tableLength = ctx.tableSize * sizeof(FntEntry);
for (size_t i = 0; i < ctx.tableSize; ++i) {
@@ -499,7 +499,7 @@ int main(int argc, const char **argv) {
size_t address = 0;
Header header;
InitHeader(&header, &region);
InitHeader(&header, &info);
if (fwrite(&header, sizeof(header), 1, fpRom) != 1) {
fprintf(stderr, "Failed to write NDS header\n");
@@ -523,7 +523,7 @@ int main(int argc, const char **argv) {
FatEntry overlayEntries[MAX_OVERLAYS];
size_t numOverlays = 0;
if (!WriteArm9Overlays(fpRom, &address, &numOverlays, &overlayEntries, MAX_OVERLAYS)) return 1;
if (!WriteArm9Overlays(fpRom, &address, &numOverlays, overlayEntries, MAX_OVERLAYS)) return 1;
if (chdir(rootDir) != 0) {
fprintf(stderr, "Failed to leave build directory '%s'\n", buildDir);
@@ -571,6 +571,5 @@ int main(int argc, const char **argv) {
}
free(readBuffer);
flose(fpRom);
free(rootDir);
fclose(fpRom);
}
+15 -13
View File
@@ -4,6 +4,14 @@
#include "util.h"
#include "rom.h"
typedef struct FileTree {
struct FileTree *children;
uint16_t numChildren;
uint16_t maxChildren;
uint16_t firstFileId;
FntSubEntry *entry;
} FileTree;
bool MakeFileTree(FileTree *pTree);
bool IterFiles(bool (*callback)(const char *name, bool isDir, void*), void *userData) {
@@ -17,7 +25,7 @@ bool IterFiles(bool (*callback)(const char *name, bool isDir, void*), void *user
if (!callback(name, isDir, userData)) return false;
} while (FindNextFileA(hFind, &findData));
FindClose(hFind);
#else __linux__
#elif __linux__
DIR *dir = opendir(".");
struct dirent entry;
while ((entry = readdir(dir)) != NULL) {
@@ -29,14 +37,6 @@ bool IterFiles(bool (*callback)(const char *name, bool isDir, void*), void *user
#endif
}
typedef struct FileTree {
struct FileTree *children;
uint16_t numChildren;
uint16_t maxChildren;
uint16_t firstFileId;
FntSubEntry *entry;
} FileTree;
bool _GrowFileTreeChildren(FileTree *pTree, size_t minChildren) {
FileTree tree;
memcpy(&tree, pTree, sizeof(tree));
@@ -128,11 +128,13 @@ bool FreeFileTree(FileTree *pTree) {
}
}
int CompareFileTree(const FileTree *a, const FileTree *b) {
size_t lenA = a->entry->length;
size_t lenB = b->entry->length;
int CompareFileTree(const void *a, const void *b) {
FileTree *treeA = (FileTree*) a;
FileTree *treeB = (FileTree*) b;
size_t lenA = treeA->entry->length;
size_t lenB = treeB->entry->length;
size_t minSize = (lenA < lenB) ? lenA : lenB;
int cmp = strncmp(a->entry->name, b->entry->name, minSize);
int cmp = strncmp(treeA->entry->name, treeB->entry->name, minSize);
if (cmp != 0) return cmp;
if (lenA < lenB) return -1;
if (lenA > lenB) return 1;