mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Support character escapes in linkerscript strings
This allows linkerscripts to refer to section names even if they contain special characters: '\r' '\n' '\t' '"' '\\'.
This commit is contained in:
@@ -222,13 +222,29 @@ static struct LinkerScriptToken *nextToken(void)
|
|||||||
size_t capacity = 16; /* Half of the default capacity */
|
size_t capacity = 16; /* Half of the default capacity */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
curchar = readChar(linkerScript);
|
||||||
|
if (curchar == EOF || isNewline(curchar)) {
|
||||||
|
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
||||||
|
linkerScriptName, lineNo);
|
||||||
|
} else if (curchar == '"') {
|
||||||
|
/* Quotes force a string termination */
|
||||||
|
curchar = '\0';
|
||||||
|
} else if (curchar == '\\') {
|
||||||
|
/* Backslashes are escape sequences */
|
||||||
curchar = readChar(linkerScript);
|
curchar = readChar(linkerScript);
|
||||||
if (curchar == EOF || isNewline(curchar))
|
if (curchar == EOF || isNewline(curchar))
|
||||||
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
||||||
linkerScriptName, lineNo);
|
linkerScriptName, lineNo);
|
||||||
else if (curchar == '"')
|
else if (curchar == 'n')
|
||||||
/* Quotes force a string termination */
|
curchar = '\n';
|
||||||
curchar = '\0';
|
else if (curchar == 'r')
|
||||||
|
curchar = '\r';
|
||||||
|
else if (curchar == 't')
|
||||||
|
curchar = '\t';
|
||||||
|
else if (curchar != '\\' && curchar != '"')
|
||||||
|
errx(1, "%s(%" PRIu32 "): Illegal character escape",
|
||||||
|
linkerScriptName, lineNo);
|
||||||
|
}
|
||||||
|
|
||||||
if (size >= capacity || token.attr.string == NULL) {
|
if (size >= capacity || token.attr.string == NULL) {
|
||||||
capacity *= 2;
|
capacity *= 2;
|
||||||
|
|||||||
3
test/link/linkerscript-escapes-test.link
Normal file
3
test/link/linkerscript-escapes-test.link
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ROM0
|
||||||
|
"A\"B\tC\rD\nE"
|
||||||
|
"in\{valid"
|
||||||
1
test/link/linkerscript-escapes-test.out
Normal file
1
test/link/linkerscript-escapes-test.out
Normal file
@@ -0,0 +1 @@
|
|||||||
|
error: ./linkerscript-escapes-test.link(3): Illegal character escape
|
||||||
4
test/link/linkerscript-escapes.asm
Normal file
4
test/link/linkerscript-escapes.asm
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
SECTION "A\"B\tC\rD\nE", ROM0
|
||||||
|
DS $1000
|
||||||
|
SECTION "in\{valid", ROM0
|
||||||
|
DS $1000
|
||||||
Reference in New Issue
Block a user