aboutsummaryrefslogtreecommitdiffstats
path: root/evaluator.c
diff options
context:
space:
mode:
authormichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-01-26 05:18:07 +0000
committermichael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-01-26 05:18:07 +0000
commit2b538e055ac14d70cc2f5a3e3b3c417e155c53e3 (patch)
tree2939c1a29d9fb6c815e1548022ce9d11b476db8e /evaluator.c
parent8402d701a9739bb207fe1edb8e682b3a95de4e51 (diff)
downloadlcd4linux-2b538e055ac14d70cc2f5a3e3b3c417e155c53e3.tar.gz
evaluator: escape sequences in strings (fix for ticket #145)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@979 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'evaluator.c')
-rw-r--r--evaluator.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/evaluator.c b/evaluator.c
index e70aaa5..52212b3 100644
--- a/evaluator.c
+++ b/evaluator.c
@@ -591,13 +591,65 @@ static void Parse(void)
/* strings */
else if (*ExprPtr == '\'') {
- char *start = ++ExprPtr;
- while (*ExprPtr != '\0' && *ExprPtr != '\'')
- ExprPtr++;
- Word = strndup(start, ExprPtr - start);
+ size_t length = 0;
+ size_t size = CHUNK_SIZE;
+ Word = malloc(size);
+ ExprPtr++;
+ while (*ExprPtr != '\0' && *ExprPtr != '\'') {
+ if (*ExprPtr == '\\') {
+ switch (*(ExprPtr + 1)) {
+ case '\\':
+ case '\'':
+ Word[length++] = *(ExprPtr + 1);
+ ExprPtr += 2;
+ break;
+ case 'a':
+ Word[length++] = '\a';
+ ExprPtr += 2;
+ break;
+ case 'b':
+ Word[length++] = '\b';
+ ExprPtr += 2;
+ break;
+ case 't':
+ Word[length++] = '\t';
+ ExprPtr += 2;
+ break;
+ case 'n':
+ Word[length++] = '\n';
+ ExprPtr += 2;
+ break;
+ case 'v':
+ Word[length++] = '\v';
+ ExprPtr += 2;
+ break;
+ case 'f':
+ Word[length++] = '\f';
+ ExprPtr += 2;
+ break;
+ case 'r':
+ Word[length++] = '\r';
+ ExprPtr += 2;
+ break;
+ default:
+ error("Evaluator: unknown escape sequence '\\%c' in <%s>", *(ExprPtr + 1), Expression);
+ Word[length++] = *ExprPtr++;
+ }
+ } else {
+ Word[length++] = *ExprPtr++;
+ }
+ if (length >= size) {
+ size += CHUNK_SIZE;
+ Word = realloc(Word, size);
+ }
+ }
+ Word[length] = '\0';
Token = T_STRING;
- if (*ExprPtr == '\'')
+ if (*ExprPtr == '\'') {
ExprPtr++;
+ } else {
+ error("Evaluator: unterminated string in <%s>", Expression);
+ }
}
/* non-alpha operators */