Allow STRCAT to take any number of args

Fixes bullet point 1 of #625
This commit is contained in:
ISSOtm
2020-12-12 17:55:41 +01:00
committed by Eldred Habert
parent 0d9de01f9d
commit 5aabb915ec
4 changed files with 29 additions and 15 deletions

View File

@@ -206,6 +206,7 @@ static inline void failAssertMsg(enum AssertionType type, char const *msg)
%type <nConstValue> sectiontype
%type <tzString> string
%type <tzString> strcat_args
%type <nConstValue> sectorg
%type <sectSpec> sectattrs
@@ -1066,32 +1067,32 @@ const : relocexpr {
}
;
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);
}

9
test/asm/strcat.asm Normal file
View File

@@ -0,0 +1,9 @@
print: MACRO
PRINTT \1
PRINTT "\n"
ENDM
print STRCAT()
print STRCAT("Durrr")
print STRCAT("Left"\, "right")
print STRCAT("Whoa"\, "\, "\, "baby!")

0
test/asm/strcat.err Normal file
View File

4
test/asm/strcat.out Normal file
View File

@@ -0,0 +1,4 @@
Durrr
Leftright
Whoa, baby!