Improved comment walking

This commit is contained in:
Devine Lu Linvega 2024-03-26 13:41:52 -07:00
parent a197c24b2a
commit 832ba26e30
2 changed files with 10 additions and 11 deletions

View File

@ -316,18 +316,17 @@ static int
walkcomment(char *w, FILE *f) walkcomment(char *w, FILE *f)
{ {
int i = 1; int i = 1;
char word[0x40]; unsigned int buf;
if(slen(w) != 1) if(slen(w) != 1)
fprintf(stderr, "-- Malformed comment: %s\n", w); return 0;
while(fscanf(f, "%63s", word) == 1) { while(fread(&buf, 1, 1, f)) {
if(slen(word) != 1) char c = (char)buf;
continue; if(c == '(')
else if(word[0] == '(')
i++; i++;
else if(word[0] == ')' && --i < 1) else if(c == ')' && --i < 1)
break; return 1;
} }
return 1; return 0;
} }
static int static int
@ -337,7 +336,7 @@ parse(char *w, FILE *f)
char c; char c;
Macro *m; Macro *m;
switch(w[0]) { 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 !doinclude(w + 1) ? error_asm("Invalid include") : 1;
case '%': return !makemacro(w + 1, f) ? error_asm("Invalid macro") : 1; case '%': return !makemacro(w + 1, f) ? error_asm("Invalid macro") : 1;
case '@': return !makelabel(w + 1, 1) ? error_asm("Invalid label") : 1; case '@': return !makelabel(w + 1, 1) ? error_asm("Invalid label") : 1;