From 832ba26e30580bff045b9b8199ec02f4f9de5a53 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 26 Mar 2024 13:41:52 -0700 Subject: [PATCH] Improved comment walking --- etc/hello.tal | 2 +- src/uxnasm.c | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/etc/hello.tal b/etc/hello.tal index 2379bcc..0f7e286 100644 --- a/etc/hello.tal +++ b/etc/hello.tal @@ -19,7 +19,7 @@ #010f DEO -BRK +BRK @program/extend BRK diff --git a/src/uxnasm.c b/src/uxnasm.c index 8851fd0..1521704 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -316,18 +316,17 @@ static int walkcomment(char *w, FILE *f) { int i = 1; - char word[0x40]; + unsigned int buf; if(slen(w) != 1) - fprintf(stderr, "-- Malformed comment: %s\n", w); - while(fscanf(f, "%63s", word) == 1) { - if(slen(word) != 1) - continue; - else if(word[0] == '(') + return 0; + while(fread(&buf, 1, 1, f)) { + char c = (char)buf; + if(c == '(') i++; - else if(word[0] == ')' && --i < 1) - break; + else if(c == ')' && --i < 1) + return 1; } - return 1; + return 0; } static int @@ -337,7 +336,7 @@ parse(char *w, FILE *f) char c; Macro *m; switch(w[0]) { - case '(': return walkcomment(w, f); + case '(': return !walkcomment(w, f) ? error_asm("Invalid comment") : 1; case '~': return !doinclude(w + 1) ? error_asm("Invalid include") : 1; case '%': return !makemacro(w + 1, f) ? error_asm("Invalid macro") : 1; case '@': return !makelabel(w + 1, 1) ? error_asm("Invalid label") : 1;