Make more RGBASM errors print their line number

Fixes #379.
This commit is contained in:
ISSOtm
2020-02-11 09:35:19 +01:00
parent 230f849229
commit 3b2c862320
3 changed files with 50 additions and 45 deletions

View File

@@ -396,7 +396,9 @@ void fstk_RunInclude(char *tzFileName)
oFailedOnMissingInclude = true; oFailedOnMissingInclude = true;
return; return;
} }
err(1, "Unable to open included file '%s'", tzFileName); yyerror("Unable to open included file '%s': %s", tzFileName,
strerror(errno));
return;
} }
pushcontext(); pushcontext();
@@ -540,7 +542,8 @@ void fstk_Init(char *pFileName)
} else { } else {
pCurrentFile = fopen(pFileName, "rb"); pCurrentFile = fopen(pFileName, "rb");
if (pCurrentFile == NULL) if (pCurrentFile == NULL)
err(1, "Unable to open file '%s'", pFileName); yyerror("Unable to open file '%s': %s", pFileName,
strerror(errno));
} }
nFileStackDepth = 0; nFileStackDepth = 0;

View File

@@ -366,72 +366,74 @@ uint32_t lex_FloatAlloc(const struct sLexFloat *token)
* Make sure that only non-zero ASCII characters are used. Also, check if the * Make sure that only non-zero ASCII characters are used. Also, check if the
* start is greater than the end of the range. * start is greater than the end of the range.
*/ */
void lex_CheckCharacterRange(uint16_t start, uint16_t end) bool lex_CheckCharacterRange(uint16_t start, uint16_t end)
{ {
if (start > end || start < 1 || end > 127) { if (start > end || start < 1 || end > 127) {
errx(1, "Invalid character range (start: %u, end: %u)", yyerror("Invalid character range (start: %u, end: %u)",
start, end); start, end);
return false;
} }
return true;
} }
void lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingChars[start] &= ~id; tFloatingChars[start] &= ~id;
start++; start++;
} }
}
} }
void lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingChars[start] |= id; tFloatingChars[start] |= id;
start++; start++;
} }
}
} }
void lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingFirstChar[start] &= ~id; tFloatingFirstChar[start] &= ~id;
start++; start++;
} }
}
} }
void lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingFirstChar[start] |= id; tFloatingFirstChar[start] |= id;
start++; start++;
} }
}
} }
void lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingSecondChar[start] &= ~id; tFloatingSecondChar[start] &= ~id;
start++; start++;
} }
}
} }
void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end) void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end)
{ {
lex_CheckCharacterRange(start, end); if (lex_CheckCharacterRange(start, end)) {
while (start <= end) { while (start <= end) {
tFloatingSecondChar[start] |= id; tFloatingSecondChar[start] |= id;
start++; start++;
} }
}
} }
static struct sLexFloat *lexgetfloat(uint32_t nFloatMask) static struct sLexFloat *lexgetfloat(uint32_t nFloatMask)
@@ -824,7 +826,7 @@ scanagain:
nLineNo++; nLineNo++;
goto scanagain; goto scanagain;
} else { } else {
errx(1, "Expected a new line after the continuation character."); yyerror("Expected a new line after the continuation character.");
} }
} }
} }
@@ -974,7 +976,7 @@ static uint32_t yylex_MACROARGS(void)
ch = 0; ch = 0;
break; break;
} else { } else {
errx(1, "Expected a new line after the continuation character."); yyerror("Expected a new line after the continuation character.");
} }
} }
break; break;

View File

@@ -142,7 +142,7 @@ void opt_Parse(char *s)
newopt.gbgfx[2] = s[3]; newopt.gbgfx[2] = s[3];
newopt.gbgfx[3] = s[4]; newopt.gbgfx[3] = s[4];
} else { } else {
errx(1, "Must specify exactly 4 characters for option 'g'"); yyerror("Must specify exactly 4 characters for option 'g'");
} }
break; break;
case 'b': case 'b':
@@ -150,7 +150,7 @@ void opt_Parse(char *s)
newopt.binary[0] = s[1]; newopt.binary[0] = s[1];
newopt.binary[1] = s[2]; newopt.binary[1] = s[2];
} else { } else {
errx(1, "Must specify exactly 2 characters for option 'b'"); yyerror("Must specify exactly 2 characters for option 'b'");
} }
break; break;
case 'z': case 'z':
@@ -159,16 +159,16 @@ void opt_Parse(char *s)
unsigned int fillchar; unsigned int fillchar;
result = sscanf(&s[1], "%x", &fillchar); result = sscanf(&s[1], "%x", &fillchar);
if (!((result == EOF) || (result == 1))) if (result != EOF && result != 1)
errx(1, "Invalid argument for option 'z'"); yyerror("Invalid argument for option 'z'");
else
newopt.fillchar = fillchar; newopt.fillchar = fillchar;
} else { } else {
errx(1, "Invalid argument for option 'z'"); yyerror("Invalid argument for option 'z'");
} }
break; break;
default: default:
fatalerror("Unknown option"); yyerror("Unknown option");
break; break;
} }