shithub: rgbds

Download patch

ref: 3b2c862320f5001746282186b6c0565ff4716dfa
parent: 230f849229f8443703ab281bd1f1cd3ef4eb6d6e
author: ISSOtm <eldredhabert0@gmail.com>
date: Tue Feb 11 04:35:19 EST 2020

Make more RGBASM errors print their line number

Fixes #379.

--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -396,7 +396,9 @@
 			oFailedOnMissingInclude = true;
 			return;
 		}
-		err(1, "Unable to open included file '%s'", tzFileName);
+		yyerror("Unable to open included file '%s': %s", tzFileName,
+			strerror(errno));
+		return;
 	}
 
 	pushcontext();
@@ -540,7 +542,8 @@
 	} else {
 		pCurrentFile = fopen(pFileName, "rb");
 		if (pCurrentFile == NULL)
-			err(1, "Unable to open file '%s'", pFileName);
+			yyerror("Unable to open file '%s': %s", pFileName,
+				strerror(errno));
 	}
 	nFileStackDepth = 0;
 
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -366,71 +366,73 @@
  * Make sure that only non-zero ASCII characters are used. Also, check if the
  * 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) {
-		errx(1, "Invalid character range (start: %u, end: %u)",
-		     start, end);
+		yyerror("Invalid character range (start: %u, end: %u)",
+			start, end);
+		return false;
 	}
+	return true;
 }
 
 void lex_FloatDeleteRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingChars[start] &= ~id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingChars[start] &= ~id;
+			start++;
+		}
 	}
 }
 
 void lex_FloatAddRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingChars[start] |= id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingChars[start] |= id;
+			start++;
+		}
 	}
 }
 
 void lex_FloatDeleteFirstRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingFirstChar[start] &= ~id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingFirstChar[start] &= ~id;
+			start++;
+		}
 	}
 }
 
 void lex_FloatAddFirstRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingFirstChar[start] |= id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingFirstChar[start] |= id;
+			start++;
+		}
 	}
 }
 
 void lex_FloatDeleteSecondRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingSecondChar[start] &= ~id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingSecondChar[start] &= ~id;
+			start++;
+		}
 	}
 }
 
 void lex_FloatAddSecondRange(uint32_t id, uint16_t start, uint16_t end)
 {
-	lex_CheckCharacterRange(start, end);
-
-	while (start <= end) {
-		tFloatingSecondChar[start] |= id;
-		start++;
+	if (lex_CheckCharacterRange(start, end)) {
+		while (start <= end) {
+			tFloatingSecondChar[start] |= id;
+			start++;
+		}
 	}
 }
 
@@ -824,7 +826,7 @@
 					nLineNo++;
 					goto scanagain;
 				} else {
-					errx(1, "Expected a new line after the continuation character.");
+					yyerror("Expected a new line after the continuation character.");
 				}
 			}
 		}
@@ -974,7 +976,7 @@
 						ch = 0;
 						break;
 					} else {
-						errx(1, "Expected a new line after the continuation character.");
+						yyerror("Expected a new line after the continuation character.");
 					}
 				}
 				break;
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -142,7 +142,7 @@
 			newopt.gbgfx[2] = s[3];
 			newopt.gbgfx[3] = s[4];
 		} else {
-			errx(1, "Must specify exactly 4 characters for option 'g'");
+			yyerror("Must specify exactly 4 characters for option 'g'");
 		}
 		break;
 	case 'b':
@@ -150,7 +150,7 @@
 			newopt.binary[0] = s[1];
 			newopt.binary[1] = s[2];
 		} else {
-			errx(1, "Must specify exactly 2 characters for option 'b'");
+			yyerror("Must specify exactly 2 characters for option 'b'");
 		}
 		break;
 	case 'z':
@@ -159,16 +159,16 @@
 			unsigned int fillchar;
 
 			result = sscanf(&s[1], "%x", &fillchar);
-			if (!((result == EOF) || (result == 1)))
-				errx(1, "Invalid argument for option 'z'");
-
-			newopt.fillchar = fillchar;
+			if (result != EOF && result != 1)
+				yyerror("Invalid argument for option 'z'");
+			else
+				newopt.fillchar = fillchar;
 		} else {
-			errx(1, "Invalid argument for option 'z'");
+			yyerror("Invalid argument for option 'z'");
 		}
 		break;
 	default:
-		fatalerror("Unknown option");
+		yyerror("Unknown option");
 		break;
 	}