From a6fac5fb278f1031298939aad9c4fe5eb60504b1 Mon Sep 17 00:00:00 2001 From: vulcandth Date: Wed, 25 Dec 2024 22:12:02 -0600 Subject: [PATCH] Update `make_patch.c` --- tools/make_patch.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/make_patch.c b/tools/make_patch.c index 706a42ccb8..88c9a00a2d 100644 --- a/tools/make_patch.c +++ b/tools/make_patch.c @@ -113,7 +113,11 @@ void parse_symbol_value(char *input, int *restrict bank, int *restrict address) } } -void parse_symbols(const char *filename, struct Symbol **symbols) { +struct Symbol *parse_symbols(const char *filename) +{ + // Create a local symbol list pointer + struct Symbol *symbols = NULL; + FILE *file = xfopen(filename, 'r'); struct Buffer *buffer = buffer_create(1); @@ -123,11 +127,12 @@ void parse_symbols(const char *filename, struct Symbol **symbols) { for (;;) { int c = getc(file); - if (c == EOF || c == '\n' || c == '\r' || c == ';' || (state == SYM_NAME && (c == ' ' || c == '\t'))) { + if (c == EOF || c == '\n' || c == '\r' || c == ';' + || (state == SYM_NAME && (c == ' ' || c == '\t'))) { if (state == SYM_NAME) { // The symbol name has ended; append the buffered symbol buffer_append(buffer, &(char []){'\0'}); - symbol_append(symbols, buffer->data, bank, address); + symbol_append(&symbols, buffer->data, bank, address); } // Skip to the next line, ignoring anything after the symbol value and name state = SYM_PRE; @@ -156,6 +161,9 @@ void parse_symbols(const char *filename, struct Symbol **symbols) { fclose(file); buffer_free(buffer); + + // Return the newly built linked list + return symbols; } int strfind(const char *s, const char *list[], int count) { @@ -453,8 +461,7 @@ int main(int argc, char *argv[]) { usage_exit(1); } - struct Symbol *symbols = NULL; - parse_symbols(argv[1], &symbols); + struct Symbol *symbols = parse_symbols(argv[1]); FILE *new_rom = xfopen(argv[2], 'r'); FILE *orig_rom = xfopen(argv[3], 'r');