diff --git a/src/asm/parser.y b/src/asm/parser.y index 88ae0449..06403ad6 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -206,6 +206,7 @@ static inline void failAssertMsg(enum AssertionType type, char const *msg) %type sectiontype %type string +%type strcat_args %type sectorg %type sectattrs @@ -1066,38 +1067,38 @@ 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); } ; -sectmod : /* empty */ { $$ = SECTION_NORMAL; } +sectmod : /* empty */ { $$ = SECTION_NORMAL; } | T_POP_UNION { $$ = SECTION_UNION; } | T_POP_FRAGMENT{ $$ = SECTION_FRAGMENT; } ; diff --git a/test/asm/strcat.asm b/test/asm/strcat.asm new file mode 100644 index 00000000..9651a3b6 --- /dev/null +++ b/test/asm/strcat.asm @@ -0,0 +1,9 @@ +print: MACRO + PRINTT \1 + PRINTT "\n" +ENDM + + print STRCAT() + print STRCAT("Durrr") + print STRCAT("Left"\, "right") + print STRCAT("Whoa"\, "\, "\, "baby!") diff --git a/test/asm/strcat.err b/test/asm/strcat.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/strcat.out b/test/asm/strcat.out new file mode 100644 index 00000000..d1523514 --- /dev/null +++ b/test/asm/strcat.out @@ -0,0 +1,4 @@ + +Durrr +Leftright +Whoa, baby!