Skip to content

Commit

Permalink
Update make_patch.c
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandth committed Dec 26, 2024
1 parent 9f5a3d8 commit a6fac5f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/make_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit a6fac5f

Please sign in to comment.