shithub: rgbds

Download patch

ref: 5aabb915ecdb8dff5fc38489b9d4d84c615d73d6
parent: 0d9de01f9dfb15198174f4f7eab209f00da9c7f9
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Dec 12 12:55:41 EST 2020

Allow STRCAT to take any number of args

Fixes bullet point 1 of #625

--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -206,6 +206,7 @@
 %type	<nConstValue>	sectiontype
 
 %type	<tzString>	string
+%type	<tzString>	strcat_args
 
 %type	<nConstValue>	sectorg
 %type	<sectSpec>	sectattrs
@@ -1066,38 +1067,38 @@
 		}
 ;
 
-string		: T_STRING {
-			if (snprintf($$, MAXSTRLEN + 1, "%s", $1) > MAXSTRLEN)
-				warning(WARNING_LONG_STR, "String is too long '%s'\n", $1);
-		}
+string		: T_STRING
 		| T_OP_STRSUB T_LPAREN string T_COMMA uconst T_COMMA uconst T_RPAREN {
 			strsubUTF8($$, $3, $5, $7);
 		}
-		| T_OP_STRCAT T_LPAREN string T_COMMA string T_RPAREN {
-			if (snprintf($$, MAXSTRLEN + 1, "%s%s", $3, $5) > MAXSTRLEN)
-				warning(WARNING_LONG_STR, "STRCAT: String too long '%s%s'\n",
-					$3, $5);
+		| T_OP_STRCAT T_LPAREN T_RPAREN {
+			$$[0] = '\0';
 		}
+		| T_OP_STRCAT T_LPAREN strcat_args T_RPAREN {
+			strcpy($$, $3);
+		}
 		| T_OP_STRUPR T_LPAREN string T_RPAREN {
-			if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
-				warning(WARNING_LONG_STR, "STRUPR: String too long '%s'\n", $3);
-
 			upperstring($$);
 		}
 		| T_OP_STRLWR T_LPAREN string T_RPAREN {
-			if (snprintf($$, MAXSTRLEN + 1, "%s", $3) > MAXSTRLEN)
-				warning(WARNING_LONG_STR, "STRUPR: String too long '%s'\n", $3);
-
 			lowerstring($$);
 		}
 ;
 
+strcat_args	: string
+		| strcat_args T_COMMA string {
+			if (snprintf($$, MAXSTRLEN + 1, "%s%s", $1, $3) > MAXSTRLEN)
+				warning(WARNING_LONG_STR, "STRCAT: String too long '%s%s'\n",
+					$1, $3);
+		}
+;
+
 section		: T_POP_SECTION sectmod string T_COMMA sectiontype sectorg sectattrs {
 			out_NewSection($3, $5, $6, &$7, $2);
 		}
 ;
 
-sectmod	: /* empty */	{ $$ = SECTION_NORMAL; }
+sectmod		: /* empty */	{ $$ = SECTION_NORMAL; }
 		| T_POP_UNION	{ $$ = SECTION_UNION; }
 		| T_POP_FRAGMENT{ $$ = SECTION_FRAGMENT; }
 ;
--- /dev/null
+++ b/test/asm/strcat.asm
@@ -1,0 +1,9 @@
+print: MACRO
+	PRINTT \1
+	PRINTT "\n"
+ENDM
+
+	print STRCAT()
+	print STRCAT("Durrr")
+	print STRCAT("Left"\, "right")
+	print STRCAT("Whoa"\, "\, "\, "baby!")
--- /dev/null
+++ b/test/asm/strcat.out
@@ -1,0 +1,4 @@
+
+Durrr
+Leftright
+Whoa, baby!