shithub: rgbds

Download patch

ref: f31deb5010b73b337b2611e2555a871ddac3cd28
parent: 0956d300c4676c5ec6ddaf8e69de4a3d5a77fab7
author: Rangi <[email protected]>
date: Tue Dec 15 08:07:04 EST 2020

Fix STRUPR and STRLWR after 5aabb915ecdb8dff5fc38489b9d4d84c615d73d6

Fixes #647

--- a/include/asm/main.h
+++ b/include/asm/main.h
@@ -43,9 +43,6 @@
 void opt_Pop(void);
 void opt_Parse(char *s);
 
-void upperstring(char *s);
-void lowerstring(char *s);
-
 /* TODO: are these really needed? */
 #define YY_FATAL_ERROR fatalerror
 
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -197,22 +197,6 @@
 		sym_AddString(cldefines[i], cldefines[i + 1]);
 }
 
-void upperstring(char *s)
-{
-	while (*s) {
-		*s = toupper(*s);
-		s++;
-	}
-}
-
-void lowerstring(char *s)
-{
-	while (*s) {
-		*s = tolower(*s);
-		s++;
-	}
-}
-
 /* Escapes Make-special chars from a string */
 static char *make_escape(const char *str)
 {
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -39,6 +39,20 @@
 int32_t nPCOffset;
 bool executeElseBlock; /* If this is set, ELIFs cannot be executed anymore */
 
+static void upperstring(char *dest, char const *src)
+{
+	while (*src)
+		*dest++ = toupper(*src++);
+	*dest = '\0';
+}
+
+static void lowerstring(char *dest, char const *src)
+{
+	while (*src)
+		*dest++ = tolower(*src++);
+	*dest = '\0';
+}
+
 static uint32_t str2int2(uint8_t *s, int32_t length)
 {
 	int32_t i;
@@ -1084,10 +1098,10 @@
 			strcpy($$, $3);
 		}
 		| T_OP_STRUPR T_LPAREN string T_RPAREN {
-			upperstring($$);
+			upperstring($$, $3);
 		}
 		| T_OP_STRLWR T_LPAREN string T_RPAREN {
-			lowerstring($$);
+			lowerstring($$, $3);
 		}
 ;
 
--- /dev/null
+++ b/test/asm/strupr-strlwr.asm
@@ -1,0 +1,4 @@
+foo equs strupr("xii")
+bar equs strlwr("LOL")
+
+	printt "foo={foo} bar={bar}\n"
--- /dev/null
+++ b/test/asm/strupr-strlwr.out
@@ -1,0 +1,1 @@
+foo=XII bar=lol